your-ai-workflow-firebase-os 1.2.38 → 1.2.39
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.
|
@@ -131,9 +131,9 @@ export const themeConfig = {
|
|
|
131
131
|
cardRadius: ${r.cardRadius||1.5}, // 24px (2xl, 3xl)
|
|
132
132
|
modalRadius: ${r.modalRadius||2.5}, // Global popups and main internal boxes
|
|
133
133
|
}
|
|
134
|
-
};`;navigator.clipboard?.writeText(i),b(!0),setTimeout(()=>b(!1),2e3)},P=e=>{let t=Gn.find(t=>t.key===e),r=l?.colors?.[e]||{},i=o.colors?.[e]||{},a=r.background||i.background||`#ffffff`;return(0,s.jsxs)(le,{icon:t.icon,title:t.label,description:t.description,defaultOpen:n===e,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-3 p-3.5 sm:p-4 ${ie}`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,s.jsx)(`span`,{className:`text-[12.5px] font-bold text-foreground`,children:`Ready-made colour sets`}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/45 font-medium leading-snug`,children:`One click repaints light and dark together. Change anything you like afterwards.`})]}),(0,s.jsx)(`div`,{className:`flex items-center gap-3 overflow-x-auto hide-scrollbars pb-2 pt-1`,children:Un.map(t=>{let n=r.accent===t[e].accent&&l?.colors?.[e]?.buttonGradient?.[0]===t[e].gradient[0],i=t.name===`Black & White`;return(0,s.jsx)(`button`,{type:`button`,onClick:()=>j(t),"aria-label":t.name,title:t.name,className:`w-9 h-9 rounded-full shrink-0 outline-none transition-all shadow-sm relative cursor-pointer ${n?`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`}`,children:(0,s.jsx)(`span`,{className:`absolute inset-0 rounded-full border border-[var(--panel-border)]/60 dark:border-0 dark:ring-1 dark:ring-inset dark:ring-white/10`,style:i?{backgroundColor:`#ffffff`,border:`3px solid #000000`}:{backgroundImage:`linear-gradient(135deg, ${t.preview[0]}, ${t.preview[1]})`}})},t.name)})})]}),(0,s.jsx)(sr,{title:`Brand and colours`,onReset:()=>O(`Reset the colours?`,`The brand colour, the text and the two backgrounds in ${t.label.toLowerCase()} go back to how they started. Nothing else changes.`,()=>A(e,cr))}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3 items-start`,children:[(0,s.jsx)(rr,{over:a,label:`Brand colour`,hint:`Links, highlights and the main buttons. Panels follow it too.`,value:r.accent||i.accent||`#7c3aed`,onChange:t=>D(e,t)}),(0,s.jsx)(rr,{over:a,label:`Text colour`,hint:`Primary typography colour used across the app.`,value:r.foreground||i.foreground||`#111827`,onChange:t=>T(e,{foreground:t})}),(0,s.jsx)(rr,{over:a,label:`Page background`,hint:`Main background canvas colour under all content.`,value:r.background||i.background||`#ffffff`,onChange:t=>T(e,{background:t})}),(0,s.jsx)(rr,{over:a,label:`Second background`,hint:`The colour the page background fades into.`,value:r.backgroundSecondary||i.backgroundSecondary||`#f9fafb`,onChange:t=>T(e,{backgroundSecondary:t})}),(0,s.jsx)(rr,{over:a,label:`Notification dot`,hint:`Colour applied to notification badging.`,value:r.notificationIconColor||r.accent||i.notificationIconColor||`#7c3aed`,onChange:t=>T(e,{notificationIconColor:t})}),(0,s.jsx)(ir,{label:`Heading colours`,hint:`The colours big headings fade through.`,value:r.textGradient||i.textGradient,onChange:t=>T(e,{textGradient:t})})]}),(0,s.jsx)(sr,{title:`Buttons`,onReset:()=>O(`Reset the buttons?`,`Every button colour in ${t.label.toLowerCase()} goes back to how it started. Nothing else changes.`,()=>A(e,lr))}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-3 items-start`,children:[(0,s.jsx)(ir,{label:`Button colours`,hint:`The colours your main buttons fade through.`,value:r.buttonGradient||i.buttonGradient,onChange:t=>T(e,{buttonGradient:t})}),(0,s.jsx)(ir,{label:`Button colours on hover`,hint:`How a main button looks under the pointer.`,value:r.buttonHoverGradient||i.buttonHoverGradient,onChange:t=>T(e,{buttonHoverGradient:t})}),(0,s.jsx)(rr,{over:a,label:`Button text`,hint:`The writing on your main buttons.`,value:r.buttonText||i.buttonText||`#ffffff`,onChange:t=>T(e,{buttonText:t})})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2 mt-1`,children:[(0,s.jsx)(`span`,{className:`text-[10px] font-extrabold uppercase tracking-wider text-foreground/40`,children:`Quieter buttons`}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-3 items-start`,children:[(0,s.jsx)(rr,{over:a,label:`Quiet button fill`,value:r.secondaryButton?.bg||i.secondaryButton?.bg||`rgba(0, 0, 0, 0.03)`,onChange:t=>E(e,{bg:t})}),(0,s.jsx)(rr,{over:a,label:`Quiet button edge`,value:r.secondaryButton?.border||i.secondaryButton?.border||`rgba(0, 0, 0, 0.06)`,onChange:t=>E(e,{border:t})}),(0,s.jsx)(rr,{over:a,label:`Quiet button text`,value:r.secondaryButton?.text||i.secondaryButton?.text||`#111827`,onChange:t=>E(e,{text:t})})]})]}),(0,s.jsx)(sr,{title:`Panels and highlights`,onReset:()=>O(`Reset the panels?`,`Panels, edges, the focus glow and text highlighting in ${t.label.toLowerCase()} go back to how they started. Nothing else changes.`,()=>A(e,ur))}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3 items-start`,children:[(0,s.jsx)(rr,{over:a,label:`Panel fill`,hint:`Background colour of cards and panels.`,value:r.panelBg||i.panelBg||`rgba(255, 255, 255, 0.70)`,onChange:t=>T(e,{panelBg:t})}),(0,s.jsx)(rr,{over:a,label:`Panel edge`,hint:`Borders of panels, inputs and dropdowns.`,value:r.panelBorder||i.panelBorder||`rgba(0, 0, 0, 0.08)`,onChange:t=>T(e,{panelBorder:t})}),(0,s.jsx)(rr,{over:a,label:`Focus glow`,hint:`The glow around the box someone is typing in.`,value:r.glowColor||i.glowColor||`rgba(124, 58, 237, 0.30)`,onChange:t=>T(e,{glowColor:t})}),(0,s.jsx)(rr,{over:a,label:`Highlight`,hint:`The colour behind text someone has selected.`,value:r.selectionBg||i.selectionBg||`rgba(124, 58, 237, 0.30)`,onChange:t=>T(e,{selectionBg:t})}),(0,s.jsx)(rr,{over:a,label:`Highlighted text`,hint:`The colour of the selected text itself.`,value:r.selectionText||i.selectionText||`#ffffff`,onChange:t=>T(e,{selectionText:t})})]})]},e)};return(0,s.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,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,s.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,s.jsx)(`p`,{className:`text-foreground/60 text-[15px] font-medium max-w-2xl`,children:`How your site looks. Every change here shows up straight away and saves itself.`})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(W,{}),(0,s.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-5 md:p-8 shadow-2xl relative bg-background flex flex-col min-h-[600px]`,children:[(0,s.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 mb-6 pb-5 border-b border-[var(--panel-border)]/50`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Your look`}),(0,s.jsx)(`p`,{className:`text-[13.5px] font-medium text-foreground/55 mt-1.5 leading-relaxed`,children:`Pick a ready-made set, or open a section and change one thing at a time.`})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(ge,{saving:d,savedAt:p}),(0,s.jsx)(Q,{icon:y?t._t:t.at,onClick:N,children:y?`Copied`:`Copy for my assistant`}),(0,s.jsx)(Q,{icon:t.D,tone:`danger`,busy:h,disabled:!_,onClick:()=>O(`Start the whole look again?`,`Every colour, the font and the corners go back to how they were the day you installed. This cannot be undone.`,M),children:`Start again`})]})]}),l?(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,s.jsxs)(le,{icon:t.Ot,title:`Name and logo`,description:`What your site is called, and the two little pictures that stand for it.`,actions:(0,s.jsx)(Q,{icon:t.D,onClick:()=>O(`Reset the name and logo?`,`The name, the opening mode, the logo and the browser icon go back to how they started.`,()=>k(dr)),children:`Reset`}),children:[(0,s.jsx)(de,{label:`Site name`,hint:`The name people see in the top bar and on the browser tab.`,value:l.appName||``,onChange:e=>w(`appName`,e),placeholder:`Your AI Firebase`}),(0,s.jsx)(pe,{label:`How the site opens`,hint:`Light, dark, or whichever one the visitor already uses on their device.`,value:l.defaultTheme||`system`,onChange:e=>w(`defaultTheme`,e||`system`),allowEmpty:!1,options:[{value:`system`,label:`Whatever their device uses`},{value:`light`,label:`Always light`},{value:`dark`,label:`Always dark`}]}),(l.defaultTheme||`system`)===`system`&&(0,s.jsx)(me,{label:`Let visitors switch it themselves`,hint:`Shows the sun and moon button in the top bar.`,enabled:l.showThemeToggle!==!1,onChange:e=>w(`showThemeToggle`,e)}),(0,s.jsx)(or,{label:`Logo`,hint:`The little picture in the top bar. Upload yours on the Assets page, then paste its link here.`,value:l.logoUrl||``,fallback:o.logoUrl||``,onChange:e=>w(`logoUrl`,e)}),(0,s.jsx)(or,{label:`Browser tab icon`,hint:`The tiny picture on the browser tab. Same place, same idea.`,value:l.faviconUrl||``,fallback:o.faviconUrl||``,onChange:e=>w(`faviconUrl`,e)}),(0,s.jsxs)(`p`,{className:`text-[11.5px] text-foreground/45 font-medium leading-relaxed px-1`,children:[`These two pictures are yours. Your assistant is told never to change them, so this page is the only place they ever move. Upload a new one on the`,` `,(0,s.jsx)(c.Link,{to:`/assets`,className:`text-accent font-bold hover:underline`,children:`Assets page`}),`.`]})]}),Gn.map(e=>P(e.key)),(0,s.jsxs)(le,{icon:t.g,title:`Lettering and corners`,description:`The typeface, and how rounded everything looks.`,defaultOpen:!1,actions:(0,s.jsx)(Q,{icon:t.D,onClick:()=>O(`Reset the lettering and corners?`,`The typeface and every corner go back to how they started.`,()=>k(fr)),children:`Reset`}),children:[(0,s.jsx)(pe,{label:`Typeface`,hint:`The lettering used everywhere on your site.`,value:l.fontFamily||`Inter`,onChange:e=>w(`fontFamily`,e||`Inter`),allowEmpty:!1,options:Wn.map(e=>({value:e,label:e}))}),(0,s.jsx)(pe,{label:`Corners`,hint:`Keep the rounding we ship with, or set each one yourself.`,value:l.cornerRounding||`default`,onChange:e=>w(`cornerRounding`,e||`default`),allowEmpty:!1,options:[{value:`default`,label:`Standard rounding`},{value:`custom`,label:`Set them myself`}]}),l.cornerRounding===`custom`&&(0,s.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,s.jsx)(ar,{label:`Buttons`,hint:`How round every button is.`,value:l.cornerRadii?.buttonRadius??.75,onChange:e=>w(`cornerRadii`,{...l.cornerRadii||{},buttonRadius:e})}),(0,s.jsx)(ar,{label:`Boxes people type in`,hint:`Form fields and search boxes.`,value:l.cornerRadii?.inputRadius??.75,onChange:e=>w(`cornerRadii`,{...l.cornerRadii||{},inputRadius:e})}),(0,s.jsx)(ar,{label:`Cards`,hint:`The panels your content sits on.`,value:l.cornerRadii?.cardRadius??1.5,onChange:e=>w(`cornerRadii`,{...l.cornerRadii||{},cardRadius:e})}),(0,s.jsx)(ar,{label:`Pop-ups`,hint:`Dialogs and confirmation boxes.`,value:l.cornerRadii?.modalRadius??2.5,onChange:e=>w(`cornerRadii`,{...l.cornerRadii||{},modalRadius:e})})]})]}),(0,s.jsx)(ke,{title:`Not sure which colours suit you?`,prompt:`I run a small design studio. Suggest one colour scheme for my site — a brand colour, a page background and a text colour for light mode and for dark mode — and give me each one as a colour code I can paste into the fields on my Theme page. Pick a typeface from Inter, Outfit, Roboto, Space Grotesk or Plus Jakarta Sans to go with it.`})]}):(0,s.jsx)(`div`,{className:`flex items-center justify-center flex-1 text-foreground/40 py-16`,children:(0,s.jsx)(t.L,{className:`w-6 h-6 animate-spin text-accent`})})]})]}),(0,s.jsx)(re,{isOpen:!!x,title:x?.title||``,message:x?.message||``,confirmText:`Reset`,cancelText:`Keep it`,isProcessing:h,onCancel:()=>S(null),onConfirm:()=>{x?.apply(),S(null)}})]})}var mr={route:`/page_1`,pageName:`New Page`,pageTitle:`My New Page`,template:`none`,form:``},hr={tabName:`New Page`,iconName:``,route:`/new-page`,tabTitle:`Your Page`,template:`none`,form:``},gr={tabName:`New Admin Page`,iconName:``,route:`/new-admin-page`,tabTitle:`Admin Page`,template:`none`,form:``},_r={tabName:`New Team Page`,iconName:``,route:`/new-team-page`,tabTitle:`Team Page`,template:`none`,form:``},vr=[{id:`home`,title:`Home`,path:`/`,type:`public`,isSystem:!0,enabled:!0}],yr=e=>[...e,...vr.filter(t=>!e.some(e=>e.id===t.id))],br={public:`Anyone`,user:`Signed-in users`,internal:`Your team`,admin:`Admins only`},xr=e=>(e||``).trim().toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9_-]/g,``),Sr=(e,t,n,r)=>{let i=e.findIndex(e=>e.id===t);if(i===-1)return null;let a=r&&e[0]?.id===r?1:0,o=n===`up`?Math.max(a,i-1):Math.min(e.length-1,i+1);if(o===i||o<a)return null;let s=[...e],[c]=s.splice(i,1);return s.splice(o,0,c),s},Cr=()=>Object.fromEntries(M()),wr=(e,t=!1)=>{let n={};for(let[r,i]of Object.entries(Cr())){let a=!!i.isPublic;if(a!==e)continue;let o=i.config||{};!t&&o.enabled===!1||(n[r]={id:r,title:a?o.pageName||o.pageTitle||o.title||r:o.tabName||o.tabTitle||o.title||r,path:o.route?o.route.startsWith(`/`)?o.route:`/`+o.route:`/`+r,type:a?`public`:w(o.pageType),isSystem:!1,enabled:o.enabled!==!1,fromFile:!0})}return n};function Tr({value:e,onChange:n,busy:r}){return(0,s.jsx)(`div`,{className:`shrink-0`,onClick:e=>e.stopPropagation(),children:(0,s.jsx)(t.n,{compact:!0,portal:!0,direction:`auto`,className:`console-select`,ariaLabel:`Who can open this page`,value:e,disabled:r,onChange:e=>n(e),options:g.map(e=>({value:e,label:br[e]}))})})}var Er=`Add it here — its web address, a name, and what you would like to see on it — then copy the sentence for your assistant.`,Dr=[{value:`none`,label:`From scratch`},{value:`board`,label:`Board`},{value:`table`,label:`Table`},{value:`calendar`,label:`Calendar`},{value:`drive`,label:`Files`}],Or=[`board`,`table`,`calendar`,`drive`],kr={board:`board`,table:`table`,calendar:`calendar`,drive:`files`},Ar=e=>(e||``).split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``),jr=(e,t)=>t?.contentKey||t?.tabName||t?.pageName||t?.pageId||e.title,Mr=(e,t)=>`src/your-ai-workflow-firebase-os/microcomponents/${Ar(jr(e,t))||`Page`}Content.tsx`,Nr=(e,t)=>{let n=String(t?.route||``).trim();return n?n.startsWith(`/`)?n:`/`+n:e.path||``},Pr=(e,t)=>Nr(e,t).replace(/^\/+/,``)?String(t?.brief||``).trim()?``:`Say what you would like to see on this page, and this sentence is ready to copy.`:`Give this page a web address and it will be created — then this sentence is ready to copy.`,Fr=(e,t)=>{let n=Nr(e,t),r=String(t?.tabName||t?.pageName||``).trim(),i=r===`New page`?``:r,a=String(t?.template||``),o=String(t?.form||``).trim(),s=String(t?.brief||``).trim(),c=[`My app already has a page${i?` called ${i}`:``} at ${n}. It is already made and it is already in the menu — do not create a page, a web address or a settings file for it, and do not edit any other file.`,`Write one file: ${Mr(e,t)}, with a default export. That file is what the page shows.`];return Or.includes(a)&&c.push(`The page already starts from the ${kr[a]} layout — build on it, do not rebuild it.`),o&&c.push(`Show my form ${Vr(o)} on it with <ContactPopup formId='${o}' /> — never write a form by hand.`),c.push(`Here is what I would like on it: ${s||`___`}`),c.join(`
|
|
135
|
-
`)},Ir=(e,t)=>{let n=e=>{let{_uiKey:t,pageType:n,route:r,contentKey:i,brief:a,...o}=e||{};return o},r=n(e),i=n(t),a=new Set([...Object.keys(r),...Object.keys(i)]);for(let e of a)if((r[e]??``)!==(i[e]??``))return!0;return!1},Lr=(e,t)=>{let{_uiKey:n,...r}=e||{};return Object.keys(r).length>0?{...r,pageType:t}:{pageType:t}},Rr=`w-6 h-5 rounded-md flex items-center justify-center text-foreground/35 hover:text-foreground hover:bg-foreground/[0.07] transition-colors cursor-pointer`,zr=`hidden sm:inline-flex items-center gap-1 text-[10px] font-bold uppercase tracking-widest text-foreground/40 border border-[var(--panel-border)] px-2 py-0.5 rounded-md`,Br=e=>{let t=typeof window<`u`?window.location.host:``;return t?`${t}${e}`:e},Vr=e=>e.replace(/[_-]+/g,` `).replace(/^./,e=>e.toUpperCase());function Hr({page:e,config:t,forms:n,saving:i,onSave:a,addressTaken:o,actions:c,footer:l,isNew:u}){let d=e.type===`public`,f=d?`pageName`:`tabName`,p=d?`pageTitle`:`tabTitle`,[m,h]=(0,r.useState)(()=>({...t||{}})),[g,_]=(0,r.useState)(``),v=(e,t)=>h(n=>({...n,[e]:t})),y=e=>{h(t=>({...t,...e}));let n={...t||{},...m,...e};delete n._uiKey,a(n)},b=e=>{(t||{})[e]!==m[e]&&y({[e]:m[e]})},x=String(m.route??``).replace(/^\/+/,``),S=(0,s.jsx)(de,{label:`Web address`,hint:u?`Where this page lives, e.g. /photos. The page is created as soon as you fill this in.`:`Where this page lives, e.g. /pricing`,prefix:`/`,value:x,onChange:e=>{v(`route`,e),g&&_(``)},onBlur:()=>{let n=xr(x);if(!n){_(`Give this page a web address, for example pricing`);return}if(o(e.id,n)){_(`Another page already lives at this address. Pick a different one.`);return}_(``),n===String(t?.route??``).replace(/^\/+/,``)?v(`route`,`/`+n):y({route:`/`+n})},error:g,placeholder:`photos`});return(0,s.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[u&&S,(0,s.jsx)(de,{label:d?`Name in the menu`:`Name in the dashboard`,hint:d?`What visitors see in the site menu.`:`What people see in the dashboard menu.`,value:m[f]??``,onChange:e=>v(f,e),onBlur:()=>b(f),placeholder:d?`Pricing`:`Photo Drive`}),(0,s.jsx)(de,{label:`Page heading`,hint:`The big heading people read at the top of the page.`,value:m[p]??``,onChange:e=>v(p,e),onBlur:()=>b(p),placeholder:`Our prices`}),!u&&S,!d&&(0,s.jsx)(Oe,{label:`Icon`,hint:`Shown next to the name in the dashboard menu.`,value:m.iconName??``,onChange:e=>y({iconName:e})}),!d&&(0,s.jsx)(pe,{label:`Starting layout`,hint:`What the page starts as. Your assistant fills in the rest when you ask.`,value:Dr.some(e=>e.value===m.template)?m.template:`none`,onChange:e=>y({template:e}),options:Dr,allowEmpty:!1}),(0,s.jsx)(pe,{label:`Form`,hint:d?`The form on this page. Only forms for website visitors are listed. Change a form itself under Forms.`:`The form on this page. Only forms for signed-in people are listed. Change a form itself under Forms.`,value:m.form??``,onChange:e=>y({form:e}),options:n.map(e=>({value:e,label:Vr(e)})),placeholder:`No form`}),(0,s.jsx)(fe,{label:`What would you like to see on this page?`,hint:`In your own words. This is what your assistant builds — it goes at the end of the sentence below.`,value:m.brief??``,onChange:e=>v(`brief`,e),onBlur:()=>b(`brief`),rows:4,placeholder:`A private photo gallery where I can upload pictures, put them in albums and open one full screen.`}),l,(0,s.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 pt-2 border-t border-[var(--panel-border)]/60`,children:[(0,s.jsx)(ge,{saving:i}),(0,s.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 ml-auto`,children:c})]})]})}function Ur(){let{userRole:e}=A(),n=(0,c.useLocation)(),[a,o]=(0,r.useState)(()=>{try{if(typeof window<`u`){let e=localStorage.getItem(`fbos_swr_pages`);if(e)return yr(JSON.parse(e))}}catch{}return vr}),[l,u]=(0,r.useState)(()=>{try{return sessionStorage.getItem(`fbos_pages_expandedId`)||null}catch{return null}}),d=(0,r.useRef)(l),[f,p]=(0,r.useState)(!1),[m,h]=(0,r.useState)(()=>{try{if(typeof window<`u`){let e=localStorage.getItem(`fbos_swr_page_configs`);if(e)return JSON.parse(e)}}catch{}return{}}),[g,_]=(0,r.useState)({}),[v,y]=(0,r.useState)({}),[b,x]=(0,r.useState)(null),[S,C]=(0,r.useState)(null),[T,E]=(0,r.useState)(!1),D=(0,r.useRef)(null);(0,r.useEffect)(()=>{function e(e){D.current&&!D.current.contains(e.target)&&p(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let[O,k]=(0,r.useState)(new Set),[j,M]=(0,r.useState)(new Set),[N,P]=(0,r.useState)([]),[F,I]=(0,r.useState)([]),L=e=>(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden,...e.removed?{removed:!0}:{}});(0,r.useEffect)(()=>{let e=(0,i.onSnapshot)((0,i.doc)(t.Pt,`sys_configs`,`page_order`),e=>{let t=L(e.exists()&&e.data().order||[]);P(t),k(new Set(t.filter(e=>e.hidden).map(e=>e.id)))}),n=(0,i.onSnapshot)((0,i.doc)(t.Pt,`sys_configs`,`tab_order`),e=>{let t=L(e.exists()&&e.data().order||[]);I(t),M(new Set(t.filter(e=>e.hidden).map(e=>e.id)))});return()=>{e(),n()}},[]),(0,r.useEffect)(()=>{let e=n.pathname.split(`/pages/`)[1]?.split(`/`)[0];e&&!l&&a.some(t=>t.id===e)&&u(e)},[n.pathname,a]),(0,r.useEffect)(()=>{d.current=l;try{l?sessionStorage.setItem(`fbos_pages_expandedId`,l):sessionStorage.removeItem(`fbos_pages_expandedId`)}catch{}},[l]);let R=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=R.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,r.useEffect)(()=>{(async()=>{try{let[e,n]=await Promise.all([(0,i.getDocs)((0,i.collection)(t.Pt,`sys_pages`)),(0,i.getDocs)((0,i.collection)(t.Pt,`sys_tabs`))]),r=[`home`,`drive`,`assets`,`contact`,`support`,`theme`,`page_order`,`tab_order`],a=[],s={};e.forEach(e=>{if(!r.includes(e.id)){let t=e.data();a.push({id:e.id,title:t.pageName||t.title||e.id,path:t.route||`/`+e.id,type:`public`,isSystem:!1,enabled:t.enabled!==!1}),s[e.id]=t}}),n.forEach(e=>{if(!r.includes(e.id)){let t=e.data(),n=w(t.pageType);a.push({id:e.id,title:t.tabName||t.title||e.id,path:t.route||`/`+e.id,type:n,isSystem:!1,enabled:t.enabled!==!1}),s[e.id]=t}});let c=Cr(),l={...wr(!0,!0),...wr(!1,!0)};for(let[e,t]of Object.entries(l)){if(s[e])continue;let n=a.find(e=>e.path===t.path);if(n){n.fromFile=!0;continue}a.push(t),s[e]=c[e]?.config||{}}o(e=>{let t=yr(e.filter(e=>(e.isSystem||e.id.startsWith(`draft_`))&&e.id!==`drive`)),n=a.filter(e=>!t.some(t=>t.id===e.id)),r=[...t,...n];return typeof window<`u`&&localStorage.setItem(`fbos_swr_pages`,JSON.stringify(r)),r}),h(e=>{let t={...e,...s};return typeof window<`u`&&localStorage.setItem(`fbos_swr_page_configs`,JSON.stringify(t)),t})}catch(e){console.error(`Error loading custom pages`,e)}})()},[]);let[ee,z]=(0,r.useState)([`contact`]),[te,B]=(0,r.useState)([`support`]);(0,r.useEffect)(()=>{let e=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},n={...t.a,...e},r=new Set([`contact`]),a=new Set([`support`]);Object.entries(n).forEach(([e,t])=>{t.formType===`private`?a.add(t.systemName||e):r.add(t.systemName||e)}),(0,i.getDocs)((0,i.collection)(t.Pt,`sys_forms`)).then(e=>{e.docs.forEach(e=>{e.data().formType===`private`?a.add(e.id):r.add(e.id)}),z(Array.from(r)),B(Array.from(a))}).catch(e=>{console.warn(`Failed fetching sys_forms in PagesAdmin:`,e),z(Array.from(r)),B(Array.from(a))})},[]);let ne=async(e,n,r)=>{if(n.route&&!n.route.startsWith(`/`)&&(n.route=`/`+n.route),!String(n.route||``).replace(/^\/+/,``).trim()){h(t=>({...t,[e]:n}));return}let s=a.find(t=>t.id===e),c=r||s?.type||n.pageType||(e.startsWith(`pub_`)?`public`:void 0),l=c===`public`?`sys_pages`:`sys_tabs`;c&&c!==`public`?n.pageType=c:delete n.pageType;let f=Object.fromEntries(Object.entries(n).filter(([e,t])=>t!==void 0)),p=n.route?n.route.replace(/^\/+/,``).replace(/[^a-zA-Z0-9_-]/g,`_`).toLowerCase():e;f.contentKey||=p,n={...n,contentKey:f.contentKey},_(t=>({...t,[e]:!0,[p]:!0}));try{if(p!==e&&p.trim()!==``&&p!==`draft`){try{let{deleteDoc:n}=await import(`firebase/firestore`);await n((0,i.doc)(t.Pt,l,e))}catch{}await(0,i.setDoc)((0,i.doc)(t.Pt,l,p),f),o(t=>t.map(t=>t.id===e?{...t,id:p,_uiKey:t._uiKey||e,path:n.route,title:n.pageName||n.tabName||n.title||t.title}:t)),d.current===e&&(u(p),window.history.replaceState(null,``,`/pages/${p}`)),h(t=>{let r={...t};return r[p]=n,delete r[e],r});let r=c===`public`,a=r?`page_order`:`tab_order`,s=r?N:F;if(!s.some(e=>e.id===p)){let n=[{id:p,hidden:!1},...s.filter(t=>t.id!==e)];try{await(0,i.setDoc)((0,i.doc)(t.Pt,`sys_configs`,a),{order:n})}catch(e){console.error(`Failed to update tab order:`,e)}}}else await(0,i.setDoc)((0,i.doc)(t.Pt,l,e),f),h(t=>({...t,[e]:n})),o(t=>t.map(t=>t.id===e?{...t,path:n.route||t.path,title:n.pageName||n.tabName||n.title||t.title}:t))}catch(t){console.error(`Failed to save ${e} config:`,t)}finally{setTimeout(()=>{_(t=>({...t,[e]:!1,[p]:!1}))},500)}},V=e=>{let t=`draft_`+Math.floor(Math.random()*1e5),n={id:t,title:`New page`,path:``,type:e,isSystem:!1,enabled:!0},r=e===`public`?{route:``,pageName:``,pageTitle:``,form:``,brief:``}:{route:``,tabName:``,tabTitle:``,iconName:``,template:`none`,form:``,brief:``,pageType:e};o(e=>[...e,n]),h(e=>({...e,[t]:r})),u(t),p(!1),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView?.({behavior:`smooth`,block:`center`})},100)},H=e=>e.id.startsWith(`draft_`);if(e!==`admin`)return(0,s.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,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,s.jsx)(t.C,{className:`w-12 h-12 text-red-500 mb-4`}),(0,s.jsx)(`h2`,{className:`text-2xl font-bold`,children:`Access Denied`}),(0,s.jsx)(`p`,{className:`text-foreground/60`,children:`You do not have permission to view pages configuration.`})]})});let U=async(e,n,r)=>{let s=r===`public`,c=s?`page_order`:`tab_order`,l=s?N:F,u=(s?O:j).has(e);o(a.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,i.setDoc)((0,i.doc)(t.Pt,`sys_configs`,c),{order:d})},G=e=>!!e.fromFile&&(e.type===`public`?N:F).some(t=>t.id===e.id&&t.removed),K=async(e,n)=>{if(e.type===n)return;let r=e.type;o(t=>t.map(t=>t.id===e.id?{...t,type:n}:t)),_(t=>({...t,[e.id]:!0}));let a=Lr(m[e.id],n);try{await(0,i.setDoc)((0,i.doc)(t.Pt,`sys_tabs`,e.id),a,{merge:!0}),h(t=>t[e.id]?{...t,[e.id]:{...t[e.id],pageType:n}}:t)}catch(t){console.error(`Failed to change the audience of ${e.id}:`,t),o(t=>t.map(t=>t.id===e.id?{...t,type:r}:t))}finally{_(t=>({...t,[e.id]:!1}))}},q=(e,t)=>{if(!t){if(H({id:e})){o(t=>t.filter(t=>t.id!==e)),h(t=>{let n={...t};return delete n[e],n}),l===e&&u(null);return}x(e)}},J=async()=>{if(b){E(!0);try{let{deleteDoc:e,collection:n,getDocs:r,doc:i,getDoc:s,query:c,where:d}=await import(`firebase/firestore`),{ref:f,deleteObject:p}=await import(`firebase/storage`),h=a.find(e=>e.id===b),g=h?.type===`public`?`sys_pages`:`sys_tabs`;if(g===`sys_tabs`&&h){let a=m[b];if(!a)try{let e=await s(i(t.Pt,`sys_tabs`,b));e.exists()&&(a=e.data())}catch{}let o=(a?.tabName||a?.pageId||b).toLowerCase().replace(/[^a-z0-9]+/g,`_`),l=[`admin_${o}_records`,`mem_${o}_records`,`user_${o}_records`],u={[`admin_${o}_records`]:{prefix:`admin_files`,driveCollection:`admin_files`},[`mem_${o}_records`]:{prefix:`mem_files`,driveCollection:`mem_files`},[`user_${o}_records`]:{prefix:`user_files`,driveCollection:`user_files`}},h=[];for(let i of l)h.push((async()=>{try{let a=await r(n(t.Pt,i)),o=u[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(t.It,`${o.prefix}/${decodeURIComponent(s)}`)).catch(()=>{});let l=await r(c(n(t.Pt,o.driveCollection),d(`downloadURL`,`==`,a.downloadURL)));await Promise.all(l.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`])h.push((async()=>{try{let a=await r(c(n(t.Pt,i),d(`sourceTab`,`==`,o)));await Promise.all(a.docs.map(async n=>{let r=n.data();if(r.downloadURL)try{let e=`${i}%2F`,n=r.downloadURL.split(e)[1]?.split(`?`)[0];n&&await p(f(t.It,`${i}/${decodeURIComponent(n)}`)).catch(()=>{})}catch{}await e(n.ref)}))}catch{}})());await Promise.all(h)}await e(i(t.Pt,g,b));let _=g===`sys_pages`?`page_order`:`tab_order`,v=g===`sys_pages`?N:F,{setDoc:y}=await import(`firebase/firestore`),x=h?.fromFile?[...v.filter(e=>e.id!==b),{id:b,hidden:!0,removed:!0}]:v.filter(e=>e.id!==b);await y(i(t.Pt,`sys_configs`,_),{order:x}),o(e=>e.filter(e=>e.id!==b)),l===b&&u(null)}catch(e){console.error(`Error deleting page:`,e)}E(!1),x(null)}},Y=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,fromFile:!1};o(e=>[...e,n]);let r={...m[e.id]||{},route:n.path,pageName:n.title};n.type!==`public`&&(r.tabName=n.title,r.pageType=n.type),h(e=>({...e,[t]:r})),u(t),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})},100)},ie=async(e,n)=>{if(e.id===`home`)return;let r=e.type===`public`,o=r?`page_order`:`tab_order`,s=[...r?N:F];a.filter(e=>e.type===`public`===r&&e.id!==`home`&&!s.some(t=>t.id===e.id)).forEach(e=>s.push({id:e.id,hidden:!1}));let c=Sr(s,e.id,n,r?`home`:void 0);if(c){r?P(c):I(c);try{await(0,i.setDoc)((0,i.doc)(t.Pt,`sys_configs`,o),{order:c})}catch(e){console.error(`Failed to reorder pages:`,e)}}},ae=(e,t)=>{let n=t.replace(/[^a-zA-Z0-9_-]/g,`_`).toLowerCase();return a.some(r=>{if(r.id===e)return!1;let i=String(m[r.id]?.route??r.path??``).replace(/^\/+/,``).toLowerCase();return i!==``&&i===t||r.id===n})},oe=e=>e===`admin`?gr:e===`internal`?_r:e===`public`?mr:hr,se=async()=>{let e=a.find(e=>e.id===S);if(!e){C(null);return}y(t=>({...t,[e.id]:!0}));let t=m[e.id]||{};await ne(e.id,{...oe(e.type),...t.contentKey?{contentKey:t.contentKey}:{},...t.brief?{brief:t.brief}:{}}),y(t=>({...t,[e.id]:!1})),C(null)},X=[{id:`public`,title:`Anyone`,icon:t.X,description:`Pages on your website. Anyone can open them, signed in or not, and they show up in the site menu.`,filter:e=>e.type===`public`},{id:`user`,title:`Signed-in users`,icon:t.I,description:`Pages in the dashboard that every signed-in person can open. Each person sees only their own information.`,filter:e=>e.type===`user`},{id:`internal`,title:`Your team`,icon:t.et,description:`Pages in the dashboard for the people you marked as team members under Users, plus admins. Everyone who can open them sees the same information — signed-in users never see them at all.`,filter:e=>e.type===`internal`},{id:`admin`,title:`Admins only`,icon:t.C,description:`Pages in the dashboard only admins can open.`,filter:e=>e.type===`admin`}];return(0,s.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,s.jsx)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,s.jsxs)(`div`,{children:[(0,s.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:`Your Pages`}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/pages`]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(W,{}),(0,s.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,s.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,s.jsx)(`div`,{children:(0,s.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 leading-relaxed max-w-3xl`,children:`Add a page here — its web address, its name, who it is for and what you would like on it — then copy the sentence it writes for you into your assistant's chat. The assistant only fills the page in; creating, renaming, reordering, hiding and deleting all happen right here.`})}),(0,s.jsx)(`div`,{className:`relative z-50 shrink-0 flex items-center gap-1`,children:(0,s.jsxs)(`div`,{className:`relative`,children:[(0,s.jsx)(t.r,{variant:`secondary`,onClick:()=>p(!f),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 a page`,children:(0,s.jsx)(t.k,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,s.jsx)(t.s,{children:f&&(0,s.jsxs)(t.o.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-56 glass-popover border border-[var(--panel-border)] rounded-2xl p-2 z-50 flex flex-col gap-1`,children:[(0,s.jsx)(`span`,{className:`px-3 pt-1 pb-2 text-[10px] font-bold uppercase tracking-widest text-foreground/40`,children:`Add a page for`}),[`public`,`user`,`internal`,`admin`].map(e=>(0,s.jsx)(`button`,{onClick:()=>V(e),className:`text-left px-3 py-2 text-[13px] font-bold text-foreground/70 hover:text-foreground hover:bg-foreground/5 rounded-lg transition-colors cursor-pointer`,children:br[e]},e))]})})]})})]}),(0,s.jsx)(`div`,{ref:R,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:X.map((e,n)=>{let r=a.filter(e.filter).filter(e=>!G(e)),i=e.id===`public`?N:F,o=r.sort((e,t)=>{if(e.id===`home`)return-1;if(t.id===`home`)return 1;let n=i.findIndex(t=>t.id===e.id),r=i.findIndex(e=>e.id===t.id);return n===-1&&r===-1?0:n===-1?1:r===-1?-1:n-r}),c=e.icon,d=e=>e.type===`public`?O.has(e.id):j.has(e.id),f=o.filter(e=>!d(e)),p=o.filter(e=>d(e)),h=(n,r)=>{let i=n.id===`home`,a=l===n.id,o=H(n),c=!n.isSystem||i,d=o?`Not saved yet — give it a web address`:r?`Hidden`:n.type===`public`?`Shown in the site menu`:`Shown in the dashboard`;return(0,s.jsxs)(`div`,{id:`page-${n.id}`,onClick:()=>{if(c){let e=a?null:n.id;u(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 ${c?`cursor-pointer hover:border-accent/40`:``} ${r?`opacity-60 bg-foreground/[0.01] border-[var(--panel-border)]/50`:`border-transparent hover:border-[var(--panel-border)]`}`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between w-full gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-start gap-2 flex-1 min-w-0`,children:[!i&&!o&&(0,s.jsxs)(`div`,{className:`flex flex-col shrink-0 pt-0.5`,onClick:e=>e.stopPropagation(),children:[(0,s.jsx)(`button`,{type:`button`,title:`Move up`,"aria-label":`Move ${n.title} up`,onClick:()=>ie(n,`up`),className:Rr,children:(0,s.jsx)(t.pt,{className:`w-3.5 h-3.5`})}),(0,s.jsx)(`button`,{type:`button`,title:`Move down`,"aria-label":`Move ${n.title} down`,onClick:()=>ie(n,`down`),className:Rr,children:(0,s.jsx)(t.gt,{className:`w-3.5 h-3.5`})})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,s.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground truncate`,children:n.title}),n.fromFile&&(0,s.jsxs)(`span`,{className:zr,title:`Your assistant built this one. Delete hides it and gives you the sentence that removes its files.`,children:[(0,s.jsx)(t.$,{className:`w-3 h-3`}),` Built for you`]})]}),(0,s.jsxs)(`span`,{className:`text-[11.5px] font-medium text-foreground/45 truncate`,children:[d,n.path?` · Web address ${Br(n.path)}`:``]})]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 self-end sm:self-auto`,children:[n.type!==`public`&&!o&&(0,s.jsx)(Tr,{value:n.type,busy:g[n.id],onChange:e=>K(n,e)}),!i&&!o&&(0,s.jsx)(Q,{icon:r?t.et:t.tt,onClick:e=>{e.stopPropagation(),U(n.id,n.isSystem,n.type)},children:r?`Show`:`Hide`}),c?(0,s.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 shrink-0 ${a?`rotate-180`:``}`,children:(0,s.jsx)(t.gt,{className:`w-3.5 h-3.5`})}):(0,s.jsx)(`div`,{className:`w-[24px] shrink-0`})]})]}),(0,s.jsxs)(t.s,{children:[a&&i&&(0,s.jsx)(t.o.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-1`,onClick:e=>e.stopPropagation(),children:(0,s.jsx)(ke,{compact:!0,title:`Change the home page`,prompt:`On my home page, change the big heading to Bright Studio and the line under it to We design websites for small businesses. Add a button that says Get in touch which opens my contact form as a pop-up, and below it three short sections: what we do, who it is for, and how to reach us.`})}),a&&!n.isSystem&&m[n.id]&&(0,s.jsx)(t.o.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-1`,onClick:e=>e.stopPropagation(),children:(0,s.jsx)(Hr,{page:n,config:m[n.id],forms:n.type===`public`?ee:te,saving:g[n.id],isNew:o,onSave:e=>ne(n.id,e),addressTaken:ae,footer:(0,s.jsx)(ke,{compact:!0,title:`Then copy this into your assistant’s chat`,prompt:Fr(n,m[n.id]),locked:!!Pr(n,m[n.id]),lockedHint:Pr(n,m[n.id])}),actions:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Q,{icon:t.at,onClick:()=>Y(n),children:`Duplicate`}),!n.fromFile&&Ir(m[n.id],oe(n.type))&&(0,s.jsx)(Q,{icon:t.D,tone:`danger`,busy:v[n.id],onClick:()=>C(n.id),children:`Reset`}),!n.isSystem&&(0,s.jsx)(Q,{icon:t.y,tone:`danger`,onClick:()=>q(n.id,n.isSystem),children:`Delete`})]})},n.id)})]})]},`${e.id}-${n._uiKey||n.id}`)};return(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex flex-col relative`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-3 mb-2 border-b border-[var(--panel-border)]/50 pb-4`,children:[(0,s.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,s.jsx)(c,{className:`w-4 h-4 text-accent`})}),(0,s.jsx)(`h2`,{className:`text-xl font-extrabold tracking-tight text-foreground`,children:e.title})]}),(0,s.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,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center gap-3 rounded-2xl border border-dashed border-[var(--panel-border)] px-5 py-4`,children:[(0,s.jsx)(Q,{icon:t.k,onClick:()=>V(e.id),children:`Add a page`}),(0,s.jsx)(`p`,{className:`text-[12.5px] text-foreground/55 font-medium leading-relaxed`,children:Er})]}):(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[f.map(e=>h(e,!1)),p.length>0&&(0,s.jsxs)(`details`,{className:`mt-4 group/details`,children:[(0,s.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,s.jsx)(t.gt,{className:`w-3.5 h-3.5 group-open/details:-rotate-180 transition-transform`}),`Hidden pages (`,p.length,`)`]}),(0,s.jsx)(`div`,{className:`flex flex-col gap-4 mt-4`,children:p.map(e=>h(e,!0))})]})]}),n<X.length-1&&(0,s.jsx)(`div`,{className:`w-full border-t border-[var(--panel-border)]/70 my-10`})]},e.id)})})]})]}),(0,s.jsx)(re,{isOpen:!!b,onCancel:()=>x(null),onConfirm:J,title:`Delete this page?`,message:`The page and everything saved on it will be gone for good. This cannot be undone.`,confirmText:`Delete page`,isProcessing:T}),(0,s.jsx)(re,{isOpen:!!S,onCancel:()=>C(null),onConfirm:se,title:`Reset this page?`,message:`Its name, heading, web address, icon and form go back to how they started. What people have saved on the page is kept.`,confirmText:`Reset page`,isProcessing:!!S&&!!v[S]})]})}var Wr=new Set([`contact`,`support`]),Gr=[{value:`text`,label:`Short text`},{value:`textarea`,label:`Long text`},{value:`email`,label:`Email`},{value:`tel`,label:`Phone`},{value:`number`,label:`Number`},{value:`currency`,label:`Money`},{value:`checkbox`,label:`Yes-no`},{value:`select`,label:`Choose one`}],Kr={age:`Age`},qr=e=>Gr.find(t=>t.value===e)?.label||Kr[e||``]||`Short text`,Jr=e=>Gr.some(t=>t.value===e)||!e?Gr:[...Gr,{value:e,label:qr(e)}],Yr={public:`Anyone`,private:`Signed-in users`},Xr=e=>(e||``).toLowerCase().trim().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``),Zr=(e,t)=>{if(!t.includes(e))return e;let n=2;for(;t.includes(`${e}_${n}`);)n++;return`${e}_${n}`},Qr=(e,t,n)=>{if(!(!e.name||e.name===Xr(e.label||``)))return e.name;let r=Xr(t);return r?Zr(r,n.filter(t=>t!==e).map(e=>e.name)):``},$r=()=>({name:``,type:`text`,label:``,placeholder:``,required:!1}),ei={firstForm:`Add the form here — its fields and who can fill it in — then tell your assistant which page should use it.`,forPage:(e,t)=>`Use the form called ${e||t} (its id is ${t}) on the page I name — show it with <ContactPopup formId='${t}' />. Do not create a form, do not change this form's fields, do not write a form by hand.`,more:`On my page at /contact, show my form called Get in touch built into the page instead of as a pop-up, and after sending take people to the home page. Do not create a form, do not change its questions, and keep everything else on the page as it is.`};function ti({choices:e,onChange:n}){return(0,s.jsx)(ue,{label:`Choices`,hint:`The options people pick from.`,children:(0,s.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.length===0&&(0,s.jsx)(`span`,{className:`text-[12px] text-foreground/40 font-medium px-1`,children:`No choices yet — add the first one.`}),e.map((r,i)=>(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(`input`,{type:`text`,value:r,"aria-label":`Choice ${i+1}`,placeholder:`e.g. Under 1,000`,onChange:t=>n(e.map((e,n)=>n===i?t.target.value:e)),className:oe}),(0,s.jsx)(Q,{icon:t.d,tone:`danger`,title:`Remove choice ${i+1}`,onClick:()=>n(e.filter((e,t)=>t!==i)),children:`Remove`})]},i)),(0,s.jsx)(`div`,{children:(0,s.jsx)(Q,{icon:t.k,onClick:()=>n([...e,``]),children:`Add choice`})})]})})}function ni(){let{userRole:e}=A(),n=(0,c.useNavigate)(),a=t.Mt(),o=()=>{let e=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},n={...t.a,contact:a?.defaultConfigs?.contactForm||t.a.contact,support:a?.defaultConfigs?.supportForm||t.a.support};for(let[t,r]of Object.entries(e))n[t]=r;return n},[l,u]=(0,r.useState)(()=>{try{if(typeof window<`u`){let e=localStorage.getItem(`fbos_swr_forms`);if(e)return JSON.parse(e)}let e={...t.a,contact:a?.defaultConfigs?.contactForm||t.a.contact,support:a?.defaultConfigs?.supportForm||t.a.support},n=(typeof window<`u`?window.__FBOS_FORMS__:null)||{};for(let[t,r]of Object.entries(n))e[t]=r;let r={};for(let[t,n]of Object.entries(e)){let e=JSON.parse(JSON.stringify(n));e._uiKey=Math.random().toString(36).substring(7),r[t]=e}return r}catch{return{}}}),[d,f]=(0,r.useState)(()=>!(typeof window<`u`&&localStorage.getItem(`fbos_swr_forms`))),[p,m]=(0,r.useState)({}),[h,g]=(0,r.useState)(null),[_,v]=(0,r.useState)(new Set),[y,b]=(0,r.useState)({}),[x,S]=(0,r.useState)(null),[C,w]=(0,r.useState)(!1),[T,E]=(0,r.useState)({}),D=(0,r.useRef)({}),O=(e,t)=>{D.current={...D.current,[e]:t},E(D.current)};(0,r.useEffect)(()=>{k()},[]);let k=async()=>{try{f(!0);let e=await(0,i.getDocs)((0,i.collection)(t.Pt,`sys_forms`)),n={},r=new Set;e.forEach(e=>{if(e.id!==`pubForm`&&e.id!==`userForm`){let t=e.data();t._uiKey=l[e.id]?._uiKey||t._uiKey||Math.random().toString(36).substring(7),n[e.id]=t,r.add(e.id)}}),v(r);try{await(0,i.deleteDoc)((0,i.doc)(t.Pt,`sys_forms`,`pubForm`)),await(0,i.deleteDoc)((0,i.doc)(t.Pt,`sys_forms`,`userForm`))}catch{}let a=o();for(let[e,t]of Object.entries(a))if(!n[e]){let r={...t};r._uiKey=l[e]?._uiKey||Math.random().toString(36).substring(7),n[e]=r}else if(n[e]._uiKey=l[e]?._uiKey||n[e]._uiKey||Math.random().toString(36).substring(7),!n[e].fields||n[e].fields.length===0){let t=a[e];n[e].fields=t.fields||[]}let s={};for(let e of Object.keys(a))n[e]&&(s[e]=n[e]);for(let e of Object.keys(n))s[e]||(s[e]=n[e]);let c=window.location.pathname.split(`/forms/`)[1]?.split(`/`)[0];c&&s[c]&&b({[c]:!0}),D.current={},E({}),u(s),typeof window<`u`&&localStorage.setItem(`fbos_swr_forms`,JSON.stringify(s))}catch(e){console.error(`Failed to load forms:`,e)}finally{f(!1)}},j=async(e,n)=>{let r={...n};l[e]?._uiKey&&(r._uiKey=l[e]._uiKey),delete r.submitPage,e===`contact`?(r.systemName=`contact`,r.formType=`public`):e===`support`&&(r.systemName=`support`,r.formType=`private`);let a=r.systemName||e;if(a!==e&&a.trim()!==``){u(t=>{let n={};for(let i of Object.keys(t))i===e?n[a]=r:n[i]=t[i];return n}),y[e]&&b(t=>{let n={};for(let r of Object.keys(t))r===e?n[a]=t[r]:n[r]=t[r];return n}),m(e=>({...e,[a]:!0}));try{await(0,i.setDoc)((0,i.doc)(t.Pt,`sys_forms`,a),r),await(0,i.deleteDoc)((0,i.doc)(t.Pt,`sys_forms`,e)),localStorage.setItem(`fbos_custom_form_${a}`,`true`),localStorage.removeItem(`fbos_custom_form_${e}`),localStorage.setItem(`fbos_form_${a}`,JSON.stringify(r)),localStorage.removeItem(`fbos_form_${e}`)}catch(e){console.error(`Failed to migrate form map ID:`,e)}finally{setTimeout(()=>{m(e=>({...e,[a]:!1}))},500)}}else{u(t=>({...t,[e]:r})),m(t=>({...t,[e]:!0}));try{await(0,i.setDoc)((0,i.doc)(t.Pt,`sys_forms`,e),r),localStorage.setItem(`fbos_custom_form_${e}`,`true`),localStorage.setItem(`fbos_form_${e}`,JSON.stringify(r))}catch(e){console.error(`Failed to save form:`,e)}finally{setTimeout(()=>{m(t=>({...t,[e]:!1}))},500)}}},M=(e,t,n)=>O(e,{...t,...n}),N=(e,t,n)=>{let r={...t,...n};O(e,r),j(e,r)},P=e=>{let t=D.current[e];t&&j(e,t)},F=(e,t,n)=>N(e,t,{fields:n}),[I,L]=(0,r.useState)(!1),R=async()=>{if(I)return;L(!0);let e=`new_form_${Date.now().toString().slice(-4)}`,r={title:`New form`,systemName:e,formType:`public`,redirectTo:``,buttonName:`Send`,submitText:`Send`,fields:[],enabled:!0,_uiKey:Math.random().toString(36).substring(7)};try{m(t=>({...t,[e]:!0})),await(0,i.setDoc)((0,i.doc)(t.Pt,`sys_forms`,e),r),u(t=>({[e]:r,...t})),b(t=>({[e]:!0,...t})),n(`/forms/${e}`)}catch(e){console.error(`Failed to create form`,e)}finally{m(t=>({...t,[e]:!1})),L(!1)}},ee=async e=>{if(!Wr.has(e)){w(!0);try{await(0,i.deleteDoc)((0,i.doc)(t.Pt,`sys_forms`,e)),u(t=>{let n={...t};return delete n[e],n}),n(`/forms`)}catch(e){console.error(`Failed to delete form`,e)}finally{w(!1),S(null)}}},z=async e=>{if(!_.has(e)){S(null);return}w(!0);let n=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},r=Wr.has(e)||!!n[e]||!!a?.defaultConfigs?.[e]||!!a?.defaultConfigs?.[`${e}Form`];try{r?(m(t=>({...t,[e]:!0})),await(0,i.deleteDoc)((0,i.doc)(t.Pt,`sys_forms`,e)),localStorage.removeItem(`fbos_form_${e}`),localStorage.removeItem(`fbos_custom_form_${e}`),await k(),setTimeout(()=>m(t=>({...t,[e]:!1})),500)):await j(e,o().contact||o().support)}catch(e){console.error(`Reset failed:`,e)}finally{w(!1),S(null)}};if(e!==`admin`)return(0,s.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,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,s.jsx)(t._,{className:`w-12 h-12 text-red-500 mb-4`}),(0,s.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,s.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 te=e=>{b(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})},B=Object.keys(y).find(e=>y[e]),ne=(e,n,r,i,a)=>{let o=(t,r)=>{let o=a.map((e,n)=>n===i?{...e,...t}:e);r?F(e,n,o):M(e,n,{fields:o})},c=t=>{let r=i+t;if(r<0||r>=a.length)return;let o=[...a];[o[i],o[r]]=[o[r],o[i]],F(e,n,o)},l=r.type!==`checkbox`&&r.type!==`select`;return(0,s.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)] p-4 sm:p-5 flex flex-col gap-5`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[(0,s.jsxs)(`span`,{className:`text-[13px] font-bold text-foreground`,children:[`Question `,i+1,` `,(0,s.jsxs)(`span`,{className:`text-foreground/40 font-medium`,children:[`· `,qr(r.type)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,s.jsx)(Q,{icon:t.St,disabled:i===0,title:`Move up`,onClick:()=>c(-1),children:`Up`}),(0,s.jsx)(Q,{icon:t.Tt,disabled:i===a.length-1,title:`Move down`,onClick:()=>c(1),children:`Down`}),(0,s.jsx)(Q,{icon:t.y,tone:`danger`,title:`Remove question ${i+1}`,onClick:()=>F(e,n,a.filter((e,t)=>t!==i)),children:`Remove`})]})]}),(0,s.jsx)(de,{label:`Question`,hint:`What you are asking for, in the words the person will read.`,value:r.label||``,placeholder:`e.g. What is your budget?`,onChange:e=>o({label:e,name:Qr(r,e,a)},!1),onBlur:()=>P(e)}),(0,s.jsx)(pe,{label:`Kind of answer`,hint:`Sets the box people type into and what counts as a valid answer.`,value:r.type||`text`,options:Jr(r.type),allowEmpty:!1,onChange:e=>o(e===`select`?{type:e,options:r.options||[]}:{type:e},!0)}),(0,s.jsx)(me,{label:`Required`,hint:`On means the form cannot be sent until this is answered.`,enabled:!!r.required,onChange:e=>o({required:e},!0)}),r.type===`select`&&(0,s.jsx)(ti,{choices:r.options||[],onChange:e=>o({options:e},!0)}),r.type===`currency`&&(0,s.jsx)(de,{label:`Currency symbol`,hint:`Shown inside the box, before the amount.`,value:r.currencySymbol||``,placeholder:`$`,onChange:e=>o({currencySymbol:e},!1),onBlur:()=>P(e)}),l&&(0,s.jsx)(de,{label:`Example answer`,hint:`Faint grey text inside the box, to show people what you expect.`,value:r.placeholder||``,placeholder:`e.g. jane@example.com`,onChange:e=>o({placeholder:e},!1),onBlur:()=>P(e)})]},i)},V=(e,n)=>{let r=T[e]||n,i=Wr.has(e),a=r.formType||`public`,o=r.fields||[],c=_.has(e);return(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,s.jsxs)(le,{icon:t.g,title:`Basics`,description:`What people see at the top of this form and on its button.`,children:[(0,s.jsx)(de,{label:`Form name`,hint:`The heading at the top of the form.`,value:r.title||``,placeholder:`e.g. Get in touch`,onChange:t=>M(e,r,{title:t}),onBlur:()=>P(e)}),(0,s.jsx)(de,{label:`Button text`,hint:`The words on the button that sends the form.`,value:r.buttonName||r.submitText||``,placeholder:`e.g. Send message`,onChange:t=>M(e,r,{buttonName:t,submitText:t}),onBlur:()=>P(e)})]}),(0,s.jsx)(le,{icon:t.p,title:`Who it is for`,description:`Who can fill this in, and where their answers land.`,children:(0,s.jsx)(pe,{label:`Who it is for`,hint:i?`This form comes with your site, so who it is for cannot change. Answers arrive in your Inbox.`:`Anyone means visitors who are not signed in — their answers arrive in your Inbox under From anyone. Signed-in users means people with an account — their answers arrive under From signed-in users.`,value:a,allowEmpty:!1,disabled:i,options:[{value:`public`,label:`Anyone`},{value:`private`,label:`Signed-in users`}],onChange:t=>N(e,r,{formType:t})})}),(0,s.jsx)(le,{icon:t.T,title:`After sending`,description:`What happens the moment someone sends this form.`,children:(0,s.jsx)(de,{label:`Where to send them next`,hint:`Leave this empty to show a thank-you message instead. Or give a web address, like /pricing, to take them there.`,value:r.redirectTo||``,placeholder:`/pricing`,onChange:t=>M(e,r,{redirectTo:t}),onBlur:()=>P(e)})}),(0,s.jsxs)(le,{icon:t.R,title:`Questions`,description:`Everything this form asks for, in the order people answer it.`,actions:(0,s.jsx)(Q,{icon:t.k,onClick:()=>F(e,r,[...o,$r()]),children:`Add question`}),children:[o.length===0?(0,s.jsx)(`p`,{className:`text-[12.5px] text-foreground/55 font-medium leading-relaxed`,children:`No questions yet. Add the first one with the button above.`}):o.map((t,n)=>ne(e,r,t,n,o)),o.length>0&&(0,s.jsx)(`div`,{className:`flex justify-start`,children:(0,s.jsx)(Q,{icon:t.k,onClick:()=>F(e,r,[...o,$r()]),children:`Add question`})})]}),(c||!i)&&(0,s.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[c&&(0,s.jsx)(Q,{icon:t.D,tone:`danger`,onClick:()=>S({kind:`reset`,id:e}),children:`Reset this form`}),!i&&(0,s.jsx)(Q,{icon:t.y,tone:`danger`,onClick:()=>S({kind:`delete`,id:e}),children:`Delete this form`})]}),(0,s.jsx)(ke,{compact:!0,title:`Ask your assistant to put this form on a page`,prompt:ei.forPage(r.title||``,e)})]})};return(0,s.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,s.jsx)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,s.jsxs)(`div`,{children:[(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/forms`,B?`/${B}`:``]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(W,{}),(0,s.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,s.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,s.jsxs)(`div`,{children:[(0,s.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Your forms`}),(0,s.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`Every form on your site, and the questions it asks. Answers arrive in your Inbox.`})]}),(0,s.jsx)(`div`,{className:`relative z-50 shrink-0 flex items-center justify-end`,children:(0,s.jsx)(t.r,{variant:`secondary`,onClick:R,title:`Add a form`,disabled:I,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:I?(0,s.jsx)(t.L,{className:`w-4 h-4 text-foreground/60 animate-spin`}):(0,s.jsx)(t.k,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})})})]}),(0,s.jsx)(`div`,{className:`p-6 md:p-8 flex flex-col gap-4 overflow-y-auto`,children:Object.keys(l).length===0&&!d?(0,s.jsx)(`div`,{className:`flex flex-col gap-4`,children:(0,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-3 p-10 glass-panel rounded-3xl border border-[var(--panel-border)] border-dashed`,children:[(0,s.jsx)(t.O,{className:`w-6 h-6 text-foreground/40`}),(0,s.jsx)(`p`,{className:`text-[13px] font-bold text-foreground/60`,children:`You have no forms yet.`}),(0,s.jsx)(Q,{icon:t.k,onClick:R,children:`New form`}),(0,s.jsx)(`p`,{className:`text-[12.5px] text-foreground/55 font-medium leading-relaxed text-center max-w-md`,children:ei.firstForm})]})}):(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,s.jsx)(t.s,{children:Object.entries(l).map(([e,n])=>{let r=T[e]||n,i=y[e],a=p[e],o=(r.fields||[]).length;return(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},transition:{duration:.35,ease:`easeOut`},onClick:()=>te(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 ${i?`border-[var(--panel-border)] bg-background/50`:`border-transparent hover:border-[var(--panel-border)]`} flex-shrink-0 ${r.enabled===!1?`opacity-40 grayscale bg-foreground/[0.01] border-[var(--panel-border)]/50`:``}`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between w-full`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-1 w-full sm:w-auto pr-4`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground break-words ml-1 leading-snug`,children:r.title||`Untitled form`}),a&&(0,s.jsx)(t.L,{className:`w-3 h-3 animate-spin text-accent ml-2 shrink-0`})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5 ml-1`,children:[(0,s.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest border px-2 py-0.5 rounded-md shrink-0 ${r.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:Yr[r.formType||`public`]}),(0,s.jsx)(`span`,{className:`text-[11px] font-medium text-foreground/45`,children:o===1?`1 question`:`${o} questions`})]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5 w-full sm:w-auto justify-end mt-2 sm:mt-0 shrink-0`,children:[(0,s.jsx)(Q,{icon:t.et,onClick:e=>{e.stopPropagation(),g(r)},children:`Preview`}),(0,s.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 ${i?`rotate-180`:``}`,children:(0,s.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,s.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})})]})]}),(0,s.jsx)(t.s,{children:i&&(0,s.jsx)(t.o.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:V(e,n)})})]},n._uiKey||e)})}),d&&(0,s.jsxs)(`div`,{className:`flex items-center justify-center gap-3 p-6 glass-panel rounded-2xl border border-[var(--panel-border)]/40 bg-foreground/[0.01] mt-2 animate-pulse`,children:[(0,s.jsx)(t.L,{className:`w-4 h-4 animate-spin text-accent`}),(0,s.jsx)(`span`,{className:`text-[12px] font-bold text-foreground/50 tracking-wider uppercase select-none`,children:`Loading your forms`})]}),(0,s.jsx)(`div`,{className:`w-full border-t border-[var(--panel-border)]/70 mt-6 mb-2`}),(0,s.jsx)(ke,{title:`Everything else is your assistant's job`,prompt:ei.more})]})})]})]}),(0,s.jsx)(re,{isOpen:!!x,onCancel:()=>S(null),onConfirm:()=>{x&&(x.kind===`delete`?ee(x.id):z(x.id))},title:x?.kind===`reset`?`Reset this form`:`Delete this form`,message:x?.kind===`reset`?`Undo every change made to ${l[x.id]?.title||x.id} and put it back the way it shipped. Answers already collected are kept.`:`Permanently delete ${x?l[x.id]?.title||x.id:``}. This cannot be undone. Answers already collected are kept.`,confirmText:x?.kind===`reset`?`Reset form`:`Delete form`,isProcessing:C}),h&&(0,s.jsx)(t.t,{formConfig:h,onClose:()=>g(null)})]})}function ri({config:e,customContent:n}){let{config:i}=t.At();return(0,r.useEffect)(()=>{document.title=e.pageName||e.pageTitle||i.appName||`Your AI Firebase`},[e.pageName,e.pageTitle,i.appName]),(0,s.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,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]}),(0,s.jsx)(`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,s.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,s.jsx)(t.wt,{className:`w-4 h-4`}),` Go Back`]})}),(0,s.jsx)(t.o.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:n?(0,s.jsx)(`div`,{className:`fbos-content-slot flex-1 p-4 md:p-8`,children:(0,s.jsx)(n,{config:e})}):e.form?(0,s.jsx)(`div`,{className:`fbos-content-slot flex-1 flex flex-col items-center justify-start p-4 md:p-8`,children:(0,s.jsx)(t.t,{isInline:!0,formId:e.form})}):(0,s.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center opacity-50 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,s.jsx)(t.S,{className:`w-8 h-8 md:w-10 md:h-10 mb-4 text-accent/70`}),(0,s.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/70`,children:`This page is empty`}),(0,s.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 max-w-sm leading-relaxed`,children:`Ask your AI assistant what you would like to see here and it will build it for you.`})]})})]})}function ii({config:e,customContent:n}){let{user:a}=A(),{config:c}=t.At(),[u,d]=(0,r.useState)([]),[f,p]=(0,r.useState)(!0),[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(``),[v,y]=(0,r.useState)(``),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(null),w=(0,r.useRef)(null),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(null),[k,j]=(0,r.useState)(null),M=e=>{if(j(e),e){let t=e.fileType||``;F(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},N=k,[P,F]=(0,r.useState)(!0),[I,L]=(0,r.useState)(!1),[R,ee]=(0,r.useState)(null),[z,te]=(0,r.useState)(``),[B,ne]=(0,r.useState)(``),[V,H]=(0,r.useState)([]),U=(0,r.useRef)(null),G=`user_${(e.tabName||e.pageId||`user_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`)}_records`;(0,r.useEffect)(()=>{document.title=e.tabTitle||e.tabName||c.appName||`Your AI Firebase`},[e.tabTitle,e.tabName,c.appName]),(0,r.useEffect)(()=>{if(!a)return;try{let e=localStorage.getItem(`fbos_records_${G}`);e?(d(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}}),n=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,G),(0,i.where)(`uid`,`==`,a.uid),(0,i.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),d(n),p(!1),localStorage.setItem(`fbos_records_${G}`,JSON.stringify(n))},e=>{console.error(`Error fetching records:`,e),p(!1)});return()=>n()},[a,G]),(0,r.useEffect)(()=>{f||localStorage.setItem(`fbos_records_${G}`,JSON.stringify(u))},[u,f,G]);let K=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=await(0,i.addDoc)((0,i.collection)(t.Pt,G),{name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,createdAt:(0,i.serverTimestamp)()});d(t=>[{id:e.id,name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,createdAt:Date.now()},...t]),_(``),y(``),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)}},q=async e=>{let n=e.target.files?.[0];if(!(!n||!a)){E(!0);try{let e=`user_files/${`${Date.now()}_${n.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,r=(0,o.ref)(t.It,e);await(0,o.uploadBytes)(r,n,{customMetadata:{ownerId:a.uid}});let s=await(0,o.getDownloadURL)(r);if(w.current)w.current(n,s,{uid:a.uid,storagePath:e});else{let e=await(0,i.addDoc)((0,i.collection)(t.Pt,G),{name:n.name,note:`${n.type||`File`} · ${ge(n.size)}`,uid:a.uid,recordType:`file`,fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:s,createdAt:(0,i.serverTimestamp)()});d(t=>[{id:e.id,name:n.name,note:`${n.type||`File`} · ${ge(n.size)}`,uid:a.uid,recordType:`file`,fileName:n.name,fileType:n.type,fileSize:n.size,downloadURL:s,createdAt:Date.now()},...t])}}catch(e){console.error(`Error uploading file:`,e)}E(!1),U.current&&(U.current.value=``)}},J=async()=>{if(D){L(!0);try{let e=u.find(e=>e.id===D);if(await(0,i.deleteDoc)((0,i.doc)(t.Pt,G,D)),e?.recordType===`file`&&e.downloadURL)try{let n=e.downloadURL.split(`user_files%2F`)[1]?.split(`?`)[0];n&&await(0,o.deleteObject)((0,o.ref)(t.It,`user_files/${decodeURIComponent(n)}`)).catch(()=>{})}catch(e){console.error(`Error cleaning up user file:`,e)}d(e=>e.filter(e=>e.id!==D)),O(null)}catch(e){console.error(`Error deleting record:`,e)}L(!1)}},[Y,ie]=(0,r.useState)(null),[ae,oe]=(0,r.useState)(``),[se,X]=(0,r.useState)(!1),[ce,Z]=(0,r.useState)(null),Q=(0,r.useRef)([]),le=e=>{if(e.recordType===`file`){ie(e.id),oe(e.name);return}ee(e.id),te(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??``)}));H(n),Q.current=n.map(e=>e.key)},ue=async()=>{if(!Y||!ae.trim()){ie(null);return}let e=u.find(e=>e.id===Y);if(e&&e.name===ae.trim()){ie(null);return}X(!0);try{await(0,i.updateDoc)((0,i.doc)(t.Pt,G,Y),{name:ae.trim()}),d(e=>e.map(e=>e.id===Y?{...e,name:ae.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}X(!1),ie(null)},de=async()=>{await fe(),ee(null)},fe=async()=>{if(!R||!z.trim())return;x(!0);let e={};V.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=V.map(e=>e.key.trim()).filter(Boolean),r=Q.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,i.deleteField)()});try{await(0,i.updateDoc)((0,i.doc)(t.Pt,G,R),{name:z.trim(),note:B.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:z.trim(),note:B.trim()};return r.forEach(e=>{delete t[e]}),V.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),Q.current=n}catch(e){console.error(`Error saving record:`,e)}x(!1)},pe=(e,n)=>e?e.startsWith(`image/`)?n?(0,s.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${n})`}}):(0,s.jsx)(t.J,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,s.jsx)(t.f,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,s.jsx)(t.Q,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,s.jsx)(t.Et,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,s.jsx)(t.ot,{className:`w-4 h-4`}):(0,s.jsx)(t.Z,{className:`w-4 h-4`}):(0,s.jsx)(t.Q,{className:`w-4 h-4`}),me=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`,he=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)},ge=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]},_e=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},ve=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.c[r]?t.c[r]:t.c[n]?t.c[n]:t.h||t.k})(),ye=e.buttonStyle!==`secondary`,be=e.buttonStorageStyle===`primary`;return(0,s.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,s.jsx)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,s.jsxs)(`div`,{children:[(0,s.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||`User Page`}),e.route&&(0,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(W,{}),(0,s.jsxs)(t.o.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,s.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,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,s.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${u.length} ${u.length===1?`item`:`items`}`})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.storage!==!1&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`input`,{type:`file`,ref:U,onChange:q,className:`hidden`}),(0,s.jsxs)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>U.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`} ${be?`btn-primary`:`btn-secondary`}`,children:[T?(0,s.jsx)(t.L,{className:`w-4 h-4 animate-spin`}):(0,s.jsx)(ve,{className:`w-4 h-4`}),e.buttonStorageText&&(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,s.jsx)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>h(!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`} ${ye?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,s.jsx)(t.k,{className:`w-4 h-4`}):(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,s.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,s.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,s.jsx)(t.L,{className:`w-8 h-8 text-accent animate-spin`})}),n?(0,s.jsx)(`div`,{className:`fbos-content-slot`,children:(0,s.jsx)(n,{config:e,actions:{records:u,loading:f,collection:G,user:a,saveRecord:async e=>{let n={id:`temp_`+Date.now(),uid:a.uid,recordType:`record`,createdAt:Date.now(),...e};d(e=>[n,...e]),await(0,i.addDoc)((0,i.collection)(t.Pt,G),{uid:a.uid,recordType:`record`,createdAt:(0,i.serverTimestamp)(),...e})},updateRecord:async(e,n)=>{d(t=>t.map(t=>t.id===e?{...t,...n}:t)),await(0,i.updateDoc)((0,i.doc)(t.Pt,G,e),n)},deleteRecord:async e=>{await(0,i.deleteDoc)((0,i.doc)(t.Pt,G,e))},startEdit:e=>le(e),confirmDelete:e=>O(e),uploadFile:()=>U.current?.click(),openAddForm:()=>h(!0),setAddForm:e=>C(()=>e),setFileHandler:e=>{w.current=e}}})}):(0,s.jsxs)(s.Fragment,{children:[!f&&u.length===0&&(0,s.jsxs)(t.o.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,s.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,s.jsx)(t.k,{className:`w-6 h-6 text-accent/40`})}),(0,s.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,s.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&&u.length>0&&(0,s.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,s.jsx)(t.s,{children:u.map((e,n)=>{let r=R===e.id;return(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},transition:{delay:n*.03,duration:.25},onClick:()=>le(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,s.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,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),Z(e.id),setTimeout(()=>Z(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:ce===e.id?(0,s.jsx)(t._t,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-3.5 h-3.5`})}),(0,s.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,s.jsx)(t.rt,{className:`w-3.5 h-3.5`})})]}),(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),le(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,s.jsx)(t.A,{className:`w-3.5 h-3.5`})}),(0,s.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,s.jsx)(t.y,{className:`w-3.5 h-3.5`})})]}),(0,s.jsxs)(`div`,{className:`flex items-start gap-3 mb-3`,children:[(0,s.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&M(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 ${me(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?pe(e.fileType,e.downloadURL):(0,s.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,s.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[Y===e.id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:ae,onChange:e=>oe(e.target.value),onBlur:()=>ue(),onKeyDown:e=>{e.key===`Enter`&&ue(),e.key===`Escape`&&ie(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,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,s.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>M(e)}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:_e(e.createdAt)})]})]}),e.note&&(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,s.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,s.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e))]},e.id)})})})]})]}),!n&&(0,s.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,s.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,s.jsx)(t.K,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,s.jsxs)(`span`,{children:[`Each user sees their own data only · Edit and delete available on all items · Records: `,(0,s.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:G}),` · Files: `,(0,s.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`user_files`}),` → Drive / User`]})]})})]})]}),(0,s.jsx)(t.s,{children:m&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>!b&&h(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,s.jsx)(t.o.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:S?r.default.createElement(S,{onSave:async e=>{x(!0);try{await(0,i.addDoc)((0,i.collection)(t.Pt,G),{uid:a.uid,recordType:`record`,createdAt:(0,i.serverTimestamp)(),...e}),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)},onClose:()=>!b&&h(!1),saving:b}):(0,s.jsxs)(`form`,{onSubmit:K,className:`p-5 flex flex-col gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>!b&&h(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,s.jsx)(t.d,{className:`w-4 h-4`})})]}),(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:g,onChange:e=>_(e.target.value),placeholder:`Name *`,disabled:b,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,s.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),placeholder:`Note (optional)`,disabled:b,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,s.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,s.jsx)(t.r,{type:`submit`,isLoading:b,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:b?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,l.createPortal)((0,s.jsx)(t.s,{children:N&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,s.jsx)(t.o.div,{onClick:()=>M(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,s.jsx)(`button`,{onClick:()=>M(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,s.jsx)(t.d,{className:`w-5 h-5`})}),(0,s.jsxs)(t.o.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,s.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,s.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,s.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:N.fileName||N.name}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[he(N.fileType),` • `,ge(N.fileSize||0)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(N.downloadURL),Z(`preview`),setTimeout(()=>Z(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:ce===`preview`?(0,s.jsx)(t._t,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{M(null),ie(N.id),oe(N.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,s.jsx)(t.A,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{M(null),O(N.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,s.jsx)(t.y,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:N.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,s.jsx)(t.rt,{className:`w-4 h-4`})})]})]}),(0,s.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>M(null),children:(0,s.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[P&&(0,s.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,s.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,s.jsx)(t.L,{className:`w-5 h-5 text-accent animate-spin`})})}),N.fileType?.startsWith(`image/`)?(0,s.jsx)(`img`,{onLoad:()=>F(!1),onError:()=>F(!1),src:N.downloadURL,alt:N.fileName||N.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 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):N.fileType?.startsWith(`video/`)?(0,s.jsx)(`video`,{onLoadedData:()=>F(!1),onError:()=>F(!1),src:N.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 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):N.fileType===`application/pdf`?(0,s.jsx)(`iframe`,{onLoad:()=>F(!1),src:N.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,s.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(),F(!1)},children:[(0,s.jsx)(t.Q,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,s.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,s.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,s.jsx)(t.s,{children:R&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>de(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,s.jsx)(t.o.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,s.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),b&&(0,s.jsx)(t.L,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>de(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,s.jsx)(t.d,{className:`w-4 h-4`})})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.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,s.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>te(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>fe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.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,s.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:B,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:()=>fe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),V.map((e,n)=>(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let t=[...V];t[n].key=e.target.value,H(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>fe(),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,s.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let t=[...V];t[n].value=e.target.value,H(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>fe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>H(V.filter((e,t)=>t!==n)),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,s.jsx)(t.d,{className:`w-3 h-3`})})]},n)),(0,s.jsxs)(`button`,{type:`button`,onClick:()=>H([...V,{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,s.jsx)(t.k,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,s.jsx)(re,{isOpen:!!D,onCancel:()=>O(null),onConfirm:J,title:`Delete Record`,message:(0,s.jsxs)(s.Fragment,{children:[`Are you sure you want to delete `,(0,s.jsx)(`strong`,{className:`text-foreground font-extrabold break-words mx-1`,children:u.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:I})]})}function ai({config:e,customContent:n}){let{user:a}=A(),{config:c}=t.At(),[u,d]=(0,r.useState)([]),[f,p]=(0,r.useState)(!0),[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(``),[v,y]=(0,r.useState)(``),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(null),w=(0,r.useRef)(null),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(null),[k,j]=(0,r.useState)(null),M=e=>{if(j(e),e){let t=e.fileType||``;F(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},N=k,[P,F]=(0,r.useState)(!0),[I,L]=(0,r.useState)(!1),[R,ee]=(0,r.useState)(null),[z,te]=(0,r.useState)(``),[B,ne]=(0,r.useState)(``),[V,H]=(0,r.useState)([]),U=(0,r.useRef)(null),[G,K]=(0,r.useState)(null),q=(0,r.useRef)([]),J=`admin_${(e.tabName||e.pageId||`admin_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`)}_records`;(0,r.useEffect)(()=>{document.title=e.tabTitle||e.tabName||c.appName||`Your AI Firebase`},[e.tabTitle,e.tabName,c.appName]);let Y=()=>({name:a.displayName||a.email?.split(`@`)[0]||`Admin`,email:a.email||``,avatar:a.photoURL||``});(0,r.useEffect)(()=>{if(!a)return;try{let e=localStorage.getItem(`fbos_records_${J}`);e?(d(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}}),n=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,J),(0,i.orderBy)(`createdAt`,`desc`),(0,i.limit)(150)),t=>{let n=e(t.docs);d(n),p(!1),localStorage.setItem(`fbos_records_${J}`,JSON.stringify(n))},n=>{console.error(`Error listening to admin records:`,n);let r=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,J),(0,i.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),d(n),p(!1),localStorage.setItem(`fbos_records_${J}`,JSON.stringify(n))});return()=>r()});return()=>n()},[a,J]);let ie=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Pt,J),{name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,i.serverTimestamp)()}),_(``),y(``),h(!1)}catch(e){console.error(`Error saving admin record:`,e)}x(!1)}},ae=async e=>{let n=e.target.files?.[0];if(!(!n||!a)){E(!0);try{let e=`admin_files/${`${Date.now()}_${n.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,r=(0,o.ref)(t.It,e);await(0,o.uploadBytes)(r,n,{customMetadata:{ownerId:a.uid}});let s=await(0,o.getDownloadURL)(r);if(w.current)w.current(n,s,{uid:a.uid,storagePath:e});else{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Pt,J),{name:n.name,note:`${n.type||`File`} · ${_e(n.size)}`,uid:a.uid,recordType:`file`,fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:s,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,i.serverTimestamp)()})}}catch(e){console.error(`Error uploading admin file:`,e)}E(!1),U.current&&(U.current.value=``)}},oe=async()=>{if(D){L(!0);try{let e=u.find(e=>e.id===D);if(await(0,i.deleteDoc)((0,i.doc)(t.Pt,J,D)),e?.recordType===`file`&&e.downloadURL)try{let n=e.downloadURL.split(`admin_files%2F`)[1]?.split(`?`)[0];n&&await(0,o.deleteObject)((0,o.ref)(t.It,`admin_files/${decodeURIComponent(n)}`)).catch(()=>{})}catch(e){console.error(`Error cleaning up admin file:`,e)}O(null)}catch(e){console.error(`Error deleting admin record:`,e)}L(!1)}},[se,X]=(0,r.useState)(null),[ce,Z]=(0,r.useState)(``),[Q,le]=(0,r.useState)(!1),ue=e=>{if(e.recordType===`file`){X(e.id),Z(e.name);return}ee(e.id),te(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??``)}));H(n),q.current=n.map(e=>e.key)},de=async()=>{if(!se||!ce.trim()){X(null);return}let e=u.find(e=>e.id===se);if(e&&e.name===ce.trim()){X(null);return}le(!0);try{await(0,i.updateDoc)((0,i.doc)(t.Pt,J,se),{name:ce.trim()}),d(e=>e.map(e=>e.id===se?{...e,name:ce.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}le(!1),X(null)},fe=async()=>{if(!R||!z.trim()){ee(null);return}x(!0);let e={};V.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=V.map(e=>e.key.trim()).filter(Boolean),r=q.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,i.deleteField)()});try{await(0,i.updateDoc)((0,i.doc)(t.Pt,J,R),{name:z.trim(),note:B.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:z.trim(),note:B.trim()};return r.forEach(e=>{delete t[e]}),V.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),q.current=n}catch(e){console.error(`Error updating record:`,e)}x(!1),ee(null)},pe=async()=>{if(!R||!z.trim())return;let e={};V.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=V.map(e=>e.key.trim()).filter(Boolean),r=q.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,i.deleteField)()});try{await(0,i.updateDoc)((0,i.doc)(t.Pt,J,R),{name:z.trim(),note:B.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:z.trim(),note:B.trim()};return r.forEach(e=>{delete t[e]}),V.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),q.current=n}catch(e){console.error(`Error silently saving record:`,e)}},me=(e,n)=>e?e.startsWith(`image/`)?n?(0,s.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${n})`}}):(0,s.jsx)(t.J,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,s.jsx)(t.f,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,s.jsx)(t.Q,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,s.jsx)(t.Et,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,s.jsx)(t.ot,{className:`w-4 h-4`}):(0,s.jsx)(t.Z,{className:`w-4 h-4`}):(0,s.jsx)(t.Q,{className:`w-4 h-4`}),he=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`,ge=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)},_e=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]},ve=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=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.c[r]?t.c[r]:t.c[n]?t.c[n]:t.h||t.k})(),be=e.buttonStyle!==`secondary`,xe=e.buttonStorageStyle===`primary`,Se=e=>e.uid===a?.uid,Ce=({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,s.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,s.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,s.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,s.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,s.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,s.jsx)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,s.jsxs)(`div`,{children:[(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(W,{}),(0,s.jsxs)(t.o.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,s.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,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,s.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${u.length} ${u.length===1?`item`:`items`}`})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.storage!==!1&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`input`,{type:`file`,ref:U,onChange:ae,className:`hidden`}),(0,s.jsxs)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>U.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`} ${xe?`btn-primary`:`btn-secondary`}`,children:[T?(0,s.jsx)(t.L,{className:`w-4 h-4 animate-spin`}):(0,s.jsx)(ye,{className:`w-4 h-4`}),e.buttonStorageText&&(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,s.jsx)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>h(!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`} ${be?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,s.jsx)(t.k,{className:`w-4 h-4`}):(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,s.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,s.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,s.jsx)(t.L,{className:`w-8 h-8 text-accent animate-spin`})}),n?(0,s.jsx)(`div`,{className:`fbos-content-slot`,children:(0,s.jsx)(n,{config:e,actions:{records:u,loading:f,collection:J,user:a,saveRecord:async e=>{let n=Y(),r={id:`temp_`+Date.now(),uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:Date.now(),...e};d(e=>[r,...e]),await(0,i.addDoc)((0,i.collection)(t.Pt,J),{uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:(0,i.serverTimestamp)(),...e})},updateRecord:async(e,n)=>{d(t=>t.map(t=>t.id===e?{...t,...n}:t)),await(0,i.updateDoc)((0,i.doc)(t.Pt,J,e),n)},deleteRecord:async e=>{await(0,i.deleteDoc)((0,i.doc)(t.Pt,J,e))},startEdit:e=>ue(e),confirmDelete:e=>O(e),uploadFile:()=>U.current?.click(),openAddForm:()=>h(!0),setAddForm:e=>C(()=>e),setFileHandler:e=>{w.current=e}}})}):(0,s.jsxs)(s.Fragment,{children:[!f&&u.length===0&&(0,s.jsxs)(t.o.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,s.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,s.jsx)(t.k,{className:`w-6 h-6 text-accent/40`})}),(0,s.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,s.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&&u.length>0&&(0,s.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,s.jsx)(t.s,{children:u.map((e,n)=>{let r=R===e.id,i=Se(e);return(0,s.jsxs)(t.o.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>ue(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,s.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,s.jsxs)(s.Fragment,{children:[(0,s.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,s.jsx)(t._t,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-3.5 h-3.5`})}),(0,s.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,s.jsx)(t.rt,{className:`w-3.5 h-3.5`})})]}),i&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ue(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,s.jsx)(t.A,{className:`w-3.5 h-3.5`})}),(0,s.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,s.jsx)(t.y,{className:`w-3.5 h-3.5`})})]})]}),(0,s.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,s.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&M(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 ${he(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?me(e.fileType,e.downloadURL):(0,s.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,s.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[se===e.id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:ce,onChange:e=>Z(e.target.value),onBlur:()=>de(),onKeyDown:e=>{e.key===`Enter`&&de(),e.key===`Escape`&&X(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,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,s.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>M(e)}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ve(e.createdAt)})]})]}),e.note&&(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,s.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,s.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,s.jsx)(Ce,{record:e})]},e.id)})})})]})]}),!n&&(0,s.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,s.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,s.jsx)(t.K,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,s.jsxs)(`span`,{children:[`Shared between all admins · Edit and delete available on your own items only · Records: `,(0,s.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:J}),` · Files: `,(0,s.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`admin_files`}),` → Drive / Admin`]})]})})]})]}),(0,s.jsx)(t.s,{children:m&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>!b&&h(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,s.jsx)(t.o.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:S?r.default.createElement(S,{onSave:async e=>{x(!0);try{let n=Y();await(0,i.addDoc)((0,i.collection)(t.Pt,J),{uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:(0,i.serverTimestamp)(),...e}),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)},onClose:()=>!b&&h(!1),saving:b}):(0,s.jsxs)(`form`,{onSubmit:ie,className:`p-5 flex flex-col gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>!b&&h(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,s.jsx)(t.d,{className:`w-4 h-4`})})]}),(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:g,onChange:e=>_(e.target.value),placeholder:`Name *`,disabled:b,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,s.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),placeholder:`Note (optional)`,disabled:b,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,s.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,s.jsx)(t.r,{type:`submit`,isLoading:b,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:b?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,l.createPortal)((0,s.jsx)(t.s,{children:N&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,s.jsx)(t.o.div,{onClick:()=>M(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,s.jsx)(`button`,{onClick:()=>M(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,s.jsx)(t.d,{className:`w-5 h-5`})}),(0,s.jsxs)(t.o.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,s.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,s.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,s.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:N.fileName||N.name}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[ge(N.fileType),` • `,_e(N.fileSize||0)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(N.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,s.jsx)(t._t,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{M(null),X(N.id),Z(N.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,s.jsx)(t.A,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{M(null),O(N.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,s.jsx)(t.y,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:N.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,s.jsx)(t.rt,{className:`w-4 h-4`})})]})]}),(0,s.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>M(null),children:(0,s.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[P&&(0,s.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,s.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,s.jsx)(t.L,{className:`w-5 h-5 text-accent animate-spin`})})}),N.fileType?.startsWith(`image/`)?(0,s.jsx)(`img`,{onLoad:()=>F(!1),onError:()=>F(!1),src:N.downloadURL,alt:N.fileName||N.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 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):N.fileType?.startsWith(`video/`)?(0,s.jsx)(`video`,{onLoadedData:()=>F(!1),onError:()=>F(!1),src:N.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 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):N.fileType===`application/pdf`?(0,s.jsx)(`iframe`,{onLoad:()=>F(!1),src:N.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,s.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(),F(!1)},children:[(0,s.jsx)(t.Q,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,s.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,s.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,s.jsx)(t.s,{children:R&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>fe(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,s.jsx)(t.o.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,s.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),b&&(0,s.jsx)(t.L,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>fe(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,s.jsx)(t.d,{className:`w-4 h-4`})})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.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,s.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>te(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>pe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.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,s.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:B,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:()=>pe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),V.map((e,n)=>(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let t=[...V];t[n].key=e.target.value,H(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>pe(),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,s.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let t=[...V];t[n].value=e.target.value,H(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>pe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>H(V.filter((e,t)=>t!==n)),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,s.jsx)(t.d,{className:`w-3 h-3`})})]},n)),(0,s.jsxs)(`button`,{type:`button`,onClick:()=>H([...V,{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,s.jsx)(t.k,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,s.jsx)(re,{isOpen:!!D,onCancel:()=>O(null),onConfirm:oe,title:`Delete Record`,message:(0,s.jsxs)(s.Fragment,{children:[`Are you sure you want to delete `,(0,s.jsx)(`strong`,{className:`text-foreground font-extrabold break-words mx-1`,children:u.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:I})]})}function oi({config:e,customContent:n}){let{user:a}=A(),{config:c}=t.At(),[u,d]=(0,r.useState)([]),[f,p]=(0,r.useState)(!0),[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(``),[v,y]=(0,r.useState)(``),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(null),w=(0,r.useRef)(null),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(null),[k,j]=(0,r.useState)(null),M=e=>{if(j(e),e){let t=e.fileType||``;F(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},N=k,[P,F]=(0,r.useState)(!0),[I,L]=(0,r.useState)(!1),[R,ee]=(0,r.useState)(null),[z,te]=(0,r.useState)(``),[B,ne]=(0,r.useState)(``),[V,H]=(0,r.useState)([]),U=(0,r.useRef)(null),[G,K]=(0,r.useState)(null),q=(0,r.useRef)([]),J=`mem_${(e.tabName||e.pageId||`internal_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`)}_records`;(0,r.useEffect)(()=>{document.title=e.tabTitle||e.tabName||c.appName||`Your AI Firebase`},[e.tabTitle,e.tabName,c.appName]),(0,r.useEffect)(()=>{if(!a)return;try{let e=localStorage.getItem(`fbos_records_${J}`);e?(d(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}}),n=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,J),(0,i.orderBy)(`createdAt`,`desc`),(0,i.limit)(150)),t=>{let n=e(t.docs);d(n),p(!1),localStorage.setItem(`fbos_records_${J}`,JSON.stringify(n))},n=>{console.error(`Error listening to shared records:`,n);let r=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,J),(0,i.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),d(n),p(!1),localStorage.setItem(`fbos_records_${J}`,JSON.stringify(n))});return()=>r()});return()=>n()},[a,J]);let Y=()=>({name:a.displayName||a.email?.split(`@`)[0]||`Member`,email:a.email||``,avatar:a.photoURL||``}),ie=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Pt,J),{name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,i.serverTimestamp)()}),_(``),y(``),h(!1)}catch(e){console.error(`Error saving shared record:`,e)}x(!1)}},ae=async e=>{let n=e.target.files?.[0];if(!(!n||!a)){E(!0);try{let e=`mem_files/${`${Date.now()}_${n.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,r=(0,o.ref)(t.It,e);await(0,o.uploadBytes)(r,n,{customMetadata:{ownerId:a.uid}});let s=await(0,o.getDownloadURL)(r);if(w.current)w.current(n,s,{uid:a.uid,storagePath:e});else{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Pt,J),{name:n.name,note:`${n.type||`File`} · ${_e(n.size)}`,uid:a.uid,recordType:`file`,fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:s,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,i.serverTimestamp)()})}}catch(e){console.error(`Error uploading shared file:`,e)}E(!1),U.current&&(U.current.value=``)}},oe=async()=>{if(D){L(!0);try{let e=u.find(e=>e.id===D);if(await(0,i.deleteDoc)((0,i.doc)(t.Pt,J,D)),e?.recordType===`file`&&e.downloadURL)try{let n=e.downloadURL.split(`mem_files%2F`)[1]?.split(`?`)[0];n&&await(0,o.deleteObject)((0,o.ref)(t.It,`mem_files/${decodeURIComponent(n)}`)).catch(()=>{})}catch(e){console.error(`Error cleaning up shared file:`,e)}O(null)}catch(e){console.error(`Error deleting shared record:`,e)}L(!1)}},[se,X]=(0,r.useState)(null),[ce,Z]=(0,r.useState)(``),[Q,le]=(0,r.useState)(!1),ue=e=>{if(e.recordType===`file`){X(e.id),Z(e.name);return}ee(e.id),te(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??``)}));H(n),q.current=n.map(e=>e.key)},de=async()=>{if(!se||!ce.trim()){X(null);return}let e=u.find(e=>e.id===se);if(e&&e.name===ce.trim()){X(null);return}le(!0);try{await(0,i.updateDoc)((0,i.doc)(t.Pt,J,se),{name:ce.trim()}),d(e=>e.map(e=>e.id===se?{...e,name:ce.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}le(!1),X(null)},fe=async()=>{await pe(),ee(null)},pe=async()=>{if(!R||!z.trim())return;x(!0);let e={};V.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=V.map(e=>e.key.trim()).filter(Boolean),r=q.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,i.deleteField)()});try{await(0,i.updateDoc)((0,i.doc)(t.Pt,J,R),{name:z.trim(),note:B.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:z.trim(),note:B.trim()};return r.forEach(e=>{delete t[e]}),V.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),q.current=n}catch(e){console.error(`Error saving record:`,e)}x(!1)},me=(e,n)=>e?e.startsWith(`image/`)?n?(0,s.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${n})`}}):(0,s.jsx)(t.J,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,s.jsx)(t.f,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,s.jsx)(t.Q,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,s.jsx)(t.Et,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,s.jsx)(t.ot,{className:`w-4 h-4`}):(0,s.jsx)(t.Z,{className:`w-4 h-4`}):(0,s.jsx)(t.Q,{className:`w-4 h-4`}),he=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`,ge=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)},_e=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]},ve=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=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.c[r]?t.c[r]:t.c[n]?t.c[n]:t.h||t.k})(),be=e.buttonStyle!==`secondary`,xe=e.buttonStorageStyle===`primary`,Se=e=>e.uid===a?.uid,Ce=({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,s.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,s.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,s.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,s.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,s.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,s.jsx)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,s.jsxs)(`div`,{children:[(0,s.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||`Internal Page`}),e.route&&(0,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(W,{}),(0,s.jsxs)(t.o.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,s.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,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,s.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${u.length} ${u.length===1?`item`:`items`} · Internal`})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.storage!==!1&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`input`,{type:`file`,ref:U,onChange:ae,className:`hidden`}),(0,s.jsxs)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>U.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`} ${xe?`btn-primary`:`btn-secondary`}`,children:[T?(0,s.jsx)(t.L,{className:`w-4 h-4 animate-spin`}):(0,s.jsx)(ye,{className:`w-4 h-4`}),e.buttonStorageText&&(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,s.jsx)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>h(!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`} ${be?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,s.jsx)(t.k,{className:`w-4 h-4`}):(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,s.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,s.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,s.jsx)(t.L,{className:`w-8 h-8 text-accent animate-spin`})}),n?(0,s.jsx)(`div`,{className:`fbos-content-slot`,children:(0,s.jsx)(n,{config:e,actions:{records:u,loading:f,collection:J,user:a,saveRecord:async e=>{let n=Y(),r={id:`temp_`+Date.now(),uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:Date.now(),...e};d(e=>[r,...e]),await(0,i.addDoc)((0,i.collection)(t.Pt,J),{uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:(0,i.serverTimestamp)(),...e})},updateRecord:async(e,n)=>{d(t=>t.map(t=>t.id===e?{...t,...n}:t)),await(0,i.updateDoc)((0,i.doc)(t.Pt,J,e),n)},deleteRecord:async e=>{await(0,i.deleteDoc)((0,i.doc)(t.Pt,J,e))},startEdit:e=>ue(e),confirmDelete:e=>O(e),uploadFile:()=>U.current?.click(),openAddForm:()=>h(!0),setAddForm:e=>C(()=>e),setFileHandler:e=>{w.current=e}}})}):(0,s.jsxs)(s.Fragment,{children:[!f&&u.length===0&&(0,s.jsxs)(t.o.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,s.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,s.jsx)(t.k,{className:`w-6 h-6 text-accent/40`})}),(0,s.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,s.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&&u.length>0&&(0,s.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,s.jsx)(t.s,{children:u.map(e=>{let n=R===e.id,r=Se(e);return(0,s.jsxs)(t.o.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>r?ue(e):null,className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative ${r?`cursor-pointer`:``} ${n?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,s.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,s.jsxs)(s.Fragment,{children:[(0,s.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,s.jsx)(t._t,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-3.5 h-3.5`})}),(0,s.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,s.jsx)(t.rt,{className:`w-3.5 h-3.5`})})]}),r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ue(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,s.jsx)(t.A,{className:`w-3.5 h-3.5`})}),(0,s.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,s.jsx)(t.y,{className:`w-3.5 h-3.5`})})]})]}),(0,s.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,s.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&M(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 ${he(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?me(e.fileType,e.downloadURL):(0,s.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,s.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[se===e.id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:ce,onChange:e=>Z(e.target.value),onBlur:()=>de(),onKeyDown:e=>{e.key===`Enter`&&de(),e.key===`Escape`&&X(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,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,s.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>M(e)}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ve(e.createdAt)})]})]}),e.note&&(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,s.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,s.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,s.jsx)(Ce,{record:e})]},e.id)})})})]})]}),!n&&(0,s.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,s.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,s.jsx)(t.K,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,s.jsxs)(`span`,{children:[`Shared with everyone marked internal · Edit and delete available on your own items only · Records: `,(0,s.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:J}),` · Files: `,(0,s.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`mem_files`}),` → Drive / Internal`]})]})})]})]}),(0,s.jsx)(t.s,{children:m&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>!b&&h(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,s.jsx)(t.o.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:S?r.default.createElement(S,{onSave:async e=>{x(!0);try{let n=Y();await(0,i.addDoc)((0,i.collection)(t.Pt,J),{uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:(0,i.serverTimestamp)(),...e}),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)},onClose:()=>!b&&h(!1),saving:b}):(0,s.jsxs)(`form`,{onSubmit:ie,className:`p-5 flex flex-col gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>!b&&h(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,s.jsx)(t.d,{className:`w-4 h-4`})})]}),(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:g,onChange:e=>_(e.target.value),placeholder:`Name *`,disabled:b,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,s.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),placeholder:`Note (optional)`,disabled:b,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,s.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,s.jsx)(t.r,{type:`submit`,isLoading:b,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:b?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,l.createPortal)((0,s.jsx)(t.s,{children:N&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,s.jsx)(t.o.div,{onClick:()=>M(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,s.jsx)(`button`,{onClick:()=>M(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,s.jsx)(t.d,{className:`w-5 h-5`})}),(0,s.jsxs)(t.o.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,s.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,s.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,s.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:N.fileName||N.name}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[ge(N.fileType),` • `,_e(N.fileSize||0)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(N.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,s.jsx)(t._t,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{M(null),X(N.id),Z(N.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,s.jsx)(t.A,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{M(null),O(N.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,s.jsx)(t.y,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:N.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,s.jsx)(t.rt,{className:`w-4 h-4`})})]})]}),(0,s.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>M(null),children:(0,s.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[P&&(0,s.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,s.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,s.jsx)(t.L,{className:`w-5 h-5 text-accent animate-spin`})})}),N.fileType?.startsWith(`image/`)?(0,s.jsx)(`img`,{onLoad:()=>F(!1),onError:()=>F(!1),src:N.downloadURL,alt:N.fileName||N.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 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):N.fileType?.startsWith(`video/`)?(0,s.jsx)(`video`,{onLoadedData:()=>F(!1),onError:()=>F(!1),src:N.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 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):N.fileType===`application/pdf`?(0,s.jsx)(`iframe`,{onLoad:()=>F(!1),src:N.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,s.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(),F(!1)},children:[(0,s.jsx)(t.Q,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,s.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,s.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,s.jsx)(t.s,{children:R&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>fe(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,s.jsx)(t.o.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,s.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),b&&(0,s.jsx)(t.L,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>fe(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,s.jsx)(t.d,{className:`w-4 h-4`})})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.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,s.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>te(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>pe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.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,s.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:B,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:()=>pe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),V.map((e,n)=>(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let t=[...V];t[n].key=e.target.value,H(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>pe(),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,s.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let t=[...V];t[n].value=e.target.value,H(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>pe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>H(V.filter((e,t)=>t!==n)),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,s.jsx)(t.d,{className:`w-3 h-3`})})]},n)),(0,s.jsxs)(`button`,{type:`button`,onClick:()=>H([...V,{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,s.jsx)(t.k,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,s.jsx)(re,{isOpen:!!D,onCancel:()=>O(null),onConfirm:oe,title:`Delete Record`,message:(0,s.jsxs)(s.Fragment,{children:[`Are you sure you want to delete `,(0,s.jsx)(`strong`,{className:`text-foreground font-extrabold break-words mx-1`,children:u.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:I})]})}var si=[`board`,`table`,`calendar`,`drive`],ci=[`inline_form`,`popup_form`],li=e=>typeof e!=`string`||e===``||e===`none`||e===`custom`||![...si,...ci].includes(e),ui=`src/your-ai-workflow-firebase-os`;function di(){let e=new Set;for(let[t,n]of M()){let r=n?.config?.route,i=typeof r==`string`&&r.trim()?r.startsWith(`/`)?r:`/`+r:`/`+t.toLowerCase();e.add(i)}return[...e].sort()}function fi(e){return[`The page at ${e} shows "Page Not Found". The app only finds a page when its config file is picked up, so check these in order and fix whatever is wrong, without asking me questions.`,`1. The page's config file sits directly in ${ui}/configs/ and its name ends with Tab.config.ts (a page for signed-in users, my team or admins) or Page.config.ts (a page for anyone). Not in a subfolder, not any other name.`,`2. It exports one const whose name ends with Config, and its route is the single string '${e}'. A page has exactly one web address — remove any other addresses you registered for it.`,`3. ${ui}/configs/pagesRegistry.ts exists and src/main.tsx contains the line import './your-ai-workflow-firebase-os/configs/pagesRegistry'. If either is missing, run npm install so the package's postinstall script restores them.`,`4. Put src/App.tsx back to the version the package wrote: it only mounts <FirebaseOS />. Never add routes, a router or the customRoutes prop.`,`5. If the page is for my team, its config says pageType: 'internal'. Any form on it is a *Form.config.ts file shown through <ContactPopup formId="..." />, never a form you wrote by hand.`,`Then rebuild and tell me, in one sentence, which of these was wrong.`].join(`
|
|
136
|
-
`)}function pi({tone:e,title:t,message:n,action:r}){let i=e===`red`?`border-red-500/20`:`border-amber-500/25`,a=e===`red`?`bg-red-500/5`:`bg-amber-500/5`,o=e===`red`?`text-red-500`:`text-amber-500`;return(0,s.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 min-h-[60vh] animate-in fade-in duration-500`,children:(0,s.jsxs)(`div`,{className:`glass-panel p-8 md:p-10 rounded-3xl border ${i} text-center shadow-xl max-w-sm w-full relative overflow-hidden`,children:[(0,s.jsx)(`div`,{className:`absolute inset-0 ${a}`}),(0,s.jsx)(`h2`,{className:`text-2xl font-black ${o} mb-3 relative z-10 tracking-tight`,children:t}),(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/70 font-medium leading-relaxed relative z-10 mb-6`,children:n}),(0,s.jsx)(`div`,{className:`relative z-10`,children:r})]})})}var mi=`w-full block py-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors`,hi=()=>(0,s.jsx)(pi,{tone:`amber`,title:`Team page`,message:`This page is for your team. Ask an admin of this app to add you to the team.`,action:(0,s.jsx)(c.Link,{to:`/dashboard`,className:mi,children:`Back to dashboard`})}),gi=()=>(0,s.jsx)(pi,{tone:`amber`,title:`Admins only`,message:`This page is part of the admin area. Ask an admin of this app if you need to get in.`,action:(0,s.jsx)(c.Link,{to:`/dashboard`,className:mi,children:`Back to dashboard`})}),_i=(e,t)=>{let n=t?w(e.pageType):`public`;return{...e,pageType:n,isPrivate:t,isAdmin:n===`admin`,isInternal:n===`internal`,isShared:n===`internal`}};function vi(){let e=(0,c.useLocation)(),{user:n,userRole:a,loading:o,roleResolved:l}=A(),u=t.Mt(),d=e=>{if(typeof window<`u`){let t=localStorage.getItem(`fbos_route_${e}`);if(t)try{let e=JSON.parse(t);if(e.form&&!e.formConfigOverride){let t=localStorage.getItem(`fbos_form_${e.form}`);t&&(e.formConfigOverride=JSON.parse(t))}return _i(e,e.isPrivate===!0)}catch{}}if(e===`/contact`)return{route:`/contact`,template:`popup_form`,form:`contact`,pageId:`contact`,formConfigOverride:u.defaultConfigs?.contactForm||t.Bt};if(e===`/support`)return{route:`/support`,template:`popup_form`,form:`support`,pageId:`support`,formConfigOverride:u.defaultConfigs?.supportForm||t.Rt};let n=(typeof window<`u`?window.__FBOS_PAGES__:null)||{},r=e.replace(/^\//,``);for(let[t,i]of Object.entries(n)){let n=i.config,a=i.isPublic,o=n.route||`/`+t;if(o===e||t===r)return _i({...n,route:o,contentKey:n.pageId||t,pageId:t},!a)}return null},[f,p]=(0,r.useState)(()=>d(e.pathname)),[m,h]=(0,r.useState)(()=>!d(e.pathname));(0,r.useEffect)(()=>{let n=!0,r=d(e.pathname);if(r){p(r),h(!1);let e=r.pageName||r.tabName||r.title;e&&(document.title=e)}return(async()=>{try{let r=e.pathname;r.startsWith(`/`)&&(r=r.substring(1));let[a,o,s,c,l,d]=await Promise.allSettled([(0,i.getDoc)((0,i.doc)(t.Pt,`sys_pages`,r)),(0,i.getDoc)((0,i.doc)(t.Pt,`sys_tabs`,r)),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Pt,`sys_pages`),(0,i.where)(`route`,`==`,e.pathname),(0,i.limit)(1))),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Pt,`sys_pages`),(0,i.where)(`route`,`==`,r),(0,i.limit)(1))),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Pt,`sys_tabs`),(0,i.where)(`route`,`==`,e.pathname),(0,i.limit)(1))),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Pt,`sys_tabs`),(0,i.where)(`route`,`==`,r),(0,i.limit)(1)))]),f=null,m=null,g=(e,t)=>{f||e.status===`fulfilled`&&(e.value.exists&&e.value.exists()?(f=_i(e.value.data(),t),m=e.value.id):e.value.docs&&e.value.docs.length>0&&(f=_i(e.value.docs[0].data(),t),m=e.value.docs[0].id))};if(g(a,!1),g(s,!1),g(c,!1),g(o,!0),g(l,!0),g(d,!0),!f)if(e.pathname===`/contact`)f={route:`/contact`,template:`popup_form`,form:`contact`},m=`contact`;else if(e.pathname===`/support`)f={route:`/support`,template:`popup_form`,form:`support`},m=`support`;else{let t=(typeof window<`u`?window.__FBOS_PAGES__:null)||{};for(let[n,i]of Object.entries(t)){let t=i.config,a=i.isPublic,o=t.route||`/`+n;if(o===e.pathname||n===r){f=_i({...t,route:o,contentKey:t.pageId||n,pageId:n},!a),m=n;break}}}if(!n)return;if(f){if((m===`contact`||m===`support`)&&!f.form&&(f.form=m),f.contentKey||=f.pageId||m,f.pageId=m,localStorage.setItem(`fbos_route_${e.pathname}`,JSON.stringify(f)),f.form){let e=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},r=n=>u.defaultConfigs?.[n]||u.defaultConfigs?.[`${n}Form`]||e[n]||(n===`contact`?t.Bt:n===`support`?t.Rt:null);if(localStorage.getItem(`fbos_custom_form_${f.form}`)){try{let e=localStorage.getItem(`fbos_form_${f.form}`);e&&(f.formConfigOverride=JSON.parse(e))}catch{}(0,i.getDoc)((0,i.doc)(t.Pt,`sys_forms`,f.form)).then(async e=>{if(n)if(e.exists()){let t={...e.data(),id:e.id};p(e=>({...e,formConfigOverride:t})),localStorage.setItem(`fbos_form_${f.form}`,JSON.stringify(t))}else{let e=r(f.form);e&&(p(t=>({...t,formConfigOverride:e})),localStorage.setItem(`fbos_form_${f.form}`,JSON.stringify(e)),localStorage.removeItem(`fbos_custom_form_${f.form}`))}})}else{let e=r(f.form);e&&(f.formConfigOverride=e)}}let r=f.pageName||f.tabName||f.title;r&&(document.title=r),p(f),h(!1)}else p(`not-found`),h(!1),localStorage.removeItem(`fbos_route_${e.pathname}`)}catch{n&&m&&(p(`not-found`),h(!1))}})(),()=>{n=!1}},[e.pathname]);let[g,_]=(0,r.useState)(!1);if((0,r.useEffect)(()=>{let e;return m||o||!l?e=setTimeout(()=>_(!0),150):_(!1),()=>clearTimeout(e)},[m,o,l]),m||o||!l)return g?n?(0,s.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,s.jsxs)(`div`,{className:`mb-6`,children:[(0,s.jsx)(`div`,{className:`h-10 w-56 rounded-xl bg-foreground/5 animate-pulse mt-1`}),(0,s.jsx)(`div`,{className:`h-3 w-24 rounded bg-foreground/5 animate-pulse mt-3`})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(W,{}),(0,s.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,s.jsx)(t.L,{className:`w-6 h-6 animate-spin text-accent`})})]})]}):(0,s.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[40vh] z-10`,children:(0,s.jsxs)(`div`,{className:`p-4 rounded-2xl glass-panel border border-[var(--panel-border)]/40 bg-background/80 shadow-md flex items-center gap-3`,children:[(0,s.jsx)(t.L,{className:`w-4 h-4 animate-spin text-accent`}),(0,s.jsx)(`span`,{className:`text-[12px] font-medium text-foreground/60 tracking-wide`,children:`Loading page...`})]})}):null;if(f===`not-found`)return(0,s.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,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1 text-center`,children:[(0,s.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,s.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,s.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,s.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,s.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]})}),(0,s.jsx)(`h2`,{className:`text-3xl font-bold mb-3 text-foreground`,children:`Page Not Found`}),(0,s.jsx)(`p`,{className:`text-foreground/60 max-w-md`,children:`The route you are looking for does not exist or has been removed.`}),x(a)&&(()=>{let t=di();return(0,s.jsxs)(`div`,{className:`mt-8 w-full max-w-lg text-left flex flex-col gap-4`,children:[(0,s.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)] px-5 py-4`,children:[(0,s.jsx)(`p`,{className:`text-[12px] font-extrabold tracking-tight text-gradient mb-1.5`,children:`Pages the app can see`}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/70 font-medium leading-relaxed`,children:t.length?t.join(` · `):`None yet. If your assistant says it created a page, the app has not picked its file up.`})]}),(0,s.jsx)(ke,{title:`If your assistant just made this page, paste this`,prompt:fi(e.pathname)})]})})()]})});if((f.pageId===`support`||f.isPrivate)&&!n)return(0,s.jsx)(c.Navigate,{to:`/login`,state:{from:e}});if(!T(a,f.isPrivate?f.pageType:`public`))return f.isAdmin?(0,s.jsx)(gi,{}):(0,s.jsx)(hi,{});let v=u.customRoutes?.[e.pathname]||(f&&f.route?u.customRoutes?.[f.route]:null),y=f.pageName?.toLowerCase().replace(/\s+/g,`_`)||f.pageId||`custom_page`,b=`pub_${y}`,S=u.microcomponents||(typeof window<`u`?window.__FBOS_MICROCOMPONENTS__:void 0),C=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_|_$/g,``),w=[f.contentKey,f.tabName,f.pageId,f.pageName,f.pageName?.replace(/\s+/g,`_`)].filter(Boolean).map(e=>C(e)).reduce((e,t)=>e||S?.[t],void 0),E=v||w||void 0,D=f.route||f.pageId||`custom`;if(li(f.template)||v&&![`board`,`table`,`calendar`,`drive`].includes(f.template))return f.isAdmin?(0,s.jsx)(ai,{config:f,customContent:E},D):f.isInternal?(0,s.jsx)(oi,{config:f,customContent:E},D):f.isPrivate?(0,s.jsx)(ii,{config:f,customContent:E},D):(0,s.jsx)(ri,{config:f,customContent:E},D);if(f.template===`board`){let e=f.isAdmin?`admin_${f.pageId||y}`:f.isInternal?`mem_${f.pageId||y}`:f.isPrivate?`user_${f.pageId||y}`:b;return(0,s.jsx)(u.components?.TemplateBoard||lt,{title:f.tabTitle||f.tabName||f.title||f.pageName||`Board`,subtitle:f.route,tasksCollection:`${e}_tasks`,categoriesCollection:`${e}_categories`,config:f,customContent:E},D)}if(f.template===`table`){let e=f.isAdmin?`admin_${f.pageId||y}`:f.isInternal?`mem_${f.pageId||y}`:f.isPrivate?`user_${f.pageId||y}`:b;return(0,s.jsx)(u.components?.TemplateTable||zn,{title:f.tabTitle||f.tabName||f.title||f.pageName||`Table`,subtitle:f.route,tableCollection:`${e}_table`,config:f,customContent:E},D)}if(f.template===`calendar`){let e=f.isAdmin?`admin_${f.pageId||y}`:f.isInternal?`mem_${f.pageId||y}`:f.isPrivate?`user_${f.pageId||y}`:b;return(0,s.jsx)(u.components?.TemplateCalendar||Hn,{title:f.tabTitle||f.tabName||f.title||f.pageName||`Calendar`,subtitle:f.route,eventsCollection:`${e}_events`,defaultTimeFormat:f.defaultTimeFormat||f.defaulttimeformat||`12h`,config:f,customContent:E},D)}if(f.template===`drive`){let e=f.isAdmin?`admin_${f.pageId||y}`:f.isInternal?`mem_${f.pageId||y}`:f.isPrivate?`user_${f.pageId||y}`:b;return(0,s.jsx)(u.components?.TemplateDrive||He,{title:f.tabTitle||f.tabName||f.title||f.pageName||`Drive`,subtitle:f.route,filesCollection:`${e}_files`,config:f,customContent:E},D)}return f.template===`inline_form`?(0,s.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-start mt-8 relative z-10 w-full min-h-[60vh]`,children:(0,s.jsx)(t.t,{isInline:!0,formId:f.form,formConfig:f.formConfigOverride})}):(0,s.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 w-full min-h-[60vh]`,children:(0,s.jsx)(t.t,{formId:f.form,formConfig:f.formConfigOverride,onClose:()=>window.history.back()})})}var yi=r.default.createContext({}),bi=Object.defineProperty,xi=Object.getOwnPropertySymbols,Si=Object.prototype.hasOwnProperty,Ci=Object.prototype.propertyIsEnumerable,wi=(e,t,n)=>t in e?bi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ti=(e,t)=>{for(var n in t||={})Si.call(t,n)&&wi(e,n,t[n]);if(xi)for(var n of xi(t))Ci.call(t,n)&&wi(e,n,t[n]);return e},Ei=(0,r.forwardRef)((e,t)=>{let n=Ti(Ti({},r.useContext(yi)),e);return r.createElement(`svg`,Ti({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),r.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`}),r.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`}))}),Di=`rules_version = '2';
|
|
134
|
+
};`;navigator.clipboard?.writeText(i),b(!0),setTimeout(()=>b(!1),2e3)},P=e=>{let t=Gn.find(t=>t.key===e),r=l?.colors?.[e]||{},i=o.colors?.[e]||{},a=r.background||i.background||`#ffffff`;return(0,s.jsxs)(le,{icon:t.icon,title:t.label,description:t.description,defaultOpen:n===e,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-3 p-3.5 sm:p-4 ${ie}`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,s.jsx)(`span`,{className:`text-[12.5px] font-bold text-foreground`,children:`Ready-made colour sets`}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/45 font-medium leading-snug`,children:`One click repaints light and dark together. Change anything you like afterwards.`})]}),(0,s.jsx)(`div`,{className:`flex items-center gap-3 overflow-x-auto hide-scrollbars pb-2 pt-1`,children:Un.map(t=>{let n=r.accent===t[e].accent&&l?.colors?.[e]?.buttonGradient?.[0]===t[e].gradient[0],i=t.name===`Black & White`;return(0,s.jsx)(`button`,{type:`button`,onClick:()=>j(t),"aria-label":t.name,title:t.name,className:`w-9 h-9 rounded-full shrink-0 outline-none transition-all shadow-sm relative cursor-pointer ${n?`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`}`,children:(0,s.jsx)(`span`,{className:`absolute inset-0 rounded-full border border-[var(--panel-border)]/60 dark:border-0 dark:ring-1 dark:ring-inset dark:ring-white/10`,style:i?{backgroundColor:`#ffffff`,border:`3px solid #000000`}:{backgroundImage:`linear-gradient(135deg, ${t.preview[0]}, ${t.preview[1]})`}})},t.name)})})]}),(0,s.jsx)(sr,{title:`Brand and colours`,onReset:()=>O(`Reset the colours?`,`The brand colour, the text and the two backgrounds in ${t.label.toLowerCase()} go back to how they started. Nothing else changes.`,()=>A(e,cr))}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3 items-start`,children:[(0,s.jsx)(rr,{over:a,label:`Brand colour`,hint:`Links, highlights and the main buttons. Panels follow it too.`,value:r.accent||i.accent||`#7c3aed`,onChange:t=>D(e,t)}),(0,s.jsx)(rr,{over:a,label:`Text colour`,hint:`Primary typography colour used across the app.`,value:r.foreground||i.foreground||`#111827`,onChange:t=>T(e,{foreground:t})}),(0,s.jsx)(rr,{over:a,label:`Page background`,hint:`Main background canvas colour under all content.`,value:r.background||i.background||`#ffffff`,onChange:t=>T(e,{background:t})}),(0,s.jsx)(rr,{over:a,label:`Second background`,hint:`The colour the page background fades into.`,value:r.backgroundSecondary||i.backgroundSecondary||`#f9fafb`,onChange:t=>T(e,{backgroundSecondary:t})}),(0,s.jsx)(rr,{over:a,label:`Notification dot`,hint:`Colour applied to notification badging.`,value:r.notificationIconColor||r.accent||i.notificationIconColor||`#7c3aed`,onChange:t=>T(e,{notificationIconColor:t})}),(0,s.jsx)(ir,{label:`Heading colours`,hint:`The colours big headings fade through.`,value:r.textGradient||i.textGradient,onChange:t=>T(e,{textGradient:t})})]}),(0,s.jsx)(sr,{title:`Buttons`,onReset:()=>O(`Reset the buttons?`,`Every button colour in ${t.label.toLowerCase()} goes back to how it started. Nothing else changes.`,()=>A(e,lr))}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-3 items-start`,children:[(0,s.jsx)(ir,{label:`Button colours`,hint:`The colours your main buttons fade through.`,value:r.buttonGradient||i.buttonGradient,onChange:t=>T(e,{buttonGradient:t})}),(0,s.jsx)(ir,{label:`Button colours on hover`,hint:`How a main button looks under the pointer.`,value:r.buttonHoverGradient||i.buttonHoverGradient,onChange:t=>T(e,{buttonHoverGradient:t})}),(0,s.jsx)(rr,{over:a,label:`Button text`,hint:`The writing on your main buttons.`,value:r.buttonText||i.buttonText||`#ffffff`,onChange:t=>T(e,{buttonText:t})})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2 mt-1`,children:[(0,s.jsx)(`span`,{className:`text-[10px] font-extrabold uppercase tracking-wider text-foreground/40`,children:`Quieter buttons`}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-3 items-start`,children:[(0,s.jsx)(rr,{over:a,label:`Quiet button fill`,value:r.secondaryButton?.bg||i.secondaryButton?.bg||`rgba(0, 0, 0, 0.03)`,onChange:t=>E(e,{bg:t})}),(0,s.jsx)(rr,{over:a,label:`Quiet button edge`,value:r.secondaryButton?.border||i.secondaryButton?.border||`rgba(0, 0, 0, 0.06)`,onChange:t=>E(e,{border:t})}),(0,s.jsx)(rr,{over:a,label:`Quiet button text`,value:r.secondaryButton?.text||i.secondaryButton?.text||`#111827`,onChange:t=>E(e,{text:t})})]})]}),(0,s.jsx)(sr,{title:`Panels and highlights`,onReset:()=>O(`Reset the panels?`,`Panels, edges, the focus glow and text highlighting in ${t.label.toLowerCase()} go back to how they started. Nothing else changes.`,()=>A(e,ur))}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3 items-start`,children:[(0,s.jsx)(rr,{over:a,label:`Panel fill`,hint:`Background colour of cards and panels.`,value:r.panelBg||i.panelBg||`rgba(255, 255, 255, 0.70)`,onChange:t=>T(e,{panelBg:t})}),(0,s.jsx)(rr,{over:a,label:`Panel edge`,hint:`Borders of panels, inputs and dropdowns.`,value:r.panelBorder||i.panelBorder||`rgba(0, 0, 0, 0.08)`,onChange:t=>T(e,{panelBorder:t})}),(0,s.jsx)(rr,{over:a,label:`Focus glow`,hint:`The glow around the box someone is typing in.`,value:r.glowColor||i.glowColor||`rgba(124, 58, 237, 0.30)`,onChange:t=>T(e,{glowColor:t})}),(0,s.jsx)(rr,{over:a,label:`Highlight`,hint:`The colour behind text someone has selected.`,value:r.selectionBg||i.selectionBg||`rgba(124, 58, 237, 0.30)`,onChange:t=>T(e,{selectionBg:t})}),(0,s.jsx)(rr,{over:a,label:`Highlighted text`,hint:`The colour of the selected text itself.`,value:r.selectionText||i.selectionText||`#ffffff`,onChange:t=>T(e,{selectionText:t})})]})]},e)};return(0,s.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,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,s.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,s.jsx)(`p`,{className:`text-foreground/60 text-[15px] font-medium max-w-2xl`,children:`How your site looks. Every change here shows up straight away and saves itself.`})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(W,{}),(0,s.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-5 md:p-8 shadow-2xl relative bg-background flex flex-col min-h-[600px]`,children:[(0,s.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 mb-6 pb-5 border-b border-[var(--panel-border)]/50`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Your look`}),(0,s.jsx)(`p`,{className:`text-[13.5px] font-medium text-foreground/55 mt-1.5 leading-relaxed`,children:`Pick a ready-made set, or open a section and change one thing at a time.`})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(ge,{saving:d,savedAt:p}),(0,s.jsx)(Q,{icon:y?t._t:t.at,onClick:N,children:y?`Copied`:`Copy for my assistant`}),(0,s.jsx)(Q,{icon:t.D,tone:`danger`,busy:h,disabled:!_,onClick:()=>O(`Start the whole look again?`,`Every colour, the font and the corners go back to how they were the day you installed. This cannot be undone.`,M),children:`Start again`})]})]}),l?(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,s.jsxs)(le,{icon:t.Ot,title:`Name and logo`,description:`What your site is called, and the two little pictures that stand for it.`,actions:(0,s.jsx)(Q,{icon:t.D,onClick:()=>O(`Reset the name and logo?`,`The name, the opening mode, the logo and the browser icon go back to how they started.`,()=>k(dr)),children:`Reset`}),children:[(0,s.jsx)(de,{label:`Site name`,hint:`The name people see in the top bar and on the browser tab.`,value:l.appName||``,onChange:e=>w(`appName`,e),placeholder:`Your AI Firebase`}),(0,s.jsx)(pe,{label:`How the site opens`,hint:`Light, dark, or whichever one the visitor already uses on their device.`,value:l.defaultTheme||`system`,onChange:e=>w(`defaultTheme`,e||`system`),allowEmpty:!1,options:[{value:`system`,label:`Whatever their device uses`},{value:`light`,label:`Always light`},{value:`dark`,label:`Always dark`}]}),(l.defaultTheme||`system`)===`system`&&(0,s.jsx)(me,{label:`Let visitors switch it themselves`,hint:`Shows the sun and moon button in the top bar.`,enabled:l.showThemeToggle!==!1,onChange:e=>w(`showThemeToggle`,e)}),(0,s.jsx)(or,{label:`Logo`,hint:`The little picture in the top bar. Upload yours on the Assets page, then paste its link here.`,value:l.logoUrl||``,fallback:o.logoUrl||``,onChange:e=>w(`logoUrl`,e)}),(0,s.jsx)(or,{label:`Browser tab icon`,hint:`The tiny picture on the browser tab. Same place, same idea.`,value:l.faviconUrl||``,fallback:o.faviconUrl||``,onChange:e=>w(`faviconUrl`,e)}),(0,s.jsxs)(`p`,{className:`text-[11.5px] text-foreground/45 font-medium leading-relaxed px-1`,children:[`These two pictures are yours. Your assistant is told never to change them, so this page is the only place they ever move. Upload a new one on the`,` `,(0,s.jsx)(c.Link,{to:`/assets`,className:`text-accent font-bold hover:underline`,children:`Assets page`}),`.`]})]}),Gn.map(e=>P(e.key)),(0,s.jsxs)(le,{icon:t.g,title:`Lettering and corners`,description:`The typeface, and how rounded everything looks.`,defaultOpen:!1,actions:(0,s.jsx)(Q,{icon:t.D,onClick:()=>O(`Reset the lettering and corners?`,`The typeface and every corner go back to how they started.`,()=>k(fr)),children:`Reset`}),children:[(0,s.jsx)(pe,{label:`Typeface`,hint:`The lettering used everywhere on your site.`,value:l.fontFamily||`Inter`,onChange:e=>w(`fontFamily`,e||`Inter`),allowEmpty:!1,options:Wn.map(e=>({value:e,label:e}))}),(0,s.jsx)(pe,{label:`Corners`,hint:`Keep the rounding we ship with, or set each one yourself.`,value:l.cornerRounding||`default`,onChange:e=>w(`cornerRounding`,e||`default`),allowEmpty:!1,options:[{value:`default`,label:`Standard rounding`},{value:`custom`,label:`Set them myself`}]}),l.cornerRounding===`custom`&&(0,s.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,s.jsx)(ar,{label:`Buttons`,hint:`How round every button is.`,value:l.cornerRadii?.buttonRadius??.75,onChange:e=>w(`cornerRadii`,{...l.cornerRadii||{},buttonRadius:e})}),(0,s.jsx)(ar,{label:`Boxes people type in`,hint:`Form fields and search boxes.`,value:l.cornerRadii?.inputRadius??.75,onChange:e=>w(`cornerRadii`,{...l.cornerRadii||{},inputRadius:e})}),(0,s.jsx)(ar,{label:`Cards`,hint:`The panels your content sits on.`,value:l.cornerRadii?.cardRadius??1.5,onChange:e=>w(`cornerRadii`,{...l.cornerRadii||{},cardRadius:e})}),(0,s.jsx)(ar,{label:`Pop-ups`,hint:`Dialogs and confirmation boxes.`,value:l.cornerRadii?.modalRadius??2.5,onChange:e=>w(`cornerRadii`,{...l.cornerRadii||{},modalRadius:e})})]})]}),(0,s.jsx)(ke,{title:`Not sure which colours suit you?`,prompt:`I run a small design studio. Suggest one colour scheme for my site — a brand colour, a page background and a text colour for light mode and for dark mode — and give me each one as a colour code I can paste into the fields on my Theme page. Pick a typeface from Inter, Outfit, Roboto, Space Grotesk or Plus Jakarta Sans to go with it.`})]}):(0,s.jsx)(`div`,{className:`flex items-center justify-center flex-1 text-foreground/40 py-16`,children:(0,s.jsx)(t.L,{className:`w-6 h-6 animate-spin text-accent`})})]})]}),(0,s.jsx)(re,{isOpen:!!x,title:x?.title||``,message:x?.message||``,confirmText:`Reset`,cancelText:`Keep it`,isProcessing:h,onCancel:()=>S(null),onConfirm:()=>{x?.apply(),S(null)}})]})}var mr={route:`/page_1`,pageName:`New Page`,pageTitle:`My New Page`,template:`none`,form:``},hr={tabName:`New Page`,iconName:``,route:`/new-page`,tabTitle:`Your Page`,template:`none`,form:``},gr={tabName:`New Admin Page`,iconName:``,route:`/new-admin-page`,tabTitle:`Admin Page`,template:`none`,form:``},_r={tabName:`New Team Page`,iconName:``,route:`/new-team-page`,tabTitle:`Team Page`,template:`none`,form:``},vr=[{id:`home`,title:`Home`,path:`/`,type:`public`,isSystem:!0,enabled:!0},{id:`contact`,title:`Contact`,path:`/contact`,type:`public`,isSystem:!0,enabled:!0},{id:`guide`,title:`Guide`,path:`/guide`,type:`public`,isSystem:!0,enabled:!0},{id:`templates`,title:`Templates`,path:`/templates`,type:`public`,isSystem:!0,enabled:!0},{id:`support`,title:`Support`,path:`/support`,type:`user`,isSystem:!0,enabled:!0}],yr=e=>[...e,...vr.filter(t=>!e.some(e=>e.id===t.id))],br={public:`Anyone`,user:`Signed-in users`,internal:`Your team`,admin:`Admins only`},xr=e=>(e||``).trim().toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9_-]/g,``),Sr=(e,t,n,r)=>{let i=e.findIndex(e=>e.id===t);if(i===-1)return null;let a=r&&e[0]?.id===r?1:0,o=n===`up`?Math.max(a,i-1):Math.min(e.length-1,i+1);if(o===i||o<a)return null;let s=[...e],[c]=s.splice(i,1);return s.splice(o,0,c),s},Cr=()=>Object.fromEntries(M()),wr=(e,t=!1)=>{let n={};for(let[r,i]of Object.entries(Cr())){let a=!!i.isPublic;if(a!==e)continue;let o=i.config||{};!t&&o.enabled===!1||(n[r]={id:r,title:a?o.pageName||o.pageTitle||o.title||r:o.tabName||o.tabTitle||o.title||r,path:o.route?o.route.startsWith(`/`)?o.route:`/`+o.route:`/`+r,type:a?`public`:w(o.pageType),isSystem:!1,enabled:o.enabled!==!1,fromFile:!0})}return n};function Tr({value:e,onChange:n,busy:r}){return(0,s.jsx)(`div`,{className:`shrink-0`,onClick:e=>e.stopPropagation(),children:(0,s.jsx)(t.n,{compact:!0,portal:!0,direction:`auto`,className:`console-select`,ariaLabel:`Who can open this page`,value:e,disabled:r,onChange:e=>n(e),options:g.map(e=>({value:e,label:br[e]}))})})}var Er=`Add it here — its web address, a name, and what you would like to see on it — then copy the sentence for your assistant.`,Dr=[{value:`none`,label:`From scratch`},{value:`board`,label:`Board`},{value:`table`,label:`Table`},{value:`calendar`,label:`Calendar`},{value:`drive`,label:`Files`}],Or=[`board`,`table`,`calendar`,`drive`],kr={board:`board`,table:`table`,calendar:`calendar`,drive:`files`},Ar=e=>(e||``).split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``),jr=(e,t)=>t?.contentKey||t?.tabName||t?.pageName||t?.pageId||e.title,Mr=(e,t)=>`src/your-ai-workflow-firebase-os/microcomponents/${Ar(jr(e,t))||`Page`}Content.tsx`,Nr=(e,t)=>{let n=String(t?.route||``).trim();return n?n.startsWith(`/`)?n:`/`+n:e.path||``},Pr=(e,t)=>Nr(e,t).replace(/^\/+/,``)?String(t?.brief||``).trim()?``:`Say what you would like to see on this page, and this sentence is ready to copy.`:`Give this page a web address and it will be created — then this sentence is ready to copy.`,Fr=(e,t)=>{let n=Nr(e,t),r=String(t?.tabName||t?.pageName||``).trim(),i=r===`New page`?``:r,a=String(t?.template||``),o=String(t?.form||``).trim(),s=String(t?.brief||``).trim(),c=[`My app already has a page${i?` called ${i}`:``} at ${n}. It is already made and it is already in the menu — do not create a page, a web address or a settings file for it, and do not edit any other file.`,`Write one file: ${Mr(e,t)}, with a default export. That file is what the page shows.`,`Make it match the rest of my app: style with the app’s own theme styles so it looks right in light and dark. Do not pick your own colors, and do not add a <style> tag or any global CSS.`];return Or.includes(a)&&c.push(`The page already starts from the ${kr[a]} layout — build on it, do not rebuild it.`),o&&c.push(`Show my form ${Hr(o)} on it with <ContactPopup formId='${o}' /> — never write a form by hand.`),c.push(`Here is what I would like on it: ${s||`___`}`),c.join(`
|
|
135
|
+
`)},Ir={home:{title:`Change the home page`,prompt:`On my home page, change the big heading to Bright Studio and the line under it to We design websites for small businesses. Add a button that says Get in touch which opens my contact form as a pop-up, and below it three short sections: what we do, who it is for, and how to reach us.`},contact:{title:`Change the contact page`,prompt:`My app already has a contact page at /contact and a contact form. Show that form built into the page instead of as a pop-up, with a short line above it saying I reply within one working day. Write one file and nothing else: src/your-ai-workflow-firebase-os/microcomponents/ContactContent.tsx, with a default export that shows the form as <ContactPopup isInline formId='contact' />. Do not create a page, do not create a form, and do not change the questions the form asks.`},support:{title:`Change the support page`,prompt:`My app already has a support page at /support and a support form. Show that form built into the page instead of as a pop-up, with a short line above it saying what to include in a request. Write one file and nothing else: src/your-ai-workflow-firebase-os/microcomponents/SupportContent.tsx, with a default export that shows the form as <ContactPopup isInline formId='support' />. Do not create a page, do not create a form, and do not change the questions the form asks.`}},Lr=(e,t)=>{let n=e=>{let{_uiKey:t,pageType:n,route:r,contentKey:i,brief:a,...o}=e||{};return o},r=n(e),i=n(t),a=new Set([...Object.keys(r),...Object.keys(i)]);for(let e of a)if((r[e]??``)!==(i[e]??``))return!0;return!1},Rr=(e,t)=>{let{_uiKey:n,...r}=e||{};return Object.keys(r).length>0?{...r,pageType:t}:{pageType:t}},zr=`w-6 h-5 rounded-md flex items-center justify-center text-foreground/35 hover:text-foreground hover:bg-foreground/[0.07] transition-colors cursor-pointer`,Br=`hidden sm:inline-flex items-center gap-1 text-[10px] font-bold uppercase tracking-widest text-foreground/40 border border-[var(--panel-border)] px-2 py-0.5 rounded-md`,Vr=e=>{let t=typeof window<`u`?window.location.host:``;return t?`${t}${e}`:e},Hr=e=>e.replace(/[_-]+/g,` `).replace(/^./,e=>e.toUpperCase());function Ur({page:e,config:t,forms:n,saving:i,onSave:a,addressTaken:o,actions:c,footer:l,isNew:u}){let d=e.type===`public`,f=d?`pageName`:`tabName`,p=d?`pageTitle`:`tabTitle`,[m,h]=(0,r.useState)(()=>({...t||{}})),[g,_]=(0,r.useState)(``),v=(e,t)=>h(n=>({...n,[e]:t})),y=e=>{h(t=>({...t,...e}));let n={...t||{},...m,...e};delete n._uiKey,a(n)},b=e=>{(t||{})[e]!==m[e]&&y({[e]:m[e]})},x=String(m.route??``).replace(/^\/+/,``),S=(0,s.jsx)(de,{label:`Web address`,hint:u?`Where this page lives, e.g. /photos. The page is created as soon as you fill this in.`:`Where this page lives, e.g. /pricing`,prefix:`/`,value:x,onChange:e=>{v(`route`,e),g&&_(``)},onBlur:()=>{let n=xr(x);if(!n){_(`Give this page a web address, for example pricing`);return}if(o(e.id,n)){_(`Another page already lives at this address. Pick a different one.`);return}_(``),n===String(t?.route??``).replace(/^\/+/,``)?v(`route`,`/`+n):y({route:`/`+n})},error:g,placeholder:`photos`});return(0,s.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[u&&S,(0,s.jsx)(de,{label:d?`Name in the menu`:`Name in the dashboard`,hint:d?`What visitors see in the site menu.`:`What people see in the dashboard menu.`,value:m[f]??``,onChange:e=>v(f,e),onBlur:()=>b(f),placeholder:d?`Pricing`:`Photo Drive`}),(0,s.jsx)(de,{label:`Page heading`,hint:`The big heading people read at the top of the page.`,value:m[p]??``,onChange:e=>v(p,e),onBlur:()=>b(p),placeholder:`Our prices`}),!u&&S,!d&&(0,s.jsx)(Oe,{label:`Icon`,hint:`Shown next to the name in the dashboard menu.`,value:m.iconName??``,onChange:e=>y({iconName:e})}),!d&&(0,s.jsx)(pe,{label:`Starting layout`,hint:`What the page starts as. Your assistant fills in the rest when you ask.`,value:Dr.some(e=>e.value===m.template)?m.template:`none`,onChange:e=>y({template:e}),options:Dr,allowEmpty:!1}),(0,s.jsx)(pe,{label:`Form`,hint:d?`The form on this page. Only forms for website visitors are listed. Change a form itself under Forms.`:`The form on this page. Only forms for signed-in people are listed. Change a form itself under Forms.`,value:m.form??``,onChange:e=>y({form:e}),options:n.map(e=>({value:e,label:Hr(e)})),placeholder:`No form`}),(0,s.jsx)(fe,{label:`What would you like to see on this page?`,hint:`In your own words. This is what your assistant builds — it goes at the end of the sentence below.`,value:m.brief??``,onChange:e=>v(`brief`,e),onBlur:()=>b(`brief`),rows:4,placeholder:`A private photo gallery where I can upload pictures, put them in albums and open one full screen.`}),l,(0,s.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 pt-2 border-t border-[var(--panel-border)]/60`,children:[(0,s.jsx)(ge,{saving:i}),(0,s.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 ml-auto`,children:c})]})]})}function Wr(){let{userRole:e}=A(),n=(0,c.useLocation)(),[a,o]=(0,r.useState)(()=>{try{if(typeof window<`u`){let e=localStorage.getItem(`fbos_swr_pages`);if(e)return yr(JSON.parse(e))}}catch{}return vr}),[l,u]=(0,r.useState)(()=>{try{return sessionStorage.getItem(`fbos_pages_expandedId`)||null}catch{return null}}),d=(0,r.useRef)(l),[f,p]=(0,r.useState)(!1),[m,h]=(0,r.useState)(()=>{try{if(typeof window<`u`){let e=localStorage.getItem(`fbos_swr_page_configs`);if(e)return JSON.parse(e)}}catch{}return{}}),[g,_]=(0,r.useState)({}),[v,y]=(0,r.useState)({}),[b,x]=(0,r.useState)(null),[S,C]=(0,r.useState)(null),[T,E]=(0,r.useState)(!1),D=(0,r.useRef)(null);(0,r.useEffect)(()=>{function e(e){D.current&&!D.current.contains(e.target)&&p(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let[O,k]=(0,r.useState)(new Set),[j,M]=(0,r.useState)(new Set),[N,P]=(0,r.useState)([]),[F,I]=(0,r.useState)([]),L=e=>(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden,...e.removed?{removed:!0}:{}});(0,r.useEffect)(()=>{let e=(0,i.onSnapshot)((0,i.doc)(t.Pt,`sys_configs`,`page_order`),e=>{let t=L(e.exists()&&e.data().order||[]);P(t),k(new Set(t.filter(e=>e.hidden).map(e=>e.id)))}),n=(0,i.onSnapshot)((0,i.doc)(t.Pt,`sys_configs`,`tab_order`),e=>{let t=L(e.exists()&&e.data().order||[]);I(t),M(new Set(t.filter(e=>e.hidden).map(e=>e.id)))});return()=>{e(),n()}},[]),(0,r.useEffect)(()=>{let e=n.pathname.split(`/pages/`)[1]?.split(`/`)[0];e&&!l&&a.some(t=>t.id===e)&&u(e)},[n.pathname,a]),(0,r.useEffect)(()=>{d.current=l;try{l?sessionStorage.setItem(`fbos_pages_expandedId`,l):sessionStorage.removeItem(`fbos_pages_expandedId`)}catch{}},[l]);let R=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=R.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,r.useEffect)(()=>{(async()=>{try{let[e,n]=await Promise.all([(0,i.getDocs)((0,i.collection)(t.Pt,`sys_pages`)),(0,i.getDocs)((0,i.collection)(t.Pt,`sys_tabs`))]),r=[`home`,`drive`,`assets`,`contact`,`guide`,`templates`,`support`,`theme`,`page_order`,`tab_order`],a=[],s={};e.forEach(e=>{if(!r.includes(e.id)){let t=e.data();a.push({id:e.id,title:t.pageName||t.title||e.id,path:t.route||`/`+e.id,type:`public`,isSystem:!1,enabled:t.enabled!==!1}),s[e.id]=t}}),n.forEach(e=>{if(!r.includes(e.id)){let t=e.data(),n=w(t.pageType);a.push({id:e.id,title:t.tabName||t.title||e.id,path:t.route||`/`+e.id,type:n,isSystem:!1,enabled:t.enabled!==!1}),s[e.id]=t}});let c=Cr(),l={...wr(!0,!0),...wr(!1,!0)};for(let[e,t]of Object.entries(l)){if(s[e])continue;let n=a.find(e=>e.path===t.path);if(n){n.fromFile=!0;continue}a.push(t),s[e]=c[e]?.config||{}}o(e=>{let t=yr(e.filter(e=>(e.isSystem||e.id.startsWith(`draft_`))&&e.id!==`drive`)),n=a.filter(e=>!t.some(t=>t.id===e.id)),r=[...t,...n];return typeof window<`u`&&localStorage.setItem(`fbos_swr_pages`,JSON.stringify(r)),r}),h(e=>{let t={...e,...s};return typeof window<`u`&&localStorage.setItem(`fbos_swr_page_configs`,JSON.stringify(t)),t})}catch(e){console.error(`Error loading custom pages`,e)}})()},[]);let[ee,z]=(0,r.useState)([`contact`]),[te,B]=(0,r.useState)([`support`]);(0,r.useEffect)(()=>{let e=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},n={...t.a,...e},r=new Set([`contact`]),a=new Set([`support`]);Object.entries(n).forEach(([e,t])=>{t.formType===`private`?a.add(t.systemName||e):r.add(t.systemName||e)}),(0,i.getDocs)((0,i.collection)(t.Pt,`sys_forms`)).then(e=>{e.docs.forEach(e=>{e.data().formType===`private`?a.add(e.id):r.add(e.id)}),z(Array.from(r)),B(Array.from(a))}).catch(e=>{console.warn(`Failed fetching sys_forms in PagesAdmin:`,e),z(Array.from(r)),B(Array.from(a))})},[]);let ne=async(e,n,r)=>{if(n.route&&!n.route.startsWith(`/`)&&(n.route=`/`+n.route),!String(n.route||``).replace(/^\/+/,``).trim()){h(t=>({...t,[e]:n}));return}let s=a.find(t=>t.id===e),c=r||s?.type||n.pageType||(e.startsWith(`pub_`)?`public`:void 0),l=c===`public`?`sys_pages`:`sys_tabs`;c&&c!==`public`?n.pageType=c:delete n.pageType;let f=Object.fromEntries(Object.entries(n).filter(([e,t])=>t!==void 0)),p=n.route?n.route.replace(/^\/+/,``).replace(/[^a-zA-Z0-9_-]/g,`_`).toLowerCase():e;f.contentKey||=p,n={...n,contentKey:f.contentKey},_(t=>({...t,[e]:!0,[p]:!0}));try{if(p!==e&&p.trim()!==``&&p!==`draft`){try{let{deleteDoc:n}=await import(`firebase/firestore`);await n((0,i.doc)(t.Pt,l,e))}catch{}await(0,i.setDoc)((0,i.doc)(t.Pt,l,p),f),o(t=>t.map(t=>t.id===e?{...t,id:p,_uiKey:t._uiKey||e,path:n.route,title:n.pageName||n.tabName||n.title||t.title}:t)),d.current===e&&(u(p),window.history.replaceState(null,``,`/pages/${p}`)),h(t=>{let r={...t};return r[p]=n,delete r[e],r});let r=c===`public`,a=r?`page_order`:`tab_order`,s=r?N:F;if(!s.some(e=>e.id===p)){let n=[{id:p,hidden:!1},...s.filter(t=>t.id!==e)];try{await(0,i.setDoc)((0,i.doc)(t.Pt,`sys_configs`,a),{order:n})}catch(e){console.error(`Failed to update tab order:`,e)}}}else await(0,i.setDoc)((0,i.doc)(t.Pt,l,e),f),h(t=>({...t,[e]:n})),o(t=>t.map(t=>t.id===e?{...t,path:n.route||t.path,title:n.pageName||n.tabName||n.title||t.title}:t))}catch(t){console.error(`Failed to save ${e} config:`,t)}finally{setTimeout(()=>{_(t=>({...t,[e]:!1,[p]:!1}))},500)}},V=e=>{let t=`draft_`+Math.floor(Math.random()*1e5),n={id:t,title:`New page`,path:``,type:e,isSystem:!1,enabled:!0},r=e===`public`?{route:``,pageName:``,pageTitle:``,form:``,brief:``}:{route:``,tabName:``,tabTitle:``,iconName:``,template:`none`,form:``,brief:``,pageType:e};o(e=>[...e,n]),h(e=>({...e,[t]:r})),u(t),p(!1),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView?.({behavior:`smooth`,block:`center`})},100)},H=e=>e.id.startsWith(`draft_`);if(e!==`admin`)return(0,s.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,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,s.jsx)(t.C,{className:`w-12 h-12 text-red-500 mb-4`}),(0,s.jsx)(`h2`,{className:`text-2xl font-bold`,children:`Access Denied`}),(0,s.jsx)(`p`,{className:`text-foreground/60`,children:`You do not have permission to view pages configuration.`})]})});let U=async(e,n,r)=>{let s=r===`public`,c=s?`page_order`:`tab_order`,l=s?N:F,u=(s?O:j).has(e);o(a.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,i.setDoc)((0,i.doc)(t.Pt,`sys_configs`,c),{order:d})},G=e=>!!e.fromFile&&(e.type===`public`?N:F).some(t=>t.id===e.id&&t.removed),K=async(e,n)=>{if(e.type===n)return;let r=e.type;o(t=>t.map(t=>t.id===e.id?{...t,type:n}:t)),_(t=>({...t,[e.id]:!0}));let a=Rr(m[e.id],n);try{await(0,i.setDoc)((0,i.doc)(t.Pt,`sys_tabs`,e.id),a,{merge:!0}),h(t=>t[e.id]?{...t,[e.id]:{...t[e.id],pageType:n}}:t)}catch(t){console.error(`Failed to change the audience of ${e.id}:`,t),o(t=>t.map(t=>t.id===e.id?{...t,type:r}:t))}finally{_(t=>({...t,[e.id]:!1}))}},q=(e,t)=>{if(!t){if(H({id:e})){o(t=>t.filter(t=>t.id!==e)),h(t=>{let n={...t};return delete n[e],n}),l===e&&u(null);return}x(e)}},J=async()=>{if(b){E(!0);try{let{deleteDoc:e,collection:n,getDocs:r,doc:i,getDoc:s,query:c,where:d}=await import(`firebase/firestore`),{ref:f,deleteObject:p}=await import(`firebase/storage`),h=a.find(e=>e.id===b),g=h?.type===`public`?`sys_pages`:`sys_tabs`;if(g===`sys_tabs`&&h){let a=m[b];if(!a)try{let e=await s(i(t.Pt,`sys_tabs`,b));e.exists()&&(a=e.data())}catch{}let o=(a?.tabName||a?.pageId||b).toLowerCase().replace(/[^a-z0-9]+/g,`_`),l=[`admin_${o}_records`,`mem_${o}_records`,`user_${o}_records`],u={[`admin_${o}_records`]:{prefix:`admin_files`,driveCollection:`admin_files`},[`mem_${o}_records`]:{prefix:`mem_files`,driveCollection:`mem_files`},[`user_${o}_records`]:{prefix:`user_files`,driveCollection:`user_files`}},h=[];for(let i of l)h.push((async()=>{try{let a=await r(n(t.Pt,i)),o=u[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(t.It,`${o.prefix}/${decodeURIComponent(s)}`)).catch(()=>{});let l=await r(c(n(t.Pt,o.driveCollection),d(`downloadURL`,`==`,a.downloadURL)));await Promise.all(l.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`])h.push((async()=>{try{let a=await r(c(n(t.Pt,i),d(`sourceTab`,`==`,o)));await Promise.all(a.docs.map(async n=>{let r=n.data();if(r.downloadURL)try{let e=`${i}%2F`,n=r.downloadURL.split(e)[1]?.split(`?`)[0];n&&await p(f(t.It,`${i}/${decodeURIComponent(n)}`)).catch(()=>{})}catch{}await e(n.ref)}))}catch{}})());await Promise.all(h)}await e(i(t.Pt,g,b));let _=g===`sys_pages`?`page_order`:`tab_order`,v=g===`sys_pages`?N:F,{setDoc:y}=await import(`firebase/firestore`),x=h?.fromFile?[...v.filter(e=>e.id!==b),{id:b,hidden:!0,removed:!0}]:v.filter(e=>e.id!==b);await y(i(t.Pt,`sys_configs`,_),{order:x}),o(e=>e.filter(e=>e.id!==b)),l===b&&u(null)}catch(e){console.error(`Error deleting page:`,e)}E(!1),x(null)}},Y=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,fromFile:!1};o(e=>[...e,n]);let r={...m[e.id]||{},route:n.path,pageName:n.title};n.type!==`public`&&(r.tabName=n.title,r.pageType=n.type),h(e=>({...e,[t]:r})),u(t),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})},100)},ie=async(e,n)=>{if(e.isSystem)return;let r=e.type===`public`,o=r?`page_order`:`tab_order`,s=[...r?N:F];a.filter(e=>e.type===`public`===r&&!e.isSystem&&!s.some(t=>t.id===e.id)).forEach(e=>s.push({id:e.id,hidden:!1}));let c=Sr(s,e.id,n,r?`home`:void 0);if(c){r?P(c):I(c);try{await(0,i.setDoc)((0,i.doc)(t.Pt,`sys_configs`,o),{order:c})}catch(e){console.error(`Failed to reorder pages:`,e)}}},ae=(e,t)=>{let n=t.replace(/[^a-zA-Z0-9_-]/g,`_`).toLowerCase();return a.some(r=>{if(r.id===e)return!1;let i=String(m[r.id]?.route??r.path??``).replace(/^\/+/,``).toLowerCase();return i!==``&&i===t||r.id===n})},oe=e=>e===`admin`?gr:e===`internal`?_r:e===`public`?mr:hr,se=async()=>{let e=a.find(e=>e.id===S);if(!e){C(null);return}y(t=>({...t,[e.id]:!0}));let t=m[e.id]||{};await ne(e.id,{...oe(e.type),...t.contentKey?{contentKey:t.contentKey}:{},...t.brief?{brief:t.brief}:{}}),y(t=>({...t,[e.id]:!1})),C(null)},X=[{id:`public`,title:`Anyone`,icon:t.X,description:`Pages on your website. Anyone can open them, signed in or not, and they show up in the site menu.`,filter:e=>e.type===`public`},{id:`user`,title:`Signed-in users`,icon:t.I,description:`Pages in the dashboard that every signed-in person can open. Each person sees only their own information.`,filter:e=>e.type===`user`},{id:`internal`,title:`Your team`,icon:t.et,description:`Pages in the dashboard for the people you marked as team members under Users, plus admins. Everyone who can open them sees the same information — signed-in users never see them at all.`,filter:e=>e.type===`internal`},{id:`admin`,title:`Admins only`,icon:t.C,description:`Pages in the dashboard only admins can open.`,filter:e=>e.type===`admin`}];return(0,s.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,s.jsx)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,s.jsxs)(`div`,{children:[(0,s.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:`Your Pages`}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/pages`]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(W,{}),(0,s.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,s.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,s.jsx)(`div`,{children:(0,s.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 leading-relaxed max-w-3xl`,children:`Add a page here — its web address, its name, who it is for and what you would like on it — then copy the sentence it writes for you into your assistant's chat. The assistant only fills the page in; creating, renaming, reordering, hiding and deleting all happen right here.`})}),(0,s.jsx)(`div`,{className:`relative z-50 shrink-0 flex items-center gap-1`,children:(0,s.jsxs)(`div`,{className:`relative`,children:[(0,s.jsx)(t.r,{variant:`secondary`,onClick:()=>p(!f),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 a page`,children:(0,s.jsx)(t.k,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,s.jsx)(t.s,{children:f&&(0,s.jsxs)(t.o.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-56 glass-popover border border-[var(--panel-border)] rounded-2xl p-2 z-50 flex flex-col gap-1`,children:[(0,s.jsx)(`span`,{className:`px-3 pt-1 pb-2 text-[10px] font-bold uppercase tracking-widest text-foreground/40`,children:`Add a page for`}),[`public`,`user`,`internal`,`admin`].map(e=>(0,s.jsx)(`button`,{onClick:()=>V(e),className:`text-left px-3 py-2 text-[13px] font-bold text-foreground/70 hover:text-foreground hover:bg-foreground/5 rounded-lg transition-colors cursor-pointer`,children:br[e]},e))]})})]})})]}),(0,s.jsx)(`div`,{ref:R,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:X.map((e,n)=>{let r=a.filter(e.filter).filter(e=>!G(e)),i=e.id===`public`?N:F,o=r.sort((e,t)=>{if(e.id===`home`)return-1;if(t.id===`home`)return 1;let n=i.findIndex(t=>t.id===e.id),r=i.findIndex(e=>e.id===t.id);return n===-1&&r===-1?0:n===-1?1:r===-1?-1:n-r}),c=e.icon,d=e=>e.type===`public`?O.has(e.id):j.has(e.id),f=o.filter(e=>!d(e)),p=o.filter(e=>d(e)),h=(n,r)=>{let i=n.isSystem?Ir[n.id]:void 0,a=l===n.id,o=H(n),c=!n.isSystem||!!i,d=o?`Not saved yet — give it a web address`:r?`Hidden`:n.type===`public`?`Shown in the site menu`:`Shown in the dashboard`;return(0,s.jsxs)(`div`,{id:`page-${n.id}`,onClick:()=>{if(c){let e=a?null:n.id;u(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 ${c?`cursor-pointer hover:border-accent/40`:``} ${r?`opacity-60 bg-foreground/[0.01] border-[var(--panel-border)]/50`:`border-transparent hover:border-[var(--panel-border)]`}`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between w-full gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-start gap-2 flex-1 min-w-0`,children:[!n.isSystem&&!o&&(0,s.jsxs)(`div`,{className:`flex flex-col shrink-0 pt-0.5`,onClick:e=>e.stopPropagation(),children:[(0,s.jsx)(`button`,{type:`button`,title:`Move up`,"aria-label":`Move ${n.title} up`,onClick:()=>ie(n,`up`),className:zr,children:(0,s.jsx)(t.pt,{className:`w-3.5 h-3.5`})}),(0,s.jsx)(`button`,{type:`button`,title:`Move down`,"aria-label":`Move ${n.title} down`,onClick:()=>ie(n,`down`),className:zr,children:(0,s.jsx)(t.gt,{className:`w-3.5 h-3.5`})})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,s.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground truncate`,children:n.title}),n.fromFile&&(0,s.jsxs)(`span`,{className:Br,title:`Your assistant built this one. Delete hides it and gives you the sentence that removes its files.`,children:[(0,s.jsx)(t.$,{className:`w-3 h-3`}),` Built for you`]})]}),(0,s.jsxs)(`span`,{className:`text-[11.5px] font-medium text-foreground/45 truncate`,children:[d,n.path?` · Web address ${Vr(n.path)}`:``]})]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 self-end sm:self-auto`,children:[n.type!==`public`&&!o&&(0,s.jsx)(Tr,{value:n.type,busy:g[n.id],onChange:e=>K(n,e)}),n.id!==`home`&&!o&&(0,s.jsx)(Q,{icon:r?t.et:t.tt,onClick:e=>{e.stopPropagation(),U(n.id,n.isSystem,n.type)},children:r?`Show`:`Hide`}),c?(0,s.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 shrink-0 ${a?`rotate-180`:``}`,children:(0,s.jsx)(t.gt,{className:`w-3.5 h-3.5`})}):(0,s.jsx)(`div`,{className:`w-[24px] shrink-0`})]})]}),(0,s.jsxs)(t.s,{children:[a&&i&&(0,s.jsx)(t.o.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-1`,onClick:e=>e.stopPropagation(),children:(0,s.jsx)(ke,{compact:!0,title:i.title,prompt:i.prompt})}),a&&!n.isSystem&&m[n.id]&&(0,s.jsx)(t.o.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-1`,onClick:e=>e.stopPropagation(),children:(0,s.jsx)(Ur,{page:n,config:m[n.id],forms:n.type===`public`?ee:te,saving:g[n.id],isNew:o,onSave:e=>ne(n.id,e),addressTaken:ae,footer:(0,s.jsx)(ke,{compact:!0,title:`Then copy this into your assistant’s chat`,prompt:Fr(n,m[n.id]),locked:!!Pr(n,m[n.id]),lockedHint:Pr(n,m[n.id])}),actions:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Q,{icon:t.at,onClick:()=>Y(n),children:`Duplicate`}),!n.fromFile&&Lr(m[n.id],oe(n.type))&&(0,s.jsx)(Q,{icon:t.D,tone:`danger`,busy:v[n.id],onClick:()=>C(n.id),children:`Reset`}),!n.isSystem&&(0,s.jsx)(Q,{icon:t.y,tone:`danger`,onClick:()=>q(n.id,n.isSystem),children:`Delete`})]})},n.id)})]})]},`${e.id}-${n._uiKey||n.id}`)};return(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex flex-col relative`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-3 mb-2 border-b border-[var(--panel-border)]/50 pb-4`,children:[(0,s.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,s.jsx)(c,{className:`w-4 h-4 text-accent`})}),(0,s.jsx)(`h2`,{className:`text-xl font-extrabold tracking-tight text-foreground`,children:e.title})]}),(0,s.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,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center gap-3 rounded-2xl border border-dashed border-[var(--panel-border)] px-5 py-4`,children:[(0,s.jsx)(Q,{icon:t.k,onClick:()=>V(e.id),children:`Add a page`}),(0,s.jsx)(`p`,{className:`text-[12.5px] text-foreground/55 font-medium leading-relaxed`,children:Er})]}):(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[f.map(e=>h(e,!1)),p.length>0&&(0,s.jsxs)(`details`,{className:`mt-4 group/details`,children:[(0,s.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,s.jsx)(t.gt,{className:`w-3.5 h-3.5 group-open/details:-rotate-180 transition-transform`}),`Hidden pages (`,p.length,`)`]}),(0,s.jsx)(`div`,{className:`flex flex-col gap-4 mt-4`,children:p.map(e=>h(e,!0))})]})]}),n<X.length-1&&(0,s.jsx)(`div`,{className:`w-full border-t border-[var(--panel-border)]/70 my-10`})]},e.id)})})]})]}),(0,s.jsx)(re,{isOpen:!!b,onCancel:()=>x(null),onConfirm:J,title:`Delete this page?`,message:`The page and everything saved on it will be gone for good. This cannot be undone.`,confirmText:`Delete page`,isProcessing:T}),(0,s.jsx)(re,{isOpen:!!S,onCancel:()=>C(null),onConfirm:se,title:`Reset this page?`,message:`Its name, heading, web address, icon and form go back to how they started. What people have saved on the page is kept.`,confirmText:`Reset page`,isProcessing:!!S&&!!v[S]})]})}var Gr=new Set([`contact`,`support`]),Kr=[{value:`text`,label:`Short text`},{value:`textarea`,label:`Long text`},{value:`email`,label:`Email`},{value:`tel`,label:`Phone`},{value:`number`,label:`Number`},{value:`currency`,label:`Money`},{value:`checkbox`,label:`Yes-no`},{value:`select`,label:`Choose one`}],qr={age:`Age`},Jr=e=>Kr.find(t=>t.value===e)?.label||qr[e||``]||`Short text`,Yr=e=>Kr.some(t=>t.value===e)||!e?Kr:[...Kr,{value:e,label:Jr(e)}],Xr={public:`Anyone`,private:`Signed-in users`},Zr=e=>(e||``).toLowerCase().trim().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``),Qr=(e,t)=>{if(!t.includes(e))return e;let n=2;for(;t.includes(`${e}_${n}`);)n++;return`${e}_${n}`},$r=(e,t,n)=>{if(!(!e.name||e.name===Zr(e.label||``)))return e.name;let r=Zr(t);return r?Qr(r,n.filter(t=>t!==e).map(e=>e.name)):``},ei=()=>({name:``,type:`text`,label:``,placeholder:``,required:!1}),ti={firstForm:`Add the form here — its fields and who can fill it in — then tell your assistant which page should use it.`,forPage:(e,t)=>`Use the form called ${e||t} (its id is ${t}) on the page I name — show it with <ContactPopup formId='${t}' />. Do not create a form, do not change this form's fields, do not write a form by hand.`};function ni({choices:e,onChange:n}){return(0,s.jsx)(ue,{label:`Choices`,hint:`The options people pick from.`,children:(0,s.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.length===0&&(0,s.jsx)(`span`,{className:`text-[12px] text-foreground/40 font-medium px-1`,children:`No choices yet — add the first one.`}),e.map((r,i)=>(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(`input`,{type:`text`,value:r,"aria-label":`Choice ${i+1}`,placeholder:`e.g. Under 1,000`,onChange:t=>n(e.map((e,n)=>n===i?t.target.value:e)),className:oe}),(0,s.jsx)(Q,{icon:t.d,tone:`danger`,title:`Remove choice ${i+1}`,onClick:()=>n(e.filter((e,t)=>t!==i)),children:`Remove`})]},i)),(0,s.jsx)(`div`,{children:(0,s.jsx)(Q,{icon:t.k,onClick:()=>n([...e,``]),children:`Add choice`})})]})})}function ri(){let{userRole:e}=A(),n=(0,c.useNavigate)(),a=t.Mt(),o=()=>{let e=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},n={...t.a,contact:a?.defaultConfigs?.contactForm||t.a.contact,support:a?.defaultConfigs?.supportForm||t.a.support};for(let[t,r]of Object.entries(e))n[t]=r;return n},[l,u]=(0,r.useState)(()=>{try{if(typeof window<`u`){let e=localStorage.getItem(`fbos_swr_forms`);if(e)return JSON.parse(e)}let e={...t.a,contact:a?.defaultConfigs?.contactForm||t.a.contact,support:a?.defaultConfigs?.supportForm||t.a.support},n=(typeof window<`u`?window.__FBOS_FORMS__:null)||{};for(let[t,r]of Object.entries(n))e[t]=r;let r={};for(let[t,n]of Object.entries(e)){let e=JSON.parse(JSON.stringify(n));e._uiKey=Math.random().toString(36).substring(7),r[t]=e}return r}catch{return{}}}),[d,f]=(0,r.useState)(()=>!(typeof window<`u`&&localStorage.getItem(`fbos_swr_forms`))),[p,m]=(0,r.useState)({}),[h,g]=(0,r.useState)(null),[_,v]=(0,r.useState)(new Set),[y,b]=(0,r.useState)({}),[x,S]=(0,r.useState)(null),[C,w]=(0,r.useState)(!1),[T,E]=(0,r.useState)({}),D=(0,r.useRef)({}),O=(e,t)=>{D.current={...D.current,[e]:t},E(D.current)};(0,r.useEffect)(()=>{k()},[]);let k=async()=>{try{f(!0);let e=await(0,i.getDocs)((0,i.collection)(t.Pt,`sys_forms`)),n={},r=new Set;e.forEach(e=>{if(e.id!==`pubForm`&&e.id!==`userForm`){let t=e.data();t._uiKey=l[e.id]?._uiKey||t._uiKey||Math.random().toString(36).substring(7),n[e.id]=t,r.add(e.id)}}),v(r);try{await(0,i.deleteDoc)((0,i.doc)(t.Pt,`sys_forms`,`pubForm`)),await(0,i.deleteDoc)((0,i.doc)(t.Pt,`sys_forms`,`userForm`))}catch{}let a=o();for(let[e,t]of Object.entries(a))if(!n[e]){let r={...t};r._uiKey=l[e]?._uiKey||Math.random().toString(36).substring(7),n[e]=r}else if(n[e]._uiKey=l[e]?._uiKey||n[e]._uiKey||Math.random().toString(36).substring(7),!n[e].fields||n[e].fields.length===0){let t=a[e];n[e].fields=t.fields||[]}let s={};for(let e of Object.keys(a))n[e]&&(s[e]=n[e]);for(let e of Object.keys(n))s[e]||(s[e]=n[e]);let c=window.location.pathname.split(`/forms/`)[1]?.split(`/`)[0];c&&s[c]&&b({[c]:!0}),D.current={},E({}),u(s),typeof window<`u`&&localStorage.setItem(`fbos_swr_forms`,JSON.stringify(s))}catch(e){console.error(`Failed to load forms:`,e)}finally{f(!1)}},j=async(e,n)=>{let r={...n};l[e]?._uiKey&&(r._uiKey=l[e]._uiKey),delete r.submitPage,e===`contact`?(r.systemName=`contact`,r.formType=`public`):e===`support`&&(r.systemName=`support`,r.formType=`private`);let a=r.systemName||e;if(a!==e&&a.trim()!==``){u(t=>{let n={};for(let i of Object.keys(t))i===e?n[a]=r:n[i]=t[i];return n}),y[e]&&b(t=>{let n={};for(let r of Object.keys(t))r===e?n[a]=t[r]:n[r]=t[r];return n}),m(e=>({...e,[a]:!0}));try{await(0,i.setDoc)((0,i.doc)(t.Pt,`sys_forms`,a),r),await(0,i.deleteDoc)((0,i.doc)(t.Pt,`sys_forms`,e)),localStorage.setItem(`fbos_custom_form_${a}`,`true`),localStorage.removeItem(`fbos_custom_form_${e}`),localStorage.setItem(`fbos_form_${a}`,JSON.stringify(r)),localStorage.removeItem(`fbos_form_${e}`)}catch(e){console.error(`Failed to migrate form map ID:`,e)}finally{setTimeout(()=>{m(e=>({...e,[a]:!1}))},500)}}else{u(t=>({...t,[e]:r})),m(t=>({...t,[e]:!0}));try{await(0,i.setDoc)((0,i.doc)(t.Pt,`sys_forms`,e),r),localStorage.setItem(`fbos_custom_form_${e}`,`true`),localStorage.setItem(`fbos_form_${e}`,JSON.stringify(r))}catch(e){console.error(`Failed to save form:`,e)}finally{setTimeout(()=>{m(t=>({...t,[e]:!1}))},500)}}},M=(e,t,n)=>O(e,{...t,...n}),N=(e,t,n)=>{let r={...t,...n};O(e,r),j(e,r)},P=e=>{let t=D.current[e];t&&j(e,t)},F=(e,t,n)=>N(e,t,{fields:n}),[I,L]=(0,r.useState)(!1),R=async()=>{if(I)return;L(!0);let e=`new_form_${Date.now().toString().slice(-4)}`,r={title:`New form`,systemName:e,formType:`public`,redirectTo:``,buttonName:`Send`,submitText:`Send`,fields:[],enabled:!0,_uiKey:Math.random().toString(36).substring(7)};try{m(t=>({...t,[e]:!0})),await(0,i.setDoc)((0,i.doc)(t.Pt,`sys_forms`,e),r),u(t=>({[e]:r,...t})),b(t=>({[e]:!0,...t})),n(`/forms/${e}`)}catch(e){console.error(`Failed to create form`,e)}finally{m(t=>({...t,[e]:!1})),L(!1)}},ee=async e=>{if(!Gr.has(e)){w(!0);try{await(0,i.deleteDoc)((0,i.doc)(t.Pt,`sys_forms`,e)),u(t=>{let n={...t};return delete n[e],n}),n(`/forms`)}catch(e){console.error(`Failed to delete form`,e)}finally{w(!1),S(null)}}},z=async e=>{if(!_.has(e)){S(null);return}w(!0);let n=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},r=Gr.has(e)||!!n[e]||!!a?.defaultConfigs?.[e]||!!a?.defaultConfigs?.[`${e}Form`];try{r?(m(t=>({...t,[e]:!0})),await(0,i.deleteDoc)((0,i.doc)(t.Pt,`sys_forms`,e)),localStorage.removeItem(`fbos_form_${e}`),localStorage.removeItem(`fbos_custom_form_${e}`),await k(),setTimeout(()=>m(t=>({...t,[e]:!1})),500)):await j(e,o().contact||o().support)}catch(e){console.error(`Reset failed:`,e)}finally{w(!1),S(null)}};if(e!==`admin`)return(0,s.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,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,s.jsx)(t._,{className:`w-12 h-12 text-red-500 mb-4`}),(0,s.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,s.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 te=e=>{b(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})},B=Object.keys(y).find(e=>y[e]),ne=(e,n,r,i,a)=>{let o=(t,r)=>{let o=a.map((e,n)=>n===i?{...e,...t}:e);r?F(e,n,o):M(e,n,{fields:o})},c=t=>{let r=i+t;if(r<0||r>=a.length)return;let o=[...a];[o[i],o[r]]=[o[r],o[i]],F(e,n,o)},l=r.type!==`checkbox`&&r.type!==`select`;return(0,s.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)] p-4 sm:p-5 flex flex-col gap-5`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[(0,s.jsxs)(`span`,{className:`text-[13px] font-bold text-foreground`,children:[`Question `,i+1,` `,(0,s.jsxs)(`span`,{className:`text-foreground/40 font-medium`,children:[`· `,Jr(r.type)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,s.jsx)(Q,{icon:t.St,disabled:i===0,title:`Move up`,onClick:()=>c(-1),children:`Up`}),(0,s.jsx)(Q,{icon:t.Tt,disabled:i===a.length-1,title:`Move down`,onClick:()=>c(1),children:`Down`}),(0,s.jsx)(Q,{icon:t.y,tone:`danger`,title:`Remove question ${i+1}`,onClick:()=>F(e,n,a.filter((e,t)=>t!==i)),children:`Remove`})]})]}),(0,s.jsx)(de,{label:`Question`,hint:`What you are asking for, in the words the person will read.`,value:r.label||``,placeholder:`e.g. What is your budget?`,onChange:e=>o({label:e,name:$r(r,e,a)},!1),onBlur:()=>P(e)}),(0,s.jsx)(pe,{label:`Kind of answer`,hint:`Sets the box people type into and what counts as a valid answer.`,value:r.type||`text`,options:Yr(r.type),allowEmpty:!1,onChange:e=>o(e===`select`?{type:e,options:r.options||[]}:{type:e},!0)}),(0,s.jsx)(me,{label:`Required`,hint:`On means the form cannot be sent until this is answered.`,enabled:!!r.required,onChange:e=>o({required:e},!0)}),r.type===`select`&&(0,s.jsx)(ni,{choices:r.options||[],onChange:e=>o({options:e},!0)}),r.type===`currency`&&(0,s.jsx)(de,{label:`Currency symbol`,hint:`Shown inside the box, before the amount.`,value:r.currencySymbol||``,placeholder:`$`,onChange:e=>o({currencySymbol:e},!1),onBlur:()=>P(e)}),l&&(0,s.jsx)(de,{label:`Example answer`,hint:`Faint grey text inside the box, to show people what you expect.`,value:r.placeholder||``,placeholder:`e.g. jane@example.com`,onChange:e=>o({placeholder:e},!1),onBlur:()=>P(e)})]},i)},V=(e,n)=>{let r=T[e]||n,i=Gr.has(e),a=r.formType||`public`,o=r.fields||[],c=_.has(e);return(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,s.jsxs)(le,{icon:t.g,title:`Basics`,description:`What people see at the top of this form and on its button.`,children:[(0,s.jsx)(de,{label:`Form name`,hint:`The heading at the top of the form.`,value:r.title||``,placeholder:`e.g. Get in touch`,onChange:t=>M(e,r,{title:t}),onBlur:()=>P(e)}),(0,s.jsx)(de,{label:`Button text`,hint:`The words on the button that sends the form.`,value:r.buttonName||r.submitText||``,placeholder:`e.g. Send message`,onChange:t=>M(e,r,{buttonName:t,submitText:t}),onBlur:()=>P(e)})]}),(0,s.jsx)(le,{icon:t.p,title:`Who it is for`,description:`Who can fill this in, and where their answers land.`,children:(0,s.jsx)(pe,{label:`Who it is for`,hint:i?`This form comes with your site, so who it is for cannot change. Answers arrive in your Inbox.`:`Anyone means visitors who are not signed in — their answers arrive in your Inbox under From anyone. Signed-in users means people with an account — their answers arrive under From signed-in users.`,value:a,allowEmpty:!1,disabled:i,options:[{value:`public`,label:`Anyone`},{value:`private`,label:`Signed-in users`}],onChange:t=>N(e,r,{formType:t})})}),(0,s.jsx)(le,{icon:t.T,title:`After sending`,description:`What happens the moment someone sends this form.`,children:(0,s.jsx)(de,{label:`Where to send them next`,hint:`Leave this empty to show a thank-you message instead. Or give a web address, like /pricing, to take them there.`,value:r.redirectTo||``,placeholder:`/pricing`,onChange:t=>M(e,r,{redirectTo:t}),onBlur:()=>P(e)})}),(0,s.jsxs)(le,{icon:t.R,title:`Questions`,description:`Everything this form asks for, in the order people answer it.`,actions:(0,s.jsx)(Q,{icon:t.k,onClick:()=>F(e,r,[...o,ei()]),children:`Add question`}),children:[o.length===0?(0,s.jsx)(`p`,{className:`text-[12.5px] text-foreground/55 font-medium leading-relaxed`,children:`No questions yet. Add the first one with the button above.`}):o.map((t,n)=>ne(e,r,t,n,o)),o.length>0&&(0,s.jsx)(`div`,{className:`flex justify-start`,children:(0,s.jsx)(Q,{icon:t.k,onClick:()=>F(e,r,[...o,ei()]),children:`Add question`})})]}),(c||!i)&&(0,s.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[c&&(0,s.jsx)(Q,{icon:t.D,tone:`danger`,onClick:()=>S({kind:`reset`,id:e}),children:`Reset this form`}),!i&&(0,s.jsx)(Q,{icon:t.y,tone:`danger`,onClick:()=>S({kind:`delete`,id:e}),children:`Delete this form`})]}),(0,s.jsx)(ke,{compact:!0,title:`Ask your assistant to put this form on a page`,prompt:ti.forPage(r.title||``,e)})]})};return(0,s.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,s.jsx)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,s.jsxs)(`div`,{children:[(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/forms`,B?`/${B}`:``]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(W,{}),(0,s.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,s.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,s.jsxs)(`div`,{children:[(0,s.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Your forms`}),(0,s.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`Every form on your site, and the questions it asks. Answers arrive in your Inbox.`})]}),(0,s.jsx)(`div`,{className:`relative z-50 shrink-0 flex items-center justify-end`,children:(0,s.jsx)(t.r,{variant:`secondary`,onClick:R,title:`Add a form`,disabled:I,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:I?(0,s.jsx)(t.L,{className:`w-4 h-4 text-foreground/60 animate-spin`}):(0,s.jsx)(t.k,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})})})]}),(0,s.jsx)(`div`,{className:`p-6 md:p-8 flex flex-col gap-4 overflow-y-auto`,children:Object.keys(l).length===0&&!d?(0,s.jsx)(`div`,{className:`flex flex-col gap-4`,children:(0,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-3 p-10 glass-panel rounded-3xl border border-[var(--panel-border)] border-dashed`,children:[(0,s.jsx)(t.O,{className:`w-6 h-6 text-foreground/40`}),(0,s.jsx)(`p`,{className:`text-[13px] font-bold text-foreground/60`,children:`You have no forms yet.`}),(0,s.jsx)(Q,{icon:t.k,onClick:R,children:`New form`}),(0,s.jsx)(`p`,{className:`text-[12.5px] text-foreground/55 font-medium leading-relaxed text-center max-w-md`,children:ti.firstForm})]})}):(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,s.jsx)(t.s,{children:Object.entries(l).map(([e,n])=>{let r=T[e]||n,i=y[e],a=p[e],o=(r.fields||[]).length;return(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},transition:{duration:.35,ease:`easeOut`},onClick:()=>te(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 ${i?`border-[var(--panel-border)] bg-background/50`:`border-transparent hover:border-[var(--panel-border)]`} flex-shrink-0 ${r.enabled===!1?`opacity-40 grayscale bg-foreground/[0.01] border-[var(--panel-border)]/50`:``}`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between w-full`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-1 w-full sm:w-auto pr-4`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground break-words ml-1 leading-snug`,children:r.title||`Untitled form`}),a&&(0,s.jsx)(t.L,{className:`w-3 h-3 animate-spin text-accent ml-2 shrink-0`})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5 ml-1`,children:[(0,s.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest border px-2 py-0.5 rounded-md shrink-0 ${r.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:Xr[r.formType||`public`]}),(0,s.jsx)(`span`,{className:`text-[11px] font-medium text-foreground/45`,children:o===1?`1 question`:`${o} questions`})]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5 w-full sm:w-auto justify-end mt-2 sm:mt-0 shrink-0`,children:[(0,s.jsx)(Q,{icon:t.et,onClick:e=>{e.stopPropagation(),g(r)},children:`Preview`}),(0,s.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 ${i?`rotate-180`:``}`,children:(0,s.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,s.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})})]})]}),(0,s.jsx)(t.s,{children:i&&(0,s.jsx)(t.o.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:V(e,n)})})]},n._uiKey||e)})}),d&&(0,s.jsxs)(`div`,{className:`flex items-center justify-center gap-3 p-6 glass-panel rounded-2xl border border-[var(--panel-border)]/40 bg-foreground/[0.01] mt-2 animate-pulse`,children:[(0,s.jsx)(t.L,{className:`w-4 h-4 animate-spin text-accent`}),(0,s.jsx)(`span`,{className:`text-[12px] font-bold text-foreground/50 tracking-wider uppercase select-none`,children:`Loading your forms`})]})]})})]})]}),(0,s.jsx)(re,{isOpen:!!x,onCancel:()=>S(null),onConfirm:()=>{x&&(x.kind===`delete`?ee(x.id):z(x.id))},title:x?.kind===`reset`?`Reset this form`:`Delete this form`,message:x?.kind===`reset`?`Undo every change made to ${l[x.id]?.title||x.id} and put it back the way it shipped. Answers already collected are kept.`:`Permanently delete ${x?l[x.id]?.title||x.id:``}. This cannot be undone. Answers already collected are kept.`,confirmText:x?.kind===`reset`?`Reset form`:`Delete form`,isProcessing:C}),h&&(0,s.jsx)(t.t,{formConfig:h,onClose:()=>g(null)})]})}function ii({config:e,customContent:n}){let{config:i}=t.At();return(0,r.useEffect)(()=>{document.title=e.pageName||e.pageTitle||i.appName||`Your AI Firebase`},[e.pageName,e.pageTitle,i.appName]),(0,s.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,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]}),(0,s.jsx)(`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,s.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,s.jsx)(t.wt,{className:`w-4 h-4`}),` Go Back`]})}),(0,s.jsx)(t.o.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:n?(0,s.jsx)(`div`,{className:`fbos-content-slot flex-1 p-4 md:p-8`,children:(0,s.jsx)(n,{config:e})}):e.form?(0,s.jsx)(`div`,{className:`fbos-content-slot flex-1 flex flex-col items-center justify-start p-4 md:p-8`,children:(0,s.jsx)(t.t,{isInline:!0,formId:e.form})}):(0,s.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center opacity-50 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,s.jsx)(t.S,{className:`w-8 h-8 md:w-10 md:h-10 mb-4 text-accent/70`}),(0,s.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/70`,children:`This page is empty`}),(0,s.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 max-w-sm leading-relaxed`,children:`Ask your AI assistant what you would like to see here and it will build it for you.`})]})})]})}function ai({config:e,customContent:n}){let{user:a}=A(),{config:c}=t.At(),[u,d]=(0,r.useState)([]),[f,p]=(0,r.useState)(!0),[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(``),[v,y]=(0,r.useState)(``),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(null),w=(0,r.useRef)(null),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(null),[k,j]=(0,r.useState)(null),M=e=>{if(j(e),e){let t=e.fileType||``;F(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},N=k,[P,F]=(0,r.useState)(!0),[I,L]=(0,r.useState)(!1),[R,ee]=(0,r.useState)(null),[z,te]=(0,r.useState)(``),[B,ne]=(0,r.useState)(``),[V,H]=(0,r.useState)([]),U=(0,r.useRef)(null),G=`user_${(e.tabName||e.pageId||`user_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`)}_records`;(0,r.useEffect)(()=>{document.title=e.tabTitle||e.tabName||c.appName||`Your AI Firebase`},[e.tabTitle,e.tabName,c.appName]),(0,r.useEffect)(()=>{if(!a)return;try{let e=localStorage.getItem(`fbos_records_${G}`);e?(d(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}}),n=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,G),(0,i.where)(`uid`,`==`,a.uid),(0,i.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),d(n),p(!1),localStorage.setItem(`fbos_records_${G}`,JSON.stringify(n))},e=>{console.error(`Error fetching records:`,e),p(!1)});return()=>n()},[a,G]),(0,r.useEffect)(()=>{f||localStorage.setItem(`fbos_records_${G}`,JSON.stringify(u))},[u,f,G]);let K=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=await(0,i.addDoc)((0,i.collection)(t.Pt,G),{name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,createdAt:(0,i.serverTimestamp)()});d(t=>[{id:e.id,name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,createdAt:Date.now()},...t]),_(``),y(``),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)}},q=async e=>{let n=e.target.files?.[0];if(!(!n||!a)){E(!0);try{let e=`user_files/${`${Date.now()}_${n.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,r=(0,o.ref)(t.It,e);await(0,o.uploadBytes)(r,n,{customMetadata:{ownerId:a.uid}});let s=await(0,o.getDownloadURL)(r);if(w.current)w.current(n,s,{uid:a.uid,storagePath:e});else{let e=await(0,i.addDoc)((0,i.collection)(t.Pt,G),{name:n.name,note:`${n.type||`File`} · ${ge(n.size)}`,uid:a.uid,recordType:`file`,fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:s,createdAt:(0,i.serverTimestamp)()});d(t=>[{id:e.id,name:n.name,note:`${n.type||`File`} · ${ge(n.size)}`,uid:a.uid,recordType:`file`,fileName:n.name,fileType:n.type,fileSize:n.size,downloadURL:s,createdAt:Date.now()},...t])}}catch(e){console.error(`Error uploading file:`,e)}E(!1),U.current&&(U.current.value=``)}},J=async()=>{if(D){L(!0);try{let e=u.find(e=>e.id===D);if(await(0,i.deleteDoc)((0,i.doc)(t.Pt,G,D)),e?.recordType===`file`&&e.downloadURL)try{let n=e.downloadURL.split(`user_files%2F`)[1]?.split(`?`)[0];n&&await(0,o.deleteObject)((0,o.ref)(t.It,`user_files/${decodeURIComponent(n)}`)).catch(()=>{})}catch(e){console.error(`Error cleaning up user file:`,e)}d(e=>e.filter(e=>e.id!==D)),O(null)}catch(e){console.error(`Error deleting record:`,e)}L(!1)}},[Y,ie]=(0,r.useState)(null),[ae,oe]=(0,r.useState)(``),[se,X]=(0,r.useState)(!1),[ce,Z]=(0,r.useState)(null),Q=(0,r.useRef)([]),le=e=>{if(e.recordType===`file`){ie(e.id),oe(e.name);return}ee(e.id),te(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??``)}));H(n),Q.current=n.map(e=>e.key)},ue=async()=>{if(!Y||!ae.trim()){ie(null);return}let e=u.find(e=>e.id===Y);if(e&&e.name===ae.trim()){ie(null);return}X(!0);try{await(0,i.updateDoc)((0,i.doc)(t.Pt,G,Y),{name:ae.trim()}),d(e=>e.map(e=>e.id===Y?{...e,name:ae.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}X(!1),ie(null)},de=async()=>{await fe(),ee(null)},fe=async()=>{if(!R||!z.trim())return;x(!0);let e={};V.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=V.map(e=>e.key.trim()).filter(Boolean),r=Q.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,i.deleteField)()});try{await(0,i.updateDoc)((0,i.doc)(t.Pt,G,R),{name:z.trim(),note:B.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:z.trim(),note:B.trim()};return r.forEach(e=>{delete t[e]}),V.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),Q.current=n}catch(e){console.error(`Error saving record:`,e)}x(!1)},pe=(e,n)=>e?e.startsWith(`image/`)?n?(0,s.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${n})`}}):(0,s.jsx)(t.J,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,s.jsx)(t.f,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,s.jsx)(t.Q,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,s.jsx)(t.Et,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,s.jsx)(t.ot,{className:`w-4 h-4`}):(0,s.jsx)(t.Z,{className:`w-4 h-4`}):(0,s.jsx)(t.Q,{className:`w-4 h-4`}),me=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`,he=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)},ge=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]},_e=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},ve=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.c[r]?t.c[r]:t.c[n]?t.c[n]:t.h||t.k})(),ye=e.buttonStyle!==`secondary`,be=e.buttonStorageStyle===`primary`;return(0,s.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,s.jsx)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,s.jsxs)(`div`,{children:[(0,s.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||`User Page`}),e.route&&(0,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(W,{}),(0,s.jsxs)(t.o.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,s.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,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,s.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${u.length} ${u.length===1?`item`:`items`}`})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.storage!==!1&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`input`,{type:`file`,ref:U,onChange:q,className:`hidden`}),(0,s.jsxs)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>U.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`} ${be?`btn-primary`:`btn-secondary`}`,children:[T?(0,s.jsx)(t.L,{className:`w-4 h-4 animate-spin`}):(0,s.jsx)(ve,{className:`w-4 h-4`}),e.buttonStorageText&&(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,s.jsx)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>h(!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`} ${ye?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,s.jsx)(t.k,{className:`w-4 h-4`}):(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,s.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,s.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,s.jsx)(t.L,{className:`w-8 h-8 text-accent animate-spin`})}),n?(0,s.jsx)(`div`,{className:`fbos-content-slot`,children:(0,s.jsx)(n,{config:e,actions:{records:u,loading:f,collection:G,user:a,saveRecord:async e=>{let n={id:`temp_`+Date.now(),uid:a.uid,recordType:`record`,createdAt:Date.now(),...e};d(e=>[n,...e]),await(0,i.addDoc)((0,i.collection)(t.Pt,G),{uid:a.uid,recordType:`record`,createdAt:(0,i.serverTimestamp)(),...e})},updateRecord:async(e,n)=>{d(t=>t.map(t=>t.id===e?{...t,...n}:t)),await(0,i.updateDoc)((0,i.doc)(t.Pt,G,e),n)},deleteRecord:async e=>{await(0,i.deleteDoc)((0,i.doc)(t.Pt,G,e))},startEdit:e=>le(e),confirmDelete:e=>O(e),uploadFile:()=>U.current?.click(),openAddForm:()=>h(!0),setAddForm:e=>C(()=>e),setFileHandler:e=>{w.current=e}}})}):(0,s.jsxs)(s.Fragment,{children:[!f&&u.length===0&&(0,s.jsxs)(t.o.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,s.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,s.jsx)(t.k,{className:`w-6 h-6 text-accent/40`})}),(0,s.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,s.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&&u.length>0&&(0,s.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,s.jsx)(t.s,{children:u.map((e,n)=>{let r=R===e.id;return(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},transition:{delay:n*.03,duration:.25},onClick:()=>le(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,s.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,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),Z(e.id),setTimeout(()=>Z(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:ce===e.id?(0,s.jsx)(t._t,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-3.5 h-3.5`})}),(0,s.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,s.jsx)(t.rt,{className:`w-3.5 h-3.5`})})]}),(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),le(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,s.jsx)(t.A,{className:`w-3.5 h-3.5`})}),(0,s.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,s.jsx)(t.y,{className:`w-3.5 h-3.5`})})]}),(0,s.jsxs)(`div`,{className:`flex items-start gap-3 mb-3`,children:[(0,s.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&M(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 ${me(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?pe(e.fileType,e.downloadURL):(0,s.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,s.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[Y===e.id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:ae,onChange:e=>oe(e.target.value),onBlur:()=>ue(),onKeyDown:e=>{e.key===`Enter`&&ue(),e.key===`Escape`&&ie(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,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,s.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>M(e)}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:_e(e.createdAt)})]})]}),e.note&&(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,s.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,s.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e))]},e.id)})})})]})]}),!n&&(0,s.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,s.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,s.jsx)(t.K,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,s.jsxs)(`span`,{children:[`Each user sees their own data only · Edit and delete available on all items · Records: `,(0,s.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:G}),` · Files: `,(0,s.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`user_files`}),` → Drive / User`]})]})})]})]}),(0,s.jsx)(t.s,{children:m&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>!b&&h(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,s.jsx)(t.o.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:S?r.default.createElement(S,{onSave:async e=>{x(!0);try{await(0,i.addDoc)((0,i.collection)(t.Pt,G),{uid:a.uid,recordType:`record`,createdAt:(0,i.serverTimestamp)(),...e}),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)},onClose:()=>!b&&h(!1),saving:b}):(0,s.jsxs)(`form`,{onSubmit:K,className:`p-5 flex flex-col gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>!b&&h(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,s.jsx)(t.d,{className:`w-4 h-4`})})]}),(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:g,onChange:e=>_(e.target.value),placeholder:`Name *`,disabled:b,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,s.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),placeholder:`Note (optional)`,disabled:b,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,s.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,s.jsx)(t.r,{type:`submit`,isLoading:b,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:b?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,l.createPortal)((0,s.jsx)(t.s,{children:N&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,s.jsx)(t.o.div,{onClick:()=>M(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,s.jsx)(`button`,{onClick:()=>M(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,s.jsx)(t.d,{className:`w-5 h-5`})}),(0,s.jsxs)(t.o.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,s.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,s.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,s.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:N.fileName||N.name}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[he(N.fileType),` • `,ge(N.fileSize||0)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(N.downloadURL),Z(`preview`),setTimeout(()=>Z(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:ce===`preview`?(0,s.jsx)(t._t,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{M(null),ie(N.id),oe(N.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,s.jsx)(t.A,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{M(null),O(N.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,s.jsx)(t.y,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:N.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,s.jsx)(t.rt,{className:`w-4 h-4`})})]})]}),(0,s.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>M(null),children:(0,s.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[P&&(0,s.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,s.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,s.jsx)(t.L,{className:`w-5 h-5 text-accent animate-spin`})})}),N.fileType?.startsWith(`image/`)?(0,s.jsx)(`img`,{onLoad:()=>F(!1),onError:()=>F(!1),src:N.downloadURL,alt:N.fileName||N.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 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):N.fileType?.startsWith(`video/`)?(0,s.jsx)(`video`,{onLoadedData:()=>F(!1),onError:()=>F(!1),src:N.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 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):N.fileType===`application/pdf`?(0,s.jsx)(`iframe`,{onLoad:()=>F(!1),src:N.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,s.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(),F(!1)},children:[(0,s.jsx)(t.Q,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,s.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,s.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,s.jsx)(t.s,{children:R&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>de(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,s.jsx)(t.o.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,s.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),b&&(0,s.jsx)(t.L,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>de(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,s.jsx)(t.d,{className:`w-4 h-4`})})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.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,s.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>te(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>fe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.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,s.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:B,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:()=>fe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),V.map((e,n)=>(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let t=[...V];t[n].key=e.target.value,H(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>fe(),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,s.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let t=[...V];t[n].value=e.target.value,H(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>fe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>H(V.filter((e,t)=>t!==n)),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,s.jsx)(t.d,{className:`w-3 h-3`})})]},n)),(0,s.jsxs)(`button`,{type:`button`,onClick:()=>H([...V,{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,s.jsx)(t.k,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,s.jsx)(re,{isOpen:!!D,onCancel:()=>O(null),onConfirm:J,title:`Delete Record`,message:(0,s.jsxs)(s.Fragment,{children:[`Are you sure you want to delete `,(0,s.jsx)(`strong`,{className:`text-foreground font-extrabold break-words mx-1`,children:u.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:I})]})}function oi({config:e,customContent:n}){let{user:a}=A(),{config:c}=t.At(),[u,d]=(0,r.useState)([]),[f,p]=(0,r.useState)(!0),[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(``),[v,y]=(0,r.useState)(``),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(null),w=(0,r.useRef)(null),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(null),[k,j]=(0,r.useState)(null),M=e=>{if(j(e),e){let t=e.fileType||``;F(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},N=k,[P,F]=(0,r.useState)(!0),[I,L]=(0,r.useState)(!1),[R,ee]=(0,r.useState)(null),[z,te]=(0,r.useState)(``),[B,ne]=(0,r.useState)(``),[V,H]=(0,r.useState)([]),U=(0,r.useRef)(null),[G,K]=(0,r.useState)(null),q=(0,r.useRef)([]),J=`admin_${(e.tabName||e.pageId||`admin_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`)}_records`;(0,r.useEffect)(()=>{document.title=e.tabTitle||e.tabName||c.appName||`Your AI Firebase`},[e.tabTitle,e.tabName,c.appName]);let Y=()=>({name:a.displayName||a.email?.split(`@`)[0]||`Admin`,email:a.email||``,avatar:a.photoURL||``});(0,r.useEffect)(()=>{if(!a)return;try{let e=localStorage.getItem(`fbos_records_${J}`);e?(d(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}}),n=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,J),(0,i.orderBy)(`createdAt`,`desc`),(0,i.limit)(150)),t=>{let n=e(t.docs);d(n),p(!1),localStorage.setItem(`fbos_records_${J}`,JSON.stringify(n))},n=>{console.error(`Error listening to admin records:`,n);let r=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,J),(0,i.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),d(n),p(!1),localStorage.setItem(`fbos_records_${J}`,JSON.stringify(n))});return()=>r()});return()=>n()},[a,J]);let ie=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Pt,J),{name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,i.serverTimestamp)()}),_(``),y(``),h(!1)}catch(e){console.error(`Error saving admin record:`,e)}x(!1)}},ae=async e=>{let n=e.target.files?.[0];if(!(!n||!a)){E(!0);try{let e=`admin_files/${`${Date.now()}_${n.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,r=(0,o.ref)(t.It,e);await(0,o.uploadBytes)(r,n,{customMetadata:{ownerId:a.uid}});let s=await(0,o.getDownloadURL)(r);if(w.current)w.current(n,s,{uid:a.uid,storagePath:e});else{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Pt,J),{name:n.name,note:`${n.type||`File`} · ${_e(n.size)}`,uid:a.uid,recordType:`file`,fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:s,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,i.serverTimestamp)()})}}catch(e){console.error(`Error uploading admin file:`,e)}E(!1),U.current&&(U.current.value=``)}},oe=async()=>{if(D){L(!0);try{let e=u.find(e=>e.id===D);if(await(0,i.deleteDoc)((0,i.doc)(t.Pt,J,D)),e?.recordType===`file`&&e.downloadURL)try{let n=e.downloadURL.split(`admin_files%2F`)[1]?.split(`?`)[0];n&&await(0,o.deleteObject)((0,o.ref)(t.It,`admin_files/${decodeURIComponent(n)}`)).catch(()=>{})}catch(e){console.error(`Error cleaning up admin file:`,e)}O(null)}catch(e){console.error(`Error deleting admin record:`,e)}L(!1)}},[se,X]=(0,r.useState)(null),[ce,Z]=(0,r.useState)(``),[Q,le]=(0,r.useState)(!1),ue=e=>{if(e.recordType===`file`){X(e.id),Z(e.name);return}ee(e.id),te(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??``)}));H(n),q.current=n.map(e=>e.key)},de=async()=>{if(!se||!ce.trim()){X(null);return}let e=u.find(e=>e.id===se);if(e&&e.name===ce.trim()){X(null);return}le(!0);try{await(0,i.updateDoc)((0,i.doc)(t.Pt,J,se),{name:ce.trim()}),d(e=>e.map(e=>e.id===se?{...e,name:ce.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}le(!1),X(null)},fe=async()=>{if(!R||!z.trim()){ee(null);return}x(!0);let e={};V.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=V.map(e=>e.key.trim()).filter(Boolean),r=q.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,i.deleteField)()});try{await(0,i.updateDoc)((0,i.doc)(t.Pt,J,R),{name:z.trim(),note:B.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:z.trim(),note:B.trim()};return r.forEach(e=>{delete t[e]}),V.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),q.current=n}catch(e){console.error(`Error updating record:`,e)}x(!1),ee(null)},pe=async()=>{if(!R||!z.trim())return;let e={};V.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=V.map(e=>e.key.trim()).filter(Boolean),r=q.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,i.deleteField)()});try{await(0,i.updateDoc)((0,i.doc)(t.Pt,J,R),{name:z.trim(),note:B.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:z.trim(),note:B.trim()};return r.forEach(e=>{delete t[e]}),V.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),q.current=n}catch(e){console.error(`Error silently saving record:`,e)}},me=(e,n)=>e?e.startsWith(`image/`)?n?(0,s.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${n})`}}):(0,s.jsx)(t.J,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,s.jsx)(t.f,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,s.jsx)(t.Q,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,s.jsx)(t.Et,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,s.jsx)(t.ot,{className:`w-4 h-4`}):(0,s.jsx)(t.Z,{className:`w-4 h-4`}):(0,s.jsx)(t.Q,{className:`w-4 h-4`}),he=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`,ge=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)},_e=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]},ve=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=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.c[r]?t.c[r]:t.c[n]?t.c[n]:t.h||t.k})(),be=e.buttonStyle!==`secondary`,xe=e.buttonStorageStyle===`primary`,Se=e=>e.uid===a?.uid,Ce=({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,s.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,s.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,s.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,s.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,s.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,s.jsx)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,s.jsxs)(`div`,{children:[(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(W,{}),(0,s.jsxs)(t.o.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,s.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,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,s.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${u.length} ${u.length===1?`item`:`items`}`})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.storage!==!1&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`input`,{type:`file`,ref:U,onChange:ae,className:`hidden`}),(0,s.jsxs)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>U.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`} ${xe?`btn-primary`:`btn-secondary`}`,children:[T?(0,s.jsx)(t.L,{className:`w-4 h-4 animate-spin`}):(0,s.jsx)(ye,{className:`w-4 h-4`}),e.buttonStorageText&&(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,s.jsx)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>h(!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`} ${be?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,s.jsx)(t.k,{className:`w-4 h-4`}):(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,s.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,s.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,s.jsx)(t.L,{className:`w-8 h-8 text-accent animate-spin`})}),n?(0,s.jsx)(`div`,{className:`fbos-content-slot`,children:(0,s.jsx)(n,{config:e,actions:{records:u,loading:f,collection:J,user:a,saveRecord:async e=>{let n=Y(),r={id:`temp_`+Date.now(),uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:Date.now(),...e};d(e=>[r,...e]),await(0,i.addDoc)((0,i.collection)(t.Pt,J),{uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:(0,i.serverTimestamp)(),...e})},updateRecord:async(e,n)=>{d(t=>t.map(t=>t.id===e?{...t,...n}:t)),await(0,i.updateDoc)((0,i.doc)(t.Pt,J,e),n)},deleteRecord:async e=>{await(0,i.deleteDoc)((0,i.doc)(t.Pt,J,e))},startEdit:e=>ue(e),confirmDelete:e=>O(e),uploadFile:()=>U.current?.click(),openAddForm:()=>h(!0),setAddForm:e=>C(()=>e),setFileHandler:e=>{w.current=e}}})}):(0,s.jsxs)(s.Fragment,{children:[!f&&u.length===0&&(0,s.jsxs)(t.o.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,s.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,s.jsx)(t.k,{className:`w-6 h-6 text-accent/40`})}),(0,s.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,s.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&&u.length>0&&(0,s.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,s.jsx)(t.s,{children:u.map((e,n)=>{let r=R===e.id,i=Se(e);return(0,s.jsxs)(t.o.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>ue(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,s.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,s.jsxs)(s.Fragment,{children:[(0,s.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,s.jsx)(t._t,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-3.5 h-3.5`})}),(0,s.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,s.jsx)(t.rt,{className:`w-3.5 h-3.5`})})]}),i&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ue(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,s.jsx)(t.A,{className:`w-3.5 h-3.5`})}),(0,s.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,s.jsx)(t.y,{className:`w-3.5 h-3.5`})})]})]}),(0,s.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,s.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&M(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 ${he(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?me(e.fileType,e.downloadURL):(0,s.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,s.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[se===e.id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:ce,onChange:e=>Z(e.target.value),onBlur:()=>de(),onKeyDown:e=>{e.key===`Enter`&&de(),e.key===`Escape`&&X(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,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,s.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>M(e)}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ve(e.createdAt)})]})]}),e.note&&(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,s.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,s.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,s.jsx)(Ce,{record:e})]},e.id)})})})]})]}),!n&&(0,s.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,s.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,s.jsx)(t.K,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,s.jsxs)(`span`,{children:[`Shared between all admins · Edit and delete available on your own items only · Records: `,(0,s.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:J}),` · Files: `,(0,s.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`admin_files`}),` → Drive / Admin`]})]})})]})]}),(0,s.jsx)(t.s,{children:m&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>!b&&h(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,s.jsx)(t.o.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:S?r.default.createElement(S,{onSave:async e=>{x(!0);try{let n=Y();await(0,i.addDoc)((0,i.collection)(t.Pt,J),{uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:(0,i.serverTimestamp)(),...e}),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)},onClose:()=>!b&&h(!1),saving:b}):(0,s.jsxs)(`form`,{onSubmit:ie,className:`p-5 flex flex-col gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>!b&&h(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,s.jsx)(t.d,{className:`w-4 h-4`})})]}),(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:g,onChange:e=>_(e.target.value),placeholder:`Name *`,disabled:b,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,s.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),placeholder:`Note (optional)`,disabled:b,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,s.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,s.jsx)(t.r,{type:`submit`,isLoading:b,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:b?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,l.createPortal)((0,s.jsx)(t.s,{children:N&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,s.jsx)(t.o.div,{onClick:()=>M(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,s.jsx)(`button`,{onClick:()=>M(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,s.jsx)(t.d,{className:`w-5 h-5`})}),(0,s.jsxs)(t.o.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,s.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,s.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,s.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:N.fileName||N.name}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[ge(N.fileType),` • `,_e(N.fileSize||0)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(N.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,s.jsx)(t._t,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{M(null),X(N.id),Z(N.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,s.jsx)(t.A,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{M(null),O(N.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,s.jsx)(t.y,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:N.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,s.jsx)(t.rt,{className:`w-4 h-4`})})]})]}),(0,s.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>M(null),children:(0,s.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[P&&(0,s.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,s.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,s.jsx)(t.L,{className:`w-5 h-5 text-accent animate-spin`})})}),N.fileType?.startsWith(`image/`)?(0,s.jsx)(`img`,{onLoad:()=>F(!1),onError:()=>F(!1),src:N.downloadURL,alt:N.fileName||N.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 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):N.fileType?.startsWith(`video/`)?(0,s.jsx)(`video`,{onLoadedData:()=>F(!1),onError:()=>F(!1),src:N.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 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):N.fileType===`application/pdf`?(0,s.jsx)(`iframe`,{onLoad:()=>F(!1),src:N.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,s.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(),F(!1)},children:[(0,s.jsx)(t.Q,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,s.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,s.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,s.jsx)(t.s,{children:R&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>fe(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,s.jsx)(t.o.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,s.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),b&&(0,s.jsx)(t.L,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>fe(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,s.jsx)(t.d,{className:`w-4 h-4`})})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.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,s.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>te(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>pe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.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,s.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:B,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:()=>pe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),V.map((e,n)=>(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let t=[...V];t[n].key=e.target.value,H(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>pe(),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,s.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let t=[...V];t[n].value=e.target.value,H(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>pe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>H(V.filter((e,t)=>t!==n)),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,s.jsx)(t.d,{className:`w-3 h-3`})})]},n)),(0,s.jsxs)(`button`,{type:`button`,onClick:()=>H([...V,{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,s.jsx)(t.k,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,s.jsx)(re,{isOpen:!!D,onCancel:()=>O(null),onConfirm:oe,title:`Delete Record`,message:(0,s.jsxs)(s.Fragment,{children:[`Are you sure you want to delete `,(0,s.jsx)(`strong`,{className:`text-foreground font-extrabold break-words mx-1`,children:u.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:I})]})}function si({config:e,customContent:n}){let{user:a}=A(),{config:c}=t.At(),[u,d]=(0,r.useState)([]),[f,p]=(0,r.useState)(!0),[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(``),[v,y]=(0,r.useState)(``),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(null),w=(0,r.useRef)(null),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(null),[k,j]=(0,r.useState)(null),M=e=>{if(j(e),e){let t=e.fileType||``;F(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},N=k,[P,F]=(0,r.useState)(!0),[I,L]=(0,r.useState)(!1),[R,ee]=(0,r.useState)(null),[z,te]=(0,r.useState)(``),[B,ne]=(0,r.useState)(``),[V,H]=(0,r.useState)([]),U=(0,r.useRef)(null),[G,K]=(0,r.useState)(null),q=(0,r.useRef)([]),J=`mem_${(e.tabName||e.pageId||`internal_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`)}_records`;(0,r.useEffect)(()=>{document.title=e.tabTitle||e.tabName||c.appName||`Your AI Firebase`},[e.tabTitle,e.tabName,c.appName]),(0,r.useEffect)(()=>{if(!a)return;try{let e=localStorage.getItem(`fbos_records_${J}`);e?(d(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}}),n=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,J),(0,i.orderBy)(`createdAt`,`desc`),(0,i.limit)(150)),t=>{let n=e(t.docs);d(n),p(!1),localStorage.setItem(`fbos_records_${J}`,JSON.stringify(n))},n=>{console.error(`Error listening to shared records:`,n);let r=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,J),(0,i.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),d(n),p(!1),localStorage.setItem(`fbos_records_${J}`,JSON.stringify(n))});return()=>r()});return()=>n()},[a,J]);let Y=()=>({name:a.displayName||a.email?.split(`@`)[0]||`Member`,email:a.email||``,avatar:a.photoURL||``}),ie=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Pt,J),{name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,i.serverTimestamp)()}),_(``),y(``),h(!1)}catch(e){console.error(`Error saving shared record:`,e)}x(!1)}},ae=async e=>{let n=e.target.files?.[0];if(!(!n||!a)){E(!0);try{let e=`mem_files/${`${Date.now()}_${n.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,r=(0,o.ref)(t.It,e);await(0,o.uploadBytes)(r,n,{customMetadata:{ownerId:a.uid}});let s=await(0,o.getDownloadURL)(r);if(w.current)w.current(n,s,{uid:a.uid,storagePath:e});else{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Pt,J),{name:n.name,note:`${n.type||`File`} · ${_e(n.size)}`,uid:a.uid,recordType:`file`,fileName:n.name,fileType:n.type||`unknown`,fileSize:n.size,downloadURL:s,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,i.serverTimestamp)()})}}catch(e){console.error(`Error uploading shared file:`,e)}E(!1),U.current&&(U.current.value=``)}},oe=async()=>{if(D){L(!0);try{let e=u.find(e=>e.id===D);if(await(0,i.deleteDoc)((0,i.doc)(t.Pt,J,D)),e?.recordType===`file`&&e.downloadURL)try{let n=e.downloadURL.split(`mem_files%2F`)[1]?.split(`?`)[0];n&&await(0,o.deleteObject)((0,o.ref)(t.It,`mem_files/${decodeURIComponent(n)}`)).catch(()=>{})}catch(e){console.error(`Error cleaning up shared file:`,e)}O(null)}catch(e){console.error(`Error deleting shared record:`,e)}L(!1)}},[se,X]=(0,r.useState)(null),[ce,Z]=(0,r.useState)(``),[Q,le]=(0,r.useState)(!1),ue=e=>{if(e.recordType===`file`){X(e.id),Z(e.name);return}ee(e.id),te(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??``)}));H(n),q.current=n.map(e=>e.key)},de=async()=>{if(!se||!ce.trim()){X(null);return}let e=u.find(e=>e.id===se);if(e&&e.name===ce.trim()){X(null);return}le(!0);try{await(0,i.updateDoc)((0,i.doc)(t.Pt,J,se),{name:ce.trim()}),d(e=>e.map(e=>e.id===se?{...e,name:ce.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}le(!1),X(null)},fe=async()=>{await pe(),ee(null)},pe=async()=>{if(!R||!z.trim())return;x(!0);let e={};V.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=V.map(e=>e.key.trim()).filter(Boolean),r=q.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,i.deleteField)()});try{await(0,i.updateDoc)((0,i.doc)(t.Pt,J,R),{name:z.trim(),note:B.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:z.trim(),note:B.trim()};return r.forEach(e=>{delete t[e]}),V.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),q.current=n}catch(e){console.error(`Error saving record:`,e)}x(!1)},me=(e,n)=>e?e.startsWith(`image/`)?n?(0,s.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${n})`}}):(0,s.jsx)(t.J,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,s.jsx)(t.f,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,s.jsx)(t.Q,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,s.jsx)(t.Et,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,s.jsx)(t.ot,{className:`w-4 h-4`}):(0,s.jsx)(t.Z,{className:`w-4 h-4`}):(0,s.jsx)(t.Q,{className:`w-4 h-4`}),he=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`,ge=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)},_e=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]},ve=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=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.c[r]?t.c[r]:t.c[n]?t.c[n]:t.h||t.k})(),be=e.buttonStyle!==`secondary`,xe=e.buttonStorageStyle===`primary`,Se=e=>e.uid===a?.uid,Ce=({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,s.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,s.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,s.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,s.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,s.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,s.jsx)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,s.jsxs)(`div`,{children:[(0,s.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||`Internal Page`}),e.route&&(0,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(W,{}),(0,s.jsxs)(t.o.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,s.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,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,s.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${u.length} ${u.length===1?`item`:`items`} · Internal`})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.storage!==!1&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`input`,{type:`file`,ref:U,onChange:ae,className:`hidden`}),(0,s.jsxs)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>U.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`} ${xe?`btn-primary`:`btn-secondary`}`,children:[T?(0,s.jsx)(t.L,{className:`w-4 h-4 animate-spin`}):(0,s.jsx)(ye,{className:`w-4 h-4`}),e.buttonStorageText&&(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,s.jsx)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>h(!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`} ${be?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,s.jsx)(t.k,{className:`w-4 h-4`}):(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,s.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,s.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,s.jsx)(t.L,{className:`w-8 h-8 text-accent animate-spin`})}),n?(0,s.jsx)(`div`,{className:`fbos-content-slot`,children:(0,s.jsx)(n,{config:e,actions:{records:u,loading:f,collection:J,user:a,saveRecord:async e=>{let n=Y(),r={id:`temp_`+Date.now(),uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:Date.now(),...e};d(e=>[r,...e]),await(0,i.addDoc)((0,i.collection)(t.Pt,J),{uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:(0,i.serverTimestamp)(),...e})},updateRecord:async(e,n)=>{d(t=>t.map(t=>t.id===e?{...t,...n}:t)),await(0,i.updateDoc)((0,i.doc)(t.Pt,J,e),n)},deleteRecord:async e=>{await(0,i.deleteDoc)((0,i.doc)(t.Pt,J,e))},startEdit:e=>ue(e),confirmDelete:e=>O(e),uploadFile:()=>U.current?.click(),openAddForm:()=>h(!0),setAddForm:e=>C(()=>e),setFileHandler:e=>{w.current=e}}})}):(0,s.jsxs)(s.Fragment,{children:[!f&&u.length===0&&(0,s.jsxs)(t.o.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,s.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,s.jsx)(t.k,{className:`w-6 h-6 text-accent/40`})}),(0,s.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,s.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&&u.length>0&&(0,s.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,s.jsx)(t.s,{children:u.map(e=>{let n=R===e.id,r=Se(e);return(0,s.jsxs)(t.o.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>r?ue(e):null,className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative ${r?`cursor-pointer`:``} ${n?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,s.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,s.jsxs)(s.Fragment,{children:[(0,s.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,s.jsx)(t._t,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-3.5 h-3.5`})}),(0,s.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,s.jsx)(t.rt,{className:`w-3.5 h-3.5`})})]}),r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ue(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,s.jsx)(t.A,{className:`w-3.5 h-3.5`})}),(0,s.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,s.jsx)(t.y,{className:`w-3.5 h-3.5`})})]})]}),(0,s.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,s.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&M(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 ${he(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?me(e.fileType,e.downloadURL):(0,s.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,s.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[se===e.id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:ce,onChange:e=>Z(e.target.value),onBlur:()=>de(),onKeyDown:e=>{e.key===`Enter`&&de(),e.key===`Escape`&&X(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,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,s.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>M(e)}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ve(e.createdAt)})]})]}),e.note&&(0,s.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,s.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,s.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,s.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,s.jsx)(Ce,{record:e})]},e.id)})})})]})]}),!n&&(0,s.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,s.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,s.jsx)(t.K,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,s.jsxs)(`span`,{children:[`Shared with everyone marked internal · Edit and delete available on your own items only · Records: `,(0,s.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:J}),` · Files: `,(0,s.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`mem_files`}),` → Drive / Internal`]})]})})]})]}),(0,s.jsx)(t.s,{children:m&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>!b&&h(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,s.jsx)(t.o.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:S?r.default.createElement(S,{onSave:async e=>{x(!0);try{let n=Y();await(0,i.addDoc)((0,i.collection)(t.Pt,J),{uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:(0,i.serverTimestamp)(),...e}),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)},onClose:()=>!b&&h(!1),saving:b}):(0,s.jsxs)(`form`,{onSubmit:ie,className:`p-5 flex flex-col gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>!b&&h(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,s.jsx)(t.d,{className:`w-4 h-4`})})]}),(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:g,onChange:e=>_(e.target.value),placeholder:`Name *`,disabled:b,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,s.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),placeholder:`Note (optional)`,disabled:b,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,s.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,s.jsx)(t.r,{type:`submit`,isLoading:b,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:b?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,l.createPortal)((0,s.jsx)(t.s,{children:N&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,s.jsx)(t.o.div,{onClick:()=>M(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,s.jsx)(`button`,{onClick:()=>M(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,s.jsx)(t.d,{className:`w-5 h-5`})}),(0,s.jsxs)(t.o.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,s.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,s.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,s.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:N.fileName||N.name}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[ge(N.fileType),` • `,_e(N.fileSize||0)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(N.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,s.jsx)(t._t,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{M(null),X(N.id),Z(N.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,s.jsx)(t.A,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{M(null),O(N.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,s.jsx)(t.y,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:N.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,s.jsx)(t.rt,{className:`w-4 h-4`})})]})]}),(0,s.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>M(null),children:(0,s.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[P&&(0,s.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,s.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,s.jsx)(t.L,{className:`w-5 h-5 text-accent animate-spin`})})}),N.fileType?.startsWith(`image/`)?(0,s.jsx)(`img`,{onLoad:()=>F(!1),onError:()=>F(!1),src:N.downloadURL,alt:N.fileName||N.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 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):N.fileType?.startsWith(`video/`)?(0,s.jsx)(`video`,{onLoadedData:()=>F(!1),onError:()=>F(!1),src:N.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 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):N.fileType===`application/pdf`?(0,s.jsx)(`iframe`,{onLoad:()=>F(!1),src:N.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,s.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(),F(!1)},children:[(0,s.jsx)(t.Q,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,s.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,s.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,s.jsx)(t.s,{children:R&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>fe(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,s.jsx)(t.o.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,s.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),b&&(0,s.jsx)(t.L,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>fe(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,s.jsx)(t.d,{className:`w-4 h-4`})})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.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,s.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>te(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>pe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.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,s.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:B,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:()=>pe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),V.map((e,n)=>(0,s.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,s.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let t=[...V];t[n].key=e.target.value,H(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>pe(),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,s.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let t=[...V];t[n].value=e.target.value,H(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>pe(),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,s.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>H(V.filter((e,t)=>t!==n)),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,s.jsx)(t.d,{className:`w-3 h-3`})})]},n)),(0,s.jsxs)(`button`,{type:`button`,onClick:()=>H([...V,{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,s.jsx)(t.k,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,s.jsx)(re,{isOpen:!!D,onCancel:()=>O(null),onConfirm:oe,title:`Delete Record`,message:(0,s.jsxs)(s.Fragment,{children:[`Are you sure you want to delete `,(0,s.jsx)(`strong`,{className:`text-foreground font-extrabold break-words mx-1`,children:u.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:I})]})}var ci=[`board`,`table`,`calendar`,`drive`],li=[`inline_form`,`popup_form`],ui=e=>typeof e!=`string`||e===``||e===`none`||e===`custom`||![...ci,...li].includes(e),di=(e,t)=>ui(e)||t&&!ci.includes(e),fi=`src/your-ai-workflow-firebase-os`;function pi(){let e=new Set;for(let[t,n]of M()){let r=n?.config?.route,i=typeof r==`string`&&r.trim()?r.startsWith(`/`)?r:`/`+r:`/`+t.toLowerCase();e.add(i)}return[...e].sort()}function mi(e){return[`The page at ${e} shows "Page Not Found". The app only finds a page when its config file is picked up, so check these in order and fix whatever is wrong, without asking me questions.`,`1. The page's config file sits directly in ${fi}/configs/ and its name ends with Tab.config.ts (a page for signed-in users, my team or admins) or Page.config.ts (a page for anyone). Not in a subfolder, not any other name.`,`2. It exports one const whose name ends with Config, and its route is the single string '${e}'. A page has exactly one web address — remove any other addresses you registered for it.`,`3. ${fi}/configs/pagesRegistry.ts exists and src/main.tsx contains the line import './your-ai-workflow-firebase-os/configs/pagesRegistry'. If either is missing, run npm install so the package's postinstall script restores them.`,`4. Put src/App.tsx back to the version the package wrote: it only mounts <FirebaseOS />. Never add routes, a router or the customRoutes prop.`,`5. If the page is for my team, its config says pageType: 'internal'. Any form on it is a *Form.config.ts file shown through <ContactPopup formId="..." />, never a form you wrote by hand.`,`Then rebuild and tell me, in one sentence, which of these was wrong.`].join(`
|
|
136
|
+
`)}function hi({tone:e,title:t,message:n,action:r}){let i=e===`red`?`border-red-500/20`:`border-amber-500/25`,a=e===`red`?`bg-red-500/5`:`bg-amber-500/5`,o=e===`red`?`text-red-500`:`text-amber-500`;return(0,s.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 min-h-[60vh] animate-in fade-in duration-500`,children:(0,s.jsxs)(`div`,{className:`glass-panel p-8 md:p-10 rounded-3xl border ${i} text-center shadow-xl max-w-sm w-full relative overflow-hidden`,children:[(0,s.jsx)(`div`,{className:`absolute inset-0 ${a}`}),(0,s.jsx)(`h2`,{className:`text-2xl font-black ${o} mb-3 relative z-10 tracking-tight`,children:t}),(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/70 font-medium leading-relaxed relative z-10 mb-6`,children:n}),(0,s.jsx)(`div`,{className:`relative z-10`,children:r})]})})}var gi=`w-full block py-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors`,_i=()=>(0,s.jsx)(hi,{tone:`amber`,title:`Team page`,message:`This page is for your team. Ask an admin of this app to add you to the team.`,action:(0,s.jsx)(c.Link,{to:`/dashboard`,className:gi,children:`Back to dashboard`})}),vi=()=>(0,s.jsx)(hi,{tone:`amber`,title:`Admins only`,message:`This page is part of the admin area. Ask an admin of this app if you need to get in.`,action:(0,s.jsx)(c.Link,{to:`/dashboard`,className:gi,children:`Back to dashboard`})}),yi=(e,t)=>{let n=t?w(e.pageType):`public`;return{...e,pageType:n,isPrivate:t,isAdmin:n===`admin`,isInternal:n===`internal`,isShared:n===`internal`}};function bi(){let e=(0,c.useLocation)(),{user:n,userRole:a,loading:o,roleResolved:l}=A(),u=t.Mt(),d=e=>{if(typeof window<`u`){let t=localStorage.getItem(`fbos_route_${e}`);if(t)try{let e=JSON.parse(t);if(e.form&&!e.formConfigOverride){let t=localStorage.getItem(`fbos_form_${e.form}`);t&&(e.formConfigOverride=JSON.parse(t))}return yi(e,e.isPrivate===!0)}catch{}}let n=(typeof window<`u`?window.__FBOS_PAGES__:null)||{},r=e.replace(/^\//,``);for(let[t,i]of Object.entries(n)){let n=i.config,a=i.isPublic,o=n.route||`/`+t;if(o===e||t===r)return yi({...n,route:o,contentKey:n.pageId||t,pageId:t},!a)}return e===`/contact`?{route:`/contact`,template:`popup_form`,form:`contact`,pageId:`contact`,contentKey:`contact`,pageName:`Contact`,formConfigOverride:u.defaultConfigs?.contactForm||t.Bt}:e===`/support`?{route:`/support`,template:`popup_form`,form:`support`,pageId:`support`,contentKey:`support`,pageName:`Support`,formConfigOverride:u.defaultConfigs?.supportForm||t.Rt}:null},[f,p]=(0,r.useState)(()=>d(e.pathname)),[m,h]=(0,r.useState)(()=>!d(e.pathname));(0,r.useEffect)(()=>{let n=!0,r=d(e.pathname);if(r){p(r),h(!1);let e=r.pageName||r.tabName||r.title;e&&(document.title=e)}return(async()=>{try{let r=e.pathname;r.startsWith(`/`)&&(r=r.substring(1));let[a,o,s,c,l,d]=await Promise.allSettled([(0,i.getDoc)((0,i.doc)(t.Pt,`sys_pages`,r)),(0,i.getDoc)((0,i.doc)(t.Pt,`sys_tabs`,r)),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Pt,`sys_pages`),(0,i.where)(`route`,`==`,e.pathname),(0,i.limit)(1))),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Pt,`sys_pages`),(0,i.where)(`route`,`==`,r),(0,i.limit)(1))),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Pt,`sys_tabs`),(0,i.where)(`route`,`==`,e.pathname),(0,i.limit)(1))),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Pt,`sys_tabs`),(0,i.where)(`route`,`==`,r),(0,i.limit)(1)))]),f=null,m=null,g=(e,t)=>{f||e.status===`fulfilled`&&(e.value.exists&&e.value.exists()?(f=yi(e.value.data(),t),m=e.value.id):e.value.docs&&e.value.docs.length>0&&(f=yi(e.value.docs[0].data(),t),m=e.value.docs[0].id))};if(g(a,!1),g(s,!1),g(c,!1),g(o,!0),g(l,!0),g(d,!0),!f){let t=(typeof window<`u`?window.__FBOS_PAGES__:null)||{};for(let[n,i]of Object.entries(t)){let t=i.config,a=i.isPublic,o=t.route||`/`+n;if(o===e.pathname||n===r){f=yi({...t,route:o,contentKey:t.pageId||n,pageId:n},!a),m=n;break}}}if(f||(e.pathname===`/contact`?(f={route:`/contact`,template:`popup_form`,form:`contact`,pageName:`Contact`},m=`contact`):e.pathname===`/support`&&(f={route:`/support`,template:`popup_form`,form:`support`,pageName:`Support`},m=`support`)),!n)return;if(f){if((m===`contact`||m===`support`)&&!f.form&&(f.form=m),f.contentKey||=f.pageId||m,f.pageId=m,localStorage.setItem(`fbos_route_${e.pathname}`,JSON.stringify(f)),f.form){let e=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},r=n=>u.defaultConfigs?.[n]||u.defaultConfigs?.[`${n}Form`]||e[n]||(n===`contact`?t.Bt:n===`support`?t.Rt:null);if(localStorage.getItem(`fbos_custom_form_${f.form}`)){try{let e=localStorage.getItem(`fbos_form_${f.form}`);e&&(f.formConfigOverride=JSON.parse(e))}catch{}(0,i.getDoc)((0,i.doc)(t.Pt,`sys_forms`,f.form)).then(async e=>{if(n)if(e.exists()){let t={...e.data(),id:e.id};p(e=>({...e,formConfigOverride:t})),localStorage.setItem(`fbos_form_${f.form}`,JSON.stringify(t))}else{let e=r(f.form);e&&(p(t=>({...t,formConfigOverride:e})),localStorage.setItem(`fbos_form_${f.form}`,JSON.stringify(e)),localStorage.removeItem(`fbos_custom_form_${f.form}`))}})}else{let e=r(f.form);e&&(f.formConfigOverride=e)}}let r=f.pageName||f.tabName||f.title;r&&(document.title=r),p(f),h(!1)}else p(`not-found`),h(!1),localStorage.removeItem(`fbos_route_${e.pathname}`)}catch{n&&m&&(p(`not-found`),h(!1))}})(),()=>{n=!1}},[e.pathname]);let[g,_]=(0,r.useState)(!1);if((0,r.useEffect)(()=>{let e;return m||o||!l?e=setTimeout(()=>_(!0),150):_(!1),()=>clearTimeout(e)},[m,o,l]),m||o||!l)return g?n?(0,s.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,s.jsxs)(`div`,{className:`mb-6`,children:[(0,s.jsx)(`div`,{className:`h-10 w-56 rounded-xl bg-foreground/5 animate-pulse mt-1`}),(0,s.jsx)(`div`,{className:`h-3 w-24 rounded bg-foreground/5 animate-pulse mt-3`})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(W,{}),(0,s.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,s.jsx)(t.L,{className:`w-6 h-6 animate-spin text-accent`})})]})]}):(0,s.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[40vh] z-10`,children:(0,s.jsxs)(`div`,{className:`p-4 rounded-2xl glass-panel border border-[var(--panel-border)]/40 bg-background/80 shadow-md flex items-center gap-3`,children:[(0,s.jsx)(t.L,{className:`w-4 h-4 animate-spin text-accent`}),(0,s.jsx)(`span`,{className:`text-[12px] font-medium text-foreground/60 tracking-wide`,children:`Loading page...`})]})}):null;if(f===`not-found`)return(0,s.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,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1 text-center`,children:[(0,s.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,s.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,s.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,s.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,s.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]})}),(0,s.jsx)(`h2`,{className:`text-3xl font-bold mb-3 text-foreground`,children:`Page Not Found`}),(0,s.jsx)(`p`,{className:`text-foreground/60 max-w-md`,children:`The route you are looking for does not exist or has been removed.`}),x(a)&&(()=>{let t=pi();return(0,s.jsxs)(`div`,{className:`mt-8 w-full max-w-lg text-left flex flex-col gap-4`,children:[(0,s.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)] px-5 py-4`,children:[(0,s.jsx)(`p`,{className:`text-[12px] font-extrabold tracking-tight text-gradient mb-1.5`,children:`Pages the app can see`}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/70 font-medium leading-relaxed`,children:t.length?t.join(` · `):`None yet. If your assistant says it created a page, the app has not picked its file up.`})]}),(0,s.jsx)(ke,{title:`If your assistant just made this page, paste this`,prompt:mi(e.pathname)})]})})()]})});if((f.pageId===`support`||f.isPrivate)&&!n)return(0,s.jsx)(c.Navigate,{to:`/login`,state:{from:e}});if(!T(a,f.isPrivate?f.pageType:`public`))return f.isAdmin?(0,s.jsx)(vi,{}):(0,s.jsx)(_i,{});let v=u.customRoutes?.[e.pathname]||(f&&f.route?u.customRoutes?.[f.route]:null),y=f.pageName?.toLowerCase().replace(/\s+/g,`_`)||f.pageId||`custom_page`,b=`pub_${y}`,S=u.microcomponents||(typeof window<`u`?window.__FBOS_MICROCOMPONENTS__:void 0),C=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_|_$/g,``),w=[f.contentKey,f.tabName,f.pageId,f.pageName,f.pageName?.replace(/\s+/g,`_`)].filter(Boolean).map(e=>C(e)).reduce((e,t)=>e||S?.[t],void 0),E=v||w||void 0,D=f.route||f.pageId||`custom`;if(di(f.template,!!E))return f.isAdmin?(0,s.jsx)(oi,{config:f,customContent:E},D):f.isInternal?(0,s.jsx)(si,{config:f,customContent:E},D):f.isPrivate?(0,s.jsx)(ai,{config:f,customContent:E},D):(0,s.jsx)(ii,{config:f,customContent:E},D);if(f.template===`board`){let e=f.isAdmin?`admin_${f.pageId||y}`:f.isInternal?`mem_${f.pageId||y}`:f.isPrivate?`user_${f.pageId||y}`:b;return(0,s.jsx)(u.components?.TemplateBoard||lt,{title:f.tabTitle||f.tabName||f.title||f.pageName||`Board`,subtitle:f.route,tasksCollection:`${e}_tasks`,categoriesCollection:`${e}_categories`,config:f,customContent:E},D)}if(f.template===`table`){let e=f.isAdmin?`admin_${f.pageId||y}`:f.isInternal?`mem_${f.pageId||y}`:f.isPrivate?`user_${f.pageId||y}`:b;return(0,s.jsx)(u.components?.TemplateTable||zn,{title:f.tabTitle||f.tabName||f.title||f.pageName||`Table`,subtitle:f.route,tableCollection:`${e}_table`,config:f,customContent:E},D)}if(f.template===`calendar`){let e=f.isAdmin?`admin_${f.pageId||y}`:f.isInternal?`mem_${f.pageId||y}`:f.isPrivate?`user_${f.pageId||y}`:b;return(0,s.jsx)(u.components?.TemplateCalendar||Hn,{title:f.tabTitle||f.tabName||f.title||f.pageName||`Calendar`,subtitle:f.route,eventsCollection:`${e}_events`,defaultTimeFormat:f.defaultTimeFormat||f.defaulttimeformat||`12h`,config:f,customContent:E},D)}if(f.template===`drive`){let e=f.isAdmin?`admin_${f.pageId||y}`:f.isInternal?`mem_${f.pageId||y}`:f.isPrivate?`user_${f.pageId||y}`:b;return(0,s.jsx)(u.components?.TemplateDrive||He,{title:f.tabTitle||f.tabName||f.title||f.pageName||`Drive`,subtitle:f.route,filesCollection:`${e}_files`,config:f,customContent:E},D)}return f.template===`inline_form`?(0,s.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-start mt-8 relative z-10 w-full min-h-[60vh]`,children:(0,s.jsx)(t.t,{isInline:!0,formId:f.form,formConfig:f.formConfigOverride})}):(0,s.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 w-full min-h-[60vh]`,children:(0,s.jsx)(t.t,{formId:f.form,formConfig:f.formConfigOverride,onClose:()=>window.history.back()})})}var xi=r.default.createContext({}),Si=Object.defineProperty,Ci=Object.getOwnPropertySymbols,wi=Object.prototype.hasOwnProperty,Ti=Object.prototype.propertyIsEnumerable,Ei=(e,t,n)=>t in e?Si(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Di=(e,t)=>{for(var n in t||={})wi.call(t,n)&&Ei(e,n,t[n]);if(Ci)for(var n of Ci(t))Ti.call(t,n)&&Ei(e,n,t[n]);return e},Oi=(0,r.forwardRef)((e,t)=>{let n=Di(Di({},r.useContext(xi)),e);return r.createElement(`svg`,Di({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),r.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`}),r.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`}))}),ki=`rules_version = '2';
|
|
137
137
|
service cloud.firestore {
|
|
138
138
|
match /databases/{database}/documents {
|
|
139
139
|
|
|
@@ -318,7 +318,7 @@ service cloud.firestore {
|
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
|
-
`,
|
|
321
|
+
`,Ai=`rules_version = '2';
|
|
322
322
|
service firebase.storage {
|
|
323
323
|
match /b/{bucket}/o {
|
|
324
324
|
|
|
@@ -491,4 +491,4 @@ service firebase.storage {
|
|
|
491
491
|
}
|
|
492
492
|
}
|
|
493
493
|
}
|
|
494
|
-
`,ki=[{key:`VITE_FIREBASE_API_KEY`,label:`API Key`,shownAs:`apiKey`},{key:`VITE_FIREBASE_AUTH_DOMAIN`,label:`Auth Domain`,shownAs:`authDomain`},{key:`VITE_FIREBASE_PROJECT_ID`,label:`Project ID`,shownAs:`projectId`},{key:`VITE_FIREBASE_STORAGE_BUCKET`,label:`Storage Bucket`,shownAs:`storageBucket`},{key:`VITE_FIREBASE_MESSAGING_SENDER_ID`,label:`Messaging Sender ID`,shownAs:`messagingSenderId`},{key:`VITE_FIREBASE_APP_ID`,label:`App ID`,shownAs:`appId`}];function Ai(e){let t;try{if(t={BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_ADMIN_EMAILS:void 0,VITE_FIREBASE_API_KEY:void 0,VITE_FIREBASE_APP_ID:void 0,VITE_FIREBASE_AUTH_DOMAIN:void 0,VITE_FIREBASE_MESSAGING_SENDER_ID:void 0,VITE_FIREBASE_PROJECT_ID:void 0,VITE_FIREBASE_STORAGE_BUCKET:void 0}?.[e],t&&typeof t==`string`&&t.trim()!==``)return t}catch{}try{if(t=(typeof window<`u`?window:globalThis)?.process?.env?.[e],t&&typeof t==`string`&&t.trim()!==``)return t}catch{}try{switch(e){case`VITE_FIREBASE_API_KEY`:t=void 0;break;case`VITE_FIREBASE_AUTH_DOMAIN`:t=void 0;break;case`VITE_FIREBASE_PROJECT_ID`:t=void 0;break;case`VITE_FIREBASE_STORAGE_BUCKET`:t=void 0;break;case`VITE_FIREBASE_MESSAGING_SENDER_ID`:t=void 0;break;case`VITE_FIREBASE_APP_ID`:t=void 0;break;case`VITE_ADMIN_EMAILS`:t=void 0;break}if(t&&typeof t==`string`&&t.trim()!==``)return t}catch{}return``}function ji(e,t){let n=Ai(e);if(n)return n;if(t?.firebaseConfig){let n={VITE_FIREBASE_API_KEY:`apiKey`,VITE_FIREBASE_AUTH_DOMAIN:`authDomain`,VITE_FIREBASE_PROJECT_ID:`projectId`,VITE_FIREBASE_STORAGE_BUCKET:`storageBucket`,VITE_FIREBASE_MESSAGING_SENDER_ID:`messagingSenderId`,VITE_FIREBASE_APP_ID:`appId`}[e];if(n&&t.firebaseConfig[n])return t.firebaseConfig[n]}return e===`VITE_ADMIN_EMAILS`&&t?.adminEmails?Array.isArray(t.adminEmails)?t.adminEmails.join(`,`):t.adminEmails||``:``}function Mi(e){let t=[],n=[],r=t=>ji(t,e);for(let{key:e,label:i}of ki){let a=r(e);a?a.trim()===``&&n.push(i):t.push(i)}let i=r(`VITE_ADMIN_EMAILS`),a=!i||i.trim()===``,o=[...t,...n];return{allSet:o.length===0,missing:o,empty:n,missingAdminEmails:a}}function Ni(){return Mi().allSet}var Pi=Oi;function Fi(e){let t=e.map(e=>e.trim().toLowerCase()).filter(Boolean).filter((e,t,n)=>n.indexOf(e)===t),n=t.length?t.map(e=>`'${e.replace(/'/g,``)}'`).join(`, `):`'your@email.com'`;return Di.replace(/(function adminEmails\(\) \{\s*return )\[[^\]]*\];/,`$1[${n}];`)}function Ii(e){return e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean)}var Li=/^[^@\s]+@[^@\s]+\.[^@\s]+$/;function Ri({code:e,label:n}){let[i,a]=r.default.useState(!1);return(0,s.jsxs)(t.o.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>{navigator.clipboard?.writeText(e),a(!0),setTimeout(()=>a(!1),2e3)},className:`inline-flex items-center gap-2 px-4 py-2 mt-2 rounded-xl text-[13px] font-bold tracking-wide transition-all ${i?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary shadow-sm`}`,children:[i?(0,s.jsx)(t._t,{className:`w-4 h-4`}):(0,s.jsx)(t.at,{className:`w-4 h-4`}),i?`Copied to Clipboard!`:n]})}function zi({name:e,shownAs:n,hint:i}){let[a,o]=r.default.useState(!1);return(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3 border-b border-[var(--panel-border)]/40 last:border-0`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`div`,{className:`text-[13.5px] font-bold text-foreground truncate`,children:e}),(0,s.jsx)(`div`,{className:`text-[12.5px] text-foreground/50 font-medium`,children:i??(0,s.jsxs)(s.Fragment,{children:[`the value Firebase labels `,n]})})]}),(0,s.jsxs)(`button`,{type:`button`,onClick:()=>{navigator.clipboard?.writeText(e),o(!0),setTimeout(()=>o(!1),2e3)},className:`inline-flex items-center gap-1.5 h-9 px-3 rounded-xl text-[12px] font-bold shrink-0 transition-all cursor-pointer active:scale-[0.98] ${a?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary`}`,children:[a?(0,s.jsx)(t._t,{className:`w-3.5 h-3.5`}):(0,s.jsx)(t.at,{className:`w-3.5 h-3.5`}),a?`Copied`:`Copy name`]})]})}function Bi({number:e,title:n,children:r,worked:i}){return(0,s.jsxs)(`div`,{className:`flex flex-col relative pb-10 mb-10 border-b border-[var(--panel-border)]/50 last:border-0 last:pb-0 last:mb-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,s.jsx)(`span`,{className:`w-8 h-8 shrink-0 rounded-full bg-accent/10 border border-accent/20 text-accent flex items-center justify-center text-[14px] font-extrabold`,children:e}),(0,s.jsx)(`h3`,{className:`text-[17px] md:text-[19px] font-extrabold text-foreground tracking-tight`,children:n})]}),(0,s.jsxs)(`div`,{className:`text-[14px] md:text-[15px] text-foreground/70 leading-relaxed space-y-4`,children:[r,(0,s.jsxs)(`p`,{"data-step-worked":!0,className:`flex items-start gap-2 text-[13px] font-semibold text-emerald-500`,children:[(0,s.jsx)(t._t,{className:`w-4 h-4 mt-[2px] shrink-0`}),(0,s.jsx)(`span`,{children:i})]})]})]})}function Vi({standalone:e}){let n=t.Mt(),[i]=(0,r.useState)(()=>{let e=localStorage.getItem(`theme-mode`);return e===`light`?!1:e===`dark`?!0:window.matchMedia(`(prefers-color-scheme: dark)`).matches}),a=Ii(ji(`VITE_ADMIN_EMAILS`,n)),o=a.filter(e=>!Li.test(e)),c=a.length>0&&o.length===0,l=Fi(a);return(0,r.useEffect)(()=>{e&&document.documentElement.setAttribute(`data-theme`,i?`dark`:`light`)},[i,e]),(0,r.useEffect)(()=>{if(e&&t.Lt.faviconUrl){let e=document.querySelector(`link[rel*='icon']`);e||(e=document.createElement(`link`),e.rel=`icon`,document.head.appendChild(e)),e.href=t.Lt.faviconUrl}},[e]),(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col min-h-screen`,children:[(0,s.jsx)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,s.jsxs)(`div`,{children:[(0,s.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:`Setup`}),(0,s.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/50`,children:`Six steps. Nothing to install — you only click and paste.`})]})}),(0,s.jsx)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},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`,children:[(0,s.jsx)(`div`,{className:`mb-8 pb-6 border-b border-[var(--panel-border)]/50 relative z-10`,children:(0,s.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Connect your app to Firebase`}),(0,s.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/50 mt-2 leading-relaxed`,children:`Firebase is the free Google service that stores your app's data and signs your people in. You will have two tabs open: Firebase in one, your app's Secrets in the other. Around ten minutes, once.`})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(t.o.a,{whileHover:{scale:1.05},whileTap:{scale:.95},href:`mailto:antonina@youraiworkflow.co`,title:`Email Support`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer btn-secondary`,children:(0,s.jsx)(t.P,{className:`w-4 h-4`})}),(0,s.jsx)(t.o.a,{whileHover:{scale:1.05},whileTap:{scale:.95},href:`https://wa.me/34632407883`,target:`_blank`,rel:`noopener noreferrer`,title:`WhatsApp Support`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer btn-secondary`,children:(0,s.jsx)(Ei,{className:`w-4 h-4 text-foreground/80`})})]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col relative z-10 p-6 md:p-8 bg-foreground/[0.015] rounded-3xl border border-[var(--panel-border)]/50 mt-4`,children:[(0,s.jsx)(Bi,{number:1,title:`Create a Firebase project`,worked:`You land on a page with your project's name across the top.`,children:(0,s.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,s.jsxs)(`li`,{children:[`Open`,` `,(0,s.jsx)(`a`,{href:`https://console.firebase.google.com`,target:`_blank`,rel:`noopener noreferrer`,className:`text-accent underline underline-offset-2 font-semibold hover:text-accent-deep transition-colors`,children:`console.firebase.google.com`}),` `,`and click `,(0,s.jsx)(`strong`,{children:`Add project`}),`. Sign in with your Google account if it asks.`]}),(0,s.jsxs)(`li`,{children:[`Type any name you like and click `,(0,s.jsx)(`strong`,{children:`Continue`}),`.`]}),(0,s.jsxs)(`li`,{children:[`If it offers `,(0,s.jsx)(`strong`,{children:`Enable Gemini in Firebase`}),`, switch it off.`]}),(0,s.jsxs)(`li`,{children:[`Switch off `,(0,s.jsx)(`strong`,{children:`Enable Google Analytics for this project`}),`.`]}),(0,s.jsxs)(`li`,{children:[`Click `,(0,s.jsx)(`strong`,{children:`Create project`}),`, wait, then click `,(0,s.jsx)(`strong`,{children:`Continue`}),`.`]})]})}),(0,s.jsx)(Bi,{number:2,title:`Add a web app and copy the six values`,worked:`Six values are on screen under your app's nickname. Leave this tab open — the next step needs them.`,children:(0,s.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,s.jsxs)(`li`,{children:[`On that page click `,(0,s.jsx)(`strong`,{children:`+ Add app`}),` under your project's name, then pick the `,(0,s.jsx)(`strong`,{children:`</> Web`}),` icon.`]}),(0,s.jsxs)(`li`,{children:[`Give it any nickname (`,(0,s.jsx)(`span`,{className:`text-accent`,children:`MyApp`}),` is fine). Leave `,(0,s.jsx)(`strong`,{children:`Firebase Hosting`}),` unticked.`]}),(0,s.jsxs)(`li`,{children:[`Click `,(0,s.jsx)(`strong`,{children:`Register app`}),`.`]}),(0,s.jsx)(`li`,{children:`Firebase now shows six values on screen, each with a label beside it — apiKey, authDomain, projectId, storageBucket, messagingSenderId and appId. You will copy them one at a time in the next step, so keep this tab open.`})]})}),(0,s.jsxs)(Bi,{number:3,title:`Paste the six values and your email into Secrets`,worked:`Seven secrets are listed in the Secrets tab, with the names spelled exactly as above.`,children:[(0,s.jsxs)(`p`,{className:`text-foreground/80`,children:[`In Google AI Studio, open the `,(0,s.jsx)(`strong`,{children:`Secrets`}),` tab beside your app. For each row below: click `,(0,s.jsx)(`strong`,{children:`Add secret`}),`, copy the name here, paste it as the name, then paste the matching value from your Firebase tab. The names have to match letter for letter — use the Copy name button and don't retype them.`]}),(0,s.jsx)(`p`,{className:`text-foreground/80`,children:`The last row is not from Firebase: its value is the email address you will sign in with. That is what makes you the owner of this app. Several people? Separate their addresses with commas.`}),(0,s.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl overflow-hidden bg-background`,children:[ki.map(({key:e,shownAs:t})=>(0,s.jsx)(zi,{name:e,shownAs:t},e)),(0,s.jsx)(zi,{name:`VITE_ADMIN_EMAILS`,hint:`the email you will sign in with`})]})]}),(0,s.jsx)(Bi,{number:4,title:`Turn on sign-in`,worked:`Email/Password shows as Enabled, and your app's address is in the Authorized domains list.`,children:(0,s.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,s.jsxs)(`li`,{children:[`In the Firebase menu on the left, open `,(0,s.jsx)(`strong`,{children:`Authentication`}),` and click `,(0,s.jsx)(`strong`,{children:`Get started`}),`.`]}),(0,s.jsxs)(`li`,{children:[`Open the `,(0,s.jsx)(`strong`,{children:`Sign-in method`}),` tab.`]}),(0,s.jsxs)(`li`,{children:[`Click `,(0,s.jsx)(`strong`,{children:`Email/Password`}),`, switch on the first toggle and `,(0,s.jsx)(`strong`,{children:`Save`}),`. (Leave email link off.)`]}),(0,s.jsxs)(`li`,{children:[`If you also want the `,(0,s.jsx)(`strong`,{children:`Sign in with Google`}),` button to work, click `,(0,s.jsx)(`strong`,{children:`Google`}),`, switch it on, pick your own address as the support email, and `,(0,s.jsx)(`strong`,{children:`Save`}),`.`]}),(0,s.jsxs)(`li`,{children:[`Open the `,(0,s.jsx)(`strong`,{children:`Settings`}),` tab, then `,(0,s.jsx)(`strong`,{children:`Authorized domains`}),`. Your app has to be listed here or nobody can sign in.`]}),(0,s.jsxs)(`li`,{children:[(0,s.jsx)(`strong`,{children:`To get your app's address:`}),` in AI Studio, right-click any link in your app's own menu and choose `,(0,s.jsx)(`strong`,{children:`Copy link address`}),`. Back in Firebase click`,` `,(0,s.jsx)(`strong`,{children:`Add domain`}),`, paste it, and save. It will look something like ais-dev-…run.app — that is the right thing.`]})]})}),(0,s.jsxs)(Bi,{number:5,title:`Create the database and publish its rules`,worked:`The Rules tab shows your text with today's date next to it, and no red error.`,children:[(0,s.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80 mb-4`,children:[(0,s.jsxs)(`li`,{children:[`In the Firebase menu, open `,(0,s.jsx)(`strong`,{children:`Firestore Database`}),` and click `,(0,s.jsx)(`strong`,{children:`Create database`}),`.`]}),(0,s.jsxs)(`li`,{children:[`Pick `,(0,s.jsx)(`strong`,{children:`Standard edition`}),` if asked, choose the location closest to your people, start in `,(0,s.jsx)(`strong`,{children:`Production mode`}),`, and click Continue.`]}),(0,s.jsx)(`li`,{children:`Check that the box below shows the email you sign in with.`}),(0,s.jsxs)(`li`,{children:[`Click `,(0,s.jsx)(`strong`,{children:`Copy the rules`}),`, then in Firebase open the `,(0,s.jsx)(`strong`,{children:`Rules`}),` tab, select everything that is there, paste over it, and click `,(0,s.jsx)(`strong`,{children:`Publish`}),`.`]})]}),(0,s.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl p-4 md:p-5 mb-2`,children:[(0,s.jsx)(`p`,{className:`text-[13px] font-bold text-foreground mb-1.5`,children:`Who runs this app?`}),a.length>0?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(`p`,{className:`text-[13px] text-foreground/60 leading-[1.6]`,children:[`Read from your `,(0,s.jsx)(`strong`,{children:`VITE_ADMIN_EMAILS`}),` secret and written into the rules you copy below. It is what makes you the owner the first time you register.`]}),(0,s.jsx)(`p`,{"data-admin-emails":!0,className:`mt-2.5 text-[14px] font-bold text-foreground break-all`,children:a.join(`, `)})]}):(0,s.jsxs)(`p`,{className:`text-[13px] text-amber-500 font-medium leading-[1.6]`,children:[`The app cannot see a `,(0,s.jsx)(`strong`,{children:`VITE_ADMIN_EMAILS`}),` secret yet. Go back to step 3, add it with the email you sign in with, then reload this page — the rules below will carry your address once it is there.`]}),o.length>0&&(0,s.jsxs)(`p`,{className:`mt-2.5 text-[12px] font-medium text-amber-500`,children:[`That does not look like an email address: `,o.join(`, `),`. Fix the secret in step 3 and reload this page.`]}),c&&(0,s.jsxs)(`p`,{className:`mt-2.5 text-[12px] font-medium text-emerald-500 flex items-center gap-1.5`,children:[(0,s.jsx)(t._t,{className:`w-3.5 h-3.5 shrink-0`}),`Written into the rules below.`]})]}),c&&(0,s.jsx)(Ri,{code:l,label:`Copy the rules`})]}),(0,s.jsxs)(Bi,{number:6,title:`Create storage and publish its rules`,worked:`The Storage Rules tab shows your text with today's date next to it, and no red error.`,children:[(0,s.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80 mb-4`,children:[(0,s.jsxs)(`li`,{children:[`In the Firebase menu, open `,(0,s.jsx)(`strong`,{children:`Storage`}),`. Google asks you to upgrade the project first: click `,(0,s.jsx)(`strong`,{children:`Upgrade project`}),` and pick the pay-as-you-go`,` `,(0,s.jsx)(`strong`,{children:`Blaze plan`}),`. Profile photos and attachments cost about $0.03 per gigabyte a month, so this is cents. Set a budget you are comfortable with (say $20), link a billing account, and continue.`]}),(0,s.jsxs)(`li`,{children:[`Click `,(0,s.jsx)(`strong`,{children:`Get started`}),`, choose a no-cost location, start in `,(0,s.jsx)(`strong`,{children:`Production mode`}),`, and click `,(0,s.jsx)(`strong`,{children:`Create`}),`.`]}),(0,s.jsx)(`li`,{children:`Once it exists, Firebase shows the storage address at the top (something like your-project.firebasestorage.app). If it is not exactly what you pasted into the storage secret in step 3, open Secrets and correct that one now.`}),(0,s.jsxs)(`li`,{children:[`Open the `,(0,s.jsx)(`strong`,{children:`Rules`}),` tab, select everything that is there, paste these over it, and click `,(0,s.jsx)(`strong`,{children:`Publish`}),`.`]})]}),(0,s.jsx)(Ri,{code:Pi,label:`Copy the storage rules`})]})]}),(0,s.jsx)(`div`,{className:`mt-8 relative z-10`,children:(0,s.jsx)(ke,{description:`Reload the app once you have added the secrets. If it still asks you to set up, hand this to your assistant.`,prompt:`My Firebase keys are in the Secrets tab — can you check the app connects?`})})]})})]})}function Hi(){let{user:e}=A(),n=(e?.displayName||e?.email?.split(`@`)[0]||`there`).split(` `)[0],r=n.charAt(0).toUpperCase()+n.slice(1);return(0,s.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,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,s.jsxs)(`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:[`Welcome back, `,r,`.`]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/dashboard`]})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-4 flex-1 min-h-[500px]`,children:[(0,s.jsx)(`div`,{className:`flex justify-start`,children:(0,s.jsx)(W,{})}),(0,s.jsxs)(`div`,{className:`w-full flex-1 glass-panel rounded-3xl p-8 md:p-12 flex items-center justify-center relative overflow-hidden border border-[var(--panel-border)] shadow-2xl bg-[var(--panel-bg)]`,children:[(0,s.jsx)(`div`,{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-64 h-64 bg-accent/10 blur-[100px] rounded-full pointer-events-none`}),(0,s.jsx)(t.s,{mode:`wait`,children:(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},transition:{duration:.3},className:`text-center z-10`,children:[(0,s.jsx)(`div`,{className:`w-16 h-16 rounded-3xl bg-accent/10 border border-accent/20 flex items-center justify-center text-accent mx-auto mb-6 shadow-inner`,children:(0,s.jsx)(t.it,{className:`w-6 h-6`})}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground mb-2`,children:`No data added here yet`}),(0,s.jsx)(`p`,{className:`text-foreground/40 font-medium`,children:`Keep moving forward, your data will appear here.`})]})})]})]})]})}var Ui=()=>(0,s.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center min-h-[60vh] z-10 animate-in fade-in duration-500`,children:[(0,s.jsx)(`div`,{className:`w-12 h-12 rounded-xl glass-panel border border-[var(--panel-border)] flex items-center justify-center mb-6 shadow-xl`,children:(0,s.jsx)(t.it,{className:`w-6 h-6 text-accent animate-pulse`})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-3 glass-panel px-5 py-2.5 rounded-full border border-[var(--panel-border)]`,children:[(0,s.jsx)(`div`,{className:`w-4 h-4 border-2 border-accent border-t-transparent rounded-full animate-spin`}),(0,s.jsx)(`span`,{className:`text-[13px] font-bold tracking-widest uppercase text-foreground/70`,children:`Connecting`})]})]});function Wi({level:e,children:t}){let{user:n,userRole:r,loading:i,userInactive:a,signOut:o,roleResolved:l}=A(),u=(0,c.useLocation)();return i||!l?(0,s.jsx)(Ui,{}):n?a?(0,s.jsx)(pi,{tone:`red`,title:`Access Denied`,message:`You don't have access to this app. Please contact the administrator.`,action:(0,s.jsx)(`button`,{onClick:()=>o(),className:mi,children:`Sign Out`})}):n.emailVerified?e===`admin`&&!x(r)?(0,s.jsx)(gi,{}):e===`internal`&&!S(r)?(0,s.jsx)(hi,{}):(0,s.jsx)(s.Fragment,{children:t}):(0,s.jsx)(c.Navigate,{to:`/verify`}):(0,s.jsx)(c.Navigate,{to:`/login?from=${encodeURIComponent(u.pathname)}`})}var Gi=({children:e})=>(0,s.jsx)(Wi,{level:`signed-in`,children:e}),Ki=({children:e})=>(0,s.jsx)(Wi,{level:`admin`,children:e});function qi({children:e}){let{user:t,loading:n,roleResolved:r}=A(),[i]=(0,c.useSearchParams)();return n||!r?(0,s.jsx)(Ui,{}):t&&t.emailVerified?(0,s.jsx)(c.Navigate,{to:i.get(`from`)||`/dashboard`,replace:!0}):(0,s.jsx)(s.Fragment,{children:e})}function Ji({children:e}){let{user:t,loading:n,roleResolved:r}=A();return n||!r?(0,s.jsx)(Ui,{}):t?t.emailVerified?(0,s.jsx)(c.Navigate,{to:`/dashboard`}):(0,s.jsx)(s.Fragment,{children:e}):(0,s.jsx)(c.Navigate,{to:`/`})}function Yi(){return(0,s.jsxs)(`div`,{className:`fixed top-0 left-0 w-full h-full pointer-events-none -z-0 overflow-hidden`,children:[(0,s.jsx)(t.o.div,{animate:{scale:[1,1.1,1],opacity:[.6,1,.6]},transition:{duration:12,repeat:1/0,ease:`easeInOut`},className:`absolute -top-[30%] md:-top-[400px] -right-[10%] md:-right-[200px] w-[500px] md:w-[800px] h-[500px] md:h-[800px] rounded-full bg-decorator-1 blur-[80px] md:blur-[120px]`}),(0,s.jsx)(t.o.div,{animate:{scale:[1,1.2,1],opacity:[.5,.9,.5]},transition:{duration:18,repeat:1/0,ease:`easeInOut`,delay:2},className:`absolute -bottom-[20%] md:-bottom-[300px] -left-[10%] md:-left-[100px] w-[400px] md:w-[600px] h-[400px] md:h-[600px] rounded-full bg-decorator-2 blur-[60px] md:blur-[100px]`})]})}function Xi(){let e=t.Mt().components?.Home||te;return(0,s.jsx)(k,{children:(0,s.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,s.jsx)(z,{}),(0,s.jsxs)(c.Routes,{children:[(0,s.jsx)(c.Route,{path:`/`,element:(0,s.jsx)(qi,{children:(0,s.jsx)(e,{})})}),(0,s.jsx)(c.Route,{path:`/register`,element:(0,s.jsx)(qi,{children:(0,s.jsx)(B,{})})}),(0,s.jsx)(c.Route,{path:`/login`,element:(0,s.jsx)(qi,{children:(0,s.jsx)(ne,{})})}),(0,s.jsx)(c.Route,{path:`/reset-password`,element:(0,s.jsx)(qi,{children:(0,s.jsx)(K,{})})}),(0,s.jsx)(c.Route,{path:`/verify`,element:(0,s.jsx)(Ji,{children:(0,s.jsx)(V,{})})}),(0,s.jsx)(c.Route,{path:`/guide`,element:(0,s.jsx)(it,{})}),(0,s.jsx)(c.Route,{path:`/templates`,element:(0,s.jsx)(qe,{})}),(0,s.jsx)(c.Route,{path:`/templates/inline_form`,element:(0,s.jsx)(at,{})}),(0,s.jsx)(c.Route,{path:`/templates/popup_form`,element:(0,s.jsx)(ot,{})}),(0,s.jsx)(c.Route,{path:`/templates/confirmation`,element:(0,s.jsx)(st,{})}),(0,s.jsx)(c.Route,{path:`/templates/board`,element:(0,s.jsx)(lt,{})}),(0,s.jsx)(c.Route,{path:`/templates/table`,element:(0,s.jsx)(zn,{})}),(0,s.jsx)(c.Route,{path:`/templates/calendar`,element:(0,s.jsx)(Hn,{})}),(0,s.jsx)(c.Route,{path:`/templates/drive`,element:(0,s.jsx)(He,{})}),(0,s.jsx)(c.Route,{path:`/users`,element:(0,s.jsx)(Ki,{children:(0,s.jsx)(Y,{})})}),(0,s.jsx)(c.Route,{path:`/users/:id`,element:(0,s.jsx)(Ki,{children:(0,s.jsx)(Y,{})})}),(0,s.jsx)(c.Route,{path:`/inbox`,element:(0,s.jsx)(Ki,{children:(0,s.jsx)(Be,{})})}),(0,s.jsx)(c.Route,{path:`/submissions`,element:(0,s.jsx)(c.Navigate,{to:`/inbox`,replace:!0})}),(0,s.jsx)(c.Route,{path:`/requests`,element:(0,s.jsx)(c.Navigate,{to:`/inbox`,replace:!0})}),(0,s.jsx)(c.Route,{path:`/assets`,element:(0,s.jsx)(Ki,{children:(0,s.jsx)(Ke,{})})}),(0,s.jsx)(c.Route,{path:`/drive/*`,element:(0,s.jsx)(c.Navigate,{to:`/assets`,replace:!0})}),(0,s.jsx)(c.Route,{path:`/theme`,element:(0,s.jsx)(Ki,{children:(0,s.jsx)(pr,{})})}),(0,s.jsx)(c.Route,{path:`/pages/*`,element:(0,s.jsx)(Ki,{children:(0,s.jsx)(Ur,{})})}),(0,s.jsx)(c.Route,{path:`/forms/*`,element:(0,s.jsx)(Ki,{children:(0,s.jsx)(ni,{})})}),(0,s.jsx)(c.Route,{path:`/settings`,element:(0,s.jsx)(c.Navigate,{to:`/pages`,replace:!0})}),(0,s.jsx)(c.Route,{path:`/profile`,element:(0,s.jsx)(Gi,{children:(0,s.jsx)(G,{})})}),(0,s.jsx)(c.Route,{path:`/dashboard`,element:(0,s.jsx)(Gi,{children:(0,s.jsx)(Hi,{})})}),(0,s.jsx)(c.Route,{path:`/setup`,element:(0,s.jsx)(Vi,{})}),(0,s.jsx)(c.Route,{path:`*`,element:(0,s.jsx)(vi,{})})]}),(0,s.jsx)(Yi,{})]})})}function Zi(){return(0,s.jsx)(c.BrowserRouter,{children:(0,s.jsx)(Qi,{})})}function Qi(){let e=t.Mt();return e.firebaseConfig&&e.firebaseConfig.apiKey&&e.firebaseConfig.apiKey.trim()!==``&&e.firebaseConfig.projectId&&e.firebaseConfig.projectId.trim()!==``||Ni()?(0,s.jsx)(Xi,{}):(0,s.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,s.jsx)(z,{standalone:!0}),(0,s.jsx)(Vi,{standalone:!0}),(0,s.jsx)(Yi,{})]})}function $i(e){let n=e.firebaseConfig;return n&&n.apiKey&&n.apiKey.trim()!==``&&n.projectId&&n.projectId.trim()!==``&&t.Ft(n),(0,s.jsx)(t.jt,{config:{firebaseConfig:e.firebaseConfig,adminEmails:e.adminEmails,basename:e.basename,onAuthChange:e.onAuthChange,themeConfig:e.themeConfig,components:e.components,customRoutes:e.customRoutes,microcomponents:e.microcomponents,defaultConfigs:e.defaultConfigs},children:(0,s.jsx)(t.kt,{children:(0,s.jsx)(`div`,{className:`firebase-os flex-1 flex flex-col min-h-screen`,style:{background:`var(--bg-gradient)`,color:`var(--fg-color)`},children:(0,s.jsx)(Zi,{})})})})}exports.AdminNotifications=N,exports.Button=t.r,exports.ConfirmModal=re,exports.ContactPopup=t.t,exports.CustomSelect=t.n,exports.DashboardNav=W,exports.FirebaseOS=$i,exports.Input=t.i,exports.Navbar=z,exports.PhoneInputField=n.t,Object.defineProperty(exports,`auth`,{enumerable:!0,get:function(){return t.Nt}}),Object.defineProperty(exports,`db`,{enumerable:!0,get:function(){return t.Pt}}),Object.defineProperty(exports,`storage`,{enumerable:!0,get:function(){return t.It}}),exports.useAuth=A,exports.useConfig=t.Mt,exports.useTheme=t.At;
|
|
494
|
+
`,ji=[{key:`VITE_FIREBASE_API_KEY`,label:`API Key`,shownAs:`apiKey`},{key:`VITE_FIREBASE_AUTH_DOMAIN`,label:`Auth Domain`,shownAs:`authDomain`},{key:`VITE_FIREBASE_PROJECT_ID`,label:`Project ID`,shownAs:`projectId`},{key:`VITE_FIREBASE_STORAGE_BUCKET`,label:`Storage Bucket`,shownAs:`storageBucket`},{key:`VITE_FIREBASE_MESSAGING_SENDER_ID`,label:`Messaging Sender ID`,shownAs:`messagingSenderId`},{key:`VITE_FIREBASE_APP_ID`,label:`App ID`,shownAs:`appId`}];function Mi(e){let t;try{if(t={BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_ADMIN_EMAILS:void 0,VITE_FIREBASE_API_KEY:void 0,VITE_FIREBASE_APP_ID:void 0,VITE_FIREBASE_AUTH_DOMAIN:void 0,VITE_FIREBASE_MESSAGING_SENDER_ID:void 0,VITE_FIREBASE_PROJECT_ID:void 0,VITE_FIREBASE_STORAGE_BUCKET:void 0}?.[e],t&&typeof t==`string`&&t.trim()!==``)return t}catch{}try{if(t=(typeof window<`u`?window:globalThis)?.process?.env?.[e],t&&typeof t==`string`&&t.trim()!==``)return t}catch{}try{switch(e){case`VITE_FIREBASE_API_KEY`:t=void 0;break;case`VITE_FIREBASE_AUTH_DOMAIN`:t=void 0;break;case`VITE_FIREBASE_PROJECT_ID`:t=void 0;break;case`VITE_FIREBASE_STORAGE_BUCKET`:t=void 0;break;case`VITE_FIREBASE_MESSAGING_SENDER_ID`:t=void 0;break;case`VITE_FIREBASE_APP_ID`:t=void 0;break;case`VITE_ADMIN_EMAILS`:t=void 0;break}if(t&&typeof t==`string`&&t.trim()!==``)return t}catch{}return``}function Ni(e,t){let n=Mi(e);if(n)return n;if(t?.firebaseConfig){let n={VITE_FIREBASE_API_KEY:`apiKey`,VITE_FIREBASE_AUTH_DOMAIN:`authDomain`,VITE_FIREBASE_PROJECT_ID:`projectId`,VITE_FIREBASE_STORAGE_BUCKET:`storageBucket`,VITE_FIREBASE_MESSAGING_SENDER_ID:`messagingSenderId`,VITE_FIREBASE_APP_ID:`appId`}[e];if(n&&t.firebaseConfig[n])return t.firebaseConfig[n]}return e===`VITE_ADMIN_EMAILS`&&t?.adminEmails?Array.isArray(t.adminEmails)?t.adminEmails.join(`,`):t.adminEmails||``:``}function Pi(e){let t=[],n=[],r=t=>Ni(t,e);for(let{key:e,label:i}of ji){let a=r(e);a?a.trim()===``&&n.push(i):t.push(i)}let i=r(`VITE_ADMIN_EMAILS`),a=!i||i.trim()===``,o=[...t,...n];return{allSet:o.length===0,missing:o,empty:n,missingAdminEmails:a}}function Fi(){return Pi().allSet}var Ii=Ai;function Li(e){let t=e.map(e=>e.trim().toLowerCase()).filter(Boolean).filter((e,t,n)=>n.indexOf(e)===t),n=t.length?t.map(e=>`'${e.replace(/'/g,``)}'`).join(`, `):`'your@email.com'`;return ki.replace(/(function adminEmails\(\) \{\s*return )\[[^\]]*\];/,`$1[${n}];`)}function Ri(e){return e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean)}var zi=/^[^@\s]+@[^@\s]+\.[^@\s]+$/;function Bi({code:e,label:n}){let[i,a]=r.default.useState(!1);return(0,s.jsxs)(t.o.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>{navigator.clipboard?.writeText(e),a(!0),setTimeout(()=>a(!1),2e3)},className:`inline-flex items-center gap-2 px-4 py-2 mt-2 rounded-xl text-[13px] font-bold tracking-wide transition-all ${i?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary shadow-sm`}`,children:[i?(0,s.jsx)(t._t,{className:`w-4 h-4`}):(0,s.jsx)(t.at,{className:`w-4 h-4`}),i?`Copied to Clipboard!`:n]})}function Vi({name:e,shownAs:n,hint:i}){let[a,o]=r.default.useState(!1);return(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3 border-b border-[var(--panel-border)]/40 last:border-0`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`div`,{className:`text-[13.5px] font-bold text-foreground truncate`,children:e}),(0,s.jsx)(`div`,{className:`text-[12.5px] text-foreground/50 font-medium`,children:i??(0,s.jsxs)(s.Fragment,{children:[`the value Firebase labels `,n]})})]}),(0,s.jsxs)(`button`,{type:`button`,onClick:()=>{navigator.clipboard?.writeText(e),o(!0),setTimeout(()=>o(!1),2e3)},className:`inline-flex items-center gap-1.5 h-9 px-3 rounded-xl text-[12px] font-bold shrink-0 transition-all cursor-pointer active:scale-[0.98] ${a?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary`}`,children:[a?(0,s.jsx)(t._t,{className:`w-3.5 h-3.5`}):(0,s.jsx)(t.at,{className:`w-3.5 h-3.5`}),a?`Copied`:`Copy name`]})]})}function Hi({number:e,title:n,children:r,worked:i}){return(0,s.jsxs)(`div`,{className:`flex flex-col relative pb-10 mb-10 border-b border-[var(--panel-border)]/50 last:border-0 last:pb-0 last:mb-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,s.jsx)(`span`,{className:`w-8 h-8 shrink-0 rounded-full bg-accent/10 border border-accent/20 text-accent flex items-center justify-center text-[14px] font-extrabold`,children:e}),(0,s.jsx)(`h3`,{className:`text-[17px] md:text-[19px] font-extrabold text-foreground tracking-tight`,children:n})]}),(0,s.jsxs)(`div`,{className:`text-[14px] md:text-[15px] text-foreground/70 leading-relaxed space-y-4`,children:[r,(0,s.jsxs)(`p`,{"data-step-worked":!0,className:`flex items-start gap-2 text-[13px] font-semibold text-emerald-500`,children:[(0,s.jsx)(t._t,{className:`w-4 h-4 mt-[2px] shrink-0`}),(0,s.jsx)(`span`,{children:i})]})]})]})}function Ui({standalone:e}){let n=t.Mt(),[i]=(0,r.useState)(()=>{let e=localStorage.getItem(`theme-mode`);return e===`light`?!1:e===`dark`?!0:window.matchMedia(`(prefers-color-scheme: dark)`).matches}),a=Ri(Ni(`VITE_ADMIN_EMAILS`,n)),o=a.filter(e=>!zi.test(e)),c=a.length>0&&o.length===0,l=Li(a);return(0,r.useEffect)(()=>{e&&document.documentElement.setAttribute(`data-theme`,i?`dark`:`light`)},[i,e]),(0,r.useEffect)(()=>{if(e&&t.Lt.faviconUrl){let e=document.querySelector(`link[rel*='icon']`);e||(e=document.createElement(`link`),e.rel=`icon`,document.head.appendChild(e)),e.href=t.Lt.faviconUrl}},[e]),(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col min-h-screen`,children:[(0,s.jsx)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,s.jsxs)(`div`,{children:[(0,s.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:`Setup`}),(0,s.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/50`,children:`Six steps. Nothing to install — you only click and paste.`})]})}),(0,s.jsx)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},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`,children:[(0,s.jsx)(`div`,{className:`mb-8 pb-6 border-b border-[var(--panel-border)]/50 relative z-10`,children:(0,s.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Connect your app to Firebase`}),(0,s.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/50 mt-2 leading-relaxed`,children:`Firebase is the free Google service that stores your app's data and signs your people in. You will have two tabs open: Firebase in one, your app's Secrets in the other. Around ten minutes, once.`})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(t.o.a,{whileHover:{scale:1.05},whileTap:{scale:.95},href:`mailto:antonina@youraiworkflow.co`,title:`Email Support`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer btn-secondary`,children:(0,s.jsx)(t.P,{className:`w-4 h-4`})}),(0,s.jsx)(t.o.a,{whileHover:{scale:1.05},whileTap:{scale:.95},href:`https://wa.me/34632407883`,target:`_blank`,rel:`noopener noreferrer`,title:`WhatsApp Support`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer btn-secondary`,children:(0,s.jsx)(Oi,{className:`w-4 h-4 text-foreground/80`})})]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col relative z-10 p-6 md:p-8 bg-foreground/[0.015] rounded-3xl border border-[var(--panel-border)]/50 mt-4`,children:[(0,s.jsx)(Hi,{number:1,title:`Create a Firebase project`,worked:`You land on a page with your project's name across the top.`,children:(0,s.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,s.jsxs)(`li`,{children:[`Open`,` `,(0,s.jsx)(`a`,{href:`https://console.firebase.google.com`,target:`_blank`,rel:`noopener noreferrer`,className:`text-accent underline underline-offset-2 font-semibold hover:text-accent-deep transition-colors`,children:`console.firebase.google.com`}),` `,`and click `,(0,s.jsx)(`strong`,{children:`Add project`}),`. Sign in with your Google account if it asks.`]}),(0,s.jsxs)(`li`,{children:[`Type any name you like and click `,(0,s.jsx)(`strong`,{children:`Continue`}),`.`]}),(0,s.jsxs)(`li`,{children:[`If it offers `,(0,s.jsx)(`strong`,{children:`Enable Gemini in Firebase`}),`, switch it off.`]}),(0,s.jsxs)(`li`,{children:[`Switch off `,(0,s.jsx)(`strong`,{children:`Enable Google Analytics for this project`}),`.`]}),(0,s.jsxs)(`li`,{children:[`Click `,(0,s.jsx)(`strong`,{children:`Create project`}),`, wait, then click `,(0,s.jsx)(`strong`,{children:`Continue`}),`.`]})]})}),(0,s.jsx)(Hi,{number:2,title:`Add a web app and copy the six values`,worked:`Six values are on screen under your app's nickname. Leave this tab open — the next step needs them.`,children:(0,s.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,s.jsxs)(`li`,{children:[`On that page click `,(0,s.jsx)(`strong`,{children:`+ Add app`}),` under your project's name, then pick the `,(0,s.jsx)(`strong`,{children:`</> Web`}),` icon.`]}),(0,s.jsxs)(`li`,{children:[`Give it any nickname (`,(0,s.jsx)(`span`,{className:`text-accent`,children:`MyApp`}),` is fine). Leave `,(0,s.jsx)(`strong`,{children:`Firebase Hosting`}),` unticked.`]}),(0,s.jsxs)(`li`,{children:[`Click `,(0,s.jsx)(`strong`,{children:`Register app`}),`.`]}),(0,s.jsx)(`li`,{children:`Firebase now shows six values on screen, each with a label beside it — apiKey, authDomain, projectId, storageBucket, messagingSenderId and appId. You will copy them one at a time in the next step, so keep this tab open.`})]})}),(0,s.jsxs)(Hi,{number:3,title:`Paste the six values and your email into Secrets`,worked:`Seven secrets are listed in the Secrets tab, with the names spelled exactly as above.`,children:[(0,s.jsxs)(`p`,{className:`text-foreground/80`,children:[`In Google AI Studio, open the `,(0,s.jsx)(`strong`,{children:`Secrets`}),` tab beside your app. For each row below: click `,(0,s.jsx)(`strong`,{children:`Add secret`}),`, copy the name here, paste it as the name, then paste the matching value from your Firebase tab. The names have to match letter for letter — use the Copy name button and don't retype them.`]}),(0,s.jsx)(`p`,{className:`text-foreground/80`,children:`The last row is not from Firebase: its value is the email address you will sign in with. That is what makes you the owner of this app. Several people? Separate their addresses with commas.`}),(0,s.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl overflow-hidden bg-background`,children:[ji.map(({key:e,shownAs:t})=>(0,s.jsx)(Vi,{name:e,shownAs:t},e)),(0,s.jsx)(Vi,{name:`VITE_ADMIN_EMAILS`,hint:`the email you will sign in with`})]})]}),(0,s.jsx)(Hi,{number:4,title:`Turn on sign-in`,worked:`Email/Password shows as Enabled, and your app's address is in the Authorized domains list.`,children:(0,s.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,s.jsxs)(`li`,{children:[`In the Firebase menu on the left, open `,(0,s.jsx)(`strong`,{children:`Authentication`}),` and click `,(0,s.jsx)(`strong`,{children:`Get started`}),`.`]}),(0,s.jsxs)(`li`,{children:[`Open the `,(0,s.jsx)(`strong`,{children:`Sign-in method`}),` tab.`]}),(0,s.jsxs)(`li`,{children:[`Click `,(0,s.jsx)(`strong`,{children:`Email/Password`}),`, switch on the first toggle and `,(0,s.jsx)(`strong`,{children:`Save`}),`. (Leave email link off.)`]}),(0,s.jsxs)(`li`,{children:[`If you also want the `,(0,s.jsx)(`strong`,{children:`Sign in with Google`}),` button to work, click `,(0,s.jsx)(`strong`,{children:`Google`}),`, switch it on, pick your own address as the support email, and `,(0,s.jsx)(`strong`,{children:`Save`}),`.`]}),(0,s.jsxs)(`li`,{children:[`Open the `,(0,s.jsx)(`strong`,{children:`Settings`}),` tab, then `,(0,s.jsx)(`strong`,{children:`Authorized domains`}),`. Your app has to be listed here or nobody can sign in.`]}),(0,s.jsxs)(`li`,{children:[(0,s.jsx)(`strong`,{children:`To get your app's address:`}),` in AI Studio, right-click any link in your app's own menu and choose `,(0,s.jsx)(`strong`,{children:`Copy link address`}),`. Back in Firebase click`,` `,(0,s.jsx)(`strong`,{children:`Add domain`}),`, paste it, and save. It will look something like ais-dev-…run.app — that is the right thing.`]})]})}),(0,s.jsxs)(Hi,{number:5,title:`Create the database and publish its rules`,worked:`The Rules tab shows your text with today's date next to it, and no red error.`,children:[(0,s.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80 mb-4`,children:[(0,s.jsxs)(`li`,{children:[`In the Firebase menu, open `,(0,s.jsx)(`strong`,{children:`Firestore Database`}),` and click `,(0,s.jsx)(`strong`,{children:`Create database`}),`.`]}),(0,s.jsxs)(`li`,{children:[`Pick `,(0,s.jsx)(`strong`,{children:`Standard edition`}),` if asked, choose the location closest to your people, start in `,(0,s.jsx)(`strong`,{children:`Production mode`}),`, and click Continue.`]}),(0,s.jsx)(`li`,{children:`Check that the box below shows the email you sign in with.`}),(0,s.jsxs)(`li`,{children:[`Click `,(0,s.jsx)(`strong`,{children:`Copy the rules`}),`, then in Firebase open the `,(0,s.jsx)(`strong`,{children:`Rules`}),` tab, select everything that is there, paste over it, and click `,(0,s.jsx)(`strong`,{children:`Publish`}),`.`]})]}),(0,s.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl p-4 md:p-5 mb-2`,children:[(0,s.jsx)(`p`,{className:`text-[13px] font-bold text-foreground mb-1.5`,children:`Who runs this app?`}),a.length>0?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(`p`,{className:`text-[13px] text-foreground/60 leading-[1.6]`,children:[`Read from your `,(0,s.jsx)(`strong`,{children:`VITE_ADMIN_EMAILS`}),` secret and written into the rules you copy below. It is what makes you the owner the first time you register.`]}),(0,s.jsx)(`p`,{"data-admin-emails":!0,className:`mt-2.5 text-[14px] font-bold text-foreground break-all`,children:a.join(`, `)})]}):(0,s.jsxs)(`p`,{className:`text-[13px] text-amber-500 font-medium leading-[1.6]`,children:[`The app cannot see a `,(0,s.jsx)(`strong`,{children:`VITE_ADMIN_EMAILS`}),` secret yet. Go back to step 3, add it with the email you sign in with, then reload this page — the rules below will carry your address once it is there.`]}),o.length>0&&(0,s.jsxs)(`p`,{className:`mt-2.5 text-[12px] font-medium text-amber-500`,children:[`That does not look like an email address: `,o.join(`, `),`. Fix the secret in step 3 and reload this page.`]}),c&&(0,s.jsxs)(`p`,{className:`mt-2.5 text-[12px] font-medium text-emerald-500 flex items-center gap-1.5`,children:[(0,s.jsx)(t._t,{className:`w-3.5 h-3.5 shrink-0`}),`Written into the rules below.`]})]}),c&&(0,s.jsx)(Bi,{code:l,label:`Copy the rules`})]}),(0,s.jsxs)(Hi,{number:6,title:`Create storage and publish its rules`,worked:`The Storage Rules tab shows your text with today's date next to it, and no red error.`,children:[(0,s.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80 mb-4`,children:[(0,s.jsxs)(`li`,{children:[`In the Firebase menu, open `,(0,s.jsx)(`strong`,{children:`Storage`}),`. Google asks you to upgrade the project first: click `,(0,s.jsx)(`strong`,{children:`Upgrade project`}),` and pick the pay-as-you-go`,` `,(0,s.jsx)(`strong`,{children:`Blaze plan`}),`. Profile photos and attachments cost about $0.03 per gigabyte a month, so this is cents. Set a budget you are comfortable with (say $20), link a billing account, and continue.`]}),(0,s.jsxs)(`li`,{children:[`Click `,(0,s.jsx)(`strong`,{children:`Get started`}),`, choose a no-cost location, start in `,(0,s.jsx)(`strong`,{children:`Production mode`}),`, and click `,(0,s.jsx)(`strong`,{children:`Create`}),`.`]}),(0,s.jsx)(`li`,{children:`Once it exists, Firebase shows the storage address at the top (something like your-project.firebasestorage.app). If it is not exactly what you pasted into the storage secret in step 3, open Secrets and correct that one now.`}),(0,s.jsxs)(`li`,{children:[`Open the `,(0,s.jsx)(`strong`,{children:`Rules`}),` tab, select everything that is there, paste these over it, and click `,(0,s.jsx)(`strong`,{children:`Publish`}),`.`]})]}),(0,s.jsx)(Bi,{code:Ii,label:`Copy the storage rules`})]})]}),(0,s.jsx)(`div`,{className:`mt-8 relative z-10`,children:(0,s.jsx)(ke,{description:`Reload the app once you have added the secrets. If it still asks you to set up, hand this to your assistant.`,prompt:`My Firebase keys are in the Secrets tab — can you check the app connects?`})})]})})]})}function Wi(){let{user:e}=A(),n=(e?.displayName||e?.email?.split(`@`)[0]||`there`).split(` `)[0],r=n.charAt(0).toUpperCase()+n.slice(1);return(0,s.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,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,s.jsxs)(`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:[`Welcome back, `,r,`.`]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/dashboard`]})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-4 flex-1 min-h-[500px]`,children:[(0,s.jsx)(`div`,{className:`flex justify-start`,children:(0,s.jsx)(W,{})}),(0,s.jsxs)(`div`,{className:`w-full flex-1 glass-panel rounded-3xl p-8 md:p-12 flex items-center justify-center relative overflow-hidden border border-[var(--panel-border)] shadow-2xl bg-[var(--panel-bg)]`,children:[(0,s.jsx)(`div`,{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-64 h-64 bg-accent/10 blur-[100px] rounded-full pointer-events-none`}),(0,s.jsx)(t.s,{mode:`wait`,children:(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},transition:{duration:.3},className:`text-center z-10`,children:[(0,s.jsx)(`div`,{className:`w-16 h-16 rounded-3xl bg-accent/10 border border-accent/20 flex items-center justify-center text-accent mx-auto mb-6 shadow-inner`,children:(0,s.jsx)(t.it,{className:`w-6 h-6`})}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground mb-2`,children:`No data added here yet`}),(0,s.jsx)(`p`,{className:`text-foreground/40 font-medium`,children:`Keep moving forward, your data will appear here.`})]})})]})]})]})}var Gi=()=>(0,s.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center min-h-[60vh] z-10 animate-in fade-in duration-500`,children:[(0,s.jsx)(`div`,{className:`w-12 h-12 rounded-xl glass-panel border border-[var(--panel-border)] flex items-center justify-center mb-6 shadow-xl`,children:(0,s.jsx)(t.it,{className:`w-6 h-6 text-accent animate-pulse`})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-3 glass-panel px-5 py-2.5 rounded-full border border-[var(--panel-border)]`,children:[(0,s.jsx)(`div`,{className:`w-4 h-4 border-2 border-accent border-t-transparent rounded-full animate-spin`}),(0,s.jsx)(`span`,{className:`text-[13px] font-bold tracking-widest uppercase text-foreground/70`,children:`Connecting`})]})]});function Ki({level:e,children:t}){let{user:n,userRole:r,loading:i,userInactive:a,signOut:o,roleResolved:l}=A(),u=(0,c.useLocation)();return i||!l?(0,s.jsx)(Gi,{}):n?a?(0,s.jsx)(hi,{tone:`red`,title:`Access Denied`,message:`You don't have access to this app. Please contact the administrator.`,action:(0,s.jsx)(`button`,{onClick:()=>o(),className:gi,children:`Sign Out`})}):n.emailVerified?e===`admin`&&!x(r)?(0,s.jsx)(vi,{}):e===`internal`&&!S(r)?(0,s.jsx)(_i,{}):(0,s.jsx)(s.Fragment,{children:t}):(0,s.jsx)(c.Navigate,{to:`/verify`}):(0,s.jsx)(c.Navigate,{to:`/login?from=${encodeURIComponent(u.pathname)}`})}var qi=({children:e})=>(0,s.jsx)(Ki,{level:`signed-in`,children:e}),Ji=({children:e})=>(0,s.jsx)(Ki,{level:`admin`,children:e});function Yi({children:e}){let{user:t,loading:n,roleResolved:r}=A(),[i]=(0,c.useSearchParams)();return n||!r?(0,s.jsx)(Gi,{}):t&&t.emailVerified?(0,s.jsx)(c.Navigate,{to:i.get(`from`)||`/dashboard`,replace:!0}):(0,s.jsx)(s.Fragment,{children:e})}function Xi({children:e}){let{user:t,loading:n,roleResolved:r}=A();return n||!r?(0,s.jsx)(Gi,{}):t?t.emailVerified?(0,s.jsx)(c.Navigate,{to:`/dashboard`}):(0,s.jsx)(s.Fragment,{children:e}):(0,s.jsx)(c.Navigate,{to:`/`})}function Zi(){return(0,s.jsxs)(`div`,{className:`fixed top-0 left-0 w-full h-full pointer-events-none -z-0 overflow-hidden`,children:[(0,s.jsx)(t.o.div,{animate:{scale:[1,1.1,1],opacity:[.6,1,.6]},transition:{duration:12,repeat:1/0,ease:`easeInOut`},className:`absolute -top-[30%] md:-top-[400px] -right-[10%] md:-right-[200px] w-[500px] md:w-[800px] h-[500px] md:h-[800px] rounded-full bg-decorator-1 blur-[80px] md:blur-[120px]`}),(0,s.jsx)(t.o.div,{animate:{scale:[1,1.2,1],opacity:[.5,.9,.5]},transition:{duration:18,repeat:1/0,ease:`easeInOut`,delay:2},className:`absolute -bottom-[20%] md:-bottom-[300px] -left-[10%] md:-left-[100px] w-[400px] md:w-[600px] h-[400px] md:h-[600px] rounded-full bg-decorator-2 blur-[60px] md:blur-[100px]`})]})}function Qi(){let e=t.Mt().components?.Home||te;return(0,s.jsx)(k,{children:(0,s.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,s.jsx)(z,{}),(0,s.jsxs)(c.Routes,{children:[(0,s.jsx)(c.Route,{path:`/`,element:(0,s.jsx)(Yi,{children:(0,s.jsx)(e,{})})}),(0,s.jsx)(c.Route,{path:`/register`,element:(0,s.jsx)(Yi,{children:(0,s.jsx)(B,{})})}),(0,s.jsx)(c.Route,{path:`/login`,element:(0,s.jsx)(Yi,{children:(0,s.jsx)(ne,{})})}),(0,s.jsx)(c.Route,{path:`/reset-password`,element:(0,s.jsx)(Yi,{children:(0,s.jsx)(K,{})})}),(0,s.jsx)(c.Route,{path:`/verify`,element:(0,s.jsx)(Xi,{children:(0,s.jsx)(V,{})})}),(0,s.jsx)(c.Route,{path:`/guide`,element:(0,s.jsx)(it,{})}),(0,s.jsx)(c.Route,{path:`/templates`,element:(0,s.jsx)(qe,{})}),(0,s.jsx)(c.Route,{path:`/templates/inline_form`,element:(0,s.jsx)(at,{})}),(0,s.jsx)(c.Route,{path:`/templates/popup_form`,element:(0,s.jsx)(ot,{})}),(0,s.jsx)(c.Route,{path:`/templates/confirmation`,element:(0,s.jsx)(st,{})}),(0,s.jsx)(c.Route,{path:`/templates/board`,element:(0,s.jsx)(lt,{})}),(0,s.jsx)(c.Route,{path:`/templates/table`,element:(0,s.jsx)(zn,{})}),(0,s.jsx)(c.Route,{path:`/templates/calendar`,element:(0,s.jsx)(Hn,{})}),(0,s.jsx)(c.Route,{path:`/templates/drive`,element:(0,s.jsx)(He,{})}),(0,s.jsx)(c.Route,{path:`/users`,element:(0,s.jsx)(Ji,{children:(0,s.jsx)(Y,{})})}),(0,s.jsx)(c.Route,{path:`/users/:id`,element:(0,s.jsx)(Ji,{children:(0,s.jsx)(Y,{})})}),(0,s.jsx)(c.Route,{path:`/inbox`,element:(0,s.jsx)(Ji,{children:(0,s.jsx)(Be,{})})}),(0,s.jsx)(c.Route,{path:`/submissions`,element:(0,s.jsx)(c.Navigate,{to:`/inbox`,replace:!0})}),(0,s.jsx)(c.Route,{path:`/requests`,element:(0,s.jsx)(c.Navigate,{to:`/inbox`,replace:!0})}),(0,s.jsx)(c.Route,{path:`/assets`,element:(0,s.jsx)(Ji,{children:(0,s.jsx)(Ke,{})})}),(0,s.jsx)(c.Route,{path:`/drive/*`,element:(0,s.jsx)(c.Navigate,{to:`/assets`,replace:!0})}),(0,s.jsx)(c.Route,{path:`/theme`,element:(0,s.jsx)(Ji,{children:(0,s.jsx)(pr,{})})}),(0,s.jsx)(c.Route,{path:`/pages/*`,element:(0,s.jsx)(Ji,{children:(0,s.jsx)(Wr,{})})}),(0,s.jsx)(c.Route,{path:`/forms/*`,element:(0,s.jsx)(Ji,{children:(0,s.jsx)(ri,{})})}),(0,s.jsx)(c.Route,{path:`/settings`,element:(0,s.jsx)(c.Navigate,{to:`/pages`,replace:!0})}),(0,s.jsx)(c.Route,{path:`/profile`,element:(0,s.jsx)(qi,{children:(0,s.jsx)(G,{})})}),(0,s.jsx)(c.Route,{path:`/dashboard`,element:(0,s.jsx)(qi,{children:(0,s.jsx)(Wi,{})})}),(0,s.jsx)(c.Route,{path:`/setup`,element:(0,s.jsx)(Ui,{})}),(0,s.jsx)(c.Route,{path:`*`,element:(0,s.jsx)(bi,{})})]}),(0,s.jsx)(Zi,{})]})})}function $i(){return(0,s.jsx)(c.BrowserRouter,{children:(0,s.jsx)(ea,{})})}function ea(){let e=t.Mt();return e.firebaseConfig&&e.firebaseConfig.apiKey&&e.firebaseConfig.apiKey.trim()!==``&&e.firebaseConfig.projectId&&e.firebaseConfig.projectId.trim()!==``||Fi()?(0,s.jsx)(Qi,{}):(0,s.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,s.jsx)(z,{standalone:!0}),(0,s.jsx)(Ui,{standalone:!0}),(0,s.jsx)(Zi,{})]})}function ta(e){let n=e.firebaseConfig;return n&&n.apiKey&&n.apiKey.trim()!==``&&n.projectId&&n.projectId.trim()!==``&&t.Ft(n),(0,s.jsx)(t.jt,{config:{firebaseConfig:e.firebaseConfig,adminEmails:e.adminEmails,basename:e.basename,onAuthChange:e.onAuthChange,themeConfig:e.themeConfig,components:e.components,customRoutes:e.customRoutes,microcomponents:e.microcomponents,defaultConfigs:e.defaultConfigs},children:(0,s.jsx)(t.kt,{children:(0,s.jsx)(`div`,{className:`firebase-os flex-1 flex flex-col min-h-screen`,style:{background:`var(--bg-gradient)`,color:`var(--fg-color)`},children:(0,s.jsx)($i,{})})})})}exports.AdminNotifications=N,exports.Button=t.r,exports.ConfirmModal=re,exports.ContactPopup=t.t,exports.CustomSelect=t.n,exports.DashboardNav=W,exports.FirebaseOS=ta,exports.Input=t.i,exports.Navbar=z,exports.PhoneInputField=n.t,Object.defineProperty(exports,`auth`,{enumerable:!0,get:function(){return t.Nt}}),Object.defineProperty(exports,`db`,{enumerable:!0,get:function(){return t.Pt}}),Object.defineProperty(exports,`storage`,{enumerable:!0,get:function(){return t.It}}),exports.useAuth=A,exports.useConfig=t.Mt,exports.useTheme=t.At;
|