import{s as f}from"./index-BKwmLAPt.js";let l=!1;function u(){return l&&window.PaystackPop?Promise.resolve():new Promise((e,r)=>{if(document.querySelector('script[src*="paystack"]')){l=!0,e();return}const i=document.createElement("script");i.src="https://js.paystack.co/v2/inline.js",i.async=!0,i.onload=()=>{l=!0,e()},i.onerror=()=>r(new Error("Failed to load Paystack SDK")),document.head.appendChild(i)})}async function m(e){const{data:r,error:i}=await f.functions.invoke("initialize-importer-onboarding",{body:{importer_profile_id:e.importer_profile_id,email:e.email}});if(i||!(r!=null&&r.access_code))throw new Error((r==null?void 0:r.error)||(i==null?void 0:i.message)||"Init failed");return await u(),new Promise((c,t)=>{new window.PaystackPop().resumeTransaction(r.access_code,{onSuccess:async n=>{var s;const o=n.reference||r.reference,{data:a}=await f.functions.invoke("verify-importer-onboarding",{body:{reference:o}});a!=null&&a.verified?((s=e.onSuccess)==null||s.call(e,o),c(o)):t(new Error("Verification failed"))},onClose:()=>{var n;(n=e.onClose)==null||n.call(e),t(new Error("Payment cancelled"))}})})}async function w(e){const{data:r,error:i}=await f.functions.invoke("initialize-importer-report-purchase",{body:{importer_profile_id:e.importer_profile_id,tier:e.tier,email:e.email}});if(i||!(r!=null&&r.access_code))throw new Error((r==null?void 0:r.error)||(i==null?void 0:i.message)||"Init failed");return await u(),new Promise((c,t)=>{new window.PaystackPop().resumeTransaction(r.access_code,{onSuccess:async n=>{var s;const o=n.reference||r.reference,{data:a}=await f.functions.invoke("verify-importer-report-purchase",{body:{reference:o}});a!=null&&a.verified?((s=e.onSuccess)==null||s.call(e,o),c(o)):t(new Error("Verification failed"))},onClose:()=>{var n;(n=e.onClose)==null||n.call(e),t(new Error("Payment cancelled"))}})})}async function y(e,r){const{data:i}=await f.from("importer_report_requests").select("report_type").eq("supplier_user_id",e).eq("importer_profile_id",r).eq("payment_status","paid");return!i||i.length===0?null:i.some(c=>c.report_type==="full")?"full":"basic"}export{w as a,y as g,m as p};
