"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../node_modules/tslib/tslib.es6.js"),i=require("react");require("../../../node_modules/react-redux/es/index.js");var n=require("../../../store/index.js"),r=require("../../../utils/deviceUtils.js"),u=require("../../../lib/webrtc/janus.js"),o=require("../../../lib/phone/trunk.js"),l=require("../../../lib/devices/devices.js"),t=require("../../../utils/genericFunctions/eventDispatch.js"),s=require("../../../node_modules/react-redux/es/hooks/useDispatch.js"),d=require("../../../node_modules/react-redux/es/hooks/useSelector.js");exports.useSideViewLogic=function(a){var c,v,p,h,f,b,g,m,_=s.useDispatch(),S=d.useSelector((function(e){return e.currentUser})),k=d.useSelector((function(e){return e.users})),j=d.useSelector((function(e){return e.paramUrl})),w=n.store.select.mediaDevices.videoInputDevices(n.store.getState()),q=i.useRef(u.default),V=d.useSelector((function(e){return e.currentUser.conversations})),C=i.useState([]),D=C[0],T=C[1],U=i.useState(!0),y=U[0],I=U[1],x=i.useCallback((function(){var e=Object.values(V).find((function(e){return Object.keys(e).length>0}));return e?Object.values(e)[0]:null}),[V]),O=i.useCallback((function(e){if(_.island.toggleSideViewVisible(!1),"openUrl"===e){var i=Object.values(V).find((function(e){return Object.keys(e).length>0})),n=i?Object.values(i)[0]:null;if((null==n?void 0:n.connected)&&"in"===(null==n?void 0:n.direction)){var r={counterpartNum:n.counterpartNum,counterpartName:n.counterpartName,owner:n.owner,uniqueId:n.uniqueId,linkedId:n.linkedId,throughQueue:n.throughQueue,throughTrunk:n.throughTrunk,direction:n.direction,connected:n.connected};t.eventDispatch("phone-island-url-parameter-opened",r)}}else null!==e&&_.island.setIslandView(e)}),[_.island,V]),Q=i.useCallback((function(){return e.__awaiter(void 0,void 0,void 0,(function(){var i;return e.__generator(this,(function(e){switch(e.label){case 0:return w.length>0?[4,l.checkWebCamPermission()]:[3,2];case 1:return i=e.sent(),I(i),[2,i];case 2:return I(!1),[2,!1]}}))}))}),[w.length]),E=i.useCallback((function(){return e.__awaiter(void 0,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return[4,Q()];case 1:return e.sent()&&(O("video"),n.store.dispatch.currentCall.updateCurrentCall({isLocalVideoEnabled:!0,isStartingVideoCall:!0})),[2]}}))}))}),[Q,O]),M=i.useCallback((function(){O("video"),n.store.dispatch.screenShare.update({isStartingScreenShare:!0})}),[O]),N=i.useMemo((function(){var e;return(null===(e=null==S?void 0:S.profile)||void 0===e?void 0:e.macro_permissions)||{}}),[null===(c=null==S?void 0:S.profile)||void 0===c?void 0:c.macro_permissions]),P=i.useMemo((function(){var e,i,n,r,u,o,l,t,s;return{canRecord:(null===(n=null===(i=null===(e=null==N?void 0:N.settings)||void 0===e?void 0:e.permissions)||void 0===i?void 0:i.recording)||void 0===n?void 0:n.value)||!1,canShareScreen:"safari"!==(null===(o=null===(u=null===(r=null==q?void 0:q.current)||void 0===r?void 0:r.webRTCAdapter)||void 0===u?void 0:u.browserDetails)||void 0===o?void 0:o.browser)&&((null===(s=null===(t=null===(l=null==N?void 0:N.nethvoice_cti)||void 0===l?void 0:l.permissions)||void 0===t?void 0:t.screen_sharing)||void 0===s?void 0:s.value)||!1),canSwitchDevice:(null==D?void 0:D.length)>0}}),[null===(h=null===(p=null===(v=null==N?void 0:N.settings)||void 0===v?void 0:v.permissions)||void 0===p?void 0:p.recording)||void 0===h?void 0:h.value,null===(g=null===(b=null===(f=null==N?void 0:N.nethvoice_cti)||void 0===f?void 0:f.permissions)||void 0===b?void 0:b.screen_sharing)||void 0===g?void 0:g.value,null==D?void 0:D.length,null===(m=null==S?void 0:S.default_device)||void 0===m?void 0:m.type,a]),A=i.useMemo((function(){var e=x();if("never"===j.openParamUrlType)return!1;if(!(null==e?void 0:e.connected)||"in"!==(null==e?void 0:e.direction))return!1;if("button"===j.openParamUrlType){if(j.onlyQueues&&(null==e?void 0:e.throughQueue))return!0;if(!j.onlyQueues&&(o.isFromTrunk(e.counterpartNum)||(null==e?void 0:e.throughQueue)))return!0}return!1}),[x,j.onlyQueues,j.openParamUrlType]);i.useEffect((function(){if(S&&k){var e=r.getAvailableDevices(S,k);T(e)}}),[S,k]);var L=i.useCallback((function(){var e=x(),i=(null==e?void 0:e.linkedId)||(null==e?void 0:e.linkedid),n=(null==e?void 0:e.uniqueId)||(null==e?void 0:e.uniqueid);(i||n)&&(_.island.toggleSideViewVisible(!1),t.eventDispatch("phone-island-transcription-open",{linkedid:i,uniqueid:n}))}),[_.island,x]),R=i.useMemo((function(){return(null==S?void 0:S.call_transcription_enabled)||!1}),[null==S?void 0:S.call_transcription_enabled]);return e.__assign(e.__assign({userInformation:S,availableDevices:D,videoInputDevices:w,isVideoCallButtonVisible:y,isUrlButtonEnabled:A,hasValidUrl:j.hasValidUrl,isTranscriptionEnabled:R},P),{goToVideoCall:E,goToScreenSharing:M,closeSideViewAndLaunchEvent:O,openTranscriptionView:L})};
//# sourceMappingURL=useSideViewLogic.js.map
