{"version":3,"file":"Library_Subscriptions.CFVaUIdj.mjs","names":[],"sources":["https:/framerusercontent.com/modules/mY71swkORDvZvsIaYcob/OYAsv3JX3XgbihmzYS3w/Library_Subscriptions.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";const useStore=createStore({status:\"idle\",error:\"\"});const VARIANT_MAP={idle:\"Idle\",loading:\"Loading\",disabled:\"Disabled\",error:\"Error\"};const API_BASE=\"https://www.kineticages.co.in\"// change\n;const PLAN_TYPE=\"library_weekly\";const SUCCESS_URL=\"https://www.kinetic-age.in/steps\"// change\n;let isProcessing=false;// const FAIL_URL = \"https://www.kinetic-age.in/services\" // optional\n// const INDIAN_PHONE_REGEX = /^(\\+91)?[6-9]\\d{9}$/\n// function normalizePhone(raw: string) {\n//     const digits = raw.replace(/\\D/g, \"\")\n//     if (digits.length === 10) return digits\n//     if (digits.length === 12 && digits.startsWith(\"91\")) return `+${digits}`\n//     return raw.trim()\n// }\n// function isValidIndianPhone(raw: string) {\n//     return INDIAN_PHONE_REGEX.test(normalizePhone(raw))\n// }\nasync function loadRazorpayScript(){if(window.Razorpay)return true;return await new Promise(resolve=>{const script=document.createElement(\"script\");script.src=\"https://checkout.razorpay.com/v1/checkout.js\";script.onload=()=>resolve(true);script.onerror=()=>resolve(false);document.body.appendChild(script);});}// export function withLibraryPhoneInput(Component): ComponentType {\n//     return (props: any) => {\n//         const [state, setState] = useStore()\n//         const setPhone = (value: string) => {\n//             const phone = value\n//             const invalid = phone.length > 0 && !isValidIndianPhone(phone)\n//             setState({\n//                 phone: value,\n//                 phoneError: invalid\n//                     ? \"Enter a valid Indian mobile number.\"\n//                     : \"\",\n//                 ...(invalid ? {} : { error: \"\" }),\n//             })\n//         }\n//         return (\n//             <Component\n//                 {...props}\n//                 value={state.phone}\n//                 onChange={(e: any) => {\n//                     setPhone(e?.target?.value ?? \"\")\n//                     props.onChange?.(e)\n//                 }}\n//                 onValueChange={(v: string) => {\n//                     setPhone(v)\n//                     props.onValueChange?.(v)\n//                 }}\n//             />\n//         )\n//     }\n// }\nexport function withLibrarySubscribeButton(Component){return props=>{const[state,setState]=useStore();const busy=state.status===\"loading\"||state.status===\"disabled\";const isDisabled=busy// ✅ no phone dependency\n;const variant=state.status===\"loading\"?\"Loading\":isDisabled?\"Disabled\":state.status===\"error\"?\"Error\":\"Idle\";const onPay=async e=>{e?.preventDefault?.();e?.stopPropagation?.();// ✅ HARD LOCK (instant, before state updates)\nif(isProcessing)return;isProcessing=true;setState({status:\"loading\",error:\"\",phoneError:\"\"});let redirected=false;const go=url=>{redirected=true;window.location.assign(url);};try{const res=await fetch(`${API_BASE}/api/client/library-subscription/create-public`,{method:\"POST\",headers:{\"Content-Type\":\"application/json\"},body:JSON.stringify({planType:PLAN_TYPE})});const data=await res.json().catch(()=>({}));if(!res.ok||!data?.success||!data?.subscription_id||!data?.key){throw new Error(data?.message||data?.error||\"Unable to start payment.\");}const sdkLoaded=await loadRazorpayScript();if(!sdkLoaded){if(data?.short_url){setState({status:\"disabled\"});requestAnimationFrame(()=>go(data.short_url));return;}throw new Error(\"Razorpay SDK failed to load.\");}setState({status:\"disabled\"});const rzp=new window.Razorpay({key:data.key,subscription_id:data.subscription_id,name:\"Kinetic Age\",description:data.description||\"Library Subscription\",handler:resp=>{isProcessing=false// ✅ unlock\n;const qs=new URLSearchParams({status:\"success\",razorpay_payment_id:resp?.razorpay_payment_id||\"\",razorpay_subscription_id:resp?.razorpay_subscription_id||data.subscription_id,razorpay_signature:resp?.razorpay_signature||\"\"}).toString();go(`${SUCCESS_URL}?${qs}`);},modal:{ondismiss:()=>{if(!redirected){isProcessing=false// ✅ unlock\n;setState({status:\"error\",error:\"Payment cancelled by user.\"});}}}});rzp.on(\"payment.failed\",resp=>{isProcessing=false// ✅ unlock\n;const reason=resp?.error?.description||resp?.error?.reason||\"payment_failed\";setState({status:\"error\",error:reason});});requestAnimationFrame(()=>rzp.open());}catch(err){isProcessing=false// ✅ unlock on error\n;setState({status:\"error\",error:err?.message||\"Something went wrong. Please try again.\"});}};return /*#__PURE__*/_jsx(Component,{...props,variant:variant,onTap:onPay,onClick:onPay,opacity:busy?.6:props.opacity,style:{...props.style||{},pointerEvents:isDisabled?\"none\":\"auto\"}});};}export function withLibraryErrorText(Component){return props=>{const[state]=useStore();const message=state.phoneError||state.error;return /*#__PURE__*/_jsx(Component,{...props,text:message||props.text,opacity:message?1:0});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withLibrarySubscribeButton\":{\"type\":\"reactHoc\",\"name\":\"withLibrarySubscribeButton\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withLibraryErrorText\":{\"type\":\"reactHoc\",\"name\":\"withLibraryErrorText\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Library_Subscriptions.map"],"mappings":"0KAaA,eAAe,GAAoB,CAAgC,OAA5B,EAAO,SAAgB,GAAY,MAAM,IAAI,QAAQ,GAAS,CAAC,IAAM,EAAO,SAAS,cAAc,SAAS,CAAC,EAAO,IAAI,+CAA+C,EAAO,WAAW,EAAQ,GAAK,CAAC,EAAO,YAAY,EAAQ,GAAM,CAAC,SAAS,KAAK,YAAY,EAAO,EAAG,CA8BpT,SAAgB,EAA2B,EAAU,CAAC,MAAO,IAAO,CAAC,GAAK,CAAC,EAAM,GAAU,GAAU,CAAO,EAAK,EAAM,SAAS,WAAW,EAAM,SAAS,WAAiB,EAAW,EAC/K,EAAQ,EAAM,SAAS,UAAU,UAAU,EAAW,WAAW,EAAM,SAAS,QAAQ,QAAQ,OAAa,EAAM,KAAM,IAAG,CACnI,GADoI,GAAG,kBAAkB,CAAC,GAAG,mBAAmB,CAC7K,EAAa,OAAO,EAAa,GAAK,EAAS,CAAC,OAAO,UAAU,MAAM,GAAG,WAAW,GAAG,CAAC,CAAC,IAAI,EAAW,GAAY,EAAG,GAAK,CAAC,EAAW,GAAK,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