@cedros/pay-react 1.1.24 → 1.1.25

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 (127) hide show
  1. package/dist/{AISettingsSection-IXS1Wt_1.js → AISettingsSection-BvSSiK2G.js} +1 -1
  2. package/dist/{AISettingsSection-Dw0ZlxMf.mjs → AISettingsSection-Dg1kazTI.mjs} +2 -2
  3. package/dist/{AutosaveIndicator-BJsg_kFZ.mjs → AutosaveIndicator-BHfkV59p.mjs} +1 -1
  4. package/dist/{AutosaveIndicator-CY_YHM1D.js → AutosaveIndicator-D2l7U8R1.js} +1 -1
  5. package/dist/CedrosContext-C2RjHLaQ.js +6 -0
  6. package/dist/{CedrosContext-DQUbL8yP.mjs → CedrosContext-CY6zvjvJ.mjs} +768 -617
  7. package/dist/ComplianceSection-BSE2f3Wo.mjs +534 -0
  8. package/dist/ComplianceSection-D6ETKG6b.js +1 -0
  9. package/dist/{CryptoButton-D1BCZBk4.mjs → CryptoButton-BV9owVe2.mjs} +2 -2
  10. package/dist/{CryptoButton-C1AAOOfj.js → CryptoButton-DpiCnyXE.js} +1 -1
  11. package/dist/{FAQSection-BmgmzDN5.js → FAQSection-6nGI0FK9.js} +1 -1
  12. package/dist/{FAQSection-C78MnK4k.mjs → FAQSection-uZG5V3pJ.mjs} +1 -1
  13. package/dist/{MessagingSection-CWLZcg11.js → MessagingSection-DrXb578q.js} +1 -1
  14. package/dist/{MessagingSection-De3t8bSI.mjs → MessagingSection-M0lj5yo4.mjs} +2 -2
  15. package/dist/{OrdersSection-_xKVzjSZ.mjs → OrdersSection-DteItv_O.mjs} +6 -6
  16. package/dist/{OrdersSection-BKOxsZw0.js → OrdersSection-_-rIw6XW.js} +1 -1
  17. package/dist/{PaymentSettingsSection-KjU_dN_d.mjs → PaymentSettingsSection-CdtdLFTg.mjs} +1 -1
  18. package/dist/{PaymentSettingsSection-BTEn9Dxb.js → PaymentSettingsSection-enTbUI95.js} +1 -1
  19. package/dist/SettingsSection-DUTEd6uV.js +1 -0
  20. package/dist/{SettingsSection-8QHZB59k.mjs → SettingsSection-mcT4LEhO.mjs} +19 -13
  21. package/dist/{SingleCategorySettings--LK0TZW0.mjs → SingleCategorySettings-BvHBVfSe.mjs} +4 -4
  22. package/dist/{SingleCategorySettings-CRXTMTo5.js → SingleCategorySettings-D2LVM5mn.js} +1 -1
  23. package/dist/{StorefrontSection-CeCpr8hn.mjs → StorefrontSection-BqQ36JIS.mjs} +2 -2
  24. package/dist/{StorefrontSection-C9DzCmOf.js → StorefrontSection-Du7hV2Gc.js} +1 -1
  25. package/dist/{SubscriptionsSection-C2xk8ApF.mjs → SubscriptionsSection-BYiCBwKZ.mjs} +7 -7
  26. package/dist/{SubscriptionsSection-Dn5SY6S_.js → SubscriptionsSection-C4BRN1dP.js} +1 -1
  27. package/dist/Token22Section-0c22NM5G.js +1 -0
  28. package/dist/Token22Section-BHvOhz5d.mjs +2260 -0
  29. package/dist/{WalletManager-Bwk3rgr1.js → WalletManager-B3UdQ5pQ.js} +1 -1
  30. package/dist/{WalletManager-CXvQ0Zu9.mjs → WalletManager-BIwH8Dw_.mjs} +1 -1
  31. package/dist/{configApi-Ch0Rr7TD.mjs → configApi-6XhAJGKX.mjs} +31 -0
  32. package/dist/{configApi-CxEbCAgG.js → configApi-DkduMQg1.js} +1 -1
  33. package/dist/crypto-only.js +1 -1
  34. package/dist/crypto-only.mjs +85 -83
  35. package/dist/{index-BHF82XBB.mjs → index-BkDimQDF.mjs} +7987 -7322
  36. package/dist/index-C7MWL6O8.js +84 -0
  37. package/dist/index.js +1 -1
  38. package/dist/index.mjs +42 -40
  39. package/dist/{sections-8e5Y3ukY.js → sections-5jO2aHAo.js} +1 -1
  40. package/dist/{sections-C1rb9YRh.mjs → sections-By4H1baL.mjs} +2 -2
  41. package/dist/src/admin/plugin.d.ts.map +1 -1
  42. package/dist/src/components/ComplianceGatePage.d.ts +38 -0
  43. package/dist/src/components/ComplianceGatePage.d.ts.map +1 -0
  44. package/dist/src/components/SubscribeButton.d.ts +1 -5
  45. package/dist/src/components/SubscribeButton.d.ts.map +1 -1
  46. package/dist/src/components/admin/AdminAuthManager.d.ts +7 -3
  47. package/dist/src/components/admin/AdminAuthManager.d.ts.map +1 -1
  48. package/dist/src/components/admin/AssetClassesTab.d.ts.map +1 -1
  49. package/dist/src/components/admin/CedrosPayAdminDashboard.d.ts +1 -1
  50. package/dist/src/components/admin/CedrosPayAdminDashboard.d.ts.map +1 -1
  51. package/dist/src/components/admin/ComplianceSanctionsApi.d.ts +3 -0
  52. package/dist/src/components/admin/ComplianceSanctionsApi.d.ts.map +1 -0
  53. package/dist/src/components/admin/ComplianceSection.d.ts +3 -0
  54. package/dist/src/components/admin/ComplianceSection.d.ts.map +1 -0
  55. package/dist/src/components/admin/GiftCardAnalytics.d.ts +3 -0
  56. package/dist/src/components/admin/GiftCardAnalytics.d.ts.map +1 -0
  57. package/dist/src/components/admin/GiftCardManager.d.ts +3 -0
  58. package/dist/src/components/admin/GiftCardManager.d.ts.map +1 -0
  59. package/dist/src/components/admin/LiquidityPoolTab.d.ts.map +1 -1
  60. package/dist/src/components/admin/PoolManagementView.d.ts +14 -0
  61. package/dist/src/components/admin/PoolManagementView.d.ts.map +1 -0
  62. package/dist/src/components/admin/ProductsSection.d.ts.map +1 -1
  63. package/dist/src/components/admin/RefundsSection.d.ts.map +1 -1
  64. package/dist/src/components/admin/SettingsSection.d.ts.map +1 -1
  65. package/dist/src/components/admin/Token22Section.d.ts.map +1 -1
  66. package/dist/src/components/admin/complianceTypes.d.ts +60 -0
  67. package/dist/src/components/admin/complianceTypes.d.ts.map +1 -0
  68. package/dist/src/components/admin/configApi.d.ts.map +1 -1
  69. package/dist/src/components/admin/icons.d.ts +1 -0
  70. package/dist/src/components/admin/icons.d.ts.map +1 -1
  71. package/dist/src/components/admin/useAdminAuth.d.ts +1 -1
  72. package/dist/src/components/admin/useAdminAuth.d.ts.map +1 -1
  73. package/dist/src/context/CedrosContext.d.ts.map +1 -1
  74. package/dist/src/ecommerce/components/catalog/TokenDisplay.d.ts +36 -0
  75. package/dist/src/ecommerce/components/catalog/TokenDisplay.d.ts.map +1 -0
  76. package/dist/src/ecommerce/components/checkout/CheckoutForm.d.ts.map +1 -1
  77. package/dist/src/ecommerce/components/checkout/SendAsGiftSection.d.ts +15 -0
  78. package/dist/src/ecommerce/components/checkout/SendAsGiftSection.d.ts.map +1 -0
  79. package/dist/src/ecommerce/components/gift-cards/GiftCardBalanceChecker.d.ts +19 -0
  80. package/dist/src/ecommerce/components/gift-cards/GiftCardBalanceChecker.d.ts.map +1 -0
  81. package/dist/src/ecommerce/components/orders/MyRedemptionsPage.d.ts +13 -0
  82. package/dist/src/ecommerce/components/orders/MyRedemptionsPage.d.ts.map +1 -0
  83. package/dist/src/ecommerce/components/orders/MyTokensPage.d.ts +15 -0
  84. package/dist/src/ecommerce/components/orders/MyTokensPage.d.ts.map +1 -0
  85. package/dist/src/ecommerce/components/orders/OrderDetails.d.ts.map +1 -1
  86. package/dist/src/ecommerce/hooks/useCartInventory.d.ts.map +1 -1
  87. package/dist/src/ecommerce/index.d.ts +10 -0
  88. package/dist/src/ecommerce/index.d.ts.map +1 -1
  89. package/dist/src/ecommerce/state/checkout/checkoutSchema.d.ts +3 -0
  90. package/dist/src/ecommerce/state/checkout/checkoutSchema.d.ts.map +1 -1
  91. package/dist/src/ecommerce/state/checkout/useCheckout.d.ts.map +1 -1
  92. package/dist/src/ecommerce/types.d.ts +6 -0
  93. package/dist/src/ecommerce/types.d.ts.map +1 -1
  94. package/dist/src/ecommerce/utils/cartItemMetadata.d.ts.map +1 -1
  95. package/dist/src/hooks/useComplianceCheck.d.ts +30 -0
  96. package/dist/src/hooks/useComplianceCheck.d.ts.map +1 -0
  97. package/dist/src/hooks/useSubscriptionManagement.d.ts.map +1 -1
  98. package/dist/src/index.d.ts +4 -0
  99. package/dist/src/index.d.ts.map +1 -1
  100. package/dist/src/managers/CreditsManager.d.ts.map +1 -1
  101. package/dist/src/managers/ManagerCache.d.ts +2 -2
  102. package/dist/src/managers/ManagerCache.d.ts.map +1 -1
  103. package/dist/src/managers/StripeManager.d.ts +7 -1
  104. package/dist/src/managers/StripeManager.d.ts.map +1 -1
  105. package/dist/src/managers/SubscriptionChangeManager.d.ts.map +1 -1
  106. package/dist/src/managers/SubscriptionManager.d.ts.map +1 -1
  107. package/dist/src/types/index.d.ts +14 -0
  108. package/dist/src/types/index.d.ts.map +1 -1
  109. package/dist/src/types/subscription.d.ts +21 -33
  110. package/dist/src/types/subscription.d.ts.map +1 -1
  111. package/dist/src/utils/exponentialBackoff.d.ts +22 -0
  112. package/dist/src/utils/exponentialBackoff.d.ts.map +1 -1
  113. package/dist/stripe-only.js +1 -1
  114. package/dist/stripe-only.mjs +2 -2
  115. package/dist/styles-BT4bhFey.js +1 -0
  116. package/dist/{styles-Ag-7ZvAB.mjs → styles-D4SQkuV3.mjs} +606 -609
  117. package/dist/testing/index.js +1 -1
  118. package/dist/testing/index.mjs +1 -1
  119. package/dist/{walletPool-C_0P4mTw.mjs → walletPool-DE-t1wSW.mjs} +1 -1
  120. package/dist/{walletPool-Ddv33tej.js → walletPool-IS7R3MR1.js} +1 -1
  121. package/package.json +1 -1
  122. package/dist/CedrosContext-7dwmEeUY.js +0 -6
  123. package/dist/SettingsSection-cKF0tLnS.js +0 -1
  124. package/dist/Token22Section-DUUl59dZ.js +0 -1
  125. package/dist/Token22Section-HygkDNtL.mjs +0 -1685
  126. package/dist/index-OaWkrl0G.js +0 -84
  127. package/dist/styles-21F1-oqx.js +0 -1
@@ -1 +1 @@
1
- "use strict";const p=require("react/jsx-runtime"),a=require("react"),ce=require("@solana/wallet-adapter-react"),le=require("@solana/wallet-adapter-base"),be=require("@solana/wallet-adapter-react-ui"),i=require("./styles-21F1-oqx.js"),t=require("./CedrosContext-7dwmEeUY.js");function ie(){const{x402Manager:C,walletManager:l}=t.useCedrosContext(),{publicKey:W,signTransaction:j}=ce.useWallet(),[N,y]=a.useState({status:"idle",error:null,transactionId:null}),[R,L]=a.useState(null),[K,k]=a.useState(null),P=a.useRef(W);P.current=W;const h=a.useRef(j);h.current=j;const g=a.useRef(0),X=6e4,I=()=>{const o=g.current;return o>0&&Date.now()-o<X},S=a.useCallback(()=>{if(!W){const o="Wallet not connected";return y({status:"error",error:o,transactionId:null}),{valid:!1,error:o}}if(!j){const o="Wallet does not support signing";return y({status:"error",error:o,transactionId:null}),{valid:!1,error:o}}return{valid:!0}},[W,j]),q=a.useCallback(async o=>{try{y(d=>({...d,status:"loading"}));const c=await C.requestQuote({resource:o});if(!C.validateRequirement(c))throw new Error("Invalid requirement received from server");return L(c),y(d=>({...d,status:"idle"})),c}catch(c){const d=t.formatError(c,"Failed to fetch requirement");throw y({status:"error",error:d,transactionId:null}),c}},[C]),B=a.useCallback(async(o,c,d,x,n="regular")=>{const s=P.current,m=h.current;if(!s||!m)throw new Error("Wallet disconnected during payment flow");if(!!o.extra?.feePayer){t.getLogger().debug("[useX402Payment] Gasless flow enabled"),t.getLogger().debug("[useX402Payment] Building gasless transaction");const{transaction:b,blockhash:M}=await C.buildGaslessTransaction({resourceId:c,userWallet:s.toString(),feePayer:o.extra.feePayer,couponCode:d});t.getLogger().debug("[useX402Payment] Deserializing backend transaction");const A=l.deserializeTransaction(b);if(P.current?.toString()!==s.toString())throw new Error("Wallet changed during payment flow");t.getLogger().debug("[useX402Payment] Requesting partial signature");const E=await l.partiallySignTransaction({transaction:A,signTransaction:m,blockhash:M});t.getLogger().debug("[useX402Payment] Submitting partial transaction");const z=await C.submitGaslessTransaction({resource:c,partialTx:E,couponCode:d,metadata:x,resourceType:n,requirement:o});return z.success&&z.settlement&&k(z.settlement),z}else{const b=await l.buildTransaction({requirement:o,payerPublicKey:s});if(P.current?.toString()!==s.toString())throw new Error("Wallet changed during payment flow");const M=await l.signTransaction({transaction:b,signTransaction:m}),A=l.buildPaymentPayload({requirement:o,signedTx:M,payerPublicKey:s}),E=await C.submitPayment({resource:c,payload:A,couponCode:d,metadata:x,resourceType:n});return E.success&&E.settlement&&k(E.settlement),E}},[C,l]),w=a.useCallback(async(o,c,d)=>{if(I())return{success:!1,error:"Payment already in progress"};const x=S();if(!x.valid)return{success:!1,error:x.error};g.current=Date.now(),y({status:"loading",error:null,transactionId:null});try{t.getLogger().debug("[useX402Payment] Fetching fresh quote");const n=await C.requestQuote({resource:o,couponCode:c});t.getLogger().debug("[useX402Payment] Received quote",{amount:n.maxAmountRequired}),L(n),t.getLogger().debug("[useX402Payment] Executing payment flow");const s=await B(n,o,c,d,"regular");return s.success?y({status:"success",error:null,transactionId:s.transactionId||"payment-success"}):y({status:"error",error:s.error||"Payment failed",transactionId:null}),s}catch(n){const s=t.formatError(n,"Payment failed");return y({status:"error",error:s,transactionId:null}),{success:!1,error:s}}finally{g.current=0}},[S,C,B]),_=a.useCallback(async(o,c,d)=>{if(I())return{success:!1,error:"Payment already in progress"};const x=S();if(!x.valid)return{success:!1,error:x.error};g.current=Date.now(),y({status:"loading",error:null,transactionId:null});try{const n=i.normalizeCartItems(o),s=await C.requestCartQuote({items:n,metadata:c,couponCode:d}),m=s.cartId,u=s.quote;if(!C.validateRequirement(u))throw new Error("Invalid cart quote received from server");L(u);const b=await B(u,m,d,c,"cart");return b.success?y({status:"success",error:null,transactionId:b.transactionId||"cart-payment-success"}):y({status:"error",error:b.error||"Cart payment failed",transactionId:null}),b}catch(n){const s=t.formatError(n,"Cart payment failed");return y({status:"error",error:s,transactionId:null}),{success:!1,error:s}}finally{g.current=0}},[S,C,B]),T=a.useCallback(()=>{y({status:"idle",error:null,transactionId:null}),L(null),k(null),g.current=0},[]);return{...N,requirement:R,settlement:K,fetchQuote:q,processPayment:w,processCartPayment:_,reset:T}}function ue({resource:C,items:l,label:W,disabled:j=!1,onAttempt:N,onSuccess:y,onError:R,className:L="",testPageUrl:K,hideMessages:k=!1,metadata:P,couponCode:h}){const{connected:g,connecting:X,connect:I,disconnect:S,select:q,wallets:B,wallet:w,publicKey:_}=ce.useWallet(),{status:T,error:o,transactionId:c,processPayment:d,processCartPayment:x}=ie(),n=t.useCedrosTheme(),{solanaError:s}=t.useCedrosContext(),{isCartMode:m,effectiveResource:u}=i.usePaymentMode(C,l),{t:b,translations:M}=i.useTranslation(),A=W||b("ui.pay_with_crypto"),E=o&&typeof o!="string"?o?.code??null:null,z=s&&typeof s!="string"?s?.code??null:null,U=e=>{if(!e||!M)return"";const r=M.errors[e];return r?r.action?`${r.message} ${r.action}`:r.message:""},Y=o?typeof o=="string"?o:U(E):null,H=s?typeof s=="string"?s:U(z):null,J=a.useRef(y),V=a.useRef(R),Z=a.useRef(d),ee=a.useRef(x);J.current=y,V.current=R,Z.current=d,ee.current=x;const de=a.useMemo(()=>B.map(e=>`${e.adapter.name}-${e.readyState}`).join(","),[B]),G=a.useMemo(()=>B.filter(({readyState:e})=>e===le.WalletReadyState.Installed||e===le.WalletReadyState.Loadable),[de]);a.useEffect(()=>{if(T==="success"&&c){const e=m&&l?i.getCartItemCount(l):void 0;i.emitPaymentSuccess("crypto",c,u,e),J.current?.(c)}},[T,c,m,l,u]),a.useEffect(()=>{if(T==="error"&&o){const e=m&&l?i.getCartItemCount(l):void 0;i.emitPaymentError("crypto",o,u,e),V.current?.(o)}},[T,o,m,l,u]);const te=typeof window<"u"&&window.top!==window.self,[re,$]=a.useState(!1),[ne,Q]=a.useState(!1),[D,v]=a.useState(null),F=s;a.useEffect(()=>{let e=!1;return e||(async()=>{if(ne&&w&&!g&&!X){t.getLogger().debug("[CryptoButton] Wallet detected, attempting auto-connect:",w.adapter.name),Q(!1),i.emitWalletConnect(w.adapter.name);try{await I(),e||t.getLogger().debug("[CryptoButton] Auto-connect successful")}catch(f){if(!e){t.getLogger().error("[CryptoButton] Auto-connect failed:",f);const O=f instanceof Error?f.message:"Failed to connect wallet";i.emitWalletError(O,w.adapter.name),v(null)}}}})(),()=>{e=!0}},[w,ne,g,X,I]),a.useEffect(()=>{let e=!0;if(t.getLogger().debug("[CryptoButton] Payment useEffect triggered",{connected:g,hasPendingPayment:!!D,hasPublicKey:!!_,pendingPaymentType:D?.type}),g&&D&&_&&w&&e){i.emitWalletConnected(w.adapter.name,_.toString()),t.getLogger().debug("[CryptoButton] All conditions met! Processing pending payment:",D);const r=D;v(null),$(!1);const f=r.type==="cart"&&r.items?i.getCartItemCount(r.items):void 0;i.emitPaymentProcessing("crypto",r.resource,f),r.type==="cart"&&r.items?(t.getLogger().debug("[CryptoButton] Auto-processing cart payment"),ee.current(r.items,r.metadata,r.couponCode)):r.type==="single"&&r.resource&&(t.getLogger().debug("[CryptoButton] Auto-processing single payment"),Z.current(r.resource,r.couponCode,r.metadata))}return()=>{e=!1}},[g,D,_,w]);const oe=a.useCallback(async()=>{t.getLogger().debug("[CryptoButton] executePaymentFlow called",{connected:g,wallet:w?.adapter.name,couponCode:h,isCartMode:m,hasItems:!!l,effectiveResource:u});const e=m&&l?i.getCartItemCount(l):void 0;if(i.emitPaymentStart("crypto",u,e),N&&N("crypto"),F){t.getLogger().error("[CryptoButton] Solana dependencies missing:",F),i.emitPaymentError("crypto",F,u,e),R&&R(F);return}if(te){const r=K||window.location.href;try{if(new URL(r,window.location.origin).origin!==window.location.origin)throw t.getLogger().error("[CryptoButton] Blocked attempt to open external URL:",r),new Error("Cannot open external URLs from embedded context");window.open(r,"_blank","noopener,noreferrer")}catch(f){throw t.getLogger().error("[CryptoButton] URL validation failed:",f),f}return}if(g)i.emitPaymentProcessing("crypto",u,e),m&&l?(t.getLogger().debug("[CryptoButton] Processing cart payment with coupon:",h),await x(l,P,h)):u&&(t.getLogger().debug("[CryptoButton] Processing single payment with coupon:",h),await d(u,h,P));else{let r=!1;if(m&&l?(t.getLogger().debug("[CryptoButton] Setting pending cart payment with coupon:",h),v({type:"cart",items:l,metadata:P,couponCode:h}),r=!0):u&&(t.getLogger().debug("[CryptoButton] Setting pending single payment with coupon:",h),v({type:"single",resource:u,metadata:P,couponCode:h}),r=!0),!r){t.getLogger().error("[CryptoButton] No valid payment to process");return}try{if(w)t.getLogger().debug("[CryptoButton] Wallet already selected, connecting:",w.adapter.name),i.emitWalletConnect(w.adapter.name),await I();else{if(t.getLogger().debug("[CryptoButton] No wallet selected, showing selector. Available wallets:",G.map(f=>f.adapter.name)),G.length===0){v(null);const f="No wallets available";throw i.emitWalletError(f),new Error(f)}$(!0)}}catch(f){v(null);const O=f instanceof Error?f.message:"Failed to connect wallet";t.getLogger().error("[CryptoButton] Connection error:",O),i.emitWalletError(O,w?.adapter.name)}}},[g,w,h,m,l,u,te,K,G,I,P,x,d,F,N,R]),ae=a.useMemo(()=>m&&l?`crypto-cart-${l.map(e=>e.resource).join("-")}`:`crypto-${u||"unknown"}`,[m,l,u]),ge=a.useMemo(()=>i.createDedupedClickHandler(ae,oe,{cooldownMs:200,deduplicationWindowMs:0}),[ae,oe]),se=T==="loading",ye=j||se||X||!!F,me=se?b("ui.processing"):A,fe=a.useCallback(async()=>{try{Q(!1),g&&await S(),q(null),$(!0)}catch(e){t.getLogger().error("Failed to change wallet:",e)}},[g,S,q]),pe=a.useCallback(e=>{t.getLogger().debug("[CryptoButton] Wallet clicked:",e),$(!1),q(e),Q(!0),t.getLogger().debug("[CryptoButton] Wallet selected, useEffect will auto-connect")},[q]),we=a.useCallback(async()=>{try{if(await S(),v(null),typeof window<"u"&&window.localStorage)try{window.localStorage.removeItem("walletName")}catch(e){e instanceof Error&&e.name==="QuotaExceededError"?t.getLogger().warn("localStorage quota exceeded when removing wallet preference"):t.getLogger().error("Failed to clear wallet preference from localStorage:",e)}}catch(e){t.getLogger().error("Failed to disconnect wallet:",e)}},[S]);return p.jsxs("div",{className:n.unstyled?L:`${n.className} cedros-theme__crypto-button ${L||""}`,style:n.unstyled?{}:n.style,children:[p.jsx("button",{onClick:ge,disabled:ye,className:n.unstyled?L:"cedros-theme__button cedros-theme__crypto",type:"button",children:me}),re&&!k&&p.jsx("div",{className:"cedros-modal-overlay",style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:n.tokens.modalOverlay,display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999,padding:"1rem"},onClick:()=>{$(!1),v(null)},children:p.jsxs("div",{className:"cedros-modal-content",style:{backgroundColor:n.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 ${n.tokens.modalBorder}`},onClick:e=>e.stopPropagation(),children:[p.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"1.5rem"},children:[p.jsx("h3",{style:{margin:0,fontSize:"1.25rem",fontWeight:600,color:n.tokens.surfaceText},children:b("wallet.select_wallet")}),p.jsx("button",{onClick:()=>{$(!1),v(null)},style:i.getModalCloseButtonStyles(n.tokens.surfaceText),"aria-label":"Close modal",type:"button",children:"×"})]}),p.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:G.map(e=>p.jsxs("button",{onClick:()=>pe(e.adapter.name),style:{width:"100%",padding:"1rem",backgroundColor:n.tokens.surfaceBackground,border:`1px solid ${n.tokens.surfaceBorder}`,borderRadius:"0.5rem",cursor:"pointer",fontSize:"1rem",textAlign:"left",color:n.tokens.surfaceText,display:"flex",alignItems:"center",gap:"1rem",transition:"all 0.2s ease"},onMouseEnter:r=>{r.currentTarget.style.backgroundColor=n.tokens.modalBackground,r.currentTarget.style.borderColor=n.tokens.surfaceText,r.currentTarget.style.transform="translateY(-2px)"},onMouseLeave:r=>{r.currentTarget.style.backgroundColor=n.tokens.surfaceBackground,r.currentTarget.style.borderColor=n.tokens.surfaceBorder,r.currentTarget.style.transform="translateY(0)"},type:"button",children:[p.jsx(be.WalletIcon,{wallet:e,style:{width:"24px",height:"24px"}}),p.jsx("span",{style:{fontWeight:500},children:e.adapter.name})]},e.adapter.name))})]})}),g&&!k&&!re&&p.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"0.5rem",fontSize:"0.75rem",color:n.tokens.surfaceText,opacity:.7},children:[p.jsx("button",{onClick:fe,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:b("wallet.change")}),p.jsx("button",{onClick:we,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:b("ui.disconnect")})]}),!k&&H&&p.jsx("div",{className:n.unstyled?"":"cedros-theme__error",children:H}),!k&&Y&&p.jsx("div",{className:n.unstyled?"":"cedros-theme__error",children:Y}),!k&&c&&p.jsx("div",{className:n.unstyled?"":"cedros-theme__success",children:b("ui.payment_successful")})]})}const Ce=Object.freeze(Object.defineProperty({__proto__:null,CryptoButton:ue},Symbol.toStringTag,{value:"Module"}));exports.CryptoButton=ue;exports.CryptoButton$1=Ce;exports.useX402Payment=ie;
1
+ "use strict";const p=require("react/jsx-runtime"),a=require("react"),ce=require("@solana/wallet-adapter-react"),le=require("@solana/wallet-adapter-base"),be=require("@solana/wallet-adapter-react-ui"),i=require("./styles-BT4bhFey.js"),t=require("./CedrosContext-C2RjHLaQ.js");function ie(){const{x402Manager:C,walletManager:l}=t.useCedrosContext(),{publicKey:W,signTransaction:j}=ce.useWallet(),[N,y]=a.useState({status:"idle",error:null,transactionId:null}),[R,L]=a.useState(null),[K,k]=a.useState(null),P=a.useRef(W);P.current=W;const h=a.useRef(j);h.current=j;const g=a.useRef(0),X=6e4,I=()=>{const o=g.current;return o>0&&Date.now()-o<X},S=a.useCallback(()=>{if(!W){const o="Wallet not connected";return y({status:"error",error:o,transactionId:null}),{valid:!1,error:o}}if(!j){const o="Wallet does not support signing";return y({status:"error",error:o,transactionId:null}),{valid:!1,error:o}}return{valid:!0}},[W,j]),q=a.useCallback(async o=>{try{y(d=>({...d,status:"loading"}));const c=await C.requestQuote({resource:o});if(!C.validateRequirement(c))throw new Error("Invalid requirement received from server");return L(c),y(d=>({...d,status:"idle"})),c}catch(c){const d=t.formatError(c,"Failed to fetch requirement");throw y({status:"error",error:d,transactionId:null}),c}},[C]),B=a.useCallback(async(o,c,d,x,n="regular")=>{const s=P.current,m=h.current;if(!s||!m)throw new Error("Wallet disconnected during payment flow");if(!!o.extra?.feePayer){t.getLogger().debug("[useX402Payment] Gasless flow enabled"),t.getLogger().debug("[useX402Payment] Building gasless transaction");const{transaction:b,blockhash:M}=await C.buildGaslessTransaction({resourceId:c,userWallet:s.toString(),feePayer:o.extra.feePayer,couponCode:d});t.getLogger().debug("[useX402Payment] Deserializing backend transaction");const A=l.deserializeTransaction(b);if(P.current?.toString()!==s.toString())throw new Error("Wallet changed during payment flow");t.getLogger().debug("[useX402Payment] Requesting partial signature");const E=await l.partiallySignTransaction({transaction:A,signTransaction:m,blockhash:M});t.getLogger().debug("[useX402Payment] Submitting partial transaction");const z=await C.submitGaslessTransaction({resource:c,partialTx:E,couponCode:d,metadata:x,resourceType:n,requirement:o});return z.success&&z.settlement&&k(z.settlement),z}else{const b=await l.buildTransaction({requirement:o,payerPublicKey:s});if(P.current?.toString()!==s.toString())throw new Error("Wallet changed during payment flow");const M=await l.signTransaction({transaction:b,signTransaction:m}),A=l.buildPaymentPayload({requirement:o,signedTx:M,payerPublicKey:s}),E=await C.submitPayment({resource:c,payload:A,couponCode:d,metadata:x,resourceType:n});return E.success&&E.settlement&&k(E.settlement),E}},[C,l]),w=a.useCallback(async(o,c,d)=>{if(I())return{success:!1,error:"Payment already in progress"};const x=S();if(!x.valid)return{success:!1,error:x.error};g.current=Date.now(),y({status:"loading",error:null,transactionId:null});try{t.getLogger().debug("[useX402Payment] Fetching fresh quote");const n=await C.requestQuote({resource:o,couponCode:c});t.getLogger().debug("[useX402Payment] Received quote",{amount:n.maxAmountRequired}),L(n),t.getLogger().debug("[useX402Payment] Executing payment flow");const s=await B(n,o,c,d,"regular");return s.success?y({status:"success",error:null,transactionId:s.transactionId||"payment-success"}):y({status:"error",error:s.error||"Payment failed",transactionId:null}),s}catch(n){const s=t.formatError(n,"Payment failed");return y({status:"error",error:s,transactionId:null}),{success:!1,error:s}}finally{g.current=0}},[S,C,B]),_=a.useCallback(async(o,c,d)=>{if(I())return{success:!1,error:"Payment already in progress"};const x=S();if(!x.valid)return{success:!1,error:x.error};g.current=Date.now(),y({status:"loading",error:null,transactionId:null});try{const n=i.normalizeCartItems(o),s=await C.requestCartQuote({items:n,metadata:c,couponCode:d}),m=s.cartId,u=s.quote;if(!C.validateRequirement(u))throw new Error("Invalid cart quote received from server");L(u);const b=await B(u,m,d,c,"cart");return b.success?y({status:"success",error:null,transactionId:b.transactionId||"cart-payment-success"}):y({status:"error",error:b.error||"Cart payment failed",transactionId:null}),b}catch(n){const s=t.formatError(n,"Cart payment failed");return y({status:"error",error:s,transactionId:null}),{success:!1,error:s}}finally{g.current=0}},[S,C,B]),T=a.useCallback(()=>{y({status:"idle",error:null,transactionId:null}),L(null),k(null),g.current=0},[]);return{...N,requirement:R,settlement:K,fetchQuote:q,processPayment:w,processCartPayment:_,reset:T}}function ue({resource:C,items:l,label:W,disabled:j=!1,onAttempt:N,onSuccess:y,onError:R,className:L="",testPageUrl:K,hideMessages:k=!1,metadata:P,couponCode:h}){const{connected:g,connecting:X,connect:I,disconnect:S,select:q,wallets:B,wallet:w,publicKey:_}=ce.useWallet(),{status:T,error:o,transactionId:c,processPayment:d,processCartPayment:x}=ie(),n=t.useCedrosTheme(),{solanaError:s}=t.useCedrosContext(),{isCartMode:m,effectiveResource:u}=i.usePaymentMode(C,l),{t:b,translations:M}=i.useTranslation(),A=W||b("ui.pay_with_crypto"),E=o&&typeof o!="string"?o?.code??null:null,z=s&&typeof s!="string"?s?.code??null:null,U=e=>{if(!e||!M)return"";const r=M.errors[e];return r?r.action?`${r.message} ${r.action}`:r.message:""},Y=o?typeof o=="string"?o:U(E):null,H=s?typeof s=="string"?s:U(z):null,J=a.useRef(y),V=a.useRef(R),Z=a.useRef(d),ee=a.useRef(x);J.current=y,V.current=R,Z.current=d,ee.current=x;const de=a.useMemo(()=>B.map(e=>`${e.adapter.name}-${e.readyState}`).join(","),[B]),G=a.useMemo(()=>B.filter(({readyState:e})=>e===le.WalletReadyState.Installed||e===le.WalletReadyState.Loadable),[de]);a.useEffect(()=>{if(T==="success"&&c){const e=m&&l?i.getCartItemCount(l):void 0;i.emitPaymentSuccess("crypto",c,u,e),J.current?.(c)}},[T,c,m,l,u]),a.useEffect(()=>{if(T==="error"&&o){const e=m&&l?i.getCartItemCount(l):void 0;i.emitPaymentError("crypto",o,u,e),V.current?.(o)}},[T,o,m,l,u]);const te=typeof window<"u"&&window.top!==window.self,[re,$]=a.useState(!1),[ne,Q]=a.useState(!1),[D,v]=a.useState(null),F=s;a.useEffect(()=>{let e=!1;return e||(async()=>{if(ne&&w&&!g&&!X){t.getLogger().debug("[CryptoButton] Wallet detected, attempting auto-connect:",w.adapter.name),Q(!1),i.emitWalletConnect(w.adapter.name);try{await I(),e||t.getLogger().debug("[CryptoButton] Auto-connect successful")}catch(f){if(!e){t.getLogger().error("[CryptoButton] Auto-connect failed:",f);const O=f instanceof Error?f.message:"Failed to connect wallet";i.emitWalletError(O,w.adapter.name),v(null)}}}})(),()=>{e=!0}},[w,ne,g,X,I]),a.useEffect(()=>{let e=!0;if(t.getLogger().debug("[CryptoButton] Payment useEffect triggered",{connected:g,hasPendingPayment:!!D,hasPublicKey:!!_,pendingPaymentType:D?.type}),g&&D&&_&&w&&e){i.emitWalletConnected(w.adapter.name,_.toString()),t.getLogger().debug("[CryptoButton] All conditions met! Processing pending payment:",D);const r=D;v(null),$(!1);const f=r.type==="cart"&&r.items?i.getCartItemCount(r.items):void 0;i.emitPaymentProcessing("crypto",r.resource,f),r.type==="cart"&&r.items?(t.getLogger().debug("[CryptoButton] Auto-processing cart payment"),ee.current(r.items,r.metadata,r.couponCode)):r.type==="single"&&r.resource&&(t.getLogger().debug("[CryptoButton] Auto-processing single payment"),Z.current(r.resource,r.couponCode,r.metadata))}return()=>{e=!1}},[g,D,_,w]);const oe=a.useCallback(async()=>{t.getLogger().debug("[CryptoButton] executePaymentFlow called",{connected:g,wallet:w?.adapter.name,couponCode:h,isCartMode:m,hasItems:!!l,effectiveResource:u});const e=m&&l?i.getCartItemCount(l):void 0;if(i.emitPaymentStart("crypto",u,e),N&&N("crypto"),F){t.getLogger().error("[CryptoButton] Solana dependencies missing:",F),i.emitPaymentError("crypto",F,u,e),R&&R(F);return}if(te){const r=K||window.location.href;try{if(new URL(r,window.location.origin).origin!==window.location.origin)throw t.getLogger().error("[CryptoButton] Blocked attempt to open external URL:",r),new Error("Cannot open external URLs from embedded context");window.open(r,"_blank","noopener,noreferrer")}catch(f){throw t.getLogger().error("[CryptoButton] URL validation failed:",f),f}return}if(g)i.emitPaymentProcessing("crypto",u,e),m&&l?(t.getLogger().debug("[CryptoButton] Processing cart payment with coupon:",h),await x(l,P,h)):u&&(t.getLogger().debug("[CryptoButton] Processing single payment with coupon:",h),await d(u,h,P));else{let r=!1;if(m&&l?(t.getLogger().debug("[CryptoButton] Setting pending cart payment with coupon:",h),v({type:"cart",items:l,metadata:P,couponCode:h}),r=!0):u&&(t.getLogger().debug("[CryptoButton] Setting pending single payment with coupon:",h),v({type:"single",resource:u,metadata:P,couponCode:h}),r=!0),!r){t.getLogger().error("[CryptoButton] No valid payment to process");return}try{if(w)t.getLogger().debug("[CryptoButton] Wallet already selected, connecting:",w.adapter.name),i.emitWalletConnect(w.adapter.name),await I();else{if(t.getLogger().debug("[CryptoButton] No wallet selected, showing selector. Available wallets:",G.map(f=>f.adapter.name)),G.length===0){v(null);const f="No wallets available";throw i.emitWalletError(f),new Error(f)}$(!0)}}catch(f){v(null);const O=f instanceof Error?f.message:"Failed to connect wallet";t.getLogger().error("[CryptoButton] Connection error:",O),i.emitWalletError(O,w?.adapter.name)}}},[g,w,h,m,l,u,te,K,G,I,P,x,d,F,N,R]),ae=a.useMemo(()=>m&&l?`crypto-cart-${l.map(e=>e.resource).join("-")}`:`crypto-${u||"unknown"}`,[m,l,u]),ge=a.useMemo(()=>i.createDedupedClickHandler(ae,oe,{cooldownMs:200,deduplicationWindowMs:0}),[ae,oe]),se=T==="loading",ye=j||se||X||!!F,me=se?b("ui.processing"):A,fe=a.useCallback(async()=>{try{Q(!1),g&&await S(),q(null),$(!0)}catch(e){t.getLogger().error("Failed to change wallet:",e)}},[g,S,q]),pe=a.useCallback(e=>{t.getLogger().debug("[CryptoButton] Wallet clicked:",e),$(!1),q(e),Q(!0),t.getLogger().debug("[CryptoButton] Wallet selected, useEffect will auto-connect")},[q]),we=a.useCallback(async()=>{try{if(await S(),v(null),typeof window<"u"&&window.localStorage)try{window.localStorage.removeItem("walletName")}catch(e){e instanceof Error&&e.name==="QuotaExceededError"?t.getLogger().warn("localStorage quota exceeded when removing wallet preference"):t.getLogger().error("Failed to clear wallet preference from localStorage:",e)}}catch(e){t.getLogger().error("Failed to disconnect wallet:",e)}},[S]);return p.jsxs("div",{className:n.unstyled?L:`${n.className} cedros-theme__crypto-button ${L||""}`,style:n.unstyled?{}:n.style,children:[p.jsx("button",{onClick:ge,disabled:ye,className:n.unstyled?L:"cedros-theme__button cedros-theme__crypto",type:"button",children:me}),re&&!k&&p.jsx("div",{className:"cedros-modal-overlay",style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:n.tokens.modalOverlay,display:"flex",alignItems:"center",justifyContent:"center",zIndex:9999,padding:"1rem"},onClick:()=>{$(!1),v(null)},children:p.jsxs("div",{className:"cedros-modal-content",style:{backgroundColor:n.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 ${n.tokens.modalBorder}`},onClick:e=>e.stopPropagation(),children:[p.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"1.5rem"},children:[p.jsx("h3",{style:{margin:0,fontSize:"1.25rem",fontWeight:600,color:n.tokens.surfaceText},children:b("wallet.select_wallet")}),p.jsx("button",{onClick:()=>{$(!1),v(null)},style:i.getModalCloseButtonStyles(n.tokens.surfaceText),"aria-label":"Close modal",type:"button",children:"×"})]}),p.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:G.map(e=>p.jsxs("button",{onClick:()=>pe(e.adapter.name),style:{width:"100%",padding:"1rem",backgroundColor:n.tokens.surfaceBackground,border:`1px solid ${n.tokens.surfaceBorder}`,borderRadius:"0.5rem",cursor:"pointer",fontSize:"1rem",textAlign:"left",color:n.tokens.surfaceText,display:"flex",alignItems:"center",gap:"1rem",transition:"all 0.2s ease"},onMouseEnter:r=>{r.currentTarget.style.backgroundColor=n.tokens.modalBackground,r.currentTarget.style.borderColor=n.tokens.surfaceText,r.currentTarget.style.transform="translateY(-2px)"},onMouseLeave:r=>{r.currentTarget.style.backgroundColor=n.tokens.surfaceBackground,r.currentTarget.style.borderColor=n.tokens.surfaceBorder,r.currentTarget.style.transform="translateY(0)"},type:"button",children:[p.jsx(be.WalletIcon,{wallet:e,style:{width:"24px",height:"24px"}}),p.jsx("span",{style:{fontWeight:500},children:e.adapter.name})]},e.adapter.name))})]})}),g&&!k&&!re&&p.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"0.5rem",fontSize:"0.75rem",color:n.tokens.surfaceText,opacity:.7},children:[p.jsx("button",{onClick:fe,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:b("wallet.change")}),p.jsx("button",{onClick:we,style:{background:"none",border:"none",padding:0,color:"inherit",textDecoration:"none",cursor:"pointer",fontSize:"inherit"},type:"button",children:b("ui.disconnect")})]}),!k&&H&&p.jsx("div",{className:n.unstyled?"":"cedros-theme__error",children:H}),!k&&Y&&p.jsx("div",{className:n.unstyled?"":"cedros-theme__error",children:Y}),!k&&c&&p.jsx("div",{className:n.unstyled?"":"cedros-theme__success",children:b("ui.payment_successful")})]})}const Ce=Object.freeze(Object.defineProperty({__proto__:null,CryptoButton:ue},Symbol.toStringTag,{value:"Module"}));exports.CryptoButton=ue;exports.CryptoButton$1=Ce;exports.useX402Payment=ie;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("react"),d=require("./index-OaWkrl0G.js");function R({serverUrl:h,apiKey:o,pageSize:g=20,authManager:r}){const[u,N]=c.useState([]),[Q,w]=c.useState(!0),[S,f]=c.useState(!1),[p,A]=c.useState(null),[F,C]=c.useState(!1),[x,P]=c.useState(""),[v,O]=c.useState("all"),[q,b]=c.useState(null),[$,j]=c.useState(null),[n,l]=c.useState({question:"",answer:"",keywordsCsv:"",active:!0,useInChat:!0,displayOnPage:!0}),_=c.useCallback(async()=>{w(!0);try{j(null);let s;const t=`/admin/faqs?limit=${g}`;if(r?.isAuthenticated())s=await r.fetchWithAuth(t);else{const i={"Content-Type":"application/json"};o&&(i["X-API-Key"]=o);const a=await fetch(`${h}${t}`,{headers:i});if(!a.ok)throw new Error(`Failed to fetch FAQs: ${a.status}`);s=await a.json()}N(s.faqs||[])}catch{N([]),j("Failed to load FAQs")}finally{w(!1)}},[h,o,g,r]);c.useEffect(()=>{_()},[_]);const E=async s=>{if(s.preventDefault(),!(!n.question.trim()||!n.answer.trim())){C(!0);try{const t=n.keywordsCsv.split(",").map(a=>a.trim().toLowerCase()).filter(Boolean),i={question:n.question.trim(),answer:n.answer.trim(),keywords:t,active:n.active,useInChat:n.useInChat,displayOnPage:n.displayOnPage};if(p){const a=`/admin/faqs/${p.id}`;if(r?.isAuthenticated())await r.fetchWithAuth(a,{method:"PUT",body:JSON.stringify(i)});else{const m={"Content-Type":"application/json"};o&&(m["X-API-Key"]=o);const I=await fetch(`${h}${a}`,{method:"PUT",headers:m,body:JSON.stringify(i)});if(!I.ok)throw new Error(`Failed to update FAQ: ${I.status}`)}}else if(r?.isAuthenticated())await r.fetchWithAuth("/admin/faqs",{method:"POST",body:JSON.stringify(i)});else{const a={"Content-Type":"application/json"};o&&(a["X-API-Key"]=o);const m=await fetch(`${h}/admin/faqs`,{method:"POST",headers:a,body:JSON.stringify(i)});if(!m.ok)throw new Error(`Failed to create FAQ: ${m.status}`)}y(),_()}catch{j(p?"Failed to update FAQ":"Failed to create FAQ")}finally{C(!1)}}},T=async s=>{try{const t=`/admin/faqs/${s}`;if(r?.isAuthenticated())await r.fetchWithAuth(t,{method:"DELETE"});else{const i={"Content-Type":"application/json"};o&&(i["X-API-Key"]=o);const a=await fetch(`${h}${t}`,{method:"DELETE",headers:i});if(!a.ok)throw new Error(`Failed to delete FAQ: ${a.status}`)}_()}catch{j("Failed to delete FAQ")}b(null)},D=async s=>{try{const t=`/admin/faqs/${s.id}`,i={...s,active:!s.active};if(r?.isAuthenticated())await r.fetchWithAuth(t,{method:"PUT",body:JSON.stringify(i)});else{const a={"Content-Type":"application/json"};o&&(a["X-API-Key"]=o);const m=await fetch(`${h}${t}`,{method:"PUT",headers:a,body:JSON.stringify(i)});if(!m.ok)throw new Error(`Failed to update FAQ: ${m.status}`)}_()}catch{j("Failed to update FAQ status")}},y=()=>{l({question:"",answer:"",keywordsCsv:"",active:!0,useInChat:!0,displayOnPage:!0}),A(null),f(!1)},L=s=>{l({question:s.question,answer:s.answer,keywordsCsv:s.keywords.join(", "),active:s.active,useInChat:s.useInChat??!0,displayOnPage:s.displayOnPage??!0}),A(s),f(!0)},W=u.length,B=u.filter(s=>s.active).length,J=u.filter(s=>s.active&&s.useInChat).length,X=u.filter(s=>s.active&&s.displayOnPage).length,k=c.useMemo(()=>u.filter(s=>{if(v==="active"&&!s.active||v==="inactive"&&s.active)return!1;if(x){const t=x.toLowerCase();return s.question.toLowerCase().includes(t)||s.answer.toLowerCase().includes(t)||s.keywords.some(i=>i.includes(t))}return!0}),[u,v,x]);return e.jsxs("div",{className:"cedros-admin__faqs",children:[e.jsx(d.ErrorBanner,{message:$,onRetry:_}),e.jsx(d.StatsBar,{stats:[{label:"Total FAQs",value:W},{label:"Active",value:B,variant:"success"},{label:"In Chat",value:J},{label:"On Page",value:X}]}),e.jsxs("div",{className:"cedros-admin__section",children:[e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsxs("div",{className:"cedros-admin__section-header-left",children:[e.jsx("h3",{className:"cedros-admin__section-title",children:"Knowledge Base"}),e.jsx("p",{className:"cedros-admin__section-subtitle",children:"Manage FAQs for the AI chat assistant and public FAQ page."})]}),e.jsx("div",{className:"cedros-admin__section-header-right",children:e.jsxs("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:()=>{y(),f(!0)},children:[d.Icons.plus," Add FAQ"]})})]}),e.jsxs("div",{className:"cedros-admin__filters",style:{display:"flex",gap:"1rem",marginBottom:"1rem"},children:[e.jsx("input",{type:"text",placeholder:"Search FAQs...",value:x,onChange:s=>P(s.target.value),className:"cedros-admin__input",style:{flex:1,maxWidth:300}}),e.jsxs("select",{value:v,onChange:s=>O(s.target.value),className:"cedros-admin__select",children:[e.jsx("option",{value:"all",children:"All Status"}),e.jsx("option",{value:"active",children:"Active Only"}),e.jsx("option",{value:"inactive",children:"Inactive Only"})]})]}),S&&e.jsx("div",{className:"cedros-admin__form-container",style:{marginBottom:"1.5rem"},children:e.jsxs("form",{onSubmit:E,className:"cedros-admin__form",children:[e.jsxs("div",{className:"cedros-admin__form-header",children:[e.jsx("h4",{children:p?"Edit FAQ":"Add New FAQ"}),e.jsx("button",{type:"button",className:"cedros-admin__button--icon",onClick:y,children:d.Icons.close})]}),e.jsxs("div",{className:"cedros-admin__form-group",children:[e.jsx("label",{className:"cedros-admin__label",children:"Question *"}),e.jsx("input",{type:"text",value:n.question,onChange:s=>l(t=>({...t,question:s.target.value})),className:"cedros-admin__input",placeholder:"What is your return policy?",required:!0})]}),e.jsxs("div",{className:"cedros-admin__form-group",children:[e.jsx("label",{className:"cedros-admin__label",children:"Answer *"}),e.jsx("textarea",{value:n.answer,onChange:s=>l(t=>({...t,answer:s.target.value})),className:"cedros-admin__textarea",placeholder:"We accept returns within 30 days...",rows:4,required:!0}),e.jsx("span",{className:"cedros-admin__hint",children:"Supports markdown formatting."})]}),e.jsxs("div",{className:"cedros-admin__form-group",children:[e.jsx("label",{className:"cedros-admin__label",children:"Keywords"}),e.jsx("input",{type:"text",value:n.keywordsCsv,onChange:s=>l(t=>({...t,keywordsCsv:s.target.value})),className:"cedros-admin__input",placeholder:"returns, refund, policy"}),e.jsx("span",{className:"cedros-admin__hint",children:"Comma-separated keywords to help AI find this FAQ."})]}),e.jsxs("div",{className:"cedros-admin__form-group",children:[e.jsxs("label",{className:"cedros-admin__checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n.active,onChange:s=>l(t=>({...t,active:s.target.checked}))}),e.jsx("span",{children:"Active"})]}),e.jsx("span",{className:"cedros-admin__hint",children:"Inactive FAQs won't appear anywhere."})]}),e.jsxs("div",{className:"cedros-admin__form-group",children:[e.jsx("label",{className:"cedros-admin__label",children:"Visibility"}),e.jsxs("div",{className:"cedros-admin__checkbox-group",children:[e.jsxs("label",{className:"cedros-admin__checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n.useInChat,onChange:s=>l(t=>({...t,useInChat:s.target.checked}))}),e.jsx("span",{children:"Use in AI Chat"})]}),e.jsxs("label",{className:"cedros-admin__checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n.displayOnPage,onChange:s=>l(t=>({...t,displayOnPage:s.target.checked}))}),e.jsx("span",{children:"Display on FAQ Page"})]})]}),e.jsx("span",{className:"cedros-admin__hint",children:"Choose where this FAQ should appear."})]}),e.jsxs("div",{className:"cedros-admin__form-actions",children:[e.jsx("button",{type:"button",className:"cedros-admin__button",onClick:y,children:"Cancel"}),e.jsx("button",{type:"submit",className:"cedros-admin__button cedros-admin__button--primary",disabled:F||!n.question.trim()||!n.answer.trim(),children:F?d.Icons.loading:p?"Update FAQ":"Create FAQ"})]})]})}),Q?e.jsxs("div",{className:"cedros-admin__loading",children:[d.Icons.loading,e.jsx("span",{children:"Loading FAQs..."})]}):k.length===0?e.jsx("div",{className:"cedros-admin__empty",children:e.jsx("p",{children:x||v!=="all"?"No FAQs match your filters.":"No FAQs yet. Add one to get started."})}):e.jsx("div",{className:"cedros-admin__faq-list",children:k.map(s=>e.jsxs("div",{className:`cedros-admin__faq-item ${s.active?"":"cedros-admin__faq-item--inactive"}`,children:[e.jsxs("div",{className:"cedros-admin__faq-content",children:[e.jsxs("div",{className:"cedros-admin__faq-question",children:[e.jsx("span",{className:`cedros-admin__status-dot ${s.active?"cedros-admin__status-dot--active":"cedros-admin__status-dot--inactive"}`}),s.question]}),e.jsx("div",{className:"cedros-admin__faq-answer",children:s.answer}),e.jsxs("div",{className:"cedros-admin__faq-meta",children:[s.keywords.length>0&&e.jsx("div",{className:"cedros-admin__faq-keywords",children:s.keywords.map(t=>e.jsx("span",{className:"cedros-admin__tag",children:t},t))}),e.jsxs("div",{className:"cedros-admin__faq-visibility",children:[s.useInChat&&e.jsxs("span",{className:"cedros-admin__badge cedros-admin__badge--chat",title:"Used in AI Chat",children:[d.Icons.chat," Chat"]}),s.displayOnPage&&e.jsxs("span",{className:"cedros-admin__badge cedros-admin__badge--page",title:"Displayed on FAQ Page",children:[d.Icons.globe," Page"]})]})]})]}),e.jsxs("div",{className:"cedros-admin__faq-actions",children:[e.jsx("button",{className:"cedros-admin__button--icon",onClick:()=>D(s),title:s.active?"Deactivate":"Activate",children:s.active?d.Icons.eyeOff:d.Icons.eye}),e.jsx("button",{className:"cedros-admin__button--icon",onClick:()=>L(s),title:"Edit",children:d.Icons.edit}),e.jsx("button",{className:"cedros-admin__button--icon cedros-admin__btn--danger",onClick:()=>b(s.id),title:"Delete",children:d.Icons.trash})]}),q===s.id&&e.jsx("div",{className:"cedros-admin__confirm-overlay",children:e.jsxs("div",{className:"cedros-admin__confirm-dialog",children:[e.jsx("p",{children:"Delete this FAQ?"}),e.jsxs("div",{className:"cedros-admin__confirm-actions",children:[e.jsx("button",{className:"cedros-admin__button",onClick:()=>b(null),children:"Cancel"}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--danger",onClick:()=>T(s.id),children:"Delete"})]})]})})]},s.id))})]})]})}exports.FAQSection=R;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("react"),d=require("./index-C7MWL6O8.js");function R({serverUrl:h,apiKey:o,pageSize:g=20,authManager:r}){const[u,N]=c.useState([]),[Q,w]=c.useState(!0),[S,f]=c.useState(!1),[p,A]=c.useState(null),[F,C]=c.useState(!1),[x,P]=c.useState(""),[v,O]=c.useState("all"),[q,b]=c.useState(null),[$,j]=c.useState(null),[n,l]=c.useState({question:"",answer:"",keywordsCsv:"",active:!0,useInChat:!0,displayOnPage:!0}),_=c.useCallback(async()=>{w(!0);try{j(null);let s;const t=`/admin/faqs?limit=${g}`;if(r?.isAuthenticated())s=await r.fetchWithAuth(t);else{const i={"Content-Type":"application/json"};o&&(i["X-API-Key"]=o);const a=await fetch(`${h}${t}`,{headers:i});if(!a.ok)throw new Error(`Failed to fetch FAQs: ${a.status}`);s=await a.json()}N(s.faqs||[])}catch{N([]),j("Failed to load FAQs")}finally{w(!1)}},[h,o,g,r]);c.useEffect(()=>{_()},[_]);const E=async s=>{if(s.preventDefault(),!(!n.question.trim()||!n.answer.trim())){C(!0);try{const t=n.keywordsCsv.split(",").map(a=>a.trim().toLowerCase()).filter(Boolean),i={question:n.question.trim(),answer:n.answer.trim(),keywords:t,active:n.active,useInChat:n.useInChat,displayOnPage:n.displayOnPage};if(p){const a=`/admin/faqs/${p.id}`;if(r?.isAuthenticated())await r.fetchWithAuth(a,{method:"PUT",body:JSON.stringify(i)});else{const m={"Content-Type":"application/json"};o&&(m["X-API-Key"]=o);const I=await fetch(`${h}${a}`,{method:"PUT",headers:m,body:JSON.stringify(i)});if(!I.ok)throw new Error(`Failed to update FAQ: ${I.status}`)}}else if(r?.isAuthenticated())await r.fetchWithAuth("/admin/faqs",{method:"POST",body:JSON.stringify(i)});else{const a={"Content-Type":"application/json"};o&&(a["X-API-Key"]=o);const m=await fetch(`${h}/admin/faqs`,{method:"POST",headers:a,body:JSON.stringify(i)});if(!m.ok)throw new Error(`Failed to create FAQ: ${m.status}`)}y(),_()}catch{j(p?"Failed to update FAQ":"Failed to create FAQ")}finally{C(!1)}}},T=async s=>{try{const t=`/admin/faqs/${s}`;if(r?.isAuthenticated())await r.fetchWithAuth(t,{method:"DELETE"});else{const i={"Content-Type":"application/json"};o&&(i["X-API-Key"]=o);const a=await fetch(`${h}${t}`,{method:"DELETE",headers:i});if(!a.ok)throw new Error(`Failed to delete FAQ: ${a.status}`)}_()}catch{j("Failed to delete FAQ")}b(null)},D=async s=>{try{const t=`/admin/faqs/${s.id}`,i={...s,active:!s.active};if(r?.isAuthenticated())await r.fetchWithAuth(t,{method:"PUT",body:JSON.stringify(i)});else{const a={"Content-Type":"application/json"};o&&(a["X-API-Key"]=o);const m=await fetch(`${h}${t}`,{method:"PUT",headers:a,body:JSON.stringify(i)});if(!m.ok)throw new Error(`Failed to update FAQ: ${m.status}`)}_()}catch{j("Failed to update FAQ status")}},y=()=>{l({question:"",answer:"",keywordsCsv:"",active:!0,useInChat:!0,displayOnPage:!0}),A(null),f(!1)},L=s=>{l({question:s.question,answer:s.answer,keywordsCsv:s.keywords.join(", "),active:s.active,useInChat:s.useInChat??!0,displayOnPage:s.displayOnPage??!0}),A(s),f(!0)},W=u.length,B=u.filter(s=>s.active).length,J=u.filter(s=>s.active&&s.useInChat).length,X=u.filter(s=>s.active&&s.displayOnPage).length,k=c.useMemo(()=>u.filter(s=>{if(v==="active"&&!s.active||v==="inactive"&&s.active)return!1;if(x){const t=x.toLowerCase();return s.question.toLowerCase().includes(t)||s.answer.toLowerCase().includes(t)||s.keywords.some(i=>i.includes(t))}return!0}),[u,v,x]);return e.jsxs("div",{className:"cedros-admin__faqs",children:[e.jsx(d.ErrorBanner,{message:$,onRetry:_}),e.jsx(d.StatsBar,{stats:[{label:"Total FAQs",value:W},{label:"Active",value:B,variant:"success"},{label:"In Chat",value:J},{label:"On Page",value:X}]}),e.jsxs("div",{className:"cedros-admin__section",children:[e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsxs("div",{className:"cedros-admin__section-header-left",children:[e.jsx("h3",{className:"cedros-admin__section-title",children:"Knowledge Base"}),e.jsx("p",{className:"cedros-admin__section-subtitle",children:"Manage FAQs for the AI chat assistant and public FAQ page."})]}),e.jsx("div",{className:"cedros-admin__section-header-right",children:e.jsxs("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:()=>{y(),f(!0)},children:[d.Icons.plus," Add FAQ"]})})]}),e.jsxs("div",{className:"cedros-admin__filters",style:{display:"flex",gap:"1rem",marginBottom:"1rem"},children:[e.jsx("input",{type:"text",placeholder:"Search FAQs...",value:x,onChange:s=>P(s.target.value),className:"cedros-admin__input",style:{flex:1,maxWidth:300}}),e.jsxs("select",{value:v,onChange:s=>O(s.target.value),className:"cedros-admin__select",children:[e.jsx("option",{value:"all",children:"All Status"}),e.jsx("option",{value:"active",children:"Active Only"}),e.jsx("option",{value:"inactive",children:"Inactive Only"})]})]}),S&&e.jsx("div",{className:"cedros-admin__form-container",style:{marginBottom:"1.5rem"},children:e.jsxs("form",{onSubmit:E,className:"cedros-admin__form",children:[e.jsxs("div",{className:"cedros-admin__form-header",children:[e.jsx("h4",{children:p?"Edit FAQ":"Add New FAQ"}),e.jsx("button",{type:"button",className:"cedros-admin__button--icon",onClick:y,children:d.Icons.close})]}),e.jsxs("div",{className:"cedros-admin__form-group",children:[e.jsx("label",{className:"cedros-admin__label",children:"Question *"}),e.jsx("input",{type:"text",value:n.question,onChange:s=>l(t=>({...t,question:s.target.value})),className:"cedros-admin__input",placeholder:"What is your return policy?",required:!0})]}),e.jsxs("div",{className:"cedros-admin__form-group",children:[e.jsx("label",{className:"cedros-admin__label",children:"Answer *"}),e.jsx("textarea",{value:n.answer,onChange:s=>l(t=>({...t,answer:s.target.value})),className:"cedros-admin__textarea",placeholder:"We accept returns within 30 days...",rows:4,required:!0}),e.jsx("span",{className:"cedros-admin__hint",children:"Supports markdown formatting."})]}),e.jsxs("div",{className:"cedros-admin__form-group",children:[e.jsx("label",{className:"cedros-admin__label",children:"Keywords"}),e.jsx("input",{type:"text",value:n.keywordsCsv,onChange:s=>l(t=>({...t,keywordsCsv:s.target.value})),className:"cedros-admin__input",placeholder:"returns, refund, policy"}),e.jsx("span",{className:"cedros-admin__hint",children:"Comma-separated keywords to help AI find this FAQ."})]}),e.jsxs("div",{className:"cedros-admin__form-group",children:[e.jsxs("label",{className:"cedros-admin__checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n.active,onChange:s=>l(t=>({...t,active:s.target.checked}))}),e.jsx("span",{children:"Active"})]}),e.jsx("span",{className:"cedros-admin__hint",children:"Inactive FAQs won't appear anywhere."})]}),e.jsxs("div",{className:"cedros-admin__form-group",children:[e.jsx("label",{className:"cedros-admin__label",children:"Visibility"}),e.jsxs("div",{className:"cedros-admin__checkbox-group",children:[e.jsxs("label",{className:"cedros-admin__checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n.useInChat,onChange:s=>l(t=>({...t,useInChat:s.target.checked}))}),e.jsx("span",{children:"Use in AI Chat"})]}),e.jsxs("label",{className:"cedros-admin__checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n.displayOnPage,onChange:s=>l(t=>({...t,displayOnPage:s.target.checked}))}),e.jsx("span",{children:"Display on FAQ Page"})]})]}),e.jsx("span",{className:"cedros-admin__hint",children:"Choose where this FAQ should appear."})]}),e.jsxs("div",{className:"cedros-admin__form-actions",children:[e.jsx("button",{type:"button",className:"cedros-admin__button",onClick:y,children:"Cancel"}),e.jsx("button",{type:"submit",className:"cedros-admin__button cedros-admin__button--primary",disabled:F||!n.question.trim()||!n.answer.trim(),children:F?d.Icons.loading:p?"Update FAQ":"Create FAQ"})]})]})}),Q?e.jsxs("div",{className:"cedros-admin__loading",children:[d.Icons.loading,e.jsx("span",{children:"Loading FAQs..."})]}):k.length===0?e.jsx("div",{className:"cedros-admin__empty",children:e.jsx("p",{children:x||v!=="all"?"No FAQs match your filters.":"No FAQs yet. Add one to get started."})}):e.jsx("div",{className:"cedros-admin__faq-list",children:k.map(s=>e.jsxs("div",{className:`cedros-admin__faq-item ${s.active?"":"cedros-admin__faq-item--inactive"}`,children:[e.jsxs("div",{className:"cedros-admin__faq-content",children:[e.jsxs("div",{className:"cedros-admin__faq-question",children:[e.jsx("span",{className:`cedros-admin__status-dot ${s.active?"cedros-admin__status-dot--active":"cedros-admin__status-dot--inactive"}`}),s.question]}),e.jsx("div",{className:"cedros-admin__faq-answer",children:s.answer}),e.jsxs("div",{className:"cedros-admin__faq-meta",children:[s.keywords.length>0&&e.jsx("div",{className:"cedros-admin__faq-keywords",children:s.keywords.map(t=>e.jsx("span",{className:"cedros-admin__tag",children:t},t))}),e.jsxs("div",{className:"cedros-admin__faq-visibility",children:[s.useInChat&&e.jsxs("span",{className:"cedros-admin__badge cedros-admin__badge--chat",title:"Used in AI Chat",children:[d.Icons.chat," Chat"]}),s.displayOnPage&&e.jsxs("span",{className:"cedros-admin__badge cedros-admin__badge--page",title:"Displayed on FAQ Page",children:[d.Icons.globe," Page"]})]})]})]}),e.jsxs("div",{className:"cedros-admin__faq-actions",children:[e.jsx("button",{className:"cedros-admin__button--icon",onClick:()=>D(s),title:s.active?"Deactivate":"Activate",children:s.active?d.Icons.eyeOff:d.Icons.eye}),e.jsx("button",{className:"cedros-admin__button--icon",onClick:()=>L(s),title:"Edit",children:d.Icons.edit}),e.jsx("button",{className:"cedros-admin__button--icon cedros-admin__btn--danger",onClick:()=>b(s.id),title:"Delete",children:d.Icons.trash})]}),q===s.id&&e.jsx("div",{className:"cedros-admin__confirm-overlay",children:e.jsxs("div",{className:"cedros-admin__confirm-dialog",children:[e.jsx("p",{children:"Delete this FAQ?"}),e.jsxs("div",{className:"cedros-admin__confirm-actions",children:[e.jsx("button",{className:"cedros-admin__button",onClick:()=>b(null),children:"Cancel"}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--danger",onClick:()=>T(s.id),children:"Delete"})]})]})})]},s.id))})]})]})}exports.FAQSection=R;
@@ -1,6 +1,6 @@
1
1
  import { jsxs as a, jsx as t } from "react/jsx-runtime";
2
2
  import { useState as r, useCallback as R, useEffect as V, useMemo as G } from "react";
3
- import { E as H, g as Y, I as l } from "./index-BHF82XBB.mjs";
3
+ import { E as H, j as Y, I as l } from "./index-BkDimQDF.mjs";
4
4
  function M({ serverUrl: u, apiKey: d, pageSize: A = 20, authManager: o }) {
5
5
  const [_, F] = r([]), [E, C] = r(!0), [S, N] = r(!1), [v, k] = r(null), [Q, I] = r(!1), [y, $] = r(""), [f, x] = r("all"), [q, w] = r(null), [T, b] = r(null), [n, m] = r({
6
6
  question: "",
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("react"),y=require("./index-OaWkrl0G.js"),S=require("./Toggle-CsPSF8Dr.js"),q=require("./useAutosave-B2p6iwh8.js"),z=require("./AutosaveIndicator-CY_YHM1D.js"),p={mailgun:{label:"Mailgun",host:"smtp.mailgun.org",username:"",credentialLabel:"SMTP Password",showUsername:!0,usernameEqualsPassword:!1},sendgrid:{label:"SendGrid",host:"smtp.sendgrid.net",username:"apikey",credentialLabel:"API Key",showUsername:!1,usernameEqualsPassword:!1},postmark:{label:"Postmark",host:"smtp.postmarkapp.com",username:"",credentialLabel:"Server API Token",showUsername:!1,usernameEqualsPassword:!0},ses:{label:"AWS SES",host:"email-smtp.us-east-1.amazonaws.com",username:"",credentialLabel:"SMTP Password",showUsername:!0,usernameEqualsPassword:!1},resend:{label:"Resend",host:"smtp.resend.com",username:"resend",credentialLabel:"API Key",showUsername:!1,usernameEqualsPassword:!1},custom:{label:"Custom SMTP",host:"",username:"",credentialLabel:"SMTP Password",showUsername:!0,usernameEqualsPassword:!1}};function R(c){if(!c)return"custom";for(const[d,n]of Object.entries(p))if(n.host&&c===n.host)return d;return"custom"}const v={email_enabled:!1,email_provider:"custom",smtp_host:"",smtp_port:587,smtp_username:"",smtp_password:"",from_email:"",from_name:"",webhook_enabled:!1,webhook_url:"",webhook_secret:"",webhook_timeout:30};function W({serverUrl:c,apiKey:d,authManager:n}){const[m,b]=l.useState("messages"),[a,h]=l.useState(v),[N,k]=l.useState(!0),[C,E]=l.useState(!0),[P,f]=l.useState(null),[_,j]=l.useState(new Set),g=l.useCallback(async()=>{try{f(null);let s;const t="/admin/config/messaging";if(n?.isAuthenticated())s=await n.fetchWithAuth(t);else{const o={"Content-Type":"application/json"};d&&(o["X-API-Key"]=d);const u=await fetch(`${c}${t}`,{headers:o});if(!u.ok)throw new Error(`Failed to fetch: ${u.status}`);s=await u.json()}const i={...v,...s.config};i.email_provider||(i.email_provider=R(i.smtp_host)),h(i)}catch{h(v),f("Could not load saved settings. Showing defaults.")}finally{k(!1),setTimeout(()=>E(!1),100)}},[c,d,n]);l.useEffect(()=>{g()},[g]);const T=l.useCallback(async s=>{const t="/admin/config/messaging",i={...s};_.has("smtp_password")||delete i.smtp_password,_.has("webhook_secret")||delete i.webhook_secret;const o=JSON.stringify({config:i});try{if(n?.isAuthenticated())await n.fetchWithAuth(t,{method:"PUT",body:o});else{const u={"Content-Type":"application/json"};d&&(u["X-API-Key"]=d);const w=await fetch(`${c}${t}`,{method:"PUT",headers:u,body:o});if(!w.ok)throw new Error(`Failed to save: ${w.status}`)}}catch{throw f("Failed to save messaging settings"),new Error("Save failed")}},[c,d,n,_]),{status:A,error:I}=q.useAutosave({data:a,onSave:T,debounceMs:1500,enabled:!C}),r=(s,t)=>{(s==="smtp_password"||s==="webhook_secret")&&j(i=>new Set(i).add(s)),h(i=>({...i,[s]:t}))},L=s=>{const t=p[s];h(i=>({...i,email_provider:s,smtp_host:t.host||i.smtp_host,smtp_port:587,smtp_username:t.username||(t.showUsername?i.smtp_username:"")}))},M=s=>{const t=a.email_provider||"custom",i=p[t];j(o=>new Set(o).add("smtp_password")),i.usernameEqualsPassword?h(o=>({...o,smtp_password:s,smtp_username:s})):h(o=>({...o,smtp_password:s}))},x=p[a.email_provider||"custom"]??p.custom;return N?e.jsxs("div",{className:"cedros-admin__messaging-settings",children:[e.jsxs("div",{className:"cedros-admin__page-header",children:[e.jsx("h2",{className:"cedros-admin__page-title",children:"Store Messages"}),e.jsx("p",{className:"cedros-admin__page-description",children:"Configure email delivery and webhook notifications."})]}),e.jsxs("div",{className:"cedros-admin__loading",style:{marginTop:"1rem"},children:[y.Icons.loading," Loading message settings..."]})]}):e.jsxs("div",{className:"cedros-admin__messaging-settings",children:[e.jsxs("div",{className:"cedros-admin__page-header",children:[e.jsx("h2",{className:"cedros-admin__page-title",children:"Store Messages"}),e.jsx("p",{className:"cedros-admin__page-description",children:"Configure email delivery and webhook notifications."})]}),e.jsxs("div",{className:"cedros-admin__tabs cedros-admin__tabs--line",children:[e.jsx("button",{type:"button",className:`cedros-admin__tab ${m==="messages"?"cedros-admin__tab--active":""}`,onClick:()=>b("messages"),children:"Messages"}),e.jsx("button",{type:"button",className:`cedros-admin__tab ${m==="email"?"cedros-admin__tab--active":""}`,onClick:()=>b("email"),children:"Email"}),e.jsx("button",{type:"button",className:`cedros-admin__tab ${m==="webhooks"?"cedros-admin__tab--active":""}`,onClick:()=>b("webhooks"),children:"Webhooks"}),e.jsx("div",{style:{flex:1}}),e.jsx(z.AutosaveIndicator,{status:A,error:I})]}),e.jsx(y.ErrorBanner,{message:P,onRetry:g}),e.jsxs("div",{className:"cedros-admin__tab-content",style:{marginTop:"1rem"},children:[m==="messages"&&e.jsxs("div",{className:"cedros-admin__section",children:[e.jsx("p",{style:{marginBottom:"1.5rem",fontSize:"0.875rem",opacity:.7},children:"Enable or disable notification types. Configure the delivery settings in the Email or Webhooks tab."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"1rem"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"1rem",padding:"1rem",border:"1px solid var(--cedros-admin-border, #e5e5e5)",borderRadius:"0.5rem"},children:[e.jsx(S.Toggle,{checked:a.email_enabled,onChange:s=>r("email_enabled",s)}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:"Email Confirmation"}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.8125rem",opacity:.6},children:"Send order confirmation emails to customers after successful purchase."}),e.jsx("p",{style:{margin:"0.5rem 0 0",fontSize:"0.75rem",opacity:.5},children:"Requires Email configuration"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"1rem",padding:"1rem",border:"1px solid var(--cedros-admin-border, #e5e5e5)",borderRadius:"0.5rem"},children:[e.jsx(S.Toggle,{checked:a.webhook_enabled,onChange:s=>r("webhook_enabled",s)}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:"Admin Purchase Notification"}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.8125rem",opacity:.6},children:"Send webhook notifications to your server when a purchase is completed."}),e.jsx("p",{style:{margin:"0.5rem 0 0",fontSize:"0.75rem",opacity:.5},children:"Requires Webhook configuration"})]})]})]})]}),m==="email"&&e.jsxs("div",{className:"cedros-admin__section",children:[e.jsx("p",{style:{marginBottom:"1.5rem",fontSize:"0.875rem",opacity:.7},children:"Select your email service provider for automatic configuration."}),!a.email_enabled&&e.jsx("div",{style:{padding:"1rem",marginBottom:"1.5rem",background:"var(--cedros-admin-bg-accent, #fef3c7)",borderRadius:"0.5rem",border:"1px solid var(--cedros-admin-warning, #f59e0b)",fontSize:"0.875rem"},children:"Email notifications are disabled. Enable them in the Messages tab."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",opacity:a.email_enabled?1:.5},children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Email Provider"}),e.jsx("select",{className:"cedros-admin__input",value:a.email_provider||"custom",onChange:s=>L(s.target.value),disabled:!a.email_enabled,children:Object.entries(p).map(([s,{label:t}])=>e.jsx("option",{value:s,children:t},s))})]}),a.email_provider==="custom"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"SMTP Host"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.smtp_host,onChange:s=>r("smtp_host",s.target.value),placeholder:"smtp.example.com",disabled:!a.email_enabled})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"SMTP Port"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:a.smtp_port,onChange:s=>r("smtp_port",parseInt(s.target.value)||587),placeholder:"587",disabled:!a.email_enabled,style:{maxWidth:120}}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.75rem",opacity:.6},children:"Common: 587 (TLS), 465 (SSL), 25 (unencrypted)."})]})]}),x.showUsername&&e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"SMTP Username"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.smtp_username,onChange:s=>r("smtp_username",s.target.value),placeholder:a.email_provider==="mailgun"?"postmaster@your-domain.com":"username",disabled:!a.email_enabled})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:x.credentialLabel}),e.jsx("input",{type:"password",className:"cedros-admin__input",value:_.has("smtp_password")?a.smtp_password:"",onChange:s=>M(s.target.value),placeholder:a.smtp_password?"••••••••":`Enter ${x.credentialLabel.toLowerCase()}`,disabled:!a.email_enabled})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"From Email"}),e.jsx("input",{type:"email",className:"cedros-admin__input",value:a.from_email,onChange:s=>r("from_email",s.target.value),placeholder:"noreply@example.com",disabled:!a.email_enabled}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.75rem",opacity:.6},children:"Default sender email address."})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"From Name"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.from_name,onChange:s=>r("from_name",s.target.value),placeholder:"Your Store",disabled:!a.email_enabled}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.75rem",opacity:.6},children:"Default sender display name."})]})]})]}),m==="webhooks"&&e.jsxs("div",{className:"cedros-admin__section",children:[e.jsx("p",{style:{marginBottom:"1.5rem",fontSize:"0.875rem",opacity:.7},children:"Configure webhook endpoint for receiving purchase notifications."}),!a.webhook_enabled&&e.jsx("div",{style:{padding:"1rem",marginBottom:"1.5rem",background:"var(--cedros-admin-bg-accent, #fef3c7)",borderRadius:"0.5rem",border:"1px solid var(--cedros-admin-warning, #f59e0b)",fontSize:"0.875rem"},children:"Webhook notifications are disabled. Enable them in the Messages tab."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",opacity:a.webhook_enabled?1:.5},children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Webhook URL"}),e.jsx("input",{type:"url",className:"cedros-admin__input",value:a.webhook_url,onChange:s=>r("webhook_url",s.target.value),placeholder:"https://api.yoursite.com/webhooks/orders",disabled:!a.webhook_enabled})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Webhook Secret"}),e.jsx("input",{type:"password",className:"cedros-admin__input",value:_.has("webhook_secret")?a.webhook_secret:"",onChange:s=>r("webhook_secret",s.target.value),placeholder:a.webhook_secret?"••••••••":"Enter secret for HMAC-SHA256",disabled:!a.webhook_enabled}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.75rem",opacity:.6},children:"Used for HMAC-SHA256 signature verification"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Timeout (seconds)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:a.webhook_timeout,onChange:s=>r("webhook_timeout",parseInt(s.target.value)||30),placeholder:"30",disabled:!a.webhook_enabled,style:{maxWidth:120}})]})]})]})]})]})}exports.MessagingSection=W;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("react"),y=require("./index-C7MWL6O8.js"),S=require("./Toggle-CsPSF8Dr.js"),q=require("./useAutosave-B2p6iwh8.js"),z=require("./AutosaveIndicator-D2l7U8R1.js"),p={mailgun:{label:"Mailgun",host:"smtp.mailgun.org",username:"",credentialLabel:"SMTP Password",showUsername:!0,usernameEqualsPassword:!1},sendgrid:{label:"SendGrid",host:"smtp.sendgrid.net",username:"apikey",credentialLabel:"API Key",showUsername:!1,usernameEqualsPassword:!1},postmark:{label:"Postmark",host:"smtp.postmarkapp.com",username:"",credentialLabel:"Server API Token",showUsername:!1,usernameEqualsPassword:!0},ses:{label:"AWS SES",host:"email-smtp.us-east-1.amazonaws.com",username:"",credentialLabel:"SMTP Password",showUsername:!0,usernameEqualsPassword:!1},resend:{label:"Resend",host:"smtp.resend.com",username:"resend",credentialLabel:"API Key",showUsername:!1,usernameEqualsPassword:!1},custom:{label:"Custom SMTP",host:"",username:"",credentialLabel:"SMTP Password",showUsername:!0,usernameEqualsPassword:!1}};function R(c){if(!c)return"custom";for(const[d,n]of Object.entries(p))if(n.host&&c===n.host)return d;return"custom"}const v={email_enabled:!1,email_provider:"custom",smtp_host:"",smtp_port:587,smtp_username:"",smtp_password:"",from_email:"",from_name:"",webhook_enabled:!1,webhook_url:"",webhook_secret:"",webhook_timeout:30};function W({serverUrl:c,apiKey:d,authManager:n}){const[m,b]=l.useState("messages"),[a,h]=l.useState(v),[N,k]=l.useState(!0),[C,E]=l.useState(!0),[P,f]=l.useState(null),[_,j]=l.useState(new Set),g=l.useCallback(async()=>{try{f(null);let s;const t="/admin/config/messaging";if(n?.isAuthenticated())s=await n.fetchWithAuth(t);else{const o={"Content-Type":"application/json"};d&&(o["X-API-Key"]=d);const u=await fetch(`${c}${t}`,{headers:o});if(!u.ok)throw new Error(`Failed to fetch: ${u.status}`);s=await u.json()}const i={...v,...s.config};i.email_provider||(i.email_provider=R(i.smtp_host)),h(i)}catch{h(v),f("Could not load saved settings. Showing defaults.")}finally{k(!1),setTimeout(()=>E(!1),100)}},[c,d,n]);l.useEffect(()=>{g()},[g]);const T=l.useCallback(async s=>{const t="/admin/config/messaging",i={...s};_.has("smtp_password")||delete i.smtp_password,_.has("webhook_secret")||delete i.webhook_secret;const o=JSON.stringify({config:i});try{if(n?.isAuthenticated())await n.fetchWithAuth(t,{method:"PUT",body:o});else{const u={"Content-Type":"application/json"};d&&(u["X-API-Key"]=d);const w=await fetch(`${c}${t}`,{method:"PUT",headers:u,body:o});if(!w.ok)throw new Error(`Failed to save: ${w.status}`)}}catch{throw f("Failed to save messaging settings"),new Error("Save failed")}},[c,d,n,_]),{status:A,error:I}=q.useAutosave({data:a,onSave:T,debounceMs:1500,enabled:!C}),r=(s,t)=>{(s==="smtp_password"||s==="webhook_secret")&&j(i=>new Set(i).add(s)),h(i=>({...i,[s]:t}))},L=s=>{const t=p[s];h(i=>({...i,email_provider:s,smtp_host:t.host||i.smtp_host,smtp_port:587,smtp_username:t.username||(t.showUsername?i.smtp_username:"")}))},M=s=>{const t=a.email_provider||"custom",i=p[t];j(o=>new Set(o).add("smtp_password")),i.usernameEqualsPassword?h(o=>({...o,smtp_password:s,smtp_username:s})):h(o=>({...o,smtp_password:s}))},x=p[a.email_provider||"custom"]??p.custom;return N?e.jsxs("div",{className:"cedros-admin__messaging-settings",children:[e.jsxs("div",{className:"cedros-admin__page-header",children:[e.jsx("h2",{className:"cedros-admin__page-title",children:"Store Messages"}),e.jsx("p",{className:"cedros-admin__page-description",children:"Configure email delivery and webhook notifications."})]}),e.jsxs("div",{className:"cedros-admin__loading",style:{marginTop:"1rem"},children:[y.Icons.loading," Loading message settings..."]})]}):e.jsxs("div",{className:"cedros-admin__messaging-settings",children:[e.jsxs("div",{className:"cedros-admin__page-header",children:[e.jsx("h2",{className:"cedros-admin__page-title",children:"Store Messages"}),e.jsx("p",{className:"cedros-admin__page-description",children:"Configure email delivery and webhook notifications."})]}),e.jsxs("div",{className:"cedros-admin__tabs cedros-admin__tabs--line",children:[e.jsx("button",{type:"button",className:`cedros-admin__tab ${m==="messages"?"cedros-admin__tab--active":""}`,onClick:()=>b("messages"),children:"Messages"}),e.jsx("button",{type:"button",className:`cedros-admin__tab ${m==="email"?"cedros-admin__tab--active":""}`,onClick:()=>b("email"),children:"Email"}),e.jsx("button",{type:"button",className:`cedros-admin__tab ${m==="webhooks"?"cedros-admin__tab--active":""}`,onClick:()=>b("webhooks"),children:"Webhooks"}),e.jsx("div",{style:{flex:1}}),e.jsx(z.AutosaveIndicator,{status:A,error:I})]}),e.jsx(y.ErrorBanner,{message:P,onRetry:g}),e.jsxs("div",{className:"cedros-admin__tab-content",style:{marginTop:"1rem"},children:[m==="messages"&&e.jsxs("div",{className:"cedros-admin__section",children:[e.jsx("p",{style:{marginBottom:"1.5rem",fontSize:"0.875rem",opacity:.7},children:"Enable or disable notification types. Configure the delivery settings in the Email or Webhooks tab."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"1rem"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"1rem",padding:"1rem",border:"1px solid var(--cedros-admin-border, #e5e5e5)",borderRadius:"0.5rem"},children:[e.jsx(S.Toggle,{checked:a.email_enabled,onChange:s=>r("email_enabled",s)}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:"Email Confirmation"}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.8125rem",opacity:.6},children:"Send order confirmation emails to customers after successful purchase."}),e.jsx("p",{style:{margin:"0.5rem 0 0",fontSize:"0.75rem",opacity:.5},children:"Requires Email configuration"})]})]}),e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"1rem",padding:"1rem",border:"1px solid var(--cedros-admin-border, #e5e5e5)",borderRadius:"0.5rem"},children:[e.jsx(S.Toggle,{checked:a.webhook_enabled,onChange:s=>r("webhook_enabled",s)}),e.jsxs("div",{style:{flex:1},children:[e.jsx("div",{style:{fontWeight:500},children:"Admin Purchase Notification"}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.8125rem",opacity:.6},children:"Send webhook notifications to your server when a purchase is completed."}),e.jsx("p",{style:{margin:"0.5rem 0 0",fontSize:"0.75rem",opacity:.5},children:"Requires Webhook configuration"})]})]})]})]}),m==="email"&&e.jsxs("div",{className:"cedros-admin__section",children:[e.jsx("p",{style:{marginBottom:"1.5rem",fontSize:"0.875rem",opacity:.7},children:"Select your email service provider for automatic configuration."}),!a.email_enabled&&e.jsx("div",{style:{padding:"1rem",marginBottom:"1.5rem",background:"var(--cedros-admin-bg-accent, #fef3c7)",borderRadius:"0.5rem",border:"1px solid var(--cedros-admin-warning, #f59e0b)",fontSize:"0.875rem"},children:"Email notifications are disabled. Enable them in the Messages tab."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",opacity:a.email_enabled?1:.5},children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Email Provider"}),e.jsx("select",{className:"cedros-admin__input",value:a.email_provider||"custom",onChange:s=>L(s.target.value),disabled:!a.email_enabled,children:Object.entries(p).map(([s,{label:t}])=>e.jsx("option",{value:s,children:t},s))})]}),a.email_provider==="custom"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"SMTP Host"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.smtp_host,onChange:s=>r("smtp_host",s.target.value),placeholder:"smtp.example.com",disabled:!a.email_enabled})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"SMTP Port"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:a.smtp_port,onChange:s=>r("smtp_port",parseInt(s.target.value)||587),placeholder:"587",disabled:!a.email_enabled,style:{maxWidth:120}}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.75rem",opacity:.6},children:"Common: 587 (TLS), 465 (SSL), 25 (unencrypted)."})]})]}),x.showUsername&&e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"SMTP Username"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.smtp_username,onChange:s=>r("smtp_username",s.target.value),placeholder:a.email_provider==="mailgun"?"postmaster@your-domain.com":"username",disabled:!a.email_enabled})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:x.credentialLabel}),e.jsx("input",{type:"password",className:"cedros-admin__input",value:_.has("smtp_password")?a.smtp_password:"",onChange:s=>M(s.target.value),placeholder:a.smtp_password?"••••••••":`Enter ${x.credentialLabel.toLowerCase()}`,disabled:!a.email_enabled})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"From Email"}),e.jsx("input",{type:"email",className:"cedros-admin__input",value:a.from_email,onChange:s=>r("from_email",s.target.value),placeholder:"noreply@example.com",disabled:!a.email_enabled}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.75rem",opacity:.6},children:"Default sender email address."})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"From Name"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.from_name,onChange:s=>r("from_name",s.target.value),placeholder:"Your Store",disabled:!a.email_enabled}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.75rem",opacity:.6},children:"Default sender display name."})]})]})]}),m==="webhooks"&&e.jsxs("div",{className:"cedros-admin__section",children:[e.jsx("p",{style:{marginBottom:"1.5rem",fontSize:"0.875rem",opacity:.7},children:"Configure webhook endpoint for receiving purchase notifications."}),!a.webhook_enabled&&e.jsx("div",{style:{padding:"1rem",marginBottom:"1.5rem",background:"var(--cedros-admin-bg-accent, #fef3c7)",borderRadius:"0.5rem",border:"1px solid var(--cedros-admin-warning, #f59e0b)",fontSize:"0.875rem"},children:"Webhook notifications are disabled. Enable them in the Messages tab."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"1rem",opacity:a.webhook_enabled?1:.5},children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Webhook URL"}),e.jsx("input",{type:"url",className:"cedros-admin__input",value:a.webhook_url,onChange:s=>r("webhook_url",s.target.value),placeholder:"https://api.yoursite.com/webhooks/orders",disabled:!a.webhook_enabled})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Webhook Secret"}),e.jsx("input",{type:"password",className:"cedros-admin__input",value:_.has("webhook_secret")?a.webhook_secret:"",onChange:s=>r("webhook_secret",s.target.value),placeholder:a.webhook_secret?"••••••••":"Enter secret for HMAC-SHA256",disabled:!a.webhook_enabled}),e.jsx("p",{style:{margin:"0.25rem 0 0",fontSize:"0.75rem",opacity:.6},children:"Used for HMAC-SHA256 signature verification"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Timeout (seconds)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:a.webhook_timeout,onChange:s=>r("webhook_timeout",parseInt(s.target.value)||30),placeholder:"30",disabled:!a.webhook_enabled,style:{maxWidth:120}})]})]})]})]})]})}exports.MessagingSection=W;
@@ -1,9 +1,9 @@
1
1
  import { jsxs as i, jsx as e, Fragment as R } from "react/jsx-runtime";
2
2
  import { useState as _, useCallback as k, useEffect as U } from "react";
3
- import { I as $, E as q } from "./index-BHF82XBB.mjs";
3
+ import { I as $, E as q } from "./index-BkDimQDF.mjs";
4
4
  import { T as C } from "./Toggle-DAxIdpY4.mjs";
5
5
  import { u as F } from "./useAutosave-YwMqRzqy.mjs";
6
- import { A as j } from "./AutosaveIndicator-BJsg_kFZ.mjs";
6
+ import { A as j } from "./AutosaveIndicator-BHfkV59p.mjs";
7
7
  const u = {
8
8
  mailgun: { label: "Mailgun", host: "smtp.mailgun.org", username: "", credentialLabel: "SMTP Password", showUsername: !0, usernameEqualsPassword: !1 },
9
9
  sendgrid: { label: "SendGrid", host: "smtp.sendgrid.net", username: "apikey", credentialLabel: "API Key", showUsername: !1, usernameEqualsPassword: !1 },
@@ -1,8 +1,8 @@
1
1
  import { jsxs as i, jsx as e, Fragment as $ } from "react/jsx-runtime";
2
2
  import { useState as r, useCallback as N, useEffect as U } from "react";
3
- import { I as z, E as G, h as F, s as k } from "./index-BHF82XBB.mjs";
3
+ import { I as z, E as G, k as F, s as L } from "./index-BkDimQDF.mjs";
4
4
  function J({ serverUrl: a, apiKey: s, pageSize: m = 20, authManager: l }) {
5
- const [c, t] = r([]), [o, y] = r(0), [R, x] = r(!0), [S, C] = r(null), [h, w] = r(null), [D, v] = r(null), [E, b] = r([]), [O, L] = r(!1), [f, T] = r(""), g = N(async (n, d) => {
5
+ const [c, t] = r([]), [o, y] = r(0), [R, x] = r(!0), [S, C] = r(null), [h, k] = r(null), [D, v] = r(null), [E, b] = r([]), [O, w] = r(!1), [f, T] = r(""), g = N(async (n, d) => {
6
6
  if (l?.isAuthenticated())
7
7
  return l.fetchWithAuth(n, d);
8
8
  const _ = { "Content-Type": "application/json" };
@@ -33,7 +33,7 @@ function J({ serverUrl: a, apiKey: s, pageSize: m = 20, authManager: l }) {
33
33
  p();
34
34
  }, [p]);
35
35
  const A = N(async (n) => {
36
- L(!0);
36
+ w(!0);
37
37
  try {
38
38
  const [d, _] = await Promise.all([
39
39
  g(`/admin/orders/${encodeURIComponent(n)}`),
@@ -43,10 +43,10 @@ function J({ serverUrl: a, apiKey: s, pageSize: m = 20, authManager: l }) {
43
43
  } catch {
44
44
  v(null), b([]);
45
45
  } finally {
46
- L(!1);
46
+ w(!1);
47
47
  }
48
48
  }, [g]), j = (n) => {
49
- h === n ? (w(null), v(null), b([])) : (w(n), A(n));
49
+ h === n ? (k(null), v(null), b([])) : (k(n), A(n));
50
50
  }, B = (n, d) => d === "USD" || d === "usd" ? `$${(n / 100).toFixed(2)}` : `${n} ${d}`;
51
51
  return /* @__PURE__ */ i("div", { className: "cedros-admin__section", children: [
52
52
  /* @__PURE__ */ i("div", { className: "cedros-admin__section-header", children: [
@@ -193,7 +193,7 @@ function W({
193
193
  a.fulfillments.map((t) => /* @__PURE__ */ i("div", { style: { fontSize: "0.8125rem", marginBottom: "0.25rem" }, children: [
194
194
  /* @__PURE__ */ e("span", { className: `cedros-admin__badge cedros-admin__badge--${I(t.status)}`, children: t.status }),
195
195
  t.carrier ? /* @__PURE__ */ e("span", { style: { marginLeft: "0.5rem" }, children: t.carrier }) : null,
196
- t.trackingNumber ? k(t.trackingUrl) ? /* @__PURE__ */ e("a", { href: k(t.trackingUrl), target: "_blank", rel: "noreferrer", style: { marginLeft: "0.5rem" }, children: t.trackingNumber }) : /* @__PURE__ */ e("span", { style: { marginLeft: "0.5rem" }, children: t.trackingNumber }) : null
196
+ t.trackingNumber ? L(t.trackingUrl) ? /* @__PURE__ */ e("a", { href: L(t.trackingUrl), target: "_blank", rel: "noreferrer", style: { marginLeft: "0.5rem" }, children: t.trackingNumber }) : /* @__PURE__ */ e("span", { style: { marginLeft: "0.5rem" }, children: t.trackingNumber }) : null
197
197
  ] }, t.id))
198
198
  ] }) : null,
199
199
  a?.history && a.history.length > 0 ? /* @__PURE__ */ i("div", { children: [
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),u=require("./index-OaWkrl0G.js");function A({serverUrl:n,apiKey:d,pageSize:o=20,authManager:r}){const[l,s]=a.useState([]),[c,p]=a.useState(0),[w,v]=a.useState(!0),[b,S]=a.useState(null),[h,N]=a.useState(null),[L,_]=a.useState(null),[R,y]=a.useState([]),[$,C]=a.useState(!1),[j,F]=a.useState(""),x=a.useCallback(async(t,i)=>{if(r?.isAuthenticated())return r.fetchWithAuth(t,i);const f={"Content-Type":"application/json"};d&&(f["X-API-Key"]=d);const m=await fetch(`${n}${t}`,{...i,headers:{...f,...i?.headers}});if(!m.ok){const I=await m.text().catch(()=>`HTTP ${m.status}`);throw new Error(I)}return m.json()},[n,d,r]),g=a.useCallback(async()=>{v(!0);try{S(null);const t=new URLSearchParams({limit:String(o)});j&&t.set("status",j);const i=await x(`/admin/orders?${t}`);s(i.orders),p(i.total)}catch{S("Failed to load orders")}finally{v(!1)}},[x,o,j]);a.useEffect(()=>{g()},[g]);const O=a.useCallback(async t=>{C(!0);try{const[i,f]=await Promise.all([x(`/admin/orders/${encodeURIComponent(t)}`),x("/admin/gift-card-redemptions?limit=50").catch(()=>[])]);_(i),y(f.filter(m=>m.orderId===t))}catch{_(null),y([])}finally{C(!1)}},[x]),T=t=>{h===t?(N(null),_(null),y([])):(N(t),O(t))},D=(t,i)=>i==="USD"||i==="usd"?`$${(t/100).toFixed(2)}`:`${t} ${i}`;return e.jsxs("div",{className:"cedros-admin__section",children:[e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsx("h2",{className:"cedros-admin__section-title",children:"Orders"}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center"},children:[e.jsxs("select",{className:"cedros-admin__input",style:{width:"auto",minWidth:"120px"},value:j,onChange:t=>F(t.target.value),children:[e.jsx("option",{value:"",children:"All statuses"}),e.jsx("option",{value:"paid",children:"Paid"}),e.jsx("option",{value:"processing",children:"Processing"}),e.jsx("option",{value:"fulfilled",children:"Fulfilled"}),e.jsx("option",{value:"shipped",children:"Shipped"}),e.jsx("option",{value:"delivered",children:"Delivered"}),e.jsx("option",{value:"cancelled",children:"Cancelled"}),e.jsx("option",{value:"refunded",children:"Refunded"})]}),e.jsxs("button",{type:"button",className:"cedros-admin__button cedros-admin__button--secondary",onClick:g,children:[u.Icons.refresh," Refresh"]})]})]}),b?e.jsx(u.ErrorBanner,{message:b,onRetry:g}):null,w?e.jsx("div",{className:"cedros-admin__loading-text",children:"Loading orders..."}):l.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No orders found."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin__table-info",children:[c," order",c===1?"":"s"," total"]}),e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Order"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Source"}),e.jsx("th",{children:"Customer"}),e.jsx("th",{children:"Date"})]})}),e.jsx("tbody",{children:l.map(t=>e.jsx(E,{order:t,expanded:h===t.id,detail:h===t.id?L:null,redemptions:h===t.id?R:[],detailLoading:h===t.id&&$,onToggle:()=>T(t.id),formatAmount:D},t.id))})]})]})]})}function E({order:n,expanded:d,detail:o,redemptions:r,detailLoading:l,onToggle:s,formatAmount:c}){const p=n.metadata?.recipient_email||r.length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{onClick:s,style:{cursor:"pointer"},className:d?"cedros-admin__table-row--active":"",children:[e.jsxs("td",{children:[e.jsxs("span",{className:"cedros-admin__mono",children:[n.id.slice(0,12),"..."]}),p?e.jsx("span",{className:"cedros-admin__badge cedros-admin__badge--info",style:{marginLeft:"0.5rem"},children:"Gift Card"}):null]}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${k(n.status)}`,children:n.status})}),e.jsx("td",{children:c(n.amount,n.amountAsset)}),e.jsx("td",{children:n.source}),e.jsx("td",{children:n.customerEmail||n.customerName||"—"}),e.jsx("td",{children:u.formatDateTime(n.createdAt)})]}),d?e.jsx("tr",{children:e.jsx("td",{colSpan:6,style:{padding:0},children:e.jsx(P,{detail:o,redemptions:r,loading:l,formatAmount:c,metadata:n.metadata})})}):null]})}function P({detail:n,redemptions:d,loading:o,formatAmount:r,metadata:l}){return o?e.jsx("div",{style:{padding:"1rem"},className:"cedros-admin__loading-text",children:"Loading details..."}):e.jsxs("div",{style:{padding:"1rem",background:"var(--cedros-admin-bg-muted, #f9fafb)"},children:[Object.keys(l).length>0?e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("div",{className:"cedros-admin__label",children:"Order Metadata"}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"auto 1fr",gap:"0.25rem 1rem",fontSize:"0.8125rem"},children:Object.entries(l).map(([s,c])=>e.jsxs("div",{style:{display:"contents"},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--cedros-admin-text-muted)"},children:s}),e.jsx("span",{children:c})]},s))})]}):null,d.length>0?e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("div",{className:"cedros-admin__label",children:"Gift Card Fulfillment"}),d.map(s=>e.jsxs("div",{style:{fontSize:"0.8125rem",padding:"0.5rem",border:"1px solid var(--cedros-admin-border)",borderRadius:"0.5rem",marginBottom:"0.5rem"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("span",{children:["Face value: ",r(s.faceValueCents,s.currency)]}),e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${s.creditsIssued>0?"success":"warning"}`,children:s.creditsIssued>0?"Credits issued":"Pending"})]}),e.jsxs("div",{style:{marginTop:"0.25rem",color:"var(--cedros-admin-text-muted)"},children:["Recipient: ",s.recipientUserId||"—",s.tokenMinted?e.jsx("span",{className:"cedros-admin__badge cedros-admin__badge--info",style:{marginLeft:"0.5rem"},children:"Token minted"}):null]})]},s.id))]}):null,n?.fulfillments&&n.fulfillments.length>0?e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("div",{className:"cedros-admin__label",children:"Fulfillments"}),n.fulfillments.map(s=>e.jsxs("div",{style:{fontSize:"0.8125rem",marginBottom:"0.25rem"},children:[e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${k(s.status)}`,children:s.status}),s.carrier?e.jsx("span",{style:{marginLeft:"0.5rem"},children:s.carrier}):null,s.trackingNumber?u.safeHref(s.trackingUrl)?e.jsx("a",{href:u.safeHref(s.trackingUrl),target:"_blank",rel:"noreferrer",style:{marginLeft:"0.5rem"},children:s.trackingNumber}):e.jsx("span",{style:{marginLeft:"0.5rem"},children:s.trackingNumber}):null]},s.id))]}):null,n?.history&&n.history.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"cedros-admin__label",children:"Status History"}),n.history.map(s=>e.jsxs("div",{style:{fontSize:"0.8125rem",marginBottom:"0.25rem"},children:[e.jsx("span",{style:{color:"var(--cedros-admin-text-muted)"},children:u.formatDateTime(s.createdAt)})," ",s.fromStatus," → ",s.toStatus,s.note?e.jsx("span",{style:{marginLeft:"0.5rem",fontStyle:"italic"},children:s.note}):null]},s.id))]}):null]})}function k(n){switch(n){case"paid":case"fulfilled":case"delivered":case"success":return"success";case"processing":case"shipped":case"pending":return"warning";case"cancelled":case"refunded":case"failed":return"error";default:return"default"}}exports.OrdersSection=A;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),u=require("./index-C7MWL6O8.js");function A({serverUrl:n,apiKey:d,pageSize:o=20,authManager:r}){const[l,s]=a.useState([]),[c,p]=a.useState(0),[w,v]=a.useState(!0),[b,S]=a.useState(null),[h,N]=a.useState(null),[L,_]=a.useState(null),[R,y]=a.useState([]),[$,C]=a.useState(!1),[j,F]=a.useState(""),x=a.useCallback(async(t,i)=>{if(r?.isAuthenticated())return r.fetchWithAuth(t,i);const f={"Content-Type":"application/json"};d&&(f["X-API-Key"]=d);const m=await fetch(`${n}${t}`,{...i,headers:{...f,...i?.headers}});if(!m.ok){const I=await m.text().catch(()=>`HTTP ${m.status}`);throw new Error(I)}return m.json()},[n,d,r]),g=a.useCallback(async()=>{v(!0);try{S(null);const t=new URLSearchParams({limit:String(o)});j&&t.set("status",j);const i=await x(`/admin/orders?${t}`);s(i.orders),p(i.total)}catch{S("Failed to load orders")}finally{v(!1)}},[x,o,j]);a.useEffect(()=>{g()},[g]);const O=a.useCallback(async t=>{C(!0);try{const[i,f]=await Promise.all([x(`/admin/orders/${encodeURIComponent(t)}`),x("/admin/gift-card-redemptions?limit=50").catch(()=>[])]);_(i),y(f.filter(m=>m.orderId===t))}catch{_(null),y([])}finally{C(!1)}},[x]),T=t=>{h===t?(N(null),_(null),y([])):(N(t),O(t))},D=(t,i)=>i==="USD"||i==="usd"?`$${(t/100).toFixed(2)}`:`${t} ${i}`;return e.jsxs("div",{className:"cedros-admin__section",children:[e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsx("h2",{className:"cedros-admin__section-title",children:"Orders"}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center"},children:[e.jsxs("select",{className:"cedros-admin__input",style:{width:"auto",minWidth:"120px"},value:j,onChange:t=>F(t.target.value),children:[e.jsx("option",{value:"",children:"All statuses"}),e.jsx("option",{value:"paid",children:"Paid"}),e.jsx("option",{value:"processing",children:"Processing"}),e.jsx("option",{value:"fulfilled",children:"Fulfilled"}),e.jsx("option",{value:"shipped",children:"Shipped"}),e.jsx("option",{value:"delivered",children:"Delivered"}),e.jsx("option",{value:"cancelled",children:"Cancelled"}),e.jsx("option",{value:"refunded",children:"Refunded"})]}),e.jsxs("button",{type:"button",className:"cedros-admin__button cedros-admin__button--secondary",onClick:g,children:[u.Icons.refresh," Refresh"]})]})]}),b?e.jsx(u.ErrorBanner,{message:b,onRetry:g}):null,w?e.jsx("div",{className:"cedros-admin__loading-text",children:"Loading orders..."}):l.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No orders found."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin__table-info",children:[c," order",c===1?"":"s"," total"]}),e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Order"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Amount"}),e.jsx("th",{children:"Source"}),e.jsx("th",{children:"Customer"}),e.jsx("th",{children:"Date"})]})}),e.jsx("tbody",{children:l.map(t=>e.jsx(E,{order:t,expanded:h===t.id,detail:h===t.id?L:null,redemptions:h===t.id?R:[],detailLoading:h===t.id&&$,onToggle:()=>T(t.id),formatAmount:D},t.id))})]})]})]})}function E({order:n,expanded:d,detail:o,redemptions:r,detailLoading:l,onToggle:s,formatAmount:c}){const p=n.metadata?.recipient_email||r.length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("tr",{onClick:s,style:{cursor:"pointer"},className:d?"cedros-admin__table-row--active":"",children:[e.jsxs("td",{children:[e.jsxs("span",{className:"cedros-admin__mono",children:[n.id.slice(0,12),"..."]}),p?e.jsx("span",{className:"cedros-admin__badge cedros-admin__badge--info",style:{marginLeft:"0.5rem"},children:"Gift Card"}):null]}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${k(n.status)}`,children:n.status})}),e.jsx("td",{children:c(n.amount,n.amountAsset)}),e.jsx("td",{children:n.source}),e.jsx("td",{children:n.customerEmail||n.customerName||"—"}),e.jsx("td",{children:u.formatDateTime(n.createdAt)})]}),d?e.jsx("tr",{children:e.jsx("td",{colSpan:6,style:{padding:0},children:e.jsx(P,{detail:o,redemptions:r,loading:l,formatAmount:c,metadata:n.metadata})})}):null]})}function P({detail:n,redemptions:d,loading:o,formatAmount:r,metadata:l}){return o?e.jsx("div",{style:{padding:"1rem"},className:"cedros-admin__loading-text",children:"Loading details..."}):e.jsxs("div",{style:{padding:"1rem",background:"var(--cedros-admin-bg-muted, #f9fafb)"},children:[Object.keys(l).length>0?e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("div",{className:"cedros-admin__label",children:"Order Metadata"}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"auto 1fr",gap:"0.25rem 1rem",fontSize:"0.8125rem"},children:Object.entries(l).map(([s,c])=>e.jsxs("div",{style:{display:"contents"},children:[e.jsx("span",{style:{fontWeight:500,color:"var(--cedros-admin-text-muted)"},children:s}),e.jsx("span",{children:c})]},s))})]}):null,d.length>0?e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("div",{className:"cedros-admin__label",children:"Gift Card Fulfillment"}),d.map(s=>e.jsxs("div",{style:{fontSize:"0.8125rem",padding:"0.5rem",border:"1px solid var(--cedros-admin-border)",borderRadius:"0.5rem",marginBottom:"0.5rem"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("span",{children:["Face value: ",r(s.faceValueCents,s.currency)]}),e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${s.creditsIssued>0?"success":"warning"}`,children:s.creditsIssued>0?"Credits issued":"Pending"})]}),e.jsxs("div",{style:{marginTop:"0.25rem",color:"var(--cedros-admin-text-muted)"},children:["Recipient: ",s.recipientUserId||"—",s.tokenMinted?e.jsx("span",{className:"cedros-admin__badge cedros-admin__badge--info",style:{marginLeft:"0.5rem"},children:"Token minted"}):null]})]},s.id))]}):null,n?.fulfillments&&n.fulfillments.length>0?e.jsxs("div",{style:{marginBottom:"1rem"},children:[e.jsx("div",{className:"cedros-admin__label",children:"Fulfillments"}),n.fulfillments.map(s=>e.jsxs("div",{style:{fontSize:"0.8125rem",marginBottom:"0.25rem"},children:[e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${k(s.status)}`,children:s.status}),s.carrier?e.jsx("span",{style:{marginLeft:"0.5rem"},children:s.carrier}):null,s.trackingNumber?u.safeHref(s.trackingUrl)?e.jsx("a",{href:u.safeHref(s.trackingUrl),target:"_blank",rel:"noreferrer",style:{marginLeft:"0.5rem"},children:s.trackingNumber}):e.jsx("span",{style:{marginLeft:"0.5rem"},children:s.trackingNumber}):null]},s.id))]}):null,n?.history&&n.history.length>0?e.jsxs("div",{children:[e.jsx("div",{className:"cedros-admin__label",children:"Status History"}),n.history.map(s=>e.jsxs("div",{style:{fontSize:"0.8125rem",marginBottom:"0.25rem"},children:[e.jsx("span",{style:{color:"var(--cedros-admin-text-muted)"},children:u.formatDateTime(s.createdAt)})," ",s.fromStatus," → ",s.toStatus,s.note?e.jsx("span",{style:{marginLeft:"0.5rem",fontStyle:"italic"},children:s.note}):null]},s.id))]}):null]})}function k(n){switch(n){case"paid":case"fulfilled":case"delivered":case"success":return"success";case"processing":case"shipped":case"pending":return"warning";case"cancelled":case"refunded":case"failed":return"error";default:return"default"}}exports.OrdersSection=A;
@@ -1,6 +1,6 @@
1
1
  import { jsxs as i, jsx as e, Fragment as s } from "react/jsx-runtime";
2
2
  import { useState as h } from "react";
3
- import { S as m } from "./SingleCategorySettings--LK0TZW0.mjs";
3
+ import { S as m } from "./SingleCategorySettings-BvHBVfSe.mjs";
4
4
  function r({ href: o, children: a }) {
5
5
  return /* @__PURE__ */ e(
6
6
  "a",
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("react"),p=require("./SingleCategorySettings-CRXTMTo5.js");function r({href:s,children:n}){return e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"underline"},children:n})}const a=[{id:"stripe",label:"Stripe",category:"stripe",description:e.jsxs(e.Fragment,{children:["Configure your Stripe integration for card payments. Get your API keys from the"," ",e.jsx(r,{href:"https://dashboard.stripe.com/apikeys",children:"Stripe Dashboard"}),"."]})},{id:"crypto",label:"Crypto",category:"x402",description:e.jsxs(e.Fragment,{children:["Configure Solana wallet and token settings for crypto payments. Get a fast RPC endpoint from"," ",e.jsx(r,{href:"https://www.helius.dev",children:"Helius"})," or"," ",e.jsx(r,{href:"https://www.quicknode.com/chains/sol",children:"QuickNode"}),". Set up a payment address using"," ",e.jsx(r,{href:"https://phantom.app",children:"Phantom"})," or"," ",e.jsx(r,{href:"https://solflare.com",children:"Solflare"})," wallet."]})},{id:"credits",label:"Credits",category:"cedros_login",description:e.jsxs(e.Fragment,{children:["Configure Cedros Login integration for credits payments. See the"," ",e.jsx(r,{href:"https://docs.cedros.dev/credits",children:"Credits API documentation"}),"."]})}];function h({serverUrl:s,apiKey:n,authManager:c}){const[o,d]=l.useState("stripe"),i=a.find(t=>t.id===o);return e.jsxs("div",{className:"cedros-admin__payment-settings",children:[e.jsxs("div",{className:"cedros-admin__page-header",children:[e.jsx("h2",{className:"cedros-admin__page-title",children:"Payment Options"}),e.jsx("p",{className:"cedros-admin__page-description",children:"Configure payment methods including Stripe, crypto, and credits."})]}),e.jsx("div",{className:"cedros-admin__tabs cedros-admin__tabs--line",children:a.map(t=>e.jsx("button",{type:"button",className:`cedros-admin__tab ${o===t.id?"cedros-admin__tab--active":""}`,onClick:()=>d(t.id),children:t.label},t.id))}),e.jsx("div",{style:{marginTop:"1rem"},children:e.jsx(p.SingleCategorySettings,{serverUrl:s,apiKey:n,authManager:c,category:i.category,title:`${i.label} Settings`,description:i.description,showEnabledToggle:!0},i.category)})]})}exports.PaymentSettingsSection=h;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("react"),p=require("./SingleCategorySettings-D2LVM5mn.js");function r({href:s,children:n}){return e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"underline"},children:n})}const a=[{id:"stripe",label:"Stripe",category:"stripe",description:e.jsxs(e.Fragment,{children:["Configure your Stripe integration for card payments. Get your API keys from the"," ",e.jsx(r,{href:"https://dashboard.stripe.com/apikeys",children:"Stripe Dashboard"}),"."]})},{id:"crypto",label:"Crypto",category:"x402",description:e.jsxs(e.Fragment,{children:["Configure Solana wallet and token settings for crypto payments. Get a fast RPC endpoint from"," ",e.jsx(r,{href:"https://www.helius.dev",children:"Helius"})," or"," ",e.jsx(r,{href:"https://www.quicknode.com/chains/sol",children:"QuickNode"}),". Set up a payment address using"," ",e.jsx(r,{href:"https://phantom.app",children:"Phantom"})," or"," ",e.jsx(r,{href:"https://solflare.com",children:"Solflare"})," wallet."]})},{id:"credits",label:"Credits",category:"cedros_login",description:e.jsxs(e.Fragment,{children:["Configure Cedros Login integration for credits payments. See the"," ",e.jsx(r,{href:"https://docs.cedros.dev/credits",children:"Credits API documentation"}),"."]})}];function h({serverUrl:s,apiKey:n,authManager:c}){const[o,d]=l.useState("stripe"),i=a.find(t=>t.id===o);return e.jsxs("div",{className:"cedros-admin__payment-settings",children:[e.jsxs("div",{className:"cedros-admin__page-header",children:[e.jsx("h2",{className:"cedros-admin__page-title",children:"Payment Options"}),e.jsx("p",{className:"cedros-admin__page-description",children:"Configure payment methods including Stripe, crypto, and credits."})]}),e.jsx("div",{className:"cedros-admin__tabs cedros-admin__tabs--line",children:a.map(t=>e.jsx("button",{type:"button",className:`cedros-admin__tab ${o===t.id?"cedros-admin__tab--active":""}`,onClick:()=>d(t.id),children:t.label},t.id))}),e.jsx("div",{style:{marginTop:"1rem"},children:e.jsx(p.SingleCategorySettings,{serverUrl:s,apiKey:n,authManager:c,category:i.category,title:`${i.label} Settings`,description:i.description,showEnabledToggle:!0},i.category)})]})}exports.PaymentSettingsSection=h;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),g=require("react"),d=require("./SingleCategorySettings-D2LVM5mn.js"),r=[{id:"logging",label:"Logging",category:"logging",description:"Configure log levels, format, and environment settings."},{id:"metrics",label:"Metrics",category:"metrics",description:"Configure metrics collection and API access for monitoring."},{id:"security",label:"Security",category:"security",description:"Configure CORS, rate limiting, and other security settings."},{id:"storage",label:"Storage",category:"storage",description:"Configure S3-compatible storage for product images."}];function l({serverUrl:n,apiKey:o,authManager:c}){const[s,a]=g.useState("logging"),t=r.find(i=>i.id===s);return e.jsxs("div",{className:"cedros-admin__server-settings",children:[e.jsxs("div",{className:"cedros-admin__page-header",children:[e.jsx("h2",{className:"cedros-admin__page-title",children:"Store Server"}),e.jsx("p",{className:"cedros-admin__page-description",children:"Configure logging, metrics, security, and storage settings."})]}),e.jsx("div",{className:"cedros-admin__tabs cedros-admin__tabs--line",children:r.map(i=>e.jsx("button",{type:"button",className:`cedros-admin__tab ${s===i.id?"cedros-admin__tab--active":""}`,onClick:()=>a(i.id),children:i.label},i.id))}),e.jsx("div",{style:{marginTop:"1rem"},children:e.jsx(d.SingleCategorySettings,{serverUrl:n,apiKey:o,authManager:c,category:t.category,title:`${t.label} Settings`,description:t.description},t.category)})]})}exports.SettingsSection=l;
@@ -1,7 +1,7 @@
1
- import { jsxs as n, jsx as i } from "react/jsx-runtime";
1
+ import { jsxs as s, jsx as i } from "react/jsx-runtime";
2
2
  import { useState as g } from "react";
3
- import { S as l } from "./SingleCategorySettings--LK0TZW0.mjs";
4
- const s = [
3
+ import { S as l } from "./SingleCategorySettings-BvHBVfSe.mjs";
4
+ const o = [
5
5
  {
6
6
  id: "logging",
7
7
  label: "Logging",
@@ -19,16 +19,22 @@ const s = [
19
19
  label: "Security",
20
20
  category: "security",
21
21
  description: "Configure CORS, rate limiting, and other security settings."
22
+ },
23
+ {
24
+ id: "storage",
25
+ label: "Storage",
26
+ category: "storage",
27
+ description: "Configure S3-compatible storage for product images."
22
28
  }
23
29
  ];
24
- function u({ serverUrl: c, apiKey: o, authManager: a }) {
25
- const [r, d] = g("logging"), t = s.find((e) => e.id === r);
26
- return /* @__PURE__ */ n("div", { className: "cedros-admin__server-settings", children: [
27
- /* @__PURE__ */ n("div", { className: "cedros-admin__page-header", children: [
30
+ function _({ serverUrl: n, apiKey: a, authManager: c }) {
31
+ const [r, d] = g("logging"), t = o.find((e) => e.id === r);
32
+ return /* @__PURE__ */ s("div", { className: "cedros-admin__server-settings", children: [
33
+ /* @__PURE__ */ s("div", { className: "cedros-admin__page-header", children: [
28
34
  /* @__PURE__ */ i("h2", { className: "cedros-admin__page-title", children: "Store Server" }),
29
- /* @__PURE__ */ i("p", { className: "cedros-admin__page-description", children: "Configure logging, metrics, and security settings." })
35
+ /* @__PURE__ */ i("p", { className: "cedros-admin__page-description", children: "Configure logging, metrics, security, and storage settings." })
30
36
  ] }),
31
- /* @__PURE__ */ i("div", { className: "cedros-admin__tabs cedros-admin__tabs--line", children: s.map((e) => /* @__PURE__ */ i(
37
+ /* @__PURE__ */ i("div", { className: "cedros-admin__tabs cedros-admin__tabs--line", children: o.map((e) => /* @__PURE__ */ i(
32
38
  "button",
33
39
  {
34
40
  type: "button",
@@ -41,9 +47,9 @@ function u({ serverUrl: c, apiKey: o, authManager: a }) {
41
47
  /* @__PURE__ */ i("div", { style: { marginTop: "1rem" }, children: /* @__PURE__ */ i(
42
48
  l,
43
49
  {
44
- serverUrl: c,
45
- apiKey: o,
46
- authManager: a,
50
+ serverUrl: n,
51
+ apiKey: a,
52
+ authManager: c,
47
53
  category: t.category,
48
54
  title: `${t.label} Settings`,
49
55
  description: t.description
@@ -53,5 +59,5 @@ function u({ serverUrl: c, apiKey: o, authManager: a }) {
53
59
  ] });
54
60
  }
55
61
  export {
56
- u as SettingsSection
62
+ _ as SettingsSection
57
63
  };
@@ -1,10 +1,10 @@
1
1
  import { jsxs as i, jsx as t, Fragment as W } from "react/jsx-runtime";
2
2
  import { useState as S, useEffect as j, useMemo as H, useCallback as z } from "react";
3
- import { I as E, F as Q, E as L, h as ee } from "./index-BHF82XBB.mjs";
4
- import { R as B, i as P, C as Z, a as te } from "./configApi-Ch0Rr7TD.mjs";
3
+ import { I as E, F as Q, E as L, k as ee } from "./index-BkDimQDF.mjs";
4
+ import { R as B, i as P, C as Z, a as te } from "./configApi-6XhAJGKX.mjs";
5
5
  import { u as re } from "./useAutosave-YwMqRzqy.mjs";
6
- import { A as ne } from "./AutosaveIndicator-BJsg_kFZ.mjs";
7
- import { S as F } from "./CedrosContext-DQUbL8yP.mjs";
6
+ import { A as ne } from "./AutosaveIndicator-BHfkV59p.mjs";
7
+ import { S as F } from "./CedrosContext-CY6zvjvJ.mjs";
8
8
  const ie = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
9
9
  function O(b) {
10
10
  return !b || b.trim() === "" ? { valid: !0 } : ie.test(b.trim()) ? { valid: !0 } : { valid: !1, error: "Invalid Solana address" };
@@ -1,3 +1,3 @@
1
- "use strict";const e=require("react/jsx-runtime"),l=require("react"),j=require("./index-OaWkrl0G.js"),N=require("./configApi-CxEbCAgG.js"),K=require("./useAutosave-B2p6iwh8.js"),L=require("./AutosaveIndicator-CY_YHM1D.js"),V=require("./CedrosContext-7dwmEeUY.js"),J=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function M(b){return!b||b.trim()===""?{valid:!0}:J.test(b.trim())?{valid:!0}:{valid:!1,error:"Invalid Solana address"}}function P({label:b,value:f,onChange:h,decimals:n,onDecimalsChange:S,disabled:o=!1,description:a,customSymbol:d="",customIcon:u="",onCustomSymbolChange:c,onCustomIconChange:x}){const[v,E]=l.useState(!1),p=Object.entries(V.STABLECOIN_METADATA),y=!!V.STABLECOIN_METADATA[f],C=v||!!f&&!y,w=t=>{if(t==="custom")E(!0),y&&h("");else{E(!1),h(t);const s=V.STABLECOIN_METADATA[t];s&&S&&S(s.decimals),c&&c(""),x&&x("")}};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:[p.map(([t,s])=>e.jsxs("button",{type:"button",onClick:()=>w(t),disabled:o,style:{display:"flex",alignItems:"center",gap:"0.5rem",padding:"0.5rem 0.75rem",border:f===t?"2px solid var(--cedros-admin-primary, #171717)":"1px solid var(--cedros-admin-border, #d4d4d4)",borderRadius:"0.5rem",background:f===t?"var(--cedros-admin-primary-bg, #f5f5f5)":"var(--cedros-admin-bg, #fff)",cursor:o?"not-allowed":"pointer",opacity:o?.5:1,fontWeight:f===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:()=>w("custom"),disabled:o,style:{display:"flex",alignItems:"center",gap:"0.5rem",padding:"0.5rem 0.75rem",border:C?"2px solid var(--cedros-admin-primary, #171717)":"1px solid var(--cedros-admin-border, #d4d4d4)",borderRadius:"0.5rem",background:C?"var(--cedros-admin-primary-bg, #f5f5f5)":"var(--cedros-admin-bg, #fff)",cursor:o?"not-allowed":"pointer",opacity:o?.5:1,fontWeight:C?600:400},children:[e.jsx("span",{style:{fontSize:"1rem"},children:"+"}),e.jsx("span",{children:"Custom"})]})]}),C&&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=M(f);return e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",className:`cedros-admin__input ${t.valid?"":"cedros-admin__input--error"}`,value:f,onChange:s=>h(s.target.value),placeholder:"e.g., EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",disabled:o,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:d,onChange:t=>c?.(t.target.value),placeholder:"e.g., MYTOKEN",disabled:o,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:u,onChange:t=>x?.(t.target.value),placeholder:"https://example.com/token-logo.png",disabled:o,style:{flex:1}}),u&&e.jsx("img",{src:u,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:n??6,onChange:t=>S?.(parseInt(t.target.value,10)||0),min:0,max:18,disabled:o,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)"})]})]}),f&&y&&e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--cedros-admin-text-muted, #64748b)",fontFamily:"monospace",wordBreak:"break-all"},children:f}),a&&e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--cedros-admin-text-muted, #64748b)",marginTop:"0.25rem"},children:a})]})]})}function Z({label:b,value:f,onChange:h,disabled:n=!1,description:S}){const[o,a]=l.useState(new Set),[d,u]=l.useState(null),[c,x]=l.useState(""),v=Array.isArray(f)?f:[],E=t=>{a(s=>{const r=new Set(s);return r.has(t)?r.delete(t):r.add(t),r})},p=()=>{h([...v,""]),u(v.length),x("")},I=(t,s)=>{const r=[...v];r[t]=s,h(r)},y=t=>{const s=v.filter((r,g)=>g!==t);h(s),a(r=>{const g=new Set;return r.forEach(_=>{_<t?g.add(_):_>t&&g.add(_-1)}),g})},T=t=>{u(t),x(v[t]||"")},C=()=>{d!==null&&(I(d,c),u(null),x(""))},w=()=>{d!==null&&v[d]===""&&y(d),u(null),x("")};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:p,disabled:n,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:n?"not-allowed":"pointer",opacity:n?.5:1},children:[j.Icons.plus,"Add"]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[v.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.'}),v.map((t,s)=>{const r=o.has(s),g=d===s,_=t===N.REDACTED_VALUE;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:c,onChange:i=>x(i.target.value),placeholder:"Enter wallet keypair...",autoFocus:!0,style:{flex:1,fontFamily:"monospace",fontSize:"0.75rem"},onKeyDown:i=>{i.key==="Enter"&&C(),i.key==="Escape"&&w()}}),e.jsx("button",{type:"button",onClick:C,style:{padding:"0.375rem",border:"none",background:"var(--cedros-admin-success, #22c55e)",color:"#fff",borderRadius:"0.25rem",cursor:"pointer"},title:"Save",children:j.Icons.check}),e.jsx("button",{type:"button",onClick:w,style:{padding:"0.375rem",border:"none",background:"var(--cedros-admin-text-muted, #64748b)",color:"#fff",borderRadius:"0.25rem",cursor:"pointer"},title:"Cancel",children:j.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&&!_?t:_?"[REDACTED]":"••••••••••••••••••••"}),e.jsx("button",{type:"button",onClick:()=>E(s),disabled:n||_,style:{padding:"0.375rem",border:"none",background:"transparent",cursor:n||_?"not-allowed":"pointer",opacity:n||_?.5:1,color:"var(--cedros-admin-text-muted, #64748b)"},title:r?"Hide":"Show",children:r?j.Icons.eyeOff:j.Icons.eye}),e.jsx("button",{type:"button",onClick:()=>T(s),disabled:n,style:{padding:"0.375rem",border:"none",background:"transparent",cursor:n?"not-allowed":"pointer",opacity:n?.5:1,color:"var(--cedros-admin-text-muted, #64748b)"},title:"Edit",children:j.Icons.settings}),e.jsx("button",{type:"button",onClick:()=>y(s),disabled:n,style:{padding:"0.375rem",border:"none",background:"transparent",cursor:n?"not-allowed":"pointer",opacity:n?.5:1,color:"var(--cedros-admin-error, #ef4444)"},title:"Delete",children:j.Icons.trash})]})},s)})]}),S&&e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--cedros-admin-text-muted, #64748b)",marginTop:"0.5rem"},children:S})]})}function q(b,f,h){const n=N.isSecretField(b,f),S=f.replace(/_/g," ").replace(/\b\w/g,u=>u.toUpperCase()),a=N.CONFIG_CATEGORIES[b]?.fields?.[f],d={isSecret:n,label:S,description:a?.description,hidden:a?.hidden,showWhen:a?.showWhen};return a?.type==="dropdown"&&a.options?{...d,type:"dropdown",options:a.options}:a?.type==="token_mint"?{...d,type:"token_mint"}:a?.type==="toggle"?{...d,type:"toggle"}:a?.type==="secret_array"?{...d,type:"secret_array",isSecret:!0}:a?.type==="solana_address"?{...d,type:"solana_address"}:a?.type==="number"?{...d,type:"number",unit:a.unit}:typeof h=="boolean"?{...d,type:"boolean"}:typeof h=="number"?{...d,type:"number",unit:a?.unit}:Array.isArray(h)?{...d,type:"array"}:typeof h=="object"&&h!==null?{...d,type:"object"}:{...d,type:"string"}}function X({category:b,config:f,originalConfig:h,isLoading:n=!1,onSave:S}){const[o,a]=l.useState(f),[d,u]=l.useState(new Set);l.useEffect(()=>{a(f)},[f]);const c=l.useMemo(()=>{const t={...o};for(const s of Object.keys(t))if(N.isSecretField(b,s)){const r=h[s],g=t[s];(g===N.REDACTED_VALUE||g===r)&&(t[s]=N.REDACTED_VALUE)}return t},[o,h,b]),x=l.useMemo(()=>{const t=o.token_mint;return typeof t!="string"||!t?!1:!M(t).valid},[o]),{status:v,error:E}=K.useAutosave({data:c,onSave:S,debounceMs:1500,enabled:!x}),p=l.useCallback((t,s)=>{a(r=>({...r,[t]:s}))},[]),I=l.useCallback(t=>{u(s=>{const r=new Set(s);return r.has(t)?r.delete(t):r.add(t),r})},[]),y=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=q(b,t,h[t]??s);if(r.type==="dropdown"&&r.options)return e.jsx(j.FormDropdown,{value:s,onChange:i=>p(t,i),options:r.options.map(i=>({value:i,label:i})),label:r.label,description:r.description,disabled:n});if(r.type==="token_mint")return e.jsx(P,{label:r.label,value:s,onChange:i=>p(t,i),decimals:o.token_decimals??6,onDecimalsChange:i=>p("token_decimals",i),disabled:n,description:r.description,customSymbol:o.custom_token_symbol||"",customIcon:o.custom_token_icon||"",onCustomSymbolChange:i=>p("custom_token_symbol",i),onCustomIconChange:i=>p("custom_token_icon",i)});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:()=>p(t,!s),disabled:n,style:{width:44,height:24,borderRadius:12,border:"none",backgroundColor:s?"var(--cedros-admin-primary, #171717)":"var(--cedros-admin-border, #d4d4d4)",cursor:n?"not-allowed":"pointer",position:"relative",transition:"background-color 0.2s",opacity:n?.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})]}),y(r.description)]});if(r.type==="solana_address"){const i=s||"",k=M(i);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 ${k.valid?"":"cedros-admin__input--error"}`,value:i,onChange:D=>p(t,D.target.value),disabled:n,placeholder:"e.g. 7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",style:{width:"100%",fontFamily:"monospace",fontSize:"0.875rem",borderColor:k.valid?void 0:"var(--cedros-admin-error, #dc2626)",paddingRight:i&&k.valid?"2rem":void 0}}),i&&k.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:"✓"})]}),!k.valid&&e.jsx("span",{style:{color:"var(--cedros-admin-error, #dc2626)",fontSize:"0.75rem",marginTop:"0.25rem",display:"block"},children:k.error}),y(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:i=>p(t,i.target.checked),disabled:n}),r.label]}),y(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:i=>p(t,parseFloat(i.target.value)||0),disabled:n}),y(r.description)]});if(r.type==="secret_array")return e.jsx(Z,{label:r.label,value:s,onChange:i=>p(t,i),disabled:n,description:r.description});if(r.type==="array"){const i=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:i.join(`
1
+ "use strict";const e=require("react/jsx-runtime"),l=require("react"),j=require("./index-C7MWL6O8.js"),N=require("./configApi-DkduMQg1.js"),K=require("./useAutosave-B2p6iwh8.js"),L=require("./AutosaveIndicator-D2l7U8R1.js"),V=require("./CedrosContext-C2RjHLaQ.js"),J=/^[1-9A-HJ-NP-Za-km-z]{32,44}$/;function M(b){return!b||b.trim()===""?{valid:!0}:J.test(b.trim())?{valid:!0}:{valid:!1,error:"Invalid Solana address"}}function P({label:b,value:f,onChange:h,decimals:n,onDecimalsChange:S,disabled:o=!1,description:a,customSymbol:d="",customIcon:u="",onCustomSymbolChange:c,onCustomIconChange:x}){const[v,E]=l.useState(!1),p=Object.entries(V.STABLECOIN_METADATA),y=!!V.STABLECOIN_METADATA[f],C=v||!!f&&!y,w=t=>{if(t==="custom")E(!0),y&&h("");else{E(!1),h(t);const s=V.STABLECOIN_METADATA[t];s&&S&&S(s.decimals),c&&c(""),x&&x("")}};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:[p.map(([t,s])=>e.jsxs("button",{type:"button",onClick:()=>w(t),disabled:o,style:{display:"flex",alignItems:"center",gap:"0.5rem",padding:"0.5rem 0.75rem",border:f===t?"2px solid var(--cedros-admin-primary, #171717)":"1px solid var(--cedros-admin-border, #d4d4d4)",borderRadius:"0.5rem",background:f===t?"var(--cedros-admin-primary-bg, #f5f5f5)":"var(--cedros-admin-bg, #fff)",cursor:o?"not-allowed":"pointer",opacity:o?.5:1,fontWeight:f===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:()=>w("custom"),disabled:o,style:{display:"flex",alignItems:"center",gap:"0.5rem",padding:"0.5rem 0.75rem",border:C?"2px solid var(--cedros-admin-primary, #171717)":"1px solid var(--cedros-admin-border, #d4d4d4)",borderRadius:"0.5rem",background:C?"var(--cedros-admin-primary-bg, #f5f5f5)":"var(--cedros-admin-bg, #fff)",cursor:o?"not-allowed":"pointer",opacity:o?.5:1,fontWeight:C?600:400},children:[e.jsx("span",{style:{fontSize:"1rem"},children:"+"}),e.jsx("span",{children:"Custom"})]})]}),C&&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=M(f);return e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",className:`cedros-admin__input ${t.valid?"":"cedros-admin__input--error"}`,value:f,onChange:s=>h(s.target.value),placeholder:"e.g., EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",disabled:o,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:d,onChange:t=>c?.(t.target.value),placeholder:"e.g., MYTOKEN",disabled:o,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:u,onChange:t=>x?.(t.target.value),placeholder:"https://example.com/token-logo.png",disabled:o,style:{flex:1}}),u&&e.jsx("img",{src:u,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:n??6,onChange:t=>S?.(parseInt(t.target.value,10)||0),min:0,max:18,disabled:o,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)"})]})]}),f&&y&&e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--cedros-admin-text-muted, #64748b)",fontFamily:"monospace",wordBreak:"break-all"},children:f}),a&&e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--cedros-admin-text-muted, #64748b)",marginTop:"0.25rem"},children:a})]})]})}function Z({label:b,value:f,onChange:h,disabled:n=!1,description:S}){const[o,a]=l.useState(new Set),[d,u]=l.useState(null),[c,x]=l.useState(""),v=Array.isArray(f)?f:[],E=t=>{a(s=>{const r=new Set(s);return r.has(t)?r.delete(t):r.add(t),r})},p=()=>{h([...v,""]),u(v.length),x("")},I=(t,s)=>{const r=[...v];r[t]=s,h(r)},y=t=>{const s=v.filter((r,g)=>g!==t);h(s),a(r=>{const g=new Set;return r.forEach(_=>{_<t?g.add(_):_>t&&g.add(_-1)}),g})},T=t=>{u(t),x(v[t]||"")},C=()=>{d!==null&&(I(d,c),u(null),x(""))},w=()=>{d!==null&&v[d]===""&&y(d),u(null),x("")};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:p,disabled:n,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:n?"not-allowed":"pointer",opacity:n?.5:1},children:[j.Icons.plus,"Add"]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[v.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.'}),v.map((t,s)=>{const r=o.has(s),g=d===s,_=t===N.REDACTED_VALUE;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:c,onChange:i=>x(i.target.value),placeholder:"Enter wallet keypair...",autoFocus:!0,style:{flex:1,fontFamily:"monospace",fontSize:"0.75rem"},onKeyDown:i=>{i.key==="Enter"&&C(),i.key==="Escape"&&w()}}),e.jsx("button",{type:"button",onClick:C,style:{padding:"0.375rem",border:"none",background:"var(--cedros-admin-success, #22c55e)",color:"#fff",borderRadius:"0.25rem",cursor:"pointer"},title:"Save",children:j.Icons.check}),e.jsx("button",{type:"button",onClick:w,style:{padding:"0.375rem",border:"none",background:"var(--cedros-admin-text-muted, #64748b)",color:"#fff",borderRadius:"0.25rem",cursor:"pointer"},title:"Cancel",children:j.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&&!_?t:_?"[REDACTED]":"••••••••••••••••••••"}),e.jsx("button",{type:"button",onClick:()=>E(s),disabled:n||_,style:{padding:"0.375rem",border:"none",background:"transparent",cursor:n||_?"not-allowed":"pointer",opacity:n||_?.5:1,color:"var(--cedros-admin-text-muted, #64748b)"},title:r?"Hide":"Show",children:r?j.Icons.eyeOff:j.Icons.eye}),e.jsx("button",{type:"button",onClick:()=>T(s),disabled:n,style:{padding:"0.375rem",border:"none",background:"transparent",cursor:n?"not-allowed":"pointer",opacity:n?.5:1,color:"var(--cedros-admin-text-muted, #64748b)"},title:"Edit",children:j.Icons.settings}),e.jsx("button",{type:"button",onClick:()=>y(s),disabled:n,style:{padding:"0.375rem",border:"none",background:"transparent",cursor:n?"not-allowed":"pointer",opacity:n?.5:1,color:"var(--cedros-admin-error, #ef4444)"},title:"Delete",children:j.Icons.trash})]})},s)})]}),S&&e.jsx("div",{style:{fontSize:"0.75rem",color:"var(--cedros-admin-text-muted, #64748b)",marginTop:"0.5rem"},children:S})]})}function q(b,f,h){const n=N.isSecretField(b,f),S=f.replace(/_/g," ").replace(/\b\w/g,u=>u.toUpperCase()),a=N.CONFIG_CATEGORIES[b]?.fields?.[f],d={isSecret:n,label:S,description:a?.description,hidden:a?.hidden,showWhen:a?.showWhen};return a?.type==="dropdown"&&a.options?{...d,type:"dropdown",options:a.options}:a?.type==="token_mint"?{...d,type:"token_mint"}:a?.type==="toggle"?{...d,type:"toggle"}:a?.type==="secret_array"?{...d,type:"secret_array",isSecret:!0}:a?.type==="solana_address"?{...d,type:"solana_address"}:a?.type==="number"?{...d,type:"number",unit:a.unit}:typeof h=="boolean"?{...d,type:"boolean"}:typeof h=="number"?{...d,type:"number",unit:a?.unit}:Array.isArray(h)?{...d,type:"array"}:typeof h=="object"&&h!==null?{...d,type:"object"}:{...d,type:"string"}}function X({category:b,config:f,originalConfig:h,isLoading:n=!1,onSave:S}){const[o,a]=l.useState(f),[d,u]=l.useState(new Set);l.useEffect(()=>{a(f)},[f]);const c=l.useMemo(()=>{const t={...o};for(const s of Object.keys(t))if(N.isSecretField(b,s)){const r=h[s],g=t[s];(g===N.REDACTED_VALUE||g===r)&&(t[s]=N.REDACTED_VALUE)}return t},[o,h,b]),x=l.useMemo(()=>{const t=o.token_mint;return typeof t!="string"||!t?!1:!M(t).valid},[o]),{status:v,error:E}=K.useAutosave({data:c,onSave:S,debounceMs:1500,enabled:!x}),p=l.useCallback((t,s)=>{a(r=>({...r,[t]:s}))},[]),I=l.useCallback(t=>{u(s=>{const r=new Set(s);return r.has(t)?r.delete(t):r.add(t),r})},[]),y=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=q(b,t,h[t]??s);if(r.type==="dropdown"&&r.options)return e.jsx(j.FormDropdown,{value:s,onChange:i=>p(t,i),options:r.options.map(i=>({value:i,label:i})),label:r.label,description:r.description,disabled:n});if(r.type==="token_mint")return e.jsx(P,{label:r.label,value:s,onChange:i=>p(t,i),decimals:o.token_decimals??6,onDecimalsChange:i=>p("token_decimals",i),disabled:n,description:r.description,customSymbol:o.custom_token_symbol||"",customIcon:o.custom_token_icon||"",onCustomSymbolChange:i=>p("custom_token_symbol",i),onCustomIconChange:i=>p("custom_token_icon",i)});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:()=>p(t,!s),disabled:n,style:{width:44,height:24,borderRadius:12,border:"none",backgroundColor:s?"var(--cedros-admin-primary, #171717)":"var(--cedros-admin-border, #d4d4d4)",cursor:n?"not-allowed":"pointer",position:"relative",transition:"background-color 0.2s",opacity:n?.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})]}),y(r.description)]});if(r.type==="solana_address"){const i=s||"",k=M(i);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 ${k.valid?"":"cedros-admin__input--error"}`,value:i,onChange:D=>p(t,D.target.value),disabled:n,placeholder:"e.g. 7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",style:{width:"100%",fontFamily:"monospace",fontSize:"0.875rem",borderColor:k.valid?void 0:"var(--cedros-admin-error, #dc2626)",paddingRight:i&&k.valid?"2rem":void 0}}),i&&k.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:"✓"})]}),!k.valid&&e.jsx("span",{style:{color:"var(--cedros-admin-error, #dc2626)",fontSize:"0.75rem",marginTop:"0.25rem",display:"block"},children:k.error}),y(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:i=>p(t,i.target.checked),disabled:n}),r.label]}),y(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:i=>p(t,parseFloat(i.target.value)||0),disabled:n}),y(r.description)]});if(r.type==="secret_array")return e.jsx(Z,{label:r.label,value:s,onChange:i=>p(t,i),disabled:n,description:r.description});if(r.type==="array"){const i=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:i.join(`
2
2
  `),onChange:k=>p(t,k.target.value.split(`
3
3
  `).filter(Boolean)),placeholder:"One item per line",rows:3,disabled:n}),y(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:i=>{try{p(t,JSON.parse(i.target.value))}catch{}},rows:5,disabled:n}),y(r.description)]});const g=d.has(t),_=r.isSecret&&!g&&s===N.REDACTED_VALUE?N.REDACTED_VALUE: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:_,onChange:i=>p(t,i.target.value),disabled:n,placeholder:r.isSecret?"••••••••":""}),r.isSecret&&e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>I(t),style:{padding:"0.5rem",minWidth:"auto"},title:g?"Hide":"Show",children:g?j.Icons.eyeOff:j.Icons.eye})]}),y(r.description)]})},C=Object.keys(o),w=t=>{const s=q(b,t,h[t]??o[t]);if(s.hidden||s.showWhen&&!o[s.showWhen])return!1;if(t==="token_decimals"){const r=o.token_mint;if(r&&V.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:C.filter(w).map(t=>e.jsx("div",{className:"cedros-admin__config-field",children:T(t,o[t])},t))}),e.jsx("div",{className:"cedros-admin__config-actions",children:e.jsx("div",{className:"cedros-admin__autosave-status",children:e.jsx(L.AutosaveIndicator,{status:v,error:E})})})]})}function Y({serverUrl:b,apiKey:f,authManager:h,category:n,title:S,description:o,enabledField:a="enabled",showEnabledToggle:d=!1}){const u=l.useMemo(()=>new N.ConfigApiClient(b,void 0,h),[b,h]),[c,x]=l.useState(null),[v,E]=l.useState([]),[p,I]=l.useState(!1),[y,T]=l.useState(!0),[C,w]=l.useState(null),[t,s]=l.useState(null),[r,g]=l.useState(!1),_=N.CONFIG_CATEGORIES[n]||{label:n,icon:"⚙️"},i=S||_.label,k=o||_.description,D=l.useCallback(async()=>{T(!0),w(null);try{const m=await u.getConfig(n,!0);x(m)}catch{x(null),w("Failed to load settings")}finally{T(!1)}},[u,n]);l.useEffect(()=>{D()},[D]);const B=l.useCallback(async()=>{try{const m=await u.getHistory(n,20);E(m.history)}catch{E([])}},[u,n]);l.useEffect(()=>{p&&B()},[p,B]);const U=l.useCallback(async m=>{await u.updateConfig(n,m,"Updated via admin dashboard")},[u,n]),F=l.useCallback(async m=>u.validateConfig(n,m),[u,n]),[z,O]=l.useState(!1),G=l.useCallback(async()=>{if(!c||z)return;const m=!!c.config[a],R=!m,W={...c.config,[a]:R};O(!0),x({...c,config:W});try{await u.updateConfig(n,W,`${R?"Enabled":"Disabled"} via admin dashboard`)}catch(H){x({...c,config:{...c.config,[a]:m}}),w(H instanceof Error?H.message:"Failed to save enabled state")}finally{O(!1)}},[c,u,n,a,z]),A=!!c?.config[a];return y&&!c?e.jsx("div",{className:"cedros-admin__section",children:e.jsxs("div",{className:"cedros-admin__loading",children:[j.Icons.loading," Loading ",i," settings..."]})}):e.jsxs("div",{className:"cedros-admin__section",children:[e.jsx(j.ErrorBanner,{message:C,onRetry:D}),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:_.icon}),i]}),k&&e.jsx("p",{className:"cedros-admin__text-muted",style:{marginTop:"0.25rem"},children:k})]}),d&&c&&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:G,disabled:z,style:{width:44,height:24,borderRadius:12,border:"none",backgroundColor:A?"var(--cedros-admin-primary, #171717)":"var(--cedros-admin-border, #d4d4d4)",cursor:z?"wait":"pointer",position:"relative",transition:"background-color 0.2s",flexShrink:0,opacity:z?.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)"}})})]})]}),c&&e.jsxs("div",{className:"cedros-admin__settings-editor",style:{marginTop:"1rem",opacity:d&&!A?.6:1,pointerEvents:d&&!A?"none":"auto"},children:[d&&!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(X,{category:c.category,config:c.config,originalConfig:c.config,onSave:U,onValidate:F})]}),p&&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"}),v.length===0?e.jsx("p",{className:"cedros-admin__text-muted",children:"No history entries found."}):e.jsx("div",{className:"cedros-admin__settings-timeline",children:v.map(m=>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:m.configKey}),e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${m.action.toLowerCase()}`,children:m.action})]}),e.jsxs("div",{className:"cedros-admin__settings-timeline-meta",children:[j.formatDateTime(m.changedAt)," by ",m.changedBy]})]})]},m.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((m,R)=>e.jsx("li",{children:m},R))}),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((m,R)=>e.jsx("li",{children:m},R))})]}),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:()=>I(!p),children:p?"Hide History":"History"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:r||!c,onClick:async()=>{if(c){g(!0),s(null);try{const m=await F(c.config);s(m)}catch(m){s({valid:!1,errors:[m instanceof Error?m.message:"Validation failed"],warnings:[]})}finally{g(!1)}}},children:r?"Validating...":"Validate"})]})]})}exports.SingleCategorySettings=Y;
@@ -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-BHF82XBB.mjs";
3
+ import { I as H, E as V, F as x } from "./index-BkDimQDF.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-BJsg_kFZ.mjs";
6
+ import { A as X } from "./AutosaveIndicator-BHfkV59p.mjs";
7
7
  const C = {
8
8
  enabled: !0,
9
9
  relatedProducts: {