"use strict";var M=Object.create;var d=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var w=Object.getPrototypeOf;var x=Object.prototype.hasOwnProperty;var m=(t,s)=>d(t,"name",{value:s,configurable:true});var B=(t,s)=>{for(var a in s)d(t,a,{get:s[a],enumerable:true})};var N=(t,s,a,l)=>{if(s&&typeof s==="object"||typeof s==="function"){for(let n of P(s))if(!x.call(t,n)&&n!==a)d(t,n,{get:()=>s[n],enumerable:!(l=L(s,n))||l.enumerable})}return t};var D=(t,s,a)=>(a=t!=null?M(w(t)):{},N(s||!t||!t.__esModule?d(a,"default",{value:t,enumerable:true}):a,t));var O=t=>N(d({},"__esModule",{value:true}),t);var H={};B(H,{default:()=>A});module.exports=O(H);var e=require("react/jsx-runtime");var f=require("electron");var c=require("react");var p=require("react-intl");var b=require("../config");var S=require("../environment");var I=D(require("./ui/FullscreenLoader"));const h=(0,p.defineMessages)({loading:{id:"service.screenshare.loading",defaultMessage:"Loading screens and windows"},cancel:{id:"service.screenshare.cancel",defaultMessage:"Cancel"}});const C=(0,p.injectIntl)(({handleOnClick:t,intl:s})=>(0,e.jsx)("li",{className:"desktop-capturer-selection__item",children:(0,e.jsx)("button",{type:"button",className:"desktop-capturer-selection__btn","data-id":b.SCREENSHARE_CANCELLED_BY_USER,title:"Cancel",onClick:t,children:(0,e.jsx)("span",{className:"desktop-capturer-selection__name desktop-capturer-selection__name--cancel",children:s.formatMessage(h.cancel)})})}));function R(t){const{service:s,intl:a}=t;const[l,n]=(0,c.useState)([]);const[k,v]=(0,c.useState)(false);const[E,y]=(0,c.useState)(null);const[_,u]=(0,c.useState)(false);(0,c.useEffect)(()=>{const r=m((i,g)=>{if(_)return;v(true);y(g.trackerId)},"handleSelectCaptureDevice");f.ipcRenderer.on(`select-capture-device:${s.id}`,r);return()=>{f.ipcRenderer.removeListener(`select-capture-device:${s.id}`,r)}},[s.id,_]);const o=m(r=>{const{id:i}=r.currentTarget.dataset;window["ferdium"].actions.service.sendIPCMessage({serviceId:s.id,channel:`selected-media-source:${E}`,args:{mediaSourceId:i}});v(false);n([]);y(null)},"handleOnClick");(0,c.useEffect)(()=>{if(k){u(true);f.ipcRenderer.invoke("get-desktop-capturer-sources").then(r=>{if(S.isWayland){o({currentTarget:{dataset:{id:r[0].id}}});return}n(r);u(false)}).catch(()=>{v(false);n([]);u(false)})}else{n([]);u(false)}},[k]);if(!k){return null}if(_){return(0,e.jsx)("div",{className:"desktop-capturer-selection",children:(0,e.jsx)("ul",{className:"desktop-capturer-selection__list",style:{display:"flex",flexDirection:"column",alignItems:"center"},children:(0,e.jsx)(I.default,{title:a.formatMessage(h.loading),children:(0,e.jsx)("div",{style:{display:"flex",justifyContent:"center"},children:(0,e.jsx)(C,{handleOnClick:o})})})})})}if(l.length===0){return(0,e.jsx)("div",{className:"desktop-capturer-selection",children:(0,e.jsxs)("ul",{className:"desktop-capturer-selection__list",children:[(0,e.jsx)("li",{children:"No available sources."}),(0,e.jsx)(C,{handleOnClick:o})]})})}return(0,e.jsxs)("div",{className:"desktop-capturer-selection",children:[(0,e.jsx)("ul",{className:"desktop-capturer-selection__list",children:l.map(({id:r,name:i,thumbnail:g})=>(0,e.jsx)("li",{className:"desktop-capturer-selection__item",children:(0,e.jsxs)("button",{type:"button",className:"desktop-capturer-selection__btn","data-id":r,title:i,onClick:o,children:[(0,e.jsx)("img",{alt:"Desktop capture preview",className:"desktop-capturer-selection__thumbnail",src:g.toDataURL()}),(0,e.jsx)("span",{className:"desktop-capturer-selection__name",children:i})]})},r))}),(0,e.jsx)(C,{handleOnClick:o})]})}m(R,"MediaSource");var A=(0,p.injectIntl)(R);
