@qwanyx/stack 0.2.10 → 0.2.12

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.
@@ -78,6 +78,11 @@ export declare class MailClient {
78
78
  success: boolean;
79
79
  folders: FolderInfo[];
80
80
  }>;
81
+ /**
82
+ * List emails using passthrough (imapExec) with client-side sorting
83
+ * This is the preferred method - all logic in TypeScript, backend is just a proxy
84
+ */
85
+ listEmailsSorted(accountId: string, folder?: string, limit?: number): Promise<MailListResult>;
81
86
  /**
82
87
  * Get a single email by UID with full body content
83
88
  */
package/dist/index.cjs.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var wt=Object.defineProperty;var _t=(p,t,r)=>t in p?wt(p,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):p[t]=r;var fe=(p,t,r)=>_t(p,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react");class jt{constructor(t){fe(this,"config");fe(this,"defaultUploadOptions",{maxSizeMB:10,maxImageDimension:0,imageQuality:.9});if(!t.system_id)throw new Error("GraphClient: system_id is REQUIRED. No system_id → No start.");this.config=t}async callGraph(t,r={}){const n={coprocessor:"graph",method:t,system_id:this.config.system_id,params:r};try{const o=await fetch(`${this.config.baseUrl}/spu/invoke`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.getToken()}`},body:JSON.stringify(n)});if(!o.ok){const l=await o.text();throw new Error(`API error (${o.status}): ${l}`)}const s=await o.json();if(!s.success&&s.error)throw new Error(s.error);return s}catch(o){throw console.error("Graph API call failed:",o),o}}getToken(){return typeof window<"u"&&window.localStorage&&localStorage.getItem("qwanyx_token")||""}async getChildren(t){return(await this.callGraph("get_children",{parent_id:t})).result||[]}async getNode(t){return(await this.callGraph("get_node",{node_id:t})).result||null}async addNode(t){const r={...t,created:t.created||new Date().toISOString(),modified:new Date().toISOString()},n=await this.callGraph("add_node",r);if(!n.result)throw new Error("Failed to add node");return n.result}async updateNode(t,r){const n={node_id:t,updates:{...r,modified:new Date().toISOString()}},o=await this.callGraph("update_node",n);if(!o.result)throw new Error("Failed to update node");return o.result}async deleteNode(t,r=!1){return(await this.callGraph("delete_node",{node_id:t,cascade:r})).success===!0}async getChildrenWithEdges(t,r="children",n,o){return(await this.callGraph("get_children_with_edges",{node_id:t,display_mode:r,edge_type:n,node_type:o})).result||[]}async addEdge(t,r,n="link",o){return await this.callGraph("add_edge",{source_id:t,target_id:r,edge_type:n,data:o})}async deleteEdge(t,r,n){return await this.callGraph("delete_edge",{source_id:t,target_id:r,edge_type:n})}async getEdges(t,r,n){return(await this.callGraph("get_edges",{source_id:t,edge_type:r,target_id:n})).result||[]}async getAncestors(t){return(await this.callGraph("get_ancestors",{node_id:t})).ancestors||[]}async getTree(t,r=10){return(await this.callGraph("get_tree",{root_id:t,max_depth:r})).tree||[]}async moveNode(t,r){const n=await this.callGraph("move",{node_id:t,new_parent_id:r});if(!n.node)throw new Error("Failed to move node");return n.node}async searchNodes(t,r){return(await this.callGraph("search",{query:t,type:r})).nodes||[]}async getNodesByType(t){return(await this.callGraph("get_nodes_by_type",{type:t})).result||[]}fileToBase64(t){return new Promise((r,n)=>{const o=new FileReader;o.onload=()=>{const l=o.result.split(",")[1];r(l)},o.onerror=()=>n(new Error("Failed to read file")),o.readAsDataURL(t)})}async resizeImage(t,r,n){return t.type.startsWith("image/")?new Promise(o=>{const s=new Image,l=URL.createObjectURL(t);s.onload=()=>{if(URL.revokeObjectURL(l),s.width<=r&&s.height<=r){o(t);return}let h,u;s.width>s.height?(h=r,u=Math.round(s.height/s.width*r)):(u=r,h=Math.round(s.width/s.height*r));const g=document.createElement("canvas");g.width=h,g.height=u;const d=g.getContext("2d");if(!d){o(t);return}d.drawImage(s,0,0,h,u);const k=t.type==="image/png"?"image/png":"image/jpeg";g.toBlob(x=>{if(x){const P=new File([x],t.name,{type:k});o(P)}else o(t)},k,n)},s.onerror=()=>{URL.revokeObjectURL(l),o(t)},s.src=l}):t}async uploadFile(t,r,n,o={}){const s={...this.defaultUploadOptions,...o};try{let l=n;s.maxImageDimension>0&&n.type.startsWith("image/")&&(l=await this.resizeImage(n,s.maxImageDimension,s.imageQuality));const h=s.maxSizeMB*1024*1024;if(l.size>h)return{success:!1,error:`File too large (${(l.size/1024/1024).toFixed(1)} MB). Max: ${s.maxSizeMB} MB`};const u=await this.fileToBase64(l),g=await this.callGraph("upload_file",{node_id:t,filename:r,content:u});return g.success?{success:!0,path:g.path}:{success:!1,error:g.error||"Upload failed"}}catch(l){return{success:!1,error:l instanceof Error?l.message:"Upload failed"}}}async listFiles(t){var o;return(((o=(await this.callGraph("list_files",{node_id:t})).result)==null?void 0:o.files)||[]).map(s=>({filename:s.name,path:s.path}))}async deleteFile(t,r){return{success:(await this.callGraph("delete_file",{node_id:t,filename:r})).success||!1}}getFileUrl(t,r){return`${this.config.baseUrl}/files/${this.config.system_id}/${t}/${r}`}}class Ze{constructor(t){fe(this,"config");if(!t.system_id)throw new Error("MailClient: system_id is REQUIRED");this.config=t}async callCoprocessor(t,r,n={}){const o={coprocessor:t,method:r,system_id:this.config.system_id,params:{user_id:this.config.system_id,...n}};try{const s=await fetch(`${this.config.baseUrl}/spu/invoke`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.getToken()}`},body:JSON.stringify(o)});if(!s.ok){const h=await s.text();throw new Error(`API error (${s.status}): ${h}`)}const l=await s.json();if(!l.success&&l.error)throw new Error(l.error);return l.result}catch(s){throw console.error("API call failed:",s),s}}async callMail(t,r={}){return this.callCoprocessor("mail",t,r)}async callEmail(t,r={}){return this.callCoprocessor("email",t,r)}getToken(){return typeof window<"u"&&window.localStorage&&localStorage.getItem("qwanyx_token")||""}async getSettings(){try{return await this.callMail("get_email_settings")||{accounts:[]}}catch{return{accounts:[]}}}async saveSettings(t){await this.callMail("save_email_settings",{accounts:t})}async listEmails(t,r=20,n){return this.callMail("list_emails",{account_id:t,limit:r,folder:n})}async deleteEmails(t,r,n=!0){return this.callMail("delete_emails",{account_id:t,uids:r,expunge:n})}async imapExec(t,r){return this.callMail("imap_exec",{account_id:t,commands:r})}async trashEmails(t,r){const n=["[Gmail]/Trash","[Gmail]/Corbeille","[Gmail]/Bin","Trash"];for(const o of n){const s=["SELECT INBOX",...r.map(u=>`UID MOVE ${u} ${o}`)],h=(await this.imapExec(t,s)).responses.filter(u=>u.ok&&u.command==="UID MOVE").length;if(h>0)return{success:!0,moved:h}}return{success:!1,moved:0}}async archiveEmails(t,r){const n=["SELECT INBOX",...r.map(l=>`UID STORE ${l} +FLAGS (\\Deleted)`),"EXPUNGE"],s=(await this.imapExec(t,n)).responses.filter(l=>l.ok&&l.command==="UID STORE").length;return{success:s>0,archived:s}}async listFolders(t){const n=(await this.imapExec(t,['LIST "" *'])).responses.find(o=>o.command==="LIST");return n!=null&&n.ok&&n.folders?{success:!0,folders:n.folders}:{success:!1,folders:[]}}async getEmail(t,r){return this.callMail("get_email",{account_id:t,uid:r})}async sendMail(t){const r={to:t.to,subject:t.subject,body:t.body};return t.html&&(r.html=t.html),t.from&&(r.from=t.from),t.smtpConfig&&(r.smtp_config=t.smtpConfig),this.callEmail("send",r)}}const Me="qwanyx_auth_token",De="qwanyx_refresh_token";class et{static setToken(t){typeof window<"u"&&localStorage.setItem(Me,t)}static getToken(){return typeof window<"u"?localStorage.getItem(Me):null}static clearToken(){typeof window<"u"&&(localStorage.removeItem(Me),localStorage.removeItem(De))}static setRefreshToken(t){typeof window<"u"&&localStorage.setItem(De,t)}static getRefreshToken(){return typeof window<"u"?localStorage.getItem(De):null}static isAuthenticated(){return!!this.getToken()}static getAuthHeader(){const t=this.getToken();return t?{Authorization:`Bearer ${t}`}:{}}}class tt{constructor(t){fe(this,"config");this.config={timeout:3e4,headers:{"Content-Type":"application/json"},...t}}buildQueryString(t){if(!t||Object.keys(t).length===0)return"";const r=new URLSearchParams;Object.entries(t).forEach(([o,s])=>{s!=null&&r.append(o,String(s))});const n=r.toString();return n?`?${n}`:""}async request(t,r={}){const{method:n="GET",headers:o={},body:s,params:l}=r,h=`${this.config.baseUrl}/${t}${this.buildQueryString(l)}`,u={...this.config.headers,...et.getAuthHeader(),...o},g={method:n,headers:u};s&&n!=="GET"&&(g.body=JSON.stringify(s));try{const d=new AbortController,k=setTimeout(()=>d.abort(),this.config.timeout),x=await fetch(h,{...g,signal:d.signal});if(clearTimeout(k),!x.ok){const P=await x.json().catch(()=>({message:x.statusText}));throw new Error(P.message||`HTTP ${x.status}`)}return await x.json()}catch(d){throw d instanceof Error?d:new Error("An unexpected error occurred")}}async get(t,r){return this.request(t,{method:"GET",params:r})}async post(t,r,n){return this.request(t,{method:"POST",body:r,params:n})}async put(t,r,n){return this.request(t,{method:"PUT",body:r,params:n})}async patch(t,r,n){return this.request(t,{method:"PATCH",body:r,params:n})}async delete(t,r){return this.request(t,{method:"DELETE",params:r})}setBaseUrl(t){this.config.baseUrl=t}getBaseUrl(){return this.config.baseUrl}}let Se=null;function Et(p){return Se=new tt(p),Se}function Ie(){if(!Se)throw new Error("API client not initialized. Call initializeApiClient() first.");return Se}function rt(p,t,r={}){const{enabled:n=!0,refetchOnMount:o=!0,onSuccess:s,onError:l}=r,[h,u]=b.useState(null),[g,d]=b.useState(n),[k,x]=b.useState(null),P=b.useCallback(async()=>{if(n){d(!0),x(null);try{const T=await Ie().get(p,t);u(T),s==null||s(T)}catch(A){const T=A instanceof Error?A:new Error("Unknown error");x(T),l==null||l(T)}finally{d(!1)}}},[p,JSON.stringify(t),n,s,l]);return b.useEffect(()=>{o&&P()},[P,o]),{data:h,loading:g,error:k,refetch:P}}function St(p,t="POST",r={}){const{onSuccess:n,onError:o}=r,[s,l]=b.useState(null),[h,u]=b.useState(!1),[g,d]=b.useState(null),k=b.useCallback(async P=>{u(!0),d(null);try{const A=Ie();let T;switch(t){case"POST":T=await A.post(p,P);break;case"PUT":T=await A.put(p,P);break;case"PATCH":T=await A.patch(p,P);break;case"DELETE":T=await A.delete(p);break;default:throw new Error(`Unsupported method: ${t}`)}return l(T),n==null||n(T,P),T}catch(A){const T=A instanceof Error?A:new Error("Unknown error");return d(T),o==null||o(T,P),null}finally{u(!1)}},[p,t,n,o]),x=b.useCallback(()=>{l(null),d(null),u(!1)},[]);return{data:s,loading:h,error:g,mutate:k,reset:x}}var Ue={exports:{}},pe={};/**
1
+ "use strict";var wt=Object.defineProperty;var Et=(h,t,r)=>t in h?wt(h,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):h[t]=r;var fe=(h,t,r)=>Et(h,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("react");class _t{constructor(t){fe(this,"config");fe(this,"defaultUploadOptions",{maxSizeMB:10,maxImageDimension:0,imageQuality:.9});if(!t.system_id)throw new Error("GraphClient: system_id is REQUIRED. No system_id → No start.");this.config=t}async callGraph(t,r={}){const s={coprocessor:"graph",method:t,system_id:this.config.system_id,params:r};try{const i=await fetch(`${this.config.baseUrl}/spu/invoke`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.getToken()}`},body:JSON.stringify(s)});if(!i.ok){const o=await i.text();throw new Error(`API error (${i.status}): ${o}`)}const n=await i.json();if(!n.success&&n.error)throw new Error(n.error);return n}catch(i){throw console.error("Graph API call failed:",i),i}}getToken(){return typeof window<"u"&&window.localStorage&&localStorage.getItem("qwanyx_token")||""}async getChildren(t){return(await this.callGraph("get_children",{parent_id:t})).result||[]}async getNode(t){return(await this.callGraph("get_node",{node_id:t})).result||null}async addNode(t){const r={...t,created:t.created||new Date().toISOString(),modified:new Date().toISOString()},s=await this.callGraph("add_node",r);if(!s.result)throw new Error("Failed to add node");return s.result}async updateNode(t,r){const s={node_id:t,updates:{...r,modified:new Date().toISOString()}},i=await this.callGraph("update_node",s);if(!i.result)throw new Error("Failed to update node");return i.result}async deleteNode(t,r=!1){return(await this.callGraph("delete_node",{node_id:t,cascade:r})).success===!0}async getChildrenWithEdges(t,r="children",s,i){return(await this.callGraph("get_children_with_edges",{node_id:t,display_mode:r,edge_type:s,node_type:i})).result||[]}async addEdge(t,r,s="link",i){return await this.callGraph("add_edge",{source_id:t,target_id:r,edge_type:s,data:i})}async deleteEdge(t,r,s){return await this.callGraph("delete_edge",{source_id:t,target_id:r,edge_type:s})}async getEdges(t,r,s){return(await this.callGraph("get_edges",{source_id:t,edge_type:r,target_id:s})).result||[]}async getAncestors(t){return(await this.callGraph("get_ancestors",{node_id:t})).ancestors||[]}async getTree(t,r=10){return(await this.callGraph("get_tree",{root_id:t,max_depth:r})).tree||[]}async moveNode(t,r){const s=await this.callGraph("move",{node_id:t,new_parent_id:r});if(!s.node)throw new Error("Failed to move node");return s.node}async searchNodes(t,r){return(await this.callGraph("search",{query:t,type:r})).nodes||[]}async getNodesByType(t){return(await this.callGraph("get_nodes_by_type",{type:t})).result||[]}fileToBase64(t){return new Promise((r,s)=>{const i=new FileReader;i.onload=()=>{const o=i.result.split(",")[1];r(o)},i.onerror=()=>s(new Error("Failed to read file")),i.readAsDataURL(t)})}async resizeImage(t,r,s){return t.type.startsWith("image/")?new Promise(i=>{const n=new Image,o=URL.createObjectURL(t);n.onload=()=>{if(URL.revokeObjectURL(o),n.width<=r&&n.height<=r){i(t);return}let p,d;n.width>n.height?(p=r,d=Math.round(n.height/n.width*r)):(d=r,p=Math.round(n.width/n.height*r));const g=document.createElement("canvas");g.width=p,g.height=d;const c=g.getContext("2d");if(!c){i(t);return}c.drawImage(n,0,0,p,d);const _=t.type==="image/png"?"image/png":"image/jpeg";g.toBlob(x=>{if(x){const m=new File([x],t.name,{type:_});i(m)}else i(t)},_,s)},n.onerror=()=>{URL.revokeObjectURL(o),i(t)},n.src=o}):t}async uploadFile(t,r,s,i={}){const n={...this.defaultUploadOptions,...i};try{let o=s;n.maxImageDimension>0&&s.type.startsWith("image/")&&(o=await this.resizeImage(s,n.maxImageDimension,n.imageQuality));const p=n.maxSizeMB*1024*1024;if(o.size>p)return{success:!1,error:`File too large (${(o.size/1024/1024).toFixed(1)} MB). Max: ${n.maxSizeMB} MB`};const d=await this.fileToBase64(o),g=await this.callGraph("upload_file",{node_id:t,filename:r,content:d});return g.success?{success:!0,path:g.path}:{success:!1,error:g.error||"Upload failed"}}catch(o){return{success:!1,error:o instanceof Error?o.message:"Upload failed"}}}async listFiles(t){var i;return(((i=(await this.callGraph("list_files",{node_id:t})).result)==null?void 0:i.files)||[]).map(n=>({filename:n.name,path:n.path}))}async deleteFile(t,r){return{success:(await this.callGraph("delete_file",{node_id:t,filename:r})).success||!1}}getFileUrl(t,r){return`${this.config.baseUrl}/files/${this.config.system_id}/${t}/${r}`}}class Ze{constructor(t){fe(this,"config");if(!t.system_id)throw new Error("MailClient: system_id is REQUIRED");this.config=t}async callCoprocessor(t,r,s={}){const i={coprocessor:t,method:r,system_id:this.config.system_id,params:{user_id:this.config.system_id,...s}};try{const n=await fetch(`${this.config.baseUrl}/spu/invoke`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.getToken()}`},body:JSON.stringify(i)});if(!n.ok){const p=await n.text();throw new Error(`API error (${n.status}): ${p}`)}const o=await n.json();if(!o.success&&o.error)throw new Error(o.error);return o.result}catch(n){throw console.error("API call failed:",n),n}}async callMail(t,r={}){return this.callCoprocessor("mail",t,r)}async callEmail(t,r={}){return this.callCoprocessor("email",t,r)}getToken(){return typeof window<"u"&&window.localStorage&&localStorage.getItem("qwanyx_token")||""}async getSettings(){try{return await this.callMail("get_email_settings")||{accounts:[]}}catch{return{accounts:[]}}}async saveSettings(t){await this.callMail("save_email_settings",{accounts:t})}async listEmails(t,r=20,s){return this.callMail("list_emails",{account_id:t,limit:r,folder:s})}async deleteEmails(t,r,s=!0){return this.callMail("delete_emails",{account_id:t,uids:r,expunge:s})}async imapExec(t,r){return this.callMail("imap_exec",{account_id:t,commands:r})}async trashEmails(t,r){const s=["[Gmail]/Trash","[Gmail]/Corbeille","[Gmail]/Bin","Trash"];for(const i of s){const n=["SELECT INBOX",...r.map(d=>`UID MOVE ${d} ${i}`)],p=(await this.imapExec(t,n)).responses.filter(d=>d.ok&&d.command==="UID MOVE").length;if(p>0)return{success:!0,moved:p}}return{success:!1,moved:0}}async archiveEmails(t,r){const s=["SELECT INBOX",...r.map(o=>`UID STORE ${o} +FLAGS (\\Deleted)`),"EXPUNGE"],n=(await this.imapExec(t,s)).responses.filter(o=>o.ok&&o.command==="UID STORE").length;return{success:n>0,archived:n}}async listFolders(t){const s=(await this.imapExec(t,['LIST "" *'])).responses.find(i=>i.command==="LIST");return s!=null&&s.ok&&s.folders?{success:!0,folders:s.folders}:{success:!1,folders:[]}}async listEmailsSorted(t,r="INBOX",s=20){const i=await this.imapExec(t,[`SELECT ${r}`,"FETCH 1:* (UID INTERNALDATE)"]),n=i.responses.find(m=>m.command==="SELECT");if(!(n!=null&&n.ok))throw new Error(`Failed to select folder: ${(n==null?void 0:n.error)||"Unknown error"}`);const o=i.responses.find(m=>m.command==="FETCH");if(!(o!=null&&o.ok)||!o.messages)return{account:{id:t,label:"",email:""},mailbox:{name:r,total:n.exists||0},messages:[]};const d=[...o.messages].sort((m,k)=>{const C=m.internalDate?new Date(m.internalDate).getTime():0;return(k.internalDate?new Date(k.internalDate).getTime():0)-C}).slice(0,s).map(m=>m.uid).filter(Boolean);if(d.length===0)return{account:{id:t,label:"",email:""},mailbox:{name:r,total:n.exists||0},messages:[]};const c=(await this.imapExec(t,[`SELECT ${r}`,`UID FETCH ${d.join(",")} (UID FLAGS ENVELOPE)`])).responses.find(m=>m.command==="UID FETCH");if(!(c!=null&&c.ok)||!c.messages)throw new Error(`Failed to fetch details: ${(c==null?void 0:c.error)||"Unknown error"}`);const _=new Map;for(const m of c.messages)m.uid&&_.set(m.uid,m);const x=d.map(m=>{var Y,E,M,y,N;const k=_.get(m);if(!k)return null;const C=((Y=k.flags)==null?void 0:Y.some(D=>D.includes("Seen")))||!1,V=((M=(E=k.envelope)==null?void 0:E.from)==null?void 0:M.email)||"Unknown",I=((y=k.envelope)==null?void 0:y.subject)||"(No subject)",F=((N=k.envelope)==null?void 0:N.date)||"";return{uid:m,from:V,subject:I,date:F,seen:C}}).filter(Boolean);return{account:{id:t,label:"",email:""},mailbox:{name:r,total:n.exists||0},messages:x}}async getEmail(t,r){return this.callMail("get_email",{account_id:t,uid:r})}async sendMail(t){const r={to:t.to,subject:t.subject,body:t.body};return t.html&&(r.html=t.html),t.from&&(r.from=t.from),t.smtpConfig&&(r.smtp_config=t.smtpConfig),this.callEmail("send",r)}}const De="qwanyx_auth_token",Me="qwanyx_refresh_token";class et{static setToken(t){typeof window<"u"&&localStorage.setItem(De,t)}static getToken(){return typeof window<"u"?localStorage.getItem(De):null}static clearToken(){typeof window<"u"&&(localStorage.removeItem(De),localStorage.removeItem(Me))}static setRefreshToken(t){typeof window<"u"&&localStorage.setItem(Me,t)}static getRefreshToken(){return typeof window<"u"?localStorage.getItem(Me):null}static isAuthenticated(){return!!this.getToken()}static getAuthHeader(){const t=this.getToken();return t?{Authorization:`Bearer ${t}`}:{}}}class tt{constructor(t){fe(this,"config");this.config={timeout:3e4,headers:{"Content-Type":"application/json"},...t}}buildQueryString(t){if(!t||Object.keys(t).length===0)return"";const r=new URLSearchParams;Object.entries(t).forEach(([i,n])=>{n!=null&&r.append(i,String(n))});const s=r.toString();return s?`?${s}`:""}async request(t,r={}){const{method:s="GET",headers:i={},body:n,params:o}=r,p=`${this.config.baseUrl}/${t}${this.buildQueryString(o)}`,d={...this.config.headers,...et.getAuthHeader(),...i},g={method:s,headers:d};n&&s!=="GET"&&(g.body=JSON.stringify(n));try{const c=new AbortController,_=setTimeout(()=>c.abort(),this.config.timeout),x=await fetch(p,{...g,signal:c.signal});if(clearTimeout(_),!x.ok){const m=await x.json().catch(()=>({message:x.statusText}));throw new Error(m.message||`HTTP ${x.status}`)}return await x.json()}catch(c){throw c instanceof Error?c:new Error("An unexpected error occurred")}}async get(t,r){return this.request(t,{method:"GET",params:r})}async post(t,r,s){return this.request(t,{method:"POST",body:r,params:s})}async put(t,r,s){return this.request(t,{method:"PUT",body:r,params:s})}async patch(t,r,s){return this.request(t,{method:"PATCH",body:r,params:s})}async delete(t,r){return this.request(t,{method:"DELETE",params:r})}setBaseUrl(t){this.config.baseUrl=t}getBaseUrl(){return this.config.baseUrl}}let Se=null;function jt(h){return Se=new tt(h),Se}function Be(){if(!Se)throw new Error("API client not initialized. Call initializeApiClient() first.");return Se}function rt(h,t,r={}){const{enabled:s=!0,refetchOnMount:i=!0,onSuccess:n,onError:o}=r,[p,d]=w.useState(null),[g,c]=w.useState(s),[_,x]=w.useState(null),m=w.useCallback(async()=>{if(s){c(!0),x(null);try{const C=await Be().get(h,t);d(C),n==null||n(C)}catch(k){const C=k instanceof Error?k:new Error("Unknown error");x(C),o==null||o(C)}finally{c(!1)}}},[h,JSON.stringify(t),s,n,o]);return w.useEffect(()=>{i&&m()},[m,i]),{data:p,loading:g,error:_,refetch:m}}function St(h,t="POST",r={}){const{onSuccess:s,onError:i}=r,[n,o]=w.useState(null),[p,d]=w.useState(!1),[g,c]=w.useState(null),_=w.useCallback(async m=>{d(!0),c(null);try{const k=Be();let C;switch(t){case"POST":C=await k.post(h,m);break;case"PUT":C=await k.put(h,m);break;case"PATCH":C=await k.patch(h,m);break;case"DELETE":C=await k.delete(h);break;default:throw new Error(`Unsupported method: ${t}`)}return o(C),s==null||s(C,m),C}catch(k){const C=k instanceof Error?k:new Error("Unknown error");return c(C),i==null||i(C,m),null}finally{d(!1)}},[h,t,s,i]),x=w.useCallback(()=>{o(null),c(null),d(!1)},[]);return{data:n,loading:p,error:g,mutate:_,reset:x}}var Ue={exports:{}},pe={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var Xe;function kt(){if(Xe)return pe;Xe=1;var p=b,t=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,o=p.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function l(h,u,g){var d,k={},x=null,P=null;g!==void 0&&(x=""+g),u.key!==void 0&&(x=""+u.key),u.ref!==void 0&&(P=u.ref);for(d in u)n.call(u,d)&&!s.hasOwnProperty(d)&&(k[d]=u[d]);if(h&&h.defaultProps)for(d in u=h.defaultProps,u)k[d]===void 0&&(k[d]=u[d]);return{$$typeof:t,type:h,key:x,ref:P,props:k,_owner:o.current}}return pe.Fragment=r,pe.jsx=l,pe.jsxs=l,pe}var he={};/**
9
+ */var Xe;function kt(){if(Xe)return pe;Xe=1;var h=w,t=Symbol.for("react.element"),r=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,i=h.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,n={key:!0,ref:!0,__self:!0,__source:!0};function o(p,d,g){var c,_={},x=null,m=null;g!==void 0&&(x=""+g),d.key!==void 0&&(x=""+d.key),d.ref!==void 0&&(m=d.ref);for(c in d)s.call(d,c)&&!n.hasOwnProperty(c)&&(_[c]=d[c]);if(p&&p.defaultProps)for(c in d=p.defaultProps,d)_[c]===void 0&&(_[c]=d[c]);return{$$typeof:t,type:p,key:x,ref:m,props:_,_owner:i.current}}return pe.Fragment=r,pe.jsx=o,pe.jsxs=o,pe}var he={};/**
10
10
  * @license React
11
11
  * react-jsx-runtime.development.js
12
12
  *
@@ -14,21 +14,21 @@
14
14
  *
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
- */var He;function Rt(){return He||(He=1,process.env.NODE_ENV!=="production"&&function(){var p=b,t=Symbol.for("react.element"),r=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),l=Symbol.for("react.provider"),h=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),g=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),k=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),P=Symbol.for("react.offscreen"),A=Symbol.iterator,T="@@iterator";function H(e){if(e===null||typeof e!="object")return null;var i=A&&e[A]||e[T];return typeof i=="function"?i:null}var G=p.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function F(e){{for(var i=arguments.length,c=new Array(i>1?i-1:0),m=1;m<i;m++)c[m-1]=arguments[m];K("error",e,c)}}function K(e,i,c){{var m=G.ReactDebugCurrentFrame,N=m.getStackAddendum();N!==""&&(i+="%s",c=c.concat([N]));var $=c.map(function(R){return String(R)});$.unshift("Warning: "+i),Function.prototype.apply.call(console[e],console,$)}}var _=!1,L=!1,v=!1,C=!1,M=!1,j;j=Symbol.for("react.module.reference");function O(e){return!!(typeof e=="string"||typeof e=="function"||e===n||e===s||M||e===o||e===g||e===d||C||e===P||_||L||v||typeof e=="object"&&e!==null&&(e.$$typeof===x||e.$$typeof===k||e.$$typeof===l||e.$$typeof===h||e.$$typeof===u||e.$$typeof===j||e.getModuleId!==void 0))}function y(e,i,c){var m=e.displayName;if(m)return m;var N=i.displayName||i.name||"";return N!==""?c+"("+N+")":c}function W(e){return e.displayName||"Context"}function I(e){if(e==null)return null;if(typeof e.tag=="number"&&F("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case n:return"Fragment";case r:return"Portal";case s:return"Profiler";case o:return"StrictMode";case g:return"Suspense";case d:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case h:var i=e;return W(i)+".Consumer";case l:var c=e;return W(c._context)+".Provider";case u:return y(e,e.render,"ForwardRef");case k:var m=e.displayName||null;return m!==null?m:I(e.type)||"Memo";case x:{var N=e,$=N._payload,R=N._init;try{return I(R($))}catch{return null}}}return null}var S=Object.assign,B=0,V,Q,te,ge,ye,me,xe;function ve(){}ve.__reactDisabledLog=!0;function ke(){{if(B===0){V=console.log,Q=console.info,te=console.warn,ge=console.error,ye=console.group,me=console.groupCollapsed,xe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ve,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}B++}}function Re(){{if(B--,B===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:S({},e,{value:V}),info:S({},e,{value:Q}),warn:S({},e,{value:te}),error:S({},e,{value:ge}),group:S({},e,{value:ye}),groupCollapsed:S({},e,{value:me}),groupEnd:S({},e,{value:xe})})}B<0&&F("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ce=G.ReactCurrentDispatcher,ue;function se(e,i,c){{if(ue===void 0)try{throw Error()}catch(N){var m=N.stack.trim().match(/\n( *(at )?)/);ue=m&&m[1]||""}return`
18
- `+ue+e}}var de=!1,ae;{var Te=typeof WeakMap=="function"?WeakMap:Map;ae=new Te}function be(e,i){if(!e||de)return"";{var c=ae.get(e);if(c!==void 0)return c}var m;de=!0;var N=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var $;$=ce.current,ce.current=null,ke();try{if(i){var R=function(){throw Error()};if(Object.defineProperty(R.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(R,[])}catch(q){m=q}Reflect.construct(e,[],R)}else{try{R.call()}catch(q){m=q}e.call(R.prototype)}}else{try{throw Error()}catch(q){m=q}e()}}catch(q){if(q&&m&&typeof q.stack=="string"){for(var E=q.stack.split(`
19
- `),Y=m.stack.split(`
20
- `),D=E.length-1,U=Y.length-1;D>=1&&U>=0&&E[D]!==Y[U];)U--;for(;D>=1&&U>=0;D--,U--)if(E[D]!==Y[U]){if(D!==1||U!==1)do if(D--,U--,U<0||E[D]!==Y[U]){var X=`
21
- `+E[D].replace(" at new "," at ");return e.displayName&&X.includes("<anonymous>")&&(X=X.replace("<anonymous>",e.displayName)),typeof e=="function"&&ae.set(e,X),X}while(D>=1&&U>=0);break}}}finally{de=!1,ce.current=$,Re(),Error.prepareStackTrace=N}var le=e?e.displayName||e.name:"",ne=le?se(le):"";return typeof e=="function"&&ae.set(e,ne),ne}function Ce(e,i,c){return be(e,!1)}function Oe(e){var i=e.prototype;return!!(i&&i.isReactComponent)}function ie(e,i,c){if(e==null)return"";if(typeof e=="function")return be(e,Oe(e));if(typeof e=="string")return se(e);switch(e){case g:return se("Suspense");case d:return se("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case u:return Ce(e.render);case k:return ie(e.type,i,c);case x:{var m=e,N=m._payload,$=m._init;try{return ie($(N),i,c)}catch{}}}return""}var re=Object.prototype.hasOwnProperty,f={},w=G.ReactDebugCurrentFrame;function z(e){if(e){var i=e._owner,c=ie(e.type,e._source,i?i.type:null);w.setExtraStackFrame(c)}else w.setExtraStackFrame(null)}function J(e,i,c,m,N){{var $=Function.call.bind(re);for(var R in e)if($(e,R)){var E=void 0;try{if(typeof e[R]!="function"){var Y=Error((m||"React class")+": "+c+" type `"+R+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[R]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Y.name="Invariant Violation",Y}E=e[R](i,R,m,c,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(D){E=D}E&&!(E instanceof Error)&&(z(N),F("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",m||"React class",c,R,typeof E),z(null)),E instanceof Error&&!(E.message in f)&&(f[E.message]=!0,z(N),F("Failed %s type: %s",c,E.message),z(null))}}}var ee=Array.isArray;function Z(e){return ee(e)}function Ne(e){{var i=typeof Symbol=="function"&&Symbol.toStringTag,c=i&&e[Symbol.toStringTag]||e.constructor.name||"Object";return c}}function we(e){try{return _e(e),!1}catch{return!0}}function _e(e){return""+e}function Be(e){if(we(e))return F("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ne(e)),_e(e)}var Le=G.ReactCurrentOwner,nt={key:!0,ref:!0,__self:!0,__source:!0},ze,Ge;function st(e){if(re.call(e,"ref")){var i=Object.getOwnPropertyDescriptor(e,"ref").get;if(i&&i.isReactWarning)return!1}return e.ref!==void 0}function at(e){if(re.call(e,"key")){var i=Object.getOwnPropertyDescriptor(e,"key").get;if(i&&i.isReactWarning)return!1}return e.key!==void 0}function it(e,i){typeof e.ref=="string"&&Le.current}function ot(e,i){{var c=function(){ze||(ze=!0,F("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",i))};c.isReactWarning=!0,Object.defineProperty(e,"key",{get:c,configurable:!0})}}function lt(e,i){{var c=function(){Ge||(Ge=!0,F("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",i))};c.isReactWarning=!0,Object.defineProperty(e,"ref",{get:c,configurable:!0})}}var ct=function(e,i,c,m,N,$,R){var E={$$typeof:t,type:e,key:i,ref:c,props:R,_owner:$};return E._store={},Object.defineProperty(E._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(E,"_self",{configurable:!1,enumerable:!1,writable:!1,value:m}),Object.defineProperty(E,"_source",{configurable:!1,enumerable:!1,writable:!1,value:N}),Object.freeze&&(Object.freeze(E.props),Object.freeze(E)),E};function ut(e,i,c,m,N){{var $,R={},E=null,Y=null;c!==void 0&&(Be(c),E=""+c),at(i)&&(Be(i.key),E=""+i.key),st(i)&&(Y=i.ref,it(i,N));for($ in i)re.call(i,$)&&!nt.hasOwnProperty($)&&(R[$]=i[$]);if(e&&e.defaultProps){var D=e.defaultProps;for($ in D)R[$]===void 0&&(R[$]=D[$])}if(E||Y){var U=typeof e=="function"?e.displayName||e.name||"Unknown":e;E&&ot(R,U),Y&&lt(R,U)}return ct(e,E,Y,N,m,Le.current,R)}}var Pe=G.ReactCurrentOwner,We=G.ReactDebugCurrentFrame;function oe(e){if(e){var i=e._owner,c=ie(e.type,e._source,i?i.type:null);We.setExtraStackFrame(c)}else We.setExtraStackFrame(null)}var Ae;Ae=!1;function $e(e){return typeof e=="object"&&e!==null&&e.$$typeof===t}function Ye(){{if(Pe.current){var e=I(Pe.current.type);if(e)return`
17
+ */var Qe;function Tt(){return Qe||(Qe=1,process.env.NODE_ENV!=="production"&&function(){var h=w,t=Symbol.for("react.element"),r=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),n=Symbol.for("react.profiler"),o=Symbol.for("react.provider"),p=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),g=Symbol.for("react.suspense"),c=Symbol.for("react.suspense_list"),_=Symbol.for("react.memo"),x=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),k=Symbol.iterator,C="@@iterator";function V(e){if(e===null||typeof e!="object")return null;var l=k&&e[k]||e[C];return typeof l=="function"?l:null}var I=h.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function F(e){{for(var l=arguments.length,u=new Array(l>1?l-1:0),b=1;b<l;b++)u[b-1]=arguments[b];Y("error",e,u)}}function Y(e,l,u){{var b=I.ReactDebugCurrentFrame,P=b.getStackAddendum();P!==""&&(l+="%s",u=u.concat([P]));var $=u.map(function(O){return String(O)});$.unshift("Warning: "+l),Function.prototype.apply.call(console[e],console,$)}}var E=!1,M=!1,y=!1,N=!1,D=!1,j;j=Symbol.for("react.module.reference");function A(e){return!!(typeof e=="string"||typeof e=="function"||e===s||e===n||D||e===i||e===g||e===c||N||e===m||E||M||y||typeof e=="object"&&e!==null&&(e.$$typeof===x||e.$$typeof===_||e.$$typeof===o||e.$$typeof===p||e.$$typeof===d||e.$$typeof===j||e.getModuleId!==void 0))}function v(e,l,u){var b=e.displayName;if(b)return b;var P=l.displayName||l.name||"";return P!==""?u+"("+P+")":u}function G(e){return e.displayName||"Context"}function L(e){if(e==null)return null;if(typeof e.tag=="number"&&F("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case s:return"Fragment";case r:return"Portal";case n:return"Profiler";case i:return"StrictMode";case g:return"Suspense";case c:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case p:var l=e;return G(l)+".Consumer";case o:var u=e;return G(u._context)+".Provider";case d:return v(e,e.render,"ForwardRef");case _:var b=e.displayName||null;return b!==null?b:L(e.type)||"Memo";case x:{var P=e,$=P._payload,O=P._init;try{return L(O($))}catch{return null}}}return null}var R=Object.assign,z=0,J,K,te,ge,me,ye,xe;function ve(){}ve.__reactDisabledLog=!0;function ke(){{if(z===0){J=console.log,K=console.info,te=console.warn,ge=console.error,me=console.group,ye=console.groupCollapsed,xe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ve,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}z++}}function Te(){{if(z--,z===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:R({},e,{value:J}),info:R({},e,{value:K}),warn:R({},e,{value:te}),error:R({},e,{value:ge}),group:R({},e,{value:me}),groupCollapsed:R({},e,{value:ye}),groupEnd:R({},e,{value:xe})})}z<0&&F("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ce=I.ReactCurrentDispatcher,ue;function ne(e,l,u){{if(ue===void 0)try{throw Error()}catch(P){var b=P.stack.trim().match(/\n( *(at )?)/);ue=b&&b[1]||""}return`
18
+ `+ue+e}}var de=!1,ae;{var Re=typeof WeakMap=="function"?WeakMap:Map;ae=new Re}function be(e,l){if(!e||de)return"";{var u=ae.get(e);if(u!==void 0)return u}var b;de=!0;var P=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var $;$=ce.current,ce.current=null,ke();try{if(l){var O=function(){throw Error()};if(Object.defineProperty(O.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(O,[])}catch(H){b=H}Reflect.construct(e,[],O)}else{try{O.call()}catch(H){b=H}e.call(O.prototype)}}else{try{throw Error()}catch(H){b=H}e()}}catch(H){if(H&&b&&typeof H.stack=="string"){for(var T=H.stack.split(`
19
+ `),q=b.stack.split(`
20
+ `),U=T.length-1,B=q.length-1;U>=1&&B>=0&&T[U]!==q[B];)B--;for(;U>=1&&B>=0;U--,B--)if(T[U]!==q[B]){if(U!==1||B!==1)do if(U--,B--,B<0||T[U]!==q[B]){var X=`
21
+ `+T[U].replace(" at new "," at ");return e.displayName&&X.includes("<anonymous>")&&(X=X.replace("<anonymous>",e.displayName)),typeof e=="function"&&ae.set(e,X),X}while(U>=1&&B>=0);break}}}finally{de=!1,ce.current=$,Te(),Error.prepareStackTrace=P}var le=e?e.displayName||e.name:"",se=le?ne(le):"";return typeof e=="function"&&ae.set(e,se),se}function Ce(e,l,u){return be(e,!1)}function Oe(e){var l=e.prototype;return!!(l&&l.isReactComponent)}function ie(e,l,u){if(e==null)return"";if(typeof e=="function")return be(e,Oe(e));if(typeof e=="string")return ne(e);switch(e){case g:return ne("Suspense");case c:return ne("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case d:return Ce(e.render);case _:return ie(e.type,l,u);case x:{var b=e,P=b._payload,$=b._init;try{return ie($(P),l,u)}catch{}}}return""}var re=Object.prototype.hasOwnProperty,f={},S=I.ReactDebugCurrentFrame;function W(e){if(e){var l=e._owner,u=ie(e.type,e._source,l?l.type:null);S.setExtraStackFrame(u)}else S.setExtraStackFrame(null)}function Q(e,l,u,b,P){{var $=Function.call.bind(re);for(var O in e)if($(e,O)){var T=void 0;try{if(typeof e[O]!="function"){var q=Error((b||"React class")+": "+u+" type `"+O+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[O]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw q.name="Invariant Violation",q}T=e[O](l,O,b,u,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(U){T=U}T&&!(T instanceof Error)&&(W(P),F("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",b||"React class",u,O,typeof T),W(null)),T instanceof Error&&!(T.message in f)&&(f[T.message]=!0,W(P),F("Failed %s type: %s",u,T.message),W(null))}}}var ee=Array.isArray;function Z(e){return ee(e)}function Ne(e){{var l=typeof Symbol=="function"&&Symbol.toStringTag,u=l&&e[Symbol.toStringTag]||e.constructor.name||"Object";return u}}function we(e){try{return Ee(e),!1}catch{return!0}}function Ee(e){return""+e}function Ie(e){if(we(e))return F("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ne(e)),Ee(e)}var Le=I.ReactCurrentOwner,st={key:!0,ref:!0,__self:!0,__source:!0},ze,Ge;function nt(e){if(re.call(e,"ref")){var l=Object.getOwnPropertyDescriptor(e,"ref").get;if(l&&l.isReactWarning)return!1}return e.ref!==void 0}function at(e){if(re.call(e,"key")){var l=Object.getOwnPropertyDescriptor(e,"key").get;if(l&&l.isReactWarning)return!1}return e.key!==void 0}function it(e,l){typeof e.ref=="string"&&Le.current}function ot(e,l){{var u=function(){ze||(ze=!0,F("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",l))};u.isReactWarning=!0,Object.defineProperty(e,"key",{get:u,configurable:!0})}}function lt(e,l){{var u=function(){Ge||(Ge=!0,F("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",l))};u.isReactWarning=!0,Object.defineProperty(e,"ref",{get:u,configurable:!0})}}var ct=function(e,l,u,b,P,$,O){var T={$$typeof:t,type:e,key:l,ref:u,props:O,_owner:$};return T._store={},Object.defineProperty(T._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(T,"_self",{configurable:!1,enumerable:!1,writable:!1,value:b}),Object.defineProperty(T,"_source",{configurable:!1,enumerable:!1,writable:!1,value:P}),Object.freeze&&(Object.freeze(T.props),Object.freeze(T)),T};function ut(e,l,u,b,P){{var $,O={},T=null,q=null;u!==void 0&&(Ie(u),T=""+u),at(l)&&(Ie(l.key),T=""+l.key),nt(l)&&(q=l.ref,it(l,P));for($ in l)re.call(l,$)&&!st.hasOwnProperty($)&&(O[$]=l[$]);if(e&&e.defaultProps){var U=e.defaultProps;for($ in U)O[$]===void 0&&(O[$]=U[$])}if(T||q){var B=typeof e=="function"?e.displayName||e.name||"Unknown":e;T&&ot(O,B),q&&lt(O,B)}return ct(e,T,q,P,b,Le.current,O)}}var Ae=I.ReactCurrentOwner,We=I.ReactDebugCurrentFrame;function oe(e){if(e){var l=e._owner,u=ie(e.type,e._source,l?l.type:null);We.setExtraStackFrame(u)}else We.setExtraStackFrame(null)}var Pe;Pe=!1;function $e(e){return typeof e=="object"&&e!==null&&e.$$typeof===t}function Ye(){{if(Ae.current){var e=L(Ae.current.type);if(e)return`
22
22
 
23
- Check the render method of \``+e+"`."}return""}}function dt(e){return""}var qe={};function ft(e){{var i=Ye();if(!i){var c=typeof e=="string"?e:e.displayName||e.name;c&&(i=`
23
+ Check the render method of \``+e+"`."}return""}}function dt(e){return""}var qe={};function ft(e){{var l=Ye();if(!l){var u=typeof e=="string"?e:e.displayName||e.name;u&&(l=`
24
24
 
25
- Check the top-level render call using <`+c+">.")}return i}}function Ve(e,i){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var c=ft(i);if(qe[c])return;qe[c]=!0;var m="";e&&e._owner&&e._owner!==Pe.current&&(m=" It was passed a child from "+I(e._owner.type)+"."),oe(e),F('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',c,m),oe(null)}}function Je(e,i){{if(typeof e!="object")return;if(Z(e))for(var c=0;c<e.length;c++){var m=e[c];$e(m)&&Ve(m,i)}else if($e(e))e._store&&(e._store.validated=!0);else if(e){var N=H(e);if(typeof N=="function"&&N!==e.entries)for(var $=N.call(e),R;!(R=$.next()).done;)$e(R.value)&&Ve(R.value,i)}}}function pt(e){{var i=e.type;if(i==null||typeof i=="string")return;var c;if(typeof i=="function")c=i.propTypes;else if(typeof i=="object"&&(i.$$typeof===u||i.$$typeof===k))c=i.propTypes;else return;if(c){var m=I(i);J(c,e.props,"prop",m,e)}else if(i.PropTypes!==void 0&&!Ae){Ae=!0;var N=I(i);F("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",N||"Unknown")}typeof i.getDefaultProps=="function"&&!i.getDefaultProps.isReactClassApproved&&F("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ht(e){{for(var i=Object.keys(e.props),c=0;c<i.length;c++){var m=i[c];if(m!=="children"&&m!=="key"){oe(e),F("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",m),oe(null);break}}e.ref!==null&&(oe(e),F("Invalid attribute `ref` supplied to `React.Fragment`."),oe(null))}}var Ke={};function Qe(e,i,c,m,N,$){{var R=O(e);if(!R){var E="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(E+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var Y=dt();Y?E+=Y:E+=Ye();var D;e===null?D="null":Z(e)?D="array":e!==void 0&&e.$$typeof===t?(D="<"+(I(e.type)||"Unknown")+" />",E=" Did you accidentally export a JSX literal instead of a component?"):D=typeof e,F("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",D,E)}var U=ut(e,i,c,N,$);if(U==null)return U;if(R){var X=i.children;if(X!==void 0)if(m)if(Z(X)){for(var le=0;le<X.length;le++)Je(X[le],e);Object.freeze&&Object.freeze(X)}else F("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Je(X,e)}if(re.call(i,"key")){var ne=I(e),q=Object.keys(i).filter(function(bt){return bt!=="key"}),Fe=q.length>0?"{key: someKey, "+q.join(": ..., ")+": ...}":"{key: someKey}";if(!Ke[ne+Fe]){var vt=q.length>0?"{"+q.join(": ..., ")+": ...}":"{}";F(`A props object containing a "key" prop is being spread into JSX:
25
+ Check the top-level render call using <`+u+">.")}return l}}function Ve(e,l){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var u=ft(l);if(qe[u])return;qe[u]=!0;var b="";e&&e._owner&&e._owner!==Ae.current&&(b=" It was passed a child from "+L(e._owner.type)+"."),oe(e),F('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',u,b),oe(null)}}function He(e,l){{if(typeof e!="object")return;if(Z(e))for(var u=0;u<e.length;u++){var b=e[u];$e(b)&&Ve(b,l)}else if($e(e))e._store&&(e._store.validated=!0);else if(e){var P=V(e);if(typeof P=="function"&&P!==e.entries)for(var $=P.call(e),O;!(O=$.next()).done;)$e(O.value)&&Ve(O.value,l)}}}function pt(e){{var l=e.type;if(l==null||typeof l=="string")return;var u;if(typeof l=="function")u=l.propTypes;else if(typeof l=="object"&&(l.$$typeof===d||l.$$typeof===_))u=l.propTypes;else return;if(u){var b=L(l);Q(u,e.props,"prop",b,e)}else if(l.PropTypes!==void 0&&!Pe){Pe=!0;var P=L(l);F("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",P||"Unknown")}typeof l.getDefaultProps=="function"&&!l.getDefaultProps.isReactClassApproved&&F("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function ht(e){{for(var l=Object.keys(e.props),u=0;u<l.length;u++){var b=l[u];if(b!=="children"&&b!=="key"){oe(e),F("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",b),oe(null);break}}e.ref!==null&&(oe(e),F("Invalid attribute `ref` supplied to `React.Fragment`."),oe(null))}}var Je={};function Ke(e,l,u,b,P,$){{var O=A(e);if(!O){var T="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(T+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var q=dt();q?T+=q:T+=Ye();var U;e===null?U="null":Z(e)?U="array":e!==void 0&&e.$$typeof===t?(U="<"+(L(e.type)||"Unknown")+" />",T=" Did you accidentally export a JSX literal instead of a component?"):U=typeof e,F("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",U,T)}var B=ut(e,l,u,P,$);if(B==null)return B;if(O){var X=l.children;if(X!==void 0)if(b)if(Z(X)){for(var le=0;le<X.length;le++)He(X[le],e);Object.freeze&&Object.freeze(X)}else F("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else He(X,e)}if(re.call(l,"key")){var se=L(e),H=Object.keys(l).filter(function(bt){return bt!=="key"}),Fe=H.length>0?"{key: someKey, "+H.join(": ..., ")+": ...}":"{key: someKey}";if(!Je[se+Fe]){var vt=H.length>0?"{"+H.join(": ..., ")+": ...}":"{}";F(`A props object containing a "key" prop is being spread into JSX:
26
26
  let props = %s;
27
27
  <%s {...props} />
28
28
  React keys must be passed directly to JSX without using spread:
29
29
  let props = %s;
30
- <%s key={someKey} {...props} />`,Fe,ne,vt,ne),Ke[ne+Fe]=!0}}return e===n?ht(U):pt(U),U}}function gt(e,i,c){return Qe(e,i,c,!0)}function yt(e,i,c){return Qe(e,i,c,!1)}var mt=yt,xt=gt;he.Fragment=n,he.jsx=mt,he.jsxs=xt}()),he}process.env.NODE_ENV==="production"?Ue.exports=kt():Ue.exports=Rt();var a=Ue.exports;class Ee{static filter(t,r){return t.filter(r)}static filterBy(t,r,n){return t.filter(o=>o[r]===n)}static filterByFields(t,r){return t.filter(n=>Object.entries(r).every(([o,s])=>n[o]===s))}static sort(t,r,n="asc"){return[...t].sort((o,s)=>{const l=o[r],h=s[r];if(l===h)return 0;let u=0;return l>h&&(u=1),l<h&&(u=-1),n==="asc"?u:-u})}static search(t,r,n){if(!r.trim())return t;const o=r.toLowerCase();return t.filter(s=>n.some(l=>{const h=s[l];return h==null?!1:String(h).toLowerCase().includes(o)}))}static paginate(t,r,n){const o=(r-1)*n,s=o+n;return{data:t.slice(o,s),total:t.length,page:r,totalPages:Math.ceil(t.length/n)}}static groupBy(t,r){return t.reduce((n,o)=>{const s=String(o[r]);return n[s]||(n[s]=[]),n[s].push(o),n},{})}static unique(t,r){const n=t.map(o=>o[r]);return[...new Set(n)]}static countBy(t,r){return t.reduce((n,o)=>{const s=String(o[r]);return n[s]=(n[s]||0)+1,n},{})}static pipe(t,r){return r.reduce((n,o)=>o(n),t)}}function Tt({endpoint:p,params:t,layout:r="list",title:n,emptyMessage:o="No items found",renderItem:s,keyExtractor:l=(T,H)=>T.id||T._id||String(H),searchable:h=!1,searchFields:u=[],searchPlaceholder:g="Search...",filters:d=[],pageSize:k=20,onItemClick:x,onRefresh:P,theme:A={}}){const{data:T,loading:H,error:G,refetch:F}=rt(p,t),[K,_]=b.useState(""),[L,v]=b.useState({}),[C,M]=b.useState(1),j=b.useMemo(()=>{if(!T)return{data:[],total:0,totalPages:0};let S=T;return h&&K&&u.length>0&&(S=Ee.search(S,K,u)),Object.keys(L).length>0&&(S=Ee.filterByFields(S,L)),Ee.paginate(S,C,k)},[T,K,L,C,k,h,u]);b.useEffect(()=>{M(1)},[K,L]);const O=()=>{_(""),v({}),M(1),F(),P==null||P()},y={background:A.background||"#ffffff",cardBackground:A.cardBackground||"#f9fafb",text:A.text||"#111827",textSecondary:A.textSecondary||"#6b7280",border:A.border||"#e5e7eb",primary:A.primary||"#3b82f6"},I=s||(S=>a.jsxs("div",{style:{padding:"16px",cursor:x?"pointer":"default"},children:[a.jsx("div",{style:{fontSize:"14px",fontWeight:500,color:y.text},children:S.title||S.name||S.label||"Untitled"}),S.description&&a.jsx("div",{style:{fontSize:"13px",color:y.textSecondary,marginTop:"4px"},children:S.description})]}));return H&&!T?a.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"48px",color:y.textSecondary},children:"Loading..."}):G?a.jsxs("div",{style:{padding:"24px",textAlign:"center",color:"#ef4444"},children:[a.jsx("div",{style:{fontWeight:500,marginBottom:"8px"},children:"Error"}),a.jsx("div",{style:{fontSize:"14px"},children:G.message}),a.jsx("button",{onClick:O,style:{marginTop:"16px",padding:"8px 16px",background:y.primary,color:"white",border:"none",borderRadius:"6px",cursor:"pointer"},children:"Retry"})]}):a.jsxs("div",{style:{background:y.background,borderRadius:"12px",overflow:"hidden"},children:[(n||h||d.length>0)&&a.jsxs("div",{style:{padding:"16px",borderBottom:`1px solid ${y.border}`},children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:h||d.length>0?"12px":"0"},children:[n&&a.jsx("h2",{style:{margin:0,fontSize:"18px",fontWeight:600,color:y.text},children:n}),a.jsx("button",{onClick:O,style:{padding:"6px 12px",background:"transparent",border:`1px solid ${y.border}`,borderRadius:"6px",color:y.textSecondary,cursor:"pointer",fontSize:"13px"},children:"Refresh"})]}),h&&a.jsx("input",{type:"text",placeholder:g,value:K,onChange:S=>_(S.target.value),style:{width:"100%",padding:"8px 12px",border:`1px solid ${y.border}`,borderRadius:"8px",fontSize:"14px",outline:"none"}})]}),a.jsx("div",{style:{display:r==="grid"?"grid":"flex",flexDirection:r==="list"?"column":void 0,gridTemplateColumns:r==="grid"?"repeat(auto-fill, minmax(250px, 1fr))":void 0,gap:r==="list"?"0":"16px",padding:r==="list"?"0":"16px"},children:j.data.length===0?a.jsx("div",{style:{padding:"48px",textAlign:"center",color:y.textSecondary},children:o}):j.data.map((S,B)=>a.jsx("div",{onClick:()=>x==null?void 0:x(S),style:{background:y.cardBackground,borderRadius:r==="list"?"0":"8px",borderBottom:r==="list"?`1px solid ${y.border}`:"none",transition:"all 0.15s ease"},onMouseEnter:V=>{x&&(V.currentTarget.style.background=y.border)},onMouseLeave:V=>{V.currentTarget.style.background=y.cardBackground},children:I(S,B)},l(S,B)))}),j.totalPages>1&&a.jsxs("div",{style:{padding:"16px",borderTop:`1px solid ${y.border}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[a.jsxs("div",{style:{fontSize:"13px",color:y.textSecondary},children:["Page ",C," of ",j.totalPages]}),a.jsxs("div",{style:{display:"flex",gap:"8px"},children:[a.jsx("button",{onClick:()=>M(S=>Math.max(1,S-1)),disabled:C===1,style:{padding:"6px 12px",border:`1px solid ${y.border}`,borderRadius:"6px",background:"white",cursor:C===1?"not-allowed":"pointer",opacity:C===1?.5:1},children:"Previous"}),a.jsx("button",{onClick:()=>M(S=>Math.min(j.totalPages,S+1)),disabled:C===j.totalPages,style:{padding:"6px 12px",border:`1px solid ${y.border}`,borderRadius:"6px",background:"white",cursor:C===j.totalPages?"not-allowed":"pointer",opacity:C===j.totalPages?.5:1},children:"Next"})]})]})]})}function Ct({item:p,onClick:t,title:r=l=>l.title||l.name||l.label||"Untitled",subtitle:n=l=>l.description||l.subtitle||"",image:o=l=>l.image||l.thumbnail||l.photo,badge:s=l=>l.badge||l.tag||l.type}){const l=r(p),h=n(p),u=o(p),g=s(p);return a.jsxs("div",{onClick:t,className:`
30
+ <%s key={someKey} {...props} />`,Fe,se,vt,se),Je[se+Fe]=!0}}return e===s?ht(B):pt(B),B}}function gt(e,l,u){return Ke(e,l,u,!0)}function mt(e,l,u){return Ke(e,l,u,!1)}var yt=mt,xt=gt;he.Fragment=s,he.jsx=yt,he.jsxs=xt}()),he}process.env.NODE_ENV==="production"?Ue.exports=kt():Ue.exports=Tt();var a=Ue.exports;class je{static filter(t,r){return t.filter(r)}static filterBy(t,r,s){return t.filter(i=>i[r]===s)}static filterByFields(t,r){return t.filter(s=>Object.entries(r).every(([i,n])=>s[i]===n))}static sort(t,r,s="asc"){return[...t].sort((i,n)=>{const o=i[r],p=n[r];if(o===p)return 0;let d=0;return o>p&&(d=1),o<p&&(d=-1),s==="asc"?d:-d})}static search(t,r,s){if(!r.trim())return t;const i=r.toLowerCase();return t.filter(n=>s.some(o=>{const p=n[o];return p==null?!1:String(p).toLowerCase().includes(i)}))}static paginate(t,r,s){const i=(r-1)*s,n=i+s;return{data:t.slice(i,n),total:t.length,page:r,totalPages:Math.ceil(t.length/s)}}static groupBy(t,r){return t.reduce((s,i)=>{const n=String(i[r]);return s[n]||(s[n]=[]),s[n].push(i),s},{})}static unique(t,r){const s=t.map(i=>i[r]);return[...new Set(s)]}static countBy(t,r){return t.reduce((s,i)=>{const n=String(i[r]);return s[n]=(s[n]||0)+1,s},{})}static pipe(t,r){return r.reduce((s,i)=>i(s),t)}}function Rt({endpoint:h,params:t,layout:r="list",title:s,emptyMessage:i="No items found",renderItem:n,keyExtractor:o=(C,V)=>C.id||C._id||String(V),searchable:p=!1,searchFields:d=[],searchPlaceholder:g="Search...",filters:c=[],pageSize:_=20,onItemClick:x,onRefresh:m,theme:k={}}){const{data:C,loading:V,error:I,refetch:F}=rt(h,t),[Y,E]=w.useState(""),[M,y]=w.useState({}),[N,D]=w.useState(1),j=w.useMemo(()=>{if(!C)return{data:[],total:0,totalPages:0};let R=C;return p&&Y&&d.length>0&&(R=je.search(R,Y,d)),Object.keys(M).length>0&&(R=je.filterByFields(R,M)),je.paginate(R,N,_)},[C,Y,M,N,_,p,d]);w.useEffect(()=>{D(1)},[Y,M]);const A=()=>{E(""),y({}),D(1),F(),m==null||m()},v={background:k.background||"#ffffff",cardBackground:k.cardBackground||"#f9fafb",text:k.text||"#111827",textSecondary:k.textSecondary||"#6b7280",border:k.border||"#e5e7eb",primary:k.primary||"#3b82f6"},L=n||(R=>a.jsxs("div",{style:{padding:"16px",cursor:x?"pointer":"default"},children:[a.jsx("div",{style:{fontSize:"14px",fontWeight:500,color:v.text},children:R.title||R.name||R.label||"Untitled"}),R.description&&a.jsx("div",{style:{fontSize:"13px",color:v.textSecondary,marginTop:"4px"},children:R.description})]}));return V&&!C?a.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"48px",color:v.textSecondary},children:"Loading..."}):I?a.jsxs("div",{style:{padding:"24px",textAlign:"center",color:"#ef4444"},children:[a.jsx("div",{style:{fontWeight:500,marginBottom:"8px"},children:"Error"}),a.jsx("div",{style:{fontSize:"14px"},children:I.message}),a.jsx("button",{onClick:A,style:{marginTop:"16px",padding:"8px 16px",background:v.primary,color:"white",border:"none",borderRadius:"6px",cursor:"pointer"},children:"Retry"})]}):a.jsxs("div",{style:{background:v.background,borderRadius:"12px",overflow:"hidden"},children:[(s||p||c.length>0)&&a.jsxs("div",{style:{padding:"16px",borderBottom:`1px solid ${v.border}`},children:[a.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:p||c.length>0?"12px":"0"},children:[s&&a.jsx("h2",{style:{margin:0,fontSize:"18px",fontWeight:600,color:v.text},children:s}),a.jsx("button",{onClick:A,style:{padding:"6px 12px",background:"transparent",border:`1px solid ${v.border}`,borderRadius:"6px",color:v.textSecondary,cursor:"pointer",fontSize:"13px"},children:"Refresh"})]}),p&&a.jsx("input",{type:"text",placeholder:g,value:Y,onChange:R=>E(R.target.value),style:{width:"100%",padding:"8px 12px",border:`1px solid ${v.border}`,borderRadius:"8px",fontSize:"14px",outline:"none"}})]}),a.jsx("div",{style:{display:r==="grid"?"grid":"flex",flexDirection:r==="list"?"column":void 0,gridTemplateColumns:r==="grid"?"repeat(auto-fill, minmax(250px, 1fr))":void 0,gap:r==="list"?"0":"16px",padding:r==="list"?"0":"16px"},children:j.data.length===0?a.jsx("div",{style:{padding:"48px",textAlign:"center",color:v.textSecondary},children:i}):j.data.map((R,z)=>a.jsx("div",{onClick:()=>x==null?void 0:x(R),style:{background:v.cardBackground,borderRadius:r==="list"?"0":"8px",borderBottom:r==="list"?`1px solid ${v.border}`:"none",transition:"all 0.15s ease"},onMouseEnter:J=>{x&&(J.currentTarget.style.background=v.border)},onMouseLeave:J=>{J.currentTarget.style.background=v.cardBackground},children:L(R,z)},o(R,z)))}),j.totalPages>1&&a.jsxs("div",{style:{padding:"16px",borderTop:`1px solid ${v.border}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[a.jsxs("div",{style:{fontSize:"13px",color:v.textSecondary},children:["Page ",N," of ",j.totalPages]}),a.jsxs("div",{style:{display:"flex",gap:"8px"},children:[a.jsx("button",{onClick:()=>D(R=>Math.max(1,R-1)),disabled:N===1,style:{padding:"6px 12px",border:`1px solid ${v.border}`,borderRadius:"6px",background:"white",cursor:N===1?"not-allowed":"pointer",opacity:N===1?.5:1},children:"Previous"}),a.jsx("button",{onClick:()=>D(R=>Math.min(j.totalPages,R+1)),disabled:N===j.totalPages,style:{padding:"6px 12px",border:`1px solid ${v.border}`,borderRadius:"6px",background:"white",cursor:N===j.totalPages?"not-allowed":"pointer",opacity:N===j.totalPages?.5:1},children:"Next"})]})]})]})}function Ct({item:h,onClick:t,title:r=o=>o.title||o.name||o.label||"Untitled",subtitle:s=o=>o.description||o.subtitle||"",image:i=o=>o.image||o.thumbnail||o.photo,badge:n=o=>o.badge||o.tag||o.type}){const o=r(h),p=s(h),d=i(h),g=n(h);return a.jsxs("div",{onClick:t,className:`
31
31
  flex items-center gap-4 p-4 border-b border-gray-200
32
32
  hover:bg-gray-50 transition-colors
33
33
  ${t?"cursor-pointer":""}
34
- `,children:[u&&a.jsx("div",{className:"flex-shrink-0",children:a.jsx("img",{src:u,alt:l,className:"w-16 h-16 object-cover rounded-lg"})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("h3",{className:"font-medium text-gray-900 truncate",children:l}),g&&a.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-blue-100 text-blue-800 rounded-full",children:g})]}),h&&a.jsx("p",{className:"text-sm text-gray-600 truncate mt-0.5",children:h})]}),t&&a.jsx("div",{className:"flex-shrink-0 text-gray-400",children:a.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})})]})}function Ot({item:p,onClose:t,title:r=s=>s.title||s.name||s.label||"Detail",image:n=s=>s.image||s.thumbnail||s.photo,fields:o=[]}){if(!p)return null;const s=r(p),l=n(p);return a.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:a.jsxs("div",{className:"bg-white rounded-xl max-w-2xl w-full max-h-[90vh] overflow-y-auto shadow-2xl",children:[a.jsxs("div",{className:"sticky top-0 bg-white border-b border-gray-200 px-6 py-4 flex items-center justify-between",children:[a.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:s}),t&&a.jsx("button",{onClick:t,className:"p-2 hover:bg-gray-100 rounded-lg transition-colors",children:a.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),a.jsxs("div",{className:"p-6",children:[l&&a.jsx("div",{className:"mb-6",children:a.jsx("img",{src:l,alt:s,className:"w-full h-64 object-cover rounded-lg"})}),o.length>0&&a.jsx("div",{className:"space-y-4",children:o.map((h,u)=>{const g=h.value(p);return g==null||g===""?null:a.jsxs("div",{children:[a.jsx("div",{className:"text-sm font-medium text-gray-500 mb-1",children:h.label}),a.jsx("div",{className:"text-base text-gray-900",children:typeof g=="object"?JSON.stringify(g,null,2):String(g)})]},u)})}),o.length===0&&a.jsx("pre",{className:"bg-gray-50 p-4 rounded-lg text-sm overflow-x-auto",children:JSON.stringify(p,null,2)})]}),t&&a.jsx("div",{className:"sticky bottom-0 bg-gray-50 border-t border-gray-200 px-6 py-4",children:a.jsx("button",{onClick:t,className:"w-full px-4 py-2 bg-gray-900 text-white rounded-lg hover:bg-gray-800 transition-colors font-medium",children:"Close"})})]})})}const Nt={small:"w-32 h-32",medium:"w-48 h-48",large:"w-64 h-64"};function Pt({nodes:p,cardCount:t=2,minInterval:r=1e3,maxInterval:n=3e3,onCardClick:o,cardSize:s="medium",className:l=""}){const h=Math.min(Math.max(t,1),5),[u,g]=b.useState([]),[d,k]=b.useState([]),[x,P]=b.useState(Array(h).fill(!1)),[A,T]=b.useState(Array(h).fill(!1)),H=b.useRef([]),G=b.useCallback(v=>{const C=p.filter(j=>!v.includes(j._id));if(C.length===0)return null;const M=Math.floor(Math.random()*C.length);return C[M]},[p]),F=b.useCallback(()=>Math.random()*(n-r)+r,[r,n]);b.useEffect(()=>{if(p.length===0){g([]),k([]);return}const v=[],C=[],M=[];for(let j=0;j<h&&j<p.length;j++){const O=G(M);O&&(v.push(O),M.push(O._id))}for(let j=0;j<v.length;j++){const O=[v[j]._id,...v.filter((W,I)=>I!==j).map(W=>W._id)],y=G(O);y?C.push(y):C.push(v[j])}g(v),k(C)},[p,h,G]);const K=b.useCallback(v=>{const C=F(),M=setTimeout(()=>{P(j=>{const O=[...j];return O[v]=!O[v],O}),setTimeout(()=>{T(j=>{const O=[...j];return O[v]=!O[v],O}),setTimeout(()=>{const j=!A[v];j&&g(O=>{const y=[...O];return y[v]=d[v],y}),k(O=>{const y=[...O],I=[(j?d[v]:u[v])._id,...u.filter((B,V)=>V!==v).map(B=>B._id),...O.filter((B,V)=>V!==v).map(B=>B._id)],S=G(I);return S&&(y[v]=S),y}),setTimeout(()=>{K(v)},150)},200)},150)},C);H.current[v]=M},[F,G,u,d,A]),_=b.useRef(!1);b.useEffect(()=>{if(!(u.length===0||p.length<=1)&&!_.current){_.current=!0;for(let v=0;v<u.length;v++)K(v);return()=>{H.current.forEach(v=>clearTimeout(v)),H.current=[],_.current=!1}}},[u.length,p.length]);const L=v=>{o&&o(v)};return p.length===0?a.jsx("div",{className:`flex items-center justify-center p-8 ${l}`,children:a.jsx("p",{className:"text-gray-500",children:"No nodes available"})}):u.length===0?a.jsx("div",{className:`flex items-center justify-center p-8 ${l}`,children:a.jsx("p",{className:"text-gray-500",children:"Loading..."})}):a.jsx("div",{className:`flex gap-4 justify-center items-center flex-wrap ${l}`,children:u.map((v,C)=>{const M=d[C],j=A[C];return a.jsx("div",{className:`relative ${Nt[s]}`,style:{perspective:"1000px"},onClick:()=>L(j?M:v),children:a.jsxs("div",{className:"w-full h-full rounded-lg shadow-lg overflow-hidden cursor-pointer hover:shadow-xl",style:{transform:`rotateY(${x[C]?180:0}deg)`,transition:"transform 0.5s",transformStyle:"preserve-3d"},children:[a.jsx("div",{className:"absolute inset-0 transition-opacity duration-200",style:{opacity:j?0:1},children:a.jsxs("div",{style:{transform:x[C]?"scaleX(-1)":"scaleX(1)",width:"100%",height:"100%"},children:[a.jsx("img",{src:v.data.image,alt:v.title,className:"w-full h-full object-cover"}),a.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/70 to-transparent p-2",children:a.jsx("p",{className:"text-white text-sm font-medium truncate",children:v.title})})]})}),M&&a.jsx("div",{className:"absolute inset-0 transition-opacity duration-200",style:{opacity:j?1:0},children:a.jsxs("div",{style:{transform:x[C]?"scaleX(-1)":"scaleX(1)",width:"100%",height:"100%"},children:[a.jsx("img",{src:M.data.image,alt:M.title,className:"w-full h-full object-cover"}),a.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/70 to-transparent p-2",children:a.jsx("p",{className:"text-white text-sm font-medium truncate",children:M.title})})]})})]})},`slot-${C}`)})})}function je(p){if(!p)return"";const t=/=\?([^?]+)\?([BQbq])\?([^?]*)\?=/g;return p.replace(t,(r,n,o,s)=>{try{if(o.toUpperCase()==="B"){const l=atob(s);return decodeURIComponent(escape(l))}else if(o.toUpperCase()==="Q"){const l=s.replace(/_/g," ").replace(/=([0-9A-Fa-f]{2})/g,(h,u)=>String.fromCharCode(parseInt(u,16)));return decodeURIComponent(escape(l))}}catch(l){console.warn("MIME decode error:",l)}return r}).replace(/\s+/g," ").trim()}const At={background:"#ffffff",cardBackground:"#ffffff",selectedBackground:"#f5f5f5",unreadBackground:"#ffffff",text:"#111827",textSecondary:"#6b7280",border:"#e5e7eb",primary:"#3b82f6",danger:"#ef4444"};function $t({baseUrl:p,systemId:t,accountId:r,limit:n=30,folder:o,selectable:s=!0,showDetail:l=!1,emptyMessage:h="No emails",autoLoad:u=!0,onSelect:g,onSelectionChange:d,onDelete:k,onError:x,onLoad:P,renderItem:A,renderDetail:T,renderActions:H,renderEmpty:G,renderLoading:F,theme:K={}}){const _={...At,...K},[L,v]=b.useState([]),[C,M]=b.useState(!1),[j,O]=b.useState(null),[y,W]=b.useState(new Set),[I,S]=b.useState(null),[B,V]=b.useState(null),Q=b.useMemo(()=>t?new Ze({baseUrl:p,system_id:t}):null,[p,t]),te=b.useCallback(async()=>{if(Q){M(!0),O(null);try{const f=await Q.listEmails(r,n,o);if(f!=null&&f.messages){const w=[...f.messages].sort((z,J)=>new Date(J.date).getTime()-new Date(z.date).getTime());v(w),P==null||P(w)}}catch(f){const w=f instanceof Error?f:new Error("Failed to fetch emails");O(w.message),x==null||x(w)}M(!1)}},[Q,r,n,o,x,P]);b.useEffect(()=>{u&&te()},[u,te]),b.useEffect(()=>{te()},[o]);const ge=b.useCallback(f=>{g==null||g(f),l&&V(f)},[g,l]),ye=b.useCallback((f,w,z)=>{if(!s){g==null||g(f),l&&V(f);return}const J=f.uid;if(z.shiftKey&&I!==null){const ee=Math.min(I,w),Z=Math.max(I,w),Ne=L.slice(ee,Z+1).map(_e=>_e.uid),we=new Set(Ne);W(we),d==null||d(Array.from(we))}else if(z.ctrlKey||z.metaKey)W(ee=>{const Z=new Set(ee);return Z.has(J)?Z.delete(J):Z.add(J),d==null||d(Array.from(Z)),Z}),S(w);else{const ee=new Set([J]);W(ee),S(w),d==null||d(Array.from(ee))}},[s,I,L,y,g,d,l]),me=b.useCallback(async()=>{if(!(!Q||y.size===0))try{const f=await Q.trashEmails(r,Array.from(y));if(console.log("Trash result:",f),f.success&&f.moved>0){v(z=>z.filter(J=>!y.has(J.uid)));const w=Array.from(y);W(new Set),k==null||k(w)}else O("Failed to move emails to trash")}catch(f){const w=f instanceof Error?f:new Error("Trash failed");console.error("Trash error:",w),O(w.message),x==null||x(w)}},[Q,r,y,k,x]),xe=b.useCallback(async()=>{if(!(!Q||y.size===0))try{const f=await Q.archiveEmails(r,Array.from(y));if(console.log("Archive result:",f),f.success&&f.archived>0){v(z=>z.filter(J=>!y.has(J.uid)));const w=Array.from(y);W(new Set),k==null||k(w)}else O("Failed to archive emails")}catch(f){const w=f instanceof Error?f:new Error("Archive failed");console.error("Archive error:",w),O(w.message),x==null||x(w)}},[Q,r,y,k,x]),ve=b.useCallback(()=>{if(y.size===L.length)W(new Set),d==null||d([]);else{const f=new Set(L.map(w=>w.uid));W(f),d==null||d(Array.from(f))}},[L,y.size,d]),ke=b.useCallback(()=>{W(new Set),d==null||d([])},[d]),Re={delete:me,archive:xe,refresh:te,selectAll:ve,clearSelection:ke},ce=f=>{if(!f)return"";const w=new Date(f),z=new Date;return w.toDateString()===z.toDateString()?w.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):w.toLocaleDateString([],{month:"short",day:"numeric"})},ue=(f,w)=>a.jsx("div",{style:{padding:"12px 16px",background:w?_.selectedBackground:f.seen?_.cardBackground:_.unreadBackground,borderBottom:`1px solid ${_.border}`,cursor:"pointer",transition:"background 0.15s ease"},children:a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:"12px"},children:[a.jsxs("div",{style:{flex:1,minWidth:0},children:[a.jsx("div",{style:{fontSize:"14px",fontWeight:f.seen?400:600,color:_.text,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:je(f.from).split("@")[0]}),a.jsx("div",{style:{fontSize:"14px",fontWeight:f.seen?400:500,color:f.seen?_.textSecondary:_.text,marginTop:"2px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:je(f.subject)||"(No subject)"})]}),a.jsx("div",{style:{fontSize:"12px",color:_.textSecondary,flexShrink:0},children:ce(f.date)})]})}),se=f=>a.jsxs("div",{style:{padding:"24px"},children:[a.jsx("h2",{style:{margin:"0 0 8px",fontSize:"20px",color:_.text},children:je(f.subject)||"(No subject)"}),a.jsxs("div",{style:{fontSize:"14px",color:_.textSecondary,marginBottom:"16px"},children:["From: ",je(f.from)," • ",new Date(f.date).toLocaleString()]}),a.jsx("div",{style:{fontSize:"14px",color:_.text},children:"Email body not loaded. Implement getEmail(uid) to fetch full content."})]}),de=(f,w)=>a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 16px",background:_.cardBackground,borderBottom:`1px solid ${_.border}`},children:[a.jsx("button",{onClick:w.selectAll,style:{padding:"6px 12px",background:"transparent",border:`1px solid ${_.border}`,borderRadius:"6px",fontSize:"13px",cursor:"pointer",color:_.text},children:f.length===L.length?"Deselect All":"Select All"}),f.length>0&&a.jsxs(a.Fragment,{children:[a.jsxs("span",{style:{fontSize:"13px",color:_.textSecondary},children:[f.length," selected"]}),a.jsx("button",{onClick:w.archive,title:"Archive",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px",background:"transparent",border:`1px solid ${_.border}`,borderRadius:"6px",cursor:"pointer",color:_.textSecondary},children:a.jsx("span",{className:"material-icons",style:{fontSize:"18px"},children:"archive"})}),a.jsx("button",{onClick:w.delete,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px",background:"transparent",border:`1px solid ${_.border}`,borderRadius:"6px",cursor:"pointer",color:_.textSecondary},children:a.jsx("span",{className:"material-icons",style:{fontSize:"18px"},children:"delete"})})]}),a.jsx("div",{style:{flex:1}}),a.jsx("button",{onClick:w.refresh,title:"Refresh",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px",background:"transparent",border:`1px solid ${_.border}`,borderRadius:"6px",cursor:"pointer",color:_.textSecondary},children:a.jsx("span",{className:"material-icons",style:{fontSize:"18px"},children:"refresh"})})]}),ae=()=>a.jsx("div",{style:{padding:"48px",textAlign:"center",color:_.textSecondary},children:h}),Te=()=>a.jsx("div",{style:{padding:"48px",textAlign:"center",color:_.textSecondary},children:"Loading..."}),be=A||ue,Ce=T||se,Oe=H||de,ie=G||ae,re=F||Te;return C&&L.length===0?a.jsx("div",{style:{background:_.background,width:"100%",height:"100%"},children:re()}):a.jsxs("div",{style:{display:"flex",background:_.background,width:"100%",height:"100%"},children:[a.jsxs("div",{style:{flex:l&&B?"0 0 50%":"1",display:"flex",flexDirection:"column",borderRight:l&&B?`1px solid ${_.border}`:"none",overflow:"hidden"},children:[s&&Oe(Array.from(y),Re),j&&a.jsx("div",{style:{padding:"12px 16px",background:"#fef2f2",color:_.danger,fontSize:"14px",borderBottom:`1px solid ${_.border}`},children:j}),a.jsx("div",{style:{flex:1,overflowY:"auto"},children:L.length===0?ie():L.map((f,w)=>a.jsx("div",{onClick:z=>ye(f,w,z),onDoubleClick:()=>ge(f),children:be(f,y.has(f.uid))},f.uid))})]}),l&&B&&a.jsx("div",{style:{flex:1,overflowY:"auto"},children:Ce(B)})]})}exports.AnimatedCardFlip=Pt;exports.ApiClient=tt;exports.AuthManager=et;exports.Card=Ct;exports.DataOperations=Ee;exports.Detail=Ot;exports.GraphClient=jt;exports.Mail=$t;exports.MailClient=Ze;exports.Stack=Tt;exports.getApiClient=Ie;exports.initializeApiClient=Et;exports.useMutation=St;exports.useQuery=rt;
34
+ `,children:[d&&a.jsx("div",{className:"flex-shrink-0",children:a.jsx("img",{src:d,alt:o,className:"w-16 h-16 object-cover rounded-lg"})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("h3",{className:"font-medium text-gray-900 truncate",children:o}),g&&a.jsx("span",{className:"px-2 py-0.5 text-xs font-medium bg-blue-100 text-blue-800 rounded-full",children:g})]}),p&&a.jsx("p",{className:"text-sm text-gray-600 truncate mt-0.5",children:p})]}),t&&a.jsx("div",{className:"flex-shrink-0 text-gray-400",children:a.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})})})]})}function Ot({item:h,onClose:t,title:r=n=>n.title||n.name||n.label||"Detail",image:s=n=>n.image||n.thumbnail||n.photo,fields:i=[]}){if(!h)return null;const n=r(h),o=s(h);return a.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4",children:a.jsxs("div",{className:"bg-white rounded-xl max-w-2xl w-full max-h-[90vh] overflow-y-auto shadow-2xl",children:[a.jsxs("div",{className:"sticky top-0 bg-white border-b border-gray-200 px-6 py-4 flex items-center justify-between",children:[a.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:n}),t&&a.jsx("button",{onClick:t,className:"p-2 hover:bg-gray-100 rounded-lg transition-colors",children:a.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:a.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),a.jsxs("div",{className:"p-6",children:[o&&a.jsx("div",{className:"mb-6",children:a.jsx("img",{src:o,alt:n,className:"w-full h-64 object-cover rounded-lg"})}),i.length>0&&a.jsx("div",{className:"space-y-4",children:i.map((p,d)=>{const g=p.value(h);return g==null||g===""?null:a.jsxs("div",{children:[a.jsx("div",{className:"text-sm font-medium text-gray-500 mb-1",children:p.label}),a.jsx("div",{className:"text-base text-gray-900",children:typeof g=="object"?JSON.stringify(g,null,2):String(g)})]},d)})}),i.length===0&&a.jsx("pre",{className:"bg-gray-50 p-4 rounded-lg text-sm overflow-x-auto",children:JSON.stringify(h,null,2)})]}),t&&a.jsx("div",{className:"sticky bottom-0 bg-gray-50 border-t border-gray-200 px-6 py-4",children:a.jsx("button",{onClick:t,className:"w-full px-4 py-2 bg-gray-900 text-white rounded-lg hover:bg-gray-800 transition-colors font-medium",children:"Close"})})]})})}const Nt={small:"w-32 h-32",medium:"w-48 h-48",large:"w-64 h-64"};function At({nodes:h,cardCount:t=2,minInterval:r=1e3,maxInterval:s=3e3,onCardClick:i,cardSize:n="medium",className:o=""}){const p=Math.min(Math.max(t,1),5),[d,g]=w.useState([]),[c,_]=w.useState([]),[x,m]=w.useState(Array(p).fill(!1)),[k,C]=w.useState(Array(p).fill(!1)),V=w.useRef([]),I=w.useCallback(y=>{const N=h.filter(j=>!y.includes(j._id));if(N.length===0)return null;const D=Math.floor(Math.random()*N.length);return N[D]},[h]),F=w.useCallback(()=>Math.random()*(s-r)+r,[r,s]);w.useEffect(()=>{if(h.length===0){g([]),_([]);return}const y=[],N=[],D=[];for(let j=0;j<p&&j<h.length;j++){const A=I(D);A&&(y.push(A),D.push(A._id))}for(let j=0;j<y.length;j++){const A=[y[j]._id,...y.filter((G,L)=>L!==j).map(G=>G._id)],v=I(A);v?N.push(v):N.push(y[j])}g(y),_(N)},[h,p,I]);const Y=w.useCallback(y=>{const N=F(),D=setTimeout(()=>{m(j=>{const A=[...j];return A[y]=!A[y],A}),setTimeout(()=>{C(j=>{const A=[...j];return A[y]=!A[y],A}),setTimeout(()=>{const j=!k[y];j&&g(A=>{const v=[...A];return v[y]=c[y],v}),_(A=>{const v=[...A],L=[(j?c[y]:d[y])._id,...d.filter((z,J)=>J!==y).map(z=>z._id),...A.filter((z,J)=>J!==y).map(z=>z._id)],R=I(L);return R&&(v[y]=R),v}),setTimeout(()=>{Y(y)},150)},200)},150)},N);V.current[y]=D},[F,I,d,c,k]),E=w.useRef(!1);w.useEffect(()=>{if(!(d.length===0||h.length<=1)&&!E.current){E.current=!0;for(let y=0;y<d.length;y++)Y(y);return()=>{V.current.forEach(y=>clearTimeout(y)),V.current=[],E.current=!1}}},[d.length,h.length]);const M=y=>{i&&i(y)};return h.length===0?a.jsx("div",{className:`flex items-center justify-center p-8 ${o}`,children:a.jsx("p",{className:"text-gray-500",children:"No nodes available"})}):d.length===0?a.jsx("div",{className:`flex items-center justify-center p-8 ${o}`,children:a.jsx("p",{className:"text-gray-500",children:"Loading..."})}):a.jsx("div",{className:`flex gap-4 justify-center items-center flex-wrap ${o}`,children:d.map((y,N)=>{const D=c[N],j=k[N];return a.jsx("div",{className:`relative ${Nt[n]}`,style:{perspective:"1000px"},onClick:()=>M(j?D:y),children:a.jsxs("div",{className:"w-full h-full rounded-lg shadow-lg overflow-hidden cursor-pointer hover:shadow-xl",style:{transform:`rotateY(${x[N]?180:0}deg)`,transition:"transform 0.5s",transformStyle:"preserve-3d"},children:[a.jsx("div",{className:"absolute inset-0 transition-opacity duration-200",style:{opacity:j?0:1},children:a.jsxs("div",{style:{transform:x[N]?"scaleX(-1)":"scaleX(1)",width:"100%",height:"100%"},children:[a.jsx("img",{src:y.data.image,alt:y.title,className:"w-full h-full object-cover"}),a.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/70 to-transparent p-2",children:a.jsx("p",{className:"text-white text-sm font-medium truncate",children:y.title})})]})}),D&&a.jsx("div",{className:"absolute inset-0 transition-opacity duration-200",style:{opacity:j?1:0},children:a.jsxs("div",{style:{transform:x[N]?"scaleX(-1)":"scaleX(1)",width:"100%",height:"100%"},children:[a.jsx("img",{src:D.data.image,alt:D.title,className:"w-full h-full object-cover"}),a.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/70 to-transparent p-2",children:a.jsx("p",{className:"text-white text-sm font-medium truncate",children:D.title})})]})})]})},`slot-${N}`)})})}function _e(h){if(!h)return"";const t=/=\?([^?]+)\?([BQbq])\?([^?]*)\?=/g;return h.replace(t,(r,s,i,n)=>{try{if(i.toUpperCase()==="B"){const o=atob(n);return decodeURIComponent(escape(o))}else if(i.toUpperCase()==="Q"){const o=n.replace(/_/g," ").replace(/=([0-9A-Fa-f]{2})/g,(p,d)=>String.fromCharCode(parseInt(d,16)));return decodeURIComponent(escape(o))}}catch(o){console.warn("MIME decode error:",o)}return r}).replace(/\s+/g," ").trim()}const Pt={background:"#ffffff",cardBackground:"#ffffff",selectedBackground:"#f5f5f5",unreadBackground:"#ffffff",text:"#111827",textSecondary:"#6b7280",border:"#e5e7eb",primary:"#3b82f6",danger:"#ef4444"};function $t({baseUrl:h,systemId:t,accountId:r,limit:s=30,folder:i,selectable:n=!0,showDetail:o=!1,emptyMessage:p="No emails",autoLoad:d=!0,onSelect:g,onSelectionChange:c,onDelete:_,onError:x,onLoad:m,renderItem:k,renderDetail:C,renderActions:V,renderEmpty:I,renderLoading:F,theme:Y={}}){const E={...Pt,...Y},[M,y]=w.useState([]),[N,D]=w.useState(!1),[j,A]=w.useState(null),[v,G]=w.useState(new Set),[L,R]=w.useState(null),[z,J]=w.useState(null),K=w.useMemo(()=>t?new Ze({baseUrl:h,system_id:t}):null,[h,t]),te=w.useCallback(async()=>{if(K){D(!0),A(null);try{const f=await K.listEmailsSorted(r,i||"INBOX",s);f!=null&&f.messages&&(y(f.messages),m==null||m(f.messages))}catch(f){const S=f instanceof Error?f:new Error("Failed to fetch emails");A(S.message),x==null||x(S)}D(!1)}},[K,r,s,i,x,m]);w.useEffect(()=>{d&&te()},[d,te]),w.useEffect(()=>{te()},[i]);const ge=w.useCallback(f=>{g==null||g(f),o&&J(f)},[g,o]),me=w.useCallback((f,S,W)=>{if(!n){g==null||g(f),o&&J(f);return}const Q=f.uid;if(W.shiftKey&&L!==null){const ee=Math.min(L,S),Z=Math.max(L,S),Ne=M.slice(ee,Z+1).map(Ee=>Ee.uid),we=new Set(Ne);G(we),c==null||c(Array.from(we))}else if(W.ctrlKey||W.metaKey)G(ee=>{const Z=new Set(ee);return Z.has(Q)?Z.delete(Q):Z.add(Q),c==null||c(Array.from(Z)),Z}),R(S);else{const ee=new Set([Q]);G(ee),R(S),c==null||c(Array.from(ee))}},[n,L,M,v,g,c,o]),ye=w.useCallback(async()=>{if(!(!K||v.size===0))try{const f=await K.trashEmails(r,Array.from(v));if(console.log("Trash result:",f),f.success&&f.moved>0){y(W=>W.filter(Q=>!v.has(Q.uid)));const S=Array.from(v);G(new Set),_==null||_(S)}else A("Failed to move emails to trash")}catch(f){const S=f instanceof Error?f:new Error("Trash failed");console.error("Trash error:",S),A(S.message),x==null||x(S)}},[K,r,v,_,x]),xe=w.useCallback(async()=>{if(!(!K||v.size===0))try{const f=await K.archiveEmails(r,Array.from(v));if(console.log("Archive result:",f),f.success&&f.archived>0){y(W=>W.filter(Q=>!v.has(Q.uid)));const S=Array.from(v);G(new Set),_==null||_(S)}else A("Failed to archive emails")}catch(f){const S=f instanceof Error?f:new Error("Archive failed");console.error("Archive error:",S),A(S.message),x==null||x(S)}},[K,r,v,_,x]),ve=w.useCallback(()=>{if(v.size===M.length)G(new Set),c==null||c([]);else{const f=new Set(M.map(S=>S.uid));G(f),c==null||c(Array.from(f))}},[M,v.size,c]),ke=w.useCallback(()=>{G(new Set),c==null||c([])},[c]),Te={delete:ye,archive:xe,refresh:te,selectAll:ve,clearSelection:ke},ce=f=>{if(!f)return"";const S=new Date(f),W=new Date;return S.toDateString()===W.toDateString()?S.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):S.toLocaleDateString([],{month:"short",day:"numeric"})},ue=(f,S)=>a.jsx("div",{style:{padding:"12px 16px",background:S?E.selectedBackground:f.seen?E.cardBackground:E.unreadBackground,borderBottom:`1px solid ${E.border}`,cursor:"pointer",transition:"background 0.15s ease"},children:a.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:"12px"},children:[a.jsxs("div",{style:{flex:1,minWidth:0},children:[a.jsx("div",{style:{fontSize:"14px",fontWeight:f.seen?400:600,color:E.text,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:_e(f.from).split("@")[0]}),a.jsx("div",{style:{fontSize:"14px",fontWeight:f.seen?400:500,color:f.seen?E.textSecondary:E.text,marginTop:"2px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:_e(f.subject)||"(No subject)"})]}),a.jsx("div",{style:{fontSize:"12px",color:E.textSecondary,flexShrink:0},children:ce(f.date)})]})}),ne=f=>a.jsxs("div",{style:{padding:"24px"},children:[a.jsx("h2",{style:{margin:"0 0 8px",fontSize:"20px",color:E.text},children:_e(f.subject)||"(No subject)"}),a.jsxs("div",{style:{fontSize:"14px",color:E.textSecondary,marginBottom:"16px"},children:["From: ",_e(f.from)," • ",new Date(f.date).toLocaleString()]}),a.jsx("div",{style:{fontSize:"14px",color:E.text},children:"Email body not loaded. Implement getEmail(uid) to fetch full content."})]}),de=(f,S)=>a.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 16px",background:E.cardBackground,borderBottom:`1px solid ${E.border}`},children:[a.jsx("button",{onClick:S.selectAll,style:{padding:"6px 12px",background:"transparent",border:`1px solid ${E.border}`,borderRadius:"6px",fontSize:"13px",cursor:"pointer",color:E.text},children:f.length===M.length?"Deselect All":"Select All"}),f.length>0&&a.jsxs(a.Fragment,{children:[a.jsxs("span",{style:{fontSize:"13px",color:E.textSecondary},children:[f.length," selected"]}),a.jsx("button",{onClick:S.archive,title:"Archive",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px",background:"transparent",border:`1px solid ${E.border}`,borderRadius:"6px",cursor:"pointer",color:E.textSecondary},children:a.jsx("span",{className:"material-icons",style:{fontSize:"18px"},children:"archive"})}),a.jsx("button",{onClick:S.delete,title:"Delete",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px",background:"transparent",border:`1px solid ${E.border}`,borderRadius:"6px",cursor:"pointer",color:E.textSecondary},children:a.jsx("span",{className:"material-icons",style:{fontSize:"18px"},children:"delete"})})]}),a.jsx("div",{style:{flex:1}}),a.jsx("button",{onClick:S.refresh,title:"Refresh",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px",background:"transparent",border:`1px solid ${E.border}`,borderRadius:"6px",cursor:"pointer",color:E.textSecondary},children:a.jsx("span",{className:"material-icons",style:{fontSize:"18px"},children:"refresh"})})]}),ae=()=>a.jsx("div",{style:{padding:"48px",textAlign:"center",color:E.textSecondary},children:p}),Re=()=>a.jsx("div",{style:{padding:"48px",textAlign:"center",color:E.textSecondary},children:"Loading..."}),be=k||ue,Ce=C||ne,Oe=V||de,ie=I||ae,re=F||Re;return N&&M.length===0?a.jsx("div",{style:{background:E.background,width:"100%",height:"100%"},children:re()}):a.jsxs("div",{style:{display:"flex",background:E.background,width:"100%",height:"100%"},children:[a.jsxs("div",{style:{flex:o&&z?"0 0 50%":"1",display:"flex",flexDirection:"column",borderRight:o&&z?`1px solid ${E.border}`:"none",overflow:"hidden"},children:[n&&Oe(Array.from(v),Te),j&&a.jsx("div",{style:{padding:"12px 16px",background:"#fef2f2",color:E.danger,fontSize:"14px",borderBottom:`1px solid ${E.border}`},children:j}),a.jsx("div",{style:{flex:1,overflowY:"auto"},children:M.length===0?ie():M.map((f,S)=>a.jsx("div",{onClick:W=>me(f,S,W),onDoubleClick:()=>ge(f),children:be(f,v.has(f.uid))},f.uid))})]}),o&&z&&a.jsx("div",{style:{flex:1,overflowY:"auto"},children:Ce(z)})]})}exports.AnimatedCardFlip=At;exports.ApiClient=tt;exports.AuthManager=et;exports.Card=Ct;exports.DataOperations=je;exports.Detail=Ot;exports.GraphClient=_t;exports.Mail=$t;exports.MailClient=Ze;exports.Stack=Rt;exports.getApiClient=Be;exports.initializeApiClient=jt;exports.useMutation=St;exports.useQuery=rt;