@cedros/login-react 0.0.26 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("./useAuth-X6Ds6WW4.cjs"),T=require("./useCedrosLogin-C9MrcZvh.cjs"),e=require("react/jsx-runtime"),l=require("react"),V=require("./LoadingSpinner-d6sSxgQN.cjs"),Us=require("./sanitization-Bo_tn-L2.cjs"),K=require("./EmailRegisterForm-B1DB-bqe.cjs"),Me=require("./validation-BuGQrA-K.cjs"),G=require("./ErrorMessage-CHbYbVi2.cjs"),Ws=require("./GoogleLoginButton-D7CoMXLq.cjs"),Xe=require("./mobileWalletAdapter-qENF5Yeh.cjs"),te=require("./PermissionsSection-BPbE-hNx.cjs"),Vt=require("./useSystemSettings-DRrreszl.cjs"),xe=require("./AutosaveStatus-BFj5GIab.cjs"),_s=require("./useOrgs-DDVRCaVi.cjs"),ze=require("./AdminDepositList-b2AXtLg0.cjs"),fe=require("./AdminWithdrawalHistory-DL9zbu2b.cjs"),Pe=require("./useUsersStatsSummary-8qY7iP4G.cjs"),Ht=require("./StatsBar-DTUZCwDD.cjs"),ge=require("./plugin-PU2vAozn.cjs"),Qt=require("./AuthenticationSettings-C9f5MKgj.cjs"),Kt=require("./EmbeddedWalletSettings-Bmx8x21f.cjs"),Oe=require("./EmailSettings-CM5l8qqK.cjs"),Os=require("./CreditSystemSettings-r3gnGjiU.cjs"),Yt=require("./ServerSettings-LIIP5TPz.cjs"),ie=require("./shamir-CiBczzDN.cjs"),$r=require("./useAdminDeposits-BkkCwHWp.cjs"),qs=require("./WebhookSettings-2p9abGm5.cjs");function Ve(s){return s instanceof Uint8Array||ArrayBuffer.isView(s)&&s.constructor.name==="Uint8Array"}function Gt(s,t){return Array.isArray(t)?t.length===0?!0:s?t.every(o=>typeof o=="string"):t.every(o=>Number.isSafeInteger(o)):!1}function Jr(s){if(typeof s!="function")throw new Error("function expected");return!0}function He(s,t){if(typeof t!="string")throw new Error(`${s}: string expected`);return!0}function ke(s){if(!Number.isSafeInteger(s))throw new Error(`invalid integer: ${s}`)}function Qe(s){if(!Array.isArray(s))throw new Error("array expected")}function Ke(s,t){if(!Gt(!0,t))throw new Error(`${s}: array of strings expected`)}function $t(s,t){if(!Gt(!1,t))throw new Error(`${s}: array of numbers expected`)}function Xr(...s){const t=n=>n,o=(n,c)=>i=>n(c(i)),a=s.map(n=>n.encode).reduceRight(o,t),r=s.map(n=>n.decode).reduce(o,t);return{encode:a,decode:r}}function Zr(s){const t=typeof s=="string"?s.split(""):s,o=t.length;Ke("alphabet",t);const a=new Map(t.map((r,n)=>[r,n]));return{encode:r=>(Qe(r),r.map(n=>{if(!Number.isSafeInteger(n)||n<0||n>=o)throw new Error(`alphabet.encode: digit index outside alphabet "${n}". Allowed: ${s}`);return t[n]})),decode:r=>(Qe(r),r.map(n=>{He("alphabet.decode",n);const c=a.get(n);if(c===void 0)throw new Error(`Unknown letter: "${n}". Allowed: ${s}`);return c}))}}function eo(s=""){return He("join",s),{encode:t=>(Ke("join.decode",t),t.join(s)),decode:t=>(He("join.decode",t),t.split(s))}}function so(s,t="="){return ke(s),He("padding",t),{encode(o){for(Ke("padding.encode",o);o.length*s%8;)o.push(t);return o},decode(o){Ke("padding.decode",o);let a=o.length;if(a*s%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;a>0&&o[a-1]===t;a--)if((a-1)*s%8===0)throw new Error("padding: invalid, string has too much padding");return o.slice(0,a)}}}function Ds(s,t,o){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(o<2)throw new Error(`convertRadix: invalid to=${o}, base cannot be less than 2`);if(Qe(s),!s.length)return[];let a=0;const r=[],n=Array.from(s,i=>{if(ke(i),i<0||i>=t)throw new Error(`invalid integer: ${i}`);return i}),c=n.length;for(;;){let i=0,d=!0;for(let h=a;h<c;h++){const p=n[h],f=t*i,g=f+p;if(!Number.isSafeInteger(g)||f/t!==i||g-p!==f)throw new Error("convertRadix: carry overflow");const w=g/o;i=g%o;const m=Math.floor(w);if(n[h]=m,!Number.isSafeInteger(m)||m*o+i!==g)throw new Error("convertRadix: carry overflow");if(d)m?d=!1:a=h;else continue}if(r.push(i),d)break}for(let i=0;i<s.length-1&&s[i]===0;i++)r.push(0);return r.reverse()}const Jt=(s,t)=>t===0?s:Jt(t,s%t),Ye=(s,t)=>s+(t-Jt(s,t)),is=(()=>{let s=[];for(let t=0;t<40;t++)s.push(2**t);return s})();function Is(s,t,o,a){if(Qe(s),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(o<=0||o>32)throw new Error(`convertRadix2: wrong to=${o}`);if(Ye(t,o)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${o} carryBits=${Ye(t,o)}`);let r=0,n=0;const c=is[t],i=is[o]-1,d=[];for(const h of s){if(ke(h),h>=c)throw new Error(`convertRadix2: invalid data word=${h} from=${t}`);if(r=r<<t|h,n+t>32)throw new Error(`convertRadix2: carry overflow pos=${n} from=${t}`);for(n+=t;n>=o;n-=o)d.push((r>>n-o&i)>>>0);const p=is[n];if(p===void 0)throw new Error("invalid carry");r&=p-1}if(r=r<<o-n&i,!a&&n>=t)throw new Error("Excess padding");if(!a&&r>0)throw new Error(`Non-zero padding: ${r}`);return a&&n>0&&d.push(r>>>0),d}function to(s){ke(s);const t=2**8;return{encode:o=>{if(!Ve(o))throw new Error("radix.encode input should be Uint8Array");return Ds(Array.from(o),t,s)},decode:o=>($t("radix.decode",o),Uint8Array.from(Ds(o,s,t)))}}function ro(s,t=!1){if(ke(s),s<=0||s>32)throw new Error("radix2: bits should be in (0..32]");if(Ye(8,s)>32||Ye(s,8)>32)throw new Error("radix2: carry overflow");return{encode:o=>{if(!Ve(o))throw new Error("radix2.encode input should be Uint8Array");return Is(Array.from(o),8,s,!t)},decode:o=>($t("radix2.decode",o),Uint8Array.from(Is(o,s,8,t)))}}function oo(s,t){return ke(s),Jr(t),{encode(o){if(!Ve(o))throw new Error("checksum.encode: input should be Uint8Array");const a=t(o).slice(0,s),r=new Uint8Array(o.length+s);return r.set(o),r.set(a,o.length),r},decode(o){if(!Ve(o))throw new Error("checksum.decode: input should be Uint8Array");const a=o.slice(0,-s),r=o.slice(-s),n=t(a).slice(0,s);for(let c=0;c<s;c++)if(n[c]!==r[c])throw new Error("Invalid checksum");return a}}}const Fe={alphabet:Zr,chain:Xr,checksum:oo,convertRadix:Ds,convertRadix2:Is,radix:to,radix2:ro,join:eo,padding:so};const no=s=>s[0]==="あいこくしん";function ao(s){if(typeof s!="string")throw new TypeError("invalid mnemonic type: "+typeof s);return s.normalize("NFKD")}function io(s){const t=ao(s),o=t.split(" ");if(![12,15,18,21,24].includes(o.length))throw new Error("Invalid mnemonic");return{nfkd:t,words:o}}function Xt(s){ie.abytes(s,16,20,24,28,32)}const lo=s=>{const t=8-s.length/4;return new Uint8Array([ie.sha256(s)[0]>>t<<t])};function Zt(s){if(!Array.isArray(s)||s.length!==2048||typeof s[0]!="string")throw new Error("Wordlist: expected array of 2048 strings");return s.forEach(t=>{if(typeof t!="string")throw new Error("wordlist: non-string element: "+t)}),Fe.chain(Fe.checksum(1,lo),Fe.radix2(11,!0),Fe.alphabet(s))}function zs(s,t){const{words:o}=io(s),a=Zt(t).decode(o);return Xt(a),a}function er(s,t){return Xt(s),Zt(t).encode(s).join(no(t)?" ":" ")}function Vs(s,t){try{zs(s,t)}catch{return!1}return!0}const he=`abandon
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("./useAuth-X6Ds6WW4.cjs"),T=require("./useCedrosLogin-C9MrcZvh.cjs"),e=require("react/jsx-runtime"),l=require("react"),V=require("./LoadingSpinner-d6sSxgQN.cjs"),Us=require("./sanitization-Bo_tn-L2.cjs"),K=require("./EmailRegisterForm-B1DB-bqe.cjs"),Me=require("./validation-BuGQrA-K.cjs"),G=require("./ErrorMessage-CHbYbVi2.cjs"),Ws=require("./GoogleLoginButton-D7CoMXLq.cjs"),Xe=require("./mobileWalletAdapter-BhzZHGIl.cjs"),te=require("./PermissionsSection-BPbE-hNx.cjs"),Vt=require("./useSystemSettings-DRrreszl.cjs"),xe=require("./AutosaveStatus-BFj5GIab.cjs"),_s=require("./useOrgs-DDVRCaVi.cjs"),ze=require("./AdminDepositList-b2AXtLg0.cjs"),fe=require("./AdminWithdrawalHistory-DL9zbu2b.cjs"),Pe=require("./useUsersStatsSummary-8qY7iP4G.cjs"),Ht=require("./StatsBar-DTUZCwDD.cjs"),ge=require("./plugin-PU2vAozn.cjs"),Qt=require("./AuthenticationSettings-C9f5MKgj.cjs"),Kt=require("./EmbeddedWalletSettings-Bmx8x21f.cjs"),Oe=require("./EmailSettings-CM5l8qqK.cjs"),Os=require("./CreditSystemSettings-r3gnGjiU.cjs"),Yt=require("./ServerSettings-LIIP5TPz.cjs"),ie=require("./shamir-CiBczzDN.cjs"),$r=require("./useAdminDeposits-BkkCwHWp.cjs"),qs=require("./WebhookSettings-2p9abGm5.cjs");function Ve(s){return s instanceof Uint8Array||ArrayBuffer.isView(s)&&s.constructor.name==="Uint8Array"}function Gt(s,t){return Array.isArray(t)?t.length===0?!0:s?t.every(o=>typeof o=="string"):t.every(o=>Number.isSafeInteger(o)):!1}function Jr(s){if(typeof s!="function")throw new Error("function expected");return!0}function He(s,t){if(typeof t!="string")throw new Error(`${s}: string expected`);return!0}function ke(s){if(!Number.isSafeInteger(s))throw new Error(`invalid integer: ${s}`)}function Qe(s){if(!Array.isArray(s))throw new Error("array expected")}function Ke(s,t){if(!Gt(!0,t))throw new Error(`${s}: array of strings expected`)}function $t(s,t){if(!Gt(!1,t))throw new Error(`${s}: array of numbers expected`)}function Xr(...s){const t=n=>n,o=(n,c)=>i=>n(c(i)),a=s.map(n=>n.encode).reduceRight(o,t),r=s.map(n=>n.decode).reduce(o,t);return{encode:a,decode:r}}function Zr(s){const t=typeof s=="string"?s.split(""):s,o=t.length;Ke("alphabet",t);const a=new Map(t.map((r,n)=>[r,n]));return{encode:r=>(Qe(r),r.map(n=>{if(!Number.isSafeInteger(n)||n<0||n>=o)throw new Error(`alphabet.encode: digit index outside alphabet "${n}". Allowed: ${s}`);return t[n]})),decode:r=>(Qe(r),r.map(n=>{He("alphabet.decode",n);const c=a.get(n);if(c===void 0)throw new Error(`Unknown letter: "${n}". Allowed: ${s}`);return c}))}}function eo(s=""){return He("join",s),{encode:t=>(Ke("join.decode",t),t.join(s)),decode:t=>(He("join.decode",t),t.split(s))}}function so(s,t="="){return ke(s),He("padding",t),{encode(o){for(Ke("padding.encode",o);o.length*s%8;)o.push(t);return o},decode(o){Ke("padding.decode",o);let a=o.length;if(a*s%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;a>0&&o[a-1]===t;a--)if((a-1)*s%8===0)throw new Error("padding: invalid, string has too much padding");return o.slice(0,a)}}}function Ds(s,t,o){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(o<2)throw new Error(`convertRadix: invalid to=${o}, base cannot be less than 2`);if(Qe(s),!s.length)return[];let a=0;const r=[],n=Array.from(s,i=>{if(ke(i),i<0||i>=t)throw new Error(`invalid integer: ${i}`);return i}),c=n.length;for(;;){let i=0,d=!0;for(let h=a;h<c;h++){const p=n[h],f=t*i,g=f+p;if(!Number.isSafeInteger(g)||f/t!==i||g-p!==f)throw new Error("convertRadix: carry overflow");const w=g/o;i=g%o;const m=Math.floor(w);if(n[h]=m,!Number.isSafeInteger(m)||m*o+i!==g)throw new Error("convertRadix: carry overflow");if(d)m?d=!1:a=h;else continue}if(r.push(i),d)break}for(let i=0;i<s.length-1&&s[i]===0;i++)r.push(0);return r.reverse()}const Jt=(s,t)=>t===0?s:Jt(t,s%t),Ye=(s,t)=>s+(t-Jt(s,t)),is=(()=>{let s=[];for(let t=0;t<40;t++)s.push(2**t);return s})();function Is(s,t,o,a){if(Qe(s),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(o<=0||o>32)throw new Error(`convertRadix2: wrong to=${o}`);if(Ye(t,o)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${o} carryBits=${Ye(t,o)}`);let r=0,n=0;const c=is[t],i=is[o]-1,d=[];for(const h of s){if(ke(h),h>=c)throw new Error(`convertRadix2: invalid data word=${h} from=${t}`);if(r=r<<t|h,n+t>32)throw new Error(`convertRadix2: carry overflow pos=${n} from=${t}`);for(n+=t;n>=o;n-=o)d.push((r>>n-o&i)>>>0);const p=is[n];if(p===void 0)throw new Error("invalid carry");r&=p-1}if(r=r<<o-n&i,!a&&n>=t)throw new Error("Excess padding");if(!a&&r>0)throw new Error(`Non-zero padding: ${r}`);return a&&n>0&&d.push(r>>>0),d}function to(s){ke(s);const t=2**8;return{encode:o=>{if(!Ve(o))throw new Error("radix.encode input should be Uint8Array");return Ds(Array.from(o),t,s)},decode:o=>($t("radix.decode",o),Uint8Array.from(Ds(o,s,t)))}}function ro(s,t=!1){if(ke(s),s<=0||s>32)throw new Error("radix2: bits should be in (0..32]");if(Ye(8,s)>32||Ye(s,8)>32)throw new Error("radix2: carry overflow");return{encode:o=>{if(!Ve(o))throw new Error("radix2.encode input should be Uint8Array");return Is(Array.from(o),8,s,!t)},decode:o=>($t("radix2.decode",o),Uint8Array.from(Is(o,s,8,t)))}}function oo(s,t){return ke(s),Jr(t),{encode(o){if(!Ve(o))throw new Error("checksum.encode: input should be Uint8Array");const a=t(o).slice(0,s),r=new Uint8Array(o.length+s);return r.set(o),r.set(a,o.length),r},decode(o){if(!Ve(o))throw new Error("checksum.decode: input should be Uint8Array");const a=o.slice(0,-s),r=o.slice(-s),n=t(a).slice(0,s);for(let c=0;c<s;c++)if(n[c]!==r[c])throw new Error("Invalid checksum");return a}}}const Fe={alphabet:Zr,chain:Xr,checksum:oo,convertRadix:Ds,convertRadix2:Is,radix:to,radix2:ro,join:eo,padding:so};const no=s=>s[0]==="あいこくしん";function ao(s){if(typeof s!="string")throw new TypeError("invalid mnemonic type: "+typeof s);return s.normalize("NFKD")}function io(s){const t=ao(s),o=t.split(" ");if(![12,15,18,21,24].includes(o.length))throw new Error("Invalid mnemonic");return{nfkd:t,words:o}}function Xt(s){ie.abytes(s,16,20,24,28,32)}const lo=s=>{const t=8-s.length/4;return new Uint8Array([ie.sha256(s)[0]>>t<<t])};function Zt(s){if(!Array.isArray(s)||s.length!==2048||typeof s[0]!="string")throw new Error("Wordlist: expected array of 2048 strings");return s.forEach(t=>{if(typeof t!="string")throw new Error("wordlist: non-string element: "+t)}),Fe.chain(Fe.checksum(1,lo),Fe.radix2(11,!0),Fe.alphabet(s))}function zs(s,t){const{words:o}=io(s),a=Zt(t).decode(o);return Xt(a),a}function er(s,t){return Xt(s),Zt(t).encode(s).join(no(t)?" ":" ")}function Vs(s,t){try{zs(s,t)}catch{return!1}return!0}const he=`abandon
2
2
  ability
3
3
  able
4
4
  about
@@ -2046,7 +2046,7 @@ zebra
2046
2046
  zero
2047
2047
  zone
2048
2048
  zoo`.split(`
2049
- `),oe=12;function co(s){if(s.length!==16)throw new Error(`Invalid share length: expected 16, got ${s.length}`);const o=er(s,he).split(" ");if(o.length!==oe)throw new Error(`Unexpected word count: expected ${oe}, got ${o.length}`);return o}function uo(s){if(s.length!==oe)throw new Error(`Invalid word count: expected ${oe}, got ${s.length}`);const t=s.join(" ").toLowerCase().trim();if(!Vs(t,he))throw new Error("Invalid recovery phrase: checksum mismatch");const o=zs(t,he);if(o.length!==16)throw new Error(`Invalid entropy length: expected 16, got ${o.length}`);return I.toShamirShare(o)}function ho(s){if(s.length!==16)throw new Error(`Invalid seed length: expected 16, got ${s.length}`);const o=er(s,he).split(" ");if(o.length!==oe)throw new Error(`Unexpected word count: expected ${oe}, got ${o.length}`);return o}function po(s){if(s.length!==oe)throw new Error(`Invalid word count: expected ${oe}, got ${s.length}`);const t=s.join(" ").toLowerCase().trim();if(!Vs(t,he))throw new Error("Invalid recovery phrase: checksum mismatch");const o=zs(t,he);if(o.length!==16)throw new Error(`Invalid entropy length: expected 16, got ${o.length}`);return I.toSeed(o)}function sr(s){if(s.length!==oe)return!1;const t=s.join(" ").toLowerCase().trim();return Vs(t,he)}function Ue(s){return he.includes(s.toLowerCase().trim())}function mo(s,t=5){const o=s.toLowerCase().trim();return o.length===0?[]:he.filter(a=>a.startsWith(o)).slice(0,t)}function fo(s){const t=[];for(let o=0;o<s.length;o+=4)t.push(s.slice(o,o+4));return t}function go(s){return s.toLowerCase().replace(/[,\n\r\t]+/g," ").split(/\s+/).map(t=>t.trim()).filter(t=>t.length>0)}function wo({className:s="",variant:t="default",size:o="md",children:a,menuItems:r=[],hideSignOut:n=!1}){const{user:c,isAuthenticated:i,isLoading:d,openLoginModal:h,logout:p}=I.useAuth(),[f,g]=l.useState(!1),[w,m]=l.useState(-1),u=l.useRef(null),y=l.useRef(null),A=l.useMemo(()=>[...r,...n?[]:[{label:"Sign out",onClick:p}]],[r,n,p]);l.useEffect(()=>{if(!f)return;const x=C=>{u.current&&!u.current.contains(C.target)&&(g(!1),m(-1))},j=C=>{C.key==="Escape"&&(g(!1),m(-1),y.current?.focus())};return document.addEventListener("mousedown",x),document.addEventListener("keydown",j),()=>{document.removeEventListener("mousedown",x),document.removeEventListener("keydown",j)}},[f]);const b=l.useCallback(x=>{if(!(!f||A.length===0))switch(x.key){case"ArrowDown":x.preventDefault(),m(j=>(j+1)%A.length);break;case"ArrowUp":x.preventDefault(),m(j=>(j-1+A.length)%A.length);break;case"Home":x.preventDefault(),m(0);break;case"End":x.preventDefault(),m(A.length-1);break;case"Enter":case" ":w>=0&&(x.preventDefault(),A[w].onClick(),g(!1),m(-1));break}},[f,w,A]),v=l.useCallback(()=>{A.length!==0&&(g(x=>!x),m(-1))},[A.length]),k={sm:"cedros-button-sm",md:"cedros-button-md",lg:"cedros-button-lg"},S={default:"cedros-button-primary",outline:"cedros-button-outline",ghost:"cedros-button-ghost"};if(d)return e.jsx("button",{type:"button",className:`cedros-button ${S[t]} ${k[o]} ${s}`,disabled:!0,children:e.jsx(V.LoadingSpinner,{size:"sm"})});if(i&&c){const x=c.name||c.email||"User",j=Us.sanitizeImageUrl(c.picture);return e.jsxs("div",{className:"cedros-user-menu",ref:u,onKeyDown:b,children:[e.jsxs("button",{ref:y,type:"button",className:`cedros-button cedros-user-button ${k[o]} ${s}`,"aria-haspopup":"menu","aria-expanded":f,"aria-label":`User menu for ${x}`,onClick:v,children:[j?e.jsx("img",{src:j,alt:x,className:"cedros-user-avatar",referrerPolicy:"no-referrer",crossOrigin:"anonymous"}):e.jsx("div",{className:"cedros-user-avatar-placeholder",children:(x[0]||"?").toUpperCase()}),e.jsx("span",{className:"cedros-user-name",children:x})]}),f&&e.jsxs("div",{className:"cedros-dropdown cedros-dropdown-open",role:"menu",children:[r.map((C,N)=>e.jsxs("button",{type:"button",className:`cedros-dropdown-item ${w===N?"cedros-dropdown-item-focused":""}`,role:"menuitem",tabIndex:w===N?0:-1,onClick:()=>{C.onClick(),g(!1)},children:[C.icon&&e.jsx("span",{className:"cedros-dropdown-icon",children:C.icon}),C.label]},N)),r.length>0&&!n&&e.jsx("div",{className:"cedros-dropdown-divider",role:"separator"}),!n&&e.jsx("button",{type:"button",className:`cedros-dropdown-item cedros-dropdown-item-danger ${w===r.length?"cedros-dropdown-item-focused":""}`,role:"menuitem",tabIndex:w===r.length?0:-1,onClick:()=>{p(),g(!1)},children:"Sign out"})]})]})}return e.jsx("button",{type:"button",className:`cedros-button ${S[t]} ${k[o]} ${s}`,onClick:h,children:a||"Sign in"})}function Hs(){const{config:s}=T.useCedrosLogin(),[t,o]=l.useState(!1),[a,r]=l.useState(!1),[n,c]=l.useState(null),i=l.useMemo(()=>new T.ApiClient({baseUrl:s.serverUrl,timeoutMs:s.requestTimeout,retryAttempts:s.retryAttempts}),[s.serverUrl,s.requestTimeout,s.retryAttempts]),{checkLimit:d,getRemainingAttempts:h}=K.useRateLimiter({maxAttempts:3,windowMs:3e5}),p=l.useCallback(async m=>{if(!Me.validateEmail(m)){const u={code:"VALIDATION_ERROR",message:"Please enter a valid email address"};throw c(u),u}try{d()}catch(u){const y={code:"RATE_LIMITED",message:u instanceof Error?u.message:"Too many attempts"};throw c(y),y}o(!0),c(null),r(!1);try{await i.post("/forgot-password",{email:m}),r(!0)}catch(u){const y=T.handleApiError(u,"Failed to send reset email");throw c(y),y}finally{o(!1)}},[i,d]),f=l.useCallback(async(m,u)=>{o(!0),c(null),r(!1);try{await i.post("/reset-password",{token:m,newPassword:u}),r(!0)}catch(y){const A=T.handleApiError(y,"Failed to reset password");throw c(A),A}finally{o(!1)}},[i]),g=l.useCallback(()=>c(null),[]),w=l.useCallback(()=>{c(null),r(!1),o(!1)},[]);return{forgotPassword:p,resetPassword:f,isLoading:t,isSuccess:a,error:n,clearError:g,reset:w,remainingAttempts:h()}}function tr({onSuccess:s,onCancel:t,className:o=""}){const[a,r]=l.useState(""),{forgotPassword:n,isLoading:c,isSuccess:i,error:d,clearError:h}=Hs(),p=l.useId(),f=async g=>{g.preventDefault();try{await n(a),s?.()}catch{}};return i?e.jsxs("div",{className:`cedros-forgot-password-success ${o}`,children:[e.jsxs("svg",{className:"cedros-success-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"22",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M14 24l7 7 13-13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),e.jsx("h3",{className:"cedros-success-title",children:"Check your email"}),e.jsxs("p",{className:"cedros-success-message",children:["If an account exists for ",e.jsx("strong",{children:a}),", you will receive a password reset link shortly."]}),t&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-md cedros-button-outline",onClick:t,children:"Back to login"})]}):e.jsxs("form",{className:`cedros-forgot-password-form ${o}`,onSubmit:f,children:[e.jsxs("div",{className:"cedros-form-header",children:[e.jsx("h3",{className:"cedros-form-title",children:"Forgot password?"}),e.jsx("p",{className:"cedros-form-subtitle",children:"Enter your email address and we'll send you a link to reset your password."})]}),e.jsx(G.ErrorMessage,{error:d,onDismiss:h}),e.jsxs("div",{className:"cedros-form-field",children:[e.jsx("label",{htmlFor:p,className:"cedros-label",children:"Email address"}),e.jsx("input",{id:p,type:"email",className:"cedros-input",value:a,onChange:g=>r(g.target.value),placeholder:"you@example.com",required:!0,autoComplete:"email",disabled:c})]}),e.jsxs("div",{className:"cedros-form-actions",children:[e.jsx("button",{type:"submit",className:"cedros-button cedros-button-md cedros-button-primary cedros-button-full",disabled:c||!a,children:c?e.jsxs(e.Fragment,{children:[e.jsx(V.LoadingSpinner,{size:"sm"}),"Sending..."]}):"Send reset link"}),t&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-md cedros-button-ghost cedros-button-full",onClick:t,disabled:c,children:"Back to login"})]})]})}const yo={loading:!1,loaded:!1,error:null,callbacks:[],load(){return typeof window>"u"||typeof document>"u"?Promise.reject(new Error("Apple Sign-In script loader cannot run in SSR")):this.loaded?Promise.resolve():this.loading?new Promise((s,t)=>{this.callbacks.push({resolve:s,reject:t})}):(this.loading=!0,new Promise((s,t)=>{this.callbacks.push({resolve:s,reject:t});const o=document.getElementById("apple-signin-script");if(o){window.AppleID?(this.loaded=!0,this.loading=!1,this.callbacks.forEach(r=>r.resolve()),this.callbacks=[]):o.addEventListener("load",()=>{this.loaded=!0,this.loading=!1,this.callbacks.forEach(r=>r.resolve()),this.callbacks=[]});return}const a=document.createElement("script");a.src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js",a.async=!0,a.defer=!0,a.id="apple-signin-script",a.onload=()=>{this.loaded=!0,this.loading=!1,this.callbacks.forEach(r=>r.resolve()),this.callbacks=[]},a.onerror=()=>{this.loading=!1,a.remove();const r=new Error("Failed to load Apple Sign In script");this.callbacks.forEach(n=>n.reject(r)),this.callbacks=[]},document.head.appendChild(a)}))},_reset(){this.loading=!1,this.loaded=!1,this.error=null,this.callbacks=[]}};function rr(){const{config:s,_internal:t}=T.useCedrosLogin(),[o,a]=l.useState(!1),[r,n]=l.useState(!1),[c,i]=l.useState(null),[d,h]=l.useState(null),p=l.useRef(s),f=l.useMemo(()=>new T.ApiClient({baseUrl:s.serverUrl,timeoutMs:s.requestTimeout,retryAttempts:s.retryAttempts}),[s.serverUrl,s.requestTimeout,s.retryAttempts]);l.useEffect(()=>{p.current=s},[s]),l.useEffect(()=>{if(!s.appleClientId)return;let u=!0;const y=()=>{if(u)try{window.AppleID?.auth?.init({clientId:s.appleClientId,scope:"name email",redirectURI:window.location.origin,usePopup:!0}),u&&n(!0)}catch{u&&i({code:"SERVER_ERROR",message:"Failed to initialize Apple Sign In"})}};return yo.load().then(()=>{u&&y()}).catch(()=>{u&&i({code:"SERVER_ERROR",message:"Failed to load Apple Sign In"})}),()=>{u=!1}},[s.appleClientId]);const g=l.useCallback(async()=>{if(!s.appleClientId){const y={code:"VALIDATION_ERROR",message:"Apple Client ID not configured"};throw i(y),y}if(!r){const y={code:"VALIDATION_ERROR",message:"Apple Sign In not initialized"};throw i(y),y}a(!0),i(null);let u;try{const y=await window.AppleID.auth.signIn();if(u=y.authorization?.id_token,!u)throw new Error("No ID token received from Apple");const A=y.user?.name?`${y.user.name.firstName||""} ${y.user.name.lastName||""}`.trim():void 0,b=await f.post("/apple",{idToken:u,name:A||void 0});return p.current.callbacks?.onLoginSuccess?.(b.user,"apple"),t?.handleLoginSuccess(b.user,b.tokens),a(!1),b}catch(y){if(y.error==="popup_closed_by_user"){const v={code:"SERVER_ERROR",message:"Apple Sign In was cancelled"};throw i(v),a(!1),v}const b=T.handleApiError(y,"Apple sign-in failed");throw b.code==="ACCOUNT_LINK_REQUIRED"&&u&&h(u),i(b),a(!1),b}},[s.appleClientId,r,f,t]),w=l.useCallback(()=>i(null),[]),m=l.useCallback(()=>h(null),[]);return{signIn:g,isLoading:o,isInitialized:r,error:c,clearError:w,pendingLinkIdToken:d,clearPendingLink:m}}function or(){if(typeof window>"u"||typeof navigator>"u")return!1;const s=navigator.userAgent.toLowerCase(),t=(navigator.platform||"").toLowerCase();return!!(/iphone|ipad|ipod/.test(s)||t.includes("mac")||/macintosh/.test(s)||t==="macintel"&&navigator.maxTouchPoints>1)}function nr({onSuccess:s,onError:t,className:o="",variant:a="default",size:r="md",disabled:n=!1,hideOnNonApple:c=!0}){const{signIn:i,isLoading:d,isInitialized:h}=rr(),[p]=l.useState(()=>or());if(c&&!p)return null;const f=async()=>{try{await i(),s?.()}catch(m){const u=m instanceof Error?m:new Error(String(m));t?.(u)}},g={sm:"cedros-button-sm",md:"cedros-button-md",lg:"cedros-button-lg"},w={default:"cedros-button-social",outline:"cedros-button-social-outline"};return e.jsxs("button",{type:"button",className:`cedros-button ${w[a]} ${g[r]} ${o}`,onClick:f,disabled:n||!h||d,"aria-label":"Sign in with Apple",children:[d?e.jsx(V.LoadingSpinner,{size:"sm"}):e.jsx("svg",{className:"cedros-button-icon",width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M18.71 19.5c-.83 1.24-1.71 2.45-3.05 2.47-1.34.03-1.77-.79-3.29-.79-1.53 0-2 .77-3.27.82-1.31.05-2.3-1.32-3.14-2.53C4.25 17 2.94 12.45 4.7 9.39c.87-1.52 2.43-2.48 4.12-2.51 1.28-.02 2.5.87 3.29.87.78 0 2.26-1.07 3.81-.91.65.03 2.47.26 3.64 1.98-.09.06-2.17 1.28-2.15 3.81.03 3.02 2.65 4.03 2.68 4.04-.03.07-.42 1.44-1.38 2.83M13 3.5c.73-.83 1.94-1.46 2.94-1.5.13 1.17-.34 2.35-1.04 3.19-.69.85-1.83 1.51-2.95 1.42-.15-1.15.41-2.35 1.05-3.11z"})}),e.jsx("span",{children:"Continue with Apple"})]})}function Z(s,t){if(!s)throw new Error(t)}function bo(s){return s.replace(/-/g,"+").replace(/_/g,"/")}function Ge(s){Z(typeof s=="string"&&s.length>0,"Expected base64url string");const t=bo(s),o=t+"=".repeat((4-t.length%4)%4),a=atob(o),r=new Uint8Array(a.length);for(let n=0;n<a.length;n++)r[n]=a.charCodeAt(n);return r.buffer}function be(s){const t=new Uint8Array(s);let o="";for(let r=0;r<t.length;r++)o+=String.fromCharCode(t[r]);return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function ar(s){Z(typeof s=="object"&&s!==null,"Invalid credential descriptor");const t=s;return Z(typeof t.type=="string","Invalid credential descriptor type"),Z(typeof t.id=="string","Invalid credential descriptor id"),{type:t.type,id:Ge(t.id),transports:Array.isArray(t.transports)?t.transports:void 0}}function ls(s){Z(s&&typeof s=="object","Missing creation options");const t=s.publicKey;Z(t&&typeof t=="object","Missing creation options.publicKey"),Z(typeof t.challenge=="string","Missing creation challenge"),Z(typeof t.rp=="object"&&t.rp!==null,"Missing rp"),Z(typeof t.user=="object"&&t.user!==null,"Missing user");const o=t.rp,a=t.user;Z(typeof o.name=="string","Missing rp.name"),Z(typeof a.id=="string","Missing user.id"),Z(typeof a.name=="string","Missing user.name"),Z(typeof a.displayName=="string","Missing user.displayName");const r=Array.isArray(t.excludeCredentials)?t.excludeCredentials.map(ar):void 0,n=Array.isArray(t.pubKeyCredParams)?t.pubKeyCredParams.map(i=>({type:i.type,alg:i.alg})):[],c={challenge:Ge(t.challenge),rp:{name:o.name,id:typeof o.id=="string"?o.id:void 0},user:{id:Ge(a.id),name:a.name,displayName:a.displayName},pubKeyCredParams:n,timeout:typeof t.timeout=="number"?t.timeout:void 0,attestation:typeof t.attestation=="string"?t.attestation:void 0,authenticatorSelection:typeof t.authenticatorSelection=="object"&&t.authenticatorSelection!==null?t.authenticatorSelection:void 0,excludeCredentials:r,extensions:typeof t.extensions=="object"&&t.extensions!==null?t.extensions:void 0};return c.hints=["client-device"],c}function it(s){Z(s&&typeof s=="object","Missing request options");const t=s.publicKey;Z(t&&typeof t=="object","Missing request options.publicKey"),Z(typeof t.challenge=="string","Missing request challenge");const o=Array.isArray(t.allowCredentials)?t.allowCredentials.map(ar):void 0,a={challenge:Ge(t.challenge),rpId:typeof t.rpId=="string"?t.rpId:void 0,timeout:typeof t.timeout=="number"?t.timeout:void 0,userVerification:typeof t.userVerification=="string"?t.userVerification:void 0,allowCredentials:o,extensions:typeof t.extensions=="object"&&t.extensions!==null?t.extensions:void 0};return a.hints=["client-device"],a}function Ce(s){const t=be(s.rawId),o=s.response,r={...{clientDataJSON:be(o.clientDataJSON)}};if("attestationObject"in o){const n=o;if(r.attestationObject=be(n.attestationObject),typeof n.getTransports=="function")try{r.transports=n.getTransports()}catch{}}if("authenticatorData"in o){const n=o;r.authenticatorData=be(n.authenticatorData),r.signature=be(n.signature),n.userHandle&&(r.userHandle=be(n.userHandle))}return{id:s.id,rawId:t,type:s.type,authenticatorAttachment:s.authenticatorAttachment??void 0,clientExtensionResults:s.getClientExtensionResults?.()??{},response:r}}function Ao(){if(typeof window<"u"){const s=window.location?.hostname,t=s==="localhost"||s==="127.0.0.1"||s?.endsWith(".localhost");if(!(window.isSecureContext===!0)&&!t)return!1}return typeof window<"u"&&typeof window.PublicKeyCredential<"u"&&typeof navigator<"u"&&typeof navigator.credentials<"u"}function Se(s){if(!(s instanceof Error))return null;const t=s.name;return t==="NotAllowedError"?{code:"SERVER_ERROR",message:"Passkey operation was cancelled or timed out"}:t==="InvalidStateError"?{code:"VALIDATION_ERROR",message:"Passkey is not available for this operation"}:t==="SecurityError"?{code:"VALIDATION_ERROR",message:"Passkeys require HTTPS and a correctly configured relying party (WEBAUTHN_RP_ID / WEBAUTHN_RP_ORIGIN)"}:null}function ir(){const{config:s,_internal:t}=T.useCedrosLogin(),[o,a]=l.useState(!1),[r,n]=l.useState(null),c=l.useMemo(()=>new T.ApiClient({baseUrl:s.serverUrl,timeoutMs:s.requestTimeout,retryAttempts:s.retryAttempts,getAccessToken:t?.getAccessToken}),[t?.getAccessToken,s.serverUrl,s.requestTimeout,s.retryAttempts]),i=l.useCallback(()=>n(null),[]),d=Ao(),h=l.useCallback(async w=>{if(!d){const m={code:"VALIDATION_ERROR",message:"Passkeys are not supported in this browser"};throw n(m),m}a(!0),n(null);try{const m=await c.post("/webauthn/auth/options",{email:w?.email}),u=it(m.options),y=await navigator.credentials.get({publicKey:u});if(!y)throw new Error("Passkey authentication returned no credential");const A=await c.post("/webauthn/auth/verify",{challengeId:m.challengeId,credential:Ce(y)});return s.callbacks?.onLoginSuccess?.(A.user,"webauthn"),t?.handleLoginSuccess(A.user,A.tokens),A}catch(m){const y=Se(m)??T.handleApiError(m,"Passkey sign-in failed");throw n(y),y}finally{a(!1)}},[c,s.callbacks,t,d]),p=l.useCallback(async w=>{if(!d){const m={code:"VALIDATION_ERROR",message:"Passkeys are not supported in this browser"};throw n(m),m}a(!0),n(null);try{const m=await c.post("/webauthn/register/options",{}),u=ls(m.options),y=await navigator.credentials.create({publicKey:u});if(!y)throw new Error("Passkey registration returned no credential");const A=await c.post("/webauthn/register/verify",{challengeId:m.challengeId,credential:Ce(y),label:w?.label});if(!A.success)throw new Error("Passkey registration failed");return{credentialId:A.credentialId,label:A.label}}catch(m){const y=Se(m)??T.handleApiError(m,"Passkey registration failed");throw n(y),y}finally{a(!1)}},[c,d]),f=l.useCallback(async w=>{if(!d){const m={code:"VALIDATION_ERROR",message:"Passkeys are not supported in this browser"};throw n(m),m}a(!0),n(null);try{const m=await c.post("/webauthn/signup/options",{}),u=ls(m.options),y=await navigator.credentials.create({publicKey:u});if(!y)throw new Error("Passkey signup returned no credential");const A=await c.post("/webauthn/signup/verify",{challengeId:m.challengeId,credential:Ce(y),email:w?.email,name:w?.name,label:w?.label});return s.callbacks?.onLoginSuccess?.(A.user,"webauthn"),t?.handleLoginSuccess(A.user,A.tokens),A}catch(m){const y=Se(m)??T.handleApiError(m,"Passkey sign-up failed");throw n(y),y}finally{a(!1)}},[c,s.callbacks,t,d]),g=l.useCallback(async()=>{if(!d){const w={code:"VALIDATION_ERROR",message:"Passkeys are not supported in this browser"};throw n(w),w}a(!0),n(null);try{const w=await c.post("/webauthn/auth/options",{}),m=it(w.options),u=await navigator.credentials.get({publicKey:m});if(!u)throw new Error("Passkey authentication returned no credential");const y=await c.post("/webauthn/auth/verify",{challengeId:w.challengeId,credential:Ce(u)});return s.callbacks?.onLoginSuccess?.(y.user,"webauthn"),t?.handleLoginSuccess(y.user,y.tokens),y}catch(w){if(w instanceof Error&&w.name==="NotAllowedError")try{const y=await c.post("/webauthn/signup/options",{}),A=ls(y.options),b=await navigator.credentials.create({publicKey:A});if(!b)throw new Error("Passkey signup returned no credential");const v=await c.post("/webauthn/signup/verify",{challengeId:y.challengeId,credential:Ce(b)});return s.callbacks?.onLoginSuccess?.(v.user,"webauthn"),t?.handleLoginSuccess(v.user,v.tokens),v}catch(y){const b=Se(y)??T.handleApiError(y,"Passkey sign-up failed");throw n(b),b}const u=Se(w)??T.handleApiError(w,"Passkey sign-in failed");throw n(u),u}finally{a(!1)}},[c,s.callbacks,t,d]);return{isSupported:d,isLoading:o,error:r,clearError:i,continueWithPasskey:g,authenticatePasskey:h,registerPasskey:p,signupWithPasskey:f}}function lr({onSuccess:s,className:t="",children:o,disabled:a}){const{continueWithPasskey:r,isLoading:n,isSupported:c}=ir(),i=a||!c||n,d=n?"Continuing...":"Continue with Passkey";return e.jsxs("button",{type:"button",className:`cedros-button cedros-button-social ${t}`,onClick:async()=>{await r(),s?.()},disabled:i,"aria-disabled":i,children:[e.jsx("span",{className:"cedros-social-icon","aria-hidden":"true",children:e.jsx(xo,{})}),e.jsx("span",{children:o??d})]})}function xo(){return e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4"}),e.jsx("path",{d:"M14 13.12c0 2.38 0 6.38-1 8.88"}),e.jsx("path",{d:"M17.29 21.02c.12-.6.43-2.3.5-3.02"}),e.jsx("path",{d:"M2 12a10 10 0 0 1 18-6"}),e.jsx("path",{d:"M2 16h.01"}),e.jsx("path",{d:"M21.8 16c.2-2 .131-5.354 0-6"}),e.jsx("path",{d:"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2"}),e.jsx("path",{d:"M8.65 22c.21-.66.45-1.32.57-2"}),e.jsx("path",{d:"M9 6.8a6 6 0 0 1 9 5.2v2"})]})}const vo=["phantom","solflare","backpack","glow","slope","sollet","coin98","clover","mathWallet","ledger","torus","walletconnect"];function lt(s){if(!s||typeof s!="object")return!1;const t=s;return typeof t.connect=="function"||typeof t.signMessage=="function"||typeof t.signTransaction=="function"||"isConnected"in t}function jo(){try{const s=window.__wallet_standard__;if(s&&typeof s=="object"&&"get"in s&&typeof s.get=="function"){const t=s.get();return Array.isArray(t)&&t.length>0}}catch{}return!1}function ct(){if(typeof window>"u")return!1;const s=window;for(const t of vo){const o=s[t];if(o&&typeof o=="object"&&"solana"in o&&lt(o.solana))return!0}return!!(lt(s.solana)||jo())}const Ee=["login","register"];function Ze({onSuccess:s,className:t="",defaultTab:o="login"}){const{config:a}=T.useCedrosLogin(),[r,n]=l.useState(o),[c,i]=l.useState("form"),[d,h]=l.useState(()=>ct()),[p]=l.useState(()=>or()),[f,g]=l.useState(!1);l.useEffect(()=>{const x=()=>h(ct());return x(),window.addEventListener("load",x),window.addEventListener("focus",x),()=>{window.removeEventListener("load",x),window.removeEventListener("focus",x)}},[]);const w=a.forms?.forgotPassword?.mode??(a.features?.instantLink?"instantLink":"reset"),m=l.useCallback(x=>{const j=Ee.indexOf(r);let C=j;switch(x.key){case"ArrowLeft":case"ArrowUp":C=j===0?Ee.length-1:j-1;break;case"ArrowRight":case"ArrowDown":C=j===Ee.length-1?0:j+1;break;case"Home":C=0;break;case"End":C=Ee.length-1;break;default:return}x.preventDefault();const N=Ee[C];n(N),document.getElementById(`cedros-tab-${N}`)?.focus()},[r]),u=a.features??{email:!0,google:!0,apple:!0,solana:!0,webauthn:!0},y=u.email!==!1,A=u.google!==!1&&a.googleClientId,b=u.apple!==!1&&a.appleClientId&&p,v=u.solana!==!1&&d,k=u.webauthn!==!1,S=y&&(A||b||v||k);return c==="forgotPassword"?e.jsx("div",{className:`cedros-login-form ${t}`,children:e.jsx(tr,{onCancel:()=>i("form")})}):e.jsxs("div",{className:`cedros-login-form ${f?"cedros-login-form--connecting":""} ${t}`,children:[(k||A||b||v)&&e.jsxs("div",{className:"cedros-social-buttons",children:[k&&e.jsx(lr,{onSuccess:s}),A&&e.jsx(Ws.GoogleLoginButton,{onSuccess:s}),b&&e.jsx(nr,{onSuccess:s}),v&&e.jsxs(e.Fragment,{children:[e.jsx(Xe.SolanaLoginButton,{onSuccess:s,onLoadingChange:g}),f&&e.jsx("p",{className:"cedros-solana-status",children:"Connecting to Solana wallet…"})]})]}),S&&e.jsx("div",{className:"cedros-divider",children:e.jsx("span",{children:"Or continue with"})}),y&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-tabs",role:"tablist","aria-label":"Authentication method",children:[e.jsx("button",{type:"button",role:"tab",id:"cedros-tab-login",className:`cedros-tab ${r==="login"?"cedros-tab-active":""}`,onClick:()=>n("login"),onKeyDown:m,"aria-selected":r==="login","aria-controls":"cedros-tabpanel-login",tabIndex:r==="login"?0:-1,children:"Sign in"}),e.jsx("button",{type:"button",role:"tab",id:"cedros-tab-register",className:`cedros-tab ${r==="register"?"cedros-tab-active":""}`,onClick:()=>n("register"),onKeyDown:m,"aria-selected":r==="register","aria-controls":"cedros-tabpanel-register",tabIndex:r==="register"?0:-1,children:"Sign up"})]}),e.jsx("div",{role:"tabpanel",id:`cedros-tabpanel-${r}`,"aria-labelledby":`cedros-tab-${r}`,children:r==="login"?e.jsx(K.EmailLoginForm,{onSuccess:s,onSwitchToRegister:()=>n("register"),onForgotPassword:w==="reset"?()=>i("forgotPassword"):void 0}):e.jsx(K.EmailRegisterForm,{onSuccess:s,onSwitchToLogin:()=>n("login")})})]})]})}class cr extends l.Component{constructor(t){super(t),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,o){this.setState({errorInfo:o}),console.error("[Cedros Login] Error caught by ErrorBoundary:",t),console.error("[Cedros Login] Component stack:",o.componentStack),this.props.onError?.(t,o)}handleRetry=()=>{this.setState({hasError:!1,error:null,errorInfo:null})};render(){const{hasError:t,error:o,errorInfo:a}=this.state,{children:r,fallback:n,showDetails:c=!1}=this.props;return t?n||e.jsx("div",{className:"cedros-error-boundary",role:"alert","aria-live":"assertive",children:e.jsxs("div",{className:"cedros-error-boundary-content",children:[e.jsxs("svg",{className:"cedros-error-boundary-icon",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),e.jsx("h2",{className:"cedros-error-boundary-title",children:"Something went wrong"}),e.jsx("p",{className:"cedros-error-boundary-message",children:"We encountered an unexpected error. Please try again."}),c&&o&&e.jsxs("details",{className:"cedros-error-boundary-details",children:[e.jsx("summary",{children:"Error details"}),e.jsxs("pre",{children:[o.toString(),a?.componentStack]})]}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:this.handleRetry,children:"Try again"})]})}):r}}function ko({className:s="",title:t="Sign in to your account"}){const{isModalOpen:o,closeModal:a}=T.useCedrosLogin(),r=l.useRef(null),n=l.useRef(null),c=l.useRef(a);if(l.useEffect(()=>{c.current=a},[a]),l.useEffect(()=>{if(!o)return;n.current=document.activeElement,r.current?.focus();const d=p=>{if(p.key==="Escape"&&c.current(),p.key==="Tab"&&r.current){const f=r.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'),g=f[0],w=f[f.length-1];p.shiftKey&&document.activeElement===g?(p.preventDefault(),w?.focus()):!p.shiftKey&&document.activeElement===w&&(p.preventDefault(),g?.focus())}};document.addEventListener("keydown",d);const h=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",d),document.body.style.overflow=h,n.current instanceof HTMLElement&&n.current.focus()}},[o]),!o)return null;const i=d=>{d.target===d.currentTarget&&a()};return e.jsx("div",{className:`cedros-modal-backdrop ${s}`,onClick:i,role:"presentation",children:e.jsxs("div",{ref:r,className:"cedros-modal",role:"dialog","aria-modal":"true","aria-labelledby":"cedros-modal-title",tabIndex:-1,children:[e.jsxs("div",{className:"cedros-modal-header",children:[e.jsx("h2",{id:"cedros-modal-title",className:"cedros-modal-title",children:t}),e.jsx("button",{type:"button",className:"cedros-modal-close",onClick:a,"aria-label":"Close",children:e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})})]}),e.jsx("div",{className:"cedros-modal-content",children:e.jsx(cr,{children:e.jsx(Ze,{onSuccess:a})})})]})})}function No({token:s,onSuccess:t,onLoginClick:o,className:a=""}){const[r,n]=l.useState(""),[c,i]=l.useState(""),[d,h]=l.useState(null),{resetPassword:p,isLoading:f,isSuccess:g,error:w,clearError:m}=Hs(),u=r===c,y=d?.isValid&&u&&r.length>0,A=async b=>{if(b.preventDefault(),!!y)try{await p(s,r),t?.()}catch{}};return g?e.jsxs("div",{className:`cedros-reset-password-success ${a}`,children:[e.jsxs("svg",{className:"cedros-success-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"22",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M14 24l7 7 13-13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),e.jsx("h3",{className:"cedros-success-title",children:"Password reset successful"}),e.jsx("p",{className:"cedros-success-message",children:"Your password has been reset. You can now log in with your new password."}),o&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-md cedros-button-primary",onClick:o,children:"Go to login"})]}):e.jsxs("form",{className:`cedros-reset-password-form ${a}`,onSubmit:A,children:[e.jsxs("div",{className:"cedros-form-header",children:[e.jsx("h3",{className:"cedros-form-title",children:"Reset your password"}),e.jsx("p",{className:"cedros-form-subtitle",children:"Enter your new password below."})]}),e.jsx(G.ErrorMessage,{error:w,onDismiss:m}),e.jsx("div",{className:"cedros-form-field",children:e.jsx(K.PasswordInput,{label:"New password",value:r,onChange:b=>{n(b.target.value),h(Me.validatePassword(b.target.value))},showStrengthMeter:!0,onValidationChange:h,disabled:f,autoComplete:"new-password",error:d&&!d.isValid?Object.values(d.errors).find(Boolean):void 0})}),e.jsx("div",{className:"cedros-form-field",children:e.jsx(K.PasswordInput,{label:"Confirm password",value:c,onChange:b=>i(b.target.value),disabled:f,autoComplete:"new-password",error:c&&!u?"Passwords do not match":void 0})}),e.jsxs("div",{className:"cedros-form-actions",children:[e.jsx("button",{type:"submit",className:"cedros-button cedros-button-md cedros-button-primary cedros-button-full",disabled:f||!y,children:f?e.jsxs(e.Fragment,{children:[e.jsx(V.LoadingSpinner,{size:"sm"}),"Resetting..."]}):"Reset password"}),o&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-md cedros-button-ghost cedros-button-full",onClick:o,disabled:f,children:"Back to login"})]})]})}function Fs({org:s,size:t="lg",className:o=""}){const a=Us.sanitizeImageUrl(s.logoUrl),r=t==="lg"?"cedros-org-avatar-lg":"",n=["cedros-org-avatar",r,o].filter(Boolean).join(" "),c=["cedros-org-avatar-placeholder",r,o].filter(Boolean).join(" ");return a?e.jsx("img",{src:a,alt:s.name,className:n,referrerPolicy:"no-referrer"}):e.jsx("div",{className:c,children:s.name[0]?.toUpperCase()||"?"})}function Co({orgs:s,activeOrg:t,isLoading:o=!1,onSelect:a,onCreateClick:r,className:n="",placeholder:c="Select organization"}){const[i,d]=l.useState(!1),h=l.useRef(null);l.useEffect(()=>{const w=m=>{h.current&&!h.current.contains(m.target)&&d(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[]),l.useEffect(()=>{const w=m=>{m.key==="Escape"&&d(!1)};if(i)return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[i]);const p=l.useCallback(w=>{a(w),d(!1)},[a]),f=l.useCallback(()=>{d(!1),r?.()},[r]),g=l.useCallback(()=>{d(w=>!w)},[]);return o?e.jsxs("div",{className:`cedros-org-selector cedros-org-selector-loading ${n}`,"aria-busy":"true","aria-live":"polite",children:[e.jsx(V.LoadingSpinner,{size:"sm"}),e.jsx("span",{children:"Loading..."})]}):e.jsxs("div",{ref:h,className:`cedros-org-selector ${n}`,children:[e.jsxs("button",{type:"button",className:"cedros-org-selector-trigger",onClick:g,"aria-haspopup":"listbox","aria-expanded":i,children:[t?e.jsxs(e.Fragment,{children:[e.jsx(Fs,{org:t,size:"sm"}),e.jsx("span",{className:"cedros-org-selector-name",children:t.name}),e.jsx(dt,{role:t.membership.role})]}):e.jsx("span",{className:"cedros-org-selector-placeholder",children:c}),e.jsx(So,{isOpen:i})]}),i&&e.jsxs("div",{className:"cedros-org-selector-dropdown",role:"listbox",children:[s.length===0?e.jsx("div",{className:"cedros-org-selector-empty",children:"No organizations"}):e.jsx("ul",{className:"cedros-org-selector-list",children:s.map(w=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:`cedros-org-selector-item ${w.id===t?.id?"cedros-org-selector-item-active":""}`,onClick:()=>p(w.id),role:"option","aria-selected":w.id===t?.id,children:[e.jsx(Fs,{org:w,size:"sm"}),e.jsx("span",{className:"cedros-org-selector-item-name",children:w.name}),e.jsx(dt,{role:w.membership.role}),w.id===t?.id&&e.jsx(Eo,{})]})},w.id))}),r&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-org-selector-divider"}),e.jsxs("button",{type:"button",className:"cedros-org-selector-create",onClick:f,children:[e.jsx(Lo,{}),e.jsx("span",{children:"Create organization"})]})]})]})]})}function dt({role:s}){return e.jsx("span",{className:`cedros-org-role cedros-org-role-${s}`,children:s})}function So({isOpen:s}){return e.jsx("svg",{className:`cedros-org-chevron ${s?"cedros-org-chevron-open":""}`,width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function Eo(){return e.jsx("svg",{className:"cedros-org-check",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M3 8L6 11L13 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function Lo(){return e.jsx("svg",{className:"cedros-org-plus",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M8 3V13M3 8H13",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function Po(){return e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function Mo(){return e.jsx("svg",{className:"cedros-org-check",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M4 10L8 14L16 5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function To(){return e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M10 4V16M4 10H16",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function Bo({orgs:s,activeOrg:t,isLoading:o,onSelect:a,onCreateClick:r}){return o?e.jsxs("div",{className:"cedros-org-switcher-loading",children:[e.jsx(V.LoadingSpinner,{}),e.jsx("span",{children:"Loading organizations..."})]}):e.jsxs(e.Fragment,{children:[s.length===0?e.jsx("div",{className:"cedros-org-switcher-empty",children:e.jsx("p",{children:"You don't belong to any organizations yet."})}):e.jsx("ul",{className:"cedros-org-switcher-list",children:s.map(n=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:`cedros-org-switcher-item ${n.id===t?.id?"cedros-org-switcher-item-active":""}`,onClick:()=>a(n.id),children:[e.jsx(Fs,{org:n}),e.jsxs("div",{className:"cedros-org-switcher-item-content",children:[e.jsx("span",{className:"cedros-org-switcher-item-name",children:n.name}),e.jsxs("span",{className:"cedros-org-switcher-item-slug",children:["@",n.slug]})]}),e.jsxs("div",{className:"cedros-org-switcher-item-meta",children:[e.jsx("span",{className:`cedros-org-role cedros-org-role-${n.membership.role}`,children:n.membership.role}),n.isPersonal&&e.jsx("span",{className:"cedros-org-personal-badge",children:"Personal"})]}),n.id===t?.id&&e.jsx(Mo,{})]})},n.id))}),r&&e.jsxs("button",{type:"button",className:"cedros-org-switcher-create",onClick:r,children:[e.jsx(To,{}),e.jsx("span",{children:"Create new organization"})]})]})}function Ro({isLoading:s,onSubmit:t,onCancel:o}){const[a,r]=l.useState(""),[n,c]=l.useState(""),[i,d]=l.useState(null),h=l.useCallback(f=>{r(f);const g=f.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"").substring(0,50);c(g)},[]),p=l.useCallback(async f=>{if(f.preventDefault(),d(null),!a.trim()){d("Organization name is required");return}if(!n.trim()){d("Organization slug is required");return}try{await t({name:a.trim(),slug:n.trim()})}catch(g){d(g.message||"Failed to create organization")}},[a,n,t]);return e.jsxs("form",{className:"cedros-org-create-form",onSubmit:p,children:[i&&e.jsx(G.ErrorMessage,{error:i}),e.jsxs("div",{className:"cedros-form-group",children:[e.jsx("label",{htmlFor:"org-name",className:"cedros-form-label",children:"Organization Name"}),e.jsx("input",{id:"org-name",type:"text",className:"cedros-form-input",value:a,onChange:f=>h(f.target.value),placeholder:"My Organization",maxLength:255,disabled:s,autoFocus:!0})]}),e.jsxs("div",{className:"cedros-form-group",children:[e.jsx("label",{htmlFor:"org-slug",className:"cedros-form-label",children:"URL Slug"}),e.jsxs("div",{className:"cedros-form-input-prefix",children:[e.jsx("span",{className:"cedros-form-prefix",children:"@"}),e.jsx("input",{id:"org-slug",type:"text",className:"cedros-form-input",value:n,onChange:f=>c(f.target.value.toLowerCase()),placeholder:"my-organization",maxLength:100,pattern:"[a-z0-9-]+",disabled:s})]}),e.jsx("span",{className:"cedros-form-hint",children:"Only lowercase letters, numbers, and hyphens"})]}),e.jsxs("div",{className:"cedros-form-actions",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline",onClick:o,disabled:s,children:"Cancel"}),e.jsx("button",{type:"submit",className:"cedros-button cedros-button-primary",disabled:s||!a.trim()||!n.trim(),children:s?e.jsx(V.LoadingSpinner,{size:"sm"}):"Create Organization"})]})]})}function Do({isOpen:s,onClose:t,orgs:o,activeOrg:a,isLoading:r=!1,error:n,onSelect:c,onCreate:i,className:d=""}){return s?e.jsx(Io,{onClose:t,orgs:o,activeOrg:a,isLoading:r,error:n,onSelect:c,onCreate:i,className:d}):null}function Io({onClose:s,orgs:t,activeOrg:o,isLoading:a=!1,error:r,onSelect:n,onCreate:c,className:i}){const[d,h]=l.useState("list"),p=l.useRef(null),f=l.useRef(null);l.useEffect(()=>(f.current=document.activeElement,p.current?.querySelector(".cedros-modal-close")?.focus(),()=>{f.current?.focus()}),[]),l.useEffect(()=>{const u=y=>{if(y.key==="Escape"){s();return}if(y.key==="Tab"&&p.current){const A=p.current.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'),b=A[0],v=A[A.length-1];y.shiftKey?document.activeElement===b&&(y.preventDefault(),v?.focus()):document.activeElement===v&&(y.preventDefault(),b?.focus())}};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[s]);const g=l.useCallback(u=>{u.target===u.currentTarget&&s()},[s]),w=l.useCallback(u=>{n(u),s()},[n,s]),m=l.useCallback(async u=>{await c?.(u),s()},[c,s]);return e.jsx("div",{className:"cedros-modal-backdrop",onClick:g,children:e.jsxs("div",{ref:p,className:`cedros-modal cedros-org-switcher ${i}`,role:"dialog","aria-modal":"true","aria-labelledby":"org-switcher-title",children:[e.jsxs("div",{className:"cedros-modal-header",children:[e.jsx("h2",{id:"org-switcher-title",className:"cedros-modal-title",children:d==="list"?"Switch Organization":"Create Organization"}),e.jsx("button",{type:"button",className:"cedros-modal-close",onClick:s,"aria-label":"Close",children:e.jsx(Po,{})})]}),e.jsxs("div",{className:"cedros-modal-body",children:[r&&e.jsx(G.ErrorMessage,{error:r}),d==="list"?e.jsx(Bo,{orgs:t,activeOrg:o,isLoading:a,onSelect:w,onCreateClick:c?()=>h("create"):void 0}):e.jsx(Ro,{isLoading:a,onSubmit:m,onCancel:()=>h("list")})]})]})})}function Fo({sessions:s,isLoading:t=!1,error:o,onRevokeAll:a,className:r=""}){const[n,c]=l.useState(!1),[i,d]=l.useState(!1),h=l.useRef(null),p=l.useMemo(()=>s.filter(g=>!g.isCurrent).length,[s]),f=l.useCallback(async()=>{if(!a)return;const g=s.filter(m=>!m.isCurrent).length;if(!(g===0||!window.confirm(`Are you sure you want to sign out of ${g} other device(s)? This will log you out everywhere except this browser.`))){c(!0),d(!1);try{await a(),d(!0),h.current!==null&&window.clearTimeout(h.current),h.current=window.setTimeout(()=>{d(!1),h.current=null},3e3)}finally{c(!1)}}},[a,s]);return l.useEffect(()=>()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},[]),t&&s.length===0?e.jsxs("div",{className:`cedros-session-list cedros-session-list-loading ${r}`,children:[e.jsx(V.LoadingSpinner,{}),e.jsx("span",{children:"Loading sessions..."})]}):o?e.jsx("div",{className:`cedros-session-list ${r}`,children:e.jsx(G.ErrorMessage,{error:o})}):s.length===0?e.jsx("div",{className:`cedros-session-list cedros-session-list-empty ${r}`,children:e.jsx("p",{children:"No active sessions found."})}):e.jsxs("div",{className:`cedros-session-list ${r}`,children:[i&&e.jsxs("div",{className:"cedros-session-success",role:"status",children:[e.jsx(zo,{}),e.jsx("span",{children:"All other sessions have been revoked."})]}),e.jsx("ul",{className:"cedros-session-items",children:s.map(g=>e.jsx(Uo,{session:g},g.id))}),a&&p>0&&e.jsx("div",{className:"cedros-session-actions",children:e.jsx("button",{type:"button",className:"cedros-button cedros-button-danger",onClick:f,disabled:n,children:n?e.jsxs(e.Fragment,{children:[e.jsx(V.LoadingSpinner,{size:"sm"}),e.jsx("span",{children:"Signing out..."})]}):`Sign out of ${p} other device${p>1?"s":""}`})})]})}function Uo({session:s}){const t=Wo(s.userAgent),o=Oo(s.expiresAt);return e.jsxs("li",{className:`cedros-session-item ${s.isCurrent?"cedros-session-item-current":""}`,children:[e.jsx("div",{className:"cedros-session-item-icon",children:e.jsx(qo,{userAgent:s.userAgent})}),e.jsxs("div",{className:"cedros-session-item-info",children:[e.jsxs("div",{className:"cedros-session-item-main",children:[e.jsxs("span",{className:"cedros-session-item-device",children:[t.browser," on ",t.os]}),s.isCurrent&&e.jsx("span",{className:"cedros-session-current-badge",children:"Current session"})]}),e.jsxs("div",{className:"cedros-session-item-meta",children:[s.ipAddress&&e.jsxs("span",{className:"cedros-session-item-ip",children:["IP: ",s.ipAddress]}),e.jsxs("span",{className:"cedros-session-item-created",children:["Started ",_o(s.createdAt)]}),o&&e.jsx("span",{className:"cedros-session-expiring",children:"Expires soon"})]})]})]})}function Wo(s){if(!s)return{browser:"Unknown browser",os:"Unknown device"};let t="Unknown browser";s.includes("Chrome")&&!s.includes("Edg")?t="Chrome":s.includes("Safari")&&!s.includes("Chrome")?t="Safari":s.includes("Firefox")?t="Firefox":s.includes("Edg")&&(t="Edge");let o="Unknown device";return s.includes("Windows")?o="Windows":s.includes("Mac")?o="macOS":s.includes("Linux")?o="Linux":s.includes("iPhone")||s.includes("iPad")?o="iOS":s.includes("Android")&&(o="Android"),{browser:t,os:o}}function _o(s){const t=new Date(s),a=new Date().getTime()-t.getTime(),r=Math.floor(a/(1e3*60)),n=Math.floor(a/(1e3*60*60)),c=Math.floor(a/(1e3*60*60*24));return r<1?"just now":r<60?`${r} minute${r>1?"s":""} ago`:n<24?`${n} hour${n>1?"s":""} ago`:c<7?`${c} day${c>1?"s":""} ago`:t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Oo(s){const t=new Date(s),o=new Date,a=3600*1e3;return t.getTime()-o.getTime()<a}function qo({userAgent:s}){return s?.includes("iPhone")||s?.includes("iPad")||s?.includes("Android")?e.jsxs("svg",{className:"cedros-session-device-icon",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("rect",{x:"5",y:"2",width:"14",height:"20",rx:"2",stroke:"currentColor",strokeWidth:"1.5"}),e.jsx("circle",{cx:"12",cy:"18",r:"1",fill:"currentColor"})]}):e.jsxs("svg",{className:"cedros-session-device-icon",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("rect",{x:"2",y:"4",width:"20",height:"14",rx:"2",stroke:"currentColor",strokeWidth:"1.5"}),e.jsx("path",{d:"M8 21H16",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),e.jsx("path",{d:"M12 18V21",stroke:"currentColor",strokeWidth:"1.5"})]})}function zo(){return e.jsx("svg",{className:"cedros-session-check",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M3 8L6 11L13 5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function dr({words:s,onConfirm:t,className:o=""}){const[a,r]=l.useState(!1),[n,c]=l.useState(!1),i=l.useRef(null),d=fo(s),h=l.useCallback(async()=>{try{await navigator.clipboard.writeText(s.join(" ")),r(!0),i.current!==null&&window.clearTimeout(i.current),i.current=window.setTimeout(()=>r(!1),2e3)}catch{}},[s]);l.useEffect(()=>()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null)},[]);const p=l.useCallback(()=>{n&&t()},[n,t]);return e.jsxs("div",{className:`cedros-recovery-phrase-display ${o}`,children:[e.jsxs("div",{className:"cedros-recovery-header",children:[e.jsx("h3",{className:"cedros-recovery-title",children:"Recovery Phrase"}),e.jsx("p",{className:"cedros-recovery-warning",children:"Write down these 12 words in order and store them securely. This is the only way to recover your wallet if you lose access."})]}),e.jsx("div",{className:"cedros-recovery-grid",children:d.map((f,g)=>e.jsx("div",{className:"cedros-word-group",children:f.map((w,m)=>{const u=g*4+m+1;return e.jsxs("div",{className:"cedros-word-item",children:[e.jsxs("span",{className:"cedros-word-number",children:[u,"."]}),e.jsx("span",{className:"cedros-word-text",children:w})]},u)})},g))}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary cedros-copy-btn",onClick:h,children:a?"Copied!":"Copy to Clipboard"}),e.jsx("div",{className:"cedros-recovery-security",children:e.jsxs("div",{className:"cedros-warning-box",children:[e.jsx("svg",{className:"cedros-warning-icon",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M10 6v4m0 4h.01M19 10a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})}),e.jsxs("div",{className:"cedros-warning-content",children:[e.jsx("strong",{children:"Security Warning"}),e.jsxs("ul",{children:[e.jsx("li",{children:"Never share this phrase with anyone"}),e.jsx("li",{children:"Store it offline in a secure location"}),e.jsx("li",{children:"Anyone with this phrase can access your wallet"}),e.jsx("li",{children:"Cedros cannot recover this phrase for you"})]})]})]})}),e.jsxs("div",{className:"cedros-recovery-confirm",children:[e.jsxs("label",{className:"cedros-checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:f=>c(f.target.checked),className:"cedros-checkbox"}),e.jsx("span",{children:"I have written down and securely stored my recovery phrase"})]}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:p,disabled:!n,children:"Continue"})]})]})}function ur({onSubmit:s,onCancel:t,isSubmitting:o=!1,error:a,className:r=""}){const[n,c]=l.useState(Array(oe).fill("")),[i,d]=l.useState(null),[h,p]=l.useState([]),[f,g]=l.useState(null),w=l.useId(),m=l.useRef(null),u=l.useCallback((x,j)=>{const C=[...n];if(C[x]=j.toLowerCase().trim(),c(C),j.length>0){const N=mo(j,5);p(N)}else p([]);g(null)},[n]),y=l.useCallback(x=>{d(x),p([])},[]),A=l.useCallback(x=>{const j=n[x];j&&!Ue(j)&&g(`Word ${x+1} is not in the wordlist`),m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{i===x&&p([])},200)},[n,i]);l.useEffect(()=>()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]);const b=l.useCallback(x=>{if(i!==null){const j=[...n];j[i]=x,c(j),p([]),document.querySelector(`[data-word-index="${i+1}"]`)?.focus()}},[i,n]),v=l.useCallback(x=>{const j=x.clipboardData.getData("text"),C=go(j);C.length===oe&&(x.preventDefault(),c(C),g(null))},[]),k=l.useCallback(x=>{if(x.preventDefault(),n.filter(N=>!N).length>0){g(`Please enter all ${oe} words`);return}const C=n.map((N,P)=>({word:N,index:P+1})).filter(({word:N})=>!Ue(N));if(C.length>0){g(`Invalid words: ${C.map(N=>`#${N.index}`).join(", ")}`);return}if(!sr(n)){g("Invalid recovery phrase - please check your words");return}s(n)},[n,s]),S=a||f;return e.jsxs("form",{className:`cedros-recovery-phrase-input ${r}`,onSubmit:k,onPaste:v,children:[e.jsxs("div",{className:"cedros-recovery-input-header",children:[e.jsx("h3",{className:"cedros-recovery-input-title",children:"Enter Recovery Phrase"}),e.jsx("p",{className:"cedros-recovery-input-description",children:"Enter your 12-word recovery phrase. You can paste the entire phrase at once."})]}),e.jsx("div",{className:"cedros-word-inputs",children:Array.from({length:oe},(x,j)=>e.jsxs("div",{className:"cedros-word-input-wrapper",children:[e.jsxs("label",{className:"cedros-word-label",children:[j+1,"."]}),e.jsx("input",{type:"text",className:`cedros-word-input ${n[j]&&!Ue(n[j])?"cedros-word-invalid":n[j]&&Ue(n[j])?"cedros-word-valid":""}`,value:n[j],onChange:C=>u(j,C.target.value),onFocus:()=>y(j),onBlur:()=>A(j),"data-word-index":j,autoComplete:"off",autoCapitalize:"none",spellCheck:!1,disabled:o,"aria-label":`Word ${j+1}`})]},j))}),i!==null&&h.length>0&&e.jsx("div",{className:"cedros-suggestions",role:"listbox",id:`${w}-suggestions`,children:h.map(x=>e.jsx("button",{type:"button",className:"cedros-suggestion",onClick:()=>b(x),role:"option",children:x},x))}),S&&e.jsx("p",{className:"cedros-input-error",role:"alert",children:S}),e.jsxs("div",{className:"cedros-recovery-input-actions",children:[t&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:t,disabled:o,children:"Cancel"}),e.jsx("button",{type:"submit",className:"cedros-button cedros-button-primary",disabled:o,children:o?"Recovering...":"Recover Wallet"})]})]})}function Vo({capabilities:s,className:t=""}){if(s.allSupported)return null;const o=I.getMissingCapabilitiesMessage(s),a=I.getBrowserSupportInfo();return e.jsxs("div",{className:`cedros-capability-warning ${t}`,role:"alert",children:[e.jsxs("div",{className:"cedros-warning-header",children:[e.jsx("svg",{className:"cedros-warning-icon",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M12 9v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})}),e.jsx("h3",{className:"cedros-warning-title",children:"Wallet Feature Unavailable"})]}),e.jsx("p",{className:"cedros-warning-message",children:o}),e.jsxs("div",{className:"cedros-capability-details",children:[e.jsx("h4",{children:"Browser Compatibility"}),e.jsxs("p",{children:["Detected: ",a.browser," ",a.version,a.likelySupported?" (likely supported)":" (may not be supported)"]}),e.jsx("h4",{children:"Required Features"}),e.jsxs("ul",{className:"cedros-capability-list",children:[e.jsxs("li",{className:s.webCrypto?"cedros-cap-ok":"cedros-cap-missing",children:["Web Crypto API: ",s.webCrypto?"Available":"Missing"]}),e.jsxs("li",{className:s.aesGcm?"cedros-cap-ok":"cedros-cap-missing",children:["AES-GCM Encryption: ",s.aesGcm?"Available":"Missing"]}),e.jsxs("li",{className:s.hkdf?"cedros-cap-ok":"cedros-cap-missing",children:["HKDF Key Derivation: ",s.hkdf?"Available":"Missing"]}),e.jsxs("li",{className:s.webAuthn?"cedros-cap-ok":"cedros-cap-missing",children:["WebAuthn/Passkeys: ",s.webAuthn?"Available":"Missing"]}),e.jsxs("li",{className:s.webAuthnPrf?"cedros-cap-ok":"cedros-cap-missing",children:["WebAuthn PRF Extension: ",s.webAuthnPrf?"Available":"Missing"]}),e.jsxs("li",{className:s.argon2?"cedros-cap-ok":"cedros-cap-missing",children:["Argon2 Password Hashing: ",s.argon2?"Available":"Missing"]})]})]}),e.jsxs("div",{className:"cedros-capability-help",children:[e.jsx("h4",{children:"Recommended Browsers"}),e.jsxs("ul",{children:[e.jsx("li",{children:"Chrome 116+ on Windows, macOS, or Android"}),e.jsx("li",{children:"Safari 17+ on macOS or iOS"}),e.jsx("li",{children:"Edge 116+ on Windows"})]}),e.jsx("p",{className:"cedros-capability-note",children:"A platform authenticator (Touch ID, Face ID, or Windows Hello) is required."})]})]})}const Ho=["share_c_only","full_seed","none"];function Qo(s){return s&&Ho.includes(s)?s:"share_c_only"}const Ko={walletEnabled:!1,recoveryMode:"share_c_only",unlockTtlSeconds:900,isLoading:!1,error:null,refetch:async()=>{}};function hr(){const s=T.useCedrosLoginOptional(),[t,o]=l.useState(null),[a,r]=l.useState(!!s),[n,c]=l.useState(null),i=l.useMemo(()=>s?new T.ApiClient({baseUrl:s.config.serverUrl,timeoutMs:s.config.requestTimeout,retryAttempts:s.config.retryAttempts}):null,[s]),d=l.useCallback(async()=>{if(i){r(!0),c(null);try{const h=await i.get("/discovery");h.wallet?o({enabled:h.wallet.enabled,recoveryMode:Qo(h.wallet.recoveryMode),unlockTtlSeconds:h.wallet.unlockTtlSeconds}):o({enabled:!1,recoveryMode:"share_c_only",unlockTtlSeconds:900})}catch(h){const p=h instanceof Error?h.message:"Failed to fetch wallet config";c(p),o({enabled:!1,recoveryMode:"share_c_only",unlockTtlSeconds:900})}finally{r(!1)}}},[i]);return l.useEffect(()=>{i&&d()},[i,d]),s?{walletEnabled:t?.enabled??!1,recoveryMode:t?.recoveryMode??"share_c_only",unlockTtlSeconds:t?.unlockTtlSeconds??900,isLoading:a,error:n,refetch:d}:Ko}function pr(){const{user:s}=T.useCedrosLogin(),{enroll:t}=I.useWalletMaterial(),{recoveryMode:o}=hr(),[a,r]=l.useState({step:"idle"}),[n,c]=l.useState(!1),i=l.useRef([]),d=l.useCallback(()=>{I.wipeAll(...i.current),i.current=[]},[]);l.useEffect(()=>()=>{d()},[d]);const h=l.useCallback(async(m,u,y,A)=>{r({step:"generating_seed"});const b=I.generateSeed();i.current.push(b),r({step:"splitting_shares"});const{shareA:v,shareB:k,shareC:S}=ie.splitSecret(b);i.current.push(v,k,S),r({step:"encrypting_shares"});const x=await I.aesGcmEncryptToBase64(v,I.toEncryptionKey(u)),j=ie.getPublicKeyFromSeed(b),C=ie.publicKeyToBase58(j);r({step:"uploading"});const N={solanaPubkey:C,shareAAuthMethod:m,shareACiphertext:x.ciphertext,shareANonce:x.nonce,shareB:I.uint8ArrayToBase64(k)};if(m==="password"){if(!y)throw new Error("KDF salt required for password method");N.shareAKdfSalt=I.uint8ArrayToBase64(y),N.shareAKdfParams=I.DEFAULT_KDF_PARAMS}if(m==="passkey"&&A&&(N.prfSalt=A),await t(N),o==="none")d(),r({step:"complete",solanaPubkey:C});else{const P=o==="full_seed"?ho(b):co(I.toShamirShare(S));r({step:"showing_recovery",recoveryPhrase:P,solanaPubkey:C})}},[t,o,d]),p=l.useCallback(async m=>{if(!s){r({step:"error",error:"User not authenticated"});return}c(!0),d();try{const u=I.generateArgon2Salt(),y=await ie.argon2DeriveInWorker(m,u,I.DEFAULT_KDF_PARAMS);i.current.push(y),await h("password",y,u)}catch(u){r({step:"error",error:u instanceof Error?u.message:"Enrollment failed"})}finally{c(!1)}},[s,d,h]),f=l.useCallback(async()=>{if(!s){r({step:"error",error:"User not authenticated"});return}c(!0),d();try{const m=I.generatePrfSalt(),u=I.uint8ArrayToBase64(m);r({step:"registering_passkey"});let y;try{const b=new TextEncoder().encode(s.id),v=s.name??s.email??"User",k=s.email??s.id;y=(await I.registerPasskeyWithPrf(b,k,v,m)).prfOutput}catch(b){if(b?.name!=="InvalidStateError")throw b;y=(await I.authenticateWithDiscoverablePrf(u)).prfOutput}i.current.push(y);const A=await I.deriveKeyFromPrf(y,m);i.current.push(A),await h("passkey",A,void 0,u)}catch(m){r({step:"error",error:m instanceof Error?m.message:"Enrollment failed"})}finally{c(!1)}},[s,d,h]),g=l.useCallback(()=>{const m=a.solanaPubkey;d(),r({step:"complete",solanaPubkey:m})},[a.solanaPubkey,d]),w=l.useCallback(()=>{d(),r({step:"idle"}),c(!1)},[d]);return{state:a,startEnrollmentWithPassword:p,startEnrollmentWithPasskey:f,confirmRecoveryPhrase:g,cancel:w,isEnrolling:n}}function mr({onComplete:s,onCancel:t,className:o="",forceAuthMethod:a}){const{user:r}=T.useCedrosLogin(),{state:n,startEnrollmentWithPassword:c,startEnrollmentWithPasskey:i,confirmRecoveryPhrase:d,cancel:h,isEnrolling:p}=pr(),f=()=>a||"password",[g,w]=l.useState(f),[m,u]=l.useState(""),[y,A]=l.useState(""),[b,v]=l.useState(null);l.useEffect(()=>{w(f())},[r?.id,a]);const k=l.useCallback(async C=>{if(C.preventDefault(),m!==y){v("Passwords do not match");return}const N=Me.validatePassword(m);if(!N.isValid){const P=Object.values(N.errors)[0];v(P??"Password does not meet requirements");return}v(null),await c(m)},[m,y,c]),S=l.useCallback(async()=>{await i()},[i]),x=l.useCallback(()=>{d(),n.solanaPubkey&&s?.(n.solanaPubkey)},[d,n.solanaPubkey,s]),j=l.useCallback(()=>{h(),t?.()},[h,t]);return n.step==="generating_seed"||n.step==="splitting_shares"?e.jsx("div",{className:`cedros-wallet-enrollment ${o}`,"aria-busy":"true",children:e.jsxs("div",{className:"cedros-enrollment-progress",role:"status","aria-live":"polite",children:[e.jsx("div",{className:"cedros-spinner","aria-hidden":"true"}),e.jsx("p",{children:"Generating secure wallet..."})]})}):n.step==="encrypting_shares"?e.jsx("div",{className:`cedros-wallet-enrollment ${o}`,"aria-busy":"true",children:e.jsxs("div",{className:"cedros-enrollment-progress",role:"status","aria-live":"polite",children:[e.jsx("div",{className:"cedros-spinner","aria-hidden":"true"}),e.jsx("p",{children:"Encrypting wallet shares..."})]})}):n.step==="registering_passkey"?e.jsx("div",{className:`cedros-wallet-enrollment ${o}`,"aria-busy":"true",children:e.jsx("div",{className:"cedros-enrollment-progress",role:"status","aria-live":"polite",children:e.jsxs("div",{className:"cedros-passkey-prompt",children:[e.jsxs("svg",{className:"cedros-passkey-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("rect",{x:"8",y:"16",width:"32",height:"24",rx:"4",stroke:"currentColor",strokeWidth:"2"}),e.jsx("circle",{cx:"24",cy:"28",r:"4",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M24 32v4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),e.jsx("h3",{children:"Authenticate with Passkey"}),e.jsx("p",{children:"Follow your browser's prompt to use your passkey."})]})})}):n.step==="uploading"?e.jsx("div",{className:`cedros-wallet-enrollment ${o}`,"aria-busy":"true",children:e.jsxs("div",{className:"cedros-enrollment-progress",role:"status","aria-live":"polite",children:[e.jsx("div",{className:"cedros-spinner","aria-hidden":"true"}),e.jsx("p",{children:"Saving wallet..."})]})}):n.step==="showing_recovery"&&n.recoveryPhrase?e.jsx("div",{className:`cedros-wallet-enrollment ${o}`,children:e.jsx(dr,{words:n.recoveryPhrase,onConfirm:x})}):n.step==="complete"?e.jsx("div",{className:`cedros-wallet-enrollment ${o}`,children:e.jsxs("div",{className:"cedros-enrollment-complete",children:[e.jsxs("svg",{className:"cedros-success-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"20",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M16 24l6 6 12-12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),e.jsx("h3",{children:"Wallet Created!"}),e.jsxs("p",{className:"cedros-pubkey",children:[e.jsx("strong",{children:"Address:"})," ",n.solanaPubkey]}),e.jsx("p",{children:"Your non-custodial Solana wallet is ready to use."})]})}):n.step==="error"?e.jsx("div",{className:`cedros-wallet-enrollment ${o}`,children:e.jsxs("div",{className:"cedros-enrollment-error",children:[e.jsxs("svg",{className:"cedros-error-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"20",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M24 16v12m0 6h.01",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),e.jsx("h3",{children:"Enrollment Failed"}),e.jsx("p",{className:"cedros-error-message",children:n.error}),e.jsxs("div",{className:"cedros-error-actions",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:j,children:"Cancel"}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:()=>h(),children:"Try Again"})]})]})}):e.jsxs("div",{className:`cedros-wallet-enrollment ${o}`,children:[e.jsxs("div",{className:"cedros-enrollment-header",children:[e.jsx("h2",{children:"Create Wallet"}),e.jsxs("p",{children:["Secure your wallet with a ",g==="passkey"?"passkey":"password","."]})]}),!a&&e.jsxs("div",{className:"cedros-auth-method-selector",children:[e.jsxs("label",{className:"cedros-radio-label",children:[e.jsx("input",{type:"radio",name:"authMethod",value:"password",checked:g==="password",onChange:()=>w("password"),disabled:p}),e.jsx("span",{children:"Password"})]}),e.jsxs("label",{className:"cedros-radio-label",children:[e.jsx("input",{type:"radio",name:"authMethod",value:"passkey",checked:g==="passkey",onChange:()=>w("passkey"),disabled:p}),e.jsx("span",{children:"Passkey"})]})]}),g==="password"&&e.jsxs("form",{onSubmit:k,className:"cedros-enrollment-form",children:[e.jsx(K.PasswordInput,{label:"Password",value:m,onChange:C=>u(C.target.value),showStrengthMeter:!0,disabled:p,required:!0,minLength:8,placeholder:"Enter a strong password"}),e.jsx(K.PasswordInput,{label:"Confirm Password",value:y,onChange:C=>A(C.target.value),error:b??void 0,disabled:p,required:!0,minLength:8,placeholder:"Confirm your password"}),e.jsx("div",{className:"cedros-password-info",children:e.jsx("p",{children:"This password will be used to sign transactions."})}),e.jsxs("div",{className:"cedros-enrollment-actions",children:[t&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:j,disabled:p,children:"Cancel"}),e.jsx("button",{type:"submit",className:"cedros-button cedros-button-primary",disabled:p||!m||!y,children:p?"Creating...":"Continue"})]})]}),g==="passkey"&&e.jsxs("div",{className:"cedros-enrollment-form",children:[e.jsxs("div",{className:"cedros-passkey-info",children:[e.jsxs("svg",{className:"cedros-passkey-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("rect",{x:"8",y:"16",width:"32",height:"24",rx:"4",stroke:"currentColor",strokeWidth:"2"}),e.jsx("circle",{cx:"24",cy:"28",r:"4",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M24 32v4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),e.jsx("p",{children:"Use your passkey (Touch ID, Face ID, or Windows Hello) to secure your wallet."}),e.jsx("p",{children:"You'll use the same passkey to sign transactions."})]}),e.jsxs("div",{className:"cedros-enrollment-actions",children:[t&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:j,disabled:p,children:"Cancel"}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:S,disabled:p,children:p?"Creating...":"Use Passkey"})]})]})]})}function fr(){const{user:s}=T.useCedrosLogin(),{signTransaction:t}=I.useWalletMaterial(),[o,a]=l.useState(!1),[r,n]=l.useState(null),c=l.useCallback(async(d,h)=>{if(!s){const p="User not authenticated";throw n(p),new Error(p)}a(!0),n(null);try{const p={transaction:I.uint8ArrayToBase64(d),...h?{credential:I.toCredentialRequest(h)}:{}},f=await t(p);return I.base64ToUint8Array(f.signature)}catch(p){const f=p instanceof Error?p.message:"Signing failed";throw n(f),p}finally{a(!1)}},[s,t]),i=l.useCallback(()=>n(null),[]);return{signTransaction:c,isSigning:o,error:r,clearError:i}}function gr(){const{getMaterial:s}=I.useWalletMaterial(),[t,o]=l.useState(!1),[a,r]=l.useState(null),n=l.useCallback(async()=>{o(!0),r(null);try{const i=await s();if(!i)throw new Error("No wallet enrolled");if(i.shareAAuthMethod!=="passkey")throw new Error("Wallet is not configured for passkey authentication");if(!i.prfSalt)throw new Error("No PRF salt configured for wallet");const d=await I.authenticateWithDiscoverablePrf(i.prfSalt);try{return{type:"prfOutput",prfOutput:I.uint8ArrayToBase64(d.prfOutput)}}finally{d.prfOutput.fill(0)}}catch(i){const d=i instanceof Error?i.message:"Passkey authentication failed";return r(d),null}finally{o(!1)}},[s]),c=l.useCallback(()=>r(null),[]);return{getPasskeyCredential:n,isAuthenticating:t,error:a,clearError:c}}function wr({mode:s,isLoading:t=!1,error:o,onPrompt:a,onRetry:r,onCancel:n,title:c,description:i,className:d=""}){const h=l.useCallback(()=>{t||a?.()},[t,a]),p=l.useCallback(()=>{r?.()},[r]),f=s==="register"?"Set Up Passkey":"Verify with Passkey",g=s==="register"?"Create a passkey to securely encrypt your wallet on this device. You will use your fingerprint, face, or device PIN.":"Use your passkey to unlock your wallet. You will be prompted for biometric verification.";return e.jsxs("div",{className:`cedros-passkey-prompt ${d}`,children:[e.jsx("div",{className:"cedros-passkey-icon",children:t?e.jsx(Go,{}):o?e.jsx($o,{}):e.jsx(Yo,{})}),e.jsx("h3",{className:"cedros-passkey-title",children:c??f}),e.jsx("p",{className:"cedros-passkey-description",children:i??g}),o&&e.jsx("div",{className:"cedros-passkey-error",role:"alert",children:e.jsx("p",{children:o})}),e.jsx("div",{className:"cedros-passkey-actions",children:o?e.jsxs(e.Fragment,{children:[r&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:p,children:"Try Again"}),n&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:n,children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:h,disabled:t,children:t?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"cedros-button-spinner","aria-hidden":"true"}),"Waiting for passkey..."]}):s==="register"?"Create Passkey":"Use Passkey"}),n&&!t&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:n,children:"Cancel"})]})}),t&&e.jsxs("p",{className:"cedros-passkey-hint",children:["Follow the prompts on your device to ",s==="register"?"create":"verify"," your passkey."]})]})}function Yo(){return e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4"}),e.jsx("path",{d:"M14 13.12c0 2.38 0 6.38-1 8.88"}),e.jsx("path",{d:"M17.29 21.02c.12-.6.43-2.3.5-3.02"}),e.jsx("path",{d:"M2 12a10 10 0 0 1 18-6"}),e.jsx("path",{d:"M2 16h.01"}),e.jsx("path",{d:"M21.8 16c.2-2 .131-5.354 0-6"}),e.jsx("path",{d:"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2"}),e.jsx("path",{d:"M8.65 22c.21-.66.45-1.32.57-2"}),e.jsx("path",{d:"M9 6.8a6 6 0 0 1 9 5.2v2"})]})}function Go(){return e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",className:"cedros-spinner",children:[e.jsx("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),e.jsx("path",{d:"M12 3a9 9 0 0 1 9 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})}function $o(){return e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 8v4M12 16h.01"})]})}function yr({onUnlock:s,onCancel:t,showCancel:o=!0,authMethod:a,className:r=""}){T.useCedrosLogin();const{unlock:n,getMaterial:c,isLoading:i}=I.useWalletMaterial(),{getPasskeyCredential:d,isAuthenticating:h}=gr(),[p,f]=l.useState("idle"),[g,w]=l.useState(a??null),[m,u]=l.useState(""),[y,A]=l.useState(null);l.useEffect(()=>{a!==void 0&&w(a)},[a]);const b=g==="password",v=g==="passkey",k=l.useCallback(async()=>{if(f("credential"),A(null),!g)try{const L=await c();L?w(L.shareAAuthMethod):(A("No wallet enrolled"),f("error"))}catch(L){A(L instanceof Error?L.message:"Failed to get wallet info"),f("error")}},[g,c]),S=l.useCallback(async L=>{L.preventDefault(),A(null),f("unlocking");try{let E;if(b)E={type:"password",password:m};else throw new Error("Invalid auth method");await n(E),f("unlocked"),s?.()}catch(E){A(E instanceof Error?E.message:"Failed to unlock wallet"),f("error")}},[b,m,n,s]),x=l.useCallback(async()=>{A(null),f("unlocking");try{const L=await d();if(!L){f("credential");return}await n(L),f("unlocked"),s?.()}catch(L){A(L instanceof Error?L.message:"Failed to unlock wallet"),f("error")}},[d,n,s]),j=l.useCallback(()=>{u(""),f("idle"),A(null),t?.()},[t]),C=l.useCallback(()=>{u(""),f("credential"),A(null)},[]),N=i||h,P=()=>{switch(p){case"idle":return e.jsxs("div",{className:"cedros-wallet-unlock-idle",children:[e.jsx("div",{className:"cedros-wallet-unlock-icon",children:e.jsx(Jo,{})}),e.jsx("h3",{className:"cedros-wallet-unlock-title",children:"Wallet Locked"}),e.jsx("p",{className:"cedros-wallet-unlock-description",children:"Unlock your wallet to sign transactions."}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:k,children:"Unlock Wallet"})]});case"credential":return b?e.jsxs("form",{className:"cedros-wallet-unlock-form",onSubmit:S,children:[e.jsx("h3",{className:"cedros-wallet-unlock-title",children:"Enter Password"}),e.jsx("p",{className:"cedros-wallet-unlock-description",children:"Enter your wallet password to unlock."}),e.jsx(K.PasswordInput,{label:"Password",value:m,onChange:L=>u(L.target.value),disabled:N,autoComplete:"current-password",error:y??void 0}),e.jsxs("div",{className:"cedros-wallet-unlock-actions",children:[e.jsx("button",{type:"submit",className:"cedros-button cedros-button-primary",disabled:N||m.length===0,children:N?"Unlocking...":"Unlock"}),o&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:j,disabled:N,children:"Cancel"})]})]}):v?e.jsxs("div",{className:"cedros-wallet-unlock-passkey",children:[e.jsx("h3",{className:"cedros-wallet-unlock-title",children:"Verify with Passkey"}),e.jsx("p",{className:"cedros-wallet-unlock-description",children:"Use your passkey to unlock your wallet."}),e.jsx(wr,{mode:"authenticate",isLoading:N,error:y??void 0,onPrompt:x,onRetry:x,onCancel:o?j:void 0})]}):e.jsxs("div",{className:"cedros-wallet-unlock-loading",children:[e.jsx(V.LoadingSpinner,{size:"xl"}),e.jsx("p",{children:"Loading wallet info..."})]});case"unlocking":return e.jsxs("div",{className:"cedros-wallet-unlock-progress",children:[e.jsx("div",{className:"cedros-wallet-unlock-icon",children:e.jsx(V.LoadingSpinner,{size:"xl"})}),e.jsx("h3",{className:"cedros-wallet-unlock-title",children:"Unlocking Wallet"}),e.jsx("p",{className:"cedros-wallet-unlock-description",children:"Verifying your credentials..."})]});case"unlocked":return e.jsxs("div",{className:"cedros-wallet-unlock-success",children:[e.jsx("div",{className:"cedros-wallet-unlock-icon",children:e.jsx(Xo,{})}),e.jsx("h3",{className:"cedros-wallet-unlock-title",children:"Wallet Unlocked"}),e.jsx("p",{className:"cedros-wallet-unlock-description",children:"Your wallet is ready to sign transactions."})]});case"error":return e.jsxs("div",{className:"cedros-wallet-unlock-error",children:[e.jsx("div",{className:"cedros-wallet-unlock-icon",children:e.jsx(Zo,{})}),e.jsx("h3",{className:"cedros-wallet-unlock-title",children:"Unlock Failed"}),e.jsx("p",{className:"cedros-wallet-unlock-description",children:y??"Failed to unlock wallet. Please try again."}),e.jsxs("div",{className:"cedros-wallet-unlock-actions",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:C,children:"Try Again"}),o&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:j,children:"Cancel"})]})]})}};return e.jsx("div",{className:`cedros-wallet-unlock ${r}`,children:P()})}function Jo(){return e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("rect",{x:"10",y:"22",width:"28",height:"20",rx:"4",stroke:"currentColor",strokeWidth:"2",fill:"var(--cedros-muted, #f3f4f6)"}),e.jsx("path",{d:"M16 22V16a8 8 0 1 1 16 0v6",stroke:"currentColor",strokeWidth:"2",fill:"none"}),e.jsx("circle",{cx:"24",cy:"32",r:"3",fill:"currentColor"})]})}function Xo(){return e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"20",stroke:"var(--cedros-success, #22c55e)",strokeWidth:"2",fill:"var(--cedros-success-light, #dcfce7)"}),e.jsx("path",{d:"M16 24l6 6 10-10",stroke:"var(--cedros-success, #22c55e)",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function Zo(){return e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"20",stroke:"var(--cedros-destructive, #ef4444)",strokeWidth:"2",fill:"var(--cedros-destructive-light, #fee2e2)"}),e.jsx("path",{d:"M24 16v10M24 30v2",stroke:"var(--cedros-destructive, #ef4444)",strokeWidth:"3",strokeLinecap:"round"})]})}function br(){const{recover:s,getShareBForRecovery:t}=I.useWalletMaterial(),{recoveryMode:o}=hr(),[a,r]=l.useState({step:"idle"}),[n,c]=l.useState(!1),i=l.useRef([]),d=l.useCallback(()=>{I.wipeAll(...i.current),i.current=[]},[]);l.useEffect(()=>()=>{d()},[d]);const h=l.useCallback(async(f,g,w)=>{c(!0),d();try{if(r({step:"validating"}),!sr(f))throw new Error("Invalid recovery phrase. Please check your words.");let m;if(o==="share_c_only"){const C=uo(f);i.current.push(C);const N=I.uint8ArrayToBase64(C),P=await t({shareC:N}),L=I.base64ToUint8Array(P.shareB);i.current.push(L),m=ie.combineShares(I.toShamirShare(L),I.toShamirShare(C)),i.current.push(m)}else m=po(f),i.current.push(m);const u=ie.getPublicKeyFromSeed(m),y=ie.publicKeyToBase58(u),{shareA:A,shareB:b}=ie.splitSecret(m);i.current.push(A,b),r({step:"encrypting"});let v,k,S;if(g==="passkey"){const C=I.generatePrfSalt();S=I.uint8ArrayToBase64(C);const N=await I.authenticateWithDiscoverablePrf(S);i.current.push(N.prfOutput),v=await I.deriveKeyFromPrf(N.prfOutput,C),i.current.push(v)}else k=I.generateArgon2Salt(),v=await ie.argon2DeriveInWorker(w,k,I.DEFAULT_KDF_PARAMS),i.current.push(v);const x=await I.aesGcmEncryptToBase64(A,I.toEncryptionKey(v));r({step:"uploading"});const j={solanaPubkey:y,shareAAuthMethod:g,shareACiphertext:x.ciphertext,shareANonce:x.nonce,shareB:I.uint8ArrayToBase64(b)};g==="password"&&(j.shareAKdfSalt=I.uint8ArrayToBase64(k),j.shareAKdfParams=I.DEFAULT_KDF_PARAMS),g==="passkey"&&(j.prfSalt=S),await s(j),d(),r({step:"complete"})}catch(m){d(),r({step:"error",error:m instanceof Error?m.message:"Recovery failed"})}finally{c(!1)}},[s,t,o,d]),p=l.useCallback(()=>{d(),r({step:"idle"}),c(!1)},[d]);return{state:a,startRecovery:h,cancel:p,isRecovering:n}}function Ar({onComplete:s,onCancel:t,className:o="",defaultAuthMethod:a="password"}){const{state:r,startRecovery:n,cancel:c,isRecovering:i}=br(),[d,h]=l.useState([]),[p,f]=l.useState(!1),[g,w]=l.useState(a),[m,u]=l.useState(""),[y,A]=l.useState(""),[b,v]=l.useState(null),k=l.useCallback(N=>{h(N),f(!0)},[]),S=l.useCallback(async N=>{if(N.preventDefault(),v(null),g!=="passkey"){if(m!==y){v("Passwords do not match");return}if(g==="password"&&m.length<8){v("Password must be at least 8 characters");return}}await n(d,g,m)},[d,g,m,y,n]),x=l.useCallback(()=>{c(),h([]),f(!1),u(""),A(""),t?.()},[c,t]),j=l.useCallback(()=>{f(!1),u(""),A("")},[]),C=l.useCallback(()=>{s?.()},[s]);return r.step==="validating"||r.step==="encrypting"||r.step==="uploading"?e.jsx("div",{className:`cedros-wallet-recovery ${o}`,children:e.jsxs("div",{className:"cedros-wallet-recovery-progress",children:[e.jsx("div",{className:"cedros-wallet-recovery-icon",children:e.jsx(en,{})}),e.jsxs("h3",{className:"cedros-wallet-recovery-title",children:[r.step==="validating"&&"Validating Recovery Phrase",r.step==="encrypting"&&"Encrypting Wallet",r.step==="uploading"&&"Saving to Server"]}),e.jsxs("p",{className:"cedros-wallet-recovery-description",children:[r.step==="validating"&&"Checking your recovery phrase...",r.step==="encrypting"&&"Securing your wallet with new encryption...",r.step==="uploading"&&"Uploading encrypted wallet data..."]})]})}):r.step==="complete"?e.jsx("div",{className:`cedros-wallet-recovery ${o}`,children:e.jsxs("div",{className:"cedros-wallet-recovery-success",children:[e.jsx("div",{className:"cedros-wallet-recovery-icon",children:e.jsx(sn,{})}),e.jsx("h3",{className:"cedros-wallet-recovery-title",children:"Wallet Recovered"}),e.jsxs("p",{className:"cedros-wallet-recovery-description",children:["Your wallet has been successfully recovered and secured with your new"," ",g==="passkey"?"passkey":"password","."]}),e.jsx("div",{className:"cedros-wallet-recovery-actions",children:e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:C,children:"Done"})})]})}):r.step==="error"?e.jsx("div",{className:`cedros-wallet-recovery ${o}`,children:e.jsxs("div",{className:"cedros-wallet-recovery-error",children:[e.jsx("div",{className:"cedros-wallet-recovery-icon",children:e.jsx(tn,{})}),e.jsx("h3",{className:"cedros-wallet-recovery-title",children:"Recovery Failed"}),e.jsx("p",{className:"cedros-wallet-recovery-description",children:r.error??"An error occurred during recovery. Please try again."}),e.jsx("div",{className:"cedros-wallet-recovery-actions",children:e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:x,children:"Start Over"})})]})}):p?e.jsx("div",{className:`cedros-wallet-recovery ${o}`,children:e.jsxs("form",{className:"cedros-wallet-recovery-credential",onSubmit:S,children:[e.jsxs("div",{className:"cedros-wallet-recovery-header",children:[e.jsx("h3",{className:"cedros-wallet-recovery-title",children:"Set New Security"}),e.jsx("p",{className:"cedros-wallet-recovery-description",children:"Choose how to secure your recovered wallet."})]}),e.jsxs("div",{className:"cedros-auth-method-selector",children:[e.jsxs("label",{className:"cedros-radio-label",children:[e.jsx("input",{type:"radio",name:"authMethod",value:"password",checked:g==="password",onChange:()=>w("password"),disabled:i}),e.jsx("span",{children:"Password"})]}),e.jsxs("label",{className:"cedros-radio-label",children:[e.jsx("input",{type:"radio",name:"authMethod",value:"passkey",checked:g==="passkey",onChange:()=>w("passkey"),disabled:i}),e.jsx("span",{children:"Passkey"})]})]}),g==="password"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-password-input",children:[e.jsx("label",{htmlFor:"recovery-password",className:"cedros-label",children:"New Password"}),e.jsx("input",{id:"recovery-password",type:"password",className:"cedros-input",value:m,onChange:N=>u(N.target.value),disabled:i,minLength:8,placeholder:"Enter a strong password"})]}),e.jsxs("div",{className:"cedros-password-input",children:[e.jsx("label",{htmlFor:"recovery-password-confirm",className:"cedros-label",children:"Confirm Password"}),e.jsx("input",{id:"recovery-password-confirm",type:"password",className:"cedros-input",value:y,onChange:N=>A(N.target.value),disabled:i,"aria-invalid":b?"true":void 0,placeholder:"Confirm your password"}),b&&e.jsx("p",{className:"cedros-input-error",role:"alert",children:b})]})]}),g==="passkey"&&e.jsxs("div",{className:"cedros-passkey-info",children:[e.jsx(rn,{}),e.jsx("p",{children:"Use your passkey (Touch ID, Face ID, or Windows Hello) to secure your wallet."})]}),e.jsxs("div",{className:"cedros-wallet-recovery-actions",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:j,disabled:i,children:"Back"}),e.jsx("button",{type:"submit",className:"cedros-button cedros-button-primary",disabled:i||g!=="passkey"&&(m.length===0||y.length===0),children:i?"Recovering...":"Recover Wallet"})]})]})}):e.jsx("div",{className:`cedros-wallet-recovery ${o}`,children:e.jsxs("div",{className:"cedros-wallet-recovery-phrase",children:[e.jsxs("div",{className:"cedros-wallet-recovery-header",children:[e.jsx("h3",{className:"cedros-wallet-recovery-title",children:"Recover Your Wallet"}),e.jsx("p",{className:"cedros-wallet-recovery-description",children:"Enter your 12-word recovery phrase to restore your wallet."})]}),e.jsx(ur,{onSubmit:k,onCancel:x,isSubmitting:!1})]})})}function en(){return e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",className:"cedros-spinner",children:[e.jsx("circle",{cx:"24",cy:"24",r:"20",stroke:"var(--cedros-muted, #e5e7eb)",strokeWidth:"3",fill:"none"}),e.jsx("path",{d:"M24 4a20 20 0 0 1 20 20",stroke:"var(--cedros-primary, #6366f1)",strokeWidth:"3",strokeLinecap:"round",fill:"none"})]})}function sn(){return e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"20",stroke:"var(--cedros-success, #22c55e)",strokeWidth:"2",fill:"var(--cedros-success-light, #dcfce7)"}),e.jsx("path",{d:"M16 24l6 6 10-10",stroke:"var(--cedros-success, #22c55e)",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function tn(){return e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"20",stroke:"var(--cedros-destructive, #ef4444)",strokeWidth:"2",fill:"var(--cedros-destructive-light, #fee2e2)"}),e.jsx("path",{d:"M24 16v10M24 30v2",stroke:"var(--cedros-destructive, #ef4444)",strokeWidth:"3",strokeLinecap:"round"})]})}function rn(){return e.jsxs("svg",{className:"cedros-passkey-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("rect",{x:"8",y:"16",width:"32",height:"24",rx:"4",stroke:"currentColor",strokeWidth:"2"}),e.jsx("circle",{cx:"24",cy:"28",r:"4",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M24 32v4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})}function xr({address:s,label:t="Wallet Address",showCopy:o=!0,showExplorerLink:a=!0,allowReveal:r=!0,className:n=""}){const c=T.useCedrosLoginOptional(),[i,d]=l.useState(!1),[h,p]=l.useState(null),[f,g]=l.useState(!1),w=l.useRef(null),m=c?.config.solana?.network??"mainnet-beta",u=l.useMemo(()=>{const v=`https://explorer.solana.com/address/${s}`;return m==="mainnet-beta"?v:`${v}?cluster=${encodeURIComponent(m)}`},[s,m]),y=r&&s.length>18,A=l.useMemo(()=>!y||f?s:`${s.slice(0,8)}...${s.slice(-8)}`,[s,y,f]),b=l.useCallback(async()=>{try{p(null),await navigator.clipboard.writeText(s),d(!0),w.current!==null&&window.clearTimeout(w.current),w.current=window.setTimeout(()=>{d(!1),w.current=null},2e3)}catch(v){d(!1),p(v instanceof Error?v.message:"Copy failed")}},[s]);return l.useEffect(()=>()=>{w.current!==null&&(window.clearTimeout(w.current),w.current=null)},[]),e.jsxs("div",{className:`cedros-wallet-address-row ${n}`,children:[e.jsxs("div",{className:"cedros-wallet-address-row-header",children:[e.jsx("span",{className:"cedros-wallet-status-pubkey-label",children:t}),e.jsxs("div",{className:"cedros-wallet-address-row-actions",children:[y&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-sm cedros-button-ghost",onClick:()=>g(v=>!v),"aria-label":f?"Hide full wallet address":"Show full wallet address",children:f?e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M3 3l18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M10.7 10.7a3 3 0 0 0 4.24 4.24",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M9.88 5.09A10.94 10.94 0 0 1 12 5c5 0 9.27 3.11 11 7-0.55 1.23-1.32 2.33-2.27 3.25",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M6.61 6.61C4.4 7.9 2.74 9.8 1 12c1.73 3.89 6 7 11 7 1.14 0 2.25-0.16 3.3-0.46",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}):e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M1 12s4-7 11-7 11 7 11 7-4 7-11 7S1 12 1 12Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}),a&&e.jsx("a",{className:"cedros-button cedros-button-sm cedros-button-ghost",href:u,target:"_blank",rel:"noreferrer",children:"Explorer"}),o&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-sm cedros-button-outline",onClick:b,"aria-label":"Copy wallet address",children:i?"Copied":"Copy"})]})]}),e.jsx("code",{className:"cedros-wallet-status-pubkey-value",title:s,children:A}),h&&e.jsx("p",{className:"cedros-input-hint",role:"status",children:h})]})}function vr({status:s,publicKey:t,onLock:o,onEnroll:a,onUnlock:r,onRecover:n,showActions:c=!0,compact:i=!1,className:d=""}){const h=s!==void 0,p=I.useWallet(),f=h?s:p.status,g=h?t??null:p.solanaPubkey,w=h?null:p.error,m=h?()=>{}:p.refresh,u=h?()=>{}:p.clearError,y=on(f,w);return i?e.jsxs("div",{className:`cedros-wallet-status cedros-wallet-status-compact ${d}`,children:[e.jsx("span",{className:`cedros-wallet-status-dot cedros-wallet-status-${y.color}`,title:y.label}),e.jsx("span",{className:"cedros-wallet-status-label",children:y.label}),g&&e.jsx("span",{className:"cedros-wallet-status-pubkey",title:g,children:nn(g)})]}):e.jsxs("div",{className:`cedros-wallet-status ${d}`,children:[e.jsxs("div",{className:"cedros-wallet-status-header",children:[e.jsx("div",{className:`cedros-wallet-status-icon cedros-wallet-status-icon-${y.color}`,children:e.jsx(an,{status:f})}),e.jsxs("div",{className:"cedros-wallet-status-info",children:[e.jsx("h4",{className:"cedros-wallet-status-title",children:y.title}),e.jsx("p",{className:"cedros-wallet-status-description",children:y.description})]})]}),g&&e.jsx("div",{className:"cedros-wallet-status-pubkey-full",children:e.jsx(xr,{address:g})}),w&&e.jsxs("div",{className:"cedros-wallet-status-error-box",role:"alert",children:[e.jsx("p",{children:w}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-sm cedros-button-secondary",onClick:u,children:"Dismiss"})]}),c&&e.jsxs("div",{className:"cedros-wallet-status-actions",children:[f==="not_enrolled"&&a&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary cedros-button-sm",onClick:a,children:"Create Wallet"}),f==="enrolled_locked"&&r&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary cedros-button-sm",onClick:r,children:"Unlock Wallet"}),(f==="not_enrolled"||f==="error")&&n&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:n,children:"Recover Wallet"}),f==="error"&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:m,children:"Retry"})]})]})}function on(s,t){switch(s){case"loading":return{label:"Loading",title:"Checking Wallet",description:"Verifying wallet status...",color:"loading"};case"not_enrolled":return{label:"Not Set Up",title:"No Wallet",description:"Create a wallet to start using Solana.",color:"muted"};case"enrolled_locked":return{label:"Locked",title:"Wallet Locked",description:"Unlock your wallet to sign transactions.",color:"warning"};case"enrolled_unlocked":case"unlocked":return{label:"Ready",title:"Wallet Ready",description:"Your wallet is unlocked and ready to use.",color:"success"};case"error":default:return{label:"Error",title:"Wallet Error",description:t??"An error occurred with your wallet.",color:"error"}}}function nn(s){return s.length<=12?s:`${s.slice(0,4)}...${s.slice(-4)}`}function an({status:s}){switch(s){case"loading":return e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",className:"cedros-spinner",children:[e.jsx("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),e.jsx("path",{d:"M12 3a9 9 0 0 1 9 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]});case"not_enrolled":return e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M8 12h8M12 8v8"})]});case"enrolled_locked":return e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]});case"enrolled_unlocked":case"unlocked":return e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M20 6L9 17l-5-5"})});case"error":return e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"}),e.jsx("path",{d:"M12 9v4M12 17h.01"})]});default:return null}}function ln({className:s="",showActions:t=!0}){const o=I.useWallet(),[a,r]=l.useState("status"),n=l.useMemo(()=>{switch(a){case"enroll":return{title:"Create Wallet",description:"Set up your embedded wallet."};case"unlock":return{title:"Unlock Wallet",description:"Unlock to sign transactions."};case"recover_intro":case"recover":return{title:"Recover Wallet",description:"Restore access using your recovery phrase."};case"status":default:return null}},[a]),c=l.useCallback(()=>r("status"),[]),i=l.useCallback(async()=>{r("status"),await o.refresh()},[o]),d=l.useCallback(async()=>{r("status"),await o.refresh()},[o]),h=l.useCallback(async()=>{r("status"),await o.refresh()},[o]);return e.jsxs("div",{className:`cedros-wallet-manager ${s}`,children:[a!=="status"&&n&&e.jsxs("div",{className:"cedros-wallet-manager-header",children:[e.jsxs("div",{className:"cedros-wallet-manager-header-text",children:[e.jsx("h3",{className:"cedros-wallet-manager-title",children:n.title}),e.jsx("p",{className:"cedros-wallet-manager-subtitle",children:n.description})]}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-sm cedros-button-ghost",onClick:c,children:"Back"})]}),a==="status"&&e.jsx(vr,{onEnroll:()=>r("enroll"),onUnlock:()=>r("unlock"),onRecover:()=>r("recover_intro"),showActions:t}),a==="enroll"&&e.jsx(mr,{onComplete:()=>{i()},onCancel:c}),a==="unlock"&&e.jsx(yr,{onUnlock:()=>{d()},onCancel:c}),a==="recover_intro"&&e.jsx("div",{className:"cedros-wallet-manager-intro",children:e.jsxs("div",{className:"cedros-wallet-manager-intro-card",children:[e.jsx("h4",{className:"cedros-wallet-manager-intro-title",children:"Before you start"}),e.jsxs("ul",{className:"cedros-wallet-manager-intro-list",children:[e.jsx("li",{children:"You’ll need your 12-word recovery phrase."}),e.jsx("li",{children:"You’ll set a new password or passkey for this wallet."}),e.jsx("li",{children:"If you’re on a shared device, avoid copying the phrase into other apps."})]}),e.jsxs("div",{className:"cedros-wallet-manager-intro-actions",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:()=>r("recover"),children:"Start recovery"}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:c,children:"Cancel"})]})]})}),a==="recover"&&e.jsx(Ar,{onComplete:()=>{h()},onCancel:c})]})}function cn({showDescriptions:s=!0,className:t="",onSave:o}){const{settings:a,isLoading:r,isUpdating:n,error:c,fetchSettings:i,updateSettings:d}=Vt.useSystemSettings(),[h,p]=l.useState({}),[f,g]=l.useState(null),[w,m]=l.useState(!1);l.useEffect(()=>{i()},[i]),l.useEffect(()=>{if(w){const S=setTimeout(()=>m(!1),3e3);return()=>clearTimeout(S)}},[w]);const u=l.useCallback((S,x)=>{p(j=>({...j,[S]:x})),g(null),m(!1)},[]),y=l.useCallback(async()=>{const S=Object.entries(h).map(([x,j])=>({key:x,value:j}));if(S.length!==0)try{await d(S),p({}),g(null),m(!0),o?.()}catch(x){g(x instanceof Error?x.message:"Failed to save settings")}},[h,d,o]),A=l.useCallback(()=>{p({}),g(null),m(!1)},[]),b=Object.keys(h).length>0,v=Object.keys(h).length;if(r&&Object.keys(a).length===0)return e.jsxs("div",{className:`cedros-system-settings cedros-system-settings-loading ${t}`,children:[e.jsx(V.LoadingSpinner,{}),e.jsx("span",{children:"Loading settings..."})]});if(c)return e.jsx("div",{className:`cedros-system-settings ${t}`,children:e.jsx(G.ErrorMessage,{error:c.message})});const k=Object.keys(a).sort();return k.length===0?e.jsx("div",{className:`cedros-system-settings cedros-system-settings-empty ${t}`,children:e.jsx("p",{children:"No system settings found."})}):e.jsxs("div",{className:`cedros-system-settings ${t}`,children:[f&&e.jsx(G.ErrorMessage,{error:f}),w&&e.jsx("div",{className:"cedros-settings-success",children:"Settings saved successfully."}),k.map(S=>e.jsx(dn,{category:S,settings:a[S],edits:h,showDescription:s,onChange:u},S)),e.jsxs("div",{className:"cedros-system-settings-actions",children:[b&&e.jsxs("span",{className:"cedros-settings-change-count",children:[v," unsaved change",v!==1?"s":""]}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:A,disabled:!b||n,children:"Reset"}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:y,disabled:!b||n,children:n?e.jsx(V.LoadingSpinner,{size:"sm"}):"Save Changes"})]})]})}const ut=Object.keys(xe.SETTING_METADATA);function dn({category:s,settings:t,edits:o,showDescription:a,onChange:r}){const n=xe.CATEGORY_METADATA[s]||{label:s,description:"",icon:""},c=l.useMemo(()=>[...t].sort((i,d)=>{const h=ut.indexOf(i.key),p=ut.indexOf(d.key);return(h===-1?1/0:h)-(p===-1?1/0:p)}),[t]);return e.jsxs("section",{className:"cedros-settings-section",children:[e.jsxs("div",{className:"cedros-settings-section-header",children:[e.jsx("span",{className:"cedros-settings-section-icon",children:n.icon}),e.jsxs("div",{children:[e.jsx("h3",{className:"cedros-settings-section-title",children:n.label}),a&&n.description&&e.jsx("p",{className:"cedros-settings-section-description",children:n.description})]})]}),e.jsx(xe.SettingsSection,{settings:c,edits:o,onChange:r})]})}class un{client;constructor(t,o,a){this.client=new T.ApiClient({baseUrl:t,timeoutMs:o,retryAttempts:a})}async getStatus(){try{return await this.client.get("/setup/status")}catch(t){throw T.handleApiError(t,"Failed to check setup status")}}async createFirstAdmin(t){try{return await this.client.post("/setup/admin",t)}catch(o){throw T.handleApiError(o,"Failed to create admin account")}}}function Qs(){const{config:s}=T.useCedrosLogin(),[t,o]=l.useState(null),[a,r]=l.useState(!1),[n,c]=l.useState(!1),[i,d]=l.useState(null),h=l.useRef(0),p=l.useMemo(()=>new un(s.serverUrl,s.requestTimeout,s.retryAttempts),[s.serverUrl,s.requestTimeout,s.retryAttempts]),f=l.useRef(p);f.current=p;const g=l.useCallback(async()=>{r(!0),d(null);const m=++h.current;try{const u=await f.current.getStatus();if(m!==h.current)return;o(u)}catch(u){if(m!==h.current)return;d(u instanceof Error?u:new Error("Failed to check setup status"))}finally{m===h.current&&r(!1)}},[]),w=l.useCallback(async m=>{c(!0),d(null);try{const u=await f.current.createFirstAdmin(m);return await g(),u}catch(u){const y=u instanceof Error?u:new Error("Failed to create admin");throw d(y),y}finally{c(!1)}},[g]);return{status:t,isLoading:a,isCreating:n,error:i,checkStatus:g,createAdmin:w}}const hn=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,ht=8;function pn(s){const t={};return s.email?hn.test(s.email)||(t.email="Invalid email format"):t.email="Email is required",s.password?s.password.length<ht&&(t.password=`Password must be at least ${ht} characters`):t.password="Password is required",s.confirmPassword?s.password!==s.confirmPassword&&(t.confirmPassword="Passwords do not match"):t.confirmPassword="Please confirm your password",t}function jr({onComplete:s,className:t=""}){const{status:o,isLoading:a,isCreating:r,error:n,checkStatus:c,createAdmin:i}=Qs(),[d,h]=l.useState({email:"",password:"",confirmPassword:"",name:"",orgName:""}),[p,f]=l.useState({}),[g,w]=l.useState(!1);l.useEffect(()=>{c()},[c]);const m=l.useCallback(y=>A=>{h(b=>({...b,[y]:A.target.value})),f(b=>({...b,[y]:void 0}))},[]),u=l.useCallback(async y=>{y.preventDefault();const A=pn(d);if(Object.keys(A).length>0){f(A);return}try{await i({email:d.email,password:d.password,name:d.name||void 0,orgName:d.orgName||void 0}),w(!0),s?.()}catch{}},[d,i,s]);return a?e.jsx("div",{className:`cedros-setup ${t}`,children:e.jsxs("div",{className:"cedros-setup__loading",children:[e.jsx(V.LoadingSpinner,{}),e.jsx("span",{className:"cedros-setup__loading-text",children:"Checking setup status..."})]})}):o&&!o.needsSetup?e.jsx("div",{className:`cedros-setup ${t}`,children:e.jsxs("div",{className:"cedros-setup__complete",children:[e.jsx("div",{className:"cedros-setup__icon cedros-setup__icon--success",children:e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]})}),e.jsx("h2",{className:"cedros-setup__title",children:"Setup Complete"}),e.jsx("p",{className:"cedros-setup__text",children:"An admin account already exists. You can now log in."})]})}):g?e.jsx("div",{className:`cedros-setup ${t}`,children:e.jsxs("div",{className:"cedros-setup__complete",children:[e.jsx("div",{className:"cedros-setup__icon cedros-setup__icon--success",children:e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]})}),e.jsx("h2",{className:"cedros-setup__title",children:"Admin Account Created"}),e.jsx("p",{className:"cedros-setup__text",children:"Your admin account has been created successfully. You can now log in with your credentials."})]})}):e.jsx("div",{className:`cedros-setup ${t}`,children:e.jsxs("div",{className:"cedros-setup__container",children:[e.jsxs("div",{className:"cedros-setup__header",children:[e.jsx("div",{className:"cedros-setup__logo",children:e.jsxs("svg",{width:"32",height:"32",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"})]})}),e.jsx("h1",{className:"cedros-setup__title",children:"Welcome to Cedros"}),e.jsx("p",{className:"cedros-setup__subtitle",children:"Let's set up your admin account to get started."})]}),e.jsxs("form",{className:"cedros-setup__form",onSubmit:u,children:[n&&e.jsx(G.ErrorMessage,{error:n.message}),e.jsxs("div",{className:"cedros-setup__field",children:[e.jsxs("label",{htmlFor:"setup-email",className:"cedros-setup__label",children:["Email Address ",e.jsx("span",{className:"cedros-setup__required",children:"*"})]}),e.jsx("input",{id:"setup-email",type:"email",className:`cedros-setup__input ${p.email?"cedros-setup__input--error":""}`,value:d.email,onChange:m("email"),placeholder:"admin@example.com",autoComplete:"email",autoFocus:!0,disabled:r}),p.email&&e.jsx("span",{className:"cedros-setup__error",children:p.email})]}),e.jsxs("div",{className:"cedros-setup__field",children:[e.jsx("label",{htmlFor:"setup-name",className:"cedros-setup__label",children:"Display Name"}),e.jsx("input",{id:"setup-name",type:"text",className:"cedros-setup__input",value:d.name,onChange:m("name"),placeholder:"Admin",autoComplete:"name",disabled:r})]}),e.jsxs("div",{className:"cedros-setup__field",children:[e.jsx("label",{htmlFor:"setup-org-name",className:"cedros-setup__label",children:"Organization Name"}),e.jsx("input",{id:"setup-org-name",type:"text",className:"cedros-setup__input",value:d.orgName,onChange:m("orgName"),placeholder:"My Organization",disabled:r})]}),e.jsxs("div",{className:"cedros-setup__field",children:[e.jsxs("label",{htmlFor:"setup-password",className:"cedros-setup__label",children:["Password ",e.jsx("span",{className:"cedros-setup__required",children:"*"})]}),e.jsx("input",{id:"setup-password",type:"password",className:`cedros-setup__input ${p.password?"cedros-setup__input--error":""}`,value:d.password,onChange:m("password"),placeholder:"At least 8 characters",autoComplete:"new-password",disabled:r}),p.password&&e.jsx("span",{className:"cedros-setup__error",children:p.password})]}),e.jsxs("div",{className:"cedros-setup__field",children:[e.jsxs("label",{htmlFor:"setup-confirm-password",className:"cedros-setup__label",children:["Confirm Password ",e.jsx("span",{className:"cedros-setup__required",children:"*"})]}),e.jsx("input",{id:"setup-confirm-password",type:"password",className:`cedros-setup__input ${p.confirmPassword?"cedros-setup__input--error":""}`,value:d.confirmPassword,onChange:m("confirmPassword"),placeholder:"Confirm your password",autoComplete:"new-password",disabled:r}),p.confirmPassword&&e.jsx("span",{className:"cedros-setup__error",children:p.confirmPassword})]}),e.jsx("button",{type:"submit",className:"cedros-setup__button",disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx(V.LoadingSpinner,{}),e.jsx("span",{children:"Creating Account..."})]}):"Create Admin Account"})]}),e.jsxs("div",{className:"cedros-setup__footer",children:[e.jsx("p",{className:"cedros-setup__note",children:"This will be the first administrator account for your installation."}),o?.serverVersion&&e.jsxs("p",{className:"cedros-setup__version",children:["Server version: ",o.serverVersion]})]})]})})}const mn=["security","rate_limit"];function fn({className:s}){return e.jsx(qs.SettingsPageLayout,{title:"Security",description:"Configure CORS, cookies, sessions, JWT, and rate limiting settings.",categories:mn,className:s})}const pt=[{id:"email",label:"Email",category:"email"},{id:"webhooks",label:"Webhooks",category:"webhook"}];function gn({className:s}){const{settings:t,edits:o,isLoading:a,autosaveStatus:r,autosaveError:n,error:c,fetchSettings:i,handleChange:d,getEffectiveValue:h}=xe.useSettingsAutosave(),[p,f]=l.useState("email");l.useEffect(()=>{i()},[i]);const g=pt.find(k=>k.id===p),w=g?.category??"",u=(h("email_provider")||"custom")==="custom",y=h("email_smtp_host"),A=!u||y!=null&&y!=="",b=l.useMemo(()=>{const k=t[w]??[];if(p!=="email")return k;const S=u?Oe.ALL_EMAIL_FIELDS:Oe.SIMPLIFIED_EMAIL_FIELDS;return k.filter(x=>S.includes(x.key)).sort((x,j)=>S.indexOf(x.key)-S.indexOf(j.key))},[t,w,p,u]),v=(k,S)=>{if(d(k,S),k==="email_provider"&&S!=="custom"){const x=Oe.PROVIDER_SMTP_HOSTS[S];x&&(d("email_smtp_host",x),d("email_smtp_port","587"),d("email_smtp_tls","true"))}};return a&&Object.keys(t).length===0?e.jsxs("div",{className:`cedros-system-settings cedros-system-settings-loading ${s??""}`,children:[e.jsx(V.LoadingSpinner,{}),e.jsx("span",{children:"Loading settings..."})]}):c?e.jsx("div",{className:`cedros-system-settings ${s??""}`,children:e.jsx(G.ErrorMessage,{error:c.message})}):e.jsxs("div",{className:`cedros-system-settings ${s??""}`,children:[e.jsxs("div",{className:"cedros-settings-page-header",children:[e.jsxs("div",{className:"cedros-settings-page-header-content",children:[e.jsx("h2",{className:"cedros-settings-page-title",children:"Auth Messages"}),e.jsx("p",{className:"cedros-settings-page-description",children:"Configure email delivery for verification emails, password resets, and instant link login. Webhook notifications can be sent to Discord or Slack."})]}),e.jsx(xe.AutosaveStatus,{status:r,error:n})]}),p==="email"&&!A&&e.jsx("div",{className:"cedros-settings-warning-banner",children:"Email features (verification, password reset, instant link) are disabled until SMTP is configured. Select a provider or enter custom SMTP settings below."}),e.jsx("div",{className:"cedros-admin-tabs cedros-admin-tabs--line",children:pt.map(k=>e.jsx("button",{type:"button",className:`cedros-admin-tab ${p===k.id?"cedros-admin-tab-active":""}`,onClick:()=>f(k.id),"aria-selected":p===k.id,role:"tab",children:k.label},k.id))}),e.jsx("div",{className:"cedros-admin-tab-content",role:"tabpanel",children:b.length===0?e.jsx("div",{className:"cedros-system-settings-empty",children:e.jsxs("p",{children:["No settings found for ",g?.label??"this section","."]})}):e.jsx(xe.SettingsSection,{settings:b,edits:o,onChange:p==="email"?v:d})})]})}const ae={users: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:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),members: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:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),deposits: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:"M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8"}),e.jsx("path",{d:"M12 18V6"})]}),withdrawals: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:"16",height:"20",x:"4",y:"2",rx:"2",ry:"2"}),e.jsx("path",{d:"M9 22v-4h6v4"}),e.jsx("path",{d:"M8 6h.01"}),e.jsx("path",{d:"M16 6h.01"}),e.jsx("path",{d:"M12 6h.01"}),e.jsx("path",{d:"M12 10h.01"}),e.jsx("path",{d:"M12 14h.01"}),e.jsx("path",{d:"M16 10h.01"}),e.jsx("path",{d:"M16 14h.01"}),e.jsx("path",{d:"M8 10h.01"}),e.jsx("path",{d:"M8 14h.01"})]}),wallet: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"})]}),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"})}),key: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:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"})}),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"})]}),coins: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:"8",cy:"8",r:"6"}),e.jsx("path",{d:"M18.09 10.37A6 6 0 1 1 10.34 18"}),e.jsx("path",{d:"M7 6h1v4"}),e.jsx("path",{d:"m16.71 13.88.7.71-2.82 2.82"})]}),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"})]})},wn=[{id:"users",label:"Users",icon:ae.users},{id:"team",label:"Team",icon:ae.members},{id:"deposits",label:"Deposits",icon:ae.deposits,requiredFeature:"credits"},{id:"withdrawals",label:"Withdrawals",icon:ae.withdrawals,requiredFeature:"credits"},{id:"settings-auth",label:"Authentication",icon:ae.key,group:"Configuration"},{id:"settings-messaging",label:"Auth Messages",icon:ae.mail,group:"Configuration"},{id:"settings-wallet",label:"User Wallets",icon:ae.wallet,group:"Configuration"},{id:"settings-credits",label:"Credit System",icon:ae.coins,group:"Configuration",requiredFeature:"credits"},{id:"settings-server",label:"Auth Server",icon:ae.server,group:"Configuration"}];function yn({title:s="Dashboard",sections:t=["users","team","deposits","withdrawals","settings-wallet","settings-auth","settings-messaging","settings-credits","settings-server"],defaultSection:o="users",refreshInterval:a=0,pageSize:r=20,onSectionChange:n,onSettingsClick:c,onLogoutClick:i,className:d=""}){const[h,p]=l.useState(o),[f,g]=l.useState(!0),{user:w,logout:m}=T.useCedrosLogin(),{activeOrg:u,role:y,isLoading:A,fetchOrgs:b,hasPermission:v}=_s.useOrgs(),{status:k,isLoading:S,checkStatus:x}=Qs(),{features:j,isLoading:C}=te.useServerFeatures(),{canAccess:N}=te.useDashboardPermissions(),P=l.useCallback(D=>{p(D),n?.(D)},[n]),L=wn.filter(D=>!(!t.includes(D.id)||D.requiredFeature&&!j[D.requiredFeature]||!N(D.id))),E=L.find(D=>D.id===h),M=!E&&!C;return l.useEffect(()=>{b(),x()},[b,x]),l.useEffect(()=>{M&&L.length>0&&p("users")},[M,L.length]),!S&&k?.needsSetup?e.jsx("div",{className:`cedros-admin cedros-dashboard cedros-dashboard--setup ${d}`,children:e.jsx(jr,{onComplete:()=>x()})}):(A||S||C)&&!u?e.jsxs("div",{className:`cedros-admin cedros-dashboard cedros-dashboard--loading ${d}`,children:[e.jsx(V.LoadingSpinner,{}),e.jsx("span",{className:"cedros-dashboard__loading-text",children:"Loading..."})]}):h==="team"&&!u?e.jsx("div",{className:`cedros-admin cedros-dashboard ${d}`,children:e.jsx(G.ErrorMessage,{error:"No organization selected. Please select an organization first."})}):e.jsxs("div",{className:`cedros-admin cedros-dashboard ${d}`,children:[e.jsxs("aside",{className:"cedros-dashboard__sidebar",children:[e.jsx("div",{className:"cedros-dashboard__sidebar-header",children:e.jsxs("div",{className:"cedros-dashboard__logo",children:[ae.wallet,e.jsx("span",{className:"cedros-dashboard__logo-text",children:s})]})}),e.jsxs("nav",{className:"cedros-dashboard__nav",children:[e.jsxs("div",{className:"cedros-dashboard__nav-group",children:[e.jsx("span",{className:"cedros-dashboard__nav-label",children:"Menu"}),L.filter(D=>!D.group).map(D=>e.jsxs("button",{type:"button",className:`cedros-dashboard__nav-item ${h===D.id?"cedros-dashboard__nav-item--active":""}`,onClick:()=>P(D.id),"aria-current":h===D.id?"page":void 0,children:[e.jsx("span",{className:"cedros-dashboard__nav-icon",children:D.icon}),e.jsx("span",{className:"cedros-dashboard__nav-text",children:D.label})]},D.id))]}),L.some(D=>D.group==="Configuration")&&e.jsxs("div",{className:"cedros-dashboard__nav-group",children:[e.jsxs("button",{type:"button",className:"cedros-dashboard__nav-label cedros-dashboard__nav-label--collapsible",onClick:()=>g(!f),"aria-expanded":f,children:[e.jsx("span",{children:"Configuration"}),e.jsx("span",{className:`cedros-dashboard__nav-chevron ${f?"cedros-dashboard__nav-chevron--expanded":""}`,children:ae.chevronRight})]}),f&&L.filter(D=>D.group==="Configuration").map(D=>e.jsxs("button",{type:"button",className:`cedros-dashboard__nav-item ${h===D.id?"cedros-dashboard__nav-item--active":""}`,onClick:()=>P(D.id),"aria-current":h===D.id?"page":void 0,children:[e.jsx("span",{className:"cedros-dashboard__nav-icon",children:D.icon}),e.jsx("span",{className:"cedros-dashboard__nav-text",children:D.label})]},D.id))]})]}),w&&e.jsx("div",{className:"cedros-dashboard__sidebar-footer",children:e.jsx(ge.ProfileDropdown,{name:w.name,email:w.email,picture:w.picture,onSettings:c,onLogout:i??m})})]}),e.jsxs("main",{className:"cedros-dashboard__main",children:[e.jsx("header",{className:"cedros-dashboard__header",children:e.jsxs("div",{className:"cedros-dashboard__breadcrumb",children:[e.jsx("span",{className:"cedros-dashboard__breadcrumb-root",children:s}),e.jsx("span",{className:"cedros-dashboard__breadcrumb-sep",children:ae.chevronRight}),e.jsx("span",{className:"cedros-dashboard__breadcrumb-current",children:E?.label})]})}),e.jsxs("div",{className:"cedros-dashboard__content",children:[h==="users"&&e.jsx(bn,{pageSize:r,currentUserId:w?.id}),h==="team"&&u&&e.jsx(An,{orgId:u.id,currentUserId:w?.id,hasPermission:v,role:y}),h==="deposits"&&e.jsx(xn,{pageSize:r,refreshInterval:a}),h==="withdrawals"&&e.jsx(vn,{pageSize:r,refreshInterval:a}),h==="settings-auth"&&e.jsx("div",{className:"cedros-dashboard__section",children:e.jsx(Qt.AuthenticationSettings,{})}),h==="settings-wallet"&&e.jsx("div",{className:"cedros-dashboard__section",children:e.jsx(Kt.EmbeddedWalletSettings,{})}),h==="settings-messaging"&&e.jsx("div",{className:"cedros-dashboard__section",children:e.jsx(gn,{})}),h==="settings-credits"&&e.jsx("div",{className:"cedros-dashboard__section",children:e.jsx(Os.CreditSystemSettings,{})}),h==="settings-server"&&e.jsx("div",{className:"cedros-dashboard__section",children:e.jsx(Yt.ServerSettings,{})})]})]})]})}function bn({pageSize:s,currentUserId:t}){const[o,a]=l.useState(null),{statsItems:r,isLoading:n,error:c,refresh:i}=Pe.useUsersStatsSummary();return o?e.jsx("div",{className:"cedros-dashboard__section",children:e.jsx(Pe.AdminUserDetail,{userId:o.id,currentUserId:t,onBack:()=>a(null)})}):e.jsxs("div",{className:"cedros-dashboard__section",children:[e.jsx(Ht.StatsBar,{stats:r,isLoading:n,onRefresh:i}),c&&e.jsx("p",{className:"cedros-admin-error-inline",children:c}),e.jsx(Pe.AdminUserList,{pageSize:s,currentUserId:t,onUserClick:d=>a(d)})]})}function An({orgId:s,currentUserId:t,hasPermission:o,role:a}){const[r,n]=l.useState("members"),{members:c,isLoading:i,error:d,fetchMembers:h,updateMemberRole:p,removeMember:f}=te.useMembers(s),{invites:g,isLoading:w,error:m,fetchInvites:u,createInvite:y,cancelInvite:A,resendInvite:b}=te.useInvites(s);l.useEffect(()=>{h(),u()},[h,u]);const v=o("invite:create"),k=o("invite:cancel"),S=g.length,x=c.reduce((P,L)=>(P[L.role]=(P[L.role]??0)+1,P),{}),j=x.owner??0,C=x.admin??0,N=x.member??0;return e.jsxs("div",{className:"cedros-dashboard__team",children:[e.jsx(Ht.StatsBar,{stats:[{label:"Owners",value:j},{label:"Admins",value:C},{label:"Members",value:N},{label:"Pending Invites",value:S}]}),e.jsxs("div",{className:"cedros-admin-tabs cedros-admin-tabs--line",children:[e.jsx("button",{type:"button",className:`cedros-admin-tab ${r==="members"?"cedros-admin-tab-active":""}`,onClick:()=>n("members"),"aria-selected":r==="members",role:"tab",children:"Members"}),e.jsxs("button",{type:"button",className:`cedros-admin-tab ${r==="invites"?"cedros-admin-tab-active":""}`,onClick:()=>n("invites"),"aria-selected":r==="invites",role:"tab",children:["Pending Invites",S>0&&` (${S})`]}),a==="owner"&&e.jsx("button",{type:"button",className:`cedros-admin-tab ${r==="permissions"?"cedros-admin-tab-active":""}`,onClick:()=>n("permissions"),"aria-selected":r==="permissions",role:"tab",children:"Permissions"})]}),e.jsxs("div",{className:"cedros-admin-tab-content",role:"tabpanel",children:[r==="members"&&e.jsx(te.MemberList,{members:c,currentUserId:t,isLoading:i,error:d?.message,canManage:o("member:remove"),canChangeRoles:o("member:role_change"),onUpdateRole:p,onRemove:f}),r==="invites"&&e.jsxs("div",{className:"cedros-dashboard__invites",children:[v&&e.jsxs("div",{className:"cedros-dashboard__section",children:[e.jsx("div",{className:"cedros-dashboard__section-header",children:e.jsx("h3",{className:"cedros-dashboard__section-title",children:"Send Invitation"})}),e.jsx(te.InviteForm,{onSubmit:y,isLoading:w,error:m?.message})]}),e.jsx("div",{className:"cedros-dashboard__section",children:e.jsx(te.InviteList,{invites:g,isLoading:w,error:m?.message,canManage:k||v,onCancel:k?A:void 0,onResend:v?b:void 0})})]}),r==="permissions"&&a==="owner"&&e.jsx(te.PermissionsSection,{userRole:a})]})]})}function xn({pageSize:s,refreshInterval:t}){const[o,a]=l.useState("");return e.jsxs("div",{className:"cedros-dashboard__deposits",children:[e.jsx(ze.AdminDepositStats,{refreshInterval:t}),e.jsxs("div",{className:"cedros-dashboard__deposits-list",children:[e.jsx("div",{className:"cedros-dashboard__toolbar",children:e.jsxs("div",{className:"cedros-dashboard__filter",children:[e.jsx("label",{className:"cedros-dashboard__filter-label",htmlFor:"status-filter",children:"Status"}),e.jsxs("select",{id:"status-filter",className:"cedros-dashboard__select",value:o,onChange:r=>a(r.target.value),children:[e.jsx("option",{value:"",children:"All statuses"}),e.jsx("option",{value:"pending",children:"Pending"}),e.jsx("option",{value:"detected",children:"Detected"}),e.jsx("option",{value:"processing",children:"Processing"}),e.jsx("option",{value:"completed",children:"Completed"}),e.jsx("option",{value:"withdrawn",children:"Withdrawn"}),e.jsx("option",{value:"expired",children:"Expired"}),e.jsx("option",{value:"failed",children:"Failed"})]})]})}),e.jsx(ze.AdminDepositList,{statusFilter:o||void 0,pageSize:s,refreshInterval:t})]})]})}function vn({pageSize:s,refreshInterval:t}){return e.jsxs("div",{className:"cedros-dashboard__withdrawals",children:[e.jsx(fe.AdminWithdrawalStats,{refreshInterval:t}),e.jsx("p",{className:"cedros-dashboard__text-muted",children:"Track deposits through the withdrawal pipeline: privacy period, ready for processing, and completed."}),e.jsxs("div",{className:"cedros-dashboard__pipeline",children:[e.jsx(fe.AdminPrivacyPeriodDeposits,{pageSize:s,refreshInterval:t}),e.jsx(fe.AdminWithdrawalQueue,{pageSize:s,refreshInterval:t}),e.jsx(fe.AdminWithdrawalHistory,{pageSize:s,refreshInterval:t})]})]})}var Ae={},cs,mt;function jn(){return mt||(mt=1,cs=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),cs}var ds={},me={},ft;function we(){if(ft)return me;ft=1;let s;const t=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return me.getSymbolSize=function(a){if(!a)throw new Error('"version" cannot be null or undefined');if(a<1||a>40)throw new Error('"version" should be in range from 1 to 40');return a*4+17},me.getSymbolTotalCodewords=function(a){return t[a]},me.getBCHDigit=function(o){let a=0;for(;o!==0;)a++,o>>>=1;return a},me.setToSJISFunction=function(a){if(typeof a!="function")throw new Error('"toSJISFunc" is not a valid function.');s=a},me.isKanjiModeEnabled=function(){return typeof s<"u"},me.toSJIS=function(a){return s(a)},me}var us={},gt;function Ks(){return gt||(gt=1,(function(s){s.L={bit:1},s.M={bit:0},s.Q={bit:3},s.H={bit:2};function t(o){if(typeof o!="string")throw new Error("Param is not a string");switch(o.toLowerCase()){case"l":case"low":return s.L;case"m":case"medium":return s.M;case"q":case"quartile":return s.Q;case"h":case"high":return s.H;default:throw new Error("Unknown EC Level: "+o)}}s.isValid=function(a){return a&&typeof a.bit<"u"&&a.bit>=0&&a.bit<4},s.from=function(a,r){if(s.isValid(a))return a;try{return t(a)}catch{return r}}})(us)),us}var hs,wt;function kn(){if(wt)return hs;wt=1;function s(){this.buffer=[],this.length=0}return s.prototype={get:function(t){const o=Math.floor(t/8);return(this.buffer[o]>>>7-t%8&1)===1},put:function(t,o){for(let a=0;a<o;a++)this.putBit((t>>>o-a-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(t){const o=Math.floor(this.length/8);this.buffer.length<=o&&this.buffer.push(0),t&&(this.buffer[o]|=128>>>this.length%8),this.length++}},hs=s,hs}var ps,yt;function Nn(){if(yt)return ps;yt=1;function s(t){if(!t||t<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=t,this.data=new Uint8Array(t*t),this.reservedBit=new Uint8Array(t*t)}return s.prototype.set=function(t,o,a,r){const n=t*this.size+o;this.data[n]=a,r&&(this.reservedBit[n]=!0)},s.prototype.get=function(t,o){return this.data[t*this.size+o]},s.prototype.xor=function(t,o,a){this.data[t*this.size+o]^=a},s.prototype.isReserved=function(t,o){return this.reservedBit[t*this.size+o]},ps=s,ps}var ms={},bt;function Cn(){return bt||(bt=1,(function(s){const t=we().getSymbolSize;s.getRowColCoords=function(a){if(a===1)return[];const r=Math.floor(a/7)+2,n=t(a),c=n===145?26:Math.ceil((n-13)/(2*r-2))*2,i=[n-7];for(let d=1;d<r-1;d++)i[d]=i[d-1]-c;return i.push(6),i.reverse()},s.getPositions=function(a){const r=[],n=s.getRowColCoords(a),c=n.length;for(let i=0;i<c;i++)for(let d=0;d<c;d++)i===0&&d===0||i===0&&d===c-1||i===c-1&&d===0||r.push([n[i],n[d]]);return r}})(ms)),ms}var fs={},At;function Sn(){if(At)return fs;At=1;const s=we().getSymbolSize,t=7;return fs.getPositions=function(a){const r=s(a);return[[0,0],[r-t,0],[0,r-t]]},fs}var gs={},xt;function En(){return xt||(xt=1,(function(s){s.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const t={N1:3,N2:3,N3:40,N4:10};s.isValid=function(r){return r!=null&&r!==""&&!isNaN(r)&&r>=0&&r<=7},s.from=function(r){return s.isValid(r)?parseInt(r,10):void 0},s.getPenaltyN1=function(r){const n=r.size;let c=0,i=0,d=0,h=null,p=null;for(let f=0;f<n;f++){i=d=0,h=p=null;for(let g=0;g<n;g++){let w=r.get(f,g);w===h?i++:(i>=5&&(c+=t.N1+(i-5)),h=w,i=1),w=r.get(g,f),w===p?d++:(d>=5&&(c+=t.N1+(d-5)),p=w,d=1)}i>=5&&(c+=t.N1+(i-5)),d>=5&&(c+=t.N1+(d-5))}return c},s.getPenaltyN2=function(r){const n=r.size;let c=0;for(let i=0;i<n-1;i++)for(let d=0;d<n-1;d++){const h=r.get(i,d)+r.get(i,d+1)+r.get(i+1,d)+r.get(i+1,d+1);(h===4||h===0)&&c++}return c*t.N2},s.getPenaltyN3=function(r){const n=r.size;let c=0,i=0,d=0;for(let h=0;h<n;h++){i=d=0;for(let p=0;p<n;p++)i=i<<1&2047|r.get(h,p),p>=10&&(i===1488||i===93)&&c++,d=d<<1&2047|r.get(p,h),p>=10&&(d===1488||d===93)&&c++}return c*t.N3},s.getPenaltyN4=function(r){let n=0;const c=r.data.length;for(let d=0;d<c;d++)n+=r.data[d];return Math.abs(Math.ceil(n*100/c/5)-10)*t.N4};function o(a,r,n){switch(a){case s.Patterns.PATTERN000:return(r+n)%2===0;case s.Patterns.PATTERN001:return r%2===0;case s.Patterns.PATTERN010:return n%3===0;case s.Patterns.PATTERN011:return(r+n)%3===0;case s.Patterns.PATTERN100:return(Math.floor(r/2)+Math.floor(n/3))%2===0;case s.Patterns.PATTERN101:return r*n%2+r*n%3===0;case s.Patterns.PATTERN110:return(r*n%2+r*n%3)%2===0;case s.Patterns.PATTERN111:return(r*n%3+(r+n)%2)%2===0;default:throw new Error("bad maskPattern:"+a)}}s.applyMask=function(r,n){const c=n.size;for(let i=0;i<c;i++)for(let d=0;d<c;d++)n.isReserved(d,i)||n.xor(d,i,o(r,d,i))},s.getBestMask=function(r,n){const c=Object.keys(s.Patterns).length;let i=0,d=1/0;for(let h=0;h<c;h++){n(h),s.applyMask(h,r);const p=s.getPenaltyN1(r)+s.getPenaltyN2(r)+s.getPenaltyN3(r)+s.getPenaltyN4(r);s.applyMask(h,r),p<d&&(d=p,i=h)}return i}})(gs)),gs}var We={},vt;function kr(){if(vt)return We;vt=1;const s=Ks(),t=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],o=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return We.getBlocksCount=function(r,n){switch(n){case s.L:return t[(r-1)*4+0];case s.M:return t[(r-1)*4+1];case s.Q:return t[(r-1)*4+2];case s.H:return t[(r-1)*4+3];default:return}},We.getTotalCodewordsCount=function(r,n){switch(n){case s.L:return o[(r-1)*4+0];case s.M:return o[(r-1)*4+1];case s.Q:return o[(r-1)*4+2];case s.H:return o[(r-1)*4+3];default:return}},We}var ws={},Le={},jt;function Ln(){if(jt)return Le;jt=1;const s=new Uint8Array(512),t=new Uint8Array(256);return(function(){let a=1;for(let r=0;r<255;r++)s[r]=a,t[a]=r,a<<=1,a&256&&(a^=285);for(let r=255;r<512;r++)s[r]=s[r-255]})(),Le.log=function(a){if(a<1)throw new Error("log("+a+")");return t[a]},Le.exp=function(a){return s[a]},Le.mul=function(a,r){return a===0||r===0?0:s[t[a]+t[r]]},Le}var kt;function Pn(){return kt||(kt=1,(function(s){const t=Ln();s.mul=function(a,r){const n=new Uint8Array(a.length+r.length-1);for(let c=0;c<a.length;c++)for(let i=0;i<r.length;i++)n[c+i]^=t.mul(a[c],r[i]);return n},s.mod=function(a,r){let n=new Uint8Array(a);for(;n.length-r.length>=0;){const c=n[0];for(let d=0;d<r.length;d++)n[d]^=t.mul(r[d],c);let i=0;for(;i<n.length&&n[i]===0;)i++;n=n.slice(i)}return n},s.generateECPolynomial=function(a){let r=new Uint8Array([1]);for(let n=0;n<a;n++)r=s.mul(r,new Uint8Array([1,t.exp(n)]));return r}})(ws)),ws}var ys,Nt;function Mn(){if(Nt)return ys;Nt=1;const s=Pn();function t(o){this.genPoly=void 0,this.degree=o,this.degree&&this.initialize(this.degree)}return t.prototype.initialize=function(a){this.degree=a,this.genPoly=s.generateECPolynomial(this.degree)},t.prototype.encode=function(a){if(!this.genPoly)throw new Error("Encoder not initialized");const r=new Uint8Array(a.length+this.degree);r.set(a);const n=s.mod(r,this.genPoly),c=this.degree-n.length;if(c>0){const i=new Uint8Array(this.degree);return i.set(n,c),i}return n},ys=t,ys}var bs={},As={},xs={},Ct;function Nr(){return Ct||(Ct=1,xs.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40}),xs}var de={},St;function Cr(){if(St)return de;St=1;const s="[0-9]+",t="[A-Z $%*+\\-./:]+";let o="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";o=o.replace(/u/g,"\\u");const a="(?:(?![A-Z0-9 $%*+\\-./:]|"+o+`)(?:.|[\r
2049
+ `),oe=12;function co(s){if(s.length!==16)throw new Error(`Invalid share length: expected 16, got ${s.length}`);const o=er(s,he).split(" ");if(o.length!==oe)throw new Error(`Unexpected word count: expected ${oe}, got ${o.length}`);return o}function uo(s){if(s.length!==oe)throw new Error(`Invalid word count: expected ${oe}, got ${s.length}`);const t=s.join(" ").toLowerCase().trim();if(!Vs(t,he))throw new Error("Invalid recovery phrase: checksum mismatch");const o=zs(t,he);if(o.length!==16)throw new Error(`Invalid entropy length: expected 16, got ${o.length}`);return I.toShamirShare(o)}function ho(s){if(s.length!==16)throw new Error(`Invalid seed length: expected 16, got ${s.length}`);const o=er(s,he).split(" ");if(o.length!==oe)throw new Error(`Unexpected word count: expected ${oe}, got ${o.length}`);return o}function po(s){if(s.length!==oe)throw new Error(`Invalid word count: expected ${oe}, got ${s.length}`);const t=s.join(" ").toLowerCase().trim();if(!Vs(t,he))throw new Error("Invalid recovery phrase: checksum mismatch");const o=zs(t,he);if(o.length!==16)throw new Error(`Invalid entropy length: expected 16, got ${o.length}`);return I.toSeed(o)}function sr(s){if(s.length!==oe)return!1;const t=s.join(" ").toLowerCase().trim();return Vs(t,he)}function Ue(s){return he.includes(s.toLowerCase().trim())}function mo(s,t=5){const o=s.toLowerCase().trim();return o.length===0?[]:he.filter(a=>a.startsWith(o)).slice(0,t)}function fo(s){const t=[];for(let o=0;o<s.length;o+=4)t.push(s.slice(o,o+4));return t}function go(s){return s.toLowerCase().replace(/[,\n\r\t]+/g," ").split(/\s+/).map(t=>t.trim()).filter(t=>t.length>0)}function wo({className:s="",variant:t="default",size:o="md",children:a,menuItems:r=[],hideSignOut:n=!1}){const{user:c,isAuthenticated:i,isLoading:d,openLoginModal:h,logout:p}=I.useAuth(),[f,g]=l.useState(!1),[w,m]=l.useState(-1),u=l.useRef(null),y=l.useRef(null),A=l.useMemo(()=>[...r,...n?[]:[{label:"Sign out",onClick:p}]],[r,n,p]);l.useEffect(()=>{if(!f)return;const x=C=>{u.current&&!u.current.contains(C.target)&&(g(!1),m(-1))},j=C=>{C.key==="Escape"&&(g(!1),m(-1),y.current?.focus())};return document.addEventListener("mousedown",x),document.addEventListener("keydown",j),()=>{document.removeEventListener("mousedown",x),document.removeEventListener("keydown",j)}},[f]);const b=l.useCallback(x=>{if(!(!f||A.length===0))switch(x.key){case"ArrowDown":x.preventDefault(),m(j=>(j+1)%A.length);break;case"ArrowUp":x.preventDefault(),m(j=>(j-1+A.length)%A.length);break;case"Home":x.preventDefault(),m(0);break;case"End":x.preventDefault(),m(A.length-1);break;case"Enter":case" ":w>=0&&(x.preventDefault(),A[w].onClick(),g(!1),m(-1));break}},[f,w,A]),v=l.useCallback(()=>{A.length!==0&&(g(x=>!x),m(-1))},[A.length]),k={sm:"cedros-button-sm",md:"cedros-button-md",lg:"cedros-button-lg"},S={default:"cedros-button-primary",outline:"cedros-button-outline",ghost:"cedros-button-ghost"};if(d)return e.jsx("button",{type:"button",className:`cedros-button ${S[t]} ${k[o]} ${s}`,disabled:!0,children:e.jsx(V.LoadingSpinner,{size:"sm"})});if(i&&c){const x=c.name||c.email||"User",j=Us.sanitizeImageUrl(c.picture);return e.jsxs("div",{className:"cedros-user-menu",ref:u,onKeyDown:b,children:[e.jsxs("button",{ref:y,type:"button",className:`cedros-button cedros-user-button ${k[o]} ${s}`,"aria-haspopup":"menu","aria-expanded":f,"aria-label":`User menu for ${x}`,onClick:v,children:[j?e.jsx("img",{src:j,alt:x,className:"cedros-user-avatar",referrerPolicy:"no-referrer",crossOrigin:"anonymous"}):e.jsx("div",{className:"cedros-user-avatar-placeholder",children:(x[0]||"?").toUpperCase()}),e.jsx("span",{className:"cedros-user-name",children:x})]}),f&&e.jsxs("div",{className:"cedros-dropdown cedros-dropdown-open",role:"menu",children:[r.map((C,N)=>e.jsxs("button",{type:"button",className:`cedros-dropdown-item ${w===N?"cedros-dropdown-item-focused":""}`,role:"menuitem",tabIndex:w===N?0:-1,onClick:()=>{C.onClick(),g(!1)},children:[C.icon&&e.jsx("span",{className:"cedros-dropdown-icon",children:C.icon}),C.label]},N)),r.length>0&&!n&&e.jsx("div",{className:"cedros-dropdown-divider",role:"separator"}),!n&&e.jsx("button",{type:"button",className:`cedros-dropdown-item cedros-dropdown-item-danger ${w===r.length?"cedros-dropdown-item-focused":""}`,role:"menuitem",tabIndex:w===r.length?0:-1,onClick:()=>{p(),g(!1)},children:"Sign out"})]})]})}return e.jsx("button",{type:"button",className:`cedros-button ${S[t]} ${k[o]} ${s}`,onClick:h,children:a||"Sign in"})}function Hs(){const{config:s}=T.useCedrosLogin(),[t,o]=l.useState(!1),[a,r]=l.useState(!1),[n,c]=l.useState(null),i=l.useMemo(()=>new T.ApiClient({baseUrl:s.serverUrl,timeoutMs:s.requestTimeout,retryAttempts:s.retryAttempts}),[s.serverUrl,s.requestTimeout,s.retryAttempts]),{checkLimit:d,getRemainingAttempts:h}=K.useRateLimiter({maxAttempts:3,windowMs:3e5}),p=l.useCallback(async m=>{if(!Me.validateEmail(m)){const u={code:"VALIDATION_ERROR",message:"Please enter a valid email address"};throw c(u),u}try{d()}catch(u){const y={code:"RATE_LIMITED",message:u instanceof Error?u.message:"Too many attempts"};throw c(y),y}o(!0),c(null),r(!1);try{await i.post("/forgot-password",{email:m}),r(!0)}catch(u){const y=T.handleApiError(u,"Failed to send reset email");throw c(y),y}finally{o(!1)}},[i,d]),f=l.useCallback(async(m,u)=>{o(!0),c(null),r(!1);try{await i.post("/reset-password",{token:m,newPassword:u}),r(!0)}catch(y){const A=T.handleApiError(y,"Failed to reset password");throw c(A),A}finally{o(!1)}},[i]),g=l.useCallback(()=>c(null),[]),w=l.useCallback(()=>{c(null),r(!1),o(!1)},[]);return{forgotPassword:p,resetPassword:f,isLoading:t,isSuccess:a,error:n,clearError:g,reset:w,remainingAttempts:h()}}function tr({onSuccess:s,onCancel:t,className:o=""}){const[a,r]=l.useState(""),{forgotPassword:n,isLoading:c,isSuccess:i,error:d,clearError:h}=Hs(),p=l.useId(),f=async g=>{g.preventDefault();try{await n(a),s?.()}catch{}};return i?e.jsxs("div",{className:`cedros-forgot-password-success ${o}`,children:[e.jsxs("svg",{className:"cedros-success-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"22",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M14 24l7 7 13-13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),e.jsx("h3",{className:"cedros-success-title",children:"Check your email"}),e.jsxs("p",{className:"cedros-success-message",children:["If an account exists for ",e.jsx("strong",{children:a}),", you will receive a password reset link shortly."]}),t&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-md cedros-button-outline",onClick:t,children:"Back to login"})]}):e.jsxs("form",{className:`cedros-forgot-password-form ${o}`,onSubmit:f,children:[e.jsxs("div",{className:"cedros-form-header",children:[e.jsx("h3",{className:"cedros-form-title",children:"Forgot password?"}),e.jsx("p",{className:"cedros-form-subtitle",children:"Enter your email address and we'll send you a link to reset your password."})]}),e.jsx(G.ErrorMessage,{error:d,onDismiss:h}),e.jsxs("div",{className:"cedros-form-field",children:[e.jsx("label",{htmlFor:p,className:"cedros-label",children:"Email address"}),e.jsx("input",{id:p,type:"email",className:"cedros-input",value:a,onChange:g=>r(g.target.value),placeholder:"you@example.com",required:!0,autoComplete:"email",disabled:c})]}),e.jsxs("div",{className:"cedros-form-actions",children:[e.jsx("button",{type:"submit",className:"cedros-button cedros-button-md cedros-button-primary cedros-button-full",disabled:c||!a,children:c?e.jsxs(e.Fragment,{children:[e.jsx(V.LoadingSpinner,{size:"sm"}),"Sending..."]}):"Send reset link"}),t&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-md cedros-button-ghost cedros-button-full",onClick:t,disabled:c,children:"Back to login"})]})]})}const yo={loading:!1,loaded:!1,error:null,callbacks:[],load(){return typeof window>"u"||typeof document>"u"?Promise.reject(new Error("Apple Sign-In script loader cannot run in SSR")):this.loaded?Promise.resolve():this.loading?new Promise((s,t)=>{this.callbacks.push({resolve:s,reject:t})}):(this.loading=!0,new Promise((s,t)=>{this.callbacks.push({resolve:s,reject:t});const o=document.getElementById("apple-signin-script");if(o){window.AppleID?(this.loaded=!0,this.loading=!1,this.callbacks.forEach(r=>r.resolve()),this.callbacks=[]):o.addEventListener("load",()=>{this.loaded=!0,this.loading=!1,this.callbacks.forEach(r=>r.resolve()),this.callbacks=[]});return}const a=document.createElement("script");a.src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js",a.async=!0,a.defer=!0,a.id="apple-signin-script",a.onload=()=>{this.loaded=!0,this.loading=!1,this.callbacks.forEach(r=>r.resolve()),this.callbacks=[]},a.onerror=()=>{this.loading=!1,a.remove();const r=new Error("Failed to load Apple Sign In script");this.callbacks.forEach(n=>n.reject(r)),this.callbacks=[]},document.head.appendChild(a)}))},_reset(){this.loading=!1,this.loaded=!1,this.error=null,this.callbacks=[]}};function rr(){const{config:s,_internal:t}=T.useCedrosLogin(),[o,a]=l.useState(!1),[r,n]=l.useState(!1),[c,i]=l.useState(null),[d,h]=l.useState(null),p=l.useRef(s),f=l.useMemo(()=>new T.ApiClient({baseUrl:s.serverUrl,timeoutMs:s.requestTimeout,retryAttempts:s.retryAttempts}),[s.serverUrl,s.requestTimeout,s.retryAttempts]);l.useEffect(()=>{p.current=s},[s]),l.useEffect(()=>{if(!s.appleClientId)return;let u=!0;const y=()=>{if(u)try{window.AppleID?.auth?.init({clientId:s.appleClientId,scope:"name email",redirectURI:window.location.origin,usePopup:!0}),u&&n(!0)}catch{u&&i({code:"SERVER_ERROR",message:"Failed to initialize Apple Sign In"})}};return yo.load().then(()=>{u&&y()}).catch(()=>{u&&i({code:"SERVER_ERROR",message:"Failed to load Apple Sign In"})}),()=>{u=!1}},[s.appleClientId]);const g=l.useCallback(async()=>{if(!s.appleClientId){const y={code:"VALIDATION_ERROR",message:"Apple Client ID not configured"};throw i(y),y}if(!r){const y={code:"VALIDATION_ERROR",message:"Apple Sign In not initialized"};throw i(y),y}a(!0),i(null);let u;try{const y=await window.AppleID.auth.signIn();if(u=y.authorization?.id_token,!u)throw new Error("No ID token received from Apple");const A=y.user?.name?`${y.user.name.firstName||""} ${y.user.name.lastName||""}`.trim():void 0,b=await f.post("/apple",{idToken:u,name:A||void 0});return p.current.callbacks?.onLoginSuccess?.(b.user,"apple"),t?.handleLoginSuccess(b.user,b.tokens),a(!1),b}catch(y){if(y.error==="popup_closed_by_user"){const v={code:"SERVER_ERROR",message:"Apple Sign In was cancelled"};throw i(v),a(!1),v}const b=T.handleApiError(y,"Apple sign-in failed");throw b.code==="ACCOUNT_LINK_REQUIRED"&&u&&h(u),i(b),a(!1),b}},[s.appleClientId,r,f,t]),w=l.useCallback(()=>i(null),[]),m=l.useCallback(()=>h(null),[]);return{signIn:g,isLoading:o,isInitialized:r,error:c,clearError:w,pendingLinkIdToken:d,clearPendingLink:m}}function or(){if(typeof window>"u"||typeof navigator>"u")return!1;const s=navigator.userAgent.toLowerCase(),t=(navigator.platform||"").toLowerCase();return!!(/iphone|ipad|ipod/.test(s)||t.includes("mac")||/macintosh/.test(s)||t==="macintel"&&navigator.maxTouchPoints>1)}function nr({onSuccess:s,onError:t,className:o="",variant:a="default",size:r="md",disabled:n=!1,hideOnNonApple:c=!0}){const{signIn:i,isLoading:d,isInitialized:h}=rr(),[p]=l.useState(()=>or());if(c&&!p)return null;const f=async()=>{try{await i(),s?.()}catch(m){const u=m instanceof Error?m:new Error(String(m));t?.(u)}},g={sm:"cedros-button-sm",md:"cedros-button-md",lg:"cedros-button-lg"},w={default:"cedros-button-social",outline:"cedros-button-social-outline"};return e.jsxs("button",{type:"button",className:`cedros-button ${w[a]} ${g[r]} ${o}`,onClick:f,disabled:n||!h||d,"aria-label":"Sign in with Apple",children:[d?e.jsx(V.LoadingSpinner,{size:"sm"}):e.jsx("svg",{className:"cedros-button-icon",width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M18.71 19.5c-.83 1.24-1.71 2.45-3.05 2.47-1.34.03-1.77-.79-3.29-.79-1.53 0-2 .77-3.27.82-1.31.05-2.3-1.32-3.14-2.53C4.25 17 2.94 12.45 4.7 9.39c.87-1.52 2.43-2.48 4.12-2.51 1.28-.02 2.5.87 3.29.87.78 0 2.26-1.07 3.81-.91.65.03 2.47.26 3.64 1.98-.09.06-2.17 1.28-2.15 3.81.03 3.02 2.65 4.03 2.68 4.04-.03.07-.42 1.44-1.38 2.83M13 3.5c.73-.83 1.94-1.46 2.94-1.5.13 1.17-.34 2.35-1.04 3.19-.69.85-1.83 1.51-2.95 1.42-.15-1.15.41-2.35 1.05-3.11z"})}),e.jsx("span",{children:"Continue with Apple"})]})}function Z(s,t){if(!s)throw new Error(t)}function bo(s){return s.replace(/-/g,"+").replace(/_/g,"/")}function Ge(s){Z(typeof s=="string"&&s.length>0,"Expected base64url string");const t=bo(s),o=t+"=".repeat((4-t.length%4)%4),a=atob(o),r=new Uint8Array(a.length);for(let n=0;n<a.length;n++)r[n]=a.charCodeAt(n);return r.buffer}function be(s){const t=new Uint8Array(s);let o="";for(let r=0;r<t.length;r++)o+=String.fromCharCode(t[r]);return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,"")}function ar(s){Z(typeof s=="object"&&s!==null,"Invalid credential descriptor");const t=s;return Z(typeof t.type=="string","Invalid credential descriptor type"),Z(typeof t.id=="string","Invalid credential descriptor id"),{type:t.type,id:Ge(t.id),transports:Array.isArray(t.transports)?t.transports:void 0}}function ls(s){Z(s&&typeof s=="object","Missing creation options");const t=s.publicKey;Z(t&&typeof t=="object","Missing creation options.publicKey"),Z(typeof t.challenge=="string","Missing creation challenge"),Z(typeof t.rp=="object"&&t.rp!==null,"Missing rp"),Z(typeof t.user=="object"&&t.user!==null,"Missing user");const o=t.rp,a=t.user;Z(typeof o.name=="string","Missing rp.name"),Z(typeof a.id=="string","Missing user.id"),Z(typeof a.name=="string","Missing user.name"),Z(typeof a.displayName=="string","Missing user.displayName");const r=Array.isArray(t.excludeCredentials)?t.excludeCredentials.map(ar):void 0,n=Array.isArray(t.pubKeyCredParams)?t.pubKeyCredParams.map(i=>({type:i.type,alg:i.alg})):[],c={challenge:Ge(t.challenge),rp:{name:o.name,id:typeof o.id=="string"?o.id:void 0},user:{id:Ge(a.id),name:a.name,displayName:a.displayName},pubKeyCredParams:n,timeout:typeof t.timeout=="number"?t.timeout:void 0,attestation:typeof t.attestation=="string"?t.attestation:void 0,authenticatorSelection:typeof t.authenticatorSelection=="object"&&t.authenticatorSelection!==null?t.authenticatorSelection:void 0,excludeCredentials:r,extensions:typeof t.extensions=="object"&&t.extensions!==null?t.extensions:void 0};return c.hints=["client-device"],c}function it(s){Z(s&&typeof s=="object","Missing request options");const t=s.publicKey;Z(t&&typeof t=="object","Missing request options.publicKey"),Z(typeof t.challenge=="string","Missing request challenge");const o=Array.isArray(t.allowCredentials)?t.allowCredentials.map(ar):void 0,a={challenge:Ge(t.challenge),rpId:typeof t.rpId=="string"?t.rpId:void 0,timeout:typeof t.timeout=="number"?t.timeout:void 0,userVerification:typeof t.userVerification=="string"?t.userVerification:void 0,allowCredentials:o,extensions:typeof t.extensions=="object"&&t.extensions!==null?t.extensions:void 0};return a.hints=["client-device"],a}function Ce(s){const t=be(s.rawId),o=s.response,r={...{clientDataJSON:be(o.clientDataJSON)}};if("attestationObject"in o){const n=o;if(r.attestationObject=be(n.attestationObject),typeof n.getTransports=="function")try{r.transports=n.getTransports()}catch{}}if("authenticatorData"in o){const n=o;r.authenticatorData=be(n.authenticatorData),r.signature=be(n.signature),n.userHandle&&(r.userHandle=be(n.userHandle))}return{id:s.id,rawId:t,type:s.type,authenticatorAttachment:s.authenticatorAttachment??void 0,clientExtensionResults:s.getClientExtensionResults?.()??{},response:r}}function Ao(){if(typeof window<"u"){const s=window.location?.hostname,t=s==="localhost"||s==="127.0.0.1"||s?.endsWith(".localhost");if(!(window.isSecureContext===!0)&&!t)return!1}return typeof window<"u"&&typeof window.PublicKeyCredential<"u"&&typeof navigator<"u"&&typeof navigator.credentials<"u"}function Se(s){if(!(s instanceof Error))return null;const t=s.name;return t==="NotAllowedError"?{code:"SERVER_ERROR",message:"Passkey operation was cancelled or timed out"}:t==="InvalidStateError"?{code:"VALIDATION_ERROR",message:"Passkey is not available for this operation"}:t==="SecurityError"?{code:"VALIDATION_ERROR",message:"Passkeys require HTTPS and a correctly configured relying party (WEBAUTHN_RP_ID / WEBAUTHN_RP_ORIGIN)"}:null}function ir(){const{config:s,_internal:t}=T.useCedrosLogin(),[o,a]=l.useState(!1),[r,n]=l.useState(null),c=l.useMemo(()=>new T.ApiClient({baseUrl:s.serverUrl,timeoutMs:s.requestTimeout,retryAttempts:s.retryAttempts,getAccessToken:t?.getAccessToken}),[t?.getAccessToken,s.serverUrl,s.requestTimeout,s.retryAttempts]),i=l.useCallback(()=>n(null),[]),d=Ao(),h=l.useCallback(async w=>{if(!d){const m={code:"VALIDATION_ERROR",message:"Passkeys are not supported in this browser"};throw n(m),m}a(!0),n(null);try{const m=await c.post("/webauthn/auth/options",{email:w?.email}),u=it(m.options),y=await navigator.credentials.get({publicKey:u});if(!y)throw new Error("Passkey authentication returned no credential");const A=await c.post("/webauthn/auth/verify",{challengeId:m.challengeId,credential:Ce(y)});return s.callbacks?.onLoginSuccess?.(A.user,"webauthn"),t?.handleLoginSuccess(A.user,A.tokens),A}catch(m){const y=Se(m)??T.handleApiError(m,"Passkey sign-in failed");throw n(y),y}finally{a(!1)}},[c,s.callbacks,t,d]),p=l.useCallback(async w=>{if(!d){const m={code:"VALIDATION_ERROR",message:"Passkeys are not supported in this browser"};throw n(m),m}a(!0),n(null);try{const m=await c.post("/webauthn/register/options",{}),u=ls(m.options),y=await navigator.credentials.create({publicKey:u});if(!y)throw new Error("Passkey registration returned no credential");const A=await c.post("/webauthn/register/verify",{challengeId:m.challengeId,credential:Ce(y),label:w?.label});if(!A.success)throw new Error("Passkey registration failed");return{credentialId:A.credentialId,label:A.label}}catch(m){const y=Se(m)??T.handleApiError(m,"Passkey registration failed");throw n(y),y}finally{a(!1)}},[c,d]),f=l.useCallback(async w=>{if(!d){const m={code:"VALIDATION_ERROR",message:"Passkeys are not supported in this browser"};throw n(m),m}a(!0),n(null);try{const m=await c.post("/webauthn/signup/options",{}),u=ls(m.options),y=await navigator.credentials.create({publicKey:u});if(!y)throw new Error("Passkey signup returned no credential");const A=await c.post("/webauthn/signup/verify",{challengeId:m.challengeId,credential:Ce(y),email:w?.email,name:w?.name,label:w?.label});return s.callbacks?.onLoginSuccess?.(A.user,"webauthn"),t?.handleLoginSuccess(A.user,A.tokens),A}catch(m){const y=Se(m)??T.handleApiError(m,"Passkey sign-up failed");throw n(y),y}finally{a(!1)}},[c,s.callbacks,t,d]),g=l.useCallback(async()=>{if(!d){const w={code:"VALIDATION_ERROR",message:"Passkeys are not supported in this browser"};throw n(w),w}a(!0),n(null);try{const w=await c.post("/webauthn/signup/options",{}),m=ls(w.options),u=await navigator.credentials.create({publicKey:m});if(!u)throw new Error("Passkey signup returned no credential");const y=await c.post("/webauthn/signup/verify",{challengeId:w.challengeId,credential:Ce(u)});return s.callbacks?.onLoginSuccess?.(y.user,"webauthn"),t?.handleLoginSuccess(y.user,y.tokens),y}catch(w){if(w instanceof Error&&w.name==="InvalidStateError")try{const y=await c.post("/webauthn/auth/options",{}),A=it(y.options),b=await navigator.credentials.get({publicKey:A});if(!b)throw new Error("Passkey authentication returned no credential");const v=await c.post("/webauthn/auth/verify",{challengeId:y.challengeId,credential:Ce(b)});return s.callbacks?.onLoginSuccess?.(v.user,"webauthn"),t?.handleLoginSuccess(v.user,v.tokens),v}catch(y){const b=Se(y)??T.handleApiError(y,"Passkey sign-in failed");throw n(b),b}const u=Se(w)??T.handleApiError(w,"Passkey sign-up failed");throw n(u),u}finally{a(!1)}},[c,s.callbacks,t,d]);return{isSupported:d,isLoading:o,error:r,clearError:i,continueWithPasskey:g,authenticatePasskey:h,registerPasskey:p,signupWithPasskey:f}}function lr({onSuccess:s,className:t="",children:o,disabled:a}){const{continueWithPasskey:r,isLoading:n,isSupported:c}=ir(),i=a||!c||n,d=n?"Continuing...":"Continue with Passkey";return e.jsxs("button",{type:"button",className:`cedros-button cedros-button-social ${t}`,onClick:async()=>{await r(),s?.()},disabled:i,"aria-disabled":i,children:[e.jsx("span",{className:"cedros-social-icon","aria-hidden":"true",children:e.jsx(xo,{})}),e.jsx("span",{children:o??d})]})}function xo(){return e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4"}),e.jsx("path",{d:"M14 13.12c0 2.38 0 6.38-1 8.88"}),e.jsx("path",{d:"M17.29 21.02c.12-.6.43-2.3.5-3.02"}),e.jsx("path",{d:"M2 12a10 10 0 0 1 18-6"}),e.jsx("path",{d:"M2 16h.01"}),e.jsx("path",{d:"M21.8 16c.2-2 .131-5.354 0-6"}),e.jsx("path",{d:"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2"}),e.jsx("path",{d:"M8.65 22c.21-.66.45-1.32.57-2"}),e.jsx("path",{d:"M9 6.8a6 6 0 0 1 9 5.2v2"})]})}const vo=["phantom","solflare","backpack","glow","slope","sollet","coin98","clover","mathWallet","ledger","torus","walletconnect"];function lt(s){if(!s||typeof s!="object")return!1;const t=s;return typeof t.connect=="function"||typeof t.signMessage=="function"||typeof t.signTransaction=="function"||"isConnected"in t}function jo(){try{const s=window.__wallet_standard__;if(s&&typeof s=="object"&&"get"in s&&typeof s.get=="function"){const t=s.get();return Array.isArray(t)&&t.length>0}}catch{}return!1}function ct(){if(typeof window>"u")return!1;const s=window;for(const t of vo){const o=s[t];if(o&&typeof o=="object"&&"solana"in o&&lt(o.solana))return!0}return!!(lt(s.solana)||jo())}const Ee=["login","register"];function Ze({onSuccess:s,className:t="",defaultTab:o="login"}){const{config:a}=T.useCedrosLogin(),[r,n]=l.useState(o),[c,i]=l.useState("form"),[d,h]=l.useState(()=>ct()),[p]=l.useState(()=>or()),[f,g]=l.useState(!1);l.useEffect(()=>{const x=()=>h(ct());return x(),window.addEventListener("load",x),window.addEventListener("focus",x),()=>{window.removeEventListener("load",x),window.removeEventListener("focus",x)}},[]);const w=a.forms?.forgotPassword?.mode??(a.features?.instantLink?"instantLink":"reset"),m=l.useCallback(x=>{const j=Ee.indexOf(r);let C=j;switch(x.key){case"ArrowLeft":case"ArrowUp":C=j===0?Ee.length-1:j-1;break;case"ArrowRight":case"ArrowDown":C=j===Ee.length-1?0:j+1;break;case"Home":C=0;break;case"End":C=Ee.length-1;break;default:return}x.preventDefault();const N=Ee[C];n(N),document.getElementById(`cedros-tab-${N}`)?.focus()},[r]),u=a.features??{email:!0,google:!0,apple:!0,solana:!0,webauthn:!0},y=u.email!==!1,A=u.google!==!1&&a.googleClientId,b=u.apple!==!1&&a.appleClientId&&p,v=u.solana!==!1&&d,k=u.webauthn!==!1,S=y&&(A||b||v||k);return c==="forgotPassword"?e.jsx("div",{className:`cedros-login-form ${t}`,children:e.jsx(tr,{onCancel:()=>i("form")})}):e.jsxs("div",{className:`cedros-login-form ${f?"cedros-login-form--connecting":""} ${t}`,children:[(k||A||b||v)&&e.jsxs("div",{className:"cedros-social-buttons",children:[k&&e.jsx(lr,{onSuccess:s}),A&&e.jsx(Ws.GoogleLoginButton,{onSuccess:s}),b&&e.jsx(nr,{onSuccess:s}),v&&e.jsxs(e.Fragment,{children:[e.jsx(Xe.SolanaLoginButton,{onSuccess:s,onLoadingChange:g}),f&&e.jsx("p",{className:"cedros-solana-status",children:"Connecting to Solana wallet…"})]})]}),S&&e.jsx("div",{className:"cedros-divider",children:e.jsx("span",{children:"Or continue with"})}),y&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-tabs",role:"tablist","aria-label":"Authentication method",children:[e.jsx("button",{type:"button",role:"tab",id:"cedros-tab-login",className:`cedros-tab ${r==="login"?"cedros-tab-active":""}`,onClick:()=>n("login"),onKeyDown:m,"aria-selected":r==="login","aria-controls":"cedros-tabpanel-login",tabIndex:r==="login"?0:-1,children:"Sign in"}),e.jsx("button",{type:"button",role:"tab",id:"cedros-tab-register",className:`cedros-tab ${r==="register"?"cedros-tab-active":""}`,onClick:()=>n("register"),onKeyDown:m,"aria-selected":r==="register","aria-controls":"cedros-tabpanel-register",tabIndex:r==="register"?0:-1,children:"Sign up"})]}),e.jsx("div",{role:"tabpanel",id:`cedros-tabpanel-${r}`,"aria-labelledby":`cedros-tab-${r}`,children:r==="login"?e.jsx(K.EmailLoginForm,{onSuccess:s,onSwitchToRegister:()=>n("register"),onForgotPassword:w==="reset"?()=>i("forgotPassword"):void 0}):e.jsx(K.EmailRegisterForm,{onSuccess:s,onSwitchToLogin:()=>n("login")})})]})]})}class cr extends l.Component{constructor(t){super(t),this.state={hasError:!1,error:null,errorInfo:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,o){this.setState({errorInfo:o}),console.error("[Cedros Login] Error caught by ErrorBoundary:",t),console.error("[Cedros Login] Component stack:",o.componentStack),this.props.onError?.(t,o)}handleRetry=()=>{this.setState({hasError:!1,error:null,errorInfo:null})};render(){const{hasError:t,error:o,errorInfo:a}=this.state,{children:r,fallback:n,showDetails:c=!1}=this.props;return t?n||e.jsx("div",{className:"cedros-error-boundary",role:"alert","aria-live":"assertive",children:e.jsxs("div",{className:"cedros-error-boundary-content",children:[e.jsxs("svg",{className:"cedros-error-boundary-icon",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),e.jsx("h2",{className:"cedros-error-boundary-title",children:"Something went wrong"}),e.jsx("p",{className:"cedros-error-boundary-message",children:"We encountered an unexpected error. Please try again."}),c&&o&&e.jsxs("details",{className:"cedros-error-boundary-details",children:[e.jsx("summary",{children:"Error details"}),e.jsxs("pre",{children:[o.toString(),a?.componentStack]})]}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:this.handleRetry,children:"Try again"})]})}):r}}function ko({className:s="",title:t="Sign in to your account"}){const{isModalOpen:o,closeModal:a}=T.useCedrosLogin(),r=l.useRef(null),n=l.useRef(null),c=l.useRef(a);if(l.useEffect(()=>{c.current=a},[a]),l.useEffect(()=>{if(!o)return;n.current=document.activeElement,r.current?.focus();const d=p=>{if(p.key==="Escape"&&c.current(),p.key==="Tab"&&r.current){const f=r.current.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'),g=f[0],w=f[f.length-1];p.shiftKey&&document.activeElement===g?(p.preventDefault(),w?.focus()):!p.shiftKey&&document.activeElement===w&&(p.preventDefault(),g?.focus())}};document.addEventListener("keydown",d);const h=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",d),document.body.style.overflow=h,n.current instanceof HTMLElement&&n.current.focus()}},[o]),!o)return null;const i=d=>{d.target===d.currentTarget&&a()};return e.jsx("div",{className:`cedros-modal-backdrop ${s}`,onClick:i,role:"presentation",children:e.jsxs("div",{ref:r,className:"cedros-modal",role:"dialog","aria-modal":"true","aria-labelledby":"cedros-modal-title",tabIndex:-1,children:[e.jsxs("div",{className:"cedros-modal-header",children:[e.jsx("h2",{id:"cedros-modal-title",className:"cedros-modal-title",children:t}),e.jsx("button",{type:"button",className:"cedros-modal-close",onClick:a,"aria-label":"Close",children:e.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})})]}),e.jsx("div",{className:"cedros-modal-content",children:e.jsx(cr,{children:e.jsx(Ze,{onSuccess:a})})})]})})}function No({token:s,onSuccess:t,onLoginClick:o,className:a=""}){const[r,n]=l.useState(""),[c,i]=l.useState(""),[d,h]=l.useState(null),{resetPassword:p,isLoading:f,isSuccess:g,error:w,clearError:m}=Hs(),u=r===c,y=d?.isValid&&u&&r.length>0,A=async b=>{if(b.preventDefault(),!!y)try{await p(s,r),t?.()}catch{}};return g?e.jsxs("div",{className:`cedros-reset-password-success ${a}`,children:[e.jsxs("svg",{className:"cedros-success-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"22",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M14 24l7 7 13-13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),e.jsx("h3",{className:"cedros-success-title",children:"Password reset successful"}),e.jsx("p",{className:"cedros-success-message",children:"Your password has been reset. You can now log in with your new password."}),o&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-md cedros-button-primary",onClick:o,children:"Go to login"})]}):e.jsxs("form",{className:`cedros-reset-password-form ${a}`,onSubmit:A,children:[e.jsxs("div",{className:"cedros-form-header",children:[e.jsx("h3",{className:"cedros-form-title",children:"Reset your password"}),e.jsx("p",{className:"cedros-form-subtitle",children:"Enter your new password below."})]}),e.jsx(G.ErrorMessage,{error:w,onDismiss:m}),e.jsx("div",{className:"cedros-form-field",children:e.jsx(K.PasswordInput,{label:"New password",value:r,onChange:b=>{n(b.target.value),h(Me.validatePassword(b.target.value))},showStrengthMeter:!0,onValidationChange:h,disabled:f,autoComplete:"new-password",error:d&&!d.isValid?Object.values(d.errors).find(Boolean):void 0})}),e.jsx("div",{className:"cedros-form-field",children:e.jsx(K.PasswordInput,{label:"Confirm password",value:c,onChange:b=>i(b.target.value),disabled:f,autoComplete:"new-password",error:c&&!u?"Passwords do not match":void 0})}),e.jsxs("div",{className:"cedros-form-actions",children:[e.jsx("button",{type:"submit",className:"cedros-button cedros-button-md cedros-button-primary cedros-button-full",disabled:f||!y,children:f?e.jsxs(e.Fragment,{children:[e.jsx(V.LoadingSpinner,{size:"sm"}),"Resetting..."]}):"Reset password"}),o&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-md cedros-button-ghost cedros-button-full",onClick:o,disabled:f,children:"Back to login"})]})]})}function Fs({org:s,size:t="lg",className:o=""}){const a=Us.sanitizeImageUrl(s.logoUrl),r=t==="lg"?"cedros-org-avatar-lg":"",n=["cedros-org-avatar",r,o].filter(Boolean).join(" "),c=["cedros-org-avatar-placeholder",r,o].filter(Boolean).join(" ");return a?e.jsx("img",{src:a,alt:s.name,className:n,referrerPolicy:"no-referrer"}):e.jsx("div",{className:c,children:s.name[0]?.toUpperCase()||"?"})}function Co({orgs:s,activeOrg:t,isLoading:o=!1,onSelect:a,onCreateClick:r,className:n="",placeholder:c="Select organization"}){const[i,d]=l.useState(!1),h=l.useRef(null);l.useEffect(()=>{const w=m=>{h.current&&!h.current.contains(m.target)&&d(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[]),l.useEffect(()=>{const w=m=>{m.key==="Escape"&&d(!1)};if(i)return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[i]);const p=l.useCallback(w=>{a(w),d(!1)},[a]),f=l.useCallback(()=>{d(!1),r?.()},[r]),g=l.useCallback(()=>{d(w=>!w)},[]);return o?e.jsxs("div",{className:`cedros-org-selector cedros-org-selector-loading ${n}`,"aria-busy":"true","aria-live":"polite",children:[e.jsx(V.LoadingSpinner,{size:"sm"}),e.jsx("span",{children:"Loading..."})]}):e.jsxs("div",{ref:h,className:`cedros-org-selector ${n}`,children:[e.jsxs("button",{type:"button",className:"cedros-org-selector-trigger",onClick:g,"aria-haspopup":"listbox","aria-expanded":i,children:[t?e.jsxs(e.Fragment,{children:[e.jsx(Fs,{org:t,size:"sm"}),e.jsx("span",{className:"cedros-org-selector-name",children:t.name}),e.jsx(dt,{role:t.membership.role})]}):e.jsx("span",{className:"cedros-org-selector-placeholder",children:c}),e.jsx(So,{isOpen:i})]}),i&&e.jsxs("div",{className:"cedros-org-selector-dropdown",role:"listbox",children:[s.length===0?e.jsx("div",{className:"cedros-org-selector-empty",children:"No organizations"}):e.jsx("ul",{className:"cedros-org-selector-list",children:s.map(w=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:`cedros-org-selector-item ${w.id===t?.id?"cedros-org-selector-item-active":""}`,onClick:()=>p(w.id),role:"option","aria-selected":w.id===t?.id,children:[e.jsx(Fs,{org:w,size:"sm"}),e.jsx("span",{className:"cedros-org-selector-item-name",children:w.name}),e.jsx(dt,{role:w.membership.role}),w.id===t?.id&&e.jsx(Eo,{})]})},w.id))}),r&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"cedros-org-selector-divider"}),e.jsxs("button",{type:"button",className:"cedros-org-selector-create",onClick:f,children:[e.jsx(Lo,{}),e.jsx("span",{children:"Create organization"})]})]})]})]})}function dt({role:s}){return e.jsx("span",{className:`cedros-org-role cedros-org-role-${s}`,children:s})}function So({isOpen:s}){return e.jsx("svg",{className:`cedros-org-chevron ${s?"cedros-org-chevron-open":""}`,width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function Eo(){return e.jsx("svg",{className:"cedros-org-check",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M3 8L6 11L13 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function Lo(){return e.jsx("svg",{className:"cedros-org-plus",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M8 3V13M3 8H13",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function Po(){return e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function Mo(){return e.jsx("svg",{className:"cedros-org-check",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M4 10L8 14L16 5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function To(){return e.jsx("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M10 4V16M4 10H16",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function Bo({orgs:s,activeOrg:t,isLoading:o,onSelect:a,onCreateClick:r}){return o?e.jsxs("div",{className:"cedros-org-switcher-loading",children:[e.jsx(V.LoadingSpinner,{}),e.jsx("span",{children:"Loading organizations..."})]}):e.jsxs(e.Fragment,{children:[s.length===0?e.jsx("div",{className:"cedros-org-switcher-empty",children:e.jsx("p",{children:"You don't belong to any organizations yet."})}):e.jsx("ul",{className:"cedros-org-switcher-list",children:s.map(n=>e.jsx("li",{children:e.jsxs("button",{type:"button",className:`cedros-org-switcher-item ${n.id===t?.id?"cedros-org-switcher-item-active":""}`,onClick:()=>a(n.id),children:[e.jsx(Fs,{org:n}),e.jsxs("div",{className:"cedros-org-switcher-item-content",children:[e.jsx("span",{className:"cedros-org-switcher-item-name",children:n.name}),e.jsxs("span",{className:"cedros-org-switcher-item-slug",children:["@",n.slug]})]}),e.jsxs("div",{className:"cedros-org-switcher-item-meta",children:[e.jsx("span",{className:`cedros-org-role cedros-org-role-${n.membership.role}`,children:n.membership.role}),n.isPersonal&&e.jsx("span",{className:"cedros-org-personal-badge",children:"Personal"})]}),n.id===t?.id&&e.jsx(Mo,{})]})},n.id))}),r&&e.jsxs("button",{type:"button",className:"cedros-org-switcher-create",onClick:r,children:[e.jsx(To,{}),e.jsx("span",{children:"Create new organization"})]})]})}function Ro({isLoading:s,onSubmit:t,onCancel:o}){const[a,r]=l.useState(""),[n,c]=l.useState(""),[i,d]=l.useState(null),h=l.useCallback(f=>{r(f);const g=f.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"").substring(0,50);c(g)},[]),p=l.useCallback(async f=>{if(f.preventDefault(),d(null),!a.trim()){d("Organization name is required");return}if(!n.trim()){d("Organization slug is required");return}try{await t({name:a.trim(),slug:n.trim()})}catch(g){d(g.message||"Failed to create organization")}},[a,n,t]);return e.jsxs("form",{className:"cedros-org-create-form",onSubmit:p,children:[i&&e.jsx(G.ErrorMessage,{error:i}),e.jsxs("div",{className:"cedros-form-group",children:[e.jsx("label",{htmlFor:"org-name",className:"cedros-form-label",children:"Organization Name"}),e.jsx("input",{id:"org-name",type:"text",className:"cedros-form-input",value:a,onChange:f=>h(f.target.value),placeholder:"My Organization",maxLength:255,disabled:s,autoFocus:!0})]}),e.jsxs("div",{className:"cedros-form-group",children:[e.jsx("label",{htmlFor:"org-slug",className:"cedros-form-label",children:"URL Slug"}),e.jsxs("div",{className:"cedros-form-input-prefix",children:[e.jsx("span",{className:"cedros-form-prefix",children:"@"}),e.jsx("input",{id:"org-slug",type:"text",className:"cedros-form-input",value:n,onChange:f=>c(f.target.value.toLowerCase()),placeholder:"my-organization",maxLength:100,pattern:"[a-z0-9-]+",disabled:s})]}),e.jsx("span",{className:"cedros-form-hint",children:"Only lowercase letters, numbers, and hyphens"})]}),e.jsxs("div",{className:"cedros-form-actions",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline",onClick:o,disabled:s,children:"Cancel"}),e.jsx("button",{type:"submit",className:"cedros-button cedros-button-primary",disabled:s||!a.trim()||!n.trim(),children:s?e.jsx(V.LoadingSpinner,{size:"sm"}):"Create Organization"})]})]})}function Do({isOpen:s,onClose:t,orgs:o,activeOrg:a,isLoading:r=!1,error:n,onSelect:c,onCreate:i,className:d=""}){return s?e.jsx(Io,{onClose:t,orgs:o,activeOrg:a,isLoading:r,error:n,onSelect:c,onCreate:i,className:d}):null}function Io({onClose:s,orgs:t,activeOrg:o,isLoading:a=!1,error:r,onSelect:n,onCreate:c,className:i}){const[d,h]=l.useState("list"),p=l.useRef(null),f=l.useRef(null);l.useEffect(()=>(f.current=document.activeElement,p.current?.querySelector(".cedros-modal-close")?.focus(),()=>{f.current?.focus()}),[]),l.useEffect(()=>{const u=y=>{if(y.key==="Escape"){s();return}if(y.key==="Tab"&&p.current){const A=p.current.querySelectorAll('button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'),b=A[0],v=A[A.length-1];y.shiftKey?document.activeElement===b&&(y.preventDefault(),v?.focus()):document.activeElement===v&&(y.preventDefault(),b?.focus())}};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[s]);const g=l.useCallback(u=>{u.target===u.currentTarget&&s()},[s]),w=l.useCallback(u=>{n(u),s()},[n,s]),m=l.useCallback(async u=>{await c?.(u),s()},[c,s]);return e.jsx("div",{className:"cedros-modal-backdrop",onClick:g,children:e.jsxs("div",{ref:p,className:`cedros-modal cedros-org-switcher ${i}`,role:"dialog","aria-modal":"true","aria-labelledby":"org-switcher-title",children:[e.jsxs("div",{className:"cedros-modal-header",children:[e.jsx("h2",{id:"org-switcher-title",className:"cedros-modal-title",children:d==="list"?"Switch Organization":"Create Organization"}),e.jsx("button",{type:"button",className:"cedros-modal-close",onClick:s,"aria-label":"Close",children:e.jsx(Po,{})})]}),e.jsxs("div",{className:"cedros-modal-body",children:[r&&e.jsx(G.ErrorMessage,{error:r}),d==="list"?e.jsx(Bo,{orgs:t,activeOrg:o,isLoading:a,onSelect:w,onCreateClick:c?()=>h("create"):void 0}):e.jsx(Ro,{isLoading:a,onSubmit:m,onCancel:()=>h("list")})]})]})})}function Fo({sessions:s,isLoading:t=!1,error:o,onRevokeAll:a,className:r=""}){const[n,c]=l.useState(!1),[i,d]=l.useState(!1),h=l.useRef(null),p=l.useMemo(()=>s.filter(g=>!g.isCurrent).length,[s]),f=l.useCallback(async()=>{if(!a)return;const g=s.filter(m=>!m.isCurrent).length;if(!(g===0||!window.confirm(`Are you sure you want to sign out of ${g} other device(s)? This will log you out everywhere except this browser.`))){c(!0),d(!1);try{await a(),d(!0),h.current!==null&&window.clearTimeout(h.current),h.current=window.setTimeout(()=>{d(!1),h.current=null},3e3)}finally{c(!1)}}},[a,s]);return l.useEffect(()=>()=>{h.current!==null&&(window.clearTimeout(h.current),h.current=null)},[]),t&&s.length===0?e.jsxs("div",{className:`cedros-session-list cedros-session-list-loading ${r}`,children:[e.jsx(V.LoadingSpinner,{}),e.jsx("span",{children:"Loading sessions..."})]}):o?e.jsx("div",{className:`cedros-session-list ${r}`,children:e.jsx(G.ErrorMessage,{error:o})}):s.length===0?e.jsx("div",{className:`cedros-session-list cedros-session-list-empty ${r}`,children:e.jsx("p",{children:"No active sessions found."})}):e.jsxs("div",{className:`cedros-session-list ${r}`,children:[i&&e.jsxs("div",{className:"cedros-session-success",role:"status",children:[e.jsx(zo,{}),e.jsx("span",{children:"All other sessions have been revoked."})]}),e.jsx("ul",{className:"cedros-session-items",children:s.map(g=>e.jsx(Uo,{session:g},g.id))}),a&&p>0&&e.jsx("div",{className:"cedros-session-actions",children:e.jsx("button",{type:"button",className:"cedros-button cedros-button-danger",onClick:f,disabled:n,children:n?e.jsxs(e.Fragment,{children:[e.jsx(V.LoadingSpinner,{size:"sm"}),e.jsx("span",{children:"Signing out..."})]}):`Sign out of ${p} other device${p>1?"s":""}`})})]})}function Uo({session:s}){const t=Wo(s.userAgent),o=Oo(s.expiresAt);return e.jsxs("li",{className:`cedros-session-item ${s.isCurrent?"cedros-session-item-current":""}`,children:[e.jsx("div",{className:"cedros-session-item-icon",children:e.jsx(qo,{userAgent:s.userAgent})}),e.jsxs("div",{className:"cedros-session-item-info",children:[e.jsxs("div",{className:"cedros-session-item-main",children:[e.jsxs("span",{className:"cedros-session-item-device",children:[t.browser," on ",t.os]}),s.isCurrent&&e.jsx("span",{className:"cedros-session-current-badge",children:"Current session"})]}),e.jsxs("div",{className:"cedros-session-item-meta",children:[s.ipAddress&&e.jsxs("span",{className:"cedros-session-item-ip",children:["IP: ",s.ipAddress]}),e.jsxs("span",{className:"cedros-session-item-created",children:["Started ",_o(s.createdAt)]}),o&&e.jsx("span",{className:"cedros-session-expiring",children:"Expires soon"})]})]})]})}function Wo(s){if(!s)return{browser:"Unknown browser",os:"Unknown device"};let t="Unknown browser";s.includes("Chrome")&&!s.includes("Edg")?t="Chrome":s.includes("Safari")&&!s.includes("Chrome")?t="Safari":s.includes("Firefox")?t="Firefox":s.includes("Edg")&&(t="Edge");let o="Unknown device";return s.includes("Windows")?o="Windows":s.includes("Mac")?o="macOS":s.includes("Linux")?o="Linux":s.includes("iPhone")||s.includes("iPad")?o="iOS":s.includes("Android")&&(o="Android"),{browser:t,os:o}}function _o(s){const t=new Date(s),a=new Date().getTime()-t.getTime(),r=Math.floor(a/(1e3*60)),n=Math.floor(a/(1e3*60*60)),c=Math.floor(a/(1e3*60*60*24));return r<1?"just now":r<60?`${r} minute${r>1?"s":""} ago`:n<24?`${n} hour${n>1?"s":""} ago`:c<7?`${c} day${c>1?"s":""} ago`:t.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function Oo(s){const t=new Date(s),o=new Date,a=3600*1e3;return t.getTime()-o.getTime()<a}function qo({userAgent:s}){return s?.includes("iPhone")||s?.includes("iPad")||s?.includes("Android")?e.jsxs("svg",{className:"cedros-session-device-icon",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("rect",{x:"5",y:"2",width:"14",height:"20",rx:"2",stroke:"currentColor",strokeWidth:"1.5"}),e.jsx("circle",{cx:"12",cy:"18",r:"1",fill:"currentColor"})]}):e.jsxs("svg",{className:"cedros-session-device-icon",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("rect",{x:"2",y:"4",width:"20",height:"14",rx:"2",stroke:"currentColor",strokeWidth:"1.5"}),e.jsx("path",{d:"M8 21H16",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"}),e.jsx("path",{d:"M12 18V21",stroke:"currentColor",strokeWidth:"1.5"})]})}function zo(){return e.jsx("svg",{className:"cedros-session-check",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M3 8L6 11L13 5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}function dr({words:s,onConfirm:t,className:o=""}){const[a,r]=l.useState(!1),[n,c]=l.useState(!1),i=l.useRef(null),d=fo(s),h=l.useCallback(async()=>{try{await navigator.clipboard.writeText(s.join(" ")),r(!0),i.current!==null&&window.clearTimeout(i.current),i.current=window.setTimeout(()=>r(!1),2e3)}catch{}},[s]);l.useEffect(()=>()=>{i.current!==null&&(window.clearTimeout(i.current),i.current=null)},[]);const p=l.useCallback(()=>{n&&t()},[n,t]);return e.jsxs("div",{className:`cedros-recovery-phrase-display ${o}`,children:[e.jsxs("div",{className:"cedros-recovery-header",children:[e.jsx("h3",{className:"cedros-recovery-title",children:"Recovery Phrase"}),e.jsx("p",{className:"cedros-recovery-warning",children:"Write down these 12 words in order and store them securely. This is the only way to recover your wallet if you lose access."})]}),e.jsx("div",{className:"cedros-recovery-grid",children:d.map((f,g)=>e.jsx("div",{className:"cedros-word-group",children:f.map((w,m)=>{const u=g*4+m+1;return e.jsxs("div",{className:"cedros-word-item",children:[e.jsxs("span",{className:"cedros-word-number",children:[u,"."]}),e.jsx("span",{className:"cedros-word-text",children:w})]},u)})},g))}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary cedros-copy-btn",onClick:h,children:a?"Copied!":"Copy to Clipboard"}),e.jsx("div",{className:"cedros-recovery-security",children:e.jsxs("div",{className:"cedros-warning-box",children:[e.jsx("svg",{className:"cedros-warning-icon",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M10 6v4m0 4h.01M19 10a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})}),e.jsxs("div",{className:"cedros-warning-content",children:[e.jsx("strong",{children:"Security Warning"}),e.jsxs("ul",{children:[e.jsx("li",{children:"Never share this phrase with anyone"}),e.jsx("li",{children:"Store it offline in a secure location"}),e.jsx("li",{children:"Anyone with this phrase can access your wallet"}),e.jsx("li",{children:"Cedros cannot recover this phrase for you"})]})]})]})}),e.jsxs("div",{className:"cedros-recovery-confirm",children:[e.jsxs("label",{className:"cedros-checkbox-label",children:[e.jsx("input",{type:"checkbox",checked:n,onChange:f=>c(f.target.checked),className:"cedros-checkbox"}),e.jsx("span",{children:"I have written down and securely stored my recovery phrase"})]}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:p,disabled:!n,children:"Continue"})]})]})}function ur({onSubmit:s,onCancel:t,isSubmitting:o=!1,error:a,className:r=""}){const[n,c]=l.useState(Array(oe).fill("")),[i,d]=l.useState(null),[h,p]=l.useState([]),[f,g]=l.useState(null),w=l.useId(),m=l.useRef(null),u=l.useCallback((x,j)=>{const C=[...n];if(C[x]=j.toLowerCase().trim(),c(C),j.length>0){const N=mo(j,5);p(N)}else p([]);g(null)},[n]),y=l.useCallback(x=>{d(x),p([])},[]),A=l.useCallback(x=>{const j=n[x];j&&!Ue(j)&&g(`Word ${x+1} is not in the wordlist`),m.current!==null&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{i===x&&p([])},200)},[n,i]);l.useEffect(()=>()=>{m.current!==null&&(window.clearTimeout(m.current),m.current=null)},[]);const b=l.useCallback(x=>{if(i!==null){const j=[...n];j[i]=x,c(j),p([]),document.querySelector(`[data-word-index="${i+1}"]`)?.focus()}},[i,n]),v=l.useCallback(x=>{const j=x.clipboardData.getData("text"),C=go(j);C.length===oe&&(x.preventDefault(),c(C),g(null))},[]),k=l.useCallback(x=>{if(x.preventDefault(),n.filter(N=>!N).length>0){g(`Please enter all ${oe} words`);return}const C=n.map((N,P)=>({word:N,index:P+1})).filter(({word:N})=>!Ue(N));if(C.length>0){g(`Invalid words: ${C.map(N=>`#${N.index}`).join(", ")}`);return}if(!sr(n)){g("Invalid recovery phrase - please check your words");return}s(n)},[n,s]),S=a||f;return e.jsxs("form",{className:`cedros-recovery-phrase-input ${r}`,onSubmit:k,onPaste:v,children:[e.jsxs("div",{className:"cedros-recovery-input-header",children:[e.jsx("h3",{className:"cedros-recovery-input-title",children:"Enter Recovery Phrase"}),e.jsx("p",{className:"cedros-recovery-input-description",children:"Enter your 12-word recovery phrase. You can paste the entire phrase at once."})]}),e.jsx("div",{className:"cedros-word-inputs",children:Array.from({length:oe},(x,j)=>e.jsxs("div",{className:"cedros-word-input-wrapper",children:[e.jsxs("label",{className:"cedros-word-label",children:[j+1,"."]}),e.jsx("input",{type:"text",className:`cedros-word-input ${n[j]&&!Ue(n[j])?"cedros-word-invalid":n[j]&&Ue(n[j])?"cedros-word-valid":""}`,value:n[j],onChange:C=>u(j,C.target.value),onFocus:()=>y(j),onBlur:()=>A(j),"data-word-index":j,autoComplete:"off",autoCapitalize:"none",spellCheck:!1,disabled:o,"aria-label":`Word ${j+1}`})]},j))}),i!==null&&h.length>0&&e.jsx("div",{className:"cedros-suggestions",role:"listbox",id:`${w}-suggestions`,children:h.map(x=>e.jsx("button",{type:"button",className:"cedros-suggestion",onClick:()=>b(x),role:"option",children:x},x))}),S&&e.jsx("p",{className:"cedros-input-error",role:"alert",children:S}),e.jsxs("div",{className:"cedros-recovery-input-actions",children:[t&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:t,disabled:o,children:"Cancel"}),e.jsx("button",{type:"submit",className:"cedros-button cedros-button-primary",disabled:o,children:o?"Recovering...":"Recover Wallet"})]})]})}function Vo({capabilities:s,className:t=""}){if(s.allSupported)return null;const o=I.getMissingCapabilitiesMessage(s),a=I.getBrowserSupportInfo();return e.jsxs("div",{className:`cedros-capability-warning ${t}`,role:"alert",children:[e.jsxs("div",{className:"cedros-warning-header",children:[e.jsx("svg",{className:"cedros-warning-icon",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M12 9v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})}),e.jsx("h3",{className:"cedros-warning-title",children:"Wallet Feature Unavailable"})]}),e.jsx("p",{className:"cedros-warning-message",children:o}),e.jsxs("div",{className:"cedros-capability-details",children:[e.jsx("h4",{children:"Browser Compatibility"}),e.jsxs("p",{children:["Detected: ",a.browser," ",a.version,a.likelySupported?" (likely supported)":" (may not be supported)"]}),e.jsx("h4",{children:"Required Features"}),e.jsxs("ul",{className:"cedros-capability-list",children:[e.jsxs("li",{className:s.webCrypto?"cedros-cap-ok":"cedros-cap-missing",children:["Web Crypto API: ",s.webCrypto?"Available":"Missing"]}),e.jsxs("li",{className:s.aesGcm?"cedros-cap-ok":"cedros-cap-missing",children:["AES-GCM Encryption: ",s.aesGcm?"Available":"Missing"]}),e.jsxs("li",{className:s.hkdf?"cedros-cap-ok":"cedros-cap-missing",children:["HKDF Key Derivation: ",s.hkdf?"Available":"Missing"]}),e.jsxs("li",{className:s.webAuthn?"cedros-cap-ok":"cedros-cap-missing",children:["WebAuthn/Passkeys: ",s.webAuthn?"Available":"Missing"]}),e.jsxs("li",{className:s.webAuthnPrf?"cedros-cap-ok":"cedros-cap-missing",children:["WebAuthn PRF Extension: ",s.webAuthnPrf?"Available":"Missing"]}),e.jsxs("li",{className:s.argon2?"cedros-cap-ok":"cedros-cap-missing",children:["Argon2 Password Hashing: ",s.argon2?"Available":"Missing"]})]})]}),e.jsxs("div",{className:"cedros-capability-help",children:[e.jsx("h4",{children:"Recommended Browsers"}),e.jsxs("ul",{children:[e.jsx("li",{children:"Chrome 116+ on Windows, macOS, or Android"}),e.jsx("li",{children:"Safari 17+ on macOS or iOS"}),e.jsx("li",{children:"Edge 116+ on Windows"})]}),e.jsx("p",{className:"cedros-capability-note",children:"A platform authenticator (Touch ID, Face ID, or Windows Hello) is required."})]})]})}const Ho=["share_c_only","full_seed","none"];function Qo(s){return s&&Ho.includes(s)?s:"share_c_only"}const Ko={walletEnabled:!1,recoveryMode:"share_c_only",unlockTtlSeconds:900,isLoading:!1,error:null,refetch:async()=>{}};function hr(){const s=T.useCedrosLoginOptional(),[t,o]=l.useState(null),[a,r]=l.useState(!!s),[n,c]=l.useState(null),i=l.useMemo(()=>s?new T.ApiClient({baseUrl:s.config.serverUrl,timeoutMs:s.config.requestTimeout,retryAttempts:s.config.retryAttempts}):null,[s]),d=l.useCallback(async()=>{if(i){r(!0),c(null);try{const h=await i.get("/discovery");h.wallet?o({enabled:h.wallet.enabled,recoveryMode:Qo(h.wallet.recoveryMode),unlockTtlSeconds:h.wallet.unlockTtlSeconds}):o({enabled:!1,recoveryMode:"share_c_only",unlockTtlSeconds:900})}catch(h){const p=h instanceof Error?h.message:"Failed to fetch wallet config";c(p),o({enabled:!1,recoveryMode:"share_c_only",unlockTtlSeconds:900})}finally{r(!1)}}},[i]);return l.useEffect(()=>{i&&d()},[i,d]),s?{walletEnabled:t?.enabled??!1,recoveryMode:t?.recoveryMode??"share_c_only",unlockTtlSeconds:t?.unlockTtlSeconds??900,isLoading:a,error:n,refetch:d}:Ko}function pr(){const{user:s}=T.useCedrosLogin(),{enroll:t}=I.useWalletMaterial(),{recoveryMode:o}=hr(),[a,r]=l.useState({step:"idle"}),[n,c]=l.useState(!1),i=l.useRef([]),d=l.useCallback(()=>{I.wipeAll(...i.current),i.current=[]},[]);l.useEffect(()=>()=>{d()},[d]);const h=l.useCallback(async(m,u,y,A)=>{r({step:"generating_seed"});const b=I.generateSeed();i.current.push(b),r({step:"splitting_shares"});const{shareA:v,shareB:k,shareC:S}=ie.splitSecret(b);i.current.push(v,k,S),r({step:"encrypting_shares"});const x=await I.aesGcmEncryptToBase64(v,I.toEncryptionKey(u)),j=ie.getPublicKeyFromSeed(b),C=ie.publicKeyToBase58(j);r({step:"uploading"});const N={solanaPubkey:C,shareAAuthMethod:m,shareACiphertext:x.ciphertext,shareANonce:x.nonce,shareB:I.uint8ArrayToBase64(k)};if(m==="password"){if(!y)throw new Error("KDF salt required for password method");N.shareAKdfSalt=I.uint8ArrayToBase64(y),N.shareAKdfParams=I.DEFAULT_KDF_PARAMS}if(m==="passkey"&&A&&(N.prfSalt=A),await t(N),o==="none")d(),r({step:"complete",solanaPubkey:C});else{const P=o==="full_seed"?ho(b):co(I.toShamirShare(S));r({step:"showing_recovery",recoveryPhrase:P,solanaPubkey:C})}},[t,o,d]),p=l.useCallback(async m=>{if(!s){r({step:"error",error:"User not authenticated"});return}c(!0),d();try{const u=I.generateArgon2Salt(),y=await ie.argon2DeriveInWorker(m,u,I.DEFAULT_KDF_PARAMS);i.current.push(y),await h("password",y,u)}catch(u){r({step:"error",error:u instanceof Error?u.message:"Enrollment failed"})}finally{c(!1)}},[s,d,h]),f=l.useCallback(async()=>{if(!s){r({step:"error",error:"User not authenticated"});return}c(!0),d();try{const m=I.generatePrfSalt(),u=I.uint8ArrayToBase64(m);r({step:"registering_passkey"});let y;try{const b=new TextEncoder().encode(s.id),v=s.name??s.email??"User",k=s.email??s.id;y=(await I.registerPasskeyWithPrf(b,k,v,m)).prfOutput}catch(b){if(b?.name!=="InvalidStateError")throw b;y=(await I.authenticateWithDiscoverablePrf(u)).prfOutput}i.current.push(y);const A=await I.deriveKeyFromPrf(y,m);i.current.push(A),await h("passkey",A,void 0,u)}catch(m){r({step:"error",error:m instanceof Error?m.message:"Enrollment failed"})}finally{c(!1)}},[s,d,h]),g=l.useCallback(()=>{const m=a.solanaPubkey;d(),r({step:"complete",solanaPubkey:m})},[a.solanaPubkey,d]),w=l.useCallback(()=>{d(),r({step:"idle"}),c(!1)},[d]);return{state:a,startEnrollmentWithPassword:p,startEnrollmentWithPasskey:f,confirmRecoveryPhrase:g,cancel:w,isEnrolling:n}}function mr({onComplete:s,onCancel:t,className:o="",forceAuthMethod:a}){const{user:r}=T.useCedrosLogin(),{state:n,startEnrollmentWithPassword:c,startEnrollmentWithPasskey:i,confirmRecoveryPhrase:d,cancel:h,isEnrolling:p}=pr(),f=()=>a||"password",[g,w]=l.useState(f),[m,u]=l.useState(""),[y,A]=l.useState(""),[b,v]=l.useState(null);l.useEffect(()=>{w(f())},[r?.id,a]);const k=l.useCallback(async C=>{if(C.preventDefault(),m!==y){v("Passwords do not match");return}const N=Me.validatePassword(m);if(!N.isValid){const P=Object.values(N.errors)[0];v(P??"Password does not meet requirements");return}v(null),await c(m)},[m,y,c]),S=l.useCallback(async()=>{await i()},[i]),x=l.useCallback(()=>{d(),n.solanaPubkey&&s?.(n.solanaPubkey)},[d,n.solanaPubkey,s]),j=l.useCallback(()=>{h(),t?.()},[h,t]);return n.step==="generating_seed"||n.step==="splitting_shares"?e.jsx("div",{className:`cedros-wallet-enrollment ${o}`,"aria-busy":"true",children:e.jsxs("div",{className:"cedros-enrollment-progress",role:"status","aria-live":"polite",children:[e.jsx("div",{className:"cedros-spinner","aria-hidden":"true"}),e.jsx("p",{children:"Generating secure wallet..."})]})}):n.step==="encrypting_shares"?e.jsx("div",{className:`cedros-wallet-enrollment ${o}`,"aria-busy":"true",children:e.jsxs("div",{className:"cedros-enrollment-progress",role:"status","aria-live":"polite",children:[e.jsx("div",{className:"cedros-spinner","aria-hidden":"true"}),e.jsx("p",{children:"Encrypting wallet shares..."})]})}):n.step==="registering_passkey"?e.jsx("div",{className:`cedros-wallet-enrollment ${o}`,"aria-busy":"true",children:e.jsx("div",{className:"cedros-enrollment-progress",role:"status","aria-live":"polite",children:e.jsxs("div",{className:"cedros-passkey-prompt",children:[e.jsxs("svg",{className:"cedros-passkey-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("rect",{x:"8",y:"16",width:"32",height:"24",rx:"4",stroke:"currentColor",strokeWidth:"2"}),e.jsx("circle",{cx:"24",cy:"28",r:"4",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M24 32v4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),e.jsx("h3",{children:"Authenticate with Passkey"}),e.jsx("p",{children:"Follow your browser's prompt to use your passkey."})]})})}):n.step==="uploading"?e.jsx("div",{className:`cedros-wallet-enrollment ${o}`,"aria-busy":"true",children:e.jsxs("div",{className:"cedros-enrollment-progress",role:"status","aria-live":"polite",children:[e.jsx("div",{className:"cedros-spinner","aria-hidden":"true"}),e.jsx("p",{children:"Saving wallet..."})]})}):n.step==="showing_recovery"&&n.recoveryPhrase?e.jsx("div",{className:`cedros-wallet-enrollment ${o}`,children:e.jsx(dr,{words:n.recoveryPhrase,onConfirm:x})}):n.step==="complete"?e.jsx("div",{className:`cedros-wallet-enrollment ${o}`,children:e.jsxs("div",{className:"cedros-enrollment-complete",children:[e.jsxs("svg",{className:"cedros-success-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"20",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M16 24l6 6 12-12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),e.jsx("h3",{children:"Wallet Created!"}),e.jsxs("p",{className:"cedros-pubkey",children:[e.jsx("strong",{children:"Address:"})," ",n.solanaPubkey]}),e.jsx("p",{children:"Your non-custodial Solana wallet is ready to use."})]})}):n.step==="error"?e.jsx("div",{className:`cedros-wallet-enrollment ${o}`,children:e.jsxs("div",{className:"cedros-enrollment-error",children:[e.jsxs("svg",{className:"cedros-error-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"20",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M24 16v12m0 6h.01",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),e.jsx("h3",{children:"Enrollment Failed"}),e.jsx("p",{className:"cedros-error-message",children:n.error}),e.jsxs("div",{className:"cedros-error-actions",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:j,children:"Cancel"}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:()=>h(),children:"Try Again"})]})]})}):e.jsxs("div",{className:`cedros-wallet-enrollment ${o}`,children:[e.jsxs("div",{className:"cedros-enrollment-header",children:[e.jsx("h2",{children:"Create Wallet"}),e.jsxs("p",{children:["Secure your wallet with a ",g==="passkey"?"passkey":"password","."]})]}),!a&&e.jsxs("div",{className:"cedros-auth-method-selector",children:[e.jsxs("label",{className:"cedros-radio-label",children:[e.jsx("input",{type:"radio",name:"authMethod",value:"password",checked:g==="password",onChange:()=>w("password"),disabled:p}),e.jsx("span",{children:"Password"})]}),e.jsxs("label",{className:"cedros-radio-label",children:[e.jsx("input",{type:"radio",name:"authMethod",value:"passkey",checked:g==="passkey",onChange:()=>w("passkey"),disabled:p}),e.jsx("span",{children:"Passkey"})]})]}),g==="password"&&e.jsxs("form",{onSubmit:k,className:"cedros-enrollment-form",children:[e.jsx(K.PasswordInput,{label:"Password",value:m,onChange:C=>u(C.target.value),showStrengthMeter:!0,disabled:p,required:!0,minLength:8,placeholder:"Enter a strong password"}),e.jsx(K.PasswordInput,{label:"Confirm Password",value:y,onChange:C=>A(C.target.value),error:b??void 0,disabled:p,required:!0,minLength:8,placeholder:"Confirm your password"}),e.jsx("div",{className:"cedros-password-info",children:e.jsx("p",{children:"This password will be used to sign transactions."})}),e.jsxs("div",{className:"cedros-enrollment-actions",children:[t&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:j,disabled:p,children:"Cancel"}),e.jsx("button",{type:"submit",className:"cedros-button cedros-button-primary",disabled:p||!m||!y,children:p?"Creating...":"Continue"})]})]}),g==="passkey"&&e.jsxs("div",{className:"cedros-enrollment-form",children:[e.jsxs("div",{className:"cedros-passkey-info",children:[e.jsxs("svg",{className:"cedros-passkey-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("rect",{x:"8",y:"16",width:"32",height:"24",rx:"4",stroke:"currentColor",strokeWidth:"2"}),e.jsx("circle",{cx:"24",cy:"28",r:"4",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M24 32v4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),e.jsx("p",{children:"Use your passkey (Touch ID, Face ID, or Windows Hello) to secure your wallet."}),e.jsx("p",{children:"You'll use the same passkey to sign transactions."})]}),e.jsxs("div",{className:"cedros-enrollment-actions",children:[t&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:j,disabled:p,children:"Cancel"}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:S,disabled:p,children:p?"Creating...":"Use Passkey"})]})]})]})}function fr(){const{user:s}=T.useCedrosLogin(),{signTransaction:t}=I.useWalletMaterial(),[o,a]=l.useState(!1),[r,n]=l.useState(null),c=l.useCallback(async(d,h)=>{if(!s){const p="User not authenticated";throw n(p),new Error(p)}a(!0),n(null);try{const p={transaction:I.uint8ArrayToBase64(d),...h?{credential:I.toCredentialRequest(h)}:{}},f=await t(p);return I.base64ToUint8Array(f.signature)}catch(p){const f=p instanceof Error?p.message:"Signing failed";throw n(f),p}finally{a(!1)}},[s,t]),i=l.useCallback(()=>n(null),[]);return{signTransaction:c,isSigning:o,error:r,clearError:i}}function gr(){const{getMaterial:s}=I.useWalletMaterial(),[t,o]=l.useState(!1),[a,r]=l.useState(null),n=l.useCallback(async()=>{o(!0),r(null);try{const i=await s();if(!i)throw new Error("No wallet enrolled");if(i.shareAAuthMethod!=="passkey")throw new Error("Wallet is not configured for passkey authentication");if(!i.prfSalt)throw new Error("No PRF salt configured for wallet");const d=await I.authenticateWithDiscoverablePrf(i.prfSalt);try{return{type:"prfOutput",prfOutput:I.uint8ArrayToBase64(d.prfOutput)}}finally{d.prfOutput.fill(0)}}catch(i){const d=i instanceof Error?i.message:"Passkey authentication failed";return r(d),null}finally{o(!1)}},[s]),c=l.useCallback(()=>r(null),[]);return{getPasskeyCredential:n,isAuthenticating:t,error:a,clearError:c}}function wr({mode:s,isLoading:t=!1,error:o,onPrompt:a,onRetry:r,onCancel:n,title:c,description:i,className:d=""}){const h=l.useCallback(()=>{t||a?.()},[t,a]),p=l.useCallback(()=>{r?.()},[r]),f=s==="register"?"Set Up Passkey":"Verify with Passkey",g=s==="register"?"Create a passkey to securely encrypt your wallet on this device. You will use your fingerprint, face, or device PIN.":"Use your passkey to unlock your wallet. You will be prompted for biometric verification.";return e.jsxs("div",{className:`cedros-passkey-prompt ${d}`,children:[e.jsx("div",{className:"cedros-passkey-icon",children:t?e.jsx(Go,{}):o?e.jsx($o,{}):e.jsx(Yo,{})}),e.jsx("h3",{className:"cedros-passkey-title",children:c??f}),e.jsx("p",{className:"cedros-passkey-description",children:i??g}),o&&e.jsx("div",{className:"cedros-passkey-error",role:"alert",children:e.jsx("p",{children:o})}),e.jsx("div",{className:"cedros-passkey-actions",children:o?e.jsxs(e.Fragment,{children:[r&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:p,children:"Try Again"}),n&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:n,children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:h,disabled:t,children:t?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"cedros-button-spinner","aria-hidden":"true"}),"Waiting for passkey..."]}):s==="register"?"Create Passkey":"Use Passkey"}),n&&!t&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:n,children:"Cancel"})]})}),t&&e.jsxs("p",{className:"cedros-passkey-hint",children:["Follow the prompts on your device to ",s==="register"?"create":"verify"," your passkey."]})]})}function Yo(){return e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4"}),e.jsx("path",{d:"M14 13.12c0 2.38 0 6.38-1 8.88"}),e.jsx("path",{d:"M17.29 21.02c.12-.6.43-2.3.5-3.02"}),e.jsx("path",{d:"M2 12a10 10 0 0 1 18-6"}),e.jsx("path",{d:"M2 16h.01"}),e.jsx("path",{d:"M21.8 16c.2-2 .131-5.354 0-6"}),e.jsx("path",{d:"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2"}),e.jsx("path",{d:"M8.65 22c.21-.66.45-1.32.57-2"}),e.jsx("path",{d:"M9 6.8a6 6 0 0 1 9 5.2v2"})]})}function Go(){return e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",className:"cedros-spinner",children:[e.jsx("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),e.jsx("path",{d:"M12 3a9 9 0 0 1 9 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})}function $o(){return e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 8v4M12 16h.01"})]})}function yr({onUnlock:s,onCancel:t,showCancel:o=!0,authMethod:a,className:r=""}){T.useCedrosLogin();const{unlock:n,getMaterial:c,isLoading:i}=I.useWalletMaterial(),{getPasskeyCredential:d,isAuthenticating:h}=gr(),[p,f]=l.useState("idle"),[g,w]=l.useState(a??null),[m,u]=l.useState(""),[y,A]=l.useState(null);l.useEffect(()=>{a!==void 0&&w(a)},[a]);const b=g==="password",v=g==="passkey",k=l.useCallback(async()=>{if(f("credential"),A(null),!g)try{const L=await c();L?w(L.shareAAuthMethod):(A("No wallet enrolled"),f("error"))}catch(L){A(L instanceof Error?L.message:"Failed to get wallet info"),f("error")}},[g,c]),S=l.useCallback(async L=>{L.preventDefault(),A(null),f("unlocking");try{let E;if(b)E={type:"password",password:m};else throw new Error("Invalid auth method");await n(E),f("unlocked"),s?.()}catch(E){A(E instanceof Error?E.message:"Failed to unlock wallet"),f("error")}},[b,m,n,s]),x=l.useCallback(async()=>{A(null),f("unlocking");try{const L=await d();if(!L){f("credential");return}await n(L),f("unlocked"),s?.()}catch(L){A(L instanceof Error?L.message:"Failed to unlock wallet"),f("error")}},[d,n,s]),j=l.useCallback(()=>{u(""),f("idle"),A(null),t?.()},[t]),C=l.useCallback(()=>{u(""),f("credential"),A(null)},[]),N=i||h,P=()=>{switch(p){case"idle":return e.jsxs("div",{className:"cedros-wallet-unlock-idle",children:[e.jsx("div",{className:"cedros-wallet-unlock-icon",children:e.jsx(Jo,{})}),e.jsx("h3",{className:"cedros-wallet-unlock-title",children:"Wallet Locked"}),e.jsx("p",{className:"cedros-wallet-unlock-description",children:"Unlock your wallet to sign transactions."}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:k,children:"Unlock Wallet"})]});case"credential":return b?e.jsxs("form",{className:"cedros-wallet-unlock-form",onSubmit:S,children:[e.jsx("h3",{className:"cedros-wallet-unlock-title",children:"Enter Password"}),e.jsx("p",{className:"cedros-wallet-unlock-description",children:"Enter your wallet password to unlock."}),e.jsx(K.PasswordInput,{label:"Password",value:m,onChange:L=>u(L.target.value),disabled:N,autoComplete:"current-password",error:y??void 0}),e.jsxs("div",{className:"cedros-wallet-unlock-actions",children:[e.jsx("button",{type:"submit",className:"cedros-button cedros-button-primary",disabled:N||m.length===0,children:N?"Unlocking...":"Unlock"}),o&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:j,disabled:N,children:"Cancel"})]})]}):v?e.jsxs("div",{className:"cedros-wallet-unlock-passkey",children:[e.jsx("h3",{className:"cedros-wallet-unlock-title",children:"Verify with Passkey"}),e.jsx("p",{className:"cedros-wallet-unlock-description",children:"Use your passkey to unlock your wallet."}),e.jsx(wr,{mode:"authenticate",isLoading:N,error:y??void 0,onPrompt:x,onRetry:x,onCancel:o?j:void 0})]}):e.jsxs("div",{className:"cedros-wallet-unlock-loading",children:[e.jsx(V.LoadingSpinner,{size:"xl"}),e.jsx("p",{children:"Loading wallet info..."})]});case"unlocking":return e.jsxs("div",{className:"cedros-wallet-unlock-progress",children:[e.jsx("div",{className:"cedros-wallet-unlock-icon",children:e.jsx(V.LoadingSpinner,{size:"xl"})}),e.jsx("h3",{className:"cedros-wallet-unlock-title",children:"Unlocking Wallet"}),e.jsx("p",{className:"cedros-wallet-unlock-description",children:"Verifying your credentials..."})]});case"unlocked":return e.jsxs("div",{className:"cedros-wallet-unlock-success",children:[e.jsx("div",{className:"cedros-wallet-unlock-icon",children:e.jsx(Xo,{})}),e.jsx("h3",{className:"cedros-wallet-unlock-title",children:"Wallet Unlocked"}),e.jsx("p",{className:"cedros-wallet-unlock-description",children:"Your wallet is ready to sign transactions."})]});case"error":return e.jsxs("div",{className:"cedros-wallet-unlock-error",children:[e.jsx("div",{className:"cedros-wallet-unlock-icon",children:e.jsx(Zo,{})}),e.jsx("h3",{className:"cedros-wallet-unlock-title",children:"Unlock Failed"}),e.jsx("p",{className:"cedros-wallet-unlock-description",children:y??"Failed to unlock wallet. Please try again."}),e.jsxs("div",{className:"cedros-wallet-unlock-actions",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:C,children:"Try Again"}),o&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:j,children:"Cancel"})]})]})}};return e.jsx("div",{className:`cedros-wallet-unlock ${r}`,children:P()})}function Jo(){return e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("rect",{x:"10",y:"22",width:"28",height:"20",rx:"4",stroke:"currentColor",strokeWidth:"2",fill:"var(--cedros-muted, #f3f4f6)"}),e.jsx("path",{d:"M16 22V16a8 8 0 1 1 16 0v6",stroke:"currentColor",strokeWidth:"2",fill:"none"}),e.jsx("circle",{cx:"24",cy:"32",r:"3",fill:"currentColor"})]})}function Xo(){return e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"20",stroke:"var(--cedros-success, #22c55e)",strokeWidth:"2",fill:"var(--cedros-success-light, #dcfce7)"}),e.jsx("path",{d:"M16 24l6 6 10-10",stroke:"var(--cedros-success, #22c55e)",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function Zo(){return e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"20",stroke:"var(--cedros-destructive, #ef4444)",strokeWidth:"2",fill:"var(--cedros-destructive-light, #fee2e2)"}),e.jsx("path",{d:"M24 16v10M24 30v2",stroke:"var(--cedros-destructive, #ef4444)",strokeWidth:"3",strokeLinecap:"round"})]})}function br(){const{recover:s,getShareBForRecovery:t}=I.useWalletMaterial(),{recoveryMode:o}=hr(),[a,r]=l.useState({step:"idle"}),[n,c]=l.useState(!1),i=l.useRef([]),d=l.useCallback(()=>{I.wipeAll(...i.current),i.current=[]},[]);l.useEffect(()=>()=>{d()},[d]);const h=l.useCallback(async(f,g,w)=>{c(!0),d();try{if(r({step:"validating"}),!sr(f))throw new Error("Invalid recovery phrase. Please check your words.");let m;if(o==="share_c_only"){const C=uo(f);i.current.push(C);const N=I.uint8ArrayToBase64(C),P=await t({shareC:N}),L=I.base64ToUint8Array(P.shareB);i.current.push(L),m=ie.combineShares(I.toShamirShare(L),I.toShamirShare(C)),i.current.push(m)}else m=po(f),i.current.push(m);const u=ie.getPublicKeyFromSeed(m),y=ie.publicKeyToBase58(u),{shareA:A,shareB:b}=ie.splitSecret(m);i.current.push(A,b),r({step:"encrypting"});let v,k,S;if(g==="passkey"){const C=I.generatePrfSalt();S=I.uint8ArrayToBase64(C);const N=await I.authenticateWithDiscoverablePrf(S);i.current.push(N.prfOutput),v=await I.deriveKeyFromPrf(N.prfOutput,C),i.current.push(v)}else k=I.generateArgon2Salt(),v=await ie.argon2DeriveInWorker(w,k,I.DEFAULT_KDF_PARAMS),i.current.push(v);const x=await I.aesGcmEncryptToBase64(A,I.toEncryptionKey(v));r({step:"uploading"});const j={solanaPubkey:y,shareAAuthMethod:g,shareACiphertext:x.ciphertext,shareANonce:x.nonce,shareB:I.uint8ArrayToBase64(b)};g==="password"&&(j.shareAKdfSalt=I.uint8ArrayToBase64(k),j.shareAKdfParams=I.DEFAULT_KDF_PARAMS),g==="passkey"&&(j.prfSalt=S),await s(j),d(),r({step:"complete"})}catch(m){d(),r({step:"error",error:m instanceof Error?m.message:"Recovery failed"})}finally{c(!1)}},[s,t,o,d]),p=l.useCallback(()=>{d(),r({step:"idle"}),c(!1)},[d]);return{state:a,startRecovery:h,cancel:p,isRecovering:n}}function Ar({onComplete:s,onCancel:t,className:o="",defaultAuthMethod:a="password"}){const{state:r,startRecovery:n,cancel:c,isRecovering:i}=br(),[d,h]=l.useState([]),[p,f]=l.useState(!1),[g,w]=l.useState(a),[m,u]=l.useState(""),[y,A]=l.useState(""),[b,v]=l.useState(null),k=l.useCallback(N=>{h(N),f(!0)},[]),S=l.useCallback(async N=>{if(N.preventDefault(),v(null),g!=="passkey"){if(m!==y){v("Passwords do not match");return}if(g==="password"&&m.length<8){v("Password must be at least 8 characters");return}}await n(d,g,m)},[d,g,m,y,n]),x=l.useCallback(()=>{c(),h([]),f(!1),u(""),A(""),t?.()},[c,t]),j=l.useCallback(()=>{f(!1),u(""),A("")},[]),C=l.useCallback(()=>{s?.()},[s]);return r.step==="validating"||r.step==="encrypting"||r.step==="uploading"?e.jsx("div",{className:`cedros-wallet-recovery ${o}`,children:e.jsxs("div",{className:"cedros-wallet-recovery-progress",children:[e.jsx("div",{className:"cedros-wallet-recovery-icon",children:e.jsx(en,{})}),e.jsxs("h3",{className:"cedros-wallet-recovery-title",children:[r.step==="validating"&&"Validating Recovery Phrase",r.step==="encrypting"&&"Encrypting Wallet",r.step==="uploading"&&"Saving to Server"]}),e.jsxs("p",{className:"cedros-wallet-recovery-description",children:[r.step==="validating"&&"Checking your recovery phrase...",r.step==="encrypting"&&"Securing your wallet with new encryption...",r.step==="uploading"&&"Uploading encrypted wallet data..."]})]})}):r.step==="complete"?e.jsx("div",{className:`cedros-wallet-recovery ${o}`,children:e.jsxs("div",{className:"cedros-wallet-recovery-success",children:[e.jsx("div",{className:"cedros-wallet-recovery-icon",children:e.jsx(sn,{})}),e.jsx("h3",{className:"cedros-wallet-recovery-title",children:"Wallet Recovered"}),e.jsxs("p",{className:"cedros-wallet-recovery-description",children:["Your wallet has been successfully recovered and secured with your new"," ",g==="passkey"?"passkey":"password","."]}),e.jsx("div",{className:"cedros-wallet-recovery-actions",children:e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:C,children:"Done"})})]})}):r.step==="error"?e.jsx("div",{className:`cedros-wallet-recovery ${o}`,children:e.jsxs("div",{className:"cedros-wallet-recovery-error",children:[e.jsx("div",{className:"cedros-wallet-recovery-icon",children:e.jsx(tn,{})}),e.jsx("h3",{className:"cedros-wallet-recovery-title",children:"Recovery Failed"}),e.jsx("p",{className:"cedros-wallet-recovery-description",children:r.error??"An error occurred during recovery. Please try again."}),e.jsx("div",{className:"cedros-wallet-recovery-actions",children:e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:x,children:"Start Over"})})]})}):p?e.jsx("div",{className:`cedros-wallet-recovery ${o}`,children:e.jsxs("form",{className:"cedros-wallet-recovery-credential",onSubmit:S,children:[e.jsxs("div",{className:"cedros-wallet-recovery-header",children:[e.jsx("h3",{className:"cedros-wallet-recovery-title",children:"Set New Security"}),e.jsx("p",{className:"cedros-wallet-recovery-description",children:"Choose how to secure your recovered wallet."})]}),e.jsxs("div",{className:"cedros-auth-method-selector",children:[e.jsxs("label",{className:"cedros-radio-label",children:[e.jsx("input",{type:"radio",name:"authMethod",value:"password",checked:g==="password",onChange:()=>w("password"),disabled:i}),e.jsx("span",{children:"Password"})]}),e.jsxs("label",{className:"cedros-radio-label",children:[e.jsx("input",{type:"radio",name:"authMethod",value:"passkey",checked:g==="passkey",onChange:()=>w("passkey"),disabled:i}),e.jsx("span",{children:"Passkey"})]})]}),g==="password"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"cedros-password-input",children:[e.jsx("label",{htmlFor:"recovery-password",className:"cedros-label",children:"New Password"}),e.jsx("input",{id:"recovery-password",type:"password",className:"cedros-input",value:m,onChange:N=>u(N.target.value),disabled:i,minLength:8,placeholder:"Enter a strong password"})]}),e.jsxs("div",{className:"cedros-password-input",children:[e.jsx("label",{htmlFor:"recovery-password-confirm",className:"cedros-label",children:"Confirm Password"}),e.jsx("input",{id:"recovery-password-confirm",type:"password",className:"cedros-input",value:y,onChange:N=>A(N.target.value),disabled:i,"aria-invalid":b?"true":void 0,placeholder:"Confirm your password"}),b&&e.jsx("p",{className:"cedros-input-error",role:"alert",children:b})]})]}),g==="passkey"&&e.jsxs("div",{className:"cedros-passkey-info",children:[e.jsx(rn,{}),e.jsx("p",{children:"Use your passkey (Touch ID, Face ID, or Windows Hello) to secure your wallet."})]}),e.jsxs("div",{className:"cedros-wallet-recovery-actions",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:j,disabled:i,children:"Back"}),e.jsx("button",{type:"submit",className:"cedros-button cedros-button-primary",disabled:i||g!=="passkey"&&(m.length===0||y.length===0),children:i?"Recovering...":"Recover Wallet"})]})]})}):e.jsx("div",{className:`cedros-wallet-recovery ${o}`,children:e.jsxs("div",{className:"cedros-wallet-recovery-phrase",children:[e.jsxs("div",{className:"cedros-wallet-recovery-header",children:[e.jsx("h3",{className:"cedros-wallet-recovery-title",children:"Recover Your Wallet"}),e.jsx("p",{className:"cedros-wallet-recovery-description",children:"Enter your 12-word recovery phrase to restore your wallet."})]}),e.jsx(ur,{onSubmit:k,onCancel:x,isSubmitting:!1})]})})}function en(){return e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",className:"cedros-spinner",children:[e.jsx("circle",{cx:"24",cy:"24",r:"20",stroke:"var(--cedros-muted, #e5e7eb)",strokeWidth:"3",fill:"none"}),e.jsx("path",{d:"M24 4a20 20 0 0 1 20 20",stroke:"var(--cedros-primary, #6366f1)",strokeWidth:"3",strokeLinecap:"round",fill:"none"})]})}function sn(){return e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"20",stroke:"var(--cedros-success, #22c55e)",strokeWidth:"2",fill:"var(--cedros-success-light, #dcfce7)"}),e.jsx("path",{d:"M16 24l6 6 10-10",stroke:"var(--cedros-success, #22c55e)",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function tn(){return e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("circle",{cx:"24",cy:"24",r:"20",stroke:"var(--cedros-destructive, #ef4444)",strokeWidth:"2",fill:"var(--cedros-destructive-light, #fee2e2)"}),e.jsx("path",{d:"M24 16v10M24 30v2",stroke:"var(--cedros-destructive, #ef4444)",strokeWidth:"3",strokeLinecap:"round"})]})}function rn(){return e.jsxs("svg",{className:"cedros-passkey-icon",width:"48",height:"48",viewBox:"0 0 48 48",fill:"none","aria-hidden":"true",children:[e.jsx("rect",{x:"8",y:"16",width:"32",height:"24",rx:"4",stroke:"currentColor",strokeWidth:"2"}),e.jsx("circle",{cx:"24",cy:"28",r:"4",stroke:"currentColor",strokeWidth:"2"}),e.jsx("path",{d:"M24 32v4",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]})}function xr({address:s,label:t="Wallet Address",showCopy:o=!0,showExplorerLink:a=!0,allowReveal:r=!0,className:n=""}){const c=T.useCedrosLoginOptional(),[i,d]=l.useState(!1),[h,p]=l.useState(null),[f,g]=l.useState(!1),w=l.useRef(null),m=c?.config.solana?.network??"mainnet-beta",u=l.useMemo(()=>{const v=`https://explorer.solana.com/address/${s}`;return m==="mainnet-beta"?v:`${v}?cluster=${encodeURIComponent(m)}`},[s,m]),y=r&&s.length>18,A=l.useMemo(()=>!y||f?s:`${s.slice(0,8)}...${s.slice(-8)}`,[s,y,f]),b=l.useCallback(async()=>{try{p(null),await navigator.clipboard.writeText(s),d(!0),w.current!==null&&window.clearTimeout(w.current),w.current=window.setTimeout(()=>{d(!1),w.current=null},2e3)}catch(v){d(!1),p(v instanceof Error?v.message:"Copy failed")}},[s]);return l.useEffect(()=>()=>{w.current!==null&&(window.clearTimeout(w.current),w.current=null)},[]),e.jsxs("div",{className:`cedros-wallet-address-row ${n}`,children:[e.jsxs("div",{className:"cedros-wallet-address-row-header",children:[e.jsx("span",{className:"cedros-wallet-status-pubkey-label",children:t}),e.jsxs("div",{className:"cedros-wallet-address-row-actions",children:[y&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-sm cedros-button-ghost",onClick:()=>g(v=>!v),"aria-label":f?"Hide full wallet address":"Show full wallet address",children:f?e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M3 3l18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M10.7 10.7a3 3 0 0 0 4.24 4.24",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M9.88 5.09A10.94 10.94 0 0 1 12 5c5 0 9.27 3.11 11 7-0.55 1.23-1.32 2.33-2.27 3.25",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M6.61 6.61C4.4 7.9 2.74 9.8 1 12c1.73 3.89 6 7 11 7 1.14 0 2.25-0.16 3.3-0.46",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}):e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",children:[e.jsx("path",{d:"M1 12s4-7 11-7 11 7 11 7-4 7-11 7S1 12 1 12Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})}),a&&e.jsx("a",{className:"cedros-button cedros-button-sm cedros-button-ghost",href:u,target:"_blank",rel:"noreferrer",children:"Explorer"}),o&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-sm cedros-button-outline",onClick:b,"aria-label":"Copy wallet address",children:i?"Copied":"Copy"})]})]}),e.jsx("code",{className:"cedros-wallet-status-pubkey-value",title:s,children:A}),h&&e.jsx("p",{className:"cedros-input-hint",role:"status",children:h})]})}function vr({status:s,publicKey:t,onLock:o,onEnroll:a,onUnlock:r,onRecover:n,showActions:c=!0,compact:i=!1,className:d=""}){const h=s!==void 0,p=I.useWallet(),f=h?s:p.status,g=h?t??null:p.solanaPubkey,w=h?null:p.error,m=h?()=>{}:p.refresh,u=h?()=>{}:p.clearError,y=on(f,w);return i?e.jsxs("div",{className:`cedros-wallet-status cedros-wallet-status-compact ${d}`,children:[e.jsx("span",{className:`cedros-wallet-status-dot cedros-wallet-status-${y.color}`,title:y.label}),e.jsx("span",{className:"cedros-wallet-status-label",children:y.label}),g&&e.jsx("span",{className:"cedros-wallet-status-pubkey",title:g,children:nn(g)})]}):e.jsxs("div",{className:`cedros-wallet-status ${d}`,children:[e.jsxs("div",{className:"cedros-wallet-status-header",children:[e.jsx("div",{className:`cedros-wallet-status-icon cedros-wallet-status-icon-${y.color}`,children:e.jsx(an,{status:f})}),e.jsxs("div",{className:"cedros-wallet-status-info",children:[e.jsx("h4",{className:"cedros-wallet-status-title",children:y.title}),e.jsx("p",{className:"cedros-wallet-status-description",children:y.description})]})]}),g&&e.jsx("div",{className:"cedros-wallet-status-pubkey-full",children:e.jsx(xr,{address:g})}),w&&e.jsxs("div",{className:"cedros-wallet-status-error-box",role:"alert",children:[e.jsx("p",{children:w}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-sm cedros-button-secondary",onClick:u,children:"Dismiss"})]}),c&&e.jsxs("div",{className:"cedros-wallet-status-actions",children:[f==="not_enrolled"&&a&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary cedros-button-sm",onClick:a,children:"Create Wallet"}),f==="enrolled_locked"&&r&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary cedros-button-sm",onClick:r,children:"Unlock Wallet"}),(f==="not_enrolled"||f==="error")&&n&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:n,children:"Recover Wallet"}),f==="error"&&e.jsx("button",{type:"button",className:"cedros-button cedros-button-outline cedros-button-sm",onClick:m,children:"Retry"})]})]})}function on(s,t){switch(s){case"loading":return{label:"Loading",title:"Checking Wallet",description:"Verifying wallet status...",color:"loading"};case"not_enrolled":return{label:"Not Set Up",title:"No Wallet",description:"Create a wallet to start using Solana.",color:"muted"};case"enrolled_locked":return{label:"Locked",title:"Wallet Locked",description:"Unlock your wallet to sign transactions.",color:"warning"};case"enrolled_unlocked":case"unlocked":return{label:"Ready",title:"Wallet Ready",description:"Your wallet is unlocked and ready to use.",color:"success"};case"error":default:return{label:"Error",title:"Wallet Error",description:t??"An error occurred with your wallet.",color:"error"}}}function nn(s){return s.length<=12?s:`${s.slice(0,4)}...${s.slice(-4)}`}function an({status:s}){switch(s){case"loading":return e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",className:"cedros-spinner",children:[e.jsx("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"2",opacity:"0.25"}),e.jsx("path",{d:"M12 3a9 9 0 0 1 9 9",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]});case"not_enrolled":return e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M8 12h8M12 8v8"})]});case"enrolled_locked":return e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]});case"enrolled_unlocked":case"unlocked":return e.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M20 6L9 17l-5-5"})});case"error":return e.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"}),e.jsx("path",{d:"M12 9v4M12 17h.01"})]});default:return null}}function ln({className:s="",showActions:t=!0}){const o=I.useWallet(),[a,r]=l.useState("status"),n=l.useMemo(()=>{switch(a){case"enroll":return{title:"Create Wallet",description:"Set up your embedded wallet."};case"unlock":return{title:"Unlock Wallet",description:"Unlock to sign transactions."};case"recover_intro":case"recover":return{title:"Recover Wallet",description:"Restore access using your recovery phrase."};case"status":default:return null}},[a]),c=l.useCallback(()=>r("status"),[]),i=l.useCallback(async()=>{r("status"),await o.refresh()},[o]),d=l.useCallback(async()=>{r("status"),await o.refresh()},[o]),h=l.useCallback(async()=>{r("status"),await o.refresh()},[o]);return e.jsxs("div",{className:`cedros-wallet-manager ${s}`,children:[a!=="status"&&n&&e.jsxs("div",{className:"cedros-wallet-manager-header",children:[e.jsxs("div",{className:"cedros-wallet-manager-header-text",children:[e.jsx("h3",{className:"cedros-wallet-manager-title",children:n.title}),e.jsx("p",{className:"cedros-wallet-manager-subtitle",children:n.description})]}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-sm cedros-button-ghost",onClick:c,children:"Back"})]}),a==="status"&&e.jsx(vr,{onEnroll:()=>r("enroll"),onUnlock:()=>r("unlock"),onRecover:()=>r("recover_intro"),showActions:t}),a==="enroll"&&e.jsx(mr,{onComplete:()=>{i()},onCancel:c}),a==="unlock"&&e.jsx(yr,{onUnlock:()=>{d()},onCancel:c}),a==="recover_intro"&&e.jsx("div",{className:"cedros-wallet-manager-intro",children:e.jsxs("div",{className:"cedros-wallet-manager-intro-card",children:[e.jsx("h4",{className:"cedros-wallet-manager-intro-title",children:"Before you start"}),e.jsxs("ul",{className:"cedros-wallet-manager-intro-list",children:[e.jsx("li",{children:"You’ll need your 12-word recovery phrase."}),e.jsx("li",{children:"You’ll set a new password or passkey for this wallet."}),e.jsx("li",{children:"If you’re on a shared device, avoid copying the phrase into other apps."})]}),e.jsxs("div",{className:"cedros-wallet-manager-intro-actions",children:[e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:()=>r("recover"),children:"Start recovery"}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:c,children:"Cancel"})]})]})}),a==="recover"&&e.jsx(Ar,{onComplete:()=>{h()},onCancel:c})]})}function cn({showDescriptions:s=!0,className:t="",onSave:o}){const{settings:a,isLoading:r,isUpdating:n,error:c,fetchSettings:i,updateSettings:d}=Vt.useSystemSettings(),[h,p]=l.useState({}),[f,g]=l.useState(null),[w,m]=l.useState(!1);l.useEffect(()=>{i()},[i]),l.useEffect(()=>{if(w){const S=setTimeout(()=>m(!1),3e3);return()=>clearTimeout(S)}},[w]);const u=l.useCallback((S,x)=>{p(j=>({...j,[S]:x})),g(null),m(!1)},[]),y=l.useCallback(async()=>{const S=Object.entries(h).map(([x,j])=>({key:x,value:j}));if(S.length!==0)try{await d(S),p({}),g(null),m(!0),o?.()}catch(x){g(x instanceof Error?x.message:"Failed to save settings")}},[h,d,o]),A=l.useCallback(()=>{p({}),g(null),m(!1)},[]),b=Object.keys(h).length>0,v=Object.keys(h).length;if(r&&Object.keys(a).length===0)return e.jsxs("div",{className:`cedros-system-settings cedros-system-settings-loading ${t}`,children:[e.jsx(V.LoadingSpinner,{}),e.jsx("span",{children:"Loading settings..."})]});if(c)return e.jsx("div",{className:`cedros-system-settings ${t}`,children:e.jsx(G.ErrorMessage,{error:c.message})});const k=Object.keys(a).sort();return k.length===0?e.jsx("div",{className:`cedros-system-settings cedros-system-settings-empty ${t}`,children:e.jsx("p",{children:"No system settings found."})}):e.jsxs("div",{className:`cedros-system-settings ${t}`,children:[f&&e.jsx(G.ErrorMessage,{error:f}),w&&e.jsx("div",{className:"cedros-settings-success",children:"Settings saved successfully."}),k.map(S=>e.jsx(dn,{category:S,settings:a[S],edits:h,showDescription:s,onChange:u},S)),e.jsxs("div",{className:"cedros-system-settings-actions",children:[b&&e.jsxs("span",{className:"cedros-settings-change-count",children:[v," unsaved change",v!==1?"s":""]}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-secondary",onClick:A,disabled:!b||n,children:"Reset"}),e.jsx("button",{type:"button",className:"cedros-button cedros-button-primary",onClick:y,disabled:!b||n,children:n?e.jsx(V.LoadingSpinner,{size:"sm"}):"Save Changes"})]})]})}const ut=Object.keys(xe.SETTING_METADATA);function dn({category:s,settings:t,edits:o,showDescription:a,onChange:r}){const n=xe.CATEGORY_METADATA[s]||{label:s,description:"",icon:""},c=l.useMemo(()=>[...t].sort((i,d)=>{const h=ut.indexOf(i.key),p=ut.indexOf(d.key);return(h===-1?1/0:h)-(p===-1?1/0:p)}),[t]);return e.jsxs("section",{className:"cedros-settings-section",children:[e.jsxs("div",{className:"cedros-settings-section-header",children:[e.jsx("span",{className:"cedros-settings-section-icon",children:n.icon}),e.jsxs("div",{children:[e.jsx("h3",{className:"cedros-settings-section-title",children:n.label}),a&&n.description&&e.jsx("p",{className:"cedros-settings-section-description",children:n.description})]})]}),e.jsx(xe.SettingsSection,{settings:c,edits:o,onChange:r})]})}class un{client;constructor(t,o,a){this.client=new T.ApiClient({baseUrl:t,timeoutMs:o,retryAttempts:a})}async getStatus(){try{return await this.client.get("/setup/status")}catch(t){throw T.handleApiError(t,"Failed to check setup status")}}async createFirstAdmin(t){try{return await this.client.post("/setup/admin",t)}catch(o){throw T.handleApiError(o,"Failed to create admin account")}}}function Qs(){const{config:s}=T.useCedrosLogin(),[t,o]=l.useState(null),[a,r]=l.useState(!1),[n,c]=l.useState(!1),[i,d]=l.useState(null),h=l.useRef(0),p=l.useMemo(()=>new un(s.serverUrl,s.requestTimeout,s.retryAttempts),[s.serverUrl,s.requestTimeout,s.retryAttempts]),f=l.useRef(p);f.current=p;const g=l.useCallback(async()=>{r(!0),d(null);const m=++h.current;try{const u=await f.current.getStatus();if(m!==h.current)return;o(u)}catch(u){if(m!==h.current)return;d(u instanceof Error?u:new Error("Failed to check setup status"))}finally{m===h.current&&r(!1)}},[]),w=l.useCallback(async m=>{c(!0),d(null);try{const u=await f.current.createFirstAdmin(m);return await g(),u}catch(u){const y=u instanceof Error?u:new Error("Failed to create admin");throw d(y),y}finally{c(!1)}},[g]);return{status:t,isLoading:a,isCreating:n,error:i,checkStatus:g,createAdmin:w}}const hn=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,ht=8;function pn(s){const t={};return s.email?hn.test(s.email)||(t.email="Invalid email format"):t.email="Email is required",s.password?s.password.length<ht&&(t.password=`Password must be at least ${ht} characters`):t.password="Password is required",s.confirmPassword?s.password!==s.confirmPassword&&(t.confirmPassword="Passwords do not match"):t.confirmPassword="Please confirm your password",t}function jr({onComplete:s,className:t=""}){const{status:o,isLoading:a,isCreating:r,error:n,checkStatus:c,createAdmin:i}=Qs(),[d,h]=l.useState({email:"",password:"",confirmPassword:"",name:"",orgName:""}),[p,f]=l.useState({}),[g,w]=l.useState(!1);l.useEffect(()=>{c()},[c]);const m=l.useCallback(y=>A=>{h(b=>({...b,[y]:A.target.value})),f(b=>({...b,[y]:void 0}))},[]),u=l.useCallback(async y=>{y.preventDefault();const A=pn(d);if(Object.keys(A).length>0){f(A);return}try{await i({email:d.email,password:d.password,name:d.name||void 0,orgName:d.orgName||void 0}),w(!0),s?.()}catch{}},[d,i,s]);return a?e.jsx("div",{className:`cedros-setup ${t}`,children:e.jsxs("div",{className:"cedros-setup__loading",children:[e.jsx(V.LoadingSpinner,{}),e.jsx("span",{className:"cedros-setup__loading-text",children:"Checking setup status..."})]})}):o&&!o.needsSetup?e.jsx("div",{className:`cedros-setup ${t}`,children:e.jsxs("div",{className:"cedros-setup__complete",children:[e.jsx("div",{className:"cedros-setup__icon cedros-setup__icon--success",children:e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]})}),e.jsx("h2",{className:"cedros-setup__title",children:"Setup Complete"}),e.jsx("p",{className:"cedros-setup__text",children:"An admin account already exists. You can now log in."})]})}):g?e.jsx("div",{className:`cedros-setup ${t}`,children:e.jsxs("div",{className:"cedros-setup__complete",children:[e.jsx("div",{className:"cedros-setup__icon cedros-setup__icon--success",children:e.jsxs("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]})}),e.jsx("h2",{className:"cedros-setup__title",children:"Admin Account Created"}),e.jsx("p",{className:"cedros-setup__text",children:"Your admin account has been created successfully. You can now log in with your credentials."})]})}):e.jsx("div",{className:`cedros-setup ${t}`,children:e.jsxs("div",{className:"cedros-setup__container",children:[e.jsxs("div",{className:"cedros-setup__header",children:[e.jsx("div",{className:"cedros-setup__logo",children:e.jsxs("svg",{width:"32",height:"32",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"})]})}),e.jsx("h1",{className:"cedros-setup__title",children:"Welcome to Cedros"}),e.jsx("p",{className:"cedros-setup__subtitle",children:"Let's set up your admin account to get started."})]}),e.jsxs("form",{className:"cedros-setup__form",onSubmit:u,children:[n&&e.jsx(G.ErrorMessage,{error:n.message}),e.jsxs("div",{className:"cedros-setup__field",children:[e.jsxs("label",{htmlFor:"setup-email",className:"cedros-setup__label",children:["Email Address ",e.jsx("span",{className:"cedros-setup__required",children:"*"})]}),e.jsx("input",{id:"setup-email",type:"email",className:`cedros-setup__input ${p.email?"cedros-setup__input--error":""}`,value:d.email,onChange:m("email"),placeholder:"admin@example.com",autoComplete:"email",autoFocus:!0,disabled:r}),p.email&&e.jsx("span",{className:"cedros-setup__error",children:p.email})]}),e.jsxs("div",{className:"cedros-setup__field",children:[e.jsx("label",{htmlFor:"setup-name",className:"cedros-setup__label",children:"Display Name"}),e.jsx("input",{id:"setup-name",type:"text",className:"cedros-setup__input",value:d.name,onChange:m("name"),placeholder:"Admin",autoComplete:"name",disabled:r})]}),e.jsxs("div",{className:"cedros-setup__field",children:[e.jsx("label",{htmlFor:"setup-org-name",className:"cedros-setup__label",children:"Organization Name"}),e.jsx("input",{id:"setup-org-name",type:"text",className:"cedros-setup__input",value:d.orgName,onChange:m("orgName"),placeholder:"My Organization",disabled:r})]}),e.jsxs("div",{className:"cedros-setup__field",children:[e.jsxs("label",{htmlFor:"setup-password",className:"cedros-setup__label",children:["Password ",e.jsx("span",{className:"cedros-setup__required",children:"*"})]}),e.jsx("input",{id:"setup-password",type:"password",className:`cedros-setup__input ${p.password?"cedros-setup__input--error":""}`,value:d.password,onChange:m("password"),placeholder:"At least 8 characters",autoComplete:"new-password",disabled:r}),p.password&&e.jsx("span",{className:"cedros-setup__error",children:p.password})]}),e.jsxs("div",{className:"cedros-setup__field",children:[e.jsxs("label",{htmlFor:"setup-confirm-password",className:"cedros-setup__label",children:["Confirm Password ",e.jsx("span",{className:"cedros-setup__required",children:"*"})]}),e.jsx("input",{id:"setup-confirm-password",type:"password",className:`cedros-setup__input ${p.confirmPassword?"cedros-setup__input--error":""}`,value:d.confirmPassword,onChange:m("confirmPassword"),placeholder:"Confirm your password",autoComplete:"new-password",disabled:r}),p.confirmPassword&&e.jsx("span",{className:"cedros-setup__error",children:p.confirmPassword})]}),e.jsx("button",{type:"submit",className:"cedros-setup__button",disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx(V.LoadingSpinner,{}),e.jsx("span",{children:"Creating Account..."})]}):"Create Admin Account"})]}),e.jsxs("div",{className:"cedros-setup__footer",children:[e.jsx("p",{className:"cedros-setup__note",children:"This will be the first administrator account for your installation."}),o?.serverVersion&&e.jsxs("p",{className:"cedros-setup__version",children:["Server version: ",o.serverVersion]})]})]})})}const mn=["security","rate_limit"];function fn({className:s}){return e.jsx(qs.SettingsPageLayout,{title:"Security",description:"Configure CORS, cookies, sessions, JWT, and rate limiting settings.",categories:mn,className:s})}const pt=[{id:"email",label:"Email",category:"email"},{id:"webhooks",label:"Webhooks",category:"webhook"}];function gn({className:s}){const{settings:t,edits:o,isLoading:a,autosaveStatus:r,autosaveError:n,error:c,fetchSettings:i,handleChange:d,getEffectiveValue:h}=xe.useSettingsAutosave(),[p,f]=l.useState("email");l.useEffect(()=>{i()},[i]);const g=pt.find(k=>k.id===p),w=g?.category??"",u=(h("email_provider")||"custom")==="custom",y=h("email_smtp_host"),A=!u||y!=null&&y!=="",b=l.useMemo(()=>{const k=t[w]??[];if(p!=="email")return k;const S=u?Oe.ALL_EMAIL_FIELDS:Oe.SIMPLIFIED_EMAIL_FIELDS;return k.filter(x=>S.includes(x.key)).sort((x,j)=>S.indexOf(x.key)-S.indexOf(j.key))},[t,w,p,u]),v=(k,S)=>{if(d(k,S),k==="email_provider"&&S!=="custom"){const x=Oe.PROVIDER_SMTP_HOSTS[S];x&&(d("email_smtp_host",x),d("email_smtp_port","587"),d("email_smtp_tls","true"))}};return a&&Object.keys(t).length===0?e.jsxs("div",{className:`cedros-system-settings cedros-system-settings-loading ${s??""}`,children:[e.jsx(V.LoadingSpinner,{}),e.jsx("span",{children:"Loading settings..."})]}):c?e.jsx("div",{className:`cedros-system-settings ${s??""}`,children:e.jsx(G.ErrorMessage,{error:c.message})}):e.jsxs("div",{className:`cedros-system-settings ${s??""}`,children:[e.jsxs("div",{className:"cedros-settings-page-header",children:[e.jsxs("div",{className:"cedros-settings-page-header-content",children:[e.jsx("h2",{className:"cedros-settings-page-title",children:"Auth Messages"}),e.jsx("p",{className:"cedros-settings-page-description",children:"Configure email delivery for verification emails, password resets, and instant link login. Webhook notifications can be sent to Discord or Slack."})]}),e.jsx(xe.AutosaveStatus,{status:r,error:n})]}),p==="email"&&!A&&e.jsx("div",{className:"cedros-settings-warning-banner",children:"Email features (verification, password reset, instant link) are disabled until SMTP is configured. Select a provider or enter custom SMTP settings below."}),e.jsx("div",{className:"cedros-admin-tabs cedros-admin-tabs--line",children:pt.map(k=>e.jsx("button",{type:"button",className:`cedros-admin-tab ${p===k.id?"cedros-admin-tab-active":""}`,onClick:()=>f(k.id),"aria-selected":p===k.id,role:"tab",children:k.label},k.id))}),e.jsx("div",{className:"cedros-admin-tab-content",role:"tabpanel",children:b.length===0?e.jsx("div",{className:"cedros-system-settings-empty",children:e.jsxs("p",{children:["No settings found for ",g?.label??"this section","."]})}):e.jsx(xe.SettingsSection,{settings:b,edits:o,onChange:p==="email"?v:d})})]})}const ae={users: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:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),members: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:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),deposits: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:"M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8"}),e.jsx("path",{d:"M12 18V6"})]}),withdrawals: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:"16",height:"20",x:"4",y:"2",rx:"2",ry:"2"}),e.jsx("path",{d:"M9 22v-4h6v4"}),e.jsx("path",{d:"M8 6h.01"}),e.jsx("path",{d:"M16 6h.01"}),e.jsx("path",{d:"M12 6h.01"}),e.jsx("path",{d:"M12 10h.01"}),e.jsx("path",{d:"M12 14h.01"}),e.jsx("path",{d:"M16 10h.01"}),e.jsx("path",{d:"M16 14h.01"}),e.jsx("path",{d:"M8 10h.01"}),e.jsx("path",{d:"M8 14h.01"})]}),wallet: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"})]}),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"})}),key: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:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"})}),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"})]}),coins: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:"8",cy:"8",r:"6"}),e.jsx("path",{d:"M18.09 10.37A6 6 0 1 1 10.34 18"}),e.jsx("path",{d:"M7 6h1v4"}),e.jsx("path",{d:"m16.71 13.88.7.71-2.82 2.82"})]}),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"})]})},wn=[{id:"users",label:"Users",icon:ae.users},{id:"team",label:"Team",icon:ae.members},{id:"deposits",label:"Deposits",icon:ae.deposits,requiredFeature:"credits"},{id:"withdrawals",label:"Withdrawals",icon:ae.withdrawals,requiredFeature:"credits"},{id:"settings-auth",label:"Authentication",icon:ae.key,group:"Configuration"},{id:"settings-messaging",label:"Auth Messages",icon:ae.mail,group:"Configuration"},{id:"settings-wallet",label:"User Wallets",icon:ae.wallet,group:"Configuration"},{id:"settings-credits",label:"Credit System",icon:ae.coins,group:"Configuration",requiredFeature:"credits"},{id:"settings-server",label:"Auth Server",icon:ae.server,group:"Configuration"}];function yn({title:s="Dashboard",sections:t=["users","team","deposits","withdrawals","settings-wallet","settings-auth","settings-messaging","settings-credits","settings-server"],defaultSection:o="users",refreshInterval:a=0,pageSize:r=20,onSectionChange:n,onSettingsClick:c,onLogoutClick:i,className:d=""}){const[h,p]=l.useState(o),[f,g]=l.useState(!0),{user:w,logout:m}=T.useCedrosLogin(),{activeOrg:u,role:y,isLoading:A,fetchOrgs:b,hasPermission:v}=_s.useOrgs(),{status:k,isLoading:S,checkStatus:x}=Qs(),{features:j,isLoading:C}=te.useServerFeatures(),{canAccess:N}=te.useDashboardPermissions(),P=l.useCallback(D=>{p(D),n?.(D)},[n]),L=wn.filter(D=>!(!t.includes(D.id)||D.requiredFeature&&!j[D.requiredFeature]||!N(D.id))),E=L.find(D=>D.id===h),M=!E&&!C;return l.useEffect(()=>{b(),x()},[b,x]),l.useEffect(()=>{M&&L.length>0&&p("users")},[M,L.length]),!S&&k?.needsSetup?e.jsx("div",{className:`cedros-admin cedros-dashboard cedros-dashboard--setup ${d}`,children:e.jsx(jr,{onComplete:()=>x()})}):(A||S||C)&&!u?e.jsxs("div",{className:`cedros-admin cedros-dashboard cedros-dashboard--loading ${d}`,children:[e.jsx(V.LoadingSpinner,{}),e.jsx("span",{className:"cedros-dashboard__loading-text",children:"Loading..."})]}):h==="team"&&!u?e.jsx("div",{className:`cedros-admin cedros-dashboard ${d}`,children:e.jsx(G.ErrorMessage,{error:"No organization selected. Please select an organization first."})}):e.jsxs("div",{className:`cedros-admin cedros-dashboard ${d}`,children:[e.jsxs("aside",{className:"cedros-dashboard__sidebar",children:[e.jsx("div",{className:"cedros-dashboard__sidebar-header",children:e.jsxs("div",{className:"cedros-dashboard__logo",children:[ae.wallet,e.jsx("span",{className:"cedros-dashboard__logo-text",children:s})]})}),e.jsxs("nav",{className:"cedros-dashboard__nav",children:[e.jsxs("div",{className:"cedros-dashboard__nav-group",children:[e.jsx("span",{className:"cedros-dashboard__nav-label",children:"Menu"}),L.filter(D=>!D.group).map(D=>e.jsxs("button",{type:"button",className:`cedros-dashboard__nav-item ${h===D.id?"cedros-dashboard__nav-item--active":""}`,onClick:()=>P(D.id),"aria-current":h===D.id?"page":void 0,children:[e.jsx("span",{className:"cedros-dashboard__nav-icon",children:D.icon}),e.jsx("span",{className:"cedros-dashboard__nav-text",children:D.label})]},D.id))]}),L.some(D=>D.group==="Configuration")&&e.jsxs("div",{className:"cedros-dashboard__nav-group",children:[e.jsxs("button",{type:"button",className:"cedros-dashboard__nav-label cedros-dashboard__nav-label--collapsible",onClick:()=>g(!f),"aria-expanded":f,children:[e.jsx("span",{children:"Configuration"}),e.jsx("span",{className:`cedros-dashboard__nav-chevron ${f?"cedros-dashboard__nav-chevron--expanded":""}`,children:ae.chevronRight})]}),f&&L.filter(D=>D.group==="Configuration").map(D=>e.jsxs("button",{type:"button",className:`cedros-dashboard__nav-item ${h===D.id?"cedros-dashboard__nav-item--active":""}`,onClick:()=>P(D.id),"aria-current":h===D.id?"page":void 0,children:[e.jsx("span",{className:"cedros-dashboard__nav-icon",children:D.icon}),e.jsx("span",{className:"cedros-dashboard__nav-text",children:D.label})]},D.id))]})]}),w&&e.jsx("div",{className:"cedros-dashboard__sidebar-footer",children:e.jsx(ge.ProfileDropdown,{name:w.name,email:w.email,picture:w.picture,onSettings:c,onLogout:i??m})})]}),e.jsxs("main",{className:"cedros-dashboard__main",children:[e.jsx("header",{className:"cedros-dashboard__header",children:e.jsxs("div",{className:"cedros-dashboard__breadcrumb",children:[e.jsx("span",{className:"cedros-dashboard__breadcrumb-root",children:s}),e.jsx("span",{className:"cedros-dashboard__breadcrumb-sep",children:ae.chevronRight}),e.jsx("span",{className:"cedros-dashboard__breadcrumb-current",children:E?.label})]})}),e.jsxs("div",{className:"cedros-dashboard__content",children:[h==="users"&&e.jsx(bn,{pageSize:r,currentUserId:w?.id}),h==="team"&&u&&e.jsx(An,{orgId:u.id,currentUserId:w?.id,hasPermission:v,role:y}),h==="deposits"&&e.jsx(xn,{pageSize:r,refreshInterval:a}),h==="withdrawals"&&e.jsx(vn,{pageSize:r,refreshInterval:a}),h==="settings-auth"&&e.jsx("div",{className:"cedros-dashboard__section",children:e.jsx(Qt.AuthenticationSettings,{})}),h==="settings-wallet"&&e.jsx("div",{className:"cedros-dashboard__section",children:e.jsx(Kt.EmbeddedWalletSettings,{})}),h==="settings-messaging"&&e.jsx("div",{className:"cedros-dashboard__section",children:e.jsx(gn,{})}),h==="settings-credits"&&e.jsx("div",{className:"cedros-dashboard__section",children:e.jsx(Os.CreditSystemSettings,{})}),h==="settings-server"&&e.jsx("div",{className:"cedros-dashboard__section",children:e.jsx(Yt.ServerSettings,{})})]})]})]})}function bn({pageSize:s,currentUserId:t}){const[o,a]=l.useState(null),{statsItems:r,isLoading:n,error:c,refresh:i}=Pe.useUsersStatsSummary();return o?e.jsx("div",{className:"cedros-dashboard__section",children:e.jsx(Pe.AdminUserDetail,{userId:o.id,currentUserId:t,onBack:()=>a(null)})}):e.jsxs("div",{className:"cedros-dashboard__section",children:[e.jsx(Ht.StatsBar,{stats:r,isLoading:n,onRefresh:i}),c&&e.jsx("p",{className:"cedros-admin-error-inline",children:c}),e.jsx(Pe.AdminUserList,{pageSize:s,currentUserId:t,onUserClick:d=>a(d)})]})}function An({orgId:s,currentUserId:t,hasPermission:o,role:a}){const[r,n]=l.useState("members"),{members:c,isLoading:i,error:d,fetchMembers:h,updateMemberRole:p,removeMember:f}=te.useMembers(s),{invites:g,isLoading:w,error:m,fetchInvites:u,createInvite:y,cancelInvite:A,resendInvite:b}=te.useInvites(s);l.useEffect(()=>{h(),u()},[h,u]);const v=o("invite:create"),k=o("invite:cancel"),S=g.length,x=c.reduce((P,L)=>(P[L.role]=(P[L.role]??0)+1,P),{}),j=x.owner??0,C=x.admin??0,N=x.member??0;return e.jsxs("div",{className:"cedros-dashboard__team",children:[e.jsx(Ht.StatsBar,{stats:[{label:"Owners",value:j},{label:"Admins",value:C},{label:"Members",value:N},{label:"Pending Invites",value:S}]}),e.jsxs("div",{className:"cedros-admin-tabs cedros-admin-tabs--line",children:[e.jsx("button",{type:"button",className:`cedros-admin-tab ${r==="members"?"cedros-admin-tab-active":""}`,onClick:()=>n("members"),"aria-selected":r==="members",role:"tab",children:"Members"}),e.jsxs("button",{type:"button",className:`cedros-admin-tab ${r==="invites"?"cedros-admin-tab-active":""}`,onClick:()=>n("invites"),"aria-selected":r==="invites",role:"tab",children:["Pending Invites",S>0&&` (${S})`]}),a==="owner"&&e.jsx("button",{type:"button",className:`cedros-admin-tab ${r==="permissions"?"cedros-admin-tab-active":""}`,onClick:()=>n("permissions"),"aria-selected":r==="permissions",role:"tab",children:"Permissions"})]}),e.jsxs("div",{className:"cedros-admin-tab-content",role:"tabpanel",children:[r==="members"&&e.jsx(te.MemberList,{members:c,currentUserId:t,isLoading:i,error:d?.message,canManage:o("member:remove"),canChangeRoles:o("member:role_change"),onUpdateRole:p,onRemove:f}),r==="invites"&&e.jsxs("div",{className:"cedros-dashboard__invites",children:[v&&e.jsxs("div",{className:"cedros-dashboard__section",children:[e.jsx("div",{className:"cedros-dashboard__section-header",children:e.jsx("h3",{className:"cedros-dashboard__section-title",children:"Send Invitation"})}),e.jsx(te.InviteForm,{onSubmit:y,isLoading:w,error:m?.message})]}),e.jsx("div",{className:"cedros-dashboard__section",children:e.jsx(te.InviteList,{invites:g,isLoading:w,error:m?.message,canManage:k||v,onCancel:k?A:void 0,onResend:v?b:void 0})})]}),r==="permissions"&&a==="owner"&&e.jsx(te.PermissionsSection,{userRole:a})]})]})}function xn({pageSize:s,refreshInterval:t}){const[o,a]=l.useState("");return e.jsxs("div",{className:"cedros-dashboard__deposits",children:[e.jsx(ze.AdminDepositStats,{refreshInterval:t}),e.jsxs("div",{className:"cedros-dashboard__deposits-list",children:[e.jsx("div",{className:"cedros-dashboard__toolbar",children:e.jsxs("div",{className:"cedros-dashboard__filter",children:[e.jsx("label",{className:"cedros-dashboard__filter-label",htmlFor:"status-filter",children:"Status"}),e.jsxs("select",{id:"status-filter",className:"cedros-dashboard__select",value:o,onChange:r=>a(r.target.value),children:[e.jsx("option",{value:"",children:"All statuses"}),e.jsx("option",{value:"pending",children:"Pending"}),e.jsx("option",{value:"detected",children:"Detected"}),e.jsx("option",{value:"processing",children:"Processing"}),e.jsx("option",{value:"completed",children:"Completed"}),e.jsx("option",{value:"withdrawn",children:"Withdrawn"}),e.jsx("option",{value:"expired",children:"Expired"}),e.jsx("option",{value:"failed",children:"Failed"})]})]})}),e.jsx(ze.AdminDepositList,{statusFilter:o||void 0,pageSize:s,refreshInterval:t})]})]})}function vn({pageSize:s,refreshInterval:t}){return e.jsxs("div",{className:"cedros-dashboard__withdrawals",children:[e.jsx(fe.AdminWithdrawalStats,{refreshInterval:t}),e.jsx("p",{className:"cedros-dashboard__text-muted",children:"Track deposits through the withdrawal pipeline: privacy period, ready for processing, and completed."}),e.jsxs("div",{className:"cedros-dashboard__pipeline",children:[e.jsx(fe.AdminPrivacyPeriodDeposits,{pageSize:s,refreshInterval:t}),e.jsx(fe.AdminWithdrawalQueue,{pageSize:s,refreshInterval:t}),e.jsx(fe.AdminWithdrawalHistory,{pageSize:s,refreshInterval:t})]})]})}var Ae={},cs,mt;function jn(){return mt||(mt=1,cs=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),cs}var ds={},me={},ft;function we(){if(ft)return me;ft=1;let s;const t=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return me.getSymbolSize=function(a){if(!a)throw new Error('"version" cannot be null or undefined');if(a<1||a>40)throw new Error('"version" should be in range from 1 to 40');return a*4+17},me.getSymbolTotalCodewords=function(a){return t[a]},me.getBCHDigit=function(o){let a=0;for(;o!==0;)a++,o>>>=1;return a},me.setToSJISFunction=function(a){if(typeof a!="function")throw new Error('"toSJISFunc" is not a valid function.');s=a},me.isKanjiModeEnabled=function(){return typeof s<"u"},me.toSJIS=function(a){return s(a)},me}var us={},gt;function Ks(){return gt||(gt=1,(function(s){s.L={bit:1},s.M={bit:0},s.Q={bit:3},s.H={bit:2};function t(o){if(typeof o!="string")throw new Error("Param is not a string");switch(o.toLowerCase()){case"l":case"low":return s.L;case"m":case"medium":return s.M;case"q":case"quartile":return s.Q;case"h":case"high":return s.H;default:throw new Error("Unknown EC Level: "+o)}}s.isValid=function(a){return a&&typeof a.bit<"u"&&a.bit>=0&&a.bit<4},s.from=function(a,r){if(s.isValid(a))return a;try{return t(a)}catch{return r}}})(us)),us}var hs,wt;function kn(){if(wt)return hs;wt=1;function s(){this.buffer=[],this.length=0}return s.prototype={get:function(t){const o=Math.floor(t/8);return(this.buffer[o]>>>7-t%8&1)===1},put:function(t,o){for(let a=0;a<o;a++)this.putBit((t>>>o-a-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(t){const o=Math.floor(this.length/8);this.buffer.length<=o&&this.buffer.push(0),t&&(this.buffer[o]|=128>>>this.length%8),this.length++}},hs=s,hs}var ps,yt;function Nn(){if(yt)return ps;yt=1;function s(t){if(!t||t<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=t,this.data=new Uint8Array(t*t),this.reservedBit=new Uint8Array(t*t)}return s.prototype.set=function(t,o,a,r){const n=t*this.size+o;this.data[n]=a,r&&(this.reservedBit[n]=!0)},s.prototype.get=function(t,o){return this.data[t*this.size+o]},s.prototype.xor=function(t,o,a){this.data[t*this.size+o]^=a},s.prototype.isReserved=function(t,o){return this.reservedBit[t*this.size+o]},ps=s,ps}var ms={},bt;function Cn(){return bt||(bt=1,(function(s){const t=we().getSymbolSize;s.getRowColCoords=function(a){if(a===1)return[];const r=Math.floor(a/7)+2,n=t(a),c=n===145?26:Math.ceil((n-13)/(2*r-2))*2,i=[n-7];for(let d=1;d<r-1;d++)i[d]=i[d-1]-c;return i.push(6),i.reverse()},s.getPositions=function(a){const r=[],n=s.getRowColCoords(a),c=n.length;for(let i=0;i<c;i++)for(let d=0;d<c;d++)i===0&&d===0||i===0&&d===c-1||i===c-1&&d===0||r.push([n[i],n[d]]);return r}})(ms)),ms}var fs={},At;function Sn(){if(At)return fs;At=1;const s=we().getSymbolSize,t=7;return fs.getPositions=function(a){const r=s(a);return[[0,0],[r-t,0],[0,r-t]]},fs}var gs={},xt;function En(){return xt||(xt=1,(function(s){s.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const t={N1:3,N2:3,N3:40,N4:10};s.isValid=function(r){return r!=null&&r!==""&&!isNaN(r)&&r>=0&&r<=7},s.from=function(r){return s.isValid(r)?parseInt(r,10):void 0},s.getPenaltyN1=function(r){const n=r.size;let c=0,i=0,d=0,h=null,p=null;for(let f=0;f<n;f++){i=d=0,h=p=null;for(let g=0;g<n;g++){let w=r.get(f,g);w===h?i++:(i>=5&&(c+=t.N1+(i-5)),h=w,i=1),w=r.get(g,f),w===p?d++:(d>=5&&(c+=t.N1+(d-5)),p=w,d=1)}i>=5&&(c+=t.N1+(i-5)),d>=5&&(c+=t.N1+(d-5))}return c},s.getPenaltyN2=function(r){const n=r.size;let c=0;for(let i=0;i<n-1;i++)for(let d=0;d<n-1;d++){const h=r.get(i,d)+r.get(i,d+1)+r.get(i+1,d)+r.get(i+1,d+1);(h===4||h===0)&&c++}return c*t.N2},s.getPenaltyN3=function(r){const n=r.size;let c=0,i=0,d=0;for(let h=0;h<n;h++){i=d=0;for(let p=0;p<n;p++)i=i<<1&2047|r.get(h,p),p>=10&&(i===1488||i===93)&&c++,d=d<<1&2047|r.get(p,h),p>=10&&(d===1488||d===93)&&c++}return c*t.N3},s.getPenaltyN4=function(r){let n=0;const c=r.data.length;for(let d=0;d<c;d++)n+=r.data[d];return Math.abs(Math.ceil(n*100/c/5)-10)*t.N4};function o(a,r,n){switch(a){case s.Patterns.PATTERN000:return(r+n)%2===0;case s.Patterns.PATTERN001:return r%2===0;case s.Patterns.PATTERN010:return n%3===0;case s.Patterns.PATTERN011:return(r+n)%3===0;case s.Patterns.PATTERN100:return(Math.floor(r/2)+Math.floor(n/3))%2===0;case s.Patterns.PATTERN101:return r*n%2+r*n%3===0;case s.Patterns.PATTERN110:return(r*n%2+r*n%3)%2===0;case s.Patterns.PATTERN111:return(r*n%3+(r+n)%2)%2===0;default:throw new Error("bad maskPattern:"+a)}}s.applyMask=function(r,n){const c=n.size;for(let i=0;i<c;i++)for(let d=0;d<c;d++)n.isReserved(d,i)||n.xor(d,i,o(r,d,i))},s.getBestMask=function(r,n){const c=Object.keys(s.Patterns).length;let i=0,d=1/0;for(let h=0;h<c;h++){n(h),s.applyMask(h,r);const p=s.getPenaltyN1(r)+s.getPenaltyN2(r)+s.getPenaltyN3(r)+s.getPenaltyN4(r);s.applyMask(h,r),p<d&&(d=p,i=h)}return i}})(gs)),gs}var We={},vt;function kr(){if(vt)return We;vt=1;const s=Ks(),t=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],o=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return We.getBlocksCount=function(r,n){switch(n){case s.L:return t[(r-1)*4+0];case s.M:return t[(r-1)*4+1];case s.Q:return t[(r-1)*4+2];case s.H:return t[(r-1)*4+3];default:return}},We.getTotalCodewordsCount=function(r,n){switch(n){case s.L:return o[(r-1)*4+0];case s.M:return o[(r-1)*4+1];case s.Q:return o[(r-1)*4+2];case s.H:return o[(r-1)*4+3];default:return}},We}var ws={},Le={},jt;function Ln(){if(jt)return Le;jt=1;const s=new Uint8Array(512),t=new Uint8Array(256);return(function(){let a=1;for(let r=0;r<255;r++)s[r]=a,t[a]=r,a<<=1,a&256&&(a^=285);for(let r=255;r<512;r++)s[r]=s[r-255]})(),Le.log=function(a){if(a<1)throw new Error("log("+a+")");return t[a]},Le.exp=function(a){return s[a]},Le.mul=function(a,r){return a===0||r===0?0:s[t[a]+t[r]]},Le}var kt;function Pn(){return kt||(kt=1,(function(s){const t=Ln();s.mul=function(a,r){const n=new Uint8Array(a.length+r.length-1);for(let c=0;c<a.length;c++)for(let i=0;i<r.length;i++)n[c+i]^=t.mul(a[c],r[i]);return n},s.mod=function(a,r){let n=new Uint8Array(a);for(;n.length-r.length>=0;){const c=n[0];for(let d=0;d<r.length;d++)n[d]^=t.mul(r[d],c);let i=0;for(;i<n.length&&n[i]===0;)i++;n=n.slice(i)}return n},s.generateECPolynomial=function(a){let r=new Uint8Array([1]);for(let n=0;n<a;n++)r=s.mul(r,new Uint8Array([1,t.exp(n)]));return r}})(ws)),ws}var ys,Nt;function Mn(){if(Nt)return ys;Nt=1;const s=Pn();function t(o){this.genPoly=void 0,this.degree=o,this.degree&&this.initialize(this.degree)}return t.prototype.initialize=function(a){this.degree=a,this.genPoly=s.generateECPolynomial(this.degree)},t.prototype.encode=function(a){if(!this.genPoly)throw new Error("Encoder not initialized");const r=new Uint8Array(a.length+this.degree);r.set(a);const n=s.mod(r,this.genPoly),c=this.degree-n.length;if(c>0){const i=new Uint8Array(this.degree);return i.set(n,c),i}return n},ys=t,ys}var bs={},As={},xs={},Ct;function Nr(){return Ct||(Ct=1,xs.isValid=function(t){return!isNaN(t)&&t>=1&&t<=40}),xs}var de={},St;function Cr(){if(St)return de;St=1;const s="[0-9]+",t="[A-Z $%*+\\-./:]+";let o="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";o=o.replace(/u/g,"\\u");const a="(?:(?![A-Z0-9 $%*+\\-./:]|"+o+`)(?:.|[\r
2050
2050
  ]))+`;de.KANJI=new RegExp(o,"g"),de.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),de.BYTE=new RegExp(a,"g"),de.NUMERIC=new RegExp(s,"g"),de.ALPHANUMERIC=new RegExp(t,"g");const r=new RegExp("^"+o+"$"),n=new RegExp("^"+s+"$"),c=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return de.testKanji=function(d){return r.test(d)},de.testNumeric=function(d){return n.test(d)},de.testAlphanumeric=function(d){return c.test(d)},de}var Et;function ye(){return Et||(Et=1,(function(s){const t=Nr(),o=Cr();s.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},s.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},s.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},s.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},s.MIXED={bit:-1},s.getCharCountIndicator=function(n,c){if(!n.ccBits)throw new Error("Invalid mode: "+n);if(!t.isValid(c))throw new Error("Invalid version: "+c);return c>=1&&c<10?n.ccBits[0]:c<27?n.ccBits[1]:n.ccBits[2]},s.getBestModeForData=function(n){return o.testNumeric(n)?s.NUMERIC:o.testAlphanumeric(n)?s.ALPHANUMERIC:o.testKanji(n)?s.KANJI:s.BYTE},s.toString=function(n){if(n&&n.id)return n.id;throw new Error("Invalid mode")},s.isValid=function(n){return n&&n.bit&&n.ccBits};function a(r){if(typeof r!="string")throw new Error("Param is not a string");switch(r.toLowerCase()){case"numeric":return s.NUMERIC;case"alphanumeric":return s.ALPHANUMERIC;case"kanji":return s.KANJI;case"byte":return s.BYTE;default:throw new Error("Unknown mode: "+r)}}s.from=function(n,c){if(s.isValid(n))return n;try{return a(n)}catch{return c}}})(As)),As}var Lt;function Tn(){return Lt||(Lt=1,(function(s){const t=we(),o=kr(),a=Ks(),r=ye(),n=Nr(),c=7973,i=t.getBCHDigit(c);function d(g,w,m){for(let u=1;u<=40;u++)if(w<=s.getCapacity(u,m,g))return u}function h(g,w){return r.getCharCountIndicator(g,w)+4}function p(g,w){let m=0;return g.forEach(function(u){const y=h(u.mode,w);m+=y+u.getBitsLength()}),m}function f(g,w){for(let m=1;m<=40;m++)if(p(g,m)<=s.getCapacity(m,w,r.MIXED))return m}s.from=function(w,m){return n.isValid(w)?parseInt(w,10):m},s.getCapacity=function(w,m,u){if(!n.isValid(w))throw new Error("Invalid QR Code version");typeof u>"u"&&(u=r.BYTE);const y=t.getSymbolTotalCodewords(w),A=o.getTotalCodewordsCount(w,m),b=(y-A)*8;if(u===r.MIXED)return b;const v=b-h(u,w);switch(u){case r.NUMERIC:return Math.floor(v/10*3);case r.ALPHANUMERIC:return Math.floor(v/11*2);case r.KANJI:return Math.floor(v/13);case r.BYTE:default:return Math.floor(v/8)}},s.getBestVersionForData=function(w,m){let u;const y=a.from(m,a.M);if(Array.isArray(w)){if(w.length>1)return f(w,y);if(w.length===0)return 1;u=w[0]}else u=w;return d(u.mode,u.getLength(),y)},s.getEncodedBits=function(w){if(!n.isValid(w)||w<7)throw new Error("Invalid QR Code version");let m=w<<12;for(;t.getBCHDigit(m)-i>=0;)m^=c<<t.getBCHDigit(m)-i;return w<<12|m}})(bs)),bs}var vs={},Pt;function Bn(){if(Pt)return vs;Pt=1;const s=we(),t=1335,o=21522,a=s.getBCHDigit(t);return vs.getEncodedBits=function(n,c){const i=n.bit<<3|c;let d=i<<10;for(;s.getBCHDigit(d)-a>=0;)d^=t<<s.getBCHDigit(d)-a;return(i<<10|d)^o},vs}var js={},ks,Mt;function Rn(){if(Mt)return ks;Mt=1;const s=ye();function t(o){this.mode=s.NUMERIC,this.data=o.toString()}return t.getBitsLength=function(a){return 10*Math.floor(a/3)+(a%3?a%3*3+1:0)},t.prototype.getLength=function(){return this.data.length},t.prototype.getBitsLength=function(){return t.getBitsLength(this.data.length)},t.prototype.write=function(a){let r,n,c;for(r=0;r+3<=this.data.length;r+=3)n=this.data.substr(r,3),c=parseInt(n,10),a.put(c,10);const i=this.data.length-r;i>0&&(n=this.data.substr(r),c=parseInt(n,10),a.put(c,i*3+1))},ks=t,ks}var Ns,Tt;function Dn(){if(Tt)return Ns;Tt=1;const s=ye(),t=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function o(a){this.mode=s.ALPHANUMERIC,this.data=a}return o.getBitsLength=function(r){return 11*Math.floor(r/2)+6*(r%2)},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.prototype.write=function(r){let n;for(n=0;n+2<=this.data.length;n+=2){let c=t.indexOf(this.data[n])*45;c+=t.indexOf(this.data[n+1]),r.put(c,11)}this.data.length%2&&r.put(t.indexOf(this.data[n]),6)},Ns=o,Ns}var Cs,Bt;function In(){if(Bt)return Cs;Bt=1;const s=ye();function t(o){this.mode=s.BYTE,typeof o=="string"?this.data=new TextEncoder().encode(o):this.data=new Uint8Array(o)}return t.getBitsLength=function(a){return a*8},t.prototype.getLength=function(){return this.data.length},t.prototype.getBitsLength=function(){return t.getBitsLength(this.data.length)},t.prototype.write=function(o){for(let a=0,r=this.data.length;a<r;a++)o.put(this.data[a],8)},Cs=t,Cs}var Ss,Rt;function Fn(){if(Rt)return Ss;Rt=1;const s=ye(),t=we();function o(a){this.mode=s.KANJI,this.data=a}return o.getBitsLength=function(r){return r*13},o.prototype.getLength=function(){return this.data.length},o.prototype.getBitsLength=function(){return o.getBitsLength(this.data.length)},o.prototype.write=function(a){let r;for(r=0;r<this.data.length;r++){let n=t.toSJIS(this.data[r]);if(n>=33088&&n<=40956)n-=33088;else if(n>=57408&&n<=60351)n-=49472;else throw new Error("Invalid SJIS character: "+this.data[r]+`
2051
2051
  Make sure your charset is UTF-8`);n=(n>>>8&255)*192+(n&255),a.put(n,13)}},Ss=o,Ss}var Es={exports:{}},Dt;function Un(){return Dt||(Dt=1,(function(s){var t={single_source_shortest_paths:function(o,a,r){var n={},c={};c[a]=0;var i=t.PriorityQueue.make();i.push(a,0);for(var d,h,p,f,g,w,m,u,y;!i.empty();){d=i.pop(),h=d.value,f=d.cost,g=o[h]||{};for(p in g)g.hasOwnProperty(p)&&(w=g[p],m=f+w,u=c[p],y=typeof c[p]>"u",(y||u>m)&&(c[p]=m,i.push(p,m),n[p]=h))}if(typeof r<"u"&&typeof c[r]>"u"){var A=["Could not find a path from ",a," to ",r,"."].join("");throw new Error(A)}return n},extract_shortest_path_from_predecessor_list:function(o,a){for(var r=[],n=a;n;)r.push(n),o[n],n=o[n];return r.reverse(),r},find_path:function(o,a,r){var n=t.single_source_shortest_paths(o,a,r);return t.extract_shortest_path_from_predecessor_list(n,r)},PriorityQueue:{make:function(o){var a=t.PriorityQueue,r={},n;o=o||{};for(n in a)a.hasOwnProperty(n)&&(r[n]=a[n]);return r.queue=[],r.sorter=o.sorter||a.default_sorter,r},default_sorter:function(o,a){return o.cost-a.cost},push:function(o,a){var r={value:o,cost:a};this.queue.push(r),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};s.exports=t})(Es)),Es.exports}var It;function Wn(){return It||(It=1,(function(s){const t=ye(),o=Rn(),a=Dn(),r=In(),n=Fn(),c=Cr(),i=we(),d=Un();function h(A){return unescape(encodeURIComponent(A)).length}function p(A,b,v){const k=[];let S;for(;(S=A.exec(v))!==null;)k.push({data:S[0],index:S.index,mode:b,length:S[0].length});return k}function f(A){const b=p(c.NUMERIC,t.NUMERIC,A),v=p(c.ALPHANUMERIC,t.ALPHANUMERIC,A);let k,S;return i.isKanjiModeEnabled()?(k=p(c.BYTE,t.BYTE,A),S=p(c.KANJI,t.KANJI,A)):(k=p(c.BYTE_KANJI,t.BYTE,A),S=[]),b.concat(v,k,S).sort(function(j,C){return j.index-C.index}).map(function(j){return{data:j.data,mode:j.mode,length:j.length}})}function g(A,b){switch(b){case t.NUMERIC:return o.getBitsLength(A);case t.ALPHANUMERIC:return a.getBitsLength(A);case t.KANJI:return n.getBitsLength(A);case t.BYTE:return r.getBitsLength(A)}}function w(A){return A.reduce(function(b,v){const k=b.length-1>=0?b[b.length-1]:null;return k&&k.mode===v.mode?(b[b.length-1].data+=v.data,b):(b.push(v),b)},[])}function m(A){const b=[];for(let v=0;v<A.length;v++){const k=A[v];switch(k.mode){case t.NUMERIC:b.push([k,{data:k.data,mode:t.ALPHANUMERIC,length:k.length},{data:k.data,mode:t.BYTE,length:k.length}]);break;case t.ALPHANUMERIC:b.push([k,{data:k.data,mode:t.BYTE,length:k.length}]);break;case t.KANJI:b.push([k,{data:k.data,mode:t.BYTE,length:h(k.data)}]);break;case t.BYTE:b.push([{data:k.data,mode:t.BYTE,length:h(k.data)}])}}return b}function u(A,b){const v={},k={start:{}};let S=["start"];for(let x=0;x<A.length;x++){const j=A[x],C=[];for(let N=0;N<j.length;N++){const P=j[N],L=""+x+N;C.push(L),v[L]={node:P,lastCount:0},k[L]={};for(let E=0;E<S.length;E++){const M=S[E];v[M]&&v[M].node.mode===P.mode?(k[M][L]=g(v[M].lastCount+P.length,P.mode)-g(v[M].lastCount,P.mode),v[M].lastCount+=P.length):(v[M]&&(v[M].lastCount=P.length),k[M][L]=g(P.length,P.mode)+4+t.getCharCountIndicator(P.mode,b))}}S=C}for(let x=0;x<S.length;x++)k[S[x]].end=0;return{map:k,table:v}}function y(A,b){let v;const k=t.getBestModeForData(A);if(v=t.from(b,k),v!==t.BYTE&&v.bit<k.bit)throw new Error('"'+A+'" cannot be encoded with mode '+t.toString(v)+`.
2052
2052
  Suggested mode is: `+t.toString(k));switch(v===t.KANJI&&!i.isKanjiModeEnabled()&&(v=t.BYTE),v){case t.NUMERIC:return new o(A);case t.ALPHANUMERIC:return new a(A);case t.KANJI:return new n(A);case t.BYTE:return new r(A)}}s.fromArray=function(b){return b.reduce(function(v,k){return typeof k=="string"?v.push(y(k,null)):k.data&&v.push(y(k.data,k.mode)),v},[])},s.fromString=function(b,v){const k=f(b,i.isKanjiModeEnabled()),S=m(k),x=u(S,v),j=d.find_path(x.map,"start","end"),C=[];for(let N=1;N<j.length-1;N++)C.push(x.table[j[N]].node);return s.fromArray(w(C))},s.rawSplit=function(b){return s.fromArray(f(b,i.isKanjiModeEnabled()))}})(js)),js}var Ft;function _n(){if(Ft)return ds;Ft=1;const s=we(),t=Ks(),o=kn(),a=Nn(),r=Cn(),n=Sn(),c=En(),i=kr(),d=Mn(),h=Tn(),p=Bn(),f=ye(),g=Wn();function w(x,j){const C=x.size,N=n.getPositions(j);for(let P=0;P<N.length;P++){const L=N[P][0],E=N[P][1];for(let M=-1;M<=7;M++)if(!(L+M<=-1||C<=L+M))for(let B=-1;B<=7;B++)E+B<=-1||C<=E+B||(M>=0&&M<=6&&(B===0||B===6)||B>=0&&B<=6&&(M===0||M===6)||M>=2&&M<=4&&B>=2&&B<=4?x.set(L+M,E+B,!0,!0):x.set(L+M,E+B,!1,!0))}}function m(x){const j=x.size;for(let C=8;C<j-8;C++){const N=C%2===0;x.set(C,6,N,!0),x.set(6,C,N,!0)}}function u(x,j){const C=r.getPositions(j);for(let N=0;N<C.length;N++){const P=C[N][0],L=C[N][1];for(let E=-2;E<=2;E++)for(let M=-2;M<=2;M++)E===-2||E===2||M===-2||M===2||E===0&&M===0?x.set(P+E,L+M,!0,!0):x.set(P+E,L+M,!1,!0)}}function y(x,j){const C=x.size,N=h.getEncodedBits(j);let P,L,E;for(let M=0;M<18;M++)P=Math.floor(M/3),L=M%3+C-8-3,E=(N>>M&1)===1,x.set(P,L,E,!0),x.set(L,P,E,!0)}function A(x,j,C){const N=x.size,P=p.getEncodedBits(j,C);let L,E;for(L=0;L<15;L++)E=(P>>L&1)===1,L<6?x.set(L,8,E,!0):L<8?x.set(L+1,8,E,!0):x.set(N-15+L,8,E,!0),L<8?x.set(8,N-L-1,E,!0):L<9?x.set(8,15-L-1+1,E,!0):x.set(8,15-L-1,E,!0);x.set(N-8,8,1,!0)}function b(x,j){const C=x.size;let N=-1,P=C-1,L=7,E=0;for(let M=C-1;M>0;M-=2)for(M===6&&M--;;){for(let B=0;B<2;B++)if(!x.isReserved(P,M-B)){let D=!1;E<j.length&&(D=(j[E]>>>L&1)===1),x.set(P,M-B,D),L--,L===-1&&(E++,L=7)}if(P+=N,P<0||C<=P){P-=N,N=-N;break}}}function v(x,j,C){const N=new o;C.forEach(function(B){N.put(B.mode.bit,4),N.put(B.getLength(),f.getCharCountIndicator(B.mode,x)),B.write(N)});const P=s.getSymbolTotalCodewords(x),L=i.getTotalCodewordsCount(x,j),E=(P-L)*8;for(N.getLengthInBits()+4<=E&&N.put(0,4);N.getLengthInBits()%8!==0;)N.putBit(0);const M=(E-N.getLengthInBits())/8;for(let B=0;B<M;B++)N.put(B%2?17:236,8);return k(N,x,j)}function k(x,j,C){const N=s.getSymbolTotalCodewords(j),P=i.getTotalCodewordsCount(j,C),L=N-P,E=i.getBlocksCount(j,C),M=N%E,B=E-M,D=Math.floor(N/E),$=Math.floor(L/E),le=$+1,J=D-$,q=new d(J);let R=0;const F=new Array(E),z=new Array(E);let X=0;const ee=new Uint8Array(x.buffer);for(let Q=0;Q<E;Q++){const ne=Q<B?$:le;F[Q]=ee.slice(R,R+ne),z[Q]=q.encode(F[Q]),R+=ne,X=Math.max(X,ne)}const ue=new Uint8Array(N);let ce=0,_,W;for(_=0;_<X;_++)for(W=0;W<E;W++)_<F[W].length&&(ue[ce++]=F[W][_]);for(_=0;_<J;_++)for(W=0;W<E;W++)ue[ce++]=z[W][_];return ue}function S(x,j,C,N){let P;if(Array.isArray(x))P=g.fromArray(x);else if(typeof x=="string"){let D=j;if(!D){const $=g.rawSplit(x);D=h.getBestVersionForData($,C)}P=g.fromString(x,D||40)}else throw new Error("Invalid data");const L=h.getBestVersionForData(P,C);if(!L)throw new Error("The amount of data is too big to be stored in a QR Code");if(!j)j=L;else if(j<L)throw new Error(`