your-ai-workflow-firebase-os 1.2.24 → 1.2.26
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/your-ai-workflow-firebase-os.cjs.js +45 -14
- package/dist/your-ai-workflow-firebase-os.es.js +703 -601
- package/package.json +1 -1
- package/src/prompts/pages/publicPage.ts +2 -1
- package/src/prompts/tabs/crud/admin.ts +14 -4
- package/src/prompts/tabs/crud/private.ts +14 -4
- package/src/prompts/tabs/crud/shared.ts +14 -4
- package/src/templates/AdminPageTemplate.tsx +35 -11
- package/src/templates/PrivatePageTemplate.tsx +31 -11
- package/src/templates/SharedPageTemplate.tsx +35 -11
|
@@ -4,7 +4,8 @@ export default function ${n}({ config }: { config: any }) {
|
|
|
4
4
|
return ( <div>your content here</div> );
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Styles — sections: \`className="glass-panel border border-[var(--panel-border)] rounded-2xl p-8"\`. Text: \`text-foreground\`, \`text-foreground/60\`. Accent: \`text-accent\`, \`bg-accent/10\`. Buttons: \`className="btn-primary px-6 py-3 rounded-xl font-bold"\`.
|
|
8
|
+
No page titles, no nav, no routing. Default export only.
|
|
8
9
|
|
|
9
10
|
[WHAT TO BUILD?]`},U="### Theme & Styling (Dynamic Firestore Theme)\nOur application uses a dynamic theme engine. You MUST use these global CSS variable tokens to ensure your design matches the user's active theme:\n- **Colors**: `var(--bg-color)`, `var(--fg-color)`, `var(--accent-color)`, `var(--accent-deep)`, `var(--panel-bg)`, `var(--panel-border)`.\n- **Text**: Use the `text-foreground` (standard), `text-accent` (primary), and `text-gradient` (headings) classes.\n- **Glassmorphism**: Always use the `.glass-panel` utility class for containers/cards.",W=`- **<Button />**, **<Input />**, **<ConfirmModal />**, **<DashboardNav />**, **<ContactPopup />**, **<CustomSelect />**.`,G=`- **<Button />**, **<Input />**, **<ConfirmModal />**, **<DashboardNav />**, **<CustomSelect />**.`,K=(e,t,n,r=[])=>`I need your help modifying the core Calendar Template which currently powers the "${e?.tabTitle||e?.tabName||t}" tab.
|
|
10
11
|
|
|
@@ -248,33 +249,63 @@ ${U}
|
|
|
248
249
|
|
|
249
250
|
[DESCRIBE FEATURE TO ADD HERE]`,ce=(e,t)=>{let n=`${(e.tabName||e.pageId||`shared_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`).split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}Content`;return`Create file: src/your-ai-workflow-firebase-os/microcomponents/${n}.tsx
|
|
250
251
|
|
|
251
|
-
export default function ${n}({ config }: { config: any }) {
|
|
252
|
+
export default function ${n}({ config, actions }: { config: any; actions: any }) {
|
|
253
|
+
const { records, saveRecord, deleteRecord, uploadFile, user, loading } = actions;
|
|
252
254
|
return ( <div>your content here</div> );
|
|
253
255
|
}
|
|
254
256
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
257
|
+
Collection: \`${t}\` — shared between all members.
|
|
258
|
+
|
|
259
|
+
Available actions from \`actions\` prop:
|
|
260
|
+
- \`records\` — live array of all members' records
|
|
261
|
+
- \`saveRecord({ name, note, ...fields })\` — save a record with any custom fields
|
|
262
|
+
- \`deleteRecord(id)\` — delete by ID
|
|
263
|
+
- \`uploadFile()\` — trigger file upload dialog
|
|
264
|
+
- \`user\` — current Firebase user
|
|
265
|
+
- \`loading\` — boolean
|
|
266
|
+
|
|
267
|
+
Styles — cards: \`glass-panel border border-[var(--panel-border)] rounded-2xl p-6\`. Text: \`text-foreground\`, \`text-foreground/60\`. Accent: \`text-accent\`, \`bg-accent/10\`. Buttons: \`btn-primary px-4 py-2 rounded-xl text-sm font-bold\`.
|
|
268
|
+
No page titles, no nav, no routing. Default export only.
|
|
258
269
|
|
|
259
270
|
[WHAT TO BUILD?]`},le=(e,t)=>{let n=`${(e.tabName||e.pageId||`admin_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`).split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}Content`;return`Create file: src/your-ai-workflow-firebase-os/microcomponents/${n}.tsx
|
|
260
271
|
|
|
261
|
-
export default function ${n}({ config }: { config: any }) {
|
|
272
|
+
export default function ${n}({ config, actions }: { config: any; actions: any }) {
|
|
273
|
+
const { records, saveRecord, deleteRecord, uploadFile, user, loading } = actions;
|
|
262
274
|
return ( <div>your content here</div> );
|
|
263
275
|
}
|
|
264
276
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
277
|
+
Collection: \`${t}\`
|
|
278
|
+
|
|
279
|
+
Available actions from \`actions\` prop:
|
|
280
|
+
- \`records\` — live array of saved records
|
|
281
|
+
- \`saveRecord({ name, note, ...fields })\` — save a record with any custom fields
|
|
282
|
+
- \`deleteRecord(id)\` — delete by ID
|
|
283
|
+
- \`uploadFile()\` — trigger file upload dialog
|
|
284
|
+
- \`user\` — current Firebase user
|
|
285
|
+
- \`loading\` — boolean
|
|
286
|
+
|
|
287
|
+
Styles — cards: \`glass-panel border border-[var(--panel-border)] rounded-2xl p-6\`. Text: \`text-foreground\`, \`text-foreground/60\`. Accent: \`text-accent\`, \`bg-accent/10\`. Buttons: \`btn-primary px-4 py-2 rounded-xl text-sm font-bold\`.
|
|
288
|
+
No page titles, no nav, no routing. Default export only.
|
|
268
289
|
|
|
269
290
|
[WHAT TO BUILD?]`},ue=(e,t)=>{let n=`${(e.tabName||e.pageId||`private_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`).split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}Content`;return`Create file: src/your-ai-workflow-firebase-os/microcomponents/${n}.tsx
|
|
270
291
|
|
|
271
|
-
export default function ${n}({ config }: { config: any }) {
|
|
292
|
+
export default function ${n}({ config, actions }: { config: any; actions: any }) {
|
|
293
|
+
const { records, saveRecord, deleteRecord, uploadFile, user, loading } = actions;
|
|
272
294
|
return ( <div>your content here</div> );
|
|
273
295
|
}
|
|
274
296
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
297
|
+
Collection: \`${t}\` — private per user (auto-filtered by uid).
|
|
298
|
+
|
|
299
|
+
Available actions from \`actions\` prop:
|
|
300
|
+
- \`records\` — live array of current user's records
|
|
301
|
+
- \`saveRecord({ name, note, ...fields })\` — save a record with any custom fields
|
|
302
|
+
- \`deleteRecord(id)\` — delete by ID
|
|
303
|
+
- \`uploadFile()\` — trigger file upload dialog
|
|
304
|
+
- \`user\` — current Firebase user
|
|
305
|
+
- \`loading\` — boolean
|
|
306
|
+
|
|
307
|
+
Styles — cards: \`glass-panel border border-[var(--panel-border)] rounded-2xl p-6\`. Text: \`text-foreground\`, \`text-foreground/60\`. Accent: \`text-accent\`, \`bg-accent/10\`. Buttons: \`btn-primary px-4 py-2 rounded-xl text-sm font-bold\`.
|
|
308
|
+
No page titles, no nav, no routing. Default export only.
|
|
278
309
|
|
|
279
310
|
[WHAT TO BUILD?]`},de=[{text:`text-red-400`,bgCircle:`bg-red-400`,bgCard:`bg-red-500/[0.08]`,borderCard:`border-red-500/30`,bgLight:`bg-red-500/15`,bgHover:`hover:bg-red-500`,bgAlt:`bg-red-500/[0.04]`,name:`Red`},{text:`text-orange-400`,bgCircle:`bg-orange-400`,bgCard:`bg-orange-500/[0.08]`,borderCard:`border-orange-500/30`,bgLight:`bg-orange-500/15`,bgHover:`hover:bg-orange-500`,bgAlt:`bg-orange-500/[0.04]`,name:`Orange`},{text:`text-yellow-400`,bgCircle:`bg-yellow-400`,bgCard:`bg-yellow-500/[0.08]`,borderCard:`border-yellow-500/30`,bgLight:`bg-yellow-500/15`,bgHover:`hover:bg-yellow-500`,bgAlt:`bg-yellow-500/[0.04]`,name:`Yellow`},{text:`text-green-400`,bgCircle:`bg-green-400`,bgCard:`bg-green-500/[0.08]`,borderCard:`border-green-500/30`,bgLight:`bg-green-500/15`,bgHover:`hover:bg-green-500`,bgAlt:`bg-green-500/[0.04]`,name:`Green`},{text:`text-blue-400`,bgCircle:`bg-blue-400`,bgCard:`bg-blue-500/[0.08]`,borderCard:`border-blue-500/30`,bgLight:`bg-blue-500/15`,bgHover:`hover:bg-blue-500`,bgAlt:`bg-blue-500/[0.04]`,name:`Blue`},{text:`text-accent`,bgCircle:`bg-accent`,bgCard:`bg-accent/[0.08]`,borderCard:`border-accent/30`,bgLight:`bg-accent/15`,bgHover:`hover:bg-accent`,bgAlt:`bg-accent/[0.04]`,name:`Purple`},{text:`text-pink-400`,bgCircle:`bg-pink-400`,bgCard:`bg-pink-500/[0.08]`,borderCard:`border-pink-500/30`,bgLight:`bg-pink-500/15`,bgHover:`hover:bg-pink-500`,bgAlt:`bg-pink-500/[0.04]`,name:`Pink`},{text:`text-foreground/60`,bgCircle:`bg-foreground/30`,bgCard:`bg-foreground/[0.04]`,borderCard:`border-[var(--panel-border)]/50`,bgLight:`bg-foreground/15`,bgHover:`hover:bg-foreground/30`,bgAlt:`bg-foreground/[0.02]`,name:`Default`}];function fe({title:e=`Board View`,subtitle:t=`/templates/board`,backUrl:r=`/templates`,tasksCollection:i=`pub_tasks`,categoriesCollection:s=`pub_categories`,config:c}){let{user:d}=m(),f=!!c;c?.isPrivate&&!c?.isAdmin&&c?.isShared;let p=c?.isAdmin||c?.isShared,h=f?p:!0,g=c?.showButton!==!1,_=c?.buttonText||`+`,v=c?.buttonStyle||`primary`,y=c?.keyName||`key`,b=c?.valueName||`value`,[x,S]=(0,a.useState)([]),[C,w]=(0,a.useState)([]),[T,E]=(0,a.useState)([]),[D,O]=(0,a.useState)(null),[k,A]=(0,a.useState)(null),[j,M]=(0,a.useState)({name:``}),[N,P]=(0,a.useState)([]),[F,I]=(0,a.useState)(null),[L,R]=(0,a.useState)(null),[z,B]=(0,a.useState)(null),[V,ne]=(0,a.useState)(null),[H,U]=(0,a.useState)(!1),[W,G]=(0,a.useState)(null),[K,re]=(0,a.useState)(``),[ie,ae]=(0,a.useState)(null),[oe,se]=(0,a.useState)(!1),ce=c?.isAdmin?J(c,e,i,s):c?.isPrivate?q(c,e,i,s,T):Y(c,e,i,s,T),le=()=>{navigator.clipboard.writeText(ce),se(!0),setTimeout(()=>se(!1),2e3)};(0,a.useEffect)(()=>{let e=c?.isShared,t=c?.isAdmin,r=c?.isPrivate&&!t&&!e,a=!t&&!e&&!r;r||a?(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{let t=a?`public`:`private`;E(e.docs.filter(e=>e.data().formType===t).map(e=>e.id))}):E([]);let l=i.startsWith(`user_`),u=s.startsWith(`user_`);if(l&&!d)return;try{let e=localStorage.getItem(`fbos_board_tasks_${i}`);e&&S(JSON.parse(e));let t=localStorage.getItem(`fbos_board_cats_${s}`);t&&w(JSON.parse(t))}catch{}let f=(0,o.onSnapshot)(l&&d?(0,o.query)((0,o.collection)(n.Tt,i),(0,o.where)(`uid`,`==`,d.uid)):(0,o.collection)(n.Tt,i),e=>{let t=[];e.forEach(e=>{let n=e.data();t.push({id:e.id,categoryId:n.categoryId,name:n.name||n.text||`Unnamed Item`,fields:n.fields||(n.value?[{key:`Label`,value:n.value}]:[]),order:n.order||0})});let n=t.sort((e,t)=>(e.order||0)-(t.order||0));S(n),localStorage.setItem(`fbos_board_tasks_${i}`,JSON.stringify(n))}),p=(0,o.onSnapshot)(u&&d?(0,o.query)((0,o.collection)(n.Tt,s),(0,o.where)(`uid`,`==`,d.uid)):(0,o.collection)(n.Tt,s),e=>{let t=[];if(e.forEach(e=>{t.push({id:e.id,...e.data()})}),t.length===0){let e=[{id:`todo`,title:`To Do`,createdAt:Date.now()-2e3},{id:`in_progress`,title:`In Progress`,createdAt:Date.now()-1e3},{id:`review`,title:`Review`,createdAt:Date.now()}],t=d?{uid:d.uid}:{};e.forEach(e=>(0,o.setDoc)((0,o.doc)(n.Tt,s,e.id),{...t,title:e.title,createdAt:e.createdAt}))}else w(t),localStorage.setItem(`fbos_board_cats_${s}`,JSON.stringify(t))});return()=>{f(),p()}},[i,s,d]);let ue=(e,t)=>{t?(A(t.id),M({id:t.id,name:t.name}),P(t.fields?.length?[...t.fields,{key:``,value:``}]:[{key:``,value:``}])):(O(e),M({name:``}),P([{key:``,value:``}]))},fe=(e,t,n)=>{let r=[...N];r[e]={key:t,value:n},e===N.length-1&&(t.trim()!==``||n.trim()!==``)&&r.push({key:``,value:``}),P(r)},X=(e,t)=>{e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`taskId`,t),I(t)},pe=(e,t)=>{e.preventDefault(),e.stopPropagation(),t!==F&&R(t)},me=(e,t)=>{e.preventDefault(),e.stopPropagation(),B(t)},Z=e=>{e.preventDefault(),R(null),B(null)},he=async(e,t,r)=>{e.preventDefault(),e.stopPropagation(),R(null),B(null);let a=e.dataTransfer.getData(`taskId`);if(!a||a===r){I(null);return}let s=x.find(e=>e.id===a);if(!s)return;let c=x.filter(e=>e.categoryId===t).sort((e,t)=>(e.order||0)-(t.order||0));if(s.categoryId===t?(c=c.filter(e=>e.id!==a),c.push(s)):c.push({...s,categoryId:t}),r){let e=c.findIndex(e=>e.id===r),t=c.findIndex(e=>e.id===a),[n]=c.splice(t,1);c.splice(e,0,n)}c.forEach((e,r)=>{let a={categoryId:t,order:r};d&&(a.uid=d.uid),(0,o.setDoc)((0,o.doc)(n.Tt,i,e.id),a,{merge:!0})}),I(null)},ge=async e=>{let t=j.id||`item_${Date.now()}`,r=j.name.trim(),a=r||`Untitled Item`,s=N.filter(e=>e.key.trim()!==``||e.value.trim()!==``),c=!0,l=j.id?x.find(e=>e.id===j.id):null;if(l){let e=JSON.stringify(l.fields||[]),t=JSON.stringify(s);l.name===a&&e===t&&(c=!1)}else !r&&s.length===0&&(c=!1);if(!c){O(null),A(null);return}ne(j.id||`new`);let u={categoryId:e,name:a,fields:s};d&&!j.id&&(u.uid=d.uid),await(0,o.setDoc)((0,o.doc)(n.Tt,i,t),u,{merge:!0}),setTimeout(()=>{O(null),A(null),ne(null)},400)},_e=(e,t)=>{ae({type:`item`,id:e,title:t})},ve=async()=>{let e=`cat_${Date.now()}`,t={title:``,createdAt:Date.now()};d&&(t.uid=d.uid),await(0,o.setDoc)((0,o.doc)(n.Tt,s,e),t),G(e),re(``),setTimeout(()=>{let e=document.getElementById(`board-container`);e&&e.scrollTo({left:e.scrollWidth,behavior:`smooth`})},150)},Q=async e=>{K.trim()?await(0,o.setDoc)((0,o.doc)(n.Tt,s,e),{title:K},{merge:!0}):await(0,o.deleteDoc)((0,o.doc)(n.Tt,s,e)),G(null)},ye=(e,t)=>{ae({type:`category`,id:e,title:t})},be=async()=>{if(ie){U(!0);try{if(ie.type===`item`)await(0,o.deleteDoc)((0,o.doc)(n.Tt,i,ie.id)),A(null);else{let e=x.filter(e=>e.categoryId===ie.id);for(let t of e)await(0,o.deleteDoc)((0,o.doc)(n.Tt,i,t.id));await(0,o.deleteDoc)((0,o.doc)(n.Tt,s,ie.id))}}catch{}U(!1),ae(null)}},xe=[...C].sort((e,t)=>(e.createdAt||0)-(t.createdAt||0));return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen overflow-x-hidden`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e}),t&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),t]})]}),f&&(0,l.jsx)(`div`,{className:`mb-6`,children:(0,l.jsx)(ee,{})}),(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between items-start sm:items-center mb-6 border-b border-[var(--panel-border)] pb-6 gap-4 relative z-20 shrink-0`,children:[!f&&r&&(0,l.jsxs)(u.Link,{to:r,className:`px-5 py-2 hover:bg-foreground/5 transition-all flex items-center gap-2`,style:{borderRadius:`var(--btn-radius, 0.75rem)`},children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` Go Back`]}),f&&(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:c?.tabTitle||c?.tabName||e}),(0,l.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[x.length,` `,x.length===1?`item`:`items`,` · `,xe.length,` `,xe.length===1?`category`:`categories`]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 w-full sm:w-auto`,children:[c?.showPrompt&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:le,title:oe?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${oe?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary shadow-lg`}`,children:oe?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),g&&(0,l.jsx)(n.n,{variant:v===`secondary`?`secondary`:void 0,onClick:ve,className:`flex-1 sm:flex-none px-3 py-2.5 text-[14px] font-bold rounded-xl shadow-lg hover:-translate-y-0.5 transition-all shrink-0`,children:_===`+`?(0,l.jsx)(n.C,{className:`w-4 h-4`}):_})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative z-40 min-h-0`,children:(0,l.jsxs)(`div`,{id:`board-container`,className:`w-full h-full flex flex-row gap-4 md:gap-6 overflow-x-auto pb-4 snap-x snap-mandatory styled-scrollbars items-start`,children:[xe.map((e,t)=>{let r=x.filter(t=>t.categoryId===e.id);r.sort((e,t)=>(e.order||0)-(t.order||0));let i=de.find(t=>t.text===e.color)||de.find(e=>e.text===`text-accent`);return i.text,i.bgLight,i.bgHover,(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:t*.1},className:`w-[300px] md:w-[320px] shrink-0 flex flex-col max-h-full rounded-3xl p-4 snap-center relative border transition-colors ${de.find(t=>t.text===e.color)?.bgCard||`bg-foreground/[0.02]`} ${de.find(t=>t.text===e.color)?.borderCard||`border-[var(--panel-border)]/50`}`,children:[(0,l.jsx)(`div`,{className:`flex items-center justify-between mb-4 px-2 relative z-[200]`,children:(0,l.jsxs)(`h3`,{className:`font-bold text-[14px] flex items-center w-full text-foreground/80 group relative z-[200]`,children:[W===e.id?(0,l.jsxs)(`div`,{className:`relative flex-1 w-full flex items-center pr-8 z-[200]`,children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),Q(e.id)}}),(0,l.jsx)(`input`,{value:K,onChange:e=>re(e.target.value),onBlur:t=>{t.relatedTarget?.closest(`.category-color-picker`)||Q(e.id)},onKeyDown:t=>t.key===`Enter`&&Q(e.id),className:`bg-transparent border-none outline-none font-bold text-[14px] w-full p-0 ${e.color||`text-foreground/80`}`,placeholder:`Category name`}),(0,l.jsxs)(`div`,{className:`absolute top-8 left-0 flex gap-1.5 bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-[100] category-color-picker items-center`,tabIndex:-1,children:[(0,l.jsx)(`button`,{onClick:async t=>{t.preventDefault(),t.stopPropagation(),await(0,o.setDoc)((0,o.doc)(n.Tt,`pub_categories`,e.id),{color:``},{merge:!0}),G(null)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Reset Category Color`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})}),(0,l.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),de.map(t=>(0,l.jsx)(`button`,{onMouseDown:async r=>{r.preventDefault(),await(0,o.setDoc)((0,o.doc)(n.Tt,`pub_categories`,e.id),{color:t.text},{merge:!0})},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50 shrink-0`},t.name))]})]}):(0,l.jsxs)(`div`,{className:`flex items-center gap-2 w-full cursor-pointer hover:text-foreground transition-colors pr-8`,onClick:()=>{G(e.id),re(e.title)},children:[(0,l.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${de.find(t=>t.text===e.color)?.bgCircle||`bg-foreground/20`} transition-colors shrink-0`}),(0,l.jsx)(`span`,{className:`truncate flex-1 max-w-[200px] ${e.color||``}`,children:e.title||`Untitled Category`}),(0,l.jsx)(`span`,{className:`text-[11px] bg-foreground/10 text-foreground/60 px-1.5 py-0.5 rounded-md font-medium shrink-0`,children:r.length})]}),C.length>1&&(0,l.jsx)(`button`,{onClick:()=>ye(e.id,e.title),className:`absolute right-0 opacity-0 group-hover:opacity-100 text-foreground/30 hover:text-red-500 transition-all shrink-0`,children:(0,l.jsx)(n.m,{className:`w-3.5 h-3.5`})})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-2.5 flex-1 overflow-y-auto styled-scrollbars pr-1 relative min-h-[150px] rounded-xl transition-all ${z===e.id&&!L?`bg-foreground/5 scale-[1.01] border-dashed border border-accent/20`:``}`,onDragOver:t=>me(t,e.id),onDragLeave:Z,onDrop:t=>he(t,e.id),children:[(0,l.jsx)(n.a,{children:r.map(t=>k===t.id?(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-md border border-accent/40 transition-all flex flex-col gap-2 relative z-[100]`,children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),ge(e.id)}}),(0,l.jsx)(`textarea`,{placeholder:`Write an item name...`,className:`no-glow bg-transparent border-none outline-none text-[13px] text-foreground/90 font-medium leading-snug resize-none w-full min-h-[40px] relative z-10`,value:j.name,onChange:e=>M({...j,name:e.target.value}),onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),ge(e.id))}}),(0,l.jsx)(`div`,{className:`flex flex-col gap-2 mt-1 relative z-10 w-full`,children:N.map((t,n)=>(0,l.jsxs)(`div`,{className:`flex items-start bg-foreground/[0.04] border border-[var(--panel-border)]/50 rounded-[8px] px-2.5 py-1.5 w-full`,children:[(0,l.jsx)(`input`,{placeholder:y,value:t.key,onChange:e=>fe(n,e.target.value,t.value),onKeyDown:t=>t.key===`Enter`&&ge(e.id),className:`no-glow bg-transparent outline-none text-[11px] text-foreground/50 font-bold placeholder:text-foreground/30 relative top-[1px] shrink-0`,style:{width:`${Math.max(3,t.key.length||y.length)}ch`}}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative top-[1px]`,children:`:`}),(0,l.jsx)(`textarea`,{rows:1,placeholder:b,value:t.value,onChange:e=>fe(n,t.key,e.target.value),onInput:e=>{let t=e.target;t.style.height=`auto`,t.style.height=t.scrollHeight+`px`},onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),ge(e.id))},className:`no-glow bg-transparent outline-none text-[12px] text-foreground/90 font-medium flex-1 min-w-[40px] placeholder:opacity-40 resize-none overflow-hidden leading-tight relative top-[1px]`})]},n))}),V===t.id&&(0,l.jsx)(`div`,{className:`flex items-center justify-end pt-1`,children:(0,l.jsx)(`div`,{className:`w-3 h-3 border-2 border-accent border-t-transparent rounded-full animate-spin`})})]},t.id):(0,l.jsxs)(n.i.div,{draggable:!0,onDragStart:e=>X(e,t.id),onDragOver:e=>pe(e,t.id),onDragLeave:Z,onDrop:n=>he(n,e.id,t.id),initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-sm hover:shadow-md cursor-grab active:cursor-grabbing hover:border-accent/40 transition-all group flex flex-col gap-2 relative z-10 border ${L===t.id?`border-accent border-t-2 translate-y-1`:`border-[var(--panel-border)]`} ${F===t.id?`opacity-30 scale-95 border-dashed border-2`:``}`,children:[(0,l.jsxs)(`div`,{className:`absolute top-2 right-2 flex items-center gap-1.5 opacity-0 group-hover:opacity-100 transition-opacity bg-background/90 backdrop-blur-md border border-[var(--panel-border)] rounded-lg p-1 z-20 shadow-md`,children:[(0,l.jsx)(`button`,{onClick:n=>{n.stopPropagation(),ue(e.id,t)},className:`p-1 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-accent transition-colors`,children:(0,l.jsx)(n.w,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),_e(t.id,t.name)},className:`p-1 hover:bg-red-500/10 rounded-md text-foreground/60 hover:text-red-500 transition-colors`,children:(0,l.jsx)(n.m,{className:`w-3.5 h-3.5`})})]}),(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/90 font-medium leading-snug break-words pr-12`,children:t.name}),t.fields&&t.fields.length>0&&(0,l.jsx)(`div`,{className:`flex flex-row flex-wrap gap-2 mt-2`,children:t.fields.map((e,t)=>(0,l.jsxs)(`div`,{className:`inline-flex bg-foreground/[0.04] border border-[var(--panel-border)]/50 rounded-[8px] px-2.5 py-1.5 max-w-full`,children:[(0,l.jsxs)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative -top-[1px] shrink-0 break-all`,children:[e.key,`:`]}),(0,l.jsx)(`span`,{className:`text-[12px] text-foreground/90 font-medium break-words leading-tight min-w-0`,children:e.value})]},t))}),(0,l.jsxs)(`div`,{className:`flex items-end justify-between mt-3 pt-3 border-t border-[var(--panel-border)]/50 w-full gap-2`,children:[h&&f&&d?(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 pr-2 border-r border-[var(--panel-border)] border-dashed mr-auto`,children:[d.photoURL?(0,l.jsx)(`img`,{src:d.photoURL,className:`w-4 h-4 rounded-full shrink-0 object-cover`}):(0,l.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-accent/20 text-accent flex items-center justify-center text-[9px] font-bold shrink-0`,children:(d.displayName||d.email||`U`)[0].toUpperCase()}),(0,l.jsx)(`span`,{className:`text-[10px] font-bold text-foreground/60 truncate max-w-[80px]`,children:d.displayName||d.email?.split(`@`)[0]||`User`})]}):(0,l.jsx)(`div`,{className:`flex items-center gap-2 pr-2 border-r border-[var(--panel-border)] border-dashed mr-auto`}),(0,l.jsx)(`span`,{className:`text-[10px] text-foreground/40 font-bold text-right pt-0.5 shrink-0 max-w-[50%] truncate flex-1`,children:t.id.startsWith(`item_`)?new Date(parseInt(t.id.split(`_`)[1])).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}):`Recently Added`})]})]},t.id))}),D===e.id?(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-md border border-accent/40 transition-all flex flex-col gap-2 relative z-[100] mt-1`,children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),ge(e.id)}}),(0,l.jsx)(`textarea`,{placeholder:`Write an item name...`,className:`no-glow bg-transparent border-none outline-none text-[13px] text-foreground/90 font-medium leading-snug resize-none w-full min-h-[40px] relative z-10`,value:j.name,onChange:e=>M({...j,name:e.target.value}),onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),ge(e.id))},autoFocus:!0}),(0,l.jsx)(`div`,{className:`flex flex-col gap-2 mt-1 relative z-10 w-full`,children:N.map((t,n)=>(0,l.jsxs)(`div`,{className:`flex items-start bg-foreground/[0.04] border border-[var(--panel-border)]/50 rounded-[8px] px-2.5 py-1.5 w-full`,children:[(0,l.jsx)(`input`,{placeholder:y,style:{width:`${Math.max(3,t.key.length||y.length)}ch`},value:t.key,onChange:e=>fe(n,e.target.value,t.value),onKeyDown:t=>t.key===`Enter`&&ge(e.id),className:`no-glow bg-transparent outline-none text-[11px] text-foreground/50 font-bold placeholder:text-foreground/30 relative top-[1px]`}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative top-[1px]`,children:`:`}),(0,l.jsx)(`textarea`,{rows:1,placeholder:b,value:t.value,onChange:e=>fe(n,t.key,e.target.value),onInput:e=>{let t=e.target;t.style.height=`auto`,t.style.height=t.scrollHeight+`px`},onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),ge(e.id))},className:`no-glow bg-transparent outline-none text-[12px] text-foreground/90 font-medium flex-1 min-w-[40px] placeholder:opacity-40 resize-none overflow-hidden leading-tight relative top-[1px]`})]},n))}),V===`new`&&(0,l.jsx)(`div`,{className:`flex items-center justify-end pt-1`,children:(0,l.jsx)(`div`,{className:`w-3 h-3 border-2 border-accent border-t-transparent rounded-full animate-spin`})})]}):(0,l.jsxs)(`button`,{onClick:()=>ue(e.id),className:`flex items-center gap-2 justify-center w-full py-2.5 mt-1 rounded-xl border border-transparent text-[12px] font-bold text-foreground/40 hover:text-foreground hover:bg-foreground/[0.03] transition-all shrink-0`,children:[(0,l.jsx)(n.C,{className:`w-4 h-4`}),` Add Item`]})]})]},e.id)}),(0,l.jsx)(`div`,{className:`w-[10px] shrink-0 pointer-events-none`})]})}),(0,l.jsx)(`style`,{children:`.styled-scrollbars::-webkit-scrollbar { width: 6px; height: 6px; } .styled-scrollbars::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--accent-color) 20%, transparent); border-radius: 4px; } .styled-scrollbars::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--accent-color) 40%, transparent); }`}),(0,l.jsx)(te,{isOpen:!!ie,title:`Confirm Deletion`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:ie?.title}),` This action is permanent.`]}),onConfirm:be,onCancel:()=>ae(null),isProcessing:H,confirmText:`Yes, Delete`})]})}function X(e){return Array.isArray?Array.isArray(e):be(e)===`[object Array]`}function pe(e){if(typeof e==`string`)return e;if(typeof e==`bigint`)return e.toString();let t=e+``;return t==`0`&&1/e==-1/0?`-0`:t}function me(e){return e==null?``:pe(e)}function Z(e){return typeof e==`string`}function he(e){return typeof e==`number`}function ge(e){return e===!0||e===!1||ve(e)&&be(e)==`[object Boolean]`}function _e(e){return typeof e==`object`}function ve(e){return _e(e)&&e!==null}function Q(e){return e!=null}function ye(e){return!e.trim().length}function be(e){return e==null?e===void 0?`[object Undefined]`:`[object Null]`:Object.prototype.toString.call(e)}var xe=`Incorrect 'index' type`,Se=e=>`Invalid value for key ${e}`,Ce=e=>`Pattern length exceeds max of ${e}.`,we=e=>`Missing ${e} property in key`,Te=e=>`Property 'weight' in key '${e}' must be a positive integer`,Ee=Object.prototype.hasOwnProperty,De=class{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(e=>{let n=Oe(e);this._keys.push(n),this._keyMap[n.id]=n,t+=n.weight}),this._keys.forEach(e=>{e.weight/=t})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function Oe(e){let t=null,n=null,r=null,i=1,a=null;if(Z(e)||X(e))r=e,t=ke(e),n=Ae(e);else{if(!Ee.call(e,`name`))throw Error(we(`name`));let o=e.name;if(r=o,Ee.call(e,`weight`)&&(i=e.weight,i<=0))throw Error(Te(o));t=ke(o),n=Ae(o),a=e.getFn}return{path:t,id:n,weight:i,src:r,getFn:a}}function ke(e){return X(e)?e:e.split(`.`)}function Ae(e){return X(e)?e.join(`.`):e}function je(e,t){let n=[],r=!1,i=(e,t,a,o)=>{if(Q(e))if(!t[a])n.push(o===void 0?e:{v:e,i:o});else{let s=e[t[a]];if(!Q(s))return;if(a===t.length-1&&(Z(s)||he(s)||ge(s)||typeof s==`bigint`))n.push(o===void 0?me(s):{v:me(s),i:o});else if(X(s)){r=!0;for(let e=0,n=s.length;e<n;e+=1)i(s[e],t,a+1,e)}else t.length&&i(s,t,a+1,o)}};return i(e,Z(t)?t.split(`.`):t,0),r?n:n[0]}var Me={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Ne={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(e,t)=>e.score===t.score?e.idx<t.idx?-1:1:e.score<t.score?-1:1},Pe={location:0,threshold:.6,distance:100},Fe={useExtendedSearch:!1,useTokenSearch:!1,getFn:je,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1},$=Object.freeze({...Ne,...Me,...Pe,...Fe}),Ie=/[^ ]+/g;function Le(e=1,t=3){let n=new Map,r=10**t;return{get(t){let i=t.match(Ie).length;if(n.has(i))return n.get(i);let a=1/i**(.5*e),o=parseFloat(Math.round(a*r)/r);return n.set(i,o),o},clear(){n.clear()}}}var Re=class{constructor({getFn:e=$.getFn,fieldNormWeight:t=$.fieldNormWeight}={}){this.norm=Le(t,3),this.getFn=e,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((e,t)=>{this._keysMap[e.id]=t})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,Z(this.docs[0])?this.docs.forEach((e,t)=>{this._addString(e,t)}):this.docs.forEach((e,t)=>{this._addObject(e,t)}),this.norm.clear())}add(e){let t=this.size();Z(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,n=this.size();t<n;t+=1)--this.records[t].i}removeAll(e){for(let t=e.length-1;t>=0;--t)this.records.splice(e[t],1);for(let e=0,t=this.records.length;e<t;e+=1)this.records[e].i=e}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_addString(e,t){if(!Q(e)||ye(e))return;let n={v:e,i:t,n:this.norm.get(e)};this.records.push(n)}_addObject(e,t){let n={i:t,$:{}};this.keys.forEach((t,r)=>{let i=t.getFn?t.getFn(e):this.getFn(e,t.path);if(Q(i)){if(X(i)){let e=[];for(let t=0,n=i.length;t<n;t+=1){let n=i[t];if(Q(n)){if(Z(n)){if(!ye(n)){let r={v:n,i:t,n:this.norm.get(n)};e.push(r)}}else if(Q(n.v)){let t=Z(n.v)?n.v:me(n.v);if(!ye(t)){let r={v:t,i:n.i,n:this.norm.get(t)};e.push(r)}}}}n.$[r]=e}else if(Z(i)&&!ye(i)){let e={v:i,n:this.norm.get(i)};n.$[r]=e}}}),this.records.push(n)}toJSON(){return{keys:this.keys.map(({getFn:e,...t})=>t),records:this.records}}};function ze(e,t,{getFn:n=$.getFn,fieldNormWeight:r=$.fieldNormWeight}={}){let i=new Re({getFn:n,fieldNormWeight:r});return i.setKeys(e.map(Oe)),i.setSources(t),i.create(),i}function Be(e,{getFn:t=$.getFn,fieldNormWeight:n=$.fieldNormWeight}={}){let{keys:r,records:i}=e,a=new Re({getFn:t,fieldNormWeight:n});return a.setKeys(r),a.setIndexRecords(i),a}function Ve(e=[],t=$.minMatchCharLength){let n=[],r=-1,i=-1,a=0;for(let o=e.length;a<o;a+=1){let o=e[a];o&&r===-1?r=a:!o&&r!==-1&&(i=a-1,i-r+1>=t&&n.push([r,i]),r=-1)}return e[a-1]&&a-r>=t&&n.push([r,a-1]),n}var He=32;function Ue(e,t,n,{location:r=$.location,distance:i=$.distance,threshold:a=$.threshold,findAllMatches:o=$.findAllMatches,minMatchCharLength:s=$.minMatchCharLength,includeMatches:c=$.includeMatches,ignoreLocation:l=$.ignoreLocation}={}){if(t.length>He)throw Error(Ce(He));let u=t.length,d=e.length,f=Math.max(0,Math.min(r,d)),p=a,m=f,h=(e,t)=>{let n=e/u;if(l)return n;let r=Math.abs(f-t);return i?n+r/i:r?1:n},g=s>1||c,_=g?Array(d):[],v;for(;(v=e.indexOf(t,m))>-1;){let e=h(0,v);if(p=Math.min(e,p),m=v+u,g){let e=0;for(;e<u;)_[v+e]=1,e+=1}}m=-1;let y=[],b=1,x=u+d,S=1<<u-1;for(let t=0;t<u;t+=1){let r=0,i=x;for(;r<i;)h(t,f+i)<=p?r=i:x=i,i=Math.floor((x-r)/2+r);x=i;let a=Math.max(1,f-i+1),s=o?d:Math.min(f+i,d)+u,c=Array(s+2);c[s+1]=(1<<t)-1;for(let r=s;r>=a;--r){let i=r-1,o=n[e[i]];if(g&&(_[i]=+!!o),c[r]=(c[r+1]<<1|1)&o,t&&(c[r]|=(y[r+1]|y[r])<<1|1|y[r+1]),c[r]&S&&(b=h(t,i),b<=p)){if(p=b,m=i,m<=f)break;a=Math.max(1,2*f-m)}}if(h(t+1,f)>p)break;y=c}let C={isMatch:m>=0,score:Math.max(.001,b)};if(g){let e=Ve(_,s);e.length?c&&(C.indices=e):C.isMatch=!1}return C}function We(e){let t={};for(let n=0,r=e.length;n<r;n+=1){let i=e.charAt(n);t[i]=(t[i]||0)|1<<r-n-1}return t}function Ge(e){if(e.length<=1)return e;e.sort((e,t)=>e[0]-t[0]||e[1]-t[1]);let t=[e[0]];for(let n=1,r=e.length;n<r;n+=1){let r=t[t.length-1],i=e[n];i[0]<=r[1]+1?r[1]=Math.max(r[1],i[1]):t.push(i)}return t}var Ke={ł:`l`,Ł:`L`,đ:`d`,Đ:`D`,ø:`o`,Ø:`O`,ħ:`h`,Ħ:`H`,ŧ:`t`,Ŧ:`T`,ı:`i`,ß:`ss`},qe=RegExp(`[`+Object.keys(Ke).join(``)+`]`,`g`),Je=String.prototype.normalize?e=>e.normalize(`NFD`).replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,``).replace(qe,e=>Ke[e]):e=>e,Ye=class{constructor(e,{location:t=$.location,threshold:n=$.threshold,distance:r=$.distance,includeMatches:i=$.includeMatches,findAllMatches:a=$.findAllMatches,minMatchCharLength:o=$.minMatchCharLength,isCaseSensitive:s=$.isCaseSensitive,ignoreDiacritics:c=$.ignoreDiacritics,ignoreLocation:l=$.ignoreLocation}={}){if(this.options={location:t,threshold:n,distance:r,includeMatches:i,findAllMatches:a,minMatchCharLength:o,isCaseSensitive:s,ignoreDiacritics:c,ignoreLocation:l},e=s?e:e.toLowerCase(),e=c?Je(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;let u=(e,t)=>{this.chunks.push({pattern:e,alphabet:We(e),startIndex:t})},d=this.pattern.length;if(d>He){let e=0,t=d%He,n=d-t;for(;e<n;)u(this.pattern.substr(e,He),e),e+=He;if(t){let e=d-He;u(this.pattern.substr(e),e)}}else u(this.pattern,0)}searchIn(e){let{isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=t?e:e.toLowerCase(),e=n?Je(e):e,this.pattern===e){let t={isMatch:!0,score:0};return r&&(t.indices=[[0,e.length-1]]),t}let{location:i,distance:a,threshold:o,findAllMatches:s,minMatchCharLength:c,ignoreLocation:l}=this.options,u=[],d=0,f=!1;this.chunks.forEach(({pattern:t,alphabet:n,startIndex:p})=>{let{isMatch:m,score:h,indices:g}=Ue(e,t,n,{location:i+p,distance:a,threshold:o,findAllMatches:s,minMatchCharLength:c,includeMatches:r,ignoreLocation:l});m&&(f=!0),d+=h,m&&g&&u.push(...g)});let p={isMatch:f,score:f?d/this.chunks.length:1};return f&&r&&(p.indices=Ge(u)),p}},Xe=class{constructor(e){this.pattern=e}static isMultiMatch(e){return Ze(e,this.multiRegex)}static isSingleMatch(e){return Ze(e,this.singleRegex)}search(e){return{isMatch:!1,score:1}}};function Ze(e,t){let n=e.match(t);return n?n[1]:null}var Qe=class extends Xe{constructor(e){super(e)}static get type(){return`exact`}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){let t=e===this.pattern;return{isMatch:t,score:+!t,indices:[0,this.pattern.length-1]}}},$e=class extends Xe{constructor(e){super(e)}static get type(){return`inverse-exact`}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){let t=e.indexOf(this.pattern)===-1;return{isMatch:t,score:+!t,indices:[0,e.length-1]}}},et=class extends Xe{constructor(e){super(e)}static get type(){return`prefix-exact`}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){let t=e.startsWith(this.pattern);return{isMatch:t,score:+!t,indices:[0,this.pattern.length-1]}}},tt=class extends Xe{constructor(e){super(e)}static get type(){return`inverse-prefix-exact`}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){let t=!e.startsWith(this.pattern);return{isMatch:t,score:+!t,indices:[0,e.length-1]}}},nt=class extends Xe{constructor(e){super(e)}static get type(){return`suffix-exact`}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){let t=e.endsWith(this.pattern);return{isMatch:t,score:+!t,indices:[e.length-this.pattern.length,e.length-1]}}},rt=class extends Xe{constructor(e){super(e)}static get type(){return`inverse-suffix-exact`}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){let t=!e.endsWith(this.pattern);return{isMatch:t,score:+!t,indices:[0,e.length-1]}}},it=class extends Xe{constructor(e,{location:t=$.location,threshold:n=$.threshold,distance:r=$.distance,includeMatches:i=$.includeMatches,findAllMatches:a=$.findAllMatches,minMatchCharLength:o=$.minMatchCharLength,isCaseSensitive:s=$.isCaseSensitive,ignoreDiacritics:c=$.ignoreDiacritics,ignoreLocation:l=$.ignoreLocation}={}){super(e),this._bitapSearch=new Ye(e,{location:t,threshold:n,distance:r,includeMatches:i,findAllMatches:a,minMatchCharLength:o,isCaseSensitive:s,ignoreDiacritics:c,ignoreLocation:l})}static get type(){return`fuzzy`}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}},at=class extends Xe{constructor(e){super(e)}static get type(){return`include`}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let t=0,n,r=[],i=this.pattern.length;for(;(n=e.indexOf(this.pattern,t))>-1;)t=n+i,r.push([n,t-1]);let a=!!r.length;return{isMatch:a,score:+!a,indices:r}}},ot=[Qe,at,et,tt,rt,nt,$e,it],st=ot.length,ct=`\0`,lt=`|`;function ut(e){let t=[],n=e.length,r=0;for(;r<n;){for(;r<n&&e[r]===` `;)r++;if(r>=n)break;let i=r;for(;i<n&&e[i]!==` `&&e[i]!==`"`;)i++;if(i<n&&e[i]===`"`){for(i++;i<n;){if(e[i]===`"`){let t=i+1;if(t>=n||e[t]===` `){i++;break}if(e[t]===`$`&&(t+1>=n||e[t+1]===` `)){i+=2;break}}i++}t.push(e.substring(r,i)),r=i}else{for(;i<n&&e[i]!==` `;)i++;t.push(e.substring(r,i)),r=i}}return t}function dt(e,t={}){return e.replace(/\\\|/g,ct).split(lt).map(e=>{let n=ut(e.replace(/\u0000/g,`|`).trim()).filter(e=>e&&!!e.trim()),r=[];for(let e=0,i=n.length;e<i;e+=1){let i=n[e],a=!1,o=-1;for(;!a&&++o<st;){let e=ot[o],n=e.isMultiMatch(i);n&&(r.push(new e(n,t)),a=!0)}if(!a)for(o=-1;++o<st;){let e=ot[o],n=e.isSingleMatch(i);if(n){r.push(new e(n,t));break}}}return r})}var ft=new Set([it.type,at.type]),pt=class{constructor(e,{isCaseSensitive:t=$.isCaseSensitive,ignoreDiacritics:n=$.ignoreDiacritics,includeMatches:r=$.includeMatches,minMatchCharLength:i=$.minMatchCharLength,ignoreLocation:a=$.ignoreLocation,findAllMatches:o=$.findAllMatches,location:s=$.location,threshold:c=$.threshold,distance:l=$.distance}={}){this.query=null,this.options={isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r,minMatchCharLength:i,findAllMatches:o,ignoreLocation:a,location:s,threshold:c,distance:l},e=t?e:e.toLowerCase(),e=n?Je(e):e,this.pattern=e,this.query=dt(this.pattern,this.options)}static condition(e,t){return t.useExtendedSearch}searchIn(e){let t=this.query;if(!t)return{isMatch:!1,score:1};let{includeMatches:n,isCaseSensitive:r,ignoreDiacritics:i}=this.options;e=r?e:e.toLowerCase(),e=i?Je(e):e;let a=0,o=[],s=0,c=!1;for(let r=0,i=t.length;r<i;r+=1){let i=t[r];o.length=0,a=0,c=!1;for(let t=0,r=i.length;t<r;t+=1){let r=i[t],{isMatch:l,indices:u,score:d}=r.search(e);if(l){a+=1,s+=d;let e=r.constructor.type;e.startsWith(`inverse`)&&(c=!0),n&&(ft.has(e)?o.push(...u):o.push(u))}else{s=0,a=0,o.length=0,c=!1;break}}if(a){let e={isMatch:!0,score:s/a};return c&&(e.hasInverse=!0),n&&(e.indices=Ge(o)),e}}return{isMatch:!1,score:1}}},mt=[];function ht(...e){mt.push(...e)}function gt(e,t){for(let n=0,r=mt.length;n<r;n+=1){let r=mt[n];if(r.condition(e,t))return new r(e,t)}return new Ye(e,t)}var _t={AND:`$and`,OR:`$or`},vt={PATH:`$path`,PATTERN:`$val`},yt=e=>!!(e[_t.AND]||e[_t.OR]),bt=e=>!!e[vt.PATH],xt=e=>!X(e)&&_e(e)&&!yt(e),St=e=>({[_t.AND]:Object.keys(e).map(t=>({[t]:e[t]}))});function Ct(e,t,{auto:n=!0}={}){let r=e=>{if(Z(e)){let r={keyId:null,pattern:e};return n&&(r.searcher=gt(e,t)),r}let i=Object.keys(e),a=bt(e);if(!a&&i.length>1&&!yt(e))return r(St(e));if(xt(e)){let r=a?e[vt.PATH]:i[0],o=a?e[vt.PATTERN]:e[r];if(!Z(o))throw Error(Se(r));let s={keyId:Ae(r),pattern:o};return n&&(s.searcher=gt(o,t)),s}let o={children:[],operator:i[0]};return i.forEach(t=>{let n=e[t];X(n)&&n.forEach(e=>{o.children.push(r(e))})}),o};return yt(e)||(e=St(e)),r(e)}function wt(e,{ignoreFieldNorm:t=$.ignoreFieldNorm}){let n=1;return e.forEach(({key:e,norm:r,score:i})=>{let a=e?e.weight:null;n*=(i===0&&a?2**-52:i)**+((a||1)*(t?1:r))}),n}function Tt(e,{ignoreFieldNorm:t=$.ignoreFieldNorm}){e.forEach(e=>{e.score=wt(e.matches,{ignoreFieldNorm:t})})}var Et=class{constructor(e){this.limit=e,this.heap=[]}get size(){return this.heap.length}shouldInsert(e){return this.size<this.limit||e<this.heap[0].score}insert(e){this.size<this.limit?(this.heap.push(e),this._bubbleUp(this.size-1)):e.score<this.heap[0].score&&(this.heap[0]=e,this._sinkDown(0))}extractSorted(e){return this.heap.sort(e)}_bubbleUp(e){let t=this.heap;for(;e>0;){let n=e-1>>1;if(t[e].score<=t[n].score)break;let r=t[e];t[e]=t[n],t[n]=r,e=n}}_sinkDown(e){let t=this.heap,n=t.length,r=e;do{e=r;let i=2*e+1,a=2*e+2;if(i<n&&t[i].score>t[r].score&&(r=i),a<n&&t[a].score>t[r].score&&(r=a),r!==e){let n=t[e];t[e]=t[r],t[r]=n}}while(r!==e)}};function Dt(e,t){let n=e.matches;t.matches=[],Q(n)&&n.forEach(e=>{if(!Q(e.indices)||!e.indices.length)return;let{indices:n,value:r}=e,i={indices:n,value:r};e.key&&(i.key=e.key.src),e.idx>-1&&(i.refIndex=e.idx),t.matches.push(i)})}function Ot(e,t){t.score=e.score}function kt(e,t,{includeMatches:n=$.includeMatches,includeScore:r=$.includeScore}={}){let i=[];return n&&i.push(Dt),r&&i.push(Ot),e.map(e=>{let{idx:n}=e,r={item:t[n],refIndex:n};return i.length&&i.forEach(t=>{t(e,r)}),r})}var At=/\b\w+\b/g;function jt({isCaseSensitive:e=!1,ignoreDiacritics:t=!1}={}){return{tokenize(n){return e||(n=n.toLowerCase()),t&&(n=Je(n)),n.match(At)||[]}}}function Mt(e,t,n){let r=new Map,i=new Map,a=0;function o(e,t,o,s){let c=n.tokenize(e);if(!c.length)return;a++;let l=new Map;for(let e of c)l.set(e,(l.get(e)||0)+1);for(let[e,n]of l){let a={docIdx:t,keyIdx:o,subIdx:s,tf:n},c=r.get(e);c||(c=[],r.set(e,c)),c.push(a),i.set(e,(i.get(e)||0)+1)}}for(let n of e){let{i:e,v:r,$:i}=n;if(r!==void 0){o(r,e,-1,-1);continue}if(i)for(let n=0;n<t;n++){let t=i[n];if(t)if(Array.isArray(t))for(let r of t)o(r.v,e,n,r.i??-1);else o(t.v,e,n,-1)}}return{terms:r,fieldCount:a,df:i}}function Nt(e,t,n,r){let{i,v:a,$:o}=t;function s(t,n,a){let o=r.tokenize(t);if(!o.length)return;e.fieldCount++;let s=new Map;for(let e of o)s.set(e,(s.get(e)||0)+1);for(let[t,r]of s){let o={docIdx:i,keyIdx:n,subIdx:a,tf:r},s=e.terms.get(t);s||(s=[],e.terms.set(t,s)),s.push(o),e.df.set(t,(e.df.get(t)||0)+1)}}if(a!==void 0){s(a,-1,-1);return}if(o)for(let e=0;e<n;e++){let t=o[e];if(t)if(Array.isArray(t))for(let n of t)s(n.v,e,n.i??-1);else s(t.v,e,-1)}}function Pt(e,t){for(let[n,r]of e.terms){let i=r.filter(e=>e.docIdx!==t),a=r.length-i.length;a>0&&(e.fieldCount-=a,e.df.set(n,(e.df.get(n)||0)-a),i.length===0?(e.terms.delete(n),e.df.delete(n)):e.terms.set(n,i))}}var Ft=class{constructor(e,t,n){this.options={...$,...t},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new De(this.options.keys),this._docs=e,this._myIndex=null,this._invertedIndex=null,this.setCollection(e,n),this._lastQuery=null,this._lastSearcher=null}_getSearcher(e){if(this._lastQuery===e)return this._lastSearcher;let t=gt(e,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=e,this._lastSearcher=t,t}setCollection(e,t){if(this._docs=e,t&&!(t instanceof Re))throw Error(xe);if(this._myIndex=t||ze(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){let e=jt({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});this._invertedIndex=Mt(this._myIndex.records,this._myIndex.keys.length,e)}}add(e){if(Q(e)&&(this._docs.push(e),this._myIndex.add(e),this._invertedIndex)){let e=this._myIndex.records[this._myIndex.records.length-1],t=jt({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});Nt(this._invertedIndex,e,this._myIndex.keys.length,t)}}remove(e=()=>!1){let t=[],n=[];for(let r=0,i=this._docs.length;r<i;r+=1)e(this._docs[r],r)&&(t.push(this._docs[r]),n.push(r));if(n.length){if(this._invertedIndex)for(let e of n)Pt(this._invertedIndex,e);for(let e=n.length-1;e>=0;--e)this._docs.splice(n[e],1);this._myIndex.removeAll(n)}return t}removeAt(e){this._invertedIndex&&Pt(this._invertedIndex,e);let t=this._docs.splice(e,1)[0];return this._myIndex.removeAt(e),t}getIndex(){return this._myIndex}search(e,t){let{limit:n=-1}=t||{},{includeMatches:r,includeScore:i,shouldSort:a,sortFn:o,ignoreFieldNorm:s}=this.options;if(Z(e)&&!e.trim()){let e=this._docs.map((e,t)=>({item:e,refIndex:t}));return he(n)&&n>-1&&(e=e.slice(0,n)),e}let c=he(n)&&n>0&&Z(e),l;if(c){let t=new Et(n);Z(this._docs[0])?this._searchStringList(e,{heap:t,ignoreFieldNorm:s}):this._searchObjectList(e,{heap:t,ignoreFieldNorm:s}),l=t.extractSorted(o)}else l=Z(e)?Z(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e),Tt(l,{ignoreFieldNorm:s}),a&&l.sort(o),he(n)&&n>-1&&(l=l.slice(0,n));return kt(l,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(e,{heap:t,ignoreFieldNorm:n}={}){let r=this._getSearcher(e),{records:i}=this._myIndex,a=t?null:[];return i.forEach(({v:e,i,n:o})=>{if(!Q(e))return;let{isMatch:s,score:c,indices:l}=r.searchIn(e);if(s){let r={item:e,idx:i,matches:[{score:c,value:e,norm:o,indices:l}]};t?(r.score=wt(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):a.push(r)}}),a}_searchLogical(e){let t=Ct(e,this.options),n=(e,t,r)=>{if(!(`children`in e)){let{keyId:n,searcher:i}=e,a;return n===null?(a=[],this._myIndex.keys.forEach((e,n)=>{a.push(...this._findMatches({key:e,value:t[n],searcher:i}))})):a=this._findMatches({key:this._keyStore.get(n),value:this._myIndex.getValueForItemAtKeyId(t,n),searcher:i}),a&&a.length?[{idx:r,item:t,matches:a}]:[]}let{children:i,operator:a}=e,o=[];for(let e=0,s=i.length;e<s;e+=1){let s=i[e],c=n(s,t,r);if(c.length)o.push(...c);else if(a===_t.AND)return[]}return o},r=this._myIndex.records,i=new Map,a=[];return r.forEach(({$:e,i:r})=>{if(Q(e)){let o=n(t,e,r);o.length&&(i.has(r)||(i.set(r,{idx:r,item:e,matches:[]}),a.push(i.get(r))),o.forEach(({matches:e})=>{i.get(r).matches.push(...e)}))}}),a}_searchObjectList(e,{heap:t,ignoreFieldNorm:n}={}){let r=this._getSearcher(e),{keys:i,records:a}=this._myIndex,o=t?null:[];return a.forEach(({$:e,i:a})=>{if(!Q(e))return;let s=[],c=!1,l=!1;if(i.forEach((t,n)=>{let i=this._findMatches({key:t,value:e[n],searcher:r});i.length?(s.push(...i),i[0].hasInverse&&(l=!0)):c=!0}),!(l&&c)&&s.length){let r={idx:a,item:e,matches:s};t?(r.score=wt(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):o.push(r)}}),o}_findMatches({key:e,value:t,searcher:n}){if(!Q(t))return[];let r=[];if(X(t))t.forEach(({v:t,i,n:a})=>{if(!Q(t))return;let{isMatch:o,score:s,indices:c,hasInverse:l}=n.searchIn(t);o&&r.push({score:s,key:e,value:t,idx:i,norm:a,indices:c,hasInverse:l})});else{let{v:i,n:a}=t,{isMatch:o,score:s,indices:c,hasInverse:l}=n.searchIn(i);o&&r.push({score:s,key:e,value:i,norm:a,indices:c,hasInverse:l})}return r}},It=class{static condition(e,t){return t.useTokenSearch}constructor(e,t){this.options=t,this.analyzer=jt({isCaseSensitive:t.isCaseSensitive,ignoreDiacritics:t.ignoreDiacritics});let n=this.analyzer.tokenize(e),{df:r,fieldCount:i}=t._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(let e of n){this.termSearchers.push(new Ye(e,{location:t.location,threshold:t.threshold,distance:t.distance,includeMatches:t.includeMatches,findAllMatches:t.findAllMatches,minMatchCharLength:t.minMatchCharLength,isCaseSensitive:t.isCaseSensitive,ignoreDiacritics:t.ignoreDiacritics,ignoreLocation:!0}));let n=r.get(e)||0,a=Math.log(1+(i-n+.5)/(n+.5));this.idfWeights.push(a)}}searchIn(e){if(!this.termSearchers.length)return{isMatch:!1,score:1};let t=[],n=0,r=0,i=0;for(let a=0;a<this.termSearchers.length;a++){let o=this.termSearchers[a].searchIn(e),s=this.idfWeights[a];r+=s,o.isMatch&&(i++,n+=s*(1-o.score),o.indices&&t.push(...o.indices))}if(i===0)return{isMatch:!1,score:1};let a=r>0?1-n/r:0,o={isMatch:!0,score:Math.max(.001,a)};return this.options.includeMatches&&t.length&&(o.indices=Ge(t)),o}};Ft.version=`7.3.0`,Ft.createIndex=ze,Ft.parseIndex=Be,Ft.config=$,Ft.match=function(e,t,n){return gt(e,{...$,...n}).searchIn(t)},Ft.parseQuery=Ct,ht(pt),ht(It),Ft.use=function(...e){e.forEach(e=>ht(e))};var Lt=[{text:`text-red-400`,bgCircle:`bg-red-400`,bgCard:`bg-red-500/[0.08]`,borderCard:`border-red-500/30`,bgLight:`bg-red-500/15`,bgHover:`hover:bg-red-500`,bgAlt:`bg-red-500/[0.04]`,name:`Red`},{text:`text-orange-400`,bgCircle:`bg-orange-400`,bgCard:`bg-orange-500/[0.08]`,borderCard:`border-orange-500/30`,bgLight:`bg-orange-500/15`,bgHover:`hover:bg-orange-500`,bgAlt:`bg-orange-500/[0.04]`,name:`Orange`},{text:`text-yellow-400`,bgCircle:`bg-yellow-400`,bgCard:`bg-yellow-500/[0.08]`,borderCard:`border-yellow-500/30`,bgLight:`bg-yellow-500/15`,bgHover:`hover:bg-yellow-500`,bgAlt:`bg-yellow-500/[0.04]`,name:`Yellow`},{text:`text-green-400`,bgCircle:`bg-green-400`,bgCard:`bg-green-500/[0.08]`,borderCard:`border-green-500/30`,bgLight:`bg-green-500/15`,bgHover:`hover:bg-green-500`,bgAlt:`bg-green-500/[0.04]`,name:`Green`},{text:`text-blue-400`,bgCircle:`bg-blue-400`,bgCard:`bg-blue-500/[0.08]`,borderCard:`border-blue-500/30`,bgLight:`bg-blue-500/15`,bgHover:`hover:bg-blue-500`,bgAlt:`bg-blue-500/[0.04]`,name:`Blue`},{text:`text-accent`,bgCircle:`bg-accent`,bgCard:`bg-accent/[0.08]`,borderCard:`border-accent/30`,bgLight:`bg-accent/15`,bgHover:`hover:bg-accent`,bgAlt:`bg-accent/[0.04]`,name:`Purple`},{text:`text-pink-400`,bgCircle:`bg-pink-400`,bgCard:`bg-pink-500/[0.08]`,borderCard:`border-pink-500/30`,bgLight:`bg-pink-500/15`,bgHover:`hover:bg-pink-500`,bgAlt:`bg-pink-500/[0.04]`,name:`Pink`},{text:`text-foreground/60`,bgCircle:`bg-foreground/30`,bgCard:`bg-foreground/[0.04]`,borderCard:`border-[var(--panel-border)]/50`,bgLight:`bg-foreground/15`,bgHover:`hover:bg-foreground/30`,bgAlt:`bg-foreground/[0.02]`,name:`Default`}];function Rt({title:e=`Table View`,subtitle:t=`/templates/table`,backUrl:r=`/templates`,tableCollection:i=`pub_table_data`,config:s}){let{user:c}=m(),d=!!s;s?.isPrivate&&!s?.isAdmin&&s?.isShared;let f=s?.isAdmin||s?.isShared,p=d?f:!0,h=s?.showButton!==!1,g=s?.buttonText||`+`,_=s?.buttonStyle||`secondary`,v=s?.showExportButton!==!1,y=s?.showPrompt,[b,x]=(0,a.useState)([]),[S,C]=(0,a.useState)(`demo`),[w,T]=(0,a.useState)(!1),[E,D]=(0,a.useState)(!1),[O,k]=(0,a.useState)(``),[A,te]=(0,a.useState)(!1),[j,M]=(0,a.useState)(!1),[N,P]=(0,a.useState)([]),F=s?.isAdmin?oe(s,e,i):s?.isPrivate?ae(s,e,i,N):se(s,e,i,N),I=()=>{navigator.clipboard.writeText(F),M(!0),setTimeout(()=>M(!1),2e3)},[L,R]=(0,a.useState)(null),[z,B]=(0,a.useState)(null),[V,ne]=(0,a.useState)(``),[H,U]=(0,a.useState)(``),[W,G]=(0,a.useState)(null),[K,re]=(0,a.useState)(null),[ie,q]=(0,a.useState)(!1);(0,a.useEffect)(()=>{let e=s?.isShared,t=s?.isAdmin,r=s?.isPrivate&&!t&&!e,a=!t&&!e&&!r;r||a?(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{let t=a?`public`:`private`;P(e.docs.filter(e=>e.data().formType===t).map(e=>e.id))}):P([]);let l=i.startsWith(`user_`);if(l&&!c)return;try{let e=localStorage.getItem(`fbos_tables_${i}`);e&&x(JSON.parse(e))}catch{}let u=(0,o.onSnapshot)(l&&c?(0,o.query)((0,o.collection)(n.Tt,i),(0,o.where)(`uid`,`==`,c.uid)):(0,o.collection)(n.Tt,i),e=>{let t=[];if(e.forEach(e=>{t.push({id:e.id,...e.data()})}),t.length===0){let e={name:`Unnamed Table`,columns:[`Column 1`,`Column 2`,`Column 3`,`Column 4`],...c?{uid:c.uid}:{},rows:[{id:`1`,"Column 1":``,"Column 2":``,"Column 3":``,"Column 4":``},{id:`2`,"Column 1":``,"Column 2":``,"Column 3":``,"Column 4":``}]};(0,o.setDoc)((0,o.doc)(n.Tt,i,`demo`),e)}else{let e=t.sort((e,t)=>(e.name||``).localeCompare(t.name||``));x(e),localStorage.setItem(`fbos_tables_${i}`,JSON.stringify(e))}});return()=>u()},[i,c]);let J=b.find(e=>e.id===S)||b[0]||{columns:[],rows:[]},Y=async e=>{J.id&&(c&&i.startsWith(`user_`)&&(e.uid=c.uid),await(0,o.setDoc)((0,o.doc)(n.Tt,i,J.id),e,{merge:!0}))},ce=()=>{if(!J.rows||J.rows.length===0)return;let e=J.columns.join(`,`),t=J.rows.map(e=>J.columns.map(t=>`"${e[t]||``}"`).join(`,`)).join(`
|
|
280
311
|
`),n=new Blob([`${e}\n${t}`],{type:`text/csv`}),r=window.URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`export_${J.name||`table`}.csv`,i.click(),window.URL.revokeObjectURL(r)},le=(e,t,n)=>{Y({...J,rows:J.rows.map(r=>r.id===e?{...r,[t]:n}:r)})},ue=()=>{let e={id:Date.now().toString()};J.columns.forEach(t=>e[t]=``),Y({...J,rows:[...J.rows||[],e]})},de=e=>{Y({...J,rows:J.rows.filter(t=>t.id!==e)})},fe=()=>{let e=`Column ${(J.columns?.length||0)+1}`;J.columns?.includes(e)||(Y({...J,columns:[...J.columns||[],e]}),setTimeout(()=>{let e=document.getElementById(`table-scroll-container`);e&&e.scrollTo({left:e.scrollWidth,behavior:`smooth`})},100))},X=e=>{let t=(J.columns||[]).filter(t=>t!==e),n=(J.rows||[]).map(t=>{let n={...t};return delete n[e],n}),r={...J.colColors||{}};delete r[e],Y({...J,columns:t,rows:n,colColors:r})},pe=async e=>{e.trim()&&J.id&&e!==J.name&&await(0,o.setDoc)((0,o.doc)(n.Tt,i,J.id),{name:e},{merge:!0})},me=async()=>{te(!0),T(!1);let e=`tbl_${Date.now()}`;await(0,o.setDoc)((0,o.doc)(n.Tt,i,e),{name:`Unnamed Table`,columns:[`Column 1`,`Column 2`,`Column 3`],...c?{uid:c.uid}:{},rows:[]}),setTimeout(()=>{C(e),te(!1)},600)},Z=e=>{let t=H.trim();if(t&&t!==e&&!J.columns?.includes(t)){let n=J.columns.map(n=>n===e?t:n),r=(J.rows||[]).map(n=>{let r={...n};return r[t]=r[e]||``,delete r[e],r}),i={...J.colColors||{}};i[e]&&(i[t]=i[e],delete i[e]),Y({...J,columns:n,rows:r,colColors:i})}B(null)},he=J.rows||[];return V.trim()!==``&&(he=new Ft(he.map(e=>({...e,_creatorMatch:`Guest`})),{keys:(J.columns||[]).concat([`_creatorMatch`]),threshold:.4,ignoreLocation:!0}).search(V).map(e=>{let{_creatorMatch:t,...n}=e.item;return n})),(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e}),t&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),t]})]}),d&&(0,l.jsx)(`div`,{className:`mb-6`,children:(0,l.jsx)(ee,{})}),(0,l.jsxs)(`div`,{className:`flex justify-between items-center mb-6 border-b border-[var(--panel-border)] pb-6 relative z-20`,children:[!d&&r&&(0,l.jsxs)(u.Link,{to:r,className:`px-4 md:px-5 py-2.5 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold hover:bg-foreground/5 transition-all flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` `,(0,l.jsx)(`span`,{className:`hidden sm:inline`,children:`Go Back`})]}),d&&(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:s?.tabTitle||s?.tabName||e}),(0,l.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[b.length,` `,b.length===1?`table`:`tables`]})]}),(0,l.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[y&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:I,title:j?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${j?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary shadow-lg`}`,children:j?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),v&&(0,l.jsx)(n.n,{variant:`secondary`,onClick:ce,className:`px-3 py-2.5 font-bold rounded-xl shadow-sm border border-[var(--panel-border)] flex items-center gap-2`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})}),h&&(0,l.jsx)(n.n,{variant:_===`primary`?void 0:`secondary`,onClick:ue,className:`px-3 py-2.5 font-bold rounded-xl border border-[var(--panel-border)] shadow-sm flex items-center gap-2`,children:g===`+`?(0,l.jsx)(n.C,{className:`w-4 h-4`}):g})]})]}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative z-10 block`,children:[(0,l.jsx)(`div`,{className:`absolute top-0 right-0 w-[400px] h-[400px] bg-accent/5 blur-[100px] rounded-full pointer-events-none -z-10`}),(0,l.jsxs)(`div`,{className:`p-4 md:px-6 border-b border-[var(--panel-border)]/50 flex flex-col sm:flex-row items-start sm:items-center justify-between bg-foreground/[0.01] gap-4`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col w-full sm:w-auto relative`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 relative`,children:[(0,l.jsxs)(`div`,{className:`relative flex items-center`,children:[E?(0,l.jsx)(`div`,{contentEditable:!0,suppressContentEditableWarning:!0,onBlur:e=>{D(!1),pe(e.currentTarget.textContent||``)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},className:`bg-transparent border-b-2 border-accent outline-none text-[16px] font-bold text-foreground inline-block min-w-[20px] whitespace-nowrap px-1 py-0.5`,children:J.name||`Unnamed Table`}):(0,l.jsx)(`h3`,{className:`font-bold text-[16px] text-foreground/90 cursor-pointer hover:text-accent transition-colors truncate max-w-[200px]`,onClick:()=>D(!0),title:`Click to rename table`,children:J.name||`Unnamed Table`}),(0,l.jsx)(n.a,{children:w&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>T(!1)}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:`absolute top-[120%] left-0 w-[220px] bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] rounded-2xl shadow-2xl z-50 py-2 flex flex-col`,children:[(0,l.jsx)(`div`,{className:`px-4 py-2 text-[10px] font-bold uppercase tracking-wider text-foreground/40 border-b border-[var(--panel-border)] mb-1`,children:`Your Tables`}),(0,l.jsx)(`div`,{className:`max-h-[250px] overflow-y-auto styled-scrollbars z-50 relative`,children:b.map(e=>(0,l.jsx)(`button`,{onClick:()=>{C(e.id),T(!1)},className:`w-full px-4 py-2 text-[13px] font-bold text-left hover:bg-foreground/[0.03] transition-colors truncate ${S===e.id?`text-accent bg-accent/5`:`text-foreground/70`}`,children:e.name||`Unnamed Table`},e.id))}),(0,l.jsx)(`div`,{className:`w-full h-[1px] bg-[var(--panel-border)]/50 my-1`}),(0,l.jsxs)(`button`,{onClick:me,className:`w-full px-4 py-2.5 text-[13px] font-bold text-left text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors flex items-center gap-2`,children:[(0,l.jsx)(n.C,{className:`w-4 h-4`}),` Create New Table`]})]})]})})]}),(0,l.jsx)(`button`,{onClick:()=>T(!w),className:`p-1 px-1.5 rounded-lg hover:bg-foreground/5 transition-colors text-foreground/40 hover:text-foreground shrink-0 border border-transparent hover:border-[var(--panel-border)]`,children:(0,l.jsx)(n.st,{className:`w-4 h-4 transition-transform ${w?`rotate-180 text-accent`:``}`})})]}),(0,l.jsxs)(`span`,{className:`opacity-40 text-[11px] font-bold mt-1 uppercase tracking-wider`,children:[(J.rows||[]).length,` Records`]})]}),(0,l.jsxs)(`div`,{className:`relative w-full sm:max-w-[300px]`,children:[(0,l.jsx)(n.b,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-foreground/40`}),(0,l.jsx)(`input`,{type:`text`,placeholder:`Search active records...`,value:V,onChange:e=>ne(e.target.value),className:`w-full bg-background border border-[var(--panel-border)] rounded-xl py-2.5 px-9 text-[13px] font-medium text-foreground focus:outline-none focus:border-accent transition-colors shadow-inner`})]})]}),(0,l.jsx)(`div`,{id:`table-scroll-container`,className:`overflow-x-auto w-full block min-h-[300px] relative styled-scrollbars`,children:(0,l.jsx)(n.a,{mode:`wait`,children:A?(0,l.jsxs)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 flex flex-col items-center justify-center bg-background/40 backdrop-blur-[2px] z-50`,children:[(0,l.jsx)(`div`,{className:`w-8 h-8 rounded-full border-2 border-accent border-r-transparent animate-spin mb-4`}),(0,l.jsx)(`p`,{className:`text-[11px] font-bold text-foreground/50 uppercase tracking-widest`,children:`Generating Table`})]},`loader`):(0,l.jsxs)(n.i.table,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full text-left border-collapse table-auto relative min-w-[800px]`,children:[(0,l.jsx)(`thead`,{children:(0,l.jsxs)(`tr`,{className:`border-b border-[var(--panel-border)] transition-colors ${J.headerColor?Lt.find(e=>e.text===J.headerColor)?.bgAlt:`bg-foreground/[0.02]`}`,children:[(0,l.jsx)(`th`,{className:`py-4 px-6 text-[12px] font-bold uppercase tracking-wider whitespace-nowrap text-foreground/50 w-32 border-r border-[var(--panel-border)]/20 ${p?``:`hidden`}`,children:`Creator`}),(J.columns||[]).map((e,t)=>{let r=(J.colColors||{})[e],i=(J.colorTimestamps||{})[`col_${e}`]||0;J.headerColor;let a=(J.colorTimestamps||{}).header||0,o=`bg-transparent`,s=`text-foreground/50`;if(r&&r!==`none`&&i>=a){let e=Lt.find(e=>e.text===r);e&&(o=e.bgCard,s=e.text)}return(0,l.jsx)(`th`,{className:`py-3 px-6 text-[12px] font-bold uppercase tracking-wider relative group h-[53px] min-w-[120px] ${s} ${o} border-r border-[var(--panel-border)]/20 last:border-r-0 select-none align-middle`,children:(0,l.jsxs)(`div`,{className:`flex items-center justify-between gap-2 w-full h-full`,children:[z===e?(0,l.jsx)(`div`,{className:`flex-1 min-w-[50px]`,children:(0,l.jsx)(`span`,{contentEditable:!0,suppressContentEditableWarning:!0,onBlur:t=>{B(null),U(t.currentTarget.textContent||``),(t.currentTarget.textContent||``).trim()!==``&&Z(e)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},className:`bg-transparent outline-none border-b border-accent/40 font-bold text-[12px] uppercase tracking-wider p-0 m-0 ${s} block w-full whitespace-nowrap overflow-hidden cursor-text`,ref:e=>{e&&requestAnimationFrame(()=>{e.focus()})},children:H})}):(0,l.jsx)(`div`,{className:`flex items-center gap-2 flex-1 overflow-hidden`,onClick:()=>{B(e),U(e)},children:(0,l.jsx)(`span`,{className:`truncate cursor-text`,children:e})}),(0,l.jsxs)(`div`,{className:`relative shrink-0 flex items-center h-full gap-0.5`,children:[(0,l.jsx)(`button`,{onClick:()=>re(K===e?null:e),className:`p-1.5 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity hover:bg-foreground/10 ${r&&r!==`none`?`!opacity-100`:``} text-current`,children:(0,l.jsx)(n.T,{className:`w-4 h-4`})}),(J.columns||[]).length>1&&(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),X(e)},className:`p-1.5 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500/10 text-foreground/30 hover:text-red-500`,title:`Delete column`,children:(0,l.jsx)(n.m,{className:`w-3.5 h-3.5`})}),K===e&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>re(null)}),(0,l.jsxs)(`div`,{className:`absolute top-8 right-0 flex gap-1.5 bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-50 items-center`,children:[(0,l.jsx)(`button`,{onClick:t=>{t.preventDefault(),t.stopPropagation();let n={...J.colColors||{},[e]:`none`},r={...J.colorTimestamps||{},[`col_${e}`]:Date.now()};Y({...J,colColors:n,colorTimestamps:r}),re(null)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Remove Color`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})}),(0,l.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Lt.map(t=>(0,l.jsx)(`button`,{onClick:n=>{n.preventDefault(),n.stopPropagation();let r={...J.colColors||{},[e]:t.text},i={...J.colorTimestamps||{},[`col_${e}`]:Date.now()};Y({...J,colColors:r,colorTimestamps:i}),re(null)},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50 shrink-0`},t.name))]})]})]})]})},`col_${t}_${e}`)}),(0,l.jsx)(`th`,{className:`py-4 px-4 w-14 border-l border-[var(--panel-border)]/30 relative`,children:(0,l.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 relative z-20`,children:[(0,l.jsx)(`button`,{onClick:()=>q(!ie),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${J.headerColor?Lt.find(e=>e.text===J.headerColor)?.text:`text-foreground/30`}`,children:(0,l.jsx)(n.T,{className:`w-4 h-4`})}),ie&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>q(!1)}),(0,l.jsxs)(`div`,{className:`absolute top-6 right-8 flex gap-1.5 bg-background/90 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-50 items-center`,children:[(0,l.jsx)(`button`,{onClick:()=>{Y({...J,headerColor:``}),q(!1)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Remove Header Color`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})}),(0,l.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Lt.map(e=>(0,l.jsx)(`button`,{onClick:()=>{let t={...J.colorTimestamps||{},header:Date.now()};Y({...J,headerColor:e.text,colorTimestamps:t}),q(!1)},className:`w-4 h-4 rounded-full ${e.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50`},e.name))]})]}),(0,l.jsx)(`button`,{onClick:fe,className:`p-1.5 rounded-lg text-foreground/40 hover:text-accent hover:bg-accent/10 transition-colors flex items-center justify-center`,children:(0,l.jsx)(n.C,{className:`w-4 h-4`})})]})})]})}),(0,l.jsxs)(`tbody`,{children:[he.map((e,t)=>{let r=t%2==1,i=(J.rowColors||{})[e.id],a=i?r?Lt.find(e=>e.text===i)?.bgAlt:Lt.find(e=>e.text===i)?.bgCard:r?`bg-foreground/[0.02]`:`bg-transparent`;return(0,l.jsxs)(`tr`,{className:`border-b border-[var(--panel-border)]/30 hover:bg-foreground/[0.04] transition-colors group`,children:[(0,l.jsx)(`td`,{className:`py-4 px-6 whitespace-nowrap h-[53px] border-r border-[var(--panel-border)]/20 ${a} ${p?``:`hidden`}`,children:(0,l.jsx)(`div`,{className:`flex items-center gap-2`,children:d&&c?(0,l.jsxs)(l.Fragment,{children:[c.photoURL?(0,l.jsx)(`img`,{src:c.photoURL,className:`w-5 h-5 rounded-full shrink-0 object-cover`}):(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/20 text-accent flex items-center justify-center text-[10px] font-bold shrink-0`,children:(c.displayName||c.email||`U`)[0].toUpperCase()}),(0,l.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/80 tracking-tight shrink-0`,children:c.displayName||c.email?.split(`@`)[0]||`User`})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/20 text-accent flex items-center justify-center text-[10px] font-bold shrink-0 shadow-inner group-hover:scale-110 transition-transform`,children:`G`}),(0,l.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/80 tracking-tight shrink-0`,children:`Guest`})]})})}),(J.columns||[]).map(n=>{let i=L?.id===e.id&&L?.field===n,a=(J.colColors||{})[n],o=(J.colorTimestamps||{})[`col_${n}`]||0,s=(J.rowColors||{})[e.id],c=(J.colorTimestamps||{})[`row_${e.id}`]||0,u=``;u=c>o?s===`none`?``:s:o>c?a===`none`?``:a:s===`none`?``:s||a||``,u===`none`&&(u=``);let d=u?Lt.find(e=>e.text===u):null,f=d?r?d.bgAlt:d.bgCard:r?`bg-foreground/[0.02]`:`bg-transparent`,p=d?d.text:`text-foreground/80`;return(0,l.jsxs)(`td`,{className:`py-4 px-6 whitespace-pre-wrap min-w-[120px] text-[14px] font-medium relative ${f} align-top border-r border-[var(--panel-border)]/10 last:border-r-0`,onClick:()=>!i&&R({id:e.id,field:n}),children:[i?(0,l.jsx)(`textarea`,{autoFocus:!0,value:e[n]||``,onChange:t=>le(e.id,n,t.target.value),onBlur:()=>R(null),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&R(null)},className:`absolute inset-0 bg-transparent !border-0 !outline-none focus:!outline-none focus:!ring-0 !ring-0 !shadow-none focus:!shadow-none p-4 px-6 text-[14px] font-medium w-full h-full caret-accent ${p} z-20 resize-none styled-scrollbars`}):null,(0,l.jsx)(`span`,{className:`block w-full min-h-[20px] break-words transition-all ${i?`opacity-0`:`opacity-100`} ${p} ${n===`Status`&&e[n]===`Active`&&!u?`text-green-500`:``}`,children:e[n]||(0,l.jsx)(`span`,{className:`opacity-30 italic font-normal`,children:`empty`})})]},`cell_${e.id||t}_${n}`)}),(0,l.jsx)(`td`,{className:`py-4 px-4 whitespace-nowrap text-right h-[53px] ${a} relative z-10`,children:(0,l.jsxs)(`div`,{className:`flex items-center justify-end gap-1 opacity-20 group-hover:opacity-100 transition-opacity relative`,children:[(0,l.jsx)(`button`,{onClick:()=>G(W===e.id?null:e.id),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${i?Lt.find(e=>e.text===i)?.text:`text-foreground/40`}`,children:(0,l.jsx)(n.T,{className:`w-4 h-4`})}),W===e.id&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>G(null)}),(0,l.jsxs)(`div`,{className:`absolute top-6 right-8 flex gap-1.5 bg-background/90 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-50 items-center`,children:[(0,l.jsx)(`button`,{onClick:t=>{t.preventDefault(),t.stopPropagation();let n={...J.rowColors||{},[e.id]:`none`},r={...J.colorTimestamps||{},[`row_${e.id}`]:Date.now()};Y({...J,rowColors:n,colorTimestamps:r}),G(null)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Remove Row Color`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})}),(0,l.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Lt.map(t=>(0,l.jsx)(`button`,{onClick:()=>{let n={...J.colorTimestamps||{},[`row_${e.id}`]:Date.now()};Y({...J,rowColors:{...J.rowColors||{},[e.id]:t.text},colorTimestamps:n}),G(null)},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50`},t.name))]})]}),(0,l.jsx)(`button`,{onClick:()=>de(e.id),className:`p-2 ml-auto rounded-lg text-foreground/20 hover:text-red-500 hover:bg-red-500/10 transition-colors flex items-center justify-center`,children:(0,l.jsx)(n.m,{className:`w-4 h-4`})})]})})]},e.id||`row_${t}`)}),he.length===0&&(0,l.jsx)(`tr`,{children:(0,l.jsxs)(`td`,{colSpan:(J.columns||[]).length+2,className:`py-12 text-center text-foreground/40 text-[14px] font-medium border border-[var(--panel-border)] m-4 rounded-xl border-dashed`,children:[`No records found in `,J.name||`this table`,`.`]})}),(0,l.jsx)(`tr`,{children:(0,l.jsx)(`td`,{colSpan:(J.columns||[]).length+2,className:`py-2 px-4 border-none bg-foreground/[0.01]`,children:(0,l.jsx)(`div`,{className:`flex items-center gap-4`,children:(0,l.jsx)(`button`,{onClick:ue,className:`p-1.5 rounded-lg text-foreground/40 hover:text-accent hover:bg-accent/10 transition-colors flex items-center justify-center ml-2 border border-transparent hover:border-accent/20`,children:(0,l.jsx)(n.C,{className:`w-4 h-4`})})})})})]})]},`table`)})})]})]})}var zt=[{text:`text-red-400`,bgCircle:`bg-red-400`,bgCard:`bg-red-500/[0.08]`,borderCard:`border-red-500/30`,bgLight:`bg-red-500/15`,bgHover:`hover:bg-red-500`,bgAlt:`bg-red-500/[0.04]`,name:`Red`},{text:`text-orange-400`,bgCircle:`bg-orange-400`,bgCard:`bg-orange-500/[0.08]`,borderCard:`border-orange-500/30`,bgLight:`bg-orange-500/15`,bgHover:`hover:bg-orange-500`,bgAlt:`bg-orange-500/[0.04]`,name:`Orange`},{text:`text-yellow-400`,bgCircle:`bg-yellow-400`,bgCard:`bg-yellow-500/[0.08]`,borderCard:`border-yellow-500/30`,bgLight:`bg-yellow-500/15`,bgHover:`hover:bg-yellow-500`,bgAlt:`bg-yellow-500/[0.04]`,name:`Yellow`},{text:`text-green-400`,bgCircle:`bg-green-400`,bgCard:`bg-green-500/[0.08]`,borderCard:`border-green-500/30`,bgLight:`bg-green-500/15`,bgHover:`hover:bg-green-500`,bgAlt:`bg-green-500/[0.04]`,name:`Green`},{text:`text-blue-400`,bgCircle:`bg-blue-400`,bgCard:`bg-blue-500/[0.08]`,borderCard:`border-blue-500/30`,bgLight:`bg-blue-500/15`,bgHover:`hover:bg-blue-500`,bgAlt:`bg-blue-500/[0.04]`,name:`Blue`},{text:`text-accent`,bgCircle:`bg-accent`,bgCard:`bg-accent/[0.08]`,borderCard:`border-accent/30`,bgLight:`bg-accent/15`,bgHover:`hover:bg-accent`,bgAlt:`bg-accent/[0.04]`,name:`Purple`},{text:`text-pink-400`,bgCircle:`bg-pink-400`,bgCard:`bg-pink-500/[0.08]`,borderCard:`border-pink-500/30`,bgLight:`bg-pink-500/15`,bgHover:`hover:bg-pink-500`,bgAlt:`bg-pink-500/[0.04]`,name:`Pink`},{text:`text-foreground/60`,bgCircle:`bg-foreground/30`,bgCard:`bg-foreground/[0.04]`,borderCard:`border-[var(--panel-border)]/50`,bgLight:`bg-foreground/15`,bgHover:`hover:bg-foreground/30`,bgAlt:`bg-foreground/[0.02]`,name:`Default`}],Bt={dateStr:``,title:``,description:``,time:`12:00`,duration:`60`,color:``,guestEmail:``,customFields:{}};function Vt({title:e=`Calendar View`,subtitle:t=`/templates/calendar`,backUrl:r=`/templates`,eventsCollection:i=`pub_events`,defaultTimeFormat:c=`12h`,config:d}){let f=!!(d?.isPrivate||d?.isAdmin||d?.isShared);d?.isAdmin,d?.isShared,d?.isPrivate;let p=d?.showButton!==!1,m=d?.buttonText||`+`,h=d?.buttonStyle||`primary`,g=d?.showViewsButton!==!1,_=d?.viewsButtonStyle||`secondary`,v=d?.showPrompt!==!1,y=d?.defaultView||`calendar`,b=d?.customFields||[],x=i.startsWith(`user_`)?`private`:i.startsWith(`mem_`)?`shared`:i.startsWith(`admin_`)?`admin_only`:`public`,[S,C]=(0,a.useState)(()=>{try{let e=localStorage.getItem(`cal_view_${i}`);if(e===`list`||e===`month`)return e}catch{}return y===`board`?`list`:`month`}),[w,T]=(0,a.useState)([]),[E,D]=(0,a.useState)([]),[O,k]=(0,a.useState)(!1),[A,j]=(0,a.useState)(null),[M,N]=(0,a.useState)(!1),[P,F]=(0,a.useState)(!1),[I,L]=(0,a.useState)(null),[R,z]=(0,a.useState)(Bt),[B,V]=(0,a.useState)(new Date),[ne,H]=(0,a.useState)(!1),[U,W]=(0,a.useState)(null),[G,q]=(0,a.useState)(null),[J,Y]=(0,a.useState)(!1),ae=`cal_24h_${i}`,[oe,se]=(0,a.useState)(()=>{try{let e=localStorage.getItem(ae);if(e!==null)return e===`true`}catch{}return c===`24h`}),ce=()=>{let e=!oe;se(e);try{localStorage.setItem(ae,String(e))}catch{}};(0,a.useEffect)(()=>{try{localStorage.setItem(`cal_view_${i}`,S)}catch{}x===`public`||x===`private`?(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{let t=x===`public`?`public`:`private`;T(e.docs.filter(e=>e.data().formType===t).map(e=>e.id))}):T([])},[S,i,x]);let le=()=>{let e=S===`month`?`list`:`month`;C(e);try{localStorage.setItem(`cal_view_${i}`,e)}catch{}},ue=()=>{try{return sessionStorage.getItem(`cal_guest_email`)||``}catch{return``}},de=e=>{try{sessionStorage.setItem(`cal_guest_email`,e)}catch{}};(0,a.useEffect)(()=>(0,s.onAuthStateChanged)(n.wt,async e=>{if(W(e),e&&x===`admin_only`)try{let t=await(0,o.getDoc)((0,o.doc)(n.Tt,`user_profiles`,e.uid));t.exists()&&q(t.data())}catch{}Y(!0)}),[x]),(0,a.useEffect)(()=>{if(!J)return;if(x!==`public`&&!U){D([]);return}try{let e=localStorage.getItem(`fbos_cal_${i}`);e&&D(JSON.parse(e))}catch{}let e=(0,o.onSnapshot)(x===`private`&&U?(0,o.query)((0,o.collection)(n.Tt,i),(0,o.where)(`uid`,`==`,U.uid)):(0,o.collection)(n.Tt,i),e=>{let t=[];e.forEach(e=>t.push({id:e.id,...e.data()})),D(t),localStorage.setItem(`fbos_cal_${i}`,JSON.stringify(t))},e=>console.error(`Calendar events:`,e));return()=>e()},[i,x,U?.uid,J]);let fe=e=>!!U&&U.uid===e.uid,X=e=>x===`public`?!1:x===`private`?!!U:fe(e),pe=e=>{if(!e)return``;if(oe)return e;let[t,n]=e.split(`:`),r=parseInt(t,10),i=r>=12?`PM`:`AM`;return r=r%12||12,`${r}:${n} ${i}`},me=e=>{if(!e)return`60m`;let t=parseInt(e,10);return isNaN(t)?e:t>=60?t%60==0?`${t/60}h`:`${Math.floor(t/60)}h ${t%60}m`:`${t}m`},Z=e=>{let[t,n]=(e||`12:00`).split(`:`),r=parseInt(t,10)||0,i=parseInt(n,10)||0,a=r>=12?`PM`:`AM`;return r=r%12||12,{h:r,m:i,ampm:a}},he=(e,t,n)=>{let r=e%12;return n===`PM`&&(r+=12),`${r.toString().padStart(2,`0`)}:${t.toString().padStart(2,`0`)}`},ge=e=>{let t=e.getTimezoneOffset()*6e4;return new Date(e.getTime()-t).toISOString().split(`T`)[0]},_e=()=>ge(new Date),ve=new Date(B.getFullYear(),B.getMonth(),1),Q=new Date(B.getFullYear(),B.getMonth()+1,0),ye=ve.getDay(),be=Q.getDate(),xe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],Se=Array.from({length:42},(e,t)=>{let n=t-ye+1,r=new Date(B.getFullYear(),B.getMonth(),n);return{day:r.getDate(),dateStr:ge(r),isCurrentMonth:n>0&&n<=be}}),Ce=()=>V(S===`month`?new Date(B.getFullYear(),B.getMonth()-1,1):new Date(B.getFullYear(),B.getMonth(),B.getDate()-1)),we=()=>V(S===`month`?new Date(B.getFullYear(),B.getMonth()+1,1):new Date(B.getFullYear(),B.getMonth(),B.getDate()+1)),Te=e=>{if(x!==`public`&&!U)return;let t=new Date;t.setDate(t.getDate()+1);let n=new Date().getHours().toString().padStart(2,`0`);z({...Bt,dateStr:e||ge(t),time:`${n}:00`,guestEmail:x===`public`?ue():``,customFields:{}}),k(!0)},Ee=e=>{let t=e.time;if(t){let[e,n]=t.split(`:`);e&&n&&(t=`${e.padStart(2,`0`)}:${n}`)}z({id:e.id,uid:e.uid,dateStr:e.dateStr,title:e.title,description:e.description||``,time:t||`12:00`,duration:e.duration||`60`,color:e.color||``,guestEmail:e.creatorEmail||``,customFields:e.customFields||{}}),k(!0)},De=async e=>{if(e.preventDefault(),R.title.trim()){N(!0);try{let e={dateStr:R.dateStr,title:R.title.trim(),description:R.description.trim(),time:R.time,duration:R.duration||`60`};if(R.color&&(e.color=R.color),b.length>0&&(e.customFields=R.customFields),!R.id)if(x===`public`){let t=R.guestEmail.trim();e.creatorEmail=t,de(t)}else x===`private`||x===`shared`?(e.uid=U?.uid,e.creatorEmail=U?.email||``,e.creatorName=U?.displayName||``,e.creatorAvatar=U?.photoURL||``):x===`admin_only`&&(e.uid=U?.uid,e.creatorEmail=G?.email||U?.email||``,e.creatorName=G?.displayName||G?.name||``,e.creatorAvatar=G?.avatar||G?.avatarUrl||U?.photoURL||``);R.id?(await(0,o.setDoc)((0,o.doc)(n.Tt,i,R.id),e,{merge:!0}),A?.id===R.id&&j({...A,...e})):await(0,o.setDoc)((0,o.doc)(n.Tt,i,`ev_${Date.now()}`),e,{merge:!0}),k(!1)}catch(e){console.error(e)}N(!1)}},Oe=async()=>{if(I){F(!0);try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,i,I.id)),A?.id===I.id&&j(null),L(null),k(!1)}catch{}F(!1)}},ke=e=>{if(x===`private`||!e.creatorEmail&&!e.creatorName)return null;let t=(e.creatorName||e.creatorEmail||`?`).charAt(0).toUpperCase(),n=zt.find(t=>t.text===e.color);return(0,l.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 p-3 rounded-xl bg-foreground/[0.03] border border-[var(--panel-border)]/50`,children:[e.creatorAvatar?(0,l.jsx)(`img`,{src:e.creatorAvatar,alt:``,className:`w-8 h-8 rounded-full object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`w-8 h-8 rounded-full ${n?.bgCircle||`bg-accent`} flex items-center justify-center text-[13px] font-extrabold text-white shrink-0`,children:t}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[e.creatorName&&(0,l.jsx)(`span`,{className:`text-[13px] font-bold text-foreground/90 truncate`,children:e.creatorName}),e.creatorEmail&&(0,l.jsx)(`span`,{className:`text-[12px] text-foreground/50 truncate`,children:e.creatorEmail})]})]})},Ae=e=>{if(x===`private`||x===`public`||!e.creatorName&&!e.creatorEmail)return null;let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||``,n=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[e.creatorAvatar?(0,l.jsx)(`img`,{src:e.creatorAvatar,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/15 text-accent flex items-center justify-center text-[8px] font-extrabold shrink-0`,children:n}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),e.creatorEmail&&(0,l.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,e.creatorEmail]})]})]})},je=x===`admin_only`?re(d,e,i,w):x===`private`?K(d,e,i,w):ie(d,e,i,w),Me=()=>{navigator.clipboard.writeText(je),H(!0),setTimeout(()=>H(!1),2e3)};if(J&&x!==`public`&&!U)return(0,l.jsx)(`main`,{className:`flex-1 w-full flex items-center justify-center min-h-screen p-8`,children:(0,l.jsxs)(`div`,{className:`text-center glass-panel border border-[var(--panel-border)] rounded-3xl p-12 max-w-sm w-full`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-accent/10 border border-accent/20 flex items-center justify-center mx-auto mb-4`,children:(0,l.jsx)(n.k,{className:`w-7 h-7 text-accent`})}),(0,l.jsx)(`h2`,{className:`text-2xl font-extrabold mb-2`,children:`Sign in required`}),(0,l.jsx)(`p`,{className:`text-foreground/50 text-[14px] mb-6`,children:`You need to be signed in to access this calendar.`}),(0,l.jsx)(u.Link,{to:`/login`,className:`inline-flex items-center justify-center gap-2 px-6 py-2.5 rounded-xl btn-primary font-bold text-[14px] w-full`,children:`Sign In`})]})});if(!J&&x!==`public`)return(0,l.jsx)(`main`,{className:`flex-1 w-full flex items-center justify-center min-h-screen`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 animate-spin text-accent`})});let Ne=(x===`public`||!!U)&&p,Pe=()=>(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:d?.tabTitle||d?.tabName||e}),(0,l.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[E.length,` `,E.length===1?`event`:`events`,` · `,S===`month`?`Month`:`Board`,` View`]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[v&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:Me,title:ne?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${ne?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:ne?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:ce,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer btn-secondary text-[12px] font-extrabold`,children:oe?`24h`:`12h`}),g&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:le,title:S===`month`?`Switch to Board`:`Switch to Calendar`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${_===`primary`?`btn-primary`:`btn-secondary`}`,children:S===`month`?(0,l.jsx)(n.F,{className:`w-4 h-4`}):(0,l.jsx)(n.dt,{className:`w-4 h-4`})}),Ne&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>Te(),className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${m===`+`?`w-10`:`px-5`} ${h===`primary`?`btn-primary`:`btn-secondary`}`,children:m===`+`?(0,l.jsx)(n.C,{className:`w-4 h-4`}):(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:m})})]})]}),Fe=()=>(0,l.jsxs)(`div`,{className:`p-4 md:p-6 border-b border-[var(--panel-border)]/50 flex items-center justify-between bg-foreground/[0.01]`,children:[(0,l.jsx)(`h3`,{className:`text-xl font-extrabold tracking-tight ml-2`,children:S===`month`?B.toLocaleString(`default`,{month:`long`,year:`numeric`}):B.toLocaleString(`default`,{month:`long`,day:`numeric`,year:`numeric`})}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,l.jsx)(`button`,{onClick:()=>V(new Date),className:`px-4 py-2 text-[13px] font-bold border border-[var(--panel-border)] rounded-xl mr-2 hover:bg-foreground/5 transition-colors`,children:`Today`}),(0,l.jsx)(`button`,{onClick:Ce,className:`p-2 rounded-xl text-foreground/50 hover:text-foreground hover:bg-foreground/5 transition-colors border border-transparent hover:border-[var(--panel-border)]`,children:(0,l.jsx)(n.ot,{className:`w-5 h-5`})}),(0,l.jsx)(`button`,{onClick:we,className:`p-2 rounded-xl text-foreground/50 hover:text-foreground hover:bg-foreground/5 transition-colors border border-transparent hover:border-[var(--panel-border)]`,children:(0,l.jsx)(n.at,{className:`w-5 h-5`})})]})]}),$=()=>(0,l.jsxs)(l.Fragment,{children:[Fe(),S===`month`?(0,l.jsx)(`div`,{className:`overflow-x-auto w-full flex-1`,children:(0,l.jsxs)(`div`,{className:`min-w-[800px] h-full flex flex-col`,children:[(0,l.jsx)(`div`,{className:`grid grid-cols-7 border-b border-[var(--panel-border)]/50 bg-foreground/[0.02]`,children:xe.map(e=>(0,l.jsx)(`div`,{className:`py-3 text-center text-[12px] font-bold uppercase tracking-wider text-foreground/40`,children:e},e))}),(0,l.jsx)(`div`,{className:`grid grid-cols-7 auto-rows-auto bg-[var(--panel-border)] gap-[1px] relative flex-1`,children:Se.map((e,t)=>{let r=e.dateStr===_e(),i=E.filter(t=>t.dateStr===e.dateStr);return(0,l.jsxs)(`div`,{onClick:()=>e.isCurrentMonth&&Ne&&Te(e.dateStr),className:`min-h-[140px] p-2 bg-[var(--panel-bg)] flex flex-col relative group
|
|
@@ -381,7 +412,7 @@ export const themeConfig = {
|
|
|
381
412
|
cardRadius: ${i.cardRadius||1.5}, // 24px (2xl, 3xl)
|
|
382
413
|
modalRadius: ${i.modalRadius||2.5}, // Global popups and main internal boxes
|
|
383
414
|
}
|
|
384
|
-
};`;navigator.clipboard.writeText(a),m(!0),setTimeout(()=>m(!1),2e3)}};return(0,a.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key===`a`&&document.activeElement===document.body&&e.preventDefault(),(e.ctrlKey||e.metaKey)&&e.key===`c`&&!window.getSelection()?.toString()&&r&&b()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]),(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Theme`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/theme`]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-6 md:p-10 shadow-2xl relative overflow-hidden bg-background flex flex-col min-h-[600px]`,children:[(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Theme Config`}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`Changes here immediately format natively. Save to update your Live Preview panel entirely.`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:_,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-xl flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:u?(0,l.jsx)(n.M,{className:`w-4 h-4 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-4 h-4 text-foreground/60 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(n.n,{variant:`secondary`,onClick:b,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors`,title:`Copy Config (Ctrl+C)`,children:p?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-4 h-4 text-foreground/60 hover:text-foreground transition-colors`})})]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 w-full relative z-10 items-start`,children:[u&&(0,l.jsx)(`div`,{className:`absolute inset-0 bg-background/60 backdrop-blur-[2px] z-50 flex items-center justify-center rounded-3xl pointer-events-none transition-all duration-300`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 animate-spin text-accent`})}),(0,l.jsxs)(`div`,{className:`w-full glass-panel border border-[var(--panel-border)] rounded-3xl p-6 md:p-8 shadow-inner overflow-hidden relative bg-background`,children:[(0,l.jsx)(`h3`,{className:`text-lg font-extrabold text-foreground tracking-tight mb-4 flex items-center gap-3`,children:`Branding & Colours`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-3 overflow-x-auto hide-scrollbars pb-4 pt-2 mb-6 border-b border-[var(--panel-border)]/50 shrink-0`,children:[(0,l.jsx)(`div`,{className:`text-[12px] font-bold text-foreground/40 shrink-0 uppercase tracking-widest pl-1 mr-2`,children:`Presets`}),Ut.map(e=>{let t=r?.colors?.dark?.accent===e.dark.accent&&r?.colors?.dark?.buttonGradient?.[0]===e.dark.gradient[0],n=e.name===`Black & White`;return(0,l.jsx)(`button`,{onClick:()=>y(e),className:`w-9 h-9 rounded-full shrink-0 outline-none transition-all shadow-sm relative group overflow-visible ${t?`ring-[3px] ring-foreground ring-offset-2 ring-offset-[var(--background)] scale-110 z-10`:`opacity-80 hover:opacity-100 hover:ring-2 hover:ring-foreground/30 hover:ring-offset-2 hover:ring-offset-[var(--background)] hover:scale-105`}`,title:e.name,children:(0,l.jsx)(`div`,{className:`absolute inset-0 rounded-full`,style:n?{backgroundColor:`#ffffff`,border:`3px solid #000000`,boxShadow:`inset 0 0 0 1px rgba(0,0,0,0.1)`}:{backgroundImage:`linear-gradient(135deg, ${e.preview[0]}, ${e.preview[1]})`}})},e.name)})]}),(0,l.jsx)(`div`,{className:`w-full relative min-h-[100px]`,children:r?(0,l.jsxs)(`div`,{className:`flex flex-col pl-2`,children:[(0,l.jsxs)(`span`,{className:`text-yellow-500 font-mono text-[13px] mb-2`,children:[`export const themeConfig = `,`{`]}),(0,l.jsx)(Kt,{value:r,keysToRender:[`appName`,`defaultTheme`,`showThemeToggle`,`logoUrl`,`faviconUrl`,`cornerRounding`,`cornerRadii`,`fontFamily`],onChange:e=>i(e),isLast:!1,isGlobalSaving:s}),(0,l.jsx)(`div`,{className:`mt-4`,children:(0,l.jsx)(Kt,{objectKey:`colors`,value:r.colors,onChange:e=>i({...r,colors:e}),isLast:!1,isGlobalSaving:s})})]}):(0,l.jsx)(`div`,{className:`flex items-center justify-center w-full h-full text-foreground/40 font-mono text-[13px] animate-pulse py-10`,children:`Loading Data Tree...`})})]})]})]})]})]})}var Jt={route:`/page_1`,pageName:`New Public Page`,template:`none`,pageTitle:`My Custom Page`,copyPrompt:!0,showButton:!0,buttonText:`Open Form`,action:`form`,form:`contact`},Yt={tabName:`New Private Page`,iconName:``,route:`/new-private-page`,template:`none`,form:`support`,showPrompt:!0,tabTitle:`Private Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},Xt={tabName:`Admin Tab`,iconName:``,route:`/admin-tab`,template:`none`,form:``,showPrompt:!0,tabTitle:`Admin Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},Zt={tabName:`Shared Tab`,iconName:``,route:`/shared-tab`,template:`none`,form:``,showPrompt:!0,tabTitle:`Shared Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},Qt=[{id:`home`,title:`Home Page`,path:`/`,type:`public`,isSystem:!0,enabled:!0}],$t=({enabled:e,onChange:t,disabled:r,className:i=``})=>(0,l.jsx)(`button`,{disabled:r,onClick:()=>t(!e),title:e?`Page Active`:`Page Hidden`,className:`p-1.5 transition-colors rounded-lg flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity ${i} ${e?`text-accent hover:bg-accent/10`:`text-foreground/40 hover:bg-foreground/5`} ${r?`!opacity-50 cursor-not-allowed`:`cursor-pointer`}`,children:e?(0,l.jsx)(n.K,{className:`w-4 h-4`}):(0,l.jsx)(n.q,{className:`w-4 h-4`})});function en(){let{userRole:e}=m(),t=(0,u.useLocation)(),r=n.Ct(),[i,s]=(0,a.useState)(Qt),[c,d]=(0,a.useState)(()=>{try{return sessionStorage.getItem(`fbos_pages_expandedId`)||null}catch{return null}}),f=(0,a.useRef)(c),[p,h]=(0,a.useState)(!1),[g,_]=(0,a.useState)({}),[v,y]=(0,a.useState)({}),[b,x]=(0,a.useState)({}),[C,w]=(0,a.useState)(null),[T,E]=(0,a.useState)(!1),D=(0,a.useRef)(null);(0,a.useEffect)(()=>{function e(e){D.current&&!D.current.contains(e.target)&&h(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let[O,k]=(0,a.useState)(null),[A,j]=(0,a.useState)(!1),[M,N]=(0,a.useState)(!1),[P,F]=(0,a.useState)(new Set),[I,L]=(0,a.useState)(new Set),[R,z]=(0,a.useState)([]),[B,V]=(0,a.useState)([]),ne=e=>(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden});(0,a.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`page_order`),e=>{let t=ne(e.exists()&&e.data().order||[]);z(t),F(new Set(t.filter(e=>e.hidden).map(e=>e.id)))}),t=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`tab_order`),e=>{let t=ne(e.exists()&&e.data().order||[]);V(t),L(new Set(t.filter(e=>e.hidden).map(e=>e.id)))});return()=>{e(),t()}},[]),(0,a.useEffect)(()=>{let e=t.pathname.split(`/pages/`)[1]?.split(`/`)[0];e&&!c&&i.some(t=>t.id===e)&&d(e)},[t.pathname,i]),(0,a.useEffect)(()=>{f.current=c;try{c?sessionStorage.setItem(`fbos_pages_expandedId`,c):sessionStorage.removeItem(`fbos_pages_expandedId`)}catch{}},[c]);let H=(0,a.useRef)(null);(0,a.useEffect)(()=>{let e=H.current;if(!e)return;try{let t=sessionStorage.getItem(`fbos_pages_scrollY`);t&&(e.scrollTop=parseInt(t,10))}catch{}let t=()=>{try{sessionStorage.setItem(`fbos_pages_scrollY`,String(e.scrollTop))}catch{}};return e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[]),(0,a.useEffect)(()=>{let e=(e,t)=>{if(!t)return e;let n=Object.fromEntries(Object.entries(t).filter(([e,t])=>t!=null&&t!==``));return{...e,...n}},t=r?.defaultConfigs?.home||S,i=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_pages`,`home`),n=>{n.exists()?k(e(t,n.data())):k(t)});return()=>{i()}},[r]),(0,a.useEffect)(()=>{(async()=>{try{let[e,t]=await Promise.all([(0,o.getDocs)((0,o.collection)(n.Tt,`sys_pages`)),(0,o.getDocs)((0,o.collection)(n.Tt,`sys_tabs`))]),r=[`home`,`contact`,`support`,`theme`,`page_order`,`tab_order`],i=[],a={};e.forEach(e=>{if(!r.includes(e.id)){let t=e.data();i.push({id:e.id,title:t.pageName||t.title||e.id,path:t.route||`/`+e.id,type:`public`,isSystem:!1,enabled:t.enabled!==!1}),a[e.id]=t}}),t.forEach(e=>{if(!r.includes(e.id)){let t=e.data(),n=t.pageType||`private`;i.push({id:e.id,title:t.tabName||t.title||e.id,path:t.route||`/`+e.id,type:n,isSystem:!1,enabled:t.enabled!==!1}),a[e.id]=t}}),i.length>0&&(s(e=>{let t=e.filter(e=>e.isSystem||e.id.startsWith(`draft_`)),n=i.filter(e=>!t.some(t=>t.id===e.id));return[...t,...n]}),_(e=>({...e,...a})))}catch(e){console.error(`Error loading custom pages`,e)}})()},[]);let[U,W]=(0,a.useState)([`contact`]),[G,K]=(0,a.useState)([`support`]);(0,a.useEffect)(()=>{(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{let t=[],n=[];e.forEach(e=>{e.data().formType===`private`?n.push(e.id):t.push(e.id)}),t.length>0&&W(t),n.length>0&&K(n)}).catch(console.error)},[]);let[re,ie]=(0,a.useState)(null),q=(e,t)=>{let n;n=e===`home`?`export const defaultHomeConfig = ${JSON.stringify(t,null,2)};\n`:JSON.stringify(t,null,2),navigator.clipboard.writeText(n),ie(e),setTimeout(()=>ie(null),2e3)},J=async(e,t)=>{t.route&&!t.route.startsWith(`/`)&&(t.route=`/`+t.route);let r=i.find(t=>t.id===e)?.type,a=r===`public`?`sys_pages`:`sys_tabs`;r&&r!==`public`&&(t.pageType=r);let c=[`home`].includes(e)?e:t.route?t.route.replace(/^\/+/,``).replace(/[^a-zA-Z0-9_\-]/g,`_`).toLowerCase():e;e===`home`?j(!0):y(t=>({...t,[e]:!0,[c]:!0}));try{if(c!==e&&c.trim()!==``&&c!==`draft`){try{let{deleteDoc:t}=await import(`firebase/firestore`);await t((0,o.doc)(n.Tt,a,e))}catch{}await(0,o.setDoc)((0,o.doc)(n.Tt,a,c),t),s(n=>n.map(n=>n.id===e?{...n,id:c,_uiKey:n._uiKey||e,path:t.route,title:t.pageName||t.tabName||t.title||n.title}:n)),f.current===e&&(d(c),window.history.replaceState(null,``,`/pages/${c}`)),_(n=>{let r={...n};return r[c]=t,delete r[e],r});let i=r===`public`,l=i?`page_order`:`tab_order`,u=i?R:B;if(!u.some(e=>e.id===c)){let t=[{id:c,hidden:!1},...u.filter(t=>t.id!==e)];try{await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,l),{order:t})}catch(e){console.error(`Failed to update tab order:`,e)}}}else await(0,o.setDoc)((0,o.doc)(n.Tt,a,e),t),e===`home`?k(t):(_(n=>({...n,[e]:t})),s(n=>n.map(n=>n.id===e?{...n,path:t.route||n.path,title:t.pageName||t.tabName||t.title||n.title}:n)))}catch(t){console.error(`Failed to save ${e} config:`,t)}finally{setTimeout(()=>{e===`home`?j(!1):y(t=>({...t,[e]:!1,[c]:!1}))},500)}},Y=async e=>{e.stopPropagation(),N(!0);try{let{deleteDoc:e}=await import(`firebase/firestore`);await e((0,o.doc)(n.Tt,`sys_pages`,`home`)),localStorage.removeItem(`fbos_home_config`),k(r?.defaultConfigs?.home||S)}catch(e){console.error(`Failed to reset home config:`,e)}setTimeout(()=>N(!1),500)},ae=async(e,t,n)=>{e.stopPropagation(),x(e=>({...e,[t]:!0})),await J(t,n),setTimeout(()=>x(e=>({...e,[t]:!1})),500)},oe=e=>{let t=`draft_`+Math.floor(Math.random()*1e4);s([...i,{id:t,title:`New Tab`,path:`/draft`,type:e,isSystem:!1,enabled:!0}]);let n=i.filter(t=>t.type===e&&!t.id.startsWith(`draft_`)).length+1,r={};e===`public`?r={...Jt,route:`/page-${n}`}:e===`private`?r={...Yt,route:`/private-tab-${n}`}:e===`admin`?r={...Xt,route:`/admin-tab-${n}`}:e===`shared`&&(r={...Zt,route:`/shared-tab-${n}`}),_(e=>({...e,[t]:r})),d(t),h(!1),J(t,{...r,pageType:e===`public`?void 0:e}),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})},100)};if(e!==`admin`)return(0,l.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,l.jsx)(n.v,{className:`w-12 h-12 text-red-500 mb-4`}),(0,l.jsx)(`h2`,{className:`text-2xl font-bold`,children:`Access Denied`}),(0,l.jsx)(`p`,{className:`text-foreground/60`,children:`You do not have permission to view pages configuration.`})]})});let se=async(e,t,r)=>{let a=r===`public`,c=a?`page_order`:`tab_order`,l=a?R:B,u=(a?P:I).has(e);s(i.map(t=>t.id===e?{...t,enabled:u}:t));let d=[...l],f=d.findIndex(t=>t.id===e);f===-1?d.push({id:e,hidden:!0}):d[f]={...d[f],hidden:!u},await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,c),{order:d})},ce=(e,t)=>{t||w(e)},le=async()=>{if(C){E(!0);try{let{deleteDoc:e,collection:t,getDocs:r,doc:a,getDoc:o,query:l,where:u}=await import(`firebase/firestore`),{ref:f,deleteObject:p}=await import(`firebase/storage`),m=i.find(e=>e.id===C),h=m?.type===`public`?`sys_pages`:`sys_tabs`;if(h===`sys_tabs`&&m){let i=g[C];if(!i)try{let e=await o(a(n.Tt,`sys_tabs`,C));e.exists()&&(i=e.data())}catch{}let s=(i?.tabName||i?.pageId||C).toLowerCase().replace(/[^a-z0-9]+/g,`_`),c=[`admin_${s}_records`,`mem_${s}_records`,`user_${s}_records`],d={[`admin_${s}_records`]:{prefix:`admin_files`,driveCollection:`admin_files`},[`mem_${s}_records`]:{prefix:`mem_files`,driveCollection:`mem_files`},[`user_${s}_records`]:{prefix:`user_files`,driveCollection:`user_files`}},m=[];for(let i of c)m.push((async()=>{try{let a=await r(t(n.Tt,i)),o=d[i],s=[];for(let i of a.docs){let a=i.data();a.recordType===`file`&&a.downloadURL&&o&&s.push((async()=>{try{let i=`${o.prefix}%2F`,s=a.downloadURL.split(i)[1]?.split(`?`)[0];s&&await p(f(n.Dt,`${o.prefix}/${decodeURIComponent(s)}`)).catch(()=>{});let c=await r(l(t(n.Tt,o.driveCollection),u(`downloadURL`,`==`,a.downloadURL)));await Promise.all(c.docs.map(t=>e(t.ref)))}catch(e){console.error(`Error deleting storage file:`,e)}})())}await Promise.all(s),await Promise.all(a.docs.map(t=>e(t.ref)));try{localStorage.removeItem(`fbos_records_${i}`)}catch{}}catch(e){console.error(`Error cleaning up collection ${i}:`,e)}})());for(let i of[`admin_files`,`mem_files`,`user_files`])m.push((async()=>{try{let a=await r(l(t(n.Tt,i),u(`sourceTab`,`==`,s)));await Promise.all(a.docs.map(async t=>{let r=t.data();if(r.downloadURL)try{let e=`${i}%2F`,t=r.downloadURL.split(e)[1]?.split(`?`)[0];t&&await p(f(n.Dt,`${i}/${decodeURIComponent(t)}`)).catch(()=>{})}catch{}await e(t.ref)}))}catch{}})());await Promise.all(m)}await e(a(n.Tt,h,C));let _=h===`sys_pages`?`page_order`:`tab_order`,v=h===`sys_pages`?R:B,{setDoc:y}=await import(`firebase/firestore`),b=v.filter(e=>e.id!==C);await y(a(n.Tt,`sys_configs`,_),{order:b}),s(e=>e.filter(e=>e.id!==C)),c===C&&d(null)}catch(e){console.error(`Error deleting page:`,e)}E(!1),w(null)}},ue=e=>{let t=e.id+`_`+Math.floor(Math.random()*1e3),n={...e,id:t,title:`${e.title} (Copy)`,path:`${e.path}_copy`,isSystem:!1,enabled:!0};s(e=>[...e,n]);let r=g[e.id];!r&&e.id===`home`&&(r=O);let i={...r||{},route:n.path,pageName:n.title};n.type!==`public`&&(i.tabName=n.title,i.pageType=n.type),_(e=>({...e,[t]:i})),d(t),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})},100)},de=[{id:`public`,title:`Public Pages`,icon:n.U,color:`bg-amber-500`,description:`Creates external menu items. Invisible to signed-in dashboard users.`,filter:e=>e.type===`public`},{id:`private`,title:`Private Pages`,icon:n.j,color:`bg-emerald-500`,description:`Internal dashboard tabs for regular users.`,filter:e=>e.type===`private`},{id:`shared`,title:`Shared Pages`,icon:n.K,color:`bg-blue-500`,description:`Dashboard tabs visible to all members, editors, and admins.`,filter:e=>e.type===`shared`},{id:`admin`,title:`Admin Pages`,icon:n.v,color:`bg-red-500`,description:`Internal dashboard tabs for admin users only.`,filter:e=>e.type===`admin`}],[fe,X]=(0,a.useState)(!1),[pe,me]=(0,a.useState)(!1);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Pages`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/pages`,c?`/${c}`:``]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(`div`,{className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-6 pt-6 md:px-10 md:pt-10`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Architecture`}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`Manage the structure of your application tabs and public pages.`})]}),(0,l.jsxs)(`div`,{className:`relative z-50 shrink-0 flex items-center gap-1`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>X(!0),className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,title:`Reset Defaults`,children:(0,l.jsx)(n.x,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>h(!p),className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,title:`Add New Page`,children:(0,l.jsx)(n.C,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,l.jsx)(n.a,{children:p&&(0,l.jsx)(n.i.div,{ref:D,initial:{opacity:0,y:10,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.95},className:`absolute top-full mt-2 right-0 w-48 glass-panel border border-[var(--panel-border)] rounded-2xl p-2 shadow-xl z-50 flex flex-col gap-1`,children:[`public`,`private`,`shared`,`admin`].map(e=>(0,l.jsxs)(`button`,{onClick:()=>{oe(e),h(!1)},className:`text-left px-3 py-2 text-[13px] font-bold uppercase tracking-wider text-foreground/70 hover:text-foreground hover:bg-foreground/5 rounded-lg transition-colors cursor-pointer`,children:[e,` Page`]},e))})})]})]})]}),(0,l.jsxs)(`div`,{ref:H,className:`px-6 md:px-10 pb-6 md:pb-10 flex flex-col pt-0 gap-10 overflow-y-auto mt-2 relative min-h-[400px]`,children:[(0,l.jsx)(n.a,{children:pe&&(0,l.jsx)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-[2px] rounded-3xl`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-6 glass-panel rounded-2xl shadow-xl`,children:[(0,l.jsx)(n.M,{className:`w-8 h-8 md:w-10 md:h-10 animate-spin text-accent mb-4`}),(0,l.jsx)(`span`,{className:`text-sm font-bold text-foreground`,children:`Synchronizing Architecture...`})]})})}),de.map((e,t)=>{let r=i.filter(e.filter),a=e.id===`public`?R:B,o=r.sort((e,t)=>{let n=a.findIndex(t=>t.id===e.id),r=a.findIndex(e=>e.id===t.id);return n===-1&&r===-1?0:n===-1?1:r===-1?-1:n-r}),s=e.icon,u=e=>e.type===`public`?P.has(e.id):I.has(e.id),f=o.filter(e=>!u(e)),p=o.filter(e=>u(e)),m=e=>{if(!e)return[];let t=[`route`,`pageName`,`template`];return e.template===`none`?(t.push(`pageTitle`,`copyPrompt`),t.push(`showButton`),e.showButton!==!1&&(t.push(`buttonText`,`action`),e.action===`form`?t.push(`form`):e.action===`redirect`&&t.push(`redirectUrl`))):(e.template===`popup_form`||e.template===`inline_form`)&&(t.push(`showButton`),e.showButton!==!1&&t.push(`form`)),t},h=e=>{if(!e)return[];let t=[`tabName`,`iconName`,`route`,`template`];return e.template===`popup_form`||e.template===`inline_form`?(t.push(`showButton`),e.showButton!==!1&&t.push(`form`)):e.template===`none`?(t.push(`showPrompt`,`tabTitle`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonStyle`,`buttonText`,`buttonAction`),t.push(`storage`),e.storage!==!1&&t.push(`buttonStorageIcon`,`buttonStorageText`,`buttonStorageStyle`,`buttonStorageAction`)):e.template===`calendar`?(t.push(`tabTitle`,`showPrompt`),t.push(`defaultView`,`defaultTimeFormat`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`showViewsButton`),e.showViewsButton!==!1&&t.push(`viewsButtonStyle`)):e.template===`table`?(t.push(`tabTitle`,`showPrompt`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`showExportButton`),e.showExportButton!==!1&&t.push(`exportButtonIcon`)):e.template===`board`&&(t.push(`tabTitle`,`showPrompt`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`keyName`,`valueName`)),t},_=(t,r,i)=>{let a=t.id===`home`,o=c===t.id,s=a||!t.isSystem;return(0,l.jsxs)(`div`,{id:`page-${t.id}`,onClick:e=>{if(s){let e=o?null:t.id;d(e),window.history.replaceState(null,``,e?`/pages/${e}`:`/pages`)}},className:`group flex flex-col py-4 px-5 glass-panel border transition-all rounded-2xl hover:shadow-sm ${s?`cursor-pointer hover:border-accent/40`:``} ${i?`opacity-40 grayscale bg-foreground/[0.01] border-[var(--panel-border)]/50`:`border-transparent hover:border-[var(--panel-border)]`}`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-center justify-between w-full gap-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-1 w-full flex-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground truncate`,children:t.title}),a&&A&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-accent ml-2`})]}),(0,l.jsxs)(`div`,{className:`text-[11px] font-medium font-mono px-2 py-0.5 rounded w-fit ml-6 border ${i?`text-foreground/50 border-foreground/10 bg-foreground/5`:`text-accent/70 bg-accent/5 border-accent/10`}`,children:[window.location.host,t.path]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-4 shrink-0`,children:[!t.isSystem||[`contact`,`support`,`templates`].includes(t.id)?(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ue(t)},className:`p-1.5 hover:bg-accent/10 text-foreground/40 hover:text-accent transition-colors rounded-lg flex items-center justify-center shrink-0`,title:`Duplicate Page`,children:(0,l.jsx)(n.Z,{className:`w-4 h-4`})}):(0,l.jsx)(`div`,{className:`w-[28px] shrink-0`}),(0,l.jsx)(`div`,{className:`flex items-center justify-end w-8 shrink-0`,children:t.id===`home`?(0,l.jsx)(`div`,{className:`w-[28px] shrink-0`}):(0,l.jsx)($t,{enabled:!u(t),onChange:()=>se(t.id,t.isSystem,t.type)})}),t.isSystem?(0,l.jsx)(`div`,{className:`w-[28px] shrink-0`}):(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ce(t.id,t.isSystem)},className:`p-1.5 hover:bg-red-500/10 text-foreground/30 hover:text-red-500 transition-colors rounded-lg flex items-center justify-center shrink-0`,title:`Delete Page`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),s?(0,l.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 shrink-0 ${o?`rotate-180`:``}`,children:(0,l.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,l.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}):(0,l.jsx)(`div`,{className:`w-[24px] shrink-0`})]})]}),(0,l.jsxs)(n.a,{children:[o&&a&&O&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50 pb-4`,onClick:e=>e.stopPropagation(),children:(0,l.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 py-6 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,l.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,l.jsx)(`button`,{onClick:Y,className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:M?(0,l.jsx)(n.M,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),q(`home`,O)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:re===`home`?(0,l.jsx)(n.nt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,l.jsx)(Kt,{value:O,keysToRender:[`hero`],onChange:e=>J(`home`,e),isLast:!0,isGlobalSaving:A,customEnums:{form:U},customExplanations:{form:`User can click to switch to any public form we have in the forms tab. Private forms are not an option here. Add a new form in forms with a link that actually works.`}})]})}),o&&!t.isSystem&&g[t.id]&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50 pb-4`,onClick:e=>e.stopPropagation(),children:(0,l.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 py-6 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,l.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,l.jsx)(`button`,{onClick:e=>ae(e,t.id,t.type===`admin`?Xt:t.type===`shared`?Zt:t.type===`public`?Jt:Yt),className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:b[t.id]?(0,l.jsx)(n.M,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),q(t.id,g[t.id])},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:re===t.id?(0,l.jsx)(n.nt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,l.jsx)(Kt,{value:g[t.id],keysToRender:t.type===`public`?m(g[t.id]):h(g[t.id]),onChange:e=>J(t.id,e),isLast:!0,isGlobalSaving:v[t.id],customEnums:{form:t.type===`public`?U:G,template:t.type===`public`?[`none`,`popup_form`,`inline_form`]:t.type===`admin`||t.type===`shared`?[`none`,`calendar`,`table`,`board`]:[`none`,`calendar`,`table`,`board`,`popup_form`,`inline_form`],action:[`save_Info`,`form`],defaultTimeFormat:[`12h`,`24h`],defaultView:[`calendar`,`board`],buttonStyle:[`primary`,`secondary`],buttonAction:[`save_info`],viewsButtonStyle:[`primary`,`secondary`],buttonStorageStyle:[`primary`,`secondary`],buttonStorageAction:[`upload_file`]},customExplanations:{tabName:`Defines the tab label in the dashboard navigation.`,iconName:`Visit https://lucide.dev/icons/, find an icon, and paste its exact name (e.g. 'book-open', 'server', 'cloud-upload').`,route:`The URL path for this tab (e.g. '/my-tab'). Must start with /.`,template:`Page layout type. 'none' gives you a freeform dashboard with add/upload buttons.`,form:`Which form to display. Only applies to popup_form or inline_form templates. Go to /forms to edit forms.`,tabTitle:`The heading that appears at the top of the page content area.`,showPrompt:`Shows the developer AI prompt copy button in the header.`,showButton:`Toggles the + add record button in the header.`,buttonStyle:`Visual style of the add button: 'primary' (accent) or 'secondary' (subtle).`,buttonText:`Label on the add button. Use '+' for a minimal icon-only button.`,buttonAction:`'save_info' saves a name + note record to the tab's Firestore collection.`,storage:`Enables the file upload button for this tab.`,buttonStorageIcon:`Icon name from https://lucide.dev/icons/ for the upload button (e.g. 'upload', 'cloud-upload').`,buttonStorageText:`Label next to the upload icon. Leave empty for icon-only.`,buttonStorageStyle:`'primary' or 'secondary' visual style for the upload button.`,buttonStorageAction:t.type===`admin`?`'upload_file' uploads to admin_files/ in Storage and mirrors metadata to admin_files collection (Drive > Admin).`:t.type===`shared`?`'upload_file' uploads to mem_files/ in Storage and mirrors metadata to mem_files collection (Drive > Shared).`:`'upload_file' uploads to user_files/ in Storage and mirrors metadata to user_files collection (Drive > Private).`,defaultView:`Starting view: 'calendar' (month grid) or 'board' (event list). Users can switch between them.`,defaultTimeFormat:`12h or 24h time format. Users can toggle this in the toolbar.`,showViewsButton:`Show the calendar/board view toggle button in the toolbar.`,viewsButtonStyle:`'primary' or 'secondary' visual style for the view toggle.`,showExportButton:`Show the CSV export/download button in the table toolbar.`,exportButtonIcon:`Icon name from https://lucide.dev/icons/ for the export button (e.g. 'download', 'import').`,keyName:`Label for the key/title field in board items (e.g. 'Task', 'Name').`,valueName:`Label for the value/description field in board items (e.g. 'Notes', 'Details').`},hideInnerLoader:!0})]})})]})]},`${e.id}-${t._uiKey||t.id}`)};return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex flex-col relative`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-3 mb-2 border-b border-[var(--panel-border)]/50 pb-4`,children:[(0,l.jsx)(`div`,{className:`w-8 h-8 rounded-xl glass-panel border border-[var(--panel-border)] flex items-center justify-center -ml-1 shadow-sm`,children:(0,l.jsx)(s,{className:`w-4 h-4 text-accent`})}),(0,l.jsx)(`h2`,{className:`text-xl font-extrabold tracking-tight text-foreground`,children:e.title})]}),(0,l.jsx)(`p`,{className:`text-[13px] leading-relaxed text-foreground/50 font-medium max-w-3xl mb-4 ml-[2px]`,children:e.description}),o.length===0?(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 opacity-40 glass-panel rounded-2xl border border-[var(--panel-border)]/50 border-dashed`,children:[(0,l.jsx)(n.L,{className:`w-5 h-5 mb-2`}),(0,l.jsx)(`p`,{className:`text-[12px] font-bold`,children:`This section is currently empty.`})]}):(0,l.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[f.map(e=>_(e,o.findIndex(t=>t.id===e.id),!1)),p.length>0&&(0,l.jsxs)(`details`,{className:`mt-4 group/details`,children:[(0,l.jsxs)(`summary`,{className:`text-[11px] font-bold uppercase tracking-wider text-foreground/40 cursor-pointer list-none flex items-center gap-2 select-none hover:text-foreground/70 transition-colors w-fit pb-1 ml-1 outline-none`,children:[(0,l.jsx)(n.st,{className:`w-3.5 h-3.5 group-open/details:-rotate-180 transition-transform`}),`Hidden pages (`,p.length,`)`]}),(0,l.jsx)(`div`,{className:`flex flex-col gap-4 mt-4`,children:p.map(e=>_(e,o.findIndex(t=>t.id===e.id),!0))})]})]}),t<de.length-1&&(0,l.jsx)(`div`,{className:`w-full border-t border-[var(--panel-border)]/70 my-10`})]},e.id)})]})]})]}),(0,l.jsx)(te,{isOpen:fe,onCancel:()=>X(!1),onConfirm:async()=>{me(!0);try{let{deleteDoc:e}=await import(`firebase/firestore`);await Promise.all([e((0,o.doc)(n.Tt,`sys_pages`,`home`))]),k(S)}catch(e){console.error(`Error resetting defaults:`,e)}setTimeout(()=>{me(!1),X(!1)},1e3)},title:`Reset System Pages`,message:`Are you sure you want to reset all system page configurations? Custom pages and their order will remain intact.`,confirmText:`Reset`,isProcessing:pe}),(0,l.jsx)(te,{isOpen:!!C,onCancel:()=>w(null),onConfirm:le,title:`Delete Page`,message:`Are you sure you want to delete this page? This action cannot be undone and will remove all associated configurations.`,confirmText:`Remove Page`,isProcessing:T})]})}var tn={contact:r.t,support:i.t};function nn(){let{userRole:e}=m(),t=(0,u.useNavigate)();(0,u.useLocation)();let[r,i]=(0,a.useState)({}),[s,c]=(0,a.useState)(!0),[d,f]=(0,a.useState)({}),p=n.Ct(),h=()=>({...tn,contact:p?.defaultConfigs?.contactForm||tn.contact,support:p?.defaultConfigs?.supportForm||tn.support}),[g,_]=(0,a.useState)(null),[v,y]=(0,a.useState)({}),[b,x]=(0,a.useState)(null),[S,C]=(0,a.useState)(!1),[w,T]=(0,a.useState)(null),E=(e,t)=>{let n;n=e===`contact`?`export const contactFormConfig = ${JSON.stringify(t,null,2)};\n`:e===`support`?`export const supportFormConfig = ${JSON.stringify(t,null,2)};\n`:JSON.stringify(t,null,2),navigator.clipboard.writeText(n),T(e),setTimeout(()=>T(null),2e3)};(0,a.useEffect)(()=>{D()},[]);let D=async()=>{try{let e=await(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)),t={};e.forEach(e=>{if(e.id!==`pubForm`&&e.id!==`userForm`){let n=e.data();n._uiKey||=Math.random().toString(36).substring(7),t[e.id]=n}});try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,`pubForm`)),await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,`userForm`))}catch{}let r=h();for(let[e,i]of Object.entries(r))if(!t[e]){await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),i);let r={...i};r._uiKey=Math.random().toString(36).substring(7),t[e]=r}else if(!t[e].fields||t[e].fields.length===0){let i=r[e];t[e].fields=i.fields||[],await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),t[e])}let a=window.location.pathname.split(`/forms/`)[1]?.split(`/`)[0];a&&t[a]&&y({[a]:!0}),i(t)}catch(e){console.error(`Failed to load forms:`,e)}finally{c(!1)}},O=async(e,t)=>{let a={...t};r[e]?._uiKey&&(a._uiKey=r[e]._uiKey),e===`contact`?(a.systemName=`contact`,a.formType=`public`,a.submitPage=`submissions`):e===`support`&&(a.systemName=`support`,a.formType=`private`,a.submitPage=`requests`);let s=a.systemName||e;if(s!==e&&s.trim()!==``){i(t=>{let n={};for(let r of Object.keys(t))r===e?n[s]=a:n[r]=t[r];return n}),v[e]&&y(t=>{let n={};for(let r of Object.keys(t))r===e?n[s]=t[r]:n[r]=t[r];return n}),f(e=>({...e,[s]:!0}));try{await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,s),a),await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,e))}catch(e){console.error(`Failed to migrate form map ID:`,e)}finally{setTimeout(()=>{f(e=>({...e,[s]:!1}))},500)}}else{i(t=>({...t,[e]:a})),f(t=>({...t,[e]:!0}));try{await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),a)}catch(e){console.error(`Failed to save form:`,e)}finally{setTimeout(()=>{f(t=>({...t,[e]:!1}))},500)}}},[k,A]=(0,a.useState)(!1),j=async()=>{if(k)return;A(!0);let e=`new_form_${Date.now().toString().slice(-4)}`,r={title:`New Custom Form`,systemName:e,formType:`public`,submitPage:`submissions`,redirectTo:``,submitText:`Submit`,fields:[],enabled:!0,_uiKey:Math.random().toString(36).substring(7)};try{f(t=>({...t,[e]:!0})),await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),r),i(t=>({[e]:r,...t})),y(t=>({[e]:!0,...t})),t(`/forms/${e}`)}catch(e){console.error(`Failed to create form`,e)}finally{f(t=>({...t,[e]:!1})),A(!1)}},M=async e=>{if(!(e===`contact`||e===`support`)){C(!0);try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,e)),i(t=>{let n={...t};return delete n[e],n}),t(`/forms`)}catch(e){console.error(`Failed to delete form`,e)}finally{C(!1),x(null)}}};if(e!==`admin`)return(0,l.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,l.jsx)(n.p,{className:`w-12 h-12 text-red-500 mb-4`}),(0,l.jsx)(`h2`,{className:`text-2xl font-bold bg-clip-text text-transparent bg-gradient-to-br from-red-400 to-red-600`,children:`Access Restricted`}),(0,l.jsx)(`p`,{className:`text-foreground/60 max-w-sm text-center mt-2 font-medium leading-relaxed`,children:`This area is exclusively for system administrators.`})]})});let N=e=>{y(t=>{let n={...t,[e]:!t[e]};if(n[e])window.history.replaceState(null,``,`/forms/${e}`);else{let e=Object.keys(n).filter(e=>n[e]);e.length>0?window.history.replaceState(null,``,`/forms/${e[0]}`):window.history.replaceState(null,``,`/forms`)}return n})},P=Object.keys(v).find(e=>v[e]);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Forms`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/forms`,P?`/${P}`:``]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(`div`,{className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-6 pt-6 md:px-10 md:pt-10 bg-background/50`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Custom Forms`}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`This is the central page where you configure and manage your application's forms. Easily add and customize the fields for your users.`})]}),(0,l.jsx)(`div`,{className:`relative z-50 shrink-0 flex items-center justify-end`,children:(0,l.jsx)(n.n,{variant:`secondary`,onClick:j,title:`Add Custom Form`,disabled:k,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,children:k?(0,l.jsx)(n.M,{className:`w-4 h-4 text-foreground/60 animate-spin`}):(0,l.jsx)(n.C,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})})})]}),(0,l.jsx)(`div`,{className:`p-6 md:p-8 flex flex-col gap-4 overflow-y-auto`,children:s?(0,l.jsx)(`div`,{className:`flex items-center justify-center p-12 glass-panel rounded-3xl border border-[var(--panel-border)]`,children:(0,l.jsx)(n.M,{className:`w-6 h-6 animate-spin text-accent`})}):Object.keys(r).length===0?(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-12 glass-panel rounded-3xl border border-[var(--panel-border)] border-dashed opacity-50`,children:[(0,l.jsx)(n.S,{className:`w-6 h-6 mb-3 text-foreground/40`}),(0,l.jsx)(`p`,{className:`text-[13px] font-bold`,children:`No forms currently configured.`})]}):(0,l.jsx)(n.a,{children:Object.entries(r).map(([e,t])=>{let r=v[e],i=d[e];return(0,l.jsxs)(n.i.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,y:-10},onClick:()=>N(e),className:`group flex flex-col p-3 px-4 glass-panel border transition-all rounded-2xl hover:shadow-sm cursor-pointer hover:border-accent/40 ${r?`border-[var(--panel-border)] bg-background/50`:`border-transparent hover:border-[var(--panel-border)]`} flex-shrink-0 ${t.enabled===!1?`opacity-40 grayscale bg-foreground/[0.01] border-[var(--panel-border)]/50`:``}`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between w-full`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col gap-1 w-full sm:w-auto pr-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground break-words ml-1 leading-snug`,children:t.title||`Untitled Form`}),i&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-accent ml-2 shrink-0`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5 ml-1`,children:[(0,l.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest border border-[var(--panel-border)] bg-foreground/5 text-foreground/60 px-2 py-0.5 rounded-md`,children:t.systemName||e}),(0,l.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest border px-2 py-0.5 rounded-md shrink-0 ${t.formType===`private`?`text-blue-500 bg-blue-500/10 border-blue-500/20`:`text-green-500 bg-green-500/10 border-green-500/20`}`,children:t.formType||`public`})]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-4 w-full sm:w-auto justify-end mt-2 sm:mt-0 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),_(t)},className:`p-1.5 hover:bg-accent/10 text-foreground/40 hover:text-accent transition-colors rounded-lg flex items-center justify-center mr-2`,title:`Preview Form`,children:(0,l.jsx)(n.K,{className:`w-4 h-4`})}),e!==`contact`&&e!==`support`?(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),x(e)},className:`p-1.5 hover:bg-red-500/10 text-foreground/30 hover:text-red-500 transition-colors rounded-lg opacity-0 group-hover:opacity-100 flex items-center justify-center mr-2`,title:`Delete Form`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}):(0,l.jsx)(`div`,{className:`w-7 mr-2 shrink-0`}),(0,l.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 ${r?`rotate-180`:``}`,children:(0,l.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,l.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})})]})]}),(0,l.jsx)(n.a,{children:r&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50`,onClick:e=>e.stopPropagation(),children:(0,l.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,l.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,l.jsx)(`button`,{onClick:async t=>{if(t.stopPropagation(),e===`contact`||e===`support`){f(t=>({...t,[e]:!0}));try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,e)),localStorage.removeItem(`fbos_form_${e}`),await D()}catch(e){console.error(`Reset failed:`,e)}setTimeout(()=>f(t=>({...t,[e]:!1})),500)}else O(e,h()[e]||h().contact)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:i?(0,l.jsx)(n.M,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(`button`,{onClick:n=>{n.stopPropagation(),E(e,t)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:w===e?(0,l.jsx)(n.nt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,l.jsx)(Kt,{value:{systemName:t.systemName||e,formType:t.formType||`public`,submitPage:t.submitPage||(t.formType===`private`?`requests`:`submissions`),redirectTo:t.redirectTo||``,title:t.title||``,buttonName:t.buttonName||t.submitText||``,fields:t.fields||[]},keysToRender:[`systemName`,`formType`,`submitPage`,`redirectTo`,`title`,`buttonName`,`fields`],meta:{formType:t.formType||`public`},onChange:n=>{n.formType===t.formType?n.submitPage!==t.submitPage&&(n.formType=n.submitPage===`requests`?`private`:`public`):n.submitPage=n.formType===`public`?`submissions`:`requests`,O(e,{...t,...n,submitText:n.buttonName})},isLast:!0,isGlobalSaving:i,disabledKeys:e===`contact`||e===`support`?[`systemName`,`formType`,`submitPage`]:[],customEnums:{type:[`text`,`email`,`tel`,`textarea`,`number`,`select`,`checkbox`,`currency`,`age`]},customExplanations:{formType:e===`contact`?`Public means its for not signed in users. Private is disabled for contact so don't allow the user to change it.`:e===`support`?`This means that the form is available to signed in users only.`:`Public means it's for non-signed in users.`,submitPage:e===`contact`?`Means the form submissions go to this folder. User can't change that since it's directly linked. Public is tied to submissions.`:e===`support`?`Can't change since all private forms go there.`:`Where to route data submissions.`,redirectTo:`If not added form will just show a success message. If added, in 30 seconds after success user is redirected.`}})]})})})]},t._uiKey||e)})})})]})]}),(0,l.jsx)(te,{isOpen:!!b,onCancel:()=>x(null),onConfirm:()=>{b&&M(b)},title:`Delete Form`,message:`Are you sure you want to permanently delete "${b}"? This action cannot be reversed.`,confirmText:`Delete form`,isProcessing:S}),g&&(0,l.jsx)(n.t,{formConfig:g,onClose:()=>_(null)})]})}function rn({config:e,customContent:t}){let{config:r}=n.xt(),[i,s]=(0,a.useState)(!1),[c,u]=(0,a.useState)(null),[d,f]=(0,a.useState)([]);(0,a.useEffect)(()=>{document.title=e.pageName||e.pageTitle||r.appName||`Firebase OS`,(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{f(e.docs.filter(e=>e.data().formType===`public`).map(e=>e.id))})},[e.pageName,e.pageTitle,r.appName]);let p=H(e,d);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 relative min-h-screen`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.pageTitle||e.pageName||`New Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]}),(0,l.jsxs)(`div`,{className:`flex justify-between items-center mb-6 pt-2 border-b border-[var(--panel-border)] pb-6 relative z-20 overflow-x-auto no-scrollbar gap-4`,children:[(0,l.jsxs)(`button`,{onClick:()=>window.history.back(),className:`px-5 py-2 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold hover:bg-foreground/5 transition-all flex items-center gap-2 cursor-pointer shadow-sm text-foreground/70 whitespace-nowrap shrink-0`,children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` Go Back`]}),(0,l.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[e.copyPrompt&&(0,l.jsxs)(`button`,{onClick:()=>{navigator.clipboard.writeText(p),s(!0),setTimeout(()=>s(!1),2e3)},title:`Copy Developer Prompt`,className:`px-6 py-2.5 rounded-xl border border-[var(--panel-border)] bg-background flex items-center gap-2 hover:bg-foreground/5 hover:text-accent transition-all cursor-pointer text-[14px] font-bold tracking-wide shadow-sm whitespace-nowrap`,children:[(0,l.jsx)(n.ft,{className:`w-4 h-4`}),(0,l.jsx)(`span`,{className:`hidden sm:inline`,children:i?`Copied!`:`Copy Prompt`})]}),e.showButton&&(0,l.jsx)(`button`,{onClick:()=>{e.action===`redirect`?window.location.href=e.url||`/`:e.action===`form`&&u(e.form||`contact`)},className:`px-6 py-2.5 rounded-xl font-bold tracking-wide transition-all duration-300 flex items-center justify-center btn-primary shadow-xl hover:-translate-y-1 active:scale-95 text-[14px] whitespace-nowrap`,children:e.buttonText||`Action Button`})]})]}),(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl shadow-2xl relative flex flex-col flex-1 bg-background/50 h-full min-h-[400px]`,children:t?(0,l.jsx)(`div`,{className:`flex-1 p-4 md:p-8`,children:(0,l.jsx)(t,{config:e})}):(0,l.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center opacity-40 glass-panel border border-[var(--panel-border)]/50 border-dashed m-4 md:m-8 rounded-2xl p-8 py-20 text-center`,children:[(0,l.jsx)(n.ft,{className:`w-8 h-8 md:w-12 md:h-12 mb-4 text-foreground/80 opacity-50`}),(0,l.jsx)(`p`,{className:`text-[14px] font-bold mb-2`,children:`Click copy prompt at the top to start adding changes`}),(0,l.jsx)(`div`,{className:`mt-8 text-left bg-background p-6 rounded-2xl text-[12px] font-mono whitespace-pre-wrap max-w-2xl border border-[var(--panel-border)]/50 text-foreground/60 shadow-inner`,children:p})]})}),(0,l.jsx)(n.a,{children:c&&(0,l.jsx)(n.t,{onClose:()=>u(null),formId:c})})]})}function an({config:e,customContent:t}){let{user:r}=m(),{config:i}=n.xt(),[s,u]=(0,a.useState)([]),[f,p]=(0,a.useState)(!0),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(``),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(!1),[T,E]=(0,a.useState)(!1),[D,O]=(0,a.useState)(null),[k,A]=(0,a.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;P(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[N,P]=(0,a.useState)(!0),[F,I]=(0,a.useState)(!1),[L,R]=(0,a.useState)(null),[z,B]=(0,a.useState)(``),[V,ne]=(0,a.useState)(``),[H,U]=(0,a.useState)([]),W=(0,a.useRef)(null),G=(e.tabName||e.pageId||`private_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),K=`user_${G}_records`;(0,a.useEffect)(()=>{document.title=e.tabTitle||e.tabName||i.appName||`Firebase OS`,(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{})},[e.tabTitle,e.tabName,i.appName]),(0,a.useEffect)(()=>{if(!r)return;try{let e=localStorage.getItem(`fbos_records_${K}`);e?(u(JSON.parse(e)),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}});(async()=>{try{let t=e((await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,K),(0,o.where)(`uid`,`==`,r.uid),(0,o.limit)(150)))).docs);t.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),u(t),p(!1),localStorage.setItem(`fbos_records_${K}`,JSON.stringify(t))}catch(e){console.error(`Error fetching records:`,e),p(!1)}})()},[r,K]),(0,a.useEffect)(()=>{f||localStorage.setItem(`fbos_records_${K}`,JSON.stringify(s))},[s,f,K]);let re=async e=>{if(e.preventDefault(),!(!r||!_.trim())){S(!0);try{let e=await(0,o.addDoc)((0,o.collection)(n.Tt,K),{name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,createdAt:(0,o.serverTimestamp)()});u(t=>[{id:e.id,name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,createdAt:Date.now()},...t]),v(``),b(``),g(!1)}catch(e){console.error(`Error saving record:`,e)}S(!1)}},ie=async e=>{let t=e.target.files?.[0];if(!(!t||!r)){E(!0);try{let e=(0,c.ref)(n.Dt,`user_files/${`${Date.now()}_${t.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,c.uploadBytes)(e,t,{customMetadata:{ownerId:r.uid}});let i=await(0,c.getDownloadURL)(e);await(0,o.addDoc)((0,o.collection)(n.Tt,`user_files`),{fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,uid:r.uid,uploaderEmail:r.email||`user`,sourceTab:G,accessPrefix:`user_`,createdAt:(0,o.serverTimestamp)()});let a=await(0,o.addDoc)((0,o.collection)(n.Tt,K),{name:t.name,note:`${t.type||`File`} · ${ve(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,createdAt:(0,o.serverTimestamp)()});u(e=>[{id:a.id,name:t.name,note:`${t.type||`File`} · ${ve(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type,fileSize:t.size,downloadURL:i,createdAt:Date.now()},...e])}catch(e){console.error(`Error uploading file:`,e)}E(!1),W.current&&(W.current.value=``)}},q=async()=>{if(D){I(!0);try{let e=s.find(e=>e.id===D);if(await(0,o.deleteDoc)((0,o.doc)(n.Tt,K,D)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`user_files%2F`)[1]?.split(`?`)[0];t&&await(0,c.deleteObject)((0,c.ref)(n.Dt,`user_files/${decodeURIComponent(t)}`)).catch(()=>{});let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`user_files`),(0,o.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of r.docs)await(0,o.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up user file:`,e)}u(e=>e.filter(e=>e.id!==D)),O(null)}catch(e){console.error(`Error deleting record:`,e)}I(!1)}},[J,Y]=(0,a.useState)(null),[ae,oe]=(0,a.useState)(``),[se,ce]=(0,a.useState)(!1),[le,de]=(0,a.useState)(null),fe=(0,a.useRef)([]),X=e=>{if(e.recordType===`file`){Y(e.id),oe(e.name);return}R(e.id),B(e.name),ne(e.note||``);let t=[`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`],n=Object.entries(e).filter(([e])=>!t.includes(e)&&e!==`id`).map(([e,t])=>({key:e,value:String(t??``)}));U(n),fe.current=n.map(e=>e.key)},pe=async()=>{if(!J||!ae.trim()){Y(null);return}let e=s.find(e=>e.id===J);if(e&&e.name===ae.trim()){Y(null);return}ce(!0);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,K,J),{name:ae.trim()}),u(e=>e.map(e=>e.id===J?{...e,name:ae.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}ce(!1),Y(null)},me=async()=>{await Z(),R(null)},Z=async()=>{if(!L||!z.trim())return;S(!0);let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=fe.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,K,L),{name:z.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==L)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),fe.current=t}catch(e){console.error(`Error saving record:`,e)}S(!1)},he=(e,t)=>e?e.startsWith(`image/`)?t?(0,l.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${t})`}}):(0,l.jsx)(n.V,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,l.jsx)(n.l,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,l.jsx)(n.G,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,l.jsx)(n._t,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,l.jsx)(n.Q,{className:`w-4 h-4`}):(0,l.jsx)(n.W,{className:`w-4 h-4`}):(0,l.jsx)(n.G,{className:`w-4 h-4`}),ge=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-purple-500/10 text-purple-500`:e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?`bg-blue-500/10 text-blue-500`:e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?`bg-yellow-500/10 text-yellow-500`:e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?`bg-emerald-500/10 text-emerald-500`:`bg-foreground/5 text-foreground/40`:`bg-foreground/5 text-foreground/40`,_e=e=>{if(!e)return`FILE`;let t={"application/pdf":`PDF`,"application/zip":`ZIP`,"application/x-zip-compressed":`ZIP`,"application/x-rar-compressed":`RAR`,"application/x-7z-compressed":`7Z`,"application/json":`JSON`,"application/xml":`XML`,"application/javascript":`JS`,"application/typescript":`TS`,"application/msword":`DOC`,"application/vnd.openxmlformats-officedocument.wordprocessingml.document":`DOCX`,"application/vnd.ms-excel":`XLS`,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":`XLSX`,"application/vnd.ms-powerpoint":`PPT`,"application/vnd.openxmlformats-officedocument.presentationml.presentation":`PPTX`,"application/rtf":`RTF`,"application/x-tar":`TAR`,"application/gzip":`GZ`,"text/plain":`TXT`,"text/html":`HTML`,"text/css":`CSS`,"text/csv":`CSV`,"text/markdown":`MD`},n=e.toLowerCase();if(t[n])return t[n];let r=n.split(`/`);return r[r.length-1].replace(/^x-/,``).replace(/^vnd\..*\./,``).toUpperCase().slice(0,10)},ve=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},Q=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},ye=ue(e,K),be=()=>{navigator.clipboard.writeText(ye),w(!0),setTimeout(()=>w(!1),2e3)},xe=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),r=t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return n.o[r]?n.o[r]:n.o[t]?n.o[t]:n.f||n.C})(),Se=e.buttonStyle!==`secondary`,Ce=e.buttonStorageStyle===`primary`;return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Private Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${s.length} ${s.length===1?`item`:`items`}`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:be,title:C?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${C?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:C?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),e.storage!==!1&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`input`,{type:`file`,ref:W,onChange:ie,className:`hidden`}),(0,l.jsxs)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${Ce?`btn-primary`:`btn-secondary`}`,children:[T?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(xe,{className:`w-4 h-4`}),e.buttonStorageText&&(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>g(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${Se?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,l.jsx)(n.C,{className:`w-4 h-4`}):(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),t?(0,l.jsx)(t,{config:e}):(0,l.jsxs)(l.Fragment,{children:[!f&&s.length===0&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,l.jsx)(n.C,{className:`w-6 h-6 text-accent/40`})}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files to get started`})]}),!f&&s.length>0&&(0,l.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,l.jsx)(n.a,{children:s.map((e,t)=>{let r=L===e.id;return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},transition:{delay:t*.03,duration:.25},onClick:()=>X(e),className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative cursor-pointer ${r?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,l.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),de(e.id),setTimeout(()=>de(null),2e3)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-emerald-500 hover:bg-emerald-500/10 transition-all cursor-pointer`,title:`Copy Link`,children:le===e.id?(0,l.jsx)(n.ct,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-3.5 h-3.5`})})]}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),X(e)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,l.jsx)(n.w,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),O(e.id)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-3.5 h-3.5`})})]}),(0,l.jsxs)(`div`,{className:`flex items-start gap-3 mb-3`,children:[(0,l.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&j(e)},className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`cursor-pointer hover:scale-105 transition-transform ${ge(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?he(e.fileType,e.downloadURL):(0,l.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[J===e.id?(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,value:ae,onChange:e=>oe(e.target.value),onBlur:()=>pe(),onKeyDown:e=>{e.key===`Enter`&&pe(),e.key===`Escape`&&Y(null)},onClick:e=>e.stopPropagation(),className:`no-glow text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full pr-12`}):(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>j(e)}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:Q(e.createdAt)})]})]}),e.note&&(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),Object.entries(e).filter(([e])=>![`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`].includes(e)&&e!==`id`).slice(0,3).map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,l.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e))]},e.id)})})})]})]}),(0,l.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,l.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,l.jsx)(n.B,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,l.jsxs)(`span`,{children:[`Each user sees their own data only · Edit and delete available on all items · Records: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:K}),` · Files: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`user_files`}),` → Drive / Private`]})]})})]})]}),(0,l.jsx)(n.a,{children:h&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!x&&g(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`form`,{onSubmit:re,className:`p-5 flex flex-col gap-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>!x&&g(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:_,onChange:e=>v(e.target.value),placeholder:`Name *`,disabled:x,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),placeholder:`Note (optional)`,disabled:x,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:x,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:x?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,d.createPortal)((0,l.jsx)(n.a,{children:M&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,l.jsx)(n.i.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(`button`,{onClick:()=>j(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-[var(--panel-border)]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 bg-background/80 backdrop-blur-md border-b border-[var(--panel-border)] shrink-0 shadow-sm z-20`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:M.fileName||M.name}),(0,l.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[_e(M.fileType),` • `,ve(M.fileSize||0)]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.downloadURL),de(`preview`),setTimeout(()=>de(null),2e3)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 transition-colors rounded-xl shadow-sm hover:text-emerald-500 cursor-pointer`,title:`Copy Link`,children:le===`preview`?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),Y(M.id),oe(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),O(M.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),(0,l.jsx)(`a`,{href:M.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>j(null),children:(0,l.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[N&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-background/80 backdrop-blur-md shadow-xl flex items-center justify-center border border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,l.jsx)(`img`,{onLoad:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,alt:M.fileName||M.name,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full object-contain drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] rounded-lg pointer-events-auto transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType?.startsWith(`video/`)?(0,l.jsx)(`video`,{onLoadedData:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,controls:!0,autoPlay:!0,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full outline-none bg-black/40 rounded-lg pointer-events-auto drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType===`application/pdf`?(0,l.jsx)(`iframe`,{onLoad:()=>P(!1),src:M.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,l.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center text-foreground/40 text-center relative z-10`,onClick:e=>{e.stopPropagation(),P(!1)},children:[(0,l.jsx)(n.G,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,l.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,l.jsx)(`span`,{className:`text-[14px] mt-2 text-foreground/60 font-medium max-w-xs`,children:`This file format cannot be previewed. Please download it instead.`})]})]})})]})]})}),document.body),(0,l.jsx)(n.a,{children:L&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>me(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[440px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),x&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>me(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NAME`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>B(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>Z(),placeholder:`Name *`,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NOTE`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{ne(e.target.value),e.target.style.height=`auto`,e.target.style.height=e.target.scrollHeight+`px`},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),e.target.blur())},onBlur:()=>Z(),placeholder:`Add a note...`,rows:1,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50 resize-none overflow-hidden`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),H.map((e,t)=>(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let n=[...H];n[t].key=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>Z(),className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none placeholder:text-foreground/15 pt-3 pb-0.5 caret-foreground/40`}),(0,l.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let n=[...H];n[t].value=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>Z(),className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pt-1.5 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>U(H.filter((e,n)=>n!==t)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})})]},t)),(0,l.jsxs)(`button`,{type:`button`,onClick:()=>U([...H,{key:``,value:``}]),className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground/25 hover:text-foreground/40 transition-colors cursor-pointer mt-4 mb-4`,children:[(0,l.jsx)(n.C,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,l.jsx)(te,{isOpen:!!D,onCancel:()=>O(null),onConfirm:q,title:`Delete Record`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:s.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:F})]})}function on({config:e,customContent:t}){let{user:r}=m(),{config:i}=n.xt(),[s,u]=(0,a.useState)([]),[f,p]=(0,a.useState)(!0),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(``),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(!1),[T,E]=(0,a.useState)(!1),[D,O]=(0,a.useState)(null),[k,A]=(0,a.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;P(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[N,P]=(0,a.useState)(!0),[F,I]=(0,a.useState)(!1),[L,R]=(0,a.useState)(null),[z,B]=(0,a.useState)(``),[V,ne]=(0,a.useState)(``),[H,U]=(0,a.useState)([]),W=(0,a.useRef)(null),[G,K]=(0,a.useState)(null),re=(0,a.useRef)([]),ie=(e.tabName||e.pageId||`admin_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),q=`admin_${ie}_records`;(0,a.useEffect)(()=>{document.title=e.tabTitle||e.tabName||i.appName||`Firebase OS`},[e.tabTitle,e.tabName,i.appName]);let J=()=>({name:r.displayName||r.email?.split(`@`)[0]||`Admin`,email:r.email||``,avatar:r.photoURL||``});(0,a.useEffect)(()=>{if(!r)return;try{let e=localStorage.getItem(`fbos_records_${q}`);e?(u(JSON.parse(e)),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}}),t=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,q),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(150)),t=>{let n=e(t.docs);u(n),p(!1),localStorage.setItem(`fbos_records_${q}`,JSON.stringify(n))},t=>{console.error(`Error listening to admin records:`,t);let r=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,q),(0,o.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),u(n),p(!1),localStorage.setItem(`fbos_records_${q}`,JSON.stringify(n))});return()=>r()});return()=>t()},[r,q]);let Y=async e=>{if(e.preventDefault(),!(!r||!_.trim())){S(!0);try{let e=J();await(0,o.addDoc)((0,o.collection)(n.Tt,q),{name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()}),v(``),b(``),g(!1)}catch(e){console.error(`Error saving admin record:`,e)}S(!1)}},ae=async e=>{let t=e.target.files?.[0];if(!(!t||!r)){E(!0);try{let e=(0,c.ref)(n.Dt,`admin_files/${`${Date.now()}_${t.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,c.uploadBytes)(e,t,{customMetadata:{ownerId:r.uid}});let i=await(0,c.getDownloadURL)(e),a=J();await(0,o.addDoc)((0,o.collection)(n.Tt,`admin_files`),{fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,uid:r.uid,uploaderEmail:r.email||`admin`,sourceTab:ie,accessPrefix:`admin_`,creatorName:a.name,creatorEmail:a.email,creatorAvatar:a.avatar,createdAt:(0,o.serverTimestamp)()}),await(0,o.addDoc)((0,o.collection)(n.Tt,q),{name:t.name,note:`${t.type||`File`} · ${Q(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,creatorName:a.name,creatorEmail:a.email,creatorAvatar:a.avatar,createdAt:(0,o.serverTimestamp)()})}catch(e){console.error(`Error uploading admin file:`,e)}E(!1),W.current&&(W.current.value=``)}},oe=async()=>{if(D){I(!0);try{let e=s.find(e=>e.id===D);if(await(0,o.deleteDoc)((0,o.doc)(n.Tt,q,D)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`admin_files%2F`)[1]?.split(`?`)[0];t&&await(0,c.deleteObject)((0,c.ref)(n.Dt,`admin_files/${decodeURIComponent(t)}`)).catch(()=>{});let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`admin_files`),(0,o.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of r.docs)await(0,o.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up admin file:`,e)}O(null)}catch(e){console.error(`Error deleting admin record:`,e)}I(!1)}},[se,ce]=(0,a.useState)(null),[ue,de]=(0,a.useState)(``),[fe,X]=(0,a.useState)(!1),pe=e=>{if(e.recordType===`file`){ce(e.id),de(e.name);return}R(e.id),B(e.name),ne(e.note||``);let t=[`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`],n=Object.entries(e).filter(([e])=>!t.includes(e)&&e!==`id`).map(([e,t])=>({key:e,value:String(t??``)}));U(n),re.current=n.map(e=>e.key)},me=async()=>{if(!se||!ue.trim()){ce(null);return}let e=s.find(e=>e.id===se);if(e&&e.name===ue.trim()){ce(null);return}X(!0);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,se),{name:ue.trim()}),u(e=>e.map(e=>e.id===se?{...e,name:ue.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}X(!1),ce(null)},Z=async()=>{if(!L||!z.trim()){R(null);return}S(!0);let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=re.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,L),{name:z.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==L)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),re.current=t}catch(e){console.error(`Error updating record:`,e)}S(!1),R(null)},he=async()=>{if(!L||!z.trim())return;let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=re.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,L),{name:z.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==L)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),re.current=t}catch(e){console.error(`Error silently saving record:`,e)}},ge=(e,t)=>e?e.startsWith(`image/`)?t?(0,l.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${t})`}}):(0,l.jsx)(n.V,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,l.jsx)(n.l,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,l.jsx)(n.G,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,l.jsx)(n._t,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,l.jsx)(n.Q,{className:`w-4 h-4`}):(0,l.jsx)(n.W,{className:`w-4 h-4`}):(0,l.jsx)(n.G,{className:`w-4 h-4`}),_e=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-purple-500/10 text-purple-500`:e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?`bg-blue-500/10 text-blue-500`:e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?`bg-yellow-500/10 text-yellow-500`:e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?`bg-emerald-500/10 text-emerald-500`:`bg-foreground/5 text-foreground/40`:`bg-foreground/5 text-foreground/40`,ve=e=>{if(!e)return`FILE`;let t={"application/pdf":`PDF`,"application/zip":`ZIP`,"application/x-zip-compressed":`ZIP`,"application/x-rar-compressed":`RAR`,"application/x-7z-compressed":`7Z`,"application/json":`JSON`,"application/xml":`XML`,"application/javascript":`JS`,"application/typescript":`TS`,"application/msword":`DOC`,"application/vnd.openxmlformats-officedocument.wordprocessingml.document":`DOCX`,"application/vnd.ms-excel":`XLS`,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":`XLSX`,"application/vnd.ms-powerpoint":`PPT`,"application/vnd.openxmlformats-officedocument.presentationml.presentation":`PPTX`,"application/rtf":`RTF`,"application/x-tar":`TAR`,"application/gzip":`GZ`,"text/plain":`TXT`,"text/html":`HTML`,"text/css":`CSS`,"text/csv":`CSV`,"text/markdown":`MD`},n=e.toLowerCase();if(t[n])return t[n];let r=n.split(`/`);return r[r.length-1].replace(/^x-/,``).replace(/^vnd\..*\./,``).toUpperCase().slice(0,10)},Q=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},ye=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},be=le(e,q),xe=()=>{navigator.clipboard.writeText(be),w(!0),setTimeout(()=>w(!1),2e3)},Se=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),r=t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return n.o[r]?n.o[r]:n.o[t]?n.o[t]:n.f||n.C})(),Ce=e.buttonStyle!==`secondary`,we=e.buttonStorageStyle===`primary`,Te=e=>e.uid===r?.uid,Ee=({record:e})=>{let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||`Admin`,n=e.creatorEmail||``,r=e.creatorAvatar||``,i=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,l.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/15 text-accent flex items-center justify-center text-[8px] font-extrabold shrink-0`,children:i}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,l.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Admin Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${s.length} ${s.length===1?`item`:`items`}`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:xe,title:C?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${C?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:C?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),e.storage!==!1&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`input`,{type:`file`,ref:W,onChange:ae,className:`hidden`}),(0,l.jsxs)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${we?`btn-primary`:`btn-secondary`}`,children:[T?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(Se,{className:`w-4 h-4`}),e.buttonStorageText&&(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>g(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${Ce?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,l.jsx)(n.C,{className:`w-4 h-4`}):(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),t?(0,l.jsx)(t,{config:e}):(0,l.jsxs)(l.Fragment,{children:[!f&&s.length===0&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,l.jsx)(n.C,{className:`w-6 h-6 text-accent/40`})}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All admins can view and contribute.`})]}),!f&&s.length>0&&(0,l.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,l.jsx)(n.a,{children:s.map((e,t)=>{let r=L===e.id,i=Te(e);return(0,l.jsxs)(n.i.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>pe(e),className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative cursor-pointer ${r?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,l.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),K(e.id),setTimeout(()=>K(null),2e3)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-emerald-500 hover:bg-emerald-500/10 transition-all cursor-pointer`,title:`Copy Link`,children:G===e.id?(0,l.jsx)(n.ct,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-3.5 h-3.5`})})]}),i&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),pe(e)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,l.jsx)(n.w,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),O(e.id)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-3.5 h-3.5`})})]})]}),(0,l.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,l.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&j(e)},className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`cursor-pointer hover:scale-105 transition-transform ${_e(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?ge(e.fileType,e.downloadURL):(0,l.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[se===e.id?(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,value:ue,onChange:e=>de(e.target.value),onBlur:()=>me(),onKeyDown:e=>{e.key===`Enter`&&me(),e.key===`Escape`&&ce(null)},onClick:e=>e.stopPropagation(),className:`no-glow text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full pr-12`}):(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>j(e)}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ye(e.createdAt)})]})]}),e.note&&(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),Object.entries(e).filter(([e])=>![`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`].includes(e)&&e!==`id`).slice(0,3).map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,l.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,l.jsx)(Ee,{record:e})]},e.id)})})})]})]}),(0,l.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,l.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,l.jsx)(n.B,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,l.jsxs)(`span`,{children:[`Shared between all admins · Edit and delete available on your own items only · Records: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:q}),` · Files: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`admin_files`}),` → Drive / Admin`]})]})})]})]}),(0,l.jsx)(n.a,{children:h&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!x&&g(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`form`,{onSubmit:Y,className:`p-5 flex flex-col gap-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>!x&&g(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:_,onChange:e=>v(e.target.value),placeholder:`Name *`,disabled:x,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),placeholder:`Note (optional)`,disabled:x,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:x,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:x?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,d.createPortal)((0,l.jsx)(n.a,{children:M&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,l.jsx)(n.i.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(`button`,{onClick:()=>j(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-[var(--panel-border)]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 bg-background/80 backdrop-blur-md border-b border-[var(--panel-border)] shrink-0 shadow-sm z-20`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:M.fileName||M.name}),(0,l.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[ve(M.fileType),` • `,Q(M.fileSize||0)]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.downloadURL),K(`preview`),setTimeout(()=>K(null),2e3)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 transition-colors rounded-xl shadow-sm hover:text-emerald-500 cursor-pointer`,title:`Copy Link`,children:G===`preview`?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),ce(M.id),de(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),O(M.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),(0,l.jsx)(`a`,{href:M.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>j(null),children:(0,l.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[N&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-background/80 backdrop-blur-md shadow-xl flex items-center justify-center border border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,l.jsx)(`img`,{onLoad:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,alt:M.fileName||M.name,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full object-contain drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] rounded-lg pointer-events-auto transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType?.startsWith(`video/`)?(0,l.jsx)(`video`,{onLoadedData:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,controls:!0,autoPlay:!0,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full outline-none bg-black/40 rounded-lg pointer-events-auto drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType===`application/pdf`?(0,l.jsx)(`iframe`,{onLoad:()=>P(!1),src:M.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,l.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center text-foreground/40 text-center relative z-10`,onClick:e=>{e.stopPropagation(),P(!1)},children:[(0,l.jsx)(n.G,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,l.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,l.jsx)(`span`,{className:`text-[14px] mt-2 text-foreground/60 font-medium max-w-xs`,children:`This file format cannot be previewed. Please download it instead.`})]})]})})]})]})}),document.body),(0,l.jsx)(n.a,{children:L&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>Z(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[440px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),x&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>Z(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NAME`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>B(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),placeholder:`Name *`,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NOTE`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{ne(e.target.value),e.target.style.height=`auto`,e.target.style.height=e.target.scrollHeight+`px`},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),e.target.blur())},onBlur:()=>he(),placeholder:`Add a note...`,rows:1,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50 resize-none overflow-hidden`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),H.map((e,t)=>(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let n=[...H];n[t].key=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none placeholder:text-foreground/15 pt-3 pb-0.5 caret-foreground/40`}),(0,l.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let n=[...H];n[t].value=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pt-1.5 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>U(H.filter((e,n)=>n!==t)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})})]},t)),(0,l.jsxs)(`button`,{type:`button`,onClick:()=>U([...H,{key:``,value:``}]),className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground/25 hover:text-foreground/40 transition-colors cursor-pointer mt-4 mb-4`,children:[(0,l.jsx)(n.C,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,l.jsx)(te,{isOpen:!!D,onCancel:()=>O(null),onConfirm:oe,title:`Delete Record`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:s.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:F})]})}function sn({config:e,customContent:t}){let{user:r}=m(),{config:i}=n.xt(),[s,u]=(0,a.useState)([]),[f,p]=(0,a.useState)(!0),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(``),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(!1),[T,E]=(0,a.useState)(!1),[D,O]=(0,a.useState)(null),[k,A]=(0,a.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;P(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[N,P]=(0,a.useState)(!0),[F,I]=(0,a.useState)(!1),[L,R]=(0,a.useState)(null),[z,B]=(0,a.useState)(``),[V,ne]=(0,a.useState)(``),[H,U]=(0,a.useState)([]),W=(0,a.useRef)(null),[G,K]=(0,a.useState)(null),re=(0,a.useRef)([]),ie=(e.tabName||e.pageId||`shared_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),q=`mem_${ie}_records`;(0,a.useEffect)(()=>{document.title=e.tabTitle||e.tabName||i.appName||`Firebase OS`},[e.tabTitle,e.tabName,i.appName]),(0,a.useEffect)(()=>{if(!r)return;try{let e=localStorage.getItem(`fbos_records_${q}`);e?(u(JSON.parse(e)),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}}),t=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,q),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(150)),t=>{let n=e(t.docs);u(n),p(!1),localStorage.setItem(`fbos_records_${q}`,JSON.stringify(n))},t=>{console.error(`Error listening to shared records:`,t);let r=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,q),(0,o.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),u(n),p(!1),localStorage.setItem(`fbos_records_${q}`,JSON.stringify(n))});return()=>r()});return()=>t()},[r,q]);let J=()=>({name:r.displayName||r.email?.split(`@`)[0]||`Member`,email:r.email||``,avatar:r.photoURL||``}),Y=async e=>{if(e.preventDefault(),!(!r||!_.trim())){S(!0);try{let e=J();await(0,o.addDoc)((0,o.collection)(n.Tt,q),{name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()}),v(``),b(``),g(!1)}catch(e){console.error(`Error saving shared record:`,e)}S(!1)}},ae=async e=>{let t=e.target.files?.[0];if(!(!t||!r)){E(!0);try{let e=(0,c.ref)(n.Dt,`mem_files/${`${Date.now()}_${t.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,c.uploadBytes)(e,t,{customMetadata:{ownerId:r.uid}});let i=await(0,c.getDownloadURL)(e),a=J();await(0,o.addDoc)((0,o.collection)(n.Tt,`mem_files`),{fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,uid:r.uid,uploaderEmail:r.email||`member`,sourceTab:ie,accessPrefix:`mem_`,creatorName:a.name,creatorEmail:a.email,creatorAvatar:a.avatar,createdAt:(0,o.serverTimestamp)()}),await(0,o.addDoc)((0,o.collection)(n.Tt,q),{name:t.name,note:`${t.type||`File`} · ${Q(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,creatorName:a.name,creatorEmail:a.email,creatorAvatar:a.avatar,createdAt:(0,o.serverTimestamp)()})}catch(e){console.error(`Error uploading shared file:`,e)}E(!1),W.current&&(W.current.value=``)}},oe=async()=>{if(D){I(!0);try{let e=s.find(e=>e.id===D);if(await(0,o.deleteDoc)((0,o.doc)(n.Tt,q,D)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`mem_files%2F`)[1]?.split(`?`)[0];t&&await(0,c.deleteObject)((0,c.ref)(n.Dt,`mem_files/${decodeURIComponent(t)}`)).catch(()=>{});let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`mem_files`),(0,o.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of r.docs)await(0,o.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up shared file:`,e)}O(null)}catch(e){console.error(`Error deleting shared record:`,e)}I(!1)}},[se,le]=(0,a.useState)(null),[ue,de]=(0,a.useState)(``),[fe,X]=(0,a.useState)(!1),pe=e=>{if(e.recordType===`file`){le(e.id),de(e.name);return}R(e.id),B(e.name),ne(e.note||``);let t=[`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`],n=Object.entries(e).filter(([e])=>!t.includes(e)&&e!==`id`).map(([e,t])=>({key:e,value:String(t??``)}));U(n),re.current=n.map(e=>e.key)},me=async()=>{if(!se||!ue.trim()){le(null);return}let e=s.find(e=>e.id===se);if(e&&e.name===ue.trim()){le(null);return}X(!0);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,se),{name:ue.trim()}),u(e=>e.map(e=>e.id===se?{...e,name:ue.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}X(!1),le(null)},Z=async()=>{await he(),R(null)},he=async()=>{if(!L||!z.trim())return;S(!0);let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=re.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,L),{name:z.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==L)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),re.current=t}catch(e){console.error(`Error saving record:`,e)}S(!1)},ge=(e,t)=>e?e.startsWith(`image/`)?t?(0,l.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${t})`}}):(0,l.jsx)(n.V,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,l.jsx)(n.l,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,l.jsx)(n.G,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,l.jsx)(n._t,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,l.jsx)(n.Q,{className:`w-4 h-4`}):(0,l.jsx)(n.W,{className:`w-4 h-4`}):(0,l.jsx)(n.G,{className:`w-4 h-4`}),_e=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-purple-500/10 text-purple-500`:e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?`bg-blue-500/10 text-blue-500`:e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?`bg-yellow-500/10 text-yellow-500`:e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?`bg-emerald-500/10 text-emerald-500`:`bg-foreground/5 text-foreground/40`:`bg-foreground/5 text-foreground/40`,ve=e=>{if(!e)return`FILE`;let t={"application/pdf":`PDF`,"application/zip":`ZIP`,"application/x-zip-compressed":`ZIP`,"application/x-rar-compressed":`RAR`,"application/x-7z-compressed":`7Z`,"application/json":`JSON`,"application/xml":`XML`,"application/javascript":`JS`,"application/typescript":`TS`,"application/msword":`DOC`,"application/vnd.openxmlformats-officedocument.wordprocessingml.document":`DOCX`,"application/vnd.ms-excel":`XLS`,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":`XLSX`,"application/vnd.ms-powerpoint":`PPT`,"application/vnd.openxmlformats-officedocument.presentationml.presentation":`PPTX`,"application/rtf":`RTF`,"application/x-tar":`TAR`,"application/gzip":`GZ`,"text/plain":`TXT`,"text/html":`HTML`,"text/css":`CSS`,"text/csv":`CSV`,"text/markdown":`MD`},n=e.toLowerCase();if(t[n])return t[n];let r=n.split(`/`);return r[r.length-1].replace(/^x-/,``).replace(/^vnd\..*\./,``).toUpperCase().slice(0,10)},Q=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},ye=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},be=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),r=t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return n.o[r]?n.o[r]:n.o[t]?n.o[t]:n.f||n.C})(),xe=e.buttonStyle!==`secondary`,Se=e.buttonStorageStyle===`primary`,Ce=e=>e.uid===r?.uid,we=ce(e,q),Te=()=>{navigator.clipboard.writeText(we),w(!0),setTimeout(()=>w(!1),2e3)},Ee=({record:e})=>{let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||`Member`,n=e.creatorEmail||``,r=e.creatorAvatar||``,i=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,l.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/15 text-accent flex items-center justify-center text-[8px] font-extrabold shrink-0`,children:i}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,l.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Shared Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${s.length} ${s.length===1?`item`:`items`} · Shared`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:Te,title:C?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${C?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:C?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),e.storage!==!1&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`input`,{type:`file`,ref:W,onChange:ae,className:`hidden`}),(0,l.jsxs)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${Se?`btn-primary`:`btn-secondary`}`,children:[T?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(be,{className:`w-4 h-4`}),e.buttonStorageText&&(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>g(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${xe?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,l.jsx)(n.C,{className:`w-4 h-4`}):(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),t?(0,l.jsx)(t,{config:e}):(0,l.jsxs)(l.Fragment,{children:[!f&&s.length===0&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,l.jsx)(n.C,{className:`w-6 h-6 text-accent/40`})}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All team members can view and contribute.`})]}),!f&&s.length>0&&(0,l.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,l.jsx)(n.a,{children:s.map(e=>{let t=L===e.id,r=Ce(e);return(0,l.jsxs)(n.i.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>r?pe(e):null,className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative ${r?`cursor-pointer`:``} ${t?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,l.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),K(e.id),setTimeout(()=>K(null),2e3)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-emerald-500 hover:bg-emerald-500/10 transition-all cursor-pointer`,title:`Copy Link`,children:G===e.id?(0,l.jsx)(n.ct,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-3.5 h-3.5`})})]}),r&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),pe(e)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,l.jsx)(n.w,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),O(e.id)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-3.5 h-3.5`})})]})]}),(0,l.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,l.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&j(e)},className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`cursor-pointer hover:scale-105 transition-transform ${_e(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?ge(e.fileType,e.downloadURL):(0,l.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[se===e.id?(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,value:ue,onChange:e=>de(e.target.value),onBlur:()=>me(),onKeyDown:e=>{e.key===`Enter`&&me(),e.key===`Escape`&&le(null)},onClick:e=>e.stopPropagation(),className:`no-glow text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full pr-12`}):(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>j(e)}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ye(e.createdAt)})]})]}),e.note&&(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),Object.entries(e).filter(([e])=>![`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`].includes(e)&&e!==`id`).slice(0,3).map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,l.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,l.jsx)(Ee,{record:e})]},e.id)})})})]})]}),(0,l.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,l.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,l.jsx)(n.B,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,l.jsxs)(`span`,{children:[`Shared between all members · Edit and delete available on your own items only · Records: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:q}),` · Files: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`mem_files`}),` → Drive / Shared`]})]})})]})]}),(0,l.jsx)(n.a,{children:h&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!x&&g(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`form`,{onSubmit:Y,className:`p-5 flex flex-col gap-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>!x&&g(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:_,onChange:e=>v(e.target.value),placeholder:`Name *`,disabled:x,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),placeholder:`Note (optional)`,disabled:x,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:x,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:x?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,d.createPortal)((0,l.jsx)(n.a,{children:M&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,l.jsx)(n.i.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(`button`,{onClick:()=>j(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-[var(--panel-border)]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 bg-background/80 backdrop-blur-md border-b border-[var(--panel-border)] shrink-0 shadow-sm z-20`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:M.fileName||M.name}),(0,l.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[ve(M.fileType),` • `,Q(M.fileSize||0)]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.downloadURL),K(`preview`),setTimeout(()=>K(null),2e3)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 transition-colors rounded-xl shadow-sm hover:text-emerald-500 cursor-pointer`,title:`Copy Link`,children:G===`preview`?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),le(M.id),de(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),O(M.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),(0,l.jsx)(`a`,{href:M.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>j(null),children:(0,l.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[N&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-background/80 backdrop-blur-md shadow-xl flex items-center justify-center border border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,l.jsx)(`img`,{onLoad:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,alt:M.fileName||M.name,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full object-contain drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] rounded-lg pointer-events-auto transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType?.startsWith(`video/`)?(0,l.jsx)(`video`,{onLoadedData:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,controls:!0,autoPlay:!0,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full outline-none bg-black/40 rounded-lg pointer-events-auto drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType===`application/pdf`?(0,l.jsx)(`iframe`,{onLoad:()=>P(!1),src:M.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,l.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center text-foreground/40 text-center relative z-10`,onClick:e=>{e.stopPropagation(),P(!1)},children:[(0,l.jsx)(n.G,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,l.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,l.jsx)(`span`,{className:`text-[14px] mt-2 text-foreground/60 font-medium max-w-xs`,children:`This file format cannot be previewed. Please download it instead.`})]})]})})]})]})}),document.body),(0,l.jsx)(n.a,{children:L&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>Z(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[440px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),x&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>Z(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NAME`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>B(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),placeholder:`Name *`,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NOTE`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{ne(e.target.value),e.target.style.height=`auto`,e.target.style.height=e.target.scrollHeight+`px`},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),e.target.blur())},onBlur:()=>he(),placeholder:`Add a note...`,rows:1,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50 resize-none overflow-hidden`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),H.map((e,t)=>(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let n=[...H];n[t].key=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none placeholder:text-foreground/15 pt-3 pb-0.5 caret-foreground/40`}),(0,l.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let n=[...H];n[t].value=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pt-1.5 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>U(H.filter((e,n)=>n!==t)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})})]},t)),(0,l.jsxs)(`button`,{type:`button`,onClick:()=>U([...H,{key:``,value:``}]),className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground/25 hover:text-foreground/40 transition-colors cursor-pointer mt-4 mb-4`,children:[(0,l.jsx)(n.C,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,l.jsx)(te,{isOpen:!!D,onCancel:()=>O(null),onConfirm:oe,title:`Delete Record`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:s.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:F})]})}function cn(){let e=(0,u.useLocation)(),{user:t}=m(),r=n.Ct(),[i,s]=(0,a.useState)(null),[c,d]=(0,a.useState)(!0);(0,a.useEffect)(()=>{let t=!0,r=localStorage.getItem(`fbos_route_${e.pathname}`);if(r)try{let e=JSON.parse(r);s(e),d(!1);let t=e.pageName||e.tabName||e.title;t&&(document.title=t)}catch{}return(async()=>{try{let r=e.pathname;r.startsWith(`/`)&&(r=r.substring(1));let[i,a,c,l,u,f]=await Promise.allSettled([(0,o.getDoc)((0,o.doc)(n.Tt,`sys_pages`,r)),(0,o.getDoc)((0,o.doc)(n.Tt,`sys_tabs`,r)),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_pages`),(0,o.where)(`route`,`==`,e.pathname),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_pages`),(0,o.where)(`route`,`==`,r),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_tabs`),(0,o.where)(`route`,`==`,e.pathname),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_tabs`),(0,o.where)(`route`,`==`,r),(0,o.limit)(1)))]),p=null,m=null,h=(e,t)=>{if(!p&&e.status===`fulfilled`){if(e.value.exists&&e.value.exists()){let n=e.value.data();p={...n,isPrivate:t,isAdmin:n.pageType===`admin`,isShared:n.pageType===`shared`},m=e.value.id}else if(e.value.docs&&e.value.docs.length>0){let n=e.value.docs[0].data();p={...n,isPrivate:t,isAdmin:n.pageType===`admin`,isShared:n.pageType===`shared`},m=e.value.docs[0].id}}};if(h(i,!1),h(c,!1),h(l,!1),h(a,!0),h(u,!0),h(f,!0),p||(e.pathname===`/contact`?(p={route:`/contact`,template:`popup_form`,form:`contact`},m=`contact`):e.pathname===`/support`&&(p={route:`/support`,template:`popup_form`,form:`support`},m=`support`)),!t)return;if(p){if((m===`contact`||m===`support`)&&!p.form&&(p.form=m),p.pageId=m,localStorage.setItem(`fbos_route_${e.pathname}`,JSON.stringify(p)),p.form){try{let e=localStorage.getItem(`fbos_form_${p.form}`);e&&(p.formConfigOverride=JSON.parse(e))}catch{}(0,o.getDoc)((0,o.doc)(n.Tt,`sys_forms`,p.form)).then(async e=>{if(t)if(e.exists()){let t={...e.data(),id:e.id};s(e=>({...e,formConfigOverride:t})),localStorage.setItem(`fbos_form_${p.form}`,JSON.stringify(t))}else{let e;if(p.form===`contact`){let{contactFormConfig:t}=await Promise.resolve().then(()=>require(`./contactForm.config-CXyq-EbM.cjs`)).then(e=>e.n);e=t}else if(p.form===`support`){let{supportFormConfig:t}=await Promise.resolve().then(()=>require(`./supportForm.config-haLod4rv.cjs`)).then(e=>e.n);e=t}e&&(s(t=>({...t,formConfigOverride:e})),localStorage.setItem(`fbos_form_${p.form}`,JSON.stringify(e)))}})}let r=p.pageName||p.tabName||p.title;r&&(document.title=r),s(p),d(!1)}else s(`not-found`),d(!1),localStorage.removeItem(`fbos_route_${e.pathname}`)}catch{t&&c&&(s(`not-found`),d(!1))}})(),()=>{t=!1}},[e.pathname]);let[f,p]=(0,a.useState)(!1);if((0,a.useEffect)(()=>{let e;return c?e=setTimeout(()=>p(!0),150):p(!1),()=>clearTimeout(e)},[c]),c)return f?t?(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(`div`,{className:`mb-6`,children:[(0,l.jsx)(`div`,{className:`h-10 w-56 rounded-xl bg-foreground/5 animate-pulse mt-1`}),(0,l.jsx)(`div`,{className:`h-3 w-24 rounded bg-foreground/5 animate-pulse mt-3`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsx)(`div`,{className:`flex-1 glass-panel border border-[var(--panel-border)] rounded-3xl flex items-center justify-center min-h-[400px] bg-background shadow-2xl`,children:(0,l.jsx)(n.M,{className:`w-6 h-6 animate-spin text-accent`})})]})]}):(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[60vh] z-10`,children:(0,l.jsx)(n.M,{className:`w-6 h-6 animate-spin text-accent`})}):null;if(i===`not-found`)return(0,l.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1 text-center`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 bg-red-500/10 text-red-500 rounded-full flex items-center justify-center mb-6`,children:(0,l.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-8 h-8`,children:[(0,l.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,l.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,l.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]})}),(0,l.jsx)(`h2`,{className:`text-3xl font-bold mb-3 text-foreground`,children:`Page Not Found`}),(0,l.jsx)(`p`,{className:`text-foreground/60 max-w-md`,children:`The route you are looking for does not exist or has been removed.`})]})});if((i.pageId===`support`||i.isPrivate)&&!t)return(0,l.jsx)(u.Navigate,{to:`/login`,state:{from:e}});let h=r.customRoutes?.[e.pathname]||(i&&i.route?r.customRoutes?.[i.route]:null),g=i.pageName?.toLowerCase().replace(/\s+/g,`_`)||i.pageId||`custom_page`,_=`pub_${g}`,v=(i.tabName||i.pageId||i.pageName||`custom`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),y=(r.microcomponents||(typeof window<`u`?window.__FBOS_MICROCOMPONENTS__:void 0))?.[v],b=h||y||void 0;if(i.template===`none`)return i.isAdmin?(0,l.jsx)(on,{config:i,customContent:b}):i.isShared?(0,l.jsx)(sn,{config:i,customContent:b}):i.isPrivate?(0,l.jsx)(an,{config:i,customContent:b}):(0,l.jsx)(rn,{config:i,customContent:b});if(h)return(0,l.jsx)(h,{config:i});if(i.template===`board`){let e=i.isAdmin?`admin_${i.pageId||g}`:i.isShared?`mem_${i.pageId||g}`:i.isPrivate?`user_${i.pageId||g}`:_;return(0,l.jsx)(r.components?.TemplateBoard||fe,{title:i.tabTitle||i.tabName||i.title||i.pageName||`Board`,subtitle:i.route,tasksCollection:`${e}_tasks`,categoriesCollection:`${e}_categories`,config:i})}if(i.template===`table`){let e=i.isAdmin?`admin_${i.pageId||g}`:i.isShared?`mem_${i.pageId||g}`:i.isPrivate?`user_${i.pageId||g}`:_;return(0,l.jsx)(r.components?.TemplateTable||Rt,{title:i.tabTitle||i.tabName||i.title||i.pageName||`Table`,subtitle:i.route,tableCollection:`${e}_table`,config:i})}if(i.template===`calendar`){let e=i.isAdmin?`admin_${i.pageId||g}`:i.isShared?`mem_${i.pageId||g}`:i.isPrivate?`user_${i.pageId||g}`:_;return(0,l.jsx)(r.components?.TemplateCalendar||Vt,{title:i.tabTitle||i.tabName||i.title||i.pageName||`Calendar`,subtitle:i.route,eventsCollection:`${e}_events`,defaultTimeFormat:i.defaultTimeFormat||i.defaulttimeformat||`12h`,config:i})}return i.template===`inline_form`?(0,l.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-start mt-8 relative z-10 w-full min-h-[60vh]`,children:(0,l.jsx)(n.t,{isInline:!0,formId:i.form,formConfig:i.formConfigOverride})}):(0,l.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 w-full min-h-[60vh]`,children:(0,l.jsx)(n.t,{formId:i.form,formConfig:i.formConfigOverride,onClose:()=>window.history.back()})})}var ln=a.default.createContext({}),un=Object.defineProperty,dn=Object.getOwnPropertySymbols,fn=Object.prototype.hasOwnProperty,pn=Object.prototype.propertyIsEnumerable,mn=(e,t,n)=>t in e?un(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,hn=(e,t)=>{for(var n in t||={})fn.call(t,n)&&mn(e,n,t[n]);if(dn)for(var n of dn(t))pn.call(t,n)&&mn(e,n,t[n]);return e},gn=(0,a.forwardRef)((e,t)=>{let n=hn(hn({},a.useContext(ln)),e);return a.createElement(`svg`,hn({width:`1.5em`,height:`1.5em`,strokeWidth:1.5,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,color:`currentColor`,ref:t},n),a.createElement(`path`,{d:`M21.1679 8C19.6247 4.46819 16.1006 2 11.9999 2C6.81459 2 2.55104 5.94668 2.04932 11`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M17 8H21.4C21.7314 8 22 7.73137 22 7.4V3`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M2.88146 16C4.42458 19.5318 7.94874 22 12.0494 22C17.2347 22 21.4983 18.0533 22 13`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M7.04932 16H2.64932C2.31795 16 2.04932 16.2686 2.04932 16.6V21`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}))}),_n=Object.defineProperty,vn=Object.getOwnPropertySymbols,yn=Object.prototype.hasOwnProperty,bn=Object.prototype.propertyIsEnumerable,xn=(e,t,n)=>t in e?_n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Sn=(e,t)=>{for(var n in t||={})yn.call(t,n)&&xn(e,n,t[n]);if(vn)for(var n of vn(t))bn.call(t,n)&&xn(e,n,t[n]);return e},Cn=(0,a.forwardRef)((e,t)=>{let n=Sn(Sn({},a.useContext(ln)),e);return a.createElement(`svg`,Sn({width:`1.5em`,height:`1.5em`,viewBox:`0 0 24 24`,strokeWidth:1.5,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,color:`currentColor`,ref:t},n),a.createElement(`path`,{d:`M22 12C22 17.5228 17.5228 22 12 22C10.1786 22 8.47087 21.513 7 20.6622L2 21.5L2.83209 16C2.29689 14.7751 2 13.4222 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M12.9604 13.8683L15.0399 13.4624L17 14.2149V16.0385C17 16.6449 16.4783 17.1073 15.8901 16.9783C14.3671 16.6444 11.5997 15.8043 9.67826 13.8683C7.84859 12.0248 7.22267 9.45734 7.01039 8.04128C6.92535 7.47406 7.3737 7 7.94306 7H9.83707L10.572 8.96888L10.1832 11.0701`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}))}),wn=`rules_version = '2';
|
|
415
|
+
};`;navigator.clipboard.writeText(a),m(!0),setTimeout(()=>m(!1),2e3)}};return(0,a.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key===`a`&&document.activeElement===document.body&&e.preventDefault(),(e.ctrlKey||e.metaKey)&&e.key===`c`&&!window.getSelection()?.toString()&&r&&b()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]),(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Theme`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/theme`]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-6 md:p-10 shadow-2xl relative overflow-hidden bg-background flex flex-col min-h-[600px]`,children:[(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Theme Config`}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`Changes here immediately format natively. Save to update your Live Preview panel entirely.`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:_,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-xl flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:u?(0,l.jsx)(n.M,{className:`w-4 h-4 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-4 h-4 text-foreground/60 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(n.n,{variant:`secondary`,onClick:b,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors`,title:`Copy Config (Ctrl+C)`,children:p?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-4 h-4 text-foreground/60 hover:text-foreground transition-colors`})})]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 w-full relative z-10 items-start`,children:[u&&(0,l.jsx)(`div`,{className:`absolute inset-0 bg-background/60 backdrop-blur-[2px] z-50 flex items-center justify-center rounded-3xl pointer-events-none transition-all duration-300`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 animate-spin text-accent`})}),(0,l.jsxs)(`div`,{className:`w-full glass-panel border border-[var(--panel-border)] rounded-3xl p-6 md:p-8 shadow-inner overflow-hidden relative bg-background`,children:[(0,l.jsx)(`h3`,{className:`text-lg font-extrabold text-foreground tracking-tight mb-4 flex items-center gap-3`,children:`Branding & Colours`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-3 overflow-x-auto hide-scrollbars pb-4 pt-2 mb-6 border-b border-[var(--panel-border)]/50 shrink-0`,children:[(0,l.jsx)(`div`,{className:`text-[12px] font-bold text-foreground/40 shrink-0 uppercase tracking-widest pl-1 mr-2`,children:`Presets`}),Ut.map(e=>{let t=r?.colors?.dark?.accent===e.dark.accent&&r?.colors?.dark?.buttonGradient?.[0]===e.dark.gradient[0],n=e.name===`Black & White`;return(0,l.jsx)(`button`,{onClick:()=>y(e),className:`w-9 h-9 rounded-full shrink-0 outline-none transition-all shadow-sm relative group overflow-visible ${t?`ring-[3px] ring-foreground ring-offset-2 ring-offset-[var(--background)] scale-110 z-10`:`opacity-80 hover:opacity-100 hover:ring-2 hover:ring-foreground/30 hover:ring-offset-2 hover:ring-offset-[var(--background)] hover:scale-105`}`,title:e.name,children:(0,l.jsx)(`div`,{className:`absolute inset-0 rounded-full`,style:n?{backgroundColor:`#ffffff`,border:`3px solid #000000`,boxShadow:`inset 0 0 0 1px rgba(0,0,0,0.1)`}:{backgroundImage:`linear-gradient(135deg, ${e.preview[0]}, ${e.preview[1]})`}})},e.name)})]}),(0,l.jsx)(`div`,{className:`w-full relative min-h-[100px]`,children:r?(0,l.jsxs)(`div`,{className:`flex flex-col pl-2`,children:[(0,l.jsxs)(`span`,{className:`text-yellow-500 font-mono text-[13px] mb-2`,children:[`export const themeConfig = `,`{`]}),(0,l.jsx)(Kt,{value:r,keysToRender:[`appName`,`defaultTheme`,`showThemeToggle`,`logoUrl`,`faviconUrl`,`cornerRounding`,`cornerRadii`,`fontFamily`],onChange:e=>i(e),isLast:!1,isGlobalSaving:s}),(0,l.jsx)(`div`,{className:`mt-4`,children:(0,l.jsx)(Kt,{objectKey:`colors`,value:r.colors,onChange:e=>i({...r,colors:e}),isLast:!1,isGlobalSaving:s})})]}):(0,l.jsx)(`div`,{className:`flex items-center justify-center w-full h-full text-foreground/40 font-mono text-[13px] animate-pulse py-10`,children:`Loading Data Tree...`})})]})]})]})]})]})}var Jt={route:`/page_1`,pageName:`New Public Page`,template:`none`,pageTitle:`My Custom Page`,copyPrompt:!0,showButton:!0,buttonText:`Open Form`,action:`form`,form:`contact`},Yt={tabName:`New Private Page`,iconName:``,route:`/new-private-page`,template:`none`,form:`support`,showPrompt:!0,tabTitle:`Private Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},Xt={tabName:`Admin Tab`,iconName:``,route:`/admin-tab`,template:`none`,form:``,showPrompt:!0,tabTitle:`Admin Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},Zt={tabName:`Shared Tab`,iconName:``,route:`/shared-tab`,template:`none`,form:``,showPrompt:!0,tabTitle:`Shared Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},Qt=[{id:`home`,title:`Home Page`,path:`/`,type:`public`,isSystem:!0,enabled:!0}],$t=({enabled:e,onChange:t,disabled:r,className:i=``})=>(0,l.jsx)(`button`,{disabled:r,onClick:()=>t(!e),title:e?`Page Active`:`Page Hidden`,className:`p-1.5 transition-colors rounded-lg flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity ${i} ${e?`text-accent hover:bg-accent/10`:`text-foreground/40 hover:bg-foreground/5`} ${r?`!opacity-50 cursor-not-allowed`:`cursor-pointer`}`,children:e?(0,l.jsx)(n.K,{className:`w-4 h-4`}):(0,l.jsx)(n.q,{className:`w-4 h-4`})});function en(){let{userRole:e}=m(),t=(0,u.useLocation)(),r=n.Ct(),[i,s]=(0,a.useState)(Qt),[c,d]=(0,a.useState)(()=>{try{return sessionStorage.getItem(`fbos_pages_expandedId`)||null}catch{return null}}),f=(0,a.useRef)(c),[p,h]=(0,a.useState)(!1),[g,_]=(0,a.useState)({}),[v,y]=(0,a.useState)({}),[b,x]=(0,a.useState)({}),[C,w]=(0,a.useState)(null),[T,E]=(0,a.useState)(!1),D=(0,a.useRef)(null);(0,a.useEffect)(()=>{function e(e){D.current&&!D.current.contains(e.target)&&h(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let[O,k]=(0,a.useState)(null),[A,j]=(0,a.useState)(!1),[M,N]=(0,a.useState)(!1),[P,F]=(0,a.useState)(new Set),[I,L]=(0,a.useState)(new Set),[R,z]=(0,a.useState)([]),[B,V]=(0,a.useState)([]),ne=e=>(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden});(0,a.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`page_order`),e=>{let t=ne(e.exists()&&e.data().order||[]);z(t),F(new Set(t.filter(e=>e.hidden).map(e=>e.id)))}),t=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`tab_order`),e=>{let t=ne(e.exists()&&e.data().order||[]);V(t),L(new Set(t.filter(e=>e.hidden).map(e=>e.id)))});return()=>{e(),t()}},[]),(0,a.useEffect)(()=>{let e=t.pathname.split(`/pages/`)[1]?.split(`/`)[0];e&&!c&&i.some(t=>t.id===e)&&d(e)},[t.pathname,i]),(0,a.useEffect)(()=>{f.current=c;try{c?sessionStorage.setItem(`fbos_pages_expandedId`,c):sessionStorage.removeItem(`fbos_pages_expandedId`)}catch{}},[c]);let H=(0,a.useRef)(null);(0,a.useEffect)(()=>{let e=H.current;if(!e)return;try{let t=sessionStorage.getItem(`fbos_pages_scrollY`);t&&(e.scrollTop=parseInt(t,10))}catch{}let t=()=>{try{sessionStorage.setItem(`fbos_pages_scrollY`,String(e.scrollTop))}catch{}};return e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[]),(0,a.useEffect)(()=>{let e=(e,t)=>{if(!t)return e;let n=Object.fromEntries(Object.entries(t).filter(([e,t])=>t!=null&&t!==``));return{...e,...n}},t=r?.defaultConfigs?.home||S,i=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_pages`,`home`),n=>{n.exists()?k(e(t,n.data())):k(t)});return()=>{i()}},[r]),(0,a.useEffect)(()=>{(async()=>{try{let[e,t]=await Promise.all([(0,o.getDocs)((0,o.collection)(n.Tt,`sys_pages`)),(0,o.getDocs)((0,o.collection)(n.Tt,`sys_tabs`))]),r=[`home`,`contact`,`support`,`theme`,`page_order`,`tab_order`],i=[],a={};e.forEach(e=>{if(!r.includes(e.id)){let t=e.data();i.push({id:e.id,title:t.pageName||t.title||e.id,path:t.route||`/`+e.id,type:`public`,isSystem:!1,enabled:t.enabled!==!1}),a[e.id]=t}}),t.forEach(e=>{if(!r.includes(e.id)){let t=e.data(),n=t.pageType||`private`;i.push({id:e.id,title:t.tabName||t.title||e.id,path:t.route||`/`+e.id,type:n,isSystem:!1,enabled:t.enabled!==!1}),a[e.id]=t}}),i.length>0&&(s(e=>{let t=e.filter(e=>e.isSystem||e.id.startsWith(`draft_`)),n=i.filter(e=>!t.some(t=>t.id===e.id));return[...t,...n]}),_(e=>({...e,...a})))}catch(e){console.error(`Error loading custom pages`,e)}})()},[]);let[U,W]=(0,a.useState)([`contact`]),[G,K]=(0,a.useState)([`support`]);(0,a.useEffect)(()=>{(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{let t=[],n=[];e.forEach(e=>{e.data().formType===`private`?n.push(e.id):t.push(e.id)}),t.length>0&&W(t),n.length>0&&K(n)}).catch(console.error)},[]);let[re,ie]=(0,a.useState)(null),q=(e,t)=>{let n;n=e===`home`?`export const defaultHomeConfig = ${JSON.stringify(t,null,2)};\n`:JSON.stringify(t,null,2),navigator.clipboard.writeText(n),ie(e),setTimeout(()=>ie(null),2e3)},J=async(e,t)=>{t.route&&!t.route.startsWith(`/`)&&(t.route=`/`+t.route);let r=i.find(t=>t.id===e)?.type,a=r===`public`?`sys_pages`:`sys_tabs`;r&&r!==`public`&&(t.pageType=r);let c=[`home`].includes(e)?e:t.route?t.route.replace(/^\/+/,``).replace(/[^a-zA-Z0-9_\-]/g,`_`).toLowerCase():e;e===`home`?j(!0):y(t=>({...t,[e]:!0,[c]:!0}));try{if(c!==e&&c.trim()!==``&&c!==`draft`){try{let{deleteDoc:t}=await import(`firebase/firestore`);await t((0,o.doc)(n.Tt,a,e))}catch{}await(0,o.setDoc)((0,o.doc)(n.Tt,a,c),t),s(n=>n.map(n=>n.id===e?{...n,id:c,_uiKey:n._uiKey||e,path:t.route,title:t.pageName||t.tabName||t.title||n.title}:n)),f.current===e&&(d(c),window.history.replaceState(null,``,`/pages/${c}`)),_(n=>{let r={...n};return r[c]=t,delete r[e],r});let i=r===`public`,l=i?`page_order`:`tab_order`,u=i?R:B;if(!u.some(e=>e.id===c)){let t=[{id:c,hidden:!1},...u.filter(t=>t.id!==e)];try{await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,l),{order:t})}catch(e){console.error(`Failed to update tab order:`,e)}}}else await(0,o.setDoc)((0,o.doc)(n.Tt,a,e),t),e===`home`?k(t):(_(n=>({...n,[e]:t})),s(n=>n.map(n=>n.id===e?{...n,path:t.route||n.path,title:t.pageName||t.tabName||t.title||n.title}:n)))}catch(t){console.error(`Failed to save ${e} config:`,t)}finally{setTimeout(()=>{e===`home`?j(!1):y(t=>({...t,[e]:!1,[c]:!1}))},500)}},Y=async e=>{e.stopPropagation(),N(!0);try{let{deleteDoc:e}=await import(`firebase/firestore`);await e((0,o.doc)(n.Tt,`sys_pages`,`home`)),localStorage.removeItem(`fbos_home_config`),k(r?.defaultConfigs?.home||S)}catch(e){console.error(`Failed to reset home config:`,e)}setTimeout(()=>N(!1),500)},ae=async(e,t,n)=>{e.stopPropagation(),x(e=>({...e,[t]:!0})),await J(t,n),setTimeout(()=>x(e=>({...e,[t]:!1})),500)},oe=e=>{let t=`draft_`+Math.floor(Math.random()*1e4);s([...i,{id:t,title:`New Tab`,path:`/draft`,type:e,isSystem:!1,enabled:!0}]);let n=i.filter(t=>t.type===e&&!t.id.startsWith(`draft_`)).length+1,r={};e===`public`?r={...Jt,route:`/page-${n}`}:e===`private`?r={...Yt,route:`/private-tab-${n}`}:e===`admin`?r={...Xt,route:`/admin-tab-${n}`}:e===`shared`&&(r={...Zt,route:`/shared-tab-${n}`}),_(e=>({...e,[t]:r})),d(t),h(!1),J(t,{...r,pageType:e===`public`?void 0:e}),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})},100)};if(e!==`admin`)return(0,l.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,l.jsx)(n.v,{className:`w-12 h-12 text-red-500 mb-4`}),(0,l.jsx)(`h2`,{className:`text-2xl font-bold`,children:`Access Denied`}),(0,l.jsx)(`p`,{className:`text-foreground/60`,children:`You do not have permission to view pages configuration.`})]})});let se=async(e,t,r)=>{let a=r===`public`,c=a?`page_order`:`tab_order`,l=a?R:B,u=(a?P:I).has(e);s(i.map(t=>t.id===e?{...t,enabled:u}:t));let d=[...l],f=d.findIndex(t=>t.id===e);f===-1?d.push({id:e,hidden:!0}):d[f]={...d[f],hidden:!u},await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,c),{order:d})},ce=(e,t)=>{t||w(e)},le=async()=>{if(C){E(!0);try{let{deleteDoc:e,collection:t,getDocs:r,doc:a,getDoc:o,query:l,where:u}=await import(`firebase/firestore`),{ref:f,deleteObject:p}=await import(`firebase/storage`),m=i.find(e=>e.id===C),h=m?.type===`public`?`sys_pages`:`sys_tabs`;if(h===`sys_tabs`&&m){let i=g[C];if(!i)try{let e=await o(a(n.Tt,`sys_tabs`,C));e.exists()&&(i=e.data())}catch{}let s=(i?.tabName||i?.pageId||C).toLowerCase().replace(/[^a-z0-9]+/g,`_`),c=[`admin_${s}_records`,`mem_${s}_records`,`user_${s}_records`],d={[`admin_${s}_records`]:{prefix:`admin_files`,driveCollection:`admin_files`},[`mem_${s}_records`]:{prefix:`mem_files`,driveCollection:`mem_files`},[`user_${s}_records`]:{prefix:`user_files`,driveCollection:`user_files`}},m=[];for(let i of c)m.push((async()=>{try{let a=await r(t(n.Tt,i)),o=d[i],s=[];for(let i of a.docs){let a=i.data();a.recordType===`file`&&a.downloadURL&&o&&s.push((async()=>{try{let i=`${o.prefix}%2F`,s=a.downloadURL.split(i)[1]?.split(`?`)[0];s&&await p(f(n.Dt,`${o.prefix}/${decodeURIComponent(s)}`)).catch(()=>{});let c=await r(l(t(n.Tt,o.driveCollection),u(`downloadURL`,`==`,a.downloadURL)));await Promise.all(c.docs.map(t=>e(t.ref)))}catch(e){console.error(`Error deleting storage file:`,e)}})())}await Promise.all(s),await Promise.all(a.docs.map(t=>e(t.ref)));try{localStorage.removeItem(`fbos_records_${i}`)}catch{}}catch(e){console.error(`Error cleaning up collection ${i}:`,e)}})());for(let i of[`admin_files`,`mem_files`,`user_files`])m.push((async()=>{try{let a=await r(l(t(n.Tt,i),u(`sourceTab`,`==`,s)));await Promise.all(a.docs.map(async t=>{let r=t.data();if(r.downloadURL)try{let e=`${i}%2F`,t=r.downloadURL.split(e)[1]?.split(`?`)[0];t&&await p(f(n.Dt,`${i}/${decodeURIComponent(t)}`)).catch(()=>{})}catch{}await e(t.ref)}))}catch{}})());await Promise.all(m)}await e(a(n.Tt,h,C));let _=h===`sys_pages`?`page_order`:`tab_order`,v=h===`sys_pages`?R:B,{setDoc:y}=await import(`firebase/firestore`),b=v.filter(e=>e.id!==C);await y(a(n.Tt,`sys_configs`,_),{order:b}),s(e=>e.filter(e=>e.id!==C)),c===C&&d(null)}catch(e){console.error(`Error deleting page:`,e)}E(!1),w(null)}},ue=e=>{let t=e.id+`_`+Math.floor(Math.random()*1e3),n={...e,id:t,title:`${e.title} (Copy)`,path:`${e.path}_copy`,isSystem:!1,enabled:!0};s(e=>[...e,n]);let r=g[e.id];!r&&e.id===`home`&&(r=O);let i={...r||{},route:n.path,pageName:n.title};n.type!==`public`&&(i.tabName=n.title,i.pageType=n.type),_(e=>({...e,[t]:i})),d(t),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})},100)},de=[{id:`public`,title:`Public Pages`,icon:n.U,color:`bg-amber-500`,description:`Creates external menu items. Invisible to signed-in dashboard users.`,filter:e=>e.type===`public`},{id:`private`,title:`Private Pages`,icon:n.j,color:`bg-emerald-500`,description:`Internal dashboard tabs for regular users.`,filter:e=>e.type===`private`},{id:`shared`,title:`Shared Pages`,icon:n.K,color:`bg-blue-500`,description:`Dashboard tabs visible to all members, editors, and admins.`,filter:e=>e.type===`shared`},{id:`admin`,title:`Admin Pages`,icon:n.v,color:`bg-red-500`,description:`Internal dashboard tabs for admin users only.`,filter:e=>e.type===`admin`}],[fe,X]=(0,a.useState)(!1),[pe,me]=(0,a.useState)(!1);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Pages`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/pages`,c?`/${c}`:``]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(`div`,{className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-6 pt-6 md:px-10 md:pt-10`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Architecture`}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`Manage the structure of your application tabs and public pages.`})]}),(0,l.jsxs)(`div`,{className:`relative z-50 shrink-0 flex items-center gap-1`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>X(!0),className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,title:`Reset Defaults`,children:(0,l.jsx)(n.x,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>h(!p),className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,title:`Add New Page`,children:(0,l.jsx)(n.C,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,l.jsx)(n.a,{children:p&&(0,l.jsx)(n.i.div,{ref:D,initial:{opacity:0,y:10,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.95},className:`absolute top-full mt-2 right-0 w-48 glass-panel border border-[var(--panel-border)] rounded-2xl p-2 shadow-xl z-50 flex flex-col gap-1`,children:[`public`,`private`,`shared`,`admin`].map(e=>(0,l.jsxs)(`button`,{onClick:()=>{oe(e),h(!1)},className:`text-left px-3 py-2 text-[13px] font-bold uppercase tracking-wider text-foreground/70 hover:text-foreground hover:bg-foreground/5 rounded-lg transition-colors cursor-pointer`,children:[e,` Page`]},e))})})]})]})]}),(0,l.jsxs)(`div`,{ref:H,className:`px-6 md:px-10 pb-6 md:pb-10 flex flex-col pt-0 gap-10 overflow-y-auto mt-2 relative min-h-[400px]`,children:[(0,l.jsx)(n.a,{children:pe&&(0,l.jsx)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-[2px] rounded-3xl`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-6 glass-panel rounded-2xl shadow-xl`,children:[(0,l.jsx)(n.M,{className:`w-8 h-8 md:w-10 md:h-10 animate-spin text-accent mb-4`}),(0,l.jsx)(`span`,{className:`text-sm font-bold text-foreground`,children:`Synchronizing Architecture...`})]})})}),de.map((e,t)=>{let r=i.filter(e.filter),a=e.id===`public`?R:B,o=r.sort((e,t)=>{let n=a.findIndex(t=>t.id===e.id),r=a.findIndex(e=>e.id===t.id);return n===-1&&r===-1?0:n===-1?1:r===-1?-1:n-r}),s=e.icon,u=e=>e.type===`public`?P.has(e.id):I.has(e.id),f=o.filter(e=>!u(e)),p=o.filter(e=>u(e)),m=e=>{if(!e)return[];let t=[`route`,`pageName`,`template`];return e.template===`none`?(t.push(`pageTitle`,`copyPrompt`),t.push(`showButton`),e.showButton!==!1&&(t.push(`buttonText`,`action`),e.action===`form`?t.push(`form`):e.action===`redirect`&&t.push(`redirectUrl`))):(e.template===`popup_form`||e.template===`inline_form`)&&(t.push(`showButton`),e.showButton!==!1&&t.push(`form`)),t},h=e=>{if(!e)return[];let t=[`tabName`,`iconName`,`route`,`template`];return e.template===`popup_form`||e.template===`inline_form`?(t.push(`showButton`),e.showButton!==!1&&t.push(`form`)):e.template===`none`?(t.push(`showPrompt`,`tabTitle`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonStyle`,`buttonText`,`buttonAction`),t.push(`storage`),e.storage!==!1&&t.push(`buttonStorageIcon`,`buttonStorageText`,`buttonStorageStyle`,`buttonStorageAction`)):e.template===`calendar`?(t.push(`tabTitle`,`showPrompt`),t.push(`defaultView`,`defaultTimeFormat`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`showViewsButton`),e.showViewsButton!==!1&&t.push(`viewsButtonStyle`)):e.template===`table`?(t.push(`tabTitle`,`showPrompt`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`showExportButton`),e.showExportButton!==!1&&t.push(`exportButtonIcon`)):e.template===`board`&&(t.push(`tabTitle`,`showPrompt`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`keyName`,`valueName`)),t},_=(t,r,i)=>{let a=t.id===`home`,o=c===t.id,s=a||!t.isSystem;return(0,l.jsxs)(`div`,{id:`page-${t.id}`,onClick:e=>{if(s){let e=o?null:t.id;d(e),window.history.replaceState(null,``,e?`/pages/${e}`:`/pages`)}},className:`group flex flex-col py-4 px-5 glass-panel border transition-all rounded-2xl hover:shadow-sm ${s?`cursor-pointer hover:border-accent/40`:``} ${i?`opacity-40 grayscale bg-foreground/[0.01] border-[var(--panel-border)]/50`:`border-transparent hover:border-[var(--panel-border)]`}`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-center justify-between w-full gap-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-1 w-full flex-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground truncate`,children:t.title}),a&&A&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-accent ml-2`})]}),(0,l.jsxs)(`div`,{className:`text-[11px] font-medium font-mono px-2 py-0.5 rounded w-fit ml-6 border ${i?`text-foreground/50 border-foreground/10 bg-foreground/5`:`text-accent/70 bg-accent/5 border-accent/10`}`,children:[window.location.host,t.path]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-4 shrink-0`,children:[!t.isSystem||[`contact`,`support`,`templates`].includes(t.id)?(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ue(t)},className:`p-1.5 hover:bg-accent/10 text-foreground/40 hover:text-accent transition-colors rounded-lg flex items-center justify-center shrink-0`,title:`Duplicate Page`,children:(0,l.jsx)(n.Z,{className:`w-4 h-4`})}):(0,l.jsx)(`div`,{className:`w-[28px] shrink-0`}),(0,l.jsx)(`div`,{className:`flex items-center justify-end w-8 shrink-0`,children:t.id===`home`?(0,l.jsx)(`div`,{className:`w-[28px] shrink-0`}):(0,l.jsx)($t,{enabled:!u(t),onChange:()=>se(t.id,t.isSystem,t.type)})}),t.isSystem?(0,l.jsx)(`div`,{className:`w-[28px] shrink-0`}):(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ce(t.id,t.isSystem)},className:`p-1.5 hover:bg-red-500/10 text-foreground/30 hover:text-red-500 transition-colors rounded-lg flex items-center justify-center shrink-0`,title:`Delete Page`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),s?(0,l.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 shrink-0 ${o?`rotate-180`:``}`,children:(0,l.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,l.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}):(0,l.jsx)(`div`,{className:`w-[24px] shrink-0`})]})]}),(0,l.jsxs)(n.a,{children:[o&&a&&O&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50 pb-4`,onClick:e=>e.stopPropagation(),children:(0,l.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 py-6 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,l.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,l.jsx)(`button`,{onClick:Y,className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:M?(0,l.jsx)(n.M,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),q(`home`,O)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:re===`home`?(0,l.jsx)(n.nt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,l.jsx)(Kt,{value:O,keysToRender:[`hero`],onChange:e=>J(`home`,e),isLast:!0,isGlobalSaving:A,customEnums:{form:U},customExplanations:{form:`User can click to switch to any public form we have in the forms tab. Private forms are not an option here. Add a new form in forms with a link that actually works.`}})]})}),o&&!t.isSystem&&g[t.id]&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50 pb-4`,onClick:e=>e.stopPropagation(),children:(0,l.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 py-6 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,l.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,l.jsx)(`button`,{onClick:e=>ae(e,t.id,t.type===`admin`?Xt:t.type===`shared`?Zt:t.type===`public`?Jt:Yt),className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:b[t.id]?(0,l.jsx)(n.M,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),q(t.id,g[t.id])},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:re===t.id?(0,l.jsx)(n.nt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,l.jsx)(Kt,{value:g[t.id],keysToRender:t.type===`public`?m(g[t.id]):h(g[t.id]),onChange:e=>J(t.id,e),isLast:!0,isGlobalSaving:v[t.id],customEnums:{form:t.type===`public`?U:G,template:t.type===`public`?[`none`,`popup_form`,`inline_form`]:t.type===`admin`||t.type===`shared`?[`none`,`calendar`,`table`,`board`]:[`none`,`calendar`,`table`,`board`,`popup_form`,`inline_form`],action:[`save_Info`,`form`],defaultTimeFormat:[`12h`,`24h`],defaultView:[`calendar`,`board`],buttonStyle:[`primary`,`secondary`],buttonAction:[`save_info`],viewsButtonStyle:[`primary`,`secondary`],buttonStorageStyle:[`primary`,`secondary`],buttonStorageAction:[`upload_file`]},customExplanations:{tabName:`Defines the tab label in the dashboard navigation.`,iconName:`Visit https://lucide.dev/icons/, find an icon, and paste its exact name (e.g. 'book-open', 'server', 'cloud-upload').`,route:`The URL path for this tab (e.g. '/my-tab'). Must start with /.`,template:`Page layout type. 'none' gives you a freeform dashboard with add/upload buttons.`,form:`Which form to display. Only applies to popup_form or inline_form templates. Go to /forms to edit forms.`,tabTitle:`The heading that appears at the top of the page content area.`,showPrompt:`Shows the developer AI prompt copy button in the header.`,showButton:`Toggles the + add record button in the header.`,buttonStyle:`Visual style of the add button: 'primary' (accent) or 'secondary' (subtle).`,buttonText:`Label on the add button. Use '+' for a minimal icon-only button.`,buttonAction:`'save_info' saves a name + note record to the tab's Firestore collection.`,storage:`Enables the file upload button for this tab.`,buttonStorageIcon:`Icon name from https://lucide.dev/icons/ for the upload button (e.g. 'upload', 'cloud-upload').`,buttonStorageText:`Label next to the upload icon. Leave empty for icon-only.`,buttonStorageStyle:`'primary' or 'secondary' visual style for the upload button.`,buttonStorageAction:t.type===`admin`?`'upload_file' uploads to admin_files/ in Storage and mirrors metadata to admin_files collection (Drive > Admin).`:t.type===`shared`?`'upload_file' uploads to mem_files/ in Storage and mirrors metadata to mem_files collection (Drive > Shared).`:`'upload_file' uploads to user_files/ in Storage and mirrors metadata to user_files collection (Drive > Private).`,defaultView:`Starting view: 'calendar' (month grid) or 'board' (event list). Users can switch between them.`,defaultTimeFormat:`12h or 24h time format. Users can toggle this in the toolbar.`,showViewsButton:`Show the calendar/board view toggle button in the toolbar.`,viewsButtonStyle:`'primary' or 'secondary' visual style for the view toggle.`,showExportButton:`Show the CSV export/download button in the table toolbar.`,exportButtonIcon:`Icon name from https://lucide.dev/icons/ for the export button (e.g. 'download', 'import').`,keyName:`Label for the key/title field in board items (e.g. 'Task', 'Name').`,valueName:`Label for the value/description field in board items (e.g. 'Notes', 'Details').`},hideInnerLoader:!0})]})})]})]},`${e.id}-${t._uiKey||t.id}`)};return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex flex-col relative`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-3 mb-2 border-b border-[var(--panel-border)]/50 pb-4`,children:[(0,l.jsx)(`div`,{className:`w-8 h-8 rounded-xl glass-panel border border-[var(--panel-border)] flex items-center justify-center -ml-1 shadow-sm`,children:(0,l.jsx)(s,{className:`w-4 h-4 text-accent`})}),(0,l.jsx)(`h2`,{className:`text-xl font-extrabold tracking-tight text-foreground`,children:e.title})]}),(0,l.jsx)(`p`,{className:`text-[13px] leading-relaxed text-foreground/50 font-medium max-w-3xl mb-4 ml-[2px]`,children:e.description}),o.length===0?(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 opacity-40 glass-panel rounded-2xl border border-[var(--panel-border)]/50 border-dashed`,children:[(0,l.jsx)(n.L,{className:`w-5 h-5 mb-2`}),(0,l.jsx)(`p`,{className:`text-[12px] font-bold`,children:`This section is currently empty.`})]}):(0,l.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[f.map(e=>_(e,o.findIndex(t=>t.id===e.id),!1)),p.length>0&&(0,l.jsxs)(`details`,{className:`mt-4 group/details`,children:[(0,l.jsxs)(`summary`,{className:`text-[11px] font-bold uppercase tracking-wider text-foreground/40 cursor-pointer list-none flex items-center gap-2 select-none hover:text-foreground/70 transition-colors w-fit pb-1 ml-1 outline-none`,children:[(0,l.jsx)(n.st,{className:`w-3.5 h-3.5 group-open/details:-rotate-180 transition-transform`}),`Hidden pages (`,p.length,`)`]}),(0,l.jsx)(`div`,{className:`flex flex-col gap-4 mt-4`,children:p.map(e=>_(e,o.findIndex(t=>t.id===e.id),!0))})]})]}),t<de.length-1&&(0,l.jsx)(`div`,{className:`w-full border-t border-[var(--panel-border)]/70 my-10`})]},e.id)})]})]})]}),(0,l.jsx)(te,{isOpen:fe,onCancel:()=>X(!1),onConfirm:async()=>{me(!0);try{let{deleteDoc:e}=await import(`firebase/firestore`);await Promise.all([e((0,o.doc)(n.Tt,`sys_pages`,`home`))]),k(S)}catch(e){console.error(`Error resetting defaults:`,e)}setTimeout(()=>{me(!1),X(!1)},1e3)},title:`Reset System Pages`,message:`Are you sure you want to reset all system page configurations? Custom pages and their order will remain intact.`,confirmText:`Reset`,isProcessing:pe}),(0,l.jsx)(te,{isOpen:!!C,onCancel:()=>w(null),onConfirm:le,title:`Delete Page`,message:`Are you sure you want to delete this page? This action cannot be undone and will remove all associated configurations.`,confirmText:`Remove Page`,isProcessing:T})]})}var tn={contact:r.t,support:i.t};function nn(){let{userRole:e}=m(),t=(0,u.useNavigate)();(0,u.useLocation)();let[r,i]=(0,a.useState)({}),[s,c]=(0,a.useState)(!0),[d,f]=(0,a.useState)({}),p=n.Ct(),h=()=>({...tn,contact:p?.defaultConfigs?.contactForm||tn.contact,support:p?.defaultConfigs?.supportForm||tn.support}),[g,_]=(0,a.useState)(null),[v,y]=(0,a.useState)({}),[b,x]=(0,a.useState)(null),[S,C]=(0,a.useState)(!1),[w,T]=(0,a.useState)(null),E=(e,t)=>{let n;n=e===`contact`?`export const contactFormConfig = ${JSON.stringify(t,null,2)};\n`:e===`support`?`export const supportFormConfig = ${JSON.stringify(t,null,2)};\n`:JSON.stringify(t,null,2),navigator.clipboard.writeText(n),T(e),setTimeout(()=>T(null),2e3)};(0,a.useEffect)(()=>{D()},[]);let D=async()=>{try{let e=await(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)),t={};e.forEach(e=>{if(e.id!==`pubForm`&&e.id!==`userForm`){let n=e.data();n._uiKey||=Math.random().toString(36).substring(7),t[e.id]=n}});try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,`pubForm`)),await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,`userForm`))}catch{}let r=h();for(let[e,i]of Object.entries(r))if(!t[e]){await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),i);let r={...i};r._uiKey=Math.random().toString(36).substring(7),t[e]=r}else if(!t[e].fields||t[e].fields.length===0){let i=r[e];t[e].fields=i.fields||[],await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),t[e])}let a=window.location.pathname.split(`/forms/`)[1]?.split(`/`)[0];a&&t[a]&&y({[a]:!0}),i(t)}catch(e){console.error(`Failed to load forms:`,e)}finally{c(!1)}},O=async(e,t)=>{let a={...t};r[e]?._uiKey&&(a._uiKey=r[e]._uiKey),e===`contact`?(a.systemName=`contact`,a.formType=`public`,a.submitPage=`submissions`):e===`support`&&(a.systemName=`support`,a.formType=`private`,a.submitPage=`requests`);let s=a.systemName||e;if(s!==e&&s.trim()!==``){i(t=>{let n={};for(let r of Object.keys(t))r===e?n[s]=a:n[r]=t[r];return n}),v[e]&&y(t=>{let n={};for(let r of Object.keys(t))r===e?n[s]=t[r]:n[r]=t[r];return n}),f(e=>({...e,[s]:!0}));try{await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,s),a),await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,e))}catch(e){console.error(`Failed to migrate form map ID:`,e)}finally{setTimeout(()=>{f(e=>({...e,[s]:!1}))},500)}}else{i(t=>({...t,[e]:a})),f(t=>({...t,[e]:!0}));try{await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),a)}catch(e){console.error(`Failed to save form:`,e)}finally{setTimeout(()=>{f(t=>({...t,[e]:!1}))},500)}}},[k,A]=(0,a.useState)(!1),j=async()=>{if(k)return;A(!0);let e=`new_form_${Date.now().toString().slice(-4)}`,r={title:`New Custom Form`,systemName:e,formType:`public`,submitPage:`submissions`,redirectTo:``,submitText:`Submit`,fields:[],enabled:!0,_uiKey:Math.random().toString(36).substring(7)};try{f(t=>({...t,[e]:!0})),await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),r),i(t=>({[e]:r,...t})),y(t=>({[e]:!0,...t})),t(`/forms/${e}`)}catch(e){console.error(`Failed to create form`,e)}finally{f(t=>({...t,[e]:!1})),A(!1)}},M=async e=>{if(!(e===`contact`||e===`support`)){C(!0);try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,e)),i(t=>{let n={...t};return delete n[e],n}),t(`/forms`)}catch(e){console.error(`Failed to delete form`,e)}finally{C(!1),x(null)}}};if(e!==`admin`)return(0,l.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,l.jsx)(n.p,{className:`w-12 h-12 text-red-500 mb-4`}),(0,l.jsx)(`h2`,{className:`text-2xl font-bold bg-clip-text text-transparent bg-gradient-to-br from-red-400 to-red-600`,children:`Access Restricted`}),(0,l.jsx)(`p`,{className:`text-foreground/60 max-w-sm text-center mt-2 font-medium leading-relaxed`,children:`This area is exclusively for system administrators.`})]})});let N=e=>{y(t=>{let n={...t,[e]:!t[e]};if(n[e])window.history.replaceState(null,``,`/forms/${e}`);else{let e=Object.keys(n).filter(e=>n[e]);e.length>0?window.history.replaceState(null,``,`/forms/${e[0]}`):window.history.replaceState(null,``,`/forms`)}return n})},P=Object.keys(v).find(e=>v[e]);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Forms`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/forms`,P?`/${P}`:``]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(`div`,{className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-6 pt-6 md:px-10 md:pt-10 bg-background/50`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Custom Forms`}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`This is the central page where you configure and manage your application's forms. Easily add and customize the fields for your users.`})]}),(0,l.jsx)(`div`,{className:`relative z-50 shrink-0 flex items-center justify-end`,children:(0,l.jsx)(n.n,{variant:`secondary`,onClick:j,title:`Add Custom Form`,disabled:k,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,children:k?(0,l.jsx)(n.M,{className:`w-4 h-4 text-foreground/60 animate-spin`}):(0,l.jsx)(n.C,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})})})]}),(0,l.jsx)(`div`,{className:`p-6 md:p-8 flex flex-col gap-4 overflow-y-auto`,children:s?(0,l.jsx)(`div`,{className:`flex items-center justify-center p-12 glass-panel rounded-3xl border border-[var(--panel-border)]`,children:(0,l.jsx)(n.M,{className:`w-6 h-6 animate-spin text-accent`})}):Object.keys(r).length===0?(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-12 glass-panel rounded-3xl border border-[var(--panel-border)] border-dashed opacity-50`,children:[(0,l.jsx)(n.S,{className:`w-6 h-6 mb-3 text-foreground/40`}),(0,l.jsx)(`p`,{className:`text-[13px] font-bold`,children:`No forms currently configured.`})]}):(0,l.jsx)(n.a,{children:Object.entries(r).map(([e,t])=>{let r=v[e],i=d[e];return(0,l.jsxs)(n.i.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,y:-10},onClick:()=>N(e),className:`group flex flex-col p-3 px-4 glass-panel border transition-all rounded-2xl hover:shadow-sm cursor-pointer hover:border-accent/40 ${r?`border-[var(--panel-border)] bg-background/50`:`border-transparent hover:border-[var(--panel-border)]`} flex-shrink-0 ${t.enabled===!1?`opacity-40 grayscale bg-foreground/[0.01] border-[var(--panel-border)]/50`:``}`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between w-full`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col gap-1 w-full sm:w-auto pr-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground break-words ml-1 leading-snug`,children:t.title||`Untitled Form`}),i&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-accent ml-2 shrink-0`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5 ml-1`,children:[(0,l.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest border border-[var(--panel-border)] bg-foreground/5 text-foreground/60 px-2 py-0.5 rounded-md`,children:t.systemName||e}),(0,l.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest border px-2 py-0.5 rounded-md shrink-0 ${t.formType===`private`?`text-blue-500 bg-blue-500/10 border-blue-500/20`:`text-green-500 bg-green-500/10 border-green-500/20`}`,children:t.formType||`public`})]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-4 w-full sm:w-auto justify-end mt-2 sm:mt-0 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),_(t)},className:`p-1.5 hover:bg-accent/10 text-foreground/40 hover:text-accent transition-colors rounded-lg flex items-center justify-center mr-2`,title:`Preview Form`,children:(0,l.jsx)(n.K,{className:`w-4 h-4`})}),e!==`contact`&&e!==`support`?(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),x(e)},className:`p-1.5 hover:bg-red-500/10 text-foreground/30 hover:text-red-500 transition-colors rounded-lg opacity-0 group-hover:opacity-100 flex items-center justify-center mr-2`,title:`Delete Form`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}):(0,l.jsx)(`div`,{className:`w-7 mr-2 shrink-0`}),(0,l.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 ${r?`rotate-180`:``}`,children:(0,l.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,l.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})})]})]}),(0,l.jsx)(n.a,{children:r&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50`,onClick:e=>e.stopPropagation(),children:(0,l.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,l.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,l.jsx)(`button`,{onClick:async t=>{if(t.stopPropagation(),e===`contact`||e===`support`){f(t=>({...t,[e]:!0}));try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,e)),localStorage.removeItem(`fbos_form_${e}`),await D()}catch(e){console.error(`Reset failed:`,e)}setTimeout(()=>f(t=>({...t,[e]:!1})),500)}else O(e,h()[e]||h().contact)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:i?(0,l.jsx)(n.M,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(`button`,{onClick:n=>{n.stopPropagation(),E(e,t)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:w===e?(0,l.jsx)(n.nt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,l.jsx)(Kt,{value:{systemName:t.systemName||e,formType:t.formType||`public`,submitPage:t.submitPage||(t.formType===`private`?`requests`:`submissions`),redirectTo:t.redirectTo||``,title:t.title||``,buttonName:t.buttonName||t.submitText||``,fields:t.fields||[]},keysToRender:[`systemName`,`formType`,`submitPage`,`redirectTo`,`title`,`buttonName`,`fields`],meta:{formType:t.formType||`public`},onChange:n=>{n.formType===t.formType?n.submitPage!==t.submitPage&&(n.formType=n.submitPage===`requests`?`private`:`public`):n.submitPage=n.formType===`public`?`submissions`:`requests`,O(e,{...t,...n,submitText:n.buttonName})},isLast:!0,isGlobalSaving:i,disabledKeys:e===`contact`||e===`support`?[`systemName`,`formType`,`submitPage`]:[],customEnums:{type:[`text`,`email`,`tel`,`textarea`,`number`,`select`,`checkbox`,`currency`,`age`]},customExplanations:{formType:e===`contact`?`Public means its for not signed in users. Private is disabled for contact so don't allow the user to change it.`:e===`support`?`This means that the form is available to signed in users only.`:`Public means it's for non-signed in users.`,submitPage:e===`contact`?`Means the form submissions go to this folder. User can't change that since it's directly linked. Public is tied to submissions.`:e===`support`?`Can't change since all private forms go there.`:`Where to route data submissions.`,redirectTo:`If not added form will just show a success message. If added, in 30 seconds after success user is redirected.`}})]})})})]},t._uiKey||e)})})})]})]}),(0,l.jsx)(te,{isOpen:!!b,onCancel:()=>x(null),onConfirm:()=>{b&&M(b)},title:`Delete Form`,message:`Are you sure you want to permanently delete "${b}"? This action cannot be reversed.`,confirmText:`Delete form`,isProcessing:S}),g&&(0,l.jsx)(n.t,{formConfig:g,onClose:()=>_(null)})]})}function rn({config:e,customContent:t}){let{config:r}=n.xt(),[i,s]=(0,a.useState)(!1),[c,u]=(0,a.useState)(null),[d,f]=(0,a.useState)([]);(0,a.useEffect)(()=>{document.title=e.pageName||e.pageTitle||r.appName||`Firebase OS`,(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{f(e.docs.filter(e=>e.data().formType===`public`).map(e=>e.id))})},[e.pageName,e.pageTitle,r.appName]);let p=H(e,d);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 relative min-h-screen`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.pageTitle||e.pageName||`New Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]}),(0,l.jsxs)(`div`,{className:`flex justify-between items-center mb-6 pt-2 border-b border-[var(--panel-border)] pb-6 relative z-20 overflow-x-auto no-scrollbar gap-4`,children:[(0,l.jsxs)(`button`,{onClick:()=>window.history.back(),className:`px-5 py-2 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold hover:bg-foreground/5 transition-all flex items-center gap-2 cursor-pointer shadow-sm text-foreground/70 whitespace-nowrap shrink-0`,children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` Go Back`]}),(0,l.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[e.copyPrompt&&(0,l.jsxs)(`button`,{onClick:()=>{navigator.clipboard.writeText(p),s(!0),setTimeout(()=>s(!1),2e3)},title:`Copy Developer Prompt`,className:`px-6 py-2.5 rounded-xl border border-[var(--panel-border)] bg-background flex items-center gap-2 hover:bg-foreground/5 hover:text-accent transition-all cursor-pointer text-[14px] font-bold tracking-wide shadow-sm whitespace-nowrap`,children:[(0,l.jsx)(n.ft,{className:`w-4 h-4`}),(0,l.jsx)(`span`,{className:`hidden sm:inline`,children:i?`Copied!`:`Copy Prompt`})]}),e.showButton&&(0,l.jsx)(`button`,{onClick:()=>{e.action===`redirect`?window.location.href=e.url||`/`:e.action===`form`&&u(e.form||`contact`)},className:`px-6 py-2.5 rounded-xl font-bold tracking-wide transition-all duration-300 flex items-center justify-center btn-primary shadow-xl hover:-translate-y-1 active:scale-95 text-[14px] whitespace-nowrap`,children:e.buttonText||`Action Button`})]})]}),(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl shadow-2xl relative flex flex-col flex-1 bg-background/50 h-full min-h-[400px]`,children:t?(0,l.jsx)(`div`,{className:`flex-1 p-4 md:p-8`,children:(0,l.jsx)(t,{config:e})}):(0,l.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center opacity-40 glass-panel border border-[var(--panel-border)]/50 border-dashed m-4 md:m-8 rounded-2xl p-8 py-20 text-center`,children:[(0,l.jsx)(n.ft,{className:`w-8 h-8 md:w-12 md:h-12 mb-4 text-foreground/80 opacity-50`}),(0,l.jsx)(`p`,{className:`text-[14px] font-bold mb-2`,children:`Click copy prompt at the top to start adding changes`}),(0,l.jsx)(`div`,{className:`mt-8 text-left bg-background p-6 rounded-2xl text-[12px] font-mono whitespace-pre-wrap max-w-2xl border border-[var(--panel-border)]/50 text-foreground/60 shadow-inner`,children:p})]})}),(0,l.jsx)(n.a,{children:c&&(0,l.jsx)(n.t,{onClose:()=>u(null),formId:c})})]})}function an({config:e,customContent:t}){let{user:r}=m(),{config:i}=n.xt(),[s,u]=(0,a.useState)([]),[f,p]=(0,a.useState)(!0),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(``),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(!1),[T,E]=(0,a.useState)(!1),[D,O]=(0,a.useState)(null),[k,A]=(0,a.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;P(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[N,P]=(0,a.useState)(!0),[F,I]=(0,a.useState)(!1),[L,R]=(0,a.useState)(null),[z,B]=(0,a.useState)(``),[V,ne]=(0,a.useState)(``),[H,U]=(0,a.useState)([]),W=(0,a.useRef)(null),G=(e.tabName||e.pageId||`private_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),K=`user_${G}_records`;(0,a.useEffect)(()=>{document.title=e.tabTitle||e.tabName||i.appName||`Firebase OS`,(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{})},[e.tabTitle,e.tabName,i.appName]),(0,a.useEffect)(()=>{if(!r)return;try{let e=localStorage.getItem(`fbos_records_${K}`);e?(u(JSON.parse(e)),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}});(async()=>{try{let t=e((await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,K),(0,o.where)(`uid`,`==`,r.uid),(0,o.limit)(150)))).docs);t.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),u(t),p(!1),localStorage.setItem(`fbos_records_${K}`,JSON.stringify(t))}catch(e){console.error(`Error fetching records:`,e),p(!1)}})()},[r,K]),(0,a.useEffect)(()=>{f||localStorage.setItem(`fbos_records_${K}`,JSON.stringify(s))},[s,f,K]);let re=async e=>{if(e.preventDefault(),!(!r||!_.trim())){S(!0);try{let e=await(0,o.addDoc)((0,o.collection)(n.Tt,K),{name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,createdAt:(0,o.serverTimestamp)()});u(t=>[{id:e.id,name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,createdAt:Date.now()},...t]),v(``),b(``),g(!1)}catch(e){console.error(`Error saving record:`,e)}S(!1)}},ie=async e=>{let t=e.target.files?.[0];if(!(!t||!r)){E(!0);try{let e=(0,c.ref)(n.Dt,`user_files/${`${Date.now()}_${t.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,c.uploadBytes)(e,t,{customMetadata:{ownerId:r.uid}});let i=await(0,c.getDownloadURL)(e);await(0,o.addDoc)((0,o.collection)(n.Tt,`user_files`),{fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,uid:r.uid,uploaderEmail:r.email||`user`,sourceTab:G,accessPrefix:`user_`,createdAt:(0,o.serverTimestamp)()});let a=await(0,o.addDoc)((0,o.collection)(n.Tt,K),{name:t.name,note:`${t.type||`File`} · ${ve(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,createdAt:(0,o.serverTimestamp)()});u(e=>[{id:a.id,name:t.name,note:`${t.type||`File`} · ${ve(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type,fileSize:t.size,downloadURL:i,createdAt:Date.now()},...e])}catch(e){console.error(`Error uploading file:`,e)}E(!1),W.current&&(W.current.value=``)}},q=async()=>{if(D){I(!0);try{let e=s.find(e=>e.id===D);if(await(0,o.deleteDoc)((0,o.doc)(n.Tt,K,D)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`user_files%2F`)[1]?.split(`?`)[0];t&&await(0,c.deleteObject)((0,c.ref)(n.Dt,`user_files/${decodeURIComponent(t)}`)).catch(()=>{});let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`user_files`),(0,o.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of r.docs)await(0,o.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up user file:`,e)}u(e=>e.filter(e=>e.id!==D)),O(null)}catch(e){console.error(`Error deleting record:`,e)}I(!1)}},[J,Y]=(0,a.useState)(null),[ae,oe]=(0,a.useState)(``),[se,ce]=(0,a.useState)(!1),[le,de]=(0,a.useState)(null),fe=(0,a.useRef)([]),X=e=>{if(e.recordType===`file`){Y(e.id),oe(e.name);return}R(e.id),B(e.name),ne(e.note||``);let t=[`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`],n=Object.entries(e).filter(([e])=>!t.includes(e)&&e!==`id`).map(([e,t])=>({key:e,value:String(t??``)}));U(n),fe.current=n.map(e=>e.key)},pe=async()=>{if(!J||!ae.trim()){Y(null);return}let e=s.find(e=>e.id===J);if(e&&e.name===ae.trim()){Y(null);return}ce(!0);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,K,J),{name:ae.trim()}),u(e=>e.map(e=>e.id===J?{...e,name:ae.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}ce(!1),Y(null)},me=async()=>{await Z(),R(null)},Z=async()=>{if(!L||!z.trim())return;S(!0);let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=fe.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,K,L),{name:z.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==L)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),fe.current=t}catch(e){console.error(`Error saving record:`,e)}S(!1)},he=(e,t)=>e?e.startsWith(`image/`)?t?(0,l.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${t})`}}):(0,l.jsx)(n.V,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,l.jsx)(n.l,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,l.jsx)(n.G,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,l.jsx)(n._t,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,l.jsx)(n.Q,{className:`w-4 h-4`}):(0,l.jsx)(n.W,{className:`w-4 h-4`}):(0,l.jsx)(n.G,{className:`w-4 h-4`}),ge=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-purple-500/10 text-purple-500`:e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?`bg-blue-500/10 text-blue-500`:e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?`bg-yellow-500/10 text-yellow-500`:e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?`bg-emerald-500/10 text-emerald-500`:`bg-foreground/5 text-foreground/40`:`bg-foreground/5 text-foreground/40`,_e=e=>{if(!e)return`FILE`;let t={"application/pdf":`PDF`,"application/zip":`ZIP`,"application/x-zip-compressed":`ZIP`,"application/x-rar-compressed":`RAR`,"application/x-7z-compressed":`7Z`,"application/json":`JSON`,"application/xml":`XML`,"application/javascript":`JS`,"application/typescript":`TS`,"application/msword":`DOC`,"application/vnd.openxmlformats-officedocument.wordprocessingml.document":`DOCX`,"application/vnd.ms-excel":`XLS`,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":`XLSX`,"application/vnd.ms-powerpoint":`PPT`,"application/vnd.openxmlformats-officedocument.presentationml.presentation":`PPTX`,"application/rtf":`RTF`,"application/x-tar":`TAR`,"application/gzip":`GZ`,"text/plain":`TXT`,"text/html":`HTML`,"text/css":`CSS`,"text/csv":`CSV`,"text/markdown":`MD`},n=e.toLowerCase();if(t[n])return t[n];let r=n.split(`/`);return r[r.length-1].replace(/^x-/,``).replace(/^vnd\..*\./,``).toUpperCase().slice(0,10)},ve=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},Q=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},ye=ue(e,K),be=()=>{navigator.clipboard.writeText(ye),w(!0),setTimeout(()=>w(!1),2e3)},xe=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),r=t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return n.o[r]?n.o[r]:n.o[t]?n.o[t]:n.f||n.C})(),Se=e.buttonStyle!==`secondary`,Ce=e.buttonStorageStyle===`primary`;return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Private Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${s.length} ${s.length===1?`item`:`items`}`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:be,title:C?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${C?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:C?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),e.storage!==!1&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`input`,{type:`file`,ref:W,onChange:ie,className:`hidden`}),(0,l.jsxs)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${Ce?`btn-primary`:`btn-secondary`}`,children:[T?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(xe,{className:`w-4 h-4`}),e.buttonStorageText&&(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>g(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${Se?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,l.jsx)(n.C,{className:`w-4 h-4`}):(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),t?(0,l.jsx)(t,{config:e,actions:{records:s,loading:f,collection:K,user:r,saveRecord:async e=>{await(0,o.addDoc)((0,o.collection)(n.Tt,K),{uid:r.uid,recordType:`record`,createdAt:(0,o.serverTimestamp)(),...e})},deleteRecord:async e=>{await(0,o.deleteDoc)((0,o.doc)(n.Tt,K,e))},uploadFile:()=>W.current?.click(),openAddForm:()=>g(!0)}}):(0,l.jsxs)(l.Fragment,{children:[!f&&s.length===0&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,l.jsx)(n.C,{className:`w-6 h-6 text-accent/40`})}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files to get started`})]}),!f&&s.length>0&&(0,l.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,l.jsx)(n.a,{children:s.map((e,t)=>{let r=L===e.id;return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},transition:{delay:t*.03,duration:.25},onClick:()=>X(e),className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative cursor-pointer ${r?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,l.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),de(e.id),setTimeout(()=>de(null),2e3)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-emerald-500 hover:bg-emerald-500/10 transition-all cursor-pointer`,title:`Copy Link`,children:le===e.id?(0,l.jsx)(n.ct,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-3.5 h-3.5`})})]}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),X(e)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,l.jsx)(n.w,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),O(e.id)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-3.5 h-3.5`})})]}),(0,l.jsxs)(`div`,{className:`flex items-start gap-3 mb-3`,children:[(0,l.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&j(e)},className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`cursor-pointer hover:scale-105 transition-transform ${ge(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?he(e.fileType,e.downloadURL):(0,l.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[J===e.id?(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,value:ae,onChange:e=>oe(e.target.value),onBlur:()=>pe(),onKeyDown:e=>{e.key===`Enter`&&pe(),e.key===`Escape`&&Y(null)},onClick:e=>e.stopPropagation(),className:`no-glow text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full pr-12`}):(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>j(e)}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:Q(e.createdAt)})]})]}),e.note&&(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),Object.entries(e).filter(([e])=>![`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`].includes(e)&&e!==`id`).slice(0,3).map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,l.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e))]},e.id)})})})]})]}),!t&&(0,l.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,l.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,l.jsx)(n.B,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,l.jsxs)(`span`,{children:[`Each user sees their own data only · Edit and delete available on all items · Records: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:K}),` · Files: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`user_files`}),` → Drive / Private`]})]})})]})]}),(0,l.jsx)(n.a,{children:h&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!x&&g(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`form`,{onSubmit:re,className:`p-5 flex flex-col gap-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>!x&&g(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:_,onChange:e=>v(e.target.value),placeholder:`Name *`,disabled:x,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),placeholder:`Note (optional)`,disabled:x,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:x,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:x?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,d.createPortal)((0,l.jsx)(n.a,{children:M&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,l.jsx)(n.i.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(`button`,{onClick:()=>j(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-[var(--panel-border)]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 bg-background/80 backdrop-blur-md border-b border-[var(--panel-border)] shrink-0 shadow-sm z-20`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:M.fileName||M.name}),(0,l.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[_e(M.fileType),` • `,ve(M.fileSize||0)]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.downloadURL),de(`preview`),setTimeout(()=>de(null),2e3)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 transition-colors rounded-xl shadow-sm hover:text-emerald-500 cursor-pointer`,title:`Copy Link`,children:le===`preview`?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),Y(M.id),oe(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),O(M.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),(0,l.jsx)(`a`,{href:M.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>j(null),children:(0,l.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[N&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-background/80 backdrop-blur-md shadow-xl flex items-center justify-center border border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,l.jsx)(`img`,{onLoad:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,alt:M.fileName||M.name,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full object-contain drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] rounded-lg pointer-events-auto transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType?.startsWith(`video/`)?(0,l.jsx)(`video`,{onLoadedData:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,controls:!0,autoPlay:!0,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full outline-none bg-black/40 rounded-lg pointer-events-auto drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType===`application/pdf`?(0,l.jsx)(`iframe`,{onLoad:()=>P(!1),src:M.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,l.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center text-foreground/40 text-center relative z-10`,onClick:e=>{e.stopPropagation(),P(!1)},children:[(0,l.jsx)(n.G,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,l.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,l.jsx)(`span`,{className:`text-[14px] mt-2 text-foreground/60 font-medium max-w-xs`,children:`This file format cannot be previewed. Please download it instead.`})]})]})})]})]})}),document.body),(0,l.jsx)(n.a,{children:L&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>me(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[440px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),x&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>me(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NAME`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>B(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>Z(),placeholder:`Name *`,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NOTE`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{ne(e.target.value),e.target.style.height=`auto`,e.target.style.height=e.target.scrollHeight+`px`},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),e.target.blur())},onBlur:()=>Z(),placeholder:`Add a note...`,rows:1,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50 resize-none overflow-hidden`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),H.map((e,t)=>(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let n=[...H];n[t].key=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>Z(),className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none placeholder:text-foreground/15 pt-3 pb-0.5 caret-foreground/40`}),(0,l.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let n=[...H];n[t].value=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>Z(),className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pt-1.5 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>U(H.filter((e,n)=>n!==t)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})})]},t)),(0,l.jsxs)(`button`,{type:`button`,onClick:()=>U([...H,{key:``,value:``}]),className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground/25 hover:text-foreground/40 transition-colors cursor-pointer mt-4 mb-4`,children:[(0,l.jsx)(n.C,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,l.jsx)(te,{isOpen:!!D,onCancel:()=>O(null),onConfirm:q,title:`Delete Record`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:s.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:F})]})}function on({config:e,customContent:t}){let{user:r}=m(),{config:i}=n.xt(),[s,u]=(0,a.useState)([]),[f,p]=(0,a.useState)(!0),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(``),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(!1),[T,E]=(0,a.useState)(!1),[D,O]=(0,a.useState)(null),[k,A]=(0,a.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;P(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[N,P]=(0,a.useState)(!0),[F,I]=(0,a.useState)(!1),[L,R]=(0,a.useState)(null),[z,B]=(0,a.useState)(``),[V,ne]=(0,a.useState)(``),[H,U]=(0,a.useState)([]),W=(0,a.useRef)(null),[G,K]=(0,a.useState)(null),re=(0,a.useRef)([]),ie=(e.tabName||e.pageId||`admin_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),q=`admin_${ie}_records`;(0,a.useEffect)(()=>{document.title=e.tabTitle||e.tabName||i.appName||`Firebase OS`},[e.tabTitle,e.tabName,i.appName]);let J=()=>({name:r.displayName||r.email?.split(`@`)[0]||`Admin`,email:r.email||``,avatar:r.photoURL||``});(0,a.useEffect)(()=>{if(!r)return;try{let e=localStorage.getItem(`fbos_records_${q}`);e?(u(JSON.parse(e)),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}}),t=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,q),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(150)),t=>{let n=e(t.docs);u(n),p(!1),localStorage.setItem(`fbos_records_${q}`,JSON.stringify(n))},t=>{console.error(`Error listening to admin records:`,t);let r=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,q),(0,o.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),u(n),p(!1),localStorage.setItem(`fbos_records_${q}`,JSON.stringify(n))});return()=>r()});return()=>t()},[r,q]);let Y=async e=>{if(e.preventDefault(),!(!r||!_.trim())){S(!0);try{let e=J();await(0,o.addDoc)((0,o.collection)(n.Tt,q),{name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()}),v(``),b(``),g(!1)}catch(e){console.error(`Error saving admin record:`,e)}S(!1)}},ae=async e=>{let t=e.target.files?.[0];if(!(!t||!r)){E(!0);try{let e=(0,c.ref)(n.Dt,`admin_files/${`${Date.now()}_${t.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,c.uploadBytes)(e,t,{customMetadata:{ownerId:r.uid}});let i=await(0,c.getDownloadURL)(e),a=J();await(0,o.addDoc)((0,o.collection)(n.Tt,`admin_files`),{fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,uid:r.uid,uploaderEmail:r.email||`admin`,sourceTab:ie,accessPrefix:`admin_`,creatorName:a.name,creatorEmail:a.email,creatorAvatar:a.avatar,createdAt:(0,o.serverTimestamp)()}),await(0,o.addDoc)((0,o.collection)(n.Tt,q),{name:t.name,note:`${t.type||`File`} · ${Q(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,creatorName:a.name,creatorEmail:a.email,creatorAvatar:a.avatar,createdAt:(0,o.serverTimestamp)()})}catch(e){console.error(`Error uploading admin file:`,e)}E(!1),W.current&&(W.current.value=``)}},oe=async()=>{if(D){I(!0);try{let e=s.find(e=>e.id===D);if(await(0,o.deleteDoc)((0,o.doc)(n.Tt,q,D)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`admin_files%2F`)[1]?.split(`?`)[0];t&&await(0,c.deleteObject)((0,c.ref)(n.Dt,`admin_files/${decodeURIComponent(t)}`)).catch(()=>{});let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`admin_files`),(0,o.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of r.docs)await(0,o.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up admin file:`,e)}O(null)}catch(e){console.error(`Error deleting admin record:`,e)}I(!1)}},[se,ce]=(0,a.useState)(null),[ue,de]=(0,a.useState)(``),[fe,X]=(0,a.useState)(!1),pe=e=>{if(e.recordType===`file`){ce(e.id),de(e.name);return}R(e.id),B(e.name),ne(e.note||``);let t=[`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`],n=Object.entries(e).filter(([e])=>!t.includes(e)&&e!==`id`).map(([e,t])=>({key:e,value:String(t??``)}));U(n),re.current=n.map(e=>e.key)},me=async()=>{if(!se||!ue.trim()){ce(null);return}let e=s.find(e=>e.id===se);if(e&&e.name===ue.trim()){ce(null);return}X(!0);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,se),{name:ue.trim()}),u(e=>e.map(e=>e.id===se?{...e,name:ue.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}X(!1),ce(null)},Z=async()=>{if(!L||!z.trim()){R(null);return}S(!0);let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=re.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,L),{name:z.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==L)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),re.current=t}catch(e){console.error(`Error updating record:`,e)}S(!1),R(null)},he=async()=>{if(!L||!z.trim())return;let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=re.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,L),{name:z.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==L)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),re.current=t}catch(e){console.error(`Error silently saving record:`,e)}},ge=(e,t)=>e?e.startsWith(`image/`)?t?(0,l.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${t})`}}):(0,l.jsx)(n.V,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,l.jsx)(n.l,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,l.jsx)(n.G,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,l.jsx)(n._t,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,l.jsx)(n.Q,{className:`w-4 h-4`}):(0,l.jsx)(n.W,{className:`w-4 h-4`}):(0,l.jsx)(n.G,{className:`w-4 h-4`}),_e=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-purple-500/10 text-purple-500`:e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?`bg-blue-500/10 text-blue-500`:e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?`bg-yellow-500/10 text-yellow-500`:e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?`bg-emerald-500/10 text-emerald-500`:`bg-foreground/5 text-foreground/40`:`bg-foreground/5 text-foreground/40`,ve=e=>{if(!e)return`FILE`;let t={"application/pdf":`PDF`,"application/zip":`ZIP`,"application/x-zip-compressed":`ZIP`,"application/x-rar-compressed":`RAR`,"application/x-7z-compressed":`7Z`,"application/json":`JSON`,"application/xml":`XML`,"application/javascript":`JS`,"application/typescript":`TS`,"application/msword":`DOC`,"application/vnd.openxmlformats-officedocument.wordprocessingml.document":`DOCX`,"application/vnd.ms-excel":`XLS`,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":`XLSX`,"application/vnd.ms-powerpoint":`PPT`,"application/vnd.openxmlformats-officedocument.presentationml.presentation":`PPTX`,"application/rtf":`RTF`,"application/x-tar":`TAR`,"application/gzip":`GZ`,"text/plain":`TXT`,"text/html":`HTML`,"text/css":`CSS`,"text/csv":`CSV`,"text/markdown":`MD`},n=e.toLowerCase();if(t[n])return t[n];let r=n.split(`/`);return r[r.length-1].replace(/^x-/,``).replace(/^vnd\..*\./,``).toUpperCase().slice(0,10)},Q=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},ye=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},be=le(e,q),xe=()=>{navigator.clipboard.writeText(be),w(!0),setTimeout(()=>w(!1),2e3)},Se=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),r=t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return n.o[r]?n.o[r]:n.o[t]?n.o[t]:n.f||n.C})(),Ce=e.buttonStyle!==`secondary`,we=e.buttonStorageStyle===`primary`,Te=e=>e.uid===r?.uid,Ee=({record:e})=>{let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||`Admin`,n=e.creatorEmail||``,r=e.creatorAvatar||``,i=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,l.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/15 text-accent flex items-center justify-center text-[8px] font-extrabold shrink-0`,children:i}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,l.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Admin Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${s.length} ${s.length===1?`item`:`items`}`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:xe,title:C?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${C?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:C?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),e.storage!==!1&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`input`,{type:`file`,ref:W,onChange:ae,className:`hidden`}),(0,l.jsxs)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${we?`btn-primary`:`btn-secondary`}`,children:[T?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(Se,{className:`w-4 h-4`}),e.buttonStorageText&&(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>g(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${Ce?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,l.jsx)(n.C,{className:`w-4 h-4`}):(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),t?(0,l.jsx)(t,{config:e,actions:{records:s,loading:f,collection:q,user:r,saveRecord:async e=>{let t=J();await(0,o.addDoc)((0,o.collection)(n.Tt,q),{uid:r.uid,recordType:`record`,creatorName:t.name,creatorEmail:t.email,creatorAvatar:t.avatar,createdAt:(0,o.serverTimestamp)(),...e})},deleteRecord:async e=>{await(0,o.deleteDoc)((0,o.doc)(n.Tt,q,e))},uploadFile:()=>W.current?.click(),openAddForm:()=>g(!0)}}):(0,l.jsxs)(l.Fragment,{children:[!f&&s.length===0&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,l.jsx)(n.C,{className:`w-6 h-6 text-accent/40`})}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All admins can view and contribute.`})]}),!f&&s.length>0&&(0,l.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,l.jsx)(n.a,{children:s.map((e,t)=>{let r=L===e.id,i=Te(e);return(0,l.jsxs)(n.i.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>pe(e),className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative cursor-pointer ${r?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,l.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),K(e.id),setTimeout(()=>K(null),2e3)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-emerald-500 hover:bg-emerald-500/10 transition-all cursor-pointer`,title:`Copy Link`,children:G===e.id?(0,l.jsx)(n.ct,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-3.5 h-3.5`})})]}),i&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),pe(e)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,l.jsx)(n.w,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),O(e.id)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-3.5 h-3.5`})})]})]}),(0,l.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,l.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&j(e)},className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`cursor-pointer hover:scale-105 transition-transform ${_e(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?ge(e.fileType,e.downloadURL):(0,l.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[se===e.id?(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,value:ue,onChange:e=>de(e.target.value),onBlur:()=>me(),onKeyDown:e=>{e.key===`Enter`&&me(),e.key===`Escape`&&ce(null)},onClick:e=>e.stopPropagation(),className:`no-glow text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full pr-12`}):(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>j(e)}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ye(e.createdAt)})]})]}),e.note&&(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),Object.entries(e).filter(([e])=>![`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`].includes(e)&&e!==`id`).slice(0,3).map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,l.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,l.jsx)(Ee,{record:e})]},e.id)})})})]})]}),!t&&(0,l.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,l.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,l.jsx)(n.B,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,l.jsxs)(`span`,{children:[`Shared between all admins · Edit and delete available on your own items only · Records: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:q}),` · Files: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`admin_files`}),` → Drive / Admin`]})]})})]})]}),(0,l.jsx)(n.a,{children:h&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!x&&g(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`form`,{onSubmit:Y,className:`p-5 flex flex-col gap-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>!x&&g(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:_,onChange:e=>v(e.target.value),placeholder:`Name *`,disabled:x,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),placeholder:`Note (optional)`,disabled:x,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:x,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:x?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,d.createPortal)((0,l.jsx)(n.a,{children:M&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,l.jsx)(n.i.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(`button`,{onClick:()=>j(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-[var(--panel-border)]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 bg-background/80 backdrop-blur-md border-b border-[var(--panel-border)] shrink-0 shadow-sm z-20`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:M.fileName||M.name}),(0,l.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[ve(M.fileType),` • `,Q(M.fileSize||0)]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.downloadURL),K(`preview`),setTimeout(()=>K(null),2e3)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 transition-colors rounded-xl shadow-sm hover:text-emerald-500 cursor-pointer`,title:`Copy Link`,children:G===`preview`?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),ce(M.id),de(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),O(M.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),(0,l.jsx)(`a`,{href:M.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>j(null),children:(0,l.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[N&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-background/80 backdrop-blur-md shadow-xl flex items-center justify-center border border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,l.jsx)(`img`,{onLoad:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,alt:M.fileName||M.name,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full object-contain drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] rounded-lg pointer-events-auto transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType?.startsWith(`video/`)?(0,l.jsx)(`video`,{onLoadedData:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,controls:!0,autoPlay:!0,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full outline-none bg-black/40 rounded-lg pointer-events-auto drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType===`application/pdf`?(0,l.jsx)(`iframe`,{onLoad:()=>P(!1),src:M.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,l.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center text-foreground/40 text-center relative z-10`,onClick:e=>{e.stopPropagation(),P(!1)},children:[(0,l.jsx)(n.G,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,l.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,l.jsx)(`span`,{className:`text-[14px] mt-2 text-foreground/60 font-medium max-w-xs`,children:`This file format cannot be previewed. Please download it instead.`})]})]})})]})]})}),document.body),(0,l.jsx)(n.a,{children:L&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>Z(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[440px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),x&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>Z(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NAME`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>B(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),placeholder:`Name *`,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NOTE`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{ne(e.target.value),e.target.style.height=`auto`,e.target.style.height=e.target.scrollHeight+`px`},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),e.target.blur())},onBlur:()=>he(),placeholder:`Add a note...`,rows:1,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50 resize-none overflow-hidden`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),H.map((e,t)=>(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let n=[...H];n[t].key=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none placeholder:text-foreground/15 pt-3 pb-0.5 caret-foreground/40`}),(0,l.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let n=[...H];n[t].value=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pt-1.5 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>U(H.filter((e,n)=>n!==t)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})})]},t)),(0,l.jsxs)(`button`,{type:`button`,onClick:()=>U([...H,{key:``,value:``}]),className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground/25 hover:text-foreground/40 transition-colors cursor-pointer mt-4 mb-4`,children:[(0,l.jsx)(n.C,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,l.jsx)(te,{isOpen:!!D,onCancel:()=>O(null),onConfirm:oe,title:`Delete Record`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:s.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:F})]})}function sn({config:e,customContent:t}){let{user:r}=m(),{config:i}=n.xt(),[s,u]=(0,a.useState)([]),[f,p]=(0,a.useState)(!0),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(``),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(!1),[T,E]=(0,a.useState)(!1),[D,O]=(0,a.useState)(null),[k,A]=(0,a.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;P(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[N,P]=(0,a.useState)(!0),[F,I]=(0,a.useState)(!1),[L,R]=(0,a.useState)(null),[z,B]=(0,a.useState)(``),[V,ne]=(0,a.useState)(``),[H,U]=(0,a.useState)([]),W=(0,a.useRef)(null),[G,K]=(0,a.useState)(null),re=(0,a.useRef)([]),ie=(e.tabName||e.pageId||`shared_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),q=`mem_${ie}_records`;(0,a.useEffect)(()=>{document.title=e.tabTitle||e.tabName||i.appName||`Firebase OS`},[e.tabTitle,e.tabName,i.appName]),(0,a.useEffect)(()=>{if(!r)return;try{let e=localStorage.getItem(`fbos_records_${q}`);e?(u(JSON.parse(e)),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}}),t=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,q),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(150)),t=>{let n=e(t.docs);u(n),p(!1),localStorage.setItem(`fbos_records_${q}`,JSON.stringify(n))},t=>{console.error(`Error listening to shared records:`,t);let r=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,q),(0,o.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),u(n),p(!1),localStorage.setItem(`fbos_records_${q}`,JSON.stringify(n))});return()=>r()});return()=>t()},[r,q]);let J=()=>({name:r.displayName||r.email?.split(`@`)[0]||`Member`,email:r.email||``,avatar:r.photoURL||``}),Y=async e=>{if(e.preventDefault(),!(!r||!_.trim())){S(!0);try{let e=J();await(0,o.addDoc)((0,o.collection)(n.Tt,q),{name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()}),v(``),b(``),g(!1)}catch(e){console.error(`Error saving shared record:`,e)}S(!1)}},ae=async e=>{let t=e.target.files?.[0];if(!(!t||!r)){E(!0);try{let e=(0,c.ref)(n.Dt,`mem_files/${`${Date.now()}_${t.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,c.uploadBytes)(e,t,{customMetadata:{ownerId:r.uid}});let i=await(0,c.getDownloadURL)(e),a=J();await(0,o.addDoc)((0,o.collection)(n.Tt,`mem_files`),{fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,uid:r.uid,uploaderEmail:r.email||`member`,sourceTab:ie,accessPrefix:`mem_`,creatorName:a.name,creatorEmail:a.email,creatorAvatar:a.avatar,createdAt:(0,o.serverTimestamp)()}),await(0,o.addDoc)((0,o.collection)(n.Tt,q),{name:t.name,note:`${t.type||`File`} · ${Q(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,creatorName:a.name,creatorEmail:a.email,creatorAvatar:a.avatar,createdAt:(0,o.serverTimestamp)()})}catch(e){console.error(`Error uploading shared file:`,e)}E(!1),W.current&&(W.current.value=``)}},oe=async()=>{if(D){I(!0);try{let e=s.find(e=>e.id===D);if(await(0,o.deleteDoc)((0,o.doc)(n.Tt,q,D)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`mem_files%2F`)[1]?.split(`?`)[0];t&&await(0,c.deleteObject)((0,c.ref)(n.Dt,`mem_files/${decodeURIComponent(t)}`)).catch(()=>{});let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`mem_files`),(0,o.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of r.docs)await(0,o.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up shared file:`,e)}O(null)}catch(e){console.error(`Error deleting shared record:`,e)}I(!1)}},[se,le]=(0,a.useState)(null),[ue,de]=(0,a.useState)(``),[fe,X]=(0,a.useState)(!1),pe=e=>{if(e.recordType===`file`){le(e.id),de(e.name);return}R(e.id),B(e.name),ne(e.note||``);let t=[`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`],n=Object.entries(e).filter(([e])=>!t.includes(e)&&e!==`id`).map(([e,t])=>({key:e,value:String(t??``)}));U(n),re.current=n.map(e=>e.key)},me=async()=>{if(!se||!ue.trim()){le(null);return}let e=s.find(e=>e.id===se);if(e&&e.name===ue.trim()){le(null);return}X(!0);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,se),{name:ue.trim()}),u(e=>e.map(e=>e.id===se?{...e,name:ue.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}X(!1),le(null)},Z=async()=>{await he(),R(null)},he=async()=>{if(!L||!z.trim())return;S(!0);let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=re.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,L),{name:z.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==L)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),re.current=t}catch(e){console.error(`Error saving record:`,e)}S(!1)},ge=(e,t)=>e?e.startsWith(`image/`)?t?(0,l.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${t})`}}):(0,l.jsx)(n.V,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,l.jsx)(n.l,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,l.jsx)(n.G,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,l.jsx)(n._t,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,l.jsx)(n.Q,{className:`w-4 h-4`}):(0,l.jsx)(n.W,{className:`w-4 h-4`}):(0,l.jsx)(n.G,{className:`w-4 h-4`}),_e=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-purple-500/10 text-purple-500`:e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?`bg-blue-500/10 text-blue-500`:e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?`bg-yellow-500/10 text-yellow-500`:e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?`bg-emerald-500/10 text-emerald-500`:`bg-foreground/5 text-foreground/40`:`bg-foreground/5 text-foreground/40`,ve=e=>{if(!e)return`FILE`;let t={"application/pdf":`PDF`,"application/zip":`ZIP`,"application/x-zip-compressed":`ZIP`,"application/x-rar-compressed":`RAR`,"application/x-7z-compressed":`7Z`,"application/json":`JSON`,"application/xml":`XML`,"application/javascript":`JS`,"application/typescript":`TS`,"application/msword":`DOC`,"application/vnd.openxmlformats-officedocument.wordprocessingml.document":`DOCX`,"application/vnd.ms-excel":`XLS`,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":`XLSX`,"application/vnd.ms-powerpoint":`PPT`,"application/vnd.openxmlformats-officedocument.presentationml.presentation":`PPTX`,"application/rtf":`RTF`,"application/x-tar":`TAR`,"application/gzip":`GZ`,"text/plain":`TXT`,"text/html":`HTML`,"text/css":`CSS`,"text/csv":`CSV`,"text/markdown":`MD`},n=e.toLowerCase();if(t[n])return t[n];let r=n.split(`/`);return r[r.length-1].replace(/^x-/,``).replace(/^vnd\..*\./,``).toUpperCase().slice(0,10)},Q=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},ye=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},be=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),r=t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return n.o[r]?n.o[r]:n.o[t]?n.o[t]:n.f||n.C})(),xe=e.buttonStyle!==`secondary`,Se=e.buttonStorageStyle===`primary`,Ce=e=>e.uid===r?.uid,we=ce(e,q),Te=()=>{navigator.clipboard.writeText(we),w(!0),setTimeout(()=>w(!1),2e3)},Ee=({record:e})=>{let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||`Member`,n=e.creatorEmail||``,r=e.creatorAvatar||``,i=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,l.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/15 text-accent flex items-center justify-center text-[8px] font-extrabold shrink-0`,children:i}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,l.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Shared Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${s.length} ${s.length===1?`item`:`items`} · Shared`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:Te,title:C?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${C?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:C?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),e.storage!==!1&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`input`,{type:`file`,ref:W,onChange:ae,className:`hidden`}),(0,l.jsxs)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${Se?`btn-primary`:`btn-secondary`}`,children:[T?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(be,{className:`w-4 h-4`}),e.buttonStorageText&&(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>g(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${xe?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,l.jsx)(n.C,{className:`w-4 h-4`}):(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),t?(0,l.jsx)(t,{config:e,actions:{records:s,loading:f,collection:q,user:r,saveRecord:async e=>{let t=J();await(0,o.addDoc)((0,o.collection)(n.Tt,q),{uid:r.uid,recordType:`record`,creatorName:t.name,creatorEmail:t.email,creatorAvatar:t.avatar,createdAt:(0,o.serverTimestamp)(),...e})},deleteRecord:async e=>{await(0,o.deleteDoc)((0,o.doc)(n.Tt,q,e))},uploadFile:()=>W.current?.click(),openAddForm:()=>g(!0)}}):(0,l.jsxs)(l.Fragment,{children:[!f&&s.length===0&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,l.jsx)(n.C,{className:`w-6 h-6 text-accent/40`})}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All team members can view and contribute.`})]}),!f&&s.length>0&&(0,l.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,l.jsx)(n.a,{children:s.map(e=>{let t=L===e.id,r=Ce(e);return(0,l.jsxs)(n.i.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>r?pe(e):null,className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative ${r?`cursor-pointer`:``} ${t?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,l.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),K(e.id),setTimeout(()=>K(null),2e3)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-emerald-500 hover:bg-emerald-500/10 transition-all cursor-pointer`,title:`Copy Link`,children:G===e.id?(0,l.jsx)(n.ct,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-3.5 h-3.5`})})]}),r&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),pe(e)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,l.jsx)(n.w,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),O(e.id)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-3.5 h-3.5`})})]})]}),(0,l.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,l.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&j(e)},className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`cursor-pointer hover:scale-105 transition-transform ${_e(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?ge(e.fileType,e.downloadURL):(0,l.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[se===e.id?(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,value:ue,onChange:e=>de(e.target.value),onBlur:()=>me(),onKeyDown:e=>{e.key===`Enter`&&me(),e.key===`Escape`&&le(null)},onClick:e=>e.stopPropagation(),className:`no-glow text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full pr-12`}):(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>j(e)}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ye(e.createdAt)})]})]}),e.note&&(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),Object.entries(e).filter(([e])=>![`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`].includes(e)&&e!==`id`).slice(0,3).map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,l.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,l.jsx)(Ee,{record:e})]},e.id)})})})]})]}),!t&&(0,l.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,l.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,l.jsx)(n.B,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,l.jsxs)(`span`,{children:[`Shared between all members · Edit and delete available on your own items only · Records: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:q}),` · Files: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`mem_files`}),` → Drive / Shared`]})]})})]})]}),(0,l.jsx)(n.a,{children:h&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!x&&g(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`form`,{onSubmit:Y,className:`p-5 flex flex-col gap-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>!x&&g(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:_,onChange:e=>v(e.target.value),placeholder:`Name *`,disabled:x,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),placeholder:`Note (optional)`,disabled:x,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:x,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:x?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,d.createPortal)((0,l.jsx)(n.a,{children:M&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,l.jsx)(n.i.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(`button`,{onClick:()=>j(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-[var(--panel-border)]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 bg-background/80 backdrop-blur-md border-b border-[var(--panel-border)] shrink-0 shadow-sm z-20`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:M.fileName||M.name}),(0,l.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[ve(M.fileType),` • `,Q(M.fileSize||0)]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.downloadURL),K(`preview`),setTimeout(()=>K(null),2e3)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 transition-colors rounded-xl shadow-sm hover:text-emerald-500 cursor-pointer`,title:`Copy Link`,children:G===`preview`?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),le(M.id),de(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),O(M.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),(0,l.jsx)(`a`,{href:M.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>j(null),children:(0,l.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[N&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-background/80 backdrop-blur-md shadow-xl flex items-center justify-center border border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,l.jsx)(`img`,{onLoad:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,alt:M.fileName||M.name,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full object-contain drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] rounded-lg pointer-events-auto transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType?.startsWith(`video/`)?(0,l.jsx)(`video`,{onLoadedData:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,controls:!0,autoPlay:!0,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full outline-none bg-black/40 rounded-lg pointer-events-auto drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType===`application/pdf`?(0,l.jsx)(`iframe`,{onLoad:()=>P(!1),src:M.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,l.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center text-foreground/40 text-center relative z-10`,onClick:e=>{e.stopPropagation(),P(!1)},children:[(0,l.jsx)(n.G,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,l.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,l.jsx)(`span`,{className:`text-[14px] mt-2 text-foreground/60 font-medium max-w-xs`,children:`This file format cannot be previewed. Please download it instead.`})]})]})})]})]})}),document.body),(0,l.jsx)(n.a,{children:L&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>Z(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[440px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),x&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>Z(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NAME`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>B(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),placeholder:`Name *`,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NOTE`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{ne(e.target.value),e.target.style.height=`auto`,e.target.style.height=e.target.scrollHeight+`px`},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),e.target.blur())},onBlur:()=>he(),placeholder:`Add a note...`,rows:1,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50 resize-none overflow-hidden`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),H.map((e,t)=>(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let n=[...H];n[t].key=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none placeholder:text-foreground/15 pt-3 pb-0.5 caret-foreground/40`}),(0,l.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let n=[...H];n[t].value=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pt-1.5 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>U(H.filter((e,n)=>n!==t)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})})]},t)),(0,l.jsxs)(`button`,{type:`button`,onClick:()=>U([...H,{key:``,value:``}]),className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground/25 hover:text-foreground/40 transition-colors cursor-pointer mt-4 mb-4`,children:[(0,l.jsx)(n.C,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,l.jsx)(te,{isOpen:!!D,onCancel:()=>O(null),onConfirm:oe,title:`Delete Record`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:s.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:F})]})}function cn(){let e=(0,u.useLocation)(),{user:t}=m(),r=n.Ct(),[i,s]=(0,a.useState)(null),[c,d]=(0,a.useState)(!0);(0,a.useEffect)(()=>{let t=!0,r=localStorage.getItem(`fbos_route_${e.pathname}`);if(r)try{let e=JSON.parse(r);s(e),d(!1);let t=e.pageName||e.tabName||e.title;t&&(document.title=t)}catch{}return(async()=>{try{let r=e.pathname;r.startsWith(`/`)&&(r=r.substring(1));let[i,a,c,l,u,f]=await Promise.allSettled([(0,o.getDoc)((0,o.doc)(n.Tt,`sys_pages`,r)),(0,o.getDoc)((0,o.doc)(n.Tt,`sys_tabs`,r)),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_pages`),(0,o.where)(`route`,`==`,e.pathname),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_pages`),(0,o.where)(`route`,`==`,r),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_tabs`),(0,o.where)(`route`,`==`,e.pathname),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_tabs`),(0,o.where)(`route`,`==`,r),(0,o.limit)(1)))]),p=null,m=null,h=(e,t)=>{if(!p&&e.status===`fulfilled`){if(e.value.exists&&e.value.exists()){let n=e.value.data();p={...n,isPrivate:t,isAdmin:n.pageType===`admin`,isShared:n.pageType===`shared`},m=e.value.id}else if(e.value.docs&&e.value.docs.length>0){let n=e.value.docs[0].data();p={...n,isPrivate:t,isAdmin:n.pageType===`admin`,isShared:n.pageType===`shared`},m=e.value.docs[0].id}}};if(h(i,!1),h(c,!1),h(l,!1),h(a,!0),h(u,!0),h(f,!0),p||(e.pathname===`/contact`?(p={route:`/contact`,template:`popup_form`,form:`contact`},m=`contact`):e.pathname===`/support`&&(p={route:`/support`,template:`popup_form`,form:`support`},m=`support`)),!t)return;if(p){if((m===`contact`||m===`support`)&&!p.form&&(p.form=m),p.pageId=m,localStorage.setItem(`fbos_route_${e.pathname}`,JSON.stringify(p)),p.form){try{let e=localStorage.getItem(`fbos_form_${p.form}`);e&&(p.formConfigOverride=JSON.parse(e))}catch{}(0,o.getDoc)((0,o.doc)(n.Tt,`sys_forms`,p.form)).then(async e=>{if(t)if(e.exists()){let t={...e.data(),id:e.id};s(e=>({...e,formConfigOverride:t})),localStorage.setItem(`fbos_form_${p.form}`,JSON.stringify(t))}else{let e;if(p.form===`contact`){let{contactFormConfig:t}=await Promise.resolve().then(()=>require(`./contactForm.config-CXyq-EbM.cjs`)).then(e=>e.n);e=t}else if(p.form===`support`){let{supportFormConfig:t}=await Promise.resolve().then(()=>require(`./supportForm.config-haLod4rv.cjs`)).then(e=>e.n);e=t}e&&(s(t=>({...t,formConfigOverride:e})),localStorage.setItem(`fbos_form_${p.form}`,JSON.stringify(e)))}})}let r=p.pageName||p.tabName||p.title;r&&(document.title=r),s(p),d(!1)}else s(`not-found`),d(!1),localStorage.removeItem(`fbos_route_${e.pathname}`)}catch{t&&c&&(s(`not-found`),d(!1))}})(),()=>{t=!1}},[e.pathname]);let[f,p]=(0,a.useState)(!1);if((0,a.useEffect)(()=>{let e;return c?e=setTimeout(()=>p(!0),150):p(!1),()=>clearTimeout(e)},[c]),c)return f?t?(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(`div`,{className:`mb-6`,children:[(0,l.jsx)(`div`,{className:`h-10 w-56 rounded-xl bg-foreground/5 animate-pulse mt-1`}),(0,l.jsx)(`div`,{className:`h-3 w-24 rounded bg-foreground/5 animate-pulse mt-3`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsx)(`div`,{className:`flex-1 glass-panel border border-[var(--panel-border)] rounded-3xl flex items-center justify-center min-h-[400px] bg-background shadow-2xl`,children:(0,l.jsx)(n.M,{className:`w-6 h-6 animate-spin text-accent`})})]})]}):(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[60vh] z-10`,children:(0,l.jsx)(n.M,{className:`w-6 h-6 animate-spin text-accent`})}):null;if(i===`not-found`)return(0,l.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1 text-center`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 bg-red-500/10 text-red-500 rounded-full flex items-center justify-center mb-6`,children:(0,l.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-8 h-8`,children:[(0,l.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,l.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,l.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]})}),(0,l.jsx)(`h2`,{className:`text-3xl font-bold mb-3 text-foreground`,children:`Page Not Found`}),(0,l.jsx)(`p`,{className:`text-foreground/60 max-w-md`,children:`The route you are looking for does not exist or has been removed.`})]})});if((i.pageId===`support`||i.isPrivate)&&!t)return(0,l.jsx)(u.Navigate,{to:`/login`,state:{from:e}});let h=r.customRoutes?.[e.pathname]||(i&&i.route?r.customRoutes?.[i.route]:null),g=i.pageName?.toLowerCase().replace(/\s+/g,`_`)||i.pageId||`custom_page`,_=`pub_${g}`,v=(i.tabName||i.pageId||i.pageName||`custom`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),y=(r.microcomponents||(typeof window<`u`?window.__FBOS_MICROCOMPONENTS__:void 0))?.[v],b=h||y||void 0;if(i.template===`none`)return i.isAdmin?(0,l.jsx)(on,{config:i,customContent:b}):i.isShared?(0,l.jsx)(sn,{config:i,customContent:b}):i.isPrivate?(0,l.jsx)(an,{config:i,customContent:b}):(0,l.jsx)(rn,{config:i,customContent:b});if(h)return(0,l.jsx)(h,{config:i});if(i.template===`board`){let e=i.isAdmin?`admin_${i.pageId||g}`:i.isShared?`mem_${i.pageId||g}`:i.isPrivate?`user_${i.pageId||g}`:_;return(0,l.jsx)(r.components?.TemplateBoard||fe,{title:i.tabTitle||i.tabName||i.title||i.pageName||`Board`,subtitle:i.route,tasksCollection:`${e}_tasks`,categoriesCollection:`${e}_categories`,config:i})}if(i.template===`table`){let e=i.isAdmin?`admin_${i.pageId||g}`:i.isShared?`mem_${i.pageId||g}`:i.isPrivate?`user_${i.pageId||g}`:_;return(0,l.jsx)(r.components?.TemplateTable||Rt,{title:i.tabTitle||i.tabName||i.title||i.pageName||`Table`,subtitle:i.route,tableCollection:`${e}_table`,config:i})}if(i.template===`calendar`){let e=i.isAdmin?`admin_${i.pageId||g}`:i.isShared?`mem_${i.pageId||g}`:i.isPrivate?`user_${i.pageId||g}`:_;return(0,l.jsx)(r.components?.TemplateCalendar||Vt,{title:i.tabTitle||i.tabName||i.title||i.pageName||`Calendar`,subtitle:i.route,eventsCollection:`${e}_events`,defaultTimeFormat:i.defaultTimeFormat||i.defaulttimeformat||`12h`,config:i})}return i.template===`inline_form`?(0,l.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-start mt-8 relative z-10 w-full min-h-[60vh]`,children:(0,l.jsx)(n.t,{isInline:!0,formId:i.form,formConfig:i.formConfigOverride})}):(0,l.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 w-full min-h-[60vh]`,children:(0,l.jsx)(n.t,{formId:i.form,formConfig:i.formConfigOverride,onClose:()=>window.history.back()})})}var ln=a.default.createContext({}),un=Object.defineProperty,dn=Object.getOwnPropertySymbols,fn=Object.prototype.hasOwnProperty,pn=Object.prototype.propertyIsEnumerable,mn=(e,t,n)=>t in e?un(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,hn=(e,t)=>{for(var n in t||={})fn.call(t,n)&&mn(e,n,t[n]);if(dn)for(var n of dn(t))pn.call(t,n)&&mn(e,n,t[n]);return e},gn=(0,a.forwardRef)((e,t)=>{let n=hn(hn({},a.useContext(ln)),e);return a.createElement(`svg`,hn({width:`1.5em`,height:`1.5em`,strokeWidth:1.5,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,color:`currentColor`,ref:t},n),a.createElement(`path`,{d:`M21.1679 8C19.6247 4.46819 16.1006 2 11.9999 2C6.81459 2 2.55104 5.94668 2.04932 11`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M17 8H21.4C21.7314 8 22 7.73137 22 7.4V3`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M2.88146 16C4.42458 19.5318 7.94874 22 12.0494 22C17.2347 22 21.4983 18.0533 22 13`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M7.04932 16H2.64932C2.31795 16 2.04932 16.2686 2.04932 16.6V21`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}))}),_n=Object.defineProperty,vn=Object.getOwnPropertySymbols,yn=Object.prototype.hasOwnProperty,bn=Object.prototype.propertyIsEnumerable,xn=(e,t,n)=>t in e?_n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Sn=(e,t)=>{for(var n in t||={})yn.call(t,n)&&xn(e,n,t[n]);if(vn)for(var n of vn(t))bn.call(t,n)&&xn(e,n,t[n]);return e},Cn=(0,a.forwardRef)((e,t)=>{let n=Sn(Sn({},a.useContext(ln)),e);return a.createElement(`svg`,Sn({width:`1.5em`,height:`1.5em`,viewBox:`0 0 24 24`,strokeWidth:1.5,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,color:`currentColor`,ref:t},n),a.createElement(`path`,{d:`M22 12C22 17.5228 17.5228 22 12 22C10.1786 22 8.47087 21.513 7 20.6622L2 21.5L2.83209 16C2.29689 14.7751 2 13.4222 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M12.9604 13.8683L15.0399 13.4624L17 14.2149V16.0385C17 16.6449 16.4783 17.1073 15.8901 16.9783C14.3671 16.6444 11.5997 15.8043 9.67826 13.8683C7.84859 12.0248 7.22267 9.45734 7.01039 8.04128C6.92535 7.47406 7.3737 7 7.94306 7H9.83707L10.572 8.96888L10.1832 11.0701`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}))}),wn=`rules_version = '2';
|
|
385
416
|
service cloud.firestore {
|
|
386
417
|
match /databases/{database}/documents {
|
|
387
418
|
|