@cedros/pay-react 1.1.29 → 1.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -0
- package/dist/{AISettingsSection-DtAgMsDw.mjs → AISettingsSection-BMh3hAb5.mjs} +4 -4
- package/dist/{AISettingsSection-B7qrycfY.js → AISettingsSection-C0zqPbd6.js} +1 -1
- package/dist/{AutosaveIndicator-BEvABoKU.mjs → AutosaveIndicator-3ctAnz8Y.mjs} +1 -1
- package/dist/AutosaveIndicator-DXRPr4P7.js +1 -0
- package/dist/{CedrosPayAdminDashboard-CBuvNAtB.mjs → CedrosPayAdminDashboard-DaJ9JoGn.mjs} +20 -20
- package/dist/CedrosPayAdminDashboard-Uvyh9p7A.js +1 -0
- package/dist/{ChatLogsSection-Ber5o8hF.mjs → ChatLogsSection-BtJixYAp.mjs} +2 -2
- package/dist/ChatLogsSection-FC3O536G.js +1 -0
- package/dist/{ComplianceSection-ZCr0wsvw.mjs → ComplianceSection-BMnb1p4w.mjs} +3 -3
- package/dist/ComplianceSection-BioTKm7k.js +1 -0
- package/dist/{CustomersSection-D9UknSKC.mjs → CustomersSection-dmwoBhcf.mjs} +2 -2
- package/dist/CustomersSection-z6ARxuex.js +1 -0
- package/dist/DisputesSection-BjHHQAi7.js +1 -0
- package/dist/{DisputesSection-C_eySK-W.mjs → DisputesSection-CHyLne76.mjs} +2 -2
- package/dist/{Dropdown-B90Zabxr.mjs → Dropdown-BRSZlhik.mjs} +1 -1
- package/dist/Dropdown-j8o0OO5L.js +1 -0
- package/dist/ErrorBanner-CAgPnj62.js +1 -0
- package/dist/{ErrorBanner-CZXsHi3H.mjs → ErrorBanner-lZJhCmDX.mjs} +1 -1
- package/dist/{FAQSection-Bv_Hdt8B.mjs → FAQSection-Di2xE9Sm.mjs} +3 -3
- package/dist/FAQSection-b34DMzgV.js +1 -0
- package/dist/{ImagesSection-DpdXQ6qu.mjs → ImagesSection-D63PEjR6.mjs} +2 -2
- package/dist/ImagesSection-DGBA7iKY.js +1 -0
- package/dist/{InventorySection-DZMu9DMw.mjs → InventorySection-Dp5Yu4TA.mjs} +2 -2
- package/dist/InventorySection-bVCECzX5.js +1 -0
- package/dist/LazyCedrosPayAdminDashboard-BqJDNrDI.mjs +9 -0
- package/dist/LazyCedrosPayAdminDashboard-CpfTtOBc.js +1 -0
- package/dist/{MessagingSection-D_cOBfFt.mjs → MessagingSection-BLCnCpEv.mjs} +3 -3
- package/dist/MessagingSection-DU0dYNMy.js +1 -0
- package/dist/{OrdersSection-wfPavit9.mjs → OrdersSection-Bd56F3cj.mjs} +2 -2
- package/dist/OrdersSection-FOFEAgs1.js +1 -0
- package/dist/{PaymentSettingsSection-DunzBo9n.mjs → PaymentSettingsSection-52iw47Su.mjs} +3 -3
- package/dist/{PaymentSettingsSection-BdBDgaRg.js → PaymentSettingsSection-B5J56VAk.js} +1 -1
- package/dist/ReturnsSection-BjpIVFfN.js +1 -0
- package/dist/{ReturnsSection-B4FL7bUv.mjs → ReturnsSection-DUVeKrCd.mjs} +2 -2
- package/dist/{SettingsSection-Cz2Yjdhr.js → SettingsSection-DKkHykaC.js} +1 -1
- package/dist/{SettingsSection-DoeNDbqd.mjs → SettingsSection-vK9WIwXE.mjs} +1 -1
- package/dist/ShippingSection-B5lk7zpS.js +1 -0
- package/dist/{ShippingSection-BlVsYC6B.mjs → ShippingSection-CZRrXrlh.mjs} +2 -2
- package/dist/{SingleCategorySettings-B406nnF-.mjs → SingleCategorySettings-C8xJ47_T.mjs} +4 -4
- package/dist/SingleCategorySettings-g7D-9lG1.js +3 -0
- package/dist/StatsBar-CWXw2ZT3.js +1 -0
- package/dist/{StatsBar-D4v-I_Dj.mjs → StatsBar-D4cOKG2e.mjs} +1 -1
- package/dist/StorefrontSection-BWnMB9k-.js +1 -0
- package/dist/{StorefrontSection-BK_rhrAi.mjs → StorefrontSection-uXSVbEAa.mjs} +4 -4
- package/dist/{SubscriptionsSection-D8V9RBv-.mjs → SubscriptionsSection-Ci_AZrWA.mjs} +3 -3
- package/dist/SubscriptionsSection-DQfXkuDv.js +1 -0
- package/dist/{TaxSection-Cj6TXL6x.mjs → TaxSection-BTukS_cU.mjs} +2 -2
- package/dist/TaxSection-cuPQISxZ.js +1 -0
- package/dist/Token22Section-CCfkDm8W.js +1 -0
- package/dist/{Token22Section-DtYAcT54.mjs → Token22Section-DRsPJuTq.mjs} +2 -2
- package/dist/{WebhooksSection-DBAIxtBy.mjs → WebhooksSection-A8Y4ZGcj.mjs} +2 -2
- package/dist/WebhooksSection-CnEmaGH1.js +1 -0
- package/dist/admin.js +1 -1
- package/dist/admin.mjs +4 -5
- package/dist/crypto-only.js +1 -1
- package/dist/crypto-only.mjs +4 -3
- package/dist/{sectionIds-DBavltrL.mjs → icons-C3yDMnKE.mjs} +129 -253
- package/dist/icons-Cjgd9YVo.js +1 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +24 -23
- package/dist/sectionIds-D46-_-h-.js +1 -0
- package/dist/sectionIds-YktNxmRt.mjs +124 -0
- package/dist/{sections-C2zEJr5G.js → sections-511_XBh4.js} +1 -1
- package/dist/{sections-BHph7CYj.mjs → sections-CRaMa8ZB.mjs} +2 -2
- package/dist/sections-more-Cgw2qJlA.js +1 -0
- package/dist/{sections-more-CMFgfU4d.mjs → sections-more-Ixw6mM6R.mjs} +5 -5
- package/dist/src/admin.d.ts +4 -4
- package/dist/src/admin.d.ts.map +1 -1
- package/dist/src/standalone-admin.d.ts +8 -0
- package/dist/src/standalone-admin.d.ts.map +1 -0
- package/dist/standalone-admin.d.ts +2 -0
- package/dist/standalone-admin.js +1 -0
- package/dist/standalone-admin.mjs +4 -0
- package/package.json +7 -1
- package/dist/AutosaveIndicator-DiyeAg93.js +0 -1
- package/dist/CedrosPayAdminDashboard-CAwEvn66.js +0 -1
- package/dist/ChatLogsSection-DLxMMi9I.js +0 -1
- package/dist/ComplianceSection-Buu0zTiL.js +0 -1
- package/dist/CustomersSection-BywmMLur.js +0 -1
- package/dist/DisputesSection-DwkHGv2a.js +0 -1
- package/dist/Dropdown-CtY91emj.js +0 -1
- package/dist/ErrorBanner-Cx2dUhps.js +0 -1
- package/dist/FAQSection-DlPLnIJD.js +0 -1
- package/dist/ImagesSection-B4Jzet79.js +0 -1
- package/dist/InventorySection-BgRdpn1l.js +0 -1
- package/dist/MessagingSection-CxV-pf-f.js +0 -1
- package/dist/OrdersSection-BbAX79Ff.js +0 -1
- package/dist/ReturnsSection-7k4LZ8yp.js +0 -1
- package/dist/ShippingSection-C-HI8rOb.js +0 -1
- package/dist/SingleCategorySettings-BqC2UXt3.js +0 -3
- package/dist/StatsBar-m6GSRNxs.js +0 -1
- package/dist/StorefrontSection-Axvh_KeS.js +0 -1
- package/dist/SubscriptionsSection-EeULMWIB.js +0 -1
- package/dist/TaxSection-CzHPhaHl.js +0 -1
- package/dist/Token22Section-DqRKVG_G.js +0 -1
- package/dist/WebhooksSection-D--iPZuM.js +0 -1
- package/dist/sectionIds-B_tFiNvF.js +0 -1
- package/dist/sections-more-C1VNVwkp.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),L=require("./sectionIds-B_tFiNvF.js"),$=require("./ErrorBanner-Cx2dUhps.js"),O=require("./dateHelpers-BKW_lGND.js"),W=c=>(c/100).toFixed(2)+"%",w=c=>Math.round(parseFloat(c)*100),v={name:"",country:"",region:"",ratePercent:"",active:!0};function M({serverUrl:c,apiKey:_,pageSize:o=50,authManager:p}){const[l,N]=a.useState([]),[I,S]=a.useState(!0),[k,d]=a.useState(null),[m,C]=a.useState(0),[D,b]=a.useState(!1),[h,f]=a.useState(null),[n,r]=a.useState(v),[R,T]=a.useState(!1),[P,E]=a.useState(null),[g,y]=a.useState(null),u=a.useCallback(async(t,s)=>{if(p?.isAuthenticated())return p.fetchWithAuth(t,s);const i={"Content-Type":"application/json"};_&&(i["X-API-Key"]=_);const j=await fetch(`${c}${t}`,{...s,headers:{...i,...s?.headers}});if(!j.ok)throw new Error(`Request failed: ${j.status}`);return j.json()},[c,_,p]),x=a.useCallback(async()=>{S(!0),d(null);try{const t=new URLSearchParams;t.set("limit",String(o)),t.set("offset",String(m));const s=await u(`/admin/tax/rates?${t.toString()}`);N(s.rates??[])}catch{d("Failed to load tax rates"),N([])}finally{S(!1)}},[u,o,m]);a.useEffect(()=>{x()},[x]);const F=()=>{r(v),f(null),b(!1)},q=()=>{f(null),r(v),b(!0)},A=t=>{f(t),r({name:t.name,country:t.country,region:t.region??"",ratePercent:(t.rateBps/100).toFixed(2),active:t.active}),b(!0)},U=async t=>{t.preventDefault();const s=parseFloat(n.ratePercent);if(isNaN(s)||s<0||s>100){d("Rate must be a number between 0 and 100");return}T(!0),d(null);try{const i={name:n.name.trim(),country:n.country.trim().toUpperCase(),region:n.region.trim()||void 0,rateBps:w(n.ratePercent),active:n.active};h?await u(`/admin/tax/rates/${encodeURIComponent(h.id)}`,{method:"PUT",body:JSON.stringify(i)}):await u("/admin/tax/rates",{method:"POST",body:JSON.stringify(i)}),F(),x()}catch(i){d(i instanceof Error?i.message:"Failed to save tax rate")}finally{T(!1)}},B=async t=>{if(g!==t){y(t);return}E(t),d(null);try{await u(`/admin/tax/rates/${encodeURIComponent(t)}`,{method:"DELETE"}),y(null),x()}catch{d("Failed to delete tax rate")}finally{E(null)}};return e.jsxs("div",{children:[e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsx("h3",{className:"cedros-admin__section-title",children:"Tax Rates"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--primary",onClick:q,children:"+ Add Rate"})]}),e.jsx($.ErrorBanner,{message:k}),D&&e.jsxs("form",{onSubmit:U,style:{border:"1px solid var(--cedros-admin-border, #e0e0e0)",borderRadius:"4px",padding:"1rem",marginBottom:"1.5rem",maxWidth:"500px"},children:[e.jsx("h4",{style:{margin:"0 0 0.75rem",fontSize:"0.9rem",fontWeight:600},children:h?"Edit Tax Rate":"New Tax Rate"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Name *"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:n.name,onChange:t=>r(s=>({...s,name:t.target.value})),required:!0,placeholder:"e.g. US Sales Tax"})]}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[e.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Country (2-letter) *"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:n.country,onChange:t=>r(s=>({...s,country:t.target.value.toUpperCase().slice(0,2)})),required:!0,maxLength:2,placeholder:"US",style:{textTransform:"uppercase"}})]}),e.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Region (optional)"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:n.region,onChange:t=>r(s=>({...s,region:t.target.value})),placeholder:"e.g. CA"})]})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Rate (%) *"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:n.ratePercent,onChange:t=>r(s=>({...s,ratePercent:t.target.value})),required:!0,min:"0",max:"100",step:"0.01",placeholder:"8.25",style:{maxWidth:"140px"}}),n.ratePercent&&!isNaN(parseFloat(n.ratePercent))&&e.jsxs("span",{style:{fontSize:"0.8rem",color:"var(--cedros-admin-text-muted, #888)",marginLeft:"0.5rem"},children:["= ",w(n.ratePercent)," bps"]})]}),e.jsx("div",{className:"cedros-admin__field",children:e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer",fontSize:"0.85rem"},children:[e.jsx("input",{type:"checkbox",checked:n.active,onChange:t=>r(s=>({...s,active:t.target.checked}))}),"Active"]})})]}),e.jsxs("div",{style:{marginTop:"0.75rem",display:"flex",gap:"0.5rem"},children:[e.jsx("button",{type:"submit",className:"cedros-admin__button cedros-admin__button--primary",disabled:R,children:R?"Saving...":h?"Update":"Create"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost",onClick:F,children:"Cancel"})]})]}),I?e.jsxs("div",{className:"cedros-admin__loading",children:[L.Icons.loading," Loading tax rates..."]}):l.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No tax rates configured."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Country"}),e.jsx("th",{children:"Region"}),e.jsx("th",{children:"Rate"}),e.jsx("th",{children:"Active"}),e.jsx("th",{children:"Created"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:l.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:t.name}),e.jsx("td",{style:{fontWeight:500},children:t.country.toUpperCase()}),e.jsx("td",{children:t.region??e.jsx("span",{style:{color:"var(--cedros-admin-text-muted, #888)"},children:"—"})}),e.jsx("td",{children:W(t.rateBps)}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${t.active?"success":"muted"}`,children:t.active?"Active":"Inactive"})}),e.jsx("td",{children:O.formatDateTime(t.createdAt)}),e.jsx("td",{children:e.jsxs("div",{style:{display:"flex",gap:"0.25rem"},children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>A(t),children:"Edit"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",style:g===t.id?{color:"var(--cedros-admin-error, #e53e3e)"}:void 0,disabled:P===t.id,onClick:()=>B(t.id),onBlur:()=>y(null),children:P===t.id?"Deleting...":g===t.id?"Confirm?":"Delete"})]})})]},t.id))})]})}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"0.75rem",fontSize:"0.85rem"},children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:m===0,onClick:()=>C(Math.max(0,m-o)),children:"Previous"}),e.jsxs("span",{children:["Showing ",l.length," rate",l.length!==1?"s":""]}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",disabled:l.length<o,onClick:()=>C(m+o),children:"Next"})]})]})]})}exports.TaxSection=M;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var we=Object.create;var xe=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var Ae=Object.getOwnPropertyNames;var Te=Object.getPrototypeOf,Ne=Object.prototype.hasOwnProperty;var Be=(t,i,n,s)=>{if(i&&typeof i=="object"||typeof i=="function")for(let a of Ae(i))!Ne.call(t,a)&&a!==n&&xe(t,a,{get:()=>i[a],enumerable:!(s=ke(i,a))||s.enumerable});return t};var me=(t,i,n)=>(n=t!=null?we(Te(t)):{},Be(i||!t||!t.__esModule?xe(n,"default",{value:t,enumerable:!0}):n,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("react"),Re=require("./sectionIds-B_tFiNvF.js"),ze=require("./ErrorBanner-Cx2dUhps.js"),ee=require("./configApi-BS5UJfzm.js"),Se=[{value:"text",label:"Short Text"},{value:"email",label:"Email"},{value:"phone",label:"Phone"},{value:"address",label:"Address"},{value:"textarea",label:"Long Text"},{value:"dropdown",label:"Dropdown"},{value:"file_upload",label:"File Upload"}],fe={fields:[],requiresApproval:!0},U={width:"100%",padding:"0.4rem 0.6rem",border:"1px solid rgba(0,0,0,0.2)",borderRadius:4,fontSize:"0.9rem",boxSizing:"border-box"},G={display:"block",fontSize:"0.8rem",fontWeight:500,marginBottom:4},Q={padding:"0.4rem 1rem",borderRadius:6,border:"1px solid rgba(0,0,0,0.2)",background:"white",cursor:"pointer",fontSize:"0.85rem"};function Ie(){return{id:Math.random().toString(36).slice(2),label:"",fieldType:"text",required:!1,options:[],placeholder:""}}function be({field:t,onSave:i,onCancel:n}){const[s,a]=r.useState(t),[c,y]=r.useState(""),p=o=>a(d=>({...d,...o})),b=()=>{const o=c.trim();o&&(p({options:[...s.options,o]}),y(""))};return e.jsxs("div",{style:{padding:"0.75rem",border:"1px solid rgba(37,99,235,0.3)",borderRadius:6,background:"#eff6ff",marginTop:6},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0.6rem",marginBottom:"0.6rem"},children:[e.jsxs("div",{children:[e.jsx("label",{style:G,children:"Label *"}),e.jsx("input",{style:U,value:s.label,onChange:o=>p({label:o.target.value}),placeholder:"e.g., Full Name"})]}),e.jsxs("div",{children:[e.jsx("label",{style:G,children:"Field Type"}),e.jsx("select",{style:U,value:s.fieldType,onChange:o=>p({fieldType:o.target.value,options:[]}),children:Se.map(o=>e.jsx("option",{value:o.value,children:o.label},o.value))})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr auto",gap:"0.6rem",alignItems:"end",marginBottom:"0.6rem"},children:[e.jsxs("div",{children:[e.jsx("label",{style:G,children:"Placeholder"}),e.jsx("input",{style:U,value:s.placeholder??"",onChange:o=>p({placeholder:o.target.value}),placeholder:"Optional hint text"})]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:6,fontSize:"0.85rem",cursor:"pointer",paddingBottom:2},children:[e.jsx("input",{type:"checkbox",checked:s.required,onChange:o=>p({required:o.target.checked})})," Required"]})]}),s.fieldType==="dropdown"&&e.jsxs("div",{style:{marginBottom:"0.6rem"},children:[e.jsx("label",{style:G,children:"Options"}),s.options.map((o,d)=>e.jsxs("div",{style:{display:"flex",gap:6,marginBottom:4},children:[e.jsx("span",{style:{flex:1,fontSize:"0.85rem",padding:"0.25rem 0.5rem",background:"white",border:"1px solid rgba(0,0,0,0.15)",borderRadius:4},children:o}),e.jsx("button",{type:"button",onClick:()=>p({options:s.options.filter((u,v)=>v!==d)}),style:{padding:"0.2rem 0.5rem",borderRadius:4,border:"1px solid rgba(0,0,0,0.2)",background:"white",cursor:"pointer",fontSize:"0.8rem",color:"#dc2626"},children:"x"})]},d)),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("input",{style:{...U,flex:1},value:c,onChange:o=>y(o.target.value),onKeyDown:o=>o.key==="Enter"&&(o.preventDefault(),b()),placeholder:"Add option..."}),e.jsx("button",{type:"button",onClick:b,style:Q,children:"Add"})]})]}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsx("button",{type:"button",onClick:()=>i(s),disabled:!s.label.trim(),style:{padding:"0.35rem 1rem",borderRadius:6,border:"none",background:"#2563eb",color:"white",cursor:s.label.trim()?"pointer":"not-allowed",fontSize:"0.85rem",opacity:s.label.trim()?1:.5},children:"Save Field"}),e.jsx("button",{type:"button",onClick:n,style:Q,children:"Cancel"})]})]})}function De({fields:t,instructions:i}){const n={...U,fontSize:"0.85rem",background:"white",opacity:.6};return e.jsxs("div",{style:{padding:"1rem",border:"1px solid rgba(0,0,0,0.1)",borderRadius:8,background:"rgba(0,0,0,0.02)"},children:[e.jsx("div",{style:{fontSize:"0.75rem",fontWeight:600,color:"rgba(0,0,0,0.4)",textTransform:"uppercase",letterSpacing:"0.05em",marginBottom:"0.75rem"},children:"Preview — Redeemer View"}),i&&e.jsx("div",{style:{padding:"0.6rem 0.75rem",background:"#fffbeb",border:"1px solid #fcd34d",borderRadius:6,fontSize:"0.85rem",marginBottom:"0.75rem",color:"#92400e"},children:i}),t.length===0&&e.jsx("div",{style:{fontSize:"0.85rem",color:"rgba(0,0,0,0.35)",fontStyle:"italic"},children:"No fields added yet."}),t.map(s=>e.jsxs("div",{style:{marginBottom:"0.6rem"},children:[e.jsxs("label",{style:{display:"block",fontSize:"0.8rem",fontWeight:500,marginBottom:4},children:[s.label||"Unlabelled field",s.required&&e.jsx("span",{style:{color:"#dc2626",marginLeft:2},children:"*"})]}),s.fieldType==="textarea"&&e.jsx("textarea",{disabled:!0,rows:2,placeholder:s.placeholder??"",style:{...n,resize:"none"}}),s.fieldType==="file_upload"&&e.jsx("div",{style:{padding:"0.5rem",border:"1px dashed rgba(0,0,0,0.25)",borderRadius:4,fontSize:"0.8rem",color:"rgba(0,0,0,0.4)",textAlign:"center"},children:"File upload"}),s.fieldType==="dropdown"&&e.jsxs("select",{disabled:!0,style:n,children:[e.jsx("option",{children:s.placeholder||"Select..."}),s.options.map((a,c)=>e.jsx("option",{children:a},c))]}),!["textarea","file_upload","dropdown"].includes(s.fieldType)&&e.jsx("input",{disabled:!0,type:s.fieldType==="email"?"email":s.fieldType==="phone"?"tel":"text",placeholder:s.placeholder??"",style:n})]},s.id))]})}function Pe({value:t,onChange:i}){const n=t!==null,s=t??fe,[a,c]=r.useState(null),[y,p]=r.useState(null),[b,o]=r.useState(!1),d=h=>i({...s,...h}),u=()=>{c(null),p(null)},v=h=>{i(h?{...fe}:null),u()},x=()=>{const h=Ie();p(h),c("new")},f=h=>{p({...h}),c(h.id)},j=h=>{d({fields:a==="new"?[...s.fields,h]:s.fields.map(S=>S.id===h.id?h:S)}),u()},k=h=>{a===h&&u(),d({fields:s.fields.filter(S=>S.id!==h)})};return e.jsxs("div",{children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",marginBottom:n?"1rem":4,fontSize:"0.9rem",fontWeight:500},children:[e.jsx("input",{type:"checkbox",checked:n,onChange:h=>v(h.target.checked)}),"Enable Redemption Form"]}),!n&&e.jsx("div",{style:{fontSize:"0.8rem",color:"rgba(0,0,0,0.4)"},children:"No redemption form — token holders cannot request physical redemption."}),n&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.75rem"},children:[e.jsxs("div",{children:[e.jsx("label",{style:G,children:"Instructions shown to redeemer"}),e.jsx("textarea",{value:s.instructions??"",onChange:h=>d({instructions:h.target.value||void 0}),placeholder:"Describe requirements, turnaround times, etc.",rows:3,style:{...U,resize:"vertical"}})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"auto 1fr",gap:"1rem",alignItems:"center",padding:"0.6rem 0.75rem",border:"1px solid rgba(0,0,0,0.1)",borderRadius:6,background:"rgba(0,0,0,0.02)"},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:6,fontSize:"0.85rem",cursor:"pointer",whiteSpace:"nowrap"},children:[e.jsx("input",{type:"checkbox",checked:s.requiresApproval,onChange:h=>d({requiresApproval:h.target.checked})})," Requires admin approval"]}),e.jsxs("div",{children:[e.jsx("label",{style:G,children:"Estimated processing days"}),e.jsx("input",{type:"number",min:0,value:s.estimatedProcessingDays??"",onChange:h=>d({estimatedProcessingDays:h.target.value?Number(h.target.value):void 0}),placeholder:"e.g., 5",style:{...U,maxWidth:120}})]})]}),e.jsxs("div",{children:[e.jsxs("div",{style:{fontSize:"0.8rem",fontWeight:500,marginBottom:"0.5rem"},children:["Form Fields (",s.fields.length,")"]}),s.fields.length===0&&a!=="new"&&e.jsx("div",{style:{fontSize:"0.85rem",color:"rgba(0,0,0,0.35)",fontStyle:"italic",marginBottom:"0.5rem"},children:"No fields yet. Add fields below."}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.4rem"},children:[s.fields.map(h=>e.jsxs("div",{children:[e.jsxs("div",{style:{padding:"0.5rem 0.75rem",border:"1px solid rgba(0,0,0,0.1)",borderRadius:6,background:"white",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:"0.9rem"},children:h.label||e.jsx("em",{style:{color:"rgba(0,0,0,0.35)"},children:"Unlabelled"})}),e.jsx("span",{style:{padding:"2px 8px",borderRadius:10,background:"#dbeafe",color:"#1d4ed8",fontSize:"0.75rem"},children:Se.find(S=>S.value===h.fieldType)?.label??h.fieldType}),h.required&&e.jsx("span",{style:{padding:"2px 8px",borderRadius:10,background:"#fef3c7",color:"#92400e",fontSize:"0.75rem"},children:"required"})]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{type:"button",onClick:()=>f(h),style:{...Q,padding:"0.25rem 0.6rem",fontSize:"0.8rem"},children:"Edit"}),e.jsx("button",{type:"button",onClick:()=>k(h.id),style:{padding:"0.25rem 0.6rem",borderRadius:4,border:"1px solid rgba(220,38,38,0.3)",background:"white",cursor:"pointer",fontSize:"0.8rem",color:"#dc2626"},children:"Delete"})]})]}),a===h.id&&y&&e.jsx(be,{field:y,onSave:j,onCancel:u})]},h.id)),a==="new"&&y&&e.jsx(be,{field:y,onSave:j,onCancel:u})]}),a===null&&e.jsx("button",{type:"button",onClick:x,style:{...Q,marginTop:"0.5rem"},children:"+ Add Field"})]}),e.jsxs("div",{children:[e.jsx("button",{type:"button",onClick:()=>o(h=>!h),style:{...Q,background:b?"rgba(0,0,0,0.05)":"white"},children:b?"Hide Preview":"Show Preview"}),b&&e.jsx("div",{style:{marginTop:"0.75rem"},children:e.jsx(De,{fields:s.fields,instructions:s.instructions})})]})]})]})}const Me=[{value:"securities",label:"Securities (fungible)"},{value:"commodities",label:"Commodities (fungible)"},{value:"property",label:"Property (non-fungible)"},{value:"collectibles",label:"Collectibles (non-fungible)"}],Fe=t=>t==="securities"||t==="commodities";function Ee({c:t,onDeployPool:i,onEdit:n,onDelete:s}){const a=t.tokenizationConfig,c=Fe(a.assetClass);return e.jsxs("div",{style:{padding:"0.75rem 1rem",border:"1px solid rgba(0,0,0,0.1)",borderRadius:8,background:"white"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsxs("div",{children:[e.jsx("strong",{children:t.name}),e.jsx("span",{style:{marginLeft:8,fontSize:"0.8rem",padding:"2px 8px",borderRadius:10,background:c?"#dbeafe":"#fef3c7",color:c?"#1d4ed8":"#92400e"},children:a.assetClass}),a.tokenSymbol&&e.jsx("span",{style:{marginLeft:6,fontSize:"0.8rem",color:"rgba(0,0,0,0.5)"},children:a.tokenSymbol})]}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:"0.8rem"},children:[a.mintAddress?e.jsx("span",{style:{color:"#16a34a"},children:"Mint initialized"}):e.jsx("span",{style:{color:"rgba(0,0,0,0.4)"},children:"No mint"}),c&&a.mintAddress&&(a.liquidityPoolAddress?e.jsxs("span",{style:{padding:"2px 8px",borderRadius:10,background:"#dcfce7",color:"#15803d",fontSize:"0.75rem"},children:["Pool Active · ",a.liquidityPoolAddress.slice(0,4),"...",a.liquidityPoolAddress.slice(-4)]}):e.jsx("button",{type:"button",onClick:i,style:{padding:0,border:"none",background:"none",color:"#2563eb",cursor:"pointer",fontSize:"0.8rem",textDecoration:"underline"},children:"Deploy Pool"}))]})]}),t.description&&e.jsx("div",{style:{fontSize:"0.85rem",color:"rgba(0,0,0,0.5)",marginTop:4},children:t.description}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:6},children:[e.jsxs("div",{style:{display:"flex",gap:"1rem",flexWrap:"wrap",fontSize:"0.8rem",color:"rgba(0,0,0,0.4)"},children:[e.jsxs("span",{children:["Fee: ",a.transferFeeBps," bps"]}),a.treasuryAddress&&e.jsxs("span",{children:["Treasury: ",a.treasuryAddress.slice(0,8),"..."]}),a.allowedJurisdictions?.length>0&&e.jsxs("span",{style:{padding:"1px 7px",borderRadius:10,background:"#f3f4f6",color:"rgba(0,0,0,0.55)"},children:[a.allowedJurisdictions.length," jurisdiction",a.allowedJurisdictions.length!==1?"s":"",": ",a.allowedJurisdictions.join(", ")]})]}),e.jsxs("div",{style:{display:"flex",gap:6},children:[n&&e.jsx("button",{type:"button",onClick:n,style:{padding:"2px 10px",border:"1px solid rgba(0,0,0,0.15)",borderRadius:4,background:"white",cursor:"pointer",fontSize:"0.75rem",color:"#2563eb"},children:"Edit"}),s&&e.jsx("button",{type:"button",onClick:s,style:{padding:"2px 10px",border:"1px solid rgba(0,0,0,0.15)",borderRadius:4,background:"white",cursor:"pointer",fontSize:"0.75rem",color:"#dc2626"},children:"Delete"})]})]})]})}const pe={name:"",description:"",assetClass:"securities",tokenSymbol:"",tokenDecimals:2,transferFeeBps:250,maxTransferFee:500,treasuryAddress:"",regulatoryNotice:"",jurisdictions:"",redemptionConfig:null};function Le({serverUrl:t,apiKey:i,authManager:n,onNavigateToLiquidity:s}){const[a,c]=r.useState([]),[y,p]=r.useState(!0),[b,o]=r.useState(null),[d,u]=r.useState(!1),[v,x]=r.useState(!1),[f,j]=r.useState(pe),[k,h]=r.useState(null),S=r.useCallback(async(g,m)=>{if(n?.isAuthenticated())return n.fetchWithAuth(g,m);const N={"Content-Type":"application/json"};i&&(N["X-API-Key"]=i);const C=await fetch(`${t}${g}`,{...m,headers:{...N,...m?.headers}});if(!C.ok){const z=await C.text().catch(()=>`HTTP ${C.status}`);throw new Error(z)}return C.json()},[t,i,n]),T=r.useCallback(async()=>{try{p(!0),o(null);const g=await S("/admin/collections");c((g.collections||[]).filter(m=>m.tokenizationConfig))}catch(g){o(g instanceof Error?g.message:"Failed to load asset classes")}finally{p(!1)}},[S]);r.useEffect(()=>{T()},[T]);const l=()=>({name:f.name.trim(),description:f.description||void 0,active:!0,productIds:[],tokenizationConfig:{assetClass:f.assetClass,tokenSymbol:f.tokenSymbol||void 0,tokenDecimals:f.tokenDecimals,transferFeeBps:f.transferFeeBps,maxTransferFee:f.maxTransferFee,treasuryAddress:f.treasuryAddress||void 0,regulatoryNotice:f.regulatoryNotice||void 0,allowedJurisdictions:f.jurisdictions?f.jurisdictions.split(",").map(g=>g.trim().toUpperCase()).filter(Boolean):[],redemptionConfig:f.redemptionConfig||void 0}}),w=async()=>{if(f.name.trim()){x(!0),o(null);try{k?await S(`/admin/collections/${encodeURIComponent(k)}`,{method:"PUT",body:JSON.stringify(l())}):await S("/admin/collections",{method:"POST",body:JSON.stringify(l())}),j(pe),u(!1),h(null),await T()}catch(g){o(g instanceof Error?g.message:`Failed to ${k?"update":"create"} asset class`)}finally{x(!1)}}},_=g=>{const m=g.tokenizationConfig;j({name:g.name,description:g.description??"",assetClass:m.assetClass,tokenSymbol:m.tokenSymbol??"",tokenDecimals:m.tokenDecimals,transferFeeBps:m.transferFeeBps,maxTransferFee:m.maxTransferFee,treasuryAddress:m.treasuryAddress??"",regulatoryNotice:m.regulatoryNotice??"",jurisdictions:m.allowedJurisdictions.join(", "),redemptionConfig:m.redemptionConfig??null}),h(g.id),u(!0)},A=async g=>{if(window.confirm(`Delete asset class "${g.name}"? This cannot be undone.`)){o(null);try{await S(`/admin/collections/${encodeURIComponent(g.id)}`,{method:"DELETE"}),await T()}catch(m){o(m instanceof Error?m.message:"Failed to delete asset class")}}};return y?e.jsx("div",{style:{padding:"1rem 0",color:"rgba(0,0,0,0.5)"},children:"Loading asset classes..."}):e.jsxs("div",{children:[b&&e.jsx("div",{style:{padding:"0.75rem 1rem",background:"#fef2f2",border:"1px solid #fecaca",borderRadius:6,color:"#dc2626",marginBottom:"1rem",fontSize:"0.9rem"},children:b}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"1rem"},children:[e.jsxs("h4",{style:{margin:0},children:["Asset Classes (",a.length,")"]}),e.jsx("button",{type:"button",onClick:()=>{u(!d),d&&(h(null),j(pe))},style:{padding:"0.4rem 1rem",borderRadius:6,border:"1px solid rgba(0,0,0,0.2)",background:d?"rgba(0,0,0,0.05)":"white",cursor:"pointer",fontSize:"0.85rem"},children:d?"Cancel":"+ New Asset Class"})]}),d&&e.jsxs("div",{style:{padding:"1rem",border:"1px solid rgba(0,0,0,0.1)",borderRadius:8,marginBottom:"1rem",background:"rgba(0,0,0,0.02)"},children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0.75rem",marginBottom:"0.75rem"},children:[e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:"0.8rem",fontWeight:500,marginBottom:4},children:"Name *"}),e.jsx("input",{type:"text",value:f.name,onChange:g=>j(m=>({...m,name:g.target.value})),placeholder:"e.g., Gold Tokens",style:{width:"100%",padding:"0.4rem 0.6rem",border:"1px solid rgba(0,0,0,0.2)",borderRadius:4,fontSize:"0.9rem"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:"0.8rem",fontWeight:500,marginBottom:4},children:"Asset Class *"}),e.jsx("select",{value:f.assetClass,onChange:g=>j(m=>({...m,assetClass:g.target.value})),style:{width:"100%",padding:"0.4rem 0.6rem",border:"1px solid rgba(0,0,0,0.2)",borderRadius:4,fontSize:"0.9rem"},children:Me.map(g=>e.jsx("option",{value:g.value,children:g.label},g.value))})]})]}),e.jsxs("div",{style:{marginBottom:"0.75rem"},children:[e.jsx("label",{style:{display:"block",fontSize:"0.8rem",fontWeight:500,marginBottom:4},children:"Description"}),e.jsx("input",{type:"text",value:f.description,onChange:g=>j(m=>({...m,description:g.target.value})),placeholder:"Brief description of this asset class",style:{width:"100%",padding:"0.4rem 0.6rem",border:"1px solid rgba(0,0,0,0.2)",borderRadius:4,fontSize:"0.9rem"}})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:"0.75rem",marginBottom:"0.75rem"},children:[e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:"0.8rem",fontWeight:500,marginBottom:4},children:"Token Symbol"}),e.jsx("input",{type:"text",value:f.tokenSymbol,onChange:g=>j(m=>({...m,tokenSymbol:g.target.value})),placeholder:"e.g., GOLD",style:{width:"100%",padding:"0.4rem 0.6rem",border:"1px solid rgba(0,0,0,0.2)",borderRadius:4,fontSize:"0.9rem"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:"0.8rem",fontWeight:500,marginBottom:4},children:"Transfer Fee (bps)"}),e.jsx("input",{type:"number",value:f.transferFeeBps,onChange:g=>j(m=>({...m,transferFeeBps:Number(g.target.value)})),style:{width:"100%",padding:"0.4rem 0.6rem",border:"1px solid rgba(0,0,0,0.2)",borderRadius:4,fontSize:"0.9rem"}})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:"0.8rem",fontWeight:500,marginBottom:4},children:"Treasury Address"}),e.jsx("input",{type:"text",value:f.treasuryAddress,onChange:g=>j(m=>({...m,treasuryAddress:g.target.value})),placeholder:"Solana address",style:{width:"100%",padding:"0.4rem 0.6rem",border:"1px solid rgba(0,0,0,0.2)",borderRadius:4,fontSize:"0.9rem"}})]})]}),e.jsxs("div",{style:{marginBottom:"0.75rem"},children:[e.jsx("label",{style:{display:"block",fontSize:"0.8rem",fontWeight:500,marginBottom:4},children:"Allowed Jurisdictions"}),e.jsx("input",{type:"text",value:f.jurisdictions,onChange:g=>j(m=>({...m,jurisdictions:g.target.value})),placeholder:"US, CA, GB (comma-separated, leave empty for all)",style:{width:"100%",padding:"0.4rem 0.6rem",border:"1px solid rgba(0,0,0,0.2)",borderRadius:4,fontSize:"0.9rem"}})]}),e.jsxs("div",{style:{marginBottom:"0.75rem"},children:[e.jsx("label",{style:{display:"block",fontSize:"0.8rem",fontWeight:500,marginBottom:4},children:"Regulatory Notice"}),e.jsx("textarea",{value:f.regulatoryNotice,onChange:g=>j(m=>({...m,regulatoryNotice:g.target.value})),placeholder:"Shown to buyers before purchase",rows:2,style:{width:"100%",padding:"0.4rem 0.6rem",border:"1px solid rgba(0,0,0,0.2)",borderRadius:4,fontSize:"0.9rem",resize:"vertical"}})]}),e.jsxs("div",{style:{marginBottom:"0.75rem"},children:[e.jsx("label",{style:{display:"block",fontSize:"0.8rem",fontWeight:600,marginBottom:8},children:"Redemption Form"}),e.jsx(Pe,{value:f.redemptionConfig,onChange:g=>j(m=>({...m,redemptionConfig:g}))})]}),e.jsx("button",{type:"button",onClick:w,disabled:v||!f.name.trim(),style:{padding:"0.5rem 1.5rem",borderRadius:6,border:"none",background:"#2563eb",color:"white",cursor:v?"wait":"pointer",fontSize:"0.9rem",opacity:v?.6:1},children:v?"Saving...":k?"Save Changes":"Create Asset Class"})]}),a.length===0?e.jsx("div",{style:{padding:"2rem",textAlign:"center",color:"rgba(0,0,0,0.4)",fontSize:"0.9rem"},children:"No asset classes configured. Create one to start tokenizing off-chain assets."}):e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:a.map(g=>e.jsx(Ee,{c:g,onDeployPool:s,onEdit:()=>_(g),onDelete:()=>A(g)},g.id))})]})}const $e=[{value:"",label:"All statuses"},{value:"pending_info",label:"Pending Info"},{value:"info_submitted",label:"Info Submitted"},{value:"under_review",label:"Under Review"},{value:"approved",label:"Approved"},{value:"completed",label:"Completed"},{value:"rejected",label:"Rejected"}];function qe(t){switch(t){case"pending_info":return"cedros-admin__badge cedros-admin__badge--muted";case"info_submitted":return"cedros-admin__badge cedros-admin__badge--info";case"under_review":return"cedros-admin__badge cedros-admin__badge--warning";case"approved":return"cedros-admin__badge cedros-admin__badge--success";case"completed":return"cedros-admin__badge cedros-admin__badge--success";case"rejected":return"cedros-admin__badge cedros-admin__badge--failed";default:return"cedros-admin__badge cedros-admin__badge--muted"}}function Oe(t){return t.replace(/_/g," ").replace(/\b\w/g,i=>i.toUpperCase())}function We(t){return new Date(t).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})}function K(t){return t.length>12?`${t.slice(0,8)}…`:t}function je(t){return`https://solscan.io/tx/${t}`}function Ue({redemption:t,onAction:i,onComplete:n,actionBusy:s}){const[a,c]=r.useState(t.adminNotes??""),y=Object.entries(t.formData??{});return e.jsx("div",{style:{padding:"1rem 1.25rem",background:"rgba(0,0,0,0.02)",borderTop:"1px solid rgba(0,0,0,0.08)"},children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"1.5rem"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:600,fontSize:"0.8rem",marginBottom:8,textTransform:"uppercase",letterSpacing:"0.05em",opacity:.6},children:"Form Data"}),y.length===0?e.jsx("div",{style:{fontSize:"0.85rem",opacity:.5},children:"No form data submitted."}):e.jsx("dl",{style:{margin:0,display:"grid",gridTemplateColumns:"auto 1fr",gap:"4px 12px",fontSize:"0.85rem"},children:y.map(([p,b])=>e.jsxs(e.Fragment,{children:[e.jsx("dt",{style:{fontWeight:500,color:"rgba(0,0,0,0.6)",whiteSpace:"nowrap"},children:p},`k-${p}`),e.jsx("dd",{style:{margin:0,wordBreak:"break-word"},children:String(b??"—")},`v-${p}`)]}))}),(t.tokenMintSignature||t.tokenBurnSignature)&&e.jsxs("div",{style:{marginTop:12,fontSize:"0.8rem"},children:[e.jsx("div",{style:{fontWeight:600,marginBottom:4,opacity:.6,textTransform:"uppercase",letterSpacing:"0.05em"},children:"Signatures"}),t.tokenMintSignature&&e.jsxs("div",{children:["Mint:"," ",e.jsx("a",{href:je(t.tokenMintSignature),target:"_blank",rel:"noopener noreferrer",style:{fontFamily:"monospace",fontSize:"0.75rem"},children:K(t.tokenMintSignature)})]}),t.tokenBurnSignature&&e.jsxs("div",{children:["Burn:"," ",e.jsx("a",{href:je(t.tokenBurnSignature),target:"_blank",rel:"noopener noreferrer",style:{fontFamily:"monospace",fontSize:"0.75rem"},children:K(t.tokenBurnSignature)})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:"0.8rem",fontWeight:500,marginBottom:4},children:"Admin Notes"}),e.jsx("textarea",{value:a,onChange:p=>c(p.target.value),rows:4,style:{width:"100%",padding:"0.4rem 0.6rem",border:"1px solid rgba(0,0,0,0.2)",borderRadius:4,fontSize:"0.85rem",resize:"vertical",boxSizing:"border-box"},placeholder:"Internal notes (not shown to user)..."}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",marginTop:8,flexWrap:"wrap"},children:[t.status==="info_submitted"&&e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary cedros-admin__button--sm",disabled:s,onClick:()=>i(t.id,"under_review",a),children:s?"Saving...":"Mark Under Review"}),t.status==="under_review"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary cedros-admin__button--sm",disabled:s,onClick:()=>i(t.id,"approved",a),children:s?"Saving...":"Approve"}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--outline cedros-admin__button--danger cedros-admin__button--sm",disabled:s,onClick:()=>i(t.id,"rejected",a),children:s?"Saving...":"Reject"})]}),t.status==="approved"&&e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary cedros-admin__button--sm",disabled:s,onClick:()=>n(t.id),children:s?"Processing...":"Complete"})]})]})]})})}function Ye({serverUrl:t,apiKey:i,authManager:n}){const[s,a]=r.useState([]),[c,y]=r.useState(!0),[p,b]=r.useState(null),[o,d]=r.useState(""),[u,v]=r.useState(null),[x,f]=r.useState(null),j=r.useCallback(async(l,w)=>{if(n?.isAuthenticated())return n.fetchWithAuth(l,w);const _={"Content-Type":"application/json"};i&&(_["X-API-Key"]=i);const A=await fetch(`${t}${l}`,{...w,headers:{..._,...w?.headers}});if(!A.ok){const g=await A.text().catch(()=>`HTTP ${A.status}`);throw new Error(g)}return A.json()},[t,i,n]),k=r.useCallback(async()=>{y(!0),b(null);try{const l=o?`?status=${encodeURIComponent(o)}&limit=50&offset=0`:"?limit=50&offset=0",w=await j(`/admin/asset-redemptions${l}`);a(w.redemptions??[])}catch(l){b(l instanceof Error?l.message:"Failed to load redemptions")}finally{y(!1)}},[j,o]);r.useEffect(()=>{k()},[k]);const h=r.useCallback(async(l,w,_)=>{f(l),b(null);try{await j(`/admin/asset-redemptions/${l}/status`,{method:"PATCH",body:JSON.stringify({status:w,adminNotes:_})}),v(null),await k()}catch(A){b(A instanceof Error?A.message:"Failed to update status")}finally{f(null)}},[j,k]),S=r.useCallback(async l=>{f(l),b(null);try{await j(`/admin/asset-redemptions/${l}/complete`,{method:"POST"}),v(null),await k()}catch(w){b(w instanceof Error?w.message:"Failed to complete redemption")}finally{f(null)}},[j,k]),T=l=>{v(w=>w===l?null:l)};return e.jsxs("div",{className:"cedros-admin__page",children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",marginBottom:"1rem",flexWrap:"wrap"},children:[e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:"0.8rem",fontWeight:500,marginBottom:4},children:"Status"}),e.jsx("select",{value:o,onChange:l=>{d(l.target.value),v(null)},style:{padding:"0.4rem 0.6rem",border:"1px solid rgba(0,0,0,0.2)",borderRadius:4,fontSize:"0.9rem",minWidth:160},children:$e.map(l=>e.jsx("option",{value:l.value,children:l.label},l.value))})]}),e.jsx("div",{style:{alignSelf:"flex-end"},children:e.jsx("button",{className:"cedros-admin__button cedros-admin__button--outline",onClick:k,disabled:c,children:c?"Loading...":"Refresh"})})]}),p&&e.jsx("div",{style:{padding:"0.75rem 1rem",background:"#fef2f2",border:"1px solid #fecaca",borderRadius:6,color:"#dc2626",marginBottom:"1rem",fontSize:"0.9rem"},children:p}),c?e.jsx("div",{className:"cedros-admin__loading",children:"Loading redemptions..."}):s.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No redemption requests found."}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Date"}),e.jsx("th",{children:"Order"}),e.jsx("th",{children:"Product"}),e.jsx("th",{children:"Collection"}),e.jsx("th",{children:"User"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Actions"})]})}),e.jsx("tbody",{children:s.map(l=>e.jsxs(e.Fragment,{children:[e.jsxs("tr",{style:{cursor:"pointer"},onClick:()=>T(l.id),children:[e.jsx("td",{children:We(l.createdAt)}),e.jsx("td",{children:e.jsx("code",{title:l.orderId,children:K(l.orderId)})}),e.jsx("td",{children:e.jsx("code",{title:l.productId,children:K(l.productId)})}),e.jsx("td",{children:e.jsx("code",{title:l.collectionId,children:K(l.collectionId)})}),e.jsx("td",{children:l.userId?e.jsx("code",{title:l.userId,children:K(l.userId)}):e.jsx("span",{style:{opacity:.4},children:"—"})}),e.jsx("td",{children:e.jsx("span",{className:qe(l.status),children:Oe(l.status)})}),e.jsx("td",{onClick:w=>w.stopPropagation(),children:e.jsxs("div",{style:{display:"flex",gap:"0.4rem",flexWrap:"wrap"},children:[(l.status==="info_submitted"||l.status==="under_review"||l.status==="approved")&&e.jsx("button",{className:"cedros-admin__button cedros-admin__button--outline cedros-admin__button--sm",onClick:()=>T(l.id),children:u===l.id?"Close":"Review"}),l.status==="under_review"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary cedros-admin__button--sm",disabled:x===l.id,onClick:()=>h(l.id,"approved",l.adminNotes??""),children:"Approve"}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--outline cedros-admin__button--danger cedros-admin__button--sm",disabled:x===l.id,onClick:()=>h(l.id,"rejected",l.adminNotes??""),children:"Reject"})]}),l.status==="approved"&&e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary cedros-admin__button--sm",disabled:x===l.id,onClick:()=>S(l.id),children:x===l.id?"Processing...":"Complete"})]})})]},l.id),u===l.id&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,style:{padding:0},children:e.jsx(Ue,{redemption:l,onAction:h,onComplete:S,actionBusy:x===l.id})})},`${l.id}-detail`)]}))})]})})]})}const Ge={CA:{cashOutCents:1500,expirationProhibited:!0,escheatmentYears:3,notes:"Cash-out threshold increases to $15 on April 1, 2026."},CO:{cashOutCents:500,escheatmentYears:5},CT:{cashOutCents:300,escheatmentYears:3},FL:{expirationProhibited:!0,escheatmentYears:5},ME:{cashOutCents:500,escheatmentYears:3},MA:{cashOutCents:500,escheatmentYears:3,notes:"Cash-out also required when 90% of value is used."},MT:{cashOutCents:500,escheatmentYears:5},NJ:{cashOutCents:500,escheatmentYears:3},OR:{cashOutCents:500,escheatmentYears:3,notes:"May require at least one prior transaction."},RI:{cashOutCents:100,escheatmentYears:3},TX:{cashOutCents:250,escheatmentYears:3},VT:{cashOutCents:100,escheatmentYears:3},WA:{cashOutCents:500,escheatmentYears:5},PR:{cashOutCents:500,escheatmentYears:5}},ye={escheatmentYears:5},re=1e6,Ke={AL:"Alabama",AK:"Alaska",AZ:"Arizona",AR:"Arkansas",CA:"California",CO:"Colorado",CT:"Connecticut",DE:"Delaware",FL:"Florida",GA:"Georgia",HI:"Hawaii",ID:"Idaho",IL:"Illinois",IN:"Indiana",IA:"Iowa",KS:"Kansas",KY:"Kentucky",LA:"Louisiana",ME:"Maine",MD:"Maryland",MA:"Massachusetts",MI:"Michigan",MN:"Minnesota",MS:"Mississippi",MO:"Missouri",MT:"Montana",NE:"Nebraska",NV:"Nevada",NH:"New Hampshire",NJ:"New Jersey",NM:"New Mexico",NY:"New York",NC:"North Carolina",ND:"North Dakota",OH:"Ohio",OK:"Oklahoma",OR:"Oregon",PA:"Pennsylvania",RI:"Rhode Island",SC:"South Carolina",SD:"South Dakota",TN:"Tennessee",TX:"Texas",UT:"Utah",VT:"Vermont",VA:"Virginia",WA:"Washington",WV:"West Virginia",WI:"Wisconsin",WY:"Wyoming",DC:"District of Columbia",PR:"Puerto Rico"};function He({serverUrl:t,authManager:i}){const[n,s]=r.useState(null),[a,c]=r.useState(null),[y,p]=r.useState(null),[b,o]=r.useState(!0),d=r.useCallback(async()=>{try{const j=(await new ee.ConfigApiClient(t,void 0,i).getConfig("gift_cards")).config??{};s(j.business_state||null),c(j.min_gift_card_value_cents!=null?Number(j.min_gift_card_value_cents):null),p(j.max_gift_card_value_cents!=null?Number(j.max_gift_card_value_cents):null)}catch{}finally{o(!1)}},[t,i]);if(r.useEffect(()=>{d()},[d]),b)return e.jsx("div",{style:{padding:"2rem",textAlign:"center",opacity:.6},children:"Loading compliance data..."});const u=n?Ge[n]??ye:null,v=n?Ke[n]??n:null;return e.jsx("div",{children:n?e.jsxs(e.Fragment,{children:[e.jsxs("h3",{className:"cedros-admin__section-title",style:{marginBottom:"1rem"},children:["Compliance Guidance — ",v]}),e.jsxs("div",{style:{display:"grid",gap:"1rem",maxWidth:720},children:[e.jsx(Ve,{reg:u,minValueCents:a}),e.jsx(Xe,{reg:u}),e.jsx(Ze,{reg:u}),e.jsx(Qe,{maxValueCents:y})]}),e.jsx(et,{reg:u,minValueCents:a,maxValueCents:y})]}):e.jsx(Je,{})})}function Je(){return e.jsxs("div",{style:{padding:"2rem",textAlign:"center"},children:[e.jsx("p",{style:{fontSize:15,opacity:.7,marginBottom:"0.5rem"},children:"No business state configured."}),e.jsxs("p",{style:{fontSize:13,opacity:.5},children:["Set your ",e.jsx("strong",{children:"business_state"})," in the Gift Cards config category to see state-specific compliance guidance."]})]})}function te({title:t,children:i}){return e.jsxs("div",{style:{border:"1px solid rgba(0,0,0,0.1)",borderRadius:8,padding:"1rem 1.25rem"},children:[e.jsx("h4",{style:{margin:"0 0 0.5rem",fontSize:14,fontWeight:600},children:t}),e.jsx("div",{style:{fontSize:13,lineHeight:1.6},children:i})]})}function Ve({reg:t,minValueCents:i}){if(!t.cashOutCents)return e.jsx(te,{title:"Cash-Out Threshold",children:e.jsx("p",{style:{margin:0},children:"Your state does not have a specific cash-out threshold for gift cards. Federal law does not require cash redemption."})});const n=(t.cashOutCents/100).toFixed(2),s=i!=null&&i>t.cashOutCents;return e.jsxs(te,{title:"Cash-Out Threshold",children:[e.jsxs("p",{style:{margin:"0 0 0.5rem"},children:["Your state requires cash redemption for gift cards with a remaining balance of ",e.jsxs("strong",{children:["$",n]})," or less."]}),e.jsxs("p",{style:{margin:"0 0 0.5rem"},children:["Since this system uses ",e.jsx("strong",{children:"one-shot full redemption"})," (entire gift card value is converted to credits at once), cash-out is avoided by setting the minimum gift card face value above the threshold."]}),s?e.jsxs(oe,{ok:!0,children:["Min value ($",((i??0)/100).toFixed(2),") exceeds threshold"]}):e.jsxs(oe,{ok:!1,children:["Set ",e.jsx("code",{children:"min_gift_card_value_cents"})," above ",t.cashOutCents," to avoid cash-out obligations"]}),t.notes&&e.jsx("p",{style:{margin:"0.5rem 0 0",opacity:.7,fontStyle:"italic"},children:t.notes})]})}function Xe({reg:t}){return e.jsx(te,{title:"Expiration Rules",children:t.expirationProhibited?e.jsxs("p",{style:{margin:0},children:["Your state ",e.jsx("strong",{children:"prohibits"})," gift card expiration. Do not set expiration dates on gift cards."]}):e.jsxs("p",{style:{margin:0},children:["Federal law (CARD Act) requires gift cards to remain valid for at least ",e.jsx("strong",{children:"5 years"})," from purchase or last reload. Your state follows the federal minimum."]})})}function Ze({reg:t}){const i=t.escheatmentYears??ye.escheatmentYears;return e.jsxs(te,{title:"Escheatment (Unclaimed Property)",children:[e.jsxs("p",{style:{margin:"0 0 0.5rem"},children:["Gift card balances unredeemed for ",e.jsxs("strong",{children:[i," years"]})," may need to be reported and remitted to the state as unclaimed property."]}),e.jsxs("p",{style:{margin:0,opacity:.7},children:["The system tracks ",e.jsx("code",{children:"last_activity_at"})," on gift card redemptions to help identify dormant balances approaching the escheatment window."]})]})}function Qe({maxValueCents:t}){const i=t??re,n=i<=re;return e.jsxs(te,{title:"Anti-Money Laundering (AML)",children:[e.jsxs("p",{style:{margin:"0 0 0.5rem"},children:["FinCEN requires closed-loop prepaid cards to stay at or below ",e.jsx("strong",{children:"$10,000"})," per card. The server enforces this cap on product creation."]}),n?e.jsxs(oe,{ok:!0,children:["Max value ($",(i/100).toFixed(2),") within AML limit"]}):e.jsxs(oe,{ok:!1,children:[e.jsx("code",{children:"max_gift_card_value_cents"})," exceeds $10,000 AML cap"]})]})}function oe({ok:t,children:i}){return e.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:6,padding:"4px 10px",borderRadius:6,fontSize:13,fontWeight:500,background:t?"rgba(34,197,94,0.1)":"rgba(234,179,8,0.15)",color:t?"#16a34a":"#a16207"},children:[e.jsx("span",{children:t?"✓":"⚠"}),i]})}function et({reg:t,minValueCents:i,maxValueCents:n}){const a=[{label:"AML: Max card value ≤ $10,000",ok:(n??re)<=re},...t.cashOutCents?[{label:`Cash-out: Min value > $${(t.cashOutCents/100).toFixed(2)} threshold`,ok:i!=null&&i>t.cashOutCents}]:[],{label:t.expirationProhibited?"Expiration: State prohibits expiration (no action needed)":"Expiration: Federal 5-year minimum applies",ok:!0},{label:`Escheatment: ${t.escheatmentYears??ye.escheatmentYears}-year dormancy tracking enabled`,ok:!0}];return e.jsxs("div",{style:{marginTop:"1.5rem"},children:[e.jsx("h4",{style:{fontSize:14,fontWeight:600,marginBottom:"0.75rem"},children:"Compliance Checklist"}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:a.map((c,y)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13},children:[e.jsx("span",{style:{color:c.ok?"#16a34a":"#d97706",fontWeight:600},children:c.ok?"✓":"⚠"}),e.jsx("span",{children:c.label})]},y))})]})}function tt({serverUrl:t,apiKey:i,authManager:n}){const[s,a]=r.useState(null),[c,y]=r.useState(!0),[p,b]=r.useState(null),o=r.useCallback(async x=>{if(n?.isAuthenticated())return n.fetchWithAuth(x);const f={"Content-Type":"application/json"};i&&(f["X-API-Key"]=i);const j=await fetch(`${t}${x}`,{headers:f});if(!j.ok)throw new Error(`HTTP ${j.status}`);return j.json()},[t,i,n]),d=r.useCallback(async()=>{y(!0),b(null);try{const[x,f]=await Promise.all([o("/admin/gift-cards?limit=50"),o("/admin/gift-card-redemptions?limit=50").catch(()=>({redemptions:[]}))]),j=x.giftCards??[],k=f.redemptions??[],h=new Date,S=j.filter(m=>m.active&&(!m.expiresAt||new Date(m.expiresAt)>h)).length,T=j.filter(m=>m.expiresAt&&new Date(m.expiresAt)<=h).length,l=j.reduce((m,N)=>m+N.initialBalance,0),w=j.reduce((m,N)=>m+N.balance,0),_=k.reduce((m,N)=>m+N.faceValueCents,0),A=k.filter(m=>m.tokenMinted).length,g=j[0]?.currency||k[0]?.currency||"USD";a({totalCards:j.length,activeCards:S,expiredCards:T,totalIssuedCents:l,totalRemainingCents:w,totalRedeemedCents:_,redemptionCount:k.length,tokensMinted:A,currency:g.toUpperCase()})}catch(x){b(x instanceof Error?x.message:"Failed to load analytics")}finally{y(!1)}},[o]);r.useEffect(()=>{d()},[d]);const u=x=>`$${(x/100).toFixed(2)}`;if(c)return e.jsx("div",{className:"cedros-admin__loading",children:"Loading analytics..."});if(p)return e.jsxs("div",{style:{padding:"0.75rem",background:"rgba(220,38,38,0.08)",borderRadius:6,fontSize:13,color:"#b91c1c"},children:[p,e.jsx("button",{className:"cedros-admin__button cedros-admin__button--sm",style:{marginLeft:8},onClick:d,children:"Retry"})]});if(!s)return null;const v=s.totalIssuedCents>0?((s.totalIssuedCents-s.totalRemainingCents)/s.totalIssuedCents*100).toFixed(1):"0.0";return e.jsxs("div",{children:[e.jsx("h3",{className:"cedros-admin__section-title",style:{marginBottom:"1rem"},children:"Gift Card & Token Analytics"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(180px, 1fr))",gap:"0.75rem",marginBottom:"1.5rem"},children:[e.jsx($,{label:"Total Cards",value:String(s.totalCards)}),e.jsx($,{label:"Active",value:String(s.activeCards),accent:"green"}),e.jsx($,{label:"Expired",value:String(s.expiredCards),accent:s.expiredCards>0?"amber":void 0}),e.jsx($,{label:"Total Issued",value:u(s.totalIssuedCents),sub:s.currency}),e.jsx($,{label:"Remaining Balance",value:u(s.totalRemainingCents),sub:s.currency}),e.jsx($,{label:"Usage Rate",value:`${v}%`,sub:"issued vs. spent"}),e.jsx($,{label:"Redemptions",value:String(s.redemptionCount)}),e.jsx($,{label:"Tokens Minted",value:String(s.tokensMinted),sub:`of ${s.redemptionCount} redemptions`})]}),s.totalIssuedCents>0&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:13,fontWeight:500,marginBottom:6},children:"Balance Breakdown"}),e.jsxs("div",{style:{display:"flex",height:24,borderRadius:6,overflow:"hidden",background:"rgba(0,0,0,0.05)"},children:[e.jsx("div",{style:{width:`${(s.totalIssuedCents-s.totalRemainingCents)/s.totalIssuedCents*100}%`,background:"#2563eb",minWidth:2},title:`Spent: ${u(s.totalIssuedCents-s.totalRemainingCents)}`}),e.jsx("div",{style:{width:`${s.totalRemainingCents/s.totalIssuedCents*100}%`,background:"#60a5fa",minWidth:2},title:`Remaining: ${u(s.totalRemainingCents)}`})]}),e.jsxs("div",{style:{display:"flex",gap:"1rem",marginTop:6,fontSize:12,opacity:.7},children:[e.jsxs("span",{children:[e.jsx("span",{style:{display:"inline-block",width:10,height:10,background:"#2563eb",borderRadius:2,marginRight:4}}),"Spent"]}),e.jsxs("span",{children:[e.jsx("span",{style:{display:"inline-block",width:10,height:10,background:"#60a5fa",borderRadius:2,marginRight:4}}),"Remaining"]})]})]})]})}function $({label:t,value:i,sub:n,accent:s}){const a=s==="green"?"#166534":s==="amber"?"#92400e":void 0;return e.jsxs("div",{style:{padding:"0.75rem 1rem",borderRadius:8,border:"1px solid rgba(0,0,0,0.08)",background:"rgba(0,0,0,0.01)"},children:[e.jsx("div",{style:{fontSize:12,opacity:.6,marginBottom:4},children:t}),e.jsx("div",{style:{fontSize:20,fontWeight:700,color:a},children:i}),n&&e.jsx("div",{style:{fontSize:11,opacity:.5,marginTop:2},children:n})]})}function st({serverUrl:t,apiKey:i,authManager:n}){const[s,a]=r.useState([]),[c,y]=r.useState(!0),[p,b]=r.useState(null),[o,d]=r.useState("list"),[u,v]=r.useState(null),[x,f]=r.useState(!1),[j,k]=r.useState(null),h=r.useCallback(async(_,A)=>{if(n?.isAuthenticated())return n.fetchWithAuth(_,A);const g={"Content-Type":"application/json"};i&&(g["X-API-Key"]=i);const m=await fetch(`${t}${_}`,{...A,headers:{...g,...A?.headers}});if(!m.ok){const N=await m.text().catch(()=>`HTTP ${m.status}`);throw new Error(N)}return m.json()},[t,i,n]),S=r.useCallback(async()=>{y(!0),b(null);try{const A=await h(`/admin/gift-cards${x?"?activeOnly=true&limit=50":"?limit=50"}`);a(A.giftCards??[])}catch(_){b(_ instanceof Error?_.message:"Failed to load gift cards")}finally{y(!1)}},[h,x]);r.useEffect(()=>{S()},[S]);const T=(_,A)=>`$${(_/100).toFixed(2)} ${A.toUpperCase()}`,l=_=>{try{return new Date(_).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})}catch{return _}},w=_=>{v(_),d("adjust"),k(null)};return o==="create"?e.jsx(nt,{onSubmit:async _=>{await h("/admin/gift-cards",{method:"POST",body:JSON.stringify(_)}),d("list"),S()},onCancel:()=>d("list")}):o==="adjust"&&u?e.jsx(it,{card:u,formatCents:T,onSubmit:async _=>{await h(`/admin/gift-cards/${encodeURIComponent(u.code)}/adjust`,{method:"POST",body:JSON.stringify({newBalance:_})}),d("list"),S()},onToggleActive:async()=>{await h(`/admin/gift-cards/${encodeURIComponent(u.code)}`,{method:"PUT",body:JSON.stringify({initialBalance:u.initialBalance,balance:u.balance,currency:u.currency,active:!u.active,expiresAt:u.expiresAt,metadata:u.metadata})}),d("list"),S()},onCancel:()=>{d("list"),v(null)}}):e.jsxs("div",{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"1rem"},children:[e.jsx("h3",{className:"cedros-admin__section-title",style:{margin:0},children:"Gift Card Inventory"}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center"},children:[e.jsxs("label",{style:{fontSize:13,display:"flex",alignItems:"center",gap:4},children:[e.jsx("input",{type:"checkbox",checked:x,onChange:_=>f(_.target.checked)}),"Active only"]}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary cedros-admin__button--sm",onClick:()=>{d("create"),k(null)},children:"+ New Gift Card"})]})]}),p&&e.jsxs("div",{style:{padding:"0.75rem",background:"rgba(220,38,38,0.08)",borderRadius:6,marginBottom:"1rem",fontSize:13,color:"#b91c1c"},children:[p,e.jsx("button",{className:"cedros-admin__button cedros-admin__button--sm",style:{marginLeft:8},onClick:S,children:"Retry"})]}),j&&e.jsx("div",{style:{padding:"0.75rem",background:"rgba(22,163,74,0.08)",borderRadius:6,marginBottom:"1rem",fontSize:13,color:"#166534"},children:j}),c?e.jsx("div",{className:"cedros-admin__loading",children:"Loading..."}):s.length?e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Code"}),e.jsx("th",{children:"Balance"}),e.jsx("th",{children:"Initial"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Expires"}),e.jsx("th",{children:"Created"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:s.map(_=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsxs("code",{style:{fontSize:12},children:[_.code.slice(0,12),"..."]})}),e.jsx("td",{style:{fontWeight:600},children:T(_.balance,_.currency)}),e.jsx("td",{style:{opacity:.7},children:T(_.initialBalance,_.currency)}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge ${_.active?"cedros-admin__badge--success":"cedros-admin__badge--muted"}`,children:_.active?"Active":"Inactive"})}),e.jsx("td",{style:{fontSize:13},children:_.expiresAt?l(_.expiresAt):"—"}),e.jsx("td",{style:{fontSize:13},children:l(_.createdAt)}),e.jsx("td",{children:e.jsx("button",{className:"cedros-admin__button cedros-admin__button--outline cedros-admin__button--sm",onClick:()=>w(_),children:"Manage"})})]},_.code))})]})}):e.jsx("div",{className:"cedros-admin__empty",style:{padding:"2rem",textAlign:"center",opacity:.6},children:"No gift cards found."})]})}function nt({onSubmit:t,onCancel:i}){const[n,s]=r.useState({code:"",initialBalance:"",currency:"USD",expiresAt:""}),[a,c]=r.useState(!1),[y,p]=r.useState(null),b=async o=>{o.preventDefault();const d=Math.round(parseFloat(n.initialBalance)*100);if(!d||d<0){p("Initial balance must be positive");return}c(!0),p(null);try{await t({...n.code.trim()?{code:n.code.trim().toUpperCase()}:{},initialBalance:d,currency:n.currency.toUpperCase(),...n.expiresAt?{expiresAt:new Date(n.expiresAt).toISOString()}:{}})}catch(u){p(u instanceof Error?u.message:"Failed to create gift card")}finally{c(!1)}};return e.jsxs("div",{children:[e.jsx("h3",{className:"cedros-admin__section-title",style:{marginBottom:"1rem"},children:"Create Gift Card"}),y&&e.jsx("div",{style:{padding:"0.75rem",background:"rgba(220,38,38,0.08)",borderRadius:6,marginBottom:"1rem",fontSize:13,color:"#b91c1c"},children:y}),e.jsxs("form",{onSubmit:b,children:[e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Code (optional, auto-generated if empty)"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:n.code,onChange:o=>s(d=>({...d,code:o.target.value})),placeholder:"Leave blank to auto-generate"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Initial Balance ($)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:n.initialBalance,onChange:o=>s(d=>({...d,initialBalance:o.target.value})),placeholder:"25.00",step:"0.01",min:"0",required:!0})]})]}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Currency"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:n.currency,onChange:o=>s(d=>({...d,currency:o.target.value})),maxLength:3,required:!0})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Expiration date (optional)"}),e.jsx("input",{type:"date",className:"cedros-admin__input",value:n.expiresAt,onChange:o=>s(d=>({...d,expiresAt:o.target.value}))})]})]}),e.jsxs("div",{className:"cedros-admin__form-actions",style:{marginTop:"1rem"},children:[e.jsx("button",{type:"submit",className:"cedros-admin__button cedros-admin__button--primary",disabled:a,children:a?"Creating...":"Create Gift Card"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--outline",onClick:i,children:"Cancel"})]})]})]})}function it({card:t,formatCents:i,onSubmit:n,onToggleActive:s,onCancel:a}){const[c,y]=r.useState((t.balance/100).toFixed(2)),[p,b]=r.useState(!1),[o,d]=r.useState(null),u=async x=>{x.preventDefault();const f=Math.round(parseFloat(c)*100);if(isNaN(f)||f<0){d("Balance must be >= 0");return}b(!0),d(null);try{await n(f)}catch(j){d(j instanceof Error?j.message:"Failed to adjust balance")}finally{b(!1)}},v=async()=>{b(!0),d(null);try{await s()}catch(x){d(x instanceof Error?x.message:"Failed to update status"),b(!1)}};return e.jsxs("div",{children:[e.jsx("h3",{className:"cedros-admin__section-title",style:{marginBottom:"1rem"},children:"Manage Gift Card"}),o&&e.jsx("div",{style:{padding:"0.75rem",background:"rgba(220,38,38,0.08)",borderRadius:6,marginBottom:"1rem",fontSize:13,color:"#b91c1c"},children:o}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0.5rem",maxWidth:500,marginBottom:"1.5rem",fontSize:13},children:[e.jsx("div",{style:{fontWeight:500},children:"Code"}),e.jsx("div",{style:{fontFamily:"monospace",wordBreak:"break-all"},children:t.code}),e.jsx("div",{style:{fontWeight:500},children:"Current Balance"}),e.jsx("div",{style:{fontWeight:600},children:i(t.balance,t.currency)}),e.jsx("div",{style:{fontWeight:500},children:"Initial Balance"}),e.jsx("div",{children:i(t.initialBalance,t.currency)}),e.jsx("div",{style:{fontWeight:500},children:"Status"}),e.jsx("div",{children:e.jsx("span",{className:`cedros-admin__badge ${t.active?"cedros-admin__badge--success":"cedros-admin__badge--muted"}`,children:t.active?"Active":"Inactive"})}),t.expiresAt&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{fontWeight:500},children:"Expires"}),e.jsx("div",{children:new Date(t.expiresAt).toLocaleDateString()})]})]}),e.jsxs("form",{onSubmit:u,children:[e.jsxs("div",{className:"cedros-admin__field",style:{maxWidth:250},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"New Balance ($)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:c,onChange:x=>y(x.target.value),step:"0.01",min:"0",required:!0})]}),e.jsxs("div",{className:"cedros-admin__form-actions",style:{marginTop:"1rem",display:"flex",gap:"0.5rem"},children:[e.jsx("button",{type:"submit",className:"cedros-admin__button cedros-admin__button--primary",disabled:p,children:p?"Saving...":"Adjust Balance"}),e.jsx("button",{type:"button",className:`cedros-admin__button ${t.active?"cedros-admin__button--danger":"cedros-admin__button--outline"}`,onClick:v,disabled:p,children:t.active?"Deactivate":"Reactivate"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--outline",onClick:a,children:"Back"})]})]})]})}const at=0;class Ce{dlmmModule=null;bnClass=null;keypairClass=null;async loadDLMM(){if(this.dlmmModule)return this.dlmmModule;try{const i=await Promise.resolve().then(()=>require("./pay-react_false-DaeIe3_l.js"));return this.dlmmModule=i.default??i,this.dlmmModule}catch{throw new Error("Install @meteora-ag/dlmm to enable pool deployment: npm install @meteora-ag/dlmm")}}async loadBN(){if(this.bnClass)return this.bnClass;const i=await Promise.resolve().then(()=>require("./bn-CHyy7EgJ.js")).then(n=>n.bn);return this.bnClass=i.default??i,this.bnClass}async loadKeypair(){if(this.keypairClass)return this.keypairClass;const{Keypair:i}=await import("@solana/web3.js");return this.keypairClass=i,this.keypairClass}async computeBinId(i,n,s,a=1){const c=await this.loadDLMM(),y=c.getPricePerLamport(n,s,i);return c.getBinIdFromPrice(y,a,!0)}async findPresetParameter(i,n,s){const a=await this.loadDLMM(),c=s?{cluster:s}:void 0,{presetParameter2:y}=await a.getAllPresetParameters(i,c),p=y.find(b=>b.account.binStep===n);if(!p)throw new Error(`No PresetParameter2 found for binStep=${n}. Available: ${y.map(b=>b.account.binStep).join(", ")}`);return p.publicKey}async createPool(i,n,s,a,c,y=1,p){const b=await this.loadDLMM(),o=await this.loadBN(),d=p?{cluster:p}:void 0,u=await this.findPresetParameter(i,y,p),v=await b.createLbPair2(i,n,s,a,u,new o(c),d),x=v.instructions[0]?.keys?.[1]?.pubkey;if(!x)throw new Error("Failed to extract pool address from transaction");return{transaction:v,poolAddress:x}}async addBuybackLiquidity(i,n,s,a,c,y){const p=await this.loadDLMM(),b=await this.loadBN(),o=await this.loadKeypair(),d=y?{cluster:y}:void 0,u=await p.create(i,s,d),v=o.generate(),x=c-1,f=c;return{transaction:await u.initializePositionAndAddLiquidityByStrategy({positionPubKey:v.publicKey,totalXAmount:new b(0),totalYAmount:new b(a),strategy:{maxBinId:f,minBinId:x,strategyType:at},user:n,slippage:1}),positionKeypair:v}}async getPoolStatus(i,n,s){const a=await this.loadDLMM(),c=s?{cluster:s}:void 0,y=await a.create(i,n,c),p=await y.getActiveBin();return{address:n.toBase58(),activeBinId:p.binId,activeBinPrice:p.price,binStep:y.lbPair.binStep}}}const he=6,rt=1,ot="https://solscan.io/account",lt="https://app.meteora.ag/dlmm";function dt({serverUrl:t,authManager:i,poolAddress:n,buybackRateBps:s,usdcAmount:a,deployedAt:c,mintAddress:y,tokenDecimals:p=2,onConfigUpdated:b}){const[o,d]=r.useState("none"),[u,v]=r.useState(s!=null?s/100:80),[x,f]=r.useState(100),[j,k]=r.useState(!1),[h,S]=r.useState(!1),[T,l]=r.useState(null),[w,_]=r.useState(null),A=s!=null?`$${(s/1e4).toFixed(2)}`:"Unknown",g=a!=null?`$${(a/10**he).toFixed(2)}`:null,m=c?new Date(c).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"}):null,N=n.length>16?`${n.slice(0,8)}...${n.slice(-8)}`:n,C=async()=>{k(!0),_(null),l(null);try{const B=new ee.ConfigApiClient(t,void 0,i),R=Math.round(u*100);await B.patchConfig("gift_cards",{buyback_rate_bps:R},`Buyback rate adjusted to ${u} cents`),l("Buyback rate updated"),d("none"),b()}catch(B){_(B instanceof Error?B.message:"Failed to update rate")}finally{k(!1)}},z=async()=>{if(y){S(!0),_(null),l(null);try{const{Connection:B,PublicKey:R,Keypair:M}=await import("@solana/web3.js"),F=new ee.ConfigApiClient(t,void 0,i),I=await F.getConfig("x402"),D=I.config?.rpc_url||"",P=I.config?.token_mint||"";if(!D||!P)throw new Error("RPC URL or USDC mint not configured");const L=new B(D,"confirmed"),O=window.solana;if(!O?.publicKey||!O.signTransaction)throw new Error("Wallet not connected");const se=new Ce,le=new R(O.publicKey.toBase58()),E=u/100,de=await se.computeBinId(E,p,he,rt),ne=new R(n),H=Math.round(x*10**he),{transaction:J,positionKeypair:W}=await se.addBuybackLiquidity(L,le,ne,H,de),V=M.fromSecretKey(W.secretKey);J.partialSign(V);const Y=await O.signTransaction(J),X=await L.sendRawTransaction(Y.serialize());await L.confirmTransaction(X,"confirmed");const Z=a??0;await F.patchConfig("gift_cards",{liquidity_usdc_amount:Z+H},`Added ${x} USDC liquidity`),l(`Added $${x} USDC liquidity`),d("none"),b()}catch(B){_(B instanceof Error?B.message:"Failed to add liquidity")}finally{S(!1)}}};return e.jsxs("div",{children:[e.jsx("h3",{className:"cedros-admin__section-title",style:{marginBottom:"1rem"},children:"Liquidity Pool Active"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0.75rem",maxWidth:600},children:[e.jsx("div",{style:{fontWeight:500,fontSize:13},children:"Pool Address"}),e.jsxs("div",{style:{fontSize:13,fontFamily:"monospace",wordBreak:"break-all"},children:[N,e.jsxs("span",{style:{marginLeft:8,display:"inline-flex",gap:6},children:[e.jsx(ct,{text:n}),e.jsx(_e,{href:`${ot}/${n}`,label:"Solscan"}),e.jsx(_e,{href:`${lt}/${n}`,label:"Meteora"})]})]}),e.jsx("div",{style:{fontWeight:500,fontSize:13},children:"Buyback Rate"}),e.jsxs("div",{style:{fontSize:13},children:[A," per $1.00"]}),g&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{fontWeight:500,fontSize:13},children:"USDC Deposited"}),e.jsx("div",{style:{fontSize:13},children:g})]}),m&&e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{fontWeight:500,fontSize:13},children:"Deployed"}),e.jsx("div",{style:{fontSize:13},children:m})]})]}),e.jsxs("div",{style:{marginTop:"1.25rem",display:"flex",gap:"0.5rem"},children:[e.jsx("button",{className:"cedros-admin__button",onClick:()=>d(o==="adjust_rate"?"none":"adjust_rate"),disabled:h||j,children:"Adjust Rate"}),e.jsx("button",{className:"cedros-admin__button",onClick:()=>d(o==="add_liquidity"?"none":"add_liquidity"),disabled:h||j||!y,children:"Add Liquidity"})]}),o==="adjust_rate"&&e.jsxs("div",{style:{marginTop:"1rem",padding:"1rem",borderRadius:8,border:"1px solid var(--cedros-admin-border, #e5e7eb)"},children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"New buyback rate (cents per $1.00)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:u,onChange:B=>v(Math.max(1,Math.min(99,parseInt(B.target.value)||80))),min:"1",max:"99",style:{maxWidth:200}}),e.jsxs("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:["Profit per redemption: $",((100-u)/100).toFixed(2)]})]}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:C,disabled:j,style:{marginTop:"0.75rem"},children:j?"Saving...":"Save Rate"})]}),o==="add_liquidity"&&e.jsxs("div",{style:{marginTop:"1rem",padding:"1rem",borderRadius:8,border:"1px solid var(--cedros-admin-border, #e5e7eb)"},children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"USDC amount to add"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:x,onChange:B=>f(Math.max(1,parseFloat(B.target.value)||100)),min:"1",step:"1",style:{maxWidth:200}})]}),e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:z,disabled:h,style:{marginTop:"0.75rem"},children:h?"Adding liquidity...":`Add $${x} USDC`}),e.jsx("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:"Requires a connected wallet and USDC balance."})]}),T&&e.jsx("div",{style:{marginTop:"0.75rem",padding:"0.5rem 0.75rem",borderRadius:6,background:"rgba(22,163,74,0.1)",color:"#16a34a",fontSize:13},children:T}),w&&e.jsx("div",{style:{marginTop:"0.75rem",padding:"0.5rem 0.75rem",borderRadius:6,background:"rgba(239,68,68,0.1)",color:"#dc2626",fontSize:13},children:w})]})}function ct({text:t}){const[i,n]=r.useState(!1),s=()=>{navigator.clipboard.writeText(t).then(()=>{n(!0),setTimeout(()=>n(!1),1500)})};return e.jsx("button",{type:"button",onClick:s,style:{background:"none",border:"none",cursor:"pointer",fontSize:12,opacity:.7,padding:0},children:i?"Copied":"Copy"})}function _e({href:t,label:i}){return e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",style:{fontSize:12,opacity:.7},children:i})}const ie=6,ge=1;function ut({serverUrl:t,authManager:i,mintConfigured:n,mintAddress:s,tokenDecimals:a=2}){const[c,y]=r.useState({liquidityPoolAddress:null,buybackRateBps:null,rpcUrl:null,usdcMint:null,usdcAmount:null,deployedAt:null}),[p,b]=r.useState(!0),[o,d]=r.useState(80),[u,v]=r.useState(250),[x,f]=r.useState("idle"),[j,k]=r.useState(null),[h,S]=r.useState(null),[T,l]=r.useState(null),w=r.useRef(new Ce),_=r.useCallback(async()=>{try{const R=new ee.ConfigApiClient(t,void 0,i),[M,F]=await Promise.all([R.getConfig("gift_cards"),R.getConfig("x402")]),I=M.config??{},D=F.config??{},P=I.liquidity_pool_address||null;y({liquidityPoolAddress:P,buybackRateBps:I.buyback_rate_bps!=null?Number(I.buyback_rate_bps):null,rpcUrl:D.rpc_url||null,usdcMint:D.token_mint||null,usdcAmount:I.liquidity_usdc_amount!=null?Number(I.liquidity_usdc_amount):null,deployedAt:I.liquidity_deployed_at||null}),P&&S(P),I.buyback_rate_bps!=null&&d(Number(I.buyback_rate_bps)/100)}catch{}finally{b(!1)}},[t,i]);r.useEffect(()=>{_()},[_]);const A=typeof window<"u"&&!!window.solana?.publicKey,g=!!c.rpcUrl,m=!!c.usdcMint,N=n&&A&&g&&m&&x==="idle",C=async R=>{if(!(!s||!c.rpcUrl||!c.usdcMint)){f(R),k(null),l(null);try{const{Connection:M,PublicKey:F,Keypair:I}=await import("@solana/web3.js"),D=new M(c.rpcUrl,"confirmed"),P=window.solana;if(!P?.publicKey||!P.signTransaction)throw new Error("Wallet not connected");const L=w.current,O=new F(P.publicKey.toBase58()),se=o/100,le=await L.computeBinId(se,a,ie,ge);let E=h;if(R==="creating_pool"){const W=new F(s),V=new F(c.usdcMint),Y=await L.computeBinId(1,a,ie,ge),{transaction:X,poolAddress:Z}=await L.createPool(D,O,W,V,Y,ge),ce=await P.signTransaction(X),ue=await D.sendRawTransaction(ce.serialize());await D.confirmTransaction(ue,"confirmed"),E=Z.toBase58(),S(E)}if(R==="creating_pool"||R==="adding_liquidity"){if(f("adding_liquidity"),!E)throw new Error("Pool address not available");const W=new F(E),V=Math.round(u*10**ie),{transaction:Y,positionKeypair:X}=await L.addBuybackLiquidity(D,O,W,V,le),Z=I.fromSecretKey(X.secretKey);Y.partialSign(Z);const ce=await P.signTransaction(Y),ue=await D.sendRawTransaction(ce.serialize());await D.confirmTransaction(ue,"confirmed")}if(f("saving_config"),!E)throw new Error("Pool address not available");const de=new ee.ConfigApiClient(t,void 0,i),ne=Math.round(o*100),H=Math.round(u*10**ie),J=new Date().toISOString();await de.patchConfig("gift_cards",{liquidity_pool_address:E,buyback_rate_bps:ne,liquidity_usdc_amount:H,liquidity_deployed_at:J},"Meteora DLMM pool deployed for gift card buyback"),y(W=>({...W,liquidityPoolAddress:E,buybackRateBps:ne,usdcAmount:H,deployedAt:J})),f("done")}catch(M){l(x==="idle"?R:x),k(M instanceof Error?M.message:"Deployment failed"),f("error")}}},z=()=>{N&&C("creating_pool")},B=()=>{!T||T==="idle"||T==="done"||T==="error"||C(T)};return p?e.jsx("div",{style:{padding:"2rem",textAlign:"center",opacity:.6},children:"Loading pool configuration..."}):c.liquidityPoolAddress?e.jsx(dt,{serverUrl:t,authManager:i,poolAddress:c.liquidityPoolAddress,buybackRateBps:c.buybackRateBps,usdcAmount:c.usdcAmount,deployedAt:c.deployedAt,mintAddress:s,tokenDecimals:a,onConfigUpdated:_}):x!=="idle"&&x!=="error"?e.jsx(pt,{step:x,poolAddress:h}):e.jsx(mt,{buybackCents:o,setBuybackCents:d,usdcAmount:u,setUsdcAmount:v,mintConfigured:n,walletConnected:A,hasRpcUrl:g,hasUsdcMint:m,canDeploy:N,onDeploy:z,errorMessage:j,canRetry:!!T&&T!=="creating_pool",onRetry:B})}function mt({buybackCents:t,setBuybackCents:i,usdcAmount:n,setUsdcAmount:s,mintConfigured:a,walletConnected:c,hasRpcUrl:y,hasUsdcMint:p,canDeploy:b,onDeploy:o,errorMessage:d,canRetry:u,onRetry:v}){const x=((100-t)/100).toFixed(2);return e.jsxs("div",{children:[e.jsx("h3",{className:"cedros-admin__section-title",style:{marginBottom:"0.5rem"},children:"Deploy Buyback Liquidity Pool"}),e.jsx("p",{style:{opacity:.7,marginBottom:"1rem",fontSize:14},children:"Create a Meteora DLMM pool to buy back gift card tokens at a discount. You earn the spread when tokens are resold at face value."}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Buyback rate (cents per $1.00)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:t,onChange:f=>i(Math.max(1,Math.min(99,parseInt(f.target.value)||80))),min:"1",max:"99"}),e.jsxs("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:["You earn $",x," profit per gift card redeemed"]})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"USDC amount"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:n,onChange:f=>s(Math.max(1,parseFloat(f.target.value)||250)),min:"1",step:"1"}),e.jsx("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:"Minimum recommended: $250"})]})]}),e.jsxs("div",{style:{margin:"1rem 0",display:"flex",flexDirection:"column",gap:6},children:[e.jsx(ae,{label:"Token-22 mint initialized",met:a}),e.jsx(ae,{label:"Wallet connected",met:c}),e.jsx(ae,{label:"RPC URL configured",met:y}),e.jsx(ae,{label:"USDC mint configured",met:p})]}),d&&e.jsx("div",{style:{padding:"0.5rem 0.75rem",marginBottom:"0.75rem",borderRadius:6,background:"rgba(239,68,68,0.1)",color:"#dc2626",fontSize:13},children:d}),e.jsx("div",{style:{display:"flex",gap:"0.75rem",alignItems:"center"},children:u?e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:v,children:"Retry (Resume from Failed Step)"}):e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:o,disabled:!b,children:"Deploy Liquidity Pool"})})]})}const ve=[{key:"creating_pool",label:"Creating DLMM pool..."},{key:"adding_liquidity",label:"Depositing USDC liquidity..."},{key:"saving_config",label:"Saving configuration..."},{key:"done",label:"Complete"}];function pt({step:t,poolAddress:i}){return e.jsxs("div",{children:[e.jsx("h3",{className:"cedros-admin__section-title",style:{marginBottom:"1rem"},children:"Deploying Pool..."}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:ve.map((n,s)=>{const a=ve.findIndex(b=>b.key===t),c=s,y=c<a||t==="done",p=c===a&&t!=="done";return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:14},children:[e.jsx("span",{style:{width:20,textAlign:"center",fontWeight:600},children:y?"✓":p?"▶":"○"}),e.jsx("span",{style:{opacity:y||p?1:.4},children:n.label})]},n.key)})}),i&&e.jsxs("div",{style:{marginTop:"1rem",fontSize:13,opacity:.7},children:["Pool: ",e.jsx("code",{style:{fontSize:12},children:i})]})]})}function ae({label:t,met:i}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,fontSize:13},children:[e.jsx("span",{style:{color:i?"#16a34a":"#dc2626",fontWeight:600},children:i?"✓":"✗"}),e.jsx("span",{style:{opacity:i?.8:.5},children:t})]})}function ht({serverUrl:t,apiKey:i,authManager:n}){const[s,a]=r.useState(null),[c,y]=r.useState([]),[p,b]=r.useState(!0),[o,d]=r.useState(null),[u,v]=r.useState("mint"),[x,f]=r.useState({treasuryAddress:"",tokenSymbol:"storeUSD",tokenDecimals:2,transferFeeBps:250,maxTransferFee:500}),[j,k]=r.useState(!1),[h,S]=r.useState(!1),[T,l]=r.useState(null),w=r.useCallback(async(C,z)=>{if(n?.isAuthenticated())return n.fetchWithAuth(C,z);const B={"Content-Type":"application/json"};i&&(B["X-API-Key"]=i);const R=await fetch(`${t}${C}`,{...z,headers:{...B,...z?.headers}});if(!R.ok){const M=await R.text().catch(()=>`HTTP ${R.status}`);throw new Error(M)}return R.json()},[t,i,n]),_=r.useCallback(async()=>{try{d(null);const C=await w("/admin/token22/status");a(C)}catch{d("Failed to load Token-22 status")}finally{b(!1)}},[w]),A=r.useCallback(async()=>{try{const C=await w("/admin/gift-card-redemptions?limit=50");y(C.redemptions||[])}catch{y([])}},[w]);r.useEffect(()=>{_(),A()},[_,A]);const g=async C=>{if(C.preventDefault(),!!x.treasuryAddress){k(!0),l(null);try{const z=await w("/admin/token22/initialize",{method:"POST",body:JSON.stringify({treasuryAddress:x.treasuryAddress,tokenSymbol:x.tokenSymbol,tokenDecimals:x.tokenDecimals,transferFeeBps:x.transferFeeBps,maxTransferFee:x.maxTransferFee})});l(`Mint created: ${z.mintAddress}`),_()}catch(z){l(`Error: ${z instanceof Error?z.message:"Failed to initialize"}`)}finally{k(!1)}}},m=async()=>{S(!0),l(null);try{const C=await w("/admin/token22/harvest-fees",{method:"POST"});l(C.message)}catch(C){l(`Error: ${C instanceof Error?C.message:"Failed to harvest"}`)}finally{S(!1)}},N=C=>{try{return new Date(C).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return C}};return e.jsxs("div",{className:"cedros-admin__page",children:[e.jsx(ze.ErrorBanner,{message:o,onRetry:_}),e.jsx("div",{style:{display:"flex",gap:0,borderBottom:"1px solid rgba(0,0,0,0.1)",marginBottom:"1rem"},children:["mint","inventory","analytics","redemptions","compliance","liquidity","asset-classes","asset-redemptions"].map(C=>{const z={mint:"Token-22 Mint",inventory:"Gift Cards",analytics:"Analytics",redemptions:"Redemptions",compliance:"Compliance",liquidity:"Liquidity","asset-classes":"Asset Classes","asset-redemptions":"Asset Redemptions"};return e.jsx("button",{type:"button",onClick:()=>v(C),style:{padding:"0.5rem 1rem",background:"none",border:"none",borderBottom:u===C?"2px solid currentColor":"2px solid transparent",fontWeight:u===C?600:400,cursor:"pointer",opacity:u===C?1:.6},children:z[C]},C)})}),p?e.jsxs("div",{className:"cedros-admin__loading",children:[Re.Icons.loading," Loading..."]}):u==="mint"?e.jsx(gt,{mintStatus:s,initForm:x,setInitForm:f,isInitializing:j,isHarvesting:h,actionMessage:T,onInitialize:g,onHarvestFees:m,formatDate:N}):u==="inventory"?e.jsx(st,{serverUrl:t,apiKey:i,authManager:n}):u==="analytics"?e.jsx(tt,{serverUrl:t,apiKey:i,authManager:n}):u==="redemptions"?e.jsx(yt,{redemptions:c,formatDate:N}):u==="compliance"?e.jsx(He,{serverUrl:t,apiKey:i,authManager:n}):u==="liquidity"?e.jsx(ut,{serverUrl:t,authManager:n,mintConfigured:!!s?.configured,mintAddress:s?.mintAddress,tokenDecimals:s?.tokenDecimals}):u==="asset-classes"?e.jsx(Le,{serverUrl:t,apiKey:i,authManager:n,onNavigateToLiquidity:()=>v("liquidity")}):e.jsx(Ye,{serverUrl:t,apiKey:i,authManager:n})]})}function gt({mintStatus:t,initForm:i,setInitForm:n,isInitializing:s,isHarvesting:a,actionMessage:c,onInitialize:y,onHarvestFees:p,formatDate:b}){return t?.configured?e.jsxs("div",{children:[e.jsx("h3",{className:"cedros-admin__section-title",style:{marginBottom:"1rem"},children:"Token-22 Mint Status"}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0.75rem",maxWidth:600},children:[e.jsx(q,{label:"Mint Address",value:t.mintAddress,mono:!0}),e.jsx(q,{label:"Token Symbol",value:t.tokenSymbol}),e.jsx(q,{label:"Decimals",value:String(t.tokenDecimals)}),e.jsx(q,{label:"Transfer Fee",value:`${t.transferFeeBps} bps (${((t.transferFeeBps??0)/100).toFixed(2)}%)`}),e.jsx(q,{label:"Max Transfer Fee",value:String(t.maxTransferFee)}),e.jsx(q,{label:"Treasury",value:t.treasuryAddress,mono:!0}),e.jsx(q,{label:"Authority",value:t.mintAuthority,mono:!0}),e.jsx(q,{label:"Created",value:t.createdAt?b(t.createdAt):"—"})]}),e.jsxs("div",{style:{marginTop:"1.5rem",display:"flex",gap:"0.75rem",alignItems:"center"},children:[e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary",onClick:p,disabled:a,children:a?"Harvesting...":"Harvest Transfer Fees"}),c&&e.jsx("span",{style:{fontSize:13,opacity:.8},children:c})]})]}):e.jsxs("div",{children:[e.jsx("h3",{className:"cedros-admin__section-title",style:{marginBottom:"0.5rem"},children:"Initialize Token-22 Mint"}),e.jsx("p",{style:{opacity:.7,marginBottom:"1rem",fontSize:14},children:"Create a Token-22 mint with transfer fee extension for the secondary market. This is a one-time operation per tenant."}),e.jsxs("form",{onSubmit:y,children:[e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Treasury address (Solana)"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:i.treasuryAddress,onChange:o=>n(d=>({...d,treasuryAddress:o.target.value})),placeholder:"e.g., 7xKX...",required:!0})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Token symbol"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:i.tokenSymbol,onChange:o=>n(d=>({...d,tokenSymbol:o.target.value})),placeholder:"storeUSD"})]})]}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Token decimals"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:i.tokenDecimals,onChange:o=>n(d=>({...d,tokenDecimals:parseInt(o.target.value)||2})),min:"0",max:"9"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Transfer fee (basis points)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:i.transferFeeBps,onChange:o=>n(d=>({...d,transferFeeBps:parseInt(o.target.value)||0})),min:"0",max:"10000"}),e.jsx("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:"e.g., 250 = 2.5% fee on secondary market transfers"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Max transfer fee (atomic)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:i.maxTransferFee,onChange:o=>n(d=>({...d,maxTransferFee:parseInt(o.target.value)||0})),min:"0"})]})]}),e.jsxs("div",{className:"cedros-admin__form-actions",style:{marginTop:"1rem"},children:[e.jsx("button",{type:"submit",className:"cedros-admin__button cedros-admin__button--primary",disabled:s,children:s?"Creating Mint...":"Initialize Mint"}),c&&e.jsx("span",{style:{marginLeft:"0.75rem",fontSize:13,opacity:.8},children:c})]})]})]})}function q({label:t,value:i,mono:n}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{style:{fontWeight:500,fontSize:13},children:t}),e.jsx("div",{style:{fontSize:13,fontFamily:n?"monospace":"inherit",wordBreak:n?"break-all":"normal",opacity:i?1:.5},children:i||"—"})]})}function yt({redemptions:t,formatDate:i}){return t.length?e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Date"}),e.jsx("th",{children:"Order"}),e.jsx("th",{children:"Product"}),e.jsx("th",{children:"Buyer"}),e.jsx("th",{children:"Recipient"}),e.jsx("th",{children:"Value"}),e.jsx("th",{children:"Token Minted"})]})}),e.jsx("tbody",{children:t.map(n=>e.jsxs("tr",{children:[e.jsx("td",{style:{whiteSpace:"nowrap"},children:i(n.createdAt)}),e.jsx("td",{children:e.jsxs("code",{style:{fontSize:12},children:[n.orderId.slice(0,8),"..."]})}),e.jsx("td",{children:e.jsx("code",{style:{fontSize:12},children:n.productId})}),e.jsx("td",{children:e.jsxs("code",{style:{fontSize:12},children:[n.buyerUserId.slice(0,8),"..."]})}),e.jsx("td",{children:e.jsxs("code",{style:{fontSize:12},children:[n.recipientUserId.slice(0,8),"..."]})}),e.jsxs("td",{children:["$",(n.faceValueCents/100).toFixed(2)," ",n.currency.toUpperCase()]}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge ${n.tokenMinted?"cedros-admin__badge--success":"cedros-admin__badge--muted"}`,children:n.tokenMinted?"Yes":"No"})})]},n.id))})]})}):e.jsx("div",{style:{padding:"2rem",textAlign:"center",opacity:.6},children:"No gift card redemptions yet."})}exports.Token22Section=ht;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("react"),q=require("./sectionIds-B_tFiNvF.js"),D=require("./ErrorBanner-Cx2dUhps.js"),E=require("./dateHelpers-BKW_lGND.js"),U=n=>n==="success"?"success":n==="failed"?"failed":n==="pending"||n==="processing"?"pending":"muted",x=(n,d=48)=>n.length>d?`${n.slice(0,d)}…`:n;function O({serverUrl:n,apiKey:d,authManager:j}){const[a,L]=s.useState("active"),[y,p]=s.useState([]),[c,W]=s.useState(0),[h,C]=s.useState("all"),[N,f]=s.useState(!0),[_,g]=s.useState([]),[k,T]=s.useState(0),[F,v]=s.useState(!1),[w,A]=s.useState(!1),[$,l]=s.useState(null),[z,o]=s.useState(null),r=s.useCallback(async(t,i)=>{if(j?.isAuthenticated())return j.fetchWithAuth(t,i);const S={"Content-Type":"application/json"};d&&(S["X-API-Key"]=d);const u=await fetch(`${n}${t}`,{...i,headers:{...S,...i?.headers}});if(!u.ok)throw new Error(`Request failed: ${u.status}`);if(u.status!==204)return u.json()},[n,d,j]),m=s.useCallback(async()=>{f(!0),l(null);try{const t=new URLSearchParams({limit:"100"});h!=="all"&&t.set("status",h);const i=await r(`/admin/webhooks?${t.toString()}`);p(i.webhooks??[]),W(i.count??0)}catch{l("Failed to load webhooks"),p([])}finally{f(!1)}},[r,h]);s.useEffect(()=>{m()},[m]);const b=s.useCallback(async()=>{v(!0),l(null);try{const t=await r("/admin/webhooks/dlq?limit=100");g(t.webhooks??[]),T(t.count??0),A(!0)}catch{l("Failed to load DLQ webhooks"),g([])}finally{v(!1)}},[r]),R=t=>{L(t),l(null),o(null),t==="dlq"&&!w&&b()},I=async t=>{o(null);try{await r(`/admin/webhooks/${encodeURIComponent(t)}/retry`,{method:"POST"}),m()}catch{o("Failed to retry webhook")}},B=async t=>{if(window.confirm("Delete this webhook?")){o(null);try{await r(`/admin/webhooks/${encodeURIComponent(t)}`,{method:"DELETE"}),m()}catch{o("Failed to delete webhook")}}},Q=async t=>{o(null);try{await r(`/admin/webhooks/dlq/${encodeURIComponent(t)}/retry`,{method:"POST"}),b()}catch{o("Failed to retry DLQ webhook")}},P=async t=>{if(window.confirm("Delete this DLQ entry?")){o(null);try{await r(`/admin/webhooks/dlq/${encodeURIComponent(t)}`,{method:"DELETE"}),b()}catch{o("Failed to delete DLQ entry")}}};return e.jsxs("div",{children:[e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Webhooks"})}),e.jsx(D.ErrorBanner,{message:$}),e.jsx(D.ErrorBanner,{message:z}),e.jsx("div",{style:{display:"flex",gap:"0.25rem",marginBottom:"1rem",borderBottom:"1px solid var(--cedros-admin-border, #e0e0e0)"},children:["active","dlq"].map(t=>e.jsx("button",{type:"button",onClick:()=>R(t),style:{padding:"0.5rem 1rem",fontSize:"0.85rem",fontWeight:a===t?600:400,background:"none",border:"none",borderBottom:a===t?"2px solid var(--cedros-admin-primary, #000)":"2px solid transparent",cursor:"pointer",color:a===t?"var(--cedros-admin-text, #333)":"var(--cedros-admin-text-muted, #888)",marginBottom:"-1px"},children:t==="active"?`Active Webhooks${c>0?` (${c})`:""}`:`Dead Letter Queue${k>0?` (${k})`:""}`},t))}),a==="active"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",gap:"0.5rem",marginBottom:"1rem",alignItems:"center"},children:[e.jsxs("select",{className:"cedros-admin__input",value:h,onChange:t=>{C(t.target.value)},style:{width:"auto",fontSize:"0.85rem"},children:[e.jsx("option",{value:"all",children:"All statuses"}),e.jsx("option",{value:"pending",children:"Pending"}),e.jsx("option",{value:"processing",children:"Processing"}),e.jsx("option",{value:"failed",children:"Failed"}),e.jsx("option",{value:"success",children:"Success"})]}),e.jsxs("span",{style:{fontSize:"0.85rem",color:"var(--cedros-admin-text-muted, #888)"},children:[c," webhook",c!==1?"s":""]})]}),N?e.jsxs("div",{className:"cedros-admin__loading",children:[q.Icons.loading," Loading webhooks..."]}):y.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No webhooks found."}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"URL"}),e.jsx("th",{children:"Event Type"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Attempts"}),e.jsx("th",{children:"Last Error"}),e.jsx("th",{children:"Created"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:y.map(t=>e.jsxs("tr",{children:[e.jsx("td",{style:{maxWidth:"200px"},children:e.jsx("span",{title:t.url,style:{fontSize:"0.8rem",fontFamily:"monospace"},children:x(t.url,40)})}),e.jsx("td",{style:{fontSize:"0.85rem"},children:t.eventType}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${U(t.status)}`,children:t.status})}),e.jsxs("td",{style:{fontSize:"0.85rem"},children:[t.attempts,"/",t.maxAttempts]}),e.jsx("td",{style:{fontSize:"0.8rem",maxWidth:"180px",color:"var(--cedros-admin-text-muted, #888)"},children:t.lastError?e.jsx("span",{title:t.lastError,children:x(t.lastError,40)}):"—"}),e.jsx("td",{style:{fontSize:"0.8rem"},children:E.formatDateTime(t.createdAt)}),e.jsx("td",{children:e.jsxs("div",{style:{display:"flex",gap:"0.25rem"},children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>I(t.id),children:"Retry"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>B(t.id),style:{color:"var(--cedros-admin-danger, #c00)"},children:"Delete"})]})})]},t.id))})]})})]}),a==="dlq"&&e.jsx(e.Fragment,{children:F?e.jsxs("div",{className:"cedros-admin__loading",children:[q.Icons.loading," Loading DLQ..."]}):_.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"Dead Letter Queue is empty."}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"URL"}),e.jsx("th",{children:"Event Type"}),e.jsx("th",{children:"Attempts"}),e.jsx("th",{children:"Final Error"}),e.jsx("th",{children:"Moved to DLQ"}),e.jsx("th",{})]})}),e.jsx("tbody",{children:_.map(t=>e.jsxs("tr",{children:[e.jsx("td",{style:{maxWidth:"200px"},children:e.jsx("span",{title:t.url,style:{fontSize:"0.8rem",fontFamily:"monospace"},children:x(t.url,40)})}),e.jsx("td",{style:{fontSize:"0.85rem"},children:t.eventType}),e.jsx("td",{style:{fontSize:"0.85rem"},children:t.totalAttempts}),e.jsx("td",{style:{fontSize:"0.8rem",maxWidth:"200px",color:"var(--cedros-admin-text-muted, #888)"},children:e.jsx("span",{title:t.finalError,children:x(t.finalError,40)})}),e.jsx("td",{style:{fontSize:"0.8rem"},children:E.formatDateTime(t.movedToDlqAt)}),e.jsx("td",{children:e.jsxs("div",{style:{display:"flex",gap:"0.25rem"},children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>Q(t.id),children:"Retry"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>P(t.id),style:{color:"var(--cedros-admin-danger, #c00)"},children:"Delete"})]})})]},t.id))})]})})})]})}exports.WebhooksSection=O;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("react/jsx-runtime"),x=require("react"),M=require("./index-WcOlBYZJ.js"),g=require("./fetchWithTimeout-CG0EKbhf.js"),C=x.lazy(async()=>({default:(await Promise.resolve().then(()=>require("./CedrosPayAdminDashboard-CAwEvn66.js"))).CedrosPayAdminDashboard}));function A(r){return e.jsx(x.Suspense,{fallback:null,children:e.jsx(C,{...r})})}function m(){return e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M20 7.5v9l-4 2.25M4 7.5v9l4 2.25"}),e.jsx("path",{d:"m20 7.5-8-4.5-8 4.5"}),e.jsx("path",{d:"m12 12 8-4.5M12 12v9.5M12 12 4 7.5"})]})}function k(){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M12 2v20M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"})})}function v(){return e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z"}),e.jsx("path",{d:"M13 5v2M13 17v2M13 11v2"})]})}function w(){return e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),e.jsx("path",{d:"M3 3v5h5"}),e.jsx("path",{d:"M12 7v5l4 2"})]})}function y(){return e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function S(){return e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1"}),e.jsx("path",{d:"M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4"})]})}const d={products:()=>e.jsx(m,{}),transactions:()=>e.jsx(k,{}),coupons:()=>e.jsx(v,{}),refunds:()=>e.jsx(w,{}),settings:()=>e.jsx(y,{}),wallet:()=>e.jsx(S,{})},b={products:e.jsx(m,{}),transactions:e.jsx(k,{}),coupons:e.jsx(v,{}),refunds:e.jsx(w,{}),settings:e.jsx(y,{}),wallet:e.jsx(S,{}),chevronRight:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),loading:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"cedros-admin__spinner",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})}),refresh:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"}),e.jsx("path",{d:"M21 3v5h-5"}),e.jsx("path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"}),e.jsx("path",{d:"M8 16H3v5"})]}),user:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"8",r:"5"}),e.jsx("path",{d:"M20 21a8 8 0 0 0-16 0"})]}),check:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})}),trash:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M3 6h18M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"})}),plus:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M12 5v14M5 12h14"})}),chevronDown:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m6 9 6 6 6-6"})}),chevronUp:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m18 15-6-6-6 6"})}),storefront:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M3 9h18v10a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V9Z"}),e.jsx("path",{d:"m3 9 2.45-4.9A2 2 0 0 1 7.24 3h9.52a2 2 0 0 1 1.8 1.1L21 9"}),e.jsx("path",{d:"M12 3v6"})]}),arrowUp:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"m5 12 7-7 7 7"}),e.jsx("path",{d:"M12 19V5"})]}),arrowDown:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"m5 12 7 7 7-7"}),e.jsx("path",{d:"M12 5v14"})]}),delete:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M3 6h18M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"}),e.jsx("path",{d:"M10 11v6M14 11v6"})]}),close:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})}),edit:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),faq:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"}),e.jsx("path",{d:"M12 17h.01"})]}),chat:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"m3 21 1.9-5.7a8.5 8.5 0 1 1 3.8 3.8z"})}),globe:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"}),e.jsx("path",{d:"M2 12h20"})]}),eye:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]}),eyeOff:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M9.88 9.88a3 3 0 1 0 4.24 4.24"}),e.jsx("path",{d:"M10.73 5.08A10.43 10.43 0 0 1 12 5c7 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"}),e.jsx("path",{d:"M6.61 6.61A13.526 13.526 0 0 0 2 12s3 7 10 7a9.74 9.74 0 0 0 5.39-1.61"}),e.jsx("line",{x1:"2",x2:"22",y1:"2",y2:"22"})]}),creditCard:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{width:"20",height:"14",x:"2",y:"5",rx:"2"}),e.jsx("line",{x1:"2",x2:"22",y1:"10",y2:"10"})]}),mail:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{width:"20",height:"16",x:"2",y:"4",rx:"2"}),e.jsx("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]}),server:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2"}),e.jsx("rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2"}),e.jsx("line",{x1:"6",x2:"6.01",y1:"6",y2:"6"}),e.jsx("line",{x1:"6",x2:"6.01",y1:"18",y2:"18"})]}),calendarRepeat:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",ry:"2"}),e.jsx("line",{x1:"16",x2:"16",y1:"2",y2:"6"}),e.jsx("line",{x1:"8",x2:"8",y1:"2",y2:"6"}),e.jsx("line",{x1:"3",x2:"21",y1:"10",y2:"10"}),e.jsx("path",{d:"M11 14h1.5a1.5 1.5 0 0 1 0 3H11v2"}),e.jsx("path",{d:"M16 14v3a1 1 0 0 0 1 1h1"})]}),shield:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"})}),brain:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z"}),e.jsx("path",{d:"M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z"}),e.jsx("path",{d:"M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4"}),e.jsx("path",{d:"M17.599 6.5a3 3 0 0 0 .399-1.375"}),e.jsx("path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5"}),e.jsx("path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396"}),e.jsx("path",{d:"M19.938 10.5a4 4 0 0 1 .585.396"}),e.jsx("path",{d:"M6 18a4 4 0 0 1-1.967-.516"}),e.jsx("path",{d:"M19.967 17.484A4 4 0 0 1 18 18"})]})};class L{serverUrl;walletSigner=null;jwtToken=null;isAdminUser=!1;constructor(o){this.serverUrl=o}getAuthMethod(){return this.walletSigner?.publicKey&&this.walletSigner.signMessage?"wallet":this.jwtToken&&this.isAdminUser?"cedros-login":"none"}isAuthenticated(){return this.getAuthMethod()!=="none"}setWalletSigner(o){this.walletSigner=o,g.getLogger().debug("[AdminAuthManager] Wallet signer updated:",!!o?.publicKey)}setCedrosLoginAuth(o,n){this.jwtToken=o,this.isAdminUser=n??!1,g.getLogger().debug("[AdminAuthManager] Cedros-login auth updated:",{hasToken:!!o,isAdmin:this.isAdminUser})}async createAuthHeaders(o){const n=this.getAuthMethod();if(n==="wallet")return this.createWalletAuthHeaders(o);if(n==="cedros-login")return this.createJwtAuthHeaders();throw new Error("No admin authentication configured. Connect a wallet or sign in as admin.")}async createWalletAuthHeaders(o){if(!this.walletSigner?.publicKey||!this.walletSigner.signMessage)throw new Error("Wallet not connected or does not support message signing");const n=await this.fetchNonce(o),c=new TextEncoder().encode(n.nonce),t=await this.walletSigner.signMessage(c),i=M.bs58.encode(this.walletSigner.publicKey.toBytes()),u=g.gBase64.fromUint8Array(t);return{"X-Signer":i,"X-Message":n.nonce,"X-Signature":u}}createJwtAuthHeaders(){if(!this.jwtToken)throw new Error("No JWT token available");return{Authorization:`Bearer ${this.jwtToken}`}}async fetchNonce(o){const n=`${this.serverUrl}/paywall/v1/nonce`,c=typeof o=="string"?{purpose:o}:{path:o.path,method:o.method.toUpperCase()};g.getLogger().debug("[AdminAuthManager] Fetching nonce:",c);const t=await g.fetchWithTimeout(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(!t.ok){const i=await t.text();throw new Error(`Failed to fetch nonce: ${t.status} ${i}`)}return await t.json()}async fetchWithAuth(o,n={}){if(this.getAuthMethod()==="none")throw new Error("No admin authentication configured");const t=(n.method||"GET").toUpperCase(),i=await this.createAuthHeaders({path:o,method:t}),u={...t!=="GET"&&t!=="HEAD"?{"Content-Type":"application/json"}:{},...n.headers||{},...i},h=await g.fetchWithTimeout(`${this.serverUrl}${o}`,{...n,headers:u});if(!h.ok){let p=`Admin API error ${h.status}`;try{const l=await h.json();l&&typeof l.error=="string"?p=l.error:l&&typeof l.message=="string"&&(p=l.message)}catch{}throw new Error(p)}return await h.json()}}const s={adminProfile:"admin-profile",adminSectionAccess:"admin-section-access",cedrosLogin:"cedros-login",cedrosPay:"cedros-pay",org:"org",dashboardPermissions:"dashboard-permissions"};function T(r={}){return{...r}}function W(r){const o=T(r.services);return!(s.adminProfile in o)&&r.cedrosLogin?.user&&(o[s.adminProfile]={user:r.cedrosLogin.user}),!(s.adminSectionAccess in o)&&r.dashboardPermissions&&(o[s.adminSectionAccess]=r.dashboardPermissions),!(s.cedrosLogin in o)&&r.cedrosLogin&&(o[s.cedrosLogin]=r.cedrosLogin),!(s.cedrosPay in o)&&r.cedrosPay&&(o[s.cedrosPay]=r.cedrosPay),!(s.org in o)&&r.org&&(o[s.org]=r.org),!(s.dashboardPermissions in o)&&r.dashboardPermissions&&(o[s.dashboardPermissions]=r.dashboardPermissions),o}function f(r,o){return B(W(r),o)}function B(r,o){return r[o]}const a=r=>x.lazy(async()=>{const c=(await r()).default;return{default:({pluginContext:i})=>{const u=i.getAccessToken(),h=i.hasPermission("cedros-pay:admin")||i.hasPermission("admin"),p=x.useMemo(()=>{const j=new L(i.serverUrl);return j.setCedrosLoginAuth(u??null,h),j},[h,i.serverUrl,u]),l={serverUrl:i.serverUrl,authManager:p};return e.jsx(c,{...l})}}}),E={id:"cedros-pay",name:"Cedros Pay",version:"1.0.0",sections:[{id:"transactions",label:"Transactions",icon:d.transactions,group:"Store",order:0},{id:"products",label:"Products",icon:d.products,group:"Store",order:1},{id:"subscriptions",label:"Subscriptions",icon:d.products,group:"Store",order:2},{id:"coupons",label:"Coupons",icon:d.coupons,group:"Store",order:3},{id:"refunds",label:"Refunds",icon:d.refunds,group:"Store",order:4},{id:"compliance",label:"Compliance",icon:d.settings,group:"Store",order:5},{id:"storefront",label:"Storefront",icon:d.products,group:"Configuration",order:10},{id:"ai-settings",label:"Store AI",icon:d.settings,group:"Configuration",order:11},{id:"faqs",label:"Knowledge Base",icon:d.settings,group:"Configuration",order:12},{id:"payment-settings",label:"Payment Options",icon:d.wallet,group:"Configuration",order:13},{id:"messaging",label:"Store Messages",icon:d.settings,group:"Configuration",order:14},{id:"settings",label:"Store Server",icon:d.settings,group:"Configuration",order:15}],groups:[{id:"Store",label:"Store",order:1},{id:"Configuration",label:"Configuration",order:2,defaultCollapsed:!0}],components:{products:a(()=>Promise.resolve().then(()=>require("./sections-C2zEJr5G.js")).then(r=>({default:r.ProductsSection}))),subscriptions:a(()=>Promise.resolve().then(()=>require("./SubscriptionsSection-EeULMWIB.js")).then(r=>({default:r.SubscriptionsSection}))),transactions:a(()=>Promise.resolve().then(()=>require("./sections-C2zEJr5G.js")).then(r=>({default:r.TransactionsSection}))),coupons:a(()=>Promise.resolve().then(()=>require("./sections-C2zEJr5G.js")).then(r=>({default:r.CouponsSection}))),refunds:a(()=>Promise.resolve().then(()=>require("./sections-C2zEJr5G.js")).then(r=>({default:r.RefundsSection}))),compliance:a(()=>Promise.resolve().then(()=>require("./ComplianceSection-Buu0zTiL.js")).then(r=>({default:r.ComplianceSection}))),storefront:a(()=>Promise.resolve().then(()=>require("./StorefrontSection-Axvh_KeS.js")).then(r=>({default:r.StorefrontSection}))),"ai-settings":a(()=>Promise.resolve().then(()=>require("./AISettingsSection-B7qrycfY.js")).then(r=>({default:r.AISettingsSection}))),faqs:a(()=>Promise.resolve().then(()=>require("./FAQSection-DlPLnIJD.js")).then(r=>({default:r.FAQSection}))),"payment-settings":a(()=>Promise.resolve().then(()=>require("./PaymentSettingsSection-BdBDgaRg.js")).then(r=>({default:r.PaymentSettingsSection}))),messaging:a(()=>Promise.resolve().then(()=>require("./MessagingSection-CxV-pf-f.js")).then(r=>({default:r.MessagingSection}))),settings:a(()=>Promise.resolve().then(()=>require("./SettingsSection-Cz2Yjdhr.js")).then(r=>({default:r.SettingsSection})))},createPluginContext(r){const o=f(r,s.cedrosPay),n=f(r,s.cedrosLogin),c=f(r,s.org);return{serverUrl:o?.serverUrl||n?.serverUrl||"",userId:n?.user?.id,getAccessToken:()=>n?.getAccessToken?.()||o?.jwtToken||null,hasPermission:i=>this.checkPermission(i,r),orgId:c?.orgId,pluginData:{walletAddress:o?.walletAddress}}},checkPermission(r,o){const n=f(o,s.org);return n?.permissions?n.permissions.includes(r):!1},cssNamespace:"cedros-dashboard"},P=[{id:"transactions",qualifiedId:"cedros-pay:transactions",label:"Transactions",group:"Store",order:0,endpoints:["GET /admin/transactions"]},{id:"products",qualifiedId:"cedros-pay:products",label:"Products",group:"Store",order:1,endpoints:["GET /admin/products","POST /admin/products","PUT /admin/products/{id}","DELETE /admin/products/{id}"]},{id:"subscriptions",qualifiedId:"cedros-pay:subscriptions",label:"Subscriptions",group:"Store",order:2,endpoints:["GET /admin/subscriptions","POST /admin/subscriptions","PUT /admin/subscriptions/{id}"]},{id:"coupons",qualifiedId:"cedros-pay:coupons",label:"Coupons",group:"Store",order:3,endpoints:["GET /admin/coupons","POST /admin/coupons","PUT /admin/coupons/{id}","DELETE /admin/coupons/{id}"]},{id:"refunds",qualifiedId:"cedros-pay:refunds",label:"Refunds",group:"Store",order:4,endpoints:["GET /admin/refunds","POST /admin/refunds/{id}/approve","POST /admin/refunds/{id}/deny"]},{id:"storefront",qualifiedId:"cedros-pay:storefront",label:"Storefront",group:"Configuration",order:10,endpoints:["GET /admin/config/shop","PUT /admin/config/shop"]},{id:"ai-settings",qualifiedId:"cedros-pay:ai-settings",label:"Store AI",group:"Configuration",order:11,endpoints:["GET /admin/config/ai","PUT /admin/config/ai/api-key","PUT /admin/config/ai/assignment","PUT /admin/config/ai/prompt"]},{id:"faqs",qualifiedId:"cedros-pay:faqs",label:"Knowledge Base",group:"Configuration",order:12,endpoints:["GET /admin/faqs","POST /admin/faqs","PUT /admin/faqs/{id}","DELETE /admin/faqs/{id}"]},{id:"payment-settings",qualifiedId:"cedros-pay:payment-settings",label:"Payment Options",group:"Configuration",order:13,endpoints:["GET /admin/config/stripe","PUT /admin/config/stripe","GET /admin/config/x402","PUT /admin/config/x402","GET /admin/config/cedros_login","PUT /admin/config/cedros_login"]},{id:"messaging",qualifiedId:"cedros-pay:messaging",label:"Store Messages",group:"Configuration",order:14,endpoints:["GET /admin/config/messaging","PUT /admin/config/messaging"]},{id:"settings",qualifiedId:"cedros-pay:settings",label:"Store Server",group:"Configuration",order:15,endpoints:["GET /admin/config/server","PUT /admin/config/server"]}],q=P.map(r=>r.qualifiedId),I=[{id:"Store",label:"Store",order:1,defaultCollapsed:!1},{id:"Configuration",label:"Configuration",order:2,defaultCollapsed:!0}];exports.AdminAuthManager=L;exports.CEDROS_PAY_GROUPS=I;exports.CEDROS_PAY_SECTIONS=P;exports.CEDROS_PAY_SECTION_IDS=q;exports.CedrosPayAdminDashboard=A;exports.Icons=b;exports.cedrosPayPlugin=E;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const e=require("react/jsx-runtime"),r=require("react"),$=require("./sectionIds-B_tFiNvF.js"),ne=require("./ErrorBanner-Cx2dUhps.js"),ce=require("./StatsBar-m6GSRNxs.js"),M=require("./Dropdown-CtY91emj.js"),de=require("./dateHelpers-BKW_lGND.js"),te=require("./fetchWithTimeout-CG0EKbhf.js");function _e({serverUrl:p,productId:o,apiKey:b,authManager:u}){const[g,A]=r.useState(null),[N,T]=r.useState(!1),[f,V]=r.useState(!1),[k,v]=r.useState(null),S=r.useCallback(async()=>{if(o){T(!0),v(null);try{let c;if(u?.isAuthenticated())c=await u.fetchWithAuth(`/admin/products/${o}/variations`);else{const a={"Content-Type":"application/json"};b&&(a["X-API-Key"]=b);const l=await fetch(`${p}/admin/products/${o}/variations`,{headers:a});if(!l.ok)throw new Error(`Failed to fetch variations: ${l.status}`);c=await l.json()}c.variationConfig||(c.variationConfig={variationTypes:[]}),c.variants||(c.variants=[]),A(c)}catch(c){const a=c instanceof Error?c.message:"Failed to fetch variations";v(a),A({productId:o,variationConfig:{variationTypes:[]},variants:[]})}finally{T(!1)}}},[p,o,b,u]),R=r.useCallback(async c=>{if(!o)return null;V(!0),v(null);try{let a;if(u?.isAuthenticated())a=await u.fetchWithAuth(`/admin/products/${o}/variations`,{method:"PUT",body:JSON.stringify(c)});else{const l={"Content-Type":"application/json"};b&&(l["X-API-Key"]=b);const C=await fetch(`${p}/admin/products/${o}/variations`,{method:"PUT",headers:l,body:JSON.stringify(c)});if(!C.ok)throw new Error(`Failed to save variations: ${C.status}`);a=await C.json()}return A({productId:o,variationConfig:a.variationConfig,variants:a.variants}),{variantsCreated:a.variantsCreated}}catch(a){const l=a instanceof Error?a.message:"Failed to save variations";return v(l),null}finally{V(!1)}},[p,o,b,u]),_=r.useCallback(async c=>{if(!o||c.length===0)return!1;V(!0),v(null);try{if(u?.isAuthenticated())await u.fetchWithAuth(`/admin/products/${o}/variants/inventory`,{method:"PUT",body:JSON.stringify({updates:c})});else{const a={"Content-Type":"application/json"};b&&(a["X-API-Key"]=b);const l=await fetch(`${p}/admin/products/${o}/variants/inventory`,{method:"PUT",headers:a,body:JSON.stringify({updates:c})});if(!l.ok)throw new Error(`Failed to update inventory: ${l.status}`)}if(g){const a=new Map(c.map(l=>[l.variantId,l]));A({...g,variants:g.variants.map(l=>{const C=a.get(l.id);return C?{...l,inventoryQuantity:C.inventoryQuantity,inventoryStatus:C.inventoryStatus??l.inventoryStatus}:l})})}return!0}catch(a){const l=a instanceof Error?a.message:"Failed to update inventory";return v(l),!1}finally{V(!1)}},[p,o,b,u,g]);return{data:g,isLoading:N,error:k,fetch:S,save:R,bulkUpdateInventory:_,isSaving:f}}function pe(){return`var_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function ye({value:p,onChange:o,maxTypes:b=5,maxValuesPerType:u=20,disabled:g=!1}){const[A,N]=r.useState(null),[T,f]=r.useState(""),[V,k]=r.useState({}),v=p.variationTypes,S=r.useCallback(()=>{if(!T.trim()||v.length>=b)return;const y={id:pe(),name:T.trim(),displayOrder:v.length,values:[]};o({variationTypes:[...v,y]}),f(""),N(y.id)},[T,v,b,o]),R=r.useCallback(y=>{o({variationTypes:v.filter(D=>D.id!==y).map((D,j)=>({...D,displayOrder:j}))}),A===y&&N(null)},[v,o,A]),_=r.useCallback((y,D)=>{o({variationTypes:v.map(j=>j.id===y?{...j,name:D}:j)})},[v,o]),c=r.useCallback((y,D)=>{const j=v.findIndex(I=>I.id===y);if(j===-1||D==="up"&&j===0||D==="down"&&j===v.length-1)return;const s=[...v],h=D==="up"?j-1:j+1;[s[j],s[h]]=[s[h],s[j]],o({variationTypes:s.map((I,d)=>({...I,displayOrder:d}))})},[v,o]),a=r.useCallback(y=>{const D=(V[y]||"").trim();if(!D)return;const j=v.find(h=>h.id===y);if(!j||j.values.length>=u)return;const s={id:pe(),label:D};o({variationTypes:v.map(h=>h.id===y?{...h,values:[...h.values,s]}:h)}),k(h=>({...h,[y]:""}))},[v,V,u,o]),l=r.useCallback((y,D)=>{o({variationTypes:v.map(j=>j.id===y?{...j,values:j.values.filter(s=>s.id!==D)}:j)})},[v,o]),C=r.useCallback((y,D,j)=>{o({variationTypes:v.map(s=>s.id===y?{...s,values:s.values.map(h=>h.id===D?{...h,label:j}:h)}:s)})},[v,o]);return e.jsxs("div",{className:"cedros-admin__variation-editor",children:[e.jsxs("div",{className:"cedros-admin__variation-editor-header",children:[e.jsx("h4",{className:"cedros-admin__field-label",style:{marginBottom:0},children:"Variation Types"}),e.jsxs("span",{style:{fontSize:12,opacity:.7},children:[v.length,"/",b," types"]})]}),v.length===0?e.jsx("div",{className:"cedros-admin__variation-empty",children:'No variation types defined. Add types like "Size" or "Color" to create product variants.'}):e.jsx("div",{className:"cedros-admin__variation-type-list",children:v.map((y,D)=>e.jsxs("div",{className:"cedros-admin__variation-type-item",children:[e.jsxs("div",{className:"cedros-admin__variation-type-header",children:[e.jsxs("div",{className:"cedros-admin__variation-type-controls",children:[e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--icon",onClick:()=>c(y.id,"up"),disabled:g||D===0,title:"Move up",children:$.Icons.arrowUp}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--icon",onClick:()=>c(y.id,"down"),disabled:g||D===v.length-1,title:"Move down",children:$.Icons.arrowDown})]}),e.jsx("input",{type:"text",className:"cedros-admin__input cedros-admin__variation-type-name",value:y.name,onChange:j=>_(y.id,j.target.value),disabled:g,placeholder:"Type name"}),e.jsxs("span",{className:"cedros-admin__variation-value-count",children:[y.values.length," values"]}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>N(A===y.id?null:y.id),children:A===y.id?"Collapse":"Edit values"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--danger",onClick:()=>R(y.id),disabled:g,title:"Remove type",children:$.Icons.delete})]}),A===y.id&&e.jsxs("div",{className:"cedros-admin__variation-values",children:[e.jsxs("div",{className:"cedros-admin__variation-values-header",children:[e.jsxs("span",{style:{fontSize:12,fontWeight:600},children:['Values for "',y.name,'"']}),e.jsxs("span",{style:{fontSize:11,opacity:.7},children:[y.values.length,"/",u]})]}),y.values.length===0?e.jsx("div",{className:"cedros-admin__variation-empty",style:{padding:"8px 0"},children:'No values yet. Add values like "Small", "Medium", "Large".'}):e.jsx("div",{className:"cedros-admin__variation-value-list",children:y.values.map(j=>e.jsxs("div",{className:"cedros-admin__variation-value-item",children:[e.jsx("input",{type:"text",className:"cedros-admin__input cedros-admin__input--sm",value:j.label,onChange:s=>C(y.id,j.id,s.target.value),disabled:g}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--icon cedros-admin__button--danger",onClick:()=>l(y.id,j.id),disabled:g,title:"Remove value",children:$.Icons.close})]},j.id))}),y.values.length<u&&e.jsxs("div",{className:"cedros-admin__variation-add-value",children:[e.jsx("input",{type:"text",className:"cedros-admin__input cedros-admin__input--sm",value:V[y.id]||"",onChange:j=>k(s=>({...s,[y.id]:j.target.value})),placeholder:"Add value...",disabled:g,onKeyDown:j=>{j.key==="Enter"&&(j.preventDefault(),a(y.id))}}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--secondary cedros-admin__button--sm",onClick:()=>a(y.id),disabled:g||!V[y.id]?.trim(),children:"Add"})]})]})]},y.id))}),v.length<b&&e.jsxs("div",{className:"cedros-admin__variation-add-type",children:[e.jsx("input",{type:"text",className:"cedros-admin__input",value:T,onChange:y=>f(y.target.value),placeholder:"New variation type (e.g., Size, Color)",disabled:g,onKeyDown:y=>{y.key==="Enter"&&(y.preventDefault(),S())}}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--secondary",onClick:S,disabled:g||!T.trim(),children:"Add Type"})]})]})}function ge(){return`variant_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}function xe(p){if(p.length===0)return[];const o=[...p].sort((u,g)=>u.displayOrder-g.displayOrder),b=(u,g)=>{if(u>=o.length){const T=g.valueIds.sort().join("|"),f=Object.values(g.options).join(" / ");return[{key:T,title:f,optionValueIds:[...g.valueIds],options:{...g.options}}]}const A=o[u],N=[];for(const T of A.values)N.push(...b(u+1,{valueIds:[...g.valueIds,T.id],options:{...g.options,[A.name]:T.label}}));return N};return b(0,{valueIds:[],options:{}})}function be(p){return p.optionValueIds?.length?[...p.optionValueIds].sort().join("|"):Object.entries(p.options).sort(([o],[b])=>o.localeCompare(b)).map(([o,b])=>`${o}:${b}`).join("|")}function ve({variationConfig:p,variants:o,onChange:b,defaultPrice:u=0,currencySymbol:g="$",maxVariants:A=100,disabled:N=!1}){const T=r.useMemo(()=>xe(p.variationTypes),[p.variationTypes]),f=r.useMemo(()=>{const c=new Map;for(const a of o)c.set(be(a),a);return c},[o]),{existingRows:V,possibleRows:k}=r.useMemo(()=>{const c=[],a=[];for(const l of T){const C=f.get(l.key);C?c.push({combo:l,variant:C}):a.push(l)}return{existingRows:c,possibleRows:a}},[T,f]),v=r.useCallback((c,a)=>{b(o.map(l=>l.id===c?{...l,...a}:l))},[o,b]),S=r.useCallback(c=>{b(o.filter(a=>a.id!==c))},[o,b]),R=r.useCallback(c=>{if(o.length>=A)return;const a={id:ge(),title:c.title,options:c.options,optionValueIds:c.optionValueIds,price:u,inventoryQuantity:0,inventoryStatus:"in_stock",autoGenerated:!1};b([...o,a])},[o,b,A,u]),_=r.useCallback(()=>{const c=A-o.length,l=k.slice(0,c).map(C=>({id:ge(),title:C.title,options:C.options,optionValueIds:C.optionValueIds,price:u,inventoryQuantity:0,inventoryStatus:"in_stock",autoGenerated:!0}));b([...o,...l])},[o,b,k,A,u]);return p.variationTypes.length===0?e.jsx("div",{className:"cedros-admin__variant-grid-empty",children:"Add variation types above to create product variants."}):T.length===0?e.jsx("div",{className:"cedros-admin__variant-grid-empty",children:"Add values to your variation types to create product variants."}):e.jsxs("div",{className:"cedros-admin__variant-grid",children:[e.jsxs("div",{className:"cedros-admin__variant-grid-header",children:[e.jsx("h4",{className:"cedros-admin__field-label",style:{marginBottom:0},children:"Variants"}),e.jsxs("span",{style:{fontSize:12,opacity:.7},children:[o.length,"/",A," variants (",T.length," ","possible)"]})]}),k.length>0&&o.length<A&&e.jsxs("div",{className:"cedros-admin__variant-grid-actions",children:[e.jsxs("button",{type:"button",className:"cedros-admin__button cedros-admin__button--secondary",onClick:_,disabled:N,children:["Generate All (",Math.min(k.length,A-o.length),")"]}),e.jsx("span",{style:{fontSize:11,opacity:.7},children:"Creates variants with default price and 0 inventory"})]}),e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table cedros-admin__variant-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Variant"}),e.jsx("th",{style:{width:100},children:"Price"}),e.jsx("th",{style:{width:80},children:"Qty"}),e.jsx("th",{style:{width:100},children:"SKU"}),e.jsx("th",{style:{width:100},children:"Status"}),e.jsx("th",{style:{width:80},children:"Actions"})]})}),e.jsxs("tbody",{children:[V.map(({combo:c,variant:a})=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.jsx("span",{style:{fontWeight:600},children:c.title}),e.jsx("span",{style:{fontSize:11,opacity:.6},children:Object.entries(c.options).map(([l,C])=>`${l}: ${C}`).join(", ")})]})}),e.jsx("td",{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4},children:[e.jsx("span",{children:g}),e.jsx("input",{type:"number",className:"cedros-admin__input cedros-admin__input--sm",value:a.price??"",onChange:l=>v(a.id,{price:l.target.value===""?void 0:parseFloat(l.target.value)||0}),disabled:N,min:"0",step:"0.01",style:{width:70}})]})}),e.jsx("td",{children:e.jsx("input",{type:"number",className:"cedros-admin__input cedros-admin__input--sm",value:a.inventoryQuantity??"",onChange:l=>v(a.id,{inventoryQuantity:l.target.value===""?void 0:parseInt(l.target.value)||0}),disabled:N,min:"0",style:{width:60}})}),e.jsx("td",{children:e.jsx("input",{type:"text",className:"cedros-admin__input cedros-admin__input--sm",value:a.sku??"",onChange:l=>v(a.id,{sku:l.target.value||void 0}),disabled:N,placeholder:"SKU",style:{width:80}})}),e.jsx("td",{children:e.jsx(M.FilterDropdown,{value:a.inventoryStatus??"in_stock",onChange:l=>v(a.id,{inventoryStatus:l}),options:[{value:"in_stock",label:"In stock"},{value:"low",label:"Low"},{value:"out_of_stock",label:"Out of stock"},{value:"backorder",label:"Backorder"}],disabled:N})}),e.jsx("td",{children:e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--icon cedros-admin__button--danger",onClick:()=>S(a.id),disabled:N,title:"Remove variant",children:$.Icons.trash})})]},a.id)),k.length>0&&o.length<A&&e.jsxs(e.Fragment,{children:[e.jsx("tr",{className:"cedros-admin__variant-separator",children:e.jsx("td",{colSpan:6,children:e.jsxs("span",{style:{fontSize:11,opacity:.6},children:["Uncreated combinations (",k.length,")"]})})}),k.slice(0,10).map(c=>e.jsxs("tr",{className:"cedros-admin__variant-possible",children:[e.jsx("td",{children:e.jsx("span",{style:{opacity:.6},children:c.title})}),e.jsx("td",{colSpan:4,style:{opacity:.5},children:"Not created"}),e.jsx("td",{children:e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--icon",onClick:()=>R(c),disabled:N,title:"Create variant",children:$.Icons.plus})})]},c.key)),k.length>10&&e.jsx("tr",{className:"cedros-admin__variant-more",children:e.jsxs("td",{colSpan:6,style:{textAlign:"center",opacity:.6},children:["+",k.length-10," more combinations"]})})]})]})]})})]})}function je({serverUrl:p,productId:o,productTitle:b,defaultPrice:u=0,currencySymbol:g="$",apiKey:A,authManager:N,onClose:T}){const{data:f,isLoading:V,error:k,fetch:v,save:S,isSaving:R}=_e({serverUrl:p,productId:o,apiKey:A,authManager:N}),[_,c]=r.useState({variationTypes:[]}),[a,l]=r.useState([]),[C,y]=r.useState(!1),[D,j]=r.useState(!1);r.useEffect(()=>{v()},[v]),r.useEffect(()=>{f&&(c(f.variationConfig),l(f.variants),y(!1))},[f]);const s=r.useCallback(d=>{c(d),y(!0),j(!1)},[]),h=r.useCallback(d=>{l(d),y(!0),j(!1)},[]),I=r.useCallback(async()=>{const d=new Set((f?.variants??[]).map(F=>F.id)),m=a.filter(F=>!d.has(F.id)),L=a.filter(F=>d.has(F.id)),E=(f?.variants??[]).filter(F=>!a.some(H=>H.id===F.id)).map(F=>F.id);await S({variationConfig:_,createVariants:m.map(F=>({optionValueIds:F.optionValueIds??[],inventoryQuantity:F.inventoryQuantity,sku:F.sku,price:F.price})),updateVariants:L.map(F=>({id:F.id,inventoryQuantity:F.inventoryQuantity,sku:F.sku,price:F.price,inventoryStatus:F.inventoryStatus})),deleteVariantIds:E.length>0?E:void 0})&&(y(!1),j(!0),setTimeout(()=>j(!1),3e3))},[_,a,f?.variants,S]);return V?e.jsxs("div",{className:"cedros-admin__variations-editor",children:[e.jsxs("div",{className:"cedros-admin__variations-editor-header",children:[e.jsx("h3",{className:"cedros-admin__section-title",children:b?`Variations: ${b}`:"Product Variations"}),T&&e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost",onClick:T,children:$.Icons.close})]}),e.jsxs("div",{className:"cedros-admin__loading",children:[$.Icons.loading," Loading variations..."]})]}):e.jsxs("div",{className:"cedros-admin__variations-editor",children:[e.jsxs("div",{className:"cedros-admin__variations-editor-header",children:[e.jsx("h3",{className:"cedros-admin__section-title",children:b?`Variations: ${b}`:"Product Variations"}),e.jsxs("div",{className:"cedros-admin__variations-editor-actions",children:[D&&e.jsxs("span",{className:"cedros-admin__success-text",children:[$.Icons.check," Saved"]}),C&&e.jsx("span",{className:"cedros-admin__unsaved-text",children:"Unsaved changes"}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--primary",onClick:I,disabled:R||!C,children:R?"Saving...":"Save Changes"}),T&&e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost",onClick:T,children:$.Icons.close})]})]}),k&&e.jsx("div",{className:"cedros-admin__error-banner",children:k}),e.jsxs("div",{className:"cedros-admin__variations-editor-content",children:[e.jsx("div",{className:"cedros-admin__variations-editor-section",children:e.jsx(ye,{value:_,onChange:s,disabled:R})}),_.variationTypes.length>0&&e.jsx("div",{className:"cedros-admin__variations-editor-section",children:e.jsx(ve,{variationConfig:_,variants:a,onChange:h,defaultPrice:u,currencySymbol:g,disabled:R})})]})]})}const fe={requireSanctionsClear:!0,requireKyc:!1,requireAccreditedInvestor:!1,tokenGates:[]};function Ce({value:p,onChange:o}){const[b,u]=r.useState(p!==null),[g,A]=r.useState(""),[N,T]=r.useState("fungible_token"),[f,V]=r.useState(1),k=p??fe,v=()=>{p?(o(null),u(!1)):(o({...fe}),u(!0))},S=c=>{o({...k,...c})},R=()=>{if(!g.trim())return;const c={address:g.trim(),gateType:N,minAmount:f},a=[...k.tokenGates??[],c];S({tokenGates:a}),A(""),V(1)},_=c=>{const a=(k.tokenGates??[]).filter((l,C)=>C!==c);S({tokenGates:a.length>0?a:[]})};return e.jsxs("div",{style:{border:"1px solid var(--cedros-admin-border, #e0e0e0)",borderRadius:"4px",padding:"0.75rem",marginTop:"0.5rem"},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",fontSize:"0.9rem",fontWeight:600,cursor:"pointer"},children:[e.jsx("input",{type:"checkbox",checked:p!==null,onChange:v}),"Enable compliance gates"]}),p!==null&&b&&e.jsxs("div",{style:{marginTop:"0.75rem",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",fontSize:"0.85rem"},children:[e.jsx("input",{type:"checkbox",checked:k.requireSanctionsClear,onChange:c=>S({requireSanctionsClear:c.target.checked})}),"Require sanctions clearance"]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",fontSize:"0.85rem"},children:[e.jsx("input",{type:"checkbox",checked:k.requireKyc,onChange:c=>S({requireKyc:c.target.checked})}),"Require KYC verification"]}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",fontSize:"0.85rem"},children:[e.jsx("input",{type:"checkbox",checked:k.requireAccreditedInvestor,onChange:c=>S({requireAccreditedInvestor:c.target.checked})}),"Require accredited investor status"]}),e.jsxs("div",{style:{marginTop:"0.5rem"},children:[e.jsx("span",{style:{fontSize:"0.85rem",fontWeight:600},children:"Token Gates"}),(k.tokenGates??[]).length>0&&e.jsx("div",{style:{marginTop:"0.25rem"},children:(k.tokenGates??[]).map((c,a)=>e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem",fontSize:"0.8rem",padding:"0.25rem 0"},children:[e.jsxs("code",{style:{fontSize:"0.75rem"},children:[c.address.slice(0,8),"..."]}),e.jsx("span",{className:"cedros-admin__badge cedros-admin__badge--muted",children:c.gateType==="fungible_token"?"Fungible":"NFT"}),e.jsxs("span",{children:["min: ",c.minAmount]}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:()=>_(a),style:{padding:"0 0.25rem"},children:"×"})]},a))}),e.jsxs("div",{style:{display:"flex",gap:"0.5rem",alignItems:"flex-end",marginTop:"0.25rem",flexWrap:"wrap"},children:[e.jsx("input",{type:"text",className:"cedros-admin__input",placeholder:"Mint or collection address",value:g,onChange:c=>A(c.target.value),style:{flex:1,minWidth:"200px",fontSize:"0.8rem"}}),e.jsxs("select",{className:"cedros-admin__input",value:N,onChange:c=>T(c.target.value),style:{width:"auto",fontSize:"0.8rem"},children:[e.jsx("option",{value:"fungible_token",children:"Fungible"}),e.jsx("option",{value:"nft_collection",children:"NFT"})]}),e.jsx("input",{type:"number",className:"cedros-admin__input",min:1,value:f,onChange:c=>V(Number(c.target.value)),style:{width:"80px",fontSize:"0.8rem"}}),e.jsx("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost cedros-admin__button--sm",onClick:R,disabled:!g.trim(),children:"Add Gate"})]})]})]})]})}function Ne({serverUrl:p,productId:o,productTitle:b,apiKey:u,authManager:g,onClose:A}){const[N,T]=r.useState(null),[f,V]=r.useState(!0),[k,v]=r.useState(null),S=r.useCallback(async()=>{V(!0),v(null);try{const R=`/paywall/v1/products/${encodeURIComponent(o)}/nft-metadata`;let _;if(g?.isAuthenticated())_=await g.fetchWithAuth(R);else{const c={"Content-Type":"application/json"};u&&(c["X-API-Key"]=u);const a=await fetch(`${p}${R}`,{headers:c});if(!a.ok)throw new Error(`Request failed: ${a.status}`);_=await a.json()}T(_)}catch{v("Failed to load NFT metadata. Ensure this product exists and the server is running.")}finally{V(!1)}},[p,o,u,g]);return r.useEffect(()=>{S()},[S]),e.jsxs("div",{children:[e.jsxs("div",{className:"cedros-admin__section-header",style:{marginBottom:"1rem"},children:[e.jsxs("h3",{className:"cedros-admin__section-title",style:{fontSize:"1rem"},children:["NFT Metadata — ",b]}),e.jsxs("button",{type:"button",className:"cedros-admin__button cedros-admin__button--ghost",onClick:A,children:[$.Icons.close," Close"]})]}),e.jsx(ne.ErrorBanner,{message:k,onRetry:S}),f?e.jsxs("div",{className:"cedros-admin__loading",children:[$.Icons.loading," Loading metadata..."]}):N?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"1rem"},children:[e.jsxs("div",{style:{display:"flex",gap:"1rem",padding:"1rem",border:"1px solid var(--cedros-admin-border, #e0e0e0)",borderRadius:"8px"},children:[N.image&&e.jsx("img",{src:N.image,alt:N.name,style:{width:120,height:120,borderRadius:8,objectFit:"cover",flexShrink:0}}),e.jsxs("div",{style:{flex:1},children:[e.jsx("h4",{style:{margin:"0 0 0.25rem",fontSize:"1rem",fontWeight:600},children:N.name}),e.jsx("p",{style:{margin:"0 0 0.5rem",fontSize:"0.85rem",color:"var(--cedros-admin-text-muted, #888)"},children:N.description}),N.external_url&&e.jsxs("p",{style:{margin:"0 0 0.5rem",fontSize:"0.8rem"},children:[e.jsx("strong",{children:"URL:"})," ",e.jsx("code",{children:N.external_url})]}),N.attributes.length>0&&e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:"0.5rem"},children:N.attributes.map(R=>e.jsxs("div",{style:{padding:"0.25rem 0.5rem",border:"1px solid var(--cedros-admin-border, #e0e0e0)",borderRadius:"4px",fontSize:"0.8rem"},children:[e.jsxs("span",{style:{color:"var(--cedros-admin-text-muted, #888)"},children:[R.trait_type,":"]})," ",e.jsx("strong",{children:R.value})]},R.trait_type))})]})]}),e.jsxs("div",{children:[e.jsx("h4",{style:{margin:"0 0 0.5rem",fontSize:"0.85rem",fontWeight:600},children:"Raw JSON (stored on-chain URI)"}),e.jsx("pre",{style:{background:"var(--cedros-admin-bg-muted, #f5f5f5)",border:"1px solid var(--cedros-admin-border, #e0e0e0)",borderRadius:"4px",padding:"0.75rem",fontSize:"0.8rem",overflow:"auto",maxHeight:"300px"},children:JSON.stringify(N,null,2)})]})]}):null]})}function ke({serverUrl:p,apiKey:o,pageSize:b=20,authManager:u}){const[g,A]=r.useState([]),[N,T]=r.useState(!0),[f,V]=r.useState(!1),[k,v]=r.useState(!1),[S,R]=r.useState(null),[_,c]=r.useState(null),[a,l]=r.useState(null),[C,y]=r.useState(null),[D,j]=r.useState(null),[s,h]=r.useState({id:"",title:"",slug:"",imageUrl:"",description:"",productType:"one_time",priceUsd:"",fiatCurrency:"usd",cryptoToken:"USDC",inventoryStatus:"in_stock",compareAtUsd:"",tagsCsv:"",categoryIdsCsv:"",checkoutEmail:"required",checkoutName:"optional",checkoutPhone:"none",checkoutShippingAddress:!1,checkoutBillingAddress:!1,fulfillmentType:"shipping",storePolicyFulfillment:"physical_goods",storeManagedKind:"none",appleProductId:"",googleProductId:"",googlePackageName:"",googleBasePlanId:"",googleOfferId:"",fulfillmentNotes:"",shippingCountriesCsv:"",inventoryQuantity:"",giftCardConfig:null,tokenizedAssetConfig:null,complianceRequirements:null}),I=t=>{const n=t.tagsCsv.split(",").map(J=>J.trim()).filter(Boolean),P=t.categoryIdsCsv.split(",").map(J=>J.trim()).filter(Boolean),W={email:t.checkoutEmail,name:t.checkoutName,phone:t.checkoutPhone,shippingAddress:t.checkoutShippingAddress,billingAddress:t.checkoutBillingAddress},B=t.fulfillmentType==="shipping"?"physical":"digital",z={title:t.title,slug:t.slug||t.id,shipping_profile:B,inventory_status:t.inventoryStatus,checkout_requirements:JSON.stringify(W),fulfillment_type:t.fulfillmentType,store_policy_fulfillment_type:t.storePolicyFulfillment};t.imageUrl&&(z.image_url=t.imageUrl);const X=t.compareAtUsd?Math.round(Number(t.compareAtUsd)*100):0;X&&(z.compare_at_amount_cents=String(X)),n.length&&(z.tags=JSON.stringify(n)),P.length&&(z.category_ids=JSON.stringify(P)),t.fulfillmentNotes&&(z.fulfillment_notes=t.fulfillmentNotes);const U=t.shippingCountriesCsv.split(",").map(J=>J.trim().toUpperCase()).filter(Boolean);return U.length&&(z.shippingCountries=U.join(","),z.shipping_countries=U.join(",")),z},[d,m]=r.useState([]),L=t=>t.title||t.metadata?.title||t.description||t.id,E=t=>t.imageUrl||t.images?.[0]?.url||t.metadata?.image_url,O=t=>{const n=t.metadata?.store_policy_fulfillment_type;if(n==="digital_in_app"||n==="physical_goods"||n==="real_world_service"||n==="reader_content"||n==="other")return n;switch(t.fulfillment?.type){case"shipping":return"physical_goods";case"service":return"real_world_service";case"digital_download":return"digital_in_app";default:return}},F=t=>{switch(t){case"digital_in_app":return"Digital in-app";case"physical_goods":return"Physical goods";case"real_world_service":return"Real-world service";case"reader_content":return"Reader content";case"other":return"Other";default:return"Not set"}},H=t=>{switch(t){case"consumable":return"Consumable";case"non_consumable":return"Non-consumable";case"auto_renewable_subscription":return"Auto-renewing subscription";default:return"External billing only"}},le=t=>{if(t.storeManagedKind==="none")return;const n=t.appleProductId.trim(),P=t.googleProductId.trim(),W=t.googlePackageName.trim(),B=t.googleBasePlanId.trim(),z=t.googleOfferId.trim();if(!(!n&&!P))return{kind:t.storeManagedKind,apple:n?{productId:n}:void 0,google:P?{productId:P,packageName:W||void 0,basePlanId:B||void 0,offerId:z||void 0}:void 0}},ae=t=>{const n=[],P=O(t);return P&&n.push(F(P)),t.storeBilling?.kind&&n.push(H(t.storeBilling.kind)),t.storeBilling?.apple?.productId&&n.push(`Apple ${t.storeBilling.apple.productId}`),t.storeBilling?.google?.productId&&n.push(`Google ${t.storeBilling.google.productId}`),n.join(" • ")},Z=r.useCallback(async()=>{try{j(null);let t;if(u?.isAuthenticated())t=await u.fetchWithAuth(`/admin/products?limit=${b}`);else{const n={"Content-Type":"application/json"};o&&(n["X-API-Key"]=o);const P=await fetch(`${p}/admin/products?limit=${b}`,{headers:n});if(!P.ok)throw new Error(`Failed to fetch products: ${P.status}`);t=await P.json()}A(t.products||[])}catch{A([]),j("Failed to load products")}finally{T(!1)}},[p,o,b,u]);r.useEffect(()=>{Z(),(async()=>{try{let t;if(u?.isAuthenticated())t=await u.fetchWithAuth("/admin/collections");else{const n={"Content-Type":"application/json"};o&&(n["X-API-Key"]=o);const P=await fetch(`${p}/admin/collections`,{headers:n});if(!P.ok)return;t=await P.json()}m((t.collections||[]).filter(n=>n.tokenizationConfig).map(n=>({id:n.id,name:n.name})))}catch{}})()},[Z,p,o,u]);const ue=async t=>{if(t.preventDefault(),!(!s.id||!s.description)){if(R(null),s.fulfillmentType==="shipping"&&s.checkoutShippingAddress&&!s.shippingCountriesCsv.split(",").map(P=>P.trim()).filter(Boolean).length){R("Shipping countries are required when collecting shipping address. Example: US,CA");return}if(s.storeManagedKind!=="none"&&!s.appleProductId.trim()&&!s.googleProductId.trim()){R("Add at least one Apple or Google store product ID for store-managed products.");return}if(s.googleBasePlanId.trim()&&!s.googleProductId.trim()){R("Google base plan ID requires a Google product ID.");return}if(s.storeManagedKind==="auto_renewable_subscription"&&s.googleProductId.trim()&&!s.googleBasePlanId.trim()){R("Google Play subscriptions require a base plan ID.");return}v(!0);try{const{productType:n}=s,P=s.inventoryQuantity===""?void 0:Number.isFinite(Number(s.inventoryQuantity))?Number(s.inventoryQuantity):void 0,W=Number(s.priceUsd)||0,B=Math.round(W*100),z=Math.round(W*1e6),X=s.tagsCsv.split(",").map(x=>x.trim()).filter(Boolean),U=s.categoryIdsCsv.split(",").map(x=>x.trim()).filter(Boolean),J={email:s.checkoutEmail,name:s.checkoutName,phone:s.checkoutPhone,shippingAddress:s.checkoutShippingAddress,billingAddress:s.checkoutBillingAddress},oe=le(s),re=s.compareAtUsd===""?void 0:Math.round(Number(s.compareAtUsd)*100),i={id:s.id,title:s.title||void 0,slug:s.slug||void 0,description:s.description,tags:X,categoryIds:U,images:s.imageUrl?[{url:s.imageUrl,alt:s.title||s.id}]:[],shippingProfile:s.fulfillmentType==="shipping"?"physical":"digital",checkoutRequirements:J,fulfillment:{type:s.fulfillmentType,notes:s.fulfillmentNotes||void 0},fiatAmountCents:B,fiatCurrency:s.fiatCurrency,compareAtFiatAmountCents:re,compareAtFiatCurrency:re?s.fiatCurrency:void 0,cryptoAtomicAmount:z,cryptoToken:s.cryptoToken,inventoryStatus:s.fulfillmentType==="shipping"?s.inventoryStatus:void 0,...P!==void 0?{inventoryQuantity:P}:{},...oe?{storeBilling:oe}:{},metadata:{...n?{product_type:n}:{},...I(s)}};if(n==="gift_card"&&s.giftCardConfig&&(i.giftCardConfig=s.giftCardConfig),n==="tokenized_asset"&&s.tokenizedAssetConfig&&(i.tokenizedAssetConfig=s.tokenizedAssetConfig),s.complianceRequirements&&(i.complianceRequirements=s.complianceRequirements),u?.isAuthenticated())await u.fetchWithAuth("/admin/products",{method:"POST",body:JSON.stringify(i)});else{const x={"Content-Type":"application/json"};o&&(x["X-API-Key"]=o);const w=await fetch(`${p}/admin/products`,{method:"POST",headers:x,body:JSON.stringify(i)});if(!w.ok)throw new Error(`Failed to create product: ${w.status}`)}h({id:"",title:"",slug:"",imageUrl:"",description:"",productType:"one_time",priceUsd:"",fiatCurrency:"usd",cryptoToken:"USDC",inventoryStatus:"in_stock",compareAtUsd:"",tagsCsv:"",categoryIdsCsv:"",checkoutEmail:"required",checkoutName:"optional",checkoutPhone:"none",checkoutShippingAddress:!1,checkoutBillingAddress:!1,fulfillmentType:"shipping",storePolicyFulfillment:"physical_goods",storeManagedKind:"none",appleProductId:"",googleProductId:"",googlePackageName:"",googleBasePlanId:"",googleOfferId:"",fulfillmentNotes:"",shippingCountriesCsv:"",inventoryQuantity:"",giftCardConfig:null,tokenizedAssetConfig:null,complianceRequirements:null}),V(!1),Z()}catch(n){R(n instanceof Error?n.message:"Failed to create product")}finally{v(!1)}}},me=t=>`$${(t/100).toFixed(2)}`,se=t=>{switch(t){case"subscription":return"Subscription";case"pay_per_access":return"Pay per access";case"one_time":return"One-time purchase";case"gift_card":return"Gift card";default:return"One-time purchase"}},ie=s.storePolicyFulfillment==="digital_in_app"||s.storePolicyFulfillment==="reader_content"||s.storePolicyFulfillment==="other"||s.productType==="subscription"||s.storeManagedKind!=="none",ee=r.useMemo(()=>{const t=g.filter(P=>P.active).length,n=g.reduce((P,W)=>{const B=W.variations?.length??0;return P+(B>0?B:1)},0);return{activeCount:t,totalSkus:n}},[g]),K=t=>{y(n=>!n||n.key!==t?{key:t,direction:"asc"}:{key:t,direction:n.direction==="asc"?"desc":"asc"})},Y=t=>!C||C.key!==t?e.jsx("span",{className:"cedros-admin__sort-icon cedros-admin__sort-icon--idle",children:$.Icons.chevronUp}):e.jsx("span",{className:"cedros-admin__sort-icon",children:C.direction==="asc"?$.Icons.chevronUp:$.Icons.chevronDown}),he=r.useMemo(()=>{if(!C)return g;const t=C.direction==="asc"?1:-1,n=P=>{switch(C.key){case"product":return L(P);case"type":return se(P.metadata?.product_type);case"price":return P.fiatAmountCents??0;case"status":return P.active?1:0;case"id":default:return P.id}};return[...g].sort((P,W)=>{const B=n(P),z=n(W);return typeof B=="number"&&typeof z=="number"?(B-z)*t:String(B).localeCompare(String(z),void 0,{sensitivity:"base"})*t})},[g,C]);return e.jsxs("div",{className:"cedros-admin__page",children:[e.jsx(ne.ErrorBanner,{message:D,onRetry:Z}),e.jsx(ce.StatsBar,{stats:[{label:"Total Products",value:g.length},{label:"Active",value:ee.activeCount,variant:ee.activeCount>0?"success":"muted"},{label:"Total SKUs",value:ee.totalSkus}],isLoading:N}),e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsx("h3",{className:"cedros-admin__section-title",children:"Paywall Products"}),e.jsxs("button",{className:"cedros-admin__button cedros-admin__button--primary cedros-admin__button--action",onClick:()=>{R(null),V(!f)},children:[f?$.Icons.close:$.Icons.plus,f?"Cancel":"Add Product"]})]}),f&&e.jsxs("form",{onSubmit:ue,className:"cedros-admin__add-form",children:[S&&e.jsx("div",{style:{marginBottom:"0.75rem",color:"#B42318",fontWeight:600},children:S}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Product ID"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.id,onChange:t=>h(n=>({...n,id:t.target.value})),placeholder:"e.g., premium-article",required:!0})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Product name"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.title,onChange:t=>h(n=>({...n,title:t.target.value})),placeholder:"e.g., Cedros Hoodie"})]})]}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Slug"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.slug,onChange:t=>h(n=>({...n,slug:t.target.value})),placeholder:"e.g., cedros-hoodie (defaults to ID)"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Primary image URL"}),e.jsx("input",{type:"url",className:"cedros-admin__input",value:s.imageUrl,onChange:t=>h(n=>({...n,imageUrl:t.target.value})),placeholder:"https://..."})]})]}),e.jsx("div",{className:"cedros-admin__form-row",children:e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Short description"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.description,onChange:t=>h(n=>({...n,description:t.target.value})),placeholder:"e.g., Midweight fleece with relaxed fit",required:!0})]})}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsx(M.FormDropdown,{value:s.productType,onChange:t=>h(n=>({...n,productType:t,storeManagedKind:t==="subscription"?"auto_renewable_subscription":n.storeManagedKind==="auto_renewable_subscription"?"non_consumable":n.storeManagedKind,giftCardConfig:t==="gift_card"?n.giftCardConfig??{faceValueCents:0,currency:"usd",secondaryMarket:!1,expiresInDays:null}:null,tokenizedAssetConfig:t==="tokenized_asset"?n.tokenizedAssetConfig??{assetClassCollectionId:"",backingValueCents:0,backingCurrency:"usd",assetIdentifier:"",tokensPerUnit:1,custodyProofUrl:null}:null})),options:[{value:"one_time",label:"One-time purchase"},{value:"pay_per_access",label:"Pay per access"},{value:"subscription",label:"Subscription"},{value:"gift_card",label:"Gift card"},{value:"tokenized_asset",label:"Tokenized asset"}],label:"Product Type"}),e.jsx(M.FormDropdown,{value:s.fulfillmentType,onChange:t=>{const n=t;h(P=>({...P,fulfillmentType:n,storePolicyFulfillment:n==="shipping"?"physical_goods":n==="service"?"real_world_service":"digital_in_app",storeManagedKind:n==="shipping"||n==="service"?"none":P.productType==="subscription"?"auto_renewable_subscription":P.storeManagedKind==="none"?"non_consumable":P.storeManagedKind,checkoutShippingAddress:n==="shipping"?P.checkoutShippingAddress:!1}))},options:[{value:"shipping",label:"Physical (shipped)"},{value:"digital_download",label:"Digital download"},{value:"service",label:"Service"}],label:"Fulfillment"})]}),e.jsxs("div",{style:{padding:"0.9rem 1rem",borderRadius:"0.75rem",border:"1px solid var(--cedros-admin-border, #e5e7eb)",background:"var(--cedros-admin-surface, #ffffff)",marginBottom:"1rem"},children:[e.jsx("div",{style:{fontWeight:700,marginBottom:"0.35rem"},children:"Store policy and app billing"}),e.jsx("div",{style:{fontSize:"0.9rem",lineHeight:1.6,opacity:.8},children:"This controls how Cedros routes payments across the web, Apple App Store, and Google Play. For digital app functionality, choose the explicit store policy classification here instead of relying on generic product type labels."})]}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsx(M.FormDropdown,{value:s.storePolicyFulfillment,onChange:t=>h(n=>({...n,storePolicyFulfillment:t,storeManagedKind:t==="physical_goods"||t==="real_world_service"?"none":n.storeManagedKind})),options:[{value:"digital_in_app",label:"Digital in-app"},{value:"physical_goods",label:"Physical goods"},{value:"real_world_service",label:"Real-world service"},{value:"reader_content",label:"Reader content"},{value:"other",label:"Other / review manually"}],label:"Store policy classification"}),e.jsx(M.FormDropdown,{value:s.storeManagedKind,onChange:t=>h(n=>({...n,storeManagedKind:t})),options:[{value:"none",label:"External billing only"},{value:"consumable",label:"Consumable"},{value:"non_consumable",label:"Non-consumable"},{value:"auto_renewable_subscription",label:"Auto-renewing subscription"}],label:"Store-managed product kind"})]}),ie&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Apple product ID"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.appleProductId,onChange:t=>h(n=>({...n,appleProductId:t.target.value})),placeholder:"e.g., com.cedros.pro.monthly"}),e.jsx("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:"Create the matching product in App Store Connect and paste the product ID here."})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Google product ID"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.googleProductId,onChange:t=>h(n=>({...n,googleProductId:t.target.value})),placeholder:"e.g., pro_monthly"}),e.jsx("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:"Create the matching one-time product or subscription in Google Play Console."})]})]}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Google package name"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.googlePackageName,onChange:t=>h(n=>({...n,googlePackageName:t.target.value})),placeholder:"e.g., com.cedros.app"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Google base plan ID"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.googleBasePlanId,onChange:t=>h(n=>({...n,googleBasePlanId:t.target.value})),placeholder:"Required for Google subscriptions"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Google offer ID"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.googleOfferId,onChange:t=>h(n=>({...n,googleOfferId:t.target.value})),placeholder:"Optional"})]})]})]}),s.productType==="gift_card"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Gift card face value (USD cents)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:s.giftCardConfig?.faceValueCents??"",onChange:t=>h(n=>({...n,giftCardConfig:{faceValueCents:parseInt(t.target.value)||0,currency:n.giftCardConfig?.currency??"usd",secondaryMarket:n.giftCardConfig?.secondaryMarket??!1,expiresInDays:n.giftCardConfig?.expiresInDays??null}})),placeholder:"e.g., 5000 for $50.00",min:"1",required:!0}),e.jsx("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:"Face value in cents (e.g. 5000 = $50.00). Must be greater than 0."})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Gift card currency"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.giftCardConfig?.currency??"",onChange:t=>h(n=>({...n,giftCardConfig:{faceValueCents:n.giftCardConfig?.faceValueCents??0,currency:t.target.value.toLowerCase().slice(0,3),secondaryMarket:n.giftCardConfig?.secondaryMarket??!1,expiresInDays:n.giftCardConfig?.expiresInDays??null}})),placeholder:"usd",maxLength:3,required:!0}),e.jsx("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:"ISO 4217 3-letter currency code (e.g. usd, eur, gbp)."})]})]}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Expiration (days)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:s.giftCardConfig?.expiresInDays??"",onChange:t=>h(n=>({...n,giftCardConfig:{faceValueCents:n.giftCardConfig?.faceValueCents??0,currency:n.giftCardConfig?.currency??"usd",secondaryMarket:n.giftCardConfig?.secondaryMarket??!1,expiresInDays:t.target.value===""?null:parseInt(t.target.value)||0}})),placeholder:"Leave blank for no expiry",min:"0"}),e.jsx("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:"Number of days until gift card expires. Leave blank for no expiry."})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Secondary market (Token-22)"}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",marginTop:8},children:[e.jsx("input",{type:"checkbox",checked:s.giftCardConfig?.secondaryMarket??!1,onChange:t=>h(n=>({...n,giftCardConfig:{faceValueCents:n.giftCardConfig?.faceValueCents??0,currency:n.giftCardConfig?.currency??"usd",secondaryMarket:t.target.checked,expiresInDays:n.giftCardConfig?.expiresInDays??null}}))}),"Enable Token-22 secondary market trading"]}),e.jsx("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:"Mints store credit tokens to recipient's embedded wallet for peer-to-peer trading with transfer fees."})]})]})]}),s.productType==="tokenized_asset"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Asset class collection"}),d.length>0?e.jsxs("select",{className:"cedros-admin__input",value:s.tokenizedAssetConfig?.assetClassCollectionId??"",onChange:t=>h(n=>({...n,tokenizedAssetConfig:{...n.tokenizedAssetConfig,assetClassCollectionId:t.target.value}})),required:!0,children:[e.jsx("option",{value:"",children:"Select asset class..."}),d.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]}):e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.tokenizedAssetConfig?.assetClassCollectionId??"",onChange:t=>h(n=>({...n,tokenizedAssetConfig:{...n.tokenizedAssetConfig,assetClassCollectionId:t.target.value}})),placeholder:"Collection ID of the asset class",required:!0})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Backing value (cents)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:s.tokenizedAssetConfig?.backingValueCents??0,onChange:t=>h(n=>({...n,tokenizedAssetConfig:{...n.tokenizedAssetConfig,backingValueCents:Number(t.target.value)}})),min:0})]})]}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Backing currency"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.tokenizedAssetConfig?.backingCurrency??"usd",onChange:t=>h(n=>({...n,tokenizedAssetConfig:{...n.tokenizedAssetConfig,backingCurrency:t.target.value}})),placeholder:"usd",maxLength:3})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Asset identifier"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.tokenizedAssetConfig?.assetIdentifier??"",onChange:t=>h(n=>({...n,tokenizedAssetConfig:{...n.tokenizedAssetConfig,assetIdentifier:t.target.value}})),placeholder:"e.g., ISIN, lot number"})]})]}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Tokens per unit"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:s.tokenizedAssetConfig?.tokensPerUnit??1,onChange:t=>h(n=>({...n,tokenizedAssetConfig:{...n.tokenizedAssetConfig,tokensPerUnit:Number(t.target.value)}})),min:1})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Custody proof URL"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.tokenizedAssetConfig?.custodyProofUrl??"",onChange:t=>h(n=>({...n,tokenizedAssetConfig:{...n.tokenizedAssetConfig,custodyProofUrl:t.target.value||null}})),placeholder:"https://..."})]})]})]}),s.fulfillmentType==="shipping"&&e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsx(M.FormDropdown,{value:s.inventoryStatus,onChange:t=>h(n=>({...n,inventoryStatus:t})),options:[{value:"in_stock",label:"In stock"},{value:"low",label:"Low"},{value:"out_of_stock",label:"Out of stock"},{value:"backorder",label:"Backorder"}],label:"Inventory status"}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Inventory quantity (tracked)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:s.inventoryQuantity,onChange:t=>h(n=>({...n,inventoryQuantity:t.target.value===""?"":parseInt(t.target.value)||0})),placeholder:"Leave blank for untracked",min:"0"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Compare-at price (USD)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:s.compareAtUsd===""?"":s.compareAtUsd,onChange:t=>h(n=>({...n,compareAtUsd:t.target.value===""?"":parseFloat(t.target.value)||0})),placeholder:"e.g., 78.00",min:"0",step:"0.01"})]})]}),e.jsx("div",{className:"cedros-admin__form-row",children:e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Price (USD)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:s.priceUsd===""?"":s.priceUsd,onChange:t=>h(n=>({...n,priceUsd:t.target.value===""?"":parseFloat(t.target.value)||0})),placeholder:"e.g., 5.00",min:"0",step:"0.01",required:!0})]})}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Tags (comma-separated)"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.tagsCsv,onChange:t=>h(n=>({...n,tagsCsv:t.target.value})),placeholder:"e.g., core, new, gift"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Category IDs (comma-separated)"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.categoryIdsCsv,onChange:t=>h(n=>({...n,categoryIdsCsv:t.target.value})),placeholder:"e.g., cat_apparel, cat_accessories"})]})]}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsx(M.FormDropdown,{value:s.checkoutEmail,onChange:t=>h(n=>({...n,checkoutEmail:t})),options:[{value:"none",label:"None"},{value:"optional",label:"Optional"},{value:"required",label:"Required"}],label:"Checkout: Email"}),e.jsx(M.FormDropdown,{value:s.checkoutName,onChange:t=>h(n=>({...n,checkoutName:t})),options:[{value:"none",label:"None"},{value:"optional",label:"Optional"},{value:"required",label:"Required"}],label:"Checkout: Name"}),e.jsx(M.FormDropdown,{value:s.checkoutPhone,onChange:t=>h(n=>({...n,checkoutPhone:t})),options:[{value:"none",label:"None"},{value:"optional",label:"Optional"},{value:"required",label:"Required"}],label:"Checkout: Phone"})]}),e.jsxs("div",{className:"cedros-admin__form-row",children:[s.fulfillmentType==="shipping"&&e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Checkout: Shipping address"}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[e.jsx("input",{type:"checkbox",checked:s.checkoutShippingAddress,onChange:t=>h(n=>({...n,checkoutShippingAddress:t.target.checked}))}),"Collect shipping address"]})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Checkout: Billing address"}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[e.jsx("input",{type:"checkbox",checked:s.checkoutBillingAddress,onChange:t=>h(n=>({...n,checkoutBillingAddress:t.target.checked}))}),"Collect billing address"]})]})]}),e.jsx("div",{className:"cedros-admin__form-row",children:e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Fulfillment notes"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.fulfillmentNotes,onChange:t=>h(n=>({...n,fulfillmentNotes:t.target.value})),placeholder:s.fulfillmentType==="shipping"?"e.g., Ships within 3-5 business days":"e.g., Downloadable from your account after purchase"})]})}),s.fulfillmentType==="shipping"&&s.checkoutShippingAddress&&e.jsx("div",{className:"cedros-admin__form-row",children:e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Shipping countries"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:s.shippingCountriesCsv,onChange:t=>h(n=>({...n,shippingCountriesCsv:t.target.value})),placeholder:"e.g., US,CA"}),e.jsx("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:"ISO 2-letter country codes, comma-separated. Required for shipping address collection."})]})}),e.jsx(Ce,{value:s.complianceRequirements,onChange:t=>h(n=>({...n,complianceRequirements:t}))}),e.jsx("div",{className:"cedros-admin__form-actions",children:e.jsx("button",{type:"submit",className:"cedros-admin__button cedros-admin__button--primary",disabled:k,children:k?"Creating...":"Create Product"})})]}),N?e.jsxs("div",{className:"cedros-admin__loading",children:[$.Icons.loading," Loading products..."]}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{"aria-sort":C?.key==="id"?C?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>K("id"),children:["ID",Y("id")]})}),e.jsx("th",{"aria-sort":C?.key==="product"?C?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>K("product"),children:["Product",Y("product")]})}),e.jsx("th",{"aria-sort":C?.key==="type"?C?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>K("type"),children:["Type",Y("type")]})}),e.jsx("th",{"aria-sort":C?.key==="price"?C?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>K("price"),children:["Price",Y("price")]})}),e.jsx("th",{"aria-sort":C?.key==="status"?C?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>K("status"),children:["Status",Y("status")]})}),e.jsx("th",{children:"Actions"})]})}),e.jsx("tbody",{children:he.map(t=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{children:t.id})}),e.jsx("td",{children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[E(t)?e.jsx("img",{src:E(t),alt:"",style:{width:28,height:28,borderRadius:6,objectFit:"cover"}}):e.jsx("div",{style:{width:28,height:28,borderRadius:6,background:"rgba(0,0,0,0.06)"}}),e.jsxs("div",{style:{display:"flex",flexDirection:"column"},children:[e.jsx("span",{style:{fontWeight:600},children:L(t)}),e.jsx("span",{style:{opacity:.8},children:t.description}),ae(t)?e.jsx("span",{style:{opacity:.7,fontSize:"0.8rem"},children:ae(t)}):null]})]})}),e.jsx("td",{children:se(t.metadata?.product_type)}),e.jsx("td",{children:me(t.fiatAmountCents)}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge ${t.active?"cedros-admin__badge--success":"cedros-admin__badge--muted"}`,children:t.active?"Active":"Inactive"})}),e.jsx("td",{children:e.jsxs("div",{style:{display:"flex",gap:"0.25rem"},children:[e.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>c(t),children:"Variations"}),t.metadata?.product_type==="tokenized_asset"&&e.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",onClick:()=>l(t),children:"NFT"})]})})]},t.id))})]})}),_&&e.jsx("div",{className:"cedros-admin__modal-overlay",onClick:()=>c(null),children:e.jsx("div",{className:"cedros-admin__modal cedros-admin__modal--lg",onClick:t=>t.stopPropagation(),children:e.jsx(je,{serverUrl:p,productId:_.id,productTitle:L(_),defaultPrice:_.fiatAmountCents/100,apiKey:o,authManager:u,onClose:()=>c(null)})})}),a&&e.jsx("div",{className:"cedros-admin__modal-overlay",onClick:()=>l(null),children:e.jsx("div",{className:"cedros-admin__modal cedros-admin__modal--lg",onClick:t=>t.stopPropagation(),children:e.jsx(Ne,{serverUrl:p,productId:a.id,productTitle:L(a),apiKey:o,authManager:u,onClose:()=>l(null)})})})]})}function Se({serverUrl:p,apiKey:o,pageSize:b=20,authManager:u}){const[g,A]=r.useState([]),[N,T]=r.useState(null),[f,V]=r.useState(!0),[k,v]=r.useState(!0),[S,R]=r.useState(null),[_,c]=r.useState(""),[a,l]=r.useState(null),C=r.useCallback(async()=>{v(!0);try{R(null);let I;if(u?.isAuthenticated())I=await u.fetchWithAuth("/admin/stats");else{const d={"Content-Type":"application/json"};o&&(d["X-API-Key"]=o);const m=await fetch(`${p}/admin/stats`,{headers:d});if(!m.ok)throw new Error(`Failed to fetch stats: ${m.status}`);I=await m.json()}T(I)}catch{T(null),R("Failed to load payment stats")}finally{v(!1)}},[p,o,u]);r.useEffect(()=>{C()},[C]);const y=r.useCallback(async()=>{try{R(null);let I;const d=new URLSearchParams({limit:b.toString()});_&&d.set("method",_);const m=`/admin/transactions?${d}`;if(u?.isAuthenticated())I=await u.fetchWithAuth(m);else{const L={"Content-Type":"application/json"};o&&(L["X-API-Key"]=o);const E=await fetch(`${p}${m}`,{headers:L});if(!E.ok)throw new Error(`Failed to fetch transactions: ${E.status}`);I=await E.json()}A(I.transactions||[])}catch{A([]),R("Failed to load transactions")}finally{V(!1)}},[p,o,b,_,u]);r.useEffect(()=>{y()},[y]);const D=(I,d="USD")=>new Intl.NumberFormat("en-US",{style:"currency",currency:d}).format(I),j=I=>{l(d=>!d||d.key!==I?{key:I,direction:"asc"}:{key:I,direction:d.direction==="asc"?"desc":"asc"})},s=I=>!a||a.key!==I?e.jsx("span",{className:"cedros-admin__sort-icon cedros-admin__sort-icon--idle",children:$.Icons.chevronUp}):e.jsx("span",{className:"cedros-admin__sort-icon",children:a.direction==="asc"?$.Icons.chevronUp:$.Icons.chevronDown}),h=r.useMemo(()=>{if(!a)return g;const I=a.direction==="asc"?1:-1,d=m=>{switch(a.key){case"resource":return m.resourceId;case"method":return m.method;case"amount":return m.amount;case"status":return m.status;case"date":return new Date(m.paidAt).getTime();case"id":default:return m.id}};return[...g].sort((m,L)=>{const E=d(m),O=d(L);return typeof E=="number"&&typeof O=="number"?(E-O)*I:String(E).localeCompare(String(O),void 0,{sensitivity:"base"})*I})},[g,a]);return e.jsxs("div",{className:"cedros-admin__page",children:[e.jsx(ne.ErrorBanner,{message:S,onRetry:()=>{C(),y()}}),e.jsx(ce.StatsBar,{stats:[{label:"Revenue",value:D(N?.totalRevenue??0)},{label:"Orders",value:N?.totalTransactions??0},{label:"Card",value:D(N?.revenueByMethod.stripe??0),description:`${N?.transactionsByMethod.stripe??0} orders`},{label:"Crypto",value:D(N?.revenueByMethod.x402??0),description:`${N?.transactionsByMethod.x402??0} orders`},{label:"Credits",value:D(N?.revenueByMethod.credits??0),description:`${N?.transactionsByMethod.credits??0} orders`}],isLoading:k,onRefresh:C}),e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsx("h3",{className:"cedros-admin__section-title",children:"Transaction History"}),e.jsx(M.FilterDropdown,{value:_,onChange:c,options:[{value:"",label:"All"},{value:"stripe",label:"Card"},{value:"x402",label:"Crypto"},{value:"credits",label:"Credits"}]})]}),f?e.jsxs("div",{className:"cedros-admin__loading",children:[$.Icons.loading," Loading transactions..."]}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{"aria-sort":a?.key==="id"?a?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>j("id"),children:["ID",s("id")]})}),e.jsx("th",{"aria-sort":a?.key==="resource"?a?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>j("resource"),children:["Resource",s("resource")]})}),e.jsx("th",{"aria-sort":a?.key==="method"?a?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>j("method"),children:["Method",s("method")]})}),e.jsx("th",{"aria-sort":a?.key==="amount"?a?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>j("amount"),children:["Amount",s("amount")]})}),e.jsx("th",{"aria-sort":a?.key==="status"?a?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>j("status"),children:["Status",s("status")]})}),e.jsx("th",{"aria-sort":a?.key==="date"?a?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>j("date"),children:["Date",s("date")]})})]})}),e.jsx("tbody",{children:h.map(I=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{children:I.id})}),e.jsx("td",{children:I.resourceId}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${I.method}`,children:I.method})}),e.jsxs("td",{children:["$",I.amount.toFixed(2)," ",I.currency.toUpperCase()]}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${I.status}`,children:I.status})}),e.jsx("td",{children:de.formatDateTime(I.paidAt)})]},I.id))})]})})]})}function we({serverUrl:p,apiKey:o,pageSize:b=20,authManager:u}){const[g,A]=r.useState([]),[N,T]=r.useState(!0),[f,V]=r.useState(!1),[k,v]=r.useState(!1),[S,R]=r.useState(null),[_,c]=r.useState(null),[a,l]=r.useState({code:"",discountType:"percentage",discountValue:0,usageLimit:void 0,expiresAt:"",scope:"all_products",productIdsCsv:"",categoryIdsCsv:"",paymentMethod:"any",autoApply:!1,appliesAt:"both",startsAt:"",minimumAmountUsd:"",usageLimitPerCustomer:void 0,firstPurchaseOnly:!1}),C=r.useCallback(async()=>{try{c(null);let d;const m=`/admin/coupons?limit=${b}`;if(u?.isAuthenticated())d=await u.fetchWithAuth(m);else{const L={"Content-Type":"application/json"};o&&(L["X-API-Key"]=o);const E=await fetch(`${p}${m}`,{headers:L});if(!E.ok)throw new Error(`Failed to fetch coupons: ${E.status}`);d=await E.json()}A(d.coupons||[])}catch(d){te.getLogger().error("[CouponsSection] Failed to fetch coupons:",d,{serverUrl:p.slice(0,20)+"...",hasApiKey:!!o}),A([]),c("Failed to load coupons")}finally{T(!1)}},[p,o,b,u]);r.useEffect(()=>{C()},[C]);const y=async d=>{if(d.preventDefault(),!(!a.code||a.discountValue<=0)){v(!0);try{const m=a.minimumAmountUsd?Math.round(Number(a.minimumAmountUsd)*100):void 0,L=a.productIdsCsv.split(",").map(F=>F.trim()).filter(Boolean),E=a.categoryIdsCsv.split(",").map(F=>F.trim()).filter(Boolean),O={code:a.code,discountType:a.discountType,discountValue:a.discountValue,usageLimit:a.usageLimit,active:!0,usageCount:0,scope:a.scope,...L.length?{productIds:L}:{},...E.length?{categoryIds:E}:{},...a.paymentMethod!=="any"?{paymentMethod:a.paymentMethod}:{},...a.autoApply?{autoApply:!0}:{},...a.appliesAt!=="both"?{appliesAt:a.appliesAt}:{},...a.startsAt?{startsAt:a.startsAt}:{},...a.expiresAt?{expiresAt:a.expiresAt}:{},...m?{minimumAmountCents:m}:{},...a.usageLimitPerCustomer?{usageLimitPerCustomer:a.usageLimitPerCustomer}:{},...a.firstPurchaseOnly?{firstPurchaseOnly:!0}:{}};if(u?.isAuthenticated())await u.fetchWithAuth("/admin/coupons",{method:"POST",body:JSON.stringify(O)});else{const F={"Content-Type":"application/json"};o&&(F["X-API-Key"]=o);const H=await fetch(`${p}/admin/coupons`,{method:"POST",headers:F,body:JSON.stringify(O)});if(!H.ok)throw new Error(`Failed to create coupon: ${H.status}`)}l({code:"",discountType:"percentage",discountValue:0,usageLimit:void 0,expiresAt:"",scope:"all_products",productIdsCsv:"",categoryIdsCsv:"",paymentMethod:"any",autoApply:!1,appliesAt:"both",startsAt:"",minimumAmountUsd:"",usageLimitPerCustomer:void 0,firstPurchaseOnly:!1}),V(!1),C()}catch(m){te.getLogger().error("[CouponsSection] Failed to add coupon:",m,{serverUrl:p.slice(0,20)+"...",hasApiKey:!!o}),c("Failed to create coupon")}finally{v(!1)}}},D=g.filter(d=>d.active).length,j=g.reduce((d,m)=>d+(m.usageCount??0),0),s=d=>{R(m=>!m||m.key!==d?{key:d,direction:"asc"}:{key:d,direction:m.direction==="asc"?"desc":"asc"})},h=d=>!S||S.key!==d?e.jsx("span",{className:"cedros-admin__sort-icon cedros-admin__sort-icon--idle",children:$.Icons.chevronUp}):e.jsx("span",{className:"cedros-admin__sort-icon",children:S.direction==="asc"?$.Icons.chevronUp:$.Icons.chevronDown}),I=r.useMemo(()=>{if(!S)return g;const d=S.direction==="asc"?1:-1,m=L=>{switch(S.key){case"discount":return L.discountValue??0;case"usage":return L.usageCount??0;case"status":return L.active?1:0;case"code":default:return L.code}};return[...g].sort((L,E)=>{const O=m(L),F=m(E);return typeof O=="number"&&typeof F=="number"?(O-F)*d:String(O).localeCompare(String(F),void 0,{sensitivity:"base"})*d})},[g,S]);return e.jsxs("div",{className:"cedros-admin__page",children:[e.jsx(ne.ErrorBanner,{message:_,onRetry:C}),e.jsx(ce.StatsBar,{stats:[{label:"Total Coupons",value:g.length},{label:"Active",value:D,variant:D>0?"success":"muted"},{label:"Redemptions",value:j}],isLoading:N}),e.jsxs("div",{className:"cedros-admin__section-header",children:[e.jsx("h3",{className:"cedros-admin__section-title",children:"Discount Coupons"}),e.jsxs("button",{className:"cedros-admin__button cedros-admin__button--primary cedros-admin__button--action",onClick:()=>V(!f),children:[f?$.Icons.close:$.Icons.plus,f?"Cancel":"Add Coupon"]})]}),f&&e.jsxs("form",{onSubmit:y,className:"cedros-admin__add-form",children:[e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Coupon Code"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.code,onChange:d=>l(m=>({...m,code:d.target.value.toUpperCase()})),placeholder:"e.g., SAVE20",required:!0})]}),e.jsx(M.FormDropdown,{value:a.discountType,onChange:d=>l(m=>({...m,discountType:d})),options:[{value:"percentage",label:"Percentage (%)"},{value:"fixed",label:"Fixed Amount ($)"}],label:"Discount Type"})]}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsxs("label",{className:"cedros-admin__field-label",children:["Discount Value ",a.discountType==="percentage"?"(%)":"($)"]}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:a.discountValue||"",onChange:d=>l(m=>({...m,discountValue:parseFloat(d.target.value)||0})),placeholder:a.discountType==="percentage"?"e.g., 20":"e.g., 10.00",min:"0",step:a.discountType==="percentage"?"1":"0.01",required:!0})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Usage Limit (optional)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:a.usageLimit||"",onChange:d=>l(m=>({...m,usageLimit:d.target.value?parseInt(d.target.value):void 0})),placeholder:"Leave empty for unlimited",min:"1"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Expiration Date (optional)"}),e.jsx("input",{type:"date",className:"cedros-admin__input",value:a.expiresAt,onChange:d=>l(m=>({...m,expiresAt:d.target.value}))})]})]}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsx(M.FormDropdown,{value:a.scope,onChange:d=>l(m=>({...m,scope:d})),options:[{value:"all_products",label:"All Products"},{value:"specific_products",label:"Specific Products"},{value:"specific_categories",label:"Specific Categories"}],label:"Scope"}),e.jsx(M.FormDropdown,{value:a.paymentMethod,onChange:d=>l(m=>({...m,paymentMethod:d})),options:[{value:"any",label:"Any Payment Method"},{value:"stripe",label:"Stripe (Card) Only"},{value:"x402",label:"Crypto (x402) Only"},{value:"credits",label:"Credits Only"}],label:"Payment Method"}),e.jsx(M.FormDropdown,{value:a.appliesAt,onChange:d=>l(m=>({...m,appliesAt:d})),options:[{value:"both",label:"Cart & Checkout"},{value:"cart",label:"Cart Only"},{value:"checkout",label:"Checkout Only"}],label:"Applies At"})]}),a.scope==="specific_products"&&e.jsx("div",{className:"cedros-admin__form-row",children:e.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Product IDs"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.productIdsCsv,onChange:d=>l(m=>({...m,productIdsCsv:d.target.value})),placeholder:"e.g., prod_123, prod_456"}),e.jsx("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:"Comma-separated product IDs this coupon applies to."})]})}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Start Date (optional)"}),e.jsx("input",{type:"date",className:"cedros-admin__input",value:a.startsAt,onChange:d=>l(m=>({...m,startsAt:d.target.value}))})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Auto Apply"}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[e.jsx("input",{type:"checkbox",checked:a.autoApply,onChange:d=>l(m=>({...m,autoApply:d.target.checked}))}),"Automatically apply when conditions met"]})]})]}),e.jsxs("div",{className:"cedros-admin__form-row",children:[e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Minimum Purchase (USD)"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:a.minimumAmountUsd===""?"":a.minimumAmountUsd,onChange:d=>l(m=>({...m,minimumAmountUsd:d.target.value===""?"":parseFloat(d.target.value)||0})),placeholder:"e.g., 50.00",min:"0",step:"0.01"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Per-Customer Limit"}),e.jsx("input",{type:"number",className:"cedros-admin__input",value:a.usageLimitPerCustomer||"",onChange:d=>l(m=>({...m,usageLimitPerCustomer:d.target.value?parseInt(d.target.value):void 0})),placeholder:"Leave empty for unlimited",min:"1"})]}),e.jsxs("div",{className:"cedros-admin__field",children:[e.jsx("label",{className:"cedros-admin__field-label",children:"First Purchase Only"}),e.jsxs("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem"},children:[e.jsx("input",{type:"checkbox",checked:a.firstPurchaseOnly,onChange:d=>l(m=>({...m,firstPurchaseOnly:d.target.checked}))}),"New customers only"]})]})]}),a.scope==="specific_categories"&&e.jsx("div",{className:"cedros-admin__form-row",children:e.jsxs("div",{className:"cedros-admin__field",style:{flex:1},children:[e.jsx("label",{className:"cedros-admin__field-label",children:"Category IDs"}),e.jsx("input",{type:"text",className:"cedros-admin__input",value:a.categoryIdsCsv,onChange:d=>l(m=>({...m,categoryIdsCsv:d.target.value})),placeholder:"e.g., cat_apparel, cat_accessories"}),e.jsx("div",{style:{marginTop:4,fontSize:12,opacity:.75},children:"Comma-separated category IDs this coupon applies to."})]})}),e.jsx("div",{className:"cedros-admin__form-actions",children:e.jsx("button",{type:"submit",className:"cedros-admin__button cedros-admin__button--primary",disabled:k,children:k?"Creating...":"Create Coupon"})})]}),N?e.jsxs("div",{className:"cedros-admin__loading",children:[$.Icons.loading," Loading coupons..."]}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{"aria-sort":S?.key==="code"?S?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>s("code"),children:["Code",h("code")]})}),e.jsx("th",{"aria-sort":S?.key==="discount"?S?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>s("discount"),children:["Discount",h("discount")]})}),e.jsx("th",{"aria-sort":S?.key==="usage"?S?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>s("usage"),children:["Usage",h("usage")]})}),e.jsx("th",{"aria-sort":S?.key==="status"?S?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>s("status"),children:["Status",h("status")]})}),e.jsx("th",{children:"Actions"})]})}),e.jsx("tbody",{children:I.map(d=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{children:d.code})}),e.jsx("td",{children:d.discountType==="percentage"?`${d.discountValue}%`:`$${d.discountValue.toFixed(2)}`}),e.jsxs("td",{children:[d.usageCount,d.usageLimit?` / ${d.usageLimit}`:""]}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge ${d.active?"cedros-admin__badge--success":"cedros-admin__badge--muted"}`,children:d.active?"Active":"Inactive"})}),e.jsx("td",{children:e.jsx("button",{className:"cedros-admin__button cedros-admin__button--ghost",children:"Edit"})})]},d.code))})]})})]})}function Ae({serverUrl:p,apiKey:o,pageSize:b=20,authManager:u}){const[g,A]=r.useState([]),[N,T]=r.useState(!0),[f,V]=r.useState(null),[k,v]=r.useState([]),[S,R]=r.useState(!0),[_,c]=r.useState(null),[a,l]=r.useState([]),[C,y]=r.useState(!0),[D,j]=r.useState(null),[s,h]=r.useState(null),[I,d]=r.useState(null),m=r.useCallback(async()=>{try{let i;const x=`/admin/refunds?limit=${b}`;if(u?.isAuthenticated())i=await u.fetchWithAuth(x);else{const w={"Content-Type":"application/json"};o&&(w["X-API-Key"]=o);const q=await fetch(`${p}${x}`,{headers:w});if(!q.ok)throw new Error(`Failed to fetch x402 refunds: ${q.status}`);i=await q.json()}A(i.refunds||[])}catch(i){te.getLogger().error("[RefundsSection] Failed to fetch x402 refunds:",i,{serverUrl:p.slice(0,20)+"...",hasApiKey:!!o}),A([]),d("Failed to load x402 refunds")}finally{T(!1)}},[p,o,b,u]);r.useEffect(()=>{m()},[m]);const L=r.useCallback(async()=>{try{let i;const x=`/admin/credits/refund-requests?status=pending&limit=${b}&offset=0`;if(u?.isAuthenticated())i=await u.fetchWithAuth(x);else{const q={"Content-Type":"application/json"};o&&(q["X-API-Key"]=o);const G=await fetch(`${p}${x}`,{headers:q});if(!G.ok)throw new Error(`Failed to fetch credits refund requests: ${G.status}`);i=await G.json()}const w=Array.isArray(i)?i:"refundRequests"in i?i.refundRequests:i.requests||[];v(w)}catch(i){te.getLogger().error("[RefundsSection] Failed to fetch credits refunds:",i,{serverUrl:p.slice(0,20)+"...",hasApiKey:!!o}),v([]),d("Failed to load credits refunds")}finally{R(!1)}},[p,o,b,u]);r.useEffect(()=>{L()},[L]);const E=r.useCallback(async()=>{try{let i;const x=`/admin/stripe/refunds?limit=${b}`;if(u?.isAuthenticated())i=await u.fetchWithAuth(x);else{const w={"Content-Type":"application/json"};o&&(w["X-API-Key"]=o);const q=await fetch(`${p}${x}`,{headers:w});if(!q.ok)throw new Error(`Failed to fetch Stripe refunds: ${q.status}`);i=await q.json()}l(i.refunds||[])}catch(i){te.getLogger().error("[RefundsSection] Failed to fetch Stripe refunds:",i,{serverUrl:p.slice(0,20)+"...",hasApiKey:!!o}),l([]),d("Failed to load Stripe refunds")}finally{y(!1)}},[p,o,b,u]);r.useEffect(()=>{E()},[E]);const O=async i=>{j(i);try{const x=`/admin/stripe/refunds/${i}/process`;if(u?.isAuthenticated())await u.fetchWithAuth(x,{method:"POST"});else{const w={"Content-Type":"application/json"};o&&(w["X-API-Key"]=o);const q=await fetch(`${p}${x}`,{method:"POST",headers:w});if(!q.ok)throw new Error(`Failed to process refund: ${q.status}`)}await E()}catch(x){te.getLogger().error("[RefundsSection] Failed to process Stripe refund:",x,{serverUrl:p.slice(0,20)+"...",hasApiKey:!!o,refundId:i}),d("Failed to process Stripe refund")}finally{j(null)}},F=(i,x)=>new Intl.NumberFormat("en-US",{style:"currency",currency:x}).format(i/100),H=i=>i?i.replace(/_/g," ").replace(/\b\w/g,x=>x.toUpperCase()):"—",le=i=>{switch(i){case"processed":return"success";case"pending":return"pending";case"rejected":default:return"muted"}},ae=(i,x)=>x?x.toLowerCase()==="usd"?`${new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(i/1e6)} (USD credits)`:`${i.toLocaleString()} ${x.toUpperCase()} (atomic)`:`${i.toLocaleString()} (atomic)`,Z=i=>{switch(i){case"succeeded":return"success";case"failed":return"failed";case"pending":case"requires_action":return"pending";case"canceled":default:return"muted"}},ue=i=>i.stripeRefundId??"—",me=i=>i.chargeId??"—",se=a.filter(i=>i.status==="pending"||i.status==="requires_action").length,ie=k.filter(i=>i.status==="pending").length,ee=g.filter(i=>i.status==="pending").length,K=se+ie+ee,Y=a.filter(i=>i.status==="succeeded").reduce((i,x)=>i+x.amount,0),he=k.filter(i=>i.status==="processed").reduce((i,x)=>i+x.amountLamports,0),t=g.filter(i=>i.status==="completed").reduce((i,x)=>i+x.amount,0),n=Y/100+he/1e6+t,P=i=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(i),W=C||S||N,B=i=>{h(x=>!x||x.key!==i?{key:i,direction:"asc"}:{key:i,direction:x.direction==="asc"?"desc":"asc"})},z=i=>{c(x=>!x||x.key!==i?{key:i,direction:"asc"}:{key:i,direction:x.direction==="asc"?"desc":"asc"})},X=i=>{V(x=>!x||x.key!==i?{key:i,direction:"asc"}:{key:i,direction:x.direction==="asc"?"desc":"asc"})},U=(i,x)=>!i||!x?e.jsx("span",{className:"cedros-admin__sort-icon cedros-admin__sort-icon--idle",children:$.Icons.chevronUp}):e.jsx("span",{className:"cedros-admin__sort-icon",children:x==="asc"?$.Icons.chevronUp:$.Icons.chevronDown}),J=r.useMemo(()=>{if(!s)return a;const i=s.direction==="asc"?1:-1,x=w=>{switch(s.key){case"stripe":return w.stripeRefundId??"";case"charge":return w.chargeId??"";case"amount":return w.amount??0;case"reason":return w.reason??"";case"status":return w.status??"";case"date":return new Date(w.createdAt).getTime();case"id":default:return w.id}};return[...a].sort((w,q)=>{const G=x(w),Q=x(q);return typeof G=="number"&&typeof Q=="number"?(G-Q)*i:String(G).localeCompare(String(Q),void 0,{sensitivity:"base"})*i})},[a,s]),oe=r.useMemo(()=>{if(!_)return k;const i=_.direction==="asc"?1:-1,x=w=>{switch(_.key){case"original":return w.originalTransactionId??"";case"user":return w.userId??"";case"amount":return w.amountLamports??0;case"reason":return w.reason??"";case"status":return w.status??"";case"date":return new Date(w.createdAt).getTime();case"id":default:return w.id}};return[...k].sort((w,q)=>{const G=x(w),Q=x(q);return typeof G=="number"&&typeof Q=="number"?(G-Q)*i:String(G).localeCompare(String(Q),void 0,{sensitivity:"base"})*i})},[k,_]),re=r.useMemo(()=>{if(!f)return g;const i=f.direction==="asc"?1:-1,x=w=>{switch(f.key){case"transaction":return w.transactionId??"";case"amount":return w.amount??0;case"reason":return w.reason??"";case"status":return w.status??"";case"date":return new Date(w.createdAt).getTime();case"id":default:return w.id}};return[...g].sort((w,q)=>{const G=x(w),Q=x(q);return typeof G=="number"&&typeof Q=="number"?(G-Q)*i:String(G).localeCompare(String(Q),void 0,{sensitivity:"base"})*i})},[g,f]);return e.jsxs("div",{className:"cedros-admin__page",children:[e.jsx(ne.ErrorBanner,{message:I,onRetry:()=>{m(),L(),E()}}),e.jsx(ce.StatsBar,{stats:[{label:"Pending",value:K,variant:K>0?"warning":"muted"},{label:"Card Pending",value:se,description:"Stripe"},{label:"Credits Pending",value:ie},{label:"Crypto Pending",value:ee,description:"x402"},{label:"Total Refunded",value:P(n),variant:"success"}],isLoading:W}),e.jsx("div",{className:"cedros-admin__section-header",children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Stripe Refund Requests"})}),C?e.jsxs("div",{className:"cedros-admin__loading",children:[$.Icons.loading," Loading Stripe refunds..."]}):a.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No Stripe refund requests found."}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{"aria-sort":s?.key==="id"?s?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>B("id"),children:["Request ID",U(s?.key==="id",s?.direction)]})}),e.jsx("th",{"aria-sort":s?.key==="stripe"?s?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>B("stripe"),children:["Stripe Refund ID",U(s?.key==="stripe",s?.direction)]})}),e.jsx("th",{"aria-sort":s?.key==="charge"?s?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>B("charge"),children:["Charge",U(s?.key==="charge",s?.direction)]})}),e.jsx("th",{"aria-sort":s?.key==="amount"?s?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>B("amount"),children:["Amount",U(s?.key==="amount",s?.direction)]})}),e.jsx("th",{"aria-sort":s?.key==="reason"?s?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>B("reason"),children:["Reason",U(s?.key==="reason",s?.direction)]})}),e.jsx("th",{"aria-sort":s?.key==="status"?s?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>B("status"),children:["Status",U(s?.key==="status",s?.direction)]})}),e.jsx("th",{"aria-sort":s?.key==="date"?s?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>B("date"),children:["Date",U(s?.key==="date",s?.direction)]})}),e.jsx("th",{children:"Actions"})]})}),e.jsx("tbody",{children:J.map(i=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{children:i.id})}),e.jsx("td",{children:e.jsx("code",{children:ue(i)})}),e.jsx("td",{children:e.jsx("code",{children:me(i)})}),e.jsx("td",{children:F(i.amount,i.currency)}),e.jsx("td",{children:H(i.reason)}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${Z(i.status)}`,children:i.status})}),e.jsx("td",{children:de.formatDateTime(i.createdAt)}),e.jsx("td",{children:(i.status==="pending"||i.status==="requires_action")&&e.jsx("button",{className:"cedros-admin__button cedros-admin__button--primary cedros-admin__button--sm",onClick:()=>O(i.id),disabled:D===i.id,children:D===i.id?"Processing...":"Process"})})]},i.id))})]})}),e.jsx("div",{className:"cedros-admin__section-header",style:{marginTop:"2rem"},children:e.jsx("h3",{className:"cedros-admin__section-title",children:"Credits Refund Requests"})}),e.jsx("p",{className:"cedros-admin__hint",style:{marginBottom:"0.75rem"},children:"Credits refund requests are read-only in this admin surface."}),S?e.jsxs("div",{className:"cedros-admin__loading",children:[$.Icons.loading," Loading credits refunds..."]}):k.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No credits refund requests found."}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{"aria-sort":_?.key==="id"?_?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>z("id"),children:["Request ID",U(_?.key==="id",_?.direction)]})}),e.jsx("th",{"aria-sort":_?.key==="original"?_?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>z("original"),children:["Original Tx",U(_?.key==="original",_?.direction)]})}),e.jsx("th",{"aria-sort":_?.key==="user"?_?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>z("user"),children:["User",U(_?.key==="user",_?.direction)]})}),e.jsx("th",{"aria-sort":_?.key==="amount"?_?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>z("amount"),children:["Amount",U(_?.key==="amount",_?.direction)]})}),e.jsx("th",{"aria-sort":_?.key==="reason"?_?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>z("reason"),children:["Reason",U(_?.key==="reason",_?.direction)]})}),e.jsx("th",{"aria-sort":_?.key==="status"?_?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>z("status"),children:["Status",U(_?.key==="status",_?.direction)]})}),e.jsx("th",{"aria-sort":_?.key==="date"?_?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>z("date"),children:["Date",U(_?.key==="date",_?.direction)]})})]})}),e.jsx("tbody",{children:oe.map(i=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{children:i.id})}),e.jsx("td",{children:e.jsx("code",{children:i.originalTransactionId})}),e.jsx("td",{children:e.jsx("code",{children:i.userId??"—"})}),e.jsx("td",{children:ae(i.amountLamports,i.currency)}),e.jsx("td",{children:i.reason??"—"}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${le(i.status)}`,children:i.status})}),e.jsx("td",{children:de.formatDateTime(i.createdAt)})]},i.id))})]})}),e.jsx("div",{className:"cedros-admin__section-header",style:{marginTop:"2rem"},children:e.jsx("h3",{className:"cedros-admin__section-title",children:"x402 Refund Requests"})}),e.jsx("p",{className:"cedros-admin__hint",style:{marginBottom:"0.75rem"},children:"x402 refund approvals use the signed refund workflow, not this dashboard table."}),N?e.jsxs("div",{className:"cedros-admin__loading",children:[$.Icons.loading," Loading x402 refunds..."]}):g.length===0?e.jsx("div",{className:"cedros-admin__empty",children:"No x402 refund requests found."}):e.jsx("div",{className:"cedros-admin__table-container",children:e.jsxs("table",{className:"cedros-admin__table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{"aria-sort":f?.key==="id"?f?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>X("id"),children:["ID",U(f?.key==="id",f?.direction)]})}),e.jsx("th",{"aria-sort":f?.key==="transaction"?f?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>X("transaction"),children:["Transaction",U(f?.key==="transaction",f?.direction)]})}),e.jsx("th",{"aria-sort":f?.key==="amount"?f?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>X("amount"),children:["Amount",U(f?.key==="amount",f?.direction)]})}),e.jsx("th",{"aria-sort":f?.key==="reason"?f?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>X("reason"),children:["Reason",U(f?.key==="reason",f?.direction)]})}),e.jsx("th",{"aria-sort":f?.key==="status"?f?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>X("status"),children:["Status",U(f?.key==="status",f?.direction)]})}),e.jsx("th",{"aria-sort":f?.key==="date"?f?.direction==="asc"?"ascending":"descending":"none",children:e.jsxs("button",{type:"button",className:"cedros-admin__table-sort",onClick:()=>X("date"),children:["Date",U(f?.key==="date",f?.direction)]})})]})}),e.jsx("tbody",{children:re.map(i=>e.jsxs("tr",{children:[e.jsx("td",{children:e.jsx("code",{children:i.id})}),e.jsx("td",{children:e.jsx("code",{children:i.transactionId})}),e.jsxs("td",{children:["$",i.amount.toFixed(2)]}),e.jsx("td",{children:i.reason||"—"}),e.jsx("td",{children:e.jsx("span",{className:`cedros-admin__badge cedros-admin__badge--${i.status}`,children:i.status})}),e.jsx("td",{children:de.formatDateTime(i.createdAt)})]},i.id))})]})})]})}const Ie=r.lazy(()=>Promise.resolve().then(()=>require("./SettingsSection-Cz2Yjdhr.js")).then(p=>({default:p.SettingsSection})));function Pe(p){return e.jsx(r.Suspense,{fallback:null,children:e.jsx(Ie,{...p})})}exports.CouponsSection=we;exports.ProductsSection=ke;exports.RefundsSection=Ae;exports.SettingsSection=Pe;exports.TransactionsSection=Se;
|