@metrifox/react-sdk 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +8 -8
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -42,4 +42,4 @@
|
|
|
42
42
|
`,children:typeof D.header=="string"?a.jsx(U,{variant:"label8",color:"text-metrifox-black",children:D.header}):D.header},I))})}),a.jsxs("tbody",{children:[c&&[...Array(u)].map((D,I)=>a.jsx(Q8,{columns:e.length},I)),t?.map((D,I)=>a.jsx("tr",{onClick:()=>o?.(D),className:`relative ${o?"cursor-pointer hover:bg-grey-100":"cursor-default"}`,children:e.map((V,O)=>a.jsx("td",{className:`px-3 py-4 text-grey-700 border-grey-100 whitespace-nowrap
|
|
43
43
|
${I===t.length-1?"border-t":"border-y"}
|
|
44
44
|
${O===e.length-1&&f?"sticky z-10 right-0 bg-white relative":""}
|
|
45
|
-
`,children:V.render?V.render(D):L(c6(D,V.key))},O))},I))]})]})}),i==="grid"&&a.jsx("div",{className:`grid ${A}`,children:t?.map((D,I)=>a.jsx("div",{className:o?"cursor-pointer":"cursor-default",onClick:()=>o?.(D),children:l?.renderItem(D)},I))}),n&&a.jsx(J8,{currentPage:n.currentPage,totalPages:n.totalPages,onPageChange:n.onPageChange})]})},Q8=({columns:e})=>a.jsx("tr",{children:Array.from({length:e}).map((t,n)=>a.jsx("td",{className:"px-3 py-4 border-b border-gray-100",children:a.jsx("div",{className:"mt-1 h-4 w-20 rounded-md bg-gray-200"})},n))}),un=({children:e,size:t="medium",background:n="transparent",textColor:r=""})=>{const s=B9[t];return a.jsx(j,{className:`inline-flex items-center ${n} min-w-fit justify-center rounded-full px-2.5 py-1 border gap-x-2 ${s} ${n==="transparent"?"border-grey-300":"border-none"} ${r}`,children:e})},em=async({subscriptionId:e})=>{const{data:t}=await It().get(`/subscriptions/${e}/billing-history`);return t},tm=({subscriptionId:e})=>{const[t,n]=p.useState(null),[r,s]=p.useState(!1),o=async()=>{if(!e){ct.error("Missing subscriptionId");return}s(!0);try{const i=await em({subscriptionId:e});n(i?.data)}catch(i){ct.error(i instanceof Error?i.message:"Failed to load billing history")}finally{s(!1)}};return p.useEffect(()=>{o()},[e]),{billingHistory:t,isLoading:r,refetch:o}},nm=async({invoiceId:e})=>{const{data:t}=await It().get(`/invoices/${e}/view`);return t},e0=({invoiceId:e})=>{const[t,n]=p.useState(null),[r,s]=p.useState(!1),o=async()=>{if(e){s(!0);try{const i=await nm({invoiceId:e});n(i?.data)}catch(i){ct.error(i instanceof Error?i.message:"Failed to load invoice details")}finally{s(!1)}}};return p.useEffect(()=>{o()},[e]),{invoiceDetails:t,isLoading:r,refetch:o}},rm=({subscriptionId:e})=>{const[t,n]=p.useState(!1),[r,s]=p.useState(null),o=p.useRef(null),{billingHistory:i}=tm({subscriptionId:e}),{invoiceDetails:l}=e0({invoiceId:r||""}),c=d=>{d.status===t1.Paid&&d.invoice_id&&(s(d.invoice_id),n(!0))},u=[{header:"Total amount",render:d=>{const{text:f,color:h}=i6(d.status),m=Pt(d.currency);return a.jsx(j,{children:a.jsxs(j,{className:"flex items-center gap-2",children:[a.jsxs(j,{className:"flex items-center",children:[a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:m}),a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:n1(parseFloat(String(d.total_amount)))})]}),a.jsx(un,{size:"small",background:`${h}`,children:a.jsx(U,{variant:"label9",className:"capitalize text-metrifox-white",children:f})})]})})}},{header:"Invoice number",render:d=>a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:d.invoice_number||"-"})},{header:"Source type",render:d=>a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:Dt(d.source_type==="billing_cycle"?"subscription":d.source_type).replace(/_/g," ")})},{header:"Issue date",render:d=>a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:d.issued_date?e1(d.issued_date).format("MMM D, YYYY"):"-"})},{header:"Due date",render:d=>a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:d.due_date?e1(d.due_date).format("MMM D, YYYY"):"-"})},{header:"Amount paid",render:d=>{const f=Pt(d.currency);return a.jsxs(j,{className:"flex items-center",children:[a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:f}),a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:n1(parseFloat(String(d.amount_paid)))})]})}}];return!i||i?.length===0?null:a.jsxs(j,{className:"bg-grey-100 rounded-2xl p-4",children:[a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(j,{className:"p-1.5 bg-grey-200 rounded-lg",children:a.jsx(be,{name:"receipt",size:16,color:"grey-500"})}),a.jsx(U,{variant:"label7",className:"text-metrifox-black font-medium",children:"Billing history"})]}),a.jsx(wr,{columns:u,data:i,onRowClick:c,className:"mt-2"}),t&&r&&a.jsx(Qd,{isOpen:t,onClose:()=>{n(!1),s(null)},contentRef:o,content:a.jsx(i1,{data:l}),modalTitle:"Invoice PDF"})]})},sm=({entitlements:e})=>a.jsx(wr,{columns:[{key:"name",header:"Feature",render:t=>a.jsx(j,{children:a.jsx(W,{variant:"body6",color:"text-grey-700",children:t.name})})},{key:"features_type",header:"Type",render:t=>{const n={[sr.METERED]:"bg-metrifox-blue",[sr.BOOLEAN]:"bg-metrifox-warning"};return a.jsx(j,{children:a.jsx(un,{size:"small",textColor:"text-metrifox-white",background:n[t.feature_type],children:a.jsx(W,{variant:"body6",children:Dt(t.feature_type)})})})}},{key:"quota",header:"Quota Limit",render:t=>{const n=`${t.quota} ${t.name}`,r=s6(),s=t.reset_interval!==Wo.NONE?Dt(r[t.reset_interval]||""):"";return a.jsx(j,{children:a.jsx(W,{variant:"body6",children:t.feature_type===sr.BOOLEAN?"Access granted":`${n} ${s}`})})}}],data:e}),om=({meteredEntitlements:e})=>a.jsx(wr,{columns:[{header:"Feature",render:t=>a.jsx(j,{children:a.jsx(W,{variant:"body6",color:"text-grey-700",children:t.name})})},{key:"featuresUsage",header:"Usage",render:t=>{const n=e?.find(o=>o.name===t.name);if(!n){const o=`${t.used_quantity}/${t.quota===-1?"\u221E":t.quota} ${t.name}`;return a.jsx(W,{variant:"body6",children:o})}const r=n.quota===-1?100:Math.min(n.used_quantity/Number(n.quota)*100,100).toFixed(0),s=n.quota==="unlimited"?"\u221E":`${r}%`;return a.jsx(j,{className:"flex gap-4 items-center",children:a.jsxs(j,{className:"flex-1",children:[a.jsxs(j,{className:"w-full flex items-center gap-x-2",children:[a.jsx(j,{className:"w-full h-[6px] bg-grey-300 rounded",children:a.jsx(j,{className:"h-[6px] bg-metrifox-blue rounded",style:{width:`${r}%`}})}),a.jsx(j,{className:"w-8",children:a.jsx(W,{variant:"body7",className:n.quota===-1?"text-xl":"",children:s})})]}),a.jsxs(W,{variant:"body6",className:"mt-1",children:[n.used_quantity,"/",n.quota===-1?"":n.quota," ",n.reset_interval===Wo.NONE?"":`every ${r6[n.reset_interval]}`]})]})})}}],data:e}),im=({entitlements:e})=>{const t=e.filter(n=>n.feature_type!==sr.BOOLEAN);return a.jsxs(j,{className:"bg-grey-100 rounded-2xl p-4",children:[a.jsx(j,{className:"flex items-center justify-between",children:a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(j,{className:"p-1.5 bg-grey-200 rounded-lg",children:a.jsx(be,{name:"radar",size:16,color:"grey-500"})}),a.jsx(U,{variant:"label7",className:"text-metrifox-black font-medium",children:"Entitlements"})]})}),a.jsx(j,{className:"bg-metrifox-white rounded-2xl p-4 mt-2",children:a.jsxs(us,{children:[a.jsxs(ds,{className:"w-max bg-grey-100 border border-neutral-200 text-grey-500 px-1.5 py-1 rounded-2xl",children:[a.jsx(rr,{className:"w-max data-[selected]:bg-metrifox-primary data-[selected]:border data-[selected]:border-grey-200 outline-none data-[selected]:text-metrifox-white rounded-xl px-8 py-2",children:a.jsx(W,{variant:"body6",children:"Summary"})}),t.length>0&&a.jsx(rr,{className:"w-max data-[selected]:bg-metrifox-primary data-[selected]:border data-[selected]:border-grey-200 outline-none data-[selected]:text-metrifox-white rounded-xl px-8 py-2",children:a.jsx(W,{variant:"body6",children:"Usage"})})]}),a.jsxs(fs,{children:[a.jsx(Sn,{children:a.jsx(sm,{entitlements:e})}),t.length>0&&a.jsx(Sn,{children:a.jsx(om,{meteredEntitlements:t})})]})]})})]})},am=({tenantDetails:e,paymentMethod:t})=>{const{address:n}=Jc(e?.billing_address),r=[{label:"Billed to",value:e?.full_name||"-"},{label:"Billing email",value:e?.billing_email||"-"},{label:"Billing address",value:n||"-"}];return a.jsxs(j,{className:"bg-grey-100 rounded-2xl p-4",children:[a.jsx(j,{className:"flex items-center justify-between",children:a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(j,{className:"p-1.5 bg-grey-200 rounded-lg",children:a.jsx(be,{name:"money",size:18,color:"grey-500"})}),a.jsx(U,{variant:"label7",className:"text-metrifox-black font-medium",children:"Payment"})]})}),a.jsx(j,{className:"bg-grey-200 rounded-t-2xl px-3 pt-2.5 pb-4 mt-2",children:a.jsx(U,{variant:"label8",className:"text-grey-500 font-medium",children:"Details"})}),a.jsxs(j,{className:"bg-metrifox-white grid grid-cols-3 gap-8 justify-between rounded-2xl p-4 -mt-2.5",children:[r?.map((s,o)=>a.jsxs(j,{children:[a.jsx(U,{variant:"label8",className:"text-grey-500",children:s?.label}),a.jsx(U,{variant:"label7",className:"text-grey-600 font-medium mt-2",children:s?.value||"-"})]},o)),a.jsxs(j,{children:[a.jsx(U,{variant:"label8",className:"text-grey-500",children:"Payment method"}),t?a.jsxs(j,{className:"flex items-center gap-x-2 mt-2",children:[a.jsxs(W,{variant:"body6",color:"text-grey-600 font-medium",children:[Dt(t?.brand)," ",t?.display_name," "]}),a.jsxs(W,{variant:"body6",className:"text-neutral-500 font-light",children:["Expires ",t?.exp_month,"/",t?.exp_year]})]}):a.jsx("span",{children:"-"})]})]})]})},lm=async({offeringKey:e,billingInterval:t,customerKey:n})=>{const{data:r}=await It().get(`/products/offerings/generate-checkout-url?offering_key=${e}&billing_interval=${t}&customer_key=${n}`);return r},cm=({billingInterval:e})=>{const[t,n]=p.useState(null),[r,s]=p.useState(!1),{customerKey:o}=en();return{checkoutUrl:t,isLoading:r,generateCheckoutUrl:async i=>{if(!(!i||!e||!o)){s(!0);try{const l=await lm({offeringKey:i,billingInterval:e,customerKey:o});n(l?.data?.checkout_url)}catch(l){ct.error(l instanceof Error?l.message:"Failed to load checkout url")}finally{s(!1)}}}}},um=async({product_key:e})=>{const{data:t}=await It().get(`/product_catalogues/products/published-plans?product_key=${e}`);return t},dm=({product_key:e})=>{const[t,n]=p.useState(null),[r,s]=p.useState(!1),o=async()=>{if(!e){ct.error("Missing product_key");return}s(!0);try{const i=await um({product_key:e});n(i?.data)}catch(i){ct.error(i instanceof Error?i.message:"Failed to load product plans")}finally{s(!1)}};return p.useEffect(()=>{o()},[e]),{productPlans:t,isLoading:r,refetch:o}},fm=e=>{const t=p6(e||[]),[n,r]=p.useState(""),s=[...t.includes(pe.DAILY)?[pe.DAILY]:[],...t.includes(pe.WEEKLY)?[pe.WEEKLY]:[],...t.includes(pe.MONTHLY)?[pe.MONTHLY]:[],...t.includes(pe.QUARTERLY)?[pe.QUARTERLY]:[],...t.includes(pe.BIANNUALLY)?[pe.BIANNUALLY]:[],...t.includes(pe.YEARLY)?[pe.YEARLY]:[]];return p.useEffect(()=>{!n&&s[0]&&r(s[0])},[s,n]),{intervals:s,selectedInterval:n,setSelectedInterval:r}},t0=({selectedInterval:e,publishedOnly:t=!1})=>{const{plans:n}=en(),r=c=>{if(c)return t?c?.is_visible?c:void 0:c},s=n?.some(c=>!!r(c)?.description),o=n?.some(c=>!!r(c)?.trial_duration_value),i=n?.some(c=>{const u=r(c);return u?u.price_options?.some(d=>d.price?.billing_interval===e)||u.is_free||u.is_custom:!1}),l=n?.some(c=>{const u=r(c);return u?[u.credit_attachment_price_options,u.entitlement_price_options].some(d=>Array.isArray(d)&&d.some(f=>f.price?.billing_interval===e)):!1});return{shouldShowDescription:s,shouldShowFreeTrial:o,shouldShowFixedPrice:i,shouldShowDynamicPrices:l}},n0=({entitlements:e,baseEntitlementsPlanName:t,credits:n})=>{const r=Zo(e).filter(s=>s?.is_visible);return a.jsxs(j,{children:[a.jsx(U,{variant:"label7",className:"text-metrifox-primary mb-3",as:"p",children:t?`Everything in ${t} plus:`:"\xA0"}),a.jsxs("ul",{className:"flex flex-col gap-y-3",children:[n?.map((s,o)=>a.jsxs("li",{className:"flex items-center gap-[10px]",children:[a.jsx(be,{name:"check",color:"green-600",size:16}),a.jsx(W,{variant:"body5",children:s.included_usage_text})]},o)),r?.map((s,o)=>a.jsxs("li",{className:"flex items-center gap-[10px]",children:[a.jsx(be,{name:"check",color:"green-600",size:16}),a.jsx(W,{variant:"body5",children:s.display_text})]},o))]})]})},hm=e=>{const t=e?.price?.billing_interval,n=e?.price.tiers,r=e?.price.currency,s=e?.price?.invoice_timing,o=Pt(r),i=x=>{const v=e?.price?.owner,b=v?.included_usage||0,C=x?.find(D=>D.first_unit===b);if(!C)return{price:null,label:null};const{unit_price:y,package_price:k,package_size:w,pricing_model:L,flat_fee:A}=C;return A?{price:A.toFixed(2),label:""}:{per_unit:{price:y?.toFixed(2),label:`per. ${v?.feature?.unit_singular||v?.credit_unit_singular}`},per_package:{price:k?.toFixed(2),label:`for ${w} ${v?.feature?.unit_plural}`}}[L]??{price:null,label:null}},{price:l,label:c}=i(n),u=e?.price?.is_custom&&e?.price?.billing_interval_value>1?`every ${e?.price?.billing_interval_value} ${d6[t]}`:t,d=[pe.DAILY,pe.WEEKLY],f={[pe.DAILY]:"day",[pe.WEEKLY]:"week"},h=t,m=d.includes(h)?f[h]:"month",g=(u6(t,e?.price?.billing_interval_value)*(e?.price?.price??0)).toFixed(2);return{amount:(e?.price?.price??0).toFixed(2),billedText:u,intervalText:m,billingAmount:g,tierPrice:l,tierLabel:c,currencySymbol:o,invoiceTiming:s,intervalValue:e?.price?.billing_interval_value}},pm=({dynamicPrices:e,showMoreCard:t,showMore:n})=>{const[r,s]=p.useState("");return a.jsxs(j,{className:t?"":"h-[75px] flex flex-col",children:[(t?e:e.slice(0,2)).map(o=>{const i=o?.price?.name||o?.price?.owner?.feature?.name||o?.price?.owner?.name,l=f6(o?.price.tiers,o.price.currency),{price:c,label:u,currencySymbol:d}=h6(o),f=l?.length===1;return t?a.jsxs(j,{className:"p-2 border-b border-grey-200 last:border-0",children:[a.jsxs(j,{className:"flex justify-between items-center",children:[a.jsx(U,{variant:"label7",className:"text-grey-600 mb-1",children:i}),f&&a.jsxs(j,{className:"flex items-center cursor-pointer",children:[a.jsxs(U,{variant:"label7",color:"text-metrifox-black",children:[d,c]}),u&&a.jsxs(W,{variant:"body5",color:"text-grey-500",className:"mr-1",children:["/",u]})]})]}),!f&&a.jsxs(j,{className:"flex justify-between items-center",children:[a.jsx(W,{variant:"body5",className:"text-grey-700",children:"Starts at"}),a.jsxs(j,{className:"flex items-center cursor-pointer",onClick:h=>{h.stopPropagation(),s(r===o.id?"":o.id)},children:[a.jsxs(U,{variant:"label7",color:"text-metrifox-black",children:[d,c]}),a.jsxs(W,{variant:"body5",color:"text-grey-500",className:"mr-1",children:["/",u]}),l.length>1&&a.jsx(be,{name:r===o.id?"arrow-up-light":"arrow-down-linear",size:16,color:"grey-400"})]})]}),r===o.id&&l.length>1&&a.jsx(j,{className:"bg-grey-200 p-2 mt-1 rounded-lg",children:a.jsx(j,{className:"flex flex-col gap-y",children:l?.map(h=>a.jsxs(j,{className:"flex justify-between items-center",children:[a.jsx(W,{variant:"body7",color:"text-grey-700",children:h?.label}),a.jsxs(W,{variant:"body7",color:"text-grey-700",children:[h?.price,h?.package?`/${h?.package} ${u}`:""]})]},h?.label))})})]},o.id):a.jsx(j,{className:"mt-1",children:a.jsxs(j,{className:"flex items-center gap-x-1 flex-wrap",children:[a.jsx(U,{variant:"label8",className:"text-grey-600 whitespace-nowrap",children:i}),a.jsx(W,{variant:"body7",children:f?"at":"from"}),a.jsxs(j,{className:"flex items-center",children:[a.jsxs(U,{variant:"label7",color:"text-metrifox-black",children:[d,c]}),u&&a.jsxs(W,{variant:"body7",color:"text-grey-500",children:["/",u]})]})]})},o.id)}),!t&&!!e?.length&&a.jsx(j,{className:"flex items-center justify-center mt-auto mb-2",children:a.jsx(Ps,{onClick:o=>{n(),o?.stopPropagation()},className:"mt-2",children:a.jsx(W,{variant:"body8",className:"text-metrifox-blue underline",children:"Explore all priced features"})})})]})},mm=({interval:e,priceOptions:t,entitlementPriceOptions:n,creditAttachmentPriceOptions:r,isPricePage:s,trialTag:o,showMoreCard:i,isFree:l,isCustom:c,showMore:u})=>{const{shouldShowFixedPrice:d,shouldShowFreeTrial:f,shouldShowDynamicPrices:h}=t0({selectedInterval:e,publishedOnly:s}),m=r1(e,t),g=s1(e,n),x=[...s1(e,r)||[],...g||[]],{amount:v,billedText:b,billingAmount:C,intervalText:y,currencySymbol:k,intervalValue:w}=hm(m),L=me(v).split("."),A=L?L[0]:"0",D=L&&L.length>1?L[1]:"00";return a.jsxs(j,{className:i?"bg-grey-100 border border-grey-200 rounded-2xl p-2 mb-3":"w-full",children:[d&&a.jsxs(j,{className:i?"":"h-[94px]",children:[l&&a.jsx(j,{className:"p-2 border-b border-grey-200 last:border-0",children:a.jsx(j,{className:"flex items-center justify-between pt-[21px] pb-4",children:a.jsx(U,{variant:"label3",children:"Free"})})}),c&&a.jsx(j,{className:"p-2 border-b border-grey-200 last:border-0",children:a.jsx(j,{className:"flex items-center justify-between pt-[21px] pb-4",children:a.jsx(U,{variant:"label4",children:"Custom"})})}),!m&&!l&&!c&&a.jsx(j,{className:"p-2 border-b border-grey-200 last:border-0",children:a.jsx(j,{className:"flex items-center justify-between pt-[21px] pb-4",children:a.jsx(U,{variant:"label4",children:"No fixed price"})})}),m&&a.jsxs(j,{className:"p-2 border-b border-grey-200 last:border-0",children:[a.jsx(j,{className:"flex items-center justify-between",children:a.jsx(U,{variant:"label7",className:"text-grey-600 mb-2",children:"Fixed price"})}),a.jsxs(j,{className:"flex items-end",children:[a.jsxs(U,{variant:"label3",className:"text-[var(--price-color,#0F0F0F)]",children:[k,A]}),a.jsxs(U,{variant:"label6",className:"mb-[5px] text-metrifox-black",children:[".",D]}),a.jsxs(W,{variant:"body4",className:"mb-[5px] text-grey-500",children:["/",y]})]}),(e!==pe.MONTHLY||w!==1)&&a.jsxs(W,{className:"-mt-2",variant:"body5",children:["Billed",a.jsxs(U,{as:"span",variant:"label7",className:"inline-block",children:[k,me(C)," ",b.toLowerCase()]})]})]})]}),f&&!s&&a.jsx(j,{className:"h-6",children:o}),h&&a.jsx(pm,{dynamicPrices:x,showMoreCard:!!i,showMore:u})]})},gm=({description:e,entitlements:t,baseEntitlementsPlanName:n,priceContent:r})=>a.jsxs(j,{children:[a.jsx(U,{variant:"label7",className:"mb-2",children:"Description"}),a.jsx(W,{variant:"body5",className:"mb-4",children:e}),r,a.jsx(n0,{entitlements:t,baseEntitlementsPlanName:n})]});function xm(e){p.useEffect(function(){typeof e=="function"&&e()},[])}var ym="Expected a function",r0=0/0,vm="[object Symbol]",bm=/^\s+|\s+$/g,Cm=/^[-+]0x[0-9a-f]+$/i,wm=/^0b[01]+$/i,km=/^0o[0-7]+$/i,jm=parseInt,Lm=typeof Ot=="object"&&Ot&&Ot.Object===Object&&Ot,Em=typeof self=="object"&&self&&self.Object===Object&&self,Mm=Lm||Em||Function("return this")(),Sm=Object.prototype,Tm=Sm.toString,Dm=Math.max,Pm=Math.min,la=function(){return Mm.Date.now()};function Am(e,t,n){var r,s,o,i,l,c,u=0,d=!1,f=!1,h=!0;if(typeof e!="function")throw new TypeError(ym);t=s0(t)||0,ca(n)&&(d=!!n.leading,f="maxWait"in n,o=f?Dm(s0(n.maxWait)||0,t):o,h="trailing"in n?!!n.trailing:h);function m(L){var A=r,D=s;return r=s=void 0,u=L,i=e.apply(D,A),i}function g(L){return u=L,l=setTimeout(b,t),d?m(L):i}function x(L){var A=L-c,D=L-u,I=t-A;return f?Pm(I,o-D):I}function v(L){var A=L-c,D=L-u;return c===void 0||A>=t||A<0||f&&D>=o}function b(){var L=la();if(v(L))return C(L);l=setTimeout(b,x(L))}function C(L){return l=void 0,h&&r?m(L):(r=s=void 0,i)}function y(){l!==void 0&&clearTimeout(l),u=0,r=c=s=l=void 0}function k(){return l===void 0?i:C(la())}function w(){var L=la(),A=v(L);if(r=arguments,s=this,c=L,A){if(l===void 0)return g(c);if(f)return l=setTimeout(b,t),m(c)}return l===void 0&&(l=setTimeout(b,t)),i}return w.cancel=y,w.flush=k,w}function ca(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function Rm(e){return!!e&&typeof e=="object"}function Nm(e){return typeof e=="symbol"||Rm(e)&&Tm.call(e)==vm}function s0(e){if(typeof e=="number")return e;if(Nm(e))return r0;if(ca(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=ca(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(bm,"");var n=wm.test(e);return n||km.test(e)?jm(e.slice(2),n?2:8):Cm.test(e)?r0:+e}var Fm=Am,Vm=Mr(Fm);function $m(e,t,n){var r=p.useCallback(function(o){return Vm(o,t,n)},[t,n]),s=p.useRef(r(e));return p.useEffect(function(){s.current=r(e)},[e,r]),s.current}function Om(e,t){var n=p.useRef(!1);typeof t<"u"&&!Array.isArray(t)?t=[t]:Array.isArray(t)&&t.length===0&&console.warn("Using [] as the second argument makes useDidUpdate a noop. The second argument should either be `undefined` or an array of length greater than 0."),p.useEffect(function(){n.current?e():n.current=!0},t),p.useEffect(function(){return function(){n.current=!1}},[])}var o0=typeof window>"u"?p.useEffect:p.useLayoutEffect;function _m(e,t){t===void 0&&(t=!1);var n=t?o0:p.useEffect,r=p.useRef(e);return n(function(){r.current=e}),r}function Bm(e){var t=_m(e);function n(){for(var r=[],s=0;s<arguments.length;s++)r[s]=arguments[s];typeof t.current=="function"&&t.current.apply(t,r)}return n}var Im=process.env.NODE_ENV!=="production",i0=function(){};if(Im){var Hm=function(e){var t="Warning: ".concat(e);typeof console<"u"&&console.error(t);try{throw new Error(t)}catch{}};i0=function(e,t){e||Hm(t)}}function Wm(e,t,n,r,s,o){r===void 0&&(r={}),s===void 0&&(s=!0),o===void 0&&(o=!1);var i=Bm(n),l=o?o0:p.useEffect;l(function(){return i0(typeof e<"u","[useGlobalObjectEventListener]: Cannot attach event handlers to undefined."),typeof e<"u"&&s?(e.addEventListener(t,i,r),function(){e.removeEventListener(t,i,r)}):function(){}},[t,r])}function Zm(e,t,n){t===void 0&&(t=!0),n===void 0&&(n=!1),typeof window<"u"?Wm(window,"resize",e,{passive:!0},t,n):console.warn("useOnWindowResize can't attach an event listener as window is undefined.")}var a0="...",Um=0,As=function(){return"__clamp_text_key__".concat(Um++)};function zm(e){var t=e.text,n=e.ellipsis,r=n===void 0?a0:n,s=e.lines,o=s===void 0?3:s,i=e.expanded,l=i===void 0?!1:i,c=e.debounceTime,u=c===void 0?300:c,d=e.charWidth,f=d===void 0?1.2:d,h=p.useState(function(){return{noClamp:!1,clampedText:".",key:As()}}),m=h[0],g=m.noClamp,x=m.clampedText,v=m.key,b=h[1],C=p.useRef(),y=p.useRef(0),k=p.useCallback(function(L){var A=L.lineHeight,D=L.originalText,I=L.expanded,V=L.ellipsis,O=L.lines,z=L.charWidth,Z=C.current;if(!Z)return;if(!D||I){b({noClamp:!0,clampedText:D,key:As()});return}var P=A*O+1,F=0;typeof V=="string"?F=V===a0?5:Math.ceil(V.length*z):typeof V=="number"&&(F=Math.ceil(V*z));var E=0,T=0,M=D.length;if(!Z.clientHeight)return;function $(){var H,Y=(H=Z?.clientHeight)!==null&&H!==void 0?H:1;Y<=P?E=T+1:M=T-1}for(;E<=M;){if(T=Math.floor((E+M)/2),Z.innerText=D.slice(0,T),T===D.length){b({clampedText:D,noClamp:!0,key:As()});return}$()}var N=D.slice(0,Math.max(T-F,0)).trim()+(typeof V=="string"?V:"");Z.innerText=N,b({noClamp:!1,clampedText:N,key:As()})},[]),w=$m(k,u);return Zm(function(){return w({lineHeight:y.current,originalText:t,expanded:l,ellipsis:r,lines:o,charWidth:f})}),xm(function(){var L,A;if(t&&!y.current){var D=((A=(L=C.current)===null||L===void 0?void 0:L.clientHeight)!==null&&A!==void 0?A:1)+1;y.current=D,k({lineHeight:D,originalText:t,expanded:l,ellipsis:r,lines:o,charWidth:f})}}),Om(function(){k({lineHeight:y.current,originalText:t,expanded:l,ellipsis:r,lines:o,charWidth:f})},[l,t,f,r,o]),[C,{noClamp:g,clampedText:x,key:v}]}const Km=({description:e,showDetails:t})=>{const[n,{noClamp:r,clampedText:s,key:o}]=zm({text:e,ellipsis:12.5,lines:3});return e?a.jsx(W,{variant:"body6",children:a.jsxs("span",{ref:n,className:"w-full inline-block",children:[s,!r&&a.jsxs(a.Fragment,{children:["...",a.jsx(Ps,{onClick:i=>{t(),i?.stopPropagation()},className:"!inline",children:a.jsx(W,{variant:"body6",className:"text-metrifox-blue border-b border-metrifox-blue",children:"See more"})})]})]},o)}):null},Ym=({selectedInterval:e,intervals:t,setSelectedInterval:n})=>a.jsx(j,{className:"rounded-2xl p-1 flex bg-[var(--card-background-color,#F5F5F5)]",children:t.map(r=>{const s=e===r;return a.jsx(j,{className:`py-[4px] px-3 rounded-[12px] cursor-pointer ${s?"bg-[var(--active-tab-color,#3D3D3D)]":""}`,onClick:()=>n(r),children:a.jsx(W,{variant:"body4",color:s?"text-[var(--button-text,#FFFFFF)]":"text-[var(--tab-color,#A1A1AA)]",children:Dt(r)})},r)})}),Gm=({planName:e,productKey:t})=>{const[n,r]=p.useState(!1),[s,o]=p.useState(null),{setPlans:i}=en(),{productPlans:l}=dm({product_key:t}),{intervals:c,selectedInterval:u,setSelectedInterval:d}=fm(l||[]),{checkoutUrl:f,generateCheckoutUrl:h,isLoading:m}=cm({billingInterval:u}),{shouldShowDescription:g}=t0({selectedInterval:u,publishedOnly:!0});f&&window.open(f,"_blank","noopener,noreferrer");const x=p.useMemo(()=>{if(!l)return[];const y=l.findIndex(k=>k.name.toLowerCase()===e?.toLowerCase());return l.filter((k,w)=>k?.is_visible||w===y)},[l,e]),v=p.useMemo(()=>x.findIndex(y=>y.name.toLowerCase()===e?.toLowerCase()),[x,e]),b=y=>{o(y),r(!0)},C=()=>{r(!1),o(null)};return p.useEffect(()=>{x&&x.length>0&&i(x)},[x,i]),!x||x?.length===0?null:a.jsx(a.Fragment,{children:a.jsxs(j,{className:"bg-grey-100 rounded-2xl p-4",children:[a.jsx(j,{className:"flex items-center justify-between",children:a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(j,{className:"p-1.5 bg-grey-200 rounded-lg",children:a.jsx(be,{name:"subtitle",size:18,color:"grey-500"})}),a.jsx(U,{variant:"label7",className:"text-metrifox-black font-medium",children:"Plan"})]})}),a.jsxs(j,{className:"bg-metrifox-white rounded-2xl mt-2 p-4",children:[c.length>0&&a.jsx(j,{className:"flex justify-center mb-2.5",children:a.jsx(Ym,{selectedInterval:u,intervals:c,setSelectedInterval:d})}),a.jsx(j,{className:"flex gap-x-2 overflow-x-auto whitespace-nowrap px-6 py-4 -mx-4 [&::-webkit-scrollbar]:h-2 [&::-webkit-scrollbar-track]:bg-grey-100 [&::-webkit-scrollbar-thumb]:bg-grey-300 [&::-webkit-scrollbar-thumb]:rounded-full",children:x?.map((y,k)=>{const w=k===v,{name:L,entitlements:A,base_entitlement_plan_name:D,is_free:I,is_custom:V,description:O,price_options:z,entitlement_price_options:Z,credit_attachment_price_options:P,credit_attachments:F,trial_duration_unit:E,trial_duration_value:T}=y,M=r1(u,[...z,...Z]),$=E&&T,N=T===1?E:`${E}s`;if(!M&&!I&&!V)return null;const H=Zo([...A]).filter(J=>J?.is_visible),{featureOrderMap:Y}=g6(x||[]),_=m6(H,Y),R=F?.filter(J=>J.included_usage),B=J=>a.jsx(mm,{trialTag:$&&a.jsx(un,{background:"bg-grey-300",textColor:"text-metrifox-black",size:"small",children:a.jsx(W,{variant:"body6",children:`${T} ${N} Free trial`})}),interval:u,priceOptions:z,entitlementPriceOptions:Z,creditAttachmentPriceOptions:P,isPricePage:!1,showMoreCard:!!J,showMore:()=>b(y),isFree:I,isCustom:V});return a.jsxs(p.Fragment,{children:[a.jsxs(j,{className:"w-[35%] mb-8 flex-none text-wrap cursor-pointer",children:[a.jsx(j,{className:`${w?"bg-metrifox-primary":"bg-grey-200"} rounded-t-2xl px-3 pt-2.5 pb-4 mt-2"`,children:a.jsx(U,{variant:"label8",className:`${w?"text-metrifox-white":"text-grey-500"} font-medium`,children:y.name})}),a.jsx(j,{className:`${w?"border-b border-x":"border"} border-grey-200 h-full flex flex-col justify-between rounded-2xl p-2 -mt-2.5 transition-all duration-200 ${w?"bg-yellow-gradient":"bg-metrifox-white"}`,children:a.jsxs(j,{className:"w-full min-h-[25rem]",children:[g&&a.jsx(j,{className:"h-[51px] mt-1",children:a.jsx(Km,{description:O,showDetails:()=>b(y)})}),B(),!w&&a.jsx(Cr,{onClick:()=>h(y?.offering_key),className:"w-full bg-metrifox-primary hover:bg-metrifox-primary-dark mb-4",disabled:w||m,children:a.jsx(U,{variant:"label8",className:"text-metrifox-white",children:k>v?"Upgrade":"Downgrade"})}),a.jsx(j,{className:"px-2 mt-3",children:a.jsx(n0,{entitlements:_,credits:R,baseEntitlementsPlanName:D})})]})})]}),a.jsx(Ts,{isOpen:n&&s?.offering_key===y.offering_key,onClose:C,title:L,size:"small",bottomContent:a.jsx(j,{className:"flex justify-end gap-x-2",children:a.jsx(aa,{onClick:C,children:"Close"})}),children:s&&a.jsx(gm,{baseEntitlementsPlanName:s.base_entitlement_plan_name,description:s.description,entitlements:s.entitlements,priceContent:B(!0)})})]},k)})})]})]})})},qm=()=>a.jsx(j,{className:"flex justify-center items-center gap-x-2 h-full",children:a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(W,{variant:"body7",color:"text-metrifox-black",children:"Powered by"}),a.jsx(o1,{height:30,width:100})]})}),Xm=({trigger:e,children:t,className:n="bg-metrifox-white rounded-[10px] shadow-md",shouldMatchWidth:r,anchorGap:s=4,anchorTo:o="bottom start",anchorOffset:i=0})=>{const l=p.useRef(null),[c,u]=p.useState(null);p.useLayoutEffect(()=>{l.current&&u(l.current.offsetWidth)},[]);const d=r&&c?c:"auto";return a.jsxs(p9,{className:"relative",children:[a.jsx(Zc,{className:"outline-none w-full cursor-pointer",ref:l,as:"span",children:e}),a.jsx(Uc,{anchor:{gap:s,to:o,offset:i},className:`${n} absolute z-10 transition duration-200 ease-out data-[closed]:scale-95 data-[closed]:opacity-0`,style:{width:d},transition:!0,children:({close:f})=>typeof t=="function"?a.jsx(a.Fragment,{children:t(f)}):a.jsx(a.Fragment,{children:t})})]})},Jm=async({subscriptionId:e})=>{const{data:t}=await It().post(`/subscriptions/${e}/schedule-cancellation`);return t},Qm=({subscriptionId:e,isOpen:t,onClose:n})=>{const[r,s]=p.useState(!1),{customerRefetch:o}=en();return a.jsxs(Ts,{size:"small",title:"Cancel subscription?",isOpen:t,onClose:n,bottomContent:a.jsxs(j,{className:"flex justify-end gap-x-2",children:[a.jsx(ia,{className:"text-primary-500",onClick:n,size:"x-small",children:"Cancel"}),a.jsx(Cr,{className:"!bg-metrifox-danger text-metrifox-white",onClick:async()=>{s(!0);try{const i=await Jm({subscriptionId:e});ct.success(i.message),s(!1),n(),o()}catch(i){ct.error(i instanceof Error?i.message:"An error ocurred"),s(!1)}},size:"x-small",isLoading:r,disabled:r,children:"Confirm"})]}),showCloseButton:!1,className:"bg-metrifox-white",children:[a.jsx(U,{variant:"label7",children:"Are you sure you want to proceed?"}),a.jsx(W,{variant:"body4",color:"text-metrifox-black",className:"mt-5",children:"This subscription is scheduled to be canceled at the end of the billing cycle"})]})},eg=async({subscriptionId:e})=>{const{data:t}=await It().post(`/subscriptions/${e}/revert-cancellation`);return t},tg=({subscriptionId:e,isOpen:t,onClose:n})=>{const[r,s]=p.useState(!1),{customerRefetch:o}=en();return a.jsxs(Ts,{size:"small",title:"Undo cancellation?",isOpen:t,onClose:n,bottomContent:a.jsxs(j,{className:"flex justify-end gap-x-2",children:[a.jsx(ia,{className:"text-primary-500",onClick:n,size:"x-small",children:"Cancel"}),a.jsx(Cr,{className:"text-metrifox-white",onClick:async()=>{s(!0);try{const i=await eg({subscriptionId:e});ct.success(i.message),s(!1),n(),o()}catch(i){ct.error(i instanceof Error?i.message:"An error ocurred"),s(!1)}},size:"x-small",isLoading:r,disabled:r,children:"Next"})]}),showCloseButton:!1,className:"bg-metrifox-white",children:[a.jsx(W,{variant:"body4",color:"text-metrifox-black",children:"Keep subscription active?"}),a.jsx(W,{variant:"body4",color:"text-metrifox-black",className:"mt-5",children:"The subscription would keep going and renew as usual."})]})},ng=({subscription:e})=>{const[t,n]=p.useState(!1),[r,s]=p.useState(!1);return a.jsxs(j,{children:[e?.ends_at?a.jsx(j,{onClick:()=>s(!0),className:"cursor-pointer",children:a.jsx(W,{variant:"body6",className:"text-metrifox-danger",children:"Undo cancellation"})}):a.jsx(j,{onClick:()=>n(!0),className:"cursor-pointer",children:a.jsx(W,{variant:"body6",className:"text-metrifox-danger",children:"Cancel subscription"})}),a.jsx(Qm,{subscriptionId:e?.id,isOpen:t,onClose:()=>n(!1)}),a.jsx(tg,{subscriptionId:e?.id,isOpen:r,onClose:()=>s(!1)})]})},rg=({subscriptionLineItems:e,handleUpdateQuantity:t,canUpdateQuantities:n})=>{const[r,s]=p.useState(!1),o=e[0];return a.jsxs(j,{children:[a.jsxs(j,{className:"bg-grey-200 rounded-t-2xl px-3 pt-2.5 pb-4 mt-4 flex items-center justify-between cursor-pointer",onClick:()=>s(!r),children:[a.jsx(U,{variant:"label8",className:"text-grey-500 font-medium",children:"Items"}),a.jsxs(j,{className:"flex gap-x-2",children:[n&&a.jsx(Ps,{className:"!text-metrifox-blue underline cursor-pointer",onClick:i=>{i?.stopPropagation(),t()},children:"Update items"}),a.jsx("span",{className:`transform transition-transform duration-300 ${r?"rotate-180":"rotate-0"}`,children:a.jsx(be,{name:"arrow-down",size:14,color:"grey-500"})})]})]}),a.jsx(j,{className:"bg-metrifox-white rounded-2xl p-2 -mt-2.5 space-y-2",children:r?a.jsx(a.Fragment,{children:e?.map((i,l)=>a.jsx(j,{className:"bg-grey-50 border border-grey-200 rounded-lg p-2 flex justify-between",children:a.jsxs(j,{className:"w-full flex items-center justify-between",children:[a.jsx(j,{className:"flex items-center gap-4",children:a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(U,{variant:"label8",className:"text-grey-800 font-medium",children:Dt(i?.name)}),i?.is_addon&&a.jsx(un,{size:"small",background:"bg-grey-300",textColor:"text-metrifox-black",children:"Add-on"})]})}),a.jsxs(W,{variant:"body6",className:"text-grey-800 font-medium",children:[Pt(i?.currency_code),(i?.unit_price||i?.total_amount)?.toFixed(2)]})]})},l))}):a.jsxs(j,{className:"bg-grey-100 rounded-lg p-2 flex items-center justify-between cursor-pointer",children:[a.jsxs(U,{variant:"label8",className:"text-grey-800 font-medium",children:[o?.name," ",a.jsx("span",{children:"\u2022"})," ",e.length," item(s)"]}),a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsxs(W,{variant:"body6",className:"text-grey-800 font-medium",children:[Pt(o?.currency_code),(o?.unit_price||o?.total_amount)?.toFixed(2)]}),a.jsxs(W,{variant:"body6",className:"text-metrifox-blue",children:["+ ",e.length-1," prices(s)"]})]})]})})]})},sg=({subscription:e,tenantDetails:t})=>{const n=e?.status,{text:r,color:s}=l6(n),{customerKey:o}=en(),i=u=>u?Io(u.split("T")[0]):"nil",l=[{label:"Current plan",value:`${e?.plan_name||"-"}`},{label:"Status",value:a.jsx(un,{size:"small",background:s,textColor:"text-metrifox-white",children:Dt(r)||"-"})},{label:"Start date",value:i(e?.starts_at)},...n===At.IN_TRIAL?[{label:"Trial period",value:e?.starts_at&&e?.trial_end_date?a.jsxs(U,{variant:"label7",className:"text-grey-600",children:[i(e?.starts_at)," -"," ",i(e?.trial_end_date)]}):"-"}]:[],...n===At.ACTIVE?[{label:"Renewal date",value:e?.renews_at?i(e?.renews_at):"-"}]:[],...n===At.ACTIVE?[{label:"Current billing period",value:e?.current_billing_period_start&&e?.current_billing_period_end?a.jsxs(j,{children:[a.jsxs(U,{variant:"label7",className:"text-grey-600",children:[i(e.current_billing_period_start)," -"," ",i(e.current_billing_period_end)]}),a.jsx(un,{size:"small",background:"bg-grey-200",textColor:"text-metrifox-black",children:"Auto-renew"})]}):"-"}]:[],...n===At.ACTIVE?[{label:"Next billing date",value:e?.renews_at?i(e?.renews_at):"-"}]:[],...n===At.ACTIVE?[{label:"Next estimated bill",value:e?.next_billing_amount?a.jsx(j,{children:a.jsxs(U,{variant:"label7",className:"text-grey-600",children:[Pt(e.currency_code),e.next_billing_amount]})}):"-"}]:[]],c=()=>{const u=`${window.location.origin}/${t.tenant_checkout_username}/${e.offering_key}/subscriptions/${e.id}?customer=${o}`;window.open(u,"_blank","noopener,noreferrer")};return a.jsx(j,{children:a.jsxs(j,{className:"bg-grey-100 rounded-2xl p-4",children:[a.jsxs(j,{className:"flex items-center justify-between",children:[a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(j,{className:"p-1.5 bg-grey-200 rounded-lg",children:a.jsx(be,{name:"money",size:18,color:"grey-500"})}),a.jsx(U,{variant:"label7",className:"text-metrifox-black font-medium",children:"Subscription"})]}),a.jsx(Xm,{trigger:a.jsx(be,{name:"more",size:20,color:"grey-500"}),anchorTo:"bottom end",className:"bg-metrifox-white rounded-md shadow-md p-4",children:a.jsx(ng,{subscription:e})})]}),a.jsx(j,{className:"bg-grey-200 rounded-t-2xl px-3 pt-2.5 pb-4 mt-2",children:a.jsx(U,{variant:"label8",className:"text-grey-500 font-medium",children:"Details"})}),a.jsx(j,{className:"bg-metrifox-white flex justify-between flex-wrap gap-8 rounded-2xl p-4 -mt-2.5",children:l?.map((u,d)=>a.jsxs(j,{className:"",children:[a.jsx(U,{variant:"label8",className:"text-grey-500",children:u?.label}),a.jsx(U,{variant:"label7",className:`text-grey-600 font-medium mt-2 ${u?.value==="-"?"text-center":""}`,children:u?.value})]},d))}),e?.subscription_items?.length>0&&a.jsx(rg,{subscriptionLineItems:e?.subscription_items,handleUpdateQuantity:c,canUpdateQuantities:e?.can_update_quantities})]})})},og=({upcomingInvoice:e})=>{const[t,n]=p.useState(!1),r=p.useRef(null),{invoiceDetails:s}=e0({invoiceId:e?.invoice_id});return a.jsxs(j,{children:[a.jsxs(j,{className:"bg-grey-100 rounded-2xl p-4 w-full flex items-center justify-between",children:[a.jsxs(j,{className:"flex items-center gap-3",children:[a.jsx(U,{variant:"label7",className:"font-medium text-metrifox-black",children:"Upcoming Invoice"}),a.jsx(j,{className:"flex items-center gap-2",children:a.jsx(un,{background:"bg-purple-500",size:"small",children:a.jsxs(U,{variant:"label8",className:"text-metrifox-white",children:[e?.currency?.symbol,e?.amount]})})}),a.jsxs(W,{variant:"body6",className:"text-metrifox-black",children:["Due"," ",new Date(e?.due_date).toLocaleString(e?.currency?.country_code,{month:"short",day:"numeric",year:"numeric"})]})]}),a.jsx(Ps,{className:"!text-metrifox-blue underline cursor-pointer",onClick:()=>{n(!0)},children:"Preview invoice"})]}),t&&a.jsx(Qd,{isOpen:t,onClose:()=>n(!1),contentRef:r,content:a.jsx(i1,{data:s}),modalTitle:"Invoice preview"})]})},ig=({tenantDetails:e,subscription:t,wallet:n})=>{const[r,s]=p.useState(0),o=c=>c.allocations.map(u=>({creditedDate:u.credited_date,source:u.source,amount:u.amount,balance:u.balance_remaining,validUntil:u.valid_until})),i=[{header:"Credited date",render:c=>a.jsx(W,{variant:"body6",color:"text-grey-700",children:new Date(c.creditedDate).toString()})},{key:"source",header:"Source"},{header:"Amount",render:c=>a.jsx(W,{variant:"body6",color:"text-grey-700",children:me(c.amount)})},{header:"Balance",render:c=>a.jsx(W,{variant:"body6",color:"text-grey-700",children:me(c.balance)})},{header:"Valid until",render:c=>a.jsx(W,{variant:"body6",color:"text-grey-700",children:c.validUntil?new Date(c.validUntil).toLocaleDateString():"No expiration"})}],l=c=>{const u=`${window.location.origin}/${e.tenant_checkout_username}/checkout/${t.offering_key}?customer=${e.customer_key}&credit=${c}`;window.open(u,"_blank","noopener,noreferrer")};return!n||n.length===0?null:a.jsxs(j,{className:"bg-grey-100 rounded-2xl p-4",children:[a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(j,{className:"p-1.5 bg-grey-200 rounded-lg",children:a.jsx(be,{name:"card-receive",size:16,color:"grey-500"})}),a.jsx(U,{variant:"label7",className:"text-metrifox-black font-medium",children:"Wallet balance"})]}),a.jsx(j,{className:"bg-metrifox-white rounded-2xl p-4 mt-2",children:n.length>1?a.jsxs(us,{defaultIndex:r,onChange:s,children:[a.jsx(ds,{className:"w-max bg-grey-100 border border-neutral-200 text-grey-500 px-1.5 py-1 rounded-2xl",children:n.map(c=>a.jsx(rr,{className:"w-max data-[selected]:bg-metrifox-primary data-[selected]:border data-[selected]:border-grey-200 outline-none data-[selected]:text-metrifox-white rounded-xl px-8 py-2",children:a.jsx(W,{variant:"body6",children:c.name})},c.id))}),a.jsx(fs,{children:n.map(c=>a.jsxs(Sn,{children:[a.jsx(j,{className:"bg-grey-100 rounded-lg p-6 mt-4",children:a.jsxs(j,{className:"w-full flex items-center justify-between gap-1",children:[a.jsxs(j,{className:"text-center",children:[a.jsx(j,{className:"flex items-center justify-center gap-1",children:a.jsx(U,{variant:"label8",className:"text-grey-500 font-medium",children:"Total available balance"})}),a.jsxs(j,{className:"flex items-baseline justify-center gap-1",children:[a.jsx(U,{variant:"label6",className:"text-neutral-800 font-medium",children:me(c.balance)}),a.jsx(U,{variant:"label8",className:"text-grey-500 mt-3.5",children:c.name})]})]}),a.jsx(Cr,{type:"button",size:"small",onClick:()=>l(c.credit_key),className:"text-metrifox-white",children:"Top up"})]})}),a.jsx(wr,{columns:i,data:o(c)})]},c.id))})]}):n[0]&&a.jsxs(a.Fragment,{children:[a.jsx(j,{className:"bg-grey-100 rounded-lg p-6 mt-4",children:a.jsxs(j,{className:"w-full flex items-center justify-between gap-1",children:[a.jsxs(j,{className:"text-center",children:[a.jsx(j,{className:"flex items-center justify-center gap-1",children:a.jsx(U,{variant:"label8",className:"text-grey-500 font-medium",children:"Total available balance"})}),a.jsxs(j,{className:"flex items-baseline justify-center gap-1",children:[a.jsx(U,{variant:"label6",className:"text-neutral-800 font-medium",children:me(n[0].balance)}),a.jsx(U,{variant:"label8",className:"text-grey-500 mt-3.5",children:n[0].name})]})]}),a.jsx(Cr,{type:"button",size:"small",onClick:()=>n[0]?.id&&l(n[0].id),className:"text-metrifox-white",children:"Top up"})]})}),a.jsx(wr,{columns:i,data:o(n[0])})]})})]})},ag=[{key:"upcomingInvoice"},{key:"subscription"},{key:"creditBalance"},{key:"entitlementUsage"},{key:"paymentOverview"},{key:"billingHistory"},{key:"plan"}],lg={upcomingInvoice:"upcoming-invoice",subscription:"subscription",creditBalance:"credit-balance",entitlementUsage:"entitlement-usage",paymentOverview:"payment-overview",billingHistory:"billing-history",plan:"plan"},l0=({product:e,tenantDetails:t,sectionsConfig:n})=>{const r=n||ag,s={upcomingInvoice:()=>e?.subscription?.upcoming_invoice?a.jsx(og,{upcomingInvoice:e.subscription.upcoming_invoice}):null,subscription:()=>e?.subscription?a.jsx(sg,{subscription:e.subscription,tenantDetails:t}):null,creditBalance:()=>e?.wallets?.length>0?a.jsx(ig,{subscription:e.subscription,tenantDetails:t,wallet:e.wallets}):null,entitlementUsage:()=>e?.entitlements?.length>0?a.jsx(im,{entitlements:e.entitlements}):null,paymentOverview:()=>a.jsx(am,{paymentMethod:e.payment_method,tenantDetails:t}),billingHistory:()=>e?.subscription?.id?a.jsx(rm,{subscriptionId:e.subscription?.id}):null,plan:()=>e?.product_key?a.jsx(Gm,{planName:e?.subscription?.plan_name,productKey:e?.product_key}):null};return a.jsxs(j,{className:"space-y-4",children:[r.filter(o=>!o.hidden).map(o=>{const i=lg[o.key]??o.key;if(o.component)return a.jsx("section",{id:i,className:"space-y-4",children:a.jsx(o.component,{product:e,tenantDetails:t,...o.props})},o.key);const l=s[o.key],c=l?l(o.props):null;return c?a.jsx("section",{id:i,children:c},o.key):null}),a.jsx(qm,{})," "]})},cg=({customerKey:e,sectionsConfig:t})=>{const[n,r]=p.useState(0),{setCustomerKey:s,setCustomerRefetch:o}=en(),{customerDetails:i,error:l,refetch:c,isLoading:u}=K9({customerKey:e});if(p.useEffect(()=>{s(e),o(c)},[]),l)return a.jsx(j,{className:"max-w-[60rem] mx-auto py-6 px-4",children:a.jsxs("div",{className:"bg-red-50 p-4 rounded-lg text-red-700",children:["Error loading customer details: ",l]})});if(u||!i)return a.jsx(j,{className:"max-w-[60rem] mx-auto py-6 px-4",children:a.jsxs("div",{className:"animate-pulse space-y-4",children:[a.jsx("div",{className:"h-12 bg-gray-200 rounded-lg"}),a.jsx("div",{className:"h-16 bg-gray-200 rounded-lg"}),[1,2,3,4,5].map(m=>a.jsx("div",{className:"h-48 bg-gray-200 rounded-lg"},m))]})});const{subscriptions:d,...f}=i||{},h=d||[];return a.jsx(Df,{children:a.jsx(j,{className:"max-w-[60rem] mx-auto py-6 px-4 space-y-4",children:h&&h.length>1?a.jsxs(us,{defaultIndex:n,onChange:m=>r(m),children:[a.jsx(ds,{className:"w-max bg-grey-100 border border-grey-200 text-grey-500 px-1.5 py-1 mb-4 rounded-2xl",children:h.map(m=>a.jsx(rr,{className:"w-max data-[selected]:bg-metrifox-primary data-[selected]:border data-[selected]:border-grey-200 outline-none data-[selected]:text-metrifox-white rounded-xl px-8 py-2",children:a.jsx(W,{variant:"body6",children:m.product_name})},m.product_key))}),a.jsx(fs,{children:h.map(m=>a.jsx(Sn,{children:a.jsx(l0,{product:m,tenantDetails:f,sectionsConfig:t})},m.product_key))})]}):a.jsx(a.Fragment,{children:h.map(m=>a.jsx(l0,{product:m,tenantDetails:f,sectionsConfig:t},m.product_key))})})})};exports.CustomerPortal=cg,exports.metrifoxInit=tf;
|
|
45
|
+
`,children:V.render?V.render(D):L(c6(D,V.key))},O))},I))]})]})}),i==="grid"&&a.jsx("div",{className:`grid ${A}`,children:t?.map((D,I)=>a.jsx("div",{className:o?"cursor-pointer":"cursor-default",onClick:()=>o?.(D),children:l?.renderItem(D)},I))}),n&&a.jsx(J8,{currentPage:n.currentPage,totalPages:n.totalPages,onPageChange:n.onPageChange})]})},Q8=({columns:e})=>a.jsx("tr",{children:Array.from({length:e}).map((t,n)=>a.jsx("td",{className:"px-3 py-4 border-b border-gray-100",children:a.jsx("div",{className:"mt-1 h-4 w-20 rounded-md bg-gray-200"})},n))}),un=({children:e,size:t="medium",background:n="transparent",textColor:r=""})=>{const s=B9[t];return a.jsx(j,{className:`inline-flex items-center ${n} min-w-fit justify-center rounded-full px-2.5 py-1 border gap-x-2 ${s} ${n==="transparent"?"border-grey-300":"border-none"} ${r}`,children:e})},em=async({subscriptionId:e})=>{const{data:t}=await It().get(`/subscriptions/${e}/billing-history`);return t},tm=({subscriptionId:e})=>{const[t,n]=p.useState(null),[r,s]=p.useState(!1),o=async()=>{if(!e){ct.error("Missing subscriptionId");return}s(!0);try{const i=await em({subscriptionId:e});n(i?.data)}catch(i){ct.error(i instanceof Error?i.message:"Failed to load billing history")}finally{s(!1)}};return p.useEffect(()=>{o()},[e]),{billingHistory:t,isLoading:r,refetch:o}},nm=async({invoiceId:e})=>{const{data:t}=await It().get(`/invoices/${e}/view`);return t},e0=({invoiceId:e})=>{const[t,n]=p.useState(null),[r,s]=p.useState(!1),o=async()=>{if(e){s(!0);try{const i=await nm({invoiceId:e});n(i?.data)}catch(i){ct.error(i instanceof Error?i.message:"Failed to load invoice details")}finally{s(!1)}}};return p.useEffect(()=>{o()},[e]),{invoiceDetails:t,isLoading:r,refetch:o}},rm=({subscriptionId:e})=>{const[t,n]=p.useState(!1),[r,s]=p.useState(null),o=p.useRef(null),{billingHistory:i}=tm({subscriptionId:e}),{invoiceDetails:l}=e0({invoiceId:r||""}),c=d=>{d.status===t1.Paid&&d.invoice_id&&(s(d.invoice_id),n(!0))},u=[{header:"Total amount",render:d=>{const{text:f,color:h}=i6(d.status),m=Pt(d.currency);return a.jsx(j,{children:a.jsxs(j,{className:"flex items-center gap-2",children:[a.jsxs(j,{className:"flex items-center",children:[a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:m}),a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:n1(parseFloat(String(d.total_amount)))})]}),a.jsx(un,{size:"small",background:`${h}`,children:a.jsx(U,{variant:"label9",className:"capitalize text-metrifox-white",children:f})})]})})}},{header:"Invoice number",render:d=>a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:d.invoice_number||"-"})},{header:"Source type",render:d=>a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:Dt(d.source_type==="billing_cycle"?"subscription":d.source_type).replace(/_/g," ")})},{header:"Issue date",render:d=>a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:d.issued_date?e1(d.issued_date).format("MMM D, YYYY"):"-"})},{header:"Due date",render:d=>a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:d.due_date?e1(d.due_date).format("MMM D, YYYY"):"-"})},{header:"Amount paid",render:d=>{const f=Pt(d.currency);return a.jsxs(j,{className:"flex items-center",children:[a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:f}),a.jsx(W,{className:"capitalize",variant:"body6",color:"text-grey-700",children:n1(parseFloat(String(d.amount_paid)))})]})}}];return!i||i?.length===0?null:a.jsxs(j,{className:"bg-grey-100 rounded-2xl p-4",children:[a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(j,{className:"p-1.5 bg-grey-200 rounded-lg",children:a.jsx(be,{name:"receipt",size:16,color:"grey-500"})}),a.jsx(U,{variant:"label7",className:"text-metrifox-black font-medium",children:"Billing history"})]}),a.jsx(wr,{columns:u,data:i,onRowClick:c,className:"mt-2"}),t&&r&&a.jsx(Qd,{isOpen:t,onClose:()=>{n(!1),s(null)},contentRef:o,content:a.jsx(i1,{data:l}),modalTitle:"Invoice PDF"})]})},sm=({entitlements:e})=>a.jsx(wr,{columns:[{key:"name",header:"Feature",render:t=>a.jsx(j,{children:a.jsx(W,{variant:"body6",color:"text-grey-700",children:t.name})})},{key:"features_type",header:"Type",render:t=>{const n={[sr.METERED]:"bg-metrifox-blue",[sr.BOOLEAN]:"bg-metrifox-warning"};return a.jsx(j,{children:a.jsx(un,{size:"small",textColor:"text-metrifox-white",background:n[t.feature_type],children:a.jsx(W,{variant:"body6",children:Dt(t.feature_type)})})})}},{key:"quota",header:"Quota Limit",render:t=>{const n=`${t.quota} ${t.name}`,r=s6(),s=t.reset_interval!==Wo.NONE?Dt(r[t.reset_interval]||""):"";return a.jsx(j,{children:a.jsx(W,{variant:"body6",children:t.feature_type===sr.BOOLEAN?"Access granted":`${n} ${s}`})})}}],data:e}),om=({meteredEntitlements:e})=>a.jsx(wr,{columns:[{header:"Feature",render:t=>a.jsx(j,{children:a.jsx(W,{variant:"body6",color:"text-grey-700",children:t.name})})},{key:"featuresUsage",header:"Usage",render:t=>{const n=e?.find(o=>o.name===t.name);if(!n){const o=`${t.used_quantity}/${t.quota===-1?"\u221E":t.quota} ${t.name}`;return a.jsx(W,{variant:"body6",children:o})}const r=n.quota===-1?100:Math.min(n.used_quantity/Number(n.quota)*100,100).toFixed(0),s=n.quota==="unlimited"?"\u221E":`${r}%`;return a.jsx(j,{className:"flex gap-4 items-center",children:a.jsxs(j,{className:"flex-1",children:[a.jsxs(j,{className:"w-full flex items-center gap-x-2",children:[a.jsx(j,{className:"w-full h-[6px] bg-grey-300 rounded",children:a.jsx(j,{className:"h-[6px] bg-metrifox-blue rounded",style:{width:`${r}%`}})}),a.jsx(j,{className:"w-8",children:a.jsx(W,{variant:"body7",className:n.quota===-1?"text-xl":"",children:s})})]}),a.jsxs(W,{variant:"body6",className:"mt-1",children:[n.used_quantity,"/",n.quota===-1?"":n.quota," ",n.reset_interval===Wo.NONE?"":`every ${r6[n.reset_interval]}`]})]})})}}],data:e}),im=({entitlements:e})=>{const t=e.filter(n=>n.feature_type!==sr.BOOLEAN);return a.jsxs(j,{className:"bg-grey-100 rounded-2xl p-4",children:[a.jsx(j,{className:"flex items-center justify-between",children:a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(j,{className:"p-1.5 bg-grey-200 rounded-lg",children:a.jsx(be,{name:"radar",size:16,color:"grey-500"})}),a.jsx(U,{variant:"label7",className:"text-metrifox-black font-medium",children:"Entitlements"})]})}),a.jsx(j,{className:"bg-metrifox-white rounded-2xl p-4 mt-2",children:a.jsxs(us,{children:[a.jsxs(ds,{className:"w-max bg-grey-100 border border-neutral-200 text-grey-500 px-1.5 py-1 rounded-2xl",children:[a.jsx(rr,{className:"w-max data-[selected]:bg-metrifox-primary data-[selected]:border data-[selected]:border-grey-200 outline-none data-[selected]:text-metrifox-white rounded-xl px-8 py-2",children:a.jsx(W,{variant:"body6",children:"Summary"})}),t.length>0&&a.jsx(rr,{className:"w-max data-[selected]:bg-metrifox-primary data-[selected]:border data-[selected]:border-grey-200 outline-none data-[selected]:text-metrifox-white rounded-xl px-8 py-2",children:a.jsx(W,{variant:"body6",children:"Usage"})})]}),a.jsxs(fs,{children:[a.jsx(Sn,{children:a.jsx(sm,{entitlements:e})}),t.length>0&&a.jsx(Sn,{children:a.jsx(om,{meteredEntitlements:t})})]})]})})]})},am=({tenantDetails:e,paymentMethod:t})=>{const{address:n}=Jc(e?.billing_address),r=[{label:"Billed to",value:e?.full_name||"-"},{label:"Billing email",value:e?.billing_email||"-"},{label:"Billing address",value:n||"-"}];return a.jsxs(j,{className:"bg-grey-100 rounded-2xl p-4",children:[a.jsx(j,{className:"flex items-center justify-between",children:a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(j,{className:"p-1.5 bg-grey-200 rounded-lg",children:a.jsx(be,{name:"money",size:18,color:"grey-500"})}),a.jsx(U,{variant:"label7",className:"text-metrifox-black font-medium",children:"Payment"})]})}),a.jsx(j,{className:"bg-grey-200 rounded-t-2xl px-3 pt-2.5 pb-4 mt-2",children:a.jsx(U,{variant:"label8",className:"text-grey-500 font-medium",children:"Details"})}),a.jsxs(j,{className:"bg-metrifox-white grid grid-cols-3 gap-8 justify-between rounded-2xl p-4 -mt-2.5",children:[r?.map((s,o)=>a.jsxs(j,{children:[a.jsx(U,{variant:"label8",className:"text-grey-500",children:s?.label}),a.jsx(U,{variant:"label7",className:"text-grey-600 font-medium mt-2",children:s?.value||"-"})]},o)),a.jsxs(j,{children:[a.jsx(U,{variant:"label8",className:"text-grey-500",children:"Payment method"}),t?a.jsxs(j,{className:"flex items-center gap-x-2 mt-2",children:[a.jsxs(W,{variant:"body6",color:"text-grey-600 font-medium",children:[Dt(t?.brand)," ",t?.display_name," "]}),a.jsxs(W,{variant:"body6",className:"text-neutral-500 font-light",children:["Expires ",t?.exp_month,"/",t?.exp_year]})]}):a.jsx("span",{children:"-"})]})]})]})},lm=async({offeringKey:e,billingInterval:t,customerKey:n})=>{const{data:r}=await It().get(`/products/offerings/generate-checkout-url?offering_key=${e}&billing_interval=${t}&customer_key=${n}`);return r},cm=({billingInterval:e})=>{const[t,n]=p.useState(null),[r,s]=p.useState(!1),{customerKey:o}=en();return{checkoutUrl:t,isLoading:r,generateCheckoutUrl:async i=>{if(!(!i||!e||!o)){s(!0);try{const l=await lm({offeringKey:i,billingInterval:e,customerKey:o});n(l?.data?.checkout_url)}catch(l){ct.error(l instanceof Error?l.message:"Failed to load checkout url")}finally{s(!1)}}}}},um=async({product_key:e})=>{const{data:t}=await It().get(`/product_catalogues/products/published-plans?product_key=${e}`);return t},dm=({product_key:e})=>{const[t,n]=p.useState(null),[r,s]=p.useState(!1),o=async()=>{if(!e){ct.error("Missing product_key");return}s(!0);try{const i=await um({product_key:e});n(i?.data)}catch(i){ct.error(i instanceof Error?i.message:"Failed to load product plans")}finally{s(!1)}};return p.useEffect(()=>{o()},[e]),{productPlans:t,isLoading:r,refetch:o}},fm=e=>{const t=p6(e||[]),[n,r]=p.useState(""),s=[...t.includes(pe.DAILY)?[pe.DAILY]:[],...t.includes(pe.WEEKLY)?[pe.WEEKLY]:[],...t.includes(pe.MONTHLY)?[pe.MONTHLY]:[],...t.includes(pe.QUARTERLY)?[pe.QUARTERLY]:[],...t.includes(pe.BIANNUALLY)?[pe.BIANNUALLY]:[],...t.includes(pe.YEARLY)?[pe.YEARLY]:[]];return p.useEffect(()=>{!n&&s[0]&&r(s[0])},[s,n]),{intervals:s,selectedInterval:n,setSelectedInterval:r}},t0=({selectedInterval:e,publishedOnly:t=!1})=>{const{plans:n}=en(),r=c=>{if(c)return t?c?.is_visible?c:void 0:c},s=n?.some(c=>!!r(c)?.description),o=n?.some(c=>!!r(c)?.trial_duration_value),i=n?.some(c=>{const u=r(c);return u?u.price_options?.some(d=>d.price?.billing_interval===e)||u.is_free||u.is_custom:!1}),l=n?.some(c=>{const u=r(c);return u?[u.credit_attachment_price_options,u.entitlement_price_options].some(d=>Array.isArray(d)&&d.some(f=>f.price?.billing_interval===e)):!1});return{shouldShowDescription:s,shouldShowFreeTrial:o,shouldShowFixedPrice:i,shouldShowDynamicPrices:l}},n0=({entitlements:e,baseEntitlementsPlanName:t,credits:n})=>{const r=Zo(e).filter(s=>s?.is_visible);return a.jsxs(j,{children:[a.jsx(U,{variant:"label7",className:"text-metrifox-primary mb-3",as:"p",children:t?`Everything in ${t} plus:`:"\xA0"}),a.jsxs("ul",{className:"flex flex-col gap-y-3",children:[n?.map((s,o)=>a.jsxs("li",{className:"flex items-center gap-[10px]",children:[a.jsx(be,{name:"check",color:"green-600",size:16}),a.jsx(W,{variant:"body5",children:s.included_usage_text})]},o)),r?.map((s,o)=>a.jsxs("li",{className:"flex items-center gap-[10px]",children:[a.jsx(be,{name:"check",color:"green-600",size:16}),a.jsx(W,{variant:"body5",children:s.display_text})]},o))]})]})},hm=e=>{const t=e?.price?.billing_interval,n=e?.price.tiers,r=e?.price.currency,s=e?.price?.invoice_timing,o=Pt(r),i=x=>{const v=e?.price?.owner,b=v?.included_usage||0,C=x?.find(D=>D.first_unit===b);if(!C)return{price:null,label:null};const{unit_price:y,package_price:k,package_size:w,pricing_model:L,flat_fee:A}=C;return A?{price:A.toFixed(2),label:""}:{per_unit:{price:y?.toFixed(2),label:`per. ${v?.feature?.unit_singular||v?.credit_unit_singular}`},per_package:{price:k?.toFixed(2),label:`for ${w} ${v?.feature?.unit_plural}`}}[L]??{price:null,label:null}},{price:l,label:c}=i(n),u=e?.price?.is_custom&&e?.price?.billing_interval_value>1?`every ${e?.price?.billing_interval_value} ${d6[t]}`:t,d=[pe.DAILY,pe.WEEKLY],f={[pe.DAILY]:"day",[pe.WEEKLY]:"week"},h=t,m=d.includes(h)?f[h]:"month",g=(u6(t,e?.price?.billing_interval_value)*(e?.price?.price??0)).toFixed(2);return{amount:(e?.price?.price??0).toFixed(2),billedText:u,intervalText:m,billingAmount:g,tierPrice:l,tierLabel:c,currencySymbol:o,invoiceTiming:s,intervalValue:e?.price?.billing_interval_value}},pm=({dynamicPrices:e,showMoreCard:t,showMore:n})=>{const[r,s]=p.useState("");return a.jsxs(j,{className:t?"":"h-[75px] flex flex-col",children:[(t?e:e.slice(0,2)).map(o=>{const i=o?.price?.name||o?.price?.owner?.feature?.name||o?.price?.owner?.name,l=f6(o?.price.tiers,o.price.currency),{price:c,label:u,currencySymbol:d}=h6(o),f=l?.length===1;return t?a.jsxs(j,{className:"p-2 border-b border-grey-200 last:border-0",children:[a.jsxs(j,{className:"flex justify-between items-center",children:[a.jsx(U,{variant:"label7",className:"text-grey-600 mb-1",children:i}),f&&a.jsxs(j,{className:"flex items-center cursor-pointer",children:[a.jsxs(U,{variant:"label7",color:"text-metrifox-black",children:[d,c]}),u&&a.jsxs(W,{variant:"body5",color:"text-grey-500",className:"mr-1",children:["/",u]})]})]}),!f&&a.jsxs(j,{className:"flex justify-between items-center",children:[a.jsx(W,{variant:"body5",className:"text-grey-700",children:"Starts at"}),a.jsxs(j,{className:"flex items-center cursor-pointer",onClick:h=>{h.stopPropagation(),s(r===o.id?"":o.id)},children:[a.jsxs(U,{variant:"label7",color:"text-metrifox-black",children:[d,c]}),a.jsxs(W,{variant:"body5",color:"text-grey-500",className:"mr-1",children:["/",u]}),l.length>1&&a.jsx(be,{name:r===o.id?"arrow-up-light":"arrow-down-linear",size:16,color:"grey-400"})]})]}),r===o.id&&l.length>1&&a.jsx(j,{className:"bg-grey-200 p-2 mt-1 rounded-lg",children:a.jsx(j,{className:"flex flex-col gap-y",children:l?.map(h=>a.jsxs(j,{className:"flex justify-between items-center",children:[a.jsx(W,{variant:"body7",color:"text-grey-700",children:h?.label}),a.jsxs(W,{variant:"body7",color:"text-grey-700",children:[h?.price,h?.package?`/${h?.package} ${u}`:""]})]},h?.label))})})]},o.id):a.jsx(j,{className:"mt-1",children:a.jsxs(j,{className:"flex items-center gap-x-1 flex-wrap",children:[a.jsx(U,{variant:"label8",className:"text-grey-600 whitespace-nowrap",children:i}),a.jsx(W,{variant:"body7",children:f?"at":"from"}),a.jsxs(j,{className:"flex items-center",children:[a.jsxs(U,{variant:"label7",color:"text-metrifox-black",children:[d,c]}),u&&a.jsxs(W,{variant:"body7",color:"text-grey-500",children:["/",u]})]})]})},o.id)}),!t&&!!e?.length&&a.jsx(j,{className:"flex items-center justify-center mt-auto mb-2",children:a.jsx(Ps,{onClick:o=>{n(),o?.stopPropagation()},className:"mt-2",children:a.jsx(W,{variant:"body8",className:"text-metrifox-blue underline",children:"Explore all priced features"})})})]})},mm=({interval:e,priceOptions:t,entitlementPriceOptions:n,creditAttachmentPriceOptions:r,isPricePage:s,trialTag:o,showMoreCard:i,isFree:l,isCustom:c,showMore:u})=>{const{shouldShowFixedPrice:d,shouldShowFreeTrial:f,shouldShowDynamicPrices:h}=t0({selectedInterval:e,publishedOnly:s}),m=r1(e,t),g=s1(e,n),x=[...s1(e,r)||[],...g||[]],{amount:v,billedText:b,billingAmount:C,intervalText:y,currencySymbol:k,intervalValue:w}=hm(m),L=me(v).split("."),A=L?L[0]:"0",D=L&&L.length>1?L[1]:"00";return a.jsxs(j,{className:i?"bg-grey-100 border border-grey-200 rounded-2xl p-2 mb-3":"w-full",children:[d&&a.jsxs(j,{className:i?"":"h-[94px]",children:[l&&a.jsx(j,{className:"p-2 border-b border-grey-200 last:border-0",children:a.jsx(j,{className:"flex items-center justify-between pt-[21px] pb-4",children:a.jsx(U,{variant:"label3",children:"Free"})})}),c&&a.jsx(j,{className:"p-2 border-b border-grey-200 last:border-0",children:a.jsx(j,{className:"flex items-center justify-between pt-[21px] pb-4",children:a.jsx(U,{variant:"label4",children:"Custom"})})}),!m&&!l&&!c&&a.jsx(j,{className:"p-2 border-b border-grey-200 last:border-0",children:a.jsx(j,{className:"flex items-center justify-between pt-[21px] pb-4",children:a.jsx(U,{variant:"label4",children:"No fixed price"})})}),m&&a.jsxs(j,{className:"p-2 border-b border-grey-200 last:border-0",children:[a.jsx(j,{className:"flex items-center justify-between",children:a.jsx(U,{variant:"label7",className:"text-grey-600 mb-2",children:"Fixed price"})}),a.jsxs(j,{className:"flex items-end",children:[a.jsxs(U,{variant:"label3",className:"text-[var(--price-color,#0F0F0F)]",children:[k,A]}),a.jsxs(U,{variant:"label6",className:"mb-[5px] text-metrifox-black",children:[".",D]}),a.jsxs(W,{variant:"body4",className:"mb-[5px] text-grey-500",children:["/",y]})]}),(e!==pe.MONTHLY||w!==1)&&a.jsxs(W,{className:"-mt-2",variant:"body5",children:["Billed",a.jsxs(U,{as:"span",variant:"label7",className:"inline-block",children:[k,me(C)," ",b.toLowerCase()]})]})]})]}),f&&!s&&a.jsx(j,{className:"h-6",children:o}),h&&a.jsx(pm,{dynamicPrices:x,showMoreCard:!!i,showMore:u})]})},gm=({description:e,entitlements:t,baseEntitlementsPlanName:n,priceContent:r})=>a.jsxs(j,{children:[a.jsx(U,{variant:"label7",className:"mb-2",children:"Description"}),a.jsx(W,{variant:"body5",className:"mb-4 whitespace-pre-wrap",children:e}),r,a.jsx(n0,{entitlements:t,baseEntitlementsPlanName:n})]});function xm(e){p.useEffect(function(){typeof e=="function"&&e()},[])}var ym="Expected a function",r0=0/0,vm="[object Symbol]",bm=/^\s+|\s+$/g,Cm=/^[-+]0x[0-9a-f]+$/i,wm=/^0b[01]+$/i,km=/^0o[0-7]+$/i,jm=parseInt,Lm=typeof Ot=="object"&&Ot&&Ot.Object===Object&&Ot,Em=typeof self=="object"&&self&&self.Object===Object&&self,Mm=Lm||Em||Function("return this")(),Sm=Object.prototype,Tm=Sm.toString,Dm=Math.max,Pm=Math.min,la=function(){return Mm.Date.now()};function Am(e,t,n){var r,s,o,i,l,c,u=0,d=!1,f=!1,h=!0;if(typeof e!="function")throw new TypeError(ym);t=s0(t)||0,ca(n)&&(d=!!n.leading,f="maxWait"in n,o=f?Dm(s0(n.maxWait)||0,t):o,h="trailing"in n?!!n.trailing:h);function m(L){var A=r,D=s;return r=s=void 0,u=L,i=e.apply(D,A),i}function g(L){return u=L,l=setTimeout(b,t),d?m(L):i}function x(L){var A=L-c,D=L-u,I=t-A;return f?Pm(I,o-D):I}function v(L){var A=L-c,D=L-u;return c===void 0||A>=t||A<0||f&&D>=o}function b(){var L=la();if(v(L))return C(L);l=setTimeout(b,x(L))}function C(L){return l=void 0,h&&r?m(L):(r=s=void 0,i)}function y(){l!==void 0&&clearTimeout(l),u=0,r=c=s=l=void 0}function k(){return l===void 0?i:C(la())}function w(){var L=la(),A=v(L);if(r=arguments,s=this,c=L,A){if(l===void 0)return g(c);if(f)return l=setTimeout(b,t),m(c)}return l===void 0&&(l=setTimeout(b,t)),i}return w.cancel=y,w.flush=k,w}function ca(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function Rm(e){return!!e&&typeof e=="object"}function Nm(e){return typeof e=="symbol"||Rm(e)&&Tm.call(e)==vm}function s0(e){if(typeof e=="number")return e;if(Nm(e))return r0;if(ca(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=ca(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(bm,"");var n=wm.test(e);return n||km.test(e)?jm(e.slice(2),n?2:8):Cm.test(e)?r0:+e}var Fm=Am,Vm=Mr(Fm);function $m(e,t,n){var r=p.useCallback(function(o){return Vm(o,t,n)},[t,n]),s=p.useRef(r(e));return p.useEffect(function(){s.current=r(e)},[e,r]),s.current}function Om(e,t){var n=p.useRef(!1);typeof t<"u"&&!Array.isArray(t)?t=[t]:Array.isArray(t)&&t.length===0&&console.warn("Using [] as the second argument makes useDidUpdate a noop. The second argument should either be `undefined` or an array of length greater than 0."),p.useEffect(function(){n.current?e():n.current=!0},t),p.useEffect(function(){return function(){n.current=!1}},[])}var o0=typeof window>"u"?p.useEffect:p.useLayoutEffect;function _m(e,t){t===void 0&&(t=!1);var n=t?o0:p.useEffect,r=p.useRef(e);return n(function(){r.current=e}),r}function Bm(e){var t=_m(e);function n(){for(var r=[],s=0;s<arguments.length;s++)r[s]=arguments[s];typeof t.current=="function"&&t.current.apply(t,r)}return n}var Im=process.env.NODE_ENV!=="production",i0=function(){};if(Im){var Hm=function(e){var t="Warning: ".concat(e);typeof console<"u"&&console.error(t);try{throw new Error(t)}catch{}};i0=function(e,t){e||Hm(t)}}function Wm(e,t,n,r,s,o){r===void 0&&(r={}),s===void 0&&(s=!0),o===void 0&&(o=!1);var i=Bm(n),l=o?o0:p.useEffect;l(function(){return i0(typeof e<"u","[useGlobalObjectEventListener]: Cannot attach event handlers to undefined."),typeof e<"u"&&s?(e.addEventListener(t,i,r),function(){e.removeEventListener(t,i,r)}):function(){}},[t,r])}function Zm(e,t,n){t===void 0&&(t=!0),n===void 0&&(n=!1),typeof window<"u"?Wm(window,"resize",e,{passive:!0},t,n):console.warn("useOnWindowResize can't attach an event listener as window is undefined.")}var a0="...",Um=0,As=function(){return"__clamp_text_key__".concat(Um++)};function zm(e){var t=e.text,n=e.ellipsis,r=n===void 0?a0:n,s=e.lines,o=s===void 0?3:s,i=e.expanded,l=i===void 0?!1:i,c=e.debounceTime,u=c===void 0?300:c,d=e.charWidth,f=d===void 0?1.2:d,h=p.useState(function(){return{noClamp:!1,clampedText:".",key:As()}}),m=h[0],g=m.noClamp,x=m.clampedText,v=m.key,b=h[1],C=p.useRef(),y=p.useRef(0),k=p.useCallback(function(L){var A=L.lineHeight,D=L.originalText,I=L.expanded,V=L.ellipsis,O=L.lines,z=L.charWidth,Z=C.current;if(!Z)return;if(!D||I){b({noClamp:!0,clampedText:D,key:As()});return}var P=A*O+1,F=0;typeof V=="string"?F=V===a0?5:Math.ceil(V.length*z):typeof V=="number"&&(F=Math.ceil(V*z));var E=0,T=0,M=D.length;if(!Z.clientHeight)return;function $(){var H,Y=(H=Z?.clientHeight)!==null&&H!==void 0?H:1;Y<=P?E=T+1:M=T-1}for(;E<=M;){if(T=Math.floor((E+M)/2),Z.innerText=D.slice(0,T),T===D.length){b({clampedText:D,noClamp:!0,key:As()});return}$()}var N=D.slice(0,Math.max(T-F,0)).trim()+(typeof V=="string"?V:"");Z.innerText=N,b({noClamp:!1,clampedText:N,key:As()})},[]),w=$m(k,u);return Zm(function(){return w({lineHeight:y.current,originalText:t,expanded:l,ellipsis:r,lines:o,charWidth:f})}),xm(function(){var L,A;if(t&&!y.current){var D=((A=(L=C.current)===null||L===void 0?void 0:L.clientHeight)!==null&&A!==void 0?A:1)+1;y.current=D,k({lineHeight:D,originalText:t,expanded:l,ellipsis:r,lines:o,charWidth:f})}}),Om(function(){k({lineHeight:y.current,originalText:t,expanded:l,ellipsis:r,lines:o,charWidth:f})},[l,t,f,r,o]),[C,{noClamp:g,clampedText:x,key:v}]}const Km=({description:e,showDetails:t})=>{const[n,{noClamp:r,clampedText:s,key:o}]=zm({text:e,ellipsis:12.5,lines:3});return e?a.jsx(W,{variant:"body6",children:a.jsxs("span",{ref:n,className:"w-full inline-block",children:[s,!r&&a.jsxs(a.Fragment,{children:["...",a.jsx(Ps,{onClick:i=>{t(),i?.stopPropagation()},className:"!inline",children:a.jsx(W,{variant:"body6",className:"text-metrifox-blue border-b border-metrifox-blue",children:"See more"})})]})]},o)}):null},Ym=({selectedInterval:e,intervals:t,setSelectedInterval:n})=>a.jsx(j,{className:"rounded-2xl p-1 flex bg-[var(--card-background-color,#F5F5F5)]",children:t.map(r=>{const s=e===r;return a.jsx(j,{className:`py-[4px] px-3 rounded-[12px] cursor-pointer ${s?"bg-[var(--active-tab-color,#3D3D3D)]":""}`,onClick:()=>n(r),children:a.jsx(W,{variant:"body4",color:s?"text-[var(--button-text,#FFFFFF)]":"text-[var(--tab-color,#A1A1AA)]",children:Dt(r)})},r)})}),Gm=({planName:e,productKey:t})=>{const[n,r]=p.useState(!1),[s,o]=p.useState(null),{setPlans:i}=en(),{productPlans:l}=dm({product_key:t}),{intervals:c,selectedInterval:u,setSelectedInterval:d}=fm(l||[]),{checkoutUrl:f,generateCheckoutUrl:h,isLoading:m}=cm({billingInterval:u}),{shouldShowDescription:g}=t0({selectedInterval:u,publishedOnly:!0}),x=p.useMemo(()=>{if(!l)return[];const y=l.findIndex(k=>k.name.toLowerCase()===e?.toLowerCase());return l.filter((k,w)=>k?.is_visible||w===y)},[l,e]),v=p.useMemo(()=>x.findIndex(y=>y.name.toLowerCase()===e?.toLowerCase()),[x,e]),b=y=>{o(y),r(!0)},C=()=>{r(!1),o(null)};return p.useEffect(()=>{f&&window.open(f,"_blank","noopener,noreferrer")},[f]),p.useEffect(()=>{x&&x.length>0&&i(x)},[x,i]),!x||x?.length===0?null:a.jsx(a.Fragment,{children:a.jsxs(j,{className:"bg-grey-100 rounded-2xl p-4",children:[a.jsx(j,{className:"flex items-center justify-between",children:a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(j,{className:"p-1.5 bg-grey-200 rounded-lg",children:a.jsx(be,{name:"subtitle",size:18,color:"grey-500"})}),a.jsx(U,{variant:"label7",className:"text-metrifox-black font-medium",children:"Plan"})]})}),a.jsxs(j,{className:"bg-metrifox-white rounded-2xl mt-2 p-4",children:[c.length>0&&a.jsx(j,{className:"flex justify-center mb-2.5",children:a.jsx(Ym,{selectedInterval:u,intervals:c,setSelectedInterval:d})}),a.jsx(j,{className:"flex gap-x-2 overflow-x-auto whitespace-nowrap px-6 py-4 -mx-4 [&::-webkit-scrollbar]:h-2 [&::-webkit-scrollbar-track]:bg-grey-100 [&::-webkit-scrollbar-thumb]:bg-grey-300 [&::-webkit-scrollbar-thumb]:rounded-full",children:x?.map((y,k)=>{const w=k===v,{name:L,entitlements:A,base_entitlement_plan_name:D,is_free:I,is_custom:V,description:O,price_options:z,entitlement_price_options:Z,credit_attachment_price_options:P,credit_attachments:F,trial_duration_unit:E,trial_duration_value:T}=y,M=r1(u,[...z,...Z]),$=E&&T,N=T===1?E:`${E}s`;if(!M&&!I&&!V)return null;const H=Zo([...A]).filter(J=>J?.is_visible),{featureOrderMap:Y}=g6(x||[]),_=m6(H,Y),R=F?.filter(J=>J.included_usage),B=J=>a.jsx(mm,{trialTag:$&&a.jsx(un,{background:"bg-grey-300",textColor:"text-metrifox-black",size:"small",children:a.jsx(W,{variant:"body6",children:`${T} ${N} Free trial`})}),interval:u,priceOptions:z,entitlementPriceOptions:Z,creditAttachmentPriceOptions:P,isPricePage:!1,showMoreCard:!!J,showMore:()=>b(y),isFree:I,isCustom:V});return a.jsxs(p.Fragment,{children:[a.jsxs(j,{className:"w-[35%] mb-8 flex-none text-wrap cursor-pointer",children:[a.jsx(j,{className:`${w?"bg-metrifox-primary":"bg-grey-200"} rounded-t-2xl px-3 pt-2.5 pb-4 mt-2"`,children:a.jsx(U,{variant:"label8",className:`${w?"text-metrifox-white":"text-grey-500"} font-medium`,children:y.name})}),a.jsx(j,{className:`${w?"border-b border-x":"border"} border-grey-200 h-full flex flex-col justify-between rounded-2xl p-2 -mt-2.5 transition-all duration-200 ${w?"bg-yellow-gradient":"bg-metrifox-white"}`,children:a.jsxs(j,{className:"w-full min-h-[25rem]",children:[g&&a.jsx(j,{className:"h-[51px] mt-1",children:a.jsx(Km,{description:O,showDetails:()=>b(y)})}),B(),!w&&a.jsx(Cr,{onClick:()=>h(y?.offering_key),className:"w-full bg-metrifox-primary hover:bg-metrifox-primary-dark mb-4",disabled:w||m,children:a.jsx(U,{variant:"label8",className:"text-metrifox-white",children:k>v?"Upgrade":"Downgrade"})}),a.jsx(j,{className:"px-2 mt-3",children:a.jsx(n0,{entitlements:_,credits:R,baseEntitlementsPlanName:D})})]})})]}),a.jsx(Ts,{isOpen:n&&s?.offering_key===y.offering_key,onClose:C,title:L,size:"small",bottomContent:a.jsx(j,{className:"flex justify-end gap-x-2",children:a.jsx(aa,{onClick:C,children:"Close"})}),children:s&&a.jsx(gm,{baseEntitlementsPlanName:s.base_entitlement_plan_name,description:s.description,entitlements:s.entitlements,priceContent:B(!0)})})]},k)})})]})]})})},qm=()=>a.jsx(j,{className:"flex justify-center items-center gap-x-2 h-full",children:a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(W,{variant:"body7",color:"text-metrifox-black",children:"Powered by"}),a.jsx(o1,{height:30,width:100})]})}),Xm=({trigger:e,children:t,className:n="bg-metrifox-white rounded-[10px] shadow-md",shouldMatchWidth:r,anchorGap:s=4,anchorTo:o="bottom start",anchorOffset:i=0})=>{const l=p.useRef(null),[c,u]=p.useState(null);p.useLayoutEffect(()=>{l.current&&u(l.current.offsetWidth)},[]);const d=r&&c?c:"auto";return a.jsxs(p9,{className:"relative",children:[a.jsx(Zc,{className:"outline-none w-full cursor-pointer",ref:l,as:"span",children:e}),a.jsx(Uc,{anchor:{gap:s,to:o,offset:i},className:`${n} absolute z-10 transition duration-200 ease-out data-[closed]:scale-95 data-[closed]:opacity-0`,style:{width:d},transition:!0,children:({close:f})=>typeof t=="function"?a.jsx(a.Fragment,{children:t(f)}):a.jsx(a.Fragment,{children:t})})]})},Jm=async({subscriptionId:e})=>{const{data:t}=await It().post(`/subscriptions/${e}/schedule-cancellation`);return t},Qm=({subscriptionId:e,isOpen:t,onClose:n})=>{const[r,s]=p.useState(!1),{customerRefetch:o}=en();return a.jsxs(Ts,{size:"small",title:"Cancel subscription?",isOpen:t,onClose:n,bottomContent:a.jsxs(j,{className:"flex justify-end gap-x-2",children:[a.jsx(ia,{className:"text-primary-500",onClick:n,size:"x-small",children:"Cancel"}),a.jsx(Cr,{className:"!bg-metrifox-danger text-metrifox-white",onClick:async()=>{s(!0);try{const i=await Jm({subscriptionId:e});ct.success(i.message),s(!1),n(),o()}catch(i){ct.error(i instanceof Error?i.message:"An error ocurred"),s(!1)}},size:"x-small",isLoading:r,disabled:r,children:"Confirm"})]}),showCloseButton:!1,className:"bg-metrifox-white",children:[a.jsx(U,{variant:"label7",children:"Are you sure you want to proceed?"}),a.jsx(W,{variant:"body4",color:"text-metrifox-black",className:"mt-5",children:"This subscription is scheduled to be canceled at the end of the billing cycle"})]})},eg=async({subscriptionId:e})=>{const{data:t}=await It().post(`/subscriptions/${e}/revert-cancellation`);return t},tg=({subscriptionId:e,isOpen:t,onClose:n})=>{const[r,s]=p.useState(!1),{customerRefetch:o}=en();return a.jsxs(Ts,{size:"small",title:"Undo cancellation?",isOpen:t,onClose:n,bottomContent:a.jsxs(j,{className:"flex justify-end gap-x-2",children:[a.jsx(ia,{className:"text-primary-500",onClick:n,size:"x-small",children:"Cancel"}),a.jsx(Cr,{className:"text-metrifox-white",onClick:async()=>{s(!0);try{const i=await eg({subscriptionId:e});ct.success(i.message),s(!1),n(),o()}catch(i){ct.error(i instanceof Error?i.message:"An error ocurred"),s(!1)}},size:"x-small",isLoading:r,disabled:r,children:"Next"})]}),showCloseButton:!1,className:"bg-metrifox-white",children:[a.jsx(W,{variant:"body4",color:"text-metrifox-black",children:"Keep subscription active?"}),a.jsx(W,{variant:"body4",color:"text-metrifox-black",className:"mt-5",children:"The subscription would keep going and renew as usual."})]})},ng=({subscription:e})=>{const[t,n]=p.useState(!1),[r,s]=p.useState(!1);return a.jsxs(j,{children:[e?.ends_at?a.jsx(j,{onClick:()=>s(!0),className:"cursor-pointer",children:a.jsx(W,{variant:"body6",className:"text-metrifox-danger",children:"Undo cancellation"})}):a.jsx(j,{onClick:()=>n(!0),className:"cursor-pointer",children:a.jsx(W,{variant:"body6",className:"text-metrifox-danger",children:"Cancel subscription"})}),a.jsx(Qm,{subscriptionId:e?.id,isOpen:t,onClose:()=>n(!1)}),a.jsx(tg,{subscriptionId:e?.id,isOpen:r,onClose:()=>s(!1)})]})},rg=({subscriptionLineItems:e,handleUpdateQuantity:t,canUpdateQuantities:n})=>{const[r,s]=p.useState(!1),o=e[0];return a.jsxs(j,{children:[a.jsxs(j,{className:"bg-grey-200 rounded-t-2xl px-3 pt-2.5 pb-4 mt-4 flex items-center justify-between cursor-pointer",onClick:()=>s(!r),children:[a.jsx(U,{variant:"label8",className:"text-grey-500 font-medium",children:"Items"}),a.jsxs(j,{className:"flex gap-x-2",children:[n&&a.jsx(Ps,{className:"!text-metrifox-blue underline cursor-pointer",onClick:i=>{i?.stopPropagation(),t()},children:"Update items"}),a.jsx("span",{className:`transform transition-transform duration-300 ${r?"rotate-180":"rotate-0"}`,children:a.jsx(be,{name:"arrow-down",size:14,color:"grey-500"})})]})]}),a.jsx(j,{className:"bg-metrifox-white rounded-2xl p-2 -mt-2.5 space-y-2",children:r?a.jsx(a.Fragment,{children:e?.map((i,l)=>a.jsx(j,{className:"bg-grey-50 border border-grey-200 rounded-lg p-2 flex justify-between",children:a.jsxs(j,{className:"w-full flex items-center justify-between",children:[a.jsx(j,{className:"flex items-center gap-4",children:a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(U,{variant:"label8",className:"text-grey-800 font-medium",children:Dt(i?.name)}),i?.is_addon&&a.jsx(un,{size:"small",background:"bg-grey-300",textColor:"text-metrifox-black",children:"Add-on"})]})}),a.jsxs(W,{variant:"body6",className:"text-grey-800 font-medium",children:[Pt(i?.currency_code),(i?.unit_price||i?.total_amount)?.toFixed(2)]})]})},l))}):a.jsxs(j,{className:"bg-grey-100 rounded-lg p-2 flex items-center justify-between cursor-pointer",children:[a.jsxs(U,{variant:"label8",className:"text-grey-800 font-medium",children:[o?.name," ",a.jsx("span",{children:"\u2022"})," ",e.length," item(s)"]}),a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsxs(W,{variant:"body6",className:"text-grey-800 font-medium",children:[Pt(o?.currency_code),(o?.unit_price||o?.total_amount)?.toFixed(2)]}),a.jsxs(W,{variant:"body6",className:"text-metrifox-blue",children:["+ ",e.length-1," prices(s)"]})]})]})})]})},sg=({subscription:e,tenantDetails:t})=>{const n=e?.status,{text:r,color:s}=l6(n),{customerKey:o}=en(),i=u=>u?Io(u.split("T")[0]):"nil",l=[{label:"Current plan",value:`${e?.plan_name||"-"}`},{label:"Status",value:a.jsx(un,{size:"small",background:s,textColor:"text-metrifox-white",children:Dt(r)||"-"})},{label:"Start date",value:i(e?.starts_at)},...n===At.IN_TRIAL?[{label:"Trial period",value:e?.starts_at&&e?.trial_end_date?a.jsxs(U,{variant:"label7",className:"text-grey-600",children:[i(e?.starts_at)," -"," ",i(e?.trial_end_date)]}):"-"}]:[],...n===At.ACTIVE?[{label:"Renewal date",value:e?.renews_at?i(e?.renews_at):"-"}]:[],...n===At.ACTIVE?[{label:"Current billing period",value:e?.current_billing_period_start&&e?.current_billing_period_end?a.jsxs(j,{children:[a.jsxs(U,{variant:"label7",className:"text-grey-600",children:[i(e.current_billing_period_start)," -"," ",i(e.current_billing_period_end)]}),a.jsx(un,{size:"small",background:"bg-grey-200",textColor:"text-metrifox-black",children:"Auto-renew"})]}):"-"}]:[],...n===At.ACTIVE?[{label:"Next billing date",value:e?.renews_at?i(e?.renews_at):"-"}]:[],...n===At.ACTIVE?[{label:"Next estimated bill",value:e?.next_billing_amount?a.jsx(j,{children:a.jsxs(U,{variant:"label7",className:"text-grey-600",children:[Pt(e.currency_code),e.next_billing_amount]})}):"-"}]:[]],c=()=>{const u=`${window.location.origin}/${t.tenant_checkout_username}/${e.offering_key}/subscriptions/${e.id}?customer=${o}`;window.open(u,"_blank","noopener,noreferrer")};return a.jsx(j,{children:a.jsxs(j,{className:"bg-grey-100 rounded-2xl p-4",children:[a.jsxs(j,{className:"flex items-center justify-between",children:[a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(j,{className:"p-1.5 bg-grey-200 rounded-lg",children:a.jsx(be,{name:"money",size:18,color:"grey-500"})}),a.jsx(U,{variant:"label7",className:"text-metrifox-black font-medium",children:"Subscription"})]}),a.jsx(Xm,{trigger:a.jsx(be,{name:"more",size:20,color:"grey-500"}),anchorTo:"bottom end",className:"bg-metrifox-white rounded-md shadow-md p-4",children:a.jsx(ng,{subscription:e})})]}),a.jsx(j,{className:"bg-grey-200 rounded-t-2xl px-3 pt-2.5 pb-4 mt-2",children:a.jsx(U,{variant:"label8",className:"text-grey-500 font-medium",children:"Details"})}),a.jsx(j,{className:"bg-metrifox-white flex justify-between flex-wrap gap-8 rounded-2xl p-4 -mt-2.5",children:l?.map((u,d)=>a.jsxs(j,{className:"",children:[a.jsx(U,{variant:"label8",className:"text-grey-500",children:u?.label}),a.jsx(U,{variant:"label7",className:`text-grey-600 font-medium mt-2 ${u?.value==="-"?"text-center":""}`,children:u?.value})]},d))}),e?.subscription_items?.length>0&&a.jsx(rg,{subscriptionLineItems:e?.subscription_items,handleUpdateQuantity:c,canUpdateQuantities:e?.can_update_quantities})]})})},og=({upcomingInvoice:e})=>{const[t,n]=p.useState(!1),r=p.useRef(null),{invoiceDetails:s}=e0({invoiceId:e?.invoice_id});return a.jsxs(j,{children:[a.jsxs(j,{className:"bg-grey-100 rounded-2xl p-4 w-full flex items-center justify-between",children:[a.jsxs(j,{className:"flex items-center gap-3",children:[a.jsx(U,{variant:"label7",className:"font-medium text-metrifox-black",children:"Upcoming Invoice"}),a.jsx(j,{className:"flex items-center gap-2",children:a.jsx(un,{background:"bg-purple-500",size:"small",children:a.jsxs(U,{variant:"label8",className:"text-metrifox-white",children:[e?.currency?.symbol,e?.amount]})})}),a.jsxs(W,{variant:"body6",className:"text-metrifox-black",children:["Due"," ",new Date(e?.due_date).toLocaleString(e?.currency?.country_code,{month:"short",day:"numeric",year:"numeric"})]})]}),a.jsx(Ps,{className:"!text-metrifox-blue underline cursor-pointer",onClick:()=>{n(!0)},children:"Preview invoice"})]}),t&&a.jsx(Qd,{isOpen:t,onClose:()=>n(!1),contentRef:r,content:a.jsx(i1,{data:s}),modalTitle:"Invoice preview"})]})},ig=({tenantDetails:e,subscription:t,wallet:n})=>{const[r,s]=p.useState(0),o=c=>c.allocations.map(u=>({creditedDate:u.credited_date,source:u.source,amount:u.amount,balance:u.balance_remaining,validUntil:u.valid_until})),i=[{header:"Credited date",render:c=>a.jsx(W,{variant:"body6",color:"text-grey-700",children:new Date(c.creditedDate).toString()})},{key:"source",header:"Source"},{header:"Amount",render:c=>a.jsx(W,{variant:"body6",color:"text-grey-700",children:me(c.amount)})},{header:"Balance",render:c=>a.jsx(W,{variant:"body6",color:"text-grey-700",children:me(c.balance)})},{header:"Valid until",render:c=>a.jsx(W,{variant:"body6",color:"text-grey-700",children:c.validUntil?new Date(c.validUntil).toLocaleDateString():"No expiration"})}],l=c=>{const u=`${window.location.origin}/${e.tenant_checkout_username}/checkout/${t.offering_key}?customer=${e.customer_key}&credit=${c}`;window.open(u,"_blank","noopener,noreferrer")};return!n||n.length===0?null:a.jsxs(j,{className:"bg-grey-100 rounded-2xl p-4",children:[a.jsxs(j,{className:"flex items-center gap-1",children:[a.jsx(j,{className:"p-1.5 bg-grey-200 rounded-lg",children:a.jsx(be,{name:"card-receive",size:16,color:"grey-500"})}),a.jsx(U,{variant:"label7",className:"text-metrifox-black font-medium",children:"Wallet balance"})]}),a.jsx(j,{className:"bg-metrifox-white rounded-2xl p-4 mt-2",children:n.length>1?a.jsxs(us,{defaultIndex:r,onChange:s,children:[a.jsx(ds,{className:"w-max bg-grey-100 border border-neutral-200 text-grey-500 px-1.5 py-1 rounded-2xl",children:n.map(c=>a.jsx(rr,{className:"w-max data-[selected]:bg-metrifox-primary data-[selected]:border data-[selected]:border-grey-200 outline-none data-[selected]:text-metrifox-white rounded-xl px-8 py-2",children:a.jsx(W,{variant:"body6",children:c.name})},c.id))}),a.jsx(fs,{children:n.map(c=>a.jsxs(Sn,{children:[a.jsx(j,{className:"bg-grey-100 rounded-lg p-6 mt-4",children:a.jsxs(j,{className:"w-full flex items-center justify-between gap-1",children:[a.jsxs(j,{className:"text-center",children:[a.jsx(j,{className:"flex items-center justify-center gap-1",children:a.jsx(U,{variant:"label8",className:"text-grey-500 font-medium",children:"Total available balance"})}),a.jsxs(j,{className:"flex items-baseline justify-center gap-1",children:[a.jsx(U,{variant:"label6",className:"text-neutral-800 font-medium",children:me(c.balance)}),a.jsx(U,{variant:"label8",className:"text-grey-500 mt-3.5",children:c.name})]})]}),a.jsx(Cr,{type:"button",size:"small",onClick:()=>l(c.credit_key),className:"text-metrifox-white",children:"Top up"})]})}),a.jsx(wr,{columns:i,data:o(c)})]},c.id))})]}):n[0]&&a.jsxs(a.Fragment,{children:[a.jsx(j,{className:"bg-grey-100 rounded-lg p-6 mt-4",children:a.jsxs(j,{className:"w-full flex items-center justify-between gap-1",children:[a.jsxs(j,{className:"text-center",children:[a.jsx(j,{className:"flex items-center justify-center gap-1",children:a.jsx(U,{variant:"label8",className:"text-grey-500 font-medium",children:"Total available balance"})}),a.jsxs(j,{className:"flex items-baseline justify-center gap-1",children:[a.jsx(U,{variant:"label6",className:"text-neutral-800 font-medium",children:me(n[0].balance)}),a.jsx(U,{variant:"label8",className:"text-grey-500 mt-3.5",children:n[0].name})]})]}),a.jsx(Cr,{type:"button",size:"small",onClick:()=>n[0]?.id&&l(n[0].id),className:"text-metrifox-white",children:"Top up"})]})}),a.jsx(wr,{columns:i,data:o(n[0])})]})})]})},ag=[{key:"upcomingInvoice"},{key:"subscription"},{key:"creditBalance"},{key:"entitlementUsage"},{key:"paymentOverview"},{key:"billingHistory"},{key:"plan"}],lg={upcomingInvoice:"upcoming-invoice",subscription:"subscription",creditBalance:"credit-balance",entitlementUsage:"entitlement-usage",paymentOverview:"payment-overview",billingHistory:"billing-history",plan:"plan"},l0=({product:e,tenantDetails:t,sectionsConfig:n})=>{const r=n||ag,s={upcomingInvoice:()=>e?.subscription?.upcoming_invoice?a.jsx(og,{upcomingInvoice:e.subscription.upcoming_invoice}):null,subscription:()=>e?.subscription?a.jsx(sg,{subscription:e.subscription,tenantDetails:t}):null,creditBalance:()=>e?.wallets?.length>0?a.jsx(ig,{subscription:e.subscription,tenantDetails:t,wallet:e.wallets}):null,entitlementUsage:()=>e?.entitlements?.length>0?a.jsx(im,{entitlements:e.entitlements}):null,paymentOverview:()=>a.jsx(am,{paymentMethod:e.payment_method,tenantDetails:t}),billingHistory:()=>e?.subscription?.id?a.jsx(rm,{subscriptionId:e.subscription?.id}):null,plan:()=>e?.product_key?a.jsx(Gm,{planName:e?.subscription?.plan_name,productKey:e?.product_key}):null};return a.jsxs(j,{className:"space-y-4",children:[r.filter(o=>!o.hidden).map(o=>{const i=lg[o.key]??o.key;if(o.component)return a.jsx("section",{id:i,className:"space-y-4",children:a.jsx(o.component,{product:e,tenantDetails:t,...o.props})},o.key);const l=s[o.key],c=l?l(o.props):null;return c?a.jsx("section",{id:i,children:c},o.key):null}),a.jsx(qm,{})," "]})},cg=({customerKey:e,sectionsConfig:t})=>{const[n,r]=p.useState(0),{setCustomerKey:s,setCustomerRefetch:o}=en(),{customerDetails:i,error:l,refetch:c,isLoading:u}=K9({customerKey:e});if(p.useEffect(()=>{s(e),o(c)},[]),l)return a.jsx(j,{className:"max-w-[60rem] mx-auto py-6 px-4",children:a.jsxs("div",{className:"bg-red-50 p-4 rounded-lg text-red-700",children:["Error loading customer details: ",l]})});if(u||!i)return a.jsx(j,{className:"max-w-[60rem] mx-auto py-6 px-4",children:a.jsxs("div",{className:"animate-pulse space-y-4",children:[a.jsx("div",{className:"h-12 bg-gray-200 rounded-lg"}),a.jsx("div",{className:"h-16 bg-gray-200 rounded-lg"}),[1,2,3,4,5].map(m=>a.jsx("div",{className:"h-48 bg-gray-200 rounded-lg"},m))]})});const{subscriptions:d,...f}=i||{},h=d||[];return a.jsx(Df,{children:a.jsx(j,{className:"max-w-[60rem] mx-auto py-6 px-4 space-y-4",children:h&&h.length>1?a.jsxs(us,{defaultIndex:n,onChange:m=>r(m),children:[a.jsx(ds,{className:"w-max bg-grey-100 border border-grey-200 text-grey-500 px-1.5 py-1 mb-4 rounded-2xl",children:h.map(m=>a.jsx(rr,{className:"w-max data-[selected]:bg-metrifox-primary data-[selected]:border data-[selected]:border-grey-200 outline-none data-[selected]:text-metrifox-white rounded-xl px-8 py-2",children:a.jsx(W,{variant:"body6",children:m.product_name})},m.product_key))}),a.jsx(fs,{children:h.map(m=>a.jsx(Sn,{children:a.jsx(l0,{product:m,tenantDetails:f,sectionsConfig:t})},m.product_key))})]}):a.jsx(a.Fragment,{children:h.map(m=>a.jsx(l0,{product:m,tenantDetails:f,sectionsConfig:t},m.product_key))})})})};exports.CustomerPortal=cg,exports.metrifoxInit=tf;
|