// Metro module 15917 (f15918). import { useEffect, useState } from "react"; import VoicePanelStore from "../../VoicePanelStore"; import { VoicePanelModes } from "../../VoicePanelConstants"; import { ComponentActions, Routes } from "../../../../Constants"; import * as _ReanimatedRexport from "../../../reanimated/ReanimatedRexport"; import { useAnimatedReaction } from "../../../reanimated/ReanimatedRexport"; import { ComponentDispatch } from "../../../../utils/ComponentDispatchUtils"; import RouteManager from "../../../routing/RouteManager"; import { matchPath } from "../../../routing/matchPathCompat"; import { RouteParam } from "../../../routing/RouteUtils"; import { extractParamsFromVoiceModalRoute } from "../../../routing/native/RouteManagerUtils"; import closeVoicePanels from "../utils/closeVoicePanels"; const __initData = { code: "function usePanelOpenStateTsx1(){const{connected}=this.__closure;return{connected:connected.get()};}" }; const __initData2 = { code: "function usePanelOpenStateTsx2(props,previous){const{runOnJS,doCloseChannel}=this.__closure;const isConnected=props.connected;const wasConnected=(previous===null||previous===void 0?void 0:previous.connected)===true;if(wasConnected&&!isConnected){runOnJS(doCloseChannel)();}}" }; export default function usePanelOpenState(a0, a1, a2, a3) { let c22602_0 = a0; let c22602_1 = a1; const doCloseChannel2 = function doCloseChannel() { return VoicePanelStore.getState().closeChannel(c22602_0); }; const f = () => ({ connected: a3.get() }); f.__closure = { connected: a3 }; f.__workletHash = 8350408810765; f.__initData = __initData; const O = function O({ connected }, a1) { if (a1?.connected === true && !connected) { _ReanimatedRexport.runOnJS(doCloseChannel2)(); } }; O.__closure = { runOnJS: _ReanimatedRexport.runOnJS, doCloseChannel: doCloseChannel2 }; O.__workletHash = 9166012598595; O.__initData = __initData2; useAnimatedReaction(f, O); useEffect(() => { let componentActionClose2; const componentActionOpen2 = function componentActionOpen(a0) { if (c22602_0 === a0.channelId && c22602_1.get() !== VoicePanelModes.PANEL) { a2(VoicePanelModes.PANEL); } }; componentActionClose2 = function componentActionClose() { if (a3.get()) { if (c22602_1.get() !== VoicePanelModes.PIP) { a2(VoicePanelModes.PIP); } } else { VoicePanelStore.getState().closeChannel(c22602_0); } }; ComponentDispatch.subscribe(ComponentActions.VOICE_PANEL_OPEN, componentActionOpen2); ComponentDispatch.subscribe(ComponentActions.VOICE_PANEL_CLOSE, componentActionClose2); return () => { ComponentDispatch.unsubscribe(ComponentActions.VOICE_PANEL_OPEN, componentActionOpen2); ComponentDispatch.unsubscribe(ComponentActions.VOICE_PANEL_CLOSE, componentActionClose2); }; }, [a0, a1, a2, a3]); const [state, setState] = useState(() => RouteManager.getHistory().location.pathname); useEffect(() => { let c28182_0 = RouteManager.addRouteChangeListener((a0) => { if (state !== a0.pathname) { setState(state); const r30 = matchPath(a0.pathname, { path: Routes.CHANNEL(RouteParam.guildId(), RouteParam.channelId()) }); if (extractParamsFromVoiceModalRoute(a0).voiceChannelId == null && !(r30 != null && r30.params.channelId === c22602_0)) { closeVoicePanels(); } } }); return () => { c28182_0(); }; }, [a0, state]); };