// Metro module 12486 (f12487). import { useMemo, useRef, useEffect, useCallback } from "react"; import WalletBalanceStore from "../../billing/stores/WalletBalanceStore"; import PaymentSourceStore from "../../../stores/billing/PaymentSourceStore"; import { ContentDismissActionType } from "../../dismissible_content/DismissibleContentConstants"; import { PaymentSourceTypes } from "../../../_bundle/Module505"; import { useGiftCardsExperimentConfig } from "../../billing/experiments/GiftCardsExperiment"; import { useStateFromStores } from "../../../_bundle/Module589"; import { DismissibleContent } from "../../../_bundle/Module1358"; import { useSelectedDismissibleContent } from "../../dismissible_content/hooks/useSelectedDismissibleContent"; import { fetchPaymentSources, fetchWalletInformation } from "../../billing/actions/BillingActionCreators"; import Dispatcher from "../../../Dispatcher"; import ActionSheetActionCreators from "../../action_sheet/native/ActionSheetActionCreators"; let c8628_9 = "GiftCardMobileConsumptionActionSheet"; let c8628_10 = { Idle: "idle", Opening: "opening", Opened: "opened" }; let Idle = c8628_10.Idle; export function useGiftCardMobileConsumptionHalfsheet() { let c19863_2, c19863_3, ref, callback; const enabled = useGiftCardsExperimentConfig({ location: "useGiftCardMobileConsumptionHalfsheet" }).enabled; const stateFromStores = useStateFromStores([PaymentSourceStore], () => { if (!enabled) { return null; } for (const item of Object.values(PaymentSourceStore.paymentSources)) { if (item.type !== PaymentSourceTypes.TDS_WALLET) { continue; } return item.id; } return null; }, [enabled]); const stateFromStores2 = useStateFromStores([WalletBalanceStore], () => stateFromStores != null ? WalletBalanceStore.getBalance(stateFromStores) : null, [stateFromStores]); const stateFromStores3 = useStateFromStores([WalletBalanceStore], () => stateFromStores != null && WalletBalanceStore.getIsFetching(stateFromStores), [stateFromStores]); const r36 = (enabled ? stateFromStores != null : enabled) && !stateFromStores3 && stateFromStores2 != null && stateFromStores2.amount > 0; c19863_2 = r36; let [r52, current] = useSelectedDismissibleContent(useMemo(() => c19863_2 ? [DismissibleContent.GIFT_CARD_MOBILE_CONSUMPTION_UNAVAILABLE_HALFSHEET] : [], [r36]), void 0, true); c19863_3 = r52; ref = useRef(current); useEffect(() => { ref.current = current; }, [current]); callback = useCallback((a0) => { ref.current(a0); }, []); useEffect(() => { if (enabled) { fetchPaymentSources(); } }, [enabled]); useEffect(() => { if (stateFromStores != null) { fetchWalletInformation(stateFromStores); } }, [stateFromStores]); useEffect(() => { let c27295_0; const handleShow2 = function handleShow(a0) { if (!(c27295_0 || a0.key !== c8628_9)) { Idle = c8628_10.Opened; } }; if (c19863_3 === DismissibleContent.GIFT_CARD_MOBILE_CONSUMPTION_UNAVAILABLE_HALFSHEET && Idle === c8628_10.Idle) { Idle = c8628_10.Opening; c27295_0 = false; Dispatcher.subscribe("SHOW_ACTION_SHEET", handleShow2); const r32 = import("./GiftCardMobileConsumptionActionSheet"); r32.catch(() => { if (!(c27295_0 || Idle !== c8628_10.Opening)) { Idle = c8628_10.Idle; } }); ActionSheetActionCreators.openLazy(r32, c8628_9, { markAsDismissed: callback }, "stack"); return () => { c27295_0 = true; Dispatcher.unsubscribe("SHOW_ACTION_SHEET", handleShow2); if (Idle === c8628_10.Opening) { Idle = c8628_10.Idle; } }; } }, [r52, callback]); useEffect(() => { const handleHide2 = function handleHide(a0) { if (a0.key === c8628_9) { ref.current(ContentDismissActionType.USER_DISMISS); } }; if (c19863_3 === DismissibleContent.GIFT_CARD_MOBILE_CONSUMPTION_UNAVAILABLE_HALFSHEET) { Dispatcher.subscribe("HIDE_ACTION_SHEET", handleHide2); return () => { Dispatcher.unsubscribe("HIDE_ACTION_SHEET", handleHide2); }; } }, [r52]); }