// Metro module 9797 (f9798). import { useState, useMemo, useCallback } from "react"; import { CollectiblesItemType } from "../../../_bundle/Module1901"; import { intl, t } from "../../../intl/index.native"; import { useShopProductItems } from "./useShopProductItems"; import { getProfileChangesForUpdateRequest } from "../../user_profile/ProfileUpdateRequestUtils"; import { saveProfileChanges } from "../../user_profile/UserProfileActionCreators"; import { saveProfileAndAccountChanges } from "../../../actions/UserSettingsAccountActionCreators"; export function useHandleUseNow({ product, onSuccess, onError }) { let r56; const [isApplying, setState] = useState(false); const shopProductItems = useShopProductItems(product); const { firstAvatarDecoration, firstProfileEffect, firstNameplate, firstProfileFrame } = shopProductItems; const type = product.type; if (CollectiblesItemType.AVATAR_DECORATION === type) { r56 = intl.string(t.zOA4ax); } else if (CollectiblesItemType.NAMEPLATE === type) { r56 = intl.string(t.gOzMvx); } else if (CollectiblesItemType.PROFILE_FRAME === type) { r56 = intl.string(t.lOF4zR); } else if (CollectiblesItemType.PROFILE_EFFECT === type) { r56 = intl.string(t.SWm2ai); } else { CollectiblesItemType.BUNDLE; r56 = intl.string(t.tf1ZZ4); } const memo = useMemo(() => (function computeCanUseNow(a0) { if (a0.type !== CollectiblesItemType.BUNDLE) { return true; } const set = new Set(); for (const item of a0.items) { if (!set.has(item.type)) { set.add(item.type); continue; } return false; } return true; })(product), [product]); return { handleUseNow: useCallback(async () => { let firstProfileEffect2, firstProfileFrame2, c26539_4; let c26539_5 = 0; let c30145_0, c30145_1; L38: { L27: { try { c30145_0 = void 0; if (!memo) { break L38; } setState(true); const r38 = {}; c30145_0 = r38; c26539_5 = 2; if (firstAvatarDecoration != null) { r38.avatarDecoration = firstAvatarDecoration; } L22: { if (firstProfileEffect == null && firstProfileFrame == null) { if (firstNameplate != null) { c30145_0.nameplate = firstNameplate; } if (Object.keys(c30145_0).length > 0) { await saveProfileAndAccountChanges(c30145_0); break L22; } if (onSuccess != null) { onSuccess(); } c26539_5 = 1; c26539_5 = 0; (0, setState)(false); break L38; } firstProfileEffect2 = firstProfileEffect; if (firstProfileEffect == null) { firstProfileEffect2 = void 0; } firstProfileFrame2 = firstProfileFrame; if (firstProfileFrame == null) { firstProfileFrame2 = void 0; } await saveProfileChanges(getProfileChangesForUpdateRequest({ pendingProfileEffect: firstProfileEffect2, pendingProfileFrame: firstProfileFrame2 })); if (firstNameplate != null) { c30145_0.nameplate = firstNameplate; } if (Object.keys(c30145_0).length > 0) { await saveProfileAndAccountChanges(c30145_0); } } if (onSuccess != null) { onSuccess(); } c26539_5 = 1; c26539_5 = 0; (0, setState)(false); } catch ($e) { const r32 = $e; let r7 = r32; c26539_4 = r32; let r33 = c26539_5; if (r33 !== 0) { while (true) { if (r33 === 1) { try { const r193 = c26539_4; c26539_5 = 0; (0, setState)(false); throw r193; } catch (r191) { r7 = r191; c26539_4 = r191; r33 = c26539_5; if (r33 === 0) { break; } } } else { try { const r179 = c26539_4; c26539_5 = 1; c30145_1 = r179; if (onError != null) { onError(c30145_1); } c26539_5 = 0; (0, setState)(false); break L27; } catch (r176) { r7 = r176; c26539_4 = r176; r33 = c26539_5; if (r33 === 0) { break; } } } } } throw r7; } } return void 0; } }, [memo, firstAvatarDecoration, firstProfileEffect, firstNameplate, firstProfileFrame, onSuccess, r56, onError]), isApplying, canUseNow: memo }; }