1import{c as Ae,r as g,j as e,u as Xe,k as gt,R as b,g as xt,a as yt,b as bt,B as fe,i as jt}from"./index-Bv3Bofm-.js";import{P as Y}from"./menuConfig-DwuokZsG.js";import{C as z,a as J,b as X,d as se,c as H,e as Qe}from"./card-DRGG1H-p.js";import{B as _}from"./button-l8E7qKOZ.js";import{B as re}from"./badge-DbmeN09M.js";import{A as q,a as V,b as vt}from"./alert-hpef4MLH.js";import{u as ie}from"./useTranslation-DVry60RK.js";import{C as Ze}from"./clock-sKPAANle.js";import{M as et}from"./monitor-CW5frXuZ.js";import{H as Nt}from"./hard-drive-G1LWlxDI.js";import{c as St}from"./createLucideIcon-CWJ9Sf_H.js";import{R as Re}from"./receipt-CPWpcELp.js";import{D as Ct,f as _t,a as Pt,b as wt,c as Et,d as kt}from"./dialog-4CO45iY9.js";import{a as At,b as Rt,u as Tt,d as Dt,c as It,f as Lt}from"./billing-DQQauTBr.js";import{L as Oe}from"./label-Bfn7I16c.js";import{C as Ot}from"./checkbox-BlacNvLf.js";import{S as tt}from"./shield-BGGcYH1A.js";import{T as Mt}from"./Trans-DMDU937o.js";import{C as Pe}from"./circle-alert-CtTt19vu.js";import{L as Te}from"./loader-circle-DI5IRqPf.js";import{T as ge}from"./triangle-alert-QteJ9e4A.js";import{C as ue}from"./circle-check-big-CGVxtbaR.js";import{P as Me}from"./plus-DHZwBb2L.js";import{C as De}from"./credit-card-CXE4Q0la.js";import{S as Ue}from"./star-CTTlMLhW.js";import{C as Ut}from"./calendar-Bu-_-TZH.js";import{T as Ft}from"./trash-2-CGRsUgki.js";import{C as Bt}from"./ChangeScreensDialog-DNX0MZDq.js";import{g as $t,b as Wt,d as st,e as Gt}from"./subscription-DuTIF8LC.js";import{A as Ie}from"./arrow-right-BJb7u8q5.js";import{D as Le}from"./download-Bqm6M6NX.js";import{C as be}from"./circle-check-CxxiAtEC.js";import{X as rt}from"./x-CPPa5Rss.js";import{S as qt}from"./settings-BAIBscSa.js";import{E as Vt}from"./external-link-D4bKnSAC.js";import{F as we}from"./file-text-KpNSvRQz.js";import"./utils-CBfrqCZ4.js";import"./index-B0S7T6Iq.js";import"./index-CdJFUDDL.js";import"./index-7sSK0Fxm.js";import"./index-Dc_FVRD7.js";import"./index-D__OmZ0k.js";import"./index-FW9E5kpD.js";import"./Combination-bWOQ-6ny.js";import"./index-DiiLNpaU.js";import"./index-DUG1lxBv.js";import"./index-CjWMj8Jq.js";import"./index-BTMm7jbm.js";import"./check-M8j5DP2u.js";import"./input-CztKq6sQ.js";import"./trending-down-DmNbQmO1.js";import"./trending-up-BfvDorTZ.js";import"./zap-uhGbQVJd.js";const zt=[["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M3 10h18",key:"8toen8"}],["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M17 14h-6",key:"bkmgh3"}],["path",{d:"M13 18H7",key:"bb0bb7"}],["path",{d:"M7 14h.01",key:"1qa3f1"}],["path",{d:"M17 18h.01",key:"1bdyru"}]],Ht=St("calendar-range",zt);async function Kt(t){const{data:s}=await Ae.get("/subscriptions/plans",{params:{product_type:t}}),n=(Array.isArray(s)?s:[]).find(a=>a.is_default_for_product);if(!n){const a=new Error(`No default plan for product_type=${t}`);throw a.code="no_default_plan",a}return n}async function Yt({productType:t,stripePriceId:s,billingCycle:r,successUrl:n,cancelUrl:a}){const{data:i}=await Ae.post("/subscriptions/add-product",{product_type:t,stripe_price_id:s,billing_cycle:r,success_url:n,cancel_url:a});return i}async function Jt({returnUrl:t}={}){const s=t?{return_url:t}:void 0,{data:r}=await Ae.post("/subscriptions/billing-portal",null,{params:s});return r}const Xt={ACTIVE:"active",TRIAL:"trial",TRIALING:"trial",PENDING_PAYMENT:"pendingPayment",CANCELLED:"cancelled",EXPIRED:"expired",SUSPENDED:"suspended"};function Qt(t){return t==="hu"?"hu-HU":t==="en"?"en-US":"ro-RO"}function ne(t,s){if(!t)return null;try{return new Date(t).toLocaleDateString(s,{year:"numeric",month:"short",day:"numeric"})}catch{return null}}function Zt(t){if(!t)return null;const s=new Date(t).getTime();return Number.isNaN(s)?null:Math.ceil((s-Date.now())/(1440*60*1e3))}function es(t,s,r){if(t==null)return null;try{return new Intl.NumberFormat(r,{style:"currency",currency:s||"EUR"}).format(t)}catch{return`${Number(t).toFixed(2)} ${s||""}`.trim()}}function ts(t,s){const r=[];return t==="digital_signage"?(s.number_of_screens!=null?r.push({key:"contractedScreens",count:s.number_of_screens}):s.max_screens!=null&&r.push({key:"screens",count:s.max_screens}),s.allocated_storage_gb!=null&&s.allocated_storage_gb>=0?r.push({key:"storage",count:s.allocated_storage_gb}):s.allocated_storage_gb==null&&s.max_storage_gb!=null&&r.push({key:"storage",count:s.max_storage_gb})):t==="remote_desktop"&&(s.max_machines!=null&&r.push({key:"machines",count:s.max_machines}),s.max_team_members!=null&&r.push({key:"teamMembers",count:s.max_team_members}),s.max_concurrent_sessions!=null&&r.push({key:"concurrentSessions",count:s.max_concurrent_sessions})),r}function ss({sub:t,locale:s,t:r}){const n=t.storage_used_mb!=null?t.storage_used_mb/1024:null,a=t.allocated_storage_gb===-1,i=ne(t.current_period_start,s),l=ne(t.current_period_end,s),f=ne(t.next_billing_date,s),o=String(t.billing_cycle||"MONTHLY").toLowerCase()==="annual"?"annual"
1:"monthly",m=es(t.total_price,t.price_currency,s),c=t.status==="TRIAL";return e.jsxs("div",{"data-testid":"signage-contracted-resources",className:"space-y-1.5 text-sm text-slate-700 dark:text-slate-200",children:[e.jsxs("p",{className:"flex items-center gap-2",children:[e.jsx(et,{className:"h-4 w-4 shrink-0 text-slate-400"}),e.jsx("span",{children:r("subscriptionsPage.card.resources.screens",{count:t.number_of_screens,used:t.screens_used??0})})]}),e.jsxs("p",{className:"flex items-center gap-2",children:[e.jsx(Nt,{className:"h-4 w-4 shrink-0 text-slate-400"}),e.jsx("span",{children:a?r("subscriptionsPage.card.resources.storageUnlimited"):r("subscriptionsPage.card.resources.storage",{total:t.allocated_storage_gb,used:n!=null?n.toFixed(n>=10?0:2):"0"})})]}),i&&l&&!c&&e.jsxs("p",{className:"flex items-center gap-2",children:[e.jsx(Ht,{className:"h-4 w-4 shrink-0 text-slate-400"}),e.jsx("span",{children:r("subscriptionsPage.card.resources.paidPeriod",{from:i,to:l})})]}),f&&!c&&e.jsxs("p",{className:"flex items-center gap-2",children:[e.jsx(Ze,{className:"h-4 w-4 shrink-0 text-slate-400"}),e.jsx("span",{children:r("subscriptionsPage.card.resources.nextBilling",{date:f})})]}),m&&!c&&e.jsxs("p",{className:"flex items-center gap-2",children:[e.jsx(Re,{className:"h-4 w-4 shrink-0 text-slate-400"}),e.jsxs("span",{children:[r("subscriptionsPage.card.resources.price",{amount:m,cycle:r(`subscriptionsPage.billingCycle.${o}`)})," ",r("profile.vatSuffix")]})]})]})}function rs({product:t,signageSubscription:s=null,onChangeScreens:r=null,onCancelPending:n=null}){const{t:a,i18n:i}=ie(),[l,f]=g.useState(!1),[o,m]=g.useState(null),c=t?.subscription;if(!c)return null;const p=Qt(i.language),d=c.status??"unknown",S=Xt[String(d).toUpperCase()]??"unknown",x=a(`subscriptionsPage.card.status.${S}`),j=String(d).toUpperCase().startsWith("TRIAL"),E=j?Zt(c.trial_ends_at):null,k=ne(c.current_period_end??c.next_renewal_at,p),te=ne(c.trial_ends_at,p),U=c.has_stripe_billing===!0,F=t.type==="digital_signage",R=F?s:null,B=ts(t.type,c),Q=c.payment_method==="INVOICE_BANK"||c.payment_method==="INVOICE_CARD",h=!U&&!Q,v=!U&&Q,P=R?.pending_number_of_screens??c.pending_number_of_screens,w=ne(R?.pending_changes_effective_date??c.pending_changes_effective_date,p),M=P!=null&&w!=null,$=F&&typeof r=="function"&&["ACTIVE","TRIAL"].includes(String(d).toUpperCase()),W=async()=>{m(null),f(!0);try{const{portal_url:T}=await Jt({returnUrl:`${window.location.origin}/profile`});if(!T)throw new Error(a("subscriptionsPage.card.portalError"));window.location.href=T}catch(T){const Z=T?.response?.data?.detail??T?.message??a("subscriptionsPage.card.portalError");m(typeof Z=="string"?Z:JSON.stringify(Z)),f(!1)}},I=c.billing_cycle?a(`subscriptionsPage.billingCycle.${String(c.billing_cycle).toLowerCase()}`,{defaultValue:String(c.billing_cycle).toLowerCase()}):null;return e.jsxs(z,{"data-testid":"active-subscription-card","data-product":t.type,"data-status":d,className:"border-t-[3px]",style:{borderTopColor:t.accent_color??t.accentColor},children:[e.jsxs(J,{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(X,{children:t.name}),e.jsx(re,{"data-testid":"active-subscription-status-badge",style:{backgroundColor:t.accent_color??t.accentColor},className:"text-white",children:x})]}),e.jsxs(se,{children:[c.plan_name,c.is_grandfathered&&e.jsx("span",{className:"ml-2 text-xs uppercase tracking-wide text-slate-500 dark:text-slate-400",children:a("subscriptionsPage.card.grandfathered")})]}),c.is_auto_granted&&e.jsx("p",{"data-testid":"active-subscription-auto-granted-note",className:"text-xs text-slate-500 dark:text-slate-400",children:a("subscriptionsPage.card.autoGrantedNote")})]}
1),e.jsxs(H,{className:"text-sm text-slate-600 dark:text-slate-300 space-y-2",children:[R?e.jsx(ss,{sub:R,locale:p,t:a}):B.length>0&&e.jsx("ul",{"data-testid":"active-subscription-quotas",className:"list-disc pl-5 space-y-0.5 text-slate-700 dark:text-slate-200",children:B.map(T=>e.jsx("li",{children:a(`subscriptionsPage.quotas.${T.key}`,{count:T.count})},T.key))}),M&&e.jsxs(q,{"data-testid":"pending-change-banner",className:"border-amber-300 bg-amber-50 dark:bg-amber-950/20",children:[e.jsx(Ze,{className:"h-4 w-4 text-amber-600"}),e.jsx(V,{children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm text-amber-900 dark:text-amber-100",children:a("subscriptionsPage.card.pendingChange",{date:w,count:P})}),typeof n=="function"&&e.jsx(_,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:n,children:a("subscriptionsPage.card.cancelPendingChange")})]})})]}),j&&E!==null&&e.jsx("p",{children:a("subscriptionsPage.card.trialEndsIn",{count:E,date:te??""})}),!R&&U&&I&&e.jsx("p",{children:a("subscriptionsPage.card.billingCycle",{cycle:I})}),!R&&U&&k&&e.jsx("p",{children:a("subscriptionsPage.card.nextRenewal",{date:k})}),h&&e.jsx("p",{"data-testid":"active-subscription-free-tier-banner",className:"text-xs text-slate-500 dark:text-slate-400",children:c.is_grandfathered?a("subscriptionsPage.card.grandfatheredNote"):a("subscriptionsPage.card.freeTier")}),v&&e.jsx("p",{"data-testid":"active-subscription-invoice-banner",className:"text-xs text-slate-500 dark:text-slate-400",children:c.payment_method==="INVOICE_CARD"?a("subscriptionsPage.card.invoiceCardNote"):a("subscriptionsPage.card.invoiceBankNote")})]}),e.jsxs(Qe,{className:"flex flex-wrap gap-x-3 gap-y-1",children:[$&&e.jsxs(_,{"data-testid":"change-screens-button",variant:"secondary",onClick:r,children:[e.jsx(et,{className:"mr-2 h-4 w-4"}),a("subscriptionsPage.card.changeScreens")]}),U&&e.jsxs(e.Fragment,{children:[e.jsx(_,{onClick:W,disabled:l,"aria-busy":l,children:a(l?"subscriptionsPage.card.managing":"subscriptionsPage.card.manage")}),e.jsx("p",{"data-testid":"active-subscription-manage-caption",className:"basis-full text-xs text-slate-500 dark:text-slate-400",children:a("subscriptionsPage.card.manageCaption")})]}),o&&e.jsx("p",{role:"alert",className:"basis-full text-sm text-red-600 dark:text-red-400 mt-1",children:o})]})]})}const ns="monthly";function as(t){return`${window.location.origin}/subscriptions?welcome=${t}`}function is(){return`${window.location.origin}/profile`}function os({product:t}){const{t:s}=ie(),{user:r,refreshProducts:n}=Xe(),i=(r?.available_products??[]).includes(t.type),[l,f]=g.useState(!1),[o,m]=g.useState(null);if(i)return null;const c=async()=>{m(null),f(!0);try{const p=t.defaultStripePriceId??(await Kt(t.type)).stripe_price_id_monthly;if(!p)throw Object.assign(new Error(s("subscriptionsPage.crossSell.missingPriceId")),{code:"missing_price_id"});const{checkout_url:d}=await Yt({productType:t.type,stripePriceId:p,billingCycle:ns,successUrl:as(t.type),cancelUrl:is()});window.location.href=d}catch(p){if(p?.response?.status===409){try{await n?.()}finally{window.location.reload()}return}const d=p?.response?.data?.detail?.message??p?.message??s("subscriptionsPage.crossSell.startError");m(d),f(!1)}};return e.jsxs(z,{"data-testid":"product-cross-sell-card","data-product":t.type,className:"border-dashed border-2",style:{borderColor:t.accentColor},children:[e.jsxs(J,{className:"space-y-2",children:[e.jsx(re,{className:"w-fit text-white",style:{backgroundColor:t.accentColor},children:s("subscriptionsPage.crossSell.newBadge")}),e.jsx(X,{children:t.name}),e.jsx(se,{children:t.tagline})]}),t.description&&e.jsx(H,{children:e.jsx("p",{className:"text-sm text-slate-600 dark:text-slate-300",children:t.description})}),e.jsxs(Qe,{className:"flex flex-wrap gap-2",children:[e.jsx(_,{onClick:c,disabled:l,"aria-busy":l,style:{backgroundColor:t.accentColor,color:"white"},children:s(l?"subscriptionsPage.crossSell.starting":"subscriptionsPage.crossSell.startTrial")}),t.marketingUrl&&e.jsx(_,{variant:"outline",asChild:!0,children:e.jsx("a",{href:t.marketingUrl,target:"_blank",rel:"noopener noreferrer",children:s("subscriptionsPage.crossSell.learnMore")})}),o&&e.jsx("p",{role:"alert",className:"basis-full text-sm text-red-600 dark:text-red-400 mt-1",children:o})]})]})}var Se={exports:{}},Ce,Fe;function cs(){if(Fe)return Ce;Fe=1;var t="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";return Ce=t,Ce}var _e,Be;function ls(){if(Be)return _e;Be=1;var t=cs();function s(){}function r(){}return r.resetWarningCache=s,_e=function(){function n(l,f,o,m,c,p){if(p!==t){var d=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw d.name="Invariant Violation",d}}n.isRequired=n;function a(){return n}var i={array:n,bigint:n,bool:n,func:n,number:n,object:n,string:n,symbol:n,any:n,arrayOf:a,element:n,elementType:n,instanceOf:a,node:n,objectOf:a,oneOf:a,oneOfType:a,shape:a,exact:a,checkPropTypes:r,resetWarningCache:s};return i.PropTypes=i,i},_e}var $e;
1function ds(){return $e||($e=1,Se.exports=ls()()),Se.exports}var us=ds();const y=gt(us);function We(t,s){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);s&&(n=n.filter(function(a){return Object.getOwnPropertyDescriptor(t,a).enumerable})),r.push.apply(r,n)}return r}function Ge(t){for(var s=1;s<arguments.length;s++){var r=arguments[s]!=null?arguments[s]:{};s%2?We(Object(r),!0).forEach(function(n){nt(t,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):We(Object(r)).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(r,n))})}return t}function je(t){"@babel/helpers - typeof";return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?je=function(s){return typeof s}:je=function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},je(t)}function nt(t,s,r){return s in t?Object.defineProperty(t,s,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[s]=r,t}function ms(t,s){if(t==null)return{};var r={},n=Object.keys(t),a,i;for(i=0;i<n.length;i++)a=n[i],!(s.indexOf(a)>=0)&&(r[a]=t[a]);return r}function ps(t,s){if(t==null)return{};var r=ms(t,s),n,a;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(a=0;a<i.length;a++)n=i[a],!(s.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(t,n)&&(r[n]=t[n])}return r}function at(t,s){return fs(t)||hs(t,s)||gs(t,s)||xs()}function fs(t){if(Array.isArray(t))return t}function hs(t,s){var r=t&&(typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"]);if(r!=null){var n=[],a=!0,i=!1,l,f;try{for(r=r.call(t);!(a=(l=r.next()).done)&&(n.push(l.value),!(s&&n.length===s));a=!0);}catch(o){i=!0,f=o}finally{try{!a&&r.return!=null&&r.return()}finally{if(i)throw f}}return n}}function gs(t,s){if(t){if(typeof t=="string")return qe(t,s);var r=Object.prototype.toString.call(t).slice(8,-1);if(r==="Object"&&t.constructor&&(r=t.constructor.name),r==="Map"||r==="Set")return Array.from(t);if(r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return qe(t,s)}}function qe(t,s){(s==null||s>t.length)&&(s=t.length);for(var r=0,n=new Array(s);r<s;r++)n[r]=t[r];return n}function xs(){throw new TypeError(`Invalid attempt to destructure non-iterable instance. 2In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var D=function(s,r,n){var a=!!n,i=b.useRef(n);b.useEffect(function(){i.current=n},[n]),b.useEffect(function(){if(!a||!s)return function(){};var l=function(){i.current&&i.current.apply(i,arguments)};return s.on(r,l),function(){s.off(r,l)}},[a,r,s,i])},Ee=function(s){var r=b.useRef(s);return b.useEffect(function(){r.current=s},[s]),r.current},ae=function(s){return s!==null&&je(s)==="object"},ys=function(s){return ae(s)&&typeof s.then=="function"},bs=function(s){return ae(s)&&typeof s.elements=="function"&&typeof s.createToken=="function"&&typeof s.createPaymentMethod=="function"&&typeof s.confirmCardPayment=="function"},Ve="[object Object]",js=function t(s,r){if(!ae(s)||!ae(r))return s===r;var n=Array.isArray(s),a=Array.isArray(r);if(n!==a)return!1;var i=Object.prototype.toString.call(s)===Ve,l=Object.prototype.toString.call(r)===Ve;if(i!==l)return!1;if(!i&&!n)return s===r;var f=Object.keys(s),o=Object.keys(r);if(f.length!==o.length)return!1;for(var m={},c=0;c<f.length;c+=1)m[f[c]]=!0;for(var p=0;p<o.length;p+=1)m[o[p]]=!0;var d=Object.keys(m);if(d.length!==f.length)return!1;var S=s,x=r,j=function(k){return t(S[k],x[k])};return d.every(j)},it=function(s,r,n){return ae(s)?Object.keys(s).reduce(function(a,i){var l=!ae(r)||!js(s[i],r[i]);return n.includes(i)?(l&&console.warn("Unsupported prop change: options.".concat(i," is not a mutable property.")),a):l?Ge(Ge({},a||{}),{},nt({},i,s[i])):a},null):null},ot="Invalid prop `stripe` supplied to `Elements`. We recommend using the `loadStripe` utility from `@stripe/stripe-js`. See https://stripe.com/docs/stripe-js/react#elements-props-stripe for details.",ze=function(s){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:ot;if(s===null||bs(s))return s;throw new Error(r)},vs=function(s){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:ot;if(ys(s))return{tag:"async",stripePromise:Promise.resolve(s).then(function(a){return ze(a,r)})};var n=ze(s,r);return n===null?{tag:"empty"}:{tag:"sync",stripe:n}},Ns=function(s){!s||!s._registerWrapper||!s.registerAppInfo||(s._registerWrapper({name:"react-stripe-js",version:"5.0.0"}),s.registerAppInfo({name:"react-stripe-js",version:"5.0.0",url:"https://stripe.com/docs/stripe-js/react"}))},ve=b.createContext(null);ve.displayName="ElementsContext";var ct=function(s,r){if(!s)throw new Error("Could not find Elements context; You need to wrap the part of your app that ".concat(r," in an <Elements> provider."));return s},lt=function(s){var r=s.stripe,n=s.options,a=s.children,i=b.useMemo(function(){return vs(r)},[r]),l=b.useState(function(){return{stripe:i.tag==="sync"?i.stripe:null,elements:i.tag==="sync"?i.stripe.elements(n):null}}),f=at(l,2),o=f[0],m=f[1];b.useEffect(function(){var d=!0,S=function(j){m(function(E){return E.stripe?E:{stripe:j,elements:j.elements(n)}})};
2return i.tag==="async"&&!o.stripe?i.stripePromise.then(function(x){x&&d&&S(x)}):i.tag==="sync"&&!o.stripe&&S(i.stripe),function(){d=!1}},[i,o,n]);var c=Ee(r);b.useEffect(function(){c!==null&&c!==r&&console.warn("Unsupported prop change on Elements: You cannot change the `stripe` prop after setting it.")},[c,r]);var p=Ee(n);return b.useEffect(function(){if(o.elements){var d=it(n,p,["clientSecret","fonts"]);d&&o.elements.update(d)}},[n,p,o.elements]),b.useEffect(function(){Ns(o.stripe)},[o.stripe]),b.createElement(ve.Provider,{value:o},a)};lt.propTypes={stripe:y.any,options:y.object};var Ss=function(s){var r=b.useContext(ve);return ct(r,s)},Cs=function(){var s=Ss("calls useElements()"),r=s.elements;return r};y.func.isRequired;var dt=b.createContext(null);dt.displayName="CheckoutContext";y.any,y.shape({clientSecret:y.oneOfType([y.string,y.instanceOf(Promise)]).isRequired,elementsOptions:y.object}).isRequired;var ke=function(s){var r=b.useContext(dt),n=b.useContext(ve);if(r){if(n)throw new Error("You cannot wrap the part of your app that ".concat(s," in both <CheckoutProvider> and <Elements> providers."));return r}else return ct(n,s)},_s=["mode"],Ps=function(s){return s.charAt(0).toUpperCase()+s.slice(1)},L=function(s,r){var n="".concat(Ps(s),"Element"),a=function(o){var m=o.id,c=o.className,p=o.options,d=p===void 0?{}:p,S=o.onBlur,x=o.onFocus,j=o.onReady,E=o.onChange,k=o.onEscape,te=o.onClick,U=o.onLoadError,F=o.onLoaderStart,R=o.onNetworksChange,B=o.onConfirm,Q=o.onCancel,h=o.onShippingAddressChange,v=o.onShippingRateChange,P=o.onSavedPaymentMethodRemove,w=o.onSavedPaymentMethodUpdate,M=ke("mounts <".concat(n,">")),$="elements"in M?M.elements:null,W="checkoutState"in M?M.checkoutState:null,I=W?.type==="success"||W?.type==="loading"?W.sdk:null,T=b.useState(null),Z=at(T,2),N=Z[0],he=Z[1],K=b.useRef(null),oe=b.useRef(null);D(N,"blur",S),D(N,"focus",x),D(N,"escape",k),D(N,"click",te),D(N,"loaderror",U),D(N,"loaderstart",F),D(N,"networkschange",R),D(N,"confirm",B),D(N,"cancel",Q),D(N,"shippingaddresschange",h),D(N,"shippingratechange",v),D(N,"savedpaymentmethodremove",P),D(N,"savedpaymentmethodupdate",w),D(N,"change",E);var ce;j&&(s==="expressCheckout"?ce=j:ce=function(){j(N)}),D(N,"ready",ce),b.useLayoutEffect(function(){if(K.current===null&&oe.current!==null&&($||I)){var C=null;if(I)switch(s){case"payment":C=I.createPaymentElement(d);break;case"address":if("mode"in d){var le=d.mode,de=ps(d,_s);if(le==="shipping")C=I.createShippingAddressElement(de);else if(le==="billing")C=I.createBillingAddressElement(de);else throw new Error("Invalid options.mode. mode must be 'billing' or 'shipping'.")}else throw new Error("You must supply options.mode. mode must be 'billing' or 'shipping'.");break;case"expressCheckout":C=I.createExpressCheckoutElement(d);break;case"currencySelector":C=I.createCurrencySelectorElement();break;case"taxId":C=I.createTaxIdElement(d);break;default:throw new Error("Invalid Element type ".concat(n,". You must use either the <PaymentElement />, <AddressElement options={{mode: 'shipping'}} />, <AddressElement options={{mode: 'billing'}} />, or <ExpressCheckoutElement />."))}else $&&(C=$.create(s,d));K.current=C,he(C),C&&C.mount(oe.current)}},[$,I,d]);var ee=Ee(d);return b.useEffect(function(){if(K.current){var C=it(d,ee,["paymentRequest"]);C&&"update"in K.current&&K.current.update(C)}},[d,ee]),b.useLayoutEffect(function(){return function(){if(K.current&&typeof K.current.destroy=="function")try{K.current.destroy(),K.current=null}catch{}}},[]),b.createElement("div",{id:m,className:c,ref:oe})},i=function(o){ke("mounts <".concat(n,">"));var m=o.id,c=o.className;return b.createElement("div",{id:m,className:c})},l=r?i:a;return l.propTypes={id:y.string,className:y.string,onChange:y.func,onBlur:y.func,onFocus:y.func,onReady:y.func,onEscape:y.func,onClick:y.func,onLoadError:y.func,onLoaderStart:y.func,onNetworksChange:y.func,onConfirm:y.func,onCancel:y.func,onShippingAddressChange:y.func,onShippingRateChange:y.func,onSavedPaymentMethodRemove:y.func,onSavedPaymentMethodUpdate:y.func,options:y.object},l.displayName=n,l.__elementType=s,l},O=typeof window>"u",ws=b.createContext(null);ws.displayName="EmbeddedCheckoutProviderContext";var Es=function(){var s=ke("calls useStripe()"),r=s.stripe;return r};L("auBankAccount",O);var He=L("card",O);L("cardNumber",O);L("cardExpiry",O);L("cardCvc",O);L("iban",O);L("payment",O);L("expressCheckout",O);L("paymentRequestButton",O);L("linkAuthentication",O);L("address",O);L("shippingAddress",O);L("paymentMethodMessaging",O);L("taxId",O);
2const ks={style:{base:{fontSize:"16px",color:"#424770","::placeholder":{color:"#aab7c4"},fontFamily:"system-ui, -apple-system, sans-serif"},invalid:{color:"#9e2146"}},hidePostalCode:!0};function As({onSuccess:t,onCancel:s}){const{t:r}=ie(),n=Es(),a=Cs(),[i,l]=g.useState(!1),[f,o]=g.useState(""),[m,c]=g.useState(!0),p=async d=>{if(d.preventDefault(),!n||!a){o(r("profile.addCard.stripeNotReady"));return}l(!0),o("");try{const S=a.getElement(He),{error:x,paymentMethod:j}=await n.createPaymentMethod({type:"card",card:S});if(x)throw new Error(x.message);console.log("â
Payment Method creat în Stripe:",j.id),await At(j.id,m),console.log("â
Payment Method salvat în backend"),t&&t()}catch(S){console.error("â Eroare la adÄugarea payment method:",S),o(S.message||r("profile.addCard.addError"))}finally{l(!1)}};return e.jsxs("form",{onSubmit:p,className:"space-y-4",children:[e.jsxs(q,{className:"border-blue-200 bg-blue-50 text-blue-800",children:[e.jsx(tt,{className:"h-4 w-4"}),e.jsx(V,{className:"text-sm",children:e.jsx(Mt,{i18nKey:"profile.addCard.securityInfo",components:{strong:e.jsx("strong",{})}})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Oe,{htmlFor:"card-element",children:r("profile.addCard.cardDetails")}),e.jsx("div",{className:"border rounded-md p-3 bg-white",children:e.jsx(He,{id:"card-element",options:ks})}),e.jsx("p",{className:"text-xs text-slate-500",children:r("profile.addCard.acceptedCards")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Ot,{id:"make-default",checked:m,onCheckedChange:c}),e.jsx(Oe,{htmlFor:"make-default",className:"text-sm font-normal cursor-pointer",children:r("profile.addCard.makeDefault")})]}),f&&e.jsxs(q,{className:"border-red-200 bg-red-50 text-red-800",children:[e.jsx(Pe,{className:"h-4 w-4"}),e.jsx(V,{children:f})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[e.jsx(_,{type:"button",variant:"outline",onClick:s,disabled:i,children:r("common.cancel")}),e.jsx(_,{type:"submit",disabled:!n||i,children:i?e.jsxs(e.Fragment,{children:[e.jsx(Te,{className:"h-4 w-4 mr-2 animate-spin"}),r("profile.addCard.adding")]}):r("profile.addCard.addButton")})]}),!1]})}var ut="clover",Rs=function(s){return s===3?"v3":s},mt="https://js.stripe.com",Ts="".concat(mt,"/").concat(ut,"/stripe.js"),Ds=/^https:\/\/js\.stripe\.com\/v3\/?(\?.*)?$/,Is=/^https:\/\/js\.stripe\.com\/(v3|[a-z]+)\/stripe\.js(\?.*)?$/;var Ls=function(s){return Ds.test(s)||Is.test(s)},Os=function(){for(var s=document.querySelectorAll('script[src^="'.concat(mt,'"]')),r=0;r<s.length;r++){var n=s[r];if(Ls(n.src))return n}return null},Ke=function(s){var r="",n=document.createElement("script");n.src="".concat(Ts).concat(r);var a=document.head||document.body;if(!a)throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");return a.appendChild(n),n},Ms=function(s,r){!s||!s._registerWrapper||s._registerWrapper({name:"stripe-js",version:"8.0.0",startTime:r})},me=null,xe=null,ye=null,Us=function(s){return function(r){s(new Error("Failed to load Stripe.js",{cause:r}))}},Fs=function(s,r){return function(){window.Stripe?s(window.Stripe):r(new Error("Stripe.js not available"))}},Bs=function(s){return me!==null?me:(me=new Promise(function(r,n){if(typeof window>"u"||typeof document>"u"){r(null);return}if(window.Stripe){r(window.Stripe);return}try{var a=Os();if(!(a&&s)){if(!a)a=Ke(s);else if(a&&ye!==null&&xe!==null){var i;a.removeEventListener("load",ye),a.removeEventListener("error",xe),(i=a.parentNode)===null||i===void 0||i.removeChild(a),a=Ke(s)}}ye=Fs(r,n),xe=Us(n),a.addEventListener("load",ye),a.addEventListener("error",xe)}catch(l){n(l);return}}),me.catch(function(r){return me=null,Promise.reject(r)}))},$s=function(s,r,n){if(s===null)return null;var a=r[0],i=a.match(/^pk_test/),l=Rs(s.version),f=ut;i&&l!==f&&console.warn("Stripe.js@".concat(l," was loaded on the page, but @stripe/stripe-js@").concat("8.0.0"," expected Stripe.js@").concat(f,". This may result in unexpected behavior. For more information, see https://docs.stripe.com/sdks/stripejs-versioning"));var o=s.apply(void 0,r);return Ms(o,n),o}
2,pe,pt=!1,ft=function(){return pe||(pe=Bs(null).catch(function(s){return pe=null,Promise.reject(s)}),pe)};Promise.resolve().then(function(){return ft()}).catch(function(t){pt||console.warn(t)});var Ws=function(){for(var s=arguments.length,r=new Array(s),n=0;n<s;n++)r[n]=arguments[n];pt=!0;var a=Date.now();return ft().then(function(i){return $s(i,r,a)})};function Gs(t){return Ws(t)}const qs=Gs("pk_live_51SCg7sEsNyNf71iyBc5pcT8dkgo1O8xiNwnIPq7cBzEwWUczBr4dcQUZO9WV7mPL3uGz3uE6uimoSEuFwC50iu4G00pdpzWb1j");function Vs(){return e.jsx(lt,{stripe:qs,children:e.jsx(zs,{})})}function zs(){const{t,i18n:s}=ie(),r=s.language==="hu"?"hu-HU":s.language==="en"?"en-US":"ro-RO",[n,a]=g.useState([]),[i,l]=g.useState(!0),[f,o]=g.useState(!1),[m,c]=g.useState(""),[p,d]=g.useState(""),[S,x]=g.useState(!1);g.useEffect(()=>{j()},[]);const j=async()=>{try{const h=await Rt();a(h)}catch{c(t("profile.payment.toast.loadError"))}finally{l(!1)}},E=async h=>{o(!0),c(""),d("");try{await Tt(h,!0),d(t("profile.payment.toast.defaultUpdated")),await j()}catch(v){c(v.message||t("profile.payment.toast.updateError"))}finally{o(!1)}},k=async(h,v)=>{if(confirm(t("profile.payment.toast.deleteConfirm",{last4:v}))){o(!0),c("");try{await Dt(h),d(t("profile.payment.toast.deleted")),await j()}catch(P){c(P.message||t("profile.payment.toast.deleteError"))}finally{o(!1)}}},te=async()=>{d(t("profile.payment.toast.added")),x(!1),await j()},U=()=>{x(!1),c("")},F=()=>"ð³",R=(h,v)=>!h||!v?"N/A":`${h.toString().padStart(2,"0")}/${v.toString().slice(-2)}`,B=(h,v)=>{if(!h||!v)return!1;const P=new Date,w=P.getFullYear(),M=P.getMonth()+1;return v<w||v===w&&h<M},Q=(h,v)=>{if(!h||!v)return!1;const P=new Date,w=P.getFullYear(),M=P.getMonth()+1,$=(v-w)*12+(h-M);return $<=2&&$>0};return i?e.jsx("div",{className:"flex items-center justify-center p-6",children:e.jsx("div",{className:"text-slate-600",children:t("profile.payment.loading")})}):e.jsxs("div",{className:"space-y-6",children:[m&&e.jsxs(q,{className:"border-red-200 bg-red-50 text-red-800",children:[e.jsx(ge,{className:"h-4 w-4"}),e.jsx(V,{children:m})]}),p&&e.jsxs(q,{className:"border-green-200 bg-green-50 text-green-800",children:[e.jsx(ue,{className:"h-4 w-4"}),e.jsx(V,{children:p})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:t("profile.payment.title")}),e.jsx("p",{className:"text-sm text-slate-600",children:t("profile.payment.description")})]}),e.jsxs(Ct,{open:S,onOpenChange:x,children:[e.jsx(_t,{asChild:!0,children:e.jsxs(_,{className:"flex items-center gap-2",children:[e.jsx(Me,{className:"h-4 w-4"}),t("profile.payment.addCard")]})}),e.jsxs(Pt,{children:[e.jsxs(wt,{children:[e.jsx(Et,{children:t("profile.payment.addDialog.title")}),e.jsx(kt,{children:t("profile.payment.addDialog.description")})]}),e.jsx("div",{className:"py-4",children:e.jsx(As,{onSuccess:te,onCancel:U})})]})]})]}),n.length===0?e.jsx(z,{children:e.jsxs(H,{className:"text-center py-8",children:[e.jsx(De,{className:"h-12 w-12 text-slate-400 mx-auto mb-3"}),e.jsx("p",{className:"text-slate-600 mb-2",children:t("profile.payment.empty.title")}),e.jsx("p",{className:"text-sm text-slate-500 mb-4",children:t("profile.payment.empty.description")}),e.jsxs(_,{onClick:()=>x(!0),children:[e.jsx(Me,{className:"h-4 w-4 mr-2"}),t("profile.payment.empty.addFirst")]})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:n.map(h=>{const v=B(h.card_exp_month,h.card_exp_year),P=Q(h.card_exp_month,h.card_exp_year);return e.jsxs(z,{className:`relative ${h.is_default?"ring-2 ring-blue-500 bg-blue-50":""} ${v?"opacity-75":""}`,children:[h.is_default&&e.jsxs(re,{className:"absolute -top-2 left-4 bg-blue-500 flex items-center gap-1",children:[e.jsx(Ue,{className:"h-3 w-3"}),t("portalI18n.paymentMethods.defaultBadge")]}),e.jsx(J,{className:"pb-3",children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"text-2xl",children:F(h.card_brand)}),e.jsxs("div",{children:[e.jsxs(X,{className:"text-base capitalize",children:[h.card_brand||"Card"," â¢â¢â¢â¢ ",h.card_last4]}),e.jsxs(se,{className:"flex items-center gap-2",children:[e.jsx(Ut,{className:"h-3 w-3"}),t("profile.payment.card.expires",{date:R(h.card_exp_month,h.card_exp_year)}),v&&e.jsx(re,{variant:"destructive",className:"text-xs",children:t("profile.payment.card.expired")}),P&&!v&&e.jsx(re,{variant:"warning",className:"text-xs",children:t("profile.payment.card.expiringSoon")})]})]})]})})}
2),e.jsxs(H,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[!h.is_default&&!v&&e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>E(h.id),disabled:f,className:"flex items-center gap-1",children:[e.jsx(Ue,{className:"h-3 w-3"}),t("profile.payment.card.setDefault")]}),e.jsxs(_,{variant:"outline",size:"sm",onClick:()=>k(h.id,h.card_last4),disabled:f,className:"text-red-600 hover:text-red-700 flex items-center gap-1",children:[e.jsx(Ft,{className:"h-3 w-3"}),t("profile.payment.card.deleteBtn")]})]}),e.jsx("div",{className:"mt-3 pt-3 border-t text-xs text-slate-500",children:t("profile.payment.card.addedOn",{date:new Date(h.created_at).toLocaleDateString(r)})})]})]},h.id)})}),e.jsxs(z,{children:[e.jsxs(J,{children:[e.jsxs(X,{className:"flex items-center gap-2",children:[e.jsx(tt,{className:"h-5 w-5"}),t("profile.payment.security.title")]}),e.jsx(se,{children:t("profile.payment.security.description")})]}),e.jsx(H,{children:e.jsxs("div",{className:"space-y-4 text-sm",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ue,{className:"h-4 w-4 text-green-500 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t("profile.payment.security.ssl")}),e.jsx("p",{className:"text-slate-600",children:t("profile.payment.security.sslDesc")})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ue,{className:"h-4 w-4 text-green-500 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t("profile.payment.security.stripe")}),e.jsx("p",{className:"text-slate-600",children:t("profile.payment.security.stripeDesc")})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ue,{className:"h-4 w-4 text-green-500 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t("profile.payment.security.noStorage")}),e.jsx("p",{className:"text-slate-600",children:t("profile.payment.security.noStorageDesc")})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ue,{className:"h-4 w-4 text-green-500 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t("profile.payment.security.pci")}),e.jsx("p",{className:"text-slate-600",children:t("profile.payment.security.pciDesc")})]})]})]})})]}),e.jsxs(z,{children:[e.jsx(J,{children:e.jsx(X,{children:t("profile.payment.tips.title")})}),e.jsx(H,{children:e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ge,{className:"h-4 w-4 text-amber-500 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t("profile.payment.tips.updateExpired")}),e.jsx("p",{className:"text-slate-600",children:t("profile.payment.tips.updateExpiredDesc")})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ge,{className:"h-4 w-4 text-amber-500 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t("profile.payment.tips.defaultMethod")}),e.jsx("p",{className:"text-slate-600",children:t("profile.payment.tips.defaultMethodDesc")})]})]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ge,{className:"h-4 w-4 text-amber-500 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t("profile.payment.tips.notifications")}),e.jsx("p",{className:"text-slate-600",children:t("profile.payment.tips.notificationsDesc")})]})]})]})})]})]})}const Ye=fe["regio-development"],Hs={[Y.DIGITAL_SIGNAGE]:fe.regiodisplay.name,[Y.REMOTE_DESKTOP]:fe.regiodesk.name,[Y.DISK_HEALTH]:"RegioScan"},Ks={[Y.DIGITAL_SIGNAGE]:fe.regiodisplay.accentColor,[Y.REMOTE_DESKTOP]:fe.regiodesk.accentColor,[Y.DISK_HEALTH]:"#F59E0B"},Ys=Object.values(Y),Je={PROFORMA:"text-amber-700 dark:text-amber-300",FISCAL:"text-emerald-700 dark:text-emerald-300"};function Js(t){return t==="hu"?"hu-HU":t==="en"?"en-US":"ro-RO"}function ht(t,s){if(!t)return"â";try{return new Date(t).toLocaleDateString(s,{year:"numeric",month:"short",day:"numeric"})}catch{return String(t)}}function Xs({productType:t,productName:s,accentColor:r,onDismiss:n}){const{t:a}=ie();return e.jsxs(q,{"data-testid":"products-welcome-banner","data-product":t,className:"relative pr-12 border-2",style:{borderColor:r},children:[e.jsx(be,{className:"h-5 w-5",style:{color:r}}),e.jsx(vt,{children:a("subscriptionsPage.welcomeBanner.title",{productName:s})}),e.jsx(V,{children:a("subscriptionsPage.welcomeBanner.description")}),e.jsx(_,{type:"button",variant:"ghost",size:"icon","aria-label":a("subscriptionsPage.welcomeBanner.dismissAria"),onClick:n,className:"absolute right-2 top-2 h-7 w-7",children:e.jsx(rt,{className:"h-4 w-4"})})]})}function Qs({proforma:t,locale:s,t:r}){async function n(){try{const a=await st(t.subscription_id,t.id),i=URL.createObjectURL(a),l=document.createElement("a");l.href=i,l.download=`Proforma_${t.smartbill_proforma_series||t.id}-${t.smartbill_proforma_number||""}.pdf`,l.click(),URL.revokeObjectURL(i)}catch(a){console.error("Could not download proforma PDF",a)}}return e.jsxs(z,{"data-testid":"outstanding-proforma-card",className:"border-2 border-amber-500/60 bg-amber-50 dark:bg-amber-950/30",children:[e.jsx(J,{children:e.jsxs(X,{className:"flex items-center gap-2",children:[e.jsx(Re,{className:"h-5 w-5 text-amber-700"}),r("billingPage.outstandingProforma.title")]})}
2),e.jsxs(H,{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-muted-foreground",children:r("billingPage.outstandingProforma.labelNumber")}),e.jsxs("div",{className:"font-medium",children:[t.smartbill_proforma_series||"?","-",t.smartbill_proforma_number||"?"]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-muted-foreground",children:r("billingPage.outstandingProforma.labelAmount")}),e.jsxs("div",{className:"font-medium",children:[Number(t.gross_amount??t.amount).toFixed(2)," ",t.currency]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-muted-foreground",children:r("billingPage.outstandingProforma.labelDueDate")}),e.jsx("div",{className:"font-medium",children:t.smartbill_proforma_due_date?ht(t.smartbill_proforma_due_date,s):"â"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-2",children:[e.jsxs(_,{onClick:n,variant:"outline",size:"sm",children:[e.jsx(Le,{className:"mr-2 h-4 w-4"}),r("billingPage.outstandingProforma.downloadPdf")]}),t.stripe_payment_link_url&&e.jsx(_,{asChild:!0,size:"sm",children:e.jsxs("a",{href:t.stripe_payment_link_url,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(De,{className:"mr-2 h-4 w-4"}),r("billingPage.outstandingProforma.payByCard"),e.jsx(Vt,{className:"ml-2 h-3 w-3"})]})})]})]})]})}function Zs({proforma:t,fiscal:s,locale:r,t:n}){const a=s!=null,i=t?`${t.smartbill_proforma_series||"?"}-${t.smartbill_proforma_number||"?"}`:null,l=s?s.smartbill_series&&s.smartbill_number?`${s.smartbill_series}-${s.smartbill_number}`:`#${s.id}`:null;async function f(){try{let x,j;if(a){if(s.invoice_url){window.open(s.invoice_url,"_blank");return}x=await Lt(s.id),j=`Invoice_${l}.pdf`}else if(t)x=await st(t.subscription_id,t.id),j=`Proforma_${i}.pdf`;else return;const E=URL.createObjectURL(x),k=document.createElement("a");k.href=E,k.download=j,k.click(),URL.revokeObjectURL(E)}catch(x){console.error("Could not download PDF",x)}}const o=a?s:t,m=o?.created_at,c=o?`${Number(o.gross_amount??o.amount).toFixed(2)} ${o.currency}`:"â",p=!a&&t?.status==="CANCELLED",d=n(a?"billingPage.history.rowStatus.PAID":p?"billingPage.history.rowStatus.CANCELLED":"billingPage.history.rowStatus.PENDING"),S=a?"billingPage.history.downloadFiscal":"billingPage.history.downloadProforma";return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border hover:bg-muted/30",children:[e.jsx(Re,{className:`h-5 w-5 shrink-0 ${a?Je.FISCAL:Je.PROFORMA}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t&&e.jsxs("span",{className:"font-medium",children:[n("billingPage.history.kind.PROFORMA")," ",i]}),s&&e.jsxs(e.Fragment,{children:[t&&e.jsx(Ie,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsxs("span",{className:"font-medium",children:[n("billingPage.history.kind.FISCAL")," ",l]})]}),e.jsx(re,{variant:a?"default":p?"outline":"secondary",className:`text-xs ${p?"text-muted-foreground line-through":""}`,children:d})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-0.5",children:[ht(m,r)," · ",c]})]}),!p&&e.jsx(_,{variant:"ghost",size:"sm",onClick:f,title:n(S),children:e.jsx(Le,{className:"h-4 w-4"})})]})}function nn(){const{t,i18n:s}=ie(),{user:r,productsCatalog:n}=Xe(),{isImpersonating:a}=xt(),i=yt(),[l,f]=bt(),o=r?.user_type==="ADMIN"&&!a,m=Js(s.language),[c,p]=g.useState([]),[d,S]=g.useState(null),[x,j]=g.useState(!0),[E,k]=g.useState(null),[te,U]=g.useState(!1),[F,R]=g.useState(null),B=g.useCallback(async()=>{const[u,G]=await Promise.all([It(0,50).catch(()=>[]),$t().catch(()=>null)]);p(Array.isArray(u)?u:u?.items||[]),S(G)},[]);g.useEffect(()=>{let u=!0;return(async()=>{try{await B()}catch{u&&k(t("billingPage.loadError"))}finally{u&&j(!1)}})(),()=>{u=!1}},[]);const Q=g.useCallback(async u=>{u?.immediate?R({type:"immediate",summary:u?.summary}):R({type:"scheduled",effectiveDate:u?.effective_date,summary:u?.summary}),await B().catch(()=>{})},[B]),h=g.useCallback(async()=>{try{await Wt(),R({type:"cancelled"}),await B().catch(()=>{})}catch(u){const G=u?.response?.data?.detail;k(typeof G=="string"?G:t("billingPage.loadError"))}},[B,t]),v=g.useMemo(()=>{const u=new Map;
2return(n??[]).forEach(G=>{G?.type&&u.set(G.type,G)}),u},[n]),P=l.get("welcome"),w=Ys.includes(P)?P:null,M=w?v.get(w):null,$=M?.name??Hs[w]??w,W=M?.accent_color??Ks[w]??Ye.accentColor,I=()=>{const u=new URLSearchParams(l);u.delete("welcome"),f(u,{replace:!0})},T=l.get("proforma")==="issued",Z=l.get("checkout")==="success",N=g.useMemo(()=>c.find(u=>u.kind==="PROFORMA"&&u.status==="PENDING"),[c]);g.useEffect(()=>{if(!x&&T&&!N){const u=new URLSearchParams(l);u.delete("proforma"),f(u,{replace:!0})}},[x,T,N]);const he=g.useMemo(()=>{const u=new Map,G=new Map;for(const A of c)A.kind==="PROFORMA"?u.set(A.id,A):A.kind==="FISCAL"&&A.parent_billing_history_id&&G.set(A.parent_billing_history_id,A);const Ne=[];for(const A of c)A.kind==="PROFORMA"?Ne.push({key:`pf-${A.id}`,proforma:A,fiscal:G.get(A.id)??null}):A.kind==="FISCAL"&&!A.parent_billing_history_id&&Ne.push({key:`fc-${A.id}`,proforma:null,fiscal:A});return Ne},[c]),oe=d&&(!d.payment_method||d.status==="TRIAL_EXPIRED")&&!N,ce=g.useMemo(()=>(n??[]).some(u=>u?.subscription?.has_stripe_billing===!0),[n]),ee=g.useMemo(()=>(n??[]).filter(u=>u?.subscription!=null),[n]),C=g.useMemo(()=>(n??[]).filter(u=>u?.subscription==null),[n]),le=g.useMemo(()=>ee.filter(u=>u?.subscription?.contract_id).map(u=>({subscriptionId:u.subscription.id,contractId:u.subscription.contract_id,productName:u.name,accentColor:u.accent_color})),[ee]),de=g.useMemo(()=>ee.filter(u=>u?.subscription&&!u.subscription.contract_id&&["ACTIVE","PAST_DUE","PENDING_PAYMENT","SUSPENDED"].includes(u.subscription.status)),[ee]);return o?e.jsx(jt,{to:"/admin",replace:!0}):e.jsxs("div",{className:"container mx-auto p-4 md:p-8 max-w-7xl space-y-6",children:[e.jsxs("div",{className:"border-l-4 pl-4 pb-1",style:{borderLeftColor:Ye.accentColor},children:[e.jsx("h1",{className:"text-3xl font-bold text-slate-900 dark:text-slate-100",children:t("subscriptionsPage.header.title")}),e.jsx("p",{className:"text-slate-600 dark:text-slate-400 mt-1",children:t("subscriptionsPage.header.subtitle")})]}),w&&e.jsx(Xs,{productType:w,productName:$,accentColor:W,onDismiss:I}),T&&N&&e.jsxs(q,{children:[e.jsx(be,{className:"h-4 w-4 text-emerald-600"}),e.jsx(V,{children:t("billingPage.flash.proformaIssued")})]}),Z&&e.jsxs(q,{children:[e.jsx(be,{className:"h-4 w-4 text-emerald-600"}),e.jsx(V,{children:t("billingPage.flash.checkoutSuccess")})]}),d?.status==="SUSPENDED"&&e.jsxs(q,{variant:"destructive","data-testid":"suspended-subscription-alert",children:[e.jsx(Pe,{className:"h-4 w-4"}),e.jsxs(V,{children:[e.jsx("p",{className:"font-semibold",children:t("billingPage.suspended.title")}),e.jsx("p",{className:"text-sm mt-1",children:t(N?"billingPage.suspended.payToReactivate":"billingPage.suspended.contactSupport")})]})]}),F&&e.jsxs(q,{"data-testid":"change-screens-flash",className:"relative pr-12",children:[e.jsx(be,{className:"h-4 w-4 text-emerald-600"}),e.jsx(V,{children:F.type==="cancelled"?t("subscriptionsPage.card.pendingChangeCancelled"):F.type==="scheduled"?t("subscriptionsPage.card.changeScheduledFlash",{date:F.effectiveDate?new Date(F.effectiveDate).toLocaleDateString(m,{year:"numeric",month:"long",day:"numeric"}):"â"}):t("subscriptionsPage.card.changeAppliedFlash")}),e.jsx(_,{type:"button",variant:"ghost",size:"icon","aria-label":t("subscriptionsPage.welcomeBanner.dismissAria"),onClick:()=>R(null),className:"absolute right-2 top-2 h-7 w-7",children:e.jsx(rt,{className:"h-4 w-4"})})]}),E&&e.jsxs(q,{variant:"destructive",children:[e.jsx(Pe,{className:"h-4 w-4"}),e.jsx(V,{children:E})]}),!x&&N&&e.jsx(Qs,{proforma:N,locale:m,t}),!x&&oe&&e.jsxs(z,{className:"border-2 border-amber-500/40 bg-amber-50 dark:bg-amber-950/30",children:[e.jsxs(J,{children:[e.jsxs(X,{className:"flex items-center gap-2",children:[e.jsx(qt,{className:"h-5 w-5"}),t("billingPage.setup.title")]}),e.jsx(se,{children:t("billingPage.setup.description")})]}),e.jsx(H,{children:e.jsxs(_,{onClick:()=>i("/billing/setup"),size:"lg",children:[t("billingPage.setup.cta"),e.jsx(Ie,{className:"ml-2 h-4 w-4"})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(er,{ownedProducts:ee,signageSubscription:d,onChangeScreens:()=>U(!0),onCancelPending:h,t}),le.length>0?e.jsx(nr,{contracts:le,language:s.language,t}):de.length>0?e.jsx(rr,{accentColor:de[0]?.accent_color,onReview:()=>i("/billing/setup"),t}):null]}),!x&&he.length>0&&e.jsx(tr,{billingEvents:he,locale:m,t}),ce&&e.jsxs(z,{"data-testid":"payment-methods-section",children:[e.jsx(J,{children:e.jsxs(X,{className:"flex items-center gap-2",children:[e.jsx(De,{className:"h-5 w-5"}),t("subscriptionsPage.paymentMethods")]})}),e.jsx(H,{children:e.jsx(Vs,{})})]}),C.length>0&&e.jsx(sr,{products:C,t}),x&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Te,{className:"h-4 w-4 animate-spin"}),t("billingPage.loading")]}),e.jsx(Bt,{open:te,onClose:()=>U(!1),currentSubscription:d,onSuccess:Q})]})}function er({ownedProducts:t,signageSubscription:s,onChangeScreens:r,onCancelPending:n,t:a}
2){return e.jsx("section",{"data-testid":"your-subscriptions-section",className:"h-full",children:t.length===0?e.jsx("p",{"data-testid":"your-subscriptions-empty",className:"text-sm text-slate-500 dark:text-slate-400",children:a("subscriptionsPage.active.empty")}):e.jsx("div",{className:"grid gap-4 h-full",children:t.map(i=>e.jsx(rs,{product:i,signageSubscription:i.type===Y.DIGITAL_SIGNAGE?s:null,onChangeScreens:i.type===Y.DIGITAL_SIGNAGE?r:null,onCancelPending:i.type===Y.DIGITAL_SIGNAGE?n:null},i.type))})})}function tr({billingEvents:t,locale:s,t:r}){return e.jsxs("section",{"data-testid":"billing-history-section",children:[e.jsx("h3",{className:"text-base font-semibold text-slate-900 dark:text-slate-100 mb-1",children:r("billingPage.history.title")}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:r("billingPage.history.subtitle")}),e.jsx("div",{className:"space-y-3",children:t.map(n=>e.jsx(Zs,{proforma:n.proforma,fiscal:n.fiscal,locale:s,t:r},n.key))})]})}function sr({products:t,t:s}){return e.jsxs("section",{"data-testid":"add-more-products-section",className:"pt-2 border-t",children:[e.jsx("h2",{className:"text-lg font-semibold text-slate-900 dark:text-slate-100 mb-1 mt-6",children:s("subscriptionsPage.available.heading")}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400 mb-3",children:s("subscriptionsPage.available.subheading")}),e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:t.map(r=>e.jsx(os,{product:{type:r.type,name:r.name,accentColor:r.accent_color,marketingUrl:r.marketing_url,tagline:s(`subscriptionsPage.products.${r.type}.tagline`,{defaultValue:""}),description:s(`subscriptionsPage.products.${r.type}.description`,{defaultValue:""})||void 0}},r.type))})]})}function rr({accentColor:t,onReview:s,t:r}){return e.jsxs(z,{"data-testid":"reaccept-contract-card",className:"h-full border-t-[3px]",style:t?{borderTopColor:t}:void 0,children:[e.jsxs(J,{className:"space-y-2",children:[e.jsxs(X,{className:"flex items-center gap-2",children:[e.jsx(we,{className:"h-5 w-5"}),r("subscriptionsPage.documents.reacceptTitle")]}),e.jsx(se,{children:r("subscriptionsPage.documents.reacceptDescription")})]}),e.jsx(H,{children:e.jsxs(_,{onClick:s,size:"sm",children:[r("subscriptionsPage.documents.reacceptCta"),e.jsx(Ie,{className:"ml-2 h-4 w-4"})]})})]})}function nr({contracts:t,language:s,t:r}){const[n,a]=g.useState(null),[i,l]=g.useState(null);if(!t||t.length===0)return null;async function f(m){l(null),a(`${m.subscriptionId}-${m.contractId}`);try{const c=await Gt(m.subscriptionId,m.contractId,s),p=URL.createObjectURL(c),d=document.createElement("a");d.href=p,d.download=`Contract_${m.productName}_${s}.pdf`,d.click(),URL.revokeObjectURL(p)}catch(c){console.error("Could not download contract",c),l(r("subscriptionsPage.documents.downloadContractFailed"))}finally{a(null)}}const o=t[0]?.accentColor??null;return e.jsxs(z,{"data-testid":"documents-sidebar",className:"h-full border-t-[3px]",style:o?{borderTopColor:o}:void 0,children:[e.jsxs(J,{className:"space-y-2",children:[e.jsxs(X,{className:"flex items-center gap-2",children:[e.jsx(we,{className:"h-5 w-5"}),r("subscriptionsPage.documents.heading")]}),e.jsx(se,{children:r("subscriptionsPage.documents.subheading")})]}
2),e.jsxs(H,{className:"space-y-3",children:[t.map(m=>{const c=`${m.subscriptionId}-${m.contractId}`,p=n===c;return e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg border bg-muted/20",children:[e.jsx(we,{className:"h-5 w-5 shrink-0 mt-0.5",style:{color:m.accentColor}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children:r("subscriptionsPage.documents.contract")}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[m.productName," ·"," ",r("subscriptionsPage.documents.contractDescription")]}),e.jsxs(_,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>f(m),disabled:p,children:[p?e.jsx(Te,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):e.jsx(Le,{className:"mr-2 h-3.5 w-3.5"}),r("subscriptionsPage.documents.downloadContract")]})]})]},c)}),i&&e.jsx("p",{role:"alert",className:"text-xs text-red-600 dark:text-red-400 mt-1",children:i})]})]})}export{Zs as BillingHistoryEventRow,nn as default};
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.