"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");require("../../node_modules/react-redux/es/index.js");var t=require("../../utils/genericFunctions/player.js"),r=require("../../styles/CustomRange.styles.js"),a=require("../../node_modules/@fortawesome/react-fontawesome/index.es.js"),i=require("../../node_modules/@fortawesome/free-solid-svg-icons/index.mjs.js"),n=require("../../utils/customHooks/useEventListener.js"),o=require("../../utils/genericFunctions/eventDispatch.js");require("../../node_modules/tslib/tslib.es6.js"),require("../../store/index.js");var s=require("../../node_modules/react-redux/es/hooks/useSelector.js"),l=require("../../node_modules/react-redux/es/hooks/useDispatch.js");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=u(e),d=r.StyledCustomRange,p=function(r){var u=r.isPlayer,p=s.useSelector((function(e){return e.player})),f=p.audioPlayer,m=p.audioPlayerPlaying,y=p.audioPlayerTrackDuration,g=e.useRef(),x=e.useRef(),v=e.useState("00:00"),h=v[0],w=v[1],E=e.useState(),P=E[0],k=E[1],j=l.useDispatch(),N=e.useState(y&&Math.round(y)||0),q=N[0],A=N[1],F=s.useSelector((function(e){return e.recorder}));F.recorded,F.playing;var C=e.useState(!1),b=C[0],D=C[1],S=e.useCallback((function(){var e,r=null===(e=null==f?void 0:f.current)||void 0===e?void 0:e.currentTime;r&&w(t.formatTime(Math.round(r))),g.current.value=r,q&&r&&g.current.style.setProperty("--range-progress","".concat(r/q*100,"%")),x.current=requestAnimationFrame(S)}),[f,q,g]);function _(e){e.stopPropagation()}function T(){j.player.pauseAudioPlayer(),j.recorder.setPlaying(!1),j.recorder.setPaused(!0),o.eventDispatch("phone-island-recording-paused",{})}function M(){j.player.startAudioPlayer((function(){j.recorder.setPlaying(!1),j.recorder.setPaused(!0)})),j.recorder.setPlaying(!0),o.eventDispatch("phone-island-recording-played",{})}function R(){j.recorder.resetRecorded(),o.eventDispatch("phone-island-recording-deleted",{})}return e.useEffect((function(){m?x.current=requestAnimationFrame(S):cancelAnimationFrame(x.current)}),[m]),e.useEffect((function(){y&&(A(Math.round(y)),k(t.formatTime(y)))}),[y]),e.useEffect((function(){return function(){cancelAnimationFrame(x.current)}}),[]),n.useEventListener("phone-island-recording-pause",(function(e){T()})),n.useEventListener("phone-island-recording-play",(function(e){M()})),n.useEventListener("phone-island-recording-delete",(function(e){R()})),c.default.createElement("div",{className:"pi-w-full pi-h-full pi-flex pi-flex-col pi-items-center pi-justify-between pi-px-2"},c.default.createElement("div",{className:"pi-w-full pi-flex pi-items-center pi-justify-between pi-gap-2"},u?c.default.createElement("div",{className:"pi-cursor-pointer pi-flex-none",onClick:function(){if(null==f?void 0:f.current){var e=!b;f.current.muted=e,D(e)}}},c.default.createElement(a.FontAwesomeIcon,{icon:b?i.faVolumeXmark:i.faVolumeHigh,className:"pi-h-4 pi-w-4 pi-text-gray-700 dark:pi-text-gray-300"})):c.default.createElement(c.default.Fragment,null,m?c.default.createElement("div",{onClick:T,className:"pi-cursor-pointer pi-flex-none","data-tooltip-id":"tooltip-pause-recorder-view","data-tooltip-content":"Pause"},c.default.createElement(a.FontAwesomeIcon,{icon:i.faPause,className:"pi-h-4 pi-w-4 pi-text-gray-700 dark:pi-text-gray-300"})):c.default.createElement("div",{onClick:M,className:"pi-cursor-pointer pi-flex-none","data-tooltip-id":"tooltip-play-recorder-view","data-tooltip-content":"Play"},c.default.createElement(a.FontAwesomeIcon,{icon:i.faPlay,className:"pi-h-4 pi-w-4 pi-text-gray-700 dark:pi-text-gray-300"}))),c.default.createElement("div",{className:"pi-w-full pi-flex-grow pi-mx-2",onClick:_,onMouseDown:_,onTouchStart:_},c.default.createElement(d,{"data-stop-propagation":!0,ref:g,defaultValue:0,type:"range",step:"1",min:"0",max:q&&q||0,onChange:function(){j.player.setAudioPlayerCurrentTime(g.current.value)},className:"pi-text-green-600 dark:pi-text-green-500"})),!u&&c.default.createElement("div",{onClick:R,className:"pi-cursor-pointer pi-flex-none","data-tooltip-id":"tooltip-delete-recorder-view","data-tooltip-content":"Delete"},c.default.createElement(a.FontAwesomeIcon,{icon:i.faTrash,className:"pi-h-4 pi-w-4 pi-text-gray-700 dark:pi-text-gray-200"}))),c.default.createElement("div",{className:"pi-flex pi-justify-between pi-w-full pi-text-xs pi-mt-2 pi-mb-1"},c.default.createElement("div",{className:"pi-font-medium pi-text-gray-700 dark:pi-text-gray-200 pi-truncate pi-max-w-[45%]"},h),c.default.createElement("div",{className:"pi-font-medium pi-text-gray-700 dark:pi-text-gray-200 pi-truncate pi-max-w-[45%]"},P)))};exports.Progress=p,exports.default=p;
//# sourceMappingURL=Progress.js.map
