@billingos/sdk 0.1.0 → 0.1.1

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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function(){"use strict";try{if(typeof document<"u"){var r=document.createElement("style");r.appendChild(document.createTextNode('/*! tailwindcss v4.1.18 | MIT License | https://tailwindcss.com */@layer properties{@supports (((-webkit-hyphens:none)) and (not (margin-trim:inline))) or ((-moz-orient:inline) and (not (color:rgb(from red r g b)))){*,:before,:after,::backdrop{--tw-translate-x:0;--tw-translate-y:0;--tw-translate-z:0;--tw-scale-x:1;--tw-scale-y:1;--tw-scale-z:1;--tw-rotate-x:initial;--tw-rotate-y:initial;--tw-rotate-z:initial;--tw-skew-x:initial;--tw-skew-y:initial;--tw-space-y-reverse:0;--tw-space-x-reverse:0;--tw-border-style:solid;--tw-gradient-position:initial;--tw-gradient-from:#0000;--tw-gradient-via:#0000;--tw-gradient-to:#0000;--tw-gradient-stops:initial;--tw-gradient-via-stops:initial;--tw-gradient-from-position:0%;--tw-gradient-via-position:50%;--tw-gradient-to-position:100%;--tw-leading:initial;--tw-font-weight:initial;--tw-tracking:initial;--tw-shadow:0 0 #0000;--tw-shadow-color:initial;--tw-shadow-alpha:100%;--tw-inset-shadow:0 0 #0000;--tw-inset-shadow-color:initial;--tw-inset-shadow-alpha:100%;--tw-ring-color:initial;--tw-ring-shadow:0 0 #0000;--tw-inset-ring-color:initial;--tw-inset-ring-shadow:0 0 #0000;--tw-ring-inset:initial;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-offset-shadow:0 0 #0000;--tw-outline-style:solid;--tw-blur:initial;--tw-brightness:initial;--tw-contrast:initial;--tw-grayscale:initial;--tw-hue-rotate:initial;--tw-invert:initial;--tw-opacity:initial;--tw-saturate:initial;--tw-sepia:initial;--tw-drop-shadow:initial;--tw-drop-shadow-color:initial;--tw-drop-shadow-alpha:100%;--tw-drop-shadow-size:initial;--tw-backdrop-blur:initial;--tw-backdrop-brightness:initial;--tw-backdrop-contrast:initial;--tw-backdrop-grayscale:initial;--tw-backdrop-hue-rotate:initial;--tw-backdrop-invert:initial;--tw-backdrop-opacity:initial;--tw-backdrop-saturate:initial;--tw-backdrop-sepia:initial;--tw-duration:initial;--tw-ease:initial}}}@layer theme{:root,:host{--font-sans:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--font-mono:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--color-red-50:oklch(97.1% .013 17.38);--color-red-100:oklch(93.6% .032 17.717);--color-red-500:oklch(63.7% .237 25.331);--color-red-600:oklch(57.7% .245 27.325);--color-red-800:oklch(44.4% .177 26.899);--color-amber-500:oklch(76.9% .188 70.08);--color-yellow-50:oklch(98.7% .026 102.212);--color-yellow-100:oklch(97.3% .071 103.193);--color-yellow-500:oklch(79.5% .184 86.047);--color-yellow-600:oklch(68.1% .162 75.834);--color-yellow-800:oklch(47.6% .114 61.907);--color-yellow-900:oklch(42.1% .095 57.708);--color-green-50:oklch(98.2% .018 155.826);--color-green-100:oklch(96.2% .044 156.743);--color-green-200:oklch(92.5% .084 155.995);--color-green-300:oklch(87.1% .15 154.449);--color-green-400:oklch(79.2% .209 151.711);--color-green-500:oklch(72.3% .219 149.579);--color-green-600:oklch(62.7% .194 149.214);--color-green-700:oklch(52.7% .154 150.069);--color-green-800:oklch(44.8% .119 151.328);--color-green-900:oklch(39.3% .095 152.535);--color-blue-100:oklch(93.2% .032 255.585);--color-blue-500:oklch(62.3% .214 259.815);--color-blue-600:oklch(54.6% .245 262.881);--color-blue-700:oklch(48.8% .243 264.376);--color-blue-800:oklch(42.4% .199 265.638);--color-purple-100:oklch(94.6% .033 307.174);--color-purple-600:oklch(55.8% .288 302.321);--color-purple-700:oklch(49.6% .265 301.924);--color-gray-50:oklch(98.5% .002 247.839);--color-gray-100:oklch(96.7% .003 264.542);--color-gray-200:oklch(92.8% .006 264.531);--color-gray-300:oklch(87.2% .01 258.338);--color-gray-400:oklch(70.7% .022 261.325);--color-gray-500:oklch(55.1% .027 264.364);--color-gray-600:oklch(44.6% .03 256.802);--color-gray-700:oklch(37.3% .034 259.733);--color-gray-900:oklch(21% .034 264.665);--color-black:#000;--color-white:#fff;--spacing:.25rem;--container-sm:24rem;--container-md:28rem;--container-lg:32rem;--container-2xl:42rem;--container-4xl:56rem;--container-6xl:72rem;--container-7xl:80rem;--text-xs:.75rem;--text-xs--line-height:calc(1/.75);--text-sm:.875rem;--text-sm--line-height:calc(1.25/.875);--text-base:1rem;--text-base--line-height: 1.5 ;--text-lg:1.125rem;--text-lg--line-height:calc(1.75/1.125);--text-xl:1.25rem;--text-xl--line-height:calc(1.75/1.25);--text-2xl:1.5rem;--text-2xl--line-height:calc(2/1.5);--text-3xl:1.875rem;--text-3xl--line-height: 1.2 ;--text-4xl:2.25rem;--text-4xl--line-height:calc(2.5/2.25);--text-5xl:3rem;--text-5xl--line-height:1;--font-weight-normal:400;--font-weight-medium:500;--font-weight-semibold:600;--font-weight-bold:700;--tracking-tight:-.025em;--leading-tight:1.25;--leading-relaxed:1.625;--radius-2xl:1rem;--ease-out:cubic-bezier(0,0,.2,1);--ease-in-out:cubic-bezier(.4,0,.2,1);--animate-spin:spin 1s linear infinite;--animate-pulse:pulse 2s cubic-bezier(.4,0,.6,1)infinite;--blur-sm:8px;--default-transition-duration:.15s;--default-transition-timing-function:cubic-bezier(.4,0,.2,1);--default-font-family:var(--font-sans);--default-mono-font-family:var(--font-mono)}}@layer base{*,:after,:before,::backdrop{box-sizing:border-box;border:0 solid;margin:0;padding:0}::file-selector-button{box-sizing:border-box;border:0 solid;margin:0;padding:0}html,:host{-webkit-text-size-adjust:100%;-moz-tab-size:4;tab-size:4;line-height:1.5;font-family:var(--default-font-family,ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji");font-feature-settings:var(--default-font-feature-settings,normal);font-variation-settings:var(--default-font-variation-settings,normal);-webkit-tap-highlight-color:transparent}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;-webkit-text-decoration:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:var(--default-mono-font-family,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace);font-feature-settings:var(--default-mono-font-feature-settings,normal);font-variation-settings:var(--default-mono-font-variation-settings,normal);font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring{outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{vertical-align:middle;display:block}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;opacity:1;background-color:#0000;border-radius:0}:where(select:is([multiple],[size])) optgroup{font-weight:bolder}:where(select:is([multiple],[size])) optgroup option{padding-inline-start:20px}::file-selector-button{margin-inline-end:4px}::placeholder{opacity:1}@supports (not ((-webkit-appearance:-apple-pay-button))) or (contain-intrinsic-size:1px){::placeholder{color:currentColor}@supports (color:color-mix(in lab,red,red)){::placeholder{color:color-mix(in oklab,currentcolor 50%,transparent)}}}textarea{resize:vertical}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-date-and-time-value{min-height:1lh;text-align:inherit}::-webkit-datetime-edit{display:inline-flex}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-datetime-edit{padding-block:0}::-webkit-datetime-edit-year-field{padding-block:0}::-webkit-datetime-edit-month-field{padding-block:0}::-webkit-datetime-edit-day-field{padding-block:0}::-webkit-datetime-edit-hour-field{padding-block:0}::-webkit-datetime-edit-minute-field{padding-block:0}::-webkit-datetime-edit-second-field{padding-block:0}::-webkit-datetime-edit-millisecond-field{padding-block:0}::-webkit-datetime-edit-meridiem-field{padding-block:0}::-webkit-calendar-picker-indicator{line-height:1}:-moz-ui-invalid{box-shadow:none}button,input:where([type=button],[type=reset],[type=submit]){-webkit-appearance:button;-moz-appearance:button;appearance:button}::file-selector-button{-webkit-appearance:button;-moz-appearance:button;appearance:button}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[hidden]:where(:not([hidden=until-found])){display:none!important}*{border-color:hsl(var(--border))}body{background-color:hsl(var(--background));color:hsl(var(--foreground))}}@layer components;@layer utilities{.pointer-events-none{pointer-events:none}.visible{visibility:visible}.sr-only{clip-path:inset(50%);white-space:nowrap;border-width:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}.absolute{position:absolute}.fixed{position:fixed}.relative{position:relative}.static{position:static}.inset-0{inset:calc(var(--spacing)*0)}.inset-x-0{inset-inline:calc(var(--spacing)*0)}.inset-y-0{inset-block:calc(var(--spacing)*0)}.-top-3{top:calc(var(--spacing)*-3)}.-top-4{top:calc(var(--spacing)*-4)}.top-0{top:calc(var(--spacing)*0)}.top-2{top:calc(var(--spacing)*2)}.top-3{top:calc(var(--spacing)*3)}.top-4{top:calc(var(--spacing)*4)}.right-0{right:calc(var(--spacing)*0)}.right-0\\.5{right:calc(var(--spacing)*.5)}.right-2{right:calc(var(--spacing)*2)}.right-3{right:calc(var(--spacing)*3)}.right-4{right:calc(var(--spacing)*4)}.bottom-0{bottom:calc(var(--spacing)*0)}.bottom-4{bottom:calc(var(--spacing)*4)}.left-0{left:calc(var(--spacing)*0)}.left-1\\/2{left:50%}.isolate{isolation:isolate}.z-10{z-index:10}.z-20{z-index:20}.z-50{z-index:50}.container{width:100%}@media(min-width:40rem){.container{max-width:40rem}}@media(min-width:48rem){.container{max-width:48rem}}@media(min-width:64rem){.container{max-width:64rem}}@media(min-width:80rem){.container{max-width:80rem}}@media(min-width:96rem){.container{max-width:96rem}}.m-0{margin:calc(var(--spacing)*0)}.mx-auto{margin-inline:auto}.my-2{margin-block:calc(var(--spacing)*2)}.mt-0{margin-top:calc(var(--spacing)*0)}.mt-0\\.5{margin-top:calc(var(--spacing)*.5)}.mt-1{margin-top:calc(var(--spacing)*1)}.mt-2{margin-top:calc(var(--spacing)*2)}.mt-3{margin-top:calc(var(--spacing)*3)}.mt-4{margin-top:calc(var(--spacing)*4)}.mt-6{margin-top:calc(var(--spacing)*6)}.mt-8{margin-top:calc(var(--spacing)*8)}.mr-1{margin-right:calc(var(--spacing)*1)}.mr-2{margin-right:calc(var(--spacing)*2)}.mb-1{margin-bottom:calc(var(--spacing)*1)}.mb-2{margin-bottom:calc(var(--spacing)*2)}.mb-3{margin-bottom:calc(var(--spacing)*3)}.mb-4{margin-bottom:calc(var(--spacing)*4)}.mb-6{margin-bottom:calc(var(--spacing)*6)}.mb-8{margin-bottom:calc(var(--spacing)*8)}.mb-12{margin-bottom:calc(var(--spacing)*12)}.ml-1{margin-left:calc(var(--spacing)*1)}.ml-3{margin-left:calc(var(--spacing)*3)}.ml-4{margin-left:calc(var(--spacing)*4)}.block{display:block}.flex{display:flex}.grid{display:grid}.hidden{display:none}.inline{display:inline}.inline-block{display:inline-block}.inline-flex{display:inline-flex}.table{display:table}.aspect-square{aspect-ratio:1}.h-1\\.5{height:calc(var(--spacing)*1.5)}.h-2{height:calc(var(--spacing)*2)}.h-2\\.5{height:calc(var(--spacing)*2.5)}.h-3{height:calc(var(--spacing)*3)}.h-4{height:calc(var(--spacing)*4)}.h-5{height:calc(var(--spacing)*5)}.h-6{height:calc(var(--spacing)*6)}.h-8{height:calc(var(--spacing)*8)}.h-9{height:calc(var(--spacing)*9)}.h-10{height:calc(var(--spacing)*10)}.h-11{height:calc(var(--spacing)*11)}.h-12{height:calc(var(--spacing)*12)}.h-16{height:calc(var(--spacing)*16)}.h-20{height:calc(var(--spacing)*20)}.h-40{height:calc(var(--spacing)*40)}.h-\\[1px\\]{height:1px}.h-\\[600px\\]{height:600px}.h-\\[650px\\]{height:650px}.h-full{height:100%}.max-h-\\[80vh\\]{max-height:80vh}.max-h-\\[90vh\\]{max-height:90vh}.min-h-0{min-height:calc(var(--spacing)*0)}.min-h-\\[80px\\]{min-height:80px}.min-h-screen{min-height:100vh}.w-1\\.5{width:calc(var(--spacing)*1.5)}.w-1\\/4{width:25%}.w-2\\.5{width:calc(var(--spacing)*2.5)}.w-3{width:calc(var(--spacing)*3)}.w-3\\/4{width:75%}.w-4{width:calc(var(--spacing)*4)}.w-5{width:calc(var(--spacing)*5)}.w-6{width:calc(var(--spacing)*6)}.w-8{width:calc(var(--spacing)*8)}.w-10{width:calc(var(--spacing)*10)}.w-12{width:calc(var(--spacing)*12)}.w-16{width:calc(var(--spacing)*16)}.w-20{width:calc(var(--spacing)*20)}.w-24{width:calc(var(--spacing)*24)}.w-28{width:calc(var(--spacing)*28)}.w-32{width:calc(var(--spacing)*32)}.w-36{width:calc(var(--spacing)*36)}.w-40{width:calc(var(--spacing)*40)}.w-44{width:calc(var(--spacing)*44)}.w-48{width:calc(var(--spacing)*48)}.w-64{width:calc(var(--spacing)*64)}.w-80{width:calc(var(--spacing)*80)}.w-96{width:calc(var(--spacing)*96)}.w-\\[1px\\]{width:1px}.w-\\[200px\\]{width:200px}.w-\\[450px\\]{width:450px}.w-full{width:100%}.max-w-2xl{max-width:var(--container-2xl)}.max-w-4xl{max-width:var(--container-4xl)}.max-w-7xl{max-width:var(--container-7xl)}.max-w-\\[200px\\]{max-width:200px}.max-w-\\[calc\\(100vw-2rem\\)\\]{max-width:calc(100vw - 2rem)}.max-w-lg{max-width:var(--container-lg)}.max-w-md{max-width:var(--container-md)}.min-w-0{min-width:calc(var(--spacing)*0)}.flex-1{flex:1}.flex-shrink-0,.shrink-0{flex-shrink:0}.caption-bottom{caption-side:bottom}.-translate-x-1\\/2{--tw-translate-x: -50% ;translate:var(--tw-translate-x)var(--tw-translate-y)}.scale-105{--tw-scale-x:105%;--tw-scale-y:105%;--tw-scale-z:105%;scale:var(--tw-scale-x)var(--tw-scale-y)}.transform{transform:var(--tw-rotate-x,)var(--tw-rotate-y,)var(--tw-rotate-z,)var(--tw-skew-x,)var(--tw-skew-y,)}.animate-pulse{animation:var(--animate-pulse)}.animate-spin{animation:var(--animate-spin)}.cursor-default{cursor:default}.cursor-pointer{cursor:pointer}.touch-none{touch-action:none}.resize{resize:both}.resize-none{resize:none}.list-inside{list-style-position:inside}.list-disc{list-style-type:disc}.grid-cols-1{grid-template-columns:repeat(1,minmax(0,1fr))}.grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.grid-cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}.flex-col{flex-direction:column}.flex-col-reverse{flex-direction:column-reverse}.flex-wrap{flex-wrap:wrap}.items-baseline{align-items:baseline}.items-center{align-items:center}.items-start{align-items:flex-start}.justify-between{justify-content:space-between}.justify-center{justify-content:center}.justify-end{justify-content:flex-end}.gap-1{gap:calc(var(--spacing)*1)}.gap-2{gap:calc(var(--spacing)*2)}.gap-3{gap:calc(var(--spacing)*3)}.gap-4{gap:calc(var(--spacing)*4)}.gap-8{gap:calc(var(--spacing)*8)}:where(.space-y-1>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*1)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*1)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-1\\.5>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*1.5)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*1.5)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-2>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*2)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*2)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-3>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*3)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*3)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-4>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*4)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*4)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-y-6>:not(:last-child)){--tw-space-y-reverse:0;margin-block-start:calc(calc(var(--spacing)*6)*var(--tw-space-y-reverse));margin-block-end:calc(calc(var(--spacing)*6)*calc(1 - var(--tw-space-y-reverse)))}:where(.space-x-2>:not(:last-child)){--tw-space-x-reverse:0;margin-inline-start:calc(calc(var(--spacing)*2)*var(--tw-space-x-reverse));margin-inline-end:calc(calc(var(--spacing)*2)*calc(1 - var(--tw-space-x-reverse)))}:where(.space-x-4>:not(:last-child)){--tw-space-x-reverse:0;margin-inline-start:calc(calc(var(--spacing)*4)*var(--tw-space-x-reverse));margin-inline-end:calc(calc(var(--spacing)*4)*calc(1 - var(--tw-space-x-reverse)))}.overflow-auto{overflow:auto}.overflow-hidden{overflow:hidden}.overflow-x-auto{overflow-x:auto}.overflow-x-hidden{overflow-x:hidden}.overflow-y-auto{overflow-y:auto}.overflow-y-hidden{overflow-y:hidden}.rounded{border-radius:.25rem}.rounded-2xl{border-radius:var(--radius-2xl)}.rounded-\\[inherit\\]{border-radius:inherit}.rounded-full{border-radius:3.40282e38px}.rounded-lg{border-radius:var(--radius)}.rounded-md{border-radius:calc(var(--radius) - 2px)}.rounded-sm{border-radius:calc(var(--radius) - 4px)}.rounded-t-\\[10px\\]{border-top-left-radius:10px;border-top-right-radius:10px}.border{border-style:var(--tw-border-style);border-width:1px}.border-0{border-style:var(--tw-border-style);border-width:0}.border-2{border-style:var(--tw-border-style);border-width:2px}.border-t{border-top-style:var(--tw-border-style);border-top-width:1px}.border-r{border-right-style:var(--tw-border-style);border-right-width:1px}.border-b{border-bottom-style:var(--tw-border-style);border-bottom-width:1px}.border-b-2{border-bottom-style:var(--tw-border-style);border-bottom-width:2px}.border-l{border-left-style:var(--tw-border-style);border-left-width:1px}.border-dashed{--tw-border-style:dashed;border-style:dashed}.border-none{--tw-border-style:none;border-style:none}.border-blue-600{border-color:var(--color-blue-600)}.border-destructive\\/50{border-color:hsl(var(--destructive))}@supports (color:color-mix(in lab,red,red)){.border-destructive\\/50{border-color:color-mix(in oklab,hsl(var(--destructive))50%,transparent)}}.border-gray-200{border-color:var(--color-gray-200)}.border-gray-300{border-color:var(--color-gray-300)}.border-green-200{border-color:var(--color-green-200)}.border-green-500\\/50{border-color:#00c75880}@supports (color:color-mix(in lab,red,red)){.border-green-500\\/50{border-color:color-mix(in oklab,var(--color-green-500)50%,transparent)}}.border-green-600{border-color:var(--color-green-600)}.border-input{border-color:hsl(var(--input))}.border-primary,.border-primary\\/20{border-color:hsl(var(--primary))}@supports (color:color-mix(in lab,red,red)){.border-primary\\/20{border-color:color-mix(in oklab,hsl(var(--primary))20%,transparent)}}.border-primary\\/50{border-color:hsl(var(--primary))}@supports (color:color-mix(in lab,red,red)){.border-primary\\/50{border-color:color-mix(in oklab,hsl(var(--primary))50%,transparent)}}.border-transparent{border-color:#0000}.border-yellow-500\\/50{border-color:#edb20080}@supports (color:color-mix(in lab,red,red)){.border-yellow-500\\/50{border-color:color-mix(in oklab,var(--color-yellow-500)50%,transparent)}}.border-t-transparent{border-top-color:#0000}.border-l-transparent{border-left-color:#0000}.bg-background{background-color:hsl(var(--background))}.bg-black\\/50{background-color:#00000080}@supports (color:color-mix(in lab,red,red)){.bg-black\\/50{background-color:color-mix(in oklab,var(--color-black)50%,transparent)}}.bg-black\\/80{background-color:#000c}@supports (color:color-mix(in lab,red,red)){.bg-black\\/80{background-color:color-mix(in oklab,var(--color-black)80%,transparent)}}.bg-blue-600{background-color:var(--color-blue-600)}.bg-border{background-color:hsl(var(--border))}.bg-card{background-color:hsl(var(--card))}.bg-destructive,.bg-destructive\\/10{background-color:hsl(var(--destructive))}@supports (color:color-mix(in lab,red,red)){.bg-destructive\\/10{background-color:color-mix(in oklab,hsl(var(--destructive))10%,transparent)}}.bg-foreground,.bg-foreground\\/5{background-color:hsl(var(--foreground))}@supports (color:color-mix(in lab,red,red)){.bg-foreground\\/5{background-color:color-mix(in oklab,hsl(var(--foreground))5%,transparent)}}.bg-gray-50{background-color:var(--color-gray-50)}.bg-gray-100{background-color:var(--color-gray-100)}.bg-gray-200{background-color:var(--color-gray-200)}.bg-gray-400{background-color:var(--color-gray-400)}.bg-gray-600{background-color:var(--color-gray-600)}.bg-green-50{background-color:var(--color-green-50)}.bg-green-100{background-color:var(--color-green-100)}.bg-green-500{background-color:var(--color-green-500)}.bg-muted{background-color:hsl(var(--muted))}.bg-muted-foreground\\/30{background-color:hsl(var(--muted-foreground))}@supports (color:color-mix(in lab,red,red)){.bg-muted-foreground\\/30{background-color:color-mix(in oklab,hsl(var(--muted-foreground))30%,transparent)}}.bg-muted\\/50{background-color:hsl(var(--muted))}@supports (color:color-mix(in lab,red,red)){.bg-muted\\/50{background-color:color-mix(in oklab,hsl(var(--muted))50%,transparent)}}.bg-primary,.bg-primary\\/10{background-color:hsl(var(--primary))}@supports (color:color-mix(in lab,red,red)){.bg-primary\\/10{background-color:color-mix(in oklab,hsl(var(--primary))10%,transparent)}}.bg-red-50{background-color:var(--color-red-50)}.bg-red-100{background-color:var(--color-red-100)}.bg-red-500{background-color:var(--color-red-500)}.bg-secondary{background-color:hsl(var(--secondary))}.bg-white{background-color:var(--color-white)}.bg-white\\/80{background-color:#fffc}@supports (color:color-mix(in lab,red,red)){.bg-white\\/80{background-color:color-mix(in oklab,var(--color-white)80%,transparent)}}.bg-yellow-50{background-color:var(--color-yellow-50)}.bg-yellow-100{background-color:var(--color-yellow-100)}.bg-yellow-500{background-color:var(--color-yellow-500)}.bg-gradient-to-br{--tw-gradient-position:to bottom right in oklab;background-image:linear-gradient(var(--tw-gradient-stops))}.bg-gradient-to-r{--tw-gradient-position:to right in oklab;background-image:linear-gradient(var(--tw-gradient-stops))}.from-blue-100{--tw-gradient-from:var(--color-blue-100);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-blue-500{--tw-gradient-from:var(--color-blue-500);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.from-blue-600{--tw-gradient-from:var(--color-blue-600);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.to-purple-100{--tw-gradient-to:var(--color-purple-100);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.to-purple-600{--tw-gradient-to:var(--color-purple-600);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.p-0{padding:calc(var(--spacing)*0)}.p-1{padding:calc(var(--spacing)*1)}.p-2{padding:calc(var(--spacing)*2)}.p-3{padding:calc(var(--spacing)*3)}.p-4{padding:calc(var(--spacing)*4)}.p-6{padding:calc(var(--spacing)*6)}.p-8{padding:calc(var(--spacing)*8)}.p-\\[1px\\]{padding:1px}.px-2{padding-inline:calc(var(--spacing)*2)}.px-2\\.5{padding-inline:calc(var(--spacing)*2.5)}.px-3{padding-inline:calc(var(--spacing)*3)}.px-4{padding-inline:calc(var(--spacing)*4)}.px-6{padding-inline:calc(var(--spacing)*6)}.px-8{padding-inline:calc(var(--spacing)*8)}.py-0\\.5{padding-block:calc(var(--spacing)*.5)}.py-1{padding-block:calc(var(--spacing)*1)}.py-1\\.5{padding-block:calc(var(--spacing)*1.5)}.py-2{padding-block:calc(var(--spacing)*2)}.py-3{padding-block:calc(var(--spacing)*3)}.py-4{padding-block:calc(var(--spacing)*4)}.py-6{padding-block:calc(var(--spacing)*6)}.py-8{padding-block:calc(var(--spacing)*8)}.py-12{padding-block:calc(var(--spacing)*12)}.pt-0{padding-top:calc(var(--spacing)*0)}.pt-2{padding-top:calc(var(--spacing)*2)}.pt-4{padding-top:calc(var(--spacing)*4)}.pt-6{padding-top:calc(var(--spacing)*6)}.pt-8{padding-top:calc(var(--spacing)*8)}.pr-4{padding-right:calc(var(--spacing)*4)}.pr-6{padding-right:calc(var(--spacing)*6)}.pr-8{padding-right:calc(var(--spacing)*8)}.pb-2{padding-bottom:calc(var(--spacing)*2)}.pb-4{padding-bottom:calc(var(--spacing)*4)}.pb-6{padding-bottom:calc(var(--spacing)*6)}.text-center{text-align:center}.text-left{text-align:left}.text-right{text-align:right}.align-middle{vertical-align:middle}.text-2xl{font-size:var(--text-2xl);line-height:var(--tw-leading,var(--text-2xl--line-height))}.text-3xl{font-size:var(--text-3xl);line-height:var(--tw-leading,var(--text-3xl--line-height))}.text-4xl{font-size:var(--text-4xl);line-height:var(--tw-leading,var(--text-4xl--line-height))}.text-5xl{font-size:var(--text-5xl);line-height:var(--tw-leading,var(--text-5xl--line-height))}.text-base{font-size:var(--text-base);line-height:var(--tw-leading,var(--text-base--line-height))}.text-lg{font-size:var(--text-lg);line-height:var(--tw-leading,var(--text-lg--line-height))}.text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.text-xl{font-size:var(--text-xl);line-height:var(--tw-leading,var(--text-xl--line-height))}.text-xs{font-size:var(--text-xs);line-height:var(--tw-leading,var(--text-xs--line-height))}.leading-none{--tw-leading:1;line-height:1}.leading-tight{--tw-leading:var(--leading-tight);line-height:var(--leading-tight)}.font-bold{--tw-font-weight:var(--font-weight-bold);font-weight:var(--font-weight-bold)}.font-medium{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.font-normal{--tw-font-weight:var(--font-weight-normal);font-weight:var(--font-weight-normal)}.font-semibold{--tw-font-weight:var(--font-weight-semibold);font-weight:var(--font-weight-semibold)}.tracking-tight{--tw-tracking:var(--tracking-tight);letter-spacing:var(--tracking-tight)}.whitespace-nowrap{white-space:nowrap}.text-amber-500{color:var(--color-amber-500)}.text-background,.text-background\\/70{color:hsl(var(--background))}@supports (color:color-mix(in lab,red,red)){.text-background\\/70{color:color-mix(in oklab,hsl(var(--background))70%,transparent)}}.text-blue-800{color:var(--color-blue-800)}.text-card-foreground{color:hsl(var(--card-foreground))}.text-destructive{color:hsl(var(--destructive))}.text-destructive-foreground{color:hsl(var(--destructive-foreground))}.text-foreground{color:hsl(var(--foreground))}.text-gray-400{color:var(--color-gray-400)}.text-gray-500{color:var(--color-gray-500)}.text-gray-600{color:var(--color-gray-600)}.text-gray-700{color:var(--color-gray-700)}.text-gray-900{color:var(--color-gray-900)}.text-green-500{color:var(--color-green-500)}.text-green-600{color:var(--color-green-600)}.text-green-700{color:var(--color-green-700)}.text-green-800{color:var(--color-green-800)}.text-green-900{color:var(--color-green-900)}.text-muted-foreground{color:hsl(var(--muted-foreground))}.text-primary{color:hsl(var(--primary))}.text-primary-foreground{color:hsl(var(--primary-foreground))}.text-red-500{color:var(--color-red-500)}.text-red-600{color:var(--color-red-600)}.text-red-800{color:var(--color-red-800)}.text-secondary-foreground{color:hsl(var(--secondary-foreground))}.text-white{color:var(--color-white)}.text-yellow-600{color:var(--color-yellow-600)}.text-yellow-800{color:var(--color-yellow-800)}.text-yellow-900{color:var(--color-yellow-900)}.uppercase{text-transform:uppercase}.underline{text-decoration-line:underline}.underline-offset-4{text-underline-offset:4px}.opacity-0{opacity:0}.opacity-25{opacity:.25}.opacity-50{opacity:.5}.opacity-60{opacity:.6}.opacity-70{opacity:.7}.opacity-75{opacity:.75}.opacity-100{opacity:1}.shadow{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a),0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-lg{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a),0 4px 6px -4px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-sm{--tw-shadow:0 1px 3px 0 var(--tw-shadow-color,#0000001a),0 1px 2px -1px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.shadow-xl{--tw-shadow:0 20px 25px -5px var(--tw-shadow-color,#0000001a),0 8px 10px -6px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.ring{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(1px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.ring-2{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(2px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.ring-primary{--tw-ring-color:hsl(var(--primary))}.ring-offset-background{--tw-ring-offset-color:hsl(var(--background))}.outline{outline-style:var(--tw-outline-style);outline-width:1px}.filter{filter:var(--tw-blur,)var(--tw-brightness,)var(--tw-contrast,)var(--tw-grayscale,)var(--tw-hue-rotate,)var(--tw-invert,)var(--tw-saturate,)var(--tw-sepia,)var(--tw-drop-shadow,)}.backdrop-blur-sm{--tw-backdrop-blur:blur(var(--blur-sm));-webkit-backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,);backdrop-filter:var(--tw-backdrop-blur,)var(--tw-backdrop-brightness,)var(--tw-backdrop-contrast,)var(--tw-backdrop-grayscale,)var(--tw-backdrop-hue-rotate,)var(--tw-backdrop-invert,)var(--tw-backdrop-opacity,)var(--tw-backdrop-saturate,)var(--tw-backdrop-sepia,)}.transition-all{transition-property:all;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-colors{transition-property:color,background-color,border-color,outline-color,text-decoration-color,fill,stroke,--tw-gradient-from,--tw-gradient-via,--tw-gradient-to;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-opacity{transition-property:opacity;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.transition-transform{transition-property:transform,translate,scale,rotate;transition-timing-function:var(--tw-ease,var(--default-transition-timing-function));transition-duration:var(--tw-duration,var(--default-transition-duration))}.duration-150{--tw-duration:.15s;transition-duration:.15s}.duration-200{--tw-duration:.2s;transition-duration:.2s}.duration-300{--tw-duration:.3s;transition-duration:.3s}.duration-400{--tw-duration:.4s;transition-duration:.4s}.ease-in-out{--tw-ease:var(--ease-in-out);transition-timing-function:var(--ease-in-out)}.ease-out{--tw-ease:var(--ease-out);transition-timing-function:var(--ease-out)}.select-none{-webkit-user-select:none;user-select:none}.\\[-ms-overflow-style\\:none\\]{-ms-overflow-style:none}.\\[scrollbar-width\\:none\\]{scrollbar-width:none}.peer-disabled\\:cursor-not-allowed:is(:where(.peer):disabled~*){cursor:not-allowed}.peer-disabled\\:opacity-70:is(:where(.peer):disabled~*){opacity:.7}.file\\:border-0::file-selector-button{border-style:var(--tw-border-style);border-width:0}.file\\:bg-transparent::file-selector-button{background-color:#0000}.file\\:text-sm::file-selector-button{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}.file\\:font-medium::file-selector-button{--tw-font-weight:var(--font-weight-medium);font-weight:var(--font-weight-medium)}.file\\:text-foreground::file-selector-button{color:hsl(var(--foreground))}.placeholder\\:text-muted-foreground::placeholder{color:hsl(var(--muted-foreground))}.checked\\:bg-primary:checked{background-color:hsl(var(--primary))}.checked\\:text-primary-foreground:checked{color:hsl(var(--primary-foreground))}@media(hover:hover){.hover\\:border-gray-300:hover{border-color:var(--color-gray-300)}.hover\\:border-primary:hover{border-color:hsl(var(--primary))}.hover\\:bg-accent:hover{background-color:hsl(var(--accent))}.hover\\:bg-background\\/50:hover{background-color:hsl(var(--background))}@supports (color:color-mix(in lab,red,red)){.hover\\:bg-background\\/50:hover{background-color:color-mix(in oklab,hsl(var(--background))50%,transparent)}}.hover\\:bg-destructive\\/80:hover{background-color:hsl(var(--destructive))}@supports (color:color-mix(in lab,red,red)){.hover\\:bg-destructive\\/80:hover{background-color:color-mix(in oklab,hsl(var(--destructive))80%,transparent)}}.hover\\:bg-destructive\\/90:hover{background-color:hsl(var(--destructive))}@supports (color:color-mix(in lab,red,red)){.hover\\:bg-destructive\\/90:hover{background-color:color-mix(in oklab,hsl(var(--destructive))90%,transparent)}}.hover\\:bg-foreground\\/90:hover{background-color:hsl(var(--foreground))}@supports (color:color-mix(in lab,red,red)){.hover\\:bg-foreground\\/90:hover{background-color:color-mix(in oklab,hsl(var(--foreground))90%,transparent)}}.hover\\:bg-gray-200:hover{background-color:var(--color-gray-200)}.hover\\:bg-gray-300:hover{background-color:var(--color-gray-300)}.hover\\:bg-gray-600:hover{background-color:var(--color-gray-600)}.hover\\:bg-gray-700:hover{background-color:var(--color-gray-700)}.hover\\:bg-green-500\\/80:hover{background-color:#00c758cc}@supports (color:color-mix(in lab,red,red)){.hover\\:bg-green-500\\/80:hover{background-color:color-mix(in oklab,var(--color-green-500)80%,transparent)}}.hover\\:bg-muted:hover,.hover\\:bg-muted\\/50:hover{background-color:hsl(var(--muted))}@supports (color:color-mix(in lab,red,red)){.hover\\:bg-muted\\/50:hover{background-color:color-mix(in oklab,hsl(var(--muted))50%,transparent)}}.hover\\:bg-primary\\/80:hover{background-color:hsl(var(--primary))}@supports (color:color-mix(in lab,red,red)){.hover\\:bg-primary\\/80:hover{background-color:color-mix(in oklab,hsl(var(--primary))80%,transparent)}}.hover\\:bg-primary\\/90:hover{background-color:hsl(var(--primary))}@supports (color:color-mix(in lab,red,red)){.hover\\:bg-primary\\/90:hover{background-color:color-mix(in oklab,hsl(var(--primary))90%,transparent)}}.hover\\:bg-secondary\\/80:hover{background-color:hsl(var(--secondary))}@supports (color:color-mix(in lab,red,red)){.hover\\:bg-secondary\\/80:hover{background-color:color-mix(in oklab,hsl(var(--secondary))80%,transparent)}}.hover\\:bg-transparent:hover{background-color:#0000}.hover\\:bg-yellow-500\\/80:hover{background-color:#edb200cc}@supports (color:color-mix(in lab,red,red)){.hover\\:bg-yellow-500\\/80:hover{background-color:color-mix(in oklab,var(--color-yellow-500)80%,transparent)}}.hover\\:from-blue-700:hover{--tw-gradient-from:var(--color-blue-700);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.hover\\:to-purple-700:hover{--tw-gradient-to:var(--color-purple-700);--tw-gradient-stops:var(--tw-gradient-via-stops,var(--tw-gradient-position),var(--tw-gradient-from)var(--tw-gradient-from-position),var(--tw-gradient-to)var(--tw-gradient-to-position))}.hover\\:text-accent-foreground:hover{color:hsl(var(--accent-foreground))}.hover\\:text-destructive:hover{color:hsl(var(--destructive))}.hover\\:text-foreground:hover{color:hsl(var(--foreground))}.hover\\:text-gray-700:hover{color:var(--color-gray-700)}.hover\\:text-yellow-900:hover{color:var(--color-yellow-900)}.hover\\:underline:hover{text-decoration-line:underline}.hover\\:opacity-100:hover{opacity:1}.hover\\:shadow-lg:hover{--tw-shadow:0 10px 15px -3px var(--tw-shadow-color,#0000001a),0 4px 6px -4px var(--tw-shadow-color,#0000001a);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}}.focus\\:ring-2:focus{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(2px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.focus\\:ring-blue-500:focus{--tw-ring-color:var(--color-blue-500)}.focus\\:ring-ring:focus{--tw-ring-color:hsl(var(--ring))}.focus\\:ring-offset-2:focus{--tw-ring-offset-width:2px;--tw-ring-offset-shadow:var(--tw-ring-inset,)0 0 0 var(--tw-ring-offset-width)var(--tw-ring-offset-color)}.focus\\:outline-none:focus{--tw-outline-style:none;outline-style:none}.focus-visible\\:ring-2:focus-visible{--tw-ring-shadow:var(--tw-ring-inset,)0 0 0 calc(2px + var(--tw-ring-offset-width))var(--tw-ring-color,currentcolor);box-shadow:var(--tw-inset-shadow),var(--tw-inset-ring-shadow),var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}.focus-visible\\:ring-ring:focus-visible{--tw-ring-color:hsl(var(--ring))}.focus-visible\\:ring-offset-2:focus-visible{--tw-ring-offset-width:2px;--tw-ring-offset-shadow:var(--tw-ring-inset,)0 0 0 var(--tw-ring-offset-width)var(--tw-ring-offset-color)}.focus-visible\\:outline-none:focus-visible{--tw-outline-style:none;outline-style:none}.disabled\\:pointer-events-none:disabled{pointer-events:none}.disabled\\:cursor-not-allowed:disabled{cursor:not-allowed}.disabled\\:opacity-50:disabled{opacity:.5}.data-\\[state\\=selected\\]\\:bg-muted[data-state=selected]{background-color:hsl(var(--muted))}@media(min-width:40rem){.sm\\:max-w-2xl{max-width:var(--container-2xl)}.sm\\:max-w-6xl{max-width:var(--container-6xl)}.sm\\:max-w-\\[500px\\]{max-width:500px}.sm\\:max-w-\\[600px\\]{max-width:600px}.sm\\:max-w-\\[800px\\]{max-width:800px}.sm\\:max-w-lg{max-width:var(--container-lg)}.sm\\:max-w-md{max-width:var(--container-md)}.sm\\:max-w-sm{max-width:var(--container-sm)}.sm\\:flex-1{flex:1}.sm\\:flex-row{flex-direction:row}.sm\\:justify-end{justify-content:flex-end}:where(.sm\\:space-x-2>:not(:last-child)){--tw-space-x-reverse:0;margin-inline-start:calc(calc(var(--spacing)*2)*var(--tw-space-x-reverse));margin-inline-end:calc(calc(var(--spacing)*2)*calc(1 - var(--tw-space-x-reverse)))}.sm\\:rounded-lg{border-radius:var(--radius)}.sm\\:px-6{padding-inline:calc(var(--spacing)*6)}.sm\\:text-left{text-align:left}}@media(min-width:48rem){.md\\:inset-auto{inset:auto}.md\\:top-1\\/2{top:50%}.md\\:left-1\\/2{left:50%}.md\\:hidden{display:none}.md\\:max-h-\\[90vh\\]{max-height:90vh}.md\\:max-h-\\[calc\\(90vh-2rem\\)\\]{max-height:calc(90vh - 2rem)}.md\\:w-full{width:100%}.md\\:max-w-\\[500px\\]{max-width:500px}.md\\:-translate-x-1\\/2{--tw-translate-x: -50% ;translate:var(--tw-translate-x)var(--tw-translate-y)}.md\\:-translate-y-1\\/2{--tw-translate-y: -50% ;translate:var(--tw-translate-x)var(--tw-translate-y)}.md\\:grid-cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.md\\:rounded-lg{border-radius:var(--radius)}.md\\:border{border-style:var(--tw-border-style);border-width:1px}.md\\:pt-6{padding-top:calc(var(--spacing)*6)}.md\\:text-sm{font-size:var(--text-sm);line-height:var(--tw-leading,var(--text-sm--line-height))}}@media(min-width:64rem){.lg\\:grid-cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.lg\\:px-8{padding-inline:calc(var(--spacing)*8)}}@media(prefers-color-scheme:dark){.dark\\:border-destructive{border-color:hsl(var(--destructive))}.dark\\:border-green-800{border-color:var(--color-green-800)}.dark\\:bg-green-900{background-color:var(--color-green-900)}.dark\\:bg-green-900\\/10{background-color:#0d542b1a}@supports (color:color-mix(in lab,red,red)){.dark\\:bg-green-900\\/10{background-color:color-mix(in oklab,var(--color-green-900)10%,transparent)}}.dark\\:bg-green-900\\/20{background-color:#0d542b33}@supports (color:color-mix(in lab,red,red)){.dark\\:bg-green-900\\/20{background-color:color-mix(in oklab,var(--color-green-900)20%,transparent)}}.dark\\:bg-yellow-900\\/10{background-color:#733e0a1a}@supports (color:color-mix(in lab,red,red)){.dark\\:bg-yellow-900\\/10{background-color:color-mix(in oklab,var(--color-yellow-900)10%,transparent)}}.dark\\:text-green-200{color:var(--color-green-200)}.dark\\:text-green-300{color:var(--color-green-300)}.dark\\:text-green-400{color:var(--color-green-400)}.dark\\:text-green-500{color:var(--color-green-500)}.dark\\:text-yellow-500{color:var(--color-yellow-500)}}.\\[\\&_p\\]\\:leading-relaxed p{--tw-leading:var(--leading-relaxed);line-height:var(--leading-relaxed)}.\\[\\&_svg\\]\\:pointer-events-none svg{pointer-events:none}.\\[\\&_svg\\]\\:size-4 svg{width:calc(var(--spacing)*4);height:calc(var(--spacing)*4)}.\\[\\&_svg\\]\\:shrink-0 svg{flex-shrink:0}.\\[\\&_tr\\]\\:border-b tr{border-bottom-style:var(--tw-border-style);border-bottom-width:1px}.\\[\\&_tr\\:last-child\\]\\:border-0 tr:last-child{border-style:var(--tw-border-style);border-width:0}.\\[\\&\\:\\:-webkit-scrollbar\\]\\:hidden::-webkit-scrollbar{display:none}.\\[\\&\\:has\\(\\[role\\=checkbox\\]\\)\\]\\:pr-0:has([role=checkbox]){padding-right:calc(var(--spacing)*0)}.\\[\\&\\>svg\\]\\:absolute>svg{position:absolute}.\\[\\&\\>svg\\]\\:top-4>svg{top:calc(var(--spacing)*4)}.\\[\\&\\>svg\\]\\:left-4>svg{left:calc(var(--spacing)*4)}.\\[\\&\\>svg\\]\\:text-destructive>svg{color:hsl(var(--destructive))}.\\[\\&\\>svg\\]\\:text-foreground>svg{color:hsl(var(--foreground))}.\\[\\&\\>svg\\]\\:text-green-500>svg{color:var(--color-green-500)}.\\[\\&\\>svg\\]\\:text-yellow-500>svg{color:var(--color-yellow-500)}.\\[\\&\\>svg\\+div\\]\\:translate-y-\\[-3px\\]>svg+div{--tw-translate-y:-3px;translate:var(--tw-translate-x)var(--tw-translate-y)}.\\[\\&\\>svg\\~\\*\\]\\:pl-7>svg~*{padding-left:calc(var(--spacing)*7)}.\\[\\&\\>tr\\]\\:last\\:border-b-0>tr:last-child{border-bottom-style:var(--tw-border-style);border-bottom-width:0}}:root{--background:0 0% 100%;--foreground:222.2 84% 4.9%;--card:0 0% 100%;--card-foreground:222.2 84% 4.9%;--popover:0 0% 100%;--popover-foreground:222.2 84% 4.9%;--primary:222.2 47.4% 11.2%;--primary-foreground:210 40% 98%;--secondary:210 40% 96.1%;--secondary-foreground:222.2 47.4% 11.2%;--muted:210 40% 96.1%;--muted-foreground:215.4 16.3% 46.9%;--accent:210 40% 96.1%;--accent-foreground:222.2 47.4% 11.2%;--destructive:0 84.2% 60.2%;--destructive-foreground:210 40% 98%;--border:214.3 31.8% 91.4%;--input:214.3 31.8% 91.4%;--ring:222.2 84% 4.9%;--radius:.5rem}.dark{--background:222.2 84% 4.9%;--foreground:210 40% 98%;--card:222.2 84% 4.9%;--card-foreground:210 40% 98%;--popover:222.2 84% 4.9%;--popover-foreground:210 40% 98%;--primary:210 40% 98%;--primary-foreground:222.2 47.4% 11.2%;--secondary:217.2 32.6% 17.5%;--secondary-foreground:210 40% 98%;--muted:217.2 32.6% 17.5%;--muted-foreground:215 20.2% 65.1%;--accent:217.2 32.6% 17.5%;--accent-foreground:210 40% 98%;--destructive:0 62.8% 30.6%;--destructive-foreground:210 40% 98%;--border:217.2 32.6% 17.5%;--input:217.2 32.6% 17.5%;--ring:212.7 26.8% 83.9%}@keyframes accordion-down{0%{height:0}to{height:var(--radix-accordion-content-height)}}@keyframes accordion-up{0%{height:var(--radix-accordion-content-height)}to{height:0}}.animate-accordion-down{animation:.2s ease-out accordion-down}.animate-accordion-up{animation:.2s ease-out accordion-up}@property --tw-translate-x{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-y{syntax:"*";inherits:false;initial-value:0}@property --tw-translate-z{syntax:"*";inherits:false;initial-value:0}@property --tw-scale-x{syntax:"*";inherits:false;initial-value:1}@property --tw-scale-y{syntax:"*";inherits:false;initial-value:1}@property --tw-scale-z{syntax:"*";inherits:false;initial-value:1}@property --tw-rotate-x{syntax:"*";inherits:false}@property --tw-rotate-y{syntax:"*";inherits:false}@property --tw-rotate-z{syntax:"*";inherits:false}@property --tw-skew-x{syntax:"*";inherits:false}@property --tw-skew-y{syntax:"*";inherits:false}@property --tw-space-y-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-space-x-reverse{syntax:"*";inherits:false;initial-value:0}@property --tw-border-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-gradient-position{syntax:"*";inherits:false}@property --tw-gradient-from{syntax:"<color>";inherits:false;initial-value:#0000}@property --tw-gradient-via{syntax:"<color>";inherits:false;initial-value:#0000}@property --tw-gradient-to{syntax:"<color>";inherits:false;initial-value:#0000}@property --tw-gradient-stops{syntax:"*";inherits:false}@property --tw-gradient-via-stops{syntax:"*";inherits:false}@property --tw-gradient-from-position{syntax:"<length-percentage>";inherits:false;initial-value:0%}@property --tw-gradient-via-position{syntax:"<length-percentage>";inherits:false;initial-value:50%}@property --tw-gradient-to-position{syntax:"<length-percentage>";inherits:false;initial-value:100%}@property --tw-leading{syntax:"*";inherits:false}@property --tw-font-weight{syntax:"*";inherits:false}@property --tw-tracking{syntax:"*";inherits:false}@property --tw-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-shadow-color{syntax:"*";inherits:false}@property --tw-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-inset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-shadow-color{syntax:"*";inherits:false}@property --tw-inset-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-ring-color{syntax:"*";inherits:false}@property --tw-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-inset-ring-color{syntax:"*";inherits:false}@property --tw-inset-ring-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-ring-inset{syntax:"*";inherits:false}@property --tw-ring-offset-width{syntax:"<length>";inherits:false;initial-value:0}@property --tw-ring-offset-color{syntax:"*";inherits:false;initial-value:#fff}@property --tw-ring-offset-shadow{syntax:"*";inherits:false;initial-value:0 0 #0000}@property --tw-outline-style{syntax:"*";inherits:false;initial-value:solid}@property --tw-blur{syntax:"*";inherits:false}@property --tw-brightness{syntax:"*";inherits:false}@property --tw-contrast{syntax:"*";inherits:false}@property --tw-grayscale{syntax:"*";inherits:false}@property --tw-hue-rotate{syntax:"*";inherits:false}@property --tw-invert{syntax:"*";inherits:false}@property --tw-opacity{syntax:"*";inherits:false}@property --tw-saturate{syntax:"*";inherits:false}@property --tw-sepia{syntax:"*";inherits:false}@property --tw-drop-shadow{syntax:"*";inherits:false}@property --tw-drop-shadow-color{syntax:"*";inherits:false}@property --tw-drop-shadow-alpha{syntax:"<percentage>";inherits:false;initial-value:100%}@property --tw-drop-shadow-size{syntax:"*";inherits:false}@property --tw-backdrop-blur{syntax:"*";inherits:false}@property --tw-backdrop-brightness{syntax:"*";inherits:false}@property --tw-backdrop-contrast{syntax:"*";inherits:false}@property --tw-backdrop-grayscale{syntax:"*";inherits:false}@property --tw-backdrop-hue-rotate{syntax:"*";inherits:false}@property --tw-backdrop-invert{syntax:"*";inherits:false}@property --tw-backdrop-opacity{syntax:"*";inherits:false}@property --tw-backdrop-saturate{syntax:"*";inherits:false}@property --tw-backdrop-sepia{syntax:"*";inherits:false}@property --tw-duration{syntax:"*";inherits:false}@property --tw-ease{syntax:"*";inherits:false}@keyframes spin{to{transform:rotate(360deg)}}@keyframes pulse{50%{opacity:.5}}')),document.head.appendChild(r)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
- "use strict";var Ps=Object.defineProperty;var Es=(t,s,r)=>s in t?Ps(t,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[s]=r;var se=(t,s,r)=>Es(t,typeof s!="symbol"?s+"":s,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("react"),P=require("@tanstack/react-query"),e=require("react/jsx-runtime"),Ds=require("react-dom/client"),Ts=require("clsx"),_s=require("tailwind-merge"),Pe=require("class-variance-authority"),dt=require("@stripe/stripe-js"),ce=require("@stripe/react-stripe-js"),Ls=require("react-hook-form"),ue=require("zod"),re=require("date-fns");function Rs(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(s,r,n.get?n:{enumerable:!0,get:()=>t[r]})}}return s.default=t,Object.freeze(s)}const d=Rs(C);class ne extends Error{constructor(s,r,n){super(s),this.status=r,this.data=n,this.name="BillingOSError",Object.setPrototypeOf(this,ne.prototype)}}class Ee extends ne{constructor(s="Unauthorized: Invalid or missing API key",r){super(s,401,r),this.name="UnauthorizedError",Object.setPrototypeOf(this,Ee.prototype)}}class De extends ne{constructor(s="Resource not found",r){super(s,404,r),this.name="NotFoundError",Object.setPrototypeOf(this,De.prototype)}}class Te extends ne{constructor(s="Validation failed",r){super(s,400,r),this.name="ValidationError",Object.setPrototypeOf(this,Te.prototype)}}class _e extends ne{constructor(s="Too many requests",r){super(s,429,r),this.name="RateLimitError",Object.setPrototypeOf(this,_e.prototype)}}class Ie extends ne{constructor(s="Internal server error",r){super(s,500,r),this.name="ServerError",Object.setPrototypeOf(this,Ie.prototype)}}class Ce extends ne{constructor(s="Network request failed",r){super(s,void 0,r),this.name="NetworkError",Object.setPrototypeOf(this,Ce.prototype)}}function Ms(t){return t instanceof Te}function Fs(t){return t instanceof Ee}function Is(t){return t instanceof De}function Us(t){return t instanceof _e}class Ve{constructor(s,r={}){se(this,"sessionToken");se(this,"baseUrl");se(this,"headers");se(this,"timeout");se(this,"checkout",{createSession:async s=>{var n,a;console.log("[SDK Client] Creating checkout session with:",{priceId:s.priceId,customer:s.customer,hasEmail:!!((n=s.customer)!=null&&n.email),hasName:!!((a=s.customer)!=null&&a.name)});const r=await this.post("/v1/checkout/create",s);return console.log("[SDK Client] Checkout session created:",{sessionId:r.id,status:r.status}),r},getSession:async s=>this.get(`/v1/checkout/${s}/status`),cancelSession:async s=>{throw new Error("Cancel session not implemented yet")},confirmPayment:async(s,r)=>this.post(`/v1/checkout/${s}/confirm`,{paymentMethodId:r}),applyCoupon:async(s,r)=>{throw new Error("Apply coupon not implemented yet")}});se(this,"portal",{createSession:async s=>{console.log("[SDK Client] Creating portal session");const r=await this.post("/v1/portal/create",s||{});return console.log("[SDK Client] Portal session created:",{sessionId:r.id,customerId:r.customerId,expiresAt:r.expiresAt}),{id:r.id,expiresAt:r.expiresAt}},getSessionStatus:async s=>this.get(`/v1/portal/${s}/status`),getPortalData:async s=>this.get(`/v1/portal/${s}/data`)});if(!s)throw new Error("Session token is required");this.sessionToken=s,this.timeout=r.timeout||3e4,r.baseUrl?this.baseUrl=r.baseUrl:r.environment==="sandbox"?this.baseUrl="https://sandbox.billingos.com/api":this.baseUrl=process.env.NEXT_PUBLIC_API_URL||"http://localhost:3001",this.headers={"Content-Type":"application/json",Authorization:`Bearer ${this.sessionToken}`,"X-BillingOS-Version":r.version||"2026-01-01",...r.headers}}async request(s,r={}){var l;const n=`${this.baseUrl}${s}`,a=new AbortController,i=setTimeout(()=>a.abort(),this.timeout);try{const o=await fetch(n,{...r,headers:{...this.headers,...r.headers},signal:a.signal});if(clearTimeout(i),o.status===204)return;const c=o.headers.get("content-type"),u=c==null?void 0:c.includes("application/json"),m=u?await o.json():await o.text();if(!o.ok){const x=u?m:{error:{message:m}},p=((l=x.error)==null?void 0:l.message)||`Request failed with status ${o.status}`;switch(o.status){case 400:throw new Te(p,x);case 401:throw new Ee(p,x);case 404:throw new De(p,x);case 429:throw new _e(p,x);case 500:case 502:case 503:case 504:throw new Ie(p,x);default:throw new ne(p,o.status,x)}}return m}catch(o){throw clearTimeout(i),o instanceof ne?o:o instanceof Error&&o.name==="AbortError"?new Ce("Request timeout"):new Ce("Network request failed",o)}}get(s){return this.request(s,{method:"GET"})}post(s,r){return this.request(s,{method:"POST",body:r?JSON.stringify(r):void 0})}patch(s,r){return this.request(s,{method:"PATCH",body:r?JSON.stringify(r):void 0})}delete(s){return this.request(s,{method:"DELETE"})}async createCustomer(s){return this.post("/customers",s)}async getCustomer(s){return this.get(`/customers/${s}`)}async listCustomers(s){const r=new URLSearchParams;s!=null&&s.page&&r.set("page",s.page.toString()),s!=null&&s.page_size&&r.set("page_size",s.page_size.toString());const n=r.toString();return this.get(`/customers${n?`?${n}`:""}`)}async updateCustomer(s,r){return this.patch(`/customers/${s}`,r)}async deleteCustomer(s){return this.delete(`/customers/${s}`)}async createSubscription(s){return this.post("/subscriptions",s)}async getSubscription(s){return this.get(`/subscriptions/${s}`)}async listSubscriptions(s){const r=new URLSearchParams;s!=null&&s.customer_id&&r.set("customer_id",s.customer_id),s!=null&&s.page&&r.set("page",s.page.toString()),s!=null&&s.page_size&&r.set("page_size",s.page_size.toString());const n=r.toString();return this.get(`/subscriptions${n?`?${n}`:""}`)}async updateSubscription(s,r){return this.patch(`/subscriptions/${s}`,r)}async cancelSubscription(s,r=!1){return this.post(`/subscriptions/${s}/cancel`,{immediately:r})}async reactivateSubscription(s){return this.post(`/subscriptions/${s}/reactivate`)}async previewSubscription(s,r){return this.post(`/subscriptions/${s}/preview`,r)}async getAvailablePlans(s){return this.get(`/subscriptions/${s}/available-plans`)}async previewPlanChange(s,r){return this.post(`/subscriptions/${s}/preview-change`,r)}async changePlan(s,r){return this.post(`/subscriptions/${s}/change-plan`,r)}async checkEntitlement(s){return this.get(`/v1/features/check?feature_key=${encodeURIComponent(s.feature_key)}`)}async listEntitlements(s){return(await this.get("/v1/features/entitlements")).entitlements}async trackUsage(s){return this.post("/v1/features/track-usage",{feature_key:s.feature_key,quantity:s.quantity,timestamp:s.timestamp,idempotency_key:s.idempotency_key,metadata:s.metadata})}async getUsageMetrics(s,r){var i;const n=r?`?feature_key=${encodeURIComponent(r)}`:"";return((i=(await this.get(`/v1/features/usage-metrics${n}`)).metrics)==null?void 0:i[0])??{feature_key:r||"",current_usage:0,period_start:"",period_end:""}}async getInvoice(s){return this.get(`/invoices/${s}`)}async listInvoices(s){const r=new URLSearchParams;s!=null&&s.customer_id&&r.set("customer_id",s.customer_id),s!=null&&s.page&&r.set("page",s.page.toString()),s!=null&&s.page_size&&r.set("page_size",s.page_size.toString());const n=r.toString();return this.get(`/invoices${n?`?${n}`:""}`)}async listPaymentMethods(s){return this.get(`/payment-methods?customer_id=${s}`)}async removePaymentMethod(s){return this.delete(`/payment-methods/${s}`)}async setDefaultPaymentMethod(s){return this.post(`/payment-methods/${s}/set-default`)}async getCustomerPortal(){return this.get("/sdk/customer/portal")}async updatePortalSubscription(s,r){return this.post(`/sdk/subscriptions/${s}/update`,r)}async cancelPortalSubscription(s,r){return this.post(`/sdk/subscriptions/${s}/cancel`,r)}async reactivatePortalSubscription(s){return this.post(`/sdk/subscriptions/${s}/reactivate`)}async addPaymentMethod(s){return this.post("/sdk/payment-methods",s)}async getSetupIntent(){return this.post("/sdk/payment-methods/setup-intent")}async retryInvoice(s,r){return this.post(`/sdk/invoices/${s}/retry`,{paymentMethodId:r})}async updateCustomerBilling(s){return this.patch("/sdk/customer/billing",s)}async createCheckout(s){return this.post("/v1/checkout/create",s)}async confirmCheckout(s,r){return this.post(`/v1/checkout/${s}/confirm`,{paymentMethodId:r})}async getProducts(s){const r=new URLSearchParams;s&&s.length>0&&r.set("planIds",s.join(","));const n=r.toString();return this.get(`/v1/products${n?`?${n}`:""}`)}async checkUsage(){const n=((await this.get("/v1/features/usage-metrics")).metrics||[]).find(a=>!a.limit||a.limit===0?!1:a.consumed/a.limit*100>=80);return n?{shouldShowNudge:!0,trigger:{type:"usage_threshold",feature:n.feature_key,threshold:80,actual:Math.round(n.consumed/n.limit*100*10)/10,message:{title:"Approaching usage limit",body:`You've used ${Math.round(n.consumed/n.limit*100)}% of your ${n.feature_title||n.feature_key} limit.`,cta:"Upgrade plan"},suggestedPlan:{id:"",priceId:"",name:"",price:{amount:0,currency:"usd",interval:"month"},highlights:[]}}}:{shouldShowNudge:!1}}}function As(t,s){return new Ve(t,s)}function ut(t={}){const{tokenUrl:s,token:r,refreshBeforeExpiry:n=300,autoRefresh:a=!0,onTokenRefresh:i,onError:l}=t,[o,c]=C.useState(r||null),[u,m]=C.useState(null),[x,p]=C.useState(!!(s&&!r)),[y,f]=C.useState(null),g=C.useRef(null),v=C.useRef(!0),b=C.useCallback(async()=>{if(s)try{p(!0),f(null);const j=await fetch(s,{method:"GET",headers:{"Content-Type":"application/json"},credentials:"include"});if(!j.ok){const _=await j.json().catch(()=>({}));throw new Error(_.error||`Failed to fetch session token: ${j.statusText}`)}const S=await j.json();if(!v.current)return;c(S.sessionToken),m(new Date(S.expiresAt)),f(null),i==null||i(S.sessionToken)}catch(j){const S=j instanceof Error?j:new Error("Failed to fetch session token");if(!v.current)return;f(S),l==null||l(S)}finally{v.current&&p(!1)}},[s,i,l]);C.useEffect(()=>{if(!a||!u||!s)return;g.current&&clearTimeout(g.current);const j=Date.now(),_=u.getTime()-j,k=_-n*1e3;return k>0?g.current=setTimeout(()=>{b()},k):_>0&&b(),()=>{g.current&&clearTimeout(g.current)}},[u,a,n,s,b]),C.useEffect(()=>{s&&!r&&b()},[s,r,b]),C.useEffect(()=>{r&&(c(r),m(null))},[r]),C.useEffect(()=>()=>{v.current=!1,g.current&&clearTimeout(g.current)},[]);const w=!!(o&&(!u||u.getTime()>Date.now()));return{token:o,expiresAt:u,isLoading:x,error:y,refresh:b,isValid:w}}const mt=C.createContext(void 0),Bs=()=>new P.QueryClient({defaultOptions:{queries:{staleTime:1e3*60*5,gcTime:1e3*60*10,retry:1,refetchOnWindowFocus:!1},mutations:{retry:!1}}});function ht({sessionToken:t,sessionTokenUrl:s,sessionTokenOptions:r,customerId:n,customerEmail:a,customerName:i,organizationId:l,options:o,queryClient:c,children:u}){C.useEffect(()=>{console.log("%c🚀 BillingOS SDK v1.2.0 Initialized","color: #10b981; font-weight: bold; font-size: 16px;"),console.log("✨ Features: Real-time subscription updates, Customer data prefill, Iframe checkout")},[]);const{token:m,isLoading:x,error:p}=ut({token:t,tokenUrl:s,...r}),y=C.useMemo(()=>c||Bs(),[c]),f=C.useMemo(()=>m?new Ve(m,o):null,[m,o]),g=C.useMemo(()=>f?{client:f,customerId:n,customerEmail:a,customerName:i,organizationId:l}:null,[f,n,a,i,l]);return s&&x?null:s&&p?(console.error("Failed to fetch BillingOS session token:",p),null):!m||!f||!g?(console.error("BillingOS: No session token provided. Use sessionToken or sessionTokenUrl prop."),null):e.jsx(mt.Provider,{value:g,children:e.jsx(P.QueryClientProvider,{client:y,children:u})})}function D(){const t=C.useContext(mt);if(!t)throw new Error("useBillingOS must be used within a BillingOSProvider. Wrap your app with <BillingOSProvider> to use BillingOS hooks and components.");return t}const q={all:["subscriptions"],lists:()=>[...q.all,"list"],list:t=>[...q.lists(),t],details:()=>[...q.all,"detail"],detail:t=>[...q.details(),t],preview:(t,s)=>[...q.all,"preview",t,s]};function Os(t,s){const{client:r}=D();return P.useQuery({queryKey:q.detail(t),queryFn:()=>r.getSubscription(t),enabled:!!t,...s})}function qs(t,s){const{client:r}=D();return P.useQuery({queryKey:q.list(t),queryFn:()=>r.listSubscriptions(t),...s})}function zs(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({...t,mutationFn:n=>s.createSubscription(n),onSuccess:(n,a,i)=>{r.invalidateQueries({queryKey:q.lists()})}})}function $s(t,s){const{client:r}=D(),n=P.useQueryClient();return P.useMutation({...s,mutationFn:a=>r.updateSubscription(t,a),onSuccess:(a,i,l)=>{n.invalidateQueries({queryKey:q.detail(t)}),n.invalidateQueries({queryKey:q.lists()})}})}function Hs(t,s){const{client:r}=D(),n=P.useQueryClient();return P.useMutation({...s,mutationFn:({immediately:a=!1})=>r.cancelSubscription(t,a),onSuccess:(a,i,l)=>{n.invalidateQueries({queryKey:q.detail(t)}),n.invalidateQueries({queryKey:q.lists()})}})}function Qs(t,s){const{client:r}=D(),n=P.useQueryClient();return P.useMutation({...s,mutationFn:()=>r.reactivateSubscription(t),onSuccess:(a,i,l)=>{n.invalidateQueries({queryKey:q.detail(t)}),n.invalidateQueries({queryKey:q.lists()})}})}function Ks(t,s,r){const{client:n}=D();return P.useQuery({queryKey:q.preview(t,s),queryFn:()=>n.previewSubscription(t,s),enabled:!!t&&!!s,...r})}function xt(t,s){const{client:r}=D();return P.useQuery({queryKey:[...q.detail(t),"available-plans"],queryFn:()=>r.getAvailablePlans(t),enabled:!!t,...s})}function ft(t){const{client:s}=D();return P.useMutation({...t,mutationFn:({subscriptionId:r,input:n})=>s.previewPlanChange(r,n)})}function gt(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({...t,mutationFn:({subscriptionId:n,input:a})=>s.changePlan(n,a),onSuccess:(n,a,i)=>{r.invalidateQueries({queryKey:q.detail(a.subscriptionId)}),r.invalidateQueries({queryKey:q.lists()}),r.invalidateQueries({queryKey:[...q.detail(a.subscriptionId),"available-plans"]})}})}function h(...t){return _s.twMerge(Ts.clsx(t))}const pt=d.createContext(null);function Ue(){const t=d.useContext(pt);if(!t)throw new Error("Dialog components must be used within a Dialog provider");return t}function fe({open:t=!1,onOpenChange:s,children:r}){const[n,a]=d.useState(!1),i=t??n,l=s??a;return e.jsx(pt.Provider,{value:{open:i,onOpenChange:l},children:r})}const yt=d.forwardRef(({onClick:t,...s},r)=>{const{onOpenChange:n}=Ue();return e.jsx("button",{ref:r,type:"button",onClick:a=>{n(!0),t==null||t(a)},...s})});yt.displayName="DialogTrigger";function Vs({children:t}){const{open:s}=Ue();return s?e.jsx(e.Fragment,{children:t}):null}const We=d.forwardRef(({className:t,...s},r)=>{const{onOpenChange:n}=Ue();return e.jsx("div",{ref:r,onClick:()=>n(!1),className:h("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...s})});We.displayName="DialogOverlay";const he=d.forwardRef(({className:t,children:s,...r},n)=>{const{open:a,onOpenChange:i}=Ue();return d.useEffect(()=>{const l=o=>{o.key==="Escape"&&i(!1)};return a&&(document.addEventListener("keydown",l),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",l),document.body.style.overflow=""}},[a,i]),a?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx(We,{}),e.jsxs("div",{ref:n,onClick:l=>l.stopPropagation(),className:h("relative z-50 w-full max-w-lg gap-4 border bg-background p-6 shadow-lg duration-200 sm:rounded-lg",t),...r,children:[s,e.jsxs("button",{type:"button",onClick:()=>i(!1),className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"h-4 w-4",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}):null});he.displayName="DialogContent";const ge=({className:t,...s})=>e.jsx("div",{className:h("flex flex-col space-y-1.5 text-center sm:text-left",t),...s});ge.displayName="DialogHeader";const ve=({className:t,...s})=>e.jsx("div",{className:h("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...s});ve.displayName="DialogFooter";const pe=d.forwardRef(({className:t,...s},r)=>e.jsx("h2",{ref:r,className:h("text-lg font-semibold leading-none tracking-tight",t),...s}));pe.displayName="DialogTitle";const be=d.forwardRef(({className:t,...s},r)=>e.jsx("p",{ref:r,className:h("text-sm text-muted-foreground",t),...s}));be.displayName="DialogDescription";const jt=C.forwardRef(({src:t,height:s=600,className:r,onLoad:n,onError:a},i)=>e.jsx("iframe",{ref:i,src:t,className:h("w-full border-none",r),style:{height:typeof s=="number"?`${s}px`:s,minHeight:"400px",maxHeight:"80vh"},onLoad:n,onError:a,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox",allow:"payment",title:"Secure Checkout",loading:"lazy"}));jt.displayName="CheckoutIframe";function Ws({enabled:t,priceId:s,customer:r,couponCode:n,metadata:a,existingSubscriptionId:i}){const{client:l}=D(),[o,c]=C.useState(null),[u,m]=C.useState(null),[x,p]=C.useState(!1),[y,f]=C.useState(null),g=async()=>{if(!(!t||!s)){console.log("%c🔄 Creating checkout session...","color: #3b82f6; font-weight: 600;",{priceId:s,customer:r}),p(!0),f(null);try{const b=await l.checkout.createSession({priceId:s,customer:r,couponCode:n,metadata:a,existingSubscriptionId:i,mode:"embedded"});c(b.id),console.log("%c✨ Session created!","color: #10b981; font-weight: 600;",`ID: ${b.id}`);const j=`${process.env.NEXT_PUBLIC_BILLINGOS_APP_URL||"http://localhost:3000"}/embed/checkout/${b.id}`;m(j),console.log("%c📍 Iframe URL ready","color: #8b5cf6; font-weight: 600;",j)}catch(b){const w=b instanceof Error?b:new Error("Failed to create checkout session");f(w),console.error("[useCheckoutSession] Error creating session:",w)}finally{p(!1)}}};return C.useEffect(()=>{t&&!o&&g()},[t,s]),C.useEffect(()=>()=>{},[o]),{sessionId:o,sessionUrl:u,loading:x,error:y,refresh:async()=>{c(null),m(null),await g()}}}function Ys(){const t=[];return process.env.NEXT_PUBLIC_APP_URL&&t.push(process.env.NEXT_PUBLIC_APP_URL),t.push("https://app.billingos.com"),t.push("https://embed.billingos.com"),process.env.NODE_ENV==="development"&&(t.push("http://localhost:3000"),t.push("http://localhost:3001"),t.push("http://127.0.0.1:3000"),t.push("http://127.0.0.1:3001")),t}function Gs(t){return Ys().includes(t)}function Xs({iframeRef:t,onMessage:s,targetOrigin:r=process.env.NEXT_PUBLIC_APP_URL||"http://localhost:3000",debug:n=!1}){var l;const a=!!((l=t.current)!=null&&l.contentWindow),i=C.useCallback(o=>{var c;(c=t.current)!=null&&c.contentWindow?(n&&console.log("[useIframeMessaging] Sending message:",o),t.current.contentWindow.postMessage(o,r)):console.warn("[useIframeMessaging] Cannot send message - iframe not ready")},[t,r,n]);return C.useEffect(()=>{const o=c=>{if(!Gs(c.origin)){n&&console.warn(`[useIframeMessaging] Invalid origin: ${c.origin}`);return}!c.data||typeof c.data!="object"||!c.data.type||!c.data.type.startsWith("CHECKOUT_")&&c.data.type!=="HEIGHT_CHANGED"&&c.data.type!=="PROCESSING"||(n&&console.log("[useIframeMessaging] Received message:",c.data),s(c.data))};return window.addEventListener("message",o),()=>{window.removeEventListener("message",o)}},[s,n]),{sendMessage:i,isConnected:a}}function Me({open:t,onOpenChange:s,priceId:r,customer:n,couponCode:a,collectBillingAddress:i,existingSubscriptionId:l,metadata:o,theme:c="light",locale:u="en",onSuccess:m,onError:x,onCancel:p,debug:y=!1}){const[f,g]=C.useState("loading"),[v,b]=C.useState(null),[w,j]=C.useState(600),S=C.useRef(null);C.useEffect(()=>{console.log("%c🚀 BillingOS SDK v1.2.0 loaded with Iframe Checkout","background: linear-gradient(to right, #667eea, #764ba2); color: white; padding: 4px 8px; border-radius: 4px; font-weight: bold;"),console.log("%c📦 Using iframe for PCI compliance and security","color: #10b981; font-weight: 600;"),console.log("%c✨ Customer prefill support enabled","color: #8b5cf6; font-weight: 600;"),y&&console.log("[CheckoutModal] Debug mode enabled")},[]);const{sessionId:_,sessionUrl:k,loading:$,error:Q}=Ws({enabled:t,priceId:r,customer:n,couponCode:a,metadata:o,existingSubscriptionId:l}),K=C.useCallback(V=>{var L,O,Z,ae;switch(console.log("[CheckoutModal] Received message from iframe:",V.type,V),V.type){case"CHECKOUT_READY":console.log("[CheckoutModal] Checkout is ready"),g("ready");break;case"CHECKOUT_SUCCESS":console.log("[CheckoutModal] Payment SUCCESS! Subscription:",(L=V.payload)==null?void 0:L.subscription),g("success"),(O=V.payload)!=null&&O.subscription?(console.log("[CheckoutModal] Calling onSuccess with subscription data"),m(V.payload.subscription)):(console.log("[CheckoutModal] No subscription data, calling onSuccess with undefined"),m(void 0)),s(!1);break;case"CHECKOUT_ERROR":g("error");const ye=((Z=V.payload)==null?void 0:Z.error)||"An error occurred",N=new Error(ye);b(N),x==null||x(N);break;case"CHECKOUT_CLOSE":p==null||p(),s(!1);break;case"HEIGHT_CHANGED":(ae=V.payload)!=null&&ae.height&&j(V.payload.height);break;case"PROCESSING":g("processing");break}},[y,m,x,p,s]),{sendMessage:X}=Xs({iframeRef:S,onMessage:K,debug:y});C.useEffect(()=>{_&&f==="ready"&&X({type:"INIT_CHECKOUT",sessionId:_,config:{theme:c,locale:u,collectBillingAddress:i}})},[_,f,c,u,i,X]),C.useEffect(()=>{t||(g("loading"),b(null),j(600))},[t]),C.useEffect(()=>{Q&&(g("error"),b(Q),x==null||x(Q))},[Q,x]);const z=$||f==="loading",B=f==="error"&&v;return e.jsx(fe,{open:t,onOpenChange:s,children:e.jsxs(he,{className:h("sm:max-w-[500px] p-0 overflow-hidden","max-h-[90vh] relative"),children:[e.jsxs("div",{className:"absolute top-2 right-2 z-20 flex items-center gap-1 bg-gradient-to-r from-blue-600 to-purple-600 text-white text-xs font-medium px-2 py-1 rounded-full shadow-lg",children:[e.jsx("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M2.166 4.999A11.954 11.954 0 0010 1.944 11.954 11.954 0 0017.834 5c.11.65.166 1.32.166 2.001 0 5.225-3.34 9.67-8 11.317C5.34 16.67 2 12.225 2 7c0-.682.057-1.35.166-2.001zm11.541 3.708a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),e.jsx("span",{children:"Secure Iframe"})]}),B?e.jsxs("div",{className:"p-8 text-center",children:[e.jsx("div",{className:"text-red-600 mb-2",children:e.jsx("svg",{className:"w-12 h-12 mx-auto",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Payment Error"}),e.jsx("p",{className:"text-gray-600",children:v.message}),e.jsx("button",{onClick:()=>s(!1),className:"mt-4 px-4 py-2 bg-gray-200 rounded-md hover:bg-gray-300",children:"Close"})]}):e.jsxs(e.Fragment,{children:[z&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-white z-10",children:e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"}),e.jsx("p",{className:"mt-4 text-gray-600 font-medium",children:"Loading secure checkout..."}),e.jsx("p",{className:"mt-2 text-xs text-gray-500",children:"Iframe-based • PCI Compliant"})]})}),k&&e.jsx(jt,{ref:S,src:k,height:w,className:h("transition-opacity duration-300",z?"opacity-0":"opacity-100"),onLoad:()=>{console.log("%c✅ Iframe loaded successfully","color: #10b981; font-weight: 600;",`
3
- URL: ${k}`),y&&console.log("[CheckoutModal] Full iframe details:",{sessionUrl:k,sessionId:_,state:f,height:w})}}),f==="processing"&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-white/80 z-10",children:e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-green-600"}),e.jsx("p",{className:"mt-4 text-gray-600",children:"Processing payment..."})]})})]}),y&&e.jsxs("div",{className:"absolute bottom-0 left-0 right-0 bg-black/80 text-white p-2 text-xs",children:[e.jsxs("div",{children:["State: ",f]}),e.jsxs("div",{children:["Session: ",_||"Creating..."]}),v&&e.jsxs("div",{children:["Error: ",v.message]})]})]})})}class vt{constructor(s){se(this,"client");se(this,"container");se(this,"root");this.client=s}async open(s){return new Promise(r=>{this.container||(this.container=document.createElement("div"),this.container.id="billingos-checkout-container",this.container.style.position="fixed",this.container.style.zIndex="999999",document.body.appendChild(this.container));const n={open:!0,onOpenChange:a=>{a||(this.close(),s.onCancel&&s.onCancel(),r({success:!1}))},priceId:s.priceId,customer:s.customer,couponCode:s.couponCode,collectBillingAddress:s.collectBillingAddress,currency:s.currency,existingSubscriptionId:s.existingSubscriptionId,metadata:s.metadata,theme:s.theme,locale:s.locale,onSuccess:a=>{s.onSuccess&&s.onSuccess(a),r({success:!0,subscription:a}),this.close()},onError:a=>{s.onError&&s.onError(a),r({success:!1,error:a})},onCancel:s.onCancel,debug:s.debug};if(this.root||(this.root=Ds.createRoot(this.container)),this.client)this.root.render(C.createElement(Me,n));else if(s.sessionToken)this.root.render(C.createElement(ht,{sessionToken:s.sessionToken,options:{baseUrl:s.apiUrl},children:C.createElement(Me,n)}));else{const a=new Error("No session token or BillingOS client provided");s.onError&&s.onError(a),r({success:!1,error:a}),this.close()}})}close(){this.root&&(this.root.unmount(),this.root=void 0),this.container&&(this.container.remove(),this.container=void 0)}}let $e=null;function Se(t){return $e||($e=new vt(t)),$e}async function Js(t){return Se().open(t)}function Zs(){const{client:t}=D(),[s,r]=C.useState(!1),[n,a]=C.useState(null),i=C.useCallback(async o=>{r(!0),a(null);try{const u=await Se(t).open(o);return!u.success&&u.error&&a(u.error),u}catch(c){const u=c instanceof Error?c:new Error("Failed to open checkout");return a(u),{success:!1,error:u}}finally{r(!1)}},[t]),l=C.useCallback(()=>{Se(t).close()},[t]);return{openCheckout:i,closeCheckout:l,isLoading:s,error:n}}const me={all:["entitlements"],lists:()=>[...me.all,"list"],list:t=>[...me.lists(),t],checks:()=>[...me.all,"check"],check:(t,s)=>[...me.checks(),t,s],usage:(t,s)=>[...me.all,"usage",t,s]};function bt(t,s,r){const{client:n}=D();return P.useQuery({queryKey:me.check(t,s),queryFn:()=>n.checkEntitlement({customer_id:t,feature_key:s}),enabled:!!t&&!!s,staleTime:1e3*60,...r})}function er(t,s,r){const{data:n}=bt(t,s,r);return(n==null?void 0:n.has_access)||!1}function tr(t,s){const{client:r}=D();return P.useQuery({queryKey:me.list(t),queryFn:()=>r.listEntitlements(t),enabled:!!t,...s})}function sr(t,s,r){const{client:n}=D();return P.useQuery({queryKey:me.usage(t,s),queryFn:()=>n.getUsageMetrics(t,s),enabled:!!t&&!!s,...r})}function rr(t,s,r=80,n){const{data:a}=sr(t,s,n);return!a||!a.limit?!1:a.current_usage/a.limit*100>=r}function wt(t,s){const{client:r}=D();return P.useQuery({queryKey:["billingos","features",t],queryFn:async()=>await r.get(`/v1/features/check?feature_key=${t}`),refetchInterval:s==null?void 0:s.refetchInterval,enabled:(s==null?void 0:s.enabled)!==!1})}function nr(){const{client:t}=D(),s=P.useQueryClient();return P.useMutation({mutationFn:async({featureKey:r,quantity:n,metadata:a})=>await t.post("/v1/features/track-usage",{feature_key:r,quantity:n,metadata:a}),onSuccess:(r,n)=>{s.invalidateQueries({queryKey:["billingos","features",n.featureKey]}),s.invalidateQueries({queryKey:["billingos","usage-metrics"]})}})}function ar(){const{client:t}=D();return P.useQuery({queryKey:["billingos","entitlements"],queryFn:async()=>await t.get("/v1/features/entitlements")})}function Ye(t){const{client:s}=D();return P.useQuery({queryKey:["billingos","usage-metrics",t],queryFn:async()=>{const r=t?`/v1/features/usage-metrics?feature_key=${t}`:"/v1/features/usage-metrics";return await s.get(r)},refetchInterval:3e4})}function Nt(t,s){var n,a,i,l,o,c,u,m;const r=wt(t);return r.data&&!r.data.has_access&&(r.data.usage&&r.data.limit&&r.data.usage>=r.data.limit?(n=s==null?void 0:s.onQuotaExceeded)==null||n.call(s,r.data.usage,r.data.limit):(a=s==null?void 0:s.onAccessDenied)==null||a.call(s)),{...r,hasAccess:((i=r.data)==null?void 0:i.has_access)||!1,isQuotaExceeded:(l=r.data)!=null&&l.usage&&r.data.limit?r.data.usage>=r.data.limit:!1,usage:((o=r.data)==null?void 0:o.usage)||0,limit:((c=r.data)==null?void 0:c.limit)||0,remaining:(u=r.data)!=null&&u.limit&&((m=r.data)!=null&&m.usage)?Math.max(0,r.data.limit-r.data.usage):0}}function Ct(){const{client:t}=D();return P.useQuery({queryKey:["billingos","products"],queryFn:async()=>await t.get("/v1/products")})}const ir=Pe.cva("relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",warning:"border-yellow-500/50 bg-yellow-50 text-yellow-900 dark:bg-yellow-900/10 dark:text-yellow-500 [&>svg]:text-yellow-500",success:"border-green-500/50 bg-green-50 text-green-900 dark:bg-green-900/10 dark:text-green-500 [&>svg]:text-green-500"}},defaultVariants:{variant:"default"}}),Y=d.forwardRef(({className:t,variant:s,...r},n)=>e.jsx("div",{ref:n,role:"alert",className:h(ir({variant:s}),t),...r}));Y.displayName="Alert";const Ae=d.forwardRef(({className:t,...s},r)=>e.jsx("h5",{ref:r,className:h("mb-1 font-medium leading-none tracking-tight",t),...s}));Ae.displayName="AlertTitle";const G=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,className:h("text-sm [&_p]:leading-relaxed",t),...s}));G.displayName="AlertDescription";const St=Pe.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground",success:"border-transparent bg-green-500 text-white hover:bg-green-500/80",warning:"border-transparent bg-yellow-500 text-white hover:bg-yellow-500/80"}},defaultVariants:{variant:"default"}});function A({className:t,variant:s,...r}){return e.jsx("div",{className:h(St({variant:s}),t),...r})}const kt=Pe.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),T=d.forwardRef(({className:t,variant:s,size:r,asChild:n=!1,...a},i)=>e.jsx("button",{className:h(kt({variant:s,size:r,className:t})),ref:i,...a}));T.displayName="Button";const F=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,className:h("rounded-lg border bg-card text-card-foreground shadow-sm",t),...s}));F.displayName="Card";const J=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,className:h("flex flex-col space-y-1.5 p-6",t),...s}));J.displayName="CardHeader";const de=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,className:h("text-2xl font-semibold leading-none tracking-tight",t),...s}));de.displayName="CardTitle";const Be=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,className:h("text-sm text-muted-foreground",t),...s}));Be.displayName="CardDescription";const I=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,className:h("p-6 pt-0",t),...s}));I.displayName="CardContent";const Ge=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,className:h("flex items-center p-6 pt-0",t),...s}));Ge.displayName="CardFooter";const Oe=d.forwardRef(({className:t,onCheckedChange:s,onChange:r,...n},a)=>{const i=l=>{r==null||r(l),s==null||s(l.target.checked)};return e.jsx("input",{type:"checkbox",ref:a,onChange:i,className:h("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 checked:bg-primary checked:text-primary-foreground",t),...n})});Oe.displayName="Checkbox";const Pt=d.createContext(null);function qe(){const t=d.useContext(Pt);if(!t)throw new Error("Drawer components must be used within a Drawer provider");return t}function Et({open:t=!1,onOpenChange:s,children:r}){const[n,a]=d.useState(!1),i=t??n,l=s??a;return d.useEffect(()=>{console.log("[Drawer] State:",{open:t,internalOpen:n,isOpen:i})},[t,n,i]),e.jsx(Pt.Provider,{value:{open:i,onOpenChange:l},children:r})}const Dt=d.forwardRef(({onClick:t,...s},r)=>{const{onOpenChange:n}=qe();return e.jsx("button",{ref:r,type:"button",onClick:a=>{n(!0),t==null||t(a)},...s})});Dt.displayName="DrawerTrigger";const Tt=d.forwardRef(({onClick:t,...s},r)=>{const{onOpenChange:n}=qe();return e.jsx("button",{ref:r,type:"button",onClick:a=>{n(!1),t==null||t(a)},...s})});Tt.displayName="DrawerClose";const lr=d.forwardRef(({className:t,...s},r)=>{const{onOpenChange:n}=qe();return e.jsx("div",{ref:r,onClick:()=>n(!1),className:h("fixed inset-0 z-50 bg-black/80 transition-opacity duration-300",t),...s})});lr.displayName="DrawerOverlay";const Xe=d.forwardRef(({className:t,children:s,preventClose:r=!1,onCloseAttempt:n,...a},i)=>{const{open:l,onOpenChange:o}=qe(),[c,u]=d.useState(!1),[m,x]=d.useState(0),p=d.useRef(null),y=d.useRef(0);d.useEffect(()=>{const w=j=>{j.key==="Escape"&&(r?n==null||n():o(!1))};return l&&(document.addEventListener("keydown",w),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",w),document.body.style.overflow=""}},[l,o,r,n]);const f=w=>{if(r)return;u(!0);const j="touches"in w?w.touches[0].clientY:w.clientY;y.current=j},g=w=>{if(!c||r)return;const S=("touches"in w?w.touches[0].clientY:w.clientY)-y.current;S>0&&x(S)},v=()=>{c&&(u(!1),m>80&&!r&&o(!1),x(0))},b=()=>{r?n==null||n():o(!1)};return console.log("[DrawerContent] Rendering, open:",l,"preventClose:",r),l?e.jsxs("div",{className:"fixed inset-0 z-50",children:[e.jsx("div",{className:"fixed inset-0 bg-black/80 transition-opacity duration-300",onClick:b}),e.jsxs("div",{ref:i,className:h("fixed z-50 bg-background shadow-lg transition-transform duration-300 ease-out","inset-x-0 bottom-0 rounded-t-[10px] border-t","md:inset-auto md:left-1/2 md:top-1/2 md:-translate-x-1/2 md:-translate-y-1/2","md:rounded-lg md:border md:max-w-[500px] md:w-full md:max-h-[90vh]",t),style:{transform:c?`translateY(${m}px)`:void 0},onClick:w=>w.stopPropagation(),onTouchStart:f,onTouchMove:g,onTouchEnd:v,onMouseDown:f,onMouseMove:g,onMouseUp:v,onMouseLeave:v,...a,children:[e.jsx("div",{className:"md:hidden flex justify-center pt-4 pb-2",children:e.jsx("div",{className:"w-12 h-1.5 rounded-full bg-muted-foreground/30"})}),e.jsxs("button",{type:"button",onClick:()=>{r?n==null||n():o(!1)},className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"h-4 w-4",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]}),e.jsx("span",{className:"sr-only",children:"Close"})]}),e.jsx("div",{ref:p,className:"px-6 pb-6 pt-2 md:pt-6 overflow-y-auto max-h-[80vh] md:max-h-[calc(90vh-2rem)]",children:s})]})]}):(console.log("[DrawerContent] Not rendering because open is false"),null)});Xe.displayName="DrawerContent";const Je=({className:t,...s})=>e.jsx("div",{className:h("flex flex-col space-y-1.5 text-center sm:text-left",t),...s});Je.displayName="DrawerHeader";const _t=({className:t,...s})=>e.jsx("div",{className:h("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...s});_t.displayName="DrawerFooter";const Ze=d.forwardRef(({className:t,...s},r)=>e.jsx("h2",{ref:r,className:h("text-lg font-semibold leading-none tracking-tight",t),...s}));Ze.displayName="DrawerTitle";const et=d.forwardRef(({className:t,...s},r)=>e.jsx("p",{ref:r,className:h("text-sm text-muted-foreground",t),...s}));et.displayName="DrawerDescription";const te=d.forwardRef(({className:t,type:s,...r},n)=>e.jsx("input",{type:s,className:h("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),ref:n,...r}));te.displayName="Input";const or=Pe.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),W=d.forwardRef(({className:t,...s},r)=>e.jsx("label",{ref:r,className:h(or(),t),...s}));W.displayName="Label";const tt=d.forwardRef(({className:t,value:s=0,max:r=100,indicatorClassName:n,...a},i)=>{const l=Math.min(Math.max(s/r*100,0),100);return e.jsx("div",{ref:i,role:"progressbar","aria-valuemin":0,"aria-valuemax":r,"aria-valuenow":s,className:h("relative h-4 w-full overflow-hidden rounded-full bg-secondary",t),...a,children:e.jsx("div",{className:h("h-full bg-primary transition-all",n),style:{width:`${l}%`}})})});tt.displayName="Progress";const Lt=d.createContext(null);function cr(){const t=d.useContext(Lt);if(!t)throw new Error("RadioGroup components must be used within a RadioGroup provider");return t}const st=d.forwardRef(({className:t,value:s,defaultValue:r,onValueChange:n,name:a="radio-group",children:i,...l},o)=>{const[c,u]=d.useState(r??""),m=s??c,x=n??u;return e.jsx(Lt.Provider,{value:{value:m,onValueChange:x,name:a},children:e.jsx("div",{ref:o,role:"radiogroup",className:h("grid gap-2",t),...l,children:i})})});st.displayName="RadioGroup";const Fe=d.forwardRef(({className:t,value:s,...r},n)=>{const{value:a,onValueChange:i,name:l}=cr(),o=a===s;return e.jsx("input",{ref:n,type:"radio",name:l,value:s,checked:o,onChange:()=>i(s),className:h("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t),...r})});Fe.displayName="RadioGroupItem";const Rt=d.forwardRef(({className:t,children:s,orientation:r="vertical",alwaysShowScrollbar:n=!1,...a},i)=>{const[l,o]=d.useState(!1),[c,u]=d.useState(0),[m,x]=d.useState(0),p=d.useRef(null),y=d.useCallback(()=>{const g=p.current;if(!g)return;const{scrollTop:v,scrollHeight:b,clientHeight:w}=g,j=b>w;if(!j&&!n){u(0),x(0);return}const S=w/b,_=Math.max(S*w,30),k=b-w,$=k>0?v/k:0,Q=w-_,K=$*Q;u(j?_:0),x(K)},[n]);d.useEffect(()=>{const g=p.current;if(!g)return;y();const v=new ResizeObserver(y);return v.observe(g),g.addEventListener("scroll",y),()=>{v.disconnect(),g.removeEventListener("scroll",y)}},[y]);const f=d.useCallback(g=>{var X;g.preventDefault();const v=p.current;if(!v)return;const{scrollHeight:b,clientHeight:w}=v,j=b-w;if(j<=0)return;const S=(X=g.currentTarget.parentElement)==null?void 0:X.parentElement;if(!S)return;const _=S.getBoundingClientRect(),k=g.clientY,$=v.scrollTop,Q=z=>{const B=z.clientY-k,V=_.height,O=B/V*j,Z=Math.max(0,Math.min(j,$+O));v.scrollTop=Z},K=()=>{document.removeEventListener("mousemove",Q),document.removeEventListener("mouseup",K),document.body.style.userSelect="",document.body.style.cursor=""};document.body.style.userSelect="none",document.body.style.cursor="grabbing",document.addEventListener("mousemove",Q),document.addEventListener("mouseup",K)},[]);return e.jsxs("div",{ref:i,className:h("relative overflow-hidden",t),onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),...a,children:[e.jsx("div",{ref:p,className:h("h-full w-full rounded-[inherit]",r==="vertical"&&"overflow-y-auto overflow-x-hidden",r==="horizontal"&&"overflow-x-auto overflow-y-hidden",r==="both"&&"overflow-auto","[&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]"),children:s}),(r==="vertical"||r==="both")&&e.jsx("div",{className:h("absolute top-0 right-0 w-2.5 h-full transition-opacity duration-150",n||l?"opacity-100":"opacity-0"),children:e.jsxs("div",{className:"relative h-full w-full",children:[e.jsx("div",{className:"absolute inset-0 rounded-full bg-gray-100 hover:bg-gray-200"}),c>0&&e.jsx("div",{className:"absolute right-0.5 w-1.5 rounded-full bg-gray-400 hover:bg-gray-600 transition-colors cursor-pointer",style:{height:`${c}px`,top:`${m}px`},onMouseDown:f})]})})]})});Rt.displayName="ScrollArea";const Mt=d.forwardRef(({className:t,orientation:s="vertical",...r},n)=>e.jsx("div",{ref:n,className:h("flex touch-none select-none transition-colors",s==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",s==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",t),...r}));Mt.displayName="ScrollBar";const rt=d.forwardRef(({className:t,children:s,onValueChange:r,onChange:n,...a},i)=>{const l=o=>{n==null||n(o),r==null||r(o.target.value)};return e.jsx("select",{ref:i,onChange:l,className:h("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t),...a,children:s})});rt.displayName="Select";const nt=d.forwardRef(({className:t,...s},r)=>e.jsx("option",{ref:r,className:h("",t),...s}));nt.displayName="SelectOption";const ke=d.forwardRef(({className:t,orientation:s="horizontal",decorative:r=!0,...n},a)=>e.jsx("div",{ref:a,role:r?"none":"separator","aria-orientation":r?void 0:s,className:h("shrink-0 bg-border",s==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",t),...n}));ke.displayName="Separator";const Ft=d.createContext(null);function ze(){const t=d.useContext(Ft);if(!t)throw new Error("Sheet components must be used within a Sheet provider");return t}function It({open:t=!1,onOpenChange:s,children:r}){const[n,a]=d.useState(!1),i=t??n,l=s??a;return e.jsx(Ft.Provider,{value:{open:i,onOpenChange:l},children:r})}const Ut=d.forwardRef(({onClick:t,...s},r)=>{const{onOpenChange:n}=ze();return e.jsx("button",{ref:r,type:"button",onClick:a=>{n(!0),t==null||t(a)},...s})});Ut.displayName="SheetTrigger";const At=d.forwardRef(({onClick:t,...s},r)=>{const{onOpenChange:n}=ze();return e.jsx("button",{ref:r,type:"button",onClick:a=>{n(!1),t==null||t(a)},...s})});At.displayName="SheetClose";const Bt=d.forwardRef(({className:t,...s},r)=>{const{onOpenChange:n}=ze();return e.jsx("div",{ref:r,onClick:()=>n(!1),className:h("fixed inset-0 z-50 bg-black/80 transition-opacity",t),...s})});Bt.displayName="SheetOverlay";const dr=Pe.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition-transform duration-300 ease-in-out",{variants:{side:{top:"inset-x-0 top-0 border-b",bottom:"inset-x-0 bottom-0 border-t",left:"inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm"}},defaultVariants:{side:"right"}}),at=d.forwardRef(({side:t="right",className:s,children:r,...n},a)=>{const{open:i,onOpenChange:l}=ze();if(d.useEffect(()=>{const c=u=>{u.key==="Escape"&&l(!1)};return i&&(document.addEventListener("keydown",c),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",c),document.body.style.overflow=""}},[i,l]),!i)return null;const o=()=>{switch(t){case"top":return i?"translateY(0)":"translateY(-100%)";case"bottom":return i?"translateY(0)":"translateY(100%)";case"left":return i?"translateX(0)":"translateX(-100%)";case"right":return i?"translateX(0)":"translateX(100%)";default:return"translateX(0)"}};return e.jsxs("div",{className:"fixed inset-0 z-50",children:[e.jsx(Bt,{}),e.jsxs("div",{ref:a,style:{transform:o()},className:h(dr({side:t}),s),onClick:c=>c.stopPropagation(),...n,children:[r,e.jsxs("button",{type:"button",onClick:()=>l(!1),className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"h-4 w-4",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});at.displayName="SheetContent";const it=({className:t,...s})=>e.jsx("div",{className:h("flex flex-col space-y-2 text-center sm:text-left",t),...s});it.displayName="SheetHeader";const Ot=({className:t,...s})=>e.jsx("div",{className:h("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...s});Ot.displayName="SheetFooter";const lt=d.forwardRef(({className:t,...s},r)=>e.jsx("h2",{ref:r,className:h("text-lg font-semibold text-foreground",t),...s}));lt.displayName="SheetTitle";const qt=d.forwardRef(({className:t,...s},r)=>e.jsx("p",{ref:r,className:h("text-sm text-muted-foreground",t),...s}));qt.displayName="SheetDescription";function E({className:t,...s}){return e.jsx("div",{className:h("animate-pulse rounded-md bg-muted",t),...s})}const zt=d.createContext(null);function $t(){const t=d.useContext(zt);if(!t)throw new Error("Tabs components must be used within a Tabs provider");return t}const Ht=d.forwardRef(({className:t,value:s,defaultValue:r,onValueChange:n,children:a,...i},l)=>{const[o,c]=d.useState(r??""),u=s??o,m=n??c;return e.jsx(zt.Provider,{value:{value:u,onValueChange:m},children:e.jsx("div",{ref:l,className:h("",t),...i,children:a})})});Ht.displayName="Tabs";const Qt=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,role:"tablist",className:h("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",t),...s}));Qt.displayName="TabsList";const Kt=d.forwardRef(({className:t,value:s,...r},n)=>{const{value:a,onValueChange:i}=$t(),l=a===s;return e.jsx("button",{ref:n,role:"tab",type:"button","aria-selected":l,"data-state":l?"active":"inactive",onClick:()=>i(s),className:h("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",l?"bg-background text-foreground shadow-sm":"hover:bg-background/50 hover:text-foreground",t),...r})});Kt.displayName="TabsTrigger";const Vt=d.forwardRef(({className:t,value:s,children:r,...n},a)=>{const{value:i}=$t(),l=i===s;return l?e.jsx("div",{ref:a,role:"tabpanel","data-state":l?"active":"inactive",className:h("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",t),...n,children:r}):null});Vt.displayName="TabsContent";const ot=d.forwardRef(({className:t,...s},r)=>e.jsx("textarea",{className:h("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),ref:r,...s}));ot.displayName="Textarea";const Wt=C.forwardRef(({src:t,height:s=600,className:r,onLoad:n},a)=>e.jsx("iframe",{ref:a,src:t,className:h("w-full border-0",r),style:{height:`${s}px`},allow:"payment",sandbox:"allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox",onLoad:n,title:"Customer Portal"}));Wt.displayName="PortalIframe";function ur({enabled:t,customerId:s,metadata:r}){const{client:n}=D(),[a,i]=C.useState(null),[l,o]=C.useState(null),[c,u]=C.useState(!1),[m,x]=C.useState(null),p=async()=>{if(t){console.log("%c🔄 Creating portal session...","color: #3b82f6; font-weight: 600;"),u(!0),x(null);try{const f=await n.portal.createSession({customerId:s,metadata:r});i(f.id),console.log("%c✨ Portal session created!","color: #10b981; font-weight: 600;",`ID: ${f.id}`);const v=`${process.env.NEXT_PUBLIC_BILLINGOS_APP_URL||"http://localhost:3000"}/embed/portal/${f.id}`;o(v),console.log("%c📍 Iframe URL ready","color: #8b5cf6; font-weight: 600;",v)}catch(f){const g=f instanceof Error?f:new Error("Failed to create portal session");x(g),console.error("[usePortalSession] Error creating session:",g)}finally{u(!1)}}};return C.useEffect(()=>{t&&!a&&p()},[t]),C.useEffect(()=>()=>{},[a]),{sessionId:a,sessionUrl:l,loading:c,error:m,refresh:async()=>{i(null),o(null),await p()}}}function mr({iframeRef:t,onMessage:s,debug:r=!1}){const n=C.useCallback(a=>{const i=t.current;if(!i||!i.contentWindow){console.warn("[usePortalMessaging] Iframe not ready");return}r&&console.log("[usePortalMessaging] 📤 Sending to iframe:",a);const l=i.src,o=new URL(l).origin;i.contentWindow.postMessage(a,o)},[t,r]);return C.useEffect(()=>{const a=i=>{if(!i.data||typeof i.data!="object"||!i.data.type)return;const l=t.current;if(!l)return;const o=l.src;if(!o)return;const c=new URL(o).origin;if(i.origin!==c&&process.env.NODE_ENV!=="development"){console.warn(`[usePortalMessaging] Message from unexpected origin: ${i.origin}`);return}const u=i.data;r&&console.log("[usePortalMessaging] 📥 Received from iframe:",u),s(u)};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[t,s,r]),{sendMessage:n}}const Yt=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:r,className:h("w-full caption-bottom text-sm",t),...s})}));Yt.displayName="Table";const Gt=d.forwardRef(({className:t,...s},r)=>e.jsx("thead",{ref:r,className:h("[&_tr]:border-b",t),...s}));Gt.displayName="TableHeader";const Xt=d.forwardRef(({className:t,...s},r)=>e.jsx("tbody",{ref:r,className:h("[&_tr:last-child]:border-0",t),...s}));Xt.displayName="TableBody";const hr=d.forwardRef(({className:t,...s},r)=>e.jsx("tfoot",{ref:r,className:h("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",t),...s}));hr.displayName="TableFooter";const Le=d.forwardRef(({className:t,...s},r)=>e.jsx("tr",{ref:r,className:h("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",t),...s}));Le.displayName="TableRow";const Ke=d.forwardRef(({className:t,...s},r)=>e.jsx("th",{ref:r,className:h("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",t),...s}));Ke.displayName="TableHead";const Ne=d.forwardRef(({className:t,...s},r)=>e.jsx("td",{ref:r,className:h("p-4 align-middle [&:has([role=checkbox])]:pr-0",t),...s}));Ne.displayName="TableCell";const xr=d.forwardRef(({className:t,...s},r)=>e.jsx("caption",{ref:r,className:h("mt-4 text-sm text-muted-foreground",t),...s}));xr.displayName="TableCaption";function Jt(t={}){const{client:s}=D(),{planIds:r,enabled:n=!0}=t;return P.useQuery({queryKey:["products",r],queryFn:async()=>s.getProducts(r),enabled:n,staleTime:300*1e3,gcTime:600*1e3})}class fr extends d.Component{constructor(r){super(r);se(this,"reset",()=>{this.setState({hasError:!1,error:null})});this.state={hasError:!1,error:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,n){var a,i;console.error("[ErrorBoundary] Caught error:",r),console.error("[ErrorBoundary] Error info:",n),(i=(a=this.props).onError)==null||i.call(a,r,n)}render(){var r;return this.state.hasError?this.props.fallback?this.props.fallback(this.state.error,this.reset):e.jsxs("div",{style:{padding:"20px",border:"1px solid #ef4444",borderRadius:"8px",backgroundColor:"#fee2e2",color:"#991b1b",fontFamily:"system-ui, -apple-system, sans-serif"},children:[e.jsx("h3",{style:{margin:"0 0 10px 0",fontSize:"16px",fontWeight:"bold"},children:"Payment Error"}),e.jsx("p",{style:{margin:"0 0 10px 0",fontSize:"14px"},children:((r=this.state.error)==null?void 0:r.message)||"An unexpected error occurred while loading the payment form."}),e.jsx("button",{onClick:this.reset,style:{padding:"8px 16px",border:"none",borderRadius:"6px",backgroundColor:"#ef4444",color:"white",fontSize:"14px",cursor:"pointer",fontWeight:"500"},children:"Try Again"})]}):this.props.children}}function Zt(t,s){const{client:r}=D();return P.useQuery({queryKey:["checkout",t==null?void 0:t.priceId,t==null?void 0:t.existingSubscriptionId],queryFn:async()=>{if(!t)throw new Error("Checkout input is required");return r.createCheckout(t)},enabled:(s==null?void 0:s.enabled)!==!1&&!!t,staleTime:0,gcTime:0})}function gr(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({mutationFn:async({clientSecret:n,paymentMethodId:a})=>s.confirmCheckout(n,a),onSuccess:n=>{var a;r.invalidateQueries({queryKey:["portal"]}),r.invalidateQueries({queryKey:["subscriptions"]}),(a=t==null?void 0:t.onSuccess)==null||a.call(t,n)},onError:n=>{var a;(a=t==null?void 0:t.onError)==null||a.call(t,n)}})}function pr({checkoutSession:t,onSuccess:s,onError:r,isProcessing:n,setIsProcessing:a}){var b;const{client:i}=D(),l=ce.useStripe(),o=ce.useElements(),[c,u]=d.useState(null),[m,x]=d.useState(!1),p=(w,j)=>new Intl.NumberFormat("en-US",{style:"currency",currency:j.toUpperCase()}).format(w/100),y=((b=t.proration)==null?void 0:b.total)??t.amount,f=p(y,t.currency),g=async w=>{if(w.preventDefault(),!(!l||!o)){a(!0),u(null);try{const{error:j,paymentIntent:S}=await l.confirmPayment({elements:o,confirmParams:{return_url:`${window.location.origin}/billing/success`},redirect:"if_required"});if(j){u(j.message||"Payment failed"),r==null||r(j.message||"Payment failed"),a(!1);return}if((S==null?void 0:S.status)==="succeeded"&&S.payment_method)try{const _=await i.confirmCheckout(t.clientSecret,S.payment_method);if(_.success)s(_.subscriptionId);else throw new Error(_.message||"Failed to create subscription")}catch(_){const k=_ instanceof Error?_.message:"Failed to complete checkout";u(k),r==null||r(k),a(!1);return}}catch(j){const S=j instanceof Error?j.message:"Payment failed";u(S),r==null||r(S)}finally{a(!1)}}},v=async w=>{if(!(!l||!o)){a(!0),u(null);try{const{error:j}=await l.confirmPayment({elements:o,clientSecret:t.clientSecret,confirmParams:{return_url:`${window.location.origin}/billing/success`},redirect:"if_required"});if(j){u(j.message||"Payment failed"),r==null||r(j.message||"Payment failed"),a(!1);return}s(t.id)}catch(j){const S=j instanceof Error?j.message:"Payment failed";u(S),r==null||r(S)}finally{a(!1)}}};return e.jsxs("form",{onSubmit:g,className:"space-y-6",children:[e.jsx("div",{className:h(!m&&"hidden"),children:e.jsx(ce.ExpressCheckoutElement,{options:{wallets:{applePay:"auto",googlePay:"auto"}},onConfirm:v,onReady:()=>x(!0)})}),m&&e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx(ke,{className:"w-full"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"or pay with card"})})]}),e.jsx("div",{className:"space-y-4",children:e.jsx(ce.PaymentElement,{options:{layout:"tabs"}})}),c&&e.jsx(Y,{variant:"destructive",children:e.jsx(G,{children:c})}),e.jsx(T,{type:"submit",className:"w-full",size:"lg",disabled:!l||n,children:n?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsxs("svg",{className:"animate-spin h-4 w-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Processing..."]}):t.proration?`Upgrade Now - ${f}`:`Subscribe - ${f}`}),e.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),e.jsx("span",{children:"Secured by Stripe • Cancel anytime"})]})]})}function yr({checkoutSession:t,onSuccess:s,isProcessing:r,setIsProcessing:n}){var v;const[a,i]=d.useState(""),[l,o]=d.useState(""),[c,u]=d.useState(""),m=(b,w)=>new Intl.NumberFormat("en-US",{style:"currency",currency:w.toUpperCase()}).format(b/100),x=((v=t.proration)==null?void 0:v.total)??t.amount,p=m(x,t.currency),y=b=>{const j=b.replace(/\D/g,"").match(/.{1,4}/g);return j?j.join(" ").substring(0,19):""},f=b=>{const w=b.replace(/\D/g,"");return w.length>=2?`${w.slice(0,2)}/${w.slice(2,4)}`:w},g=async b=>{b.preventDefault(),n(!0),await new Promise(w=>setTimeout(w,2e3)),s(`sub_demo_${Date.now()}`)};return e.jsxs("form",{onSubmit:g,className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs(T,{type:"button",variant:"outline",className:"h-12",disabled:r,onClick:()=>{n(!0),setTimeout(()=>s(`sub_demo_apple_${Date.now()}`),2e3)},children:[e.jsx("svg",{viewBox:"0 0 24 24",className:"w-5 h-5 mr-2",fill:"currentColor",children:e.jsx("path",{d:"M17.05 20.28c-.98.95-2.05.8-3.08.35-1.09-.46-2.09-.48-3.24 0-1.44.62-2.2.44-3.06-.35C2.79 15.25 3.51 7.59 9.05 7.31c1.35.07 2.29.74 3.08.8 1.18-.24 2.31-.93 3.57-.84 1.51.12 2.65.72 3.4 1.8-3.12 1.87-2.38 5.98.48 7.13-.57 1.5-1.31 2.99-2.54 4.09l.01-.01zM12.03 7.25c-.15-2.23 1.66-4.07 3.74-4.25.29 2.58-2.34 4.5-3.74 4.25z"})}),"Apple Pay"]}),e.jsxs(T,{type:"button",variant:"outline",className:"h-12",disabled:r,onClick:()=>{n(!0),setTimeout(()=>s(`sub_demo_google_${Date.now()}`),2e3)},children:[e.jsxs("svg",{viewBox:"0 0 24 24",className:"w-5 h-5 mr-2",children:[e.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"}),e.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),e.jsx("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),e.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]}),"Google Pay"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"or pay with card"})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"card-number",children:"Card number"}),e.jsx(te,{id:"card-number",placeholder:"1234 5678 9012 3456",value:a,onChange:b=>i(y(b.target.value)),disabled:r,maxLength:19})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"expiry",children:"Expiry date"}),e.jsx(te,{id:"expiry",placeholder:"MM/YY",value:l,onChange:b=>o(f(b.target.value)),disabled:r,maxLength:5})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"cvc",children:"CVC"}),e.jsx(te,{id:"cvc",placeholder:"123",value:c,onChange:b=>u(b.target.value.replace(/\D/g,"").substring(0,4)),disabled:r,maxLength:4})]})]})]}),e.jsx(T,{type:"submit",className:"w-full",size:"lg",disabled:r,children:r?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsxs("svg",{className:"animate-spin h-4 w-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Processing..."]}):t.proration?`Upgrade Now - ${p}`:`Subscribe - ${p}`}),e.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),e.jsx("span",{children:"Secured by Stripe - Cancel anytime"})]})]})}const He="pk_test_51SihBODiEfx9xR94hb9APIlKq2CEr3uJqjQ1j98VdO5i30EGWi4HieGFjy1O3lEF3OWangT10RYr2Kae4CxfAvYd00xEVl0Raw";function jr(t){return!!((t.startsWith("pk_live_")||t.startsWith("pk_test_"))&&t.length>20)}function vr(t){return!!(t&&/^(pi|seti)_[a-zA-Z0-9]+_secret_[a-zA-Z0-9]+$/.test(t))}function es({priceId:t,isOpen:s,onClose:r,onSuccess:n,existingSubscriptionId:a,theme:i}){console.log("[PaymentBottomSheet v0.1.3] Rendering with checkout fix:",{priceId:t,isOpen:s,existingSubscriptionId:a,theme:i});const{customerEmail:l,customerName:o}=D(),c=P.useQueryClient(),[u,m]=d.useState(null),[x,p]=d.useState("loading"),[y,f]=d.useState(null),[g,v]=d.useState(!1),[b,w]=d.useState(!1);d.useEffect(()=>{console.log("[PaymentBottomSheet] State changed:",{sheetState:x,error:y,isProcessing:g,isDemoMode:b,hasStripePromise:!!u})},[x,y,g,b,u]);const{data:j,error:S,refetch:_}=Zt(s?{priceId:t,customerEmail:l,customerName:o,existingSubscriptionId:a}:null,{enabled:s}),k=j;d.useEffect(()=>{console.log("[PaymentBottomSheet] Checkout session data:",{hasCheckoutData:!!j,checkoutSession:k,checkoutError:S==null?void 0:S.message,isOpen:s})},[j,k,S,s]),d.useEffect(()=>{var L;if(console.log("[PaymentBottomSheet] Stripe initialization effect triggered"),k){const O=jr(He),Z=vr(k.clientSecret);if(console.log("[PaymentBottomSheet] Stripe validation:",{publishableKey:He,validKey:O,clientSecret:((L=k.clientSecret)==null?void 0:L.substring(0,20))+"...",validSecret:Z,stripeAccountId:k.stripeAccountId}),O&&Z){console.log("[PaymentBottomSheet] Loading Stripe with valid credentials");const ae=dt.loadStripe(He,{stripeAccount:k.stripeAccountId});m(ae),w(!1)}else console.log("[PaymentBottomSheet] Invalid Stripe credentials, entering demo mode"),w(!0);p("ready")}},[k]),d.useEffect(()=>{S&&(f(S.message||"Failed to create checkout session"),p("error"))},[S]),d.useEffect(()=>{s||(p("loading"),f(null),m(null),w(!1))},[s]);const $=L=>{p("success"),c.invalidateQueries({queryKey:["billingos","products"]}),console.log("💫 Invalidated products query - PricingTable will auto-refresh"),setTimeout(()=>{n(L)},1500)},Q=L=>{f(L)},K=()=>{console.log("[PaymentBottomSheet] handleClose called, isProcessing:",g),!(g&&!window.confirm("Your payment is being processed. Are you sure you want to close?"))&&r()},X=()=>{f(null),p("loading"),_()},z={theme:i==="dark"?"night":"stripe",variables:{colorPrimary:"#3B82F6",borderRadius:"8px"}},B=(L,O)=>new Intl.NumberFormat("en-US",{style:"currency",currency:O.toUpperCase()}).format(L/100),V=L=>{switch(L){case"day":return"day";case"week":return"week";case"month":return"month";case"year":return"year";default:return L}};return console.log("[PaymentBottomSheet] Rendering drawer with isOpen:",s,"sheetState:",x),e.jsx(fr,{fallback:(L,O)=>e.jsxs("div",{style:{padding:"20px",maxWidth:"400px",margin:"0 auto"},children:[e.jsx(Y,{variant:"destructive",children:e.jsxs(G,{children:["Failed to load payment form: ",(L==null?void 0:L.message)||"Unknown error"]})}),e.jsxs("div",{className:"mt-4 flex gap-2",children:[e.jsx(T,{variant:"outline",onClick:r,children:"Cancel"}),e.jsx(T,{onClick:O,children:"Try Again"})]})]}),onError:(L,O)=>{console.error("[PaymentBottomSheet] Error caught by boundary:",L),console.error("[PaymentBottomSheet] Error info:",O)},children:e.jsx(Et,{open:s,onOpenChange:L=>{console.log("[PaymentBottomSheet] Drawer.onOpenChange called with open:",L),L||K()},children:e.jsxs(Xe,{preventClose:g,onCloseAttempt:()=>{window.alert("Please wait while your payment is being processed.")},children:[e.jsxs(Je,{className:"text-center sm:text-left",children:[e.jsx(Ze,{children:x==="success"?"Payment Successful!":a?"Complete Your Upgrade":"Complete Payment"}),x!=="success"&&k&&e.jsxs(et,{children:[a?"Upgrading to":"Subscribing to",":"," ",e.jsx("span",{className:"font-medium",children:k.product.name})]})]}),x==="loading"&&e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsx(E,{className:"h-20 w-full"}),e.jsx(E,{className:"h-40 w-full"}),e.jsx(E,{className:"h-12 w-full"})]}),x==="error"&&e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsx(Y,{variant:"destructive",children:e.jsx(G,{children:y||"Something went wrong. Please try again."})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{variant:"outline",onClick:r,className:"flex-1",children:"Cancel"}),e.jsx(T,{onClick:X,className:"flex-1",children:"Try Again"})]})]}),x==="success"&&k&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 space-y-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-green-100 flex items-center justify-center",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-green-600",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-lg font-semibold",children:"Payment Successful!"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Your subscription to ",k.product.name," is now active."]})]})]}),x==="processing"&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 space-y-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsxs("svg",{className:"animate-spin h-8 w-8 text-primary",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-lg font-semibold",children:"Processing Payment..."}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Please don't close this window."})]})]}),x==="ready"&&k&&e.jsxs("div",{className:"space-y-6",children:[b&&e.jsx(Y,{children:e.jsxs(G,{className:"text-sm",children:[e.jsx("strong",{children:"Demo Mode:"})," This is a preview with mock data. In production, a real Stripe payment form will appear here."]})}),e.jsx(F,{children:e.jsxs(I,{className:"pt-4",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:k.product.name}),e.jsxs("p",{className:"text-2xl font-bold mt-1",children:[B(k.amount,k.currency),e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["/",V(k.product.interval)]})]})]}),e.jsx(A,{variant:"secondary",children:a?"Upgrade":"New"})]}),k.product.features.length>0&&e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Features Included:"}),e.jsx("ul",{className:"space-y-1",children:k.product.features.map((L,O)=>e.jsxs("li",{className:"flex items-center gap-2 text-sm",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-green-500",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),L]},O))})]})]})}),k.proration&&e.jsx(F,{children:e.jsxs(I,{className:"pt-4",children:[e.jsx("h4",{className:"font-medium mb-3",children:"Amount Due Today:"}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:k.product.name}),e.jsx("span",{children:B(k.proration.charged,k.currency)})]}),e.jsxs("div",{className:"flex justify-between text-green-600",children:[e.jsx("span",{children:"Credit (unused time)"}),e.jsxs("span",{children:["-",B(k.proration.credited,k.currency)]})]}),e.jsx(ke,{}),e.jsxs("div",{className:"flex justify-between font-semibold",children:[e.jsx("span",{children:"Total Due Now"}),e.jsx("span",{children:B(k.proration.total,k.currency)})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-3 flex items-start gap-1",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"mt-0.5 flex-shrink-0",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 16v-4"}),e.jsx("path",{d:"M12 8h.01"})]}),k.proration.explanation]})]})}),!k.proration&&e.jsx(F,{children:e.jsx(I,{className:"pt-4",children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"font-medium",children:"Amount Due Today:"}),e.jsx("span",{className:"text-xl font-bold",children:B(k.amount,k.currency)})]})})}),e.jsx(ke,{}),b?e.jsx(yr,{checkoutSession:k,onSuccess:$,isProcessing:g,setIsProcessing:v}):u?e.jsx(ce.Elements,{stripe:u,options:{clientSecret:k.clientSecret,appearance:z},children:e.jsx(pr,{checkoutSession:k,onSuccess:$,onError:Q,isProcessing:g,setIsProcessing:v})}):null]})]})})})}function ts({planIds:t,showIntervalToggle:s=!0,defaultInterval:r="month",onSelectPlan:n,theme:a,title:i="Choose Your Plan",description:l,useCheckoutModal:o=!1,onPlanChanged:c,customer:u}){const[m,x]=d.useState(r),[p,y]=d.useState(null),[f,g]=d.useState(!1),{customerEmail:v,customerName:b}=D(),w=(u==null?void 0:u.email)||v,j=(u==null?void 0:u.name)||b,S=P.useQueryClient(),[_,k]=d.useState(!1);d.useEffect(()=>{console.log("[PricingTable] Customer data:",{fromProp:u,fromContext:{customerEmail:v,customerName:b},final:{email:w,name:j},hasEmail:!!w,hasName:!!j})},[u,v,b,w,j]),d.useEffect(()=>{console.log("📊 BillingOS SDK v1.2.0 - PricingTable rendered - CSS injected"),console.log("%c🚀 BillingOS SDK Version: 1.1.0","color: #10b981; font-weight: bold; font-size: 14px;"),o?console.log("%c🎉 Using NEW Iframe-based CheckoutModal with Real-time Updates!","background: linear-gradient(to right, #10b981, #3b82f6); color: white; padding: 4px 8px; border-radius: 4px; font-weight: bold;"):console.log("📦 Using PaymentBottomSheet (legacy)")},[o]);const{data:$,isLoading:Q,error:K,refetch:X}=Jt({planIds:t}),z=($==null?void 0:$.products)||[],B=($==null?void 0:$.currentSubscription)||null,V=z.some(N=>N.prices.some(M=>M.interval==="year")),L=d.useMemo(()=>{const N=new Map;z.forEach(R=>{R.features.forEach(U=>{N.has(U.id)||N.set(U.id,{name:U.title,values:Array(z.length).fill(null)})})});const M=Array.from(N.entries());return M.forEach(([R,U])=>{z.forEach((ie,H)=>{var we;const le=ie.features.find(xe=>xe.id===R);if(le){if(le.type==="boolean_flag")U.values[H]=!0;else if(le.type==="usage_quota"||le.type==="numeric_limit"){const xe=(we=le.properties)==null?void 0:we.limit;xe===-1?U.values[H]="Unlimited":typeof xe=="number"?U.values[H]=xe:U.values[H]=!0}}})}),M.map(([,R])=>R)},[z]),O=N=>new Intl.NumberFormat("en-US",{style:"currency",currency:N.currency.toUpperCase(),minimumFractionDigits:0,maximumFractionDigits:0}).format(N.amount/100),Z=N=>N.prices.find(M=>M.interval===m)||N.prices[0]||null,ae=N=>{n?n(N):(y(N),g(!0))},ye=d.useCallback(async N=>{console.log("%c🎉 [PricingTable] handlePaymentSuccess CALLED!","color: #10b981; font-size: 14px; font-weight: bold;",N),console.log("[PricingTable] Subscription data:",N),g(!1),y(null),console.log("[PricingTable] Showing success notification..."),k(!0),setTimeout(()=>k(!1),5e3),c&&N&&(console.log("[PricingTable] Calling onPlanChanged callback..."),c(N)),console.log("%c🔄 Invalidating products cache...","color: #8b5cf6; font-weight: 600;"),await S.invalidateQueries({queryKey:["products"],refetchType:"all"}),N&&(console.log("[PricingTable] Optimistically updating cache with subscription:",N),S.setQueryData(["products",t],M=>{var U;if(!M)return M;console.log("[PricingTable] Updating cache - old data:",M);const R={...M,currentSubscription:N,products:(U=M.products)==null?void 0:U.map(ie=>{var H;return{...ie,isCurrentPlan:((H=ie.prices)==null?void 0:H.some(le=>le.id===N.priceId))||!1}})};return console.log("[PricingTable] Updated cache data:",R),R})),console.log("[PricingTable] Triggering background refetch..."),await X(),console.log("%c✅ Products cache invalidated and refetched","color: #10b981; font-weight: 600;")},[S,X,t,c]);return Q?e.jsxs("div",{className:h("w-full",a==="dark"&&"dark"),children:[i&&e.jsxs("div",{className:"text-center mb-8",children:[e.jsx(E,{className:"h-10 w-64 mx-auto mb-2"}),l&&e.jsx(E,{className:"h-5 w-96 mx-auto"})]}),e.jsx(E,{className:"h-[600px] w-full"})]}):K?e.jsxs("div",{className:h("w-full max-w-md mx-auto",a==="dark"&&"dark"),children:[e.jsx(Y,{variant:"destructive",children:e.jsx(G,{children:K.message||"Failed to load pricing plans"})}),e.jsx("div",{className:"mt-4 flex justify-center",children:e.jsx(T,{onClick:()=>X(),children:"Try Again"})})]}):z.length===0?e.jsx("div",{className:h("w-full text-center py-12",a==="dark"&&"dark"),children:e.jsx("p",{className:"text-muted-foreground",children:"No pricing plans available"})}):e.jsxs("div",{className:h("w-full",a==="dark"&&"dark"),children:[_&&e.jsx("div",{className:"mb-6 p-4 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg animate-in slide-in-from-top-2 duration-300",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("svg",{className:"w-5 h-5 text-green-600 dark:text-green-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e.jsx("p",{className:"text-green-800 dark:text-green-200 font-medium",children:"Payment successful! Your subscription has been updated."})]})}),(i||l)&&e.jsxs("div",{className:"text-center mb-8",children:[i&&e.jsx("h2",{className:"text-3xl font-bold tracking-tight text-foreground",children:i}),l&&e.jsx("p",{className:"text-muted-foreground mt-2 max-w-2xl mx-auto",children:l}),o&&e.jsxs("div",{className:"inline-flex items-center gap-2 mt-4 px-3 py-1 bg-gradient-to-r from-blue-100 to-purple-100 text-blue-800 rounded-full text-sm font-medium",children:[e.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),e.jsx("span",{children:"Using Secure Iframe Checkout"})]})]}),s&&V&&e.jsx("div",{className:"flex justify-center mb-8",children:e.jsxs("div",{className:"inline-flex items-center rounded-lg bg-muted p-1",children:[e.jsx("button",{onClick:()=>x("month"),className:h("px-4 py-2 rounded-md text-sm font-medium transition-colors",m==="month"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:"Monthly"}),e.jsxs("button",{onClick:()=>x("year"),className:h("px-4 py-2 rounded-md text-sm font-medium transition-colors flex items-center gap-2",m==="year"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:["Yearly",e.jsx(A,{variant:"secondary",className:"text-xs",children:"Save"})]})]})}),e.jsx("div",{className:"rounded-lg border bg-card overflow-hidden",children:e.jsxs(Yt,{children:[e.jsx(Gt,{children:e.jsxs(Le,{className:"hover:bg-transparent border-b",children:[e.jsx(Ke,{className:"w-[200px]"}),z.map(N=>{const M=Z(N),R=N.highlighted,U=N.isCurrentPlan;return e.jsx(Ke,{className:h("text-center relative",R&&"bg-foreground text-background"),children:e.jsxs("div",{className:"py-8",children:[(R||U)&&e.jsxs("div",{className:"flex justify-center gap-2 mb-3",children:[U&&e.jsx(A,{className:"bg-primary text-primary-foreground text-xs",children:"Current Plan"}),R&&!U&&e.jsx(A,{variant:"secondary",className:h("text-xs",R&&"bg-background text-foreground"),children:"Popular"})]}),e.jsx("div",{className:h("font-bold text-xl mb-3",R?"text-background":"text-foreground"),children:N.name}),M&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:h("text-5xl font-bold mb-2",R?"text-background":"text-foreground"),children:O(M)}),e.jsxs("div",{className:h("text-sm mt-1",R?"text-background/70":"text-muted-foreground"),children:["Per ",m==="year"?"year":"month"]})]})]})},N.id)})]})}),e.jsxs(Xt,{children:[L.map((N,M)=>e.jsxs(Le,{children:[e.jsx(Ne,{className:"font-medium text-foreground py-4",children:N.name}),N.values.map((R,U)=>{var H;const ie=(H=z[U])==null?void 0:H.highlighted;return e.jsx(Ne,{className:h("text-center py-4",ie&&"bg-foreground/5"),children:R===null||R===!1?e.jsx("span",{className:"text-muted-foreground",children:"-"}):R===!0?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"inline-block text-foreground",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"9 12 11 14 15 10"})]}):e.jsx("span",{className:"text-foreground font-medium",children:R})},U)})]},M)),e.jsxs(Le,{className:"hover:bg-transparent border-t",children:[e.jsx(Ne,{className:"font-medium text-foreground py-6",children:"Server speed"}),z.map(N=>{var le;const M=Z(N),R=N.highlighted,U=N.isCurrentPlan,ie=B!==null;let H="Get Started";if(U)H="Current Plan";else if(ie&&M&&B){const we=z.find(ks=>ks.isCurrentPlan),xe=we&&((le=Z(we))==null?void 0:le.amount)||0;M.amount>xe?H="Upgrade":M.amount<xe?H="Downgrade":H="Switch Plan"}return e.jsx(Ne,{className:h("text-center py-6",R&&"bg-foreground/5"),children:e.jsx(T,{onClick:()=>M&&ae(M.id),disabled:U||!M,variant:R&&!U?"default":"outline",className:h("w-full max-w-[200px]",R&&!U&&"bg-foreground text-background hover:bg-foreground/90"),children:H})},N.id)})]})]})]})}),!n&&p&&e.jsx(e.Fragment,{children:o?e.jsx(Me,{open:f,onOpenChange:N=>{N||(g(!1),y(null))},priceId:p,customer:{email:w,name:j},onSuccess:N=>{ye(N)},existingSubscriptionId:B==null?void 0:B.id,theme:a}):e.jsx(es,{priceId:p,isOpen:f,onClose:()=>{g(!1),y(null)},onSuccess:ye,existingSubscriptionId:B==null?void 0:B.id,theme:a})})]})}function br({product:t,selectedInterval:s,currentSubscription:r,onSelectPlan:n}){const a=t.prices.find(y=>y.interval===s)||t.prices[0],i=t.isCurrentPlan,o=r?i||r.productId===t.id?"current":"upgrade":"buy",c=y=>new Intl.NumberFormat("en-US",{style:"currency",currency:y.currency.toUpperCase(),minimumFractionDigits:0,maximumFractionDigits:0}).format(y.amount/100),m=s==="year"?(()=>{const y=t.prices.find(w=>w.interval==="month"),f=t.prices.find(w=>w.interval==="year");if(!y||!f)return null;const g=y.amount*12,v=f.amount,b=(g-v)/g*100;return Math.round(b)})():null,x=y=>{var f,g;return((f=y.properties)==null?void 0:f.limit)===-1?`Unlimited ${((g=y.properties)==null?void 0:g.unit)||y.title.toLowerCase()}`:y.title},p=()=>{o!=="current"&&a&&n(a.id)};return e.jsxs(F,{className:h("relative flex flex-col h-full transition-all duration-200",i&&"border-primary border-2 shadow-lg",t.highlighted&&!i&&"border-primary/50","hover:shadow-lg"),children:[e.jsxs("div",{className:"absolute -top-3 left-1/2 -translate-x-1/2 flex gap-2",children:[i&&e.jsx(A,{className:"bg-primary text-primary-foreground",children:"Current Plan"}),t.highlighted&&!i&&e.jsx(A,{variant:"secondary",children:"Most Popular"})]}),e.jsxs(J,{className:"text-center pb-2 pt-8",children:[e.jsx(de,{className:"text-2xl font-bold",children:t.name}),e.jsx(Be,{className:"text-sm mt-1",children:t.description})]}),e.jsxs(I,{className:"flex-1 pt-4",children:[e.jsxs("div",{className:"text-center mb-6",children:[e.jsxs("div",{className:"flex items-baseline justify-center gap-1",children:[e.jsx("span",{className:"text-4xl font-bold tracking-tight",children:a?c(a):"N/A"}),e.jsxs("span",{className:"text-muted-foreground text-sm",children:["/",s==="year"?"year":"mo"]})]}),m&&m>0&&e.jsxs(A,{variant:"secondary",className:"mt-2 bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-300",children:["Save ",m,"%"]}),t.trialDays>0&&o==="buy"&&e.jsxs("p",{className:"text-sm text-muted-foreground mt-2",children:[t.trialDays,"-day free trial"]})]}),e.jsx("ul",{className:"space-y-3",children:t.features.map(y=>e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-green-500 flex-shrink-0 mt-0.5",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),e.jsx("span",{className:"text-sm",children:x(y)})]},y.id))})]}),e.jsx(Ge,{className:"pt-4",children:e.jsxs(T,{className:"w-full",size:"lg",variant:o==="current"?"outline":"default",disabled:o==="current",onClick:p,children:[o==="current"&&e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Current Plan"]}),o==="buy"&&(t.trialDays>0?"Start Free Trial":"Get Started"),o==="upgrade"&&"Upgrade",o==="downgrade"&&"Downgrade"]})})]})}function wr({isOpen:t=!1,onClose:s,mode:r="drawer",defaultTab:n="subscription",theme:a="light",className:i,customerId:l,metadata:o,onSubscriptionUpdate:c,onSubscriptionCancel:u,onPaymentMethodAdd:m,onPaymentMethodUpdate:x,debug:p=!1}){const[y,f]=C.useState("loading"),[g,v]=C.useState(null),[b,w]=C.useState(600),[j,S]=C.useState(!1),[_,k]=C.useState(null),$=C.useRef(null);C.useEffect(()=>{console.log("%c🚀 BillingOS SDK v1.2.0 - Iframe Customer Portal with Smart Pricing Table","background: linear-gradient(to right, #667eea, #764ba2); color: white; padding: 4px 8px; border-radius: 4px; font-weight: bold;"),console.log("%c📦 Using iframe for instant updates and security","color: #10b981; font-weight: 600;"),console.log("%c🎨 Supports drawer, modal, and page modes","color: #8b5cf6; font-weight: 600;"),p&&console.log("[CustomerPortal] Debug mode enabled")},[]);const Q=r==="page"||t,{sessionId:K,sessionUrl:X,loading:z,error:B}=ur({enabled:Q,customerId:l,metadata:o}),V=C.useCallback(N=>{var M,R,U;switch(p&&console.log("[CustomerPortal] Received message from iframe:",N.type,N),N.type){case"PORTAL_READY":console.log("[CustomerPortal] Portal is ready"),f("ready");break;case"PORTAL_CLOSE":console.log("[CustomerPortal] User requested close"),s==null||s();break;case"SUBSCRIPTION_UPDATED":console.log("[CustomerPortal] Subscription updated"),c==null||c(N.payload);break;case"SUBSCRIPTION_CANCELLED":console.log("[CustomerPortal] Subscription cancelled"),u==null||u();break;case"PAYMENT_METHOD_ADDED":console.log("[CustomerPortal] Payment method added"),m==null||m();break;case"PAYMENT_METHOD_UPDATED":console.log("[CustomerPortal] Payment method updated"),x==null||x();break;case"HEIGHT_CHANGED":(M=N.payload)!=null&&M.height&&(w(N.payload.height),p&&console.log("[CustomerPortal] Height changed to:",N.payload.height));break;case"OPEN_PRICING_TABLE":console.log("[CustomerPortal] Opening pricing table for plan change"),(R=N.payload)!=null&&R.customer&&(console.log("[CustomerPortal] Received customer data for prefill:",N.payload.customer),k(N.payload.customer)),S(!0);break;case"CLOSE_PRICING_TABLE":console.log("[CustomerPortal] Closing pricing table"),S(!1);break;case"ERROR":f("error");const ie=((U=N.payload)==null?void 0:U.error)||"An error occurred",H=new Error(ie);v(H);break}},[p,s,c,u,m,x]),{sendMessage:L}=mr({iframeRef:$,onMessage:V,debug:p});C.useEffect(()=>{K&&y==="ready"&&L({type:"INIT_PORTAL",sessionId:K,config:{theme:a,defaultTab:n}})},[K,y,a,n,L]),C.useEffect(()=>{Q||(f("loading"),v(null),w(600))},[Q]),C.useEffect(()=>{B&&(f("error"),v(B))},[B]);const O=z||y==="loading",Z=y==="error"&&g,ae=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"absolute top-2 right-2 z-20 flex items-center gap-1 bg-gradient-to-r from-blue-600 to-purple-600 text-white text-xs font-medium px-2 py-1 rounded-full shadow-lg",children:[e.jsx("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M2.166 4.999A11.954 11.954 0 0010 1.944 11.954 11.954 0 0017.834 5c.11.65.166 1.32.166 2.001 0 5.225-3.34 9.67-8 11.317C5.34 16.67 2 12.225 2 7c0-.682.057-1.35.166-2.001zm11.541 3.708a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),e.jsx("span",{children:"Secure Iframe"})]}),Z?e.jsx("div",{className:"p-8",children:e.jsx(Y,{variant:"destructive",children:e.jsx(G,{children:g.message})})}):e.jsxs(e.Fragment,{children:[O&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-white z-10",children:e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"}),e.jsx("p",{className:"mt-4 text-gray-600 font-medium",children:"Loading portal..."}),e.jsx("p",{className:"mt-2 text-xs text-gray-500",children:"Iframe-based • Always up-to-date"})]})}),X&&e.jsx(Wt,{ref:$,src:X,height:b,className:h("transition-opacity duration-300",O?"opacity-0":"opacity-100"),onLoad:()=>{console.log("%c✅ Portal iframe loaded successfully","color: #10b981; font-weight: 600;",`
4
- URL: ${X}`),p&&console.log("[CustomerPortal] Full iframe details:",{sessionUrl:X,sessionId:K,state:y,height:b})}})]}),p&&e.jsxs("div",{className:"absolute bottom-0 left-0 right-0 bg-black/80 text-white p-2 text-xs",children:[e.jsxs("div",{children:["State: ",y]}),e.jsxs("div",{children:["Session: ",K||"Creating..."]}),g&&e.jsxs("div",{children:["Error: ",g.message]})]})]}),ye=r==="page"?e.jsx("div",{className:h("relative w-full",i),children:ae}):r==="modal"?e.jsx(fe,{open:t,onOpenChange:N=>!N&&(s==null?void 0:s()),children:e.jsxs(he,{className:h("sm:max-w-[800px] p-0 overflow-hidden max-h-[90vh] relative",i),children:[e.jsx(ge,{className:"sr-only",children:e.jsx(pe,{children:"Customer Portal"})}),ae]})}):e.jsx(It,{open:t,onOpenChange:N=>!N&&(s==null?void 0:s()),children:e.jsxs(at,{side:"right",className:h("w-full sm:max-w-[600px] p-0 overflow-hidden",i),children:[e.jsx(it,{className:"sr-only",children:e.jsx(lt,{children:"Customer Portal"})}),ae]})});return e.jsxs(e.Fragment,{children:[ye,e.jsx(fe,{open:j,onOpenChange:S,children:e.jsxs(he,{className:"sm:max-w-6xl max-h-[90vh] overflow-y-auto",children:[e.jsx(ge,{children:e.jsx(pe,{children:"Change Your Plan"})}),e.jsx(ts,{useCheckoutModal:!0,theme:a,customer:_||void 0,onPlanChanged:N=>{console.log("[CustomerPortal] Plan changed successfully:",N),S(!1),k(null),L({type:"UPDATE_CONFIG",payload:{refresh:!0}}),c==null||c(N)}})]})})]})}const ee={all:["portal"],data:()=>[...ee.all,"data"],setupIntent:()=>[...ee.all,"setupIntent"]};function Nr(t){const{client:s}=D();return P.useQuery({queryKey:ee.data(),queryFn:()=>s.getCustomerPortal(),staleTime:1e3*60*5,...t})}function Cr(t,s){const{client:r}=D(),n=P.useQueryClient();return P.useMutation({...s,mutationFn:a=>r.updatePortalSubscription(t,a),onSuccess:(...a)=>{var i;n.invalidateQueries({queryKey:ee.data()}),(i=s==null?void 0:s.onSuccess)==null||i.call(s,...a)}})}function Sr(t,s){const{client:r}=D(),n=P.useQueryClient();return P.useMutation({...s,mutationFn:a=>r.cancelPortalSubscription(t,a),onSuccess:(...a)=>{var i;n.invalidateQueries({queryKey:ee.data()}),(i=s==null?void 0:s.onSuccess)==null||i.call(s,...a)}})}function kr(t,s){const{client:r}=D(),n=P.useQueryClient();return P.useMutation({...s,mutationFn:()=>r.reactivatePortalSubscription(t),onSuccess:(...a)=>{var i;n.invalidateQueries({queryKey:ee.data()}),(i=s==null?void 0:s.onSuccess)==null||i.call(s,...a)}})}function Pr(t){const{client:s}=D();return P.useQuery({queryKey:ee.setupIntent(),queryFn:()=>s.getSetupIntent(),enabled:!1,...t})}function Er(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({...t,mutationFn:n=>s.addPaymentMethod(n),onSuccess:(...n)=>{var a;r.invalidateQueries({queryKey:ee.data()}),(a=t==null?void 0:t.onSuccess)==null||a.call(t,...n)}})}function Dr(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({...t,mutationFn:n=>s.removePaymentMethod(n),onSuccess:(...n)=>{var a;r.invalidateQueries({queryKey:ee.data()}),(a=t==null?void 0:t.onSuccess)==null||a.call(t,...n)}})}function Tr(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({...t,mutationFn:n=>s.setDefaultPaymentMethod(n),onSuccess:(...n)=>{var a;r.invalidateQueries({queryKey:ee.data()}),(a=t==null?void 0:t.onSuccess)==null||a.call(t,...n)}})}function _r(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({...t,mutationFn:({invoiceId:n,paymentMethodId:a})=>s.retryInvoice(n,a),onSuccess:(...n)=>{var a;r.invalidateQueries({queryKey:ee.data()}),(a=t==null?void 0:t.onSuccess)==null||a.call(t,...n)}})}function Lr(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({...t,mutationFn:n=>s.updateCustomerBilling(n),onSuccess:(...n)=>{var a;r.invalidateQueries({queryKey:ee.data()}),(a=t==null?void 0:t.onSuccess)==null||a.call(t,...n)}})}function ct(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toLocaleString()}function Rr(t){return t>=90?"bg-destructive":t>=75?"bg-yellow-500":"bg-primary"}function ss({title:t,usage:s,unit:r,className:n}){const{consumed:a,limit:i,percentage:l,resetDate:o}=s,c=ct(a),u=ct(i),m=Rr(l);return e.jsxs("div",{className:h("space-y-2",n),children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"font-medium",children:t}),e.jsxs("span",{className:"text-muted-foreground",children:[c," / ",u," ",r&&`(${r})`]})]}),e.jsx(tt,{value:l,max:100,className:"h-2",indicatorClassName:m}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsxs("span",{children:[Math.round(l),"% used"]}),o&&e.jsxs("span",{children:["Resets: ",new Date(o).toLocaleDateString("en-US",{month:"short",day:"numeric"})]})]})]})}function Mr({className:t}){return e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:h("h-4 w-4",t),children:e.jsx("path",{d:"M20 6 9 17l-5-5"})})}function rs({features:t,className:s}){const r=t.filter(n=>n.type==="boolean_flag"&&n.enabled);return r.length===0?null:e.jsxs("div",{className:h("space-y-2",s),children:[e.jsx("h4",{className:"text-sm font-medium text-muted-foreground",children:"Included Features"}),e.jsx("ul",{className:"space-y-1.5",children:r.map(n=>e.jsxs("li",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Mr,{className:"text-green-500"}),e.jsx("span",{children:n.title})]},n.id))})]})}function Fr({className:t}){return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:h("h-4 w-4",t),children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"}),e.jsx("path",{d:"M12 9v4"}),e.jsx("path",{d:"M12 17h.01"})]})}function Ir(t){switch(t){case"trial_ending":return"Trial Ending Soon";case"payment_failed":return"Payment Failed";case"subscription_canceled":return"Subscription Canceled";case"past_due":return"Payment Past Due";default:return"Warning"}}function Ur(t){switch(t){case"payment_failed":case"past_due":return"destructive";default:return"warning"}}function Re({type:t,message:s,actionLabel:r,onAction:n,className:a}){const i=Ir(t),l=Ur(t);return e.jsxs(Y,{variant:l,className:h("",a),children:[e.jsx(Fr,{}),e.jsx(Ae,{children:i}),e.jsxs(G,{className:"flex items-center justify-between",children:[e.jsx("span",{children:s}),r&&n&&e.jsx(T,{size:"sm",variant:l==="destructive"?"outline":"default",onClick:n,className:"ml-4",children:r})]})]})}const Ar=(t,s=!1,r=!1)=>{const n=t/100,a=t%100===0&&!s?0:2;return r?n.toLocaleString("en-US",{maximumFractionDigits:a,minimumFractionDigits:a}):n.toFixed(a)},je=(t,s,r,n,a)=>new Intl.NumberFormat("en-US",{style:"currency",currency:s,minimumFractionDigits:r,maximumFractionDigits:a,notation:n}).format(t/100),ns=t=>t/100,as=t=>Math.round(t*100),is=(t,s)=>je(t,s,0,"compact",1),ls=(t,s)=>je(t,s,0,"standard",0),os=t=>{const n=new Intl.NumberFormat("en-US",{style:"currency",currency:t,minimumFractionDigits:0,maximumFractionDigits:0}).formatToParts(0).find(a=>a.type==="currency");return(n==null?void 0:n.value)||t},cs=(t,s,r)=>{const n=je(t,r),a=je(s,r);return`${n} - ${a}`},ds=t=>t===0,us=t=>t<0,ms=(t,s)=>Math.round(t*s/100),hs=(...t)=>t.reduce((s,r)=>s+r,0),oe={format:je,formatCompact:is,formatWhole:ls,formatRange:cs,fromCents:ns,toCents:as,getSymbol:os,isZero:ds,isNegative:us,calculatePercentage:ms,add:hs};function Br(t,s){return s===1?t:`${s} ${t}s`}function Or(t,s){if(s)return e.jsx(A,{variant:"warning",children:"Cancels at period end"});switch(t){case"active":return e.jsx(A,{variant:"success",children:"Active"});case"trialing":return e.jsx(A,{variant:"secondary",children:"Trial"});case"past_due":return e.jsx(A,{variant:"destructive",children:"Past Due"});case"canceled":return e.jsx(A,{variant:"outline",children:"Canceled"});case"unpaid":return e.jsx(A,{variant:"destructive",children:"Unpaid"});default:return e.jsx(A,{variant:"outline",children:t})}}function qr({onBrowsePlans:t}){return e.jsx(F,{children:e.jsxs(I,{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"You don't have an active subscription."}),e.jsx(T,{onClick:t,children:"Browse Plans"})]})})}function zr(){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(F,{children:[e.jsxs(J,{children:[e.jsx(E,{className:"h-6 w-32"}),e.jsx(E,{className:"h-4 w-48"})]}),e.jsxs(I,{className:"space-y-4",children:[e.jsx(E,{className:"h-4 w-24"}),e.jsx(E,{className:"h-4 w-36"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(E,{className:"h-9 w-32"}),e.jsx(E,{className:"h-9 w-40"})]})]})]}),e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(E,{className:"h-5 w-20"})}),e.jsxs(I,{className:"space-y-4",children:[e.jsx(E,{className:"h-12 w-full"}),e.jsx(E,{className:"h-12 w-full"})]})]})]})}function $r({subscription:t,onChangePlan:s,onCancelSubscription:r,onReactivate:n,onAddPaymentMethod:a,isLoading:i,className:l}){if(i)return e.jsx(zr,{});if(!t)return e.jsx(qr,{onBrowsePlans:s});const{product:o,price:c,status:u,currentPeriodEnd:m,cancelAtPeriodEnd:x,trialEnd:p,features:y}=t,f=oe.format(c.amount,c.currency),g=Br(c.interval,c.intervalCount),v=new Date(m).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}),b=y.filter(j=>(j.type==="usage_quota"||j.type==="numeric_limit")&&j.usage),w=u==="trialing"&&p&&new Date(p).getTime()-Date.now()<4320*60*1e3;return e.jsxs("div",{className:h("space-y-6",l),children:[u==="past_due"&&e.jsx(Re,{type:"past_due",message:"Your last payment was declined. Update your payment method to avoid service interruption.",actionLabel:"Update Payment",onAction:a}),w&&p&&e.jsx(Re,{type:"trial_ending",message:`Your trial ends on ${new Date(p).toLocaleDateString()}. Add a payment method to continue.`,actionLabel:"Add Payment Method",onAction:a}),x&&e.jsx(Re,{type:"subscription_canceled",message:`Your subscription will end on ${v}. You'll have access until then.`,actionLabel:"Reactivate",onAction:n}),e.jsxs(F,{children:[e.jsx(J,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(de,{children:o.name}),e.jsxs(Be,{children:[f," / ",g]})]}),Or(u,x)]})}),e.jsxs(I,{className:"space-y-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:e.jsxs("p",{children:[x?"Access until":"Next billing",":"," ",e.jsx("span",{className:"font-medium text-foreground",children:v})]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(T,{variant:"outline",onClick:s,children:"View Other Plans"}),!x&&u!=="canceled"&&e.jsx(T,{variant:"ghost",className:"text-destructive hover:text-destructive",onClick:r,children:"Cancel Subscription"})]})]})]}),b.length>0&&e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(de,{className:"text-base",children:"Usage This Billing Period"})}),e.jsx(I,{className:"space-y-6",children:b.map(j=>e.jsx(ss,{title:j.title,usage:j.usage,unit:j.properties.unit},j.id))})]}),y.some(j=>j.type==="boolean_flag"&&j.enabled)&&e.jsx(F,{children:e.jsx(I,{className:"pt-6",children:e.jsx(rs,{features:y})})})]})}function Hr({className:t}){return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:h("h-4 w-4",t),children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",x2:"12",y1:"15",y2:"3"})]})}function Qr(t){switch(t){case"paid":return e.jsx(A,{variant:"success",children:"Paid"});case"open":return e.jsx(A,{variant:"secondary",children:"Open"});case"failed":return e.jsx(A,{variant:"destructive",children:"Failed"});case"void":return e.jsx(A,{variant:"outline",children:"Void"});default:return e.jsx(A,{variant:"outline",children:t})}}function xs({invoice:t,onRetry:s,onDownload:r,isRetrying:n,className:a}){const i=new Date(t.date).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}),l=oe.format(t.amount,t.currency);return e.jsx(F,{className:h("",a),children:e.jsxs(I,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:t.number}),Qr(t.status)]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:i}),t.lineItems.length>0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:t.lineItems[0].description})]}),e.jsx("div",{className:"text-right",children:e.jsx("p",{className:"font-semibold",children:l})})]}),t.status==="failed"&&t.failureReason&&e.jsx("div",{className:"mt-3 rounded-md bg-destructive/10 p-2 text-sm text-destructive",children:t.failureReason}),e.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[t.status==="failed"&&s&&e.jsx(T,{size:"sm",variant:"default",onClick:()=>s(t.id),disabled:n,children:n?"Retrying...":"Retry Payment"}),t.pdfUrl&&r&&e.jsxs(T,{size:"sm",variant:"outline",onClick:()=>r(t.pdfUrl),children:[e.jsx(Hr,{className:"mr-1"}),"Download PDF"]})]})]})})}function Kr(){return e.jsx(F,{children:e.jsxs(I,{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx("p",{className:"text-muted-foreground",children:"No invoices yet."}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Your first invoice will appear here after your first billing cycle."})]})})}function Vr(){return e.jsx("div",{className:"space-y-4",children:[1,2,3].map(t=>e.jsx(F,{children:e.jsxs(I,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"h-5 w-32"}),e.jsx(E,{className:"h-4 w-24"}),e.jsx(E,{className:"h-4 w-48"})]}),e.jsx(E,{className:"h-5 w-16"})]}),e.jsx("div",{className:"mt-4 flex gap-2",children:e.jsx(E,{className:"h-8 w-24"})})]})},t))})}function Wr({invoices:t,onRetryInvoice:s,onDownloadInvoice:r,retryingInvoiceId:n,isLoading:a,className:i}){return a?e.jsx(Vr,{}):t.length===0?e.jsx(Kr,{}):e.jsxs("div",{className:h("space-y-4",i),children:[e.jsx("h3",{className:"font-medium",children:"Invoice History"}),t.map(l=>e.jsx(xs,{invoice:l,onRetry:s,onDownload:r,isRetrying:n===l.id},l.id))]})}function Yr(t){return{visa:"💳",mastercard:"💳",amex:"💳",discover:"💳",diners:"💳",jcb:"💳",unionpay:"💳"}[t]||"💳"}function Gr(t){return{visa:"Visa",mastercard:"Mastercard",amex:"American Express",discover:"Discover",diners:"Diners Club",jcb:"JCB",unionpay:"UnionPay"}[t]||t.charAt(0).toUpperCase()+t.slice(1)}function fs({paymentMethod:t,onSetDefault:s,onRemove:r,isSettingDefault:n,isRemoving:a,className:i}){const{id:l,card:o,isDefault:c}=t;if(!o)return null;const u=`${o.expMonth.toString().padStart(2,"0")}/${o.expYear}`;return e.jsx(F,{className:h("",i),children:e.jsxs(I,{className:"p-4",children:[e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-2xl",children:Yr(o.brand)}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"font-medium",children:[Gr(o.brand)," •••• ",o.last4]}),c&&e.jsx(A,{variant:"secondary",children:"Default"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Expires ",u]})]})]})}),e.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[!c&&s&&e.jsx(T,{size:"sm",variant:"outline",onClick:()=>s(l),disabled:n,children:n?"Setting...":"Set as Default"}),r&&!c&&e.jsx(T,{size:"sm",variant:"ghost",onClick:()=>r(l),disabled:a,className:"text-destructive hover:text-destructive",children:a?"Removing...":"Remove"})]})]})})}function gs({className:t}){return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:h("h-4 w-4",t),children:[e.jsx("path",{d:"M5 12h14"}),e.jsx("path",{d:"M12 5v14"})]})}function Xr({onAdd:t}){return e.jsx(F,{children:e.jsxs(I,{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"No payment methods on file."}),e.jsxs(T,{onClick:t,children:[e.jsx(gs,{className:"mr-2"}),"Add Payment Method"]})]})})}function Jr(){return e.jsxs("div",{className:"space-y-4",children:[[1,2].map(t=>e.jsx(F,{children:e.jsxs(I,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(E,{className:"h-8 w-8 rounded"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"h-5 w-40"}),e.jsx(E,{className:"h-4 w-24"})]})]}),e.jsxs("div",{className:"mt-4 flex gap-2",children:[e.jsx(E,{className:"h-8 w-28"}),e.jsx(E,{className:"h-8 w-20"})]})]})},t)),e.jsx(E,{className:"h-10 w-44"})]})}function Zr({paymentMethods:t,onAddPaymentMethod:s,onSetDefault:r,onRemove:n,settingDefaultId:a,removingId:i,isLoading:l,className:o}){if(l)return e.jsx(Jr,{});if(t.length===0)return e.jsx(Xr,{onAdd:s});const c=[...t].sort((u,m)=>u.isDefault&&!m.isDefault?-1:!u.isDefault&&m.isDefault?1:0);return e.jsxs("div",{className:h("space-y-4",o),children:[e.jsx("h3",{className:"font-medium",children:"Payment Methods"}),c.map(u=>e.jsx(fs,{paymentMethod:u,onSetDefault:r,onRemove:n,isSettingDefault:a===u.id,isRemoving:i===u.id},u.id)),e.jsxs(T,{variant:"outline",onClick:s,children:[e.jsx(gs,{className:"mr-2"}),"Add New Payment Method"]})]})}const en=[{code:"US",name:"United States"},{code:"CA",name:"Canada"},{code:"GB",name:"United Kingdom"},{code:"AU",name:"Australia"},{code:"DE",name:"Germany"},{code:"FR",name:"France"},{code:"JP",name:"Japan"},{code:"IN",name:"India"},{code:"BR",name:"Brazil"},{code:"MX",name:"Mexico"}];ue.z.object({name:ue.z.string().min(1,"Name is required"),email:ue.z.string().email("Invalid email address"),line1:ue.z.string().optional(),line2:ue.z.string().optional(),city:ue.z.string().optional(),state:ue.z.string().optional(),postalCode:ue.z.string().optional(),country:ue.z.string().optional()});function tn(){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(E,{className:"h-5 w-40"})}),e.jsxs(I,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"h-4 w-12"}),e.jsx(E,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"h-4 w-12"}),e.jsx(E,{className:"h-10 w-full"})]})]})]}),e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(E,{className:"h-5 w-32"})}),e.jsxs(I,{className:"space-y-4",children:[e.jsx(E,{className:"h-10 w-full"}),e.jsx(E,{className:"h-10 w-full"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(E,{className:"h-10 w-full"}),e.jsx(E,{className:"h-10 w-full"})]})]})]}),e.jsx(E,{className:"h-10 w-28"})]})}function sn({customer:t,onSave:s,isSaving:r,isLoading:n,className:a}){var m,x,p,y,f,g;const{register:i,handleSubmit:l,formState:{errors:o,isDirty:c}}=Ls.useForm({defaultValues:{name:t.name||"",email:t.email||"",line1:((m=t.billingAddress)==null?void 0:m.line1)||"",line2:((x=t.billingAddress)==null?void 0:x.line2)||"",city:((p=t.billingAddress)==null?void 0:p.city)||"",state:((y=t.billingAddress)==null?void 0:y.state)||"",postalCode:((f=t.billingAddress)==null?void 0:f.postalCode)||"",country:((g=t.billingAddress)==null?void 0:g.country)||"US"}});if(n)return e.jsx(tn,{});const u=v=>{const b=v.line1||v.city||v.state||v.postalCode?{line1:v.line1||"",line2:v.line2,city:v.city||"",state:v.state||"",postalCode:v.postalCode||"",country:v.country||"US"}:void 0;s({name:v.name,email:v.email,billingAddress:b})};return e.jsxs("form",{onSubmit:l(u),className:h("space-y-6",a),children:[e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(de,{className:"text-base",children:"Personal Information"})}),e.jsxs(I,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"name",children:"Name"}),e.jsx(te,{id:"name",...i("name"),placeholder:"Your name"}),o.name&&e.jsx("p",{className:"text-sm text-destructive",children:o.name.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"email",children:"Email"}),e.jsx(te,{id:"email",type:"email",...i("email"),placeholder:"your@email.com"}),o.email&&e.jsx("p",{className:"text-sm text-destructive",children:o.email.message})]})]})]}),e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(de,{className:"text-base",children:"Billing Address"})}),e.jsxs(I,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"line1",children:"Address Line 1"}),e.jsx(te,{id:"line1",...i("line1"),placeholder:"123 Main St"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"line2",children:"Address Line 2"}),e.jsx(te,{id:"line2",...i("line2"),placeholder:"Apt 4B (optional)"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"city",children:"City"}),e.jsx(te,{id:"city",...i("city"),placeholder:"San Francisco"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"state",children:"State/Province"}),e.jsx(te,{id:"state",...i("state"),placeholder:"CA"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"postalCode",children:"ZIP/Postal Code"}),e.jsx(te,{id:"postalCode",...i("postalCode"),placeholder:"94102"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"country",children:"Country"}),e.jsx(rt,{id:"country",...i("country"),children:en.map(v=>e.jsx(nt,{value:v.code,children:v.name},v.code))})]})]})]})]}),e.jsx(T,{type:"submit",disabled:r||!c,children:r?"Saving...":"Save Changes"})]})}function rn({preview:t}){const{current_plan:s,new_plan:r,proration:n,change_type:a,next_billing_date:i,notes:l}=t,o=a==="upgrade";return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(de,{className:"text-sm",children:"Plan Change Summary"})}),e.jsxs(I,{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Current Plan:"}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"font-medium",children:s.product_name}),e.jsxs("div",{className:"text-muted-foreground text-xs",children:[oe.format(s.amount,s.currency)," / ",s.interval]})]})]}),e.jsx("div",{className:"flex justify-center",children:e.jsx("svg",{className:"w-4 h-4 text-muted-foreground",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 14l-7 7m0 0l-7-7m7 7V3"})})}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"New Plan:"}),e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"font-medium flex items-center gap-2 justify-end",children:[r.product_name,e.jsx(A,{variant:o?"default":"secondary",className:"text-xs",children:o?"Upgrade":"Downgrade"})]}),e.jsxs("div",{className:"text-muted-foreground text-xs",children:[oe.format(r.amount,r.currency)," / ",r.interval]})]})]})]})]}),o&&n.immediate_payment>0&&e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(de,{className:"text-sm",children:"Billing Details"})}),e.jsxs(I,{className:"space-y-2",children:[n.unused_time_credit>0&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Credit for unused time:"}),e.jsxs("span",{className:"text-green-600 font-medium",children:["-",oe.format(n.unused_time_credit,s.currency)]})]}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Prorated charge for new plan:"}),e.jsx("span",{className:"font-medium",children:oe.format(n.new_plan_charge,r.currency)})]}),e.jsx("div",{className:"border-t my-2"}),e.jsxs("div",{className:"flex justify-between text-base font-semibold",children:[e.jsx("span",{children:"Due Today:"}),e.jsx("span",{children:oe.format(n.immediate_payment,r.currency)})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-3",children:["Next billing: ",new Date(i).toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"})]})]})]}),!o&&e.jsx(Y,{children:e.jsxs(G,{className:"text-sm",children:["Your plan will change to ",e.jsx("strong",{children:r.product_name})," on"," ",e.jsx("strong",{children:new Date(i).toLocaleDateString(void 0,{month:"long",day:"numeric",year:"numeric"})}),". You'll keep access to your current plan features until then."]})}),l&&l.length>0&&e.jsx(Y,{children:e.jsx(G,{children:e.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm",children:l.map((c,u)=>e.jsx("li",{children:c},u))})})})]})}function nn({plan:t,isSelected:s,isCurrent:r,onSelect:n,disabled:a}){const i=oe.format(t.amount,t.currency),l=!r&&t.amount>0,o=!r&&!l;return e.jsx(F,{className:h("cursor-pointer transition-all hover:border-primary",s&&"ring-2 ring-primary",r&&"opacity-60",a&&"pointer-events-none opacity-50"),onClick:()=>!r&&!a&&n(),children:e.jsx(I,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-semibold",children:t.product_name}),r&&e.jsx(A,{variant:"secondary",children:"Current"}),l&&e.jsx(A,{variant:"default",children:"Upgrade"}),o&&e.jsx(A,{variant:"outline",children:"Downgrade"})]}),t.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t.description}),e.jsx("p",{className:"text-sm font-medium mt-2",children:t.is_free?"Free":`${i} / ${t.interval}`})]}),!r&&e.jsx("div",{className:"h-5 w-5 rounded-full border-2 border-primary flex items-center justify-center flex-shrink-0 ml-3",children:s&&e.jsx("div",{className:"h-2.5 w-2.5 rounded-full bg-primary"})})]})})})}function an({open:t,onOpenChange:s,subscriptionId:r,onSuccess:n}){var j;const[a,i]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(!1),{data:m,isLoading:x,error:p}=xt(r,{enabled:t}),y=ft(),f=gt({onSuccess:()=>{n==null||n(),s(!1)}});d.useEffect(()=>{t||(i(null),o(null),u(!1))},[t]);const g=async S=>{i(S),u(!1),o(null);try{const _=await y.mutateAsync({subscriptionId:r,input:{new_price_id:S.price_id,effective_date:"immediate"}});o(_),u(!0)}catch(_){console.error("Failed to preview plan change:",_),i(null)}},v=async()=>{if(!(!a||!l))try{await f.mutateAsync({subscriptionId:r,input:{new_price_id:a.price_id,confirm_amount:l.proration.immediate_payment,effective_date:"immediate"}})}catch(S){console.error("Failed to change plan:",S)}},b=[...(m==null?void 0:m.available_upgrades)||[],...(m==null?void 0:m.available_downgrades)||[]],w=(j=m==null?void 0:m.current_plan)==null?void 0:j.price_id;return e.jsx(fe,{open:t,onOpenChange:s,children:e.jsxs(he,{className:"sm:max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(ge,{children:[e.jsx(pe,{children:c?"Confirm Plan Change":"Change Your Plan"}),!c&&(m==null?void 0:m.current_plan)&&e.jsxs(be,{children:["You're currently on:"," ",e.jsxs("strong",{children:[m.current_plan.product_name," (",oe.format(m.current_plan.amount,m.current_plan.currency),"/",m.current_plan.interval,")"]})]})]}),e.jsxs("div",{className:"py-4",children:[x&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{className:"h-20 w-full"}),e.jsx(E,{className:"h-20 w-full"}),e.jsx(E,{className:"h-20 w-full"})]}),p&&e.jsx(Y,{variant:"destructive",children:e.jsx(G,{children:"Failed to load available plans. Please try again."})}),!x&&!p&&!c&&e.jsx("div",{className:"space-y-3",children:b.length===0?e.jsx(Y,{children:e.jsx(G,{children:"No other plans are currently available. Contact support if you need assistance."})}):e.jsxs(e.Fragment,{children:[b.map(S=>e.jsx(nn,{plan:S,isSelected:(a==null?void 0:a.price_id)===S.price_id,isCurrent:S.price_id===w,onSelect:()=>g(S),disabled:y.isPending},S.price_id)),(m==null?void 0:m.restrictions)&&m.restrictions.length>0&&e.jsx(Y,{className:"mt-4",children:e.jsxs(G,{children:[e.jsx("p",{className:"font-semibold mb-2",children:"Plan Change Restrictions:"}),e.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm",children:m.restrictions.map((S,_)=>e.jsx("li",{children:S},_))})]})})]})}),y.isPending&&a&&e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("svg",{className:"animate-spin h-5 w-5",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),e.jsx("span",{children:"Calculating proration..."})]})}),y.isError&&e.jsx(Y,{variant:"destructive",children:e.jsx(G,{children:"Failed to calculate proration. Please try again."})}),c&&l&&e.jsxs("div",{children:[e.jsx(Y,{className:"mb-4",children:e.jsx(G,{className:"text-sm",children:"Please review the details below before confirming your plan change."})}),e.jsx(rn,{preview:l})]})]}),e.jsx(ve,{children:c?e.jsxs(e.Fragment,{children:[e.jsx(T,{variant:"outline",onClick:()=>{u(!1),o(null),i(null)},disabled:f.isPending,children:"Back"}),e.jsx(T,{onClick:v,disabled:f.isPending,children:f.isPending?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsxs("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Processing..."]}):`Confirm ${(l==null?void 0:l.change_type)==="upgrade"?"Upgrade":"Downgrade"}`})]}):e.jsx(T,{variant:"outline",onClick:()=>s(!1),children:"Cancel"})})]})})}const ln=[{value:"too_expensive",label:"Too expensive"},{value:"missing_features",label:"Missing features I need"},{value:"found_alternative",label:"Found a better alternative"},{value:"no_longer_needed",label:"No longer need the service"},{value:"other",label:"Other"}];function on({open:t,onOpenChange:s,periodEndDate:r,onConfirm:n,isCanceling:a}){const[i,l]=d.useState([]),[o,c]=d.useState(""),[u,m]=d.useState("period_end");d.useEffect(()=>{t&&(l([]),c(""),m("period_end"))},[t]);const x=new Date(r).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}),p=f=>{l(g=>g.includes(f)?g.filter(v=>v!==f):[...g,f])},y=()=>{n({cancelAtPeriodEnd:u==="period_end",cancellationReason:i[0],feedback:o||void 0})};return e.jsx(fe,{open:t,onOpenChange:s,children:e.jsxs(he,{className:"sm:max-w-md",children:[e.jsxs(ge,{children:[e.jsx(pe,{children:"Cancel Subscription"}),e.jsx(be,{children:"We're sorry to see you go! Help us improve by telling us why you're canceling."})]}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(W,{className:"text-sm font-medium",children:"Reason for canceling"}),ln.map(f=>e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(Oe,{checked:i.includes(f.value),onCheckedChange:()=>p(f.value)}),e.jsx("span",{className:"text-sm",children:f.label})]},f.value))]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{htmlFor:"feedback",className:"text-sm font-medium",children:"Additional feedback (optional)"}),e.jsx(ot,{id:"feedback",value:o,onChange:f=>c(f.target.value),placeholder:"What could we have done better?",className:"resize-none",rows:3})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(W,{className:"text-sm font-medium",children:"When would you like to cancel?"}),e.jsxs(st,{value:u,onValueChange:f=>m(f),children:[e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx(Fe,{value:"period_end",className:"mt-1"}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-sm font-medium",children:["Cancel at period end (",x,")"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"You'll keep access until then."})]})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx(Fe,{value:"immediately",className:"mt-1"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"Cancel immediately"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"You'll lose access now. No refunds."})]})]})]})]})]}),e.jsxs(ve,{children:[e.jsx(T,{variant:"outline",onClick:()=>s(!1),disabled:a,children:"Keep Subscription"}),e.jsx(T,{variant:"destructive",onClick:y,disabled:a,children:a?"Canceling...":"Confirm Cancellation"})]})]})})}const cn={style:{base:{fontSize:"16px",color:"hsl(var(--foreground))","::placeholder":{color:"hsl(var(--muted-foreground))"}},invalid:{color:"hsl(var(--destructive))"}}};function dn({clientSecret:t,onSuccess:s,onCancel:r}){const n=ce.useStripe(),a=ce.useElements(),[i,l]=d.useState(!1),[o,c]=d.useState(null),[u,m]=d.useState(!0),x=async p=>{if(p.preventDefault(),!n||!a)return;l(!0),c(null);const y=a.getElement(ce.CardElement);if(!y){c("Card element not found"),l(!1);return}try{const{setupIntent:f,error:g}=await n.confirmCardSetup(t,{payment_method:{card:y}});if(g){c(g.message||"Failed to set up payment method"),l(!1);return}f!=null&&f.payment_method&&s(f.payment_method,u)}catch{c("An unexpected error occurred"),l(!1)}};return e.jsxs("form",{onSubmit:x,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(W,{children:"Card Details"}),e.jsx("div",{className:"rounded-md border border-input bg-background p-3",children:e.jsx(ce.CardElement,{options:cn})})]}),o&&e.jsx("p",{className:"text-sm text-destructive",children:o}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(Oe,{checked:u,onCheckedChange:p=>m(p)}),e.jsx("span",{className:"text-sm",children:"Set as default payment method"})]})]}),e.jsxs(ve,{children:[e.jsx(T,{type:"button",variant:"outline",onClick:r,disabled:i,children:"Cancel"}),e.jsx(T,{type:"submit",disabled:!n||i,children:i?"Adding...":"Add Card"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground text-center flex items-center justify-center gap-1",children:[e.jsx(un,{className:"h-3 w-3"}),"Secured by Stripe"]})]})}function un({className:t}){return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:h("h-4 w-4",t),children:[e.jsx("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function mn(){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"h-4 w-24"}),e.jsx(E,{className:"h-12 w-full"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{className:"h-4 w-4"}),e.jsx(E,{className:"h-4 w-48"})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(E,{className:"h-10 w-20"}),e.jsx(E,{className:"h-10 w-24"})]})]})}let Qe=null;function hn(t){return Qe||(Qe=dt.loadStripe(t)),Qe}function xn({open:t,onOpenChange:s,onSuccess:r,clientSecret:n,stripePublishableKey:a,isLoading:i}){const l=()=>{s(!1)},o=(u,m)=>{r(u,m),s(!1)},c=!i&&n&&a;return e.jsx(fe,{open:t,onOpenChange:s,children:e.jsxs(he,{className:"sm:max-w-md",children:[e.jsxs(ge,{children:[e.jsx(pe,{children:"Add Payment Method"}),e.jsx(be,{children:"Enter your card details below. Your card will be saved for future payments."})]}),i&&e.jsx(mn,{}),c&&e.jsx(ce.Elements,{stripe:hn(a),children:e.jsx(dn,{clientSecret:n,onSuccess:o,onCancel:l})}),!i&&!c&&e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx("p",{children:"Unable to load payment form. Please try again."}),e.jsx(T,{variant:"outline",className:"mt-4",onClick:l,children:"Close"})]})]})})}function ps({trigger:t,onUpgrade:s,onDismiss:r}){const n=t.actual&&t.actual>=95;return e.jsx("div",{className:h("fixed top-0 left-0 right-0 z-50 animate-in slide-in-from-top duration-300","px-4 py-2"),role:n?"alert":"status",children:e.jsxs(Y,{variant:n?"destructive":"default",className:"max-w-4xl mx-auto flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3 flex-1",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:n?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-destructive",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-amber-500",children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),e.jsx("line",{x1:"12",x2:"12",y1:"9",y2:"13"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"17",y2:"17"})]})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx(Ae,{className:"mb-1 font-semibold",children:t.message.title}),e.jsx(G,{className:"text-sm",children:t.message.body})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4 flex-shrink-0",children:[e.jsx(T,{size:"sm",onClick:s,children:t.message.cta}),e.jsx(T,{variant:"ghost",size:"sm",onClick:r,children:"Maybe Later"})]})]})})}function ys({trigger:t,onUpgrade:s,onDismiss:r}){const n=t.actual&&t.actual>=95;return e.jsx("div",{className:h("fixed bottom-4 right-4 z-50 animate-in slide-in-from-bottom-4 duration-400","w-80 max-w-[calc(100vw-2rem)]"),role:"status","aria-live":"polite",children:e.jsxs(F,{className:"shadow-lg border-2",children:[e.jsxs(J,{className:"pb-2 pr-8 relative",children:[e.jsx("button",{onClick:r,className:"absolute top-3 right-3 p-1 rounded-md hover:bg-muted transition-colors","aria-label":"Dismiss",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})}),e.jsxs("div",{className:"flex items-start gap-2",children:[n?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-destructive flex-shrink-0 mt-0.5",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-amber-500 flex-shrink-0 mt-0.5",children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),e.jsx("line",{x1:"12",x2:"12",y1:"9",y2:"13"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"17",y2:"17"})]}),e.jsx(de,{className:"text-base font-semibold leading-tight",children:t.message.title})]})]}),e.jsxs(I,{className:"pt-0 pb-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:t.message.body}),e.jsx(T,{className:"w-full",size:"sm",onClick:s,children:t.message.cta})]})]})})}function js({trigger:t,onUpgrade:s,onDismiss:r}){const n=t.actual&&t.actual>=100,a=(i,l)=>new Intl.NumberFormat("en-US",{style:"currency",currency:l.toUpperCase(),minimumFractionDigits:0,maximumFractionDigits:0}).format(i/100);return e.jsx(fe,{open:!0,onOpenChange:i=>!i&&r(),children:e.jsxs(he,{className:"sm:max-w-md",role:n?"alertdialog":"dialog",children:[e.jsxs(ge,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[n?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-destructive",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-amber-500",children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),e.jsx("line",{x1:"12",x2:"12",y1:"9",y2:"13"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"17",y2:"17"})]}),e.jsx(pe,{children:t.message.title})]}),e.jsx(be,{className:"pt-2",children:t.message.body})]}),e.jsx(F,{className:"border-2 border-primary/20",children:e.jsxs(I,{className:"pt-4",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:t.suggestedPlan.name}),e.jsxs("div",{className:"flex items-baseline gap-1 mt-1",children:[e.jsx("span",{className:"text-2xl font-bold",children:a(t.suggestedPlan.price.amount,t.suggestedPlan.price.currency)}),e.jsxs("span",{className:"text-muted-foreground text-sm",children:["/ ",t.suggestedPlan.price.interval]})]})]}),e.jsx(A,{variant:"secondary",children:"Recommended"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"What you'll get:"}),e.jsx("ul",{className:"space-y-2",children:t.suggestedPlan.highlights.map((i,l)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-green-500 flex-shrink-0 mt-0.5",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),i]},l))})]})]})}),e.jsxs(ve,{className:"flex-col sm:flex-row gap-2",children:[e.jsx(T,{variant:"outline",onClick:r,className:"sm:flex-1",children:"Maybe Later"}),e.jsxs(T,{onClick:s,className:"sm:flex-1",children:[t.message.cta," - ",a(t.suggestedPlan.price.amount,t.suggestedPlan.price.currency),"/",t.suggestedPlan.price.interval]})]})]})})}function fn(t){if(typeof window>"u")return;const s=`nudge_dismissed_${t.type}_${t.feature||"general"}`;localStorage.setItem(s,Date.now().toString())}function gn({trigger:t,style:s="banner",autoDismiss:r=0,onUpgrade:n,onDismiss:a,theme:i}){const[l,o]=d.useState(!0);d.useEffect(()=>{o(!0)},[t,s]),d.useEffect(()=>{if(r>0&&l){const m=setTimeout(()=>{c()},r);return()=>clearTimeout(m)}},[r,l]),d.useEffect(()=>{const m=x=>{x.key==="Escape"&&l&&c()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[l]);const c=()=>{o(!1),fn(t),a==null||a()},u=()=>{n==null||n(t.suggestedPlan.priceId)};if(!l)return null;switch(s){case"banner":return e.jsx(ps,{trigger:t,onUpgrade:u,onDismiss:c,theme:i});case"toast":return e.jsx(ys,{trigger:t,onUpgrade:u,onDismiss:c,theme:i});case"modal":return e.jsx(js,{trigger:t,onUpgrade:u,onDismiss:c,theme:i});default:return null}}function pn(t={}){const{client:s}=D(),{enabled:r=!0,refetchInterval:n=0}=t;return P.useQuery({queryKey:["usageCheck"],queryFn:async()=>s.checkUsage(),enabled:r,staleTime:300*1e3,gcTime:600*1e3,refetchInterval:n>0?n:void 0})}function yn({feature:t,children:s,fallback:r,loading:n,onAccessDenied:a,onQuotaExceeded:i,showUsageBadge:l=!1}){const{hasAccess:o,isLoading:c,isError:u,usage:m,limit:x,remaining:p}=Nt(t,{onAccessDenied:a,onQuotaExceeded:i});return c?e.jsx(e.Fragment,{children:n||e.jsx(jn,{})}):u||!o?e.jsx(e.Fragment,{children:r||e.jsx(vn,{feature:t})}):l&&x>0?e.jsxs("div",{className:"relative",children:[s,e.jsx(bn,{usage:m,limit:x,remaining:p})]}):e.jsx(e.Fragment,{children:s})}function jn(){return e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx("div",{className:"animate-pulse text-gray-400",children:"Checking access..."})})}function vn({feature:t}){return e.jsx("div",{className:"p-4 border border-gray-200 bg-gray-50 rounded-lg",children:e.jsxs("div",{className:"text-center",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})}),e.jsx("h3",{className:"mt-2 text-sm font-medium text-gray-900",children:"Feature Locked"}),e.jsxs("p",{className:"mt-1 text-sm text-gray-500",children:["Upgrade your plan to access ",t.replace(/_/g," ")]})]})})}function bn({usage:t,limit:s,remaining:r}){const n=Math.min(100,Math.round(t/s*100));let a="bg-green-100 text-green-800";return n>=90?a="bg-red-100 text-red-800":n>=75&&(a="bg-yellow-100 text-yellow-800"),e.jsxs("div",{className:`absolute top-2 right-2 px-2 py-1 rounded-full text-xs font-medium ${a}`,children:[r.toLocaleString()," / ",s.toLocaleString()," remaining"]})}function wn({featureKey:t,title:s="Usage Metrics",showProgress:r=!0,showResetTimer:n=!0,className:a=""}){const{data:i,isLoading:l,isError:o}=Ye(t);return l?e.jsxs("div",{className:`p-4 animate-pulse ${a}`,children:[e.jsx("div",{className:"h-4 bg-gray-200 rounded w-1/4 mb-4"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded"}),e.jsx("div",{className:"h-8 bg-gray-200 rounded"})]})]}):o||!(i!=null&&i.metrics)||i.metrics.length===0?e.jsx("div",{className:`p-4 text-center text-gray-500 ${a}`,children:"No usage data available"}):e.jsxs("div",{className:`p-4 ${a}`,children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:s}),e.jsx("div",{className:"space-y-4",children:i.metrics.map(c=>e.jsx(Nn,{metric:c,showProgress:r,showResetTimer:n},c.feature_key))})]})}function Nn({metric:t,showProgress:s,showResetTimer:r}){const n=a=>a>=90?"bg-red-500":a>=75?"bg-yellow-500":"bg-green-500";return e.jsxs("div",{className:"border border-gray-200 rounded-lg p-4 bg-white",children:[e.jsxs("div",{className:"flex justify-between items-start mb-2",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-gray-900",children:t.feature_title}),e.jsx("p",{className:"text-sm text-gray-500",children:t.product_name})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-2xl font-semibold",children:t.consumed.toLocaleString()}),e.jsxs("div",{className:"text-sm text-gray-500",children:["of ",t.limit.toLocaleString()]})]})]}),s&&e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"w-full bg-gray-200 rounded-full h-2",children:e.jsx("div",{className:`h-2 rounded-full transition-all ${n(t.percentage_used)}`,style:{width:`${Math.min(100,t.percentage_used)}%`}})}),e.jsxs("div",{className:"flex justify-between mt-1",children:[e.jsxs("span",{className:"text-xs text-gray-500",children:[t.percentage_used,"% used"]}),e.jsxs("span",{className:"text-xs text-gray-500",children:[t.remaining.toLocaleString()," remaining"]})]})]}),r&&t.resets_in_days>0&&e.jsxs("div",{className:"mt-2 text-xs text-gray-500",children:[e.jsx("svg",{className:"inline-block w-3 h-3 mr-1",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Resets in ",t.resets_in_days," day",t.resets_in_days!==1?"s":""]})]})}function Cn({featureKey:t,className:s=""}){var l;const{data:r,isLoading:n}=Ye(t);if(n||!((l=r==null?void 0:r.metrics)!=null&&l[0]))return null;const a=r.metrics[0],i=o=>o>=90?"text-red-600":o>=75?"text-yellow-600":"text-green-600";return e.jsxs("div",{className:`inline-flex items-center gap-2 ${s}`,children:[e.jsx("span",{className:"text-sm text-gray-500",children:"Usage:"}),e.jsxs("span",{className:`text-sm font-medium ${i(a.percentage_used)}`,children:[a.consumed.toLocaleString()," / ",a.limit.toLocaleString()]}),a.percentage_used>=90&&e.jsx("svg",{className:"w-4 h-4 text-red-500",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})]})}function Sn({feature:t,title:s="Upgrade Required",description:r,isQuotaExceeded:n=!1,usage:a,limit:i,className:l="",onUpgradeClick:o}){const{data:c}=Ct(),u=n?`You've reached your usage limit${t?` for ${t}`:""}. Upgrade your plan to continue.`:`Upgrade your plan to access${t?` ${t}`:" this feature"}.`,m=()=>{if(o)o();else{const x=document.querySelector("[data-pricing-table]");x&&x.scrollIntoView({behavior:"smooth",block:"center"})}};return e.jsx("div",{className:`rounded-lg border-2 border-dashed border-gray-300 p-8 ${l}`,children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-gradient-to-br from-blue-500 to-purple-600",children:e.jsx("svg",{className:"h-6 w-6 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),e.jsx("h3",{className:"mt-4 text-lg font-semibold text-gray-900",children:s}),e.jsx("p",{className:"mt-2 text-sm text-gray-600",children:r||u}),n&&a!==void 0&&i!==void 0&&e.jsxs("div",{className:"mt-4 inline-flex items-center gap-2 rounded-full bg-red-50 px-3 py-1",children:[e.jsx("svg",{className:"h-4 w-4 text-red-500",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})}),e.jsxs("span",{className:"text-sm font-medium text-red-800",children:[a.toLocaleString()," / ",i.toLocaleString()," used"]})]}),e.jsx("div",{className:"mt-6",children:e.jsxs("button",{onClick:m,className:"inline-flex items-center rounded-md bg-gradient-to-r from-blue-600 to-purple-600 px-6 py-3 text-sm font-semibold text-white shadow-sm hover:from-blue-700 hover:to-purple-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2",children:[e.jsx("svg",{className:"mr-2 h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 10l7-7m0 0l7 7m-7-7v18"})}),"Upgrade Plan"]})}),(c==null?void 0:c.products)&&c.products.length>0&&e.jsxs("div",{className:"mt-6 text-xs text-gray-500",children:["Available plans:",e.jsx("div",{className:"mt-1 flex justify-center gap-2",children:c.products.slice(0,3).map(x=>e.jsx("span",{className:"inline-block rounded-full bg-gray-100 px-2 py-1",children:x.name},x.id))})]})]})})}function kn({feature:t,onUpgradeClick:s,className:r=""}){return e.jsxs("div",{className:`inline-flex items-center gap-2 rounded-md bg-yellow-50 px-3 py-2 ${r}`,children:[e.jsx("svg",{className:"h-4 w-4 text-yellow-600",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M10 1.944A11.954 11.954 0 012.166 5C2.056 5.649 2 6.319 2 7c0 5.225 3.34 9.67 8 11.317C14.66 16.67 18 12.225 18 7c0-.682-.057-1.35-.166-2.001A11.954 11.954 0 0110 1.944zM11 14a1 1 0 11-2 0 1 1 0 012 0zm0-7a1 1 0 10-2 0v3a1 1 0 102 0V7z",clipRule:"evenodd"})}),e.jsxs("span",{className:"text-sm text-yellow-800",children:["Upgrade to access",t?` ${t}`:" this feature"]}),e.jsx("button",{onClick:s,className:"ml-1 text-sm font-medium text-yellow-800 hover:text-yellow-900 underline",children:"Upgrade"})]})}const vs=(t,s="PPP")=>{const r=typeof t=="string"?re.parseISO(t):t;return re.format(r,s)},bs=(t,s=new Date)=>{const r=typeof t=="string"?re.parseISO(t):t;return re.formatDistance(r,s,{addSuffix:!0})},ws=(t,s=new Date)=>{const r=typeof t=="string"?re.parseISO(t):t;return re.formatRelative(r,s)},Ns=t=>{const s=typeof t=="string"?re.parseISO(t):t;return re.isBefore(s,new Date)},Cs=t=>{const s=typeof t=="string"?re.parseISO(t):t;return re.isAfter(s,new Date)},Ss=t=>re.parseISO(t),Pn={format:vs,formatRelative:bs,formatRelativeDate:ws,isPast:Ns,isFuture:Cs,parse:Ss};console.log("%c🎯 BillingOS SDK v1.2.0 loaded with Iframe Checkout","background: #3b82f6; color: white; padding: 6px 12px; border-radius: 6px; font-weight: bold; font-size: 14px;");typeof window<"u"&&(window.billingOS={checkout:{open:async t=>Se().open(t)}});Object.defineProperty(exports,"useBillingOSQueryClient",{enumerable:!0,get:()=>P.useQueryClient});exports.AddPaymentMethodModal=xn;exports.Alert=Y;exports.AlertDescription=G;exports.AlertTitle=Ae;exports.Badge=A;exports.BannerNudge=ps;exports.BillingOSClient=Ve;exports.BillingOSError=ne;exports.BillingOSProvider=ht;exports.Button=T;exports.CancelSubscriptionModal=on;exports.Card=F;exports.CardContent=I;exports.CardDescription=Be;exports.CardFooter=Ge;exports.CardHeader=J;exports.CardTitle=de;exports.ChangePlanModal=an;exports.Checkbox=Oe;exports.CheckoutAPI=vt;exports.CheckoutModal=Me;exports.CompactUpgradePrompt=kn;exports.CompactUsageDisplay=Cn;exports.CustomerPortal=wr;exports.DateUtils=Pn;exports.Dialog=fe;exports.DialogContent=he;exports.DialogDescription=be;exports.DialogFooter=ve;exports.DialogHeader=ge;exports.DialogOverlay=We;exports.DialogPortal=Vs;exports.DialogTitle=pe;exports.DialogTrigger=yt;exports.Drawer=Et;exports.DrawerClose=Tt;exports.DrawerContent=Xe;exports.DrawerDescription=et;exports.DrawerFooter=_t;exports.DrawerHeader=Je;exports.DrawerTitle=Ze;exports.DrawerTrigger=Dt;exports.FeatureGate=yn;exports.FeatureList=rs;exports.Input=te;exports.InvoiceCard=xs;exports.InvoicesTab=Wr;exports.Label=W;exports.ModalNudge=js;exports.Money=oe;exports.NetworkError=Ce;exports.NotFoundError=De;exports.PaymentBottomSheet=es;exports.PaymentMethodCard=fs;exports.PaymentMethodsTab=Zr;exports.PricingCard=br;exports.PricingTable=ts;exports.Progress=tt;exports.RadioGroup=st;exports.RadioGroupItem=Fe;exports.RateLimitError=_e;exports.ScrollArea=Rt;exports.ScrollBar=Mt;exports.Select=rt;exports.SelectOption=nt;exports.Separator=ke;exports.ServerError=Ie;exports.SettingsTab=sn;exports.Sheet=It;exports.SheetClose=At;exports.SheetContent=at;exports.SheetDescription=qt;exports.SheetFooter=Ot;exports.SheetHeader=it;exports.SheetTitle=lt;exports.SheetTrigger=Ut;exports.Skeleton=E;exports.SubscriptionTab=$r;exports.Tabs=Ht;exports.TabsContent=Vt;exports.TabsList=Qt;exports.TabsTrigger=Kt;exports.Textarea=ot;exports.ToastNudge=ys;exports.UnauthorizedError=Ee;exports.UpgradeNudge=gn;exports.UpgradePrompt=Sn;exports.UsageBar=ss;exports.UsageDisplay=wn;exports.ValidationError=Te;exports.WarningBanner=Re;exports.addAmounts=hs;exports.badgeVariants=St;exports.buttonVariants=kt;exports.calculatePercentage=ms;exports.cn=h;exports.convertCentsToFloat=ns;exports.convertFloatToCents=as;exports.createBillingOSClient=As;exports.entitlementKeys=me;exports.formatCurrencyAndAmount=je;exports.formatCurrencyCompact=is;exports.formatCurrencyWhole=ls;exports.formatDate=vs;exports.formatPriceRange=cs;exports.formatRelativeDate=ws;exports.formatRelativeTime=bs;exports.getCentsInDollarString=Ar;exports.getCheckoutAPI=Se;exports.getCurrencySymbol=os;exports.isFuture=Cs;exports.isNegativeAmount=us;exports.isNotFoundError=Is;exports.isPast=Ns;exports.isRateLimitError=Us;exports.isUnauthorizedError=Fs;exports.isValidationError=Ms;exports.isZeroAmount=ds;exports.openCheckout=Js;exports.parseDate=Ss;exports.portalKeys=ee;exports.subscriptionKeys=q;exports.useAddPaymentMethod=Er;exports.useAvailablePlans=xt;exports.useBillingOS=D;exports.useCancelPortalSubscription=Sr;exports.useCancelSubscription=Hs;exports.useChangePlan=gt;exports.useCheckEntitlement=bt;exports.useCheckout=Zs;exports.useConfirmCheckout=gr;exports.useCreateCheckout=Zt;exports.useCreateSubscription=zs;exports.useEntitlements=tr;exports.useFeature=wt;exports.useFeatureEntitlements=ar;exports.useFeatureGate=Nt;exports.useHasFeature=er;exports.useIsApproachingLimit=rr;exports.usePortalData=Nr;exports.usePreviewPlanChange=ft;exports.usePricingTableProducts=Jt;exports.useProducts=Ct;exports.useReactivatePortalSubscription=kr;exports.useReactivateSubscription=Qs;exports.useRemovePaymentMethod=Dr;exports.useRetryInvoice=_r;exports.useSessionToken=ut;exports.useSetDefaultPaymentMethod=Tr;exports.useSetupIntent=Pr;exports.useSubscription=Os;exports.useSubscriptionPreview=Ks;exports.useSubscriptions=qs;exports.useTrackUsage=nr;exports.useUpdateCustomerBilling=Lr;exports.useUpdatePortalSubscription=Cr;exports.useUpdateSubscription=$s;exports.useUsageCheck=pn;exports.useUsageMetrics=Ye;
2
+ "use strict";var Ps=Object.defineProperty;var Es=(t,s,r)=>s in t?Ps(t,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[s]=r;var se=(t,s,r)=>Es(t,typeof s!="symbol"?s+"":s,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("react"),P=require("@tanstack/react-query"),e=require("react/jsx-runtime"),Ds=require("react-dom/client"),Ts=require("clsx"),_s=require("tailwind-merge"),Pe=require("class-variance-authority"),dt=require("@stripe/stripe-js"),ce=require("@stripe/react-stripe-js"),Ls=require("react-hook-form"),ue=require("zod"),re=require("date-fns");function Rs(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(s,r,n.get?n:{enumerable:!0,get:()=>t[r]})}}return s.default=t,Object.freeze(s)}const d=Rs(C);class ne extends Error{constructor(s,r,n){super(s),this.status=r,this.data=n,this.name="BillingOSError",Object.setPrototypeOf(this,ne.prototype)}}class Ee extends ne{constructor(s="Unauthorized: Invalid or missing API key",r){super(s,401,r),this.name="UnauthorizedError",Object.setPrototypeOf(this,Ee.prototype)}}class De extends ne{constructor(s="Resource not found",r){super(s,404,r),this.name="NotFoundError",Object.setPrototypeOf(this,De.prototype)}}class Te extends ne{constructor(s="Validation failed",r){super(s,400,r),this.name="ValidationError",Object.setPrototypeOf(this,Te.prototype)}}class _e extends ne{constructor(s="Too many requests",r){super(s,429,r),this.name="RateLimitError",Object.setPrototypeOf(this,_e.prototype)}}class Ie extends ne{constructor(s="Internal server error",r){super(s,500,r),this.name="ServerError",Object.setPrototypeOf(this,Ie.prototype)}}class Ce extends ne{constructor(s="Network request failed",r){super(s,void 0,r),this.name="NetworkError",Object.setPrototypeOf(this,Ce.prototype)}}function Ms(t){return t instanceof Te}function Fs(t){return t instanceof Ee}function Is(t){return t instanceof De}function Us(t){return t instanceof _e}class We{constructor(s,r={}){se(this,"sessionToken");se(this,"baseUrl");se(this,"headers");se(this,"timeout");se(this,"checkout",{createSession:async s=>{var n,a;console.log("[SDK Client] Creating checkout session with:",{priceId:s.priceId,customer:s.customer,hasEmail:!!((n=s.customer)!=null&&n.email),hasName:!!((a=s.customer)!=null&&a.name)});const r=await this.post("/v1/checkout/create",s);return console.log("[SDK Client] Checkout session created:",{sessionId:r.id,status:r.status}),r},getSession:async s=>this.get(`/v1/checkout/${s}/status`),cancelSession:async s=>{throw new Error("Cancel session not implemented yet")},confirmPayment:async(s,r)=>this.post(`/v1/checkout/${s}/confirm`,{paymentMethodId:r}),applyCoupon:async(s,r)=>{throw new Error("Apply coupon not implemented yet")}});se(this,"portal",{createSession:async s=>{console.log("[SDK Client] Creating portal session");const r=await this.post("/v1/portal/create",s||{});return console.log("[SDK Client] Portal session created:",{sessionId:r.id,customerId:r.customerId,expiresAt:r.expiresAt}),{id:r.id,expiresAt:r.expiresAt}},getSessionStatus:async s=>this.get(`/v1/portal/${s}/status`),getPortalData:async s=>this.get(`/v1/portal/${s}/data`)});if(!s)throw new Error("Session token is required");this.sessionToken=s,this.timeout=r.timeout||3e4,r.baseUrl?this.baseUrl=r.baseUrl:r.environment==="sandbox"?this.baseUrl="https://sandbox.billingos.com/api":this.baseUrl=process.env.NEXT_PUBLIC_API_URL||"http://localhost:3001",this.headers={"Content-Type":"application/json",Authorization:`Bearer ${this.sessionToken}`,"X-BillingOS-Version":r.version||"2026-01-01",...r.headers}}async request(s,r={}){var l;const n=`${this.baseUrl}${s}`,a=new AbortController,i=setTimeout(()=>a.abort(),this.timeout);try{const o=await fetch(n,{...r,headers:{...this.headers,...r.headers},signal:a.signal});if(clearTimeout(i),o.status===204)return;const c=o.headers.get("content-type"),u=c==null?void 0:c.includes("application/json"),m=u?await o.json():await o.text();if(!o.ok){const x=u?m:{error:{message:m}},p=((l=x.error)==null?void 0:l.message)||`Request failed with status ${o.status}`;switch(o.status){case 400:throw new Te(p,x);case 401:throw new Ee(p,x);case 404:throw new De(p,x);case 429:throw new _e(p,x);case 500:case 502:case 503:case 504:throw new Ie(p,x);default:throw new ne(p,o.status,x)}}return m}catch(o){throw clearTimeout(i),o instanceof ne?o:o instanceof Error&&o.name==="AbortError"?new Ce("Request timeout"):new Ce("Network request failed",o)}}get(s){return this.request(s,{method:"GET"})}post(s,r){return this.request(s,{method:"POST",body:r?JSON.stringify(r):void 0})}patch(s,r){return this.request(s,{method:"PATCH",body:r?JSON.stringify(r):void 0})}delete(s){return this.request(s,{method:"DELETE"})}async createCustomer(s){return this.post("/customers",s)}async getCustomer(s){return this.get(`/customers/${s}`)}async listCustomers(s){const r=new URLSearchParams;s!=null&&s.page&&r.set("page",s.page.toString()),s!=null&&s.page_size&&r.set("page_size",s.page_size.toString());const n=r.toString();return this.get(`/customers${n?`?${n}`:""}`)}async updateCustomer(s,r){return this.patch(`/customers/${s}`,r)}async deleteCustomer(s){return this.delete(`/customers/${s}`)}async createSubscription(s){return this.post("/subscriptions",s)}async getSubscription(s){return this.get(`/subscriptions/${s}`)}async listSubscriptions(s){const r=new URLSearchParams;s!=null&&s.customer_id&&r.set("customer_id",s.customer_id),s!=null&&s.page&&r.set("page",s.page.toString()),s!=null&&s.page_size&&r.set("page_size",s.page_size.toString());const n=r.toString();return this.get(`/subscriptions${n?`?${n}`:""}`)}async updateSubscription(s,r){return this.patch(`/subscriptions/${s}`,r)}async cancelSubscription(s,r=!1){return this.post(`/subscriptions/${s}/cancel`,{immediately:r})}async reactivateSubscription(s){return this.post(`/subscriptions/${s}/reactivate`)}async previewSubscription(s,r){return this.post(`/subscriptions/${s}/preview`,r)}async getAvailablePlans(s){return this.get(`/subscriptions/${s}/available-plans`)}async previewPlanChange(s,r){return this.post(`/subscriptions/${s}/preview-change`,r)}async changePlan(s,r){return this.post(`/subscriptions/${s}/change-plan`,r)}async checkEntitlement(s){return this.get(`/v1/features/check?feature_key=${encodeURIComponent(s.feature_key)}`)}async listEntitlements(s){return(await this.get("/v1/features/entitlements")).entitlements}async trackUsage(s){return this.post("/v1/features/track-usage",{feature_key:s.feature_key,quantity:s.quantity,timestamp:s.timestamp,idempotency_key:s.idempotency_key,metadata:s.metadata})}async getUsageMetrics(s,r){var i;const n=r?`?feature_key=${encodeURIComponent(r)}`:"";return((i=(await this.get(`/v1/features/usage-metrics${n}`)).metrics)==null?void 0:i[0])??{feature_key:r||"",current_usage:0,period_start:"",period_end:""}}async getInvoice(s){return this.get(`/invoices/${s}`)}async listInvoices(s){const r=new URLSearchParams;s!=null&&s.customer_id&&r.set("customer_id",s.customer_id),s!=null&&s.page&&r.set("page",s.page.toString()),s!=null&&s.page_size&&r.set("page_size",s.page_size.toString());const n=r.toString();return this.get(`/invoices${n?`?${n}`:""}`)}async listPaymentMethods(s){return this.get(`/payment-methods?customer_id=${s}`)}async removePaymentMethod(s){return this.delete(`/payment-methods/${s}`)}async setDefaultPaymentMethod(s){return this.post(`/payment-methods/${s}/set-default`)}async getCustomerPortal(){return this.get("/sdk/customer/portal")}async updatePortalSubscription(s,r){return this.post(`/sdk/subscriptions/${s}/update`,r)}async cancelPortalSubscription(s,r){return this.post(`/sdk/subscriptions/${s}/cancel`,r)}async reactivatePortalSubscription(s){return this.post(`/sdk/subscriptions/${s}/reactivate`)}async addPaymentMethod(s){return this.post("/sdk/payment-methods",s)}async getSetupIntent(){return this.post("/sdk/payment-methods/setup-intent")}async retryInvoice(s,r){return this.post(`/sdk/invoices/${s}/retry`,{paymentMethodId:r})}async updateCustomerBilling(s){return this.patch("/sdk/customer/billing",s)}async createCheckout(s){return this.post("/v1/checkout/create",s)}async confirmCheckout(s,r){return this.post(`/v1/checkout/${s}/confirm`,{paymentMethodId:r})}async getProducts(s){const r=new URLSearchParams;s&&s.length>0&&r.set("planIds",s.join(","));const n=r.toString();return this.get(`/v1/products${n?`?${n}`:""}`)}async checkUsage(){const n=((await this.get("/v1/features/usage-metrics")).metrics||[]).find(a=>!a.limit||a.limit===0?!1:a.consumed/a.limit*100>=80);return n?{shouldShowNudge:!0,trigger:{type:"usage_threshold",feature:n.feature_key,threshold:80,actual:Math.round(n.consumed/n.limit*100*10)/10,message:{title:"Approaching usage limit",body:`You've used ${Math.round(n.consumed/n.limit*100)}% of your ${n.feature_title||n.feature_key} limit.`,cta:"Upgrade plan"},suggestedPlan:{id:"",priceId:"",name:"",price:{amount:0,currency:"usd",interval:"month"},highlights:[]}}}:{shouldShowNudge:!1}}}function As(t,s){return new We(t,s)}function ut(t={}){const{tokenUrl:s,token:r,refreshBeforeExpiry:n=300,autoRefresh:a=!0,onTokenRefresh:i,onError:l}=t,[o,c]=C.useState(r||null),[u,m]=C.useState(null),[x,p]=C.useState(!!(s&&!r)),[y,f]=C.useState(null),g=C.useRef(null),v=C.useRef(!0),b=C.useCallback(async()=>{if(s)try{p(!0),f(null);const j=await fetch(s,{method:"GET",headers:{"Content-Type":"application/json"},credentials:"include"});if(!j.ok){const _=await j.json().catch(()=>({}));throw new Error(_.error||`Failed to fetch session token: ${j.statusText}`)}const S=await j.json();if(!v.current)return;c(S.sessionToken),m(new Date(S.expiresAt)),f(null),i==null||i(S.sessionToken)}catch(j){const S=j instanceof Error?j:new Error("Failed to fetch session token");if(!v.current)return;f(S),l==null||l(S)}finally{v.current&&p(!1)}},[s,i,l]);C.useEffect(()=>{if(!a||!u||!s)return;g.current&&clearTimeout(g.current);const j=Date.now(),_=u.getTime()-j,k=_-n*1e3;return k>0?g.current=setTimeout(()=>{b()},k):_>0&&b(),()=>{g.current&&clearTimeout(g.current)}},[u,a,n,s,b]),C.useEffect(()=>{s&&!r&&b()},[s,r,b]),C.useEffect(()=>{r&&(c(r),m(null))},[r]),C.useEffect(()=>()=>{v.current=!1,g.current&&clearTimeout(g.current)},[]);const w=!!(o&&(!u||u.getTime()>Date.now()));return{token:o,expiresAt:u,isLoading:x,error:y,refresh:b,isValid:w}}const mt=C.createContext(void 0),Bs=()=>new P.QueryClient({defaultOptions:{queries:{staleTime:1e3*60*5,gcTime:1e3*60*10,retry:1,refetchOnWindowFocus:!1},mutations:{retry:!1}}});function ht({sessionToken:t,sessionTokenUrl:s,sessionTokenOptions:r,customerId:n,customerEmail:a,customerName:i,organizationId:l,options:o,queryClient:c,children:u}){C.useEffect(()=>{console.log("%c🚀 BillingOS SDK v1.2.0 Initialized","color: #10b981; font-weight: bold; font-size: 16px;"),console.log("✨ Features: Real-time subscription updates, Customer data prefill, Iframe checkout")},[]);const{token:m,isLoading:x,error:p}=ut({token:t,tokenUrl:s,...r}),y=C.useMemo(()=>c||Bs(),[c]),f=C.useMemo(()=>m?new We(m,o):null,[m,o]),g=C.useMemo(()=>f?{client:f,customerId:n,customerEmail:a,customerName:i,organizationId:l}:null,[f,n,a,i,l]);return s&&x?null:s&&p?(console.error("Failed to fetch BillingOS session token:",p),null):!m||!f||!g?(console.error("BillingOS: No session token provided. Use sessionToken or sessionTokenUrl prop."),null):e.jsx(mt.Provider,{value:g,children:e.jsx(P.QueryClientProvider,{client:y,children:u})})}function D(){const t=C.useContext(mt);if(!t)throw new Error("useBillingOS must be used within a BillingOSProvider. Wrap your app with <BillingOSProvider> to use BillingOS hooks and components.");return t}const q={all:["subscriptions"],lists:()=>[...q.all,"list"],list:t=>[...q.lists(),t],details:()=>[...q.all,"detail"],detail:t=>[...q.details(),t],preview:(t,s)=>[...q.all,"preview",t,s]};function Os(t,s){const{client:r}=D();return P.useQuery({queryKey:q.detail(t),queryFn:()=>r.getSubscription(t),enabled:!!t,...s})}function qs(t,s){const{client:r}=D();return P.useQuery({queryKey:q.list(t),queryFn:()=>r.listSubscriptions(t),...s})}function zs(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({...t,mutationFn:n=>s.createSubscription(n),onSuccess:(n,a,i)=>{r.invalidateQueries({queryKey:q.lists()})}})}function $s(t,s){const{client:r}=D(),n=P.useQueryClient();return P.useMutation({...s,mutationFn:a=>r.updateSubscription(t,a),onSuccess:(a,i,l)=>{n.invalidateQueries({queryKey:q.detail(t)}),n.invalidateQueries({queryKey:q.lists()})}})}function Hs(t,s){const{client:r}=D(),n=P.useQueryClient();return P.useMutation({...s,mutationFn:({immediately:a=!1})=>r.cancelSubscription(t,a),onSuccess:(a,i,l)=>{n.invalidateQueries({queryKey:q.detail(t)}),n.invalidateQueries({queryKey:q.lists()})}})}function Qs(t,s){const{client:r}=D(),n=P.useQueryClient();return P.useMutation({...s,mutationFn:()=>r.reactivateSubscription(t),onSuccess:(a,i,l)=>{n.invalidateQueries({queryKey:q.detail(t)}),n.invalidateQueries({queryKey:q.lists()})}})}function Ks(t,s,r){const{client:n}=D();return P.useQuery({queryKey:q.preview(t,s),queryFn:()=>n.previewSubscription(t,s),enabled:!!t&&!!s,...r})}function xt(t,s){const{client:r}=D();return P.useQuery({queryKey:[...q.detail(t),"available-plans"],queryFn:()=>r.getAvailablePlans(t),enabled:!!t,...s})}function ft(t){const{client:s}=D();return P.useMutation({...t,mutationFn:({subscriptionId:r,input:n})=>s.previewPlanChange(r,n)})}function gt(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({...t,mutationFn:({subscriptionId:n,input:a})=>s.changePlan(n,a),onSuccess:(n,a,i)=>{r.invalidateQueries({queryKey:q.detail(a.subscriptionId)}),r.invalidateQueries({queryKey:q.lists()}),r.invalidateQueries({queryKey:[...q.detail(a.subscriptionId),"available-plans"]})}})}function h(...t){return _s.twMerge(Ts.clsx(t))}const pt=d.createContext(null);function Ue(){const t=d.useContext(pt);if(!t)throw new Error("Dialog components must be used within a Dialog provider");return t}function fe({open:t=!1,onOpenChange:s,children:r}){const[n,a]=d.useState(!1),i=t??n,l=s??a;return e.jsx(pt.Provider,{value:{open:i,onOpenChange:l},children:r})}const yt=d.forwardRef(({onClick:t,...s},r)=>{const{onOpenChange:n}=Ue();return e.jsx("button",{ref:r,type:"button",onClick:a=>{n(!0),t==null||t(a)},...s})});yt.displayName="DialogTrigger";function Ws({children:t}){const{open:s}=Ue();return s?e.jsx(e.Fragment,{children:t}):null}const Ve=d.forwardRef(({className:t,...s},r)=>{const{onOpenChange:n}=Ue();return e.jsx("div",{ref:r,onClick:()=>n(!1),className:h("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...s})});Ve.displayName="DialogOverlay";const he=d.forwardRef(({className:t,children:s,...r},n)=>{const{open:a,onOpenChange:i}=Ue();return d.useEffect(()=>{const l=o=>{o.key==="Escape"&&i(!1)};return a&&(document.addEventListener("keydown",l),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",l),document.body.style.overflow=""}},[a,i]),a?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx(Ve,{}),e.jsxs("div",{ref:n,onClick:l=>l.stopPropagation(),className:h("relative z-50 w-full max-w-lg gap-4 border bg-background p-6 shadow-lg duration-200 sm:rounded-lg",t),...r,children:[s,e.jsxs("button",{type:"button",onClick:()=>i(!1),className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"h-4 w-4",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}):null});he.displayName="DialogContent";const ge=({className:t,...s})=>e.jsx("div",{className:h("flex flex-col space-y-1.5 text-center sm:text-left",t),...s});ge.displayName="DialogHeader";const ve=({className:t,...s})=>e.jsx("div",{className:h("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...s});ve.displayName="DialogFooter";const pe=d.forwardRef(({className:t,...s},r)=>e.jsx("h2",{ref:r,className:h("text-lg font-semibold leading-none tracking-tight",t),...s}));pe.displayName="DialogTitle";const be=d.forwardRef(({className:t,...s},r)=>e.jsx("p",{ref:r,className:h("text-sm text-muted-foreground",t),...s}));be.displayName="DialogDescription";const jt=C.forwardRef(({src:t,height:s=600,className:r,onLoad:n,onError:a},i)=>e.jsx("iframe",{ref:i,src:t,className:h("w-full border-none",r),style:{height:typeof s=="number"?`${s}px`:s,minHeight:"400px",maxHeight:"80vh"},onLoad:n,onError:a,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox",allow:"payment",title:"Secure Checkout",loading:"lazy"}));jt.displayName="CheckoutIframe";function Vs({enabled:t,priceId:s,customer:r,couponCode:n,metadata:a,existingSubscriptionId:i}){const{client:l}=D(),[o,c]=C.useState(null),[u,m]=C.useState(null),[x,p]=C.useState(!1),[y,f]=C.useState(null),g=async()=>{if(!(!t||!s)){console.log("%c🔄 Creating checkout session...","color: #3b82f6; font-weight: 600;",{priceId:s,customer:r}),p(!0),f(null);try{const b=await l.checkout.createSession({priceId:s,customer:r,couponCode:n,metadata:a,existingSubscriptionId:i,mode:"embedded"});c(b.id),console.log("%c✨ Session created!","color: #10b981; font-weight: 600;",`ID: ${b.id}`);const j=`${process.env.NEXT_PUBLIC_BILLINGOS_APP_URL||"http://localhost:3000"}/embed/checkout/${b.id}`;m(j),console.log("%c📍 Iframe URL ready","color: #8b5cf6; font-weight: 600;",j)}catch(b){const w=b instanceof Error?b:new Error("Failed to create checkout session");f(w),console.error("[useCheckoutSession] Error creating session:",w)}finally{p(!1)}}};return C.useEffect(()=>{t&&!o&&g()},[t,s]),C.useEffect(()=>()=>{},[o]),{sessionId:o,sessionUrl:u,loading:x,error:y,refresh:async()=>{c(null),m(null),await g()}}}function Ys(){const t=[];return process.env.NEXT_PUBLIC_APP_URL&&t.push(process.env.NEXT_PUBLIC_APP_URL),t.push("https://app.billingos.com"),t.push("https://embed.billingos.com"),process.env.NODE_ENV==="development"&&(t.push("http://localhost:3000"),t.push("http://localhost:3001"),t.push("http://127.0.0.1:3000"),t.push("http://127.0.0.1:3001")),t}function Gs(t){return!!(Ys().includes(t)||t.endsWith(".vercel.app")&&t.includes("billingos")||t.endsWith(".stripe.com"))}function Xs({iframeRef:t,onMessage:s,targetOrigin:r=process.env.NEXT_PUBLIC_APP_URL||"http://localhost:3000",debug:n=!1}){var l;const a=!!((l=t.current)!=null&&l.contentWindow),i=C.useCallback(o=>{var c;(c=t.current)!=null&&c.contentWindow?(n&&console.log("[useIframeMessaging] Sending message:",o),t.current.contentWindow.postMessage(o,r)):console.warn("[useIframeMessaging] Cannot send message - iframe not ready")},[t,r,n]);return C.useEffect(()=>{const o=c=>{if(!Gs(c.origin)){n&&console.warn(`[useIframeMessaging] Invalid origin: ${c.origin}`);return}!c.data||typeof c.data!="object"||!c.data.type||!c.data.type.startsWith("CHECKOUT_")&&c.data.type!=="HEIGHT_CHANGED"&&c.data.type!=="PROCESSING"||(n&&console.log("[useIframeMessaging] Received message:",c.data),s(c.data))};return window.addEventListener("message",o),()=>{window.removeEventListener("message",o)}},[s,n]),{sendMessage:i,isConnected:a}}function Me({open:t,onOpenChange:s,priceId:r,customer:n,couponCode:a,collectBillingAddress:i,existingSubscriptionId:l,metadata:o,theme:c="light",locale:u="en",onSuccess:m,onError:x,onCancel:p,debug:y=!1}){const[f,g]=C.useState("loading"),[v,b]=C.useState(null),[w,j]=C.useState(600),S=C.useRef(null);C.useEffect(()=>{console.log("%c🚀 BillingOS SDK v1.2.0 loaded with Iframe Checkout","background: linear-gradient(to right, #667eea, #764ba2); color: white; padding: 4px 8px; border-radius: 4px; font-weight: bold;"),console.log("%c📦 Using iframe for PCI compliance and security","color: #10b981; font-weight: 600;"),console.log("%c✨ Customer prefill support enabled","color: #8b5cf6; font-weight: 600;"),y&&console.log("[CheckoutModal] Debug mode enabled")},[]);const{sessionId:_,sessionUrl:k,loading:$,error:Q}=Vs({enabled:t,priceId:r,customer:n,couponCode:a,metadata:o,existingSubscriptionId:l}),K=C.useCallback(W=>{var L,O,Z,ae;switch(console.log("[CheckoutModal] Received message from iframe:",W.type,W),W.type){case"CHECKOUT_READY":console.log("[CheckoutModal] Checkout is ready"),g("ready");break;case"CHECKOUT_SUCCESS":console.log("[CheckoutModal] Payment SUCCESS! Subscription:",(L=W.payload)==null?void 0:L.subscription),g("success"),(O=W.payload)!=null&&O.subscription?(console.log("[CheckoutModal] Calling onSuccess with subscription data"),m(W.payload.subscription)):(console.log("[CheckoutModal] No subscription data, calling onSuccess with undefined"),m(void 0)),s(!1);break;case"CHECKOUT_ERROR":g("error");const ye=((Z=W.payload)==null?void 0:Z.error)||"An error occurred",N=new Error(ye);b(N),x==null||x(N);break;case"CHECKOUT_CLOSE":p==null||p(),s(!1);break;case"HEIGHT_CHANGED":(ae=W.payload)!=null&&ae.height&&j(W.payload.height);break;case"PROCESSING":g("processing");break}},[y,m,x,p,s]),{sendMessage:X}=Xs({iframeRef:S,onMessage:K,debug:y});C.useEffect(()=>{_&&f==="ready"&&X({type:"INIT_CHECKOUT",sessionId:_,config:{theme:c,locale:u,collectBillingAddress:i}})},[_,f,c,u,i,X]),C.useEffect(()=>{t||(g("loading"),b(null),j(600))},[t]),C.useEffect(()=>{Q&&(g("error"),b(Q),x==null||x(Q))},[Q,x]);const z=$||f==="loading",B=f==="error"&&v;return e.jsx(fe,{open:t,onOpenChange:s,children:e.jsxs(he,{className:h("sm:max-w-[500px] p-0 overflow-hidden","max-h-[90vh] relative"),children:[e.jsxs("div",{className:"absolute top-2 right-2 z-20 flex items-center gap-1 bg-gradient-to-r from-blue-600 to-purple-600 text-white text-xs font-medium px-2 py-1 rounded-full shadow-lg",children:[e.jsx("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M2.166 4.999A11.954 11.954 0 0010 1.944 11.954 11.954 0 0017.834 5c.11.65.166 1.32.166 2.001 0 5.225-3.34 9.67-8 11.317C5.34 16.67 2 12.225 2 7c0-.682.057-1.35.166-2.001zm11.541 3.708a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),e.jsx("span",{children:"Secure Iframe"})]}),B?e.jsxs("div",{className:"p-8 text-center",children:[e.jsx("div",{className:"text-red-600 mb-2",children:e.jsx("svg",{className:"w-12 h-12 mx-auto",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Payment Error"}),e.jsx("p",{className:"text-gray-600",children:v.message}),e.jsx("button",{onClick:()=>s(!1),className:"mt-4 px-4 py-2 bg-gray-200 rounded-md hover:bg-gray-300",children:"Close"})]}):e.jsxs(e.Fragment,{children:[z&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-white z-10",children:e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"}),e.jsx("p",{className:"mt-4 text-gray-600 font-medium",children:"Loading secure checkout..."}),e.jsx("p",{className:"mt-2 text-xs text-gray-500",children:"Iframe-based • PCI Compliant"})]})}),k&&e.jsx(jt,{ref:S,src:k,height:w,className:h("transition-opacity duration-300",z?"opacity-0":"opacity-100"),onLoad:()=>{console.log("%c✅ Iframe loaded successfully","color: #10b981; font-weight: 600;",`
3
+ URL: ${k}`),y&&console.log("[CheckoutModal] Full iframe details:",{sessionUrl:k,sessionId:_,state:f,height:w})}}),f==="processing"&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-white/80 z-10",children:e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-green-600"}),e.jsx("p",{className:"mt-4 text-gray-600",children:"Processing payment..."})]})})]}),y&&e.jsxs("div",{className:"absolute bottom-0 left-0 right-0 bg-black/80 text-white p-2 text-xs",children:[e.jsxs("div",{children:["State: ",f]}),e.jsxs("div",{children:["Session: ",_||"Creating..."]}),v&&e.jsxs("div",{children:["Error: ",v.message]})]})]})})}class vt{constructor(s){se(this,"client");se(this,"container");se(this,"root");this.client=s}async open(s){return new Promise(r=>{this.container||(this.container=document.createElement("div"),this.container.id="billingos-checkout-container",this.container.style.position="fixed",this.container.style.zIndex="999999",document.body.appendChild(this.container));const n={open:!0,onOpenChange:a=>{a||(this.close(),s.onCancel&&s.onCancel(),r({success:!1}))},priceId:s.priceId,customer:s.customer,couponCode:s.couponCode,collectBillingAddress:s.collectBillingAddress,currency:s.currency,existingSubscriptionId:s.existingSubscriptionId,metadata:s.metadata,theme:s.theme,locale:s.locale,onSuccess:a=>{s.onSuccess&&s.onSuccess(a),r({success:!0,subscription:a}),this.close()},onError:a=>{s.onError&&s.onError(a),r({success:!1,error:a})},onCancel:s.onCancel,debug:s.debug};if(this.root||(this.root=Ds.createRoot(this.container)),this.client)this.root.render(C.createElement(Me,n));else if(s.sessionToken)this.root.render(C.createElement(ht,{sessionToken:s.sessionToken,options:{baseUrl:s.apiUrl},children:C.createElement(Me,n)}));else{const a=new Error("No session token or BillingOS client provided");s.onError&&s.onError(a),r({success:!1,error:a}),this.close()}})}close(){this.root&&(this.root.unmount(),this.root=void 0),this.container&&(this.container.remove(),this.container=void 0)}}let $e=null;function Se(t){return $e||($e=new vt(t)),$e}async function Js(t){return Se().open(t)}function Zs(){const{client:t}=D(),[s,r]=C.useState(!1),[n,a]=C.useState(null),i=C.useCallback(async o=>{r(!0),a(null);try{const u=await Se(t).open(o);return!u.success&&u.error&&a(u.error),u}catch(c){const u=c instanceof Error?c:new Error("Failed to open checkout");return a(u),{success:!1,error:u}}finally{r(!1)}},[t]),l=C.useCallback(()=>{Se(t).close()},[t]);return{openCheckout:i,closeCheckout:l,isLoading:s,error:n}}const me={all:["entitlements"],lists:()=>[...me.all,"list"],list:t=>[...me.lists(),t],checks:()=>[...me.all,"check"],check:(t,s)=>[...me.checks(),t,s],usage:(t,s)=>[...me.all,"usage",t,s]};function bt(t,s,r){const{client:n}=D();return P.useQuery({queryKey:me.check(t,s),queryFn:()=>n.checkEntitlement({customer_id:t,feature_key:s}),enabled:!!t&&!!s,staleTime:1e3*60,...r})}function er(t,s,r){const{data:n}=bt(t,s,r);return(n==null?void 0:n.has_access)||!1}function tr(t,s){const{client:r}=D();return P.useQuery({queryKey:me.list(t),queryFn:()=>r.listEntitlements(t),enabled:!!t,...s})}function sr(t,s,r){const{client:n}=D();return P.useQuery({queryKey:me.usage(t,s),queryFn:()=>n.getUsageMetrics(t,s),enabled:!!t&&!!s,...r})}function rr(t,s,r=80,n){const{data:a}=sr(t,s,n);return!a||!a.limit?!1:a.current_usage/a.limit*100>=r}function wt(t,s){const{client:r}=D();return P.useQuery({queryKey:["billingos","features",t],queryFn:async()=>await r.get(`/v1/features/check?feature_key=${t}`),refetchInterval:s==null?void 0:s.refetchInterval,enabled:(s==null?void 0:s.enabled)!==!1})}function nr(){const{client:t}=D(),s=P.useQueryClient();return P.useMutation({mutationFn:async({featureKey:r,quantity:n,metadata:a})=>await t.post("/v1/features/track-usage",{feature_key:r,quantity:n,metadata:a}),onSuccess:(r,n)=>{s.invalidateQueries({queryKey:["billingos","features",n.featureKey]}),s.invalidateQueries({queryKey:["billingos","usage-metrics"]})}})}function ar(){const{client:t}=D();return P.useQuery({queryKey:["billingos","entitlements"],queryFn:async()=>await t.get("/v1/features/entitlements")})}function Ye(t){const{client:s}=D();return P.useQuery({queryKey:["billingos","usage-metrics",t],queryFn:async()=>{const r=t?`/v1/features/usage-metrics?feature_key=${t}`:"/v1/features/usage-metrics";return await s.get(r)},refetchInterval:3e4})}function Nt(t,s){var n,a,i,l,o,c,u,m;const r=wt(t);return r.data&&!r.data.has_access&&(r.data.usage&&r.data.limit&&r.data.usage>=r.data.limit?(n=s==null?void 0:s.onQuotaExceeded)==null||n.call(s,r.data.usage,r.data.limit):(a=s==null?void 0:s.onAccessDenied)==null||a.call(s)),{...r,hasAccess:((i=r.data)==null?void 0:i.has_access)||!1,isQuotaExceeded:(l=r.data)!=null&&l.usage&&r.data.limit?r.data.usage>=r.data.limit:!1,usage:((o=r.data)==null?void 0:o.usage)||0,limit:((c=r.data)==null?void 0:c.limit)||0,remaining:(u=r.data)!=null&&u.limit&&((m=r.data)!=null&&m.usage)?Math.max(0,r.data.limit-r.data.usage):0}}function Ct(){const{client:t}=D();return P.useQuery({queryKey:["billingos","products"],queryFn:async()=>await t.get("/v1/products")})}const ir=Pe.cva("relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive",warning:"border-yellow-500/50 bg-yellow-50 text-yellow-900 dark:bg-yellow-900/10 dark:text-yellow-500 [&>svg]:text-yellow-500",success:"border-green-500/50 bg-green-50 text-green-900 dark:bg-green-900/10 dark:text-green-500 [&>svg]:text-green-500"}},defaultVariants:{variant:"default"}}),Y=d.forwardRef(({className:t,variant:s,...r},n)=>e.jsx("div",{ref:n,role:"alert",className:h(ir({variant:s}),t),...r}));Y.displayName="Alert";const Ae=d.forwardRef(({className:t,...s},r)=>e.jsx("h5",{ref:r,className:h("mb-1 font-medium leading-none tracking-tight",t),...s}));Ae.displayName="AlertTitle";const G=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,className:h("text-sm [&_p]:leading-relaxed",t),...s}));G.displayName="AlertDescription";const St=Pe.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground",success:"border-transparent bg-green-500 text-white hover:bg-green-500/80",warning:"border-transparent bg-yellow-500 text-white hover:bg-yellow-500/80"}},defaultVariants:{variant:"default"}});function A({className:t,variant:s,...r}){return e.jsx("div",{className:h(St({variant:s}),t),...r})}const kt=Pe.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),T=d.forwardRef(({className:t,variant:s,size:r,asChild:n=!1,...a},i)=>e.jsx("button",{className:h(kt({variant:s,size:r,className:t})),ref:i,...a}));T.displayName="Button";const F=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,className:h("rounded-lg border bg-card text-card-foreground shadow-sm",t),...s}));F.displayName="Card";const J=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,className:h("flex flex-col space-y-1.5 p-6",t),...s}));J.displayName="CardHeader";const de=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,className:h("text-2xl font-semibold leading-none tracking-tight",t),...s}));de.displayName="CardTitle";const Be=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,className:h("text-sm text-muted-foreground",t),...s}));Be.displayName="CardDescription";const I=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,className:h("p-6 pt-0",t),...s}));I.displayName="CardContent";const Ge=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,className:h("flex items-center p-6 pt-0",t),...s}));Ge.displayName="CardFooter";const Oe=d.forwardRef(({className:t,onCheckedChange:s,onChange:r,...n},a)=>{const i=l=>{r==null||r(l),s==null||s(l.target.checked)};return e.jsx("input",{type:"checkbox",ref:a,onChange:i,className:h("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 checked:bg-primary checked:text-primary-foreground",t),...n})});Oe.displayName="Checkbox";const Pt=d.createContext(null);function qe(){const t=d.useContext(Pt);if(!t)throw new Error("Drawer components must be used within a Drawer provider");return t}function Et({open:t=!1,onOpenChange:s,children:r}){const[n,a]=d.useState(!1),i=t??n,l=s??a;return d.useEffect(()=>{console.log("[Drawer] State:",{open:t,internalOpen:n,isOpen:i})},[t,n,i]),e.jsx(Pt.Provider,{value:{open:i,onOpenChange:l},children:r})}const Dt=d.forwardRef(({onClick:t,...s},r)=>{const{onOpenChange:n}=qe();return e.jsx("button",{ref:r,type:"button",onClick:a=>{n(!0),t==null||t(a)},...s})});Dt.displayName="DrawerTrigger";const Tt=d.forwardRef(({onClick:t,...s},r)=>{const{onOpenChange:n}=qe();return e.jsx("button",{ref:r,type:"button",onClick:a=>{n(!1),t==null||t(a)},...s})});Tt.displayName="DrawerClose";const lr=d.forwardRef(({className:t,...s},r)=>{const{onOpenChange:n}=qe();return e.jsx("div",{ref:r,onClick:()=>n(!1),className:h("fixed inset-0 z-50 bg-black/80 transition-opacity duration-300",t),...s})});lr.displayName="DrawerOverlay";const Xe=d.forwardRef(({className:t,children:s,preventClose:r=!1,onCloseAttempt:n,...a},i)=>{const{open:l,onOpenChange:o}=qe(),[c,u]=d.useState(!1),[m,x]=d.useState(0),p=d.useRef(null),y=d.useRef(0);d.useEffect(()=>{const w=j=>{j.key==="Escape"&&(r?n==null||n():o(!1))};return l&&(document.addEventListener("keydown",w),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",w),document.body.style.overflow=""}},[l,o,r,n]);const f=w=>{if(r)return;u(!0);const j="touches"in w?w.touches[0].clientY:w.clientY;y.current=j},g=w=>{if(!c||r)return;const S=("touches"in w?w.touches[0].clientY:w.clientY)-y.current;S>0&&x(S)},v=()=>{c&&(u(!1),m>80&&!r&&o(!1),x(0))},b=()=>{r?n==null||n():o(!1)};return console.log("[DrawerContent] Rendering, open:",l,"preventClose:",r),l?e.jsxs("div",{className:"fixed inset-0 z-50",children:[e.jsx("div",{className:"fixed inset-0 bg-black/80 transition-opacity duration-300",onClick:b}),e.jsxs("div",{ref:i,className:h("fixed z-50 bg-background shadow-lg transition-transform duration-300 ease-out","inset-x-0 bottom-0 rounded-t-[10px] border-t","md:inset-auto md:left-1/2 md:top-1/2 md:-translate-x-1/2 md:-translate-y-1/2","md:rounded-lg md:border md:max-w-[500px] md:w-full md:max-h-[90vh]",t),style:{transform:c?`translateY(${m}px)`:void 0},onClick:w=>w.stopPropagation(),onTouchStart:f,onTouchMove:g,onTouchEnd:v,onMouseDown:f,onMouseMove:g,onMouseUp:v,onMouseLeave:v,...a,children:[e.jsx("div",{className:"md:hidden flex justify-center pt-4 pb-2",children:e.jsx("div",{className:"w-12 h-1.5 rounded-full bg-muted-foreground/30"})}),e.jsxs("button",{type:"button",onClick:()=>{r?n==null||n():o(!1)},className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"h-4 w-4",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]}),e.jsx("span",{className:"sr-only",children:"Close"})]}),e.jsx("div",{ref:p,className:"px-6 pb-6 pt-2 md:pt-6 overflow-y-auto max-h-[80vh] md:max-h-[calc(90vh-2rem)]",children:s})]})]}):(console.log("[DrawerContent] Not rendering because open is false"),null)});Xe.displayName="DrawerContent";const Je=({className:t,...s})=>e.jsx("div",{className:h("flex flex-col space-y-1.5 text-center sm:text-left",t),...s});Je.displayName="DrawerHeader";const _t=({className:t,...s})=>e.jsx("div",{className:h("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...s});_t.displayName="DrawerFooter";const Ze=d.forwardRef(({className:t,...s},r)=>e.jsx("h2",{ref:r,className:h("text-lg font-semibold leading-none tracking-tight",t),...s}));Ze.displayName="DrawerTitle";const et=d.forwardRef(({className:t,...s},r)=>e.jsx("p",{ref:r,className:h("text-sm text-muted-foreground",t),...s}));et.displayName="DrawerDescription";const te=d.forwardRef(({className:t,type:s,...r},n)=>e.jsx("input",{type:s,className:h("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),ref:n,...r}));te.displayName="Input";const or=Pe.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),V=d.forwardRef(({className:t,...s},r)=>e.jsx("label",{ref:r,className:h(or(),t),...s}));V.displayName="Label";const tt=d.forwardRef(({className:t,value:s=0,max:r=100,indicatorClassName:n,...a},i)=>{const l=Math.min(Math.max(s/r*100,0),100);return e.jsx("div",{ref:i,role:"progressbar","aria-valuemin":0,"aria-valuemax":r,"aria-valuenow":s,className:h("relative h-4 w-full overflow-hidden rounded-full bg-secondary",t),...a,children:e.jsx("div",{className:h("h-full bg-primary transition-all",n),style:{width:`${l}%`}})})});tt.displayName="Progress";const Lt=d.createContext(null);function cr(){const t=d.useContext(Lt);if(!t)throw new Error("RadioGroup components must be used within a RadioGroup provider");return t}const st=d.forwardRef(({className:t,value:s,defaultValue:r,onValueChange:n,name:a="radio-group",children:i,...l},o)=>{const[c,u]=d.useState(r??""),m=s??c,x=n??u;return e.jsx(Lt.Provider,{value:{value:m,onValueChange:x,name:a},children:e.jsx("div",{ref:o,role:"radiogroup",className:h("grid gap-2",t),...l,children:i})})});st.displayName="RadioGroup";const Fe=d.forwardRef(({className:t,value:s,...r},n)=>{const{value:a,onValueChange:i,name:l}=cr(),o=a===s;return e.jsx("input",{ref:n,type:"radio",name:l,value:s,checked:o,onChange:()=>i(s),className:h("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t),...r})});Fe.displayName="RadioGroupItem";const Rt=d.forwardRef(({className:t,children:s,orientation:r="vertical",alwaysShowScrollbar:n=!1,...a},i)=>{const[l,o]=d.useState(!1),[c,u]=d.useState(0),[m,x]=d.useState(0),p=d.useRef(null),y=d.useCallback(()=>{const g=p.current;if(!g)return;const{scrollTop:v,scrollHeight:b,clientHeight:w}=g,j=b>w;if(!j&&!n){u(0),x(0);return}const S=w/b,_=Math.max(S*w,30),k=b-w,$=k>0?v/k:0,Q=w-_,K=$*Q;u(j?_:0),x(K)},[n]);d.useEffect(()=>{const g=p.current;if(!g)return;y();const v=new ResizeObserver(y);return v.observe(g),g.addEventListener("scroll",y),()=>{v.disconnect(),g.removeEventListener("scroll",y)}},[y]);const f=d.useCallback(g=>{var X;g.preventDefault();const v=p.current;if(!v)return;const{scrollHeight:b,clientHeight:w}=v,j=b-w;if(j<=0)return;const S=(X=g.currentTarget.parentElement)==null?void 0:X.parentElement;if(!S)return;const _=S.getBoundingClientRect(),k=g.clientY,$=v.scrollTop,Q=z=>{const B=z.clientY-k,W=_.height,O=B/W*j,Z=Math.max(0,Math.min(j,$+O));v.scrollTop=Z},K=()=>{document.removeEventListener("mousemove",Q),document.removeEventListener("mouseup",K),document.body.style.userSelect="",document.body.style.cursor=""};document.body.style.userSelect="none",document.body.style.cursor="grabbing",document.addEventListener("mousemove",Q),document.addEventListener("mouseup",K)},[]);return e.jsxs("div",{ref:i,className:h("relative overflow-hidden",t),onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),...a,children:[e.jsx("div",{ref:p,className:h("h-full w-full rounded-[inherit]",r==="vertical"&&"overflow-y-auto overflow-x-hidden",r==="horizontal"&&"overflow-x-auto overflow-y-hidden",r==="both"&&"overflow-auto","[&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]"),children:s}),(r==="vertical"||r==="both")&&e.jsx("div",{className:h("absolute top-0 right-0 w-2.5 h-full transition-opacity duration-150",n||l?"opacity-100":"opacity-0"),children:e.jsxs("div",{className:"relative h-full w-full",children:[e.jsx("div",{className:"absolute inset-0 rounded-full bg-gray-100 hover:bg-gray-200"}),c>0&&e.jsx("div",{className:"absolute right-0.5 w-1.5 rounded-full bg-gray-400 hover:bg-gray-600 transition-colors cursor-pointer",style:{height:`${c}px`,top:`${m}px`},onMouseDown:f})]})})]})});Rt.displayName="ScrollArea";const Mt=d.forwardRef(({className:t,orientation:s="vertical",...r},n)=>e.jsx("div",{ref:n,className:h("flex touch-none select-none transition-colors",s==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",s==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",t),...r}));Mt.displayName="ScrollBar";const rt=d.forwardRef(({className:t,children:s,onValueChange:r,onChange:n,...a},i)=>{const l=o=>{n==null||n(o),r==null||r(o.target.value)};return e.jsx("select",{ref:i,onChange:l,className:h("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t),...a,children:s})});rt.displayName="Select";const nt=d.forwardRef(({className:t,...s},r)=>e.jsx("option",{ref:r,className:h("",t),...s}));nt.displayName="SelectOption";const ke=d.forwardRef(({className:t,orientation:s="horizontal",decorative:r=!0,...n},a)=>e.jsx("div",{ref:a,role:r?"none":"separator","aria-orientation":r?void 0:s,className:h("shrink-0 bg-border",s==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",t),...n}));ke.displayName="Separator";const Ft=d.createContext(null);function ze(){const t=d.useContext(Ft);if(!t)throw new Error("Sheet components must be used within a Sheet provider");return t}function It({open:t=!1,onOpenChange:s,children:r}){const[n,a]=d.useState(!1),i=t??n,l=s??a;return e.jsx(Ft.Provider,{value:{open:i,onOpenChange:l},children:r})}const Ut=d.forwardRef(({onClick:t,...s},r)=>{const{onOpenChange:n}=ze();return e.jsx("button",{ref:r,type:"button",onClick:a=>{n(!0),t==null||t(a)},...s})});Ut.displayName="SheetTrigger";const At=d.forwardRef(({onClick:t,...s},r)=>{const{onOpenChange:n}=ze();return e.jsx("button",{ref:r,type:"button",onClick:a=>{n(!1),t==null||t(a)},...s})});At.displayName="SheetClose";const Bt=d.forwardRef(({className:t,...s},r)=>{const{onOpenChange:n}=ze();return e.jsx("div",{ref:r,onClick:()=>n(!1),className:h("fixed inset-0 z-50 bg-black/80 transition-opacity",t),...s})});Bt.displayName="SheetOverlay";const dr=Pe.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition-transform duration-300 ease-in-out",{variants:{side:{top:"inset-x-0 top-0 border-b",bottom:"inset-x-0 bottom-0 border-t",left:"inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm"}},defaultVariants:{side:"right"}}),at=d.forwardRef(({side:t="right",className:s,children:r,...n},a)=>{const{open:i,onOpenChange:l}=ze();if(d.useEffect(()=>{const c=u=>{u.key==="Escape"&&l(!1)};return i&&(document.addEventListener("keydown",c),document.body.style.overflow="hidden"),()=>{document.removeEventListener("keydown",c),document.body.style.overflow=""}},[i,l]),!i)return null;const o=()=>{switch(t){case"top":return i?"translateY(0)":"translateY(-100%)";case"bottom":return i?"translateY(0)":"translateY(100%)";case"left":return i?"translateX(0)":"translateX(-100%)";case"right":return i?"translateX(0)":"translateX(100%)";default:return"translateX(0)"}};return e.jsxs("div",{className:"fixed inset-0 z-50",children:[e.jsx(Bt,{}),e.jsxs("div",{ref:a,style:{transform:o()},className:h(dr({side:t}),s),onClick:c=>c.stopPropagation(),...n,children:[r,e.jsxs("button",{type:"button",onClick:()=>l(!1),className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"h-4 w-4",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});at.displayName="SheetContent";const it=({className:t,...s})=>e.jsx("div",{className:h("flex flex-col space-y-2 text-center sm:text-left",t),...s});it.displayName="SheetHeader";const Ot=({className:t,...s})=>e.jsx("div",{className:h("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...s});Ot.displayName="SheetFooter";const lt=d.forwardRef(({className:t,...s},r)=>e.jsx("h2",{ref:r,className:h("text-lg font-semibold text-foreground",t),...s}));lt.displayName="SheetTitle";const qt=d.forwardRef(({className:t,...s},r)=>e.jsx("p",{ref:r,className:h("text-sm text-muted-foreground",t),...s}));qt.displayName="SheetDescription";function E({className:t,...s}){return e.jsx("div",{className:h("animate-pulse rounded-md bg-muted",t),...s})}const zt=d.createContext(null);function $t(){const t=d.useContext(zt);if(!t)throw new Error("Tabs components must be used within a Tabs provider");return t}const Ht=d.forwardRef(({className:t,value:s,defaultValue:r,onValueChange:n,children:a,...i},l)=>{const[o,c]=d.useState(r??""),u=s??o,m=n??c;return e.jsx(zt.Provider,{value:{value:u,onValueChange:m},children:e.jsx("div",{ref:l,className:h("",t),...i,children:a})})});Ht.displayName="Tabs";const Qt=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{ref:r,role:"tablist",className:h("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",t),...s}));Qt.displayName="TabsList";const Kt=d.forwardRef(({className:t,value:s,...r},n)=>{const{value:a,onValueChange:i}=$t(),l=a===s;return e.jsx("button",{ref:n,role:"tab",type:"button","aria-selected":l,"data-state":l?"active":"inactive",onClick:()=>i(s),className:h("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",l?"bg-background text-foreground shadow-sm":"hover:bg-background/50 hover:text-foreground",t),...r})});Kt.displayName="TabsTrigger";const Wt=d.forwardRef(({className:t,value:s,children:r,...n},a)=>{const{value:i}=$t(),l=i===s;return l?e.jsx("div",{ref:a,role:"tabpanel","data-state":l?"active":"inactive",className:h("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",t),...n,children:r}):null});Wt.displayName="TabsContent";const ot=d.forwardRef(({className:t,...s},r)=>e.jsx("textarea",{className:h("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),ref:r,...s}));ot.displayName="Textarea";const Vt=C.forwardRef(({src:t,height:s=600,className:r,onLoad:n},a)=>e.jsx("iframe",{ref:a,src:t,className:h("w-full border-0",r),style:{height:`${s}px`},allow:"payment",sandbox:"allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox",onLoad:n,title:"Customer Portal"}));Vt.displayName="PortalIframe";function ur({enabled:t,customerId:s,metadata:r}){const{client:n}=D(),[a,i]=C.useState(null),[l,o]=C.useState(null),[c,u]=C.useState(!1),[m,x]=C.useState(null),p=async()=>{if(t){console.log("%c🔄 Creating portal session...","color: #3b82f6; font-weight: 600;"),u(!0),x(null);try{const f=await n.portal.createSession({customerId:s,metadata:r});i(f.id),console.log("%c✨ Portal session created!","color: #10b981; font-weight: 600;",`ID: ${f.id}`);const v=`${process.env.NEXT_PUBLIC_BILLINGOS_APP_URL||"http://localhost:3000"}/embed/portal/${f.id}`;o(v),console.log("%c📍 Iframe URL ready","color: #8b5cf6; font-weight: 600;",v)}catch(f){const g=f instanceof Error?f:new Error("Failed to create portal session");x(g),console.error("[usePortalSession] Error creating session:",g)}finally{u(!1)}}};return C.useEffect(()=>{t&&!a&&p()},[t]),C.useEffect(()=>()=>{},[a]),{sessionId:a,sessionUrl:l,loading:c,error:m,refresh:async()=>{i(null),o(null),await p()}}}function mr({iframeRef:t,onMessage:s,debug:r=!1}){const n=C.useCallback(a=>{const i=t.current;if(!i||!i.contentWindow){console.warn("[usePortalMessaging] Iframe not ready");return}r&&console.log("[usePortalMessaging] 📤 Sending to iframe:",a);const l=i.src,o=new URL(l).origin;i.contentWindow.postMessage(a,o)},[t,r]);return C.useEffect(()=>{const a=i=>{if(!i.data||typeof i.data!="object"||!i.data.type)return;const l=t.current;if(!l)return;const o=l.src;if(!o)return;const c=new URL(o).origin;if(i.origin!==c&&process.env.NODE_ENV!=="development"){console.warn(`[usePortalMessaging] Message from unexpected origin: ${i.origin}`);return}const u=i.data;r&&console.log("[usePortalMessaging] 📥 Received from iframe:",u),s(u)};return window.addEventListener("message",a),()=>{window.removeEventListener("message",a)}},[t,s,r]),{sendMessage:n}}const Yt=d.forwardRef(({className:t,...s},r)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:r,className:h("w-full caption-bottom text-sm",t),...s})}));Yt.displayName="Table";const Gt=d.forwardRef(({className:t,...s},r)=>e.jsx("thead",{ref:r,className:h("[&_tr]:border-b",t),...s}));Gt.displayName="TableHeader";const Xt=d.forwardRef(({className:t,...s},r)=>e.jsx("tbody",{ref:r,className:h("[&_tr:last-child]:border-0",t),...s}));Xt.displayName="TableBody";const hr=d.forwardRef(({className:t,...s},r)=>e.jsx("tfoot",{ref:r,className:h("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",t),...s}));hr.displayName="TableFooter";const Le=d.forwardRef(({className:t,...s},r)=>e.jsx("tr",{ref:r,className:h("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",t),...s}));Le.displayName="TableRow";const Ke=d.forwardRef(({className:t,...s},r)=>e.jsx("th",{ref:r,className:h("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",t),...s}));Ke.displayName="TableHead";const Ne=d.forwardRef(({className:t,...s},r)=>e.jsx("td",{ref:r,className:h("p-4 align-middle [&:has([role=checkbox])]:pr-0",t),...s}));Ne.displayName="TableCell";const xr=d.forwardRef(({className:t,...s},r)=>e.jsx("caption",{ref:r,className:h("mt-4 text-sm text-muted-foreground",t),...s}));xr.displayName="TableCaption";function Jt(t={}){const{client:s}=D(),{planIds:r,enabled:n=!0}=t;return P.useQuery({queryKey:["products",r],queryFn:async()=>s.getProducts(r),enabled:n,staleTime:300*1e3,gcTime:600*1e3})}class fr extends d.Component{constructor(r){super(r);se(this,"reset",()=>{this.setState({hasError:!1,error:null})});this.state={hasError:!1,error:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,n){var a,i;console.error("[ErrorBoundary] Caught error:",r),console.error("[ErrorBoundary] Error info:",n),(i=(a=this.props).onError)==null||i.call(a,r,n)}render(){var r;return this.state.hasError?this.props.fallback?this.props.fallback(this.state.error,this.reset):e.jsxs("div",{style:{padding:"20px",border:"1px solid #ef4444",borderRadius:"8px",backgroundColor:"#fee2e2",color:"#991b1b",fontFamily:"system-ui, -apple-system, sans-serif"},children:[e.jsx("h3",{style:{margin:"0 0 10px 0",fontSize:"16px",fontWeight:"bold"},children:"Payment Error"}),e.jsx("p",{style:{margin:"0 0 10px 0",fontSize:"14px"},children:((r=this.state.error)==null?void 0:r.message)||"An unexpected error occurred while loading the payment form."}),e.jsx("button",{onClick:this.reset,style:{padding:"8px 16px",border:"none",borderRadius:"6px",backgroundColor:"#ef4444",color:"white",fontSize:"14px",cursor:"pointer",fontWeight:"500"},children:"Try Again"})]}):this.props.children}}function Zt(t,s){const{client:r}=D();return P.useQuery({queryKey:["checkout",t==null?void 0:t.priceId,t==null?void 0:t.existingSubscriptionId],queryFn:async()=>{if(!t)throw new Error("Checkout input is required");return r.createCheckout(t)},enabled:(s==null?void 0:s.enabled)!==!1&&!!t,staleTime:0,gcTime:0})}function gr(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({mutationFn:async({clientSecret:n,paymentMethodId:a})=>s.confirmCheckout(n,a),onSuccess:n=>{var a;r.invalidateQueries({queryKey:["portal"]}),r.invalidateQueries({queryKey:["subscriptions"]}),(a=t==null?void 0:t.onSuccess)==null||a.call(t,n)},onError:n=>{var a;(a=t==null?void 0:t.onError)==null||a.call(t,n)}})}function pr({checkoutSession:t,onSuccess:s,onError:r,isProcessing:n,setIsProcessing:a}){var b;const{client:i}=D(),l=ce.useStripe(),o=ce.useElements(),[c,u]=d.useState(null),[m,x]=d.useState(!1),p=(w,j)=>new Intl.NumberFormat("en-US",{style:"currency",currency:j.toUpperCase()}).format(w/100),y=((b=t.proration)==null?void 0:b.total)??t.amount,f=p(y,t.currency),g=async w=>{if(w.preventDefault(),!(!l||!o)){a(!0),u(null);try{const{error:j,paymentIntent:S}=await l.confirmPayment({elements:o,confirmParams:{return_url:`${window.location.origin}/billing/success`},redirect:"if_required"});if(j){u(j.message||"Payment failed"),r==null||r(j.message||"Payment failed"),a(!1);return}if((S==null?void 0:S.status)==="succeeded"&&S.payment_method)try{const _=await i.confirmCheckout(t.clientSecret,S.payment_method);if(_.success)s(_.subscriptionId);else throw new Error(_.message||"Failed to create subscription")}catch(_){const k=_ instanceof Error?_.message:"Failed to complete checkout";u(k),r==null||r(k),a(!1);return}}catch(j){const S=j instanceof Error?j.message:"Payment failed";u(S),r==null||r(S)}finally{a(!1)}}},v=async w=>{if(!(!l||!o)){a(!0),u(null);try{const{error:j}=await l.confirmPayment({elements:o,clientSecret:t.clientSecret,confirmParams:{return_url:`${window.location.origin}/billing/success`},redirect:"if_required"});if(j){u(j.message||"Payment failed"),r==null||r(j.message||"Payment failed"),a(!1);return}s(t.id)}catch(j){const S=j instanceof Error?j.message:"Payment failed";u(S),r==null||r(S)}finally{a(!1)}}};return e.jsxs("form",{onSubmit:g,className:"space-y-6",children:[e.jsx("div",{className:h(!m&&"hidden"),children:e.jsx(ce.ExpressCheckoutElement,{options:{wallets:{applePay:"auto",googlePay:"auto"}},onConfirm:v,onReady:()=>x(!0)})}),m&&e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx(ke,{className:"w-full"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"or pay with card"})})]}),e.jsx("div",{className:"space-y-4",children:e.jsx(ce.PaymentElement,{options:{layout:"tabs"}})}),c&&e.jsx(Y,{variant:"destructive",children:e.jsx(G,{children:c})}),e.jsx(T,{type:"submit",className:"w-full",size:"lg",disabled:!l||n,children:n?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsxs("svg",{className:"animate-spin h-4 w-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Processing..."]}):t.proration?`Upgrade Now - ${f}`:`Subscribe - ${f}`}),e.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),e.jsx("span",{children:"Secured by Stripe • Cancel anytime"})]})]})}function yr({checkoutSession:t,onSuccess:s,isProcessing:r,setIsProcessing:n}){var v;const[a,i]=d.useState(""),[l,o]=d.useState(""),[c,u]=d.useState(""),m=(b,w)=>new Intl.NumberFormat("en-US",{style:"currency",currency:w.toUpperCase()}).format(b/100),x=((v=t.proration)==null?void 0:v.total)??t.amount,p=m(x,t.currency),y=b=>{const j=b.replace(/\D/g,"").match(/.{1,4}/g);return j?j.join(" ").substring(0,19):""},f=b=>{const w=b.replace(/\D/g,"");return w.length>=2?`${w.slice(0,2)}/${w.slice(2,4)}`:w},g=async b=>{b.preventDefault(),n(!0),await new Promise(w=>setTimeout(w,2e3)),s(`sub_demo_${Date.now()}`)};return e.jsxs("form",{onSubmit:g,className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs(T,{type:"button",variant:"outline",className:"h-12",disabled:r,onClick:()=>{n(!0),setTimeout(()=>s(`sub_demo_apple_${Date.now()}`),2e3)},children:[e.jsx("svg",{viewBox:"0 0 24 24",className:"w-5 h-5 mr-2",fill:"currentColor",children:e.jsx("path",{d:"M17.05 20.28c-.98.95-2.05.8-3.08.35-1.09-.46-2.09-.48-3.24 0-1.44.62-2.2.44-3.06-.35C2.79 15.25 3.51 7.59 9.05 7.31c1.35.07 2.29.74 3.08.8 1.18-.24 2.31-.93 3.57-.84 1.51.12 2.65.72 3.4 1.8-3.12 1.87-2.38 5.98.48 7.13-.57 1.5-1.31 2.99-2.54 4.09l.01-.01zM12.03 7.25c-.15-2.23 1.66-4.07 3.74-4.25.29 2.58-2.34 4.5-3.74 4.25z"})}),"Apple Pay"]}),e.jsxs(T,{type:"button",variant:"outline",className:"h-12",disabled:r,onClick:()=>{n(!0),setTimeout(()=>s(`sub_demo_google_${Date.now()}`),2e3)},children:[e.jsxs("svg",{viewBox:"0 0 24 24",className:"w-5 h-5 mr-2",children:[e.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"}),e.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),e.jsx("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),e.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]}),"Google Pay"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"or pay with card"})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"card-number",children:"Card number"}),e.jsx(te,{id:"card-number",placeholder:"1234 5678 9012 3456",value:a,onChange:b=>i(y(b.target.value)),disabled:r,maxLength:19})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"expiry",children:"Expiry date"}),e.jsx(te,{id:"expiry",placeholder:"MM/YY",value:l,onChange:b=>o(f(b.target.value)),disabled:r,maxLength:5})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"cvc",children:"CVC"}),e.jsx(te,{id:"cvc",placeholder:"123",value:c,onChange:b=>u(b.target.value.replace(/\D/g,"").substring(0,4)),disabled:r,maxLength:4})]})]})]}),e.jsx(T,{type:"submit",className:"w-full",size:"lg",disabled:r,children:r?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsxs("svg",{className:"animate-spin h-4 w-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Processing..."]}):t.proration?`Upgrade Now - ${p}`:`Subscribe - ${p}`}),e.jsxs("div",{className:"flex items-center justify-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]}),e.jsx("span",{children:"Secured by Stripe - Cancel anytime"})]})]})}const He="pk_test_51SihBODiEfx9xR94hb9APIlKq2CEr3uJqjQ1j98VdO5i30EGWi4HieGFjy1O3lEF3OWangT10RYr2Kae4CxfAvYd00xEVl0Raw";function jr(t){return!!((t.startsWith("pk_live_")||t.startsWith("pk_test_"))&&t.length>20)}function vr(t){return!!(t&&/^(pi|seti)_[a-zA-Z0-9]+_secret_[a-zA-Z0-9]+$/.test(t))}function es({priceId:t,isOpen:s,onClose:r,onSuccess:n,existingSubscriptionId:a,theme:i}){console.log("[PaymentBottomSheet v0.1.3] Rendering with checkout fix:",{priceId:t,isOpen:s,existingSubscriptionId:a,theme:i});const{customerEmail:l,customerName:o}=D(),c=P.useQueryClient(),[u,m]=d.useState(null),[x,p]=d.useState("loading"),[y,f]=d.useState(null),[g,v]=d.useState(!1),[b,w]=d.useState(!1);d.useEffect(()=>{console.log("[PaymentBottomSheet] State changed:",{sheetState:x,error:y,isProcessing:g,isDemoMode:b,hasStripePromise:!!u})},[x,y,g,b,u]);const{data:j,error:S,refetch:_}=Zt(s?{priceId:t,customerEmail:l,customerName:o,existingSubscriptionId:a}:null,{enabled:s}),k=j;d.useEffect(()=>{console.log("[PaymentBottomSheet] Checkout session data:",{hasCheckoutData:!!j,checkoutSession:k,checkoutError:S==null?void 0:S.message,isOpen:s})},[j,k,S,s]),d.useEffect(()=>{var L;if(console.log("[PaymentBottomSheet] Stripe initialization effect triggered"),k){const O=jr(He),Z=vr(k.clientSecret);if(console.log("[PaymentBottomSheet] Stripe validation:",{publishableKey:He,validKey:O,clientSecret:((L=k.clientSecret)==null?void 0:L.substring(0,20))+"...",validSecret:Z,stripeAccountId:k.stripeAccountId}),O&&Z){console.log("[PaymentBottomSheet] Loading Stripe with valid credentials");const ae=dt.loadStripe(He,{stripeAccount:k.stripeAccountId});m(ae),w(!1)}else console.log("[PaymentBottomSheet] Invalid Stripe credentials, entering demo mode"),w(!0);p("ready")}},[k]),d.useEffect(()=>{S&&(f(S.message||"Failed to create checkout session"),p("error"))},[S]),d.useEffect(()=>{s||(p("loading"),f(null),m(null),w(!1))},[s]);const $=L=>{p("success"),c.invalidateQueries({queryKey:["billingos","products"]}),console.log("💫 Invalidated products query - PricingTable will auto-refresh"),setTimeout(()=>{n(L)},1500)},Q=L=>{f(L)},K=()=>{console.log("[PaymentBottomSheet] handleClose called, isProcessing:",g),!(g&&!window.confirm("Your payment is being processed. Are you sure you want to close?"))&&r()},X=()=>{f(null),p("loading"),_()},z={theme:i==="dark"?"night":"stripe",variables:{colorPrimary:"#3B82F6",borderRadius:"8px"}},B=(L,O)=>new Intl.NumberFormat("en-US",{style:"currency",currency:O.toUpperCase()}).format(L/100),W=L=>{switch(L){case"day":return"day";case"week":return"week";case"month":return"month";case"year":return"year";default:return L}};return console.log("[PaymentBottomSheet] Rendering drawer with isOpen:",s,"sheetState:",x),e.jsx(fr,{fallback:(L,O)=>e.jsxs("div",{style:{padding:"20px",maxWidth:"400px",margin:"0 auto"},children:[e.jsx(Y,{variant:"destructive",children:e.jsxs(G,{children:["Failed to load payment form: ",(L==null?void 0:L.message)||"Unknown error"]})}),e.jsxs("div",{className:"mt-4 flex gap-2",children:[e.jsx(T,{variant:"outline",onClick:r,children:"Cancel"}),e.jsx(T,{onClick:O,children:"Try Again"})]})]}),onError:(L,O)=>{console.error("[PaymentBottomSheet] Error caught by boundary:",L),console.error("[PaymentBottomSheet] Error info:",O)},children:e.jsx(Et,{open:s,onOpenChange:L=>{console.log("[PaymentBottomSheet] Drawer.onOpenChange called with open:",L),L||K()},children:e.jsxs(Xe,{preventClose:g,onCloseAttempt:()=>{window.alert("Please wait while your payment is being processed.")},children:[e.jsxs(Je,{className:"text-center sm:text-left",children:[e.jsx(Ze,{children:x==="success"?"Payment Successful!":a?"Complete Your Upgrade":"Complete Payment"}),x!=="success"&&k&&e.jsxs(et,{children:[a?"Upgrading to":"Subscribing to",":"," ",e.jsx("span",{className:"font-medium",children:k.product.name})]})]}),x==="loading"&&e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsx(E,{className:"h-20 w-full"}),e.jsx(E,{className:"h-40 w-full"}),e.jsx(E,{className:"h-12 w-full"})]}),x==="error"&&e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsx(Y,{variant:"destructive",children:e.jsx(G,{children:y||"Something went wrong. Please try again."})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{variant:"outline",onClick:r,className:"flex-1",children:"Cancel"}),e.jsx(T,{onClick:X,className:"flex-1",children:"Try Again"})]})]}),x==="success"&&k&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 space-y-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-green-100 flex items-center justify-center",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-green-600",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})})}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-lg font-semibold",children:"Payment Successful!"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Your subscription to ",k.product.name," is now active."]})]})]}),x==="processing"&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 space-y-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsxs("svg",{className:"animate-spin h-8 w-8 text-primary",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-lg font-semibold",children:"Processing Payment..."}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Please don't close this window."})]})]}),x==="ready"&&k&&e.jsxs("div",{className:"space-y-6",children:[b&&e.jsx(Y,{children:e.jsxs(G,{className:"text-sm",children:[e.jsx("strong",{children:"Demo Mode:"})," This is a preview with mock data. In production, a real Stripe payment form will appear here."]})}),e.jsx(F,{children:e.jsxs(I,{className:"pt-4",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:k.product.name}),e.jsxs("p",{className:"text-2xl font-bold mt-1",children:[B(k.amount,k.currency),e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["/",W(k.product.interval)]})]})]}),e.jsx(A,{variant:"secondary",children:a?"Upgrade":"New"})]}),k.product.features.length>0&&e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Features Included:"}),e.jsx("ul",{className:"space-y-1",children:k.product.features.map((L,O)=>e.jsxs("li",{className:"flex items-center gap-2 text-sm",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-green-500",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),L]},O))})]})]})}),k.proration&&e.jsx(F,{children:e.jsxs(I,{className:"pt-4",children:[e.jsx("h4",{className:"font-medium mb-3",children:"Amount Due Today:"}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{children:k.product.name}),e.jsx("span",{children:B(k.proration.charged,k.currency)})]}),e.jsxs("div",{className:"flex justify-between text-green-600",children:[e.jsx("span",{children:"Credit (unused time)"}),e.jsxs("span",{children:["-",B(k.proration.credited,k.currency)]})]}),e.jsx(ke,{}),e.jsxs("div",{className:"flex justify-between font-semibold",children:[e.jsx("span",{children:"Total Due Now"}),e.jsx("span",{children:B(k.proration.total,k.currency)})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-3 flex items-start gap-1",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"mt-0.5 flex-shrink-0",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 16v-4"}),e.jsx("path",{d:"M12 8h.01"})]}),k.proration.explanation]})]})}),!k.proration&&e.jsx(F,{children:e.jsx(I,{className:"pt-4",children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"font-medium",children:"Amount Due Today:"}),e.jsx("span",{className:"text-xl font-bold",children:B(k.amount,k.currency)})]})})}),e.jsx(ke,{}),b?e.jsx(yr,{checkoutSession:k,onSuccess:$,isProcessing:g,setIsProcessing:v}):u?e.jsx(ce.Elements,{stripe:u,options:{clientSecret:k.clientSecret,appearance:z},children:e.jsx(pr,{checkoutSession:k,onSuccess:$,onError:Q,isProcessing:g,setIsProcessing:v})}):null]})]})})})}function ts({planIds:t,showIntervalToggle:s=!0,defaultInterval:r="month",onSelectPlan:n,theme:a,title:i="Choose Your Plan",description:l,useCheckoutModal:o=!1,onPlanChanged:c,customer:u}){const[m,x]=d.useState(r),[p,y]=d.useState(null),[f,g]=d.useState(!1),{customerEmail:v,customerName:b}=D(),w=(u==null?void 0:u.email)||v,j=(u==null?void 0:u.name)||b,S=P.useQueryClient(),[_,k]=d.useState(!1);d.useEffect(()=>{console.log("[PricingTable] Customer data:",{fromProp:u,fromContext:{customerEmail:v,customerName:b},final:{email:w,name:j},hasEmail:!!w,hasName:!!j})},[u,v,b,w,j]),d.useEffect(()=>{console.log("📊 BillingOS SDK v1.2.0 - PricingTable rendered - CSS injected"),console.log("%c🚀 BillingOS SDK Version: 1.1.0","color: #10b981; font-weight: bold; font-size: 14px;"),o?console.log("%c🎉 Using NEW Iframe-based CheckoutModal with Real-time Updates!","background: linear-gradient(to right, #10b981, #3b82f6); color: white; padding: 4px 8px; border-radius: 4px; font-weight: bold;"):console.log("📦 Using PaymentBottomSheet (legacy)")},[o]);const{data:$,isLoading:Q,error:K,refetch:X}=Jt({planIds:t}),z=($==null?void 0:$.products)||[],B=($==null?void 0:$.currentSubscription)||null,W=z.some(N=>N.prices.some(M=>M.interval==="year")),L=d.useMemo(()=>{const N=new Map;z.forEach(R=>{R.features.forEach(U=>{N.has(U.id)||N.set(U.id,{name:U.title,values:Array(z.length).fill(null)})})});const M=Array.from(N.entries());return M.forEach(([R,U])=>{z.forEach((ie,H)=>{var we;const le=ie.features.find(xe=>xe.id===R);if(le){if(le.type==="boolean_flag")U.values[H]=!0;else if(le.type==="usage_quota"||le.type==="numeric_limit"){const xe=(we=le.properties)==null?void 0:we.limit;xe===-1?U.values[H]="Unlimited":typeof xe=="number"?U.values[H]=xe:U.values[H]=!0}}})}),M.map(([,R])=>R)},[z]),O=N=>new Intl.NumberFormat("en-US",{style:"currency",currency:N.currency.toUpperCase(),minimumFractionDigits:0,maximumFractionDigits:0}).format(N.amount/100),Z=N=>N.prices.find(M=>M.interval===m)||N.prices[0]||null,ae=N=>{n?n(N):(y(N),g(!0))},ye=d.useCallback(async N=>{console.log("%c🎉 [PricingTable] handlePaymentSuccess CALLED!","color: #10b981; font-size: 14px; font-weight: bold;",N),console.log("[PricingTable] Subscription data:",N),g(!1),y(null),console.log("[PricingTable] Showing success notification..."),k(!0),setTimeout(()=>k(!1),5e3),c&&N&&(console.log("[PricingTable] Calling onPlanChanged callback..."),c(N)),console.log("%c🔄 Invalidating products cache...","color: #8b5cf6; font-weight: 600;"),await S.invalidateQueries({queryKey:["products"],refetchType:"all"}),N&&(console.log("[PricingTable] Optimistically updating cache with subscription:",N),S.setQueryData(["products",t],M=>{var U;if(!M)return M;console.log("[PricingTable] Updating cache - old data:",M);const R={...M,currentSubscription:N,products:(U=M.products)==null?void 0:U.map(ie=>{var H;return{...ie,isCurrentPlan:((H=ie.prices)==null?void 0:H.some(le=>le.id===N.priceId))||!1}})};return console.log("[PricingTable] Updated cache data:",R),R})),console.log("[PricingTable] Triggering background refetch..."),await X(),console.log("%c✅ Products cache invalidated and refetched","color: #10b981; font-weight: 600;")},[S,X,t,c]);return Q?e.jsxs("div",{className:h("w-full",a==="dark"&&"dark"),children:[i&&e.jsxs("div",{className:"text-center mb-8",children:[e.jsx(E,{className:"h-10 w-64 mx-auto mb-2"}),l&&e.jsx(E,{className:"h-5 w-96 mx-auto"})]}),e.jsx(E,{className:"h-[600px] w-full"})]}):K?e.jsxs("div",{className:h("w-full max-w-md mx-auto",a==="dark"&&"dark"),children:[e.jsx(Y,{variant:"destructive",children:e.jsx(G,{children:K.message||"Failed to load pricing plans"})}),e.jsx("div",{className:"mt-4 flex justify-center",children:e.jsx(T,{onClick:()=>X(),children:"Try Again"})})]}):z.length===0?e.jsx("div",{className:h("w-full text-center py-12",a==="dark"&&"dark"),children:e.jsx("p",{className:"text-muted-foreground",children:"No pricing plans available"})}):e.jsxs("div",{className:h("w-full",a==="dark"&&"dark"),children:[_&&e.jsx("div",{className:"mb-6 p-4 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg animate-in slide-in-from-top-2 duration-300",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("svg",{className:"w-5 h-5 text-green-600 dark:text-green-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),e.jsx("p",{className:"text-green-800 dark:text-green-200 font-medium",children:"Payment successful! Your subscription has been updated."})]})}),(i||l)&&e.jsxs("div",{className:"text-center mb-8",children:[i&&e.jsx("h2",{className:"text-3xl font-bold tracking-tight text-foreground",children:i}),l&&e.jsx("p",{className:"text-muted-foreground mt-2 max-w-2xl mx-auto",children:l}),o&&e.jsxs("div",{className:"inline-flex items-center gap-2 mt-4 px-3 py-1 bg-gradient-to-r from-blue-100 to-purple-100 text-blue-800 rounded-full text-sm font-medium",children:[e.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),e.jsx("span",{children:"Using Secure Iframe Checkout"})]})]}),s&&W&&e.jsx("div",{className:"flex justify-center mb-8",children:e.jsxs("div",{className:"inline-flex items-center rounded-lg bg-muted p-1",children:[e.jsx("button",{onClick:()=>x("month"),className:h("px-4 py-2 rounded-md text-sm font-medium transition-colors",m==="month"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:"Monthly"}),e.jsxs("button",{onClick:()=>x("year"),className:h("px-4 py-2 rounded-md text-sm font-medium transition-colors flex items-center gap-2",m==="year"?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:["Yearly",e.jsx(A,{variant:"secondary",className:"text-xs",children:"Save"})]})]})}),e.jsx("div",{className:"rounded-lg border bg-card overflow-hidden",children:e.jsxs(Yt,{children:[e.jsx(Gt,{children:e.jsxs(Le,{className:"hover:bg-transparent border-b",children:[e.jsx(Ke,{className:"w-[200px]"}),z.map(N=>{const M=Z(N),R=N.highlighted,U=N.isCurrentPlan;return e.jsx(Ke,{className:h("text-center relative",R&&"bg-foreground text-background"),children:e.jsxs("div",{className:"py-8",children:[(R||U)&&e.jsxs("div",{className:"flex justify-center gap-2 mb-3",children:[U&&e.jsx(A,{className:"bg-primary text-primary-foreground text-xs",children:"Current Plan"}),R&&!U&&e.jsx(A,{variant:"secondary",className:h("text-xs",R&&"bg-background text-foreground"),children:"Popular"})]}),e.jsx("div",{className:h("font-bold text-xl mb-3",R?"text-background":"text-foreground"),children:N.name}),M&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:h("text-5xl font-bold mb-2",R?"text-background":"text-foreground"),children:O(M)}),e.jsxs("div",{className:h("text-sm mt-1",R?"text-background/70":"text-muted-foreground"),children:["Per ",m==="year"?"year":"month"]})]})]})},N.id)})]})}),e.jsxs(Xt,{children:[L.map((N,M)=>e.jsxs(Le,{children:[e.jsx(Ne,{className:"font-medium text-foreground py-4",children:N.name}),N.values.map((R,U)=>{var H;const ie=(H=z[U])==null?void 0:H.highlighted;return e.jsx(Ne,{className:h("text-center py-4",ie&&"bg-foreground/5"),children:R===null||R===!1?e.jsx("span",{className:"text-muted-foreground",children:"-"}):R===!0?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"inline-block text-foreground",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"9 12 11 14 15 10"})]}):e.jsx("span",{className:"text-foreground font-medium",children:R})},U)})]},M)),e.jsxs(Le,{className:"hover:bg-transparent border-t",children:[e.jsx(Ne,{className:"font-medium text-foreground py-6",children:"Server speed"}),z.map(N=>{var le;const M=Z(N),R=N.highlighted,U=N.isCurrentPlan,ie=B!==null;let H="Get Started";if(U)H="Current Plan";else if(ie&&M&&B){const we=z.find(ks=>ks.isCurrentPlan),xe=we&&((le=Z(we))==null?void 0:le.amount)||0;M.amount>xe?H="Upgrade":M.amount<xe?H="Downgrade":H="Switch Plan"}return e.jsx(Ne,{className:h("text-center py-6",R&&"bg-foreground/5"),children:e.jsx(T,{onClick:()=>M&&ae(M.id),disabled:U||!M,variant:R&&!U?"default":"outline",className:h("w-full max-w-[200px]",R&&!U&&"bg-foreground text-background hover:bg-foreground/90"),children:H})},N.id)})]})]})]})}),!n&&p&&e.jsx(e.Fragment,{children:o?e.jsx(Me,{open:f,onOpenChange:N=>{N||(g(!1),y(null))},priceId:p,customer:{email:w,name:j},onSuccess:N=>{ye(N)},existingSubscriptionId:B==null?void 0:B.id,theme:a}):e.jsx(es,{priceId:p,isOpen:f,onClose:()=>{g(!1),y(null)},onSuccess:ye,existingSubscriptionId:B==null?void 0:B.id,theme:a})})]})}function br({product:t,selectedInterval:s,currentSubscription:r,onSelectPlan:n}){const a=t.prices.find(y=>y.interval===s)||t.prices[0],i=t.isCurrentPlan,o=r?i||r.productId===t.id?"current":"upgrade":"buy",c=y=>new Intl.NumberFormat("en-US",{style:"currency",currency:y.currency.toUpperCase(),minimumFractionDigits:0,maximumFractionDigits:0}).format(y.amount/100),m=s==="year"?(()=>{const y=t.prices.find(w=>w.interval==="month"),f=t.prices.find(w=>w.interval==="year");if(!y||!f)return null;const g=y.amount*12,v=f.amount,b=(g-v)/g*100;return Math.round(b)})():null,x=y=>{var f,g;return((f=y.properties)==null?void 0:f.limit)===-1?`Unlimited ${((g=y.properties)==null?void 0:g.unit)||y.title.toLowerCase()}`:y.title},p=()=>{o!=="current"&&a&&n(a.id)};return e.jsxs(F,{className:h("relative flex flex-col h-full transition-all duration-200",i&&"border-primary border-2 shadow-lg",t.highlighted&&!i&&"border-primary/50","hover:shadow-lg"),children:[e.jsxs("div",{className:"absolute -top-3 left-1/2 -translate-x-1/2 flex gap-2",children:[i&&e.jsx(A,{className:"bg-primary text-primary-foreground",children:"Current Plan"}),t.highlighted&&!i&&e.jsx(A,{variant:"secondary",children:"Most Popular"})]}),e.jsxs(J,{className:"text-center pb-2 pt-8",children:[e.jsx(de,{className:"text-2xl font-bold",children:t.name}),e.jsx(Be,{className:"text-sm mt-1",children:t.description})]}),e.jsxs(I,{className:"flex-1 pt-4",children:[e.jsxs("div",{className:"text-center mb-6",children:[e.jsxs("div",{className:"flex items-baseline justify-center gap-1",children:[e.jsx("span",{className:"text-4xl font-bold tracking-tight",children:a?c(a):"N/A"}),e.jsxs("span",{className:"text-muted-foreground text-sm",children:["/",s==="year"?"year":"mo"]})]}),m&&m>0&&e.jsxs(A,{variant:"secondary",className:"mt-2 bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-300",children:["Save ",m,"%"]}),t.trialDays>0&&o==="buy"&&e.jsxs("p",{className:"text-sm text-muted-foreground mt-2",children:[t.trialDays,"-day free trial"]})]}),e.jsx("ul",{className:"space-y-3",children:t.features.map(y=>e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-green-500 flex-shrink-0 mt-0.5",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),e.jsx("span",{className:"text-sm",children:x(y)})]},y.id))})]}),e.jsx(Ge,{className:"pt-4",children:e.jsxs(T,{className:"w-full",size:"lg",variant:o==="current"?"outline":"default",disabled:o==="current",onClick:p,children:[o==="current"&&e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Current Plan"]}),o==="buy"&&(t.trialDays>0?"Start Free Trial":"Get Started"),o==="upgrade"&&"Upgrade",o==="downgrade"&&"Downgrade"]})})]})}function wr({isOpen:t=!1,onClose:s,mode:r="drawer",defaultTab:n="subscription",theme:a="light",className:i,customerId:l,metadata:o,onSubscriptionUpdate:c,onSubscriptionCancel:u,onPaymentMethodAdd:m,onPaymentMethodUpdate:x,debug:p=!1}){const[y,f]=C.useState("loading"),[g,v]=C.useState(null),[b,w]=C.useState(600),[j,S]=C.useState(!1),[_,k]=C.useState(null),$=C.useRef(null);C.useEffect(()=>{console.log("%c🚀 BillingOS SDK v1.2.0 - Iframe Customer Portal with Smart Pricing Table","background: linear-gradient(to right, #667eea, #764ba2); color: white; padding: 4px 8px; border-radius: 4px; font-weight: bold;"),console.log("%c📦 Using iframe for instant updates and security","color: #10b981; font-weight: 600;"),console.log("%c🎨 Supports drawer, modal, and page modes","color: #8b5cf6; font-weight: 600;"),p&&console.log("[CustomerPortal] Debug mode enabled")},[]);const Q=r==="page"||t,{sessionId:K,sessionUrl:X,loading:z,error:B}=ur({enabled:Q,customerId:l,metadata:o}),W=C.useCallback(N=>{var M,R,U;switch(p&&console.log("[CustomerPortal] Received message from iframe:",N.type,N),N.type){case"PORTAL_READY":console.log("[CustomerPortal] Portal is ready"),f("ready");break;case"PORTAL_CLOSE":console.log("[CustomerPortal] User requested close"),s==null||s();break;case"SUBSCRIPTION_UPDATED":console.log("[CustomerPortal] Subscription updated"),c==null||c(N.payload);break;case"SUBSCRIPTION_CANCELLED":console.log("[CustomerPortal] Subscription cancelled"),u==null||u();break;case"PAYMENT_METHOD_ADDED":console.log("[CustomerPortal] Payment method added"),m==null||m();break;case"PAYMENT_METHOD_UPDATED":console.log("[CustomerPortal] Payment method updated"),x==null||x();break;case"HEIGHT_CHANGED":(M=N.payload)!=null&&M.height&&(w(N.payload.height),p&&console.log("[CustomerPortal] Height changed to:",N.payload.height));break;case"OPEN_PRICING_TABLE":console.log("[CustomerPortal] Opening pricing table for plan change"),(R=N.payload)!=null&&R.customer&&(console.log("[CustomerPortal] Received customer data for prefill:",N.payload.customer),k(N.payload.customer)),S(!0);break;case"CLOSE_PRICING_TABLE":console.log("[CustomerPortal] Closing pricing table"),S(!1);break;case"ERROR":f("error");const ie=((U=N.payload)==null?void 0:U.error)||"An error occurred",H=new Error(ie);v(H);break}},[p,s,c,u,m,x]),{sendMessage:L}=mr({iframeRef:$,onMessage:W,debug:p});C.useEffect(()=>{K&&y==="ready"&&L({type:"INIT_PORTAL",sessionId:K,config:{theme:a,defaultTab:n}})},[K,y,a,n,L]),C.useEffect(()=>{Q||(f("loading"),v(null),w(600))},[Q]),C.useEffect(()=>{B&&(f("error"),v(B))},[B]);const O=z||y==="loading",Z=y==="error"&&g,ae=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"absolute top-2 right-2 z-20 flex items-center gap-1 bg-gradient-to-r from-blue-600 to-purple-600 text-white text-xs font-medium px-2 py-1 rounded-full shadow-lg",children:[e.jsx("svg",{className:"w-3 h-3",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M2.166 4.999A11.954 11.954 0 0010 1.944 11.954 11.954 0 0017.834 5c.11.65.166 1.32.166 2.001 0 5.225-3.34 9.67-8 11.317C5.34 16.67 2 12.225 2 7c0-.682.057-1.35.166-2.001zm11.541 3.708a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),e.jsx("span",{children:"Secure Iframe"})]}),Z?e.jsx("div",{className:"p-8",children:e.jsx(Y,{variant:"destructive",children:e.jsx(G,{children:g.message})})}):e.jsxs(e.Fragment,{children:[O&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-white z-10",children:e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"}),e.jsx("p",{className:"mt-4 text-gray-600 font-medium",children:"Loading portal..."}),e.jsx("p",{className:"mt-2 text-xs text-gray-500",children:"Iframe-based • Always up-to-date"})]})}),X&&e.jsx(Vt,{ref:$,src:X,height:b,className:h("transition-opacity duration-300",O?"opacity-0":"opacity-100"),onLoad:()=>{console.log("%c✅ Portal iframe loaded successfully","color: #10b981; font-weight: 600;",`
4
+ URL: ${X}`),p&&console.log("[CustomerPortal] Full iframe details:",{sessionUrl:X,sessionId:K,state:y,height:b})}})]}),p&&e.jsxs("div",{className:"absolute bottom-0 left-0 right-0 bg-black/80 text-white p-2 text-xs",children:[e.jsxs("div",{children:["State: ",y]}),e.jsxs("div",{children:["Session: ",K||"Creating..."]}),g&&e.jsxs("div",{children:["Error: ",g.message]})]})]}),ye=r==="page"?e.jsx("div",{className:h("relative w-full",i),children:ae}):r==="modal"?e.jsx(fe,{open:t,onOpenChange:N=>!N&&(s==null?void 0:s()),children:e.jsxs(he,{className:h("sm:max-w-[800px] p-0 overflow-hidden max-h-[90vh] relative",i),children:[e.jsx(ge,{className:"sr-only",children:e.jsx(pe,{children:"Customer Portal"})}),ae]})}):e.jsx(It,{open:t,onOpenChange:N=>!N&&(s==null?void 0:s()),children:e.jsxs(at,{side:"right",className:h("w-full sm:max-w-[600px] p-0 overflow-hidden",i),children:[e.jsx(it,{className:"sr-only",children:e.jsx(lt,{children:"Customer Portal"})}),ae]})});return e.jsxs(e.Fragment,{children:[ye,e.jsx(fe,{open:j,onOpenChange:S,children:e.jsxs(he,{className:"sm:max-w-6xl max-h-[90vh] overflow-y-auto",children:[e.jsx(ge,{children:e.jsx(pe,{children:"Change Your Plan"})}),e.jsx(ts,{useCheckoutModal:!0,theme:a,customer:_||void 0,onPlanChanged:N=>{console.log("[CustomerPortal] Plan changed successfully:",N),S(!1),k(null),L({type:"UPDATE_CONFIG",payload:{refresh:!0}}),c==null||c(N)}})]})})]})}const ee={all:["portal"],data:()=>[...ee.all,"data"],setupIntent:()=>[...ee.all,"setupIntent"]};function Nr(t){const{client:s}=D();return P.useQuery({queryKey:ee.data(),queryFn:()=>s.getCustomerPortal(),staleTime:1e3*60*5,...t})}function Cr(t,s){const{client:r}=D(),n=P.useQueryClient();return P.useMutation({...s,mutationFn:a=>r.updatePortalSubscription(t,a),onSuccess:(...a)=>{var i;n.invalidateQueries({queryKey:ee.data()}),(i=s==null?void 0:s.onSuccess)==null||i.call(s,...a)}})}function Sr(t,s){const{client:r}=D(),n=P.useQueryClient();return P.useMutation({...s,mutationFn:a=>r.cancelPortalSubscription(t,a),onSuccess:(...a)=>{var i;n.invalidateQueries({queryKey:ee.data()}),(i=s==null?void 0:s.onSuccess)==null||i.call(s,...a)}})}function kr(t,s){const{client:r}=D(),n=P.useQueryClient();return P.useMutation({...s,mutationFn:()=>r.reactivatePortalSubscription(t),onSuccess:(...a)=>{var i;n.invalidateQueries({queryKey:ee.data()}),(i=s==null?void 0:s.onSuccess)==null||i.call(s,...a)}})}function Pr(t){const{client:s}=D();return P.useQuery({queryKey:ee.setupIntent(),queryFn:()=>s.getSetupIntent(),enabled:!1,...t})}function Er(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({...t,mutationFn:n=>s.addPaymentMethod(n),onSuccess:(...n)=>{var a;r.invalidateQueries({queryKey:ee.data()}),(a=t==null?void 0:t.onSuccess)==null||a.call(t,...n)}})}function Dr(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({...t,mutationFn:n=>s.removePaymentMethod(n),onSuccess:(...n)=>{var a;r.invalidateQueries({queryKey:ee.data()}),(a=t==null?void 0:t.onSuccess)==null||a.call(t,...n)}})}function Tr(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({...t,mutationFn:n=>s.setDefaultPaymentMethod(n),onSuccess:(...n)=>{var a;r.invalidateQueries({queryKey:ee.data()}),(a=t==null?void 0:t.onSuccess)==null||a.call(t,...n)}})}function _r(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({...t,mutationFn:({invoiceId:n,paymentMethodId:a})=>s.retryInvoice(n,a),onSuccess:(...n)=>{var a;r.invalidateQueries({queryKey:ee.data()}),(a=t==null?void 0:t.onSuccess)==null||a.call(t,...n)}})}function Lr(t){const{client:s}=D(),r=P.useQueryClient();return P.useMutation({...t,mutationFn:n=>s.updateCustomerBilling(n),onSuccess:(...n)=>{var a;r.invalidateQueries({queryKey:ee.data()}),(a=t==null?void 0:t.onSuccess)==null||a.call(t,...n)}})}function ct(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:t.toLocaleString()}function Rr(t){return t>=90?"bg-destructive":t>=75?"bg-yellow-500":"bg-primary"}function ss({title:t,usage:s,unit:r,className:n}){const{consumed:a,limit:i,percentage:l,resetDate:o}=s,c=ct(a),u=ct(i),m=Rr(l);return e.jsxs("div",{className:h("space-y-2",n),children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"font-medium",children:t}),e.jsxs("span",{className:"text-muted-foreground",children:[c," / ",u," ",r&&`(${r})`]})]}),e.jsx(tt,{value:l,max:100,className:"h-2",indicatorClassName:m}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsxs("span",{children:[Math.round(l),"% used"]}),o&&e.jsxs("span",{children:["Resets: ",new Date(o).toLocaleDateString("en-US",{month:"short",day:"numeric"})]})]})]})}function Mr({className:t}){return e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:h("h-4 w-4",t),children:e.jsx("path",{d:"M20 6 9 17l-5-5"})})}function rs({features:t,className:s}){const r=t.filter(n=>n.type==="boolean_flag"&&n.enabled);return r.length===0?null:e.jsxs("div",{className:h("space-y-2",s),children:[e.jsx("h4",{className:"text-sm font-medium text-muted-foreground",children:"Included Features"}),e.jsx("ul",{className:"space-y-1.5",children:r.map(n=>e.jsxs("li",{className:"flex items-center gap-2 text-sm",children:[e.jsx(Mr,{className:"text-green-500"}),e.jsx("span",{children:n.title})]},n.id))})]})}function Fr({className:t}){return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:h("h-4 w-4",t),children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"}),e.jsx("path",{d:"M12 9v4"}),e.jsx("path",{d:"M12 17h.01"})]})}function Ir(t){switch(t){case"trial_ending":return"Trial Ending Soon";case"payment_failed":return"Payment Failed";case"subscription_canceled":return"Subscription Canceled";case"past_due":return"Payment Past Due";default:return"Warning"}}function Ur(t){switch(t){case"payment_failed":case"past_due":return"destructive";default:return"warning"}}function Re({type:t,message:s,actionLabel:r,onAction:n,className:a}){const i=Ir(t),l=Ur(t);return e.jsxs(Y,{variant:l,className:h("",a),children:[e.jsx(Fr,{}),e.jsx(Ae,{children:i}),e.jsxs(G,{className:"flex items-center justify-between",children:[e.jsx("span",{children:s}),r&&n&&e.jsx(T,{size:"sm",variant:l==="destructive"?"outline":"default",onClick:n,className:"ml-4",children:r})]})]})}const Ar=(t,s=!1,r=!1)=>{const n=t/100,a=t%100===0&&!s?0:2;return r?n.toLocaleString("en-US",{maximumFractionDigits:a,minimumFractionDigits:a}):n.toFixed(a)},je=(t,s,r,n,a)=>new Intl.NumberFormat("en-US",{style:"currency",currency:s,minimumFractionDigits:r,maximumFractionDigits:a,notation:n}).format(t/100),ns=t=>t/100,as=t=>Math.round(t*100),is=(t,s)=>je(t,s,0,"compact",1),ls=(t,s)=>je(t,s,0,"standard",0),os=t=>{const n=new Intl.NumberFormat("en-US",{style:"currency",currency:t,minimumFractionDigits:0,maximumFractionDigits:0}).formatToParts(0).find(a=>a.type==="currency");return(n==null?void 0:n.value)||t},cs=(t,s,r)=>{const n=je(t,r),a=je(s,r);return`${n} - ${a}`},ds=t=>t===0,us=t=>t<0,ms=(t,s)=>Math.round(t*s/100),hs=(...t)=>t.reduce((s,r)=>s+r,0),oe={format:je,formatCompact:is,formatWhole:ls,formatRange:cs,fromCents:ns,toCents:as,getSymbol:os,isZero:ds,isNegative:us,calculatePercentage:ms,add:hs};function Br(t,s){return s===1?t:`${s} ${t}s`}function Or(t,s){if(s)return e.jsx(A,{variant:"warning",children:"Cancels at period end"});switch(t){case"active":return e.jsx(A,{variant:"success",children:"Active"});case"trialing":return e.jsx(A,{variant:"secondary",children:"Trial"});case"past_due":return e.jsx(A,{variant:"destructive",children:"Past Due"});case"canceled":return e.jsx(A,{variant:"outline",children:"Canceled"});case"unpaid":return e.jsx(A,{variant:"destructive",children:"Unpaid"});default:return e.jsx(A,{variant:"outline",children:t})}}function qr({onBrowsePlans:t}){return e.jsx(F,{children:e.jsxs(I,{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"You don't have an active subscription."}),e.jsx(T,{onClick:t,children:"Browse Plans"})]})})}function zr(){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(F,{children:[e.jsxs(J,{children:[e.jsx(E,{className:"h-6 w-32"}),e.jsx(E,{className:"h-4 w-48"})]}),e.jsxs(I,{className:"space-y-4",children:[e.jsx(E,{className:"h-4 w-24"}),e.jsx(E,{className:"h-4 w-36"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(E,{className:"h-9 w-32"}),e.jsx(E,{className:"h-9 w-40"})]})]})]}),e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(E,{className:"h-5 w-20"})}),e.jsxs(I,{className:"space-y-4",children:[e.jsx(E,{className:"h-12 w-full"}),e.jsx(E,{className:"h-12 w-full"})]})]})]})}function $r({subscription:t,onChangePlan:s,onCancelSubscription:r,onReactivate:n,onAddPaymentMethod:a,isLoading:i,className:l}){if(i)return e.jsx(zr,{});if(!t)return e.jsx(qr,{onBrowsePlans:s});const{product:o,price:c,status:u,currentPeriodEnd:m,cancelAtPeriodEnd:x,trialEnd:p,features:y}=t,f=oe.format(c.amount,c.currency),g=Br(c.interval,c.intervalCount),v=new Date(m).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}),b=y.filter(j=>(j.type==="usage_quota"||j.type==="numeric_limit")&&j.usage),w=u==="trialing"&&p&&new Date(p).getTime()-Date.now()<4320*60*1e3;return e.jsxs("div",{className:h("space-y-6",l),children:[u==="past_due"&&e.jsx(Re,{type:"past_due",message:"Your last payment was declined. Update your payment method to avoid service interruption.",actionLabel:"Update Payment",onAction:a}),w&&p&&e.jsx(Re,{type:"trial_ending",message:`Your trial ends on ${new Date(p).toLocaleDateString()}. Add a payment method to continue.`,actionLabel:"Add Payment Method",onAction:a}),x&&e.jsx(Re,{type:"subscription_canceled",message:`Your subscription will end on ${v}. You'll have access until then.`,actionLabel:"Reactivate",onAction:n}),e.jsxs(F,{children:[e.jsx(J,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(de,{children:o.name}),e.jsxs(Be,{children:[f," / ",g]})]}),Or(u,x)]})}),e.jsxs(I,{className:"space-y-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:e.jsxs("p",{children:[x?"Access until":"Next billing",":"," ",e.jsx("span",{className:"font-medium text-foreground",children:v})]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(T,{variant:"outline",onClick:s,children:"View Other Plans"}),!x&&u!=="canceled"&&e.jsx(T,{variant:"ghost",className:"text-destructive hover:text-destructive",onClick:r,children:"Cancel Subscription"})]})]})]}),b.length>0&&e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(de,{className:"text-base",children:"Usage This Billing Period"})}),e.jsx(I,{className:"space-y-6",children:b.map(j=>e.jsx(ss,{title:j.title,usage:j.usage,unit:j.properties.unit},j.id))})]}),y.some(j=>j.type==="boolean_flag"&&j.enabled)&&e.jsx(F,{children:e.jsx(I,{className:"pt-6",children:e.jsx(rs,{features:y})})})]})}function Hr({className:t}){return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:h("h-4 w-4",t),children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",x2:"12",y1:"15",y2:"3"})]})}function Qr(t){switch(t){case"paid":return e.jsx(A,{variant:"success",children:"Paid"});case"open":return e.jsx(A,{variant:"secondary",children:"Open"});case"failed":return e.jsx(A,{variant:"destructive",children:"Failed"});case"void":return e.jsx(A,{variant:"outline",children:"Void"});default:return e.jsx(A,{variant:"outline",children:t})}}function xs({invoice:t,onRetry:s,onDownload:r,isRetrying:n,className:a}){const i=new Date(t.date).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}),l=oe.format(t.amount,t.currency);return e.jsx(F,{className:h("",a),children:e.jsxs(I,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:t.number}),Qr(t.status)]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:i}),t.lineItems.length>0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:t.lineItems[0].description})]}),e.jsx("div",{className:"text-right",children:e.jsx("p",{className:"font-semibold",children:l})})]}),t.status==="failed"&&t.failureReason&&e.jsx("div",{className:"mt-3 rounded-md bg-destructive/10 p-2 text-sm text-destructive",children:t.failureReason}),e.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[t.status==="failed"&&s&&e.jsx(T,{size:"sm",variant:"default",onClick:()=>s(t.id),disabled:n,children:n?"Retrying...":"Retry Payment"}),t.pdfUrl&&r&&e.jsxs(T,{size:"sm",variant:"outline",onClick:()=>r(t.pdfUrl),children:[e.jsx(Hr,{className:"mr-1"}),"Download PDF"]})]})]})})}function Kr(){return e.jsx(F,{children:e.jsxs(I,{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx("p",{className:"text-muted-foreground",children:"No invoices yet."}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Your first invoice will appear here after your first billing cycle."})]})})}function Wr(){return e.jsx("div",{className:"space-y-4",children:[1,2,3].map(t=>e.jsx(F,{children:e.jsxs(I,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"h-5 w-32"}),e.jsx(E,{className:"h-4 w-24"}),e.jsx(E,{className:"h-4 w-48"})]}),e.jsx(E,{className:"h-5 w-16"})]}),e.jsx("div",{className:"mt-4 flex gap-2",children:e.jsx(E,{className:"h-8 w-24"})})]})},t))})}function Vr({invoices:t,onRetryInvoice:s,onDownloadInvoice:r,retryingInvoiceId:n,isLoading:a,className:i}){return a?e.jsx(Wr,{}):t.length===0?e.jsx(Kr,{}):e.jsxs("div",{className:h("space-y-4",i),children:[e.jsx("h3",{className:"font-medium",children:"Invoice History"}),t.map(l=>e.jsx(xs,{invoice:l,onRetry:s,onDownload:r,isRetrying:n===l.id},l.id))]})}function Yr(t){return{visa:"💳",mastercard:"💳",amex:"💳",discover:"💳",diners:"💳",jcb:"💳",unionpay:"💳"}[t]||"💳"}function Gr(t){return{visa:"Visa",mastercard:"Mastercard",amex:"American Express",discover:"Discover",diners:"Diners Club",jcb:"JCB",unionpay:"UnionPay"}[t]||t.charAt(0).toUpperCase()+t.slice(1)}function fs({paymentMethod:t,onSetDefault:s,onRemove:r,isSettingDefault:n,isRemoving:a,className:i}){const{id:l,card:o,isDefault:c}=t;if(!o)return null;const u=`${o.expMonth.toString().padStart(2,"0")}/${o.expYear}`;return e.jsx(F,{className:h("",i),children:e.jsxs(I,{className:"p-4",children:[e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-2xl",children:Yr(o.brand)}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"font-medium",children:[Gr(o.brand)," •••• ",o.last4]}),c&&e.jsx(A,{variant:"secondary",children:"Default"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Expires ",u]})]})]})}),e.jsxs("div",{className:"mt-4 flex items-center gap-2",children:[!c&&s&&e.jsx(T,{size:"sm",variant:"outline",onClick:()=>s(l),disabled:n,children:n?"Setting...":"Set as Default"}),r&&!c&&e.jsx(T,{size:"sm",variant:"ghost",onClick:()=>r(l),disabled:a,className:"text-destructive hover:text-destructive",children:a?"Removing...":"Remove"})]})]})})}function gs({className:t}){return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:h("h-4 w-4",t),children:[e.jsx("path",{d:"M5 12h14"}),e.jsx("path",{d:"M12 5v14"})]})}function Xr({onAdd:t}){return e.jsx(F,{children:e.jsxs(I,{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"No payment methods on file."}),e.jsxs(T,{onClick:t,children:[e.jsx(gs,{className:"mr-2"}),"Add Payment Method"]})]})})}function Jr(){return e.jsxs("div",{className:"space-y-4",children:[[1,2].map(t=>e.jsx(F,{children:e.jsxs(I,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(E,{className:"h-8 w-8 rounded"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"h-5 w-40"}),e.jsx(E,{className:"h-4 w-24"})]})]}),e.jsxs("div",{className:"mt-4 flex gap-2",children:[e.jsx(E,{className:"h-8 w-28"}),e.jsx(E,{className:"h-8 w-20"})]})]})},t)),e.jsx(E,{className:"h-10 w-44"})]})}function Zr({paymentMethods:t,onAddPaymentMethod:s,onSetDefault:r,onRemove:n,settingDefaultId:a,removingId:i,isLoading:l,className:o}){if(l)return e.jsx(Jr,{});if(t.length===0)return e.jsx(Xr,{onAdd:s});const c=[...t].sort((u,m)=>u.isDefault&&!m.isDefault?-1:!u.isDefault&&m.isDefault?1:0);return e.jsxs("div",{className:h("space-y-4",o),children:[e.jsx("h3",{className:"font-medium",children:"Payment Methods"}),c.map(u=>e.jsx(fs,{paymentMethod:u,onSetDefault:r,onRemove:n,isSettingDefault:a===u.id,isRemoving:i===u.id},u.id)),e.jsxs(T,{variant:"outline",onClick:s,children:[e.jsx(gs,{className:"mr-2"}),"Add New Payment Method"]})]})}const en=[{code:"US",name:"United States"},{code:"CA",name:"Canada"},{code:"GB",name:"United Kingdom"},{code:"AU",name:"Australia"},{code:"DE",name:"Germany"},{code:"FR",name:"France"},{code:"JP",name:"Japan"},{code:"IN",name:"India"},{code:"BR",name:"Brazil"},{code:"MX",name:"Mexico"}];ue.z.object({name:ue.z.string().min(1,"Name is required"),email:ue.z.string().email("Invalid email address"),line1:ue.z.string().optional(),line2:ue.z.string().optional(),city:ue.z.string().optional(),state:ue.z.string().optional(),postalCode:ue.z.string().optional(),country:ue.z.string().optional()});function tn(){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(E,{className:"h-5 w-40"})}),e.jsxs(I,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"h-4 w-12"}),e.jsx(E,{className:"h-10 w-full"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"h-4 w-12"}),e.jsx(E,{className:"h-10 w-full"})]})]})]}),e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(E,{className:"h-5 w-32"})}),e.jsxs(I,{className:"space-y-4",children:[e.jsx(E,{className:"h-10 w-full"}),e.jsx(E,{className:"h-10 w-full"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(E,{className:"h-10 w-full"}),e.jsx(E,{className:"h-10 w-full"})]})]})]}),e.jsx(E,{className:"h-10 w-28"})]})}function sn({customer:t,onSave:s,isSaving:r,isLoading:n,className:a}){var m,x,p,y,f,g;const{register:i,handleSubmit:l,formState:{errors:o,isDirty:c}}=Ls.useForm({defaultValues:{name:t.name||"",email:t.email||"",line1:((m=t.billingAddress)==null?void 0:m.line1)||"",line2:((x=t.billingAddress)==null?void 0:x.line2)||"",city:((p=t.billingAddress)==null?void 0:p.city)||"",state:((y=t.billingAddress)==null?void 0:y.state)||"",postalCode:((f=t.billingAddress)==null?void 0:f.postalCode)||"",country:((g=t.billingAddress)==null?void 0:g.country)||"US"}});if(n)return e.jsx(tn,{});const u=v=>{const b=v.line1||v.city||v.state||v.postalCode?{line1:v.line1||"",line2:v.line2,city:v.city||"",state:v.state||"",postalCode:v.postalCode||"",country:v.country||"US"}:void 0;s({name:v.name,email:v.email,billingAddress:b})};return e.jsxs("form",{onSubmit:l(u),className:h("space-y-6",a),children:[e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(de,{className:"text-base",children:"Personal Information"})}),e.jsxs(I,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"name",children:"Name"}),e.jsx(te,{id:"name",...i("name"),placeholder:"Your name"}),o.name&&e.jsx("p",{className:"text-sm text-destructive",children:o.name.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"email",children:"Email"}),e.jsx(te,{id:"email",type:"email",...i("email"),placeholder:"your@email.com"}),o.email&&e.jsx("p",{className:"text-sm text-destructive",children:o.email.message})]})]})]}),e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(de,{className:"text-base",children:"Billing Address"})}),e.jsxs(I,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"line1",children:"Address Line 1"}),e.jsx(te,{id:"line1",...i("line1"),placeholder:"123 Main St"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"line2",children:"Address Line 2"}),e.jsx(te,{id:"line2",...i("line2"),placeholder:"Apt 4B (optional)"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"city",children:"City"}),e.jsx(te,{id:"city",...i("city"),placeholder:"San Francisco"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"state",children:"State/Province"}),e.jsx(te,{id:"state",...i("state"),placeholder:"CA"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"postalCode",children:"ZIP/Postal Code"}),e.jsx(te,{id:"postalCode",...i("postalCode"),placeholder:"94102"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"country",children:"Country"}),e.jsx(rt,{id:"country",...i("country"),children:en.map(v=>e.jsx(nt,{value:v.code,children:v.name},v.code))})]})]})]})]}),e.jsx(T,{type:"submit",disabled:r||!c,children:r?"Saving...":"Save Changes"})]})}function rn({preview:t}){const{current_plan:s,new_plan:r,proration:n,change_type:a,next_billing_date:i,notes:l}=t,o=a==="upgrade";return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(de,{className:"text-sm",children:"Plan Change Summary"})}),e.jsxs(I,{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Current Plan:"}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"font-medium",children:s.product_name}),e.jsxs("div",{className:"text-muted-foreground text-xs",children:[oe.format(s.amount,s.currency)," / ",s.interval]})]})]}),e.jsx("div",{className:"flex justify-center",children:e.jsx("svg",{className:"w-4 h-4 text-muted-foreground",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 14l-7 7m0 0l-7-7m7 7V3"})})}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"New Plan:"}),e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"font-medium flex items-center gap-2 justify-end",children:[r.product_name,e.jsx(A,{variant:o?"default":"secondary",className:"text-xs",children:o?"Upgrade":"Downgrade"})]}),e.jsxs("div",{className:"text-muted-foreground text-xs",children:[oe.format(r.amount,r.currency)," / ",r.interval]})]})]})]})]}),o&&n.immediate_payment>0&&e.jsxs(F,{children:[e.jsx(J,{children:e.jsx(de,{className:"text-sm",children:"Billing Details"})}),e.jsxs(I,{className:"space-y-2",children:[n.unused_time_credit>0&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Credit for unused time:"}),e.jsxs("span",{className:"text-green-600 font-medium",children:["-",oe.format(n.unused_time_credit,s.currency)]})]}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Prorated charge for new plan:"}),e.jsx("span",{className:"font-medium",children:oe.format(n.new_plan_charge,r.currency)})]}),e.jsx("div",{className:"border-t my-2"}),e.jsxs("div",{className:"flex justify-between text-base font-semibold",children:[e.jsx("span",{children:"Due Today:"}),e.jsx("span",{children:oe.format(n.immediate_payment,r.currency)})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-3",children:["Next billing: ",new Date(i).toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"})]})]})]}),!o&&e.jsx(Y,{children:e.jsxs(G,{className:"text-sm",children:["Your plan will change to ",e.jsx("strong",{children:r.product_name})," on"," ",e.jsx("strong",{children:new Date(i).toLocaleDateString(void 0,{month:"long",day:"numeric",year:"numeric"})}),". You'll keep access to your current plan features until then."]})}),l&&l.length>0&&e.jsx(Y,{children:e.jsx(G,{children:e.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm",children:l.map((c,u)=>e.jsx("li",{children:c},u))})})})]})}function nn({plan:t,isSelected:s,isCurrent:r,onSelect:n,disabled:a}){const i=oe.format(t.amount,t.currency),l=!r&&t.amount>0,o=!r&&!l;return e.jsx(F,{className:h("cursor-pointer transition-all hover:border-primary",s&&"ring-2 ring-primary",r&&"opacity-60",a&&"pointer-events-none opacity-50"),onClick:()=>!r&&!a&&n(),children:e.jsx(I,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-semibold",children:t.product_name}),r&&e.jsx(A,{variant:"secondary",children:"Current"}),l&&e.jsx(A,{variant:"default",children:"Upgrade"}),o&&e.jsx(A,{variant:"outline",children:"Downgrade"})]}),t.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:t.description}),e.jsx("p",{className:"text-sm font-medium mt-2",children:t.is_free?"Free":`${i} / ${t.interval}`})]}),!r&&e.jsx("div",{className:"h-5 w-5 rounded-full border-2 border-primary flex items-center justify-center flex-shrink-0 ml-3",children:s&&e.jsx("div",{className:"h-2.5 w-2.5 rounded-full bg-primary"})})]})})})}function an({open:t,onOpenChange:s,subscriptionId:r,onSuccess:n}){var j;const[a,i]=d.useState(null),[l,o]=d.useState(null),[c,u]=d.useState(!1),{data:m,isLoading:x,error:p}=xt(r,{enabled:t}),y=ft(),f=gt({onSuccess:()=>{n==null||n(),s(!1)}});d.useEffect(()=>{t||(i(null),o(null),u(!1))},[t]);const g=async S=>{i(S),u(!1),o(null);try{const _=await y.mutateAsync({subscriptionId:r,input:{new_price_id:S.price_id,effective_date:"immediate"}});o(_),u(!0)}catch(_){console.error("Failed to preview plan change:",_),i(null)}},v=async()=>{if(!(!a||!l))try{await f.mutateAsync({subscriptionId:r,input:{new_price_id:a.price_id,confirm_amount:l.proration.immediate_payment,effective_date:"immediate"}})}catch(S){console.error("Failed to change plan:",S)}},b=[...(m==null?void 0:m.available_upgrades)||[],...(m==null?void 0:m.available_downgrades)||[]],w=(j=m==null?void 0:m.current_plan)==null?void 0:j.price_id;return e.jsx(fe,{open:t,onOpenChange:s,children:e.jsxs(he,{className:"sm:max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(ge,{children:[e.jsx(pe,{children:c?"Confirm Plan Change":"Change Your Plan"}),!c&&(m==null?void 0:m.current_plan)&&e.jsxs(be,{children:["You're currently on:"," ",e.jsxs("strong",{children:[m.current_plan.product_name," (",oe.format(m.current_plan.amount,m.current_plan.currency),"/",m.current_plan.interval,")"]})]})]}),e.jsxs("div",{className:"py-4",children:[x&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(E,{className:"h-20 w-full"}),e.jsx(E,{className:"h-20 w-full"}),e.jsx(E,{className:"h-20 w-full"})]}),p&&e.jsx(Y,{variant:"destructive",children:e.jsx(G,{children:"Failed to load available plans. Please try again."})}),!x&&!p&&!c&&e.jsx("div",{className:"space-y-3",children:b.length===0?e.jsx(Y,{children:e.jsx(G,{children:"No other plans are currently available. Contact support if you need assistance."})}):e.jsxs(e.Fragment,{children:[b.map(S=>e.jsx(nn,{plan:S,isSelected:(a==null?void 0:a.price_id)===S.price_id,isCurrent:S.price_id===w,onSelect:()=>g(S),disabled:y.isPending},S.price_id)),(m==null?void 0:m.restrictions)&&m.restrictions.length>0&&e.jsx(Y,{className:"mt-4",children:e.jsxs(G,{children:[e.jsx("p",{className:"font-semibold mb-2",children:"Plan Change Restrictions:"}),e.jsx("ul",{className:"list-disc list-inside space-y-1 text-sm",children:m.restrictions.map((S,_)=>e.jsx("li",{children:S},_))})]})})]})}),y.isPending&&a&&e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("svg",{className:"animate-spin h-5 w-5",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),e.jsx("span",{children:"Calculating proration..."})]})}),y.isError&&e.jsx(Y,{variant:"destructive",children:e.jsx(G,{children:"Failed to calculate proration. Please try again."})}),c&&l&&e.jsxs("div",{children:[e.jsx(Y,{className:"mb-4",children:e.jsx(G,{className:"text-sm",children:"Please review the details below before confirming your plan change."})}),e.jsx(rn,{preview:l})]})]}),e.jsx(ve,{children:c?e.jsxs(e.Fragment,{children:[e.jsx(T,{variant:"outline",onClick:()=>{u(!1),o(null),i(null)},disabled:f.isPending,children:"Back"}),e.jsx(T,{onClick:v,disabled:f.isPending,children:f.isPending?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsxs("svg",{className:"animate-spin h-4 w-4",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Processing..."]}):`Confirm ${(l==null?void 0:l.change_type)==="upgrade"?"Upgrade":"Downgrade"}`})]}):e.jsx(T,{variant:"outline",onClick:()=>s(!1),children:"Cancel"})})]})})}const ln=[{value:"too_expensive",label:"Too expensive"},{value:"missing_features",label:"Missing features I need"},{value:"found_alternative",label:"Found a better alternative"},{value:"no_longer_needed",label:"No longer need the service"},{value:"other",label:"Other"}];function on({open:t,onOpenChange:s,periodEndDate:r,onConfirm:n,isCanceling:a}){const[i,l]=d.useState([]),[o,c]=d.useState(""),[u,m]=d.useState("period_end");d.useEffect(()=>{t&&(l([]),c(""),m("period_end"))},[t]);const x=new Date(r).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}),p=f=>{l(g=>g.includes(f)?g.filter(v=>v!==f):[...g,f])},y=()=>{n({cancelAtPeriodEnd:u==="period_end",cancellationReason:i[0],feedback:o||void 0})};return e.jsx(fe,{open:t,onOpenChange:s,children:e.jsxs(he,{className:"sm:max-w-md",children:[e.jsxs(ge,{children:[e.jsx(pe,{children:"Cancel Subscription"}),e.jsx(be,{children:"We're sorry to see you go! Help us improve by telling us why you're canceling."})]}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(V,{className:"text-sm font-medium",children:"Reason for canceling"}),ln.map(f=>e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(Oe,{checked:i.includes(f.value),onCheckedChange:()=>p(f.value)}),e.jsx("span",{className:"text-sm",children:f.label})]},f.value))]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{htmlFor:"feedback",className:"text-sm font-medium",children:"Additional feedback (optional)"}),e.jsx(ot,{id:"feedback",value:o,onChange:f=>c(f.target.value),placeholder:"What could we have done better?",className:"resize-none",rows:3})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(V,{className:"text-sm font-medium",children:"When would you like to cancel?"}),e.jsxs(st,{value:u,onValueChange:f=>m(f),children:[e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx(Fe,{value:"period_end",className:"mt-1"}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-sm font-medium",children:["Cancel at period end (",x,")"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"You'll keep access until then."})]})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx(Fe,{value:"immediately",className:"mt-1"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"Cancel immediately"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"You'll lose access now. No refunds."})]})]})]})]})]}),e.jsxs(ve,{children:[e.jsx(T,{variant:"outline",onClick:()=>s(!1),disabled:a,children:"Keep Subscription"}),e.jsx(T,{variant:"destructive",onClick:y,disabled:a,children:a?"Canceling...":"Confirm Cancellation"})]})]})})}const cn={style:{base:{fontSize:"16px",color:"hsl(var(--foreground))","::placeholder":{color:"hsl(var(--muted-foreground))"}},invalid:{color:"hsl(var(--destructive))"}}};function dn({clientSecret:t,onSuccess:s,onCancel:r}){const n=ce.useStripe(),a=ce.useElements(),[i,l]=d.useState(!1),[o,c]=d.useState(null),[u,m]=d.useState(!0),x=async p=>{if(p.preventDefault(),!n||!a)return;l(!0),c(null);const y=a.getElement(ce.CardElement);if(!y){c("Card element not found"),l(!1);return}try{const{setupIntent:f,error:g}=await n.confirmCardSetup(t,{payment_method:{card:y}});if(g){c(g.message||"Failed to set up payment method"),l(!1);return}f!=null&&f.payment_method&&s(f.payment_method,u)}catch{c("An unexpected error occurred"),l(!1)}};return e.jsxs("form",{onSubmit:x,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(V,{children:"Card Details"}),e.jsx("div",{className:"rounded-md border border-input bg-background p-3",children:e.jsx(ce.CardElement,{options:cn})})]}),o&&e.jsx("p",{className:"text-sm text-destructive",children:o}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(Oe,{checked:u,onCheckedChange:p=>m(p)}),e.jsx("span",{className:"text-sm",children:"Set as default payment method"})]})]}),e.jsxs(ve,{children:[e.jsx(T,{type:"button",variant:"outline",onClick:r,disabled:i,children:"Cancel"}),e.jsx(T,{type:"submit",disabled:!n||i,children:i?"Adding...":"Add Card"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground text-center flex items-center justify-center gap-1",children:[e.jsx(un,{className:"h-3 w-3"}),"Secured by Stripe"]})]})}function un({className:t}){return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:h("h-4 w-4",t),children:[e.jsx("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function mn(){return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{className:"h-4 w-24"}),e.jsx(E,{className:"h-12 w-full"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{className:"h-4 w-4"}),e.jsx(E,{className:"h-4 w-48"})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(E,{className:"h-10 w-20"}),e.jsx(E,{className:"h-10 w-24"})]})]})}let Qe=null;function hn(t){return Qe||(Qe=dt.loadStripe(t)),Qe}function xn({open:t,onOpenChange:s,onSuccess:r,clientSecret:n,stripePublishableKey:a,isLoading:i}){const l=()=>{s(!1)},o=(u,m)=>{r(u,m),s(!1)},c=!i&&n&&a;return e.jsx(fe,{open:t,onOpenChange:s,children:e.jsxs(he,{className:"sm:max-w-md",children:[e.jsxs(ge,{children:[e.jsx(pe,{children:"Add Payment Method"}),e.jsx(be,{children:"Enter your card details below. Your card will be saved for future payments."})]}),i&&e.jsx(mn,{}),c&&e.jsx(ce.Elements,{stripe:hn(a),children:e.jsx(dn,{clientSecret:n,onSuccess:o,onCancel:l})}),!i&&!c&&e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx("p",{children:"Unable to load payment form. Please try again."}),e.jsx(T,{variant:"outline",className:"mt-4",onClick:l,children:"Close"})]})]})})}function ps({trigger:t,onUpgrade:s,onDismiss:r}){const n=t.actual&&t.actual>=95;return e.jsx("div",{className:h("fixed top-0 left-0 right-0 z-50 animate-in slide-in-from-top duration-300","px-4 py-2"),role:n?"alert":"status",children:e.jsxs(Y,{variant:n?"destructive":"default",className:"max-w-4xl mx-auto flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3 flex-1",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:n?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-destructive",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-amber-500",children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),e.jsx("line",{x1:"12",x2:"12",y1:"9",y2:"13"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"17",y2:"17"})]})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx(Ae,{className:"mb-1 font-semibold",children:t.message.title}),e.jsx(G,{className:"text-sm",children:t.message.body})]})]}),e.jsxs("div",{className:"flex items-center gap-2 ml-4 flex-shrink-0",children:[e.jsx(T,{size:"sm",onClick:s,children:t.message.cta}),e.jsx(T,{variant:"ghost",size:"sm",onClick:r,children:"Maybe Later"})]})]})})}function ys({trigger:t,onUpgrade:s,onDismiss:r}){const n=t.actual&&t.actual>=95;return e.jsx("div",{className:h("fixed bottom-4 right-4 z-50 animate-in slide-in-from-bottom-4 duration-400","w-80 max-w-[calc(100vw-2rem)]"),role:"status","aria-live":"polite",children:e.jsxs(F,{className:"shadow-lg border-2",children:[e.jsxs(J,{className:"pb-2 pr-8 relative",children:[e.jsx("button",{onClick:r,className:"absolute top-3 right-3 p-1 rounded-md hover:bg-muted transition-colors","aria-label":"Dismiss",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})}),e.jsxs("div",{className:"flex items-start gap-2",children:[n?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-destructive flex-shrink-0 mt-0.5",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-amber-500 flex-shrink-0 mt-0.5",children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),e.jsx("line",{x1:"12",x2:"12",y1:"9",y2:"13"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"17",y2:"17"})]}),e.jsx(de,{className:"text-base font-semibold leading-tight",children:t.message.title})]})]}),e.jsxs(I,{className:"pt-0 pb-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:t.message.body}),e.jsx(T,{className:"w-full",size:"sm",onClick:s,children:t.message.cta})]})]})})}function js({trigger:t,onUpgrade:s,onDismiss:r}){const n=t.actual&&t.actual>=100,a=(i,l)=>new Intl.NumberFormat("en-US",{style:"currency",currency:l.toUpperCase(),minimumFractionDigits:0,maximumFractionDigits:0}).format(i/100);return e.jsx(fe,{open:!0,onOpenChange:i=>!i&&r(),children:e.jsxs(he,{className:"sm:max-w-md",role:n?"alertdialog":"dialog",children:[e.jsxs(ge,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[n?e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-destructive",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]}):e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-amber-500",children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"}),e.jsx("line",{x1:"12",x2:"12",y1:"9",y2:"13"}),e.jsx("line",{x1:"12",x2:"12.01",y1:"17",y2:"17"})]}),e.jsx(pe,{children:t.message.title})]}),e.jsx(be,{className:"pt-2",children:t.message.body})]}),e.jsx(F,{className:"border-2 border-primary/20",children:e.jsxs(I,{className:"pt-4",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:t.suggestedPlan.name}),e.jsxs("div",{className:"flex items-baseline gap-1 mt-1",children:[e.jsx("span",{className:"text-2xl font-bold",children:a(t.suggestedPlan.price.amount,t.suggestedPlan.price.currency)}),e.jsxs("span",{className:"text-muted-foreground text-sm",children:["/ ",t.suggestedPlan.price.interval]})]})]}),e.jsx(A,{variant:"secondary",children:"Recommended"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"What you'll get:"}),e.jsx("ul",{className:"space-y-2",children:t.suggestedPlan.highlights.map((i,l)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-green-500 flex-shrink-0 mt-0.5",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),i]},l))})]})]})}),e.jsxs(ve,{className:"flex-col sm:flex-row gap-2",children:[e.jsx(T,{variant:"outline",onClick:r,className:"sm:flex-1",children:"Maybe Later"}),e.jsxs(T,{onClick:s,className:"sm:flex-1",children:[t.message.cta," - ",a(t.suggestedPlan.price.amount,t.suggestedPlan.price.currency),"/",t.suggestedPlan.price.interval]})]})]})})}function fn(t){if(typeof window>"u")return;const s=`nudge_dismissed_${t.type}_${t.feature||"general"}`;localStorage.setItem(s,Date.now().toString())}function gn({trigger:t,style:s="banner",autoDismiss:r=0,onUpgrade:n,onDismiss:a,theme:i}){const[l,o]=d.useState(!0);d.useEffect(()=>{o(!0)},[t,s]),d.useEffect(()=>{if(r>0&&l){const m=setTimeout(()=>{c()},r);return()=>clearTimeout(m)}},[r,l]),d.useEffect(()=>{const m=x=>{x.key==="Escape"&&l&&c()};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[l]);const c=()=>{o(!1),fn(t),a==null||a()},u=()=>{n==null||n(t.suggestedPlan.priceId)};if(!l)return null;switch(s){case"banner":return e.jsx(ps,{trigger:t,onUpgrade:u,onDismiss:c,theme:i});case"toast":return e.jsx(ys,{trigger:t,onUpgrade:u,onDismiss:c,theme:i});case"modal":return e.jsx(js,{trigger:t,onUpgrade:u,onDismiss:c,theme:i});default:return null}}function pn(t={}){const{client:s}=D(),{enabled:r=!0,refetchInterval:n=0}=t;return P.useQuery({queryKey:["usageCheck"],queryFn:async()=>s.checkUsage(),enabled:r,staleTime:300*1e3,gcTime:600*1e3,refetchInterval:n>0?n:void 0})}function yn({feature:t,children:s,fallback:r,loading:n,onAccessDenied:a,onQuotaExceeded:i,showUsageBadge:l=!1}){const{hasAccess:o,isLoading:c,isError:u,usage:m,limit:x,remaining:p}=Nt(t,{onAccessDenied:a,onQuotaExceeded:i});return c?e.jsx(e.Fragment,{children:n||e.jsx(jn,{})}):u||!o?e.jsx(e.Fragment,{children:r||e.jsx(vn,{feature:t})}):l&&x>0?e.jsxs("div",{className:"relative",children:[s,e.jsx(bn,{usage:m,limit:x,remaining:p})]}):e.jsx(e.Fragment,{children:s})}function jn(){return e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx("div",{className:"animate-pulse text-gray-400",children:"Checking access..."})})}function vn({feature:t}){return e.jsx("div",{className:"p-4 border border-gray-200 bg-gray-50 rounded-lg",children:e.jsxs("div",{className:"text-center",children:[e.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})}),e.jsx("h3",{className:"mt-2 text-sm font-medium text-gray-900",children:"Feature Locked"}),e.jsxs("p",{className:"mt-1 text-sm text-gray-500",children:["Upgrade your plan to access ",t.replace(/_/g," ")]})]})})}function bn({usage:t,limit:s,remaining:r}){const n=Math.min(100,Math.round(t/s*100));let a="bg-green-100 text-green-800";return n>=90?a="bg-red-100 text-red-800":n>=75&&(a="bg-yellow-100 text-yellow-800"),e.jsxs("div",{className:`absolute top-2 right-2 px-2 py-1 rounded-full text-xs font-medium ${a}`,children:[r.toLocaleString()," / ",s.toLocaleString()," remaining"]})}function wn({featureKey:t,title:s="Usage Metrics",showProgress:r=!0,showResetTimer:n=!0,className:a=""}){const{data:i,isLoading:l,isError:o}=Ye(t);return l?e.jsxs("div",{className:`p-4 animate-pulse ${a}`,children:[e.jsx("div",{className:"h-4 bg-gray-200 rounded w-1/4 mb-4"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded"}),e.jsx("div",{className:"h-8 bg-gray-200 rounded"})]})]}):o||!(i!=null&&i.metrics)||i.metrics.length===0?e.jsx("div",{className:`p-4 text-center text-gray-500 ${a}`,children:"No usage data available"}):e.jsxs("div",{className:`p-4 ${a}`,children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:s}),e.jsx("div",{className:"space-y-4",children:i.metrics.map(c=>e.jsx(Nn,{metric:c,showProgress:r,showResetTimer:n},c.feature_key))})]})}function Nn({metric:t,showProgress:s,showResetTimer:r}){const n=a=>a>=90?"bg-red-500":a>=75?"bg-yellow-500":"bg-green-500";return e.jsxs("div",{className:"border border-gray-200 rounded-lg p-4 bg-white",children:[e.jsxs("div",{className:"flex justify-between items-start mb-2",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-gray-900",children:t.feature_title}),e.jsx("p",{className:"text-sm text-gray-500",children:t.product_name})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-2xl font-semibold",children:t.consumed.toLocaleString()}),e.jsxs("div",{className:"text-sm text-gray-500",children:["of ",t.limit.toLocaleString()]})]})]}),s&&e.jsxs("div",{className:"mt-3",children:[e.jsx("div",{className:"w-full bg-gray-200 rounded-full h-2",children:e.jsx("div",{className:`h-2 rounded-full transition-all ${n(t.percentage_used)}`,style:{width:`${Math.min(100,t.percentage_used)}%`}})}),e.jsxs("div",{className:"flex justify-between mt-1",children:[e.jsxs("span",{className:"text-xs text-gray-500",children:[t.percentage_used,"% used"]}),e.jsxs("span",{className:"text-xs text-gray-500",children:[t.remaining.toLocaleString()," remaining"]})]})]}),r&&t.resets_in_days>0&&e.jsxs("div",{className:"mt-2 text-xs text-gray-500",children:[e.jsx("svg",{className:"inline-block w-3 h-3 mr-1",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Resets in ",t.resets_in_days," day",t.resets_in_days!==1?"s":""]})]})}function Cn({featureKey:t,className:s=""}){var l;const{data:r,isLoading:n}=Ye(t);if(n||!((l=r==null?void 0:r.metrics)!=null&&l[0]))return null;const a=r.metrics[0],i=o=>o>=90?"text-red-600":o>=75?"text-yellow-600":"text-green-600";return e.jsxs("div",{className:`inline-flex items-center gap-2 ${s}`,children:[e.jsx("span",{className:"text-sm text-gray-500",children:"Usage:"}),e.jsxs("span",{className:`text-sm font-medium ${i(a.percentage_used)}`,children:[a.consumed.toLocaleString()," / ",a.limit.toLocaleString()]}),a.percentage_used>=90&&e.jsx("svg",{className:"w-4 h-4 text-red-500",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})]})}function Sn({feature:t,title:s="Upgrade Required",description:r,isQuotaExceeded:n=!1,usage:a,limit:i,className:l="",onUpgradeClick:o}){const{data:c}=Ct(),u=n?`You've reached your usage limit${t?` for ${t}`:""}. Upgrade your plan to continue.`:`Upgrade your plan to access${t?` ${t}`:" this feature"}.`,m=()=>{if(o)o();else{const x=document.querySelector("[data-pricing-table]");x&&x.scrollIntoView({behavior:"smooth",block:"center"})}};return e.jsx("div",{className:`rounded-lg border-2 border-dashed border-gray-300 p-8 ${l}`,children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-gradient-to-br from-blue-500 to-purple-600",children:e.jsx("svg",{className:"h-6 w-6 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})})}),e.jsx("h3",{className:"mt-4 text-lg font-semibold text-gray-900",children:s}),e.jsx("p",{className:"mt-2 text-sm text-gray-600",children:r||u}),n&&a!==void 0&&i!==void 0&&e.jsxs("div",{className:"mt-4 inline-flex items-center gap-2 rounded-full bg-red-50 px-3 py-1",children:[e.jsx("svg",{className:"h-4 w-4 text-red-500",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})}),e.jsxs("span",{className:"text-sm font-medium text-red-800",children:[a.toLocaleString()," / ",i.toLocaleString()," used"]})]}),e.jsx("div",{className:"mt-6",children:e.jsxs("button",{onClick:m,className:"inline-flex items-center rounded-md bg-gradient-to-r from-blue-600 to-purple-600 px-6 py-3 text-sm font-semibold text-white shadow-sm hover:from-blue-700 hover:to-purple-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2",children:[e.jsx("svg",{className:"mr-2 h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 10l7-7m0 0l7 7m-7-7v18"})}),"Upgrade Plan"]})}),(c==null?void 0:c.products)&&c.products.length>0&&e.jsxs("div",{className:"mt-6 text-xs text-gray-500",children:["Available plans:",e.jsx("div",{className:"mt-1 flex justify-center gap-2",children:c.products.slice(0,3).map(x=>e.jsx("span",{className:"inline-block rounded-full bg-gray-100 px-2 py-1",children:x.name},x.id))})]})]})})}function kn({feature:t,onUpgradeClick:s,className:r=""}){return e.jsxs("div",{className:`inline-flex items-center gap-2 rounded-md bg-yellow-50 px-3 py-2 ${r}`,children:[e.jsx("svg",{className:"h-4 w-4 text-yellow-600",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M10 1.944A11.954 11.954 0 012.166 5C2.056 5.649 2 6.319 2 7c0 5.225 3.34 9.67 8 11.317C14.66 16.67 18 12.225 18 7c0-.682-.057-1.35-.166-2.001A11.954 11.954 0 0110 1.944zM11 14a1 1 0 11-2 0 1 1 0 012 0zm0-7a1 1 0 10-2 0v3a1 1 0 102 0V7z",clipRule:"evenodd"})}),e.jsxs("span",{className:"text-sm text-yellow-800",children:["Upgrade to access",t?` ${t}`:" this feature"]}),e.jsx("button",{onClick:s,className:"ml-1 text-sm font-medium text-yellow-800 hover:text-yellow-900 underline",children:"Upgrade"})]})}const vs=(t,s="PPP")=>{const r=typeof t=="string"?re.parseISO(t):t;return re.format(r,s)},bs=(t,s=new Date)=>{const r=typeof t=="string"?re.parseISO(t):t;return re.formatDistance(r,s,{addSuffix:!0})},ws=(t,s=new Date)=>{const r=typeof t=="string"?re.parseISO(t):t;return re.formatRelative(r,s)},Ns=t=>{const s=typeof t=="string"?re.parseISO(t):t;return re.isBefore(s,new Date)},Cs=t=>{const s=typeof t=="string"?re.parseISO(t):t;return re.isAfter(s,new Date)},Ss=t=>re.parseISO(t),Pn={format:vs,formatRelative:bs,formatRelativeDate:ws,isPast:Ns,isFuture:Cs,parse:Ss};console.log("%c🎯 BillingOS SDK v1.2.0 loaded with Iframe Checkout","background: #3b82f6; color: white; padding: 6px 12px; border-radius: 6px; font-weight: bold; font-size: 14px;");typeof window<"u"&&(window.billingOS={checkout:{open:async t=>Se().open(t)}});Object.defineProperty(exports,"useBillingOSQueryClient",{enumerable:!0,get:()=>P.useQueryClient});exports.AddPaymentMethodModal=xn;exports.Alert=Y;exports.AlertDescription=G;exports.AlertTitle=Ae;exports.Badge=A;exports.BannerNudge=ps;exports.BillingOSClient=We;exports.BillingOSError=ne;exports.BillingOSProvider=ht;exports.Button=T;exports.CancelSubscriptionModal=on;exports.Card=F;exports.CardContent=I;exports.CardDescription=Be;exports.CardFooter=Ge;exports.CardHeader=J;exports.CardTitle=de;exports.ChangePlanModal=an;exports.Checkbox=Oe;exports.CheckoutAPI=vt;exports.CheckoutModal=Me;exports.CompactUpgradePrompt=kn;exports.CompactUsageDisplay=Cn;exports.CustomerPortal=wr;exports.DateUtils=Pn;exports.Dialog=fe;exports.DialogContent=he;exports.DialogDescription=be;exports.DialogFooter=ve;exports.DialogHeader=ge;exports.DialogOverlay=Ve;exports.DialogPortal=Ws;exports.DialogTitle=pe;exports.DialogTrigger=yt;exports.Drawer=Et;exports.DrawerClose=Tt;exports.DrawerContent=Xe;exports.DrawerDescription=et;exports.DrawerFooter=_t;exports.DrawerHeader=Je;exports.DrawerTitle=Ze;exports.DrawerTrigger=Dt;exports.FeatureGate=yn;exports.FeatureList=rs;exports.Input=te;exports.InvoiceCard=xs;exports.InvoicesTab=Vr;exports.Label=V;exports.ModalNudge=js;exports.Money=oe;exports.NetworkError=Ce;exports.NotFoundError=De;exports.PaymentBottomSheet=es;exports.PaymentMethodCard=fs;exports.PaymentMethodsTab=Zr;exports.PricingCard=br;exports.PricingTable=ts;exports.Progress=tt;exports.RadioGroup=st;exports.RadioGroupItem=Fe;exports.RateLimitError=_e;exports.ScrollArea=Rt;exports.ScrollBar=Mt;exports.Select=rt;exports.SelectOption=nt;exports.Separator=ke;exports.ServerError=Ie;exports.SettingsTab=sn;exports.Sheet=It;exports.SheetClose=At;exports.SheetContent=at;exports.SheetDescription=qt;exports.SheetFooter=Ot;exports.SheetHeader=it;exports.SheetTitle=lt;exports.SheetTrigger=Ut;exports.Skeleton=E;exports.SubscriptionTab=$r;exports.Tabs=Ht;exports.TabsContent=Wt;exports.TabsList=Qt;exports.TabsTrigger=Kt;exports.Textarea=ot;exports.ToastNudge=ys;exports.UnauthorizedError=Ee;exports.UpgradeNudge=gn;exports.UpgradePrompt=Sn;exports.UsageBar=ss;exports.UsageDisplay=wn;exports.ValidationError=Te;exports.WarningBanner=Re;exports.addAmounts=hs;exports.badgeVariants=St;exports.buttonVariants=kt;exports.calculatePercentage=ms;exports.cn=h;exports.convertCentsToFloat=ns;exports.convertFloatToCents=as;exports.createBillingOSClient=As;exports.entitlementKeys=me;exports.formatCurrencyAndAmount=je;exports.formatCurrencyCompact=is;exports.formatCurrencyWhole=ls;exports.formatDate=vs;exports.formatPriceRange=cs;exports.formatRelativeDate=ws;exports.formatRelativeTime=bs;exports.getCentsInDollarString=Ar;exports.getCheckoutAPI=Se;exports.getCurrencySymbol=os;exports.isFuture=Cs;exports.isNegativeAmount=us;exports.isNotFoundError=Is;exports.isPast=Ns;exports.isRateLimitError=Us;exports.isUnauthorizedError=Fs;exports.isValidationError=Ms;exports.isZeroAmount=ds;exports.openCheckout=Js;exports.parseDate=Ss;exports.portalKeys=ee;exports.subscriptionKeys=q;exports.useAddPaymentMethod=Er;exports.useAvailablePlans=xt;exports.useBillingOS=D;exports.useCancelPortalSubscription=Sr;exports.useCancelSubscription=Hs;exports.useChangePlan=gt;exports.useCheckEntitlement=bt;exports.useCheckout=Zs;exports.useConfirmCheckout=gr;exports.useCreateCheckout=Zt;exports.useCreateSubscription=zs;exports.useEntitlements=tr;exports.useFeature=wt;exports.useFeatureEntitlements=ar;exports.useFeatureGate=Nt;exports.useHasFeature=er;exports.useIsApproachingLimit=rr;exports.usePortalData=Nr;exports.usePreviewPlanChange=ft;exports.usePricingTableProducts=Jt;exports.useProducts=Ct;exports.useReactivatePortalSubscription=kr;exports.useReactivateSubscription=Qs;exports.useRemovePaymentMethod=Dr;exports.useRetryInvoice=_r;exports.useSessionToken=ut;exports.useSetDefaultPaymentMethod=Tr;exports.useSetupIntent=Pr;exports.useSubscription=Os;exports.useSubscriptionPreview=Ks;exports.useSubscriptions=qs;exports.useTrackUsage=nr;exports.useUpdateCustomerBilling=Lr;exports.useUpdatePortalSubscription=Cr;exports.useUpdateSubscription=$s;exports.useUsageCheck=pn;exports.useUsageMetrics=Ye;
5
5
  //# sourceMappingURL=index.js.map