1import{j as s}from"./jsx-runtime-BjG_zV1W.js";import{j as y,r as n,i as C}from"./chunk-KS7C4IRE-BIdQG7so.js";import{c as D}from"./ClassesUtils-2dOUpm6k.js";import{C as F,T,a as M,D as B}from"./CurrencyToggle-Bsx5jn8i.js";import{P as I}from"./PricingModel-ClvOw3yK.js";import{a as E,d as O}from"./PricingHelper-DwcaCxt6.js";import{M as k}from"./Modal-BiZX0Gu0.js";import{T as R}from"./TableSimple-uhVPHTLy.js";import{C as U}from"./CreditType-CGQ7bMVD.js";import{N as L}from"./NumberUtils-DfXvstXl.js";import{u as z}from"./useTranslation-CaKQvU12.js";import{P as Y}from"./PreDowngradeModal-Dr9ElKvZ.js";import{S as q}from"./SubscriptionBillingPeriod-CGITvcWi.js";function G({items:i,tenantSubscription:a,canSubmit:P,className:w,stripeCoupon:f,currenciesAndPeriod:l,onClickFeature:N,onDowngrade:b}){const[u,h]=y(),[g]=n.useState(i),[c,x]=n.useState(l.currencies.value),[m,p]=n.useState(l.billingPeriods.value);n.useEffect(()=>{c!==l.currencies.value&&x(l.currencies.value)},[l.currencies.value]);function j(){let r=[];return g.filter(e=>e.model!==I.ONCE).forEach(e=>{const t=e.prices;r=r.concat(t)}),r}function S(r){const e=a?.products.find(t=>t.subscriptionProductId===r.id);return!!(e&&e.cancelledAt===null)}function v(r){const e=a?.products.find(t=>t.cancelledAt===null)?.subscriptionProduct;if(e)return r.order>e.order?{upgrade:!0}:{downgrade:!0}}return s.jsxs("div",{className:D(w,i.length===1&&"mx-auto max-w-2xl"),children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("div",{children:s.jsx(F,{value:c,setValue:r=>{u.set("c",r.toString()),h(u,{preventScrollReset:!0}),x(r)},possibleCurrencies:l.currencies.options,darkMode:!0})}),s.jsx("div",{children:s.jsx(T,{currency:c,products:i,size:"sm",billingPeriod:m,onChange:r=>{u.set("b",O(r)),h(u,{preventScrollReset:!0}),p(r)},yearlyDiscount:E(j(),c),possibleBillingPeriods:l.billingPeriods.options,darkMode:!0})})]}),s.jsx("div",{className:D("grid gap-6 lg:gap-3",i.length===2&&"lg:grid-cols-2 xl:grid-cols-2",i.length===3&&"lg:grid-cols-3 xl:grid-cols-3",i.length===4&&"lg:grid-cols-4 xl:grid-cols-4",i.length===5&&"lg:grid-cols-4 xl:grid-cols-4",i.length===6&&"lg:grid-cols-3 xl:grid-cols-3",i.length===7&&"lg:grid-cols-3 xl:grid-cols-3",i.length>=8&&"lg:grid-cols-3 xl:grid-cols-3"),children:g.map((r,e)=>s.jsx(M,{className:D((g.length===1||g.length===4&&e===3)&&"lg:col-span-1"),product:r,title:r.title,description:r.description??void 0,badge:r.badge??void 0,features:r.features,billingPeriod:m,currency:c,prices:r.prices,model:r.model,usageBasedPrices:r.usageBasedPrices,alreadyOwned:S(r),canSubmit:P,isUpgrade:v(r)?.upgrade,isDowngrade:v(r)?.downgrade,stripeCoupon:f,onClickFeature:N,onDowngrade:b},e))})]})}function H(){const{t:i}=z();return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsx("h3",{className:"text-lg font-medium",children:i("models.credit.whatIs")}),s.jsx("p",{className:"text-muted-foreground text-sm",children:i("models.credit.info")})]}),s.jsx(R,{items:U,headers:[{name:"name",title:i("shared.name"),className:"w-full",value:a=>s.jsxs("div",{className:"flex flex-col",children:[s.jsx("div",{className:"font-bold",children:a.name}),s.jsx("div",{className:"text-muted-foreground text-xs",children:a.description})]})},{name:"amount",title:i("models.credit.plural"),align:"right",value:a=>L.intFormat(a.amount)}]})]})}function te({items:i,tenantSubscription:a,canSubmit:P,stripeCoupon:w,currenciesAndPeriod:f,bots:l,effectiveDate:N}){const b=C(),[u,h]=n.useState(!1),[g,c]=n.useState(null),[x,m]=n.useState(!1),[p,j]=n.useState(null),S=()=>{const e=[];return i.forEach(t=>{let o=e.find(d=>d.group.title===t.groupTitle&&d.group.description===t.groupDescription);o||(o=e.find(d=>!d.group.title&&!d.group.description&&!t.groupTitle&&!t.groupDescription)),o?o.items.push(t):e.push({group:{title:t.groupTitle??"",description:t.groupDescription??""},items:[t]})}),e},v=e=>(e.title?.toLowerCase().includes("free")||e.prices.some(o=>Number(o.price)===0))&&l&&l.length>1?(j(e),m(!0),!1):!0,r=()=>{if(!p)return;const e=new FormData;e.set("action","subscribe"),e.set("product-id",p.id?.toString()??"");const o=p.title?.toLowerCase().includes("free")||p.prices.some(d=>Number(d.price)===0)?q.MONTHLY:f.billingPeriods.value;e.set("billing-period",o.toString()),e.set("currency",f.currencies.value),e.set("quantity","1"),e.set("is-downgrade","true"),b(e,{method:"post"}),m(!1),j(null)};return s.jsxs(n.Fragment,{children:[s.jsx("div",{className:"space-y-10",children:S().map((e,t)=>s.jsx(n.Fragment,{children:s.jsxs("div",{children:[e.group.title&&s.jsx("div",{className:"py-4",children:s.jsxs("div",{className:"py-2",children:[s.jsx("h2",{className:"text-2xl font-bold md:text-3xl",children:e.group.title}),s.jsx("p",{className:"text-muted-foreground text-lg",children:e.group.description})]})}),s.jsx(G,{items:e.items,tenantSubscription:a,canSubmit:P,className:"space-y-4",stripeCoupon:w,currenciesAndPeriod:f,onClickFeature:o=>{c(o),h(!0)},onDowngrade:v},t)]})},t))}),s.jsx(k,{size:"lg",open:u,setOpen:()=>h(!1),children:g===B.Credits&&s.jsx("div",{children:s.jsx(H,{})})}),l&&l.length>1&&s.jsx(Y,{open:x,setOpen:m,bots:l,effectiveDate:N||null,onConfirm:r})]})}
1export{te as P};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.