@cedros/pay-react 1.1.21 → 1.1.22

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.
Files changed (28) hide show
  1. package/dist/{AISettingsSection-BXWZcMQT.js → AISettingsSection-BtOxEweU.js} +1 -1
  2. package/dist/{AISettingsSection-8eDaxYp8.mjs → AISettingsSection-p3iikbSw.mjs} +2 -2
  3. package/dist/{AutosaveIndicator-DW4IPbZ5.js → AutosaveIndicator-C-CH-obR.js} +1 -1
  4. package/dist/{AutosaveIndicator-3S7EvXip.mjs → AutosaveIndicator-CWbb-VXf.mjs} +1 -1
  5. package/dist/{FAQSection-r6eKjfdO.js → FAQSection-DQpF7hVx.js} +1 -1
  6. package/dist/{FAQSection-Dg-I7Z-N.mjs → FAQSection-byh7zfqI.mjs} +1 -1
  7. package/dist/{MessagingSection-Cld5Q7ZM.js → MessagingSection-B6EHvjDw.js} +1 -1
  8. package/dist/{MessagingSection-D39EuOLN.mjs → MessagingSection-CK208brx.mjs} +2 -2
  9. package/dist/{PaymentSettingsSection-CEGHN6VI.mjs → PaymentSettingsSection-B9H253x1.mjs} +1 -1
  10. package/dist/{PaymentSettingsSection-B-MRsh1K.js → PaymentSettingsSection-Cmmuhmd4.js} +1 -1
  11. package/dist/{SettingsSection-CPFOuoZG.mjs → SettingsSection-DDLMaEPo.mjs} +1 -1
  12. package/dist/{SettingsSection-ZrzfLBlS.js → SettingsSection-DrzGdvHH.js} +1 -1
  13. package/dist/{SingleCategorySettings-DhHGIGwB.mjs → SingleCategorySettings-BU98SRFV.mjs} +56 -56
  14. package/dist/SingleCategorySettings-DqcXe-q4.js +3 -0
  15. package/dist/{StorefrontSection-DGVcJu1T.js → StorefrontSection-DTpZ_GgO.js} +1 -1
  16. package/dist/{StorefrontSection-f54ySA6i.mjs → StorefrontSection-Dr2ciBVg.mjs} +2 -2
  17. package/dist/{SubscriptionsSection-F2IiU2jv.mjs → SubscriptionsSection-CU3Ce8r9.mjs} +1 -1
  18. package/dist/{SubscriptionsSection-fzbL5DGC.js → SubscriptionsSection-CYJpArJ8.js} +1 -1
  19. package/dist/crypto-only.js +1 -1
  20. package/dist/crypto-only.mjs +1 -1
  21. package/dist/{index-bqhsxBTY.mjs → index-CufXF9Yd.mjs} +18 -18
  22. package/dist/{index-7YUxR4u5.js → index-IZ4WcMd7.js} +1 -1
  23. package/dist/index.js +1 -1
  24. package/dist/index.mjs +1 -1
  25. package/dist/{sections-CiAMjlPd.mjs → sections-Bc6ARlND.mjs} +1 -1
  26. package/dist/{sections-Dh0qFSUW.js → sections-CR7NRsjq.js} +1 -1
  27. package/package.json +1 -1
  28. package/dist/SingleCategorySettings-DxjCafCk.js +0 -3
@@ -0,0 +1,3 @@
1
+ "use strict";const e=require("react/jsx-runtime"),m=require("react"),w=require("./index-IZ4WcMd7.js"),J=require("./useAutosave-B2p6iwh8.js"),$=require("./AutosaveIndicator-C-CH-obR.js"),P=require("./CedrosContext-D-lnoEkR.js");class G{constructor(n,a,i){this._serverUrl=n,this.auth=a,this.authManager=i}get serverUrl(){return this._serverUrl}async fetch(n,a={}){if(this.authManager?.isAuthenticated())return this.authManager.fetchWithAuth(n,a);throw this.auth?new Error("Legacy AdminAuth is no longer supported due to replay vulnerability. Use IAdminAuthManager instead."):new Error("Admin authentication required. Provide an IAdminAuthManager to ConfigApi.")}async listCategories(n=100){return this.fetch(`/admin/config?limit=${n}`)}async getConfig(n,a=!0){return this.fetch(`/admin/config/${n}?redact_secrets=${a}`)}async updateConfig(n,a,i){await this.fetch(`/admin/config/${n}`,{method:"PUT",body:JSON.stringify({config:a,description:i})})}async patchConfig(n,a,i){await this.fetch(`/admin/config/${n}`,{method:"PATCH",body:JSON.stringify({updates:a,description:i})})}async batchUpdate(n){await this.fetch("/admin/config/batch",{method:"POST",body:JSON.stringify({updates:n})})}async validateConfig(n,a){return this.fetch("/admin/config/validate",{method:"POST",body:JSON.stringify({category:n,config:a})})}async getHistory(n,a=50){const i=new URLSearchParams({limit:a.toString()});return n&&i.set("category",n),this.fetch(`/admin/config/history?${i}`)}}const O={server:{label:"Server",secrets:[],icon:"🖥️",fields:{admin_metrics_api_key:{hidden:!0},cors_allowed_origins:{hidden:!0}}},security:{label:"Security",description:"Configure CORS, rate limiting, and other security settings",secrets:[],icon:"🔒",fields:{cors_allowed_origins:{description:'List of allowed origins for CORS requests. Use ["*"] to allow all origins (not recommended for production).'}}},metrics:{label:"Metrics",description:"Configure metrics collection and API access",secrets:["admin_metrics_api_key"],icon:"📊",fields:{admin_metrics_api_key:{description:"API key for accessing the admin metrics endpoint. Keep this secret."}}},logging:{label:"Logging",secrets:[],icon:"📝",fields:{level:{type:"dropdown",options:["trace","debug","info","warn","error"]},format:{hidden:!0},environment:{hidden:!0}}},stripe:{label:"Stripe",secrets:["secret_key","webhook_secret"],icon:"💳",fields:{enabled:{hidden:!0},secret_key:{description:"Stripe Dashboard → Developers → API keys → Secret key. Use the test key (sk_test_...) for testing, or the live key (sk_live_...) for production."},publishable_key:{description:"Stripe Dashboard → Developers → API keys → Publishable key. Starts with pk_test_... or pk_live_..."},mode:{type:"dropdown",options:["test","live"],description:'Use "test" mode with test API keys during development, then switch to "live" with live keys for real payments.'},webhook_url:{description:"The full URL Stripe sends webhook events to. Default is your server URL + /webhook/stripe (e.g. https://example.com/webhook/stripe). Only change this if you've customized the route in your cedros-pay server."},webhook_secret:{description:`Stripe Dashboard → Developers → Webhooks → "Create an event destination" → select events: checkout.session.completed, customer.subscription.created, customer.subscription.updated, customer.subscription.deleted, invoice.paid, invoice.payment_failed → Continue → choose "Webhook endpoint" → enter your server's webhook endpoint, e.g. https://example.com/webhook/stripe (your server URL + /webhook/stripe) → after creating, click the endpoint and "Click to reveal" the signing secret. Starts with whsec_...`},tax_rate_id:{description:`Stripe Dashboard → More → Product catalog → Tax rates → "+ New" → set the percentage, region, and whether tax is inclusive or exclusive → Save → copy the tax rate ID from the detail page (starts with txr_...). Leave empty if you don't collect tax.`},success_url:{hidden:!0},cancel_url:{hidden:!0}}},x402:{label:"X402 (Crypto)",secrets:["server_wallets"],icon:"⚡",fields:{enabled:{hidden:!0},payment_address:{type:"solana_address",description:"The Solana wallet address where payments are received. This is where customer funds are sent."},token_mint:{type:"token_mint",description:"The SPL token used for payments. Most commonly USDC."},token_decimals:{type:"number",description:"Number of decimal places for the token (e.g., USDC has 6 decimals).",hidden:!0},custom_token_symbol:{description:'Display symbol for your custom token (e.g., "MYTOKEN").',hidden:!0},custom_token_icon:{description:"URL to your token's icon image.",hidden:!0},rpc_url:{description:"Solana RPC endpoint URL. Required for crypto payment verification (e.g., from Helius, QuickNode, or Alchemy)."},gasless_enabled:{type:"toggle",description:"When enabled, your server pays transaction fees so customers don't need SOL."},server_wallets:{type:"secret_array",description:"Server keypair(s) used to sign and pay for transactions. Required for gasless payments.",showWhen:"gasless_enabled"},rounding_mode:{type:"dropdown",options:["nearest","up","down"],description:"How to round fractional token amounts: nearest (default), up (always round up), or down (always round down)."},network:{hidden:!0},ws_url:{hidden:!0},skip_preflight:{hidden:!0},commitment:{hidden:!0},compute_unit_limit:{hidden:!0},compute_unit_price:{hidden:!0}}},paywall:{label:"Paywall",secrets:[],icon:"🚪",fields:{product_cache_ttl:{type:"number",unit:"seconds"}}},coupons:{label:"Coupons",secrets:[],icon:"🎟️",fields:{cache_ttl:{type:"number",unit:"seconds"}}},subscriptions:{label:"Subscriptions",secrets:[],icon:"🔄",fields:{grace_period_hours:{type:"number",unit:"hours"}}},callbacks:{label:"Callbacks",secrets:["hmac_secret"],icon:"🔔"},email:{label:"Email",description:"Email receipts for customers after purchase",secrets:["smtp_password"],icon:"📧",fields:{enabled:{hidden:!0},provider:{type:"dropdown",options:["sendgrid","mailgun","postmark","ses","resend","custom"],description:"Email service provider."},smtp_host:{description:"SMTP server hostname.",showWhen:"provider"},smtp_port:{type:"number",description:"SMTP server port (typically 587 for TLS).",showWhen:"provider"},smtp_user:{description:"SMTP authentication username or API key name.",showWhen:"provider"},smtp_password:{description:"SMTP password or API key.",showWhen:"provider"},from_address:{description:"Sender email address (e.g., orders@yourstore.com)."},from_name:{description:'Sender display name (e.g., "Your Store").'}}},webhook:{label:"Webhook",description:"HTTP notifications when purchases occur",secrets:["secret"],icon:"🔔",fields:{enabled:{hidden:!0},url:{description:"URL to receive POST notifications (e.g., https://api.yoursite.com/webhooks/orders)."},secret:{description:"Shared secret for HMAC-SHA256 signature verification."},retry_attempts:{type:"number",description:"Number of retry attempts on failure (default: 3)."}}},messaging:{label:"Messaging",description:"Email and webhook notifications for purchases",secrets:["smtp_password","webhook_secret"],icon:"📬",fields:{email_enabled:{type:"boolean",description:"Send order confirmation emails to customers."},email_provider:{description:"Email service provider (mailgun, sendgrid, postmark, ses, resend, custom).",showWhen:"email_enabled"},smtp_host:{description:"SMTP server hostname.",showWhen:"email_enabled"},smtp_port:{type:"number",description:"SMTP server port (typically 587 for TLS).",showWhen:"email_enabled"},smtp_username:{description:"SMTP authentication username or API key.",showWhen:"email_enabled"},smtp_password:{description:"SMTP password or API key.",showWhen:"email_enabled"},from_email:{description:"Sender email address (e.g., orders@yourstore.com).",showWhen:"email_enabled"},from_name:{description:'Sender display name (e.g., "Your Store").',showWhen:"email_enabled"},webhook_enabled:{type:"boolean",description:"Send webhook notifications when purchases complete."},webhook_url:{description:"URL to receive POST notifications.",showWhen:"webhook_enabled"},webhook_secret:{description:"Shared secret for HMAC-SHA256 signature verification.",showWhen:"webhook_enabled"},webhook_timeout:{type:"number",description:"Request timeout in seconds (default: 30).",showWhen:"webhook_enabled"}}},monitoring:{label:"Monitoring",secrets:[],icon:"📊",fields:{check_interval:{type:"number",unit:"seconds"},low_balance_threshold:{type:"number",unit:"SOL"}}},rate_limit:{label:"Rate Limiting",secrets:[],icon:"⏱️"},circuit_breaker:{label:"Circuit Breaker",secrets:[],icon:"🔌"},admin:{label:"Admin Keys",secrets:[],icon:"👤"},api_keys:{label:"API Keys",secrets:[],icon:"🔐"},cedros_login:{label:"Cedros Login",secrets:["api_key"],icon:"🔑",fields:{enabled:{hidden:!0},credits_enabled:{hidden:!0},base_url:{hidden:!0},timeout:{hidden:!0},jwt_issuer:{hidden:!0},jwt_audience:{hidden:!0}}},shop:{label:"Storefront",description:"Product pages & display settings",secrets:[],icon:"🏪",fields:{enabled:{hidden:!0},"relatedProducts.mode":{type:"dropdown",options:["most_recent","by_category","manual","ai"]},"relatedProducts.maxItems":{type:"number"}}}};function F(b,n){return O[b]?.secrets.includes(n)??!1}const D="[REDACTED]",Y=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function W(b){return!b||b.trim()===""?{valid:!0}:Y.test(b.trim())?{valid:!0}:{valid:!1,error:"Invalid Solana address"}}function X({label:b,value:n,onChange:a,decimals:i,onDecimalsChange:S,disabled:d=!1,description:c,customSymbol:l="",customIcon:h="",onCustomSymbolChange:p,onCustomIconChange:y}){const[x,N]=m.useState(!1),f=Object.entries(P.STABLECOIN_METADATA),_=!!P.STABLECOIN_METADATA[n],k=x||!!n&&!_,j=t=>{if(t==="custom")N(!0),_&&a("");else{N(!1),a(t);const s=P.STABLECOIN_METADATA[t];s&&S&&S(s.decimals),p&&p(""),y&&y("")}};return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:b}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[e.jsxs("div",{style:{display:"flex",flexWrap:"wrap",gap:"0.5rem"},children:[f.map(([t,s])=>e.jsxs("button",{type:"button",onClick:()=>j(t),disabled:d,style:{display:"flex",alignItems:"center",gap:"0.5rem",padding:"0.5rem 0.75rem",border:n===t?"2px solid var(--cedros-admin-primary, #171717)":"1px solid var(--cedros-admin-border, #d4d4d4)",borderRadius:"0.5rem",background:n===t?"var(--cedros-admin-primary-bg, #f5f5f5)":"var(--cedros-admin-bg, #fff)",cursor:d?"not-allowed":"pointer",opacity:d?.5:1,fontWeight:n===t?600:400},children:[e.jsx("img",{src:s.icon,alt:s.symbol,style:{width:20,height:20,borderRadius:"50%"},onError:r=>{r.target.style.display="none"}}),e.jsx("span",{children:s.symbol})]},t)),e.jsxs("button",{type:"button",onClick:()=>j("custom"),disabled:d,style:{display:"flex",alignItems:"center",gap:"0.5rem",padding:"0.5rem 0.75rem",border:k?"2px solid var(--cedros-admin-primary, #171717)":"1px solid var(--cedros-admin-border, #d4d4d4)",borderRadius:"0.5rem",background:k?"var(--cedros-admin-primary-bg, #f5f5f5)":"var(--cedros-admin-bg, #fff)",cursor:d?"not-allowed":"pointer",opacity:d?.5:1,fontWeight:k?600:400},children:[e.jsx("span",{style:{fontSize:"1rem"},children:"+"}),e.jsx("span",{children:"Custom"})]})]}),k&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem",padding:"1rem",background:"var(--cedros-admin-bg-muted, #f9fafb)",borderRadius:"0.5rem",border:"1px solid var(--cedros-admin-border, #e5e7eb)"},children:[e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:"0.75rem",fontWeight:500,marginBottom:"0.25rem",color:"var(--cedros-admin-text-muted, #64748b)"},children:"Token Mint Address"}),(()=>{const t=W(n);return e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",className:`cedros-admin__input ${t.valid?"":"cedros-admin__input--error"}`,value:n,onChange:s=>a(s.target.value),placeholder:"e.g., EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",disabled:d,style:{fontFamily:"monospace",fontSize:"0.875rem",borderColor:t.valid?void 0:"var(--cedros-admin-error, #dc2626)"}}),!t.valid&&e.jsx("span",{style:{color:"var(--cedros-admin-error, #dc2626)",fontSize:"0.75rem",marginTop:"0.25rem",display:"block"},children:t.error})]})})()]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:"0.75rem",fontWeight:500,marginBottom:"0.25rem",color:"var(--cedros-admin-text-muted, #64748b)"},children:"Token Symbol"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:l,onChange:t=>p?.(t.target.value),placeholder:"e.g., MYTOKEN",disabled:d,style:{textTransform:"uppercase"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:"0.75rem",fontWeight:500,marginBottom:"0.25rem",color:"var(--cedros-admin-text-muted, #64748b)"},children:"Token Icon URL"}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center"},children:[e.jsx("input",{type:"text",className:"cedros-admin__input",value:h,onChange:t=>y?.(t.target.value),placeholder:"https://example.com/token-logo.png",disabled:d,style:{flex:1}}),h&&e.jsx("img",{src:h,alt:"Token icon preview",style:{width:32,height:32,borderRadius:"50%",border:"1px solid var(--cedros-admin-border, #e5e7eb)",objectFit:"cover"},onError:t=>{t.target.style.display="none"}})]}),e.jsx("div",{style:{fontSize:"0.7rem",color:"var(--cedros-admin-text-muted, #94a3b8)",marginTop:"0.25rem"},children:"Shown to customers during checkout"})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:"0.75rem",fontWeight:500,marginBottom:"0.25rem",color:"var(--cedros-admin-text-muted, #64748b)"},children:"Token Decimals"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:i??6,onChange:t=>S?.(parseInt(t.target.value,10)||0),min:0,max:18,disabled:d,style:{width:"100px"}}),e.jsx("div",{style:{fontSize:"0.7rem",color:"var(--cedros-admin-text-muted, #94a3b8)",marginTop:"0.25rem"},children:"Most SPL tokens use 6 decimals (like USDC)"})]})]}),n&&_&&e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--cedros-admin-text-muted, #64748b)",fontFamily:"monospace",wordBreak:"break-all"},children:n}),c&&e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--cedros-admin-text-muted, #64748b)",marginTop:"0.25rem"},children:c})]})]})}function Z({label:b,value:n,onChange:a,disabled:i=!1,description:S}){const[d,c]=m.useState(new Set),[l,h]=m.useState(null),[p,y]=m.useState(""),x=Array.isArray(n)?n:[],N=t=>{c(s=>{const r=new Set(s);return r.has(t)?r.delete(t):r.add(t),r})},f=()=>{a([...x,""]),h(x.length),y("")},E=(t,s)=>{const r=[...x];r[t]=s,a(r)},_=t=>{const s=x.filter((r,g)=>g!==t);a(s),c(r=>{const g=new Set;return r.forEach(v=>{v<t?g.add(v):v>t&&g.add(v-1)}),g})},T=t=>{h(t),y(x[t]||"")},k=()=>{l!==null&&(E(l,p),h(null),y(""))},j=()=>{l!==null&&x[l]===""&&_(l),h(null),y("")};return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"0.5rem"},children:[e.jsx("label",{className:"cedros-admin__field-label",style:{marginBottom:0},children:b}),e.jsxs("button",{type:"button",onClick:f,disabled:i,style:{display:"flex",alignItems:"center",gap:"0.25rem",padding:"0.25rem 0.5rem",fontSize:"0.75rem",border:"1px solid var(--cedros-admin-border, #d4d4d4)",borderRadius:"0.375rem",background:"var(--cedros-admin-bg, #fff)",cursor:i?"not-allowed":"pointer",opacity:i?.5:1},children:[w.Icons.plus,"Add"]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[x.length===0&&e.jsx("div",{style:{padding:"1rem",textAlign:"center",color:"var(--cedros-admin-text-muted, #64748b)",fontSize:"0.875rem",border:"1px dashed var(--cedros-admin-border, #d4d4d4)",borderRadius:"0.5rem"},children:'No items. Click "Add" to create one.'}),x.map((t,s)=>{const r=d.has(s),g=l===s,v=t===D;return e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",padding:"0.5rem",background:"var(--cedros-admin-bg-muted, #f9fafb)",borderRadius:"0.375rem",border:"1px solid var(--cedros-admin-border, #e5e7eb)"},children:g?e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",className:"cedros-admin__input",value:p,onChange:o=>y(o.target.value),placeholder:"Enter wallet keypair...",autoFocus:!0,style:{flex:1,fontFamily:"monospace",fontSize:"0.75rem"},onKeyDown:o=>{o.key==="Enter"&&k(),o.key==="Escape"&&j()}}),e.jsx("button",{type:"button",onClick:k,style:{padding:"0.375rem",border:"none",background:"var(--cedros-admin-success, #22c55e)",color:"#fff",borderRadius:"0.25rem",cursor:"pointer"},title:"Save",children:w.Icons.check}),e.jsx("button",{type:"button",onClick:j,style:{padding:"0.375rem",border:"none",background:"var(--cedros-admin-text-muted, #64748b)",color:"#fff",borderRadius:"0.25rem",cursor:"pointer"},title:"Cancel",children:w.Icons.close})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{flex:1,fontFamily:"monospace",fontSize:"0.75rem",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r&&!v?t:v?"[REDACTED]":"••••••••••••••••••••"}),e.jsx("button",{type:"button",onClick:()=>N(s),disabled:i||v,style:{padding:"0.375rem",border:"none",background:"transparent",cursor:i||v?"not-allowed":"pointer",opacity:i||v?.5:1,color:"var(--cedros-admin-text-muted, #64748b)"},title:r?"Hide":"Show",children:r?w.Icons.eyeOff:w.Icons.eye}),e.jsx("button",{type:"button",onClick:()=>T(s),disabled:i,style:{padding:"0.375rem",border:"none",background:"transparent",cursor:i?"not-allowed":"pointer",opacity:i?.5:1,color:"var(--cedros-admin-text-muted, #64748b)"},title:"Edit",children:w.Icons.settings}),e.jsx("button",{type:"button",onClick:()=>_(s),disabled:i,style:{padding:"0.375rem",border:"none",background:"transparent",cursor:i?"not-allowed":"pointer",opacity:i?.5:1,color:"var(--cedros-admin-error, #ef4444)"},title:"Delete",children:w.Icons.trash})]})},s)})]}),S&&e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--cedros-admin-text-muted, #64748b)",marginTop:"0.5rem"},children:S})]})}function L(b,n,a){const i=F(b,n),S=n.replace(/_/g," ").replace(/\b\w/g,h=>h.toUpperCase()),c=O[b]?.fields?.[n],l={isSecret:i,label:S,description:c?.description,hidden:c?.hidden,showWhen:c?.showWhen};return c?.type==="dropdown"&&c.options?{...l,type:"dropdown",options:c.options}:c?.type==="token_mint"?{...l,type:"token_mint"}:c?.type==="toggle"?{...l,type:"toggle"}:c?.type==="secret_array"?{...l,type:"secret_array",isSecret:!0}:c?.type==="solana_address"?{...l,type:"solana_address"}:c?.type==="number"?{...l,type:"number",unit:c.unit}:typeof a=="boolean"?{...l,type:"boolean"}:typeof a=="number"?{...l,type:"number",unit:c?.unit}:Array.isArray(a)?{...l,type:"array"}:typeof a=="object"&&a!==null?{...l,type:"object"}:{...l,type:"string"}}function Q({category:b,config:n,originalConfig:a,isLoading:i=!1,onSave:S}){const[d,c]=m.useState(n),[l,h]=m.useState(new Set);m.useEffect(()=>{c(n)},[n]);const p=m.useMemo(()=>{const t={...d};for(const s of Object.keys(t))if(F(b,s)){const r=a[s],g=t[s];(g===D||g===r)&&(t[s]=D)}return t},[d,a,b]),y=m.useMemo(()=>{const t=d.token_mint;return typeof t!="string"||!t?!1:!W(t).valid},[d]),{status:x,error:N}=J.useAutosave({data:p,onSave:S,debounceMs:1500,enabled:!y}),f=m.useCallback((t,s)=>{c(r=>({...r,[t]:s}))},[]),E=m.useCallback(t=>{h(s=>{const r=new Set(s);return r.has(t)?r.delete(t):r.add(t),r})},[]),_=t=>t?e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--cedros-admin-text-muted, #64748b)",marginTop:"0.25rem"},children:t}):null,T=(t,s)=>{const r=L(b,t,a[t]??s);if(r.type==="dropdown"&&r.options)return e.jsx(w.FormDropdown,{value:s,onChange:o=>f(t,o),options:r.options.map(o=>({value:o,label:o})),label:r.label,description:r.description,disabled:i});if(r.type==="token_mint")return e.jsx(X,{label:r.label,value:s,onChange:o=>f(t,o),decimals:d.token_decimals??6,onDecimalsChange:o=>f("token_decimals",o),disabled:i,description:r.description,customSymbol:d.custom_token_symbol||"",customIcon:d.custom_token_icon||"",onCustomSymbolChange:o=>f("custom_token_symbol",o),onCustomIconChange:o=>f("custom_token_icon",o)});if(r.type==="toggle")return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx("button",{type:"button",role:"switch","aria-checked":s,onClick:()=>f(t,!s),disabled:i,style:{width:44,height:24,borderRadius:12,border:"none",backgroundColor:s?"var(--cedros-admin-primary, #171717)":"var(--cedros-admin-border, #d4d4d4)",cursor:i?"not-allowed":"pointer",position:"relative",transition:"background-color 0.2s",opacity:i?.5:1,flexShrink:0},children:e.jsx("span",{style:{position:"absolute",top:2,left:s?22:2,width:20,height:20,borderRadius:"50%",backgroundColor:"#fff",transition:"left 0.2s",boxShadow:"0 1px 3px rgba(0,0,0,0.2)"}})}),e.jsx("span",{className:"cedros-admin__field-label",style:{marginBottom:0},children:r.label})]}),_(r.description)]});if(r.type==="solana_address"){const o=s||"",C=W(o);return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:r.label}),e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:"text",className:`cedros-admin__input ${C.valid?"":"cedros-admin__input--error"}`,value:o,onChange:R=>f(t,R.target.value),disabled:i,placeholder:"e.g. 7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",style:{width:"100%",fontFamily:"monospace",fontSize:"0.875rem",borderColor:C.valid?void 0:"var(--cedros-admin-error, #dc2626)",paddingRight:o&&C.valid?"2rem":void 0}}),o&&C.valid&&e.jsx("span",{style:{position:"absolute",right:10,top:"50%",transform:"translateY(-50%)",color:"var(--cedros-admin-success, #16a34a)",fontSize:"1rem"},title:"Valid Solana address",children:"✓"})]}),!C.valid&&e.jsx("span",{style:{color:"var(--cedros-admin-error, #dc2626)",fontSize:"0.75rem",marginTop:"0.25rem",display:"block"},children:C.error}),_(r.description)]})}if(r.type==="boolean")return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsxs("label",{className:"cedros-admin__checkbox",children:[e.jsx("input",{type:"checkbox",checked:s,onChange:o=>f(t,o.target.checked),disabled:i}),r.label]}),_(r.description)]});if(r.type==="number")return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsxs("label",{className:"cedros-admin__field-label",children:[r.label,r.unit&&e.jsxs("span",{className:"cedros-admin__field-unit",children:[" (",r.unit,")"]})]}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:s,onChange:o=>f(t,parseFloat(o.target.value)||0),disabled:i}),_(r.description)]});if(r.type==="secret_array")return e.jsx(Z,{label:r.label,value:s,onChange:o=>f(t,o),disabled:i,description:r.description});if(r.type==="array"){const o=s;return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:r.label}),e.jsx("textarea",{className:"cedros-admin__textarea",value:o.join(`
2
+ `),onChange:C=>f(t,C.target.value.split(`
3
+ `).filter(Boolean)),placeholder:"One item per line",rows:3,disabled:i}),_(r.description)]})}if(r.type==="object")return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:r.label}),e.jsx("textarea",{className:"cedros-admin__textarea cedros-admin__textarea--mono",value:JSON.stringify(s,null,2),onChange:o=>{try{f(t,JSON.parse(o.target.value))}catch{}},rows:5,disabled:i}),_(r.description)]});const g=l.has(t),v=r.isSecret&&!g&&s===D?D:s;return e.jsxs("div",{className:"cedros-admin__field",children:[e.jsxs("label",{className:"cedros-admin__field-label",children:[r.label,r.isSecret&&e.jsx("span",{className:"cedros-admin__field-secret",children:" (secret)"})]}),e.jsxs("div",{className:"cedros-admin__input-group",children:[e.jsx("input",{type:r.isSecret&&!g?"password":"text",className:"cedros-admin__input",value:v,onChange:o=>f(t,o.target.value),disabled:i,placeholder:r.isSecret?"••••••••":""}),r.isSecret&&e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>E(t),style:{padding:"0.5rem",minWidth:"auto"},title:g?"Hide":"Show",children:g?w.Icons.eyeOff:w.Icons.eye})]}),_(r.description)]})},k=Object.keys(d),j=t=>{const s=L(b,t,a[t]??d[t]);if(s.hidden||s.showWhen&&!d[s.showWhen])return!1;if(t==="token_decimals"){const r=d.token_mint;if(r&&P.STABLECOIN_METADATA[r])return!1}return!0};return e.jsxs("div",{className:"cedros-admin__config-editor",children:[e.jsx("div",{className:"cedros-admin__config-fields",children:k.filter(j).map(t=>e.jsx("div",{className:"cedros-admin__config-field",children:T(t,d[t])},t))}),e.jsx("div",{className:"cedros-admin__config-actions",children:e.jsx("div",{className:"cedros-admin__autosave-status",children:e.jsx($.AutosaveIndicator,{status:x,error:N})})})]})}function ee({serverUrl:b,apiKey:n,authManager:a,category:i,title:S,description:d,enabledField:c="enabled",showEnabledToggle:l=!1}){const h=m.useMemo(()=>new G(b,void 0,a),[b,a]),[p,y]=m.useState(null),[x,N]=m.useState([]),[f,E]=m.useState(!1),[_,T]=m.useState(!0),[k,j]=m.useState(null),[t,s]=m.useState(null),[r,g]=m.useState(!1),v=O[i]||{label:i,icon:"⚙️"},o=S||v.label,C=d||v.description,R=m.useCallback(async()=>{T(!0),j(null);try{const u=await h.getConfig(i,!0);y(u)}catch{y(null),j("Failed to load settings")}finally{T(!1)}},[h,i]);m.useEffect(()=>{R()},[R]);const z=m.useCallback(async()=>{try{const u=await h.getHistory(i,20);N(u.history)}catch{N([])}},[h,i]);m.useEffect(()=>{f&&z()},[f,z]);const q=m.useCallback(async u=>{await h.updateConfig(i,u,"Updated via admin dashboard")},[h,i]),U=m.useCallback(async u=>h.validateConfig(i,u),[h,i]),[M,B]=m.useState(!1),K=m.useCallback(async()=>{if(!p||M)return;const u=!!p.config[c],I=!u,H={...p.config,[c]:I};B(!0),y({...p,config:H});try{await h.updateConfig(i,H,`${I?"Enabled":"Disabled"} via admin dashboard`)}catch(V){y({...p,config:{...p.config,[c]:u}}),j(V instanceof Error?V.message:"Failed to save enabled state")}finally{B(!1)}},[p,h,i,c,M]),A=!!p?.config[c];return _&&!p?e.jsx("div",{className:"cedros-admin__section",children:e.jsxs("div",{className:"cedros-admin__loading",children:[w.Icons.loading," Loading ",o," settings..."]})}):e.jsxs("div",{className:"cedros-admin__section",children:[e.jsx(w.ErrorBanner,{message:k,onRetry:R}),e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"cedros-admin__section-title",children:[e.jsx("span",{style:{marginRight:"0.5rem"},children:v.icon}),o]}),C&&e.jsx("p",{className:"cedros-admin__text-muted",style:{marginTop:"0.25rem"},children:C})]}),l&&p&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx("span",{style:{fontSize:"0.875rem",color:A?"var(--cedros-admin-text, #171717)":"var(--cedros-admin-muted, #737373)"},children:A?"Enabled":"Disabled"}),e.jsx("button",{type:"button",role:"switch","aria-checked":A,onClick:K,disabled:M,style:{width:44,height:24,borderRadius:12,border:"none",backgroundColor:A?"var(--cedros-admin-primary, #171717)":"var(--cedros-admin-border, #d4d4d4)",cursor:M?"wait":"pointer",position:"relative",transition:"background-color 0.2s",flexShrink:0,opacity:M?.6:1},children:e.jsx("span",{style:{position:"absolute",top:2,left:A?22:2,width:20,height:20,borderRadius:"50%",backgroundColor:"#fff",transition:"left 0.2s",boxShadow:"0 1px 3px rgba(0,0,0,0.2)"}})})]})]}),p&&e.jsxs("div",{className:"cedros-admin__settings-editor",style:{marginTop:"1rem",opacity:l&&!A?.6:1,pointerEvents:l&&!A?"none":"auto"},children:[l&&!A&&e.jsx("div",{style:{padding:"0.75rem 1rem",marginBottom:"1rem",backgroundColor:"var(--cedros-admin-warning-bg, #fef3c7)",border:"1px solid var(--cedros-admin-warning-border, #f59e0b)",borderRadius:"0.375rem",fontSize:"0.875rem",color:"var(--cedros-admin-warning-text, #92400e)",pointerEvents:"auto"},children:"This payment method is disabled. Enable it using the toggle above to accept payments."}),e.jsx(Q,{category:p.category,config:p.config,originalConfig:p.config,onSave:q,onValidate:U})]}),f&&e.jsxs("div",{className:"cedros-admin__settings-history",style:{marginTop:"1.5rem"},children:[e.jsx("h4",{style:{marginBottom:"0.75rem",fontWeight:600},children:"Change History"}),x.length===0?e.jsx("p",{className:"cedros-admin__text-muted",children:"No history entries found."}):e.jsx("div",{className:"cedros-admin__settings-timeline",children:x.map(u=>e.jsxs("div",{className:"cedros-admin__settings-timeline-item",children:[e.jsx("div",{className:"cedros-admin__settings-timeline-dot"}),e.jsxs("div",{className:"cedros-admin__settings-timeline-content",children:[e.jsxs("div",{className:"cedros-admin__settings-timeline-header",children:[e.jsx("code",{children:u.configKey}),e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${u.action.toLowerCase()}`,children:u.action})]}),e.jsxs("div",{className:"cedros-admin__settings-timeline-meta",children:[w.formatDateTime(u.changedAt)," by ",u.changedBy]})]})]},u.id))})]}),t&&e.jsx("div",{style:{marginTop:"1rem",padding:"0.75rem 1rem",borderRadius:"0.375rem",backgroundColor:t.valid?"var(--cedros-admin-success-bg, #dcfce7)":"var(--cedros-admin-error-bg, #fef2f2)",border:`1px solid ${t.valid?"var(--cedros-admin-success-border, #86efac)":"var(--cedros-admin-error-border, #fecaca)"}`},children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:600,color:t.valid?"var(--cedros-admin-success, #16a34a)":"var(--cedros-admin-error, #dc2626)",marginBottom:t.errors.length>0||t.warnings.length>0?"0.5rem":0},children:t.valid?"✓ Configuration is valid":"✗ Validation failed"}),t.errors.length>0&&e.jsx("ul",{style:{margin:0,paddingLeft:"1.25rem",color:"var(--cedros-admin-error, #dc2626)",fontSize:"0.875rem"},children:t.errors.map((u,I)=>e.jsx("li",{children:u},I))}),t.warnings.length>0&&e.jsx("ul",{style:{margin:t.errors.length>0?"0.5rem 0 0":0,paddingLeft:"1.25rem",color:"var(--cedros-admin-warning, #ca8a04)",fontSize:"0.875rem"},children:t.warnings.map((u,I)=>e.jsx("li",{children:u},I))})]}),e.jsx("button",{type:"button",onClick:()=>s(null),style:{background:"none",border:"none",cursor:"pointer",padding:"0.25rem",color:"var(--cedros-admin-text-muted, #64748b)",fontSize:"1.25rem",lineHeight:1},title:"Dismiss",children:"×"})]})}),e.jsxs("div",{style:{marginTop:"1.5rem",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>E(!f),children:f?"Hide History":"History"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:r||!p,onClick:async()=>{if(p){g(!0),s(null);try{const u=await U(p.config);s(u)}catch(u){s({valid:!1,errors:[u instanceof Error?u.message:"Validation failed"],warnings:[]})}finally{g(!1)}}},children:r?"Validating...":"Validate"})]})]})}exports.SingleCategorySettings=ee;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("react"),g=require("./index-7YUxR4u5.js"),o=require("./Toggle-CsPSF8Dr.js"),O=require("./useAutosave-B2p6iwh8.js"),M=require("./AutosaveIndicator-DW4IPbZ5.js"),b={enabled:!0,relatedProducts:{mode:"most_recent",maxItems:4,layout:{layout:"large",imageCrop:"center"}},catalog:{filters:{tags:!0,priceRange:!0,inStock:!0},sort:{featured:!0,priceAsc:!0,priceDesc:!0}},checkout:{promoCodes:!0},shopLayout:{layout:"large",imageCrop:"center"},categoryLayout:{layout:"large",imageCrop:"center"},sections:{showDescription:!0,showSpecs:!0,showShipping:!0,showRelatedProducts:!0},inventory:{preCheckoutVerification:!0,holdsEnabled:!1,holdDurationMinutes:15},shopPage:{title:"Shop",description:""}},$=[{value:"most_recent",label:"Most Recent",description:"Show the most recently added products (excluding current product)."},{value:"by_category",label:"By Category",description:"Show products from the same category as the current product."},{value:"manual",label:"Manual Selection",description:"Specify related products per-product using relatedProductIds in metadata."},{value:"ai",label:"AI Recommendations",description:"Let AI analyze products and suggest the best matches. Requires AI to be configured in AI Settings."}],S=[{value:"large",label:"Large",description:"Portrait cards (4:5) with full product info, description, and tags."},{value:"square",label:"Square",description:"Square cards (1:1) showing title and price only."},{value:"compact",label:"Compact",description:"Compact cards (3:4) with smaller text to fit more products."}],C=[{value:"center",label:"Center"},{value:"top",label:"Top"},{value:"bottom",label:"Bottom"},{value:"left",label:"Left"},{value:"right",label:"Right"}],q=[{id:"shop-page",label:"Shop Page"},{id:"catalog",label:"Catalog"},{id:"layouts",label:"Layouts"},{id:"product-pages",label:"Product Pages"},{id:"checkout",label:"Checkout"}];function H({serverUrl:h,apiKey:d,authManager:c}){const[m,P]=l.useState("shop-page"),[a,i]=l.useState(b),[I,z]=l.useState(!0),[W,B]=l.useState(!0),[L,y]=l.useState(null),x=l.useCallback(async()=>{try{y(null);let t;const s="/admin/config/shop";if(c?.isAuthenticated())t=await c.fetchWithAuth(s);else{const r={"Content-Type":"application/json"};d&&(r["X-API-Key"]=d);const n=await fetch(`${h}${s}`,{headers:r});if(!n.ok)throw new Error(`Failed to fetch settings: ${n.status}`);t=await n.json()}i({...b,...t.config})}catch{i(b),y("Could not load saved settings. Showing defaults.")}finally{z(!1),setTimeout(()=>B(!1),100)}},[h,d,c]);l.useEffect(()=>{x()},[x]);const D=l.useCallback(async t=>{const s="/admin/config/shop",r=JSON.stringify({config:t});try{if(c?.isAuthenticated())await c.fetchWithAuth(s,{method:"PUT",body:r});else{const n={"Content-Type":"application/json"};d&&(n["X-API-Key"]=d);const p=await fetch(`${h}${s}`,{method:"PUT",headers:n,body:r});if(!p.ok)throw new Error(`Failed to save settings: ${p.status}`)}}catch{throw y("Failed to save storefront settings"),new Error("Save failed")}},[h,d,c]),{status:N,error:R}=O.useAutosave({data:a,onSave:D,debounceMs:1500,enabled:!W}),A=t=>{i(s=>({...s,relatedProducts:{...s.relatedProducts,mode:t}}))},E=t=>{i(s=>({...s,relatedProducts:{...s.relatedProducts,maxItems:t}}))},_=(t,s)=>{i(r=>({...r,relatedProducts:{...r.relatedProducts,layout:{...r.relatedProducts.layout,[t]:s}}}))},f=(t,s)=>{i(r=>({...r,catalog:{...r.catalog,filters:{...r.catalog.filters,[t]:s}}}))},v=(t,s)=>{const r=a.catalog.sort,n=Object.values(r).filter(Boolean).length;!s&&n<=1||i(p=>({...p,catalog:{...p.catalog,sort:{...p.catalog.sort,[t]:s}}}))},F=(t,s)=>{i(r=>({...r,checkout:{...r.checkout,[t]:s}}))},k=(t,s)=>{i(r=>({...r,shopLayout:{...r.shopLayout,[t]:s}}))},T=(t,s)=>{i(r=>({...r,categoryLayout:{...r.categoryLayout,[t]:s}}))},u=(t,s)=>{i(r=>({...r,sections:{...r.sections,[t]:s}}))},j=(t,s)=>{i(r=>({...r,inventory:{...r.inventory,[t]:s}}))},w=(t,s)=>{i(r=>({...r,shopPage:{...r.shopPage,[t]:s}}))};return I?e.jsx("div",{className:"cedros-admin__section",children:e.jsxs("div",{className:"cedros-admin__loading",children:[g.Icons.loading," Loading storefront settings..."]})}):e.jsxs("div",{className:"cedros-admin__storefront-settings",children:[e.jsxs("div",{className:"cedros-admin__page-header",style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[e.jsxs("div",{children:[e.jsx("h2",{className:"cedros-admin__page-title",children:"Storefront"}),e.jsx("p",{className:"cedros-admin__page-description",children:"Configure catalog filters, product layouts, and checkout settings."})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",flexShrink:0},children:[e.jsx("span",{style:{fontSize:"0.875rem",color:a.enabled?"var(--cedros-admin-text, #171717)":"var(--cedros-admin-muted, #737373)"},children:a.enabled?"Enabled":"Disabled"}),e.jsx(o.Toggle,{checked:a.enabled,onChange:t=>i(s=>({...s,enabled:t}))})]})]}),!a.enabled&&e.jsx("div",{style:{padding:"0.75rem 1rem",marginBottom:"1rem",backgroundColor:"var(--cedros-admin-warning-bg, #fef3c7)",border:"1px solid var(--cedros-admin-warning-border, #f59e0b)",borderRadius:"0.375rem",fontSize:"0.875rem",color:"var(--cedros-admin-warning-text, #92400e)"},children:"The storefront is disabled. Enable it using the toggle above to activate your store."}),e.jsxs("div",{className:"cedros-admin__tabs cedros-admin__tabs--line",style:{opacity:a.enabled?1:.5,pointerEvents:a.enabled?"auto":"none"},children:[q.map(t=>e.jsx("button",{type:"button",className:`cedros-admin__tab ${m===t.id?"cedros-admin__tab--active":""}`,onClick:()=>P(t.id),children:t.label},t.id)),e.jsx("div",{style:{flex:1}}),e.jsx(M.AutosaveIndicator,{status:N,error:R})]}),e.jsx(g.ErrorBanner,{message:L,onRetry:x}),m==="shop-page"&&e.jsxs("div",{className:"cedros-admin__section",style:{marginTop:"1rem"},children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Shop Page Content"}),e.jsx("p",{style:{marginBottom:"1.5rem",fontSize:14,opacity:.7},children:"Customize the title and description shown on your shop page."}),e.jsxs("div",{className:"cedros-admin__field",style:{marginBottom:"1.5rem"},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Page Title"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.shopPage.title,onChange:t=>w("title",t.target.value),placeholder:"Shop"}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:12,opacity:.6},children:"The main heading displayed on your shop page."})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Page Description"}),e.jsx("textarea",{className:"cedros-admin__textarea",value:a.shopPage.description,onChange:t=>w("description",t.target.value),placeholder:"Browse our collection of products...",rows:3,style:{resize:"vertical"}}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:12,opacity:.6},children:"A short description or subtitle shown below the title. Leave empty to hide."})]})]}),m==="catalog"&&e.jsxs("div",{className:"cedros-admin__section",style:{marginTop:"1rem"},children:[e.jsxs("div",{children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Catalog Filters"}),e.jsx("p",{style:{marginBottom:"1rem",fontSize:14,opacity:.7},children:"Choose which filters appear in the shop and category page sidebars."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.catalog.filters.tags,onChange:t=>f("tags",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Tags"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Filter products by tags (multi-select checkboxes)"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.catalog.filters.priceRange,onChange:t=>f("priceRange",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Price Range"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Filter by minimum and maximum price"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.catalog.filters.inStock,onChange:t=>f("inStock",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"In Stock"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Show only products that are in stock"})]})]})]})]}),e.jsxs("div",{style:{marginTop:"2rem",paddingTop:"1.5rem",borderTop:"1px solid var(--cedros-admin-border, #e5e5e5)"},children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Sort Options"}),e.jsx("p",{style:{marginBottom:"1rem",fontSize:14,opacity:.7},children:"Choose which sort options appear in the shop and category pages. At least one must be enabled."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.catalog.sort.featured,onChange:t=>v("featured",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Featured"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Default sort order (as returned by backend)"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.catalog.sort.priceAsc,onChange:t=>v("priceAsc",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Price: Low to High"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Sort products by price ascending"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.catalog.sort.priceDesc,onChange:t=>v("priceDesc",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Price: High to Low"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Sort products by price descending"})]})]})]})]})]}),m==="layouts"&&e.jsxs("div",{className:"cedros-admin__section",style:{marginTop:"1rem"},children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Product Layouts"}),e.jsx("p",{style:{marginBottom:"1.5rem",fontSize:14,opacity:.7},children:"Configure product card layouts for shop and category pages."}),e.jsxs("div",{style:{marginBottom:"2rem"},children:[e.jsx("div",{style:{fontWeight:500,marginBottom:"0.75rem"},children:"Shop Page"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem",marginBottom:"1rem"},children:S.map(t=>{const s=a.shopLayout.layout===t.value;return e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:"0.75rem",padding:"0.75rem",border:`2px solid ${s?"var(--cedros-admin-primary, #171717)":"var(--cedros-admin-border, #e5e5e5)"}`,borderRadius:6,cursor:"pointer",background:s?"var(--cedros-admin-bg-accent, #f5f5f5)":void 0,transition:"border-color 0.15s, background 0.15s"},children:[e.jsx("input",{type:"radio",name:"shopLayout",value:t.value,checked:s,onChange:()=>k("layout",t.value),style:{marginTop:2}}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:t.label}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:12,opacity:.6},children:t.description})]})]},t.value)})}),e.jsx(g.FormDropdown,{value:a.shopLayout.imageCrop,onChange:t=>k("imageCrop",t),options:C,label:"Image Crop",style:{maxWidth:180}})]}),e.jsxs("div",{style:{paddingTop:"1.5rem",borderTop:"1px solid var(--cedros-admin-border, #e5e5e5)"},children:[e.jsx("div",{style:{fontWeight:500,marginBottom:"0.75rem"},children:"Category Pages"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem",marginBottom:"1rem"},children:S.map(t=>{const s=a.categoryLayout.layout===t.value;return e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:"0.75rem",padding:"0.75rem",border:`2px solid ${s?"var(--cedros-admin-primary, #171717)":"var(--cedros-admin-border, #e5e5e5)"}`,borderRadius:6,cursor:"pointer",background:s?"var(--cedros-admin-bg-accent, #f5f5f5)":void 0,transition:"border-color 0.15s, background 0.15s"},children:[e.jsx("input",{type:"radio",name:"categoryLayout",value:t.value,checked:s,onChange:()=>T("layout",t.value),style:{marginTop:2}}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:t.label}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:12,opacity:.6},children:t.description})]})]},t.value)})}),e.jsx(g.FormDropdown,{value:a.categoryLayout.imageCrop,onChange:t=>T("imageCrop",t),options:C,label:"Image Crop",style:{maxWidth:180}})]})]}),m==="product-pages"&&e.jsxs("div",{className:"cedros-admin__section",style:{marginTop:"1rem"},children:[e.jsxs("div",{children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Related Products"}),e.jsx("p",{style:{marginBottom:"1rem",fontSize:14,opacity:.7},children:"Configure how related products are displayed on product detail pages."}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem",marginBottom:"1.5rem"},children:$.map(t=>{const s=a.relatedProducts.mode===t.value,r=t.badge==="Coming Soon";return e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:"0.75rem",padding:"1rem",border:`2px solid ${s?"var(--cedros-admin-primary, #171717)":"var(--cedros-admin-border, #e5e5e5)"}`,borderRadius:8,cursor:r?"not-allowed":"pointer",opacity:r?.6:1,background:s?"var(--cedros-admin-bg-accent, #f5f5f5)":void 0,transition:"border-color 0.15s, background 0.15s"},children:[e.jsx("input",{type:"radio",name:"relatedProductsMode",value:t.value,checked:s,onChange:()=>!r&&A(t.value),disabled:r,style:{marginTop:2}}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[e.jsx("span",{style:{fontWeight:600},children:t.label}),t.badge&&e.jsx("span",{style:{fontSize:11,padding:"2px 6px",borderRadius:4,background:"#6366f1",color:"#fff"},children:t.badge})]}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:13,opacity:.75},children:t.description})]})]},t.value)})}),a.relatedProducts.mode==="manual"&&e.jsxs("div",{style:{padding:"1rem",marginBottom:"1.5rem",background:"var(--cedros-admin-bg-accent, #f5f5f5)",borderRadius:8,border:"1px solid var(--cedros-admin-border, #e5e5e5)"},children:[e.jsx("strong",{style:{fontSize:14},children:"How to set related products:"}),e.jsxs("p",{style:{margin:"0.5rem 0 0",fontSize:13,opacity:.8},children:["When editing a product, add a ",e.jsx("code",{style:{background:"rgba(0,0,0,0.1)",padding:"2px 4px",borderRadius:3},children:"relatedProductIds"})," field to its metadata containing a comma-separated list of product IDs."]}),e.jsxs("p",{style:{margin:"0.5rem 0 0",fontSize:13,opacity:.6},children:["Example: ",e.jsx("code",{style:{background:"rgba(0,0,0,0.1)",padding:"2px 4px",borderRadius:3},children:"prod_123,prod_456,prod_789"})]})]}),e.jsxs("div",{className:"cedros-admin__field",style:{maxWidth:200},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Max Related Products"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:a.relatedProducts.maxItems,onChange:t=>E(Math.max(1,Math.min(12,parseInt(t.target.value)||4))),min:1,max:12}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:12,opacity:.6},children:"How many related products to show (1-12)"})]}),e.jsxs("div",{style:{marginTop:"1.5rem"},children:[e.jsx("div",{style:{fontWeight:500,marginBottom:"0.75rem"},children:"Display Layout"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem",marginBottom:"1rem"},children:S.map(t=>{const s=a.relatedProducts.layout.layout===t.value;return e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:"0.75rem",padding:"0.75rem",border:`2px solid ${s?"var(--cedros-admin-primary, #171717)":"var(--cedros-admin-border, #e5e5e5)"}`,borderRadius:6,cursor:"pointer",background:s?"var(--cedros-admin-bg-accent, #f5f5f5)":void 0,transition:"border-color 0.15s, background 0.15s"},children:[e.jsx("input",{type:"radio",name:"relatedLayout",value:t.value,checked:s,onChange:()=>_("layout",t.value),style:{marginTop:2}}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:t.label}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:12,opacity:.6},children:t.description})]})]},t.value)})}),e.jsx(g.FormDropdown,{value:a.relatedProducts.layout.imageCrop,onChange:t=>_("imageCrop",t),options:C,label:"Image Crop",style:{maxWidth:180}})]})]}),e.jsxs("div",{style:{marginTop:"2rem",paddingTop:"1.5rem",borderTop:"1px solid var(--cedros-admin-border, #e5e5e5)"},children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Page Sections"}),e.jsx("p",{style:{marginBottom:"1rem",fontSize:14,opacity:.7},children:"Choose which sections appear on product detail pages."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.sections.showDescription,onChange:t=>u("showDescription",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Description"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Expandable description accordion"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.sections.showSpecs,onChange:t=>u("showSpecs",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Specifications"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Product attributes and details"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.sections.showShipping,onChange:t=>u("showShipping",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Shipping & Returns"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Shipping and return policy information"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.sections.showRelatedProducts,onChange:t=>u("showRelatedProducts",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Related Products"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Product recommendations section"})]})]})]})]})]}),m==="checkout"&&e.jsxs("div",{className:"cedros-admin__section",style:{marginTop:"1rem"},children:[e.jsxs("div",{children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Checkout Settings"}),e.jsx("p",{style:{marginBottom:"1rem",fontSize:14,opacity:.7},children:"Configure checkout and cart page features."}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.checkout.promoCodes,onChange:t=>F("promoCodes",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Promo Codes"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Show promo/coupon code input on cart and checkout pages"})]})]})})]}),e.jsxs("div",{style:{marginTop:"2rem",paddingTop:"1.5rem",borderTop:"1px solid var(--cedros-admin-border, #e5e5e5)"},children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Inventory Settings"}),e.jsx("p",{style:{marginBottom:"1rem",fontSize:14,opacity:.7},children:"Configure inventory verification and reservation behavior."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.inventory.preCheckoutVerification,onChange:t=>j("preCheckoutVerification",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Pre-Checkout Verification"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Verify inventory availability before processing payment"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.inventory.holdsEnabled,onChange:t=>j("holdsEnabled",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Inventory Holds"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Reserve inventory when items are added to cart"})]})]})]}),a.inventory.holdsEnabled&&e.jsxs("div",{className:"cedros-admin__field",style:{maxWidth:200,marginTop:"1rem"},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Hold Duration (minutes)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:a.inventory.holdDurationMinutes,onChange:t=>j("holdDurationMinutes",Math.max(5,Math.min(60,parseInt(t.target.value)||15))),min:5,max:60}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:12,opacity:.6},children:"How long to reserve inventory in carts (5-60 minutes)"})]})]})]})]})}exports.StorefrontSection=H;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("react"),g=require("./index-IZ4WcMd7.js"),o=require("./Toggle-CsPSF8Dr.js"),O=require("./useAutosave-B2p6iwh8.js"),M=require("./AutosaveIndicator-C-CH-obR.js"),b={enabled:!0,relatedProducts:{mode:"most_recent",maxItems:4,layout:{layout:"large",imageCrop:"center"}},catalog:{filters:{tags:!0,priceRange:!0,inStock:!0},sort:{featured:!0,priceAsc:!0,priceDesc:!0}},checkout:{promoCodes:!0},shopLayout:{layout:"large",imageCrop:"center"},categoryLayout:{layout:"large",imageCrop:"center"},sections:{showDescription:!0,showSpecs:!0,showShipping:!0,showRelatedProducts:!0},inventory:{preCheckoutVerification:!0,holdsEnabled:!1,holdDurationMinutes:15},shopPage:{title:"Shop",description:""}},$=[{value:"most_recent",label:"Most Recent",description:"Show the most recently added products (excluding current product)."},{value:"by_category",label:"By Category",description:"Show products from the same category as the current product."},{value:"manual",label:"Manual Selection",description:"Specify related products per-product using relatedProductIds in metadata."},{value:"ai",label:"AI Recommendations",description:"Let AI analyze products and suggest the best matches. Requires AI to be configured in AI Settings."}],S=[{value:"large",label:"Large",description:"Portrait cards (4:5) with full product info, description, and tags."},{value:"square",label:"Square",description:"Square cards (1:1) showing title and price only."},{value:"compact",label:"Compact",description:"Compact cards (3:4) with smaller text to fit more products."}],C=[{value:"center",label:"Center"},{value:"top",label:"Top"},{value:"bottom",label:"Bottom"},{value:"left",label:"Left"},{value:"right",label:"Right"}],q=[{id:"shop-page",label:"Shop Page"},{id:"catalog",label:"Catalog"},{id:"layouts",label:"Layouts"},{id:"product-pages",label:"Product Pages"},{id:"checkout",label:"Checkout"}];function H({serverUrl:h,apiKey:d,authManager:c}){const[m,P]=l.useState("shop-page"),[a,i]=l.useState(b),[I,z]=l.useState(!0),[W,B]=l.useState(!0),[L,y]=l.useState(null),x=l.useCallback(async()=>{try{y(null);let t;const s="/admin/config/shop";if(c?.isAuthenticated())t=await c.fetchWithAuth(s);else{const r={"Content-Type":"application/json"};d&&(r["X-API-Key"]=d);const n=await fetch(`${h}${s}`,{headers:r});if(!n.ok)throw new Error(`Failed to fetch settings: ${n.status}`);t=await n.json()}i({...b,...t.config})}catch{i(b),y("Could not load saved settings. Showing defaults.")}finally{z(!1),setTimeout(()=>B(!1),100)}},[h,d,c]);l.useEffect(()=>{x()},[x]);const D=l.useCallback(async t=>{const s="/admin/config/shop",r=JSON.stringify({config:t});try{if(c?.isAuthenticated())await c.fetchWithAuth(s,{method:"PUT",body:r});else{const n={"Content-Type":"application/json"};d&&(n["X-API-Key"]=d);const p=await fetch(`${h}${s}`,{method:"PUT",headers:n,body:r});if(!p.ok)throw new Error(`Failed to save settings: ${p.status}`)}}catch{throw y("Failed to save storefront settings"),new Error("Save failed")}},[h,d,c]),{status:N,error:R}=O.useAutosave({data:a,onSave:D,debounceMs:1500,enabled:!W}),A=t=>{i(s=>({...s,relatedProducts:{...s.relatedProducts,mode:t}}))},E=t=>{i(s=>({...s,relatedProducts:{...s.relatedProducts,maxItems:t}}))},_=(t,s)=>{i(r=>({...r,relatedProducts:{...r.relatedProducts,layout:{...r.relatedProducts.layout,[t]:s}}}))},f=(t,s)=>{i(r=>({...r,catalog:{...r.catalog,filters:{...r.catalog.filters,[t]:s}}}))},v=(t,s)=>{const r=a.catalog.sort,n=Object.values(r).filter(Boolean).length;!s&&n<=1||i(p=>({...p,catalog:{...p.catalog,sort:{...p.catalog.sort,[t]:s}}}))},F=(t,s)=>{i(r=>({...r,checkout:{...r.checkout,[t]:s}}))},k=(t,s)=>{i(r=>({...r,shopLayout:{...r.shopLayout,[t]:s}}))},T=(t,s)=>{i(r=>({...r,categoryLayout:{...r.categoryLayout,[t]:s}}))},u=(t,s)=>{i(r=>({...r,sections:{...r.sections,[t]:s}}))},j=(t,s)=>{i(r=>({...r,inventory:{...r.inventory,[t]:s}}))},w=(t,s)=>{i(r=>({...r,shopPage:{...r.shopPage,[t]:s}}))};return I?e.jsx("div",{className:"cedros-admin__section",children:e.jsxs("div",{className:"cedros-admin__loading",children:[g.Icons.loading," Loading storefront settings..."]})}):e.jsxs("div",{className:"cedros-admin__storefront-settings",children:[e.jsxs("div",{className:"cedros-admin__page-header",style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[e.jsxs("div",{children:[e.jsx("h2",{className:"cedros-admin__page-title",children:"Storefront"}),e.jsx("p",{className:"cedros-admin__page-description",children:"Configure catalog filters, product layouts, and checkout settings."})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",flexShrink:0},children:[e.jsx("span",{style:{fontSize:"0.875rem",color:a.enabled?"var(--cedros-admin-text, #171717)":"var(--cedros-admin-muted, #737373)"},children:a.enabled?"Enabled":"Disabled"}),e.jsx(o.Toggle,{checked:a.enabled,onChange:t=>i(s=>({...s,enabled:t}))})]})]}),!a.enabled&&e.jsx("div",{style:{padding:"0.75rem 1rem",marginBottom:"1rem",backgroundColor:"var(--cedros-admin-warning-bg, #fef3c7)",border:"1px solid var(--cedros-admin-warning-border, #f59e0b)",borderRadius:"0.375rem",fontSize:"0.875rem",color:"var(--cedros-admin-warning-text, #92400e)"},children:"The storefront is disabled. Enable it using the toggle above to activate your store."}),e.jsxs("div",{className:"cedros-admin__tabs cedros-admin__tabs--line",style:{opacity:a.enabled?1:.5,pointerEvents:a.enabled?"auto":"none"},children:[q.map(t=>e.jsx("button",{type:"button",className:`cedros-admin__tab ${m===t.id?"cedros-admin__tab--active":""}`,onClick:()=>P(t.id),children:t.label},t.id)),e.jsx("div",{style:{flex:1}}),e.jsx(M.AutosaveIndicator,{status:N,error:R})]}),e.jsx(g.ErrorBanner,{message:L,onRetry:x}),m==="shop-page"&&e.jsxs("div",{className:"cedros-admin__section",style:{marginTop:"1rem"},children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Shop Page Content"}),e.jsx("p",{style:{marginBottom:"1.5rem",fontSize:14,opacity:.7},children:"Customize the title and description shown on your shop page."}),e.jsxs("div",{className:"cedros-admin__field",style:{marginBottom:"1.5rem"},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Page Title"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.shopPage.title,onChange:t=>w("title",t.target.value),placeholder:"Shop"}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:12,opacity:.6},children:"The main heading displayed on your shop page."})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Page Description"}),e.jsx("textarea",{className:"cedros-admin__textarea",value:a.shopPage.description,onChange:t=>w("description",t.target.value),placeholder:"Browse our collection of products...",rows:3,style:{resize:"vertical"}}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:12,opacity:.6},children:"A short description or subtitle shown below the title. Leave empty to hide."})]})]}),m==="catalog"&&e.jsxs("div",{className:"cedros-admin__section",style:{marginTop:"1rem"},children:[e.jsxs("div",{children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Catalog Filters"}),e.jsx("p",{style:{marginBottom:"1rem",fontSize:14,opacity:.7},children:"Choose which filters appear in the shop and category page sidebars."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.catalog.filters.tags,onChange:t=>f("tags",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Tags"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Filter products by tags (multi-select checkboxes)"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.catalog.filters.priceRange,onChange:t=>f("priceRange",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Price Range"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Filter by minimum and maximum price"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.catalog.filters.inStock,onChange:t=>f("inStock",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"In Stock"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Show only products that are in stock"})]})]})]})]}),e.jsxs("div",{style:{marginTop:"2rem",paddingTop:"1.5rem",borderTop:"1px solid var(--cedros-admin-border, #e5e5e5)"},children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Sort Options"}),e.jsx("p",{style:{marginBottom:"1rem",fontSize:14,opacity:.7},children:"Choose which sort options appear in the shop and category pages. At least one must be enabled."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.catalog.sort.featured,onChange:t=>v("featured",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Featured"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Default sort order (as returned by backend)"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.catalog.sort.priceAsc,onChange:t=>v("priceAsc",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Price: Low to High"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Sort products by price ascending"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.catalog.sort.priceDesc,onChange:t=>v("priceDesc",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Price: High to Low"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Sort products by price descending"})]})]})]})]})]}),m==="layouts"&&e.jsxs("div",{className:"cedros-admin__section",style:{marginTop:"1rem"},children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Product Layouts"}),e.jsx("p",{style:{marginBottom:"1.5rem",fontSize:14,opacity:.7},children:"Configure product card layouts for shop and category pages."}),e.jsxs("div",{style:{marginBottom:"2rem"},children:[e.jsx("div",{style:{fontWeight:500,marginBottom:"0.75rem"},children:"Shop Page"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem",marginBottom:"1rem"},children:S.map(t=>{const s=a.shopLayout.layout===t.value;return e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:"0.75rem",padding:"0.75rem",border:`2px solid ${s?"var(--cedros-admin-primary, #171717)":"var(--cedros-admin-border, #e5e5e5)"}`,borderRadius:6,cursor:"pointer",background:s?"var(--cedros-admin-bg-accent, #f5f5f5)":void 0,transition:"border-color 0.15s, background 0.15s"},children:[e.jsx("input",{type:"radio",name:"shopLayout",value:t.value,checked:s,onChange:()=>k("layout",t.value),style:{marginTop:2}}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:t.label}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:12,opacity:.6},children:t.description})]})]},t.value)})}),e.jsx(g.FormDropdown,{value:a.shopLayout.imageCrop,onChange:t=>k("imageCrop",t),options:C,label:"Image Crop",style:{maxWidth:180}})]}),e.jsxs("div",{style:{paddingTop:"1.5rem",borderTop:"1px solid var(--cedros-admin-border, #e5e5e5)"},children:[e.jsx("div",{style:{fontWeight:500,marginBottom:"0.75rem"},children:"Category Pages"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem",marginBottom:"1rem"},children:S.map(t=>{const s=a.categoryLayout.layout===t.value;return e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:"0.75rem",padding:"0.75rem",border:`2px solid ${s?"var(--cedros-admin-primary, #171717)":"var(--cedros-admin-border, #e5e5e5)"}`,borderRadius:6,cursor:"pointer",background:s?"var(--cedros-admin-bg-accent, #f5f5f5)":void 0,transition:"border-color 0.15s, background 0.15s"},children:[e.jsx("input",{type:"radio",name:"categoryLayout",value:t.value,checked:s,onChange:()=>T("layout",t.value),style:{marginTop:2}}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:t.label}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:12,opacity:.6},children:t.description})]})]},t.value)})}),e.jsx(g.FormDropdown,{value:a.categoryLayout.imageCrop,onChange:t=>T("imageCrop",t),options:C,label:"Image Crop",style:{maxWidth:180}})]})]}),m==="product-pages"&&e.jsxs("div",{className:"cedros-admin__section",style:{marginTop:"1rem"},children:[e.jsxs("div",{children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Related Products"}),e.jsx("p",{style:{marginBottom:"1rem",fontSize:14,opacity:.7},children:"Configure how related products are displayed on product detail pages."}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem",marginBottom:"1.5rem"},children:$.map(t=>{const s=a.relatedProducts.mode===t.value,r=t.badge==="Coming Soon";return e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:"0.75rem",padding:"1rem",border:`2px solid ${s?"var(--cedros-admin-primary, #171717)":"var(--cedros-admin-border, #e5e5e5)"}`,borderRadius:8,cursor:r?"not-allowed":"pointer",opacity:r?.6:1,background:s?"var(--cedros-admin-bg-accent, #f5f5f5)":void 0,transition:"border-color 0.15s, background 0.15s"},children:[e.jsx("input",{type:"radio",name:"relatedProductsMode",value:t.value,checked:s,onChange:()=>!r&&A(t.value),disabled:r,style:{marginTop:2}}),e.jsxs("div",{style:{flex:1},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[e.jsx("span",{style:{fontWeight:600},children:t.label}),t.badge&&e.jsx("span",{style:{fontSize:11,padding:"2px 6px",borderRadius:4,background:"#6366f1",color:"#fff"},children:t.badge})]}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:13,opacity:.75},children:t.description})]})]},t.value)})}),a.relatedProducts.mode==="manual"&&e.jsxs("div",{style:{padding:"1rem",marginBottom:"1.5rem",background:"var(--cedros-admin-bg-accent, #f5f5f5)",borderRadius:8,border:"1px solid var(--cedros-admin-border, #e5e5e5)"},children:[e.jsx("strong",{style:{fontSize:14},children:"How to set related products:"}),e.jsxs("p",{style:{margin:"0.5rem 0 0",fontSize:13,opacity:.8},children:["When editing a product, add a ",e.jsx("code",{style:{background:"rgba(0,0,0,0.1)",padding:"2px 4px",borderRadius:3},children:"relatedProductIds"})," field to its metadata containing a comma-separated list of product IDs."]}),e.jsxs("p",{style:{margin:"0.5rem 0 0",fontSize:13,opacity:.6},children:["Example: ",e.jsx("code",{style:{background:"rgba(0,0,0,0.1)",padding:"2px 4px",borderRadius:3},children:"prod_123,prod_456,prod_789"})]})]}),e.jsxs("div",{className:"cedros-admin__field",style:{maxWidth:200},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Max Related Products"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:a.relatedProducts.maxItems,onChange:t=>E(Math.max(1,Math.min(12,parseInt(t.target.value)||4))),min:1,max:12}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:12,opacity:.6},children:"How many related products to show (1-12)"})]}),e.jsxs("div",{style:{marginTop:"1.5rem"},children:[e.jsx("div",{style:{fontWeight:500,marginBottom:"0.75rem"},children:"Display Layout"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem",marginBottom:"1rem"},children:S.map(t=>{const s=a.relatedProducts.layout.layout===t.value;return e.jsxs("label",{style:{display:"flex",alignItems:"flex-start",gap:"0.75rem",padding:"0.75rem",border:`2px solid ${s?"var(--cedros-admin-primary, #171717)":"var(--cedros-admin-border, #e5e5e5)"}`,borderRadius:6,cursor:"pointer",background:s?"var(--cedros-admin-bg-accent, #f5f5f5)":void 0,transition:"border-color 0.15s, background 0.15s"},children:[e.jsx("input",{type:"radio",name:"relatedLayout",value:t.value,checked:s,onChange:()=>_("layout",t.value),style:{marginTop:2}}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:t.label}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:12,opacity:.6},children:t.description})]})]},t.value)})}),e.jsx(g.FormDropdown,{value:a.relatedProducts.layout.imageCrop,onChange:t=>_("imageCrop",t),options:C,label:"Image Crop",style:{maxWidth:180}})]})]}),e.jsxs("div",{style:{marginTop:"2rem",paddingTop:"1.5rem",borderTop:"1px solid var(--cedros-admin-border, #e5e5e5)"},children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Page Sections"}),e.jsx("p",{style:{marginBottom:"1rem",fontSize:14,opacity:.7},children:"Choose which sections appear on product detail pages."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.sections.showDescription,onChange:t=>u("showDescription",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Description"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Expandable description accordion"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.sections.showSpecs,onChange:t=>u("showSpecs",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Specifications"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Product attributes and details"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.sections.showShipping,onChange:t=>u("showShipping",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Shipping & Returns"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Shipping and return policy information"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.sections.showRelatedProducts,onChange:t=>u("showRelatedProducts",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Related Products"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Product recommendations section"})]})]})]})]})]}),m==="checkout"&&e.jsxs("div",{className:"cedros-admin__section",style:{marginTop:"1rem"},children:[e.jsxs("div",{children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Checkout Settings"}),e.jsx("p",{style:{marginBottom:"1rem",fontSize:14,opacity:.7},children:"Configure checkout and cart page features."}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.checkout.promoCodes,onChange:t=>F("promoCodes",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Promo Codes"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Show promo/coupon code input on cart and checkout pages"})]})]})})]}),e.jsxs("div",{style:{marginTop:"2rem",paddingTop:"1.5rem",borderTop:"1px solid var(--cedros-admin-border, #e5e5e5)"},children:[e.jsx("h4",{style:{marginBottom:"0.5rem",fontWeight:600},children:"Inventory Settings"}),e.jsx("p",{style:{marginBottom:"1rem",fontSize:14,opacity:.7},children:"Configure inventory verification and reservation behavior."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.inventory.preCheckoutVerification,onChange:t=>j("preCheckoutVerification",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Pre-Checkout Verification"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Verify inventory availability before processing payment"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e.jsx(o.Toggle,{checked:a.inventory.holdsEnabled,onChange:t=>j("holdsEnabled",t)}),e.jsxs("div",{children:[e.jsx("span",{style:{fontWeight:500},children:"Inventory Holds"}),e.jsx("p",{style:{margin:"0.125rem 0 0",fontSize:13,opacity:.6},children:"Reserve inventory when items are added to cart"})]})]})]}),a.inventory.holdsEnabled&&e.jsxs("div",{className:"cedros-admin__field",style:{maxWidth:200,marginTop:"1rem"},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Hold Duration (minutes)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:a.inventory.holdDurationMinutes,onChange:t=>j("holdDurationMinutes",Math.max(5,Math.min(60,parseInt(t.target.value)||15))),min:5,max:60}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:12,opacity:.6},children:"How long to reserve inventory in carts (5-60 minutes)"})]})]})]})]})}exports.StorefrontSection=H;
@@ -1,9 +1,9 @@
1
1
  import { jsx as t, jsxs as a } from "react/jsx-runtime";
2
2
  import { useState as h, useCallback as z, useEffect as j } from "react";
3
- import { I as H, E as V, F as x } from "./index-bqhsxBTY.mjs";
3
+ import { I as H, E as V, F as x } from "./index-CufXF9Yd.mjs";
4
4
  import { T as d } from "./Toggle-DAxIdpY4.mjs";
5
5
  import { u as q } from "./useAutosave-YwMqRzqy.mjs";
6
- import { A as X } from "./AutosaveIndicator-3S7EvXip.mjs";
6
+ import { A as X } from "./AutosaveIndicator-CWbb-VXf.mjs";
7
7
  const C = {
8
8
  enabled: !0,
9
9
  relatedProducts: {
@@ -1,6 +1,6 @@
1
1
  import { jsx as a, jsxs as i } from "react/jsx-runtime";
2
2
  import { useState as g, useCallback as F, useEffect as D, useMemo as E } from "react";
3
- import { I as h, E as Z, f as K } from "./index-bqhsxBTY.mjs";
3
+ import { I as h, E as Z, f as K } from "./index-CufXF9Yd.mjs";
4
4
  const l = {
5
5
  enabled: !1,
6
6
  plans: [],
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),d=require("react"),u=require("./index-7YUxR4u5.js"),i={enabled:!1,plans:[],pageTitle:"Choose Your Plan",pageSubtitle:"Select the plan that best fits your needs.",annualSavingsBadge:"2 months free",popularBadgeText:"Best Deal",footerNotice:""},X={title:"New Plan",description:"",priceMonthlyUsd:0,priceAnnualUsd:0,features:[],featureHighlight:"",buttonText:"Purchase",isPopular:!1,isActive:!0,sortOrder:0};function Y(){return`plan_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function G({serverUrl:v,apiKey:b,authManager:f}){const[r,h]=d.useState(i),[_,R]=d.useState(!0),[k,T]=d.useState(null),[p,A]=d.useState("plans"),[y,B]=d.useState("idle"),[z,j]=d.useState(null),[l,m]=d.useState({enabled:i.enabled,pageTitle:i.pageTitle,pageSubtitle:i.pageSubtitle,annualSavingsBadge:i.annualSavingsBadge,popularBadgeText:i.popularBadgeText,footerNotice:i.footerNotice}),[x,P]=d.useState(l),[F,C]=d.useState(""),w=d.useCallback(async()=>{try{j(null);let e;const t="/admin/subscriptions/settings";if(f?.isAuthenticated())e=await f.fetchWithAuth(t);else{const n={"Content-Type":"application/json"};b&&(n["X-API-Key"]=b);const s=await fetch(`${v}${t}`,{headers:n});if(!s.ok)throw new Error(`Failed to fetch settings: ${s.status}`);e=await s.json()}h({...i,...e}),m({enabled:e.enabled??i.enabled,pageTitle:e.pageTitle??i.pageTitle,pageSubtitle:e.pageSubtitle??i.pageSubtitle,annualSavingsBadge:e.annualSavingsBadge??i.annualSavingsBadge,popularBadgeText:e.popularBadgeText??i.popularBadgeText,footerNotice:e.footerNotice??i.footerNotice}),P({enabled:e.enabled??i.enabled,pageTitle:e.pageTitle??i.pageTitle,pageSubtitle:e.pageSubtitle??i.pageSubtitle,annualSavingsBadge:e.annualSavingsBadge??i.annualSavingsBadge,popularBadgeText:e.popularBadgeText??i.popularBadgeText,footerNotice:e.footerNotice??i.footerNotice}),C(JSON.stringify(e.plans??[]))}catch{h(i),m({enabled:i.enabled,pageTitle:i.pageTitle,pageSubtitle:i.pageSubtitle,annualSavingsBadge:i.annualSavingsBadge,popularBadgeText:i.popularBadgeText,footerNotice:i.footerNotice}),P({enabled:i.enabled,pageTitle:i.pageTitle,pageSubtitle:i.pageSubtitle,annualSavingsBadge:i.annualSavingsBadge,popularBadgeText:i.popularBadgeText,footerNotice:i.footerNotice}),C(JSON.stringify([])),j("Failed to load subscription settings")}finally{R(!1)}},[v,b,f]);d.useEffect(()=>{w()},[w]);const I=d.useCallback(async e=>{try{j(null);const t="/admin/subscriptions/settings",n=JSON.stringify(e);if(f?.isAuthenticated())await f.fetchWithAuth(t,{method:"PUT",body:n});else{const s={"Content-Type":"application/json"};b&&(s["X-API-Key"]=b);const o=await fetch(`${v}${t}`,{method:"PUT",headers:s,body:n});if(!o.ok)throw new Error(`Failed to save settings: ${o.status}`)}return!0}catch{return j("Failed to save subscription settings"),!1}},[f,b,v]),E=d.useMemo(()=>x.enabled!==l.enabled||x.pageTitle!==l.pageTitle||x.pageSubtitle!==l.pageSubtitle||x.annualSavingsBadge!==l.annualSavingsBadge||x.popularBadgeText!==l.popularBadgeText||x.footerNotice!==l.footerNotice,[l,x]),D=d.useMemo(()=>JSON.stringify(r.plans),[r.plans]),U=d.useMemo(()=>F!==D,[D,F]),S=d.useCallback(async()=>{const e={...r,enabled:l.enabled,pageTitle:l.pageTitle,pageSubtitle:l.pageSubtitle,annualSavingsBadge:l.annualSavingsBadge,popularBadgeText:l.popularBadgeText,footerNotice:l.footerNotice};B("saving");const t=await I(e);h(e),t&&(P({enabled:e.enabled,pageTitle:e.pageTitle,pageSubtitle:e.pageSubtitle,annualSavingsBadge:e.annualSavingsBadge,popularBadgeText:e.popularBadgeText,footerNotice:e.footerNotice}),C(JSON.stringify(e.plans))),B(t?"saved":"error"),setTimeout(()=>B("idle"),1500)},[l,I,r]);d.useEffect(()=>{if(p!=="page"||_||!E)return;const e=setTimeout(S,600);return()=>clearTimeout(e)},[p,E,_,S]),d.useEffect(()=>{if(p!=="plans"||_||!U)return;const e=setTimeout(S,800);return()=>clearTimeout(e)},[p,U,_,S]);const O=()=>{const e={...X,id:Y(),sortOrder:r.plans.length};h(t=>({...t,plans:[...t.plans,e]})),T(e.id)},c=(e,t)=>{h(n=>({...n,plans:n.plans.map(s=>s.id===e?{...s,...t}:s)}))},H=e=>{confirm("Delete this plan? This cannot be undone.")&&(h(t=>({...t,plans:t.plans.filter(n=>n.id!==e)})),k===e&&T(null))},$=(e,t)=>{const n=r.plans.findIndex(g=>g.id===e);if(n===-1||t==="up"&&n===0||t==="down"&&n===r.plans.length-1)return;const s=[...r.plans],o=t==="up"?n-1:n+1;[s[n],s[o]]=[s[o],s[n]],h(g=>({...g,plans:s}))},Q=e=>{c(e,{features:[...r.plans.find(t=>t.id===e)?.features||[],""]})},J=(e,t,n)=>{const s=r.plans.find(g=>g.id===e);if(!s)return;const o=[...s.features];o[t]=n,c(e,{features:o})},q=(e,t)=>{const n=r.plans.find(o=>o.id===e);if(!n)return;const s=n.features.filter((o,g)=>g!==t);c(e,{features:s})};if(_)return a.jsx("div",{className:"cedros-admin__page",children:a.jsxs("div",{className:"cedros-admin__loading",children:[u.Icons.loading," Loading subscription settings..."]})});const M=r.plans.filter(e=>e.isActive).length,L=r.plans.reduce((e,t)=>e+(t.activeSubscribers??0),0),N=l.enabled,W=r.plans.filter(e=>e.isActive).map(e=>({label:e.title,value:e.activeSubscribers??0,description:"subscribers"}));return a.jsxs("div",{className:"cedros-admin__page",children:[a.jsx(u.ErrorBanner,{message:z,onRetry:w}),a.jsx(u.StatsBar,{stats:[{label:"Status",value:N?"Enabled":"Disabled",variant:N?"success":"muted"},{label:"Active Plans",value:M,variant:M>0?"success":"muted"},{label:"Total Subscribers",value:L,variant:L>0?"success":"muted"},...W],isLoading:_}),a.jsxs("div",{className:"cedros-admin__section",children:[a.jsxs("div",{className:"cedros-admin__section-header",children:[a.jsx("h3",{className:"cedros-admin__section-title",children:"Subscription Settings"}),a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[p==="plans"&&a.jsxs("button",{className:"cedros-admin__button cedros-admin__button--primary cedros-admin__button--action",onClick:O,disabled:!N,children:[u.Icons.plus,"Add Plan"]}),a.jsxs("span",{className:`cedros-admin__autosave-indicator cedros-admin__autosave-indicator--${y}`,children:[y==="saving"&&"Saving...",y==="saved"&&"Saved",y==="error"&&"Error"]})]})]}),a.jsxs("div",{className:"cedros-admin__tabs cedros-admin__tabs--line",children:[a.jsx("button",{type:"button",className:`cedros-admin__tab ${p==="plans"?"cedros-admin__tab--active":""}`,onClick:()=>A("plans"),children:"Plans"}),a.jsx("button",{type:"button",className:`cedros-admin__tab ${p==="page"?"cedros-admin__tab--active":""}`,onClick:()=>A("page"),children:"Page Settings"})]}),p==="page"&&a.jsxs("div",{children:[a.jsx("div",{className:"cedros-admin__form-row",children:a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Subscriptions"}),a.jsxs("label",{className:"cedros-admin__toggle",children:[a.jsx("input",{type:"checkbox",className:"cedros-admin__toggle-input",checked:l.enabled,onChange:e=>m(t=>({...t,enabled:e.target.checked}))}),a.jsx("span",{className:"cedros-admin__toggle-track",children:a.jsx("span",{className:"cedros-admin__toggle-thumb"})}),a.jsx("span",{className:"cedros-admin__toggle-label",children:"Enable Subscriptions"})]})]})}),a.jsxs("div",{className:"cedros-admin__form-row",children:[a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Page Title"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:l.pageTitle||"",onChange:e=>m(t=>({...t,pageTitle:e.target.value})),placeholder:"Choose Your Plan"})]}),a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Page Subtitle"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:l.pageSubtitle||"",onChange:e=>m(t=>({...t,pageSubtitle:e.target.value})),placeholder:"Select the plan that best fits your needs."})]})]}),a.jsxs("div",{className:"cedros-admin__form-row",children:[a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Annual Savings Badge"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:l.annualSavingsBadge||"",onChange:e=>m(t=>({...t,annualSavingsBadge:e.target.value})),placeholder:"2 months free"})]}),a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Popular Plan Badge"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:l.popularBadgeText||"",onChange:e=>m(t=>({...t,popularBadgeText:e.target.value})),placeholder:"Best Deal"})]})]}),a.jsx("div",{className:"cedros-admin__form-row",children:a.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Footer Notice (optional)"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:l.footerNotice||"",onChange:e=>m(t=>({...t,footerNotice:e.target.value})),placeholder:"For information regarding invoices, taxes..."})]})})]}),p==="plans"&&a.jsxs("div",{children:[!N&&a.jsx("div",{style:{padding:"1.5rem",textAlign:"center",opacity:.6},children:"Subscriptions are disabled. Enable them to configure plans."}),r.plans.length===0?a.jsx("div",{style:{padding:"2rem",textAlign:"center",opacity:.6,border:"1px dashed currentColor",borderRadius:8},children:'No plans configured. Click "Add Plan" to create your first subscription tier.'}):a.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:r.plans.map((e,t)=>{const n=k===e.id;return a.jsxs("div",{style:{border:"1px solid var(--cedros-admin-border, #e5e5e5)",borderRadius:8,overflow:"hidden",background:e.isPopular?"var(--cedros-admin-bg-accent, #f5f5f5)":void 0},children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"1rem",padding:"0.75rem 1rem",cursor:"pointer"},onClick:()=>T(n?null:e.id),children:[a.jsx("span",{style:{opacity:.5},children:n?u.Icons.chevronDown:u.Icons.chevronRight}),a.jsxs("div",{style:{flex:1},children:[a.jsx("span",{style:{fontWeight:600},children:e.title||"Untitled Plan"}),e.isPopular&&a.jsx("span",{style:{marginLeft:"0.5rem",fontSize:11,padding:"2px 6px",borderRadius:4,background:"var(--cedros-admin-primary, #171717)",color:"#fff"},children:"Popular"}),!e.isActive&&a.jsx("span",{style:{marginLeft:"0.5rem",fontSize:11,padding:"2px 6px",borderRadius:4,background:"#9ca3af",color:"#fff"},children:"Inactive"})]}),a.jsxs("span",{style:{opacity:.6,fontSize:14},children:["$",e.priceMonthlyUsd,"/mo · $",e.priceAnnualUsd,"/yr"]}),a.jsxs("div",{style:{display:"flex",gap:"0.25rem"},onClick:s=>s.stopPropagation(),children:[a.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>$(e.id,"up"),disabled:t===0,title:"Move up",style:{padding:"4px 8px"},children:u.Icons.chevronUp}),a.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>$(e.id,"down"),disabled:t===r.plans.length-1,title:"Move down",style:{padding:"4px 8px"},children:u.Icons.chevronDown}),a.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>H(e.id),title:"Delete plan",style:{padding:"4px 8px",color:"#dc2626"},children:u.Icons.trash})]})]}),n&&a.jsxs("div",{style:{padding:"1rem",borderTop:"1px solid var(--cedros-admin-border, #e5e5e5)"},children:[a.jsxs("div",{className:"cedros-admin__form-row",children:[a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Plan Name"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:e.title,onChange:s=>c(e.id,{title:s.target.value}),placeholder:"e.g., Starter"})]}),a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Button Text"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:e.buttonText||"",onChange:s=>c(e.id,{buttonText:s.target.value}),placeholder:"Purchase"})]})]}),a.jsx("div",{className:"cedros-admin__form-row",children:a.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Description"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:e.description,onChange:s=>c(e.id,{description:s.target.value}),placeholder:"For entry-level developers managing lightweight workloads"})]})}),a.jsxs("div",{className:"cedros-admin__form-row",children:[a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Monthly Price (USD)"}),a.jsx("input",{type:"number",className:"cedros-admin__input",value:e.priceMonthlyUsd||"",onChange:s=>c(e.id,{priceMonthlyUsd:parseFloat(s.target.value)||0}),placeholder:"10",min:"0",step:"0.01"})]}),a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Annual Price (USD)"}),a.jsx("input",{type:"number",className:"cedros-admin__input",value:e.priceAnnualUsd||"",onChange:s=>c(e.id,{priceAnnualUsd:parseFloat(s.target.value)||0}),placeholder:"100",min:"0",step:"0.01"})]})]}),a.jsx("div",{className:"cedros-admin__form-row",children:a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Feature Highlight"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:e.featureHighlight||"",onChange:s=>c(e.id,{featureHighlight:s.target.value}),placeholder:"100 prompts every 5 hours"}),a.jsx("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:"Bold text shown above feature list"})]})}),a.jsxs("div",{className:"cedros-admin__form-row",children:[a.jsx("div",{className:"cedros-admin__field",children:a.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},children:[a.jsx("input",{type:"checkbox",checked:e.isPopular||!1,onChange:s=>c(e.id,{isPopular:s.target.checked})}),"Mark as Popular (featured styling)"]})}),a.jsx("div",{className:"cedros-admin__field",children:a.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},children:[a.jsx("input",{type:"checkbox",checked:e.isActive,onChange:s=>c(e.id,{isActive:s.target.checked})}),"Active (available for purchase)"]})})]}),a.jsxs("div",{className:"cedros-admin__form-row",style:{marginTop:"0.5rem"},children:[a.jsx("div",{className:"cedros-admin__field",children:a.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},children:[a.jsx("input",{type:"checkbox",checked:e.inventoryQuantity!=null,onChange:s=>c(e.id,{inventoryQuantity:s.target.checked?100:null})}),"Limit quantity available"]})}),e.inventoryQuantity!=null&&a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Total Available"}),a.jsx("input",{type:"number",className:"cedros-admin__input",value:e.inventoryQuantity??"",onChange:s=>c(e.id,{inventoryQuantity:parseInt(s.target.value)||0}),min:"0",style:{width:100}}),e.inventorySold!=null&&e.inventorySold>0&&a.jsxs("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:[e.inventorySold," sold · ",Math.max(0,e.inventoryQuantity-e.inventorySold)," remaining"]})]})]}),a.jsxs("div",{style:{marginTop:"1rem"},children:[a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"0.5rem"},children:[a.jsxs("label",{className:"cedros-admin__field-label",style:{margin:0},children:["Feature List (",e.features.length,")"]}),a.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>Q(e.id),style:{fontSize:12,padding:"4px 8px"},children:"+ Add Feature"})]}),e.features.length===0?a.jsx("div",{style:{padding:"1rem",textAlign:"center",opacity:.5,fontSize:13,border:"1px dashed currentColor",borderRadius:6},children:'No features. Click "Add Feature" to add bullet points.'}):a.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:e.features.map((s,o)=>a.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center"},children:[a.jsxs("span",{style:{opacity:.4,fontSize:12},children:[o+1,"."]}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:s,onChange:g=>J(e.id,o,g.target.value),placeholder:"e.g., Powered by MiniMax M2.1",style:{flex:1}}),a.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>q(e.id,o),style:{padding:"4px 8px",color:"#dc2626"},title:"Remove feature",children:u.Icons.trash})]},o))})]})]})]},e.id)})})]})]})]})}exports.SubscriptionsSection=G;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),d=require("react"),u=require("./index-IZ4WcMd7.js"),i={enabled:!1,plans:[],pageTitle:"Choose Your Plan",pageSubtitle:"Select the plan that best fits your needs.",annualSavingsBadge:"2 months free",popularBadgeText:"Best Deal",footerNotice:""},X={title:"New Plan",description:"",priceMonthlyUsd:0,priceAnnualUsd:0,features:[],featureHighlight:"",buttonText:"Purchase",isPopular:!1,isActive:!0,sortOrder:0};function Y(){return`plan_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function G({serverUrl:v,apiKey:b,authManager:f}){const[r,h]=d.useState(i),[_,R]=d.useState(!0),[k,T]=d.useState(null),[p,A]=d.useState("plans"),[y,B]=d.useState("idle"),[z,j]=d.useState(null),[l,m]=d.useState({enabled:i.enabled,pageTitle:i.pageTitle,pageSubtitle:i.pageSubtitle,annualSavingsBadge:i.annualSavingsBadge,popularBadgeText:i.popularBadgeText,footerNotice:i.footerNotice}),[x,P]=d.useState(l),[F,C]=d.useState(""),w=d.useCallback(async()=>{try{j(null);let e;const t="/admin/subscriptions/settings";if(f?.isAuthenticated())e=await f.fetchWithAuth(t);else{const n={"Content-Type":"application/json"};b&&(n["X-API-Key"]=b);const s=await fetch(`${v}${t}`,{headers:n});if(!s.ok)throw new Error(`Failed to fetch settings: ${s.status}`);e=await s.json()}h({...i,...e}),m({enabled:e.enabled??i.enabled,pageTitle:e.pageTitle??i.pageTitle,pageSubtitle:e.pageSubtitle??i.pageSubtitle,annualSavingsBadge:e.annualSavingsBadge??i.annualSavingsBadge,popularBadgeText:e.popularBadgeText??i.popularBadgeText,footerNotice:e.footerNotice??i.footerNotice}),P({enabled:e.enabled??i.enabled,pageTitle:e.pageTitle??i.pageTitle,pageSubtitle:e.pageSubtitle??i.pageSubtitle,annualSavingsBadge:e.annualSavingsBadge??i.annualSavingsBadge,popularBadgeText:e.popularBadgeText??i.popularBadgeText,footerNotice:e.footerNotice??i.footerNotice}),C(JSON.stringify(e.plans??[]))}catch{h(i),m({enabled:i.enabled,pageTitle:i.pageTitle,pageSubtitle:i.pageSubtitle,annualSavingsBadge:i.annualSavingsBadge,popularBadgeText:i.popularBadgeText,footerNotice:i.footerNotice}),P({enabled:i.enabled,pageTitle:i.pageTitle,pageSubtitle:i.pageSubtitle,annualSavingsBadge:i.annualSavingsBadge,popularBadgeText:i.popularBadgeText,footerNotice:i.footerNotice}),C(JSON.stringify([])),j("Failed to load subscription settings")}finally{R(!1)}},[v,b,f]);d.useEffect(()=>{w()},[w]);const I=d.useCallback(async e=>{try{j(null);const t="/admin/subscriptions/settings",n=JSON.stringify(e);if(f?.isAuthenticated())await f.fetchWithAuth(t,{method:"PUT",body:n});else{const s={"Content-Type":"application/json"};b&&(s["X-API-Key"]=b);const o=await fetch(`${v}${t}`,{method:"PUT",headers:s,body:n});if(!o.ok)throw new Error(`Failed to save settings: ${o.status}`)}return!0}catch{return j("Failed to save subscription settings"),!1}},[f,b,v]),E=d.useMemo(()=>x.enabled!==l.enabled||x.pageTitle!==l.pageTitle||x.pageSubtitle!==l.pageSubtitle||x.annualSavingsBadge!==l.annualSavingsBadge||x.popularBadgeText!==l.popularBadgeText||x.footerNotice!==l.footerNotice,[l,x]),D=d.useMemo(()=>JSON.stringify(r.plans),[r.plans]),U=d.useMemo(()=>F!==D,[D,F]),S=d.useCallback(async()=>{const e={...r,enabled:l.enabled,pageTitle:l.pageTitle,pageSubtitle:l.pageSubtitle,annualSavingsBadge:l.annualSavingsBadge,popularBadgeText:l.popularBadgeText,footerNotice:l.footerNotice};B("saving");const t=await I(e);h(e),t&&(P({enabled:e.enabled,pageTitle:e.pageTitle,pageSubtitle:e.pageSubtitle,annualSavingsBadge:e.annualSavingsBadge,popularBadgeText:e.popularBadgeText,footerNotice:e.footerNotice}),C(JSON.stringify(e.plans))),B(t?"saved":"error"),setTimeout(()=>B("idle"),1500)},[l,I,r]);d.useEffect(()=>{if(p!=="page"||_||!E)return;const e=setTimeout(S,600);return()=>clearTimeout(e)},[p,E,_,S]),d.useEffect(()=>{if(p!=="plans"||_||!U)return;const e=setTimeout(S,800);return()=>clearTimeout(e)},[p,U,_,S]);const O=()=>{const e={...X,id:Y(),sortOrder:r.plans.length};h(t=>({...t,plans:[...t.plans,e]})),T(e.id)},c=(e,t)=>{h(n=>({...n,plans:n.plans.map(s=>s.id===e?{...s,...t}:s)}))},H=e=>{confirm("Delete this plan? This cannot be undone.")&&(h(t=>({...t,plans:t.plans.filter(n=>n.id!==e)})),k===e&&T(null))},$=(e,t)=>{const n=r.plans.findIndex(g=>g.id===e);if(n===-1||t==="up"&&n===0||t==="down"&&n===r.plans.length-1)return;const s=[...r.plans],o=t==="up"?n-1:n+1;[s[n],s[o]]=[s[o],s[n]],h(g=>({...g,plans:s}))},Q=e=>{c(e,{features:[...r.plans.find(t=>t.id===e)?.features||[],""]})},J=(e,t,n)=>{const s=r.plans.find(g=>g.id===e);if(!s)return;const o=[...s.features];o[t]=n,c(e,{features:o})},q=(e,t)=>{const n=r.plans.find(o=>o.id===e);if(!n)return;const s=n.features.filter((o,g)=>g!==t);c(e,{features:s})};if(_)return a.jsx("div",{className:"cedros-admin__page",children:a.jsxs("div",{className:"cedros-admin__loading",children:[u.Icons.loading," Loading subscription settings..."]})});const M=r.plans.filter(e=>e.isActive).length,L=r.plans.reduce((e,t)=>e+(t.activeSubscribers??0),0),N=l.enabled,W=r.plans.filter(e=>e.isActive).map(e=>({label:e.title,value:e.activeSubscribers??0,description:"subscribers"}));return a.jsxs("div",{className:"cedros-admin__page",children:[a.jsx(u.ErrorBanner,{message:z,onRetry:w}),a.jsx(u.StatsBar,{stats:[{label:"Status",value:N?"Enabled":"Disabled",variant:N?"success":"muted"},{label:"Active Plans",value:M,variant:M>0?"success":"muted"},{label:"Total Subscribers",value:L,variant:L>0?"success":"muted"},...W],isLoading:_}),a.jsxs("div",{className:"cedros-admin__section",children:[a.jsxs("div",{className:"cedros-admin__section-header",children:[a.jsx("h3",{className:"cedros-admin__section-title",children:"Subscription Settings"}),a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[p==="plans"&&a.jsxs("button",{className:"cedros-admin__button cedros-admin__button--primary cedros-admin__button--action",onClick:O,disabled:!N,children:[u.Icons.plus,"Add Plan"]}),a.jsxs("span",{className:`cedros-admin__autosave-indicator cedros-admin__autosave-indicator--${y}`,children:[y==="saving"&&"Saving...",y==="saved"&&"Saved",y==="error"&&"Error"]})]})]}),a.jsxs("div",{className:"cedros-admin__tabs cedros-admin__tabs--line",children:[a.jsx("button",{type:"button",className:`cedros-admin__tab ${p==="plans"?"cedros-admin__tab--active":""}`,onClick:()=>A("plans"),children:"Plans"}),a.jsx("button",{type:"button",className:`cedros-admin__tab ${p==="page"?"cedros-admin__tab--active":""}`,onClick:()=>A("page"),children:"Page Settings"})]}),p==="page"&&a.jsxs("div",{children:[a.jsx("div",{className:"cedros-admin__form-row",children:a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Subscriptions"}),a.jsxs("label",{className:"cedros-admin__toggle",children:[a.jsx("input",{type:"checkbox",className:"cedros-admin__toggle-input",checked:l.enabled,onChange:e=>m(t=>({...t,enabled:e.target.checked}))}),a.jsx("span",{className:"cedros-admin__toggle-track",children:a.jsx("span",{className:"cedros-admin__toggle-thumb"})}),a.jsx("span",{className:"cedros-admin__toggle-label",children:"Enable Subscriptions"})]})]})}),a.jsxs("div",{className:"cedros-admin__form-row",children:[a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Page Title"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:l.pageTitle||"",onChange:e=>m(t=>({...t,pageTitle:e.target.value})),placeholder:"Choose Your Plan"})]}),a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Page Subtitle"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:l.pageSubtitle||"",onChange:e=>m(t=>({...t,pageSubtitle:e.target.value})),placeholder:"Select the plan that best fits your needs."})]})]}),a.jsxs("div",{className:"cedros-admin__form-row",children:[a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Annual Savings Badge"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:l.annualSavingsBadge||"",onChange:e=>m(t=>({...t,annualSavingsBadge:e.target.value})),placeholder:"2 months free"})]}),a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Popular Plan Badge"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:l.popularBadgeText||"",onChange:e=>m(t=>({...t,popularBadgeText:e.target.value})),placeholder:"Best Deal"})]})]}),a.jsx("div",{className:"cedros-admin__form-row",children:a.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Footer Notice (optional)"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:l.footerNotice||"",onChange:e=>m(t=>({...t,footerNotice:e.target.value})),placeholder:"For information regarding invoices, taxes..."})]})})]}),p==="plans"&&a.jsxs("div",{children:[!N&&a.jsx("div",{style:{padding:"1.5rem",textAlign:"center",opacity:.6},children:"Subscriptions are disabled. Enable them to configure plans."}),r.plans.length===0?a.jsx("div",{style:{padding:"2rem",textAlign:"center",opacity:.6,border:"1px dashed currentColor",borderRadius:8},children:'No plans configured. Click "Add Plan" to create your first subscription tier.'}):a.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:r.plans.map((e,t)=>{const n=k===e.id;return a.jsxs("div",{style:{border:"1px solid var(--cedros-admin-border, #e5e5e5)",borderRadius:8,overflow:"hidden",background:e.isPopular?"var(--cedros-admin-bg-accent, #f5f5f5)":void 0},children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"1rem",padding:"0.75rem 1rem",cursor:"pointer"},onClick:()=>T(n?null:e.id),children:[a.jsx("span",{style:{opacity:.5},children:n?u.Icons.chevronDown:u.Icons.chevronRight}),a.jsxs("div",{style:{flex:1},children:[a.jsx("span",{style:{fontWeight:600},children:e.title||"Untitled Plan"}),e.isPopular&&a.jsx("span",{style:{marginLeft:"0.5rem",fontSize:11,padding:"2px 6px",borderRadius:4,background:"var(--cedros-admin-primary, #171717)",color:"#fff"},children:"Popular"}),!e.isActive&&a.jsx("span",{style:{marginLeft:"0.5rem",fontSize:11,padding:"2px 6px",borderRadius:4,background:"#9ca3af",color:"#fff"},children:"Inactive"})]}),a.jsxs("span",{style:{opacity:.6,fontSize:14},children:["$",e.priceMonthlyUsd,"/mo · $",e.priceAnnualUsd,"/yr"]}),a.jsxs("div",{style:{display:"flex",gap:"0.25rem"},onClick:s=>s.stopPropagation(),children:[a.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>$(e.id,"up"),disabled:t===0,title:"Move up",style:{padding:"4px 8px"},children:u.Icons.chevronUp}),a.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>$(e.id,"down"),disabled:t===r.plans.length-1,title:"Move down",style:{padding:"4px 8px"},children:u.Icons.chevronDown}),a.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>H(e.id),title:"Delete plan",style:{padding:"4px 8px",color:"#dc2626"},children:u.Icons.trash})]})]}),n&&a.jsxs("div",{style:{padding:"1rem",borderTop:"1px solid var(--cedros-admin-border, #e5e5e5)"},children:[a.jsxs("div",{className:"cedros-admin__form-row",children:[a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Plan Name"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:e.title,onChange:s=>c(e.id,{title:s.target.value}),placeholder:"e.g., Starter"})]}),a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Button Text"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:e.buttonText||"",onChange:s=>c(e.id,{buttonText:s.target.value}),placeholder:"Purchase"})]})]}),a.jsx("div",{className:"cedros-admin__form-row",children:a.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Description"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:e.description,onChange:s=>c(e.id,{description:s.target.value}),placeholder:"For entry-level developers managing lightweight workloads"})]})}),a.jsxs("div",{className:"cedros-admin__form-row",children:[a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Monthly Price (USD)"}),a.jsx("input",{type:"number",className:"cedros-admin__input",value:e.priceMonthlyUsd||"",onChange:s=>c(e.id,{priceMonthlyUsd:parseFloat(s.target.value)||0}),placeholder:"10",min:"0",step:"0.01"})]}),a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Annual Price (USD)"}),a.jsx("input",{type:"number",className:"cedros-admin__input",value:e.priceAnnualUsd||"",onChange:s=>c(e.id,{priceAnnualUsd:parseFloat(s.target.value)||0}),placeholder:"100",min:"0",step:"0.01"})]})]}),a.jsx("div",{className:"cedros-admin__form-row",children:a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Feature Highlight"}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:e.featureHighlight||"",onChange:s=>c(e.id,{featureHighlight:s.target.value}),placeholder:"100 prompts every 5 hours"}),a.jsx("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:"Bold text shown above feature list"})]})}),a.jsxs("div",{className:"cedros-admin__form-row",children:[a.jsx("div",{className:"cedros-admin__field",children:a.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},children:[a.jsx("input",{type:"checkbox",checked:e.isPopular||!1,onChange:s=>c(e.id,{isPopular:s.target.checked})}),"Mark as Popular (featured styling)"]})}),a.jsx("div",{className:"cedros-admin__field",children:a.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},children:[a.jsx("input",{type:"checkbox",checked:e.isActive,onChange:s=>c(e.id,{isActive:s.target.checked})}),"Active (available for purchase)"]})})]}),a.jsxs("div",{className:"cedros-admin__form-row",style:{marginTop:"0.5rem"},children:[a.jsx("div",{className:"cedros-admin__field",children:a.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},children:[a.jsx("input",{type:"checkbox",checked:e.inventoryQuantity!=null,onChange:s=>c(e.id,{inventoryQuantity:s.target.checked?100:null})}),"Limit quantity available"]})}),e.inventoryQuantity!=null&&a.jsxs("div",{className:"cedros-admin__field",children:[a.jsx("label",{className:"cedros-admin__field-label",children:"Total Available"}),a.jsx("input",{type:"number",className:"cedros-admin__input",value:e.inventoryQuantity??"",onChange:s=>c(e.id,{inventoryQuantity:parseInt(s.target.value)||0}),min:"0",style:{width:100}}),e.inventorySold!=null&&e.inventorySold>0&&a.jsxs("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:[e.inventorySold," sold · ",Math.max(0,e.inventoryQuantity-e.inventorySold)," remaining"]})]})]}),a.jsxs("div",{style:{marginTop:"1rem"},children:[a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"0.5rem"},children:[a.jsxs("label",{className:"cedros-admin__field-label",style:{margin:0},children:["Feature List (",e.features.length,")"]}),a.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>Q(e.id),style:{fontSize:12,padding:"4px 8px"},children:"+ Add Feature"})]}),e.features.length===0?a.jsx("div",{style:{padding:"1rem",textAlign:"center",opacity:.5,fontSize:13,border:"1px dashed currentColor",borderRadius:6},children:'No features. Click "Add Feature" to add bullet points.'}):a.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:e.features.map((s,o)=>a.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center"},children:[a.jsxs("span",{style:{opacity:.4,fontSize:12},children:[o+1,"."]}),a.jsx("input",{type:"text",className:"cedros-admin__input",value:s,onChange:g=>J(e.id,o,g.target.value),placeholder:"e.g., Powered by MiniMax M2.1",style:{flex:1}}),a.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>q(e.id,o),style:{padding:"4px 8px",color:"#dc2626"},title:"Remove feature",children:u.Icons.trash})]},o))})]})]})]},e.id)})})]})]})]})}exports.SubscriptionsSection=G;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./styles-BWrLnaUW.js"),t=require("./CedrosContext-D-lnoEkR.js"),N=require("./index-7YUxR4u5.js"),ce=require("./CryptoButton-Dy-g3bR0.js"),S=require("react/jsx-runtime"),a=require("react"),$=require("@solana/wallet-adapter-react"),ie=require("@solana/wallet-adapter-base"),Pe=require("@solana/wallet-adapter-react-ui"),le=require("./walletPool-BqNfOhB0.js");function ue(){const{subscriptionManager:o,x402Manager:d,walletManager:f}=t.useCedrosContext(),{publicKey:u,signTransaction:T}=$.useWallet(),[P,y]=a.useState({status:"idle",error:null,sessionId:null,subscriptionStatus:null,expiresAt:null}),[k,R]=a.useState(null),x=a.useRef(!1),h=a.useCallback(()=>{if(!u){const c="Wallet not connected";return y(n=>({...n,status:"error",error:c})),{valid:!1,error:c}}if(!T){const c="Wallet does not support signing";return y(n=>({...n,status:"error",error:c})),{valid:!1,error:c}}return{valid:!0}},[u,T]),_=a.useCallback(async c=>{if(!u)return y(n=>({...n,status:"error",error:"Wallet not connected"})),null;y(n=>({...n,status:"checking",error:null}));try{const n=await o.checkSubscriptionStatus({resource:c,userId:u.toString()});return y(s=>({...s,status:n.active?"success":"idle",subscriptionStatus:n.status,expiresAt:n.expiresAt||n.currentPeriodEnd||null})),n}catch(n){const s=t.formatError(n,"Failed to check subscription status");return y(g=>({...g,status:"error",error:s})),null}},[u,o]),L=a.useCallback(async(c,n,s)=>{y(g=>({...g,status:"loading",error:null}));try{const g=await o.requestSubscriptionQuote(c,n,s);return R(g),y(i=>({...i,status:"idle"})),g}catch(g){const i=t.formatError(g,"Failed to get subscription quote");return y(l=>({...l,status:"error",error:i})),null}},[o]),C=a.useCallback(async(c,n,s)=>{if(x.current)return{success:!1,error:"Payment already in progress"};const g=h();if(!g.valid)return{success:!1,error:g.error};x.current=!0,y(i=>({...i,status:"loading",error:null}));try{const i=await o.requestSubscriptionQuote(c,n,s);R(i);const l=i.requirement;if(!d.validateRequirement(l))throw new Error("Invalid subscription quote received from server");const E=!!l.extra?.feePayer;let b;if(E){const{transaction:w,blockhash:W}=await d.buildGaslessTransaction({resourceId:c,userWallet:u.toString(),feePayer:l.extra.feePayer,couponCode:s?.couponCode}),M=f.deserializeTransaction(w),q=await f.partiallySignTransaction({transaction:M,signTransaction:T,blockhash:W});b=await d.submitGaslessTransaction({resource:c,partialTx:q,couponCode:s?.couponCode,resourceType:"regular",requirement:l})}else{const w=await f.buildTransaction({requirement:l,payerPublicKey:u}),W=await f.signTransaction({transaction:w,signTransaction:T}),M=f.buildPaymentPayload({requirement:l,signedTx:W,payerPublicKey:u});b=await d.submitPayment({resource:c,payload:M,couponCode:s?.couponCode,resourceType:"regular"})}if(b.success){const w=await o.checkSubscriptionStatus({resource:c,userId:u.toString()});y({status:"success",error:null,sessionId:b.transactionId||null,subscriptionStatus:w.status,expiresAt:w.expiresAt||w.currentPeriodEnd||null})}else y(w=>({...w,status:"error",error:b.error||"Subscription payment failed"}));return b}catch(i){const l=t.formatError(i,"Subscription payment failed");return y(E=>({...E,status:"error",error:l})),{success:!1,error:l}}finally{x.current=!1}},[h,o,d,f,u,T]),v=a.useCallback(()=>{y({status:"idle",error:null,sessionId:null,subscriptionStatus:null,expiresAt:null}),R(null)},[]);return{...P,quote:k,checkStatus:_,requestQuote:L,processPayment:C,reset:v}}function we({resource:o,interval:d,intervalDays:f,couponCode:u,label:T,disabled:P=!1,onAttempt:y,onSuccess:k,onError:R,className:x="",testPageUrl:h,hideMessages:_=!1,autoCheckStatus:L=!0}){const{connected:C,connecting:v,connect:c,disconnect:n,select:s,wallets:g,wallet:i,publicKey:l}=$.useWallet(),{status:E,error:b,subscriptionStatus:w,expiresAt:W,checkStatus:M,processPayment:q}=ue(),p=t.useCedrosTheme(),{solanaError:I}=t.useCedrosContext(),{t:B,translations:G}=e.useTranslation(),de=T||B("ui.subscribe_with_crypto"),Q=a.useRef(k),F=a.useRef(R),V=a.useRef(q),X=a.useRef(M);Q.current=k,F.current=R,V.current=q,X.current=M;const ge=b&&typeof b!="string"?b?.code??null:null,pe=I&&typeof I!="string"?I?.code??null:null,H=r=>{if(!r||!G)return"";const m=G.errors[r];return m?m.action?`${m.message} ${m.action}`:m.message:""},J=b?typeof b=="string"?b:H(ge):null,Z=I?typeof I=="string"?I:H(pe):null,me=a.useMemo(()=>g.map(r=>`${r.adapter.name}-${r.readyState}`).join(","),[g]),K=a.useMemo(()=>g.filter(({readyState:r})=>r===ie.WalletReadyState.Installed||r===ie.WalletReadyState.Loadable),[me]);a.useEffect(()=>{L&&C&&l&&(t.getLogger().debug("[CryptoSubscribeButton] Auto-checking subscription status"),X.current(o))},[L,C,l,o]),a.useEffect(()=>{E==="success"&&w==="active"&&(e.emitPaymentSuccess("crypto","subscription-active",o),Q.current?.("subscription-active"))},[E,w,o]),a.useEffect(()=>{E==="error"&&b&&(e.emitPaymentError("crypto",b,o),F.current?.(b))},[E,b,o]);const ee=typeof window<"u"&&window.top!==window.self,[te,O]=a.useState(!1),[re,U]=a.useState(!1),[ne,A]=a.useState(!1),D=I;a.useEffect(()=>{let r=!1;return r||(async()=>{if(re&&i&&!C&&!v){t.getLogger().debug("[CryptoSubscribeButton] Wallet detected, attempting auto-connect:",i.adapter.name),U(!1),e.emitWalletConnect(i.adapter.name);try{await c(),r||t.getLogger().debug("[CryptoSubscribeButton] Auto-connect successful")}catch(Y){if(!r){t.getLogger().error("[CryptoSubscribeButton] Auto-connect failed:",Y);const Ee=Y instanceof Error?Y.message:"Failed to connect wallet";e.emitWalletError(Ee,i.adapter.name),A(!1)}}}})(),()=>{r=!0}},[i,re,C,v,c]),a.useEffect(()=>{C&&ne&&l&&i&&(e.emitWalletConnected(i.adapter.name,l.toString()),t.getLogger().debug("[CryptoSubscribeButton] Processing pending subscription payment"),A(!1),O(!1),e.emitPaymentProcessing("crypto",o),V.current(o,d,{couponCode:u,intervalDays:f}))},[C,ne,l,i,o,d,u,f]);const oe=a.useCallback(async()=>{if(t.getLogger().debug("[CryptoSubscribeButton] executeSubscriptionFlow called",{connected:C,wallet:i?.adapter.name,resource:o,interval:d}),e.emitPaymentStart("crypto",o),y&&y("crypto"),D){t.getLogger().error("[CryptoSubscribeButton] Solana dependencies missing:",D),e.emitPaymentError("crypto",D,o),R&&R(D);return}if(ee){const r=h||window.location.href;try{if(new URL(r,window.location.origin).origin!==window.location.origin)throw t.getLogger().error("[CryptoSubscribeButton] Blocked attempt to open external URL:",r),new Error("Cannot open external URLs from embedded context");window.open(r,"_blank","noopener,noreferrer")}catch(m){throw t.getLogger().error("[CryptoSubscribeButton] URL validation failed:",m),m}return}if(C)e.emitPaymentProcessing("crypto",o),await q(o,d,{couponCode:u,intervalDays:f});else{A(!0);try{if(i)t.getLogger().debug("[CryptoSubscribeButton] Wallet already selected, connecting:",i.adapter.name),e.emitWalletConnect(i.adapter.name),await c();else{if(t.getLogger().debug("[CryptoSubscribeButton] No wallet selected, showing selector"),K.length===0){A(!1);const r="No wallets available";throw e.emitWalletError(r),new Error(r)}O(!0)}}catch(r){A(!1);const m=r instanceof Error?r.message:"Failed to connect wallet";t.getLogger().error("[CryptoSubscribeButton] Connection error:",m),e.emitWalletError(m,i?.adapter.name)}}},[C,i,o,d,u,f,ee,h,K,c,q,D,y,R]),ae=a.useMemo(()=>`crypto-subscribe-${o}-${d}`,[o,d]),ye=a.useMemo(()=>e.createDedupedClickHandler(ae,oe,{cooldownMs:200,deduplicationWindowMs:0}),[ae,oe]),se=E==="loading"||E==="checking",j=w==="active"||w==="trialing",fe=P||se||v||!!D||j;let z=de;if(se)z=B("ui.processing");else if(j&&W){const r=new Date(W).toLocaleDateString();z=`${B("ui.subscribed_until")} ${r}`}else j&&(z=B("ui.subscribed"));const be=a.useCallback(async()=>{try{U(!1),C&&await n(),s(null),O(!0)}catch(r){t.getLogger().error("Failed to change wallet:",r)}},[C,n,s]),Se=a.useCallback(r=>{t.getLogger().debug("[CryptoSubscribeButton] Wallet clicked:",r),O(!1),s(r),U(!0)},[s]),Ce=a.useCallback(async()=>{try{if(await n(),A(!1),typeof window<"u"&&window.localStorage)try{window.localStorage.removeItem("walletName")}catch(r){r instanceof Error&&r.name==="QuotaExceededError"?t.getLogger().warn("localStorage quota exceeded when removing wallet preference"):t.getLogger().error("Failed to clear wallet preference from localStorage:",r)}}catch(r){t.getLogger().error("Failed to disconnect wallet:",r)}},[n]);return S.jsxs("div",{className:p.unstyled?x:`${p.className} cedros-theme__crypto-button ${x||""}`,style:p.unstyled?{}:p.style,children:[S.jsx("button",{onClick:ye,disabled:fe,className:p.unstyled?x:"cedros-theme__button cedros-theme__crypto",type:"button",children:z}),te&&!_&&S.jsx("div",{className:"cedros-modal-overlay",style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:p.tokens.modalOverlay,display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999,padding:"1rem"},onClick:()=>O(!1),children:S.jsxs("div",{className:"cedros-modal-content",style:{backgroundColor:p.tokens.modalBackground,borderRadius:"12px",padding:"2rem",maxWidth:"400px",width:"100%",boxShadow:"0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)",border:`1px solid ${p.tokens.modalBorder}`},onClick:r=>r.stopPropagation(),children:[S.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"1.5rem"},children:[S.jsx("h3",{style:{margin:0,fontSize:"1.25rem",fontWeight:600,color:p.tokens.surfaceText},children:B("wallet.select_wallet")}),S.jsx("button",{onClick:()=>O(!1),style:e.getModalCloseButtonStyles(p.tokens.surfaceText),"aria-label":"Close modal",type:"button",children:"×"})]}),S.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:K.map(r=>S.jsxs("button",{onClick:()=>Se(r.adapter.name),style:{width:"100%",padding:"1rem",backgroundColor:p.tokens.surfaceBackground,border:`1px solid ${p.tokens.surfaceBorder}`,borderRadius:"0.5rem",cursor:"pointer",fontSize:"1rem",textAlign:"left",color:p.tokens.surfaceText,display:"flex",alignItems:"center",gap:"1rem",transition:"all 0.2s ease"},onMouseEnter:m=>{m.currentTarget.style.backgroundColor=p.tokens.modalBackground,m.currentTarget.style.borderColor=p.tokens.surfaceText,m.currentTarget.style.transform="translateY(-2px)"},onMouseLeave:m=>{m.currentTarget.style.backgroundColor=p.tokens.surfaceBackground,m.currentTarget.style.borderColor=p.tokens.surfaceBorder,m.currentTarget.style.transform="translateY(0)"},type:"button",children:[S.jsx(Pe.WalletIcon,{wallet:r,style:{width:"24px",height:"24px"}}),S.jsx("span",{style:{fontWeight:500},children:r.adapter.name})]},r.adapter.name))})]})}),C&&!_&&!te&&S.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"0.5rem",fontSize:"0.75rem",color:p.tokens.surfaceText,opacity:.7},children:[S.jsx("button",{onClick:be,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:B("wallet.change")}),S.jsx("button",{onClick:Ce,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:B("ui.disconnect")})]}),!_&&Z&&S.jsx("div",{className:p.unstyled?"":"cedros-theme__error",children:Z}),!_&&J&&S.jsx("div",{className:p.unstyled?"":"cedros-theme__error",children:J}),!_&&j&&S.jsx("div",{className:p.unstyled?"":"cedros-theme__success",children:B("ui.subscription_active")})]})}function he(){const{x402Manager:o,walletManager:d}=t.useCedrosContext(),{publicKey:f,signTransaction:u}=$.useWallet(),[T,P]=a.useState({status:"idle",error:null,transactionId:null}),[y,k]=a.useState(null),[R,x]=a.useState(null),h=a.useRef(!1),_=a.useCallback(async c=>{try{P(s=>({...s,status:"loading"}));const n=await o.requestQuote({resource:c});if(!o.validateRequirement(n))throw new Error("Invalid refund requirement received from server");return k(n),P(s=>({...s,status:"idle"})),n}catch(n){const s=t.formatError(n,"Failed to fetch refund requirement");throw P({status:"error",error:s,transactionId:null}),n}},[o]),L=a.useCallback(async(c,n)=>{if(h.current)throw new Error("Refund already in progress");if(!f||!u)throw new Error("Wallet not connected");h.current=!0;try{P({status:"loading",error:null,transactionId:null});const s=await o.requestQuote({resource:c,couponCode:n});if(!o.validateRequirement(s))throw new Error("Invalid refund requirement received");k(s);const g=await d.buildTransaction({requirement:s,payerPublicKey:f}),i=await d.signTransaction({transaction:g,signTransaction:u}),l=d.buildPaymentPayload({requirement:s,signedTx:i,payerPublicKey:f}),E=await o.submitPayment({resource:c,payload:l,couponCode:n,metadata:void 0,resourceType:"refund"});return E.settlement&&x(E.settlement),P({status:"success",error:null,transactionId:E.transactionId||i.signature}),E}catch(s){const g=t.formatError(s,"Refund payment failed");throw P({status:"error",error:g,transactionId:null}),s}finally{h.current=!1}},[f,u,o,d]),C=a.useCallback(async c=>{if(h.current)throw new Error("Refund already in progress");if(!f||!u)throw new Error("Wallet not connected");h.current=!0;try{P({status:"loading",error:null,transactionId:null});const n=await o.requestQuote({resource:c});if(!o.validateRequirement(n))throw new Error("Invalid refund requirement received");k(n);const{transaction:s}=await o.buildGaslessTransaction({resourceId:c,userWallet:f.toString(),feePayer:n.extra.feePayer}),g=d.deserializeTransaction(s),i=await d.partiallySignTransaction({transaction:g,signTransaction:u}),l=await o.submitGaslessTransaction({resource:c,partialTx:i,couponCode:void 0,metadata:void 0,resourceType:"refund",requirement:n});return l.settlement&&x(l.settlement),P({status:"success",error:null,transactionId:l.transactionId||"gasless-refund-tx"}),l}catch(n){const s=t.formatError(n,"Gasless refund payment failed");throw P({status:"error",error:s,transactionId:null}),n}finally{h.current=!1}},[f,u,o,d]),v=a.useCallback(()=>{P({status:"idle",error:null,transactionId:null}),k(null),x(null)},[]);return{state:T,requirement:y,settlement:R,fetchRefundQuote:_,processRefund:L,processGaslessRefund:C,reset:v}}exports.CEDROS_EVENTS=e.CEDROS_EVENTS;exports.CSP_PRESETS=e.CSP_PRESETS;exports.CedrosPay=e.CedrosPay;exports.CreditsButton=e.CreditsButton;exports.CreditsSubscribeButton=e.CreditsSubscribeButton;exports.PaymentMethodBadge=e.PaymentMethodBadge;exports.PaymentModal=e.PaymentModal;exports.ProductPrice=e.ProductPrice;exports.PurchaseButton=e.PurchaseButton;exports.RPC_PROVIDERS=e.RPC_PROVIDERS;exports.SECURITY_RECOMMENDATIONS=e.SECURITY_RECOMMENDATIONS;exports.StripeButton=e.StripeButton;exports.SubscribeButton=e.SubscribeButton;exports.SubscriptionManagementPanel=e.SubscriptionManagementPanel;exports.calculateDiscountPercentage=e.calculateDiscountPercentage;exports.createTranslator=e.createTranslator;exports.detectLocale=e.detectLocale;exports.emitPaymentError=e.emitPaymentError;exports.emitPaymentProcessing=e.emitPaymentProcessing;exports.emitPaymentStart=e.emitPaymentStart;exports.emitPaymentSuccess=e.emitPaymentSuccess;exports.emitWalletConnect=e.emitWalletConnect;exports.emitWalletConnected=e.emitWalletConnected;exports.emitWalletError=e.emitWalletError;exports.formatCSP=e.formatCSP;exports.formatCouponCodes=e.formatCouponCodes;exports.generateCSP=e.generateCSP;exports.generateCSPDirectives=e.generateCSPDirectives;exports.getAvailableLocales=e.getAvailableLocales;exports.getLocalizedError=e.getLocalizedError;exports.getUserErrorMessage=e.getUserErrorMessage;exports.isRetryableError=e.isRetryableError;exports.loadLocale=e.loadLocale;exports.logSecurityReport=e.logSecurityReport;exports.parseCouponCodes=e.parseCouponCodes;exports.stackCheckoutCoupons=e.stackCheckoutCoupons;exports.useCreditsPayment=e.useCreditsPayment;exports.useCreditsSubscription=e.useCreditsSubscription;exports.useLocalizedError=e.useLocalizedError;exports.usePaymentMode=e.usePaymentMode;exports.useStripeCheckout=e.useStripeCheckout;exports.useSubscription=e.useSubscription;exports.useSubscriptionManagement=e.useSubscriptionManagement;exports.useTranslation=e.useTranslation;exports.validateSecurity=e.validateSecurity;exports.CIRCUIT_BREAKER_PRESETS=t.CIRCUIT_BREAKER_PRESETS;exports.CedrosProvider=t.CedrosProvider;exports.CircuitBreakerOpenError=t.CircuitBreakerOpenError;exports.CircuitState=t.CircuitState;exports.ERROR_CATEGORIES=t.ERROR_CATEGORIES;exports.KNOWN_STABLECOINS=t.KNOWN_STABLECOINS;exports.LogLevel=t.LogLevel;exports.Logger=t.Logger;exports.RATE_LIMITER_PRESETS=t.RATE_LIMITER_PRESETS;exports.RETRY_PRESETS=t.RETRY_PRESETS;exports.createCircuitBreaker=t.createCircuitBreaker;exports.createLogger=t.createLogger;exports.createRateLimiter=t.createRateLimiter;exports.getLogger=t.getLogger;exports.retryWithBackoff=t.retryWithBackoff;exports.useCedrosContext=t.useCedrosContext;exports.useCedrosTheme=t.useCedrosTheme;exports.validateConfig=t.validateConfig;exports.validateTokenMint=t.validateTokenMint;exports.CEDROS_PAY_GROUPS=N.CEDROS_PAY_GROUPS;exports.CEDROS_PAY_SECTIONS=N.CEDROS_PAY_SECTIONS;exports.CEDROS_PAY_SECTION_IDS=N.CEDROS_PAY_SECTION_IDS;exports.CedrosPayAdminDashboard=N.CedrosPayAdminDashboard;exports.cedrosPayPlugin=N.cedrosPayPlugin;exports.ecommerce=N.index;exports.CryptoButton=ce.CryptoButton;exports.useX402Payment=ce.useX402Payment;exports.WalletPool=le.WalletPool;exports.createWalletPool=le.createWalletPool;exports.CryptoSubscribeButton=we;exports.useCryptoSubscription=ue;exports.useRefundVerification=he;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./styles-BWrLnaUW.js"),t=require("./CedrosContext-D-lnoEkR.js"),N=require("./index-IZ4WcMd7.js"),ce=require("./CryptoButton-Dy-g3bR0.js"),S=require("react/jsx-runtime"),a=require("react"),$=require("@solana/wallet-adapter-react"),ie=require("@solana/wallet-adapter-base"),Pe=require("@solana/wallet-adapter-react-ui"),le=require("./walletPool-BqNfOhB0.js");function ue(){const{subscriptionManager:o,x402Manager:d,walletManager:f}=t.useCedrosContext(),{publicKey:u,signTransaction:T}=$.useWallet(),[P,y]=a.useState({status:"idle",error:null,sessionId:null,subscriptionStatus:null,expiresAt:null}),[k,R]=a.useState(null),x=a.useRef(!1),h=a.useCallback(()=>{if(!u){const c="Wallet not connected";return y(n=>({...n,status:"error",error:c})),{valid:!1,error:c}}if(!T){const c="Wallet does not support signing";return y(n=>({...n,status:"error",error:c})),{valid:!1,error:c}}return{valid:!0}},[u,T]),_=a.useCallback(async c=>{if(!u)return y(n=>({...n,status:"error",error:"Wallet not connected"})),null;y(n=>({...n,status:"checking",error:null}));try{const n=await o.checkSubscriptionStatus({resource:c,userId:u.toString()});return y(s=>({...s,status:n.active?"success":"idle",subscriptionStatus:n.status,expiresAt:n.expiresAt||n.currentPeriodEnd||null})),n}catch(n){const s=t.formatError(n,"Failed to check subscription status");return y(g=>({...g,status:"error",error:s})),null}},[u,o]),L=a.useCallback(async(c,n,s)=>{y(g=>({...g,status:"loading",error:null}));try{const g=await o.requestSubscriptionQuote(c,n,s);return R(g),y(i=>({...i,status:"idle"})),g}catch(g){const i=t.formatError(g,"Failed to get subscription quote");return y(l=>({...l,status:"error",error:i})),null}},[o]),C=a.useCallback(async(c,n,s)=>{if(x.current)return{success:!1,error:"Payment already in progress"};const g=h();if(!g.valid)return{success:!1,error:g.error};x.current=!0,y(i=>({...i,status:"loading",error:null}));try{const i=await o.requestSubscriptionQuote(c,n,s);R(i);const l=i.requirement;if(!d.validateRequirement(l))throw new Error("Invalid subscription quote received from server");const E=!!l.extra?.feePayer;let b;if(E){const{transaction:w,blockhash:W}=await d.buildGaslessTransaction({resourceId:c,userWallet:u.toString(),feePayer:l.extra.feePayer,couponCode:s?.couponCode}),M=f.deserializeTransaction(w),q=await f.partiallySignTransaction({transaction:M,signTransaction:T,blockhash:W});b=await d.submitGaslessTransaction({resource:c,partialTx:q,couponCode:s?.couponCode,resourceType:"regular",requirement:l})}else{const w=await f.buildTransaction({requirement:l,payerPublicKey:u}),W=await f.signTransaction({transaction:w,signTransaction:T}),M=f.buildPaymentPayload({requirement:l,signedTx:W,payerPublicKey:u});b=await d.submitPayment({resource:c,payload:M,couponCode:s?.couponCode,resourceType:"regular"})}if(b.success){const w=await o.checkSubscriptionStatus({resource:c,userId:u.toString()});y({status:"success",error:null,sessionId:b.transactionId||null,subscriptionStatus:w.status,expiresAt:w.expiresAt||w.currentPeriodEnd||null})}else y(w=>({...w,status:"error",error:b.error||"Subscription payment failed"}));return b}catch(i){const l=t.formatError(i,"Subscription payment failed");return y(E=>({...E,status:"error",error:l})),{success:!1,error:l}}finally{x.current=!1}},[h,o,d,f,u,T]),v=a.useCallback(()=>{y({status:"idle",error:null,sessionId:null,subscriptionStatus:null,expiresAt:null}),R(null)},[]);return{...P,quote:k,checkStatus:_,requestQuote:L,processPayment:C,reset:v}}function we({resource:o,interval:d,intervalDays:f,couponCode:u,label:T,disabled:P=!1,onAttempt:y,onSuccess:k,onError:R,className:x="",testPageUrl:h,hideMessages:_=!1,autoCheckStatus:L=!0}){const{connected:C,connecting:v,connect:c,disconnect:n,select:s,wallets:g,wallet:i,publicKey:l}=$.useWallet(),{status:E,error:b,subscriptionStatus:w,expiresAt:W,checkStatus:M,processPayment:q}=ue(),p=t.useCedrosTheme(),{solanaError:I}=t.useCedrosContext(),{t:B,translations:G}=e.useTranslation(),de=T||B("ui.subscribe_with_crypto"),Q=a.useRef(k),F=a.useRef(R),V=a.useRef(q),X=a.useRef(M);Q.current=k,F.current=R,V.current=q,X.current=M;const ge=b&&typeof b!="string"?b?.code??null:null,pe=I&&typeof I!="string"?I?.code??null:null,H=r=>{if(!r||!G)return"";const m=G.errors[r];return m?m.action?`${m.message} ${m.action}`:m.message:""},J=b?typeof b=="string"?b:H(ge):null,Z=I?typeof I=="string"?I:H(pe):null,me=a.useMemo(()=>g.map(r=>`${r.adapter.name}-${r.readyState}`).join(","),[g]),K=a.useMemo(()=>g.filter(({readyState:r})=>r===ie.WalletReadyState.Installed||r===ie.WalletReadyState.Loadable),[me]);a.useEffect(()=>{L&&C&&l&&(t.getLogger().debug("[CryptoSubscribeButton] Auto-checking subscription status"),X.current(o))},[L,C,l,o]),a.useEffect(()=>{E==="success"&&w==="active"&&(e.emitPaymentSuccess("crypto","subscription-active",o),Q.current?.("subscription-active"))},[E,w,o]),a.useEffect(()=>{E==="error"&&b&&(e.emitPaymentError("crypto",b,o),F.current?.(b))},[E,b,o]);const ee=typeof window<"u"&&window.top!==window.self,[te,O]=a.useState(!1),[re,U]=a.useState(!1),[ne,A]=a.useState(!1),D=I;a.useEffect(()=>{let r=!1;return r||(async()=>{if(re&&i&&!C&&!v){t.getLogger().debug("[CryptoSubscribeButton] Wallet detected, attempting auto-connect:",i.adapter.name),U(!1),e.emitWalletConnect(i.adapter.name);try{await c(),r||t.getLogger().debug("[CryptoSubscribeButton] Auto-connect successful")}catch(Y){if(!r){t.getLogger().error("[CryptoSubscribeButton] Auto-connect failed:",Y);const Ee=Y instanceof Error?Y.message:"Failed to connect wallet";e.emitWalletError(Ee,i.adapter.name),A(!1)}}}})(),()=>{r=!0}},[i,re,C,v,c]),a.useEffect(()=>{C&&ne&&l&&i&&(e.emitWalletConnected(i.adapter.name,l.toString()),t.getLogger().debug("[CryptoSubscribeButton] Processing pending subscription payment"),A(!1),O(!1),e.emitPaymentProcessing("crypto",o),V.current(o,d,{couponCode:u,intervalDays:f}))},[C,ne,l,i,o,d,u,f]);const oe=a.useCallback(async()=>{if(t.getLogger().debug("[CryptoSubscribeButton] executeSubscriptionFlow called",{connected:C,wallet:i?.adapter.name,resource:o,interval:d}),e.emitPaymentStart("crypto",o),y&&y("crypto"),D){t.getLogger().error("[CryptoSubscribeButton] Solana dependencies missing:",D),e.emitPaymentError("crypto",D,o),R&&R(D);return}if(ee){const r=h||window.location.href;try{if(new URL(r,window.location.origin).origin!==window.location.origin)throw t.getLogger().error("[CryptoSubscribeButton] Blocked attempt to open external URL:",r),new Error("Cannot open external URLs from embedded context");window.open(r,"_blank","noopener,noreferrer")}catch(m){throw t.getLogger().error("[CryptoSubscribeButton] URL validation failed:",m),m}return}if(C)e.emitPaymentProcessing("crypto",o),await q(o,d,{couponCode:u,intervalDays:f});else{A(!0);try{if(i)t.getLogger().debug("[CryptoSubscribeButton] Wallet already selected, connecting:",i.adapter.name),e.emitWalletConnect(i.adapter.name),await c();else{if(t.getLogger().debug("[CryptoSubscribeButton] No wallet selected, showing selector"),K.length===0){A(!1);const r="No wallets available";throw e.emitWalletError(r),new Error(r)}O(!0)}}catch(r){A(!1);const m=r instanceof Error?r.message:"Failed to connect wallet";t.getLogger().error("[CryptoSubscribeButton] Connection error:",m),e.emitWalletError(m,i?.adapter.name)}}},[C,i,o,d,u,f,ee,h,K,c,q,D,y,R]),ae=a.useMemo(()=>`crypto-subscribe-${o}-${d}`,[o,d]),ye=a.useMemo(()=>e.createDedupedClickHandler(ae,oe,{cooldownMs:200,deduplicationWindowMs:0}),[ae,oe]),se=E==="loading"||E==="checking",j=w==="active"||w==="trialing",fe=P||se||v||!!D||j;let z=de;if(se)z=B("ui.processing");else if(j&&W){const r=new Date(W).toLocaleDateString();z=`${B("ui.subscribed_until")} ${r}`}else j&&(z=B("ui.subscribed"));const be=a.useCallback(async()=>{try{U(!1),C&&await n(),s(null),O(!0)}catch(r){t.getLogger().error("Failed to change wallet:",r)}},[C,n,s]),Se=a.useCallback(r=>{t.getLogger().debug("[CryptoSubscribeButton] Wallet clicked:",r),O(!1),s(r),U(!0)},[s]),Ce=a.useCallback(async()=>{try{if(await n(),A(!1),typeof window<"u"&&window.localStorage)try{window.localStorage.removeItem("walletName")}catch(r){r instanceof Error&&r.name==="QuotaExceededError"?t.getLogger().warn("localStorage quota exceeded when removing wallet preference"):t.getLogger().error("Failed to clear wallet preference from localStorage:",r)}}catch(r){t.getLogger().error("Failed to disconnect wallet:",r)}},[n]);return S.jsxs("div",{className:p.unstyled?x:`${p.className} cedros-theme__crypto-button ${x||""}`,style:p.unstyled?{}:p.style,children:[S.jsx("button",{onClick:ye,disabled:fe,className:p.unstyled?x:"cedros-theme__button cedros-theme__crypto",type:"button",children:z}),te&&!_&&S.jsx("div",{className:"cedros-modal-overlay",style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:p.tokens.modalOverlay,display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999,padding:"1rem"},onClick:()=>O(!1),children:S.jsxs("div",{className:"cedros-modal-content",style:{backgroundColor:p.tokens.modalBackground,borderRadius:"12px",padding:"2rem",maxWidth:"400px",width:"100%",boxShadow:"0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)",border:`1px solid ${p.tokens.modalBorder}`},onClick:r=>r.stopPropagation(),children:[S.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"1.5rem"},children:[S.jsx("h3",{style:{margin:0,fontSize:"1.25rem",fontWeight:600,color:p.tokens.surfaceText},children:B("wallet.select_wallet")}),S.jsx("button",{onClick:()=>O(!1),style:e.getModalCloseButtonStyles(p.tokens.surfaceText),"aria-label":"Close modal",type:"button",children:"×"})]}),S.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:K.map(r=>S.jsxs("button",{onClick:()=>Se(r.adapter.name),style:{width:"100%",padding:"1rem",backgroundColor:p.tokens.surfaceBackground,border:`1px solid ${p.tokens.surfaceBorder}`,borderRadius:"0.5rem",cursor:"pointer",fontSize:"1rem",textAlign:"left",color:p.tokens.surfaceText,display:"flex",alignItems:"center",gap:"1rem",transition:"all 0.2s ease"},onMouseEnter:m=>{m.currentTarget.style.backgroundColor=p.tokens.modalBackground,m.currentTarget.style.borderColor=p.tokens.surfaceText,m.currentTarget.style.transform="translateY(-2px)"},onMouseLeave:m=>{m.currentTarget.style.backgroundColor=p.tokens.surfaceBackground,m.currentTarget.style.borderColor=p.tokens.surfaceBorder,m.currentTarget.style.transform="translateY(0)"},type:"button",children:[S.jsx(Pe.WalletIcon,{wallet:r,style:{width:"24px",height:"24px"}}),S.jsx("span",{style:{fontWeight:500},children:r.adapter.name})]},r.adapter.name))})]})}),C&&!_&&!te&&S.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"0.5rem",fontSize:"0.75rem",color:p.tokens.surfaceText,opacity:.7},children:[S.jsx("button",{onClick:be,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:B("wallet.change")}),S.jsx("button",{onClick:Ce,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:B("ui.disconnect")})]}),!_&&Z&&S.jsx("div",{className:p.unstyled?"":"cedros-theme__error",children:Z}),!_&&J&&S.jsx("div",{className:p.unstyled?"":"cedros-theme__error",children:J}),!_&&j&&S.jsx("div",{className:p.unstyled?"":"cedros-theme__success",children:B("ui.subscription_active")})]})}function he(){const{x402Manager:o,walletManager:d}=t.useCedrosContext(),{publicKey:f,signTransaction:u}=$.useWallet(),[T,P]=a.useState({status:"idle",error:null,transactionId:null}),[y,k]=a.useState(null),[R,x]=a.useState(null),h=a.useRef(!1),_=a.useCallback(async c=>{try{P(s=>({...s,status:"loading"}));const n=await o.requestQuote({resource:c});if(!o.validateRequirement(n))throw new Error("Invalid refund requirement received from server");return k(n),P(s=>({...s,status:"idle"})),n}catch(n){const s=t.formatError(n,"Failed to fetch refund requirement");throw P({status:"error",error:s,transactionId:null}),n}},[o]),L=a.useCallback(async(c,n)=>{if(h.current)throw new Error("Refund already in progress");if(!f||!u)throw new Error("Wallet not connected");h.current=!0;try{P({status:"loading",error:null,transactionId:null});const s=await o.requestQuote({resource:c,couponCode:n});if(!o.validateRequirement(s))throw new Error("Invalid refund requirement received");k(s);const g=await d.buildTransaction({requirement:s,payerPublicKey:f}),i=await d.signTransaction({transaction:g,signTransaction:u}),l=d.buildPaymentPayload({requirement:s,signedTx:i,payerPublicKey:f}),E=await o.submitPayment({resource:c,payload:l,couponCode:n,metadata:void 0,resourceType:"refund"});return E.settlement&&x(E.settlement),P({status:"success",error:null,transactionId:E.transactionId||i.signature}),E}catch(s){const g=t.formatError(s,"Refund payment failed");throw P({status:"error",error:g,transactionId:null}),s}finally{h.current=!1}},[f,u,o,d]),C=a.useCallback(async c=>{if(h.current)throw new Error("Refund already in progress");if(!f||!u)throw new Error("Wallet not connected");h.current=!0;try{P({status:"loading",error:null,transactionId:null});const n=await o.requestQuote({resource:c});if(!o.validateRequirement(n))throw new Error("Invalid refund requirement received");k(n);const{transaction:s}=await o.buildGaslessTransaction({resourceId:c,userWallet:f.toString(),feePayer:n.extra.feePayer}),g=d.deserializeTransaction(s),i=await d.partiallySignTransaction({transaction:g,signTransaction:u}),l=await o.submitGaslessTransaction({resource:c,partialTx:i,couponCode:void 0,metadata:void 0,resourceType:"refund",requirement:n});return l.settlement&&x(l.settlement),P({status:"success",error:null,transactionId:l.transactionId||"gasless-refund-tx"}),l}catch(n){const s=t.formatError(n,"Gasless refund payment failed");throw P({status:"error",error:s,transactionId:null}),n}finally{h.current=!1}},[f,u,o,d]),v=a.useCallback(()=>{P({status:"idle",error:null,transactionId:null}),k(null),x(null)},[]);return{state:T,requirement:y,settlement:R,fetchRefundQuote:_,processRefund:L,processGaslessRefund:C,reset:v}}exports.CEDROS_EVENTS=e.CEDROS_EVENTS;exports.CSP_PRESETS=e.CSP_PRESETS;exports.CedrosPay=e.CedrosPay;exports.CreditsButton=e.CreditsButton;exports.CreditsSubscribeButton=e.CreditsSubscribeButton;exports.PaymentMethodBadge=e.PaymentMethodBadge;exports.PaymentModal=e.PaymentModal;exports.ProductPrice=e.ProductPrice;exports.PurchaseButton=e.PurchaseButton;exports.RPC_PROVIDERS=e.RPC_PROVIDERS;exports.SECURITY_RECOMMENDATIONS=e.SECURITY_RECOMMENDATIONS;exports.StripeButton=e.StripeButton;exports.SubscribeButton=e.SubscribeButton;exports.SubscriptionManagementPanel=e.SubscriptionManagementPanel;exports.calculateDiscountPercentage=e.calculateDiscountPercentage;exports.createTranslator=e.createTranslator;exports.detectLocale=e.detectLocale;exports.emitPaymentError=e.emitPaymentError;exports.emitPaymentProcessing=e.emitPaymentProcessing;exports.emitPaymentStart=e.emitPaymentStart;exports.emitPaymentSuccess=e.emitPaymentSuccess;exports.emitWalletConnect=e.emitWalletConnect;exports.emitWalletConnected=e.emitWalletConnected;exports.emitWalletError=e.emitWalletError;exports.formatCSP=e.formatCSP;exports.formatCouponCodes=e.formatCouponCodes;exports.generateCSP=e.generateCSP;exports.generateCSPDirectives=e.generateCSPDirectives;exports.getAvailableLocales=e.getAvailableLocales;exports.getLocalizedError=e.getLocalizedError;exports.getUserErrorMessage=e.getUserErrorMessage;exports.isRetryableError=e.isRetryableError;exports.loadLocale=e.loadLocale;exports.logSecurityReport=e.logSecurityReport;exports.parseCouponCodes=e.parseCouponCodes;exports.stackCheckoutCoupons=e.stackCheckoutCoupons;exports.useCreditsPayment=e.useCreditsPayment;exports.useCreditsSubscription=e.useCreditsSubscription;exports.useLocalizedError=e.useLocalizedError;exports.usePaymentMode=e.usePaymentMode;exports.useStripeCheckout=e.useStripeCheckout;exports.useSubscription=e.useSubscription;exports.useSubscriptionManagement=e.useSubscriptionManagement;exports.useTranslation=e.useTranslation;exports.validateSecurity=e.validateSecurity;exports.CIRCUIT_BREAKER_PRESETS=t.CIRCUIT_BREAKER_PRESETS;exports.CedrosProvider=t.CedrosProvider;exports.CircuitBreakerOpenError=t.CircuitBreakerOpenError;exports.CircuitState=t.CircuitState;exports.ERROR_CATEGORIES=t.ERROR_CATEGORIES;exports.KNOWN_STABLECOINS=t.KNOWN_STABLECOINS;exports.LogLevel=t.LogLevel;exports.Logger=t.Logger;exports.RATE_LIMITER_PRESETS=t.RATE_LIMITER_PRESETS;exports.RETRY_PRESETS=t.RETRY_PRESETS;exports.createCircuitBreaker=t.createCircuitBreaker;exports.createLogger=t.createLogger;exports.createRateLimiter=t.createRateLimiter;exports.getLogger=t.getLogger;exports.retryWithBackoff=t.retryWithBackoff;exports.useCedrosContext=t.useCedrosContext;exports.useCedrosTheme=t.useCedrosTheme;exports.validateConfig=t.validateConfig;exports.validateTokenMint=t.validateTokenMint;exports.CEDROS_PAY_GROUPS=N.CEDROS_PAY_GROUPS;exports.CEDROS_PAY_SECTIONS=N.CEDROS_PAY_SECTIONS;exports.CEDROS_PAY_SECTION_IDS=N.CEDROS_PAY_SECTION_IDS;exports.CedrosPayAdminDashboard=N.CedrosPayAdminDashboard;exports.cedrosPayPlugin=N.cedrosPayPlugin;exports.ecommerce=N.index;exports.CryptoButton=ce.CryptoButton;exports.useX402Payment=ce.useX402Payment;exports.WalletPool=le.WalletPool;exports.createWalletPool=le.createWalletPool;exports.CryptoSubscribeButton=we;exports.useCryptoSubscription=ue;exports.useRefundVerification=he;
@@ -2,7 +2,7 @@ import { O as ke, B as ve, D as fe, y as Ie, A as me, w as Be, x as ye, z as V,
2
2
  import { v as Ue, t as Ye, C as Ve, a as He, f as Je, d as Xe, b as Ze, c as et, P as tt, R as rt, I as nt, S as at, e as st, g as ot, n as it, M as ct, J as lt, r as ut, m as dt, o as pt, q as ft, L as mt, N as yt, F as gt, E as bt, K as St, H as wt, p as ht, s as Ct, h as xt, k as Pt, Q as Et, i as Rt, u as Tt, j as kt, l as vt, G as It } from "./styles--eKKnfdj.mjs";
3
3
  import { u as H, m as z, a as qe, i as y } from "./CedrosContext-BE6P5PQ0.mjs";
4
4
  import { f as _t, C as Wt, e as qt, d as Mt, E as Lt, K as At, L as Dt, h as Ot, R as Nt, g as zt, b as Kt, j as Qt, c as $t, r as Ft, v as Gt, n as jt } from "./CedrosContext-BE6P5PQ0.mjs";
5
- import { d as Yt, a as Vt, b as Ht, C as Jt, c as Xt, i as Zt } from "./index-bqhsxBTY.mjs";
5
+ import { d as Yt, a as Vt, b as Ht, C as Jt, c as Xt, i as Zt } from "./index-CufXF9Yd.mjs";
6
6
  import { C as tr, u as rr } from "./CryptoButton-CksMkZjL.mjs";
7
7
  import { jsxs as K, jsx as x } from "react/jsx-runtime";
8
8
  import { useState as I, useRef as N, useCallback as h, useMemo as G, useEffect as Q } from "react";
@@ -2707,7 +2707,7 @@ function rm({ serverUrl: e, apiKey: t, pageSize: n = 20, authManager: r }) {
2707
2707
  ] });
2708
2708
  }
2709
2709
  const om = hn(
2710
- () => import("./SettingsSection-CPFOuoZG.mjs").then((e) => ({ default: e.SettingsSection }))
2710
+ () => import("./SettingsSection-DDLMaEPo.mjs").then((e) => ({ default: e.SettingsSection }))
2711
2711
  );
2712
2712
  function am(e) {
2713
2713
  return /* @__PURE__ */ a(Nn, { fallback: null, children: /* @__PURE__ */ a(om, { ...e }) });
@@ -2865,17 +2865,17 @@ function sm({
2865
2865
  };
2866
2866
  }
2867
2867
  const cm = hn(
2868
- () => import("./SubscriptionsSection-F2IiU2jv.mjs").then((e) => ({ default: e.SubscriptionsSection }))
2868
+ () => import("./SubscriptionsSection-CU3Ce8r9.mjs").then((e) => ({ default: e.SubscriptionsSection }))
2869
2869
  ), lm = hn(
2870
- () => import("./StorefrontSection-f54ySA6i.mjs").then((e) => ({ default: e.StorefrontSection }))
2870
+ () => import("./StorefrontSection-Dr2ciBVg.mjs").then((e) => ({ default: e.StorefrontSection }))
2871
2871
  ), dm = hn(
2872
- () => import("./AISettingsSection-8eDaxYp8.mjs").then((e) => ({ default: e.AISettingsSection }))
2872
+ () => import("./AISettingsSection-p3iikbSw.mjs").then((e) => ({ default: e.AISettingsSection }))
2873
2873
  ), um = hn(
2874
- () => import("./PaymentSettingsSection-CEGHN6VI.mjs").then((e) => ({ default: e.PaymentSettingsSection }))
2874
+ () => import("./PaymentSettingsSection-B9H253x1.mjs").then((e) => ({ default: e.PaymentSettingsSection }))
2875
2875
  ), fm = hn(
2876
- () => import("./MessagingSection-D39EuOLN.mjs").then((e) => ({ default: e.MessagingSection }))
2876
+ () => import("./MessagingSection-CK208brx.mjs").then((e) => ({ default: e.MessagingSection }))
2877
2877
  ), mm = hn(
2878
- () => import("./FAQSection-Dg-I7Z-N.mjs").then((e) => ({ default: e.FAQSection }))
2878
+ () => import("./FAQSection-byh7zfqI.mjs").then((e) => ({ default: e.FAQSection }))
2879
2879
  ), Vc = [
2880
2880
  {
2881
2881
  label: "Menu",
@@ -3124,17 +3124,17 @@ const At = (e) => hn(async () => {
3124
3124
  { id: "Configuration", label: "Configuration", order: 2, defaultCollapsed: !0 }
3125
3125
  ],
3126
3126
  components: {
3127
- products: At(() => import("./sections-CiAMjlPd.mjs").then((e) => ({ default: e.ProductsSection }))),
3128
- subscriptions: At(() => import("./SubscriptionsSection-F2IiU2jv.mjs").then((e) => ({ default: e.SubscriptionsSection }))),
3129
- transactions: At(() => import("./sections-CiAMjlPd.mjs").then((e) => ({ default: e.TransactionsSection }))),
3130
- coupons: At(() => import("./sections-CiAMjlPd.mjs").then((e) => ({ default: e.CouponsSection }))),
3131
- refunds: At(() => import("./sections-CiAMjlPd.mjs").then((e) => ({ default: e.RefundsSection }))),
3132
- storefront: At(() => import("./StorefrontSection-f54ySA6i.mjs").then((e) => ({ default: e.StorefrontSection }))),
3133
- "ai-settings": At(() => import("./AISettingsSection-8eDaxYp8.mjs").then((e) => ({ default: e.AISettingsSection }))),
3134
- faqs: At(() => import("./FAQSection-Dg-I7Z-N.mjs").then((e) => ({ default: e.FAQSection }))),
3135
- "payment-settings": At(() => import("./PaymentSettingsSection-CEGHN6VI.mjs").then((e) => ({ default: e.PaymentSettingsSection }))),
3136
- messaging: At(() => import("./MessagingSection-D39EuOLN.mjs").then((e) => ({ default: e.MessagingSection }))),
3137
- settings: At(() => import("./SettingsSection-CPFOuoZG.mjs").then((e) => ({ default: e.SettingsSection })))
3127
+ products: At(() => import("./sections-Bc6ARlND.mjs").then((e) => ({ default: e.ProductsSection }))),
3128
+ subscriptions: At(() => import("./SubscriptionsSection-CU3Ce8r9.mjs").then((e) => ({ default: e.SubscriptionsSection }))),
3129
+ transactions: At(() => import("./sections-Bc6ARlND.mjs").then((e) => ({ default: e.TransactionsSection }))),
3130
+ coupons: At(() => import("./sections-Bc6ARlND.mjs").then((e) => ({ default: e.CouponsSection }))),
3131
+ refunds: At(() => import("./sections-Bc6ARlND.mjs").then((e) => ({ default: e.RefundsSection }))),
3132
+ storefront: At(() => import("./StorefrontSection-Dr2ciBVg.mjs").then((e) => ({ default: e.StorefrontSection }))),
3133
+ "ai-settings": At(() => import("./AISettingsSection-p3iikbSw.mjs").then((e) => ({ default: e.AISettingsSection }))),
3134
+ faqs: At(() => import("./FAQSection-byh7zfqI.mjs").then((e) => ({ default: e.FAQSection }))),
3135
+ "payment-settings": At(() => import("./PaymentSettingsSection-B9H253x1.mjs").then((e) => ({ default: e.PaymentSettingsSection }))),
3136
+ messaging: At(() => import("./MessagingSection-CK208brx.mjs").then((e) => ({ default: e.MessagingSection }))),
3137
+ settings: At(() => import("./SettingsSection-DDLMaEPo.mjs").then((e) => ({ default: e.SettingsSection })))
3138
3138
  },
3139
3139
  createPluginContext(e) {
3140
3140
  const t = e.cedrosPay, n = e.cedrosLogin;