your-ai-workflow-firebase-os 1.2.37 → 1.2.38

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.
@@ -1,5 +1,5 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-DYteiM-1.cjs`),t=require(`./ContactPopup-DY0VLjCP.cjs`),n=require(`./PhoneInputField-CQ7ylxOC.cjs`);let r=require(`react`);r=e.i(r,1);let i=require(`firebase/firestore`),a=require(`firebase/auth`),o=require(`firebase/storage`),s=require(`react/jsx-runtime`),c=require(`react-router-dom`),l=require(`react-dom`);var u=Object.assign({"./contactForm.config.ts":t.Vt,"./supportForm.config.ts":t.zt}),d={};for(let e in u){let t=u[e];if(!t)continue;let n=null;for(let e in t)if(e.endsWith(`FormConfig`)||e.endsWith(`Config`)){n=t[e];break}if(!n&&t?.default&&(n=t.default),!n)continue;let r=e.replace(`./`,``).replace(`.config.ts`,``).replace(/Form$/,``).toLowerCase(),i={...n,systemName:n.systemName||r};d[r]=i,i.systemName&&(d[i.systemName]=i,d[i.systemName.toLowerCase()]=i)}if(typeof window<`u`){let e=window.__FBOS_FORMS__||{};window.__FBOS_FORMS__={...d,...e}}var f=Object.assign({}),p=Object.assign({}),m={};for(let e in f){let t=f[e];if(!t)continue;let n=null;for(let e in t)if(e.endsWith(`TabConfig`)||e.endsWith(`Config`)){n=t[e];break}if(!n&&t?.default&&(n=t.default),!n)continue;let r=e.replace(`./`,``).replace(`.config.ts`,``).replace(/Tab$/,``).toLowerCase(),i={config:{...n,pageId:n.pageId||r,tabName:n.tabName||n.title||r},isPublic:!1};m[r]=i,i.config.pageId&&(m[i.config.pageId]=i,m[i.config.pageId.toLowerCase()]=i)}for(let e in p){let t=p[e];if(!t)continue;let n=null;for(let e in t)if(e.endsWith(`PageConfig`)||e.endsWith(`Config`)){n=t[e];break}if(!n&&t?.default&&(n=t.default),!n)continue;let r=e.replace(`./`,``).replace(`.config.ts`,``).replace(/Page$/,``).toLowerCase(),i={config:{...n,pageId:n.pageId||r,pageName:n.pageName||n.title||r},isPublic:!0};m[r]=i,i.config.pageId&&(m[i.config.pageId]=i,m[i.config.pageId.toLowerCase()]=i)}if(typeof window<`u`){let e=window.__FBOS_PAGES__||{};window.__FBOS_PAGES__={...m,...e}}var h=[`free`,`internal`,`admin`],g=[`user`,`internal`,`admin`],_={free:`Free`,internal:`Internal`,admin:`Admin`},v={free:`Pages for anyone, plus their own pages. Your team’s pages stay hidden.`,internal:`Everything a signed-in user sees, plus every page for your team.`,admin:`Full access, including Users, Pages, Forms, Inbox, Theme and Assets.`};function y(e){return e===`admin`?`admin`:e===`internal`?`internal`:`free`}function b(e){return e===`free`?`user`:e}var x=e=>y(e)===`admin`,S=e=>y(e)!==`free`;function C(e){return e===`admin`?`admin`:e===`public`?`public`:e===`internal`||e===`shared`?`internal`:`user`}function w(e){let t=C(e);return t===`public`?`user`:t}function T(e,t){switch(C(t)){case`public`:return!0;case`admin`:return x(e);case`internal`:return S(e);case`user`:return!0}}function E(e,t=!0){if(!t)return`guest`;let n=y(e);return n===`free`?`user`:n}function D(e){switch(C(e)){case`public`:return[`admin`,`internal`,`user`,`guest`];case`admin`:return[`admin`];case`internal`:return[`admin`,`internal`];case`user`:return[`admin`,`internal`,`user`]}}var O=(0,r.createContext)({user:null,userRole:null,accessLevel:`free`,isInternal:!1,isAdmin:!1,loading:!0,signOut:async()=>{},registerUser:async()=>{},refreshUser:async()=>{},userInactive:!1,roleResolved:!1,activeOrg:null,activeWorkspace:null,checkOrg:async()=>{},workspaceAccess:{},userWorkspaces:[],switchWorkspace:async()=>{},createWorkspace:async()=>{},createOrg:async()=>{}});function k({children:e}){let n=t.Mt(),[o,c]=(0,r.useState)(null),[l,u]=(0,r.useState)(null),[d,f]=(0,r.useState)(!1),[p,m]=(0,r.useState)(!0),[h,g]=(0,r.useState)(!1),_=r.default.useRef(null),v=r.default.useRef(null),b=r.default.useMemo(()=>{let e=``;try{e={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}?.VITE_ADMIN_EMAILS||``}catch{}return(n.adminEmails||(e?e.split(`,`):[])).map(e=>e.trim().toLowerCase()).filter(Boolean)},[n.adminEmails]),C=b.join(`,`),w=r.default.useRef(b);(0,r.useEffect)(()=>{w.current=b},[b]);let T=e=>!!e&&w.current.includes(e.toLowerCase()),E=e=>(0,i.updateDoc)((0,i.doc)(t.Pt,`user_profiles`,e),{role:`admin`}).catch(e=>console.error(`Error auto-setting admin role:`,e));return(0,r.useEffect)(()=>{let e;if(!t.Nt){m(!1),g(!0);return}(0,a.getRedirectResult)(t.Nt).catch(()=>{});let n=(0,a.onAuthStateChanged)(t.Nt,async n=>{if(n?.uid===v.current&&h){c(n);return}if(v.current=n?.uid||null,n){let r=localStorage.getItem(`fbos_role_${n.uid}`);r&&(u(r),g(!0),m(!1)),console.log(`[AuthContext] 1. onAuthStateChanged fired for user:`,n.uid),c(n);try{let r=(0,i.doc)(t.Pt,`user_profiles`,n.uid),a=(await(0,i.getDoc)(r)).data()||{};(0,i.setDoc)(r,{uid:n.uid,email:n.email,displayName:n.displayName||a.displayName||``,lastLoginAt:new Date().toISOString(),createdAt:a.createdAt||new Date().toISOString()},{merge:!0}).catch(e=>console.error(`Failed to sync profile:`,e)),e&&e(),e=(0,i.onSnapshot)(r,e=>{if(e.exists()){let r=e.data(),i=r.role||`user`;!r.role&&t.Nt.currentUser?.emailVerified&&T(n.email)&&(i=`admin`,E(n.uid)),_.current===null&&(_.current=i),u(i),localStorage.setItem(`fbos_role_${n.uid}`,i),f(r.inactive===!0)}g(!0),m(!1)},e=>{console.warn(`[AuthContext] user_profiles snapshot error (safe to ignore during auth transition):`,e),g(!0),m(!1)})}catch(e){console.error(`[AuthContext] ERROR in auth resolution:`,e),g(!0),m(!1)}}else console.log(`[AuthContext] No user currently signed in.`),c(null),u(null),f(!1),g(!0),m(!1),_.current=null,e&&e()});return()=>{n(),e&&e()}},[]),(0,r.useEffect)(()=>{if(!o?.emailVerified||l===`admin`||!T(o.email))return;let e=!1;return(0,i.getDoc)((0,i.doc)(t.Pt,`user_profiles`,o.uid)).then(t=>{!e&&t.exists()&&!t.data().role&&E(o.uid)}).catch(()=>{}),()=>{e=!0}},[o?.uid,o?.emailVerified,l,C]),(0,s.jsx)(O.Provider,{value:{user:o,userRole:l,accessLevel:y(l),isInternal:S(l),isAdmin:x(l),loading:p,signOut:async()=>{await(0,a.signOut)(t.Nt),c(null)},registerUser:async(e,n,r,o)=>{let{createUserWithEmailAndPassword:s}=await import(`firebase/auth`),{user:c}=await s(t.Nt,e,n),l=`${r} ${o}`.trim();await(0,a.updateProfile)(c,{displayName:l});try{await c.getIdToken(!0),await(0,i.setDoc)((0,i.doc)(t.Pt,`user_profiles`,c.uid),{uid:c.uid,email:c.email,displayName:l,createdAt:new Date().toISOString()},{merge:!0})}catch(e){console.warn(`Could not write public profile on registration.`,e)}await(0,a.sendEmailVerification)(c)},refreshUser:async()=>{t.Nt.currentUser&&(await t.Nt.currentUser.reload(),c(Object.assign(Object.create(t.Nt.currentUser),{photoURL:t.Nt.currentUser.photoURL,displayName:t.Nt.currentUser.displayName,email:t.Nt.currentUser.email,emailVerified:t.Nt.currentUser.emailVerified})))},userInactive:d,roleResolved:h},children:e})}var A=()=>(0,r.useContext)(O);function j(){return(typeof window<`u`?window.__FBOS_PAGES__:null)||{}}function M(e=j()){let t=new Set,n=[];for(let[r,i]of Object.entries(e))!i||t.has(i)||(t.add(i),n.push([r,i]));return n}function N(){let[e,n]=(0,r.useState)(!1),[a,o]=(0,r.useState)([]),l=(0,r.useRef)(null),u=(0,c.useNavigate)();(0,r.useEffect)(()=>{function e(e){l.current&&!l.current.contains(e.target)&&n(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let d=(0,r.useRef)({users:[],submissions:[],requests:[]}),f=(e,t)=>{d.current[e]=t;let n=[...d.current.users,...d.current.submissions,...d.current.requests];n.sort((e,t)=>{let n=e.time?.toDate?e.time.toDate().getTime():new Date(e.time).getTime();return((t.time?.toDate?t.time.toDate().getTime():new Date(t.time).getTime())||0)-(n||0)}),o(n.slice(0,8))};(0,r.useEffect)(()=>{let e=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,`user_profiles`),(0,i.orderBy)(`createdAt`,`desc`),(0,i.limit)(5)),e=>{f(`users`,e.docs.map(e=>{let t=e.data();return{id:`u_${e.id}`,type:`user`,title:`New user registered`,subtitle:t.email||`Unknown`,time:t.createdAt}}))}),n=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,`user_submissions`),(0,i.orderBy)(`submittedAt`,`desc`),(0,i.limit)(5)),e=>{f(`submissions`,e.docs.map(e=>{let t=e.data();return{id:`s_${e.id}`,type:`submission`,title:`New form submission`,subtitle:t.name||t.email||`Anonymous`,time:t.submittedAt}}))}),r=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,`user_requests`),(0,i.orderBy)(`submittedAt`,`desc`),(0,i.limit)(5)),e=>{f(`requests`,e.docs.map(e=>{let t=e.data();return{id:`r_${e.id}`,type:`request`,title:`New support request`,subtitle:t.name||t.submitterName||t.contactEmail||t.email||`Anonymous`,time:t.submittedAt}}))});return()=>{e(),n(),r()}},[]);let[p,m]=(0,r.useState)(()=>typeof window<`u`?parseInt(localStorage.getItem(`admin_notifications_last_read`)||`0`,10):0),h=()=>{let t=!e;if(n(t),t){let e=Date.now();m(e),typeof window<`u`&&localStorage.setItem(`admin_notifications_last_read`,e.toString())}},g=a.some(e=>{if(!e.time)return!0;let t=e.time?.toDate?e.time.toDate().getTime():new Date(e.time).getTime();return t>p||isNaN(t)}),_=e=>{n(!1),u(e===`user`?`/users`:e===`submission`?`/submissions`:`/requests`)},v=e=>{if(!e)return``;let t=e.toDate?e.toDate():new Date(e);return new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`,hour:`numeric`,minute:`numeric`}).format(t)};return(0,s.jsxs)(`div`,{className:`relative z-50 flex-shrink-0 mr-1 md:mr-2`,ref:l,children:[(0,s.jsxs)(`button`,{onClick:h,className:`p-2 rounded-xl glass-panel transition-all border border-transparent relative text-notification-icon hover:bg-foreground/5 hover:border-[var(--panel-border)]`,"aria-label":`Admin Notifications`,children:[(0,s.jsx)(t.xt,{className:`w-4 h-4 md:w-5 md:h-5`}),g&&(0,s.jsx)(`span`,{className:`absolute top-1.5 right-1.5 w-2 h-2 bg-red-500 rounded-full animate-pulse`})]}),(0,s.jsx)(t.s,{children:e&&(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:-5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98,y:-5},className:`absolute top-full mt-2 right-[-60px] md:right-0 w-[320px] md:w-[400px] glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col origin-top-right overflow-hidden`,children:[(0,s.jsxs)(`div`,{className:`px-4 border-b border-[var(--panel-border)]/50 pb-3 pt-4 flex items-center justify-between`,children:[(0,s.jsx)(`span`,{className:`font-bold text-[14px] text-foreground tracking-wide`,children:`Notifications`}),(0,s.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest text-accent bg-accent/10 px-2 py-0.5 rounded-md`,children:`Admin`})]}),(0,s.jsx)(`div`,{className:`max-h-[350px] overflow-y-auto w-full p-2 flex flex-col gap-1`,children:a.length===0?(0,s.jsx)(`div`,{className:`p-6 text-center text-foreground/40 text-[13px] font-medium`,children:`No recent activity.`}):a.map(e=>(0,s.jsxs)(`button`,{onClick:()=>_(e.type),className:`w-full flex items-start gap-3 p-3 rounded-xl hover:bg-foreground/5 transition-all text-left group border border-transparent hover:border-[var(--panel-border)]`,children:[(0,s.jsx)(`div`,{className:`mt-0.5 w-8 h-8 rounded-full flex items-center justify-center shrink-0 bg-foreground/5 text-notification-icon`,children:e.type===`user`?(0,s.jsx)(t.m,{className:`w-4 h-4`}):e.type===`submission`?(0,s.jsx)(t.P,{className:`w-4 h-4`}):(0,s.jsx)(t.lt,{className:`w-4 h-4`})}),(0,s.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0 pr-2`,children:[(0,s.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground group-hover:text-accent transition-colors truncate`,children:e.title}),(0,s.jsx)(`span`,{className:`text-[12px] text-foreground/60 truncate`,children:e.subtitle}),(0,s.jsx)(`span`,{className:`text-[10px] font-mono tracking-wide text-foreground/40 mt-1`,children:v(e.time)})]})]},e.id))})]})})]})}var P=[{id:`guide`,hidden:!1},{id:`contact`,hidden:!1},{id:`templates`,hidden:!1},{id:`setup`,hidden:!1}],F={drive:`assets`,submissions:`inbox`,requests:`inbox`},I=e=>{let t=(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden}).map(e=>({...e,id:F[e.id]||e.id}));return t.filter((e,n)=>t.findIndex(t=>t.id===e.id)===n)},L=[{id:`pages`,hidden:!1},{id:`forms`,hidden:!1},{id:`inbox`,hidden:!1},{id:`users`,hidden:!1},{id:`theme`,hidden:!1},{id:`assets`,hidden:!1}],R={route:`/support`,template:`popup_form`,form:`support`,tabName:`Support`,iconName:``},ee={guide:{label:`Guide`,path:`/guide`},templates:{label:`Templates`,path:`/templates`},setup:{label:`Setup`,path:`/setup`},contact:{label:`Contact`,path:`/contact`}};function z({customMenu:e,standalone:n}){let{user:a,userRole:o,signOut:l}=A(),u=x(o),d=y(o),f=d===`free`?`Free User`:_[d],p=(0,c.useNavigate)(),[m,h]=(0,r.useState)(!1),[g,v]=(0,r.useState)(null),[b,S]=(0,r.useState)(!1),[C,w]=(0,r.useState)(!1),[T,E]=(0,r.useState)(!1),D=a?.displayName||a?.email?.split(`@`)[0]||`User`,O=D.charAt(0).toUpperCase()+D.slice(1),{theme:k,toggleTheme:j,activeConfig:F}=t.At(),L=async()=>{await l(),p(`/`),h(!1)},[z,B]=(0,r.useState)({...ee}),[V,te]=(0,r.useState)(P);(0,r.useEffect)(()=>{if(!t.Pt)return;let e=(0,i.onSnapshot)((0,i.collection)(t.Pt,`sys_pages`),e=>{let t={...ee};for(let[e,n]of M()){if(!n.isPublic)continue;let r=n.config||{};if(r.enabled===!1)continue;let i=r.route?r.route.startsWith(`/`)?r.route:`/`+r.route:`/`+e;t[e]={label:r.pageName||r.pageTitle||r.title||e,path:i}}e.forEach(e=>{let n=e.data();if(n.enabled===!1)return;let r=n.pageName||n.title||ee[e.id]?.label||e.id,i=n.route||(e.id===`home`?`/`:`/`+e.id);t[e.id]={label:r,path:i}}),B(t)},e=>{console.warn(`sys_pages snapshot error (safe to ignore during auth transition):`,e)}),n=(0,i.onSnapshot)((0,i.doc)(t.Pt,`sys_configs`,`page_order`),e=>{te(e.exists()&&Array.isArray(e.data().order)?I(e.data().order):P)},e=>{console.warn(`page_order snapshot error (safe to ignore during auth transition):`,e)}),r=(0,i.onSnapshot)((0,i.doc)(t.Pt,`sys_tabs`,`support`),e=>{e.exists()&&e.data().pageName&&U(e.data().pageName)},e=>{console.warn(`support snapshot error (safe to ignore during auth transition):`,e)});return()=>{e(),n(),r()}},[]);let[H,U]=(0,r.useState)(R.tabName),W=(()=>{let e=new Set(V.filter(e=>e.hidden).map(e=>e.id)),t=new Set,n=[];return V.forEach(e=>{if(e.hidden||e.id===`home`)return;let r=z[e.id];r&&(n.push({label:r.label,path:r.path}),t.add(e.id))}),Object.entries(z).forEach(([r,i])=>{!t.has(r)&&!e.has(r)&&r!==`home`&&i.path!==`/`&&i.path!==`/support`&&n.push({label:i.label,path:i.path})}),n})(),ne=e||W,G=(0,r.useRef)(null),K=(0,r.useRef)(null),[q,J]=(0,r.useState)(ne.length);(0,r.useEffect)(()=>{if(n||a)return;let e=()=>{let e=G.current,t=K.current;if(!e||!t)return;let n=e.clientWidth,r=t.querySelectorAll(`[data-measure-nav]`);if(r.length===0){J(ne.length);return}let i=0,a=!0;for(let e=0;e<r.length;e++)if(i+=r[e].offsetWidth+(e>0?28:0),i>n){a=!1;break}if(a){J(ne.length);return}let o=0,s=0;for(let e=0;e<r.length;e++){let t=r[e].offsetWidth,i=o+t+(e>0?28:0);if(i+50>n)break;o=i,s++}J(Math.max(s,1))},t=requestAnimationFrame(e);if(typeof ResizeObserver>`u`)return()=>cancelAnimationFrame(t);let r=new ResizeObserver(()=>requestAnimationFrame(e));return G.current&&r.observe(G.current),()=>{cancelAnimationFrame(t),r.disconnect()}},[ne.map(e=>e.label).join(`|`),n,a,ne.length]);let Y=ne.slice(0,q),re=ne.slice(q);return(0,s.jsxs)(`nav`,{className:`flex items-center justify-between w-full max-w-7xl mx-auto z-40 p-4 md:p-10 relative`,children:[(0,s.jsx)(`div`,{className:`flex items-center gap-2 md:gap-4 z-50`,children:(0,s.jsxs)(c.Link,{to:`/`,className:`flex items-center gap-2 md:gap-3 group cursor-pointer z-50`,children:[(0,s.jsx)(`div`,{className:`w-9 h-9 md:w-10 md:h-10 rounded-xl glass-panel flex items-center justify-center glow-hover shadow-lg transition-transform duration-500 group-hover:rotate-[360deg] group-active:scale-95 overflow-hidden`,children:F?.logoUrl?(0,s.jsx)(`img`,{src:F.logoUrl,alt:`Logo`,className:`w-full h-full object-cover`}):(0,s.jsx)(t.it,{className:`w-4 h-4 md:w-5 md:h-5 text-accent`})}),(0,s.jsx)(`span`,{className:`hidden lg:block font-bold text-[22px] tracking-tight text-gradient transition-colors duration-300 drop-shadow-sm`,children:F?.appName||``})]})}),(0,s.jsx)(t.s,{children:b&&(0,s.jsx)(t.t,{formId:`contact`,onClose:()=>S(!1)})}),(0,s.jsx)(t.s,{children:C&&(0,s.jsx)(t.t,{formId:`support`,onClose:()=>w(!1)})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 md:gap-4 z-50 relative ml-auto flex-1 justify-end`,children:[!n&&!a&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{ref:K,"aria-hidden":`true`,className:`flex items-center gap-7 whitespace-nowrap px-1`,style:{position:`fixed`,top:-9999,left:0,visibility:`hidden`,height:0,pointerEvents:`none`},children:ne.map((e,n)=>(0,s.jsxs)(`span`,{"data-measure-nav":!0,className:`text-[13px] md:text-[14px] font-bold tracking-wide flex items-center gap-1.5 shrink-0`,children:[e.label,e.submenu&&(0,s.jsx)(t.gt,{className:`w-3 h-3`})]},e.path||n))}),(0,s.jsxs)(`div`,{className:`hidden sm:flex items-center gap-7 mr-6 w-full max-w-full justify-end relative`,ref:G,children:[Y.map((e,n)=>(0,s.jsxs)(`div`,{className:`relative shrink-0`,onMouseEnter:()=>v(e.label),onMouseLeave:()=>v(null),children:[e.path?(0,s.jsxs)(c.Link,{to:e.path,className:`text-[13px] md:text-[14px] font-bold tracking-wide text-foreground/50 hover:text-accent transition-all cursor-pointer flex items-center gap-1.5`,children:[e.label,e.submenu&&(0,s.jsx)(t.gt,{className:`w-3 h-3`})]}):(0,s.jsxs)(`button`,{onClick:e.action,className:`text-[13px] md:text-[14px] font-bold tracking-wide text-foreground/50 hover:text-accent transition-all flex items-center gap-1.5`,children:[e.label,e.submenu&&(0,s.jsx)(t.gt,{className:`w-3 h-3`})]}),e.submenu&&g===e.label&&(0,s.jsx)(`div`,{className:`absolute top-[100%] left-0 pt-2 z-50`,children:(0,s.jsx)(t.o.div,{initial:{opacity:0,y:5},animate:{opacity:1,y:0},className:`min-w-[180px] max-h-[300px] overflow-y-auto styled-scrollbars bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] rounded-2xl shadow-xl flex flex-col py-2`,children:e.submenu.map((e,t)=>e.path?(0,s.jsx)(c.Link,{to:e.path,className:`px-5 py-3 text-[13px] font-medium text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors`,children:e.label},t):(0,s.jsx)(`button`,{onClick:e.action,className:`px-5 py-3 text-left w-full text-[13px] font-medium text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors`,children:e.label},t))})})]},`${e.path||`no-path`}-${n}`)),re.length>0&&(0,s.jsxs)(`div`,{className:`relative flex items-center shrink-0`,onMouseEnter:()=>h(`overflow`),children:[(0,s.jsx)(`button`,{onClick:()=>h(m===`overflow`?!1:`overflow`),className:`p-1 rounded-lg transition-colors flex items-center ${m===`overflow`?`bg-foreground/5 text-accent`:`text-foreground/50 hover:bg-foreground/5 hover:text-accent`}`,children:(0,s.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-5 h-5`,children:[(0,s.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,s.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1`}),(0,s.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1`})]})}),(0,s.jsx)(t.s,{children:m===`overflow`&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>h(!1)}),(0,s.jsx)(t.o.div,{initial:{opacity:0,y:5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:5,scale:.98},className:`absolute top-[100%] pt-1 right-0 min-w-[200px] max-h-[350px] overflow-y-auto styled-scrollbars glass-popover border border-[var(--panel-border)] rounded-2xl flex flex-col py-2 z-50 origin-top-right`,children:re.map((e,t)=>e.path?(0,s.jsx)(c.Link,{to:e.path,onClick:()=>h(!1),className:`px-5 py-3 text-[13px] font-bold tracking-wide text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors`,children:e.label},t):(0,s.jsx)(`button`,{onClick:()=>{e.action&&e.action(),h(!1)},className:`px-5 py-3 text-left w-full text-[13px] font-bold tracking-wide text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors`,children:e.label},t))})]})})]})]}),F?.showThemeToggle&&(0,s.jsx)(`button`,{onClick:j,className:`p-2 mr-2 rounded-xl glass-panel hover:bg-foreground/5 transition-all text-accent border border-[var(--panel-border)] hover:border-accent/40 shrink-0`,"aria-label":`Toggle Theme`,children:k===`dark`?(0,s.jsx)(t.x,{className:`w-4 h-4 md:w-5 md:h-5`}):(0,s.jsx)(t.M,{className:`w-4 h-4 md:w-5 md:h-5`})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(c.Link,{to:`/login`,className:`hidden sm:flex text-[14px] font-bold tracking-wide text-foreground/80 hover:text-accent transition-colors px-3 py-1.5 shrink-0`,children:`Sign In`}),(0,s.jsx)(c.Link,{to:`/register`,className:`hidden sm:flex text-[13px] md:text-[14px] font-bold tracking-wide px-4 py-1.5 md:px-5 md:py-2 rounded-xl btn-primary transition-all duration-300 hover:shadow-lg hover:-translate-y-0.5 active:scale-95 items-center justify-center ml-2`,children:`Get Started`}),(0,s.jsxs)(`div`,{className:`relative sm:hidden ml-1`,children:[(0,s.jsx)(`button`,{onClick:()=>h(m===`guest`?!1:`guest`),className:`p-2 rounded-xl glass-panel glow-hover border transition-all ${m===`guest`?`border-accent bg-foreground/5`:`border-[var(--panel-border)] hover:bg-foreground/5`}`,children:(0,s.jsx)(t.N,{className:`w-5 h-5 text-accent/80`})}),(0,s.jsx)(t.s,{children:m===`guest`&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>h(!1)}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:-10,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.95},className:`absolute top-full right-0 mt-3 w-[220px] p-2 glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col gap-1 origin-top-right`,children:[(0,s.jsxs)(c.Link,{to:`/guide`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.ut,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Guide`})]}),(0,s.jsxs)(c.Link,{to:`/templates`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.B,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Templates`})]}),(0,s.jsxs)(c.Link,{to:`/setup`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.w,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Setup`})]}),(0,s.jsxs)(c.Link,{to:`/contact`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all w-full text-left`,children:[(0,s.jsx)(t.P,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Contact`})]}),(0,s.jsxs)(`div`,{className:`pt-2 mt-1 border-t border-[var(--panel-border)]/50 flex flex-col gap-1`,children:[(0,s.jsxs)(c.Link,{to:`/login`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all w-full`,children:[(0,s.jsx)(t.F,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Sign In`})]}),(0,s.jsx)(c.Link,{to:`/register`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl btn-primary w-full shadow-lg hover:-translate-y-0.5 transition-transform text-white`,children:(0,s.jsx)(`span`,{className:`text-[14px] font-bold mx-auto`,children:`Get Started`})})]})]})]})})]})]})]}),!n&&a&&(0,s.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2 mr-1`,children:[o===`admin`&&(0,s.jsx)(N,{}),F?.showThemeToggle&&(0,s.jsx)(`button`,{onClick:j,className:`p-2 ml-1 rounded-xl glass-panel hover:bg-foreground/5 transition-all text-accent border border-[var(--panel-border)] hover:border-accent/40`,"aria-label":`Toggle Theme`,children:k===`dark`?(0,s.jsx)(t.x,{className:`w-4 h-4 md:w-5 md:h-5`}):(0,s.jsx)(t.M,{className:`w-4 h-4 md:w-5 md:h-5`})})]}),(0,s.jsxs)(`div`,{className:`relative z-50 flex items-center gap-3`,children:[(0,s.jsxs)(`div`,{className:`relative flex-shrink-0`,children:[(0,s.jsxs)(`button`,{onClick:()=>h(m===`user`?!1:`user`),className:`flex items-center gap-2 group p-1 sm:pr-2.5 rounded-full glass-panel hover:bg-foreground/5 transition-all duration-300 border ${m===`user`?`border-accent/40 bg-foreground/5`:`border-transparent hover:border-[var(--panel-border)]`}`,children:[(0,s.jsx)(`div`,{className:`w-8 h-8 md:w-9 md:h-9 rounded-full bg-accent/10 flex items-center justify-center overflow-hidden border border-[var(--panel-border)] group-hover:border-accent/30 transition-colors shrink-0 text-accent`,children:a.photoURL&&!T?(0,s.jsx)(`img`,{src:a.photoURL,alt:`Profile`,className:`w-full h-full object-cover`,onError:()=>E(!0)}):(0,s.jsx)(t.m,{className:`w-4 h-4 md:w-5 md:h-5 text-accent`})}),(0,s.jsxs)(`div`,{className:`hidden sm:flex flex-col text-left mr-1 justify-center min-w-[70px] max-w-[160px]`,children:[(0,s.jsx)(`span`,{className:`text-[12px] font-extrabold leading-tight text-foreground truncate w-full`,children:O}),(0,s.jsx)(`span`,{className:`text-[10px] font-mono tracking-wider leading-tight text-accent truncate w-full mt-0.5 uppercase font-bold`,children:f})]})]}),(0,s.jsx)(t.s,{children:m===`user`&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>h(!1)}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:-5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98,y:-5},className:`absolute top-full mt-2 right-0 w-[280px] md:w-[320px] glass-popover border border-[var(--panel-border)] rounded-2xl p-2 z-50 flex flex-col origin-top-right`,children:[(0,s.jsxs)(`div`,{className:`p-3 border-b border-[var(--panel-border)]/50 mb-1 flex flex-col gap-1.5`,children:[(0,s.jsx)(`span`,{className:`font-bold text-[15px] text-foreground truncate`,children:O}),(0,s.jsx)(`span`,{className:`text-[12px] text-foreground/50 truncate font-mono`,children:a.email})]}),(0,s.jsxs)(`div`,{className:`py-1`,children:[(0,s.jsxs)(c.Link,{to:`/profile`,onClick:()=>h(!1),className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-semibold tracking-wide hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all gap-3`,children:[(0,s.jsx)(`span`,{className:`w-5 h-5 rounded-md bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.m,{className:`w-3 h-3 text-accent`})}),`Profile Settings`]}),u&&(0,s.jsxs)(c.Link,{to:`/assets`,onClick:()=>h(!1),className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-semibold tracking-wide hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all gap-3`,children:[(0,s.jsx)(`span`,{className:`w-5 h-5 rounded-md bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.Y,{className:`w-3 h-3 text-accent`})}),`Assets`]}),o===`admin`&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(c.Link,{to:`/users`,onClick:()=>h(!1),className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-semibold tracking-wide hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all gap-3`,children:[(0,s.jsx)(`span`,{className:`w-5 h-5 rounded-md bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.p,{className:`w-3 h-3 text-accent`})}),`Users`]}),(0,s.jsxs)(c.Link,{to:`/inbox`,onClick:()=>h(!1),className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-semibold tracking-wide hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all gap-3`,children:[(0,s.jsx)(`span`,{className:`w-5 h-5 rounded-md bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.q,{className:`w-3 h-3 text-accent`})}),`Inbox`]}),(0,s.jsxs)(c.Link,{to:`/pages`,onClick:()=>h(!1),className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-semibold tracking-wide hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all gap-3`,children:[(0,s.jsx)(`span`,{className:`w-5 h-5 rounded-md bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.U,{className:`w-3 h-3 text-accent`})}),`Pages`]})]}),o!==`admin`&&(0,s.jsxs)(c.Link,{to:`/support`,onClick:()=>h(!1),className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-semibold tracking-wide hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all gap-3 text-left`,children:[(0,s.jsx)(`span`,{className:`w-5 h-5 rounded-md bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.lt,{className:`w-3 h-3 text-accent`})}),H]})]}),(0,s.jsx)(`div`,{className:`pt-1 mt-1 border-t border-[var(--panel-border)]/50`,children:(0,s.jsxs)(`button`,{onClick:L,className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-bold tracking-wide hover:bg-red-500/10 hover:text-red-500 text-foreground/70 transition-all gap-3`,children:[(0,s.jsx)(`span`,{className:`w-5 h-5 rounded-md bg-red-500/5 flex items-center justify-center shrink-0 text-red-500`,children:(0,s.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-3 h-3`,children:[(0,s.jsx)(`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`}),(0,s.jsx)(`polyline`,{points:`16 17 21 12 16 7`}),(0,s.jsx)(`line`,{x1:`21`,y1:`12`,x2:`9`,y2:`12`})]})}),`Sign Out`]})})]})]})})]}),(0,s.jsxs)(`div`,{className:`relative sm:hidden`,children:[(0,s.jsx)(`button`,{onClick:()=>h(m===`nav`?!1:`nav`),className:`p-2 rounded-xl glass-panel glow-hover border transition-all ${m===`nav`?`border-accent bg-foreground/5`:`border-[var(--panel-border)] hover:bg-foreground/5`}`,children:(0,s.jsx)(t.N,{className:`w-5 h-5 text-accent/80`})}),(0,s.jsx)(t.s,{children:m===`nav`&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>h(!1)}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:-10,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.95},className:`absolute top-full right-0 mt-3 w-[220px] p-2 glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col gap-1 origin-top-right`,children:[(0,s.jsxs)(c.Link,{to:`/profile`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.m,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Profile Settings`})]}),u&&(0,s.jsxs)(c.Link,{to:`/assets`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.Y,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Assets`})]}),(0,s.jsxs)(c.Link,{to:`/dashboard`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.H,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Dashboard`})]}),o===`admin`&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(c.Link,{to:`/users`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.p,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Users`})]}),(0,s.jsxs)(c.Link,{to:`/inbox`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.q,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Inbox`})]})]}),o!==`admin`&&(0,s.jsxs)(c.Link,{to:`/support`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all w-full text-left`,children:[(0,s.jsx)(t.lt,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Support`})]}),(0,s.jsx)(`div`,{className:`pt-1 mt-1 border-t border-[var(--panel-border)]/50`,children:(0,s.jsx)(`button`,{onClick:L,className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-red-500/10 text-red-500/80 hover:text-red-500 transition-all w-full`,children:(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Sign Out`})})})]})]})})]})]})]}),n&&(0,s.jsx)(s.Fragment,{children:F?.showThemeToggle&&(0,s.jsx)(`button`,{onClick:j,className:`p-2 ml-1 rounded-xl glass-panel hover:bg-foreground/5 transition-all text-accent border border-[var(--panel-border)] hover:border-accent/40`,"aria-label":`Toggle Theme`,children:k===`dark`?(0,s.jsx)(t.x,{className:`w-4 h-4`}):(0,s.jsx)(t.M,{className:`w-4 h-4`})})})]})]})}function B(){let[e,n]=(0,r.useState)(null);return(0,s.jsxs)(`main`,{className:`flex-1 flex flex-col items-center justify-center w-full max-w-5xl mx-auto mt-4 md:mt-12 mb-16 md:mb-24 z-10 relative`,children:[(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},transition:{duration:.8},className:`text-center mb-8 md:mb-12`,children:[(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},transition:{delay:.2},className:`inline-flex items-center gap-2 md:gap-3 px-5 md:px-6 py-2 md:py-2.5 mb-8 md:mb-10 text-[13px] md:text-[15px] font-semibold tracking-wide uppercase rounded-full glass-panel text-foreground glow-hover cursor-pointer`,children:[(0,s.jsx)(t.u,{className:`w-4 h-4 text-accent`}),` The Open-Source Firebase Starter`]}),(0,s.jsx)(t.o.h1,{className:`text-5xl sm:text-6xl md:text-7xl lg:text-[5.5rem] font-extrabold tracking-tight mb-6 md:mb-8 text-gradient animate-float leading-[1.1] md:leading-[1.15] px-2`,children:`Your AI Firebase`}),(0,s.jsx)(`p`,{className:`text-[14px] sm:text-[15px] md:text-lg lg:text-xl text-foreground/60 max-w-3xl mx-auto font-medium leading-[1.6] md:leading-[1.7] mb-10 md:mb-14 px-6 md:px-4`,children:`A production-ready Firebase backend template with Auth, Firestore prefix rules, and a clean dashboard — ready for vibe-coded apps.`}),(0,s.jsxs)(t.o.div,{className:`flex flex-col sm:flex-row items-center justify-center gap-4 sm:gap-6 w-full max-w-2xl mx-auto px-6`,initial:{opacity:0},animate:{opacity:1},transition:{delay:.5},children:[(0,s.jsx)(c.Link,{to:`/register`,style:{borderRadius:`var(--btn-radius, 0.75rem)`},className:`w-full sm:w-auto px-6 md:px-8 py-3 md:py-3.5 font-semibold tracking-wide btn-primary text-[15px] shadow-xl transition-all duration-300 hover:-translate-y-1 active:scale-95 flex items-center justify-center`,children:`Start Building Free`}),(0,s.jsx)(c.Link,{to:`/login`,style:{borderRadius:`var(--btn-radius, 0.75rem)`},className:`w-full sm:w-auto px-6 md:px-8 py-3 md:py-3.5 font-semibold tracking-wide btn-secondary text-[15px] transition-all duration-300 flex items-center justify-center hover:-translate-y-1`,children:`Sign In`})]})]}),(0,s.jsx)(t.s,{children:e&&(0,s.jsx)(t.t,{onClose:()=>n(null),formId:e})})]})}function V(){let[e,n]=(0,r.useState)(!1),[i,o]=(0,r.useState)(null),l=(0,c.useNavigate)(),{registerUser:u}=A();return(0,s.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mt-6 md:mt-8 mb-8`,children:(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5},className:`w-full max-w-[500px] p-6 sm:p-8 lg:p-10 rounded-3xl md:rounded-3xl glass-panel relative glow-hover shadow-[0_8px_32px_rgba(0,0,0,0.08)]`,children:[(0,s.jsx)(`div`,{className:`absolute -inset-[1px] bg-gradient-to-br from-[var(--primary-glow)] to-transparent opacity-30 blur-[20px] rounded-3xl md:rounded-3xl -z-10`}),(0,s.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,s.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight`,children:`Create an account`}),(0,s.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Join Your AI Firebase and start building today.`})]}),i&&(0,s.jsx)(`div`,{className:`p-3 mb-6 text-[14px] font-medium text-red-400 bg-red-500/10 rounded-xl border border-red-500/20`,children:i}),(0,s.jsxs)(`form`,{className:`space-y-4`,onSubmit:async e=>{e.preventDefault(),n(!0),o(null);let t=new FormData(e.currentTarget),r=t.get(`email`),i=t.get(`password`),a=t.get(`firstName`),d=t.get(`lastName`);if(i.length<6){o(`Password must be at least 6 characters.`),n(!1);return}try{await u(r,i,a,d),l(`/verify`)}catch(e){e?.code===`auth/email-already-in-use`?o((0,s.jsxs)(`span`,{children:[`An account with this email already exists.`,` `,(0,s.jsx)(c.Link,{to:`/login?email=${encodeURIComponent(r)}`,className:`font-bold underline hover:text-accent transition-colors`,children:`Sign in?`})]})):e?.code===`auth/weak-password`?o(`Password must be at least 6 characters.`):o(e?.message||`An error occurred during registration.`)}finally{n(!1)}},children:[(0,s.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,s.jsx)(t.i,{name:`firstName`,label:`First Name`,type:`text`,placeholder:`John`,required:!0}),(0,s.jsx)(t.i,{name:`lastName`,label:`Last Name`,type:`text`,placeholder:`Doe`,required:!0})]}),(0,s.jsx)(t.i,{name:`email`,label:`Email`,type:`email`,placeholder:`name@example.com`,required:!0}),(0,s.jsx)(t.i,{name:`password`,label:`Password`,type:`password`,placeholder:`••••••••`,required:!0}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsxs)(t.r,{type:`submit`,className:`w-full py-3 text-[15px] font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,isLoading:e,children:[`Create Account `,(0,s.jsx)(t.Ct,{className:`ml-2 w-4 h-4 group-hover:translate-x-1 transition-transform shrink-0`})]})})]}),(0,s.jsxs)(`div`,{className:`mt-6 pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:[(0,s.jsxs)(t.r,{variant:`secondary`,onClick:async()=>{n(!0),o(null);try{if(!t.Nt)throw Error(`Firebase is not initialized. Check your configuration.`);let e=new a.GoogleAuthProvider;try{await(0,a.signInWithPopup)(t.Nt,e)}catch(n){if(n?.code===`auth/popup-blocked`||n?.code===`auth/popup-closed-by-user`||n?.code===`auth/cancelled-popup-request`){let{signInWithRedirect:n}=await import(`firebase/auth`);await n(t.Nt,e);return}throw n}}catch(e){let t=e?.code||``;t===`auth/unauthorized-domain`||(e?.message||``).includes(`requested action is invalid`)?o(`Google Sign-In failed: your app domain is not authorized. Go to Firebase Console → Authentication → Settings → Authorized domains and add your domain (e.g. localhost or your-app.com).`):o(t===`auth/network-request-failed`?`Network error — please check your internet connection and Firebase configuration.`:e?.message||`Google sign-up failed.`)}finally{n(!1)}},className:`w-full py-3 text-[15px] font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,disabled:e,children:[(0,s.jsxs)(`svg`,{className:`w-5 h-5 mr-3`,viewBox:`0 0 24 24`,children:[(0,s.jsx)(`path`,{fill:`currentColor`,d:`M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z`}),(0,s.jsx)(`path`,{fill:`currentColor`,d:`M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z`}),(0,s.jsx)(`path`,{fill:`currentColor`,d:`M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z`}),(0,s.jsx)(`path`,{fill:`currentColor`,d:`M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z`})]}),`Sign up with Google`]}),(0,s.jsxs)(`p`,{className:`text-[14px] text-foreground/70 font-medium pt-2 tracking-wide`,children:[`Already have an account? `,(0,s.jsx)(c.Link,{to:`/login`,className:`text-accent hover:underline font-bold ml-1`,children:`Sign in`})]})]})]})})}function te(){let[e,n]=(0,r.useState)(!1),[i,o]=(0,r.useState)(null),[l]=(0,c.useSearchParams)(),u=(0,c.useNavigate)(),[d]=(0,r.useState)(l.get(`email`)||``);return(0,s.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mt-6 md:mt-8 mb-8`,children:(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5},className:`w-full max-w-[480px] p-6 sm:p-8 lg:p-10 rounded-3xl md:rounded-3xl glass-panel relative glow-hover shadow-[0_8px_32px_rgba(0,0,0,0.08)]`,children:[(0,s.jsx)(`div`,{className:`absolute -inset-[1px] bg-gradient-to-br from-[var(--primary-glow)] to-transparent opacity-30 blur-[20px] rounded-3xl md:rounded-3xl -z-10`}),(0,s.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,s.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight`,children:`Welcome back`}),(0,s.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Sign in to Your AI Firebase.`})]}),i&&(0,s.jsx)(`div`,{className:`p-3 mb-6 text-[14px] font-medium text-red-400 bg-red-500/10 rounded-xl border border-red-500/20`,children:i}),(0,s.jsxs)(`form`,{className:`space-y-4`,onSubmit:async e=>{e.preventDefault(),n(!0),o(null);let r=new FormData(e.currentTarget),i=r.get(`email`),d=r.get(`password`);try{if(!t.Nt)throw Error(`Firebase is not initialized. Check your configuration.`);await(0,a.signInWithEmailAndPassword)(t.Nt,i,d),u(l.get(`from`)||`/dashboard`,{replace:!0})}catch(e){e?.code===`auth/invalid-credential`||e?.code===`auth/user-not-found`||e?.code===`auth/wrong-password`?o((0,s.jsxs)(`span`,{children:[`Email or Password are incorrect.`,` `,(0,s.jsx)(c.Link,{to:`/reset-password`,className:`font-bold underline hover:text-red-400 transition-colors`,children:`Reset password?`})]})):e?.code===`auth/network-request-failed`?o(`Network error — please check your internet connection and Firebase configuration.`):o(e?.message||`Invalid credentials.`),n(!1)}},children:[(0,s.jsx)(t.i,{name:`email`,label:`Email`,type:`email`,defaultValue:d,placeholder:`name@example.com`,required:!0}),(0,s.jsxs)(`div`,{className:`space-y-2`,children:[(0,s.jsxs)(`div`,{className:`flex justify-between items-center pr-1`,children:[(0,s.jsx)(`label`,{className:`text-[14px] md:text-[15px] tracking-wide font-medium text-foreground/80 select-none pb-1`,children:`Password`}),(0,s.jsx)(c.Link,{to:`/reset-password`,className:`text-[13px] md:text-[14px] text-accent hover:underline font-bold tracking-wide`,children:`Forgot Password?`})]}),(0,s.jsx)(t.i,{name:`password`,type:`password`,placeholder:`••••••••`,required:!0})]}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsxs)(t.r,{type:`submit`,className:`w-full py-3 text-base font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,isLoading:e,children:[`Sign In `,(0,s.jsx)(t.Ct,{className:`ml-2 w-4 h-4 group-hover:translate-x-1 transition-transform shrink-0`})]})})]}),(0,s.jsxs)(`div`,{className:`mt-6 pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:[(0,s.jsxs)(t.r,{variant:`secondary`,onClick:async()=>{n(!0),o(null);try{if(!t.Nt)throw Error(`Firebase is not initialized. Check your configuration.`);let e=new a.GoogleAuthProvider;try{await(0,a.signInWithPopup)(t.Nt,e)}catch(n){if(n?.code===`auth/popup-blocked`||n?.code===`auth/popup-closed-by-user`||n?.code===`auth/cancelled-popup-request`){let{signInWithRedirect:n}=await import(`firebase/auth`);await n(t.Nt,e);return}throw n}u(l.get(`from`)||`/dashboard`,{replace:!0})}catch(e){let t=e?.code||``;t===`auth/unauthorized-domain`||(e?.message||``).includes(`requested action is invalid`)?o(`Google Sign-In failed: your app domain is not authorized. Go to Firebase Console → Authentication → Settings → Authorized domains and add your domain (e.g. localhost or your-app.com).`):o(t===`auth/network-request-failed`?`Network error — please check your internet connection and Firebase configuration.`:e?.message||`Google sign-in failed.`)}finally{n(!1)}},className:`w-full py-3 text-base font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,disabled:e,children:[(0,s.jsxs)(`svg`,{className:`w-5 h-5 mr-3`,viewBox:`0 0 24 24`,children:[(0,s.jsx)(`path`,{fill:`currentColor`,d:`M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z`}),(0,s.jsx)(`path`,{fill:`currentColor`,d:`M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z`}),(0,s.jsx)(`path`,{fill:`currentColor`,d:`M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z`}),(0,s.jsx)(`path`,{fill:`currentColor`,d:`M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z`})]}),`Sign in with Google`]}),(0,s.jsxs)(`p`,{className:`text-[14px] text-foreground/70 font-medium pt-2 tracking-wide`,children:[`New here? `,(0,s.jsx)(c.Link,{to:`/register`,className:`text-accent hover:underline font-bold ml-1`,children:`Create account`})]})]})]})})}function H(){let{user:e,refreshUser:n}=A(),i=(0,c.useNavigate)(),[o,l]=(0,r.useState)(!1),[u,d]=(0,r.useState)(!1),[f,p]=(0,r.useState)(``);return(0,s.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mb-16`,children:(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5},className:`w-full max-w-[480px] p-6 md:p-8 lg:p-10 rounded-3xl glass-panel relative glow-hover text-center shadow-[0_8px_32px_rgba(0,0,0,0.08)]`,children:[(0,s.jsx)(`div`,{className:`absolute -inset-[1px] bg-gradient-to-br from-[var(--primary-glow)] to-transparent opacity-30 blur-[20px] rounded-3xl -z-10`}),(0,s.jsx)(`div`,{className:`w-14 h-14 md:w-16 md:h-16 rounded-2xl glass-panel border border-[var(--panel-border)] flex items-center justify-center mx-auto mb-5 md:mb-6 animate-float shadow-xl`,children:(0,s.jsx)(t.P,{className:`w-7 h-7 md:w-8 md:h-8 text-accent opacity-90`})}),(0,s.jsx)(`h1`,{className:`text-2xl md:text-3xl font-extrabold mb-3 text-foreground tracking-tight`,children:`Verify your email`}),(0,s.jsxs)(`p`,{className:`text-[14px] md:text-[15px] text-foreground/60 mb-6 md:mb-8 leading-[1.6] tracking-wide`,children:[`We've sent a verification link to `,(0,s.jsx)(`span`,{className:`font-semibold text-foreground`,children:e?.email}),`. Please check your inbox (and spam folder) to verify your account and access your dashboard.`]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-3 max-w-[360px] mx-auto`,children:[f&&(0,s.jsx)(`div`,{role:`status`,className:`w-full px-4 py-2.5 md:py-3 text-[13px] md:text-[14px] font-semibold leading-snug rounded-xl border ${f.includes(`Failed`)||f.includes(`not verified`)||f.includes(`wrong`)?`text-red-400 bg-red-500/10 border-red-500/20`:`text-emerald-400 bg-emerald-500/10 border-emerald-500/20`}`,children:f}),(0,s.jsx)(t.r,{variant:`primary`,onClick:async()=>{l(!0),p(``);try{if(t.Nt.currentUser){if(await t.Nt.currentUser.reload(),!t.Nt.currentUser.emailVerified){p(`Email is not verified yet. Please check your inbox.`),l(!1);return}await t.Nt.currentUser.getIdToken(!0),await n(),i(`/dashboard`)}}catch{p(`Something went wrong. Please try again.`),l(!1)}},isLoading:o,className:`w-full py-2.5 md:py-3 text-[14px] font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,children:`I've verified my email`}),(0,s.jsx)(t.r,{variant:`ghost`,onClick:async()=>{if(e){d(!0),p(``);try{await(0,a.sendEmailVerification)(e),p(`Verification email sent! Please check your inbox.`)}catch(e){e?.code===`auth/too-many-requests`?p(`Failed to resend: Please wait a minute before trying again.`):p(e?.message||`Failed to resend. Please try again later.`)}finally{d(!1)}}},isLoading:u,className:`w-full py-2.5 md:py-3 text-[13px] md:text-[14px] font-semibold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,children:`Resend verification link`})]})]})})}var U=D(`admin`),W={pages:{path:`/pages`,label:`Pages`,icon:t.U,roles:U},forms:{path:`/forms`,label:`Forms`,icon:t.O,roles:U},inbox:{path:`/inbox`,label:`Inbox`,icon:t.q,roles:U},users:{path:`/users`,label:`Users`,icon:t.p,roles:U},theme:{path:`/theme`,label:`Theme`,icon:t.j,roles:U},assets:{path:`/assets`,label:`Assets`,icon:t.Y,roles:U}};function ne({customTabs:e=[]}){let{pathname:n}=(0,c.useLocation)(),{user:a,userRole:o}=A(),[l,u]=(0,r.useState)(!1),d=(0,r.useRef)(null),[f,p]=(0,r.useState)({}),[m,h]=(0,r.useState)(L);(0,r.useEffect)(()=>{try{let e=localStorage.getItem(`fbos_nav_tabs`);e&&p(JSON.parse(e));let t=localStorage.getItem(`fbos_nav_order`);t&&h(JSON.parse(t))}catch{}let e=(0,i.onSnapshot)((0,i.collection)(t.Pt,`sys_tabs`),e=>{let t={};e.forEach(e=>{t[e.id]=e.data()}),p(t),localStorage.setItem(`fbos_nav_tabs`,JSON.stringify(t))},e=>{console.warn(`sys_tabs snapshot error:`,e)}),n=(0,i.onSnapshot)((0,i.doc)(t.Pt,`sys_configs`,`tab_order`),e=>{let t=e.exists()&&Array.isArray(e.data().order)?I(e.data().order):L;h(t),localStorage.setItem(`fbos_nav_order`,JSON.stringify(t))},e=>{console.warn(`tab_order snapshot error:`,e)});return()=>{e(),n()}},[]),(0,r.useEffect)(()=>{function e(e){d.current&&!d.current.contains(e.target)&&u(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let g=[...(()=>{let e={};Object.entries(W).forEach(([t,n])=>{e[t]={id:t,...n,exact:!0}});let n={...f};for(let[e,t]of M())t.isPublic||(n[e]={...t.config,...f[e]});Object.entries(n).forEach(([n,r])=>{let i=e[n],a=i?.icon??t.U;if(r?.iconName){let e=r.iconName.trim(),n=e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);t.c[n]?a=t.c[n]:t.c[e]&&(a=t.c[e])}let o=i?.roles??U;r?.pageType&&(o=D(w(r.pageType))),e[n]={id:n,path:r?.route?r.route.startsWith(`/`)?r.route:`/`+r.route:i?.path??`/`+n,label:r?.tabName||r?.pageTitle||r?.pageName||i?.label||n,icon:a,roles:o,exact:!0}});let r=[],i=new Set;m.forEach(t=>{t.hidden||e[t.id]&&(r.push(e[t.id]),i.add(t.id))});let a=[],o=[];return Object.keys(e).forEach(t=>{if(i.has(t))return;let r=m.find(e=>e.id===t);r?.hidden||(t in n&&!r?a.push(e[t]):o.push(e[t]))}),a.length>0&&r.unshift(...a),o.length>0&&r.push(...o),r})(),...e.map(e=>({...e,id:e.path}))].filter(e=>{let t=E(o,!!a);return Array.isArray(e.roles)?e.roles.includes(t):!1}),_=(0,r.useRef)(null),v=(0,r.useRef)(null),[y,b]=(0,r.useState)(g.length);(0,r.useEffect)(()=>{let e=()=>{let e=_.current,t=v.current;if(!e||!t)return;let n=e.clientWidth;if(n===0)return;let r=t.querySelectorAll(`[data-measure-tab]`);if(r.length===0){b(g.length);return}let i=0,a=!0;for(let e=0;e<r.length;e++)if(i+=r[e].offsetWidth+(e>0?40:0),i>n){a=!1;break}if(a){b(g.length);return}let o=0,s=0;for(let e=0;e<r.length;e++){let t=r[e].offsetWidth,i=o+t+(e>0?40:0);if(i+52>n)break;o=i,s++}b(Math.max(s,1))},t=requestAnimationFrame(e);if(typeof ResizeObserver>`u`)return()=>cancelAnimationFrame(t);let n=new ResizeObserver(()=>requestAnimationFrame(e));return _.current&&n.observe(_.current),()=>{cancelAnimationFrame(t),n.disconnect()}},[g.map(e=>e.id+e.label).join(`|`),g.length]);let x=g.slice(0,y),S=g.slice(y),C=e=>e.exact?n===e.path:n.startsWith(e.path),T=S.some(e=>C(e));return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{ref:v,"aria-hidden":`true`,className:`flex items-center gap-6 md:gap-10 whitespace-nowrap px-1`,style:{position:`fixed`,top:-9999,left:0,visibility:`hidden`,pointerEvents:`none`},children:g.map(e=>{let t=e.icon;return(0,s.jsxs)(`span`,{"data-measure-tab":!0,className:`flex items-center gap-2 text-[14.5px] font-semibold shrink-0 pb-3`,children:[(0,s.jsx)(t,{className:`w-[18px] h-[18px]`}),e.label]},e.path||e.id)})}),(0,s.jsxs)(`div`,{ref:_,className:`w-full flex items-center gap-6 md:gap-10 mb-8 border-b border-[var(--panel-border)] px-1 whitespace-nowrap relative`,children:[x.map(e=>{let t=C(e),n=e.icon;return(0,s.jsxs)(c.Link,{to:e.path||`/`,className:`flex items-center gap-2 text-[14.5px] font-semibold transition-all duration-300 pb-3 -mb-[1px] border-b-2 shrink-0 ${t?`text-accent border-accent`:`text-foreground/50 hover:text-foreground/80 border-transparent`}`,children:[(0,s.jsx)(n,{className:`w-[18px] h-[18px]`}),e.label]},e.path||e.id)}),S.length>0&&(0,s.jsxs)(`div`,{className:`relative shrink-0 ml-auto`,ref:d,children:[(0,s.jsx)(`button`,{onClick:()=>u(!l),className:`flex items-center justify-center transition-all duration-300 pb-3 -mb-[1px] border-b-2 cursor-pointer ${T?`text-accent border-accent`:`text-foreground/50 hover:text-foreground/80 border-transparent`}`,title:`More items`,children:(0,s.jsx)(t.nt,{className:`w-5 h-5`})}),(0,s.jsx)(t.s,{children:l&&(0,s.jsx)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:10},className:`absolute top-[100%] right-0 mt-2 min-w-[200px] glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col py-2 overflow-hidden`,children:S.map(e=>{let t=C(e),n=e.icon;return(0,s.jsxs)(c.Link,{to:e.path||`/`,onClick:()=>u(!1),className:`flex items-center gap-3 px-5 py-3 text-[14px] font-medium transition-colors ${t?`text-accent bg-accent/5`:`text-foreground/70 hover:text-foreground hover:bg-foreground/5`}`,children:[(0,s.jsx)(n,{className:`w-4 h-4`}),e.label]},e.path||e.id)})})})]})]})]})}function G(){let{user:e,refreshUser:n,isInternal:c}=A(),[l,u]=(0,r.useState)(e?.displayName||``),[d,f]=(0,r.useState)(e?.email||``),[p,m]=(0,r.useState)(e?.photoURL||``),[h,g]=(0,r.useState)(!1),[_,v]=(0,r.useState)(null),[y,b]=(0,r.useState)(``),[x,S]=(0,r.useState)(``),[w,T]=(0,r.useState)(!1),[E,D]=(0,r.useState)(!1),[O,k]=(0,r.useState)(!0);r.default.useEffect(()=>{u(e?.displayName||``),f(e?.email||``),m(e?.photoURL||``)},[e?.uid,e?.displayName,e?.email,e?.photoURL]);let j=async n=>{if(e)try{if(!c)return;let r=[`mem_files`,`admin_files`];(await(0,i.getDocs)((0,i.collection)(t.Pt,`sys_tabs`))).forEach(e=>{let t=e.data(),n=(t.tabName||e.id).toLowerCase().replace(/[^a-z0-9]+/g,`_`),i=C(t.pageType);i===`internal`&&r.push(`mem_${n}_records`),i===`admin`&&r.push(`admin_${n}_records`)});for(let a of r)try{let r=await(0,i.getDocs)((0,i.query)((0,i.collection)(t.Pt,a),(0,i.where)(`uid`,`==`,e.uid)));if(r.empty)continue;let o=(0,i.writeBatch)(t.Pt);r.docs.forEach(e=>o.update(e.ref,{creatorAvatar:n})),await o.commit()}catch{}}catch(e){console.error(`Error propagating avatar to records:`,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-8`,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:`Profile Settings`}),(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`}),`/profile`]})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 animate-in fade-in duration-500 pb-20`,children:[(0,s.jsx)(`div`,{className:`flex justify-start`,children:(0,s.jsx)(ne,{})}),(0,s.jsx)(t.s,{children:_&&(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.98,y:-10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.98,y:-10},className:`p-4 mb-6 rounded-2xl border flex flex-col sm:flex-row sm:items-center gap-3 ${_.type===`error`?`bg-red-500/10 border-red-500/20 text-red-400`:`bg-accent/10 border-accent/20 text-accent`}`,children:[_.type===`success`?(0,s.jsx)(t.dt,{className:`w-5 h-5 shrink-0`}):(0,s.jsx)(t.ft,{className:`w-5 h-5 shrink-0`}),(0,s.jsx)(`span`,{className:`text-[14px] font-semibold tracking-wide leading-relaxed`,children:_.text})]})}),(0,s.jsx)(`form`,{onSubmit:async r=>{if(r.preventDefault(),e){g(!0),v(null);try{l!==e.displayName&&await(0,a.updateProfile)(e,{displayName:l});let r=!1;if(d!==e.email){let n=await(0,a.fetchSignInMethodsForEmail)(t.Nt,d);if(n&&n.length>0)throw Error(`An account with this email already exists.`);await(0,a.verifyBeforeUpdateEmail)(e,d),r=!0}if(y){if(y!==x)throw Error(`Passwords do not match.`);if(y.length<6)throw Error(`Password must be at least 6 characters.`);await(0,a.updatePassword)(e,y),b(``),S(``)}await n(),v(r?{text:`Profile updated. A verification link has been sent to your new email address.`,type:`success`}:{text:`Profile successfully updated.`,type:`success`})}catch(e){console.error(e),e.code===`auth/requires-recent-login`?v({text:`For security, please sign out and sign back in before changing your email or password.`,type:`error`}):v({text:e.message||`Failed to update profile.`,type:`error`})}finally{g(!1)}}},className:`w-full flex flex-col`,children:(0,s.jsxs)(`div`,{className:`glass-panel w-full p-8 md:p-12 rounded-3xl border border-[var(--panel-border)] shadow-2xl space-y-8 min-h-[500px]`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-6 pb-6 border-b border-[var(--panel-border)]/50`,children:[(0,s.jsxs)(`div`,{className:`w-24 h-24 md:w-28 md:h-28 rounded-full glass-panel border-4 border-[var(--panel-border)] shadow-xl bg-accent/10 flex items-center justify-center relative overflow-hidden shrink-0 group transition-transform duration-300 hover:scale-[1.02]`,children:[(E||p&&O&&!w)&&(0,s.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-accent/5 backdrop-blur-sm z-10`,children:(0,s.jsx)(t.L,{className:`w-8 h-8 text-accent animate-spin`})}),p&&!w?(0,s.jsx)(`img`,{src:p,alt:`Avatar`,className:`w-full h-full object-cover transition-opacity duration-300 ${O?`opacity-0`:`opacity-100`}`,onLoad:()=>k(!1),onError:()=>{T(!0),k(!1)}}):(0,s.jsx)(t.m,{className:`w-10 h-10 md:w-12 md:h-12 text-accent`}),!E&&(0,s.jsxs)(`div`,{className:`absolute inset-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2 z-10 backdrop-blur-sm`,children:[(0,s.jsxs)(`label`,{className:`flex flex-col items-center justify-center cursor-pointer p-2 rounded-full hover:bg-white/20 transition-colors text-white`,title:`Upload Photo`,children:[(0,s.jsx)(t.yt,{className:`w-5 h-5`}),(0,s.jsx)(`input`,{type:`file`,accept:`image/*`,onChange:async r=>{let s=r.target.files?.[0];if(!(!s||!e)){if(s.size>2*1024*1024){v({text:`File too large. Please select an image under 2MB.`,type:`error`});return}D(!0),T(!1),k(!0);try{let r=(0,o.ref)(t.It,`user_avatars/${e.uid}/file.png`);await(0,o.uploadBytes)(r,s,{customMetadata:{ownerId:e.uid}});let c=await(0,o.getDownloadURL)(r);m(c);let l=(0,i.doc)(t.Pt,`user_profiles`,e.uid);await Promise.all([(0,a.updateProfile)(e,{photoURL:c}),(0,i.updateDoc)(l,{avatar:c}),j(c)]),await n(),v({text:`Avatar successfully updated!`,type:`success`})}catch(e){console.error(e),v({text:`Failed to upload photo.`,type:`error`})}finally{D(!1)}}},className:`hidden`})]}),p&&(0,s.jsx)(`button`,{type:`button`,onClick:async()=>{if(e){D(!0),T(!1),k(!1);try{let r=(0,o.ref)(t.It,`user_avatars/${e.uid}/file.png`);m(``),D(!1);let s=(0,i.doc)(t.Pt,`user_profiles`,e.uid);await Promise.all([(0,o.deleteObject)(r).catch(e=>console.error(e)),(0,a.updateProfile)(e,{photoURL:``}),(0,i.updateDoc)(s,{avatar:``}),j(``)]),await n(),v({text:`Avatar removed.`,type:`success`})}catch(e){console.error(e),v({text:`Failed to delete photo.`,type:`error`}),D(!1)}}},className:`p-2 rounded-full hover:bg-red-500/80 text-white transition-colors`,title:`Delete Photo`,children:(0,s.jsx)(t.y,{className:`w-5 h-5`})})]})]}),(0,s.jsxs)(`div`,{className:`flex-1 text-left`,children:[(0,s.jsx)(`h3`,{className:`font-extrabold text-2xl text-foreground mb-1`,children:l||`User`}),(0,s.jsx)(`div`,{className:`text-[12px] font-mono uppercase tracking-widest text-accent bg-accent/10 px-2.5 py-1 rounded-md border border-accent/20 inline-block`,children:e?.emailVerified?`Verified Account`:`Unverified`}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/40 mt-2 font-medium`,children:e?.email})]})]}),(0,s.jsxs)(`div`,{className:`space-y-6`,children:[(0,s.jsx)(`h3`,{className:`text-[16px] font-extrabold text-foreground flex items-center gap-2`,children:`Account Details`}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-5 md:gap-6`,children:[(0,s.jsx)(t.i,{name:`name`,value:l,onChange:e=>u(e.target.value),label:`Display Name`,placeholder:`John Doe`}),(0,s.jsxs)(`div`,{className:`flex flex-col`,children:[(0,s.jsx)(t.i,{name:`email`,type:`email`,value:d,onChange:e=>f(e.target.value),label:`Email Address`,placeholder:`name@example.com`,required:!0}),(0,s.jsx)(`p`,{className:`text-[11px] text-foreground/40 mt-1.5 px-2 font-medium`,children:`Changing email sends a verification link to the new address.`})]})]})]}),(0,s.jsxs)(`div`,{className:`pt-6 border-t border-[var(--panel-border)]/50`,children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold text-foreground mb-4 flex items-center gap-2`,children:`Change Password`}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-5 md:gap-6`,children:[(0,s.jsx)(t.i,{name:`password`,type:`password`,label:`New Password`,value:y,onChange:e=>b(e.target.value),placeholder:`Minimum 6 characters`}),(0,s.jsx)(t.i,{name:`confirmPassword`,type:`password`,label:`Confirm Password`,value:x,onChange:e=>S(e.target.value),placeholder:`Repeat password`})]})]}),(0,s.jsx)(`div`,{className:`pt-8 border-t border-[var(--panel-border)]/50 flex justify-start w-full`,children:(0,s.jsx)(t.r,{type:`submit`,isLoading:h,className:`px-12 py-3 md:py-2.5 text-[14px] md:text-[15px] font-bold tracking-wide rounded-xl hover:-translate-y-0.5`,children:`Save Changes`})})]})})]})]})}function K(){let[e,n]=(0,r.useState)(!1),[i,o]=(0,r.useState)(null),[l,u]=(0,r.useState)(0),[d,f]=(0,r.useState)(0);return(0,r.useEffect)(()=>{let e;return l>0&&(e=setInterval(()=>u(e=>e-1),1e3)),()=>clearInterval(e)},[l]),(0,s.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mb-16 mt-6 md:mt-8`,children:(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5},className:`w-full max-w-[480px] p-6 md:p-8 lg:p-10 rounded-3xl glass-panel relative glow-hover shadow-[0_8px_32px_rgba(0,0,0,0.08)] text-center`,children:[(0,s.jsx)(`div`,{className:`absolute -inset-[1px] bg-gradient-to-br from-[var(--primary-glow)] to-transparent opacity-40 blur-[15px] rounded-3xl -z-10`}),(0,s.jsx)(`div`,{className:`w-14 h-14 md:w-16 md:h-16 rounded-2xl glass-panel border border-[var(--panel-border)] flex items-center justify-center mx-auto mb-5 md:mb-6 animate-float shadow-xl`,children:(0,s.jsx)(t.W,{className:`w-7 h-7 md:w-8 md:h-8 text-accent opacity-90`})}),(0,s.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,s.jsx)(`h3`,{className:`text-2xl md:text-3xl font-extrabold mb-2 md:mb-3 text-foreground tracking-tight`,children:`Reset Password`}),(0,s.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Enter your email to receive a recovery link.`})]}),i&&(0,s.jsx)(`div`,{className:`p-3 md:p-4 mb-5 md:mb-6 text-[13px] md:text-[14px] font-medium text-emerald-400 bg-emerald-500/10 rounded-xl border border-emerald-500/20 max-w-[360px] mx-auto`,children:i}),(0,s.jsxs)(`form`,{className:`space-y-4 text-left max-w-[360px] mx-auto`,onSubmit:async e=>{e.preventDefault(),n(!0),o(null);let r=new FormData(e.currentTarget).get(`email`);try{await(0,a.sendPasswordResetEmail)(t.Nt,r)}catch(e){console.error(e)}finally{o(`If an account exists, a password reset link has been sent. Please check your inbox (and spam folder).`);let e=d+1;f(e),u(e===1?60:120),n(!1)}},children:[(0,s.jsx)(t.i,{name:`email`,label:`Work Email`,type:`email`,placeholder:`name@company.com`,required:!0}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsx)(t.r,{type:`submit`,className:`w-full py-2.5 md:py-3 text-[14px] font-bold tracking-wide rounded-xl md:rounded-xl transition-all ${l>0?`bg-foreground/5 text-foreground/40 border border-[var(--panel-border)] shadow-none cursor-not-allowed hover:translate-y-0`:`hover:-translate-y-0.5`}`,isLoading:e,disabled:l>0,children:l>0?`Resend link in ${(e=>`${Math.floor(e/60)}:${(e%60).toString().padStart(2,`0`)}`)(l)}`:d>0?`Resend reset password link`:`Send Reset Link`})})]}),(0,s.jsx)(`div`,{className:`mt-6 pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:(0,s.jsxs)(c.Link,{to:`/login`,className:`inline-flex items-center text-[13px] md:text-[14px] text-foreground/70 font-medium hover:text-accent transition-colors tracking-wide`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4 mr-2`}),`Back to Sign In`]})})]})})}var q={free:``,internal:`text-blue-500 border-blue-500/30 bg-blue-500/10`,admin:`text-red-500 border-red-500/30 bg-red-500/10`},J=({level:e})=>e===`free`?null:(0,s.jsx)(`span`,{className:`shrink-0 text-[9px] font-bold uppercase tracking-widest px-1.5 py-0.5 rounded border ${q[e]}`,children:_[e]});function Y(){let{user:e,userRole:n}=A(),[a,l]=(0,r.useState)(!0),u=(0,c.useNavigate)(),{id:d}=(0,c.useParams)(),[f,p]=(0,r.useState)([]),[m,g]=(0,r.useState)(null),[x,S]=(0,r.useState)(!1),[C,w]=(0,r.useState)(``),[T,E]=(0,r.useState)(!1),D=d?f.find(e=>e.id===d)||null:f.length>0?f[0]:null,O=e=>{u(e?`/users/${e.id}`:`/users`)};(0,r.useEffect)(()=>{l(!0);let e=(0,i.onSnapshot)((0,i.collection)(t.Pt,`user_profiles`),e=>{let t=[];e.forEach(e=>{t.push({id:e.id,...e.data()})}),p(t),l(!1),!d&&t.length>0&&u(`/users/${t[0].id}`,{replace:!0})},e=>{console.error(`Error fetching users:`,e),l(!1)});return()=>e()},[d,u]);let k=f.find(t=>t.id===e?.uid),j=e=>e.id===k?.id?!1:e.role!==`admin`||!k?.createdAt?!0:e.createdAt?new Date(k.createdAt).getTime()<=new Date(e.createdAt).getTime():!1,M=async(e,r)=>{if(!(n!==`admin`||!j(e))&&y(e.role)!==r)try{await(0,i.updateDoc)((0,i.doc)(t.Pt,`user_profiles`,e.id),{role:b(r)}),g({text:`Access level set to ${_[r]}`,type:`success`}),setTimeout(()=>g(null),3e3)}catch(e){g({text:e.message,type:`error`}),setTimeout(()=>g(null),3e3)}},N=async(e,r)=>{if(!(n!==`admin`||!j(e)))try{await(0,i.updateDoc)((0,i.doc)(t.Pt,`user_profiles`,e.id),{inactive:r}),g({text:`User ${r?`deactivated`:`activated`} successfully`,type:`success`}),setTimeout(()=>g(null),3e3)}catch(e){g({text:e.message,type:`error`}),setTimeout(()=>g(null),3e3)}},P=async()=>{if(S(!1),!(!D||!j(D)||C===D.displayName))try{await(0,i.updateDoc)((0,i.doc)(t.Pt,`user_profiles`,D.id),{displayName:C}),g({text:`Name updated successfully`,type:`success`}),setTimeout(()=>g(null),3e3)}catch(e){g({text:e.message,type:`error`}),setTimeout(()=>g(null),3e3)}},F=async e=>{let n=e.target.files?.[0];if(!(!n||!D||!j(D))){if(n.size>2*1024*1024){g({text:`File too large. Please select an image under 2MB.`,type:`error`});return}E(!0);try{let e=(0,o.ref)(t.It,`user_avatars/${D.id}/file.png`);await(0,o.uploadBytes)(e,n);let r=await(0,o.getDownloadURL)(e);p(e=>e.map(e=>e.id===D.id?{...e,avatar:r}:e)),await(0,i.updateDoc)((0,i.doc)(t.Pt,`user_profiles`,D.id),{avatar:r}),g({text:`Avatar successfully updated.`,type:`success`}),setTimeout(()=>g(null),3e3)}catch{g({text:`Failed to upload photo.`,type:`error`})}E(!1)}},[I,L]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{let e;return a&&f.length===0?e=setTimeout(()=>L(!0),150):L(!1),()=>clearTimeout(e)},[a,f.length]),a&&f.length===0?I?(0,s.jsx)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center bg-background/60 backdrop-blur-xl transition-all duration-300`,children:(0,s.jsx)(t.L,{className:`w-8 h-8 animate-spin text-accent`})}):null:(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.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:`Users`}),(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`}),`/users`]})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 animate-in fade-in duration-500 pb-20`,children:[(0,s.jsx)(t.s,{children:m&&(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:`p-4 text-[14px] font-medium border ${m.type===`error`?`text-red-500 bg-red-500/10 border-red-500/20 shadow-[0_0_15px_rgba(239,68,68,0.1)]`:`text-emerald-400 bg-emerald-500/10 border-emerald-500/20 shadow-[0_0_15px_rgba(52,211,153,0.1)]`} rounded-xl flex items-center gap-2`,children:[m.type===`success`&&(0,s.jsx)(t.dt,{className:`w-4 h-4 shrink-0`}),m.text]})}),(0,s.jsx)(`div`,{className:`flex justify-start`,children:(0,s.jsx)(ne,{})}),(0,s.jsx)(`div`,{className:`glass-panel rounded-3xl border border-[var(--panel-border)] shadow-sm`,children:f.length===0?(0,s.jsx)(`div`,{className:`p-8 text-center text-foreground/50 text-[14px]`,children:`No members found.`}):(0,s.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 min-h-[500px]`,children:[(0,s.jsxs)(`div`,{className:`md:col-span-1 border-r md:border-r-[var(--panel-border)] border-b md:border-b-0 border-[var(--panel-border)] flex flex-col hide-scrollbar bg-foreground/[0.03] rounded-t-3xl md:rounded-tr-none md:rounded-l-3xl`,children:[(0,s.jsx)(`div`,{className:`p-4 border-b border-[var(--panel-border)] font-bold text-[13px] text-foreground/70 uppercase tracking-wider`,children:`System Users`}),(0,s.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-2`,children:f.map(e=>(0,s.jsxs)(`div`,{onClick:()=>O(e),className:`p-4 py-5 rounded-2xl border transition-all flex items-center gap-4 cursor-pointer ${D?.id===e.id?`bg-accent/10 border-accent/40 shadow-sm`:`glass-panel border-transparent hover:border-[var(--panel-border)]`} ${e.inactive?`opacity-50 grayscale`:``}`,children:[(0,s.jsx)(`div`,{className:`w-12 h-12 rounded-full overflow-hidden bg-accent/20 shrink-0 flex items-center justify-center border border-[var(--panel-border)]`,children:e.avatar||e.photoURL?(0,s.jsx)(`img`,{src:e.avatar||e.photoURL,alt:``,className:`w-full h-full object-cover`}):(0,s.jsx)(t.m,{className:`w-5 h-5 text-accent`})}),(0,s.jsxs)(`div`,{className:`flex flex-col truncate`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 truncate`,children:[(0,s.jsx)(`span`,{className:`font-bold text-[14px] truncate`,children:e.displayName||`No Name`}),(0,s.jsx)(J,{level:y(e.role)})]}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/50 truncate font-mono mt-0.5`,children:e.email})]})]},e.id))})]}),(0,s.jsx)(`div`,{className:`md:col-span-2 flex flex-col p-6 md:p-10 relative`,children:D?(0,s.jsxs)(`div`,{className:`animate-in fade-in duration-300 w-full max-w-lg`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-6 md:gap-8 mb-10`,children:[(0,s.jsxs)(`div`,{className:`w-24 h-24 rounded-full glass-panel border-4 border-[var(--panel-border)] shadow-xl bg-accent/10 flex items-center justify-center relative overflow-hidden shrink-0 group`,children:[T?(0,s.jsx)(t.L,{className:`w-8 h-8 text-accent animate-spin`}):D.avatar||D.photoURL?(0,s.jsx)(`img`,{src:D.avatar||D.photoURL,alt:`Avatar`,className:`w-full h-full object-cover`}):(0,s.jsx)(t.m,{className:`w-10 h-10 text-accent`}),!T&&j(D)&&(0,s.jsx)(`div`,{className:`absolute inset-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center z-10 backdrop-blur-md`,children:(0,s.jsxs)(`label`,{className:`flex flex-col items-center justify-center cursor-pointer p-2 hover:bg-white/20 transition-colors text-white rounded-full`,title:`Upload Photo`,children:[(0,s.jsx)(t.yt,{className:`w-5 h-5`}),(0,s.jsx)(`input`,{type:`file`,accept:`image/*`,onChange:F,className:`hidden`})]})})]}),(0,s.jsxs)(`div`,{className:`flex flex-col flex-1 w-full relative`,children:[x?(0,s.jsx)(`input`,{autoFocus:!0,value:C,onChange:e=>w(e.target.value),onBlur:P,onKeyDown:e=>e.key===`Enter`&&P(),className:`text-2xl md:text-3xl font-extrabold mb-1 bg-transparent border-b-2 border-accent outline-none text-foreground w-full py-1`}):(0,s.jsx)(`h3`,{onDoubleClick:()=>{j(D)&&(w(D.displayName||``),S(!0))},className:`text-2xl md:text-3xl font-extrabold mb-1 select-none ${j(D)?`cursor-pointer hover:text-accent transition-colors`:``}`,title:j(D)?`Double-click to edit`:``,children:D.displayName||`No Name`}),(0,s.jsx)(`p`,{className:`text-[14px] font-mono text-foreground/50`,children:D.email}),!j(D)&&D.id!==k?.id&&(0,s.jsxs)(`p`,{className:`mt-2 flex items-center gap-1.5 text-[12px] font-medium text-foreground/45`,children:[(0,s.jsx)(t.I,{className:`w-3 h-3 shrink-0`}),`Admin since before you, so only they can change this account.`]})]})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,s.jsxs)(`div`,{className:`p-4 rounded-2xl glass-panel border border-[var(--panel-border)] flex flex-col gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col`,children:[(0,s.jsx)(`span`,{className:`font-bold text-[14px] text-foreground`,children:`Access level`}),(0,s.jsx)(`span`,{className:`text-[12px] text-foreground/50`,children:`What this person can open`})]}),(0,s.jsx)(`div`,{role:`radiogroup`,"aria-label":`Access level`,className:`flex items-center gap-1.5 flex-wrap ${j(D)?``:`opacity-50`}`,children:h.map(e=>{let t=y(D.role)===e;return(0,s.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t,disabled:!j(D),onClick:()=>M(D,e),className:`h-8 px-3.5 rounded-full text-[12.5px] font-semibold border transition-all ${t?`bg-accent/10 border-accent/40 text-accent`:`border-[var(--panel-border)] text-foreground/55 hover:text-foreground hover:border-accent/30`} ${j(D)?`cursor-pointer`:`cursor-not-allowed`}`,children:_[e]},e)})})]}),(0,s.jsx)(`p`,{className:`text-[12px] text-foreground/50 leading-relaxed`,children:v[y(D.role)]})]}),(0,s.jsxs)(`div`,{className:`p-4 rounded-2xl glass-panel border flex items-center justify-between ${D.inactive?`border-amber-500/30 bg-amber-500/5`:`border-red-500/20 bg-red-500/5`}`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col`,children:[(0,s.jsx)(`span`,{className:`font-bold text-[14px] ${D.inactive?`text-amber-500`:`text-red-500`}`,children:D.inactive?`Reactivate User`:`Deactivate User`}),(0,s.jsx)(`span`,{className:`text-[12px] ${D.inactive?`text-amber-500/70`:`text-red-500/70`}`,children:`Block access to this app`})]}),(0,s.jsx)(`button`,{type:`button`,disabled:!j(D),onClick:()=>N(D,!D.inactive),className:`relative inline-flex h-7 w-12 items-center rounded-full transition-colors focus:outline-none shadow-inner ${D.inactive?`bg-amber-500`:`bg-red-500/20`} ${j(D)?`cursor-pointer`:`opacity-50 cursor-not-allowed`}`,children:(0,s.jsx)(`span`,{className:`inline-block h-5 w-5 transform rounded-full bg-white transition-transform shadow-md ${D.inactive?`translate-x-6`:`translate-x-1`}`})})]})]})]}):(0,s.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center opacity-30 pointer-events-none`,children:[(0,s.jsx)(t.p,{className:`w-12 h-12 mb-4`}),(0,s.jsx)(`p`,{className:`font-bold tracking-widest uppercase text-[12px]`,children:`Select a User`})]})})]})})]})]})}function re({isOpen:e,title:n,message:r,confirmText:i=`Delete`,cancelText:a=`Cancel`,onConfirm:o,onCancel:c,isProcessing:l=!1,disableConfirm:u=!1}){return(0,s.jsx)(t.s,{children:e&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>!l&&c(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(0,s.jsx)(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:`w-full max-w-[400px] p-6 rounded-3xl glass-popover border border-[var(--panel-border)] shadow-2xl relative z-10 text-center`,children:(0,s.jsxs)(`div`,{className:`w-full flex flex-col items-center`,children:[(0,s.jsx)(`h3`,{className:`text-xl font-extrabold mb-2 text-foreground tracking-tight`,children:n}),(0,s.jsx)(`p`,{className:`w-full text-[14px] font-medium text-foreground/60 leading-relaxed mb-6 break-words`,children:r}),(0,s.jsxs)(`div`,{className:`flex items-center gap-3 w-full`,children:[(0,s.jsx)(t.r,{variant:`secondary`,onClick:c,disabled:l,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:a}),(0,s.jsx)(t.r,{onClick:o,disabled:l||u,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl bg-red-500 hover:bg-red-600 border-none text-white shadow-xl hover:shadow-red-500/20 glow-hover`,children:l?(0,s.jsx)(t.L,{className:`w-5 h-5 animate-spin mx-auto`}):i})]})]})})]})})}var ie=`rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)] transition-colors hover:border-accent/40`,ae=`inline-flex items-center justify-center gap-1.5 h-9 px-3 rounded-[var(--btn-radius,0.75rem)] text-[12.5px] font-semibold border border-[var(--panel-border)] bg-transparent text-foreground/60 hover:text-foreground hover:border-accent/40 hover:bg-foreground/[0.04] active:scale-[0.98] transition-all cursor-pointer disabled:opacity-40 disabled:pointer-events-none`,oe=`w-full h-11 px-4 rounded-[var(--input-radius,0.75rem)] border border-[var(--panel-border)] bg-[var(--panel-bg)] text-[14px] text-foreground outline-none transition-all duration-300 placeholder:text-foreground/35 hover:border-accent/40 focus:border-accent disabled:opacity-50 disabled:cursor-not-allowed console-field`,se=`w-full h-11 flex items-center px-4 rounded-[var(--input-radius,0.75rem)] border border-[var(--panel-border)] bg-[var(--panel-bg)] transition-all duration-300 hover:border-accent/40 focus-within:border-accent console-field`,X=`flex-1 min-w-0 h-full bg-transparent border-none outline-none shadow-none text-[14px] text-foreground placeholder:text-foreground/35 disabled:cursor-not-allowed`,ce=`text-[13px] font-medium text-foreground/50 select-none`;function Z({state:e=`saved`,label:n}){return(0,s.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[11.5px] font-semibold text-foreground/50 whitespace-nowrap shrink-0`,children:[e===`saving`?(0,s.jsx)(t.L,{className:`w-3 h-3 animate-spin text-foreground/40 shrink-0`}):(0,s.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 ${e===`saved`?`bg-emerald-500`:e===`error`?`bg-red-500`:`bg-foreground/25`}`}),n]})}function Q({icon:e,children:n,onClick:r,disabled:i,busy:a,tone:o=`default`,className:c=``,title:l}){return(0,s.jsxs)(`button`,{type:`button`,title:l,onClick:r,disabled:i||a,className:`${ae} ${o===`danger`?`hover:text-red-500 hover:border-red-500/40 hover:bg-red-500/[0.06]`:``} ${c}`,children:[a?(0,s.jsx)(t.L,{className:`w-3.5 h-3.5 animate-spin shrink-0`}):e?(0,s.jsx)(e,{className:`w-3.5 h-3.5 shrink-0`}):null,n]})}function le({icon:e,title:n,description:i,actions:a,children:o,defaultOpen:c=!0,collapsible:l=!0}){let[u,d]=(0,r.useState)(c),f=l?u:!0;return(0,s.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)] overflow-hidden`,children:[(0,s.jsxs)(`div`,{className:`w-full px-5 py-4 flex items-start justify-between gap-4 text-left`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,s.jsxs)(`span`,{className:`flex items-center gap-2 min-w-0`,children:[e&&(0,s.jsx)(e,{className:`w-4 h-4 text-accent shrink-0`}),(0,s.jsx)(`span`,{className:`text-[14.5px] font-bold text-foreground tracking-tight truncate`,children:n})]}),i&&(0,s.jsx)(`span`,{className:`text-[11.5px] text-foreground/40 font-medium leading-snug ${e?`pl-6`:``}`,children:i})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[a,l&&(0,s.jsx)(`button`,{type:`button`,onClick:()=>d(e=>!e),"aria-expanded":f,"aria-label":f?`Collapse ${n}`:`Expand ${n}`,className:`w-8 h-8 rounded-lg flex items-center justify-center text-foreground/40 hover:text-foreground hover:bg-foreground/5 transition-colors cursor-pointer`,children:(0,s.jsx)(t.gt,{className:`w-4 h-4 transition-transform duration-200 ${f?`rotate-180`:``}`})})]})]}),(0,s.jsx)(t.s,{initial:!1,children:f&&(0,s.jsx)(t.o.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden`,children:(0,s.jsx)(`div`,{className:`border-t border-[var(--panel-border)]/60 px-5 py-5 flex flex-col gap-5`,children:o})})})]})}function ue({label:e,hint:t,action:n,children:r,error:i}){return(0,s.jsxs)(`div`,{className:`flex flex-col w-full`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 mb-1.5 ml-1`,children:[(0,s.jsx)(`label`,{className:ce,children:e}),n]}),r,t&&!i&&(0,s.jsx)(`span`,{className:`text-[11.5px] text-foreground/40 font-medium leading-snug mt-1.5 px-1`,children:t}),i&&(0,s.jsx)(`span`,{className:`text-[11.5px] font-semibold text-red-500 leading-snug mt-1.5 px-1`,children:i})]})}function de({label:e,hint:t,value:n,onChange:r,onBlur:i,placeholder:a,prefix:o,error:c,disabled:l,action:u}){return(0,s.jsx)(ue,{label:e,hint:t,error:c,action:u,children:o?(0,s.jsxs)(`div`,{className:`${se} ${c?`is-invalid border-red-500/60`:``} ${l?`opacity-50`:``}`,children:[(0,s.jsx)(`span`,{className:`mr-0.5 text-[14px] font-semibold text-foreground/40 select-none shrink-0`,children:o}),(0,s.jsx)(`input`,{type:`text`,value:n??``,disabled:l,placeholder:a,onChange:e=>r(e.target.value),onBlur:i,"aria-label":e,className:`${X} no-glow`})]}):(0,s.jsx)(`input`,{type:`text`,value:n??``,disabled:l,placeholder:a,onChange:e=>r(e.target.value),onBlur:i,"aria-label":e,className:`${oe} ${c?`is-invalid border-red-500/60`:``}`})})}function fe({label:e,hint:n,value:r,onChange:i,options:a,placeholder:o=`None`,allowEmpty:c=!0,disabled:l}){let u=[...c?[{value:``,label:o}]:[],...a.filter(e=>e.value!==``)];return(0,s.jsx)(ue,{label:e,hint:n,children:(0,s.jsx)(t.n,{ariaLabel:e,value:r??``,options:u,onChange:i,disabled:l,className:`console-select`,portal:!0,direction:`auto`})})}function pe({label:e,hint:t,enabled:n,onChange:r,disabled:i}){return(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-4 w-full`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0 ml-1`,children:[(0,s.jsx)(`span`,{className:`text-[13px] font-medium text-foreground/80`,children:e}),t&&(0,s.jsx)(`span`,{className:`text-[11.5px] text-foreground/40 font-medium leading-snug`,children:t})]}),(0,s.jsx)(me,{enabled:n,onChange:r,disabled:i,label:e})]})}function me({enabled:e,onChange:t,disabled:n,label:r}){return(0,s.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e,"aria-label":r,disabled:n,onClick:n=>{n.stopPropagation(),t(!e)},className:`relative w-10 h-6 rounded-full transition-colors shrink-0 cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed ${e?`bg-accent`:`bg-foreground/15`}`,children:(0,s.jsx)(`span`,{className:`absolute top-1 left-1 w-4 h-4 rounded-full bg-[var(--button-fg,#fff)] shadow transition-transform ${e?`translate-x-4`:`translate-x-0`}`})})}function he({saving:e,savedAt:t}){return e?(0,s.jsx)(Z,{state:`saving`,label:`Saving`}):t?(0,s.jsx)(Z,{state:`saved`,label:`Saved`}):null}var ge=e=>e.trim().split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),_e=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/([A-Z])([A-Z][a-z])/g,`$1-$2`).toLowerCase(),ve=e=>{let t=e.replace(/-/g,` `);return t.charAt(0).toUpperCase()+t.slice(1)},ye=(()=>{let e=t.l,n=e?Object.keys(e):[];return Array.from(new Set(n.map(_e))).sort()})(),be=`layers.house.layout-dashboard.list.table.kanban.calendar.clock.file-text.files.folder.hard-drive.upload.download.paperclip.book-open.notebook-pen.users.user.user-plus.contact.building-2.briefcase.handshake.mail.message-square.message-circle.send.inbox.bell.megaphone.phone.shopping-cart.package.truck.receipt.credit-card.banknote.wallet.tag.percent.chart-bar.chart-line.chart-pie.trending-up.target.gauge.activity.settings.sliders-horizontal.wrench.shield.lock.key.eye.search.star.heart.bookmark.flag.pin.map-pin.globe.circle-check.circle-alert.info.circle-help.life-buoy.sparkles.zap.rocket.camera.image.video.music.mic.palette.pen-tool.scissors.stethoscope.graduation-cap.utensils.plane.car.dumbbell.leaf.sun.moon`.split(`.`),xe={money:[`banknote`,`wallet`,`credit-card`,`coins`,`dollar-sign`,`receipt`],cash:[`banknote`,`coins`,`wallet`],payment:[`credit-card`,`banknote`,`receipt`],invoice:[`receipt`,`file-text`],price:[`tag`,`dollar-sign`,`receipt`],people:[`users`,`user`,`contact`],customer:[`users`,`contact`,`user-round`],client:[`users`,`contact`,`briefcase`],team:[`users`,`users-round`],staff:[`users`,`id-card`],chat:[`message-circle`,`message-square`,`messages-square`],message:[`message-circle`,`mail`,`send`],email:[`mail`,`send`,`inbox`],task:[`list-checks`,`square-check`,`clipboard-check`],todo:[`list-checks`,`square-check`],project:[`kanban`,`folder-kanban`,`briefcase`],board:[`kanban`,`layout-dashboard`],photo:[`image`,`camera`,`images`],picture:[`image`,`images`],document:[`file-text`,`files`,`file`],doc:[`file-text`,`file`],shop:[`shopping-cart`,`store`,`shopping-bag`],store:[`store`,`shopping-bag`,`shopping-cart`],order:[`shopping-cart`,`package`,`receipt`],delivery:[`truck`,`package`],home:[`house`,`home`],booking:[`calendar-check`,`calendar`,`clock`],appointment:[`calendar-clock`,`calendar`,`clock`],schedule:[`calendar-days`,`calendar`,`clock`],event:[`calendar`,`party-popper`,`ticket`],report:[`chart-bar`,`chart-line`,`file-chart-column`],stats:[`chart-bar`,`chart-line`,`chart-pie`],analytics:[`chart-line`,`chart-bar`,`activity`],help:[`circle-help`,`life-buoy`,`info`],support:[`life-buoy`,`headset`,`circle-help`],idea:[`lightbulb`,`sparkles`],health:[`heart-pulse`,`stethoscope`,`activity`],food:[`utensils`,`chef-hat`,`pizza`],travel:[`plane`,`map`,`luggage`],location:[`map-pin`,`map`,`globe`],address:[`map-pin`,`house`],security:[`shield`,`lock`,`key`],password:[`key`,`lock`],settings:[`settings`,`sliders-horizontal`,`wrench`],file:[`file`,`file-text`,`files`,`folder`],upload:[`upload`,`cloud-upload`],video:[`video`,`film`,`clapperboard`],school:[`graduation-cap`,`book-open`,`school`],course:[`graduation-cap`,`book-open`],gym:[`dumbbell`,`activity`],garden:[`leaf`,`flower`,`sprout`],car:[`car`,`car-front`],pet:[`paw-print`,`dog`,`cat`],note:[`notebook-pen`,`sticky-note`,`pencil`],write:[`pencil`,`pen-tool`,`notebook-pen`],time:[`clock`,`timer`,`hourglass`],star:[`star`,`sparkles`],favourite:[`star`,`heart`,`bookmark`],favorite:[`star`,`heart`,`bookmark`]},Se=(e,t)=>{if(Math.abs(e.length-t.length)>2)return 3;let n=Array.from({length:t.length+1},(e,t)=>t);for(let r=1;r<=e.length;r++){let i=n[0];n[0]=r;for(let a=1;a<=t.length;a++){let o=n[a];n[a]=Math.min(n[a]+1,n[a-1]+1,i+(e[r-1]===t[a-1]?0:1)),i=o}}return n[t.length]},Ce=(e,t)=>{let n=0;for(let r of t)r===e[n]&&n++;return n===e.length};function we(e,t=24,n=ye){let r=e.trim().toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``);if(!r)return[];let i=r.split(`-`).filter(Boolean),a=new Set(n),o=new Map,s=(e,t)=>{a.has(e)&&o.set(e,Math.max(o.get(e)||0,t))};for(let e of n){let t=e.split(`-`);if(e===r){s(e,100);continue}if(e.startsWith(r)){s(e,90);continue}if(t.some(e=>e===r)){s(e,85);continue}if(t.some(e=>e.startsWith(r))){s(e,75);continue}if(e.includes(r)){s(e,65);continue}if(i.length>1&&i.every(e=>t.some(t=>t.startsWith(e)))){s(e,60);continue}}for(let e of i){for(let t of xe[e]||[])s(t,70);if(e.endsWith(`s`))for(let t of xe[e.slice(0,-1)]||[])s(t,70)}if(o.size===0&&r.length>=3)for(let e of n)e.split(`-`).some(e=>Se(r,e)<=(r.length>5?2:1))?s(e,40):r.length>=4&&Ce(r,e.replace(/-/g,``))&&s(e,20);let c=e=>{let t=be.indexOf(e);return t===-1?be.length:t};return Array.from(o.entries()).sort((e,t)=>t[1]-e[1]||c(e[0])-c(t[0])||e[0].length-t[0].length||e[0].localeCompare(t[0])).slice(0,t).map(([e])=>e)}function Te(e){if(!e)return t.U;let n=e.trim(),r=t.c;return r[ge(n)]||r[n]||t.U}function Ee({name:e,className:t}){return(0,r.createElement)(Te(e),{className:t})}function De({label:e=`Icon`,hint:n=`Shown next to the name in the menu.`,value:i,onChange:a}){let[o,c]=(0,r.useState)(``),l=(i||``).trim(),u=(0,r.useMemo)(()=>we(o),[o]),d=o.trim().length>0;return(0,s.jsx)(ue,{label:e,hint:n,action:l?(0,s.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[11.5px] font-medium text-foreground/45 min-w-0`,children:[(0,s.jsx)(Ee,{name:l,className:`w-3.5 h-3.5 text-accent shrink-0`}),(0,s.jsx)(`span`,{className:`truncate`,children:ve(_e(l))})]}):void 0,children:(0,s.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,s.jsxs)(`div`,{className:se,children:[(0,s.jsx)(t.E,{className:`w-4 h-4 mr-2.5 text-foreground/30 shrink-0`}),(0,s.jsx)(`input`,{type:`text`,value:o,onChange:e=>c(e.target.value),placeholder:`Type a word to change it, e.g. calendar`,"aria-label":`Search icons`,className:`${X} no-glow`})]}),d&&(0,s.jsx)(`div`,{className:`rounded-[var(--input-radius,0.75rem)] border border-[var(--panel-border)] bg-[var(--panel-bg)] p-2`,children:u.length>0?(0,s.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>{let t=_e(l).toLowerCase()===e;return(0,s.jsx)(`button`,{type:`button`,title:ve(e),"aria-label":ve(e),"aria-pressed":t,onClick:()=>{a(e),c(``)},className:`w-9 h-9 rounded-lg flex items-center justify-center transition-all cursor-pointer ${t?`bg-accent text-[var(--button-fg,#fff)]`:`text-foreground/60 hover:text-foreground hover:bg-foreground/[0.06]`}`,children:(0,s.jsx)(Ee,{name:e,className:`w-4 h-4`})},e)})}):(0,s.jsx)(`span`,{className:`block px-2 py-2 text-[12px] font-medium text-foreground/45`,children:`Nothing close to that. Try a simpler word, like calendar or people.`})})]})})}function Oe({title:e=`Ask your assistant`,description:n,prompt:i,compact:a=!1}){let[o,c]=(0,r.useState)(!1),l=i.includes(`
2
- `);return(0,s.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)] ${a?`px-4 py-3.5`:`px-5 py-4`}`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,s.jsx)(`span`,{className:`text-[12px] font-extrabold tracking-tight text-gradient`,children:e}),(0,s.jsxs)(`button`,{type:`button`,onClick:()=>{navigator.clipboard?.writeText(i),c(!0),setTimeout(()=>c(!1),2e3)},className:`inline-flex items-center justify-center gap-1.5 h-8 px-3 rounded-[var(--btn-radius,0.75rem)] text-[12px] font-semibold shrink-0 border transition-all cursor-pointer active:scale-[0.98] ${o?`border-emerald-500/30 bg-emerald-500/10 text-emerald-500`:`border-[var(--panel-border)] text-foreground/60 hover:text-accent hover:border-accent/40`}`,children:[o?(0,s.jsx)(t._t,{className:`w-3.5 h-3.5`}):(0,s.jsx)(t.at,{className:`w-3.5 h-3.5`}),o?`Copied`:`Copy`]})]}),n&&(0,s.jsx)(`p`,{className:`text-[12.5px] text-foreground/50 font-medium leading-relaxed`,children:n}),(0,s.jsx)(`p`,{className:`text-[13.5px] text-foreground/80 font-medium leading-relaxed whitespace-pre-line`,children:l?i:`“${i}”`})]})}var ke={anyone:{collectionName:`user_submissions`,chip:`Anyone`,filterLabel:`From anyone`},signedIn:{collectionName:`user_requests`,chip:`Signed-in user`,filterLabel:`From signed-in users`}},Ae=`Create a form called Ask a question for website visitors. Ask for full name (required), email (required) and their question as long text (required). Put it on my /contact page built into the page, send the answers to my Inbox, and show a thank-you message after sending.`,je=[`id`,`source`,`uid`,`submittedAt`,`avatarUrl`,`isArchived`,`name`,`full_name`,`email`,`contactEmail`,`topic`],Me=e=>{let t=e.submittedAt;if(!t)return 0;if(typeof t.toMillis==`function`)return t.toMillis();if(typeof t.toDate==`function`)return t.toDate().getTime();let n=new Date(t).getTime();return Number.isNaN(n)?0:n},Ne=e=>{if(!e)return`Just now`;let t=e.toDate?e.toDate():new Date(e);return new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`,hour:`numeric`,minute:`numeric`}).format(t)},Pe=e=>e.submitterName||e.name||e.full_name||`Anonymous`,Fe=e=>e.contactEmail||e.email||`No email provided`;function Ie(e){let[n,a]=(0,r.useState)([]),[o,s]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{let n=!1,r=ke[e].collectionName,o=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,r),(0,i.orderBy)(`submittedAt`,`desc`)),async r=>{let o=[];for(let n of r.docs){let r={...n.data()},a=``;if(r.uid&&r.uid!==`guest`)try{let e=await(0,i.getDoc)((0,i.doc)(t.Pt,`user_profiles`,r.uid));if(e.exists()){let t=e.data();(t.avatar||t.photoURL)&&(a=t.avatar||t.photoURL),r.name||=t.name||t.displayName,r.email||=t.email,r.contactEmail||=t.email}}catch(e){console.error(`Failed to fetch profile`,e)}o.push({...r,id:n.id,source:e,avatarUrl:a})}n||(a(o),s(!1))},e=>{console.error(`Error loading ${r}:`,e),n||s(!1)});return()=>{n=!0,o()}},[e]),{items:n,loading:o}}function Le({source:e}){return(0,s.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest text-accent bg-accent/10 px-2 py-0.5 rounded-md border border-accent/20 shrink-0`,children:ke[e].chip})}function Re({item:e,isExpanded:n,onToggle:r,onArchive:i,onDelete:a,busy:o,dimmed:l}){let u=Pe(e),d=e.avatarUrl||e.submitterAvatar,f=!!e.uid&&e.uid!==`guest`,p=Object.entries(e).filter(([e])=>!je.includes(e)&&!e.toLowerCase().startsWith(`submitter`)&&e.toLowerCase()!==`formid`);return(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-2xl flex flex-col overflow-hidden hover:border-accent/40 transition-all duration-300 ${l?`opacity-60 hover:opacity-100`:``}`,children:[(0,s.jsxs)(`div`,{className:`w-full flex items-center gap-3 p-4 md:px-6`,children:[(0,s.jsxs)(`button`,{type:`button`,onClick:r,"aria-expanded":n,className:`flex items-center gap-4 flex-1 min-w-0 text-left cursor-pointer`,children:[(0,s.jsx)(`div`,{className:`relative shrink-0`,children:d?(0,s.jsx)(`img`,{src:d,alt:``,className:`w-10 h-10 rounded-full object-cover border border-[var(--panel-border)] shadow-sm`}):(0,s.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-accent/10 text-accent flex items-center justify-center font-bold border border-accent/20 shadow-sm uppercase`,children:(u||`A`)[0]})}),(0,s.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,s.jsx)(`span`,{className:`font-bold text-[14px] md:text-[15px] text-foreground truncate`,children:u}),(0,s.jsx)(Le,{source:e.source}),e.formId&&(0,s.jsx)(`span`,{className:`hidden sm:inline text-[10px] font-bold uppercase tracking-widest text-foreground/40 bg-foreground/5 px-2 py-0.5 rounded-md border border-[var(--panel-border)] shrink-0`,children:String(e.formId).replace(/_/g,` `)})]}),(0,s.jsxs)(`span`,{className:`text-[13px] text-foreground/50 truncate flex items-center gap-1.5 font-medium mt-0.5`,children:[(0,s.jsx)(t.P,{className:`w-3.5 h-3.5 shrink-0`}),` `,Fe(e)]})]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`div`,{className:`hidden lg:block text-[12px] font-medium text-foreground/40`,children:Ne(e.submittedAt)}),(0,s.jsx)(Q,{icon:e.isArchived?t.Dt:t.Et,onClick:i,busy:o,children:(0,s.jsx)(`span`,{className:`hidden sm:inline`,children:e.isArchived?`Restore`:`Archive`})}),(0,s.jsx)(Q,{icon:t.y,tone:`danger`,onClick:a,children:(0,s.jsx)(`span`,{className:`hidden sm:inline`,children:`Delete`})}),(0,s.jsx)(`button`,{type:`button`,onClick:r,"aria-label":n?`Hide details from ${u}`:`Show details from ${u}`,className:`p-1.5 text-foreground/40 transition-transform duration-300 cursor-pointer ${n?`rotate-180`:``}`,children:(0,s.jsx)(t.gt,{className:`w-4 h-4`})})]})]}),(0,s.jsx)(t.s,{children:n&&(0,s.jsx)(t.o.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden`,children:(0,s.jsxs)(`div`,{className:`p-4 md:p-6 pt-0 mt-2 border-t border-[var(--panel-border)]/30`,children:[(0,s.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mb-4 mt-4`,children:[(0,s.jsx)(`span`,{className:`lg:hidden text-[12px] font-medium text-foreground/40`,children:Ne(e.submittedAt)}),f&&(0,s.jsx)(c.Link,{to:`/users/${e.uid}`,className:`text-[12.5px] font-bold text-accent hover:underline`,children:`Open this person’s profile`})]}),e.topic&&(0,s.jsxs)(`div`,{className:`flex items-center gap-2 mb-4 text-[13px] text-foreground/70 bg-foreground/5 px-4 py-2.5 rounded-xl w-fit border border-[var(--panel-border)]`,children:[(0,s.jsx)(t.ft,{className:`w-4 h-4 text-accent`}),(0,s.jsx)(`span`,{className:`font-medium text-accent`,children:`Topic:`}),(0,s.jsx)(`span`,{className:`font-bold`,children:e.topic})]}),p.map(([e,t])=>(0,s.jsxs)(`div`,{className:`bg-foreground/[0.02] rounded-2xl p-5 border border-[var(--panel-border)] mb-3`,children:[(0,s.jsx)(`span`,{className:`block text-[12px] font-bold uppercase tracking-widest text-accent mb-3`,children:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}),(0,s.jsx)(`p`,{className:`text-[14px] md:text-[15px] text-foreground/80 leading-relaxed whitespace-pre-wrap font-medium`,children:typeof t==`boolean`?t?`Yes`:`No`:e.toLowerCase()===`budget`&&t?`$${t}`:String(t??``)||`No data provided`})]},e))]})})})]})}function ze(){let e=Ie(`anyone`),n=Ie(`signedIn`),[a,o]=(0,r.useState)(`all`),[c,l]=(0,r.useState)(null),[u,d]=(0,r.useState)(!1),[f,p]=(0,r.useState)(null),[m,h]=(0,r.useState)(null),[g,_]=(0,r.useState)(!1),v=e.loading||n.loading,y=(0,r.useMemo)(()=>[...e.items,...n.items].sort((e,t)=>Me(t)-Me(e)),[e.items,n.items]),b=a===`all`?y:y.filter(e=>e.source===a),x=b.filter(e=>!e.isArchived),S=b.filter(e=>e.isArchived),C=e=>`${e.source}:${e.id}`,w=e=>l(t=>t===C(e)?null:C(e)),T=async e=>{p(C(e));try{await(0,i.updateDoc)((0,i.doc)(t.Pt,ke[e.source].collectionName,e.id),{isArchived:!e.isArchived}),!e.isArchived&&c===C(e)&&l(null)}catch(e){console.error(`Failed to archive`,e)}p(null)},E=async()=>{if(m){_(!0);try{await(0,i.deleteDoc)((0,i.doc)(t.Pt,ke[m.source].collectionName,m.id)),c===C(m)&&l(null),h(null)}catch(e){console.error(`Failed to delete`,e)}_(!1)}},D=[{key:`all`,label:`Everything`},{key:`anyone`,label:ke.anyone.filterLabel},{key:`signedIn`,label:ke.signedIn.filterLabel}];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.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:`Inbox`}),(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`}),`/inbox`]})]}),(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)(ne,{})}),(0,s.jsxs)(`div`,{className:`w-full flex-1 flex flex-col glass-panel rounded-3xl p-6 md:p-10 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/5 blur-[100px] rounded-full pointer-events-none`}),(0,s.jsx)(`div`,{className:`relative z-10 flex-1 flex flex-col`,children:v?(0,s.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[500px]`,children:(0,s.jsx)(`div`,{className:`w-8 h-8 md:w-10 md:h-10 border-4 border-accent/20 border-t-accent rounded-full animate-spin`})}):y.length===0?(0,s.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center p-8 gap-6`,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 shadow-inner`,children:(0,s.jsx)(t.q,{className:`w-6 h-6`})}),(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground mb-2`,children:`Nothing here yet`}),(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/50 font-medium max-w-md`,children:`Everything people send you through a form on your site lands here.`})]}),(0,s.jsx)(`div`,{className:`w-full max-w-xl text-left`,children:(0,s.jsx)(Oe,{prompt:Ae})})]}):(0,s.jsxs)(`div`,{className:`flex flex-col gap-3 pb-8`,children:[(0,s.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 mb-2`,children:D.map(e=>(0,s.jsx)(`button`,{type:`button`,onClick:()=>o(e.key),"aria-pressed":a===e.key,className:`h-9 px-4 rounded-full text-[12.5px] font-bold border transition-all cursor-pointer ${a===e.key?`bg-accent/10 border-accent/40 text-accent`:`border-[var(--panel-border)]/70 bg-background/60 text-foreground/60 hover:text-foreground hover:border-accent/30`}`,children:e.label},e.key))}),x.length===0&&(0,s.jsx)(`div`,{className:`bg-foreground/[0.02] border border-dashed border-[var(--panel-border)] rounded-2xl flex flex-col items-center justify-center p-8 text-center mb-4`,children:(0,s.jsx)(`p`,{className:`text-[14px] font-bold text-foreground/50`,children:S.length>0?`Everything here is archived.`:`Nothing matches this filter.`})}),(0,s.jsx)(t.s,{children:x.map(e=>(0,s.jsx)(Re,{item:e,isExpanded:c===C(e),onToggle:()=>w(e),onArchive:()=>T(e),onDelete:()=>h(e),busy:f===C(e)},C(e)))}),S.length>0&&(0,s.jsxs)(`div`,{className:`mt-6 pt-4 border-t border-[var(--panel-border)]/30`,children:[(0,s.jsx)(`div`,{className:`flex justify-center`,children:(0,s.jsxs)(`button`,{type:`button`,onClick:()=>d(e=>!e),className:`flex items-center gap-2 text-[11px] font-bold text-foreground/40 hover:text-foreground/70 transition-colors py-2 uppercase tracking-widest cursor-pointer`,children:[u?`Hide`:`View`,` `,S.length,` archived`,(0,s.jsx)(t.gt,{className:`w-3.5 h-3.5 transition-transform duration-300 ${u?`rotate-180`:``}`})]})}),(0,s.jsx)(t.s,{children:u&&(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`,children:(0,s.jsx)(`div`,{className:`flex flex-col gap-3`,children:S.map(e=>(0,s.jsx)(Re,{item:e,isExpanded:c===C(e),onToggle:()=>w(e),onArchive:()=>T(e),onDelete:()=>h(e),busy:f===C(e),dimmed:!0},C(e)))})})})]})]})})]})]}),(0,s.jsx)(re,{isOpen:!!m,title:`Delete this message?`,message:`This removes it for good. There is no undo — archive it instead if you only want it out of the way.`,onConfirm:E,onCancel:()=>h(null),isProcessing:g,confirmText:`Yes, delete`})]})}var Be=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]};function Ve({title:e=`Drive`,subtitle:n=`/templates/drive`,backUrl:a=`/templates`,filesCollection:u=`pub_files`,config:d,customContent:f,footer:p}){let{user:m,userRole:h}=A(),g=!!d,_=h===`admin`,v=u,y=u.startsWith(`user_`),[b,x]=(0,r.useState)([]),[S,C]=(0,r.useState)(!0),[w,T]=(0,r.useState)(null),[E,D]=(0,r.useState)(!0),[O,k]=(0,r.useState)(null),[j,M]=(0,r.useState)(!1),[N,P]=(0,r.useState)(null),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)({}),[ee,z]=(0,r.useState)(!1),[B,V]=(0,r.useState)(null),[te,H]=(0,r.useState)(``),[U,W]=(0,r.useState)(!1),[G,K]=(0,r.useState)(``),[q,J]=(0,r.useState)(!1),Y=(0,r.useRef)(null);(0,r.useEffect)(()=>{D(!0)},[w?._id]),(0,r.useEffect)(()=>{if(!(y&&!m))return C(!0),(0,i.onSnapshot)(y?(0,i.query)((0,i.collection)(t.Pt,u),(0,i.where)(`uid`,`==`,m.uid)):(0,i.query)((0,i.collection)(t.Pt,u),(0,i.orderBy)(`createdAt`,`desc`)),e=>{let t=e.docs.map(e=>({_id:e.id,...e.data()}));t.sort((e,t)=>(t.createdAt?.toMillis?.()||0)-(e.createdAt?.toMillis?.()||0)),x(t),C(!1)},e=>{console.warn(`Error listening to ${u}:`,e),C(!1)})},[u,y,m?.uid]);let ie=e=>!!m&&(e.uid===m.uid||_),ae=e=>{V(e),H(e.name),K(``),z(!0)},oe=async e=>{if(e.preventDefault(),!(!B||!te.trim()||!m)){W(!0),K(``);try{let e=`${v}/${`${Date.now()}_${B.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,n=(0,o.ref)(t.It,e);await(0,o.uploadBytes)(n,B,{customMetadata:{ownerId:m.uid}});let r=await(0,o.getDownloadURL)(n);await(0,i.addDoc)((0,i.collection)(t.Pt,u),{fileName:te.trim(),fileType:B.type||`unknown`,fileSize:B.size,downloadURL:r,storagePath:e,uid:m.uid,uploaderEmail:m.email||``,createdAt:(0,i.serverTimestamp)()}),z(!1),V(null),H(``)}catch(e){K(e?.code===`storage/unauthorized`?`You do not have permission to upload here.`:e?.message||`Upload failed. Please try again.`)}W(!1)}},se=async()=>{if(O){M(!0);try{await Promise.all([(0,o.deleteObject)((0,o.ref)(t.It,O.storagePath||O.downloadURL)).catch(e=>console.warn(`Storage object missing:`,e)),(0,i.deleteDoc)((0,i.doc)(t.Pt,u,O._id))]),k(null)}catch(e){console.error(`Delete failed:`,e)}M(!1)}},X=async()=>{if(!N||!N.name.trim()){P(null);return}try{await(0,i.updateDoc)((0,i.doc)(t.Pt,u,N.id),{fileName:N.name.trim()})}catch(e){console.error(`Rename failed:`,e)}P(null)},ce=(e,t)=>{navigator.clipboard.writeText(e),I(t),setTimeout(()=>I(null),2e3)},Z=(e,n=!1)=>{let r=n?`w-16 h-16`:`w-10 h-10`,i=n?`w-8 h-8`:`w-5 h-5`;return e.includes(`video`)||e.includes(`audio`)?(0,s.jsx)(`div`,{className:`${r} flex items-center justify-center bg-purple-500/10 text-purple-500 rounded-lg`,children:(0,s.jsx)(t.f,{className:i})}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,s.jsx)(`div`,{className:`${r} flex items-center justify-center bg-blue-500/10 text-blue-500 rounded-lg`,children:(0,s.jsx)(t.Q,{className:i})}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,s.jsx)(`div`,{className:`${r} flex items-center justify-center bg-yellow-500/10 text-yellow-500 rounded-lg`,children:(0,s.jsx)(t.Et,{className:i})}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,s.jsx)(`div`,{className:`${r} flex items-center justify-center bg-emerald-500/10 text-emerald-500 rounded-lg`,children:(0,s.jsx)(t.ot,{className:i})}):(0,s.jsx)(`div`,{className:`${r} flex items-center justify-center bg-foreground/5 text-foreground/40 rounded-lg`,children:(0,s.jsx)(t.Z,{className:i})})};return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 flex flex-col pt-12 min-h-screen relative`,onDragOver:e=>{e.preventDefault(),J(!0)},onDragLeave:e=>{e.preventDefault(),J(!1)},onDrop:e=>{e.preventDefault(),J(!1),e.dataTransfer.files?.[0]&&ae(e.dataTransfer.files[0])},children:[(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[!g&&(0,s.jsxs)(c.Link,{to:a,className:`inline-flex items-center gap-2 text-[13px] font-bold text-foreground/50 hover:text-accent transition-colors mb-4`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4`}),` Back to templates`]}),(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}),(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`}),n]})]}),g&&(0,s.jsx)(`div`,{className:`mb-6`,children:(0,s.jsx)(ne,{})}),(0,s.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl min-h-[520px] bg-background flex flex-col`,children:[(0,s.jsxs)(`div`,{className:`p-6 md:p-8 flex items-center justify-between gap-6 border-b border-[var(--panel-border)]/50 bg-background/50`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground tracking-tight`,children:`Files`}),(0,s.jsx)(`p`,{className:`text-[13px] mt-2 text-foreground/60 font-medium`,children:y?`Only you can see the files you upload here.`:`Everyone who can open this page can see these files.`})]}),m&&(0,s.jsxs)(t.r,{onClick:()=>{V(null),K(``),z(!0)},className:`flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-bold shadow-md`,children:[(0,s.jsx)(t.k,{className:`w-4 h-4`}),` Add file`]})]}),f?(0,s.jsx)(`div`,{className:`p-6 md:p-8 flex-1`,children:(0,s.jsx)(f,{files:b,loading:S,user:m,uploadFile:ae,deleteFile:k,config:d})}):(0,s.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 relative`,children:[S&&(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`})}),b.length>0?(0,s.jsx)(`div`,{className:`grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:b.map(e=>(0,s.jsxs)(`div`,{className:`flex flex-col bg-background border border-[var(--panel-border)] rounded-2xl hover:border-accent/40 transition-all group overflow-hidden shadow-sm h-[190px] relative`,children:[(0,s.jsxs)(`div`,{className:`absolute top-2 right-2 flex flex-col gap-1 opacity-0 group-hover:opacity-100 transition-opacity z-10 bg-background/90 backdrop-blur-md rounded-lg p-1 border border-[var(--panel-border)] shadow-xl`,children:[(0,s.jsx)(`a`,{href:e.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-1.5 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-blue-500 transition-colors`,title:`Download`,children:(0,s.jsx)(t.rt,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ce(e.downloadURL,e._id)},className:`p-1.5 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-emerald-500 transition-colors`,title:`Copy link`,children:F===e._id?(0,s.jsx)(t._t,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-4 h-4`})}),ie(e)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),P({id:e._id,name:e.fileName})},className:`p-1.5 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-purple-500 transition-colors`,title:`Rename`,children:(0,s.jsx)(t.A,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),k(e)},className:`p-1.5 hover:bg-red-500/10 rounded-md text-foreground/60 hover:text-red-500 transition-colors`,title:`Delete`,children:(0,s.jsx)(t.y,{className:`w-4 h-4`})})]})]}),(0,s.jsx)(`div`,{className:`h-[120px] w-full border-b border-[var(--panel-border)]/50 bg-foreground/[0.02] flex items-center justify-center overflow-hidden relative cursor-pointer`,onClick:()=>T(e),children:e.fileType.startsWith(`image/`)?(0,s.jsxs)(s.Fragment,{children:[L[e._id]!==!1&&(0,s.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-accent/5 z-0`,children:(0,s.jsx)(t.L,{className:`w-5 h-5 text-accent animate-spin`})}),(0,s.jsx)(`img`,{src:e.downloadURL,alt:``,className:`absolute inset-0 w-full h-full object-contain p-2 transition-opacity duration-300 ${L[e._id]===!1?`opacity-100`:`opacity-0`}`,onLoad:()=>R(t=>({...t,[e._id]:!1})),onError:()=>R(t=>({...t,[e._id]:!1}))})]}):Z(e.fileType,!0)}),(0,s.jsxs)(`div`,{className:`p-3 flex flex-col justify-center flex-1 min-w-0`,onClick:()=>!N&&T(e),children:[N?.id===e._id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:N.name,onChange:e=>P({...N,name:e.target.value}),onBlur:X,onKeyDown:e=>{e.key===`Enter`&&X(),e.key===`Escape`&&P(null)},onClick:e=>e.stopPropagation(),className:`no-glow text-[12.5px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full`}):(0,s.jsx)(`span`,{className:`text-[12.5px] font-bold text-foreground truncate select-none group-hover:text-accent transition-colors`,title:e.fileName,children:e.fileName}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/40 font-bold uppercase tracking-wider mt-1 select-none`,children:Be(e.fileSize)})]})]},e._id))}):!S&&(0,s.jsxs)(`div`,{onClick:()=>m&&z(!0),className:`min-h-[320px] flex flex-col items-center justify-center text-center cursor-pointer group`,children:[(0,s.jsx)(t.st,{className:`w-12 h-12 text-foreground/15 mb-4`}),(0,s.jsx)(`p`,{className:`text-[20px] font-bold text-foreground/50 group-hover:text-foreground/70 transition-colors`,children:`No files yet`}),(0,s.jsx)(`p`,{className:`text-[13px] font-medium mt-1 text-foreground/40`,children:m?`Click here or drag a file in to upload`:`Sign in to upload a file`})]})]})]}),p,(0,s.jsx)(t.s,{children:ee&&(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:()=>!U&&z(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(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:`w-full max-w-[480px] border-[var(--panel-border)] border rounded-3xl relative z-10 glass-panel shadow-2xl flex flex-col bg-background`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between p-6 border-b border-[var(--panel-border)]/50`,children:[(0,s.jsx)(`span`,{className:`text-[16px] font-extrabold text-foreground tracking-tight`,children:`Upload a file`}),(0,s.jsx)(`button`,{onClick:()=>!U&&z(!1),className:`text-foreground/40 hover:text-foreground transition-colors`,children:(0,s.jsx)(t.d,{className:`w-5 h-5`})})]}),B?(0,s.jsxs)(`form`,{onSubmit:oe,className:`p-6 flex flex-col gap-6`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-4 bg-foreground/[0.03] p-4 rounded-2xl border border-[var(--panel-border)]`,children:[Z(B.type),(0,s.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0 pr-4`,children:[(0,s.jsx)(`span`,{className:`text-[13px] font-bold text-foreground truncate`,children:B.name}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold uppercase tracking-wider mt-1`,children:Be(B.size)})]}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>!U&&V(null),className:`w-8 h-8 flex items-center justify-center text-foreground/40 hover:text-red-500 rounded-xl hover:bg-red-500/10 transition-colors shrink-0`,children:(0,s.jsx)(t.y,{className:`w-4 h-4`})})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,s.jsx)(`label`,{className:`text-[11px] font-bold text-foreground/50 uppercase tracking-widest pl-1`,children:`File name`}),(0,s.jsx)(`input`,{type:`text`,required:!0,value:te,onChange:e=>H(e.target.value),disabled:U,className:`no-glow w-full bg-foreground/[0.02] border border-[var(--panel-border)] rounded-xl px-4 py-3.5 text-[14px] font-bold text-foreground outline-none focus:border-accent transition-colors`})]}),G&&(0,s.jsx)(`p`,{className:`text-[13px] font-medium text-red-400 bg-red-500/10 border border-red-500/20 rounded-xl p-3`,children:G}),(0,s.jsx)(t.r,{type:`submit`,isLoading:U,className:`w-full py-4 rounded-xl text-[14px] font-bold shadow-lg`,children:U?`Uploading…`:`Upload`})]}):(0,s.jsxs)(`div`,{onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),e.dataTransfer.files?.[0]&&ae(e.dataTransfer.files[0])},className:`p-12 flex flex-col items-center justify-center`,children:[(0,s.jsx)(`div`,{className:`w-20 h-20 rounded-full bg-foreground/5 flex items-center justify-center mb-5 border-2 border-dashed border-[var(--panel-border)]`,children:(0,s.jsx)(t.st,{className:`w-8 h-8 text-foreground/40`})}),(0,s.jsx)(`p`,{className:`text-[15px] font-bold text-foreground mb-1`,children:`Drag and drop a file here`}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/50 font-medium mb-8`,children:`or click to browse`}),(0,s.jsx)(`input`,{type:`file`,ref:Y,onChange:e=>e.target.files?.[0]&&ae(e.target.files[0]),className:`hidden`}),(0,s.jsx)(t.r,{onClick:()=>Y.current?.click(),className:`px-8 py-3 rounded-full font-bold shadow-md`,children:`Browse files`})]})]})]})}),typeof window<`u`&&(0,l.createPortal)((0,s.jsx)(t.s,{children:w&&(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:()=>T(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:()=>T(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`,children:(0,s.jsx)(t.d,{className:`w-5 h-5`})}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col 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`,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:w.fileName}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[w.fileType,` • `,Be(w.fileSize)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>ce(w.downloadURL,w._id),className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-emerald-500 transition-colors rounded-xl`,title:`Copy link`,children:F===w._id?(0,s.jsx)(t._t,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-4 h-4`})}),ie(w)&&(0,s.jsx)(`button`,{onClick:()=>{let e=w;T(null),k(e)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl`,title:`Delete`,children:(0,s.jsx)(t.y,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:w.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-0 h-[70vh]`,children:(0,s.jsxs)(`div`,{className:`absolute inset-4 md:inset-8 flex items-center justify-center`,children:[E&&(0,s.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center z-50 pointer-events-none`,children:(0,s.jsx)(t.L,{className:`w-6 h-6 text-accent animate-spin`})}),w.fileType.startsWith(`image/`)?(0,s.jsx)(`img`,{onLoad:()=>D(!1),src:w.downloadURL,alt:w.fileName,className:`block max-w-full max-h-full w-auto h-auto object-contain rounded-lg transition-opacity duration-500 ${E?`opacity-0`:`opacity-100`}`}):w.fileType.startsWith(`video/`)?(0,s.jsx)(`video`,{onLoadedData:()=>D(!1),src:w.downloadURL,controls:!0,className:`max-w-full max-h-full rounded-lg transition-opacity duration-500 ${E?`opacity-0`:`opacity-100`}`}):w.fileType===`application/pdf`?(0,s.jsx)(`iframe`,{onLoad:()=>D(!1),src:w.downloadURL,className:`w-full h-full border-none bg-white rounded-lg transition-opacity duration-500 ${E?`opacity-0`:`opacity-100`}`,title:`PDF preview`}):(0,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center text-foreground/40 text-center`,onClick:()=>D(!1),children:[(0,s.jsx)(t.Z,{className:`w-24 h-24 mb-6 opacity-40`}),(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 format cannot be previewed. Download it instead.`})]})]})})]})]})}),document.body),(0,s.jsx)(re,{isOpen:!!O,title:`Delete file`,message:(0,s.jsxs)(s.Fragment,{children:[`Delete `,(0,s.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left break-words max-w-full`,children:O?.fileName}),` This cannot be undone.`]}),onConfirm:se,onCancel:()=>k(null),isProcessing:j,confirmText:`Yes, delete`}),(0,s.jsx)(t.s,{children:q&&(0,s.jsx)(t.o.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`fixed inset-0 z-[1000] bg-background/60 backdrop-blur-md pointer-events-none flex items-center justify-center p-6`,children:(0,s.jsxs)(`div`,{className:`w-full max-w-lg aspect-video bg-background/80 border-2 border-dashed border-accent rounded-[40px] shadow-2xl flex flex-col items-center justify-center gap-6`,children:[(0,s.jsx)(`div`,{className:`w-20 h-20 rounded-full bg-accent/10 flex items-center justify-center text-accent`,children:(0,s.jsx)(t.st,{className:`w-10 h-10 animate-bounce`})}),(0,s.jsx)(`span`,{className:`text-[24px] font-extrabold text-foreground tracking-tight`,children:`Drop to upload`})]})})})]})}var He=[`mem_files`,`user_files`,`admin_files`],Ue=e=>!e.sourceTab;function We(){let[e,n]=(0,r.useState)(null),[a,c]=(0,r.useState)(!1),[l,u]=(0,r.useState)(!1),[d,f]=(0,r.useState)(``),[p,m]=(0,r.useState)(0);(0,r.useEffect)(()=>{let e=!1;return Promise.all(He.map(async e=>{try{return(await(0,i.getDocs)((0,i.collection)(t.Pt,e))).docs.map(t=>({collectionName:e,id:t.id,...t.data()}))}catch{return[]}})).then(t=>{e||n(t.flat())}),()=>{e=!0}},[]);let h=async()=>{if(!e)return;u(!0),f(``);let r=0;for(let n of e)try{let e=n.storagePath||n.downloadURL;e&&Ue(n)&&await(0,o.deleteObject)((0,o.ref)(t.It,e)).catch(()=>{}),await(0,i.deleteDoc)((0,i.doc)(t.Pt,n.collectionName,n.id)),m(e=>e+1)}catch(e){r+=1,console.error(`Could not delete ${n.collectionName}/${n.id}:`,e)}r>0?(f(`${r} file${r===1?``:`s`} could not be deleted. Reload and try again.`),n((await Promise.all(He.map(async e=>{try{return(await(0,i.getDocs)((0,i.collection)(t.Pt,e))).docs.map(t=>({collectionName:e,id:t.id,...t.data()}))}catch{return[]}}))).flat())):n([]),u(!1),c(!1)};if(!e||e.length===0)return null;let g=e.filter(Ue).length,_=He.map(t=>({name:t,n:e.filter(e=>e.collectionName===t).length})).filter(e=>e.n>0);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`mt-6 glass-panel border border-amber-500/25 bg-amber-500/[0.03] rounded-3xl p-6 md:p-8`,children:[(0,s.jsxs)(`h3`,{className:`text-[17px] font-extrabold text-foreground tracking-tight mb-2`,children:[e.length,` leftover record`,e.length===1?``:`s`,` from the old Drive`]}),(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/60 leading-relaxed mb-3 max-w-2xl`,children:`Drive used to have Internal, User and Admin folders. They are gone — this page is the only built-in folder now, and each page you have built keeps its own files. Nothing reads these records any more.`}),(0,s.jsxs)(`p`,{className:`text-[14px] text-foreground/60 leading-relaxed mb-3 max-w-2xl`,children:[g>0?`${g} ${g===1?`was`:`were`} uploaded through the old Drive screen, so ${g===1?`its file is`:`their files are`} deleted too. `:``,e.length-g>0?`${e.length-g} belong to files a page still shows, so only the leftover record goes — the ${e.length-g===1?`file stays`:`files stay`} where ${e.length-g===1?`it is`:`they are`}.`:``]}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/50 font-medium mb-5`,children:_.map(e=>`${e.n} in ${e.name}`).join(` · `)}),d&&(0,s.jsx)(`p`,{className:`text-[13px] font-medium text-red-400 bg-red-500/10 border border-red-500/20 rounded-xl p-3 mb-4`,children:d}),(0,s.jsxs)(`button`,{onClick:()=>c(!0),disabled:l,className:`inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-bold bg-red-500/10 hover:bg-red-500/20 text-red-500 border border-red-500/20 transition-colors disabled:opacity-50`,children:[l?(0,s.jsx)(t.L,{className:`w-4 h-4 animate-spin`}):(0,s.jsx)(t.y,{className:`w-4 h-4`}),l?`Deleting ${p} of ${e.length}…`:`Clean up all ${e.length} permanently`]})]}),(0,s.jsx)(re,{isOpen:a,title:`Delete the old Drive files`,message:(0,s.jsxs)(s.Fragment,{children:[`This permanently deletes `,(0,s.jsxs)(`strong`,{className:`text-foreground`,children:[e.length,` leftover record`,e.length===1?``:`s`]}),` `,`from `,_.map(e=>e.name).join(`, `),g>0&&(0,s.jsxs)(s.Fragment,{children:[`, along with the `,(0,s.jsxs)(`strong`,{className:`text-foreground`,children:[g,` file`,g===1?``:`s`]}),` uploaded through the old Drive screen`]}),`. It cannot be undone, and it covers every user's uploads, not only your own. Files that a page still shows are left alone.`]}),onConfirm:h,onCancel:()=>c(!1),isProcessing:l,confirmText:`Yes, delete them`})]})}function Ge(){let{isAdmin:e}=A();return(0,s.jsx)(Ve,{title:`Assets`,subtitle:`/assets`,filesCollection:`pub_files`,config:{isAdmin:!0,pageId:`assets`},footer:e?(0,s.jsx)(We,{}):null})}function Ke(){let e=[{id:`form`,title:`Inline Form`,description:`A contact form built straight into the page, so people can write to you without leaving it.`,icon:t.B,path:`/templates/inline_form`,prompt:`Create a page anyone can visit at /contact-us, called Contact in the site menu, with the heading Get in touch, using the inline form template as the reference. Build the form into the page, asking for full name (required), email (required) and message as long text (required). Send the answers to my Inbox and show a thank-you message after sending.`},{id:`popup`,title:`Modal Popup Form`,description:`A button that opens the form in a popup over the page, with the background softly blurred.`,icon:t.Ot,path:`/templates/popup_form`,prompt:`Create a page anyone can visit at /enquire, called Enquire in the site menu, with the heading Tell us what you need, using the pop-up form template as the reference. Put a button that says Start an enquiry which opens a form asking for full name (required), email (required) and a short message. Send the answers to my Inbox and show a thank-you message after sending.`},{id:`confirmation`,title:`Action Confirmation`,description:`A short "are you sure?" step that appears before anything is deleted or sent.`,icon:t.vt,path:`/templates/confirmation`,prompt:`On every page of mine where something can be deleted, ask me to confirm first with a pop-up that says Delete this? and two buttons, Cancel and Delete, using the confirmation template as the reference.`},{id:`board`,title:`Board View`,description:`Cards in columns that you drag from one stage to the next, for work in progress.`,icon:t.G,path:`/templates/board`,prompt:`Create a page for my team at /onboarding, called Onboarding in the dashboard, with the heading Client onboarding, using the board template as the reference. Columns: To do, In progress and Done. Each card has a client name, a contact email and a short note.`},{id:`table`,title:`Data Table`,description:`Rows and columns for longer lists, with sorting and actions on many rows at once.`,icon:t.b,path:`/templates/table`,prompt:`Create a page for my team at /customers, called Customers in the dashboard, with the heading Our customers, using the table template as the reference. Columns: name, email, phone and status (Lead, Active, Past). Everyone on the team sees the same rows and can add, edit and delete them.`},{id:`calendar`,title:`Calendar View`,description:`A month at a time, for anything that belongs on a date — bookings, shifts, deadlines.`,icon:t.bt,path:`/templates/calendar`,prompt:`Create a page for my team at /appointments, called Appointments in the dashboard, with the heading Appointments, using the calendar template as the reference. Each appointment has a client name, a start time, a length in minutes and a note. Everyone on the team sees the same calendar.`},{id:`drive`,title:`Drive View`,description:`A file library with upload, preview, rename and delete. The demo writes to the Assets folder, so uploading from here is something only admins can do.`,icon:t.Y,path:`/templates/drive`,prompt:`Create a page only admins can open at /documents, called Documents in the dashboard, with the heading Shared documents, using the drive template as the reference, where admins can upload, preview, rename and delete files.`}];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`,children:[(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-10 text-center`,children:[(0,s.jsx)(`h1`,{className:`w-fit mx-auto inline-block text-4xl md:text-5xl lg:text-[4.8rem] leading-[1.1] font-extrabold tracking-tight mb-4 text-gradient animate-float`,children:`What your assistant can build`}),(0,s.jsx)(`p`,{className:`text-foreground/60 text-lg font-medium max-w-2xl mx-auto`,children:`Every layout below already works. Look at one, then copy the sentence underneath it and paste it to your assistant to get a page like it.`}),(0,s.jsxs)(`p`,{className:`text-foreground/50 text-[13.5px] font-medium max-w-2xl mx-auto mt-3`,children:[`New here?`,` `,(0,s.jsx)(c.Link,{to:`/guide`,className:`text-accent font-bold hover:underline`,children:`Start with the guide`}),`.`]})]}),(0,s.jsxs)(`div`,{className:`w-full max-w-4xl mx-auto flex flex-col gap-4 relative`,children:[(0,s.jsx)(`div`,{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[80%] h-[80%] bg-accent/5 blur-[120px] rounded-full pointer-events-none -z-10`}),e.map((e,n)=>{let r=e.icon;return(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:n*.05},className:`flex flex-col gap-3 w-full p-4 md:p-6 glass-panel border border-[var(--panel-border)] rounded-2xl hover:border-accent/40 transition-all duration-300 group`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-4 md:gap-6`,children:[(0,s.jsx)(`div`,{className:`w-12 h-12 rounded-xl bg-accent/10 flex items-center justify-center text-accent shrink-0 border border-accent/20 group-hover:scale-105 transition-transform`,children:(0,s.jsx)(r,{className:`w-5 h-5`})}),(0,s.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold text-foreground`,children:e.title}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/50 font-medium leading-snug`,children:e.description})]}),(0,s.jsxs)(c.Link,{to:e.path,className:`hidden md:flex items-center gap-2 text-[13px] font-bold px-5 py-2.5 rounded-xl btn-primary shrink-0 transition-transform shadow-lg hover:-translate-y-0.5`,children:[`View `,(0,s.jsx)(`span`,{className:`font-black leading-none ml-0.5`,children:`→`})]})]}),(0,s.jsx)(Oe,{title:`Ask your assistant for this`,prompt:e.prompt,compact:!0}),(0,s.jsxs)(c.Link,{to:e.path,className:`md:hidden inline-flex items-center justify-center gap-2 text-[13px] font-bold px-5 py-2.5 rounded-xl btn-primary transition-transform shadow-lg`,children:[`View `,(0,s.jsx)(`span`,{className:`font-black leading-none ml-0.5`,children:`→`})]})]},e.id)})]})]})}var qe=`Xl271wWblkY`,Je=[{term:`Who it is for`,body:`One of the four audiences below. It decides who can open the page and which menu it appears in. Ask the chat only for pages anyone can visit — dashboard pages are added on the Pages screen, see the three steps below.`,example:`Create a page anyone can visit.`},{term:`The web address`,body:`Starts with a slash. It is the address people type or click, and it never changes unless you change it on the Pages screen.`,example:`Web address: /pricing.`},{term:`The name in the menu`,body:`The word people click to get there.`,example:`Name in the site menu: Pricing.`},{term:`The heading`,body:`The title at the top of the page.`,example:`Heading: Our prices.`},{term:`What is on it`,body:`The sections from top to bottom, with the exact words for every heading and button, and what each button does.`,example:`Three plans side by side, each with a price and a button that says Choose this plan.`},{term:`Where to start`,body:`For a page in the dashboard you pick this on the Pages screen when you add it — board, table, calendar, files, or from scratch. In the chat, only say whether people can upload files.`,example:`No file uploads.`},{term:`The questions`,body:`For a form: every question, its kind, and whether it is required. Kinds: short text, long text, email, phone, number, money, yes-no, or choose one with the choices listed.`,example:`Budget (money in dollars, optional).`},{term:`After sending`,body:`Stay and show a message, go to the home page, or go to another page by its web address.`,example:`After sending, stay on the page and show Thanks, we will reply today.`},{term:`What to leave alone`,body:`End with "Build only this" and name anything that must not change. Without it the assistant adds pages, sample data and sections you did not ask for.`,example:`Build only this — no other pages, forms or sample data.`}],Ye=[{name:`Anyone`,how:`Say: a page anyone can visit`,who:`Everybody, signed in or not. This is your public website, and the page shows in the site menu.`},{name:`Signed-in users`,how:`Pick it when you add the page`,who:`Anyone who registers. Each person sees only their own information, never anyone else’s.`},{name:`Your team`,how:`Pick it when you add the page`,who:`Only people you marked as team members on the Users screen, plus admins. Everyone on it sees the same information.`},{name:`Admins only`,how:`Pick it when you add the page`,who:`You, and anyone you marked as an admin.`}],Xe=[{title:`Add the page on the Pages screen`,body:`Press Add a page and pick who it is for — Your team, Signed-in users or Admins only. Give it a name, a web address and a starting layout: board, table, calendar, files, or from scratch.`},{title:`If it needs a form, add that on the Forms screen`,body:`Press New form, write the questions and choose who can fill it in. Then open the page on the Pages screen and pick the form in its Form box.`},{title:`Ask your assistant to fill it`,body:`Open the page on the Pages screen and copy the sentence under Ask your assistant to fill this page. Paste it into the chat and finish it with what the page should show — the finished requests below are examples of that part.`}],Ze=[{screen:`Pages`,path:`/pages`,body:`Add a page for your team, signed-in users or admins. Rename a page, change its web address, icon or starting layout, link a different form, reorder it, hide it or delete it.`},{screen:`Forms`,path:`/forms`,body:`Add a form and its questions, choose who can fill it in, and change a form’s title and the words on its button.`},{screen:`Theme`,path:`/theme`,body:`Colours, typeface, corner rounding, the logo, and whether the site opens light or dark.`},{screen:`Users`,path:`/users`,body:`Mark a person as a team member or an admin.`},{screen:`Inbox`,path:`/inbox`,body:`Read every answer people sent through your forms.`}],Qe=[{title:`One page or one form per message`,body:`Describe it completely, then send. Ask for the next one when the first is live.`},{title:`Give every detail up front`,body:`If a part of the recipe is missing, the assistant stops to ask for it. Answer with just that part.`},{title:`Use the exact words you want to see`,body:`Headings, button labels, choices in a list. The assistant copies them; it does not improve them.`},{title:`When something is wrong, describe your screen`,body:`The web address, what you clicked, what happened, what you expected. Not what you think the cause is.`},{title:`Never accept homework`,body:`The assistant makes every change itself. If a reply ends with something for you to edit, paste or run, answer: "Do that for me."`}],$e=[{id:`website`,title:`Pages anyone can visit`,description:`Your public website. They appear in the site menu.`,prompts:[{title:`A pricing page with a quote form`,prompt:`Create a page anyone can visit.
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-DYteiM-1.cjs`),t=require(`./ContactPopup-DY0VLjCP.cjs`),n=require(`./PhoneInputField-CQ7ylxOC.cjs`);let r=require(`react`);r=e.i(r,1);let i=require(`firebase/firestore`),a=require(`firebase/auth`),o=require(`firebase/storage`),s=require(`react/jsx-runtime`),c=require(`react-router-dom`),l=require(`react-dom`);var u=Object.assign({"./contactForm.config.ts":t.Vt,"./supportForm.config.ts":t.zt}),d={};for(let e in u){let t=u[e];if(!t)continue;let n=null;for(let e in t)if(e.endsWith(`FormConfig`)||e.endsWith(`Config`)){n=t[e];break}if(!n&&t?.default&&(n=t.default),!n)continue;let r=e.replace(`./`,``).replace(`.config.ts`,``).replace(/Form$/,``).toLowerCase(),i={...n,systemName:n.systemName||r};d[r]=i,i.systemName&&(d[i.systemName]=i,d[i.systemName.toLowerCase()]=i)}if(typeof window<`u`){let e=window.__FBOS_FORMS__||{};window.__FBOS_FORMS__={...d,...e}}var f=Object.assign({}),p=Object.assign({}),m={};for(let e in f){let t=f[e];if(!t)continue;let n=null;for(let e in t)if(e.endsWith(`TabConfig`)||e.endsWith(`Config`)){n=t[e];break}if(!n&&t?.default&&(n=t.default),!n)continue;let r=e.replace(`./`,``).replace(`.config.ts`,``).replace(/Tab$/,``).toLowerCase(),i={config:{...n,pageId:n.pageId||r,tabName:n.tabName||n.title||r},isPublic:!1};m[r]=i,i.config.pageId&&(m[i.config.pageId]=i,m[i.config.pageId.toLowerCase()]=i)}for(let e in p){let t=p[e];if(!t)continue;let n=null;for(let e in t)if(e.endsWith(`PageConfig`)||e.endsWith(`Config`)){n=t[e];break}if(!n&&t?.default&&(n=t.default),!n)continue;let r=e.replace(`./`,``).replace(`.config.ts`,``).replace(/Page$/,``).toLowerCase(),i={config:{...n,pageId:n.pageId||r,pageName:n.pageName||n.title||r},isPublic:!0};m[r]=i,i.config.pageId&&(m[i.config.pageId]=i,m[i.config.pageId.toLowerCase()]=i)}if(typeof window<`u`){let e=window.__FBOS_PAGES__||{};window.__FBOS_PAGES__={...m,...e}}var h=[`free`,`internal`,`admin`],g=[`user`,`internal`,`admin`],_={free:`Free`,internal:`Internal`,admin:`Admin`},v={free:`Pages for anyone, plus their own pages. Your team’s pages stay hidden.`,internal:`Everything a signed-in user sees, plus every page for your team.`,admin:`Full access, including Users, Pages, Forms, Inbox, Theme and Assets.`};function y(e){return e===`admin`?`admin`:e===`internal`?`internal`:`free`}function b(e){return e===`free`?`user`:e}var x=e=>y(e)===`admin`,S=e=>y(e)!==`free`;function C(e){return e===`admin`?`admin`:e===`public`?`public`:e===`internal`||e===`shared`?`internal`:`user`}function w(e){let t=C(e);return t===`public`?`user`:t}function T(e,t){switch(C(t)){case`public`:return!0;case`admin`:return x(e);case`internal`:return S(e);case`user`:return!0}}function E(e,t=!0){if(!t)return`guest`;let n=y(e);return n===`free`?`user`:n}function D(e){switch(C(e)){case`public`:return[`admin`,`internal`,`user`,`guest`];case`admin`:return[`admin`];case`internal`:return[`admin`,`internal`];case`user`:return[`admin`,`internal`,`user`]}}var O=(0,r.createContext)({user:null,userRole:null,accessLevel:`free`,isInternal:!1,isAdmin:!1,loading:!0,signOut:async()=>{},registerUser:async()=>{},refreshUser:async()=>{},userInactive:!1,roleResolved:!1,activeOrg:null,activeWorkspace:null,checkOrg:async()=>{},workspaceAccess:{},userWorkspaces:[],switchWorkspace:async()=>{},createWorkspace:async()=>{},createOrg:async()=>{}});function k({children:e}){let n=t.Mt(),[o,c]=(0,r.useState)(null),[l,u]=(0,r.useState)(null),[d,f]=(0,r.useState)(!1),[p,m]=(0,r.useState)(!0),[h,g]=(0,r.useState)(!1),_=r.default.useRef(null),v=r.default.useRef(null),b=r.default.useMemo(()=>{let e=``;try{e={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}?.VITE_ADMIN_EMAILS||``}catch{}return(n.adminEmails||(e?e.split(`,`):[])).map(e=>e.trim().toLowerCase()).filter(Boolean)},[n.adminEmails]),C=b.join(`,`),w=r.default.useRef(b);(0,r.useEffect)(()=>{w.current=b},[b]);let T=e=>!!e&&w.current.includes(e.toLowerCase()),E=e=>(0,i.updateDoc)((0,i.doc)(t.Pt,`user_profiles`,e),{role:`admin`}).catch(e=>console.error(`Error auto-setting admin role:`,e));return(0,r.useEffect)(()=>{let e;if(!t.Nt){m(!1),g(!0);return}(0,a.getRedirectResult)(t.Nt).catch(()=>{});let n=(0,a.onAuthStateChanged)(t.Nt,async n=>{if(n?.uid===v.current&&h){c(n);return}if(v.current=n?.uid||null,n){let r=localStorage.getItem(`fbos_role_${n.uid}`);r&&(u(r),g(!0),m(!1)),console.log(`[AuthContext] 1. onAuthStateChanged fired for user:`,n.uid),c(n);try{let r=(0,i.doc)(t.Pt,`user_profiles`,n.uid),a=(await(0,i.getDoc)(r)).data()||{};(0,i.setDoc)(r,{uid:n.uid,email:n.email,displayName:n.displayName||a.displayName||``,lastLoginAt:new Date().toISOString(),createdAt:a.createdAt||new Date().toISOString()},{merge:!0}).catch(e=>console.error(`Failed to sync profile:`,e)),e&&e(),e=(0,i.onSnapshot)(r,e=>{if(e.exists()){let r=e.data(),i=r.role||`user`;!r.role&&t.Nt.currentUser?.emailVerified&&T(n.email)&&(i=`admin`,E(n.uid)),_.current===null&&(_.current=i),u(i),localStorage.setItem(`fbos_role_${n.uid}`,i),f(r.inactive===!0)}g(!0),m(!1)},e=>{console.warn(`[AuthContext] user_profiles snapshot error (safe to ignore during auth transition):`,e),g(!0),m(!1)})}catch(e){console.error(`[AuthContext] ERROR in auth resolution:`,e),g(!0),m(!1)}}else console.log(`[AuthContext] No user currently signed in.`),c(null),u(null),f(!1),g(!0),m(!1),_.current=null,e&&e()});return()=>{n(),e&&e()}},[]),(0,r.useEffect)(()=>{if(!o?.emailVerified||l===`admin`||!T(o.email))return;let e=!1;return(0,i.getDoc)((0,i.doc)(t.Pt,`user_profiles`,o.uid)).then(t=>{!e&&t.exists()&&!t.data().role&&E(o.uid)}).catch(()=>{}),()=>{e=!0}},[o?.uid,o?.emailVerified,l,C]),(0,s.jsx)(O.Provider,{value:{user:o,userRole:l,accessLevel:y(l),isInternal:S(l),isAdmin:x(l),loading:p,signOut:async()=>{await(0,a.signOut)(t.Nt),c(null)},registerUser:async(e,n,r,o)=>{let{createUserWithEmailAndPassword:s}=await import(`firebase/auth`),{user:c}=await s(t.Nt,e,n),l=`${r} ${o}`.trim();await(0,a.updateProfile)(c,{displayName:l});try{await c.getIdToken(!0),await(0,i.setDoc)((0,i.doc)(t.Pt,`user_profiles`,c.uid),{uid:c.uid,email:c.email,displayName:l,createdAt:new Date().toISOString()},{merge:!0})}catch(e){console.warn(`Could not write public profile on registration.`,e)}await(0,a.sendEmailVerification)(c)},refreshUser:async()=>{t.Nt.currentUser&&(await t.Nt.currentUser.reload(),c(Object.assign(Object.create(t.Nt.currentUser),{photoURL:t.Nt.currentUser.photoURL,displayName:t.Nt.currentUser.displayName,email:t.Nt.currentUser.email,emailVerified:t.Nt.currentUser.emailVerified})))},userInactive:d,roleResolved:h},children:e})}var A=()=>(0,r.useContext)(O);function j(){return(typeof window<`u`?window.__FBOS_PAGES__:null)||{}}function M(e=j()){let t=new Set,n=[];for(let[r,i]of Object.entries(e))!i||t.has(i)||(t.add(i),n.push([r,i]));return n}function N(){let[e,n]=(0,r.useState)(!1),[a,o]=(0,r.useState)([]),l=(0,r.useRef)(null),u=(0,c.useNavigate)();(0,r.useEffect)(()=>{function e(e){l.current&&!l.current.contains(e.target)&&n(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let d=(0,r.useRef)({users:[],submissions:[],requests:[]}),f=(e,t)=>{d.current[e]=t;let n=[...d.current.users,...d.current.submissions,...d.current.requests];n.sort((e,t)=>{let n=e.time?.toDate?e.time.toDate().getTime():new Date(e.time).getTime();return((t.time?.toDate?t.time.toDate().getTime():new Date(t.time).getTime())||0)-(n||0)}),o(n.slice(0,8))};(0,r.useEffect)(()=>{let e=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,`user_profiles`),(0,i.orderBy)(`createdAt`,`desc`),(0,i.limit)(5)),e=>{f(`users`,e.docs.map(e=>{let t=e.data();return{id:`u_${e.id}`,type:`user`,title:`New user registered`,subtitle:t.email||`Unknown`,time:t.createdAt}}))}),n=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,`user_submissions`),(0,i.orderBy)(`submittedAt`,`desc`),(0,i.limit)(5)),e=>{f(`submissions`,e.docs.map(e=>{let t=e.data();return{id:`s_${e.id}`,type:`submission`,title:`New form submission`,subtitle:t.name||t.email||`Anonymous`,time:t.submittedAt}}))}),r=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,`user_requests`),(0,i.orderBy)(`submittedAt`,`desc`),(0,i.limit)(5)),e=>{f(`requests`,e.docs.map(e=>{let t=e.data();return{id:`r_${e.id}`,type:`request`,title:`New support request`,subtitle:t.name||t.submitterName||t.contactEmail||t.email||`Anonymous`,time:t.submittedAt}}))});return()=>{e(),n(),r()}},[]);let[p,m]=(0,r.useState)(()=>typeof window<`u`?parseInt(localStorage.getItem(`admin_notifications_last_read`)||`0`,10):0),h=()=>{let t=!e;if(n(t),t){let e=Date.now();m(e),typeof window<`u`&&localStorage.setItem(`admin_notifications_last_read`,e.toString())}},g=a.some(e=>{if(!e.time)return!0;let t=e.time?.toDate?e.time.toDate().getTime():new Date(e.time).getTime();return t>p||isNaN(t)}),_=e=>{n(!1),u(e===`user`?`/users`:e===`submission`?`/submissions`:`/requests`)},v=e=>{if(!e)return``;let t=e.toDate?e.toDate():new Date(e);return new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`,hour:`numeric`,minute:`numeric`}).format(t)};return(0,s.jsxs)(`div`,{className:`relative z-50 flex-shrink-0 mr-1 md:mr-2`,ref:l,children:[(0,s.jsxs)(`button`,{onClick:h,className:`p-2 rounded-xl glass-panel transition-all border border-transparent relative text-notification-icon hover:bg-foreground/5 hover:border-[var(--panel-border)]`,"aria-label":`Admin Notifications`,children:[(0,s.jsx)(t.xt,{className:`w-4 h-4 md:w-5 md:h-5`}),g&&(0,s.jsx)(`span`,{className:`absolute top-1.5 right-1.5 w-2 h-2 bg-red-500 rounded-full animate-pulse`})]}),(0,s.jsx)(t.s,{children:e&&(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:-5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98,y:-5},className:`absolute top-full mt-2 right-[-60px] md:right-0 w-[320px] md:w-[400px] glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col origin-top-right overflow-hidden`,children:[(0,s.jsxs)(`div`,{className:`px-4 border-b border-[var(--panel-border)]/50 pb-3 pt-4 flex items-center justify-between`,children:[(0,s.jsx)(`span`,{className:`font-bold text-[14px] text-foreground tracking-wide`,children:`Notifications`}),(0,s.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest text-accent bg-accent/10 px-2 py-0.5 rounded-md`,children:`Admin`})]}),(0,s.jsx)(`div`,{className:`max-h-[350px] overflow-y-auto w-full p-2 flex flex-col gap-1`,children:a.length===0?(0,s.jsx)(`div`,{className:`p-6 text-center text-foreground/40 text-[13px] font-medium`,children:`No recent activity.`}):a.map(e=>(0,s.jsxs)(`button`,{onClick:()=>_(e.type),className:`w-full flex items-start gap-3 p-3 rounded-xl hover:bg-foreground/5 transition-all text-left group border border-transparent hover:border-[var(--panel-border)]`,children:[(0,s.jsx)(`div`,{className:`mt-0.5 w-8 h-8 rounded-full flex items-center justify-center shrink-0 bg-foreground/5 text-notification-icon`,children:e.type===`user`?(0,s.jsx)(t.m,{className:`w-4 h-4`}):e.type===`submission`?(0,s.jsx)(t.P,{className:`w-4 h-4`}):(0,s.jsx)(t.lt,{className:`w-4 h-4`})}),(0,s.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0 pr-2`,children:[(0,s.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground group-hover:text-accent transition-colors truncate`,children:e.title}),(0,s.jsx)(`span`,{className:`text-[12px] text-foreground/60 truncate`,children:e.subtitle}),(0,s.jsx)(`span`,{className:`text-[10px] font-mono tracking-wide text-foreground/40 mt-1`,children:v(e.time)})]})]},e.id))})]})})]})}var P=[{id:`guide`,hidden:!1},{id:`contact`,hidden:!1},{id:`templates`,hidden:!1},{id:`setup`,hidden:!1}],F={drive:`assets`,submissions:`inbox`,requests:`inbox`},I=e=>{let t=(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden}).map(e=>({...e,id:F[e.id]||e.id}));return t.filter((e,n)=>t.findIndex(t=>t.id===e.id)===n)},L=[{id:`pages`,hidden:!1},{id:`forms`,hidden:!1},{id:`inbox`,hidden:!1},{id:`users`,hidden:!1},{id:`theme`,hidden:!1},{id:`assets`,hidden:!1}],R={route:`/support`,template:`popup_form`,form:`support`,tabName:`Support`,iconName:``},ee={guide:{label:`Guide`,path:`/guide`},templates:{label:`Templates`,path:`/templates`},setup:{label:`Setup`,path:`/setup`},contact:{label:`Contact`,path:`/contact`}};function z({customMenu:e,standalone:n}){let{user:a,userRole:o,signOut:l}=A(),u=x(o),d=y(o),f=d===`free`?`Free User`:_[d],p=(0,c.useNavigate)(),[m,h]=(0,r.useState)(!1),[g,v]=(0,r.useState)(null),[b,S]=(0,r.useState)(!1),[C,w]=(0,r.useState)(!1),[T,E]=(0,r.useState)(!1),D=a?.displayName||a?.email?.split(`@`)[0]||`User`,O=D.charAt(0).toUpperCase()+D.slice(1),{theme:k,toggleTheme:j,activeConfig:F}=t.At(),L=async()=>{await l(),p(`/`),h(!1)},[z,te]=(0,r.useState)({...ee}),[B,ne]=(0,r.useState)(P);(0,r.useEffect)(()=>{if(!t.Pt)return;let e=(0,i.onSnapshot)((0,i.collection)(t.Pt,`sys_pages`),e=>{let t={...ee};for(let[e,n]of M()){if(!n.isPublic)continue;let r=n.config||{};if(r.enabled===!1)continue;let i=r.route?r.route.startsWith(`/`)?r.route:`/`+r.route:`/`+e;t[e]={label:r.pageName||r.pageTitle||r.title||e,path:i}}e.forEach(e=>{let n=e.data();if(n.enabled===!1)return;let r=n.pageName||n.title||ee[e.id]?.label||e.id,i=n.route||(e.id===`home`?`/`:`/`+e.id);t[e.id]={label:r,path:i}}),te(t)},e=>{console.warn(`sys_pages snapshot error (safe to ignore during auth transition):`,e)}),n=(0,i.onSnapshot)((0,i.doc)(t.Pt,`sys_configs`,`page_order`),e=>{ne(e.exists()&&Array.isArray(e.data().order)?I(e.data().order):P)},e=>{console.warn(`page_order snapshot error (safe to ignore during auth transition):`,e)}),r=(0,i.onSnapshot)((0,i.doc)(t.Pt,`sys_tabs`,`support`),e=>{e.exists()&&e.data().pageName&&H(e.data().pageName)},e=>{console.warn(`support snapshot error (safe to ignore during auth transition):`,e)});return()=>{e(),n(),r()}},[]);let[V,H]=(0,r.useState)(R.tabName),U=(()=>{let e=new Set(B.filter(e=>e.hidden).map(e=>e.id)),t=new Set,n=[];return B.forEach(e=>{if(e.hidden||e.id===`home`)return;let r=z[e.id];r&&(n.push({label:r.label,path:r.path}),t.add(e.id))}),Object.entries(z).forEach(([r,i])=>{!t.has(r)&&!e.has(r)&&r!==`home`&&i.path!==`/`&&i.path!==`/support`&&n.push({label:i.label,path:i.path})}),n})(),W=e||U,G=(0,r.useRef)(null),K=(0,r.useRef)(null),[q,J]=(0,r.useState)(W.length);(0,r.useEffect)(()=>{if(n||a)return;let e=()=>{let e=G.current,t=K.current;if(!e||!t)return;let n=e.clientWidth,r=t.querySelectorAll(`[data-measure-nav]`);if(r.length===0){J(W.length);return}let i=0,a=!0;for(let e=0;e<r.length;e++)if(i+=r[e].offsetWidth+(e>0?28:0),i>n){a=!1;break}if(a){J(W.length);return}let o=0,s=0;for(let e=0;e<r.length;e++){let t=r[e].offsetWidth,i=o+t+(e>0?28:0);if(i+50>n)break;o=i,s++}J(Math.max(s,1))},t=requestAnimationFrame(e);if(typeof ResizeObserver>`u`)return()=>cancelAnimationFrame(t);let r=new ResizeObserver(()=>requestAnimationFrame(e));return G.current&&r.observe(G.current),()=>{cancelAnimationFrame(t),r.disconnect()}},[W.map(e=>e.label).join(`|`),n,a,W.length]);let Y=W.slice(0,q),re=W.slice(q);return(0,s.jsxs)(`nav`,{className:`flex items-center justify-between w-full max-w-7xl mx-auto z-40 p-4 md:p-10 relative`,children:[(0,s.jsx)(`div`,{className:`flex items-center gap-2 md:gap-4 z-50`,children:(0,s.jsxs)(c.Link,{to:`/`,className:`flex items-center gap-2 md:gap-3 group cursor-pointer z-50`,children:[(0,s.jsx)(`div`,{className:`w-9 h-9 md:w-10 md:h-10 rounded-xl glass-panel flex items-center justify-center glow-hover shadow-lg transition-transform duration-500 group-hover:rotate-[360deg] group-active:scale-95 overflow-hidden`,children:F?.logoUrl?(0,s.jsx)(`img`,{src:F.logoUrl,alt:`Logo`,className:`w-full h-full object-cover`}):(0,s.jsx)(t.it,{className:`w-4 h-4 md:w-5 md:h-5 text-accent`})}),(0,s.jsx)(`span`,{className:`hidden lg:block font-bold text-[22px] tracking-tight text-gradient transition-colors duration-300 drop-shadow-sm`,children:F?.appName||``})]})}),(0,s.jsx)(t.s,{children:b&&(0,s.jsx)(t.t,{formId:`contact`,onClose:()=>S(!1)})}),(0,s.jsx)(t.s,{children:C&&(0,s.jsx)(t.t,{formId:`support`,onClose:()=>w(!1)})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 md:gap-4 z-50 relative ml-auto flex-1 justify-end`,children:[!n&&!a&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{ref:K,"aria-hidden":`true`,className:`flex items-center gap-7 whitespace-nowrap px-1`,style:{position:`fixed`,top:-9999,left:0,visibility:`hidden`,height:0,pointerEvents:`none`},children:W.map((e,n)=>(0,s.jsxs)(`span`,{"data-measure-nav":!0,className:`text-[13px] md:text-[14px] font-bold tracking-wide flex items-center gap-1.5 shrink-0`,children:[e.label,e.submenu&&(0,s.jsx)(t.gt,{className:`w-3 h-3`})]},e.path||n))}),(0,s.jsxs)(`div`,{className:`hidden sm:flex items-center gap-7 mr-6 w-full max-w-full justify-end relative`,ref:G,children:[Y.map((e,n)=>(0,s.jsxs)(`div`,{className:`relative shrink-0`,onMouseEnter:()=>v(e.label),onMouseLeave:()=>v(null),children:[e.path?(0,s.jsxs)(c.Link,{to:e.path,className:`text-[13px] md:text-[14px] font-bold tracking-wide text-foreground/50 hover:text-accent transition-all cursor-pointer flex items-center gap-1.5`,children:[e.label,e.submenu&&(0,s.jsx)(t.gt,{className:`w-3 h-3`})]}):(0,s.jsxs)(`button`,{onClick:e.action,className:`text-[13px] md:text-[14px] font-bold tracking-wide text-foreground/50 hover:text-accent transition-all flex items-center gap-1.5`,children:[e.label,e.submenu&&(0,s.jsx)(t.gt,{className:`w-3 h-3`})]}),e.submenu&&g===e.label&&(0,s.jsx)(`div`,{className:`absolute top-[100%] left-0 pt-2 z-50`,children:(0,s.jsx)(t.o.div,{initial:{opacity:0,y:5},animate:{opacity:1,y:0},className:`min-w-[180px] max-h-[300px] overflow-y-auto styled-scrollbars bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] rounded-2xl shadow-xl flex flex-col py-2`,children:e.submenu.map((e,t)=>e.path?(0,s.jsx)(c.Link,{to:e.path,className:`px-5 py-3 text-[13px] font-medium text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors`,children:e.label},t):(0,s.jsx)(`button`,{onClick:e.action,className:`px-5 py-3 text-left w-full text-[13px] font-medium text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors`,children:e.label},t))})})]},`${e.path||`no-path`}-${n}`)),re.length>0&&(0,s.jsxs)(`div`,{className:`relative flex items-center shrink-0`,onMouseEnter:()=>h(`overflow`),children:[(0,s.jsx)(`button`,{onClick:()=>h(m===`overflow`?!1:`overflow`),className:`p-1 rounded-lg transition-colors flex items-center ${m===`overflow`?`bg-foreground/5 text-accent`:`text-foreground/50 hover:bg-foreground/5 hover:text-accent`}`,children:(0,s.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-5 h-5`,children:[(0,s.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,s.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1`}),(0,s.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1`})]})}),(0,s.jsx)(t.s,{children:m===`overflow`&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>h(!1)}),(0,s.jsx)(t.o.div,{initial:{opacity:0,y:5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:5,scale:.98},className:`absolute top-[100%] pt-1 right-0 min-w-[200px] max-h-[350px] overflow-y-auto styled-scrollbars glass-popover border border-[var(--panel-border)] rounded-2xl flex flex-col py-2 z-50 origin-top-right`,children:re.map((e,t)=>e.path?(0,s.jsx)(c.Link,{to:e.path,onClick:()=>h(!1),className:`px-5 py-3 text-[13px] font-bold tracking-wide text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors`,children:e.label},t):(0,s.jsx)(`button`,{onClick:()=>{e.action&&e.action(),h(!1)},className:`px-5 py-3 text-left w-full text-[13px] font-bold tracking-wide text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors`,children:e.label},t))})]})})]})]}),F?.showThemeToggle&&(0,s.jsx)(`button`,{onClick:j,className:`p-2 mr-2 rounded-xl glass-panel hover:bg-foreground/5 transition-all text-accent border border-[var(--panel-border)] hover:border-accent/40 shrink-0`,"aria-label":`Toggle Theme`,children:k===`dark`?(0,s.jsx)(t.x,{className:`w-4 h-4 md:w-5 md:h-5`}):(0,s.jsx)(t.M,{className:`w-4 h-4 md:w-5 md:h-5`})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(c.Link,{to:`/login`,className:`hidden sm:flex text-[14px] font-bold tracking-wide text-foreground/80 hover:text-accent transition-colors px-3 py-1.5 shrink-0`,children:`Sign In`}),(0,s.jsx)(c.Link,{to:`/register`,className:`hidden sm:flex text-[13px] md:text-[14px] font-bold tracking-wide px-4 py-1.5 md:px-5 md:py-2 rounded-xl btn-primary transition-all duration-300 hover:shadow-lg hover:-translate-y-0.5 active:scale-95 items-center justify-center ml-2`,children:`Get Started`}),(0,s.jsxs)(`div`,{className:`relative sm:hidden ml-1`,children:[(0,s.jsx)(`button`,{onClick:()=>h(m===`guest`?!1:`guest`),className:`p-2 rounded-xl glass-panel glow-hover border transition-all ${m===`guest`?`border-accent bg-foreground/5`:`border-[var(--panel-border)] hover:bg-foreground/5`}`,children:(0,s.jsx)(t.N,{className:`w-5 h-5 text-accent/80`})}),(0,s.jsx)(t.s,{children:m===`guest`&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>h(!1)}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:-10,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.95},className:`absolute top-full right-0 mt-3 w-[220px] p-2 glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col gap-1 origin-top-right`,children:[(0,s.jsxs)(c.Link,{to:`/guide`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.ut,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Guide`})]}),(0,s.jsxs)(c.Link,{to:`/templates`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.B,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Templates`})]}),(0,s.jsxs)(c.Link,{to:`/setup`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.w,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Setup`})]}),(0,s.jsxs)(c.Link,{to:`/contact`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all w-full text-left`,children:[(0,s.jsx)(t.P,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Contact`})]}),(0,s.jsxs)(`div`,{className:`pt-2 mt-1 border-t border-[var(--panel-border)]/50 flex flex-col gap-1`,children:[(0,s.jsxs)(c.Link,{to:`/login`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all w-full`,children:[(0,s.jsx)(t.F,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Sign In`})]}),(0,s.jsx)(c.Link,{to:`/register`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl btn-primary w-full shadow-lg hover:-translate-y-0.5 transition-transform text-white`,children:(0,s.jsx)(`span`,{className:`text-[14px] font-bold mx-auto`,children:`Get Started`})})]})]})]})})]})]})]}),!n&&a&&(0,s.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2 mr-1`,children:[o===`admin`&&(0,s.jsx)(N,{}),F?.showThemeToggle&&(0,s.jsx)(`button`,{onClick:j,className:`p-2 ml-1 rounded-xl glass-panel hover:bg-foreground/5 transition-all text-accent border border-[var(--panel-border)] hover:border-accent/40`,"aria-label":`Toggle Theme`,children:k===`dark`?(0,s.jsx)(t.x,{className:`w-4 h-4 md:w-5 md:h-5`}):(0,s.jsx)(t.M,{className:`w-4 h-4 md:w-5 md:h-5`})})]}),(0,s.jsxs)(`div`,{className:`relative z-50 flex items-center gap-3`,children:[(0,s.jsxs)(`div`,{className:`relative flex-shrink-0`,children:[(0,s.jsxs)(`button`,{onClick:()=>h(m===`user`?!1:`user`),className:`flex items-center gap-2 group p-1 sm:pr-2.5 rounded-full glass-panel hover:bg-foreground/5 transition-all duration-300 border ${m===`user`?`border-accent/40 bg-foreground/5`:`border-transparent hover:border-[var(--panel-border)]`}`,children:[(0,s.jsx)(`div`,{className:`w-8 h-8 md:w-9 md:h-9 rounded-full bg-accent/10 flex items-center justify-center overflow-hidden border border-[var(--panel-border)] group-hover:border-accent/30 transition-colors shrink-0 text-accent`,children:a.photoURL&&!T?(0,s.jsx)(`img`,{src:a.photoURL,alt:`Profile`,className:`w-full h-full object-cover`,onError:()=>E(!0)}):(0,s.jsx)(t.m,{className:`w-4 h-4 md:w-5 md:h-5 text-accent`})}),(0,s.jsxs)(`div`,{className:`hidden sm:flex flex-col text-left mr-1 justify-center min-w-[70px] max-w-[160px]`,children:[(0,s.jsx)(`span`,{className:`text-[12px] font-extrabold leading-tight text-foreground truncate w-full`,children:O}),(0,s.jsx)(`span`,{className:`text-[10px] font-mono tracking-wider leading-tight text-accent truncate w-full mt-0.5 uppercase font-bold`,children:f})]})]}),(0,s.jsx)(t.s,{children:m===`user`&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>h(!1)}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:-5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98,y:-5},className:`absolute top-full mt-2 right-0 w-[280px] md:w-[320px] glass-popover border border-[var(--panel-border)] rounded-2xl p-2 z-50 flex flex-col origin-top-right`,children:[(0,s.jsxs)(`div`,{className:`p-3 border-b border-[var(--panel-border)]/50 mb-1 flex flex-col gap-1.5`,children:[(0,s.jsx)(`span`,{className:`font-bold text-[15px] text-foreground truncate`,children:O}),(0,s.jsx)(`span`,{className:`text-[12px] text-foreground/50 truncate font-mono`,children:a.email})]}),(0,s.jsxs)(`div`,{className:`py-1`,children:[(0,s.jsxs)(c.Link,{to:`/profile`,onClick:()=>h(!1),className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-semibold tracking-wide hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all gap-3`,children:[(0,s.jsx)(`span`,{className:`w-5 h-5 rounded-md bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.m,{className:`w-3 h-3 text-accent`})}),`Profile Settings`]}),u&&(0,s.jsxs)(c.Link,{to:`/assets`,onClick:()=>h(!1),className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-semibold tracking-wide hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all gap-3`,children:[(0,s.jsx)(`span`,{className:`w-5 h-5 rounded-md bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.Y,{className:`w-3 h-3 text-accent`})}),`Assets`]}),o===`admin`&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(c.Link,{to:`/users`,onClick:()=>h(!1),className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-semibold tracking-wide hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all gap-3`,children:[(0,s.jsx)(`span`,{className:`w-5 h-5 rounded-md bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.p,{className:`w-3 h-3 text-accent`})}),`Users`]}),(0,s.jsxs)(c.Link,{to:`/inbox`,onClick:()=>h(!1),className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-semibold tracking-wide hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all gap-3`,children:[(0,s.jsx)(`span`,{className:`w-5 h-5 rounded-md bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.q,{className:`w-3 h-3 text-accent`})}),`Inbox`]}),(0,s.jsxs)(c.Link,{to:`/pages`,onClick:()=>h(!1),className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-semibold tracking-wide hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all gap-3`,children:[(0,s.jsx)(`span`,{className:`w-5 h-5 rounded-md bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.U,{className:`w-3 h-3 text-accent`})}),`Pages`]})]}),o!==`admin`&&(0,s.jsxs)(c.Link,{to:`/support`,onClick:()=>h(!1),className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-semibold tracking-wide hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all gap-3 text-left`,children:[(0,s.jsx)(`span`,{className:`w-5 h-5 rounded-md bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.lt,{className:`w-3 h-3 text-accent`})}),V]})]}),(0,s.jsx)(`div`,{className:`pt-1 mt-1 border-t border-[var(--panel-border)]/50`,children:(0,s.jsxs)(`button`,{onClick:L,className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-bold tracking-wide hover:bg-red-500/10 hover:text-red-500 text-foreground/70 transition-all gap-3`,children:[(0,s.jsx)(`span`,{className:`w-5 h-5 rounded-md bg-red-500/5 flex items-center justify-center shrink-0 text-red-500`,children:(0,s.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-3 h-3`,children:[(0,s.jsx)(`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`}),(0,s.jsx)(`polyline`,{points:`16 17 21 12 16 7`}),(0,s.jsx)(`line`,{x1:`21`,y1:`12`,x2:`9`,y2:`12`})]})}),`Sign Out`]})})]})]})})]}),(0,s.jsxs)(`div`,{className:`relative sm:hidden`,children:[(0,s.jsx)(`button`,{onClick:()=>h(m===`nav`?!1:`nav`),className:`p-2 rounded-xl glass-panel glow-hover border transition-all ${m===`nav`?`border-accent bg-foreground/5`:`border-[var(--panel-border)] hover:bg-foreground/5`}`,children:(0,s.jsx)(t.N,{className:`w-5 h-5 text-accent/80`})}),(0,s.jsx)(t.s,{children:m===`nav`&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>h(!1)}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:-10,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.95},className:`absolute top-full right-0 mt-3 w-[220px] p-2 glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col gap-1 origin-top-right`,children:[(0,s.jsxs)(c.Link,{to:`/profile`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.m,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Profile Settings`})]}),u&&(0,s.jsxs)(c.Link,{to:`/assets`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.Y,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Assets`})]}),(0,s.jsxs)(c.Link,{to:`/dashboard`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.H,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Dashboard`})]}),o===`admin`&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(c.Link,{to:`/users`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.p,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Users`})]}),(0,s.jsxs)(c.Link,{to:`/inbox`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,s.jsx)(t.q,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Inbox`})]})]}),o!==`admin`&&(0,s.jsxs)(c.Link,{to:`/support`,onClick:()=>h(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all w-full text-left`,children:[(0,s.jsx)(t.lt,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Support`})]}),(0,s.jsx)(`div`,{className:`pt-1 mt-1 border-t border-[var(--panel-border)]/50`,children:(0,s.jsx)(`button`,{onClick:L,className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-red-500/10 text-red-500/80 hover:text-red-500 transition-all w-full`,children:(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Sign Out`})})})]})]})})]})]})]}),n&&(0,s.jsx)(s.Fragment,{children:F?.showThemeToggle&&(0,s.jsx)(`button`,{onClick:j,className:`p-2 ml-1 rounded-xl glass-panel hover:bg-foreground/5 transition-all text-accent border border-[var(--panel-border)] hover:border-accent/40`,"aria-label":`Toggle Theme`,children:k===`dark`?(0,s.jsx)(t.x,{className:`w-4 h-4`}):(0,s.jsx)(t.M,{className:`w-4 h-4`})})})]})]})}function te(){let[e,n]=(0,r.useState)(null);return(0,s.jsxs)(`main`,{className:`flex-1 flex flex-col items-center justify-center w-full max-w-5xl mx-auto mt-4 md:mt-12 mb-16 md:mb-24 z-10 relative`,children:[(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},transition:{duration:.8},className:`text-center mb-8 md:mb-12`,children:[(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},transition:{delay:.2},className:`inline-flex items-center gap-2 md:gap-3 px-5 md:px-6 py-2 md:py-2.5 mb-8 md:mb-10 text-[13px] md:text-[15px] font-semibold tracking-wide uppercase rounded-full glass-panel text-foreground glow-hover cursor-pointer`,children:[(0,s.jsx)(t.u,{className:`w-4 h-4 text-accent`}),` The Open-Source Firebase Starter`]}),(0,s.jsx)(t.o.h1,{className:`text-5xl sm:text-6xl md:text-7xl lg:text-[5.5rem] font-extrabold tracking-tight mb-6 md:mb-8 text-gradient animate-float leading-[1.1] md:leading-[1.15] px-2`,children:`Your AI Firebase`}),(0,s.jsx)(`p`,{className:`text-[14px] sm:text-[15px] md:text-lg lg:text-xl text-foreground/60 max-w-3xl mx-auto font-medium leading-[1.6] md:leading-[1.7] mb-10 md:mb-14 px-6 md:px-4`,children:`A production-ready Firebase backend template with Auth, Firestore prefix rules, and a clean dashboard — ready for vibe-coded apps.`}),(0,s.jsxs)(t.o.div,{className:`flex flex-col sm:flex-row items-center justify-center gap-4 sm:gap-6 w-full max-w-2xl mx-auto px-6`,initial:{opacity:0},animate:{opacity:1},transition:{delay:.5},children:[(0,s.jsx)(c.Link,{to:`/register`,style:{borderRadius:`var(--btn-radius, 0.75rem)`},className:`w-full sm:w-auto px-6 md:px-8 py-3 md:py-3.5 font-semibold tracking-wide btn-primary text-[15px] shadow-xl transition-all duration-300 hover:-translate-y-1 active:scale-95 flex items-center justify-center`,children:`Start Building Free`}),(0,s.jsx)(c.Link,{to:`/login`,style:{borderRadius:`var(--btn-radius, 0.75rem)`},className:`w-full sm:w-auto px-6 md:px-8 py-3 md:py-3.5 font-semibold tracking-wide btn-secondary text-[15px] transition-all duration-300 flex items-center justify-center hover:-translate-y-1`,children:`Sign In`})]})]}),(0,s.jsx)(t.s,{children:e&&(0,s.jsx)(t.t,{onClose:()=>n(null),formId:e})})]})}function B(){let[e,n]=(0,r.useState)(!1),[i,o]=(0,r.useState)(null),l=(0,c.useNavigate)(),{registerUser:u}=A();return(0,s.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mt-6 md:mt-8 mb-8`,children:(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5},className:`w-full max-w-[500px] p-6 sm:p-8 lg:p-10 rounded-3xl md:rounded-3xl glass-panel relative glow-hover shadow-[0_8px_32px_rgba(0,0,0,0.08)]`,children:[(0,s.jsx)(`div`,{className:`absolute -inset-[1px] bg-gradient-to-br from-[var(--primary-glow)] to-transparent opacity-30 blur-[20px] rounded-3xl md:rounded-3xl -z-10`}),(0,s.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,s.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight`,children:`Create an account`}),(0,s.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Join Your AI Firebase and start building today.`})]}),i&&(0,s.jsx)(`div`,{className:`p-3 mb-6 text-[14px] font-medium text-red-400 bg-red-500/10 rounded-xl border border-red-500/20`,children:i}),(0,s.jsxs)(`form`,{className:`space-y-4`,onSubmit:async e=>{e.preventDefault(),n(!0),o(null);let t=new FormData(e.currentTarget),r=t.get(`email`),i=t.get(`password`),a=t.get(`firstName`),d=t.get(`lastName`);if(i.length<6){o(`Password must be at least 6 characters.`),n(!1);return}try{await u(r,i,a,d),l(`/verify`)}catch(e){e?.code===`auth/email-already-in-use`?o((0,s.jsxs)(`span`,{children:[`An account with this email already exists.`,` `,(0,s.jsx)(c.Link,{to:`/login?email=${encodeURIComponent(r)}`,className:`font-bold underline hover:text-accent transition-colors`,children:`Sign in?`})]})):e?.code===`auth/weak-password`?o(`Password must be at least 6 characters.`):o(e?.message||`An error occurred during registration.`)}finally{n(!1)}},children:[(0,s.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,s.jsx)(t.i,{name:`firstName`,label:`First Name`,type:`text`,placeholder:`John`,required:!0}),(0,s.jsx)(t.i,{name:`lastName`,label:`Last Name`,type:`text`,placeholder:`Doe`,required:!0})]}),(0,s.jsx)(t.i,{name:`email`,label:`Email`,type:`email`,placeholder:`name@example.com`,required:!0}),(0,s.jsx)(t.i,{name:`password`,label:`Password`,type:`password`,placeholder:`••••••••`,required:!0}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsxs)(t.r,{type:`submit`,className:`w-full py-3 text-[15px] font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,isLoading:e,children:[`Create Account `,(0,s.jsx)(t.Ct,{className:`ml-2 w-4 h-4 group-hover:translate-x-1 transition-transform shrink-0`})]})})]}),(0,s.jsxs)(`div`,{className:`mt-6 pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:[(0,s.jsxs)(t.r,{variant:`secondary`,onClick:async()=>{n(!0),o(null);try{if(!t.Nt)throw Error(`Firebase is not initialized. Check your configuration.`);let e=new a.GoogleAuthProvider;try{await(0,a.signInWithPopup)(t.Nt,e)}catch(n){if(n?.code===`auth/popup-blocked`||n?.code===`auth/popup-closed-by-user`||n?.code===`auth/cancelled-popup-request`){let{signInWithRedirect:n}=await import(`firebase/auth`);await n(t.Nt,e);return}throw n}}catch(e){let t=e?.code||``;t===`auth/unauthorized-domain`||(e?.message||``).includes(`requested action is invalid`)?o(`Google Sign-In failed: your app domain is not authorized. Go to Firebase Console → Authentication → Settings → Authorized domains and add your domain (e.g. localhost or your-app.com).`):o(t===`auth/network-request-failed`?`Network error — please check your internet connection and Firebase configuration.`:e?.message||`Google sign-up failed.`)}finally{n(!1)}},className:`w-full py-3 text-[15px] font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,disabled:e,children:[(0,s.jsxs)(`svg`,{className:`w-5 h-5 mr-3`,viewBox:`0 0 24 24`,children:[(0,s.jsx)(`path`,{fill:`currentColor`,d:`M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z`}),(0,s.jsx)(`path`,{fill:`currentColor`,d:`M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z`}),(0,s.jsx)(`path`,{fill:`currentColor`,d:`M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z`}),(0,s.jsx)(`path`,{fill:`currentColor`,d:`M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z`})]}),`Sign up with Google`]}),(0,s.jsxs)(`p`,{className:`text-[14px] text-foreground/70 font-medium pt-2 tracking-wide`,children:[`Already have an account? `,(0,s.jsx)(c.Link,{to:`/login`,className:`text-accent hover:underline font-bold ml-1`,children:`Sign in`})]})]})]})})}function ne(){let[e,n]=(0,r.useState)(!1),[i,o]=(0,r.useState)(null),[l]=(0,c.useSearchParams)(),u=(0,c.useNavigate)(),[d]=(0,r.useState)(l.get(`email`)||``);return(0,s.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mt-6 md:mt-8 mb-8`,children:(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5},className:`w-full max-w-[480px] p-6 sm:p-8 lg:p-10 rounded-3xl md:rounded-3xl glass-panel relative glow-hover shadow-[0_8px_32px_rgba(0,0,0,0.08)]`,children:[(0,s.jsx)(`div`,{className:`absolute -inset-[1px] bg-gradient-to-br from-[var(--primary-glow)] to-transparent opacity-30 blur-[20px] rounded-3xl md:rounded-3xl -z-10`}),(0,s.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,s.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight`,children:`Welcome back`}),(0,s.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Sign in to Your AI Firebase.`})]}),i&&(0,s.jsx)(`div`,{className:`p-3 mb-6 text-[14px] font-medium text-red-400 bg-red-500/10 rounded-xl border border-red-500/20`,children:i}),(0,s.jsxs)(`form`,{className:`space-y-4`,onSubmit:async e=>{e.preventDefault(),n(!0),o(null);let r=new FormData(e.currentTarget),i=r.get(`email`),d=r.get(`password`);try{if(!t.Nt)throw Error(`Firebase is not initialized. Check your configuration.`);await(0,a.signInWithEmailAndPassword)(t.Nt,i,d),u(l.get(`from`)||`/dashboard`,{replace:!0})}catch(e){e?.code===`auth/invalid-credential`||e?.code===`auth/user-not-found`||e?.code===`auth/wrong-password`?o((0,s.jsxs)(`span`,{children:[`Email or Password are incorrect.`,` `,(0,s.jsx)(c.Link,{to:`/reset-password`,className:`font-bold underline hover:text-red-400 transition-colors`,children:`Reset password?`})]})):e?.code===`auth/network-request-failed`?o(`Network error — please check your internet connection and Firebase configuration.`):o(e?.message||`Invalid credentials.`),n(!1)}},children:[(0,s.jsx)(t.i,{name:`email`,label:`Email`,type:`email`,defaultValue:d,placeholder:`name@example.com`,required:!0}),(0,s.jsxs)(`div`,{className:`space-y-2`,children:[(0,s.jsxs)(`div`,{className:`flex justify-between items-center pr-1`,children:[(0,s.jsx)(`label`,{className:`text-[14px] md:text-[15px] tracking-wide font-medium text-foreground/80 select-none pb-1`,children:`Password`}),(0,s.jsx)(c.Link,{to:`/reset-password`,className:`text-[13px] md:text-[14px] text-accent hover:underline font-bold tracking-wide`,children:`Forgot Password?`})]}),(0,s.jsx)(t.i,{name:`password`,type:`password`,placeholder:`••••••••`,required:!0})]}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsxs)(t.r,{type:`submit`,className:`w-full py-3 text-base font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,isLoading:e,children:[`Sign In `,(0,s.jsx)(t.Ct,{className:`ml-2 w-4 h-4 group-hover:translate-x-1 transition-transform shrink-0`})]})})]}),(0,s.jsxs)(`div`,{className:`mt-6 pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:[(0,s.jsxs)(t.r,{variant:`secondary`,onClick:async()=>{n(!0),o(null);try{if(!t.Nt)throw Error(`Firebase is not initialized. Check your configuration.`);let e=new a.GoogleAuthProvider;try{await(0,a.signInWithPopup)(t.Nt,e)}catch(n){if(n?.code===`auth/popup-blocked`||n?.code===`auth/popup-closed-by-user`||n?.code===`auth/cancelled-popup-request`){let{signInWithRedirect:n}=await import(`firebase/auth`);await n(t.Nt,e);return}throw n}u(l.get(`from`)||`/dashboard`,{replace:!0})}catch(e){let t=e?.code||``;t===`auth/unauthorized-domain`||(e?.message||``).includes(`requested action is invalid`)?o(`Google Sign-In failed: your app domain is not authorized. Go to Firebase Console → Authentication → Settings → Authorized domains and add your domain (e.g. localhost or your-app.com).`):o(t===`auth/network-request-failed`?`Network error — please check your internet connection and Firebase configuration.`:e?.message||`Google sign-in failed.`)}finally{n(!1)}},className:`w-full py-3 text-base font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,disabled:e,children:[(0,s.jsxs)(`svg`,{className:`w-5 h-5 mr-3`,viewBox:`0 0 24 24`,children:[(0,s.jsx)(`path`,{fill:`currentColor`,d:`M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z`}),(0,s.jsx)(`path`,{fill:`currentColor`,d:`M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z`}),(0,s.jsx)(`path`,{fill:`currentColor`,d:`M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z`}),(0,s.jsx)(`path`,{fill:`currentColor`,d:`M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z`})]}),`Sign in with Google`]}),(0,s.jsxs)(`p`,{className:`text-[14px] text-foreground/70 font-medium pt-2 tracking-wide`,children:[`New here? `,(0,s.jsx)(c.Link,{to:`/register`,className:`text-accent hover:underline font-bold ml-1`,children:`Create account`})]})]})]})})}function V(){let{user:e,refreshUser:n}=A(),i=(0,c.useNavigate)(),[o,l]=(0,r.useState)(!1),[u,d]=(0,r.useState)(!1),[f,p]=(0,r.useState)(``);return(0,s.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mb-16`,children:(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5},className:`w-full max-w-[480px] p-6 md:p-8 lg:p-10 rounded-3xl glass-panel relative glow-hover text-center shadow-[0_8px_32px_rgba(0,0,0,0.08)]`,children:[(0,s.jsx)(`div`,{className:`absolute -inset-[1px] bg-gradient-to-br from-[var(--primary-glow)] to-transparent opacity-30 blur-[20px] rounded-3xl -z-10`}),(0,s.jsx)(`div`,{className:`w-14 h-14 md:w-16 md:h-16 rounded-2xl glass-panel border border-[var(--panel-border)] flex items-center justify-center mx-auto mb-5 md:mb-6 animate-float shadow-xl`,children:(0,s.jsx)(t.P,{className:`w-7 h-7 md:w-8 md:h-8 text-accent opacity-90`})}),(0,s.jsx)(`h1`,{className:`text-2xl md:text-3xl font-extrabold mb-3 text-foreground tracking-tight`,children:`Verify your email`}),(0,s.jsxs)(`p`,{className:`text-[14px] md:text-[15px] text-foreground/60 mb-6 md:mb-8 leading-[1.6] tracking-wide`,children:[`We've sent a verification link to `,(0,s.jsx)(`span`,{className:`font-semibold text-foreground`,children:e?.email}),`. Please check your inbox (and spam folder) to verify your account and access your dashboard.`]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-3 max-w-[360px] mx-auto`,children:[f&&(0,s.jsx)(`div`,{role:`status`,className:`w-full px-4 py-2.5 md:py-3 text-[13px] md:text-[14px] font-semibold leading-snug rounded-xl border ${f.includes(`Failed`)||f.includes(`not verified`)||f.includes(`wrong`)?`text-red-400 bg-red-500/10 border-red-500/20`:`text-emerald-400 bg-emerald-500/10 border-emerald-500/20`}`,children:f}),(0,s.jsx)(t.r,{variant:`primary`,onClick:async()=>{l(!0),p(``);try{if(t.Nt.currentUser){if(await t.Nt.currentUser.reload(),!t.Nt.currentUser.emailVerified){p(`Email is not verified yet. Please check your inbox.`),l(!1);return}await t.Nt.currentUser.getIdToken(!0),await n(),i(`/dashboard`)}}catch{p(`Something went wrong. Please try again.`),l(!1)}},isLoading:o,className:`w-full py-2.5 md:py-3 text-[14px] font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,children:`I've verified my email`}),(0,s.jsx)(t.r,{variant:`ghost`,onClick:async()=>{if(e){d(!0),p(``);try{await(0,a.sendEmailVerification)(e),p(`Verification email sent! Please check your inbox.`)}catch(e){e?.code===`auth/too-many-requests`?p(`Failed to resend: Please wait a minute before trying again.`):p(e?.message||`Failed to resend. Please try again later.`)}finally{d(!1)}}},isLoading:u,className:`w-full py-2.5 md:py-3 text-[13px] md:text-[14px] font-semibold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,children:`Resend verification link`})]})]})})}var H=D(`admin`),U={pages:{path:`/pages`,label:`Pages`,icon:t.U,roles:H},forms:{path:`/forms`,label:`Forms`,icon:t.O,roles:H},inbox:{path:`/inbox`,label:`Inbox`,icon:t.q,roles:H},users:{path:`/users`,label:`Users`,icon:t.p,roles:H},theme:{path:`/theme`,label:`Theme`,icon:t.j,roles:H},assets:{path:`/assets`,label:`Assets`,icon:t.Y,roles:H}};function W({customTabs:e=[]}){let{pathname:n}=(0,c.useLocation)(),{user:a,userRole:o}=A(),[l,u]=(0,r.useState)(!1),d=(0,r.useRef)(null),[f,p]=(0,r.useState)({}),[m,h]=(0,r.useState)(L);(0,r.useEffect)(()=>{try{let e=localStorage.getItem(`fbos_nav_tabs`);e&&p(JSON.parse(e));let t=localStorage.getItem(`fbos_nav_order`);t&&h(JSON.parse(t))}catch{}let e=(0,i.onSnapshot)((0,i.collection)(t.Pt,`sys_tabs`),e=>{let t={};e.forEach(e=>{t[e.id]=e.data()}),p(t),localStorage.setItem(`fbos_nav_tabs`,JSON.stringify(t))},e=>{console.warn(`sys_tabs snapshot error:`,e)}),n=(0,i.onSnapshot)((0,i.doc)(t.Pt,`sys_configs`,`tab_order`),e=>{let t=e.exists()&&Array.isArray(e.data().order)?I(e.data().order):L;h(t),localStorage.setItem(`fbos_nav_order`,JSON.stringify(t))},e=>{console.warn(`tab_order snapshot error:`,e)});return()=>{e(),n()}},[]),(0,r.useEffect)(()=>{function e(e){d.current&&!d.current.contains(e.target)&&u(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let g=[...(()=>{let e={};Object.entries(U).forEach(([t,n])=>{e[t]={id:t,...n,exact:!0}});let n={...f};for(let[e,t]of M())t.isPublic||(n[e]={...t.config,...f[e]});Object.entries(n).forEach(([n,r])=>{let i=e[n],a=i?.icon??t.U;if(r?.iconName){let e=r.iconName.trim(),n=e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);t.c[n]?a=t.c[n]:t.c[e]&&(a=t.c[e])}let o=i?.roles??H;r?.pageType&&(o=D(w(r.pageType))),e[n]={id:n,path:r?.route?r.route.startsWith(`/`)?r.route:`/`+r.route:i?.path??`/`+n,label:r?.tabName||r?.pageTitle||r?.pageName||i?.label||n,icon:a,roles:o,exact:!0}});let r=[],i=new Set;m.forEach(t=>{t.hidden||e[t.id]&&(r.push(e[t.id]),i.add(t.id))});let a=[],o=[];return Object.keys(e).forEach(t=>{if(i.has(t))return;let r=m.find(e=>e.id===t);r?.hidden||(t in n&&!r?a.push(e[t]):o.push(e[t]))}),a.length>0&&r.unshift(...a),o.length>0&&r.push(...o),r})(),...e.map(e=>({...e,id:e.path}))].filter(e=>{let t=E(o,!!a);return Array.isArray(e.roles)?e.roles.includes(t):!1}),_=(0,r.useRef)(null),v=(0,r.useRef)(null),[y,b]=(0,r.useState)(g.length);(0,r.useEffect)(()=>{let e=()=>{let e=_.current,t=v.current;if(!e||!t)return;let n=e.clientWidth;if(n===0)return;let r=t.querySelectorAll(`[data-measure-tab]`);if(r.length===0){b(g.length);return}let i=0,a=!0;for(let e=0;e<r.length;e++)if(i+=r[e].offsetWidth+(e>0?40:0),i>n){a=!1;break}if(a){b(g.length);return}let o=0,s=0;for(let e=0;e<r.length;e++){let t=r[e].offsetWidth,i=o+t+(e>0?40:0);if(i+52>n)break;o=i,s++}b(Math.max(s,1))},t=requestAnimationFrame(e);if(typeof ResizeObserver>`u`)return()=>cancelAnimationFrame(t);let n=new ResizeObserver(()=>requestAnimationFrame(e));return _.current&&n.observe(_.current),()=>{cancelAnimationFrame(t),n.disconnect()}},[g.map(e=>e.id+e.label).join(`|`),g.length]);let x=g.slice(0,y),S=g.slice(y),C=e=>e.exact?n===e.path:n.startsWith(e.path),T=S.some(e=>C(e));return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{ref:v,"aria-hidden":`true`,className:`flex items-center gap-6 md:gap-10 whitespace-nowrap px-1`,style:{position:`fixed`,top:-9999,left:0,visibility:`hidden`,pointerEvents:`none`},children:g.map(e=>{let t=e.icon;return(0,s.jsxs)(`span`,{"data-measure-tab":!0,className:`flex items-center gap-2 text-[14.5px] font-semibold shrink-0 pb-3`,children:[(0,s.jsx)(t,{className:`w-[18px] h-[18px]`}),e.label]},e.path||e.id)})}),(0,s.jsxs)(`div`,{ref:_,className:`w-full flex items-center gap-6 md:gap-10 mb-8 border-b border-[var(--panel-border)] px-1 whitespace-nowrap relative`,children:[x.map(e=>{let t=C(e),n=e.icon;return(0,s.jsxs)(c.Link,{to:e.path||`/`,className:`flex items-center gap-2 text-[14.5px] font-semibold transition-all duration-300 pb-3 -mb-[1px] border-b-2 shrink-0 ${t?`text-accent border-accent`:`text-foreground/50 hover:text-foreground/80 border-transparent`}`,children:[(0,s.jsx)(n,{className:`w-[18px] h-[18px]`}),e.label]},e.path||e.id)}),S.length>0&&(0,s.jsxs)(`div`,{className:`relative shrink-0 ml-auto`,ref:d,children:[(0,s.jsx)(`button`,{onClick:()=>u(!l),className:`flex items-center justify-center transition-all duration-300 pb-3 -mb-[1px] border-b-2 cursor-pointer ${T?`text-accent border-accent`:`text-foreground/50 hover:text-foreground/80 border-transparent`}`,title:`More items`,children:(0,s.jsx)(t.nt,{className:`w-5 h-5`})}),(0,s.jsx)(t.s,{children:l&&(0,s.jsx)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:10},className:`absolute top-[100%] right-0 mt-2 min-w-[200px] glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col py-2 overflow-hidden`,children:S.map(e=>{let t=C(e),n=e.icon;return(0,s.jsxs)(c.Link,{to:e.path||`/`,onClick:()=>u(!1),className:`flex items-center gap-3 px-5 py-3 text-[14px] font-medium transition-colors ${t?`text-accent bg-accent/5`:`text-foreground/70 hover:text-foreground hover:bg-foreground/5`}`,children:[(0,s.jsx)(n,{className:`w-4 h-4`}),e.label]},e.path||e.id)})})})]})]})]})}function G(){let{user:e,refreshUser:n,isInternal:c}=A(),[l,u]=(0,r.useState)(e?.displayName||``),[d,f]=(0,r.useState)(e?.email||``),[p,m]=(0,r.useState)(e?.photoURL||``),[h,g]=(0,r.useState)(!1),[_,v]=(0,r.useState)(null),[y,b]=(0,r.useState)(``),[x,S]=(0,r.useState)(``),[w,T]=(0,r.useState)(!1),[E,D]=(0,r.useState)(!1),[O,k]=(0,r.useState)(!0);r.default.useEffect(()=>{u(e?.displayName||``),f(e?.email||``),m(e?.photoURL||``)},[e?.uid,e?.displayName,e?.email,e?.photoURL]);let j=async n=>{if(e)try{if(!c)return;let r=[`mem_files`,`admin_files`];(await(0,i.getDocs)((0,i.collection)(t.Pt,`sys_tabs`))).forEach(e=>{let t=e.data(),n=(t.tabName||e.id).toLowerCase().replace(/[^a-z0-9]+/g,`_`),i=C(t.pageType);i===`internal`&&r.push(`mem_${n}_records`),i===`admin`&&r.push(`admin_${n}_records`)});for(let a of r)try{let r=await(0,i.getDocs)((0,i.query)((0,i.collection)(t.Pt,a),(0,i.where)(`uid`,`==`,e.uid)));if(r.empty)continue;let o=(0,i.writeBatch)(t.Pt);r.docs.forEach(e=>o.update(e.ref,{creatorAvatar:n})),await o.commit()}catch{}}catch(e){console.error(`Error propagating avatar to records:`,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-8`,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:`Profile Settings`}),(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`}),`/profile`]})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 animate-in fade-in duration-500 pb-20`,children:[(0,s.jsx)(`div`,{className:`flex justify-start`,children:(0,s.jsx)(W,{})}),(0,s.jsx)(t.s,{children:_&&(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.98,y:-10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.98,y:-10},className:`p-4 mb-6 rounded-2xl border flex flex-col sm:flex-row sm:items-center gap-3 ${_.type===`error`?`bg-red-500/10 border-red-500/20 text-red-400`:`bg-accent/10 border-accent/20 text-accent`}`,children:[_.type===`success`?(0,s.jsx)(t.dt,{className:`w-5 h-5 shrink-0`}):(0,s.jsx)(t.ft,{className:`w-5 h-5 shrink-0`}),(0,s.jsx)(`span`,{className:`text-[14px] font-semibold tracking-wide leading-relaxed`,children:_.text})]})}),(0,s.jsx)(`form`,{onSubmit:async r=>{if(r.preventDefault(),e){g(!0),v(null);try{l!==e.displayName&&await(0,a.updateProfile)(e,{displayName:l});let r=!1;if(d!==e.email){let n=await(0,a.fetchSignInMethodsForEmail)(t.Nt,d);if(n&&n.length>0)throw Error(`An account with this email already exists.`);await(0,a.verifyBeforeUpdateEmail)(e,d),r=!0}if(y){if(y!==x)throw Error(`Passwords do not match.`);if(y.length<6)throw Error(`Password must be at least 6 characters.`);await(0,a.updatePassword)(e,y),b(``),S(``)}await n(),v(r?{text:`Profile updated. A verification link has been sent to your new email address.`,type:`success`}:{text:`Profile successfully updated.`,type:`success`})}catch(e){console.error(e),e.code===`auth/requires-recent-login`?v({text:`For security, please sign out and sign back in before changing your email or password.`,type:`error`}):v({text:e.message||`Failed to update profile.`,type:`error`})}finally{g(!1)}}},className:`w-full flex flex-col`,children:(0,s.jsxs)(`div`,{className:`glass-panel w-full p-8 md:p-12 rounded-3xl border border-[var(--panel-border)] shadow-2xl space-y-8 min-h-[500px]`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-6 pb-6 border-b border-[var(--panel-border)]/50`,children:[(0,s.jsxs)(`div`,{className:`w-24 h-24 md:w-28 md:h-28 rounded-full glass-panel border-4 border-[var(--panel-border)] shadow-xl bg-accent/10 flex items-center justify-center relative overflow-hidden shrink-0 group transition-transform duration-300 hover:scale-[1.02]`,children:[(E||p&&O&&!w)&&(0,s.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-accent/5 backdrop-blur-sm z-10`,children:(0,s.jsx)(t.L,{className:`w-8 h-8 text-accent animate-spin`})}),p&&!w?(0,s.jsx)(`img`,{src:p,alt:`Avatar`,className:`w-full h-full object-cover transition-opacity duration-300 ${O?`opacity-0`:`opacity-100`}`,onLoad:()=>k(!1),onError:()=>{T(!0),k(!1)}}):(0,s.jsx)(t.m,{className:`w-10 h-10 md:w-12 md:h-12 text-accent`}),!E&&(0,s.jsxs)(`div`,{className:`absolute inset-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2 z-10 backdrop-blur-sm`,children:[(0,s.jsxs)(`label`,{className:`flex flex-col items-center justify-center cursor-pointer p-2 rounded-full hover:bg-white/20 transition-colors text-white`,title:`Upload Photo`,children:[(0,s.jsx)(t.yt,{className:`w-5 h-5`}),(0,s.jsx)(`input`,{type:`file`,accept:`image/*`,onChange:async r=>{let s=r.target.files?.[0];if(!(!s||!e)){if(s.size>2*1024*1024){v({text:`File too large. Please select an image under 2MB.`,type:`error`});return}D(!0),T(!1),k(!0);try{let r=(0,o.ref)(t.It,`user_avatars/${e.uid}/file.png`);await(0,o.uploadBytes)(r,s,{customMetadata:{ownerId:e.uid}});let c=await(0,o.getDownloadURL)(r);m(c);let l=(0,i.doc)(t.Pt,`user_profiles`,e.uid);await Promise.all([(0,a.updateProfile)(e,{photoURL:c}),(0,i.updateDoc)(l,{avatar:c}),j(c)]),await n(),v({text:`Avatar successfully updated!`,type:`success`})}catch(e){console.error(e),v({text:`Failed to upload photo.`,type:`error`})}finally{D(!1)}}},className:`hidden`})]}),p&&(0,s.jsx)(`button`,{type:`button`,onClick:async()=>{if(e){D(!0),T(!1),k(!1);try{let r=(0,o.ref)(t.It,`user_avatars/${e.uid}/file.png`);m(``),D(!1);let s=(0,i.doc)(t.Pt,`user_profiles`,e.uid);await Promise.all([(0,o.deleteObject)(r).catch(e=>console.error(e)),(0,a.updateProfile)(e,{photoURL:``}),(0,i.updateDoc)(s,{avatar:``}),j(``)]),await n(),v({text:`Avatar removed.`,type:`success`})}catch(e){console.error(e),v({text:`Failed to delete photo.`,type:`error`}),D(!1)}}},className:`p-2 rounded-full hover:bg-red-500/80 text-white transition-colors`,title:`Delete Photo`,children:(0,s.jsx)(t.y,{className:`w-5 h-5`})})]})]}),(0,s.jsxs)(`div`,{className:`flex-1 text-left`,children:[(0,s.jsx)(`h3`,{className:`font-extrabold text-2xl text-foreground mb-1`,children:l||`User`}),(0,s.jsx)(`div`,{className:`text-[12px] font-mono uppercase tracking-widest text-accent bg-accent/10 px-2.5 py-1 rounded-md border border-accent/20 inline-block`,children:e?.emailVerified?`Verified Account`:`Unverified`}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/40 mt-2 font-medium`,children:e?.email})]})]}),(0,s.jsxs)(`div`,{className:`space-y-6`,children:[(0,s.jsx)(`h3`,{className:`text-[16px] font-extrabold text-foreground flex items-center gap-2`,children:`Account Details`}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-5 md:gap-6`,children:[(0,s.jsx)(t.i,{name:`name`,value:l,onChange:e=>u(e.target.value),label:`Display Name`,placeholder:`John Doe`}),(0,s.jsxs)(`div`,{className:`flex flex-col`,children:[(0,s.jsx)(t.i,{name:`email`,type:`email`,value:d,onChange:e=>f(e.target.value),label:`Email Address`,placeholder:`name@example.com`,required:!0}),(0,s.jsx)(`p`,{className:`text-[11px] text-foreground/40 mt-1.5 px-2 font-medium`,children:`Changing email sends a verification link to the new address.`})]})]})]}),(0,s.jsxs)(`div`,{className:`pt-6 border-t border-[var(--panel-border)]/50`,children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold text-foreground mb-4 flex items-center gap-2`,children:`Change Password`}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-5 md:gap-6`,children:[(0,s.jsx)(t.i,{name:`password`,type:`password`,label:`New Password`,value:y,onChange:e=>b(e.target.value),placeholder:`Minimum 6 characters`}),(0,s.jsx)(t.i,{name:`confirmPassword`,type:`password`,label:`Confirm Password`,value:x,onChange:e=>S(e.target.value),placeholder:`Repeat password`})]})]}),(0,s.jsx)(`div`,{className:`pt-8 border-t border-[var(--panel-border)]/50 flex justify-start w-full`,children:(0,s.jsx)(t.r,{type:`submit`,isLoading:h,className:`px-12 py-3 md:py-2.5 text-[14px] md:text-[15px] font-bold tracking-wide rounded-xl hover:-translate-y-0.5`,children:`Save Changes`})})]})})]})]})}function K(){let[e,n]=(0,r.useState)(!1),[i,o]=(0,r.useState)(null),[l,u]=(0,r.useState)(0),[d,f]=(0,r.useState)(0);return(0,r.useEffect)(()=>{let e;return l>0&&(e=setInterval(()=>u(e=>e-1),1e3)),()=>clearInterval(e)},[l]),(0,s.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mb-16 mt-6 md:mt-8`,children:(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5},className:`w-full max-w-[480px] p-6 md:p-8 lg:p-10 rounded-3xl glass-panel relative glow-hover shadow-[0_8px_32px_rgba(0,0,0,0.08)] text-center`,children:[(0,s.jsx)(`div`,{className:`absolute -inset-[1px] bg-gradient-to-br from-[var(--primary-glow)] to-transparent opacity-40 blur-[15px] rounded-3xl -z-10`}),(0,s.jsx)(`div`,{className:`w-14 h-14 md:w-16 md:h-16 rounded-2xl glass-panel border border-[var(--panel-border)] flex items-center justify-center mx-auto mb-5 md:mb-6 animate-float shadow-xl`,children:(0,s.jsx)(t.W,{className:`w-7 h-7 md:w-8 md:h-8 text-accent opacity-90`})}),(0,s.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,s.jsx)(`h3`,{className:`text-2xl md:text-3xl font-extrabold mb-2 md:mb-3 text-foreground tracking-tight`,children:`Reset Password`}),(0,s.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Enter your email to receive a recovery link.`})]}),i&&(0,s.jsx)(`div`,{className:`p-3 md:p-4 mb-5 md:mb-6 text-[13px] md:text-[14px] font-medium text-emerald-400 bg-emerald-500/10 rounded-xl border border-emerald-500/20 max-w-[360px] mx-auto`,children:i}),(0,s.jsxs)(`form`,{className:`space-y-4 text-left max-w-[360px] mx-auto`,onSubmit:async e=>{e.preventDefault(),n(!0),o(null);let r=new FormData(e.currentTarget).get(`email`);try{await(0,a.sendPasswordResetEmail)(t.Nt,r)}catch(e){console.error(e)}finally{o(`If an account exists, a password reset link has been sent. Please check your inbox (and spam folder).`);let e=d+1;f(e),u(e===1?60:120),n(!1)}},children:[(0,s.jsx)(t.i,{name:`email`,label:`Work Email`,type:`email`,placeholder:`name@company.com`,required:!0}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsx)(t.r,{type:`submit`,className:`w-full py-2.5 md:py-3 text-[14px] font-bold tracking-wide rounded-xl md:rounded-xl transition-all ${l>0?`bg-foreground/5 text-foreground/40 border border-[var(--panel-border)] shadow-none cursor-not-allowed hover:translate-y-0`:`hover:-translate-y-0.5`}`,isLoading:e,disabled:l>0,children:l>0?`Resend link in ${(e=>`${Math.floor(e/60)}:${(e%60).toString().padStart(2,`0`)}`)(l)}`:d>0?`Resend reset password link`:`Send Reset Link`})})]}),(0,s.jsx)(`div`,{className:`mt-6 pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:(0,s.jsxs)(c.Link,{to:`/login`,className:`inline-flex items-center text-[13px] md:text-[14px] text-foreground/70 font-medium hover:text-accent transition-colors tracking-wide`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4 mr-2`}),`Back to Sign In`]})})]})})}var q={free:``,internal:`text-blue-500 border-blue-500/30 bg-blue-500/10`,admin:`text-red-500 border-red-500/30 bg-red-500/10`},J=({level:e})=>e===`free`?null:(0,s.jsx)(`span`,{className:`shrink-0 text-[9px] font-bold uppercase tracking-widest px-1.5 py-0.5 rounded border ${q[e]}`,children:_[e]});function Y(){let{user:e,userRole:n}=A(),[a,l]=(0,r.useState)(!0),u=(0,c.useNavigate)(),{id:d}=(0,c.useParams)(),[f,p]=(0,r.useState)([]),[m,g]=(0,r.useState)(null),[x,S]=(0,r.useState)(!1),[C,w]=(0,r.useState)(``),[T,E]=(0,r.useState)(!1),D=d?f.find(e=>e.id===d)||null:f.length>0?f[0]:null,O=e=>{u(e?`/users/${e.id}`:`/users`)};(0,r.useEffect)(()=>{l(!0);let e=(0,i.onSnapshot)((0,i.collection)(t.Pt,`user_profiles`),e=>{let t=[];e.forEach(e=>{t.push({id:e.id,...e.data()})}),p(t),l(!1),!d&&t.length>0&&u(`/users/${t[0].id}`,{replace:!0})},e=>{console.error(`Error fetching users:`,e),l(!1)});return()=>e()},[d,u]);let k=f.find(t=>t.id===e?.uid),j=e=>e.id===k?.id?!1:e.role!==`admin`||!k?.createdAt?!0:e.createdAt?new Date(k.createdAt).getTime()<=new Date(e.createdAt).getTime():!1,M=async(e,r)=>{if(!(n!==`admin`||!j(e))&&y(e.role)!==r)try{await(0,i.updateDoc)((0,i.doc)(t.Pt,`user_profiles`,e.id),{role:b(r)}),g({text:`Access level set to ${_[r]}`,type:`success`}),setTimeout(()=>g(null),3e3)}catch(e){g({text:e.message,type:`error`}),setTimeout(()=>g(null),3e3)}},N=async(e,r)=>{if(!(n!==`admin`||!j(e)))try{await(0,i.updateDoc)((0,i.doc)(t.Pt,`user_profiles`,e.id),{inactive:r}),g({text:`User ${r?`deactivated`:`activated`} successfully`,type:`success`}),setTimeout(()=>g(null),3e3)}catch(e){g({text:e.message,type:`error`}),setTimeout(()=>g(null),3e3)}},P=async()=>{if(S(!1),!(!D||!j(D)||C===D.displayName))try{await(0,i.updateDoc)((0,i.doc)(t.Pt,`user_profiles`,D.id),{displayName:C}),g({text:`Name updated successfully`,type:`success`}),setTimeout(()=>g(null),3e3)}catch(e){g({text:e.message,type:`error`}),setTimeout(()=>g(null),3e3)}},F=async e=>{let n=e.target.files?.[0];if(!(!n||!D||!j(D))){if(n.size>2*1024*1024){g({text:`File too large. Please select an image under 2MB.`,type:`error`});return}E(!0);try{let e=(0,o.ref)(t.It,`user_avatars/${D.id}/file.png`);await(0,o.uploadBytes)(e,n);let r=await(0,o.getDownloadURL)(e);p(e=>e.map(e=>e.id===D.id?{...e,avatar:r}:e)),await(0,i.updateDoc)((0,i.doc)(t.Pt,`user_profiles`,D.id),{avatar:r}),g({text:`Avatar successfully updated.`,type:`success`}),setTimeout(()=>g(null),3e3)}catch{g({text:`Failed to upload photo.`,type:`error`})}E(!1)}},[I,L]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{let e;return a&&f.length===0?e=setTimeout(()=>L(!0),150):L(!1),()=>clearTimeout(e)},[a,f.length]),a&&f.length===0?I?(0,s.jsx)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center bg-background/60 backdrop-blur-xl transition-all duration-300`,children:(0,s.jsx)(t.L,{className:`w-8 h-8 animate-spin text-accent`})}):null:(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.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:`Users`}),(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`}),`/users`]})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 animate-in fade-in duration-500 pb-20`,children:[(0,s.jsx)(t.s,{children:m&&(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:`p-4 text-[14px] font-medium border ${m.type===`error`?`text-red-500 bg-red-500/10 border-red-500/20 shadow-[0_0_15px_rgba(239,68,68,0.1)]`:`text-emerald-400 bg-emerald-500/10 border-emerald-500/20 shadow-[0_0_15px_rgba(52,211,153,0.1)]`} rounded-xl flex items-center gap-2`,children:[m.type===`success`&&(0,s.jsx)(t.dt,{className:`w-4 h-4 shrink-0`}),m.text]})}),(0,s.jsx)(`div`,{className:`flex justify-start`,children:(0,s.jsx)(W,{})}),(0,s.jsx)(`div`,{className:`glass-panel rounded-3xl border border-[var(--panel-border)] shadow-sm`,children:f.length===0?(0,s.jsx)(`div`,{className:`p-8 text-center text-foreground/50 text-[14px]`,children:`No members found.`}):(0,s.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 min-h-[500px]`,children:[(0,s.jsxs)(`div`,{className:`md:col-span-1 border-r md:border-r-[var(--panel-border)] border-b md:border-b-0 border-[var(--panel-border)] flex flex-col hide-scrollbar bg-foreground/[0.03] rounded-t-3xl md:rounded-tr-none md:rounded-l-3xl`,children:[(0,s.jsx)(`div`,{className:`p-4 border-b border-[var(--panel-border)] font-bold text-[13px] text-foreground/70 uppercase tracking-wider`,children:`System Users`}),(0,s.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-2`,children:f.map(e=>(0,s.jsxs)(`div`,{onClick:()=>O(e),className:`p-4 py-5 rounded-2xl border transition-all flex items-center gap-4 cursor-pointer ${D?.id===e.id?`bg-accent/10 border-accent/40 shadow-sm`:`glass-panel border-transparent hover:border-[var(--panel-border)]`} ${e.inactive?`opacity-50 grayscale`:``}`,children:[(0,s.jsx)(`div`,{className:`w-12 h-12 rounded-full overflow-hidden bg-accent/20 shrink-0 flex items-center justify-center border border-[var(--panel-border)]`,children:e.avatar||e.photoURL?(0,s.jsx)(`img`,{src:e.avatar||e.photoURL,alt:``,className:`w-full h-full object-cover`}):(0,s.jsx)(t.m,{className:`w-5 h-5 text-accent`})}),(0,s.jsxs)(`div`,{className:`flex flex-col truncate`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 truncate`,children:[(0,s.jsx)(`span`,{className:`font-bold text-[14px] truncate`,children:e.displayName||`No Name`}),(0,s.jsx)(J,{level:y(e.role)})]}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/50 truncate font-mono mt-0.5`,children:e.email})]})]},e.id))})]}),(0,s.jsx)(`div`,{className:`md:col-span-2 flex flex-col p-6 md:p-10 relative`,children:D?(0,s.jsxs)(`div`,{className:`animate-in fade-in duration-300 w-full max-w-lg`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-6 md:gap-8 mb-10`,children:[(0,s.jsxs)(`div`,{className:`w-24 h-24 rounded-full glass-panel border-4 border-[var(--panel-border)] shadow-xl bg-accent/10 flex items-center justify-center relative overflow-hidden shrink-0 group`,children:[T?(0,s.jsx)(t.L,{className:`w-8 h-8 text-accent animate-spin`}):D.avatar||D.photoURL?(0,s.jsx)(`img`,{src:D.avatar||D.photoURL,alt:`Avatar`,className:`w-full h-full object-cover`}):(0,s.jsx)(t.m,{className:`w-10 h-10 text-accent`}),!T&&j(D)&&(0,s.jsx)(`div`,{className:`absolute inset-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center z-10 backdrop-blur-md`,children:(0,s.jsxs)(`label`,{className:`flex flex-col items-center justify-center cursor-pointer p-2 hover:bg-white/20 transition-colors text-white rounded-full`,title:`Upload Photo`,children:[(0,s.jsx)(t.yt,{className:`w-5 h-5`}),(0,s.jsx)(`input`,{type:`file`,accept:`image/*`,onChange:F,className:`hidden`})]})})]}),(0,s.jsxs)(`div`,{className:`flex flex-col flex-1 w-full relative`,children:[x?(0,s.jsx)(`input`,{autoFocus:!0,value:C,onChange:e=>w(e.target.value),onBlur:P,onKeyDown:e=>e.key===`Enter`&&P(),className:`text-2xl md:text-3xl font-extrabold mb-1 bg-transparent border-b-2 border-accent outline-none text-foreground w-full py-1`}):(0,s.jsx)(`h3`,{onDoubleClick:()=>{j(D)&&(w(D.displayName||``),S(!0))},className:`text-2xl md:text-3xl font-extrabold mb-1 select-none ${j(D)?`cursor-pointer hover:text-accent transition-colors`:``}`,title:j(D)?`Double-click to edit`:``,children:D.displayName||`No Name`}),(0,s.jsx)(`p`,{className:`text-[14px] font-mono text-foreground/50`,children:D.email}),!j(D)&&D.id!==k?.id&&(0,s.jsxs)(`p`,{className:`mt-2 flex items-center gap-1.5 text-[12px] font-medium text-foreground/45`,children:[(0,s.jsx)(t.I,{className:`w-3 h-3 shrink-0`}),`Admin since before you, so only they can change this account.`]})]})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,s.jsxs)(`div`,{className:`p-4 rounded-2xl glass-panel border border-[var(--panel-border)] flex flex-col gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col`,children:[(0,s.jsx)(`span`,{className:`font-bold text-[14px] text-foreground`,children:`Access level`}),(0,s.jsx)(`span`,{className:`text-[12px] text-foreground/50`,children:`What this person can open`})]}),(0,s.jsx)(`div`,{role:`radiogroup`,"aria-label":`Access level`,className:`flex items-center gap-1.5 flex-wrap ${j(D)?``:`opacity-50`}`,children:h.map(e=>{let t=y(D.role)===e;return(0,s.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t,disabled:!j(D),onClick:()=>M(D,e),className:`h-8 px-3.5 rounded-full text-[12.5px] font-semibold border transition-all ${t?`bg-accent/10 border-accent/40 text-accent`:`border-[var(--panel-border)] text-foreground/55 hover:text-foreground hover:border-accent/30`} ${j(D)?`cursor-pointer`:`cursor-not-allowed`}`,children:_[e]},e)})})]}),(0,s.jsx)(`p`,{className:`text-[12px] text-foreground/50 leading-relaxed`,children:v[y(D.role)]})]}),(0,s.jsxs)(`div`,{className:`p-4 rounded-2xl glass-panel border flex items-center justify-between ${D.inactive?`border-amber-500/30 bg-amber-500/5`:`border-red-500/20 bg-red-500/5`}`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col`,children:[(0,s.jsx)(`span`,{className:`font-bold text-[14px] ${D.inactive?`text-amber-500`:`text-red-500`}`,children:D.inactive?`Reactivate User`:`Deactivate User`}),(0,s.jsx)(`span`,{className:`text-[12px] ${D.inactive?`text-amber-500/70`:`text-red-500/70`}`,children:`Block access to this app`})]}),(0,s.jsx)(`button`,{type:`button`,disabled:!j(D),onClick:()=>N(D,!D.inactive),className:`relative inline-flex h-7 w-12 items-center rounded-full transition-colors focus:outline-none shadow-inner ${D.inactive?`bg-amber-500`:`bg-red-500/20`} ${j(D)?`cursor-pointer`:`opacity-50 cursor-not-allowed`}`,children:(0,s.jsx)(`span`,{className:`inline-block h-5 w-5 transform rounded-full bg-white transition-transform shadow-md ${D.inactive?`translate-x-6`:`translate-x-1`}`})})]})]})]}):(0,s.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center opacity-30 pointer-events-none`,children:[(0,s.jsx)(t.p,{className:`w-12 h-12 mb-4`}),(0,s.jsx)(`p`,{className:`font-bold tracking-widest uppercase text-[12px]`,children:`Select a User`})]})})]})})]})]})}function re({isOpen:e,title:n,message:r,confirmText:i=`Delete`,cancelText:a=`Cancel`,onConfirm:o,onCancel:c,isProcessing:l=!1,disableConfirm:u=!1}){return(0,s.jsx)(t.s,{children:e&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>!l&&c(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(0,s.jsx)(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:`w-full max-w-[400px] p-6 rounded-3xl glass-popover border border-[var(--panel-border)] shadow-2xl relative z-10 text-center`,children:(0,s.jsxs)(`div`,{className:`w-full flex flex-col items-center`,children:[(0,s.jsx)(`h3`,{className:`text-xl font-extrabold mb-2 text-foreground tracking-tight`,children:n}),(0,s.jsx)(`p`,{className:`w-full text-[14px] font-medium text-foreground/60 leading-relaxed mb-6 break-words`,children:r}),(0,s.jsxs)(`div`,{className:`flex items-center gap-3 w-full`,children:[(0,s.jsx)(t.r,{variant:`secondary`,onClick:c,disabled:l,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:a}),(0,s.jsx)(t.r,{onClick:o,disabled:l||u,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl bg-red-500 hover:bg-red-600 border-none text-white shadow-xl hover:shadow-red-500/20 glow-hover`,children:l?(0,s.jsx)(t.L,{className:`w-5 h-5 animate-spin mx-auto`}):i})]})]})})]})})}var ie=`rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)] transition-colors hover:border-accent/40`,ae=`inline-flex items-center justify-center gap-1.5 h-9 px-3 rounded-[var(--btn-radius,0.75rem)] text-[12.5px] font-semibold border border-[var(--panel-border)] bg-transparent text-foreground/60 hover:text-foreground hover:border-accent/40 hover:bg-foreground/[0.04] active:scale-[0.98] transition-all cursor-pointer disabled:opacity-40 disabled:pointer-events-none`,oe=`w-full h-11 px-4 rounded-[var(--input-radius,0.75rem)] border border-[var(--panel-border)] bg-[var(--panel-bg)] text-[14px] text-foreground outline-none transition-all duration-300 placeholder:text-foreground/35 hover:border-accent/40 focus:border-accent disabled:opacity-50 disabled:cursor-not-allowed console-field`,se=`w-full h-11 flex items-center px-4 rounded-[var(--input-radius,0.75rem)] border border-[var(--panel-border)] bg-[var(--panel-bg)] transition-all duration-300 hover:border-accent/40 focus-within:border-accent console-field`,X=`flex-1 min-w-0 h-full bg-transparent border-none outline-none shadow-none text-[14px] text-foreground placeholder:text-foreground/35 disabled:cursor-not-allowed`,ce=`text-[13px] font-medium text-foreground/50 select-none`;function Z({state:e=`saved`,label:n}){return(0,s.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[11.5px] font-semibold text-foreground/50 whitespace-nowrap shrink-0`,children:[e===`saving`?(0,s.jsx)(t.L,{className:`w-3 h-3 animate-spin text-foreground/40 shrink-0`}):(0,s.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 ${e===`saved`?`bg-emerald-500`:e===`error`?`bg-red-500`:`bg-foreground/25`}`}),n]})}function Q({icon:e,children:n,onClick:r,disabled:i,busy:a,tone:o=`default`,className:c=``,title:l}){return(0,s.jsxs)(`button`,{type:`button`,title:l,onClick:r,disabled:i||a,className:`${ae} ${o===`danger`?`hover:text-red-500 hover:border-red-500/40 hover:bg-red-500/[0.06]`:``} ${c}`,children:[a?(0,s.jsx)(t.L,{className:`w-3.5 h-3.5 animate-spin shrink-0`}):e?(0,s.jsx)(e,{className:`w-3.5 h-3.5 shrink-0`}):null,n]})}function le({icon:e,title:n,description:i,actions:a,children:o,defaultOpen:c=!0,collapsible:l=!0}){let[u,d]=(0,r.useState)(c),f=l?u:!0;return(0,s.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)] overflow-hidden`,children:[(0,s.jsxs)(`div`,{className:`w-full px-5 py-4 flex items-start justify-between gap-4 text-left`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,s.jsxs)(`span`,{className:`flex items-center gap-2 min-w-0`,children:[e&&(0,s.jsx)(e,{className:`w-4 h-4 text-accent shrink-0`}),(0,s.jsx)(`span`,{className:`text-[14.5px] font-bold text-foreground tracking-tight truncate`,children:n})]}),i&&(0,s.jsx)(`span`,{className:`text-[11.5px] text-foreground/40 font-medium leading-snug ${e?`pl-6`:``}`,children:i})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[a,l&&(0,s.jsx)(`button`,{type:`button`,onClick:()=>d(e=>!e),"aria-expanded":f,"aria-label":f?`Collapse ${n}`:`Expand ${n}`,className:`w-8 h-8 rounded-lg flex items-center justify-center text-foreground/40 hover:text-foreground hover:bg-foreground/5 transition-colors cursor-pointer`,children:(0,s.jsx)(t.gt,{className:`w-4 h-4 transition-transform duration-200 ${f?`rotate-180`:``}`})})]})]}),(0,s.jsx)(t.s,{initial:!1,children:f&&(0,s.jsx)(t.o.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden`,children:(0,s.jsx)(`div`,{className:`border-t border-[var(--panel-border)]/60 px-5 py-5 flex flex-col gap-5`,children:o})})})]})}function ue({label:e,hint:t,action:n,children:r,error:i}){return(0,s.jsxs)(`div`,{className:`flex flex-col w-full`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 mb-1.5 ml-1`,children:[(0,s.jsx)(`label`,{className:ce,children:e}),n]}),r,t&&!i&&(0,s.jsx)(`span`,{className:`text-[11.5px] text-foreground/40 font-medium leading-snug mt-1.5 px-1`,children:t}),i&&(0,s.jsx)(`span`,{className:`text-[11.5px] font-semibold text-red-500 leading-snug mt-1.5 px-1`,children:i})]})}function de({label:e,hint:t,value:n,onChange:r,onBlur:i,placeholder:a,prefix:o,error:c,disabled:l,action:u}){return(0,s.jsx)(ue,{label:e,hint:t,error:c,action:u,children:o?(0,s.jsxs)(`div`,{className:`${se} ${c?`is-invalid border-red-500/60`:``} ${l?`opacity-50`:``}`,children:[(0,s.jsx)(`span`,{className:`mr-0.5 text-[14px] font-semibold text-foreground/40 select-none shrink-0`,children:o}),(0,s.jsx)(`input`,{type:`text`,value:n??``,disabled:l,placeholder:a,onChange:e=>r(e.target.value),onBlur:i,"aria-label":e,className:`${X} no-glow`})]}):(0,s.jsx)(`input`,{type:`text`,value:n??``,disabled:l,placeholder:a,onChange:e=>r(e.target.value),onBlur:i,"aria-label":e,className:`${oe} ${c?`is-invalid border-red-500/60`:``}`})})}function fe({label:e,hint:t,value:n,onChange:r,onBlur:i,placeholder:a,rows:o=3}){return(0,s.jsx)(ue,{label:e,hint:t,children:(0,s.jsx)(`textarea`,{rows:o,value:n??``,placeholder:a,onChange:e=>r(e.target.value),onBlur:i,"aria-label":e,className:`${oe} h-auto py-3 leading-relaxed resize-y`})})}function pe({label:e,hint:n,value:r,onChange:i,options:a,placeholder:o=`None`,allowEmpty:c=!0,disabled:l}){let u=[...c?[{value:``,label:o}]:[],...a.filter(e=>e.value!==``)];return(0,s.jsx)(ue,{label:e,hint:n,children:(0,s.jsx)(t.n,{ariaLabel:e,value:r??``,options:u,onChange:i,disabled:l,className:`console-select`,portal:!0,direction:`auto`})})}function me({label:e,hint:t,enabled:n,onChange:r,disabled:i}){return(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-4 w-full`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0 ml-1`,children:[(0,s.jsx)(`span`,{className:`text-[13px] font-medium text-foreground/80`,children:e}),t&&(0,s.jsx)(`span`,{className:`text-[11.5px] text-foreground/40 font-medium leading-snug`,children:t})]}),(0,s.jsx)(he,{enabled:n,onChange:r,disabled:i,label:e})]})}function he({enabled:e,onChange:t,disabled:n,label:r}){return(0,s.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":e,"aria-label":r,disabled:n,onClick:n=>{n.stopPropagation(),t(!e)},className:`relative w-10 h-6 rounded-full transition-colors shrink-0 cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed ${e?`bg-accent`:`bg-foreground/15`}`,children:(0,s.jsx)(`span`,{className:`absolute top-1 left-1 w-4 h-4 rounded-full bg-[var(--button-fg,#fff)] shadow transition-transform ${e?`translate-x-4`:`translate-x-0`}`})})}function ge({saving:e,savedAt:t}){return e?(0,s.jsx)(Z,{state:`saving`,label:`Saving`}):t?(0,s.jsx)(Z,{state:`saved`,label:`Saved`}):null}var _e=e=>e.trim().split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),ve=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/([A-Z])([A-Z][a-z])/g,`$1-$2`).toLowerCase(),ye=e=>{let t=e.replace(/-/g,` `);return t.charAt(0).toUpperCase()+t.slice(1)},be=(()=>{let e=t.l,n=e?Object.keys(e):[];return Array.from(new Set(n.map(ve))).sort()})(),xe=`layers.house.layout-dashboard.list.table.kanban.calendar.clock.file-text.files.folder.hard-drive.upload.download.paperclip.book-open.notebook-pen.users.user.user-plus.contact.building-2.briefcase.handshake.mail.message-square.message-circle.send.inbox.bell.megaphone.phone.shopping-cart.package.truck.receipt.credit-card.banknote.wallet.tag.percent.chart-bar.chart-line.chart-pie.trending-up.target.gauge.activity.settings.sliders-horizontal.wrench.shield.lock.key.eye.search.star.heart.bookmark.flag.pin.map-pin.globe.circle-check.circle-alert.info.circle-help.life-buoy.sparkles.zap.rocket.camera.image.video.music.mic.palette.pen-tool.scissors.stethoscope.graduation-cap.utensils.plane.car.dumbbell.leaf.sun.moon`.split(`.`),Se={money:[`banknote`,`wallet`,`credit-card`,`coins`,`dollar-sign`,`receipt`],cash:[`banknote`,`coins`,`wallet`],payment:[`credit-card`,`banknote`,`receipt`],invoice:[`receipt`,`file-text`],price:[`tag`,`dollar-sign`,`receipt`],people:[`users`,`user`,`contact`],customer:[`users`,`contact`,`user-round`],client:[`users`,`contact`,`briefcase`],team:[`users`,`users-round`],staff:[`users`,`id-card`],chat:[`message-circle`,`message-square`,`messages-square`],message:[`message-circle`,`mail`,`send`],email:[`mail`,`send`,`inbox`],task:[`list-checks`,`square-check`,`clipboard-check`],todo:[`list-checks`,`square-check`],project:[`kanban`,`folder-kanban`,`briefcase`],board:[`kanban`,`layout-dashboard`],photo:[`image`,`camera`,`images`],picture:[`image`,`images`],document:[`file-text`,`files`,`file`],doc:[`file-text`,`file`],shop:[`shopping-cart`,`store`,`shopping-bag`],store:[`store`,`shopping-bag`,`shopping-cart`],order:[`shopping-cart`,`package`,`receipt`],delivery:[`truck`,`package`],home:[`house`,`home`],booking:[`calendar-check`,`calendar`,`clock`],appointment:[`calendar-clock`,`calendar`,`clock`],schedule:[`calendar-days`,`calendar`,`clock`],event:[`calendar`,`party-popper`,`ticket`],report:[`chart-bar`,`chart-line`,`file-chart-column`],stats:[`chart-bar`,`chart-line`,`chart-pie`],analytics:[`chart-line`,`chart-bar`,`activity`],help:[`circle-help`,`life-buoy`,`info`],support:[`life-buoy`,`headset`,`circle-help`],idea:[`lightbulb`,`sparkles`],health:[`heart-pulse`,`stethoscope`,`activity`],food:[`utensils`,`chef-hat`,`pizza`],travel:[`plane`,`map`,`luggage`],location:[`map-pin`,`map`,`globe`],address:[`map-pin`,`house`],security:[`shield`,`lock`,`key`],password:[`key`,`lock`],settings:[`settings`,`sliders-horizontal`,`wrench`],file:[`file`,`file-text`,`files`,`folder`],upload:[`upload`,`cloud-upload`],video:[`video`,`film`,`clapperboard`],school:[`graduation-cap`,`book-open`,`school`],course:[`graduation-cap`,`book-open`],gym:[`dumbbell`,`activity`],garden:[`leaf`,`flower`,`sprout`],car:[`car`,`car-front`],pet:[`paw-print`,`dog`,`cat`],note:[`notebook-pen`,`sticky-note`,`pencil`],write:[`pencil`,`pen-tool`,`notebook-pen`],time:[`clock`,`timer`,`hourglass`],star:[`star`,`sparkles`],favourite:[`star`,`heart`,`bookmark`],favorite:[`star`,`heart`,`bookmark`]},Ce=(e,t)=>{if(Math.abs(e.length-t.length)>2)return 3;let n=Array.from({length:t.length+1},(e,t)=>t);for(let r=1;r<=e.length;r++){let i=n[0];n[0]=r;for(let a=1;a<=t.length;a++){let o=n[a];n[a]=Math.min(n[a]+1,n[a-1]+1,i+(e[r-1]===t[a-1]?0:1)),i=o}}return n[t.length]},we=(e,t)=>{let n=0;for(let r of t)r===e[n]&&n++;return n===e.length};function Te(e,t=24,n=be){let r=e.trim().toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``);if(!r)return[];let i=r.split(`-`).filter(Boolean),a=new Set(n),o=new Map,s=(e,t)=>{a.has(e)&&o.set(e,Math.max(o.get(e)||0,t))};for(let e of n){let t=e.split(`-`);if(e===r){s(e,100);continue}if(e.startsWith(r)){s(e,90);continue}if(t.some(e=>e===r)){s(e,85);continue}if(t.some(e=>e.startsWith(r))){s(e,75);continue}if(e.includes(r)){s(e,65);continue}if(i.length>1&&i.every(e=>t.some(t=>t.startsWith(e)))){s(e,60);continue}}for(let e of i){for(let t of Se[e]||[])s(t,70);if(e.endsWith(`s`))for(let t of Se[e.slice(0,-1)]||[])s(t,70)}if(o.size===0&&r.length>=3)for(let e of n)e.split(`-`).some(e=>Ce(r,e)<=(r.length>5?2:1))?s(e,40):r.length>=4&&we(r,e.replace(/-/g,``))&&s(e,20);let c=e=>{let t=xe.indexOf(e);return t===-1?xe.length:t};return Array.from(o.entries()).sort((e,t)=>t[1]-e[1]||c(e[0])-c(t[0])||e[0].length-t[0].length||e[0].localeCompare(t[0])).slice(0,t).map(([e])=>e)}function Ee(e){if(!e)return t.U;let n=e.trim(),r=t.c;return r[_e(n)]||r[n]||t.U}function De({name:e,className:t}){return(0,r.createElement)(Ee(e),{className:t})}function Oe({label:e=`Icon`,hint:n=`Shown next to the name in the menu.`,value:i,onChange:a}){let[o,c]=(0,r.useState)(``),l=(i||``).trim(),u=(0,r.useMemo)(()=>Te(o),[o]),d=o.trim().length>0;return(0,s.jsx)(ue,{label:e,hint:n,action:l?(0,s.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[11.5px] font-medium text-foreground/45 min-w-0`,children:[(0,s.jsx)(De,{name:l,className:`w-3.5 h-3.5 text-accent shrink-0`}),(0,s.jsx)(`span`,{className:`truncate`,children:ye(ve(l))})]}):void 0,children:(0,s.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,s.jsxs)(`div`,{className:se,children:[(0,s.jsx)(t.E,{className:`w-4 h-4 mr-2.5 text-foreground/30 shrink-0`}),(0,s.jsx)(`input`,{type:`text`,value:o,onChange:e=>c(e.target.value),placeholder:`Type a word to change it, e.g. calendar`,"aria-label":`Search icons`,className:`${X} no-glow`})]}),d&&(0,s.jsx)(`div`,{className:`rounded-[var(--input-radius,0.75rem)] border border-[var(--panel-border)] bg-[var(--panel-bg)] p-2`,children:u.length>0?(0,s.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>{let t=ve(l).toLowerCase()===e;return(0,s.jsx)(`button`,{type:`button`,title:ye(e),"aria-label":ye(e),"aria-pressed":t,onClick:()=>{a(e),c(``)},className:`w-9 h-9 rounded-lg flex items-center justify-center transition-all cursor-pointer ${t?`bg-accent text-[var(--button-fg,#fff)]`:`text-foreground/60 hover:text-foreground hover:bg-foreground/[0.06]`}`,children:(0,s.jsx)(De,{name:e,className:`w-4 h-4`})},e)})}):(0,s.jsx)(`span`,{className:`block px-2 py-2 text-[12px] font-medium text-foreground/45`,children:`Nothing close to that. Try a simpler word, like calendar or people.`})})]})})}function ke({title:e=`Ask your assistant`,description:n,prompt:i,compact:a=!1,locked:o=!1,lockedHint:c}){let[l,u]=(0,r.useState)(!1),d=i.includes(`
2
+ `);return(0,s.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)] ${a?`px-4 py-3.5`:`px-5 py-4`}`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,s.jsx)(`span`,{className:`text-[12px] font-extrabold tracking-tight text-gradient`,children:e}),(0,s.jsxs)(`button`,{type:`button`,onClick:()=>{o||(navigator.clipboard?.writeText(i),u(!0),setTimeout(()=>u(!1),2e3))},disabled:o,"aria-disabled":o,className:`inline-flex items-center justify-center gap-1.5 h-8 px-3 rounded-[var(--btn-radius,0.75rem)] text-[12px] font-semibold shrink-0 border transition-all active:scale-[0.98] ${o?`border-[var(--panel-border)] text-foreground/30 cursor-not-allowed active:scale-100`:l?`border-emerald-500/30 bg-emerald-500/10 text-emerald-500 cursor-pointer`:`border-[var(--panel-border)] text-foreground/60 hover:text-accent hover:border-accent/40 cursor-pointer`}`,children:[l?(0,s.jsx)(t._t,{className:`w-3.5 h-3.5`}):(0,s.jsx)(t.at,{className:`w-3.5 h-3.5`}),l?`Copied`:`Copy`]})]}),n&&(0,s.jsx)(`p`,{className:`text-[12.5px] text-foreground/50 font-medium leading-relaxed`,children:n}),o?(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/45 font-medium leading-relaxed`,children:c||`Fill in the fields above first.`}):(0,s.jsx)(`p`,{className:`text-[13.5px] text-foreground/80 font-medium leading-relaxed whitespace-pre-line`,children:d?i:`“${i}”`})]})}var Ae={anyone:{collectionName:`user_submissions`,chip:`Anyone`,filterLabel:`From anyone`},signedIn:{collectionName:`user_requests`,chip:`Signed-in user`,filterLabel:`From signed-in users`}},je=`Create a form called Ask a question for website visitors. Ask for full name (required), email (required) and their question as long text (required). Put it on my /contact page built into the page, send the answers to my Inbox, and show a thank-you message after sending.`,Me=[`id`,`source`,`uid`,`submittedAt`,`avatarUrl`,`isArchived`,`name`,`full_name`,`email`,`contactEmail`,`topic`],Ne=e=>{let t=e.submittedAt;if(!t)return 0;if(typeof t.toMillis==`function`)return t.toMillis();if(typeof t.toDate==`function`)return t.toDate().getTime();let n=new Date(t).getTime();return Number.isNaN(n)?0:n},Pe=e=>{if(!e)return`Just now`;let t=e.toDate?e.toDate():new Date(e);return new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`,hour:`numeric`,minute:`numeric`}).format(t)},Fe=e=>e.submitterName||e.name||e.full_name||`Anonymous`,Ie=e=>e.contactEmail||e.email||`No email provided`;function Le(e){let[n,a]=(0,r.useState)([]),[o,s]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{let n=!1,r=Ae[e].collectionName,o=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Pt,r),(0,i.orderBy)(`submittedAt`,`desc`)),async r=>{let o=[];for(let n of r.docs){let r={...n.data()},a=``;if(r.uid&&r.uid!==`guest`)try{let e=await(0,i.getDoc)((0,i.doc)(t.Pt,`user_profiles`,r.uid));if(e.exists()){let t=e.data();(t.avatar||t.photoURL)&&(a=t.avatar||t.photoURL),r.name||=t.name||t.displayName,r.email||=t.email,r.contactEmail||=t.email}}catch(e){console.error(`Failed to fetch profile`,e)}o.push({...r,id:n.id,source:e,avatarUrl:a})}n||(a(o),s(!1))},e=>{console.error(`Error loading ${r}:`,e),n||s(!1)});return()=>{n=!0,o()}},[e]),{items:n,loading:o}}function Re({source:e}){return(0,s.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest text-accent bg-accent/10 px-2 py-0.5 rounded-md border border-accent/20 shrink-0`,children:Ae[e].chip})}function ze({item:e,isExpanded:n,onToggle:r,onArchive:i,onDelete:a,busy:o,dimmed:l}){let u=Fe(e),d=e.avatarUrl||e.submitterAvatar,f=!!e.uid&&e.uid!==`guest`,p=Object.entries(e).filter(([e])=>!Me.includes(e)&&!e.toLowerCase().startsWith(`submitter`)&&e.toLowerCase()!==`formid`);return(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-2xl flex flex-col overflow-hidden hover:border-accent/40 transition-all duration-300 ${l?`opacity-60 hover:opacity-100`:``}`,children:[(0,s.jsxs)(`div`,{className:`w-full flex items-center gap-3 p-4 md:px-6`,children:[(0,s.jsxs)(`button`,{type:`button`,onClick:r,"aria-expanded":n,className:`flex items-center gap-4 flex-1 min-w-0 text-left cursor-pointer`,children:[(0,s.jsx)(`div`,{className:`relative shrink-0`,children:d?(0,s.jsx)(`img`,{src:d,alt:``,className:`w-10 h-10 rounded-full object-cover border border-[var(--panel-border)] shadow-sm`}):(0,s.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-accent/10 text-accent flex items-center justify-center font-bold border border-accent/20 shadow-sm uppercase`,children:(u||`A`)[0]})}),(0,s.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,s.jsx)(`span`,{className:`font-bold text-[14px] md:text-[15px] text-foreground truncate`,children:u}),(0,s.jsx)(Re,{source:e.source}),e.formId&&(0,s.jsx)(`span`,{className:`hidden sm:inline text-[10px] font-bold uppercase tracking-widest text-foreground/40 bg-foreground/5 px-2 py-0.5 rounded-md border border-[var(--panel-border)] shrink-0`,children:String(e.formId).replace(/_/g,` `)})]}),(0,s.jsxs)(`span`,{className:`text-[13px] text-foreground/50 truncate flex items-center gap-1.5 font-medium mt-0.5`,children:[(0,s.jsx)(t.P,{className:`w-3.5 h-3.5 shrink-0`}),` `,Ie(e)]})]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`div`,{className:`hidden lg:block text-[12px] font-medium text-foreground/40`,children:Pe(e.submittedAt)}),(0,s.jsx)(Q,{icon:e.isArchived?t.Dt:t.Et,onClick:i,busy:o,children:(0,s.jsx)(`span`,{className:`hidden sm:inline`,children:e.isArchived?`Restore`:`Archive`})}),(0,s.jsx)(Q,{icon:t.y,tone:`danger`,onClick:a,children:(0,s.jsx)(`span`,{className:`hidden sm:inline`,children:`Delete`})}),(0,s.jsx)(`button`,{type:`button`,onClick:r,"aria-label":n?`Hide details from ${u}`:`Show details from ${u}`,className:`p-1.5 text-foreground/40 transition-transform duration-300 cursor-pointer ${n?`rotate-180`:``}`,children:(0,s.jsx)(t.gt,{className:`w-4 h-4`})})]})]}),(0,s.jsx)(t.s,{children:n&&(0,s.jsx)(t.o.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden`,children:(0,s.jsxs)(`div`,{className:`p-4 md:p-6 pt-0 mt-2 border-t border-[var(--panel-border)]/30`,children:[(0,s.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 mb-4 mt-4`,children:[(0,s.jsx)(`span`,{className:`lg:hidden text-[12px] font-medium text-foreground/40`,children:Pe(e.submittedAt)}),f&&(0,s.jsx)(c.Link,{to:`/users/${e.uid}`,className:`text-[12.5px] font-bold text-accent hover:underline`,children:`Open this person’s profile`})]}),e.topic&&(0,s.jsxs)(`div`,{className:`flex items-center gap-2 mb-4 text-[13px] text-foreground/70 bg-foreground/5 px-4 py-2.5 rounded-xl w-fit border border-[var(--panel-border)]`,children:[(0,s.jsx)(t.ft,{className:`w-4 h-4 text-accent`}),(0,s.jsx)(`span`,{className:`font-medium text-accent`,children:`Topic:`}),(0,s.jsx)(`span`,{className:`font-bold`,children:e.topic})]}),p.map(([e,t])=>(0,s.jsxs)(`div`,{className:`bg-foreground/[0.02] rounded-2xl p-5 border border-[var(--panel-border)] mb-3`,children:[(0,s.jsx)(`span`,{className:`block text-[12px] font-bold uppercase tracking-widest text-accent mb-3`,children:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}),(0,s.jsx)(`p`,{className:`text-[14px] md:text-[15px] text-foreground/80 leading-relaxed whitespace-pre-wrap font-medium`,children:typeof t==`boolean`?t?`Yes`:`No`:e.toLowerCase()===`budget`&&t?`$${t}`:String(t??``)||`No data provided`})]},e))]})})})]})}function Be(){let e=Le(`anyone`),n=Le(`signedIn`),[a,o]=(0,r.useState)(`all`),[c,l]=(0,r.useState)(null),[u,d]=(0,r.useState)(!1),[f,p]=(0,r.useState)(null),[m,h]=(0,r.useState)(null),[g,_]=(0,r.useState)(!1),v=e.loading||n.loading,y=(0,r.useMemo)(()=>[...e.items,...n.items].sort((e,t)=>Ne(t)-Ne(e)),[e.items,n.items]),b=a===`all`?y:y.filter(e=>e.source===a),x=b.filter(e=>!e.isArchived),S=b.filter(e=>e.isArchived),C=e=>`${e.source}:${e.id}`,w=e=>l(t=>t===C(e)?null:C(e)),T=async e=>{p(C(e));try{await(0,i.updateDoc)((0,i.doc)(t.Pt,Ae[e.source].collectionName,e.id),{isArchived:!e.isArchived}),!e.isArchived&&c===C(e)&&l(null)}catch(e){console.error(`Failed to archive`,e)}p(null)},E=async()=>{if(m){_(!0);try{await(0,i.deleteDoc)((0,i.doc)(t.Pt,Ae[m.source].collectionName,m.id)),c===C(m)&&l(null),h(null)}catch(e){console.error(`Failed to delete`,e)}_(!1)}},D=[{key:`all`,label:`Everything`},{key:`anyone`,label:Ae.anyone.filterLabel},{key:`signedIn`,label:Ae.signedIn.filterLabel}];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.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:`Inbox`}),(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`}),`/inbox`]})]}),(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 flex flex-col glass-panel rounded-3xl p-6 md:p-10 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/5 blur-[100px] rounded-full pointer-events-none`}),(0,s.jsx)(`div`,{className:`relative z-10 flex-1 flex flex-col`,children:v?(0,s.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[500px]`,children:(0,s.jsx)(`div`,{className:`w-8 h-8 md:w-10 md:h-10 border-4 border-accent/20 border-t-accent rounded-full animate-spin`})}):y.length===0?(0,s.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center p-8 gap-6`,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 shadow-inner`,children:(0,s.jsx)(t.q,{className:`w-6 h-6`})}),(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground mb-2`,children:`Nothing here yet`}),(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/50 font-medium max-w-md`,children:`Everything people send you through a form on your site lands here.`})]}),(0,s.jsx)(`div`,{className:`w-full max-w-xl text-left`,children:(0,s.jsx)(ke,{prompt:je})})]}):(0,s.jsxs)(`div`,{className:`flex flex-col gap-3 pb-8`,children:[(0,s.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 mb-2`,children:D.map(e=>(0,s.jsx)(`button`,{type:`button`,onClick:()=>o(e.key),"aria-pressed":a===e.key,className:`h-9 px-4 rounded-full text-[12.5px] font-bold border transition-all cursor-pointer ${a===e.key?`bg-accent/10 border-accent/40 text-accent`:`border-[var(--panel-border)]/70 bg-background/60 text-foreground/60 hover:text-foreground hover:border-accent/30`}`,children:e.label},e.key))}),x.length===0&&(0,s.jsx)(`div`,{className:`bg-foreground/[0.02] border border-dashed border-[var(--panel-border)] rounded-2xl flex flex-col items-center justify-center p-8 text-center mb-4`,children:(0,s.jsx)(`p`,{className:`text-[14px] font-bold text-foreground/50`,children:S.length>0?`Everything here is archived.`:`Nothing matches this filter.`})}),(0,s.jsx)(t.s,{children:x.map(e=>(0,s.jsx)(ze,{item:e,isExpanded:c===C(e),onToggle:()=>w(e),onArchive:()=>T(e),onDelete:()=>h(e),busy:f===C(e)},C(e)))}),S.length>0&&(0,s.jsxs)(`div`,{className:`mt-6 pt-4 border-t border-[var(--panel-border)]/30`,children:[(0,s.jsx)(`div`,{className:`flex justify-center`,children:(0,s.jsxs)(`button`,{type:`button`,onClick:()=>d(e=>!e),className:`flex items-center gap-2 text-[11px] font-bold text-foreground/40 hover:text-foreground/70 transition-colors py-2 uppercase tracking-widest cursor-pointer`,children:[u?`Hide`:`View`,` `,S.length,` archived`,(0,s.jsx)(t.gt,{className:`w-3.5 h-3.5 transition-transform duration-300 ${u?`rotate-180`:``}`})]})}),(0,s.jsx)(t.s,{children:u&&(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`,children:(0,s.jsx)(`div`,{className:`flex flex-col gap-3`,children:S.map(e=>(0,s.jsx)(ze,{item:e,isExpanded:c===C(e),onToggle:()=>w(e),onArchive:()=>T(e),onDelete:()=>h(e),busy:f===C(e),dimmed:!0},C(e)))})})})]})]})})]})]}),(0,s.jsx)(re,{isOpen:!!m,title:`Delete this message?`,message:`This removes it for good. There is no undo — archive it instead if you only want it out of the way.`,onConfirm:E,onCancel:()=>h(null),isProcessing:g,confirmText:`Yes, delete`})]})}var Ve=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]};function He({title:e=`Drive`,subtitle:n=`/templates/drive`,backUrl:a=`/templates`,filesCollection:u=`pub_files`,config:d,customContent:f,footer:p}){let{user:m,userRole:h}=A(),g=!!d,_=h===`admin`,v=u,y=u.startsWith(`user_`),[b,x]=(0,r.useState)([]),[S,C]=(0,r.useState)(!0),[w,T]=(0,r.useState)(null),[E,D]=(0,r.useState)(!0),[O,k]=(0,r.useState)(null),[j,M]=(0,r.useState)(!1),[N,P]=(0,r.useState)(null),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)({}),[ee,z]=(0,r.useState)(!1),[te,B]=(0,r.useState)(null),[ne,V]=(0,r.useState)(``),[H,U]=(0,r.useState)(!1),[G,K]=(0,r.useState)(``),[q,J]=(0,r.useState)(!1),Y=(0,r.useRef)(null);(0,r.useEffect)(()=>{D(!0)},[w?._id]),(0,r.useEffect)(()=>{if(!(y&&!m))return C(!0),(0,i.onSnapshot)(y?(0,i.query)((0,i.collection)(t.Pt,u),(0,i.where)(`uid`,`==`,m.uid)):(0,i.query)((0,i.collection)(t.Pt,u),(0,i.orderBy)(`createdAt`,`desc`)),e=>{let t=e.docs.map(e=>({_id:e.id,...e.data()}));t.sort((e,t)=>(t.createdAt?.toMillis?.()||0)-(e.createdAt?.toMillis?.()||0)),x(t),C(!1)},e=>{console.warn(`Error listening to ${u}:`,e),C(!1)})},[u,y,m?.uid]);let ie=e=>!!m&&(e.uid===m.uid||_),ae=e=>{B(e),V(e.name),K(``),z(!0)},oe=async e=>{if(e.preventDefault(),!(!te||!ne.trim()||!m)){U(!0),K(``);try{let e=`${v}/${`${Date.now()}_${te.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,n=(0,o.ref)(t.It,e);await(0,o.uploadBytes)(n,te,{customMetadata:{ownerId:m.uid}});let r=await(0,o.getDownloadURL)(n);await(0,i.addDoc)((0,i.collection)(t.Pt,u),{fileName:ne.trim(),fileType:te.type||`unknown`,fileSize:te.size,downloadURL:r,storagePath:e,uid:m.uid,uploaderEmail:m.email||``,createdAt:(0,i.serverTimestamp)()}),z(!1),B(null),V(``)}catch(e){K(e?.code===`storage/unauthorized`?`You do not have permission to upload here.`:e?.message||`Upload failed. Please try again.`)}U(!1)}},se=async()=>{if(O){M(!0);try{await Promise.all([(0,o.deleteObject)((0,o.ref)(t.It,O.storagePath||O.downloadURL)).catch(e=>console.warn(`Storage object missing:`,e)),(0,i.deleteDoc)((0,i.doc)(t.Pt,u,O._id))]),k(null)}catch(e){console.error(`Delete failed:`,e)}M(!1)}},X=async()=>{if(!N||!N.name.trim()){P(null);return}try{await(0,i.updateDoc)((0,i.doc)(t.Pt,u,N.id),{fileName:N.name.trim()})}catch(e){console.error(`Rename failed:`,e)}P(null)},ce=(e,t)=>{navigator.clipboard.writeText(e),I(t),setTimeout(()=>I(null),2e3)},Z=(e,n=!1)=>{let r=n?`w-16 h-16`:`w-10 h-10`,i=n?`w-8 h-8`:`w-5 h-5`;return e.includes(`video`)||e.includes(`audio`)?(0,s.jsx)(`div`,{className:`${r} flex items-center justify-center bg-purple-500/10 text-purple-500 rounded-lg`,children:(0,s.jsx)(t.f,{className:i})}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,s.jsx)(`div`,{className:`${r} flex items-center justify-center bg-blue-500/10 text-blue-500 rounded-lg`,children:(0,s.jsx)(t.Q,{className:i})}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,s.jsx)(`div`,{className:`${r} flex items-center justify-center bg-yellow-500/10 text-yellow-500 rounded-lg`,children:(0,s.jsx)(t.Et,{className:i})}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,s.jsx)(`div`,{className:`${r} flex items-center justify-center bg-emerald-500/10 text-emerald-500 rounded-lg`,children:(0,s.jsx)(t.ot,{className:i})}):(0,s.jsx)(`div`,{className:`${r} flex items-center justify-center bg-foreground/5 text-foreground/40 rounded-lg`,children:(0,s.jsx)(t.Z,{className:i})})};return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 flex flex-col pt-12 min-h-screen relative`,onDragOver:e=>{e.preventDefault(),J(!0)},onDragLeave:e=>{e.preventDefault(),J(!1)},onDrop:e=>{e.preventDefault(),J(!1),e.dataTransfer.files?.[0]&&ae(e.dataTransfer.files[0])},children:[(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[!g&&(0,s.jsxs)(c.Link,{to:a,className:`inline-flex items-center gap-2 text-[13px] font-bold text-foreground/50 hover:text-accent transition-colors mb-4`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4`}),` Back to templates`]}),(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}),(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`}),n]})]}),g&&(0,s.jsx)(`div`,{className:`mb-6`,children:(0,s.jsx)(W,{})}),(0,s.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl min-h-[520px] bg-background flex flex-col`,children:[(0,s.jsxs)(`div`,{className:`p-6 md:p-8 flex items-center justify-between gap-6 border-b border-[var(--panel-border)]/50 bg-background/50`,children:[(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground tracking-tight`,children:`Files`}),(0,s.jsx)(`p`,{className:`text-[13px] mt-2 text-foreground/60 font-medium`,children:y?`Only you can see the files you upload here.`:`Everyone who can open this page can see these files.`})]}),m&&(0,s.jsxs)(t.r,{onClick:()=>{B(null),K(``),z(!0)},className:`flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-bold shadow-md`,children:[(0,s.jsx)(t.k,{className:`w-4 h-4`}),` Add file`]})]}),f?(0,s.jsx)(`div`,{className:`p-6 md:p-8 flex-1`,children:(0,s.jsx)(f,{files:b,loading:S,user:m,uploadFile:ae,deleteFile:k,config:d})}):(0,s.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 relative`,children:[S&&(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`})}),b.length>0?(0,s.jsx)(`div`,{className:`grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:b.map(e=>(0,s.jsxs)(`div`,{className:`flex flex-col bg-background border border-[var(--panel-border)] rounded-2xl hover:border-accent/40 transition-all group overflow-hidden shadow-sm h-[190px] relative`,children:[(0,s.jsxs)(`div`,{className:`absolute top-2 right-2 flex flex-col gap-1 opacity-0 group-hover:opacity-100 transition-opacity z-10 bg-background/90 backdrop-blur-md rounded-lg p-1 border border-[var(--panel-border)] shadow-xl`,children:[(0,s.jsx)(`a`,{href:e.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-1.5 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-blue-500 transition-colors`,title:`Download`,children:(0,s.jsx)(t.rt,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ce(e.downloadURL,e._id)},className:`p-1.5 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-emerald-500 transition-colors`,title:`Copy link`,children:F===e._id?(0,s.jsx)(t._t,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-4 h-4`})}),ie(e)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),P({id:e._id,name:e.fileName})},className:`p-1.5 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-purple-500 transition-colors`,title:`Rename`,children:(0,s.jsx)(t.A,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),k(e)},className:`p-1.5 hover:bg-red-500/10 rounded-md text-foreground/60 hover:text-red-500 transition-colors`,title:`Delete`,children:(0,s.jsx)(t.y,{className:`w-4 h-4`})})]})]}),(0,s.jsx)(`div`,{className:`h-[120px] w-full border-b border-[var(--panel-border)]/50 bg-foreground/[0.02] flex items-center justify-center overflow-hidden relative cursor-pointer`,onClick:()=>T(e),children:e.fileType.startsWith(`image/`)?(0,s.jsxs)(s.Fragment,{children:[L[e._id]!==!1&&(0,s.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-accent/5 z-0`,children:(0,s.jsx)(t.L,{className:`w-5 h-5 text-accent animate-spin`})}),(0,s.jsx)(`img`,{src:e.downloadURL,alt:``,className:`absolute inset-0 w-full h-full object-contain p-2 transition-opacity duration-300 ${L[e._id]===!1?`opacity-100`:`opacity-0`}`,onLoad:()=>R(t=>({...t,[e._id]:!1})),onError:()=>R(t=>({...t,[e._id]:!1}))})]}):Z(e.fileType,!0)}),(0,s.jsxs)(`div`,{className:`p-3 flex flex-col justify-center flex-1 min-w-0`,onClick:()=>!N&&T(e),children:[N?.id===e._id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:N.name,onChange:e=>P({...N,name:e.target.value}),onBlur:X,onKeyDown:e=>{e.key===`Enter`&&X(),e.key===`Escape`&&P(null)},onClick:e=>e.stopPropagation(),className:`no-glow text-[12.5px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full`}):(0,s.jsx)(`span`,{className:`text-[12.5px] font-bold text-foreground truncate select-none group-hover:text-accent transition-colors`,title:e.fileName,children:e.fileName}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/40 font-bold uppercase tracking-wider mt-1 select-none`,children:Ve(e.fileSize)})]})]},e._id))}):!S&&(0,s.jsxs)(`div`,{onClick:()=>m&&z(!0),className:`min-h-[320px] flex flex-col items-center justify-center text-center cursor-pointer group`,children:[(0,s.jsx)(t.st,{className:`w-12 h-12 text-foreground/15 mb-4`}),(0,s.jsx)(`p`,{className:`text-[20px] font-bold text-foreground/50 group-hover:text-foreground/70 transition-colors`,children:`No files yet`}),(0,s.jsx)(`p`,{className:`text-[13px] font-medium mt-1 text-foreground/40`,children:m?`Click here or drag a file in to upload`:`Sign in to upload a file`})]})]})]}),p,(0,s.jsx)(t.s,{children:ee&&(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:()=>!H&&z(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(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:`w-full max-w-[480px] border-[var(--panel-border)] border rounded-3xl relative z-10 glass-panel shadow-2xl flex flex-col bg-background`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between p-6 border-b border-[var(--panel-border)]/50`,children:[(0,s.jsx)(`span`,{className:`text-[16px] font-extrabold text-foreground tracking-tight`,children:`Upload a file`}),(0,s.jsx)(`button`,{onClick:()=>!H&&z(!1),className:`text-foreground/40 hover:text-foreground transition-colors`,children:(0,s.jsx)(t.d,{className:`w-5 h-5`})})]}),te?(0,s.jsxs)(`form`,{onSubmit:oe,className:`p-6 flex flex-col gap-6`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-4 bg-foreground/[0.03] p-4 rounded-2xl border border-[var(--panel-border)]`,children:[Z(te.type),(0,s.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0 pr-4`,children:[(0,s.jsx)(`span`,{className:`text-[13px] font-bold text-foreground truncate`,children:te.name}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold uppercase tracking-wider mt-1`,children:Ve(te.size)})]}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>!H&&B(null),className:`w-8 h-8 flex items-center justify-center text-foreground/40 hover:text-red-500 rounded-xl hover:bg-red-500/10 transition-colors shrink-0`,children:(0,s.jsx)(t.y,{className:`w-4 h-4`})})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,s.jsx)(`label`,{className:`text-[11px] font-bold text-foreground/50 uppercase tracking-widest pl-1`,children:`File name`}),(0,s.jsx)(`input`,{type:`text`,required:!0,value:ne,onChange:e=>V(e.target.value),disabled:H,className:`no-glow w-full bg-foreground/[0.02] border border-[var(--panel-border)] rounded-xl px-4 py-3.5 text-[14px] font-bold text-foreground outline-none focus:border-accent transition-colors`})]}),G&&(0,s.jsx)(`p`,{className:`text-[13px] font-medium text-red-400 bg-red-500/10 border border-red-500/20 rounded-xl p-3`,children:G}),(0,s.jsx)(t.r,{type:`submit`,isLoading:H,className:`w-full py-4 rounded-xl text-[14px] font-bold shadow-lg`,children:H?`Uploading…`:`Upload`})]}):(0,s.jsxs)(`div`,{onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),e.dataTransfer.files?.[0]&&ae(e.dataTransfer.files[0])},className:`p-12 flex flex-col items-center justify-center`,children:[(0,s.jsx)(`div`,{className:`w-20 h-20 rounded-full bg-foreground/5 flex items-center justify-center mb-5 border-2 border-dashed border-[var(--panel-border)]`,children:(0,s.jsx)(t.st,{className:`w-8 h-8 text-foreground/40`})}),(0,s.jsx)(`p`,{className:`text-[15px] font-bold text-foreground mb-1`,children:`Drag and drop a file here`}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/50 font-medium mb-8`,children:`or click to browse`}),(0,s.jsx)(`input`,{type:`file`,ref:Y,onChange:e=>e.target.files?.[0]&&ae(e.target.files[0]),className:`hidden`}),(0,s.jsx)(t.r,{onClick:()=>Y.current?.click(),className:`px-8 py-3 rounded-full font-bold shadow-md`,children:`Browse files`})]})]})]})}),typeof window<`u`&&(0,l.createPortal)((0,s.jsx)(t.s,{children:w&&(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:()=>T(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:()=>T(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`,children:(0,s.jsx)(t.d,{className:`w-5 h-5`})}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col 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`,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:w.fileName}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[w.fileType,` • `,Ve(w.fileSize)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>ce(w.downloadURL,w._id),className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-emerald-500 transition-colors rounded-xl`,title:`Copy link`,children:F===w._id?(0,s.jsx)(t._t,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.z,{className:`w-4 h-4`})}),ie(w)&&(0,s.jsx)(`button`,{onClick:()=>{let e=w;T(null),k(e)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl`,title:`Delete`,children:(0,s.jsx)(t.y,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:w.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-0 h-[70vh]`,children:(0,s.jsxs)(`div`,{className:`absolute inset-4 md:inset-8 flex items-center justify-center`,children:[E&&(0,s.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center z-50 pointer-events-none`,children:(0,s.jsx)(t.L,{className:`w-6 h-6 text-accent animate-spin`})}),w.fileType.startsWith(`image/`)?(0,s.jsx)(`img`,{onLoad:()=>D(!1),src:w.downloadURL,alt:w.fileName,className:`block max-w-full max-h-full w-auto h-auto object-contain rounded-lg transition-opacity duration-500 ${E?`opacity-0`:`opacity-100`}`}):w.fileType.startsWith(`video/`)?(0,s.jsx)(`video`,{onLoadedData:()=>D(!1),src:w.downloadURL,controls:!0,className:`max-w-full max-h-full rounded-lg transition-opacity duration-500 ${E?`opacity-0`:`opacity-100`}`}):w.fileType===`application/pdf`?(0,s.jsx)(`iframe`,{onLoad:()=>D(!1),src:w.downloadURL,className:`w-full h-full border-none bg-white rounded-lg transition-opacity duration-500 ${E?`opacity-0`:`opacity-100`}`,title:`PDF preview`}):(0,s.jsxs)(`div`,{className:`flex flex-col items-center justify-center text-foreground/40 text-center`,onClick:()=>D(!1),children:[(0,s.jsx)(t.Z,{className:`w-24 h-24 mb-6 opacity-40`}),(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 format cannot be previewed. Download it instead.`})]})]})})]})]})}),document.body),(0,s.jsx)(re,{isOpen:!!O,title:`Delete file`,message:(0,s.jsxs)(s.Fragment,{children:[`Delete `,(0,s.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left break-words max-w-full`,children:O?.fileName}),` This cannot be undone.`]}),onConfirm:se,onCancel:()=>k(null),isProcessing:j,confirmText:`Yes, delete`}),(0,s.jsx)(t.s,{children:q&&(0,s.jsx)(t.o.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`fixed inset-0 z-[1000] bg-background/60 backdrop-blur-md pointer-events-none flex items-center justify-center p-6`,children:(0,s.jsxs)(`div`,{className:`w-full max-w-lg aspect-video bg-background/80 border-2 border-dashed border-accent rounded-[40px] shadow-2xl flex flex-col items-center justify-center gap-6`,children:[(0,s.jsx)(`div`,{className:`w-20 h-20 rounded-full bg-accent/10 flex items-center justify-center text-accent`,children:(0,s.jsx)(t.st,{className:`w-10 h-10 animate-bounce`})}),(0,s.jsx)(`span`,{className:`text-[24px] font-extrabold text-foreground tracking-tight`,children:`Drop to upload`})]})})})]})}var Ue=[`mem_files`,`user_files`,`admin_files`],We=e=>!e.sourceTab;function Ge(){let[e,n]=(0,r.useState)(null),[a,c]=(0,r.useState)(!1),[l,u]=(0,r.useState)(!1),[d,f]=(0,r.useState)(``),[p,m]=(0,r.useState)(0);(0,r.useEffect)(()=>{let e=!1;return Promise.all(Ue.map(async e=>{try{return(await(0,i.getDocs)((0,i.collection)(t.Pt,e))).docs.map(t=>({collectionName:e,id:t.id,...t.data()}))}catch{return[]}})).then(t=>{e||n(t.flat())}),()=>{e=!0}},[]);let h=async()=>{if(!e)return;u(!0),f(``);let r=0;for(let n of e)try{let e=n.storagePath||n.downloadURL;e&&We(n)&&await(0,o.deleteObject)((0,o.ref)(t.It,e)).catch(()=>{}),await(0,i.deleteDoc)((0,i.doc)(t.Pt,n.collectionName,n.id)),m(e=>e+1)}catch(e){r+=1,console.error(`Could not delete ${n.collectionName}/${n.id}:`,e)}r>0?(f(`${r} file${r===1?``:`s`} could not be deleted. Reload and try again.`),n((await Promise.all(Ue.map(async e=>{try{return(await(0,i.getDocs)((0,i.collection)(t.Pt,e))).docs.map(t=>({collectionName:e,id:t.id,...t.data()}))}catch{return[]}}))).flat())):n([]),u(!1),c(!1)};if(!e||e.length===0)return null;let g=e.filter(We).length,_=Ue.map(t=>({name:t,n:e.filter(e=>e.collectionName===t).length})).filter(e=>e.n>0);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`mt-6 glass-panel border border-amber-500/25 bg-amber-500/[0.03] rounded-3xl p-6 md:p-8`,children:[(0,s.jsxs)(`h3`,{className:`text-[17px] font-extrabold text-foreground tracking-tight mb-2`,children:[e.length,` leftover record`,e.length===1?``:`s`,` from the old Drive`]}),(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/60 leading-relaxed mb-3 max-w-2xl`,children:`Drive used to have Internal, User and Admin folders. They are gone — this page is the only built-in folder now, and each page you have built keeps its own files. Nothing reads these records any more.`}),(0,s.jsxs)(`p`,{className:`text-[14px] text-foreground/60 leading-relaxed mb-3 max-w-2xl`,children:[g>0?`${g} ${g===1?`was`:`were`} uploaded through the old Drive screen, so ${g===1?`its file is`:`their files are`} deleted too. `:``,e.length-g>0?`${e.length-g} belong to files a page still shows, so only the leftover record goes — the ${e.length-g===1?`file stays`:`files stay`} where ${e.length-g===1?`it is`:`they are`}.`:``]}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/50 font-medium mb-5`,children:_.map(e=>`${e.n} in ${e.name}`).join(` · `)}),d&&(0,s.jsx)(`p`,{className:`text-[13px] font-medium text-red-400 bg-red-500/10 border border-red-500/20 rounded-xl p-3 mb-4`,children:d}),(0,s.jsxs)(`button`,{onClick:()=>c(!0),disabled:l,className:`inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-bold bg-red-500/10 hover:bg-red-500/20 text-red-500 border border-red-500/20 transition-colors disabled:opacity-50`,children:[l?(0,s.jsx)(t.L,{className:`w-4 h-4 animate-spin`}):(0,s.jsx)(t.y,{className:`w-4 h-4`}),l?`Deleting ${p} of ${e.length}…`:`Clean up all ${e.length} permanently`]})]}),(0,s.jsx)(re,{isOpen:a,title:`Delete the old Drive files`,message:(0,s.jsxs)(s.Fragment,{children:[`This permanently deletes `,(0,s.jsxs)(`strong`,{className:`text-foreground`,children:[e.length,` leftover record`,e.length===1?``:`s`]}),` `,`from `,_.map(e=>e.name).join(`, `),g>0&&(0,s.jsxs)(s.Fragment,{children:[`, along with the `,(0,s.jsxs)(`strong`,{className:`text-foreground`,children:[g,` file`,g===1?``:`s`]}),` uploaded through the old Drive screen`]}),`. It cannot be undone, and it covers every user's uploads, not only your own. Files that a page still shows are left alone.`]}),onConfirm:h,onCancel:()=>c(!1),isProcessing:l,confirmText:`Yes, delete them`})]})}function Ke(){let{isAdmin:e}=A();return(0,s.jsx)(He,{title:`Assets`,subtitle:`/assets`,filesCollection:`pub_files`,config:{isAdmin:!0,pageId:`assets`},footer:e?(0,s.jsx)(Ge,{}):null})}function qe(){let e=[{id:`form`,title:`Inline Form`,description:`A contact form built straight into the page, so people can write to you without leaving it.`,icon:t.B,path:`/templates/inline_form`,prompt:`Create a page anyone can visit at /contact-us, called Contact in the site menu, with the heading Get in touch, using the inline form template as the reference. Build the form into the page, asking for full name (required), email (required) and message as long text (required). Send the answers to my Inbox and show a thank-you message after sending.`},{id:`popup`,title:`Modal Popup Form`,description:`A button that opens the form in a popup over the page, with the background softly blurred.`,icon:t.Ot,path:`/templates/popup_form`,prompt:`Create a page anyone can visit at /enquire, called Enquire in the site menu, with the heading Tell us what you need, using the pop-up form template as the reference. Put a button that says Start an enquiry which opens a form asking for full name (required), email (required) and a short message. Send the answers to my Inbox and show a thank-you message after sending.`},{id:`confirmation`,title:`Action Confirmation`,description:`A short "are you sure?" step that appears before anything is deleted or sent.`,icon:t.vt,path:`/templates/confirmation`,prompt:`On every page of mine where something can be deleted, ask me to confirm first with a pop-up that says Delete this? and two buttons, Cancel and Delete, using the confirmation template as the reference.`},{id:`board`,title:`Board View`,description:`Cards in columns that you drag from one stage to the next, for work in progress.`,icon:t.G,path:`/templates/board`,prompt:`Create a page for my team at /onboarding, called Onboarding in the dashboard, with the heading Client onboarding, using the board template as the reference. Columns: To do, In progress and Done. Each card has a client name, a contact email and a short note.`},{id:`table`,title:`Data Table`,description:`Rows and columns for longer lists, with sorting and actions on many rows at once.`,icon:t.b,path:`/templates/table`,prompt:`Create a page for my team at /customers, called Customers in the dashboard, with the heading Our customers, using the table template as the reference. Columns: name, email, phone and status (Lead, Active, Past). Everyone on the team sees the same rows and can add, edit and delete them.`},{id:`calendar`,title:`Calendar View`,description:`A month at a time, for anything that belongs on a date — bookings, shifts, deadlines.`,icon:t.bt,path:`/templates/calendar`,prompt:`Create a page for my team at /appointments, called Appointments in the dashboard, with the heading Appointments, using the calendar template as the reference. Each appointment has a client name, a start time, a length in minutes and a note. Everyone on the team sees the same calendar.`},{id:`drive`,title:`Drive View`,description:`A file library with upload, preview, rename and delete. The demo writes to the Assets folder, so uploading from here is something only admins can do.`,icon:t.Y,path:`/templates/drive`,prompt:`Create a page only admins can open at /documents, called Documents in the dashboard, with the heading Shared documents, using the drive template as the reference, where admins can upload, preview, rename and delete files.`}];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`,children:[(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-10 text-center`,children:[(0,s.jsx)(`h1`,{className:`w-fit mx-auto inline-block text-4xl md:text-5xl lg:text-[4.8rem] leading-[1.1] font-extrabold tracking-tight mb-4 text-gradient animate-float`,children:`What your assistant can build`}),(0,s.jsx)(`p`,{className:`text-foreground/60 text-lg font-medium max-w-2xl mx-auto`,children:`Every layout below already works. Look at one, then copy the sentence underneath it and paste it to your assistant to get a page like it.`}),(0,s.jsxs)(`p`,{className:`text-foreground/50 text-[13.5px] font-medium max-w-2xl mx-auto mt-3`,children:[`New here?`,` `,(0,s.jsx)(c.Link,{to:`/guide`,className:`text-accent font-bold hover:underline`,children:`Start with the guide`}),`.`]})]}),(0,s.jsxs)(`div`,{className:`w-full max-w-4xl mx-auto flex flex-col gap-4 relative`,children:[(0,s.jsx)(`div`,{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[80%] h-[80%] bg-accent/5 blur-[120px] rounded-full pointer-events-none -z-10`}),e.map((e,n)=>{let r=e.icon;return(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:n*.05},className:`flex flex-col gap-3 w-full p-4 md:p-6 glass-panel border border-[var(--panel-border)] rounded-2xl hover:border-accent/40 transition-all duration-300 group`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-4 md:gap-6`,children:[(0,s.jsx)(`div`,{className:`w-12 h-12 rounded-xl bg-accent/10 flex items-center justify-center text-accent shrink-0 border border-accent/20 group-hover:scale-105 transition-transform`,children:(0,s.jsx)(r,{className:`w-5 h-5`})}),(0,s.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold text-foreground`,children:e.title}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/50 font-medium leading-snug`,children:e.description})]}),(0,s.jsxs)(c.Link,{to:e.path,className:`hidden md:flex items-center gap-2 text-[13px] font-bold px-5 py-2.5 rounded-xl btn-primary shrink-0 transition-transform shadow-lg hover:-translate-y-0.5`,children:[`View `,(0,s.jsx)(`span`,{className:`font-black leading-none ml-0.5`,children:`→`})]})]}),(0,s.jsx)(ke,{title:`Ask your assistant for this`,prompt:e.prompt,compact:!0}),(0,s.jsxs)(c.Link,{to:e.path,className:`md:hidden inline-flex items-center justify-center gap-2 text-[13px] font-bold px-5 py-2.5 rounded-xl btn-primary transition-transform shadow-lg`,children:[`View `,(0,s.jsx)(`span`,{className:`font-black leading-none ml-0.5`,children:`→`})]})]},e.id)})]})]})}var Je=`Xl271wWblkY`,Ye=[{term:`Who it is for`,body:`One of the four audiences below. It decides who can open the page and which menu it appears in. Ask the chat only for pages anyone can visit — dashboard pages are added on the Pages screen, see the three steps below.`,example:`Create a page anyone can visit.`},{term:`The web address`,body:`Starts with a slash. It is the address people type or click, and it never changes unless you change it on the Pages screen.`,example:`Web address: /pricing.`},{term:`The name in the menu`,body:`The word people click to get there.`,example:`Name in the site menu: Pricing.`},{term:`The heading`,body:`The title at the top of the page.`,example:`Heading: Our prices.`},{term:`What is on it`,body:`The sections from top to bottom, with the exact words for every heading and button, and what each button does.`,example:`Three plans side by side, each with a price and a button that says Choose this plan.`},{term:`Where to start`,body:`For a page in the dashboard you pick this on the Pages screen when you add it — board, table, calendar, files, or from scratch. In the chat, only say whether people can upload files.`,example:`No file uploads.`},{term:`The questions`,body:`For a form: every question, its kind, and whether it is required. Kinds: short text, long text, email, phone, number, money, yes-no, or choose one with the choices listed.`,example:`Budget (money in dollars, optional).`},{term:`After sending`,body:`Stay and show a message, go to the home page, or go to another page by its web address.`,example:`After sending, stay on the page and show Thanks, we will reply today.`},{term:`What to leave alone`,body:`End with "Build only this" and name anything that must not change. Without it the assistant adds pages, sample data and sections you did not ask for.`,example:`Build only this — no other pages, forms or sample data.`}],Xe=[{name:`Anyone`,how:`Say: a page anyone can visit`,who:`Everybody, signed in or not. This is your public website, and the page shows in the site menu.`},{name:`Signed-in users`,how:`Pick it when you add the page`,who:`Anyone who registers. Each person sees only their own information, never anyone else’s.`},{name:`Your team`,how:`Pick it when you add the page`,who:`Only people you marked as team members on the Users screen, plus admins. Everyone on it sees the same information.`},{name:`Admins only`,how:`Pick it when you add the page`,who:`You, and anyone you marked as an admin.`}],Ze=[{title:`Add the page on the Pages screen`,body:`Press Add a page and pick who it is for — Your team, Signed-in users or Admins only. Give it a name, a web address and a starting layout: board, table, calendar, files, or from scratch.`},{title:`If it needs a form, add that on the Forms screen`,body:`Press New form, write the questions and choose who can fill it in. Then open the page on the Pages screen and pick the form in its Form box.`},{title:`Say what you want on it, then copy the sentence`,body:`On the page’s row, write what you would like to see on the page in your own words — the examples below show what that can sound like. The finished sentence appears under it; copy it and paste it into the chat. That is the whole hand-over.`}],Qe=[{screen:`Pages`,path:`/pages`,body:`Add a page for your team, signed-in users or admins. Rename a page, change its web address, icon or starting layout, link a different form, reorder it, hide it or delete it.`},{screen:`Forms`,path:`/forms`,body:`Add a form and its questions, choose who can fill it in, and change a form’s title and the words on its button.`},{screen:`Theme`,path:`/theme`,body:`Colours, typeface, corner rounding, the logo, and whether the site opens light or dark.`},{screen:`Users`,path:`/users`,body:`Mark a person as a team member or an admin.`},{screen:`Inbox`,path:`/inbox`,body:`Read every answer people sent through your forms.`}],$e=[{title:`One page or one form per message`,body:`Describe it completely, then send. Ask for the next one when the first is live.`},{title:`Give every detail up front`,body:`If a part of the recipe is missing, the assistant stops to ask for it. Answer with just that part.`},{title:`Use the exact words you want to see`,body:`Headings, button labels, choices in a list. The assistant copies them; it does not improve them.`},{title:`When something is wrong, describe your screen`,body:`The web address, what you clicked, what happened, what you expected. Not what you think the cause is.`},{title:`Never accept homework`,body:`The assistant makes every change itself. If a reply ends with something for you to edit, paste or run, answer: "Do that for me."`}],et=[{id:`website`,title:`Pages anyone can visit`,description:`Your public website. They appear in the site menu.`,prompts:[{title:`A pricing page with a quote form`,prompt:`Create a page anyone can visit.
3
3
  Web address: /pricing. Name in the site menu: Pricing. Heading at the top: Our prices.
4
4
  On the page: three plans side by side — Starter, Growth and Pro — each with a one-line description, a monthly price in dollars and a button that says Choose this plan.
5
5
  Every button opens the same pop-up form, called Request a quote, for website visitors. Questions, in this order: full name (short text, required), email (required), which plan (choose one: Starter, Growth, Pro — required), budget (money in dollars, optional), message (long text, optional).
@@ -10,7 +10,7 @@ On the page: one short introduction paragraph, then three people side by side
10
10
  No form on this page. Build only this — no other pages or sections.`},{title:`A questions-and-answers page`,prompt:`Create a page anyone can visit.
11
11
  Web address: /faq. Name in the site menu: FAQ. Heading: Common questions.
12
12
  On the page: six questions, each one a row that opens to show its answer when clicked, closed by default. Use these questions and write a two-sentence answer for each: How long does delivery take? Can I return an item? Do you ship abroad? How do I track my order? Which payment methods do you accept? How do I contact you?
13
- No form on this page. Build only this.`}]},{id:`dashboard`,title:`Pages in the dashboard`,description:`Add the page on the Pages screen first, then copy its Ask your assistant to fill this page sentence. Each of these is the part you add after it what the page should show.`,prompts:[{title:`A board for your team (starting layout: board)`,prompt:`Columns, in this order: To do, In progress, Done. Each card has a client name (short text), a contact email, a start date and a short note (long text). Anyone on the team can add a card, drag it between columns, edit it and delete it. The button at the top says New client.
13
+ No form on this page. Build only this.`}]},{id:`dashboard`,title:`Pages in the dashboard`,description:`Add the page on the Pages screen first. Each of these is an example of what to write in its What would you like to see on this page boxthe screen folds your words into the sentence you copy.`,prompts:[{title:`A board for your team (starting layout: board)`,prompt:`Columns, in this order: To do, In progress, Done. Each card has a client name (short text), a contact email, a start date and a short note (long text). Anyone on the team can add a card, drag it between columns, edit it and delete it. The button at the top says New client.
14
14
  No file uploads on this page. Fill only this page — no other pages, no forms, no sample cards.`},{title:`Each signed-in user sees their own orders (starting layout: table)`,prompt:`Each person sees only their own orders. Columns: date, item (short text), amount (money in dollars), status (choose one: Paid, Shipped, Delivered). People can add, edit and delete their own rows. The button at the top says Add order.
15
15
  No file uploads on this page. Fill only this page — no other pages, no forms, no sample rows.`},{title:`A file library for admins (starting layout: files)`,prompt:`Admins can upload files, preview them, rename them and delete them. Show the name, size and upload date of every file. The button at the top says Upload contract.
16
16
  Fill only this page — no other pages, no forms.`},{title:`Every Inbox entry becomes a card (starting layout: board)`,prompt:`Every new entry that arrives in my Inbox from the Request a quote form automatically becomes a card showing everything the person typed. Columns, in this order: New, Contacted, Proposal sent, Won, Lost. On each card my team can also fill in a deadline (date), an expected value (money in dollars) and notes (long text), and drag the card between columns.
@@ -26,20 +26,20 @@ Build only this.`},{title:`Change some words on the home page`,prompt:`On my hom
26
26
  Leave everything else on the page exactly as it is — the buttons, the sections, the colours and the logo.`},{title:`Get colours to paste into the Theme screen`,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 boxes on my Theme screen. Pick a typeface from Inter, Outfit, Roboto, Space Grotesk or Plus Jakarta Sans to go with it.
27
27
  Do not change anything yourself — I will paste the codes in.`}]},{id:`fixing`,title:`Fixing and removing`,description:`When something is wrong, or something has to go.`,prompts:[{title:`Something on a page does not work`,prompt:`On my page at /orders, the Add order button does nothing when I click it. I expected a box to appear where I can type a new order. Nothing else on the page has changed.
28
28
  Fix it, and tell me in one sentence what I should see now.`},{title:`The assistant says a page exists, but I cannot open it`,prompt:`You said you created a page at /leads, but when I open that address I see a page that says it cannot be found. Check the page you made, fix whatever stops it from showing, and tell me the exact address to open when it works.`},{title:`Delete a page you asked for`,prompt:`Delete the page at /pricing, including its entry in the site menu and any button or link on other pages that leads to it. Keep the Request a quote form only if another page still uses it; otherwise delete that too.
29
- Do not change anything else.`},{title:`Remove the pages that came with the app`,prompt:`Remove the Guide, Templates and Contact pages from my site, including their entries in the site menu.`}]}],et=`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px] mb-3`,tt=`rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)]`;function nt({children:e}){return(0,s.jsxs)(`div`,{className:et,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e]})}function rt(){return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-4xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12`,children:[(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-10 text-center`,children:[(0,s.jsx)(`h1`,{className:`w-fit mx-auto inline-block text-4xl md:text-5xl lg:text-[4.2rem] leading-[1.1] font-extrabold tracking-tight mb-4 text-gradient`,children:`Guide`}),(0,s.jsx)(`p`,{className:`text-foreground/60 text-lg font-medium max-w-2xl mx-auto`,children:`Your website is built by describing it, and your dashboard pages are added on the Pages screen and filled by describing them. This page shows what a complete description contains, and gives you finished ones to paste.`})]}),(0,s.jsxs)(t.o.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`mb-12`,children:[(0,s.jsx)(`div`,{className:`relative w-full rounded-2xl overflow-hidden border border-[var(--panel-border)] glass-panel`,children:(0,s.jsx)(`div`,{className:`relative w-full aspect-video`,children:(0,s.jsx)(`iframe`,{className:`absolute inset-0 w-full h-full`,src:`https://www.youtube-nocookie.com/embed/${qe}?start=1`,title:`Watch the guide`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share`,allowFullScreen:!0,loading:`lazy`,referrerPolicy:`strict-origin-when-cross-origin`})})}),(0,s.jsx)(`p`,{className:`mt-3 text-center text-[12.5px] text-foreground/45 font-medium`,children:`Six minutes, from an empty project to a finished site.`})]}),(0,s.jsxs)(t.o.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.05},className:`mb-12`,children:[(0,s.jsx)(nt,{children:`A page anyone can visit: what a complete request contains`}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold tracking-tight text-foreground mb-2`,children:`Nine things, in this order`}),(0,s.jsx)(`p`,{className:`text-[13.5px] text-foreground/55 font-medium leading-relaxed mb-5 max-w-2xl`,children:`Before the assistant builds anything it needs every one of these. Say them all in one message and it builds the whole thing in one go. Leave one out and it stops to ask.`}),(0,s.jsx)(`div`,{className:`${tt} divide-y divide-[var(--panel-border)]`,children:Je.map((e,t)=>(0,s.jsxs)(`div`,{className:`grid gap-1.5 sm:grid-cols-[11rem_1fr] sm:gap-6 px-5 py-4`,children:[(0,s.jsxs)(`div`,{className:`flex items-baseline gap-2.5 sm:block`,children:[(0,s.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/35 tabular-nums sm:block sm:mb-0.5`,children:String(t+1).padStart(2,`0`)}),(0,s.jsx)(`h3`,{className:`text-[13.5px] font-bold text-foreground tracking-tight`,children:e.term})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-1.5 min-w-0`,children:[(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed`,children:e.body}),(0,s.jsx)(`p`,{className:`text-[13px] text-accent font-semibold leading-relaxed`,children:e.example})]})]},e.term))})]}),(0,s.jsxs)(t.o.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.1},className:`mb-12`,children:[(0,s.jsx)(nt,{children:`Who it is for`}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold tracking-tight text-foreground mb-2`,children:`The four audiences`}),(0,s.jsx)(`p`,{className:`text-[13.5px] text-foreground/55 font-medium leading-relaxed mb-5 max-w-2xl`,children:`Every page is for exactly one of these. These are the words on your Pages screen. A page anyone can visit is asked for in the chat; the other three are added on the Pages screen.`}),(0,s.jsx)(`div`,{className:`${tt} divide-y divide-[var(--panel-border)]`,children:Ye.map(e=>(0,s.jsxs)(`div`,{className:`grid gap-1.5 sm:grid-cols-[11rem_1fr] sm:gap-6 px-5 py-4`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,s.jsx)(`h3`,{className:`text-[13.5px] font-bold text-foreground tracking-tight`,children:e.name}),(0,s.jsx)(`p`,{className:`text-[12px] text-accent font-semibold`,children:e.how})]}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed`,children:e.who})]},e.name))}),(0,s.jsx)(`p`,{className:`mt-3 text-[12.5px] text-foreground/50 font-medium leading-relaxed max-w-2xl`,children:`Registering only makes someone a signed-in user, not a team member. Never put your team’s information on a page for signed-in users: any stranger who registers could open it.`})]}),(0,s.jsxs)(t.o.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.12},className:`mb-12`,children:[(0,s.jsx)(nt,{children:`A page for your team, signed-in users or admins`}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold tracking-tight text-foreground mb-2`,children:`Three steps, and the assistant only fills it in`}),(0,s.jsx)(`p`,{className:`text-[13.5px] text-foreground/55 font-medium leading-relaxed mb-5 max-w-2xl`,children:`Never ask the chat to create a dashboard page. Asked to, it rewrites files it must not touch, opens the page to strangers and invents forms. You add the page; the assistant only writes what is on it.`}),(0,s.jsx)(`div`,{className:`${tt} divide-y divide-[var(--panel-border)]`,children:Xe.map((e,t)=>(0,s.jsxs)(`div`,{className:`grid gap-1.5 sm:grid-cols-[11rem_1fr] sm:gap-6 px-5 py-4`,children:[(0,s.jsxs)(`div`,{className:`flex items-baseline gap-2.5 sm:block`,children:[(0,s.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/35 tabular-nums sm:block sm:mb-0.5`,children:String(t+1).padStart(2,`0`)}),(0,s.jsx)(`h3`,{className:`text-[13.5px] font-bold text-foreground tracking-tight`,children:e.title})]}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed`,children:e.body})]},e.title))})]}),(0,s.jsxs)(t.o.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.15},className:`mb-12`,children:[(0,s.jsx)(nt,{children:`No assistant needed`}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold tracking-tight text-foreground mb-2`,children:`Things you change yourself`}),(0,s.jsx)(`p`,{className:`text-[13.5px] text-foreground/55 font-medium leading-relaxed mb-5 max-w-2xl`,children:`These are switches and boxes in your admin screens. Asking the assistant for them only gets you sent here.`}),(0,s.jsx)(`div`,{className:`${tt} divide-y divide-[var(--panel-border)]`,children:Ze.map(e=>(0,s.jsxs)(`div`,{className:`grid gap-1 sm:grid-cols-[11rem_1fr] sm:gap-6 px-5 py-4`,children:[(0,s.jsx)(c.Link,{to:e.path,className:`text-[13.5px] font-bold text-foreground tracking-tight hover:text-accent transition-colors w-fit`,children:e.screen}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed`,children:e.body})]},e.screen))}),(0,s.jsx)(`p`,{className:`mt-3 text-[12.5px] text-foreground/50 font-medium leading-relaxed max-w-2xl`,children:`The Guide, Templates, Contact and Setup pages come with the app and are visible on purpose. Hide any of them on the Pages screen with the switch next to its name.`})]}),(0,s.jsxs)(t.o.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.2},className:`mb-12`,children:[(0,s.jsx)(nt,{children:`Working with the assistant`}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold tracking-tight text-foreground mb-5`,children:`Five habits`}),(0,s.jsx)(`div`,{className:`${tt} divide-y divide-[var(--panel-border)]`,children:Qe.map(e=>(0,s.jsxs)(`div`,{className:`flex flex-col gap-1 px-5 py-4`,children:[(0,s.jsx)(`h3`,{className:`text-[13.5px] font-bold text-foreground tracking-tight`,children:e.title}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed`,children:e.body})]},e.title))})]}),(0,s.jsxs)(t.o.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.25},className:`flex flex-col gap-4 mb-12`,children:[(0,s.jsxs)(`div`,{className:`mb-1`,children:[(0,s.jsx)(nt,{children:`Ready to paste`}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold tracking-tight text-foreground mb-2`,children:`Finished requests`}),(0,s.jsxs)(`p`,{className:`text-[13.5px] text-foreground/55 font-medium leading-relaxed max-w-2xl`,children:[`Each one answers every question the assistant would otherwise ask. Copy it, change the words to yours, and paste it as one message. Want to see the layouts first?`,` `,(0,s.jsx)(c.Link,{to:`/templates`,className:`text-accent font-bold hover:underline`,children:`Look through the templates`}),`.`]})]}),$e.map(e=>(0,s.jsx)(le,{title:e.title,description:e.description,children:e.prompts.map(e=>(0,s.jsx)(Oe,{title:e.title,prompt:e.prompt,compact:!0},e.title))},e.id))]})]})}function it(){let[e,n]=(0,r.useState)({favoriteService:``,satisfactionRating:``,detailedThoughts:``}),[a,o]=(0,r.useState)(`idle`);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`,children:[(0,s.jsx)(`div`,{className:`w-full max-w-5xl mx-auto mb-6`,children:(0,s.jsxs)(c.Link,{to:`/templates`,className:`inline-flex items-center gap-2 text-foreground/50 hover:text-accent transition-colors font-medium text-[14px]`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4`}),` Back to Templates`]})}),(0,s.jsx)(`div`,{className:`w-full max-w-5xl mx-auto mt-6`,children:(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`w-full max-w-[500px] p-6 sm:p-8 lg:p-10 rounded-3xl md:rounded-3xl glass-panel relative glow-hover shadow-[0_8px_32px_rgba(0,0,0,0.08)] z-10 mx-auto`,children:[(0,s.jsx)(`div`,{className:`absolute -inset-[1px] bg-gradient-to-br from-[var(--primary-glow)] to-transparent opacity-30 blur-[20px] rounded-3xl md:rounded-3xl -z-10`}),(0,s.jsx)(`div`,{className:`relative z-10 w-full`,children:a===`success`?(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex flex-col items-center justify-center py-8 text-center`,children:[(0,s.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-green-500/10 border border-green-500/20 flex items-center justify-center text-green-500 mb-4`,children:(0,s.jsx)(t.dt,{className:`w-8 h-8`})}),(0,s.jsx)(`h4`,{className:`text-lg font-bold text-foreground mb-2`,children:`Simulation Complete!`}),(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/60 leading-relaxed`,children:`Your test data was sent successfully. Log in as an admin and open your Inbox to see it.`})]}):a===`loading`?(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`flex flex-col items-center justify-center py-16 text-center`,children:[(0,s.jsx)(`div`,{className:`w-10 h-10 border-4 border-accent border-r-transparent rounded-full animate-spin mb-4`}),(0,s.jsx)(`h4`,{className:`text-lg font-bold text-foreground tracking-tight`,children:`Processing`}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/50 mt-1`,children:`Simulating submission...`})]}):(0,s.jsxs)(t.o.div,{initial:{opacity:0},animate:{opacity:1},children:[(0,s.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,s.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight break-words`,children:`Inline Form Template`}),(0,s.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide leading-relaxed`,children:`Try interacting with this simulated inline template block.`})]}),(0,s.jsxs)(`form`,{onSubmit:async r=>{r.preventDefault(),o(`loading`);try{let r=t.Nt.currentUser?.uid||`guest`;await(0,i.addDoc)((0,i.collection)(t.Pt,`user_submissions`),{uid:r,...e,type:`template_simulation`,submittedAt:(0,i.serverTimestamp)()}),o(`success`),setTimeout(()=>{o(`idle`),n({favoriteService:``,satisfactionRating:``,detailedThoughts:``})},3e3)}catch{o(`error`)}},className:`space-y-4 w-full`,children:[(0,s.jsx)(t.i,{label:`Favorite Service`,placeholder:`e.g. Design Consulting`,value:e.favoriteService,onChange:t=>n({...e,favoriteService:t.target.value})}),(0,s.jsx)(t.i,{label:`Satisfaction Rating`,type:`number`,placeholder:`1 to 10`,value:e.satisfactionRating,onChange:t=>n({...e,satisfactionRating:t.target.value})}),(0,s.jsxs)(`div`,{className:`flex flex-col w-full relative`,children:[(0,s.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Detailed Thoughts`}),(0,s.jsx)(`textarea`,{rows:3,placeholder:`Type something here...`,value:e.detailedThoughts,onChange:t=>n({...e,detailedThoughts:t.target.value}),className:`flex w-full rounded-xl text-[15px] text-foreground px-4 py-3 transition-all duration-300 placeholder:text-foreground/40 focus:outline-none focus:border-accent glow-focus disabled:cursor-not-allowed disabled:opacity-50 glass-panel min-h-[100px] resize-none`})]}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsx)(t.r,{type:`submit`,className:`w-full px-6 md:px-8 py-3 md:py-3.5 rounded-xl font-semibold tracking-wide btn-primary text-[15px] shadow-xl transition-all duration-300 hover:-translate-y-1 active:scale-95 flex items-center justify-center`,isLoading:!1,children:`Trigger Simulation`})})]})]})})]})})]})}function at(){let[e,n]=(0,r.useState)(!1),[a,o]=(0,r.useState)({concept:``,featureRequest:``,notes:``}),[l,u]=(0,r.useState)(`idle`);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-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:`Popup Form`}),(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`}),`/popup_form`]})]}),(0,s.jsx)(`div`,{className:`flex justify-between items-center mb-6 border-b border-[var(--panel-border)] pb-6 relative z-20`,children:(0,s.jsxs)(c.Link,{to:`/templates`,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 text-foreground/70`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4`}),` Go Back`]})}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative flex flex-col w-full min-h-[150px] p-6 lg:p-10`,children:[(0,s.jsx)(`div`,{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[800px] h-[800px] bg-accent/5 blur-[120px] rounded-full pointer-events-none -z-10`}),(0,s.jsx)(`div`,{className:`flex h-full w-full justify-end items-start relative z-10`,children:(0,s.jsxs)(t.r,{onClick:()=>n(!0),className:`px-6 py-2.5 text-[14px] font-bold rounded-xl shadow-lg flex items-center justify-center gap-2 btn-primary transition-all hover:-translate-y-1`,children:[(0,s.jsx)(t.k,{className:`w-4 h-4`}),` Open Form`]})})]}),(0,s.jsx)(t.s,{children:e&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-xl cursor-pointer`,onClick:()=>n(!1)}),(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:`w-full max-w-[500px] p-6 sm:p-8 lg:p-10 rounded-3xl md:rounded-3xl glass-panel relative glow-hover shadow-[0_8px_32px_rgba(0,0,0,0.08)] z-10 mx-4 max-h-[95vh] overflow-y-auto no-scrollbar`,children:[(0,s.jsx)(`div`,{className:`absolute -inset-[1px] bg-gradient-to-br from-[var(--primary-glow)] to-transparent opacity-30 blur-[20px] rounded-3xl md:rounded-3xl -z-10`}),(0,s.jsxs)(`div`,{className:`relative z-10 w-full`,children:[(0,s.jsx)(`button`,{onClick:()=>n(!1),className:`absolute -top-2 -right-2 w-8 h-8 flex items-center justify-center rounded-full hover:bg-foreground/5 text-foreground/60 hover:text-foreground transition-colors z-20`,children:(0,s.jsx)(t.d,{className:`w-5 h-5`})}),l===`success`?(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex flex-col items-center justify-center py-12 text-center`,children:[(0,s.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-green-500/10 border border-green-500/20 flex items-center justify-center text-green-500 mb-4`,children:(0,s.jsx)(t.dt,{className:`w-8 h-8`})}),(0,s.jsx)(`h4`,{className:`text-xl font-bold text-foreground mb-2`,children:`Simulation Complete!`}),(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/60 leading-relaxed max-w-[280px]`,children:`Your test data was sent successfully. Log in as an admin and open your Inbox to see it.`})]}):l===`loading`?(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`flex flex-col items-center justify-center py-16 text-center`,children:[(0,s.jsx)(`div`,{className:`w-10 h-10 border-4 border-accent border-r-transparent rounded-full animate-spin mb-4`}),(0,s.jsx)(`h4`,{className:`text-lg font-bold text-foreground tracking-tight`,children:`Processing`}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/50 mt-1`,children:`Simulating submission...`})]}):(0,s.jsxs)(t.o.div,{initial:{opacity:0},animate:{opacity:1},children:[(0,s.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,s.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight break-words`,children:`Popup Template`}),(0,s.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide leading-relaxed`,children:`Fill out the simulated fields below to test the interaction.`})]}),(0,s.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),u(`loading`);try{let e=t.Nt.currentUser?.uid||`guest`;await(0,i.addDoc)((0,i.collection)(t.Pt,`user_submissions`),{uid:e,...a,type:`template_simulation`,submittedAt:(0,i.serverTimestamp)()}),u(`success`),setTimeout(()=>{u(`idle`),o({concept:``,featureRequest:``,notes:``}),n(!1)},3e3)}catch{u(`error`)}},className:`space-y-4 w-full`,children:[(0,s.jsx)(t.i,{label:`Concept Name`,placeholder:`e.g. Project Apollo`,value:a.concept,onChange:e=>o({...a,concept:e.target.value})}),(0,s.jsx)(t.i,{label:`Feature Request`,placeholder:`e.g. Real-time sync`,value:a.featureRequest,onChange:e=>o({...a,featureRequest:e.target.value})}),(0,s.jsxs)(`div`,{className:`flex flex-col w-full relative`,children:[(0,s.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Simulated Notes`}),(0,s.jsx)(`textarea`,{rows:3,placeholder:`Type something here...`,value:a.notes,onChange:e=>o({...a,notes:e.target.value}),className:`flex w-full rounded-xl text-[15px] text-foreground px-4 py-3 transition-all duration-300 placeholder:text-foreground/40 focus:outline-none focus:border-accent glow-focus disabled:cursor-not-allowed disabled:opacity-50 glass-panel min-h-[100px] resize-none`})]}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsx)(t.r,{type:`submit`,className:`w-full px-6 md:px-8 py-3 md:py-3.5 rounded-xl font-semibold tracking-wide btn-primary text-[15px] shadow-xl transition-all duration-300 hover:-translate-y-1 active:scale-95 flex items-center justify-center`,isLoading:!1,children:`Trigger Simulation`})})]})]})]})]})]})})]})}function ot(){let[e,n]=(0,r.useState)(void 0);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 items-center`,children:[(0,s.jsx)(`div`,{className:`w-full max-w-5xl mb-8`,children:(0,s.jsxs)(c.Link,{to:`/templates`,className:`inline-flex items-center gap-2 text-foreground/50 hover:text-accent transition-colors font-medium text-[14px]`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4`}),` Back to Templates`]})}),(0,s.jsxs)(`div`,{className:`w-full max-w-5xl mx-auto mt-2 glass-panel rounded-3xl border border-[var(--panel-border)] p-6 md:p-10 relative overflow-hidden shadow-2xl`,children:[(0,s.jsx)(`div`,{className:`flex items-center justify-between mb-8 pb-6 border-b border-[var(--panel-border)]/50`,children:(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h3`,{className:`text-2xl font-extrabold text-foreground tracking-tight`,children:`System Files`}),(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/50 mt-1`,children:`Review and manage core application assets.`})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,s.jsxs)(`div`,{className:`glass-panel p-5 rounded-2xl border border-[var(--panel-border)]/50 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-4 w-full sm:w-auto`,children:[(0,s.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-red-500/10 flex items-center justify-center text-red-500 shrink-0`,children:(0,s.jsx)(t._,{className:`w-5 h-5`})}),(0,s.jsxs)(`div`,{className:`min-w-0 pr-2`,children:[(0,s.jsx)(`h4`,{className:`font-bold text-[14px] sm:text-[15px] text-foreground truncate`,children:`Critical Configuration File`}),(0,s.jsx)(`p`,{className:`text-[12px] sm:text-[13px] text-foreground/50 font-medium mt-0.5 truncate`,children:`Size: 4.2 MB • Modified 2 hours ago`})]})]}),(0,s.jsx)(t.r,{variant:`secondary`,onClick:()=>n(null),className:`w-full sm:w-auto shrink-0 flex items-center justify-center px-6 py-3 sm:py-2.5 text-[13px] font-bold rounded-xl text-red-500 hover:bg-red-500/10 hover:border-red-500/20 bg-red-500/5 sm:bg-transparent`,children:`Delete File`})]}),(0,s.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 opacity-50 pointer-events-none mt-2`,children:[1,2].map(e=>(0,s.jsxs)(`div`,{className:`glass-panel p-5 rounded-2xl border border-[var(--panel-border)]/20 flex items-center gap-4`,children:[(0,s.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-foreground/5 shrink-0`}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2 flex-1`,children:[(0,s.jsx)(`div`,{className:`w-32 h-3 rounded-full bg-foreground/10`}),(0,s.jsx)(`div`,{className:`w-20 h-2 rounded-full bg-foreground/5`})]})]},e))})]})]}),(0,s.jsx)(t.s,{children:e!==void 0&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-xl`}),(0,s.jsx)(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:`w-full max-w-[400px] p-6 rounded-3xl glass-panel border border-[var(--panel-border)] shadow-2xl relative z-10 text-center`,children:(0,s.jsx)(t.s,{mode:`wait`,children:e===null?(0,s.jsxs)(t.o.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full flex flex-col items-center`,children:[(0,s.jsx)(`h3`,{className:`text-xl font-extrabold mb-2 text-foreground tracking-tight`,children:`Confirm Deletion`}),(0,s.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 leading-relaxed mb-6`,children:`Are you entirely sure you wish to delete this configuration? This action is permanent.`}),(0,s.jsxs)(`div`,{className:`flex items-center gap-3 w-full`,children:[(0,s.jsx)(t.r,{variant:`secondary`,onClick:()=>n(!1),className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:`Cancel`}),(0,s.jsx)(t.r,{onClick:()=>n(!0),className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl bg-red-500 hover:bg-red-600 border-none text-white shadow-xl hover:shadow-red-500/20 glow-hover`,children:`Yes, Delete`})]})]},`confirm`):e===!0?(0,s.jsxs)(t.o.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full flex flex-col items-center py-2`,children:[(0,s.jsxs)(`h3`,{className:`text-xl font-extrabold mb-1 text-green-500 tracking-tight flex items-center gap-2`,children:[(0,s.jsx)(t._t,{className:`w-5 h-5`}),` Verified`]}),(0,s.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mb-6`,children:`Action successfully executed.`}),(0,s.jsx)(t.r,{variant:`secondary`,onClick:()=>n(void 0),className:`px-6 py-2 rounded-xl text-[13px] font-bold`,children:`Close Panel`})]},`success`):(0,s.jsxs)(t.o.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full flex flex-col items-center py-2`,children:[(0,s.jsxs)(`h3`,{className:`text-xl font-extrabold mb-1 text-foreground/80 tracking-tight flex items-center gap-2`,children:[(0,s.jsx)(t.d,{className:`w-5 h-5`}),` Aborted`]}),(0,s.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mb-6`,children:`Cancellation securely caught.`}),(0,s.jsx)(t.r,{variant:`secondary`,onClick:()=>n(void 0),className:`px-6 py-2 rounded-xl text-[13px] font-bold`,children:`Close Panel`})]},`error`)})})]})})]})}var st=[{text:`text-red-400`,bgCircle:`bg-red-400`,bgCard:`bg-red-500/[0.08]`,borderCard:`border-red-500/30`,bgLight:`bg-red-500/15`,bgHover:`hover:bg-red-500`,bgAlt:`bg-red-500/[0.04]`,name:`Red`},{text:`text-orange-400`,bgCircle:`bg-orange-400`,bgCard:`bg-orange-500/[0.08]`,borderCard:`border-orange-500/30`,bgLight:`bg-orange-500/15`,bgHover:`hover:bg-orange-500`,bgAlt:`bg-orange-500/[0.04]`,name:`Orange`},{text:`text-yellow-400`,bgCircle:`bg-yellow-400`,bgCard:`bg-yellow-500/[0.08]`,borderCard:`border-yellow-500/30`,bgLight:`bg-yellow-500/15`,bgHover:`hover:bg-yellow-500`,bgAlt:`bg-yellow-500/[0.04]`,name:`Yellow`},{text:`text-green-400`,bgCircle:`bg-green-400`,bgCard:`bg-green-500/[0.08]`,borderCard:`border-green-500/30`,bgLight:`bg-green-500/15`,bgHover:`hover:bg-green-500`,bgAlt:`bg-green-500/[0.04]`,name:`Green`},{text:`text-blue-400`,bgCircle:`bg-blue-400`,bgCard:`bg-blue-500/[0.08]`,borderCard:`border-blue-500/30`,bgLight:`bg-blue-500/15`,bgHover:`hover:bg-blue-500`,bgAlt:`bg-blue-500/[0.04]`,name:`Blue`},{text:`text-accent`,bgCircle:`bg-accent`,bgCard:`bg-accent/[0.08]`,borderCard:`border-accent/30`,bgLight:`bg-accent/15`,bgHover:`hover:bg-accent`,bgAlt:`bg-accent/[0.04]`,name:`Purple`},{text:`text-pink-400`,bgCircle:`bg-pink-400`,bgCard:`bg-pink-500/[0.08]`,borderCard:`border-pink-500/30`,bgLight:`bg-pink-500/15`,bgHover:`hover:bg-pink-500`,bgAlt:`bg-pink-500/[0.04]`,name:`Pink`},{text:`text-foreground/60`,bgCircle:`bg-foreground/30`,bgCard:`bg-foreground/[0.04]`,borderCard:`border-[var(--panel-border)]/50`,bgLight:`bg-foreground/15`,bgHover:`hover:bg-foreground/30`,bgAlt:`bg-foreground/[0.02]`,name:`Default`}];function ct({title:e=`Board View`,subtitle:n=`/templates/board`,backUrl:a=`/templates`,tasksCollection:o=`pub_tasks`,categoriesCollection:l=`pub_categories`,config:u,customContent:d}){let{user:f}=A(),p=!!u,m=u?.isInternal||u?.isShared;u?.isPrivate&&u?.isAdmin;let h=u?.isAdmin||m,g=p?h:!0,_=u?.showButton!==!1,v=u?.buttonText||`+`,y=u?.buttonStyle||`primary`,b=u?.keyName||`key`,x=u?.valueName||`value`,[S,C]=(0,r.useState)([]),[w,T]=(0,r.useState)([]),[E,D]=(0,r.useState)(null),[O,k]=(0,r.useState)(null),[j,M]=(0,r.useState)({name:``}),[N,P]=(0,r.useState)([]),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)(null),[ee,z]=(0,r.useState)(null),[B,V]=(0,r.useState)(null),[te,H]=(0,r.useState)(!1),[U,W]=(0,r.useState)(null),[G,K]=(0,r.useState)(``),[q,J]=(0,r.useState)(null);(0,r.useEffect)(()=>{let e=o.startsWith(`user_`),n=l.startsWith(`user_`);if(e&&!f)return;try{let e=localStorage.getItem(`fbos_board_tasks_${o}`);e&&C(JSON.parse(e));let t=localStorage.getItem(`fbos_board_cats_${l}`);t&&T(JSON.parse(t))}catch{}let r=(0,i.onSnapshot)(e&&f?(0,i.query)((0,i.collection)(t.Pt,o),(0,i.where)(`uid`,`==`,f.uid)):(0,i.collection)(t.Pt,o),e=>{let t=[];e.forEach(e=>{let n=e.data();t.push({id:e.id,categoryId:n.categoryId,name:n.name||n.text||`Unnamed Item`,fields:n.fields||(n.value?[{key:`Label`,value:n.value}]:[]),order:n.order||0})});let n=t.sort((e,t)=>(e.order||0)-(t.order||0));C(n),localStorage.setItem(`fbos_board_tasks_${o}`,JSON.stringify(n))}),a=(0,i.onSnapshot)(n&&f?(0,i.query)((0,i.collection)(t.Pt,l),(0,i.where)(`uid`,`==`,f.uid)):(0,i.collection)(t.Pt,l),e=>{let n=[];if(e.forEach(e=>{n.push({id:e.id,...e.data()})}),n.length===0){let e=[{id:`todo`,title:`To Do`,createdAt:Date.now()-2e3},{id:`in_progress`,title:`In Progress`,createdAt:Date.now()-1e3},{id:`review`,title:`Review`,createdAt:Date.now()}],n=f?{uid:f.uid}:{};e.forEach(e=>(0,i.setDoc)((0,i.doc)(t.Pt,l,e.id),{...n,title:e.title,createdAt:e.createdAt}))}else T(n),localStorage.setItem(`fbos_board_cats_${l}`,JSON.stringify(n))});return()=>{r(),a()}},[o,l,f]);let Y=(e,t)=>{t?(k(t.id),M({id:t.id,name:t.name}),P(t.fields?.length?[...t.fields,{key:``,value:``}]:[{key:``,value:``}])):(D(e),M({name:``}),P([{key:``,value:``}]))},ie=(e,t,n)=>{let r=[...N];r[e]={key:t,value:n},e===N.length-1&&(t.trim()!==``||n.trim()!==``)&&r.push({key:``,value:``}),P(r)},ae=(e,t)=>{e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`taskId`,t),I(t)},oe=(e,t)=>{e.preventDefault(),e.stopPropagation(),t!==F&&R(t)},se=(e,t)=>{e.preventDefault(),e.stopPropagation(),z(t)},X=e=>{e.preventDefault(),R(null),z(null)},ce=async(e,n,r)=>{e.preventDefault(),e.stopPropagation(),R(null),z(null);let a=e.dataTransfer.getData(`taskId`);if(!a||a===r){I(null);return}let s=S.find(e=>e.id===a);if(!s)return;let c=S.filter(e=>e.categoryId===n).sort((e,t)=>(e.order||0)-(t.order||0));if(s.categoryId===n?(c=c.filter(e=>e.id!==a),c.push(s)):c.push({...s,categoryId:n}),r){let e=c.findIndex(e=>e.id===r),t=c.findIndex(e=>e.id===a),[n]=c.splice(t,1);c.splice(e,0,n)}c.forEach((e,r)=>{let a={categoryId:n,order:r};f&&(a.uid=f.uid),(0,i.setDoc)((0,i.doc)(t.Pt,o,e.id),a,{merge:!0})}),I(null)},Z=async e=>{let n=j.id||`item_${Date.now()}`,r=j.name.trim(),a=r||`Untitled Item`,s=N.filter(e=>e.key.trim()!==``||e.value.trim()!==``),c=!0,l=j.id?S.find(e=>e.id===j.id):null;if(l){let e=JSON.stringify(l.fields||[]),t=JSON.stringify(s);l.name===a&&e===t&&(c=!1)}else !r&&s.length===0&&(c=!1);if(!c){D(null),k(null);return}V(j.id||`new`);let u={categoryId:e,name:a,fields:s};f&&!j.id&&(u.uid=f.uid),await(0,i.setDoc)((0,i.doc)(t.Pt,o,n),u,{merge:!0}),setTimeout(()=>{D(null),k(null),V(null)},400)},Q=(e,t)=>{J({type:`item`,id:e,title:t})},le=async()=>{let e=`cat_${Date.now()}`,n={title:``,createdAt:Date.now()};f&&(n.uid=f.uid),await(0,i.setDoc)((0,i.doc)(t.Pt,l,e),n),W(e),K(``),setTimeout(()=>{let e=document.getElementById(`board-container`);e&&e.scrollTo({left:e.scrollWidth,behavior:`smooth`})},150)},ue=async(e,n)=>{T(t=>t.map(t=>t.id===e?{...t,color:n}:t)),await(0,i.setDoc)((0,i.doc)(t.Pt,l,e),{color:n},{merge:!0})},de=async e=>{G.trim()?await(0,i.setDoc)((0,i.doc)(t.Pt,l,e),{title:G},{merge:!0}):await(0,i.deleteDoc)((0,i.doc)(t.Pt,l,e)),W(null)},fe=(e,t)=>{J({type:`category`,id:e,title:t})},pe=async()=>{if(q){H(!0);try{if(q.type===`item`)await(0,i.deleteDoc)((0,i.doc)(t.Pt,o,q.id)),k(null);else{let e=S.filter(e=>e.categoryId===q.id);for(let n of e)await(0,i.deleteDoc)((0,i.doc)(t.Pt,o,n.id));await(0,i.deleteDoc)((0,i.doc)(t.Pt,l,q.id))}}catch{}H(!1),J(null)}},me=[...w].sort((e,t)=>(e.createdAt||0)-(t.createdAt||0));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 overflow-x-hidden`,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}),n&&(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`}),n]})]}),p&&(0,s.jsx)(`div`,{className:`mb-6`,children:(0,s.jsx)(ne,{})}),(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between items-start sm:items-center mb-6 border-b border-[var(--panel-border)] pb-6 gap-4 relative z-20 shrink-0`,children:[!p&&a&&(0,s.jsxs)(c.Link,{to:a,className:`px-5 py-2 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold text-foreground/70 hover:bg-foreground/5 transition-all flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4`}),` Go Back`]}),p&&(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:u?.tabTitle||u?.tabName||e}),(0,s.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[S.length,` `,S.length===1?`item`:`items`,` · `,me.length,` `,me.length===1?`category`:`categories`]})]}),(0,s.jsx)(`div`,{className:`flex flex-col sm:flex-row gap-2 w-full sm:w-auto`,children:_&&(0,s.jsx)(t.r,{variant:y===`secondary`?`secondary`:void 0,onClick:le,className:`flex-1 sm:flex-none px-3 py-2.5 text-[14px] font-bold rounded-xl shadow-lg hover:-translate-y-0.5 transition-all shrink-0`,children:v===`+`?(0,s.jsx)(t.k,{className:`w-4 h-4`}):v})})]}),(0,s.jsx)(`div`,{className:`flex-1 w-full relative z-40 min-h-0`,children:d?(0,s.jsx)(`div`,{className:`fbos-content-slot w-full h-full overflow-y-auto`,children:(0,s.jsx)(d,{config:u,actions:{tasks:S,categories:w,collection:o,catCollection:l,user:f,saveTask:async(e,n)=>{let r=e||`item_${Date.now()}`;C(e=>e.find(e=>e.id===r)?e.map(e=>e.id===r?{...e,...n}:e):[...e,{id:r,...n}]),await(0,i.setDoc)((0,i.doc)(t.Pt,o,r),n,{merge:!0})},deleteTask:async e=>{C(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Pt,o,e))},saveCategory:async(e,n)=>{T(t=>t.find(t=>t.id===e)?t.map(t=>t.id===e?{...t,...n}:t):[...t,{id:e,...n}]),await(0,i.setDoc)((0,i.doc)(t.Pt,l,e),n,{merge:!0})},deleteCategory:async e=>{T(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Pt,l,e))},openInlineEditor:(e,t)=>Y(e,t)}})}):(0,s.jsxs)(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 z-10 flex flex-col h-full p-4 md:p-6`,children:[(0,s.jsx)(`div`,{className:`absolute top-0 right-0 w-[400px] h-[400px] bg-accent/5 blur-[100px] rounded-full pointer-events-none -z-10`}),(0,s.jsxs)(`div`,{id:`board-container`,className:`w-full h-full flex flex-row gap-4 md:gap-6 overflow-x-auto pb-4 snap-x snap-mandatory styled-scrollbars items-start`,children:[me.map((e,n)=>{let r=S.filter(t=>t.categoryId===e.id);r.sort((e,t)=>(e.order||0)-(t.order||0));let i=st.find(t=>t.text===e.color)||st.find(e=>e.text===`text-accent`);return i.text,i.bgLight,i.bgHover,(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:n*.1},className:`w-[300px] md:w-[320px] shrink-0 flex flex-col max-h-full rounded-3xl p-4 snap-center relative border transition-colors ${st.find(t=>t.text===e.color)?.bgCard||`bg-foreground/[0.02]`} ${st.find(t=>t.text===e.color)?.borderCard||`border-[var(--panel-border)]/50`}`,children:[(0,s.jsx)(`div`,{className:`flex items-center justify-between mb-4 px-2 relative z-[200]`,children:(0,s.jsxs)(`h3`,{className:`font-bold text-[14px] flex items-center w-full text-foreground/80 group relative z-[200]`,children:[U===e.id?(0,s.jsxs)(`div`,{className:`relative flex-1 w-full flex items-center pr-8 z-[200]`,children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),de(e.id)}}),(0,s.jsx)(`input`,{value:G,onChange:e=>K(e.target.value),onBlur:t=>{t.relatedTarget?.closest(`.category-color-picker`)||de(e.id)},onKeyDown:t=>t.key===`Enter`&&de(e.id),className:`bg-transparent border-none outline-none font-bold text-[14px] w-full p-0 ${e.color||`text-foreground/80`}`,placeholder:`Category name`,autoFocus:!0}),(0,s.jsxs)(`div`,{className:`absolute top-8 left-0 flex gap-1.5 bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-[100] category-color-picker items-center`,tabIndex:-1,children:[(0,s.jsx)(`button`,{onClick:async t=>{t.preventDefault(),t.stopPropagation(),await ue(e.id,``),W(null)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Reset Category Color`,children:(0,s.jsx)(t.d,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),st.map(t=>(0,s.jsx)(`button`,{onMouseDown:async n=>{n.preventDefault(),await ue(e.id,t.text)},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50 shrink-0`},t.name))]})]}):(0,s.jsxs)(`div`,{className:`flex items-center gap-2 w-full cursor-pointer hover:text-foreground transition-colors pr-8`,onClick:()=>{W(e.id),K(e.title)},children:[(0,s.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${st.find(t=>t.text===e.color)?.bgCircle||`bg-foreground/20`} transition-colors shrink-0`}),(0,s.jsx)(`span`,{className:`truncate flex-1 max-w-[200px] ${e.color||``}`,children:e.title||`Untitled Category`}),(0,s.jsx)(`span`,{className:`text-[11px] bg-foreground/10 text-foreground/60 px-1.5 py-0.5 rounded-md font-medium shrink-0`,children:r.length})]}),w.length>1&&(0,s.jsx)(`button`,{onClick:()=>fe(e.id,e.title),className:`absolute right-0 opacity-0 group-hover:opacity-100 text-foreground/30 hover:text-red-500 transition-all shrink-0`,children:(0,s.jsx)(t.v,{className:`w-3.5 h-3.5`})})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2.5 flex-1 overflow-y-auto styled-scrollbars pr-1 relative min-h-[150px] rounded-xl transition-all ${ee===e.id&&!L?`bg-foreground/5 scale-[1.01] border-dashed border border-accent/20`:``}`,onDragOver:t=>se(t,e.id),onDragLeave:X,onDrop:t=>ce(t,e.id),children:[(0,s.jsx)(t.s,{children:r.map(n=>O===n.id?(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-md border border-accent/40 transition-all flex flex-col gap-2 relative z-[100]`,children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),Z(e.id)}}),(0,s.jsx)(`textarea`,{placeholder:`Write an item name...`,className:`no-glow bg-transparent border-none outline-none text-[13px] text-foreground/90 font-medium leading-snug resize-none w-full min-h-[40px] relative z-10`,value:j.name,onChange:e=>M({...j,name:e.target.value}),onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),Z(e.id))}}),(0,s.jsx)(`div`,{className:`flex flex-col gap-2 mt-1 relative z-10 w-full`,children:N.map((t,n)=>(0,s.jsxs)(`div`,{className:`flex items-start bg-foreground/[0.04] border border-[var(--panel-border)]/50 rounded-[8px] px-2.5 py-1.5 w-full`,children:[(0,s.jsx)(`input`,{placeholder:b,value:t.key,onChange:e=>ie(n,e.target.value,t.value),onKeyDown:t=>t.key===`Enter`&&Z(e.id),className:`no-glow bg-transparent outline-none text-[11px] text-foreground/50 font-bold placeholder:text-foreground/30 relative top-[1px] shrink-0`,style:{width:`${Math.max(3,t.key.length||b.length)}ch`}}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative top-[1px]`,children:`:`}),(0,s.jsx)(`textarea`,{rows:1,placeholder:x,value:t.value,onChange:e=>ie(n,t.key,e.target.value),onInput:e=>{let t=e.target;t.style.height=`auto`,t.style.height=t.scrollHeight+`px`},onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),Z(e.id))},className:`no-glow bg-transparent outline-none text-[12px] text-foreground/90 font-medium flex-1 min-w-[40px] placeholder:opacity-40 resize-none overflow-hidden leading-tight relative top-[1px]`})]},n))}),B===n.id&&(0,s.jsx)(`div`,{className:`flex items-center justify-end pt-1`,children:(0,s.jsx)(`div`,{className:`w-3 h-3 border-2 border-accent border-t-transparent rounded-full animate-spin`})})]},n.id):(0,s.jsxs)(t.o.div,{draggable:!0,onDragStart:e=>ae(e,n.id),onDragOver:e=>oe(e,n.id),onDragLeave:X,onDrop:t=>ce(t,e.id,n.id),initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-sm hover:shadow-md cursor-grab active:cursor-grabbing hover:border-accent/40 transition-all group flex flex-col gap-2 relative z-10 border ${L===n.id?`border-accent border-t-2 translate-y-1`:`border-[var(--panel-border)]`} ${F===n.id?`opacity-30 scale-95 border-dashed border-2`:``}`,children:[(0,s.jsxs)(`div`,{className:`absolute top-2 right-2 flex items-center gap-1.5 opacity-0 group-hover:opacity-100 transition-opacity bg-background/90 backdrop-blur-md border border-[var(--panel-border)] rounded-lg p-1 z-20 shadow-md`,children:[(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),Y(e.id,n)},className:`p-1 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-accent transition-colors`,children:(0,s.jsx)(t.A,{className:`w-3.5 h-3.5`})}),(0,s.jsx)(`button`,{onClick:e=>{e.stopPropagation(),Q(n.id,n.name)},className:`p-1 hover:bg-red-500/10 rounded-md text-foreground/60 hover:text-red-500 transition-colors`,children:(0,s.jsx)(t.v,{className:`w-3.5 h-3.5`})})]}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/90 font-medium leading-snug break-words pr-12`,children:n.name}),n.fields&&n.fields.length>0&&(0,s.jsx)(`div`,{className:`flex flex-row flex-wrap gap-2 mt-2`,children:n.fields.map((e,t)=>(0,s.jsxs)(`div`,{className:`inline-flex bg-foreground/[0.04] border border-[var(--panel-border)]/50 rounded-[8px] px-2.5 py-1.5 max-w-full`,children:[(0,s.jsxs)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative -top-[1px] shrink-0 break-all`,children:[e.key,`:`]}),(0,s.jsx)(`span`,{className:`text-[12px] text-foreground/90 font-medium break-words leading-tight min-w-0`,children:e.value})]},t))}),(0,s.jsxs)(`div`,{className:`flex items-end justify-between mt-3 pt-3 border-t border-[var(--panel-border)]/50 w-full gap-2`,children:[g&&p&&f?(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5 pr-2 border-r border-[var(--panel-border)] border-dashed mr-auto`,children:[f.photoURL?(0,s.jsx)(`img`,{src:f.photoURL,className:`w-4 h-4 rounded-full shrink-0 object-cover`}):(0,s.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-accent/20 text-accent flex items-center justify-center text-[9px] font-bold shrink-0`,children:(f.displayName||f.email||`U`)[0].toUpperCase()}),(0,s.jsx)(`span`,{className:`text-[10px] font-bold text-foreground/60 truncate max-w-[80px]`,children:f.displayName||f.email?.split(`@`)[0]||`User`})]}):(0,s.jsx)(`div`,{className:`flex items-center gap-2 pr-2 border-r border-[var(--panel-border)] border-dashed mr-auto`}),(0,s.jsx)(`span`,{className:`text-[10px] text-foreground/40 font-bold text-right pt-0.5 shrink-0 max-w-[50%] truncate flex-1`,children:n.id.startsWith(`item_`)?new Date(parseInt(n.id.split(`_`)[1])).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}):`Recently Added`})]})]},n.id))}),E===e.id?(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-md border border-accent/40 transition-all flex flex-col gap-2 relative z-[100] mt-1`,children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),Z(e.id)}}),(0,s.jsx)(`textarea`,{placeholder:`Write an item name...`,className:`no-glow bg-transparent border-none outline-none text-[13px] text-foreground/90 font-medium leading-snug resize-none w-full min-h-[40px] relative z-10`,value:j.name,onChange:e=>M({...j,name:e.target.value}),onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),Z(e.id))},autoFocus:!0}),(0,s.jsx)(`div`,{className:`flex flex-col gap-2 mt-1 relative z-10 w-full`,children:N.map((t,n)=>(0,s.jsxs)(`div`,{className:`flex items-start bg-foreground/[0.04] border border-[var(--panel-border)]/50 rounded-[8px] px-2.5 py-1.5 w-full`,children:[(0,s.jsx)(`input`,{placeholder:b,style:{width:`${Math.max(3,t.key.length||b.length)}ch`},value:t.key,onChange:e=>ie(n,e.target.value,t.value),onKeyDown:t=>t.key===`Enter`&&Z(e.id),className:`no-glow bg-transparent outline-none text-[11px] text-foreground/50 font-bold placeholder:text-foreground/30 relative top-[1px]`}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative top-[1px]`,children:`:`}),(0,s.jsx)(`textarea`,{rows:1,placeholder:x,value:t.value,onChange:e=>ie(n,t.key,e.target.value),onInput:e=>{let t=e.target;t.style.height=`auto`,t.style.height=t.scrollHeight+`px`},onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),Z(e.id))},className:`no-glow bg-transparent outline-none text-[12px] text-foreground/90 font-medium flex-1 min-w-[40px] placeholder:opacity-40 resize-none overflow-hidden leading-tight relative top-[1px]`})]},n))}),B===`new`&&(0,s.jsx)(`div`,{className:`flex items-center justify-end pt-1`,children:(0,s.jsx)(`div`,{className:`w-3 h-3 border-2 border-accent border-t-transparent rounded-full animate-spin`})})]}):(0,s.jsxs)(`button`,{onClick:()=>Y(e.id),className:`flex items-center gap-2 justify-center w-full py-2.5 mt-1 rounded-xl border border-transparent text-[12px] font-bold text-foreground/40 hover:text-foreground hover:bg-foreground/[0.03] transition-all shrink-0`,children:[(0,s.jsx)(t.k,{className:`w-4 h-4`}),` Add Item`]})]})]},e.id)}),(0,s.jsx)(`div`,{className:`w-[10px] shrink-0 pointer-events-none`})]})]})}),(0,s.jsx)(`style`,{children:`.styled-scrollbars::-webkit-scrollbar { width: 6px; height: 6px; } .styled-scrollbars::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--accent-color) 20%, transparent); border-radius: 4px; } .styled-scrollbars::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--accent-color) 40%, transparent); }`}),(0,s.jsx)(re,{isOpen:!!q,title:`Confirm Deletion`,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:q?.title}),` This action is permanent.`]}),onConfirm:pe,onCancel:()=>J(null),isProcessing:te,confirmText:`Yes, Delete`})]})}function lt(e){return Array.isArray?Array.isArray(e):yt(e)===`[object Array]`}function ut(e){if(typeof e==`string`)return e;if(typeof e==`bigint`)return e.toString();let t=e+``;return t==`0`&&1/e==-1/0?`-0`:t}function dt(e){return e==null?``:ut(e)}function ft(e){return typeof e==`string`}function pt(e){return typeof e==`number`}function mt(e){return e===!0||e===!1||gt(e)&&yt(e)==`[object Boolean]`}function ht(e){return typeof e==`object`}function gt(e){return ht(e)&&e!==null}function _t(e){return e!=null}function vt(e){return!e.trim().length}function yt(e){return e==null?e===void 0?`[object Undefined]`:`[object Null]`:Object.prototype.toString.call(e)}var bt=`Incorrect 'index' type`,xt=e=>`Invalid value for key ${e}`,St=e=>`Pattern length exceeds max of ${e}.`,Ct=e=>`Missing ${e} property in key`,wt=e=>`Property 'weight' in key '${e}' must be a positive integer`,Tt=Object.prototype.hasOwnProperty,Et=class{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(e=>{let n=Dt(e);this._keys.push(n),this._keyMap[n.id]=n,t+=n.weight}),this._keys.forEach(e=>{e.weight/=t})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function Dt(e){let t=null,n=null,r=null,i=1,a=null;if(ft(e)||lt(e))r=e,t=Ot(e),n=kt(e);else{if(!Tt.call(e,`name`))throw Error(Ct(`name`));let o=e.name;if(r=o,Tt.call(e,`weight`)&&(i=e.weight,i<=0))throw Error(wt(o));t=Ot(o),n=kt(o),a=e.getFn}return{path:t,id:n,weight:i,src:r,getFn:a}}function Ot(e){return lt(e)?e:e.split(`.`)}function kt(e){return lt(e)?e.join(`.`):e}function At(e,t){let n=[],r=!1,i=(e,t,a,o)=>{if(_t(e))if(!t[a])n.push(o===void 0?e:{v:e,i:o});else{let s=e[t[a]];if(!_t(s))return;if(a===t.length-1&&(ft(s)||pt(s)||mt(s)||typeof s==`bigint`))n.push(o===void 0?dt(s):{v:dt(s),i:o});else if(lt(s)){r=!0;for(let e=0,n=s.length;e<n;e+=1)i(s[e],t,a+1,e)}else t.length&&i(s,t,a+1,o)}};return i(e,ft(t)?t.split(`.`):t,0),r?n:n[0]}var jt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Mt={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(e,t)=>e.score===t.score?e.idx<t.idx?-1:1:e.score<t.score?-1:1},Nt={location:0,threshold:.6,distance:100},Pt={useExtendedSearch:!1,useTokenSearch:!1,getFn:At,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1},$=Object.freeze({...Mt,...jt,...Nt,...Pt}),Ft=/[^ ]+/g;function It(e=1,t=3){let n=new Map,r=10**t;return{get(t){let i=t.match(Ft).length;if(n.has(i))return n.get(i);let a=1/i**(.5*e),o=parseFloat(Math.round(a*r)/r);return n.set(i,o),o},clear(){n.clear()}}}var Lt=class{constructor({getFn:e=$.getFn,fieldNormWeight:t=$.fieldNormWeight}={}){this.norm=It(t,3),this.getFn=e,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((e,t)=>{this._keysMap[e.id]=t})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,ft(this.docs[0])?this.docs.forEach((e,t)=>{this._addString(e,t)}):this.docs.forEach((e,t)=>{this._addObject(e,t)}),this.norm.clear())}add(e){let t=this.size();ft(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,n=this.size();t<n;t+=1)--this.records[t].i}removeAll(e){for(let t=e.length-1;t>=0;--t)this.records.splice(e[t],1);for(let e=0,t=this.records.length;e<t;e+=1)this.records[e].i=e}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_addString(e,t){if(!_t(e)||vt(e))return;let n={v:e,i:t,n:this.norm.get(e)};this.records.push(n)}_addObject(e,t){let n={i:t,$:{}};this.keys.forEach((t,r)=>{let i=t.getFn?t.getFn(e):this.getFn(e,t.path);if(_t(i)){if(lt(i)){let e=[];for(let t=0,n=i.length;t<n;t+=1){let n=i[t];if(_t(n)){if(ft(n)){if(!vt(n)){let r={v:n,i:t,n:this.norm.get(n)};e.push(r)}}else if(_t(n.v)){let t=ft(n.v)?n.v:dt(n.v);if(!vt(t)){let r={v:t,i:n.i,n:this.norm.get(t)};e.push(r)}}}}n.$[r]=e}else if(ft(i)&&!vt(i)){let e={v:i,n:this.norm.get(i)};n.$[r]=e}}}),this.records.push(n)}toJSON(){return{keys:this.keys.map(({getFn:e,...t})=>t),records:this.records}}};function Rt(e,t,{getFn:n=$.getFn,fieldNormWeight:r=$.fieldNormWeight}={}){let i=new Lt({getFn:n,fieldNormWeight:r});return i.setKeys(e.map(Dt)),i.setSources(t),i.create(),i}function zt(e,{getFn:t=$.getFn,fieldNormWeight:n=$.fieldNormWeight}={}){let{keys:r,records:i}=e,a=new Lt({getFn:t,fieldNormWeight:n});return a.setKeys(r),a.setIndexRecords(i),a}function Bt(e=[],t=$.minMatchCharLength){let n=[],r=-1,i=-1,a=0;for(let o=e.length;a<o;a+=1){let o=e[a];o&&r===-1?r=a:!o&&r!==-1&&(i=a-1,i-r+1>=t&&n.push([r,i]),r=-1)}return e[a-1]&&a-r>=t&&n.push([r,a-1]),n}var Vt=32;function Ht(e,t,n,{location:r=$.location,distance:i=$.distance,threshold:a=$.threshold,findAllMatches:o=$.findAllMatches,minMatchCharLength:s=$.minMatchCharLength,includeMatches:c=$.includeMatches,ignoreLocation:l=$.ignoreLocation}={}){if(t.length>Vt)throw Error(St(Vt));let u=t.length,d=e.length,f=Math.max(0,Math.min(r,d)),p=a,m=f,h=(e,t)=>{let n=e/u;if(l)return n;let r=Math.abs(f-t);return i?n+r/i:r?1:n},g=s>1||c,_=g?Array(d):[],v;for(;(v=e.indexOf(t,m))>-1;){let e=h(0,v);if(p=Math.min(e,p),m=v+u,g){let e=0;for(;e<u;)_[v+e]=1,e+=1}}m=-1;let y=[],b=1,x=u+d,S=1<<u-1;for(let t=0;t<u;t+=1){let r=0,i=x;for(;r<i;)h(t,f+i)<=p?r=i:x=i,i=Math.floor((x-r)/2+r);x=i;let a=Math.max(1,f-i+1),s=o?d:Math.min(f+i,d)+u,c=Array(s+2);c[s+1]=(1<<t)-1;for(let r=s;r>=a;--r){let i=r-1,o=n[e[i]];if(g&&(_[i]=+!!o),c[r]=(c[r+1]<<1|1)&o,t&&(c[r]|=(y[r+1]|y[r])<<1|1|y[r+1]),c[r]&S&&(b=h(t,i),b<=p)){if(p=b,m=i,m<=f)break;a=Math.max(1,2*f-m)}}if(h(t+1,f)>p)break;y=c}let C={isMatch:m>=0,score:Math.max(.001,b)};if(g){let e=Bt(_,s);e.length?c&&(C.indices=e):C.isMatch=!1}return C}function Ut(e){let t={};for(let n=0,r=e.length;n<r;n+=1){let i=e.charAt(n);t[i]=(t[i]||0)|1<<r-n-1}return t}function Wt(e){if(e.length<=1)return e;e.sort((e,t)=>e[0]-t[0]||e[1]-t[1]);let t=[e[0]];for(let n=1,r=e.length;n<r;n+=1){let r=t[t.length-1],i=e[n];i[0]<=r[1]+1?r[1]=Math.max(r[1],i[1]):t.push(i)}return t}var Gt={ł:`l`,Ł:`L`,đ:`d`,Đ:`D`,ø:`o`,Ø:`O`,ħ:`h`,Ħ:`H`,ŧ:`t`,Ŧ:`T`,ı:`i`,ß:`ss`},Kt=RegExp(`[`+Object.keys(Gt).join(``)+`]`,`g`),qt=String.prototype.normalize?e=>e.normalize(`NFD`).replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,``).replace(Kt,e=>Gt[e]):e=>e,Jt=class{constructor(e,{location:t=$.location,threshold:n=$.threshold,distance:r=$.distance,includeMatches:i=$.includeMatches,findAllMatches:a=$.findAllMatches,minMatchCharLength:o=$.minMatchCharLength,isCaseSensitive:s=$.isCaseSensitive,ignoreDiacritics:c=$.ignoreDiacritics,ignoreLocation:l=$.ignoreLocation}={}){if(this.options={location:t,threshold:n,distance:r,includeMatches:i,findAllMatches:a,minMatchCharLength:o,isCaseSensitive:s,ignoreDiacritics:c,ignoreLocation:l},e=s?e:e.toLowerCase(),e=c?qt(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;let u=(e,t)=>{this.chunks.push({pattern:e,alphabet:Ut(e),startIndex:t})},d=this.pattern.length;if(d>Vt){let e=0,t=d%Vt,n=d-t;for(;e<n;)u(this.pattern.substr(e,Vt),e),e+=Vt;if(t){let e=d-Vt;u(this.pattern.substr(e),e)}}else u(this.pattern,0)}searchIn(e){let{isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=t?e:e.toLowerCase(),e=n?qt(e):e,this.pattern===e){let t={isMatch:!0,score:0};return r&&(t.indices=[[0,e.length-1]]),t}let{location:i,distance:a,threshold:o,findAllMatches:s,minMatchCharLength:c,ignoreLocation:l}=this.options,u=[],d=0,f=!1;this.chunks.forEach(({pattern:t,alphabet:n,startIndex:p})=>{let{isMatch:m,score:h,indices:g}=Ht(e,t,n,{location:i+p,distance:a,threshold:o,findAllMatches:s,minMatchCharLength:c,includeMatches:r,ignoreLocation:l});m&&(f=!0),d+=h,m&&g&&u.push(...g)});let p={isMatch:f,score:f?d/this.chunks.length:1};return f&&r&&(p.indices=Wt(u)),p}},Yt=class{constructor(e){this.pattern=e}static isMultiMatch(e){return Xt(e,this.multiRegex)}static isSingleMatch(e){return Xt(e,this.singleRegex)}search(e){return{isMatch:!1,score:1}}};function Xt(e,t){let n=e.match(t);return n?n[1]:null}var Zt=class extends Yt{constructor(e){super(e)}static get type(){return`exact`}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){let t=e===this.pattern;return{isMatch:t,score:+!t,indices:[0,this.pattern.length-1]}}},Qt=class extends Yt{constructor(e){super(e)}static get type(){return`inverse-exact`}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){let t=e.indexOf(this.pattern)===-1;return{isMatch:t,score:+!t,indices:[0,e.length-1]}}},$t=class extends Yt{constructor(e){super(e)}static get type(){return`prefix-exact`}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){let t=e.startsWith(this.pattern);return{isMatch:t,score:+!t,indices:[0,this.pattern.length-1]}}},en=class extends Yt{constructor(e){super(e)}static get type(){return`inverse-prefix-exact`}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){let t=!e.startsWith(this.pattern);return{isMatch:t,score:+!t,indices:[0,e.length-1]}}},tn=class extends Yt{constructor(e){super(e)}static get type(){return`suffix-exact`}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){let t=e.endsWith(this.pattern);return{isMatch:t,score:+!t,indices:[e.length-this.pattern.length,e.length-1]}}},nn=class extends Yt{constructor(e){super(e)}static get type(){return`inverse-suffix-exact`}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){let t=!e.endsWith(this.pattern);return{isMatch:t,score:+!t,indices:[0,e.length-1]}}},rn=class extends Yt{constructor(e,{location:t=$.location,threshold:n=$.threshold,distance:r=$.distance,includeMatches:i=$.includeMatches,findAllMatches:a=$.findAllMatches,minMatchCharLength:o=$.minMatchCharLength,isCaseSensitive:s=$.isCaseSensitive,ignoreDiacritics:c=$.ignoreDiacritics,ignoreLocation:l=$.ignoreLocation}={}){super(e),this._bitapSearch=new Jt(e,{location:t,threshold:n,distance:r,includeMatches:i,findAllMatches:a,minMatchCharLength:o,isCaseSensitive:s,ignoreDiacritics:c,ignoreLocation:l})}static get type(){return`fuzzy`}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}},an=class extends Yt{constructor(e){super(e)}static get type(){return`include`}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let t=0,n,r=[],i=this.pattern.length;for(;(n=e.indexOf(this.pattern,t))>-1;)t=n+i,r.push([n,t-1]);let a=!!r.length;return{isMatch:a,score:+!a,indices:r}}},on=[Zt,an,$t,en,nn,tn,Qt,rn],sn=on.length,cn=`\0`,ln=`|`;function un(e){let t=[],n=e.length,r=0;for(;r<n;){for(;r<n&&e[r]===` `;)r++;if(r>=n)break;let i=r;for(;i<n&&e[i]!==` `&&e[i]!==`"`;)i++;if(i<n&&e[i]===`"`){for(i++;i<n;){if(e[i]===`"`){let t=i+1;if(t>=n||e[t]===` `){i++;break}if(e[t]===`$`&&(t+1>=n||e[t+1]===` `)){i+=2;break}}i++}t.push(e.substring(r,i)),r=i}else{for(;i<n&&e[i]!==` `;)i++;t.push(e.substring(r,i)),r=i}}return t}function dn(e,t={}){return e.replace(/\\\|/g,cn).split(ln).map(e=>{let n=un(e.replace(/\u0000/g,`|`).trim()).filter(e=>e&&!!e.trim()),r=[];for(let e=0,i=n.length;e<i;e+=1){let i=n[e],a=!1,o=-1;for(;!a&&++o<sn;){let e=on[o],n=e.isMultiMatch(i);n&&(r.push(new e(n,t)),a=!0)}if(!a)for(o=-1;++o<sn;){let e=on[o],n=e.isSingleMatch(i);if(n){r.push(new e(n,t));break}}}return r})}var fn=new Set([rn.type,an.type]),pn=class{constructor(e,{isCaseSensitive:t=$.isCaseSensitive,ignoreDiacritics:n=$.ignoreDiacritics,includeMatches:r=$.includeMatches,minMatchCharLength:i=$.minMatchCharLength,ignoreLocation:a=$.ignoreLocation,findAllMatches:o=$.findAllMatches,location:s=$.location,threshold:c=$.threshold,distance:l=$.distance}={}){this.query=null,this.options={isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r,minMatchCharLength:i,findAllMatches:o,ignoreLocation:a,location:s,threshold:c,distance:l},e=t?e:e.toLowerCase(),e=n?qt(e):e,this.pattern=e,this.query=dn(this.pattern,this.options)}static condition(e,t){return t.useExtendedSearch}searchIn(e){let t=this.query;if(!t)return{isMatch:!1,score:1};let{includeMatches:n,isCaseSensitive:r,ignoreDiacritics:i}=this.options;e=r?e:e.toLowerCase(),e=i?qt(e):e;let a=0,o=[],s=0,c=!1;for(let r=0,i=t.length;r<i;r+=1){let i=t[r];o.length=0,a=0,c=!1;for(let t=0,r=i.length;t<r;t+=1){let r=i[t],{isMatch:l,indices:u,score:d}=r.search(e);if(l){a+=1,s+=d;let e=r.constructor.type;e.startsWith(`inverse`)&&(c=!0),n&&(fn.has(e)?o.push(...u):o.push(u))}else{s=0,a=0,o.length=0,c=!1;break}}if(a){let e={isMatch:!0,score:s/a};return c&&(e.hasInverse=!0),n&&(e.indices=Wt(o)),e}}return{isMatch:!1,score:1}}},mn=[];function hn(...e){mn.push(...e)}function gn(e,t){for(let n=0,r=mn.length;n<r;n+=1){let r=mn[n];if(r.condition(e,t))return new r(e,t)}return new Jt(e,t)}var _n={AND:`$and`,OR:`$or`},vn={PATH:`$path`,PATTERN:`$val`},yn=e=>!!(e[_n.AND]||e[_n.OR]),bn=e=>!!e[vn.PATH],xn=e=>!lt(e)&&ht(e)&&!yn(e),Sn=e=>({[_n.AND]:Object.keys(e).map(t=>({[t]:e[t]}))});function Cn(e,t,{auto:n=!0}={}){let r=e=>{if(ft(e)){let r={keyId:null,pattern:e};return n&&(r.searcher=gn(e,t)),r}let i=Object.keys(e),a=bn(e);if(!a&&i.length>1&&!yn(e))return r(Sn(e));if(xn(e)){let r=a?e[vn.PATH]:i[0],o=a?e[vn.PATTERN]:e[r];if(!ft(o))throw Error(xt(r));let s={keyId:kt(r),pattern:o};return n&&(s.searcher=gn(o,t)),s}let o={children:[],operator:i[0]};return i.forEach(t=>{let n=e[t];lt(n)&&n.forEach(e=>{o.children.push(r(e))})}),o};return yn(e)||(e=Sn(e)),r(e)}function wn(e,{ignoreFieldNorm:t=$.ignoreFieldNorm}){let n=1;return e.forEach(({key:e,norm:r,score:i})=>{let a=e?e.weight:null;n*=(i===0&&a?2**-52:i)**+((a||1)*(t?1:r))}),n}function Tn(e,{ignoreFieldNorm:t=$.ignoreFieldNorm}){e.forEach(e=>{e.score=wn(e.matches,{ignoreFieldNorm:t})})}var En=class{constructor(e){this.limit=e,this.heap=[]}get size(){return this.heap.length}shouldInsert(e){return this.size<this.limit||e<this.heap[0].score}insert(e){this.size<this.limit?(this.heap.push(e),this._bubbleUp(this.size-1)):e.score<this.heap[0].score&&(this.heap[0]=e,this._sinkDown(0))}extractSorted(e){return this.heap.sort(e)}_bubbleUp(e){let t=this.heap;for(;e>0;){let n=e-1>>1;if(t[e].score<=t[n].score)break;let r=t[e];t[e]=t[n],t[n]=r,e=n}}_sinkDown(e){let t=this.heap,n=t.length,r=e;do{e=r;let i=2*e+1,a=2*e+2;if(i<n&&t[i].score>t[r].score&&(r=i),a<n&&t[a].score>t[r].score&&(r=a),r!==e){let n=t[e];t[e]=t[r],t[r]=n}}while(r!==e)}};function Dn(e,t){let n=e.matches;t.matches=[],_t(n)&&n.forEach(e=>{if(!_t(e.indices)||!e.indices.length)return;let{indices:n,value:r}=e,i={indices:n,value:r};e.key&&(i.key=e.key.src),e.idx>-1&&(i.refIndex=e.idx),t.matches.push(i)})}function On(e,t){t.score=e.score}function kn(e,t,{includeMatches:n=$.includeMatches,includeScore:r=$.includeScore}={}){let i=[];return n&&i.push(Dn),r&&i.push(On),e.map(e=>{let{idx:n}=e,r={item:t[n],refIndex:n};return i.length&&i.forEach(t=>{t(e,r)}),r})}var An=/\b\w+\b/g;function jn({isCaseSensitive:e=!1,ignoreDiacritics:t=!1}={}){return{tokenize(n){return e||(n=n.toLowerCase()),t&&(n=qt(n)),n.match(An)||[]}}}function Mn(e,t,n){let r=new Map,i=new Map,a=0;function o(e,t,o,s){let c=n.tokenize(e);if(!c.length)return;a++;let l=new Map;for(let e of c)l.set(e,(l.get(e)||0)+1);for(let[e,n]of l){let a={docIdx:t,keyIdx:o,subIdx:s,tf:n},c=r.get(e);c||(c=[],r.set(e,c)),c.push(a),i.set(e,(i.get(e)||0)+1)}}for(let n of e){let{i:e,v:r,$:i}=n;if(r!==void 0){o(r,e,-1,-1);continue}if(i)for(let n=0;n<t;n++){let t=i[n];if(t)if(Array.isArray(t))for(let r of t)o(r.v,e,n,r.i??-1);else o(t.v,e,n,-1)}}return{terms:r,fieldCount:a,df:i}}function Nn(e,t,n,r){let{i,v:a,$:o}=t;function s(t,n,a){let o=r.tokenize(t);if(!o.length)return;e.fieldCount++;let s=new Map;for(let e of o)s.set(e,(s.get(e)||0)+1);for(let[t,r]of s){let o={docIdx:i,keyIdx:n,subIdx:a,tf:r},s=e.terms.get(t);s||(s=[],e.terms.set(t,s)),s.push(o),e.df.set(t,(e.df.get(t)||0)+1)}}if(a!==void 0){s(a,-1,-1);return}if(o)for(let e=0;e<n;e++){let t=o[e];if(t)if(Array.isArray(t))for(let n of t)s(n.v,e,n.i??-1);else s(t.v,e,-1)}}function Pn(e,t){for(let[n,r]of e.terms){let i=r.filter(e=>e.docIdx!==t),a=r.length-i.length;a>0&&(e.fieldCount-=a,e.df.set(n,(e.df.get(n)||0)-a),i.length===0?(e.terms.delete(n),e.df.delete(n)):e.terms.set(n,i))}}var Fn=class{constructor(e,t,n){this.options={...$,...t},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new Et(this.options.keys),this._docs=e,this._myIndex=null,this._invertedIndex=null,this.setCollection(e,n),this._lastQuery=null,this._lastSearcher=null}_getSearcher(e){if(this._lastQuery===e)return this._lastSearcher;let t=gn(e,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=e,this._lastSearcher=t,t}setCollection(e,t){if(this._docs=e,t&&!(t instanceof Lt))throw Error(bt);if(this._myIndex=t||Rt(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){let e=jn({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});this._invertedIndex=Mn(this._myIndex.records,this._myIndex.keys.length,e)}}add(e){if(_t(e)&&(this._docs.push(e),this._myIndex.add(e),this._invertedIndex)){let e=this._myIndex.records[this._myIndex.records.length-1],t=jn({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});Nn(this._invertedIndex,e,this._myIndex.keys.length,t)}}remove(e=()=>!1){let t=[],n=[];for(let r=0,i=this._docs.length;r<i;r+=1)e(this._docs[r],r)&&(t.push(this._docs[r]),n.push(r));if(n.length){if(this._invertedIndex)for(let e of n)Pn(this._invertedIndex,e);for(let e=n.length-1;e>=0;--e)this._docs.splice(n[e],1);this._myIndex.removeAll(n)}return t}removeAt(e){this._invertedIndex&&Pn(this._invertedIndex,e);let t=this._docs.splice(e,1)[0];return this._myIndex.removeAt(e),t}getIndex(){return this._myIndex}search(e,t){let{limit:n=-1}=t||{},{includeMatches:r,includeScore:i,shouldSort:a,sortFn:o,ignoreFieldNorm:s}=this.options;if(ft(e)&&!e.trim()){let e=this._docs.map((e,t)=>({item:e,refIndex:t}));return pt(n)&&n>-1&&(e=e.slice(0,n)),e}let c=pt(n)&&n>0&&ft(e),l;if(c){let t=new En(n);ft(this._docs[0])?this._searchStringList(e,{heap:t,ignoreFieldNorm:s}):this._searchObjectList(e,{heap:t,ignoreFieldNorm:s}),l=t.extractSorted(o)}else l=ft(e)?ft(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e),Tn(l,{ignoreFieldNorm:s}),a&&l.sort(o),pt(n)&&n>-1&&(l=l.slice(0,n));return kn(l,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(e,{heap:t,ignoreFieldNorm:n}={}){let r=this._getSearcher(e),{records:i}=this._myIndex,a=t?null:[];return i.forEach(({v:e,i,n:o})=>{if(!_t(e))return;let{isMatch:s,score:c,indices:l}=r.searchIn(e);if(s){let r={item:e,idx:i,matches:[{score:c,value:e,norm:o,indices:l}]};t?(r.score=wn(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):a.push(r)}}),a}_searchLogical(e){let t=Cn(e,this.options),n=(e,t,r)=>{if(!(`children`in e)){let{keyId:n,searcher:i}=e,a;return n===null?(a=[],this._myIndex.keys.forEach((e,n)=>{a.push(...this._findMatches({key:e,value:t[n],searcher:i}))})):a=this._findMatches({key:this._keyStore.get(n),value:this._myIndex.getValueForItemAtKeyId(t,n),searcher:i}),a&&a.length?[{idx:r,item:t,matches:a}]:[]}let{children:i,operator:a}=e,o=[];for(let e=0,s=i.length;e<s;e+=1){let s=i[e],c=n(s,t,r);if(c.length)o.push(...c);else if(a===_n.AND)return[]}return o},r=this._myIndex.records,i=new Map,a=[];return r.forEach(({$:e,i:r})=>{if(_t(e)){let o=n(t,e,r);o.length&&(i.has(r)||(i.set(r,{idx:r,item:e,matches:[]}),a.push(i.get(r))),o.forEach(({matches:e})=>{i.get(r).matches.push(...e)}))}}),a}_searchObjectList(e,{heap:t,ignoreFieldNorm:n}={}){let r=this._getSearcher(e),{keys:i,records:a}=this._myIndex,o=t?null:[];return a.forEach(({$:e,i:a})=>{if(!_t(e))return;let s=[],c=!1,l=!1;if(i.forEach((t,n)=>{let i=this._findMatches({key:t,value:e[n],searcher:r});i.length?(s.push(...i),i[0].hasInverse&&(l=!0)):c=!0}),!(l&&c)&&s.length){let r={idx:a,item:e,matches:s};t?(r.score=wn(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):o.push(r)}}),o}_findMatches({key:e,value:t,searcher:n}){if(!_t(t))return[];let r=[];if(lt(t))t.forEach(({v:t,i,n:a})=>{if(!_t(t))return;let{isMatch:o,score:s,indices:c,hasInverse:l}=n.searchIn(t);o&&r.push({score:s,key:e,value:t,idx:i,norm:a,indices:c,hasInverse:l})});else{let{v:i,n:a}=t,{isMatch:o,score:s,indices:c,hasInverse:l}=n.searchIn(i);o&&r.push({score:s,key:e,value:i,norm:a,indices:c,hasInverse:l})}return r}},In=class{static condition(e,t){return t.useTokenSearch}constructor(e,t){this.options=t,this.analyzer=jn({isCaseSensitive:t.isCaseSensitive,ignoreDiacritics:t.ignoreDiacritics});let n=this.analyzer.tokenize(e),{df:r,fieldCount:i}=t._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(let e of n){this.termSearchers.push(new Jt(e,{location:t.location,threshold:t.threshold,distance:t.distance,includeMatches:t.includeMatches,findAllMatches:t.findAllMatches,minMatchCharLength:t.minMatchCharLength,isCaseSensitive:t.isCaseSensitive,ignoreDiacritics:t.ignoreDiacritics,ignoreLocation:!0}));let n=r.get(e)||0,a=Math.log(1+(i-n+.5)/(n+.5));this.idfWeights.push(a)}}searchIn(e){if(!this.termSearchers.length)return{isMatch:!1,score:1};let t=[],n=0,r=0,i=0;for(let a=0;a<this.termSearchers.length;a++){let o=this.termSearchers[a].searchIn(e),s=this.idfWeights[a];r+=s,o.isMatch&&(i++,n+=s*(1-o.score),o.indices&&t.push(...o.indices))}if(i===0)return{isMatch:!1,score:1};let a=r>0?1-n/r:0,o={isMatch:!0,score:Math.max(.001,a)};return this.options.includeMatches&&t.length&&(o.indices=Wt(t)),o}};Fn.version=`7.3.0`,Fn.createIndex=Rt,Fn.parseIndex=zt,Fn.config=$,Fn.match=function(e,t,n){return gn(e,{...$,...n}).searchIn(t)},Fn.parseQuery=Cn,hn(pn),hn(In),Fn.use=function(...e){e.forEach(e=>hn(e))};var Ln=[{text:`text-red-400`,bgCircle:`bg-red-400`,bgCard:`bg-red-500/[0.08]`,borderCard:`border-red-500/30`,bgLight:`bg-red-500/15`,bgHover:`hover:bg-red-500`,bgAlt:`bg-red-500/[0.04]`,name:`Red`},{text:`text-orange-400`,bgCircle:`bg-orange-400`,bgCard:`bg-orange-500/[0.08]`,borderCard:`border-orange-500/30`,bgLight:`bg-orange-500/15`,bgHover:`hover:bg-orange-500`,bgAlt:`bg-orange-500/[0.04]`,name:`Orange`},{text:`text-yellow-400`,bgCircle:`bg-yellow-400`,bgCard:`bg-yellow-500/[0.08]`,borderCard:`border-yellow-500/30`,bgLight:`bg-yellow-500/15`,bgHover:`hover:bg-yellow-500`,bgAlt:`bg-yellow-500/[0.04]`,name:`Yellow`},{text:`text-green-400`,bgCircle:`bg-green-400`,bgCard:`bg-green-500/[0.08]`,borderCard:`border-green-500/30`,bgLight:`bg-green-500/15`,bgHover:`hover:bg-green-500`,bgAlt:`bg-green-500/[0.04]`,name:`Green`},{text:`text-blue-400`,bgCircle:`bg-blue-400`,bgCard:`bg-blue-500/[0.08]`,borderCard:`border-blue-500/30`,bgLight:`bg-blue-500/15`,bgHover:`hover:bg-blue-500`,bgAlt:`bg-blue-500/[0.04]`,name:`Blue`},{text:`text-accent`,bgCircle:`bg-accent`,bgCard:`bg-accent/[0.08]`,borderCard:`border-accent/30`,bgLight:`bg-accent/15`,bgHover:`hover:bg-accent`,bgAlt:`bg-accent/[0.04]`,name:`Purple`},{text:`text-pink-400`,bgCircle:`bg-pink-400`,bgCard:`bg-pink-500/[0.08]`,borderCard:`border-pink-500/30`,bgLight:`bg-pink-500/15`,bgHover:`hover:bg-pink-500`,bgAlt:`bg-pink-500/[0.04]`,name:`Pink`},{text:`text-foreground/60`,bgCircle:`bg-foreground/30`,bgCard:`bg-foreground/[0.04]`,borderCard:`border-[var(--panel-border)]/50`,bgLight:`bg-foreground/15`,bgHover:`hover:bg-foreground/30`,bgAlt:`bg-foreground/[0.02]`,name:`Default`}];function Rn({title:e=`Table View`,subtitle:n=`/templates/table`,backUrl:a=`/templates`,tableCollection:o=`pub_table_data`,config:l,customContent:u}){let{user:d}=A(),f=!!l,p=l?.isInternal||l?.isShared;l?.isPrivate&&l?.isAdmin;let m=l?.isAdmin||p,h=f?m:!0,g=l?.showButton!==!1,_=l?.buttonText||`+`,v=l?.buttonStyle||`secondary`,y=l?.showExportButton!==!1,[b,x]=(0,r.useState)([]),[S,C]=(0,r.useState)(`demo`),[w,T]=(0,r.useState)(!1),[E,D]=(0,r.useState)(!1),[O,k]=(0,r.useState)(``),[j,M]=(0,r.useState)(!1),[N,P]=(0,r.useState)(null),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)(``),[ee,z]=(0,r.useState)(``),[B,V]=(0,r.useState)(null),[te,H]=(0,r.useState)(null),[U,W]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=o.startsWith(`user_`);if(e&&!d)return;try{let e=localStorage.getItem(`fbos_tables_${o}`);e&&x(JSON.parse(e))}catch{}let n=(0,i.onSnapshot)(e&&d?(0,i.query)((0,i.collection)(t.Pt,o),(0,i.where)(`uid`,`==`,d.uid)):(0,i.collection)(t.Pt,o),e=>{let n=[];if(e.forEach(e=>{n.push({id:e.id,...e.data()})}),n.length===0){let e={name:`Unnamed Table`,columns:[`Column 1`,`Column 2`,`Column 3`,`Column 4`],...d?{uid:d.uid}:{},rows:[{id:`1`,"Column 1":``,"Column 2":``,"Column 3":``,"Column 4":``},{id:`2`,"Column 1":``,"Column 2":``,"Column 3":``,"Column 4":``}]};(0,i.setDoc)((0,i.doc)(t.Pt,o,`demo`),e)}else{let e=n.sort((e,t)=>(e.name||``).localeCompare(t.name||``));x(e),localStorage.setItem(`fbos_tables_${o}`,JSON.stringify(e))}});return()=>n()},[o,d]);let G=b.find(e=>e.id===S)||b[0]||{columns:[],rows:[]},K=async e=>{G.id&&(d&&o.startsWith(`user_`)&&(e.uid=d.uid),await(0,i.setDoc)((0,i.doc)(t.Pt,o,G.id),e,{merge:!0}))},q=()=>{if(!G.rows||G.rows.length===0)return;let e=G.columns.join(`,`),t=G.rows.map(e=>G.columns.map(t=>`"${e[t]||``}"`).join(`,`)).join(`
30
- `),n=new Blob([`${e}\n${t}`],{type:`text/csv`}),r=window.URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`export_${G.name||`table`}.csv`,i.click(),window.URL.revokeObjectURL(r)},J=(e,t,n)=>{K({...G,rows:G.rows.map(r=>r.id===e?{...r,[t]:n}:r)})},Y=()=>{let e={id:Date.now().toString()};G.columns.forEach(t=>e[t]=``),K({...G,rows:[...G.rows||[],e]})},re=e=>{K({...G,rows:G.rows.filter(t=>t.id!==e)})},ie=()=>{let e=`Column ${(G.columns?.length||0)+1}`;G.columns?.includes(e)||(K({...G,columns:[...G.columns||[],e]}),setTimeout(()=>{let e=document.getElementById(`table-scroll-container`);e&&e.scrollTo({left:e.scrollWidth,behavior:`smooth`})},100))},ae=e=>{let t=(G.columns||[]).filter(t=>t!==e),n=(G.rows||[]).map(t=>{let n={...t};return delete n[e],n}),r={...G.colColors||{}};delete r[e],K({...G,columns:t,rows:n,colColors:r})},oe=async e=>{e.trim()&&G.id&&e!==G.name&&await(0,i.setDoc)((0,i.doc)(t.Pt,o,G.id),{name:e},{merge:!0})},se=async()=>{M(!0),T(!1);let e=`tbl_${Date.now()}`;await(0,i.setDoc)((0,i.doc)(t.Pt,o,e),{name:`Unnamed Table`,columns:[`Column 1`,`Column 2`,`Column 3`],...d?{uid:d.uid}:{},rows:[]}),setTimeout(()=>{C(e),M(!1)},600)},X=e=>{let t=ee.trim();if(t&&t!==e&&!G.columns?.includes(t)){let n=G.columns.map(n=>n===e?t:n),r=(G.rows||[]).map(n=>{let r={...n};return r[t]=r[e]||``,delete r[e],r}),i={...G.colColors||{}};i[e]&&(i[t]=i[e],delete i[e]),K({...G,columns:n,rows:r,colColors:i})}I(null)},ce=G.rows||[];return L.trim()!==``&&(ce=new Fn(ce.map(e=>({...e,_creatorMatch:`Guest`})),{keys:(G.columns||[]).concat([`_creatorMatch`]),threshold:.4,ignoreLocation:!0}).search(L).map(e=>{let{_creatorMatch:t,...n}=e.item;return 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)(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}),n&&(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`}),n]})]}),f&&(0,s.jsx)(`div`,{className:`mb-6`,children:(0,s.jsx)(ne,{})}),(0,s.jsxs)(`div`,{className:`flex justify-between items-center mb-6 border-b border-[var(--panel-border)] pb-6 relative z-20`,children:[!f&&a&&(0,s.jsxs)(c.Link,{to:a,className:`px-4 md:px-5 py-2.5 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold hover:bg-foreground/5 transition-all flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4`}),` `,(0,s.jsx)(`span`,{className:`hidden sm:inline`,children:`Go Back`})]}),f&&(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:l?.tabTitle||l?.tabName||e}),(0,s.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[b.length,` `,b.length===1?`table`:`tables`]})]}),(0,s.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[y&&(0,s.jsx)(t.r,{variant:`secondary`,onClick:q,className:`px-3 py-2.5 font-bold rounded-xl shadow-sm border border-[var(--panel-border)] flex items-center gap-2`,children:(0,s.jsx)(t.rt,{className:`w-4 h-4`})}),g&&(0,s.jsx)(t.r,{variant:v===`primary`?void 0:`secondary`,onClick:Y,className:`px-3 py-2.5 font-bold rounded-xl border border-[var(--panel-border)] shadow-sm flex items-center gap-2`,children:_===`+`?(0,s.jsx)(t.k,{className:`w-4 h-4`}):_})]})]}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative z-10 block`,children:[(0,s.jsx)(`div`,{className:`absolute top-0 right-0 w-[400px] h-[400px] bg-accent/5 blur-[100px] rounded-full pointer-events-none -z-10`}),(0,s.jsxs)(`div`,{className:`p-4 md:px-6 border-b border-[var(--panel-border)]/50 flex flex-col sm:flex-row items-start sm:items-center justify-between bg-foreground/[0.01] gap-4`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col w-full sm:w-auto relative`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 relative`,children:[(0,s.jsxs)(`div`,{className:`relative flex items-center`,children:[E?(0,s.jsx)(`div`,{contentEditable:!0,suppressContentEditableWarning:!0,onBlur:e=>{D(!1),oe(e.currentTarget.textContent||``)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},className:`bg-transparent border-b-2 border-accent outline-none text-[16px] font-bold text-foreground inline-block min-w-[20px] whitespace-nowrap px-1 py-0.5`,children:G.name||`Unnamed Table`}):(0,s.jsx)(`h3`,{className:`font-bold text-[16px] text-foreground/90 cursor-pointer hover:text-accent transition-colors truncate max-w-[200px]`,onClick:()=>D(!0),title:`Click to rename table`,children:G.name||`Unnamed Table`}),(0,s.jsx)(t.s,{children:w&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>T(!1)}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:`absolute top-[120%] left-0 w-[220px] bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] rounded-2xl shadow-2xl z-50 py-2 flex flex-col`,children:[(0,s.jsx)(`div`,{className:`px-4 py-2 text-[10px] font-bold uppercase tracking-wider text-foreground/40 border-b border-[var(--panel-border)] mb-1`,children:`Your Tables`}),(0,s.jsx)(`div`,{className:`max-h-[250px] overflow-y-auto styled-scrollbars z-50 relative`,children:b.map(e=>(0,s.jsx)(`button`,{onClick:()=>{C(e.id),T(!1)},className:`w-full px-4 py-2 text-[13px] font-bold text-left hover:bg-foreground/[0.03] transition-colors truncate ${S===e.id?`text-accent bg-accent/5`:`text-foreground/70`}`,children:e.name||`Unnamed Table`},e.id))}),(0,s.jsx)(`div`,{className:`w-full h-[1px] bg-[var(--panel-border)]/50 my-1`}),(0,s.jsxs)(`button`,{onClick:se,className:`w-full px-4 py-2.5 text-[13px] font-bold text-left text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors flex items-center gap-2`,children:[(0,s.jsx)(t.k,{className:`w-4 h-4`}),` Create New Table`]})]})]})})]}),(0,s.jsx)(`button`,{onClick:()=>T(!w),className:`p-1 px-1.5 rounded-lg hover:bg-foreground/5 transition-colors text-foreground/40 hover:text-foreground shrink-0 border border-transparent hover:border-[var(--panel-border)]`,children:(0,s.jsx)(t.gt,{className:`w-4 h-4 transition-transform ${w?`rotate-180 text-accent`:``}`})})]}),(0,s.jsxs)(`span`,{className:`opacity-40 text-[11px] font-bold mt-1 uppercase tracking-wider`,children:[(G.rows||[]).length,` Records`]})]}),(0,s.jsxs)(`div`,{className:`relative w-full sm:max-w-[300px]`,children:[(0,s.jsx)(t.E,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-foreground/40`}),(0,s.jsx)(`input`,{type:`text`,placeholder:`Search active records...`,value:L,onChange:e=>R(e.target.value),className:`w-full bg-background border border-[var(--panel-border)] rounded-xl py-2.5 px-9 text-[13px] font-medium text-foreground focus:outline-none focus:border-accent transition-colors shadow-inner`})]})]}),(0,s.jsx)(`div`,{id:`table-scroll-container`,className:`overflow-x-auto w-full block min-h-[300px] relative styled-scrollbars`,children:u?(0,s.jsx)(`div`,{className:`fbos-content-slot p-4 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:(0,s.jsx)(u,{config:l,actions:{tables:b,activeTable:G,collection:o,user:d,saveTable:async(e,n)=>{x(t=>t.find(t=>t.id===e)?t.map(t=>t.id===e?{...t,...n}:t):[...t,{id:e,...n}]),await(0,i.setDoc)((0,i.doc)(t.Pt,o,e),n,{merge:!0})},deleteTable:async e=>{x(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Pt,o,e))},updateCell:(e,t,n)=>J(e,t,n),addRow:()=>Y(),addColumn:()=>ie()}})}):(0,s.jsx)(t.s,{mode:`wait`,children:j?(0,s.jsxs)(t.o.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 flex flex-col items-center justify-center bg-background/40 backdrop-blur-[2px] z-50`,children:[(0,s.jsx)(`div`,{className:`w-8 h-8 rounded-full border-2 border-accent border-r-transparent animate-spin mb-4`}),(0,s.jsx)(`p`,{className:`text-[11px] font-bold text-foreground/50 uppercase tracking-widest`,children:`Generating Table`})]},`loader`):(0,s.jsxs)(t.o.table,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full text-left border-collapse table-auto relative min-w-[800px]`,children:[(0,s.jsx)(`thead`,{children:(0,s.jsxs)(`tr`,{className:`border-b border-[var(--panel-border)] transition-colors ${G.headerColor?Ln.find(e=>e.text===G.headerColor)?.bgAlt:`bg-foreground/[0.02]`}`,children:[(0,s.jsx)(`th`,{className:`py-4 px-6 text-[12px] font-bold uppercase tracking-wider whitespace-nowrap text-foreground/50 w-32 border-r border-[var(--panel-border)]/20 ${h?``:`hidden`}`,children:`Creator`}),(G.columns||[]).map((e,n)=>{let r=(G.colColors||{})[e],i=(G.colorTimestamps||{})[`col_${e}`]||0;G.headerColor;let a=(G.colorTimestamps||{}).header||0,o=`bg-transparent`,c=`text-foreground/50`;if(r&&r!==`none`&&i>=a){let e=Ln.find(e=>e.text===r);e&&(o=e.bgCard,c=e.text)}return(0,s.jsx)(`th`,{className:`py-3 px-6 text-[12px] font-bold uppercase tracking-wider relative group h-[53px] min-w-[120px] ${c} ${o} border-r border-[var(--panel-border)]/20 last:border-r-0 select-none align-middle`,children:(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-2 w-full h-full`,children:[F===e?(0,s.jsx)(`div`,{className:`flex-1 min-w-[50px]`,children:(0,s.jsx)(`span`,{contentEditable:!0,suppressContentEditableWarning:!0,onBlur:t=>{I(null),z(t.currentTarget.textContent||``),(t.currentTarget.textContent||``).trim()!==``&&X(e)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},className:`bg-transparent outline-none border-b border-accent/40 font-bold text-[12px] uppercase tracking-wider p-0 m-0 ${c} block w-full whitespace-nowrap overflow-hidden cursor-text`,ref:e=>{e&&requestAnimationFrame(()=>{e.focus()})},children:ee})}):(0,s.jsx)(`div`,{className:`flex items-center gap-2 flex-1 overflow-hidden`,onClick:()=>{I(e),z(e)},children:(0,s.jsx)(`span`,{className:`truncate cursor-text`,children:e})}),(0,s.jsxs)(`div`,{className:`relative shrink-0 flex items-center h-full gap-0.5`,children:[(0,s.jsx)(`button`,{onClick:()=>H(te===e?null:e),className:`p-1.5 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity hover:bg-foreground/10 ${r&&r!==`none`?`!opacity-100`:``} text-current`,children:(0,s.jsx)(t.j,{className:`w-4 h-4`})}),(G.columns||[]).length>1&&(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ae(e)},className:`p-1.5 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500/10 text-foreground/30 hover:text-red-500`,title:`Delete column`,children:(0,s.jsx)(t.v,{className:`w-3.5 h-3.5`})}),te===e&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>H(null)}),(0,s.jsxs)(`div`,{className:`absolute top-8 right-0 flex gap-1.5 bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-50 items-center`,children:[(0,s.jsx)(`button`,{onClick:t=>{t.preventDefault(),t.stopPropagation();let n={...G.colColors||{},[e]:`none`},r={...G.colorTimestamps||{},[`col_${e}`]:Date.now()};K({...G,colColors:n,colorTimestamps:r}),H(null)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Remove Color`,children:(0,s.jsx)(t.d,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Ln.map(t=>(0,s.jsx)(`button`,{onClick:n=>{n.preventDefault(),n.stopPropagation();let r={...G.colColors||{},[e]:t.text},i={...G.colorTimestamps||{},[`col_${e}`]:Date.now()};K({...G,colColors:r,colorTimestamps:i}),H(null)},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50 shrink-0`},t.name))]})]})]})]})},`col_${n}_${e}`)}),(0,s.jsx)(`th`,{className:`py-4 px-4 w-14 border-l border-[var(--panel-border)]/30 relative`,children:(0,s.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 relative z-20`,children:[(0,s.jsx)(`button`,{onClick:()=>W(!U),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${G.headerColor?Ln.find(e=>e.text===G.headerColor)?.text:`text-foreground/30`}`,children:(0,s.jsx)(t.j,{className:`w-4 h-4`})}),U&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>W(!1)}),(0,s.jsxs)(`div`,{className:`absolute top-6 right-8 flex gap-1.5 bg-background/90 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-50 items-center`,children:[(0,s.jsx)(`button`,{onClick:()=>{K({...G,headerColor:``}),W(!1)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Remove Header Color`,children:(0,s.jsx)(t.d,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Ln.map(e=>(0,s.jsx)(`button`,{onClick:()=>{let t={...G.colorTimestamps||{},header:Date.now()};K({...G,headerColor:e.text,colorTimestamps:t}),W(!1)},className:`w-4 h-4 rounded-full ${e.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50`},e.name))]})]}),(0,s.jsx)(`button`,{onClick:ie,className:`p-1.5 rounded-lg text-foreground/40 hover:text-accent hover:bg-accent/10 transition-colors flex items-center justify-center`,children:(0,s.jsx)(t.k,{className:`w-4 h-4`})})]})})]})}),(0,s.jsxs)(`tbody`,{children:[ce.map((e,n)=>{let r=n%2==1,i=(G.rowColors||{})[e.id],a=i?r?Ln.find(e=>e.text===i)?.bgAlt:Ln.find(e=>e.text===i)?.bgCard:r?`bg-foreground/[0.02]`:`bg-transparent`;return(0,s.jsxs)(`tr`,{className:`border-b border-[var(--panel-border)]/30 hover:bg-foreground/[0.04] transition-colors group`,children:[(0,s.jsx)(`td`,{className:`py-4 px-6 whitespace-nowrap h-[53px] border-r border-[var(--panel-border)]/20 ${a} ${h?``:`hidden`}`,children:(0,s.jsx)(`div`,{className:`flex items-center gap-2`,children:f&&d?(0,s.jsxs)(s.Fragment,{children:[d.photoURL?(0,s.jsx)(`img`,{src:d.photoURL,className:`w-5 h-5 rounded-full shrink-0 object-cover`}):(0,s.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/20 text-accent flex items-center justify-center text-[10px] font-bold shrink-0`,children:(d.displayName||d.email||`U`)[0].toUpperCase()}),(0,s.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/80 tracking-tight shrink-0`,children:d.displayName||d.email?.split(`@`)[0]||`User`})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/20 text-accent flex items-center justify-center text-[10px] font-bold shrink-0 shadow-inner group-hover:scale-110 transition-transform`,children:`G`}),(0,s.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/80 tracking-tight shrink-0`,children:`Guest`})]})})}),(G.columns||[]).map(t=>{let i=N?.id===e.id&&N?.field===t,a=(G.colColors||{})[t],o=(G.colorTimestamps||{})[`col_${t}`]||0,c=(G.rowColors||{})[e.id],l=(G.colorTimestamps||{})[`row_${e.id}`]||0,u=``;u=l>o?c===`none`?``:c:o>l?a===`none`?``:a:c===`none`?``:c||a||``,u===`none`&&(u=``);let d=u?Ln.find(e=>e.text===u):null,f=d?r?d.bgAlt:d.bgCard:r?`bg-foreground/[0.02]`:`bg-transparent`,p=d?d.text:`text-foreground/80`;return(0,s.jsxs)(`td`,{className:`py-4 px-6 whitespace-pre-wrap min-w-[120px] text-[14px] font-medium relative ${f} align-top border-r border-[var(--panel-border)]/10 last:border-r-0`,onClick:()=>!i&&P({id:e.id,field:t}),children:[i?(0,s.jsx)(`textarea`,{autoFocus:!0,value:e[t]||``,onChange:n=>J(e.id,t,n.target.value),onBlur:()=>P(null),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&P(null)},className:`absolute inset-0 bg-transparent !border-0 !outline-none focus:!outline-none focus:!ring-0 !ring-0 !shadow-none focus:!shadow-none p-4 px-6 text-[14px] font-medium w-full h-full caret-accent ${p} z-20 resize-none styled-scrollbars`}):null,(0,s.jsx)(`span`,{className:`block w-full min-h-[20px] break-words transition-all ${i?`opacity-0`:`opacity-100`} ${p} ${t===`Status`&&e[t]===`Active`&&!u?`text-green-500`:``}`,children:e[t]||(0,s.jsx)(`span`,{className:`opacity-30 italic font-normal`,children:`empty`})})]},`cell_${e.id||n}_${t}`)}),(0,s.jsx)(`td`,{className:`py-4 px-4 whitespace-nowrap text-right h-[53px] ${a} relative z-10`,children:(0,s.jsxs)(`div`,{className:`flex items-center justify-end gap-1 opacity-20 group-hover:opacity-100 transition-opacity relative`,children:[(0,s.jsx)(`button`,{onClick:()=>V(B===e.id?null:e.id),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${i?Ln.find(e=>e.text===i)?.text:`text-foreground/40`}`,children:(0,s.jsx)(t.j,{className:`w-4 h-4`})}),B===e.id&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>V(null)}),(0,s.jsxs)(`div`,{className:`absolute top-6 right-8 flex gap-1.5 bg-background/90 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-50 items-center`,children:[(0,s.jsx)(`button`,{onClick:t=>{t.preventDefault(),t.stopPropagation();let n={...G.rowColors||{},[e.id]:`none`},r={...G.colorTimestamps||{},[`row_${e.id}`]:Date.now()};K({...G,rowColors:n,colorTimestamps:r}),V(null)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Remove Row Color`,children:(0,s.jsx)(t.d,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Ln.map(t=>(0,s.jsx)(`button`,{onClick:()=>{let n={...G.colorTimestamps||{},[`row_${e.id}`]:Date.now()};K({...G,rowColors:{...G.rowColors||{},[e.id]:t.text},colorTimestamps:n}),V(null)},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50`},t.name))]})]}),(0,s.jsx)(`button`,{onClick:()=>re(e.id),className:`p-2 ml-auto rounded-lg text-foreground/20 hover:text-red-500 hover:bg-red-500/10 transition-colors flex items-center justify-center`,children:(0,s.jsx)(t.v,{className:`w-4 h-4`})})]})})]},e.id||`row_${n}`)}),ce.length===0&&(0,s.jsx)(`tr`,{children:(0,s.jsxs)(`td`,{colSpan:(G.columns||[]).length+2,className:`py-12 text-center text-foreground/40 text-[14px] font-medium border border-[var(--panel-border)] m-4 rounded-xl border-dashed`,children:[`No records found in `,G.name||`this table`,`.`]})}),(0,s.jsx)(`tr`,{children:(0,s.jsx)(`td`,{colSpan:(G.columns||[]).length+2,className:`py-2 px-4 border-none bg-foreground/[0.01]`,children:(0,s.jsx)(`div`,{className:`flex items-center gap-4`,children:(0,s.jsx)(`button`,{onClick:Y,className:`p-1.5 rounded-lg text-foreground/40 hover:text-accent hover:bg-accent/10 transition-colors flex items-center justify-center ml-2 border border-transparent hover:border-accent/20`,children:(0,s.jsx)(t.k,{className:`w-4 h-4`})})})})})]})]},`table`)})})]})]})}var zn=[{text:`text-red-400`,bgCircle:`bg-red-400`,bgCard:`bg-red-500/[0.08]`,borderCard:`border-red-500/30`,bgLight:`bg-red-500/15`,bgHover:`hover:bg-red-500`,bgAlt:`bg-red-500/[0.04]`,name:`Red`},{text:`text-orange-400`,bgCircle:`bg-orange-400`,bgCard:`bg-orange-500/[0.08]`,borderCard:`border-orange-500/30`,bgLight:`bg-orange-500/15`,bgHover:`hover:bg-orange-500`,bgAlt:`bg-orange-500/[0.04]`,name:`Orange`},{text:`text-yellow-400`,bgCircle:`bg-yellow-400`,bgCard:`bg-yellow-500/[0.08]`,borderCard:`border-yellow-500/30`,bgLight:`bg-yellow-500/15`,bgHover:`hover:bg-yellow-500`,bgAlt:`bg-yellow-500/[0.04]`,name:`Yellow`},{text:`text-green-400`,bgCircle:`bg-green-400`,bgCard:`bg-green-500/[0.08]`,borderCard:`border-green-500/30`,bgLight:`bg-green-500/15`,bgHover:`hover:bg-green-500`,bgAlt:`bg-green-500/[0.04]`,name:`Green`},{text:`text-blue-400`,bgCircle:`bg-blue-400`,bgCard:`bg-blue-500/[0.08]`,borderCard:`border-blue-500/30`,bgLight:`bg-blue-500/15`,bgHover:`hover:bg-blue-500`,bgAlt:`bg-blue-500/[0.04]`,name:`Blue`},{text:`text-accent`,bgCircle:`bg-accent`,bgCard:`bg-accent/[0.08]`,borderCard:`border-accent/30`,bgLight:`bg-accent/15`,bgHover:`hover:bg-accent`,bgAlt:`bg-accent/[0.04]`,name:`Purple`},{text:`text-pink-400`,bgCircle:`bg-pink-400`,bgCard:`bg-pink-500/[0.08]`,borderCard:`border-pink-500/30`,bgLight:`bg-pink-500/15`,bgHover:`hover:bg-pink-500`,bgAlt:`bg-pink-500/[0.04]`,name:`Pink`},{text:`text-foreground/60`,bgCircle:`bg-foreground/30`,bgCard:`bg-foreground/[0.04]`,borderCard:`border-[var(--panel-border)]/50`,bgLight:`bg-foreground/15`,bgHover:`hover:bg-foreground/30`,bgAlt:`bg-foreground/[0.02]`,name:`Default`}],Bn={dateStr:``,title:``,description:``,time:`12:00`,duration:`60`,color:``,guestEmail:``,customFields:{}};function Vn({title:e=`Calendar View`,subtitle:n=`/templates/calendar`,backUrl:o=`/templates`,eventsCollection:l=`pub_events`,defaultTimeFormat:u=`12h`,config:d,customContent:f}){let p=!!(d?.isPrivate||d?.isAdmin||d?.isInternal||d?.isShared);d?.isAdmin,d?.isInternal||d?.isShared,d?.isPrivate;let m=d?.showButton!==!1,h=d?.buttonText||`+`,g=d?.buttonStyle||`primary`,_=d?.showViewsButton!==!1,v=d?.viewsButtonStyle||`secondary`,y=d?.defaultView||`calendar`,b=d?.customFields||[],x=l.startsWith(`user_`)?`user`:l.startsWith(`mem_`)?`internal`:l.startsWith(`admin_`)?`admin_only`:`public`,[S,C]=(0,r.useState)(()=>{try{let e=localStorage.getItem(`cal_view_${l}`);if(e===`list`||e===`month`)return e}catch{}return y===`board`?`list`:`month`}),[w,T]=(0,r.useState)([]),[E,D]=(0,r.useState)(!1),[O,k]=(0,r.useState)(null),[A,j]=(0,r.useState)(!1),[M,N]=(0,r.useState)(!1),[P,F]=(0,r.useState)(null),[I,L]=(0,r.useState)(Bn),[R,ee]=(0,r.useState)(new Date),[z,B]=(0,r.useState)(null),[V,te]=(0,r.useState)(null),[H,U]=(0,r.useState)(!1),W=`cal_24h_${l}`,[G,K]=(0,r.useState)(()=>{try{let e=localStorage.getItem(W);if(e!==null)return e===`true`}catch{}return u===`24h`}),q=()=>{let e=!G;K(e);try{localStorage.setItem(W,String(e))}catch{}};(0,r.useEffect)(()=>{try{localStorage.setItem(`cal_view_${l}`,S)}catch{}},[S,l,x]);let J=()=>{let e=S===`month`?`list`:`month`;C(e);try{localStorage.setItem(`cal_view_${l}`,e)}catch{}},Y=()=>{try{return sessionStorage.getItem(`cal_guest_email`)||``}catch{return``}},ie=e=>{try{sessionStorage.setItem(`cal_guest_email`,e)}catch{}};(0,r.useEffect)(()=>(0,a.onAuthStateChanged)(t.Nt,async e=>{if(B(e),e&&x===`admin_only`)try{let n=await(0,i.getDoc)((0,i.doc)(t.Pt,`user_profiles`,e.uid));n.exists()&&te(n.data())}catch{}U(!0)}),[x]),(0,r.useEffect)(()=>{if(!H)return;if(x!==`public`&&!z){T([]);return}try{let e=localStorage.getItem(`fbos_cal_${l}`);e&&T(JSON.parse(e))}catch{}let e=(0,i.onSnapshot)(x===`user`&&z?(0,i.query)((0,i.collection)(t.Pt,l),(0,i.where)(`uid`,`==`,z.uid)):(0,i.collection)(t.Pt,l),e=>{let t=[];e.forEach(e=>t.push({id:e.id,...e.data()})),T(t),localStorage.setItem(`fbos_cal_${l}`,JSON.stringify(t))},e=>console.error(`Calendar events:`,e));return()=>e()},[l,x,z?.uid,H]);let ae=e=>!!z&&z.uid===e.uid,oe=e=>x===`public`?!1:x===`user`?!!z:ae(e),se=e=>{if(!e)return``;if(G)return e;let[t,n]=e.split(`:`),r=parseInt(t,10),i=r>=12?`PM`:`AM`;return r=r%12||12,`${r}:${n} ${i}`},X=e=>{if(!e)return`60m`;let t=parseInt(e,10);return isNaN(t)?e:t>=60?t%60==0?`${t/60}h`:`${Math.floor(t/60)}h ${t%60}m`:`${t}m`},ce=e=>{let[t,n]=(e||`12:00`).split(`:`),r=parseInt(t,10)||0,i=parseInt(n,10)||0,a=r>=12?`PM`:`AM`;return r=r%12||12,{h:r,m:i,ampm:a}},Z=(e,t,n)=>{let r=e%12;return n===`PM`&&(r+=12),`${r.toString().padStart(2,`0`)}:${t.toString().padStart(2,`0`)}`},Q=e=>{let t=e.getTimezoneOffset()*6e4;return new Date(e.getTime()-t).toISOString().split(`T`)[0]},le=()=>Q(new Date),ue=new Date(R.getFullYear(),R.getMonth(),1),de=new Date(R.getFullYear(),R.getMonth()+1,0),fe=ue.getDay(),pe=de.getDate(),me=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],he=Array.from({length:42},(e,t)=>{let n=t-fe+1,r=new Date(R.getFullYear(),R.getMonth(),n);return{day:r.getDate(),dateStr:Q(r),isCurrentMonth:n>0&&n<=pe}}),ge=()=>ee(S===`month`?new Date(R.getFullYear(),R.getMonth()-1,1):new Date(R.getFullYear(),R.getMonth(),R.getDate()-1)),_e=()=>ee(S===`month`?new Date(R.getFullYear(),R.getMonth()+1,1):new Date(R.getFullYear(),R.getMonth(),R.getDate()+1)),ve=e=>{if(x!==`public`&&!z)return;let t=new Date;t.setDate(t.getDate()+1);let n=new Date().getHours().toString().padStart(2,`0`);L({...Bn,dateStr:e||Q(t),time:`${n}:00`,guestEmail:x===`public`?Y():``,customFields:{}}),D(!0)},ye=e=>{let t=e.time;if(t){let[e,n]=t.split(`:`);e&&n&&(t=`${e.padStart(2,`0`)}:${n}`)}L({id:e.id,uid:e.uid,dateStr:e.dateStr,title:e.title,description:e.description||``,time:t||`12:00`,duration:e.duration||`60`,color:e.color||``,guestEmail:e.creatorEmail||``,customFields:e.customFields||{}}),D(!0)},be=async e=>{if(e.preventDefault(),I.title.trim()){j(!0);try{let e={dateStr:I.dateStr,title:I.title.trim(),description:I.description.trim(),time:I.time,duration:I.duration||`60`};if(I.color&&(e.color=I.color),b.length>0&&(e.customFields=I.customFields),!I.id)if(x===`public`){let t=I.guestEmail.trim();e.creatorEmail=t,ie(t)}else x===`user`||x===`internal`?(e.uid=z?.uid,e.creatorEmail=z?.email||``,e.creatorName=z?.displayName||``,e.creatorAvatar=z?.photoURL||``):x===`admin_only`&&(e.uid=z?.uid,e.creatorEmail=V?.email||z?.email||``,e.creatorName=V?.displayName||V?.name||``,e.creatorAvatar=V?.avatar||V?.avatarUrl||z?.photoURL||``);I.id?(await(0,i.setDoc)((0,i.doc)(t.Pt,l,I.id),e,{merge:!0}),O?.id===I.id&&k({...O,...e})):await(0,i.setDoc)((0,i.doc)(t.Pt,l,`ev_${Date.now()}`),e,{merge:!0}),D(!1)}catch(e){console.error(e)}j(!1)}},xe=async()=>{if(P){N(!0);try{await(0,i.deleteDoc)((0,i.doc)(t.Pt,l,P.id)),O?.id===P.id&&k(null),F(null),D(!1)}catch{}N(!1)}},Se=e=>{if(x===`user`||!e.creatorEmail&&!e.creatorName)return null;let t=(e.creatorName||e.creatorEmail||`?`).charAt(0).toUpperCase(),n=zn.find(t=>t.text===e.color);return(0,s.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 p-3 rounded-xl bg-foreground/[0.03] border border-[var(--panel-border)]/50`,children:[e.creatorAvatar?(0,s.jsx)(`img`,{src:e.creatorAvatar,alt:``,className:`w-8 h-8 rounded-full object-cover shrink-0`}):(0,s.jsx)(`div`,{className:`w-8 h-8 rounded-full ${n?.bgCircle||`bg-accent`} flex items-center justify-center text-[13px] font-extrabold text-white shrink-0`,children:t}),(0,s.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[e.creatorName&&(0,s.jsx)(`span`,{className:`text-[13px] font-bold text-foreground/90 truncate`,children:e.creatorName}),e.creatorEmail&&(0,s.jsx)(`span`,{className:`text-[12px] text-foreground/50 truncate`,children:e.creatorEmail})]})]})},Ce=e=>{if(x===`user`||x===`public`||!e.creatorName&&!e.creatorEmail)return null;let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||``,n=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,s.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[e.creatorAvatar?(0,s.jsx)(`img`,{src:e.creatorAvatar,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:n}),(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}),e.creatorEmail&&(0,s.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,e.creatorEmail]})]})]})};if(H&&x!==`public`&&!z)return(0,s.jsx)(`main`,{className:`flex-1 w-full flex items-center justify-center min-h-screen p-8`,children:(0,s.jsxs)(`div`,{className:`text-center glass-panel border border-[var(--panel-border)] rounded-3xl p-12 max-w-sm w-full`,children:[(0,s.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-accent/10 border border-accent/20 flex items-center justify-center mx-auto mb-4`,children:(0,s.jsx)(t.P,{className:`w-7 h-7 text-accent`})}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold mb-2`,children:`Sign in required`}),(0,s.jsx)(`p`,{className:`text-foreground/50 text-[14px] mb-6`,children:`You need to be signed in to access this calendar.`}),(0,s.jsx)(c.Link,{to:`/login`,className:`inline-flex items-center justify-center gap-2 px-6 py-2.5 rounded-xl btn-primary font-bold text-[14px] w-full`,children:`Sign In`})]})});if(!H&&x!==`public`)return(0,s.jsx)(`main`,{className:`flex-1 w-full flex items-center justify-center min-h-screen`,children:(0,s.jsx)(t.L,{className:`w-8 h-8 animate-spin text-accent`})});let we=(x===`public`||!!z)&&m,Te=()=>(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:d?.tabTitle||d?.tabName||e}),(0,s.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[w.length,` `,w.length===1?`event`:`events`,` · `,S===`month`?`Month`:`Board`,` View`]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:q,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer btn-secondary text-[12px] font-extrabold`,children:G?`24h`:`12h`}),_&&(0,s.jsx)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:J,title:S===`month`?`Switch to Board`:`Switch to Calendar`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${v===`primary`?`btn-primary`:`btn-secondary`}`,children:S===`month`?(0,s.jsx)(t.V,{className:`w-4 h-4`}):(0,s.jsx)(t.bt,{className:`w-4 h-4`})}),we&&(0,s.jsx)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>ve(),className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${h===`+`?`w-10`:`px-5`} ${g===`primary`?`btn-primary`:`btn-secondary`}`,children:h===`+`?(0,s.jsx)(t.k,{className:`w-4 h-4`}):(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:h})})]})]}),Ee=()=>(0,s.jsxs)(`div`,{className:`p-4 md:p-6 border-b border-[var(--panel-border)]/50 flex items-center justify-between bg-foreground/[0.01]`,children:[(0,s.jsx)(`h3`,{className:`text-xl font-extrabold tracking-tight ml-2`,children:S===`month`?R.toLocaleString(`default`,{month:`long`,year:`numeric`}):R.toLocaleString(`default`,{month:`long`,day:`numeric`,year:`numeric`})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,s.jsx)(`button`,{onClick:()=>ee(new Date),className:`px-4 py-2 text-[13px] font-bold border border-[var(--panel-border)] rounded-xl mr-2 hover:bg-foreground/5 transition-colors`,children:`Today`}),(0,s.jsx)(`button`,{onClick:ge,className:`p-2 rounded-xl text-foreground/50 hover:text-foreground hover:bg-foreground/5 transition-colors border border-transparent hover:border-[var(--panel-border)]`,children:(0,s.jsx)(t.ht,{className:`w-5 h-5`})}),(0,s.jsx)(`button`,{onClick:_e,className:`p-2 rounded-xl text-foreground/50 hover:text-foreground hover:bg-foreground/5 transition-colors border border-transparent hover:border-[var(--panel-border)]`,children:(0,s.jsx)(t.mt,{className:`w-5 h-5`})})]})]}),De=()=>(0,s.jsxs)(s.Fragment,{children:[Ee(),f?(0,s.jsx)(`div`,{className:`fbos-content-slot p-4 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:(0,s.jsx)(f,{config:d,actions:{events:w,loading:!H,collection:l,currentUser:z,saveEvent:async e=>{let n=e.id||`ev_${Date.now()}`;T(t=>t.find(e=>e.id===n)?t.map(t=>t.id===n?{...t,...e}:t):[...t,{id:n,...e}]),await(0,i.setDoc)((0,i.doc)(t.Pt,l,n),e,{merge:!0})},deleteEvent:async e=>{T(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Pt,l,e))},openAddModal:e=>ve(e),openEditModal:e=>ye(e),setViewingEvent:e=>k(e)}})}):S===`month`?(0,s.jsx)(`div`,{className:`overflow-x-auto w-full flex-1`,children:(0,s.jsxs)(`div`,{className:`min-w-[800px] h-full flex flex-col`,children:[(0,s.jsx)(`div`,{className:`grid grid-cols-7 border-b border-[var(--panel-border)]/50 bg-foreground/[0.02]`,children:me.map(e=>(0,s.jsx)(`div`,{className:`py-3 text-center text-[12px] font-bold uppercase tracking-wider text-foreground/40`,children:e},e))}),(0,s.jsx)(`div`,{className:`grid grid-cols-7 auto-rows-auto bg-[var(--panel-border)] gap-[1px] relative flex-1`,children:he.map((e,n)=>{let r=e.dateStr===le(),i=w.filter(t=>t.dateStr===e.dateStr);return(0,s.jsxs)(`div`,{onClick:()=>e.isCurrentMonth&&we&&ve(e.dateStr),className:`min-h-[140px] p-2 bg-[var(--panel-bg)] flex flex-col relative group
31
- ${e.isCurrentMonth?we?`hover:bg-foreground/[0.03] transition-colors cursor-cell`:``:`opacity-30 bg-background/50 pointer-events-none`}`,children:[(0,s.jsx)(`div`,{className:`flex justify-between items-start mb-2 shrink-0`,children:(0,s.jsx)(`span`,{className:`w-8 h-8 rounded-full flex items-center justify-center text-[14px] font-bold ${r?`bg-accent text-white shadow-lg shadow-accent/20`:`text-foreground/70 group-hover:text-foreground`}`,children:e.day})}),(0,s.jsx)(`div`,{className:`flex flex-col gap-1.5 flex-1 w-full relative z-10 pb-1`,children:i.map(e=>{let n=zn.find(t=>t.text===e.color),r=oe(e);return(0,s.jsxs)(`div`,{className:`px-2 py-1.5 rounded-lg border transition-colors shadow-sm cursor-pointer group/ev relative ${n?n.bgCard+` `+n.borderCard:`bg-accent/20 border-accent/30 hover:bg-accent/40`}`,onClick:t=>{t.stopPropagation(),k(e)},children:[(0,s.jsx)(`p`,{className:`text-[12px] font-bold truncate leading-tight ${r?`pr-5`:``} ${n?n.text:`text-foreground`}`,children:e.title}),(0,s.jsx)(`p`,{className:`text-[10px] text-foreground/70 mt-0.5`,children:se(e.time)}),r&&(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ye(e)},className:`absolute top-1 right-1 opacity-0 group-hover/ev:opacity-100 p-1 text-foreground/60 hover:bg-foreground/10 hover:text-foreground transition-all rounded`,children:(0,s.jsx)(t.A,{className:`w-3 h-3`})})]},e.id)})})]},n)})}),(0,s.jsx)(`style`,{children:`
29
+ Do not change anything else.`},{title:`Remove the pages that came with the app`,prompt:`Remove the Guide, Templates and Contact pages from my site, including their entries in the site menu.`}]}],tt=`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px] mb-3`,nt=`rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)]`;function rt({children:e}){return(0,s.jsxs)(`div`,{className:tt,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e]})}function it(){return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-4xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12`,children:[(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-10 text-center`,children:[(0,s.jsx)(`h1`,{className:`w-fit mx-auto inline-block text-4xl md:text-5xl lg:text-[4.2rem] leading-[1.1] font-extrabold tracking-tight mb-4 text-gradient`,children:`Guide`}),(0,s.jsx)(`p`,{className:`text-foreground/60 text-lg font-medium max-w-2xl mx-auto`,children:`Your website is built by describing it, and your dashboard pages are added on the Pages screen and filled by describing them. This page shows what a complete description contains, and gives you finished ones to paste.`})]}),(0,s.jsxs)(t.o.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`mb-12`,children:[(0,s.jsx)(`div`,{className:`relative w-full rounded-2xl overflow-hidden border border-[var(--panel-border)] glass-panel`,children:(0,s.jsx)(`div`,{className:`relative w-full aspect-video`,children:(0,s.jsx)(`iframe`,{className:`absolute inset-0 w-full h-full`,src:`https://www.youtube-nocookie.com/embed/${Je}?start=1`,title:`Watch the guide`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share`,allowFullScreen:!0,loading:`lazy`,referrerPolicy:`strict-origin-when-cross-origin`})})}),(0,s.jsx)(`p`,{className:`mt-3 text-center text-[12.5px] text-foreground/45 font-medium`,children:`Six minutes, from an empty project to a finished site.`})]}),(0,s.jsxs)(t.o.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.05},className:`mb-12`,children:[(0,s.jsx)(rt,{children:`A page anyone can visit: what a complete request contains`}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold tracking-tight text-foreground mb-2`,children:`Nine things, in this order`}),(0,s.jsx)(`p`,{className:`text-[13.5px] text-foreground/55 font-medium leading-relaxed mb-5 max-w-2xl`,children:`Before the assistant builds anything it needs every one of these. Say them all in one message and it builds the whole thing in one go. Leave one out and it stops to ask.`}),(0,s.jsx)(`div`,{className:`${nt} divide-y divide-[var(--panel-border)]`,children:Ye.map((e,t)=>(0,s.jsxs)(`div`,{className:`grid gap-1.5 sm:grid-cols-[11rem_1fr] sm:gap-6 px-5 py-4`,children:[(0,s.jsxs)(`div`,{className:`flex items-baseline gap-2.5 sm:block`,children:[(0,s.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/35 tabular-nums sm:block sm:mb-0.5`,children:String(t+1).padStart(2,`0`)}),(0,s.jsx)(`h3`,{className:`text-[13.5px] font-bold text-foreground tracking-tight`,children:e.term})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-1.5 min-w-0`,children:[(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed`,children:e.body}),(0,s.jsx)(`p`,{className:`text-[13px] text-accent font-semibold leading-relaxed`,children:e.example})]})]},e.term))})]}),(0,s.jsxs)(t.o.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.1},className:`mb-12`,children:[(0,s.jsx)(rt,{children:`Who it is for`}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold tracking-tight text-foreground mb-2`,children:`The four audiences`}),(0,s.jsx)(`p`,{className:`text-[13.5px] text-foreground/55 font-medium leading-relaxed mb-5 max-w-2xl`,children:`Every page is for exactly one of these. These are the words on your Pages screen. A page anyone can visit is asked for in the chat; the other three are added on the Pages screen.`}),(0,s.jsx)(`div`,{className:`${nt} divide-y divide-[var(--panel-border)]`,children:Xe.map(e=>(0,s.jsxs)(`div`,{className:`grid gap-1.5 sm:grid-cols-[11rem_1fr] sm:gap-6 px-5 py-4`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,s.jsx)(`h3`,{className:`text-[13.5px] font-bold text-foreground tracking-tight`,children:e.name}),(0,s.jsx)(`p`,{className:`text-[12px] text-accent font-semibold`,children:e.how})]}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed`,children:e.who})]},e.name))}),(0,s.jsx)(`p`,{className:`mt-3 text-[12.5px] text-foreground/50 font-medium leading-relaxed max-w-2xl`,children:`Registering only makes someone a signed-in user, not a team member. Never put your team’s information on a page for signed-in users: any stranger who registers could open it.`})]}),(0,s.jsxs)(t.o.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.12},className:`mb-12`,children:[(0,s.jsx)(rt,{children:`A page for your team, signed-in users or admins`}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold tracking-tight text-foreground mb-2`,children:`Three steps, and the assistant only fills it in`}),(0,s.jsx)(`p`,{className:`text-[13.5px] text-foreground/55 font-medium leading-relaxed mb-5 max-w-2xl`,children:`Never ask the chat to create a dashboard page. Asked to, it rewrites files it must not touch, opens the page to strangers and invents forms. You add the page; the assistant only writes what is on it.`}),(0,s.jsx)(`div`,{className:`${nt} divide-y divide-[var(--panel-border)]`,children:Ze.map((e,t)=>(0,s.jsxs)(`div`,{className:`grid gap-1.5 sm:grid-cols-[11rem_1fr] sm:gap-6 px-5 py-4`,children:[(0,s.jsxs)(`div`,{className:`flex items-baseline gap-2.5 sm:block`,children:[(0,s.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/35 tabular-nums sm:block sm:mb-0.5`,children:String(t+1).padStart(2,`0`)}),(0,s.jsx)(`h3`,{className:`text-[13.5px] font-bold text-foreground tracking-tight`,children:e.title})]}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed`,children:e.body})]},e.title))})]}),(0,s.jsxs)(t.o.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.15},className:`mb-12`,children:[(0,s.jsx)(rt,{children:`No assistant needed`}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold tracking-tight text-foreground mb-2`,children:`Things you change yourself`}),(0,s.jsx)(`p`,{className:`text-[13.5px] text-foreground/55 font-medium leading-relaxed mb-5 max-w-2xl`,children:`These are switches and boxes in your admin screens. Asking the assistant for them only gets you sent here.`}),(0,s.jsx)(`div`,{className:`${nt} divide-y divide-[var(--panel-border)]`,children:Qe.map(e=>(0,s.jsxs)(`div`,{className:`grid gap-1 sm:grid-cols-[11rem_1fr] sm:gap-6 px-5 py-4`,children:[(0,s.jsx)(c.Link,{to:e.path,className:`text-[13.5px] font-bold text-foreground tracking-tight hover:text-accent transition-colors w-fit`,children:e.screen}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed`,children:e.body})]},e.screen))}),(0,s.jsx)(`p`,{className:`mt-3 text-[12.5px] text-foreground/50 font-medium leading-relaxed max-w-2xl`,children:`The Guide, Templates, Contact and Setup pages come with the app and are visible on purpose. Hide any of them on the Pages screen with the switch next to its name.`})]}),(0,s.jsxs)(t.o.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.2},className:`mb-12`,children:[(0,s.jsx)(rt,{children:`Working with the assistant`}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold tracking-tight text-foreground mb-5`,children:`Five habits`}),(0,s.jsx)(`div`,{className:`${nt} divide-y divide-[var(--panel-border)]`,children:$e.map(e=>(0,s.jsxs)(`div`,{className:`flex flex-col gap-1 px-5 py-4`,children:[(0,s.jsx)(`h3`,{className:`text-[13.5px] font-bold text-foreground tracking-tight`,children:e.title}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed`,children:e.body})]},e.title))})]}),(0,s.jsxs)(t.o.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.25},className:`flex flex-col gap-4 mb-12`,children:[(0,s.jsxs)(`div`,{className:`mb-1`,children:[(0,s.jsx)(rt,{children:`Ready to paste`}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold tracking-tight text-foreground mb-2`,children:`Finished requests`}),(0,s.jsxs)(`p`,{className:`text-[13.5px] text-foreground/55 font-medium leading-relaxed max-w-2xl`,children:[`Each one answers every question the assistant would otherwise ask. Copy it, change the words to yours, and paste it as one message. Want to see the layouts first?`,` `,(0,s.jsx)(c.Link,{to:`/templates`,className:`text-accent font-bold hover:underline`,children:`Look through the templates`}),`.`]})]}),et.map(e=>(0,s.jsx)(le,{title:e.title,description:e.description,children:e.prompts.map(e=>(0,s.jsx)(ke,{title:e.title,prompt:e.prompt,compact:!0},e.title))},e.id))]})]})}function at(){let[e,n]=(0,r.useState)({favoriteService:``,satisfactionRating:``,detailedThoughts:``}),[a,o]=(0,r.useState)(`idle`);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`,children:[(0,s.jsx)(`div`,{className:`w-full max-w-5xl mx-auto mb-6`,children:(0,s.jsxs)(c.Link,{to:`/templates`,className:`inline-flex items-center gap-2 text-foreground/50 hover:text-accent transition-colors font-medium text-[14px]`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4`}),` Back to Templates`]})}),(0,s.jsx)(`div`,{className:`w-full max-w-5xl mx-auto mt-6`,children:(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`w-full max-w-[500px] p-6 sm:p-8 lg:p-10 rounded-3xl md:rounded-3xl glass-panel relative glow-hover shadow-[0_8px_32px_rgba(0,0,0,0.08)] z-10 mx-auto`,children:[(0,s.jsx)(`div`,{className:`absolute -inset-[1px] bg-gradient-to-br from-[var(--primary-glow)] to-transparent opacity-30 blur-[20px] rounded-3xl md:rounded-3xl -z-10`}),(0,s.jsx)(`div`,{className:`relative z-10 w-full`,children:a===`success`?(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex flex-col items-center justify-center py-8 text-center`,children:[(0,s.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-green-500/10 border border-green-500/20 flex items-center justify-center text-green-500 mb-4`,children:(0,s.jsx)(t.dt,{className:`w-8 h-8`})}),(0,s.jsx)(`h4`,{className:`text-lg font-bold text-foreground mb-2`,children:`Simulation Complete!`}),(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/60 leading-relaxed`,children:`Your test data was sent successfully. Log in as an admin and open your Inbox to see it.`})]}):a===`loading`?(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`flex flex-col items-center justify-center py-16 text-center`,children:[(0,s.jsx)(`div`,{className:`w-10 h-10 border-4 border-accent border-r-transparent rounded-full animate-spin mb-4`}),(0,s.jsx)(`h4`,{className:`text-lg font-bold text-foreground tracking-tight`,children:`Processing`}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/50 mt-1`,children:`Simulating submission...`})]}):(0,s.jsxs)(t.o.div,{initial:{opacity:0},animate:{opacity:1},children:[(0,s.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,s.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight break-words`,children:`Inline Form Template`}),(0,s.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide leading-relaxed`,children:`Try interacting with this simulated inline template block.`})]}),(0,s.jsxs)(`form`,{onSubmit:async r=>{r.preventDefault(),o(`loading`);try{let r=t.Nt.currentUser?.uid||`guest`;await(0,i.addDoc)((0,i.collection)(t.Pt,`user_submissions`),{uid:r,...e,type:`template_simulation`,submittedAt:(0,i.serverTimestamp)()}),o(`success`),setTimeout(()=>{o(`idle`),n({favoriteService:``,satisfactionRating:``,detailedThoughts:``})},3e3)}catch{o(`error`)}},className:`space-y-4 w-full`,children:[(0,s.jsx)(t.i,{label:`Favorite Service`,placeholder:`e.g. Design Consulting`,value:e.favoriteService,onChange:t=>n({...e,favoriteService:t.target.value})}),(0,s.jsx)(t.i,{label:`Satisfaction Rating`,type:`number`,placeholder:`1 to 10`,value:e.satisfactionRating,onChange:t=>n({...e,satisfactionRating:t.target.value})}),(0,s.jsxs)(`div`,{className:`flex flex-col w-full relative`,children:[(0,s.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Detailed Thoughts`}),(0,s.jsx)(`textarea`,{rows:3,placeholder:`Type something here...`,value:e.detailedThoughts,onChange:t=>n({...e,detailedThoughts:t.target.value}),className:`flex w-full rounded-xl text-[15px] text-foreground px-4 py-3 transition-all duration-300 placeholder:text-foreground/40 focus:outline-none focus:border-accent glow-focus disabled:cursor-not-allowed disabled:opacity-50 glass-panel min-h-[100px] resize-none`})]}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsx)(t.r,{type:`submit`,className:`w-full px-6 md:px-8 py-3 md:py-3.5 rounded-xl font-semibold tracking-wide btn-primary text-[15px] shadow-xl transition-all duration-300 hover:-translate-y-1 active:scale-95 flex items-center justify-center`,isLoading:!1,children:`Trigger Simulation`})})]})]})})]})})]})}function ot(){let[e,n]=(0,r.useState)(!1),[a,o]=(0,r.useState)({concept:``,featureRequest:``,notes:``}),[l,u]=(0,r.useState)(`idle`);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-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:`Popup Form`}),(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`}),`/popup_form`]})]}),(0,s.jsx)(`div`,{className:`flex justify-between items-center mb-6 border-b border-[var(--panel-border)] pb-6 relative z-20`,children:(0,s.jsxs)(c.Link,{to:`/templates`,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 text-foreground/70`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4`}),` Go Back`]})}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative flex flex-col w-full min-h-[150px] p-6 lg:p-10`,children:[(0,s.jsx)(`div`,{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[800px] h-[800px] bg-accent/5 blur-[120px] rounded-full pointer-events-none -z-10`}),(0,s.jsx)(`div`,{className:`flex h-full w-full justify-end items-start relative z-10`,children:(0,s.jsxs)(t.r,{onClick:()=>n(!0),className:`px-6 py-2.5 text-[14px] font-bold rounded-xl shadow-lg flex items-center justify-center gap-2 btn-primary transition-all hover:-translate-y-1`,children:[(0,s.jsx)(t.k,{className:`w-4 h-4`}),` Open Form`]})})]}),(0,s.jsx)(t.s,{children:e&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-xl cursor-pointer`,onClick:()=>n(!1)}),(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:`w-full max-w-[500px] p-6 sm:p-8 lg:p-10 rounded-3xl md:rounded-3xl glass-panel relative glow-hover shadow-[0_8px_32px_rgba(0,0,0,0.08)] z-10 mx-4 max-h-[95vh] overflow-y-auto no-scrollbar`,children:[(0,s.jsx)(`div`,{className:`absolute -inset-[1px] bg-gradient-to-br from-[var(--primary-glow)] to-transparent opacity-30 blur-[20px] rounded-3xl md:rounded-3xl -z-10`}),(0,s.jsxs)(`div`,{className:`relative z-10 w-full`,children:[(0,s.jsx)(`button`,{onClick:()=>n(!1),className:`absolute -top-2 -right-2 w-8 h-8 flex items-center justify-center rounded-full hover:bg-foreground/5 text-foreground/60 hover:text-foreground transition-colors z-20`,children:(0,s.jsx)(t.d,{className:`w-5 h-5`})}),l===`success`?(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex flex-col items-center justify-center py-12 text-center`,children:[(0,s.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-green-500/10 border border-green-500/20 flex items-center justify-center text-green-500 mb-4`,children:(0,s.jsx)(t.dt,{className:`w-8 h-8`})}),(0,s.jsx)(`h4`,{className:`text-xl font-bold text-foreground mb-2`,children:`Simulation Complete!`}),(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/60 leading-relaxed max-w-[280px]`,children:`Your test data was sent successfully. Log in as an admin and open your Inbox to see it.`})]}):l===`loading`?(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`flex flex-col items-center justify-center py-16 text-center`,children:[(0,s.jsx)(`div`,{className:`w-10 h-10 border-4 border-accent border-r-transparent rounded-full animate-spin mb-4`}),(0,s.jsx)(`h4`,{className:`text-lg font-bold text-foreground tracking-tight`,children:`Processing`}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/50 mt-1`,children:`Simulating submission...`})]}):(0,s.jsxs)(t.o.div,{initial:{opacity:0},animate:{opacity:1},children:[(0,s.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,s.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight break-words`,children:`Popup Template`}),(0,s.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide leading-relaxed`,children:`Fill out the simulated fields below to test the interaction.`})]}),(0,s.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),u(`loading`);try{let e=t.Nt.currentUser?.uid||`guest`;await(0,i.addDoc)((0,i.collection)(t.Pt,`user_submissions`),{uid:e,...a,type:`template_simulation`,submittedAt:(0,i.serverTimestamp)()}),u(`success`),setTimeout(()=>{u(`idle`),o({concept:``,featureRequest:``,notes:``}),n(!1)},3e3)}catch{u(`error`)}},className:`space-y-4 w-full`,children:[(0,s.jsx)(t.i,{label:`Concept Name`,placeholder:`e.g. Project Apollo`,value:a.concept,onChange:e=>o({...a,concept:e.target.value})}),(0,s.jsx)(t.i,{label:`Feature Request`,placeholder:`e.g. Real-time sync`,value:a.featureRequest,onChange:e=>o({...a,featureRequest:e.target.value})}),(0,s.jsxs)(`div`,{className:`flex flex-col w-full relative`,children:[(0,s.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Simulated Notes`}),(0,s.jsx)(`textarea`,{rows:3,placeholder:`Type something here...`,value:a.notes,onChange:e=>o({...a,notes:e.target.value}),className:`flex w-full rounded-xl text-[15px] text-foreground px-4 py-3 transition-all duration-300 placeholder:text-foreground/40 focus:outline-none focus:border-accent glow-focus disabled:cursor-not-allowed disabled:opacity-50 glass-panel min-h-[100px] resize-none`})]}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsx)(t.r,{type:`submit`,className:`w-full px-6 md:px-8 py-3 md:py-3.5 rounded-xl font-semibold tracking-wide btn-primary text-[15px] shadow-xl transition-all duration-300 hover:-translate-y-1 active:scale-95 flex items-center justify-center`,isLoading:!1,children:`Trigger Simulation`})})]})]})]})]})]})})]})}function st(){let[e,n]=(0,r.useState)(void 0);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 items-center`,children:[(0,s.jsx)(`div`,{className:`w-full max-w-5xl mb-8`,children:(0,s.jsxs)(c.Link,{to:`/templates`,className:`inline-flex items-center gap-2 text-foreground/50 hover:text-accent transition-colors font-medium text-[14px]`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4`}),` Back to Templates`]})}),(0,s.jsxs)(`div`,{className:`w-full max-w-5xl mx-auto mt-2 glass-panel rounded-3xl border border-[var(--panel-border)] p-6 md:p-10 relative overflow-hidden shadow-2xl`,children:[(0,s.jsx)(`div`,{className:`flex items-center justify-between mb-8 pb-6 border-b border-[var(--panel-border)]/50`,children:(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h3`,{className:`text-2xl font-extrabold text-foreground tracking-tight`,children:`System Files`}),(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/50 mt-1`,children:`Review and manage core application assets.`})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,s.jsxs)(`div`,{className:`glass-panel p-5 rounded-2xl border border-[var(--panel-border)]/50 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-4 w-full sm:w-auto`,children:[(0,s.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-red-500/10 flex items-center justify-center text-red-500 shrink-0`,children:(0,s.jsx)(t._,{className:`w-5 h-5`})}),(0,s.jsxs)(`div`,{className:`min-w-0 pr-2`,children:[(0,s.jsx)(`h4`,{className:`font-bold text-[14px] sm:text-[15px] text-foreground truncate`,children:`Critical Configuration File`}),(0,s.jsx)(`p`,{className:`text-[12px] sm:text-[13px] text-foreground/50 font-medium mt-0.5 truncate`,children:`Size: 4.2 MB • Modified 2 hours ago`})]})]}),(0,s.jsx)(t.r,{variant:`secondary`,onClick:()=>n(null),className:`w-full sm:w-auto shrink-0 flex items-center justify-center px-6 py-3 sm:py-2.5 text-[13px] font-bold rounded-xl text-red-500 hover:bg-red-500/10 hover:border-red-500/20 bg-red-500/5 sm:bg-transparent`,children:`Delete File`})]}),(0,s.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 opacity-50 pointer-events-none mt-2`,children:[1,2].map(e=>(0,s.jsxs)(`div`,{className:`glass-panel p-5 rounded-2xl border border-[var(--panel-border)]/20 flex items-center gap-4`,children:[(0,s.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-foreground/5 shrink-0`}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2 flex-1`,children:[(0,s.jsx)(`div`,{className:`w-32 h-3 rounded-full bg-foreground/10`}),(0,s.jsx)(`div`,{className:`w-20 h-2 rounded-full bg-foreground/5`})]})]},e))})]})]}),(0,s.jsx)(t.s,{children:e!==void 0&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-xl`}),(0,s.jsx)(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:`w-full max-w-[400px] p-6 rounded-3xl glass-panel border border-[var(--panel-border)] shadow-2xl relative z-10 text-center`,children:(0,s.jsx)(t.s,{mode:`wait`,children:e===null?(0,s.jsxs)(t.o.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full flex flex-col items-center`,children:[(0,s.jsx)(`h3`,{className:`text-xl font-extrabold mb-2 text-foreground tracking-tight`,children:`Confirm Deletion`}),(0,s.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 leading-relaxed mb-6`,children:`Are you entirely sure you wish to delete this configuration? This action is permanent.`}),(0,s.jsxs)(`div`,{className:`flex items-center gap-3 w-full`,children:[(0,s.jsx)(t.r,{variant:`secondary`,onClick:()=>n(!1),className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:`Cancel`}),(0,s.jsx)(t.r,{onClick:()=>n(!0),className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl bg-red-500 hover:bg-red-600 border-none text-white shadow-xl hover:shadow-red-500/20 glow-hover`,children:`Yes, Delete`})]})]},`confirm`):e===!0?(0,s.jsxs)(t.o.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full flex flex-col items-center py-2`,children:[(0,s.jsxs)(`h3`,{className:`text-xl font-extrabold mb-1 text-green-500 tracking-tight flex items-center gap-2`,children:[(0,s.jsx)(t._t,{className:`w-5 h-5`}),` Verified`]}),(0,s.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mb-6`,children:`Action successfully executed.`}),(0,s.jsx)(t.r,{variant:`secondary`,onClick:()=>n(void 0),className:`px-6 py-2 rounded-xl text-[13px] font-bold`,children:`Close Panel`})]},`success`):(0,s.jsxs)(t.o.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full flex flex-col items-center py-2`,children:[(0,s.jsxs)(`h3`,{className:`text-xl font-extrabold mb-1 text-foreground/80 tracking-tight flex items-center gap-2`,children:[(0,s.jsx)(t.d,{className:`w-5 h-5`}),` Aborted`]}),(0,s.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mb-6`,children:`Cancellation securely caught.`}),(0,s.jsx)(t.r,{variant:`secondary`,onClick:()=>n(void 0),className:`px-6 py-2 rounded-xl text-[13px] font-bold`,children:`Close Panel`})]},`error`)})})]})})]})}var ct=[{text:`text-red-400`,bgCircle:`bg-red-400`,bgCard:`bg-red-500/[0.08]`,borderCard:`border-red-500/30`,bgLight:`bg-red-500/15`,bgHover:`hover:bg-red-500`,bgAlt:`bg-red-500/[0.04]`,name:`Red`},{text:`text-orange-400`,bgCircle:`bg-orange-400`,bgCard:`bg-orange-500/[0.08]`,borderCard:`border-orange-500/30`,bgLight:`bg-orange-500/15`,bgHover:`hover:bg-orange-500`,bgAlt:`bg-orange-500/[0.04]`,name:`Orange`},{text:`text-yellow-400`,bgCircle:`bg-yellow-400`,bgCard:`bg-yellow-500/[0.08]`,borderCard:`border-yellow-500/30`,bgLight:`bg-yellow-500/15`,bgHover:`hover:bg-yellow-500`,bgAlt:`bg-yellow-500/[0.04]`,name:`Yellow`},{text:`text-green-400`,bgCircle:`bg-green-400`,bgCard:`bg-green-500/[0.08]`,borderCard:`border-green-500/30`,bgLight:`bg-green-500/15`,bgHover:`hover:bg-green-500`,bgAlt:`bg-green-500/[0.04]`,name:`Green`},{text:`text-blue-400`,bgCircle:`bg-blue-400`,bgCard:`bg-blue-500/[0.08]`,borderCard:`border-blue-500/30`,bgLight:`bg-blue-500/15`,bgHover:`hover:bg-blue-500`,bgAlt:`bg-blue-500/[0.04]`,name:`Blue`},{text:`text-accent`,bgCircle:`bg-accent`,bgCard:`bg-accent/[0.08]`,borderCard:`border-accent/30`,bgLight:`bg-accent/15`,bgHover:`hover:bg-accent`,bgAlt:`bg-accent/[0.04]`,name:`Purple`},{text:`text-pink-400`,bgCircle:`bg-pink-400`,bgCard:`bg-pink-500/[0.08]`,borderCard:`border-pink-500/30`,bgLight:`bg-pink-500/15`,bgHover:`hover:bg-pink-500`,bgAlt:`bg-pink-500/[0.04]`,name:`Pink`},{text:`text-foreground/60`,bgCircle:`bg-foreground/30`,bgCard:`bg-foreground/[0.04]`,borderCard:`border-[var(--panel-border)]/50`,bgLight:`bg-foreground/15`,bgHover:`hover:bg-foreground/30`,bgAlt:`bg-foreground/[0.02]`,name:`Default`}];function lt({title:e=`Board View`,subtitle:n=`/templates/board`,backUrl:a=`/templates`,tasksCollection:o=`pub_tasks`,categoriesCollection:l=`pub_categories`,config:u,customContent:d}){let{user:f}=A(),p=!!u,m=u?.isInternal||u?.isShared;u?.isPrivate&&u?.isAdmin;let h=u?.isAdmin||m,g=p?h:!0,_=u?.showButton!==!1,v=u?.buttonText||`+`,y=u?.buttonStyle||`primary`,b=u?.keyName||`key`,x=u?.valueName||`value`,[S,C]=(0,r.useState)([]),[w,T]=(0,r.useState)([]),[E,D]=(0,r.useState)(null),[O,k]=(0,r.useState)(null),[j,M]=(0,r.useState)({name:``}),[N,P]=(0,r.useState)([]),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)(null),[ee,z]=(0,r.useState)(null),[te,B]=(0,r.useState)(null),[ne,V]=(0,r.useState)(!1),[H,U]=(0,r.useState)(null),[G,K]=(0,r.useState)(``),[q,J]=(0,r.useState)(null);(0,r.useEffect)(()=>{let e=o.startsWith(`user_`),n=l.startsWith(`user_`);if(e&&!f)return;try{let e=localStorage.getItem(`fbos_board_tasks_${o}`);e&&C(JSON.parse(e));let t=localStorage.getItem(`fbos_board_cats_${l}`);t&&T(JSON.parse(t))}catch{}let r=(0,i.onSnapshot)(e&&f?(0,i.query)((0,i.collection)(t.Pt,o),(0,i.where)(`uid`,`==`,f.uid)):(0,i.collection)(t.Pt,o),e=>{let t=[];e.forEach(e=>{let n=e.data();t.push({id:e.id,categoryId:n.categoryId,name:n.name||n.text||`Unnamed Item`,fields:n.fields||(n.value?[{key:`Label`,value:n.value}]:[]),order:n.order||0})});let n=t.sort((e,t)=>(e.order||0)-(t.order||0));C(n),localStorage.setItem(`fbos_board_tasks_${o}`,JSON.stringify(n))}),a=(0,i.onSnapshot)(n&&f?(0,i.query)((0,i.collection)(t.Pt,l),(0,i.where)(`uid`,`==`,f.uid)):(0,i.collection)(t.Pt,l),e=>{let n=[];if(e.forEach(e=>{n.push({id:e.id,...e.data()})}),n.length===0){let e=[{id:`todo`,title:`To Do`,createdAt:Date.now()-2e3},{id:`in_progress`,title:`In Progress`,createdAt:Date.now()-1e3},{id:`review`,title:`Review`,createdAt:Date.now()}],n=f?{uid:f.uid}:{};e.forEach(e=>(0,i.setDoc)((0,i.doc)(t.Pt,l,e.id),{...n,title:e.title,createdAt:e.createdAt}))}else T(n),localStorage.setItem(`fbos_board_cats_${l}`,JSON.stringify(n))});return()=>{r(),a()}},[o,l,f]);let Y=(e,t)=>{t?(k(t.id),M({id:t.id,name:t.name}),P(t.fields?.length?[...t.fields,{key:``,value:``}]:[{key:``,value:``}])):(D(e),M({name:``}),P([{key:``,value:``}]))},ie=(e,t,n)=>{let r=[...N];r[e]={key:t,value:n},e===N.length-1&&(t.trim()!==``||n.trim()!==``)&&r.push({key:``,value:``}),P(r)},ae=(e,t)=>{e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`taskId`,t),I(t)},oe=(e,t)=>{e.preventDefault(),e.stopPropagation(),t!==F&&R(t)},se=(e,t)=>{e.preventDefault(),e.stopPropagation(),z(t)},X=e=>{e.preventDefault(),R(null),z(null)},ce=async(e,n,r)=>{e.preventDefault(),e.stopPropagation(),R(null),z(null);let a=e.dataTransfer.getData(`taskId`);if(!a||a===r){I(null);return}let s=S.find(e=>e.id===a);if(!s)return;let c=S.filter(e=>e.categoryId===n).sort((e,t)=>(e.order||0)-(t.order||0));if(s.categoryId===n?(c=c.filter(e=>e.id!==a),c.push(s)):c.push({...s,categoryId:n}),r){let e=c.findIndex(e=>e.id===r),t=c.findIndex(e=>e.id===a),[n]=c.splice(t,1);c.splice(e,0,n)}c.forEach((e,r)=>{let a={categoryId:n,order:r};f&&(a.uid=f.uid),(0,i.setDoc)((0,i.doc)(t.Pt,o,e.id),a,{merge:!0})}),I(null)},Z=async e=>{let n=j.id||`item_${Date.now()}`,r=j.name.trim(),a=r||`Untitled Item`,s=N.filter(e=>e.key.trim()!==``||e.value.trim()!==``),c=!0,l=j.id?S.find(e=>e.id===j.id):null;if(l){let e=JSON.stringify(l.fields||[]),t=JSON.stringify(s);l.name===a&&e===t&&(c=!1)}else !r&&s.length===0&&(c=!1);if(!c){D(null),k(null);return}B(j.id||`new`);let u={categoryId:e,name:a,fields:s};f&&!j.id&&(u.uid=f.uid),await(0,i.setDoc)((0,i.doc)(t.Pt,o,n),u,{merge:!0}),setTimeout(()=>{D(null),k(null),B(null)},400)},Q=(e,t)=>{J({type:`item`,id:e,title:t})},le=async()=>{let e=`cat_${Date.now()}`,n={title:``,createdAt:Date.now()};f&&(n.uid=f.uid),await(0,i.setDoc)((0,i.doc)(t.Pt,l,e),n),U(e),K(``),setTimeout(()=>{let e=document.getElementById(`board-container`);e&&e.scrollTo({left:e.scrollWidth,behavior:`smooth`})},150)},ue=async(e,n)=>{T(t=>t.map(t=>t.id===e?{...t,color:n}:t)),await(0,i.setDoc)((0,i.doc)(t.Pt,l,e),{color:n},{merge:!0})},de=async e=>{G.trim()?await(0,i.setDoc)((0,i.doc)(t.Pt,l,e),{title:G},{merge:!0}):await(0,i.deleteDoc)((0,i.doc)(t.Pt,l,e)),U(null)},fe=(e,t)=>{J({type:`category`,id:e,title:t})},pe=async()=>{if(q){V(!0);try{if(q.type===`item`)await(0,i.deleteDoc)((0,i.doc)(t.Pt,o,q.id)),k(null);else{let e=S.filter(e=>e.categoryId===q.id);for(let n of e)await(0,i.deleteDoc)((0,i.doc)(t.Pt,o,n.id));await(0,i.deleteDoc)((0,i.doc)(t.Pt,l,q.id))}}catch{}V(!1),J(null)}},me=[...w].sort((e,t)=>(e.createdAt||0)-(t.createdAt||0));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 overflow-x-hidden`,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}),n&&(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`}),n]})]}),p&&(0,s.jsx)(`div`,{className:`mb-6`,children:(0,s.jsx)(W,{})}),(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between items-start sm:items-center mb-6 border-b border-[var(--panel-border)] pb-6 gap-4 relative z-20 shrink-0`,children:[!p&&a&&(0,s.jsxs)(c.Link,{to:a,className:`px-5 py-2 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold text-foreground/70 hover:bg-foreground/5 transition-all flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4`}),` Go Back`]}),p&&(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:u?.tabTitle||u?.tabName||e}),(0,s.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[S.length,` `,S.length===1?`item`:`items`,` · `,me.length,` `,me.length===1?`category`:`categories`]})]}),(0,s.jsx)(`div`,{className:`flex flex-col sm:flex-row gap-2 w-full sm:w-auto`,children:_&&(0,s.jsx)(t.r,{variant:y===`secondary`?`secondary`:void 0,onClick:le,className:`flex-1 sm:flex-none px-3 py-2.5 text-[14px] font-bold rounded-xl shadow-lg hover:-translate-y-0.5 transition-all shrink-0`,children:v===`+`?(0,s.jsx)(t.k,{className:`w-4 h-4`}):v})})]}),(0,s.jsx)(`div`,{className:`flex-1 w-full relative z-40 min-h-0`,children:d?(0,s.jsx)(`div`,{className:`fbos-content-slot w-full h-full overflow-y-auto`,children:(0,s.jsx)(d,{config:u,actions:{tasks:S,categories:w,collection:o,catCollection:l,user:f,saveTask:async(e,n)=>{let r=e||`item_${Date.now()}`;C(e=>e.find(e=>e.id===r)?e.map(e=>e.id===r?{...e,...n}:e):[...e,{id:r,...n}]),await(0,i.setDoc)((0,i.doc)(t.Pt,o,r),n,{merge:!0})},deleteTask:async e=>{C(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Pt,o,e))},saveCategory:async(e,n)=>{T(t=>t.find(t=>t.id===e)?t.map(t=>t.id===e?{...t,...n}:t):[...t,{id:e,...n}]),await(0,i.setDoc)((0,i.doc)(t.Pt,l,e),n,{merge:!0})},deleteCategory:async e=>{T(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Pt,l,e))},openInlineEditor:(e,t)=>Y(e,t)}})}):(0,s.jsxs)(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 z-10 flex flex-col h-full p-4 md:p-6`,children:[(0,s.jsx)(`div`,{className:`absolute top-0 right-0 w-[400px] h-[400px] bg-accent/5 blur-[100px] rounded-full pointer-events-none -z-10`}),(0,s.jsxs)(`div`,{id:`board-container`,className:`w-full h-full flex flex-row gap-4 md:gap-6 overflow-x-auto pb-4 snap-x snap-mandatory styled-scrollbars items-start`,children:[me.map((e,n)=>{let r=S.filter(t=>t.categoryId===e.id);r.sort((e,t)=>(e.order||0)-(t.order||0));let i=ct.find(t=>t.text===e.color)||ct.find(e=>e.text===`text-accent`);return i.text,i.bgLight,i.bgHover,(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:n*.1},className:`w-[300px] md:w-[320px] shrink-0 flex flex-col max-h-full rounded-3xl p-4 snap-center relative border transition-colors ${ct.find(t=>t.text===e.color)?.bgCard||`bg-foreground/[0.02]`} ${ct.find(t=>t.text===e.color)?.borderCard||`border-[var(--panel-border)]/50`}`,children:[(0,s.jsx)(`div`,{className:`flex items-center justify-between mb-4 px-2 relative z-[200]`,children:(0,s.jsxs)(`h3`,{className:`font-bold text-[14px] flex items-center w-full text-foreground/80 group relative z-[200]`,children:[H===e.id?(0,s.jsxs)(`div`,{className:`relative flex-1 w-full flex items-center pr-8 z-[200]`,children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),de(e.id)}}),(0,s.jsx)(`input`,{value:G,onChange:e=>K(e.target.value),onBlur:t=>{t.relatedTarget?.closest(`.category-color-picker`)||de(e.id)},onKeyDown:t=>t.key===`Enter`&&de(e.id),className:`bg-transparent border-none outline-none font-bold text-[14px] w-full p-0 ${e.color||`text-foreground/80`}`,placeholder:`Category name`,autoFocus:!0}),(0,s.jsxs)(`div`,{className:`absolute top-8 left-0 flex gap-1.5 bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-[100] category-color-picker items-center`,tabIndex:-1,children:[(0,s.jsx)(`button`,{onClick:async t=>{t.preventDefault(),t.stopPropagation(),await ue(e.id,``),U(null)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Reset Category Color`,children:(0,s.jsx)(t.d,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),ct.map(t=>(0,s.jsx)(`button`,{onMouseDown:async n=>{n.preventDefault(),await ue(e.id,t.text)},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50 shrink-0`},t.name))]})]}):(0,s.jsxs)(`div`,{className:`flex items-center gap-2 w-full cursor-pointer hover:text-foreground transition-colors pr-8`,onClick:()=>{U(e.id),K(e.title)},children:[(0,s.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${ct.find(t=>t.text===e.color)?.bgCircle||`bg-foreground/20`} transition-colors shrink-0`}),(0,s.jsx)(`span`,{className:`truncate flex-1 max-w-[200px] ${e.color||``}`,children:e.title||`Untitled Category`}),(0,s.jsx)(`span`,{className:`text-[11px] bg-foreground/10 text-foreground/60 px-1.5 py-0.5 rounded-md font-medium shrink-0`,children:r.length})]}),w.length>1&&(0,s.jsx)(`button`,{onClick:()=>fe(e.id,e.title),className:`absolute right-0 opacity-0 group-hover:opacity-100 text-foreground/30 hover:text-red-500 transition-all shrink-0`,children:(0,s.jsx)(t.v,{className:`w-3.5 h-3.5`})})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2.5 flex-1 overflow-y-auto styled-scrollbars pr-1 relative min-h-[150px] rounded-xl transition-all ${ee===e.id&&!L?`bg-foreground/5 scale-[1.01] border-dashed border border-accent/20`:``}`,onDragOver:t=>se(t,e.id),onDragLeave:X,onDrop:t=>ce(t,e.id),children:[(0,s.jsx)(t.s,{children:r.map(n=>O===n.id?(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-md border border-accent/40 transition-all flex flex-col gap-2 relative z-[100]`,children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),Z(e.id)}}),(0,s.jsx)(`textarea`,{placeholder:`Write an item name...`,className:`no-glow bg-transparent border-none outline-none text-[13px] text-foreground/90 font-medium leading-snug resize-none w-full min-h-[40px] relative z-10`,value:j.name,onChange:e=>M({...j,name:e.target.value}),onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),Z(e.id))}}),(0,s.jsx)(`div`,{className:`flex flex-col gap-2 mt-1 relative z-10 w-full`,children:N.map((t,n)=>(0,s.jsxs)(`div`,{className:`flex items-start bg-foreground/[0.04] border border-[var(--panel-border)]/50 rounded-[8px] px-2.5 py-1.5 w-full`,children:[(0,s.jsx)(`input`,{placeholder:b,value:t.key,onChange:e=>ie(n,e.target.value,t.value),onKeyDown:t=>t.key===`Enter`&&Z(e.id),className:`no-glow bg-transparent outline-none text-[11px] text-foreground/50 font-bold placeholder:text-foreground/30 relative top-[1px] shrink-0`,style:{width:`${Math.max(3,t.key.length||b.length)}ch`}}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative top-[1px]`,children:`:`}),(0,s.jsx)(`textarea`,{rows:1,placeholder:x,value:t.value,onChange:e=>ie(n,t.key,e.target.value),onInput:e=>{let t=e.target;t.style.height=`auto`,t.style.height=t.scrollHeight+`px`},onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),Z(e.id))},className:`no-glow bg-transparent outline-none text-[12px] text-foreground/90 font-medium flex-1 min-w-[40px] placeholder:opacity-40 resize-none overflow-hidden leading-tight relative top-[1px]`})]},n))}),te===n.id&&(0,s.jsx)(`div`,{className:`flex items-center justify-end pt-1`,children:(0,s.jsx)(`div`,{className:`w-3 h-3 border-2 border-accent border-t-transparent rounded-full animate-spin`})})]},n.id):(0,s.jsxs)(t.o.div,{draggable:!0,onDragStart:e=>ae(e,n.id),onDragOver:e=>oe(e,n.id),onDragLeave:X,onDrop:t=>ce(t,e.id,n.id),initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-sm hover:shadow-md cursor-grab active:cursor-grabbing hover:border-accent/40 transition-all group flex flex-col gap-2 relative z-10 border ${L===n.id?`border-accent border-t-2 translate-y-1`:`border-[var(--panel-border)]`} ${F===n.id?`opacity-30 scale-95 border-dashed border-2`:``}`,children:[(0,s.jsxs)(`div`,{className:`absolute top-2 right-2 flex items-center gap-1.5 opacity-0 group-hover:opacity-100 transition-opacity bg-background/90 backdrop-blur-md border border-[var(--panel-border)] rounded-lg p-1 z-20 shadow-md`,children:[(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),Y(e.id,n)},className:`p-1 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-accent transition-colors`,children:(0,s.jsx)(t.A,{className:`w-3.5 h-3.5`})}),(0,s.jsx)(`button`,{onClick:e=>{e.stopPropagation(),Q(n.id,n.name)},className:`p-1 hover:bg-red-500/10 rounded-md text-foreground/60 hover:text-red-500 transition-colors`,children:(0,s.jsx)(t.v,{className:`w-3.5 h-3.5`})})]}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/90 font-medium leading-snug break-words pr-12`,children:n.name}),n.fields&&n.fields.length>0&&(0,s.jsx)(`div`,{className:`flex flex-row flex-wrap gap-2 mt-2`,children:n.fields.map((e,t)=>(0,s.jsxs)(`div`,{className:`inline-flex bg-foreground/[0.04] border border-[var(--panel-border)]/50 rounded-[8px] px-2.5 py-1.5 max-w-full`,children:[(0,s.jsxs)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative -top-[1px] shrink-0 break-all`,children:[e.key,`:`]}),(0,s.jsx)(`span`,{className:`text-[12px] text-foreground/90 font-medium break-words leading-tight min-w-0`,children:e.value})]},t))}),(0,s.jsxs)(`div`,{className:`flex items-end justify-between mt-3 pt-3 border-t border-[var(--panel-border)]/50 w-full gap-2`,children:[g&&p&&f?(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5 pr-2 border-r border-[var(--panel-border)] border-dashed mr-auto`,children:[f.photoURL?(0,s.jsx)(`img`,{src:f.photoURL,className:`w-4 h-4 rounded-full shrink-0 object-cover`}):(0,s.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-accent/20 text-accent flex items-center justify-center text-[9px] font-bold shrink-0`,children:(f.displayName||f.email||`U`)[0].toUpperCase()}),(0,s.jsx)(`span`,{className:`text-[10px] font-bold text-foreground/60 truncate max-w-[80px]`,children:f.displayName||f.email?.split(`@`)[0]||`User`})]}):(0,s.jsx)(`div`,{className:`flex items-center gap-2 pr-2 border-r border-[var(--panel-border)] border-dashed mr-auto`}),(0,s.jsx)(`span`,{className:`text-[10px] text-foreground/40 font-bold text-right pt-0.5 shrink-0 max-w-[50%] truncate flex-1`,children:n.id.startsWith(`item_`)?new Date(parseInt(n.id.split(`_`)[1])).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}):`Recently Added`})]})]},n.id))}),E===e.id?(0,s.jsxs)(t.o.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-md border border-accent/40 transition-all flex flex-col gap-2 relative z-[100] mt-1`,children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),Z(e.id)}}),(0,s.jsx)(`textarea`,{placeholder:`Write an item name...`,className:`no-glow bg-transparent border-none outline-none text-[13px] text-foreground/90 font-medium leading-snug resize-none w-full min-h-[40px] relative z-10`,value:j.name,onChange:e=>M({...j,name:e.target.value}),onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),Z(e.id))},autoFocus:!0}),(0,s.jsx)(`div`,{className:`flex flex-col gap-2 mt-1 relative z-10 w-full`,children:N.map((t,n)=>(0,s.jsxs)(`div`,{className:`flex items-start bg-foreground/[0.04] border border-[var(--panel-border)]/50 rounded-[8px] px-2.5 py-1.5 w-full`,children:[(0,s.jsx)(`input`,{placeholder:b,style:{width:`${Math.max(3,t.key.length||b.length)}ch`},value:t.key,onChange:e=>ie(n,e.target.value,t.value),onKeyDown:t=>t.key===`Enter`&&Z(e.id),className:`no-glow bg-transparent outline-none text-[11px] text-foreground/50 font-bold placeholder:text-foreground/30 relative top-[1px]`}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative top-[1px]`,children:`:`}),(0,s.jsx)(`textarea`,{rows:1,placeholder:x,value:t.value,onChange:e=>ie(n,t.key,e.target.value),onInput:e=>{let t=e.target;t.style.height=`auto`,t.style.height=t.scrollHeight+`px`},onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),Z(e.id))},className:`no-glow bg-transparent outline-none text-[12px] text-foreground/90 font-medium flex-1 min-w-[40px] placeholder:opacity-40 resize-none overflow-hidden leading-tight relative top-[1px]`})]},n))}),te===`new`&&(0,s.jsx)(`div`,{className:`flex items-center justify-end pt-1`,children:(0,s.jsx)(`div`,{className:`w-3 h-3 border-2 border-accent border-t-transparent rounded-full animate-spin`})})]}):(0,s.jsxs)(`button`,{onClick:()=>Y(e.id),className:`flex items-center gap-2 justify-center w-full py-2.5 mt-1 rounded-xl border border-transparent text-[12px] font-bold text-foreground/40 hover:text-foreground hover:bg-foreground/[0.03] transition-all shrink-0`,children:[(0,s.jsx)(t.k,{className:`w-4 h-4`}),` Add Item`]})]})]},e.id)}),(0,s.jsx)(`div`,{className:`w-[10px] shrink-0 pointer-events-none`})]})]})}),(0,s.jsx)(`style`,{children:`.styled-scrollbars::-webkit-scrollbar { width: 6px; height: 6px; } .styled-scrollbars::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--accent-color) 20%, transparent); border-radius: 4px; } .styled-scrollbars::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--accent-color) 40%, transparent); }`}),(0,s.jsx)(re,{isOpen:!!q,title:`Confirm Deletion`,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:q?.title}),` This action is permanent.`]}),onConfirm:pe,onCancel:()=>J(null),isProcessing:ne,confirmText:`Yes, Delete`})]})}function ut(e){return Array.isArray?Array.isArray(e):bt(e)===`[object Array]`}function dt(e){if(typeof e==`string`)return e;if(typeof e==`bigint`)return e.toString();let t=e+``;return t==`0`&&1/e==-1/0?`-0`:t}function ft(e){return e==null?``:dt(e)}function pt(e){return typeof e==`string`}function mt(e){return typeof e==`number`}function ht(e){return e===!0||e===!1||_t(e)&&bt(e)==`[object Boolean]`}function gt(e){return typeof e==`object`}function _t(e){return gt(e)&&e!==null}function vt(e){return e!=null}function yt(e){return!e.trim().length}function bt(e){return e==null?e===void 0?`[object Undefined]`:`[object Null]`:Object.prototype.toString.call(e)}var xt=`Incorrect 'index' type`,St=e=>`Invalid value for key ${e}`,Ct=e=>`Pattern length exceeds max of ${e}.`,wt=e=>`Missing ${e} property in key`,Tt=e=>`Property 'weight' in key '${e}' must be a positive integer`,Et=Object.prototype.hasOwnProperty,Dt=class{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(e=>{let n=Ot(e);this._keys.push(n),this._keyMap[n.id]=n,t+=n.weight}),this._keys.forEach(e=>{e.weight/=t})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function Ot(e){let t=null,n=null,r=null,i=1,a=null;if(pt(e)||ut(e))r=e,t=kt(e),n=At(e);else{if(!Et.call(e,`name`))throw Error(wt(`name`));let o=e.name;if(r=o,Et.call(e,`weight`)&&(i=e.weight,i<=0))throw Error(Tt(o));t=kt(o),n=At(o),a=e.getFn}return{path:t,id:n,weight:i,src:r,getFn:a}}function kt(e){return ut(e)?e:e.split(`.`)}function At(e){return ut(e)?e.join(`.`):e}function jt(e,t){let n=[],r=!1,i=(e,t,a,o)=>{if(vt(e))if(!t[a])n.push(o===void 0?e:{v:e,i:o});else{let s=e[t[a]];if(!vt(s))return;if(a===t.length-1&&(pt(s)||mt(s)||ht(s)||typeof s==`bigint`))n.push(o===void 0?ft(s):{v:ft(s),i:o});else if(ut(s)){r=!0;for(let e=0,n=s.length;e<n;e+=1)i(s[e],t,a+1,e)}else t.length&&i(s,t,a+1,o)}};return i(e,pt(t)?t.split(`.`):t,0),r?n:n[0]}var Mt={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Nt={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(e,t)=>e.score===t.score?e.idx<t.idx?-1:1:e.score<t.score?-1:1},Pt={location:0,threshold:.6,distance:100},Ft={useExtendedSearch:!1,useTokenSearch:!1,getFn:jt,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1},$=Object.freeze({...Nt,...Mt,...Pt,...Ft}),It=/[^ ]+/g;function Lt(e=1,t=3){let n=new Map,r=10**t;return{get(t){let i=t.match(It).length;if(n.has(i))return n.get(i);let a=1/i**(.5*e),o=parseFloat(Math.round(a*r)/r);return n.set(i,o),o},clear(){n.clear()}}}var Rt=class{constructor({getFn:e=$.getFn,fieldNormWeight:t=$.fieldNormWeight}={}){this.norm=Lt(t,3),this.getFn=e,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((e,t)=>{this._keysMap[e.id]=t})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,pt(this.docs[0])?this.docs.forEach((e,t)=>{this._addString(e,t)}):this.docs.forEach((e,t)=>{this._addObject(e,t)}),this.norm.clear())}add(e){let t=this.size();pt(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,n=this.size();t<n;t+=1)--this.records[t].i}removeAll(e){for(let t=e.length-1;t>=0;--t)this.records.splice(e[t],1);for(let e=0,t=this.records.length;e<t;e+=1)this.records[e].i=e}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_addString(e,t){if(!vt(e)||yt(e))return;let n={v:e,i:t,n:this.norm.get(e)};this.records.push(n)}_addObject(e,t){let n={i:t,$:{}};this.keys.forEach((t,r)=>{let i=t.getFn?t.getFn(e):this.getFn(e,t.path);if(vt(i)){if(ut(i)){let e=[];for(let t=0,n=i.length;t<n;t+=1){let n=i[t];if(vt(n)){if(pt(n)){if(!yt(n)){let r={v:n,i:t,n:this.norm.get(n)};e.push(r)}}else if(vt(n.v)){let t=pt(n.v)?n.v:ft(n.v);if(!yt(t)){let r={v:t,i:n.i,n:this.norm.get(t)};e.push(r)}}}}n.$[r]=e}else if(pt(i)&&!yt(i)){let e={v:i,n:this.norm.get(i)};n.$[r]=e}}}),this.records.push(n)}toJSON(){return{keys:this.keys.map(({getFn:e,...t})=>t),records:this.records}}};function zt(e,t,{getFn:n=$.getFn,fieldNormWeight:r=$.fieldNormWeight}={}){let i=new Rt({getFn:n,fieldNormWeight:r});return i.setKeys(e.map(Ot)),i.setSources(t),i.create(),i}function Bt(e,{getFn:t=$.getFn,fieldNormWeight:n=$.fieldNormWeight}={}){let{keys:r,records:i}=e,a=new Rt({getFn:t,fieldNormWeight:n});return a.setKeys(r),a.setIndexRecords(i),a}function Vt(e=[],t=$.minMatchCharLength){let n=[],r=-1,i=-1,a=0;for(let o=e.length;a<o;a+=1){let o=e[a];o&&r===-1?r=a:!o&&r!==-1&&(i=a-1,i-r+1>=t&&n.push([r,i]),r=-1)}return e[a-1]&&a-r>=t&&n.push([r,a-1]),n}var Ht=32;function Ut(e,t,n,{location:r=$.location,distance:i=$.distance,threshold:a=$.threshold,findAllMatches:o=$.findAllMatches,minMatchCharLength:s=$.minMatchCharLength,includeMatches:c=$.includeMatches,ignoreLocation:l=$.ignoreLocation}={}){if(t.length>Ht)throw Error(Ct(Ht));let u=t.length,d=e.length,f=Math.max(0,Math.min(r,d)),p=a,m=f,h=(e,t)=>{let n=e/u;if(l)return n;let r=Math.abs(f-t);return i?n+r/i:r?1:n},g=s>1||c,_=g?Array(d):[],v;for(;(v=e.indexOf(t,m))>-1;){let e=h(0,v);if(p=Math.min(e,p),m=v+u,g){let e=0;for(;e<u;)_[v+e]=1,e+=1}}m=-1;let y=[],b=1,x=u+d,S=1<<u-1;for(let t=0;t<u;t+=1){let r=0,i=x;for(;r<i;)h(t,f+i)<=p?r=i:x=i,i=Math.floor((x-r)/2+r);x=i;let a=Math.max(1,f-i+1),s=o?d:Math.min(f+i,d)+u,c=Array(s+2);c[s+1]=(1<<t)-1;for(let r=s;r>=a;--r){let i=r-1,o=n[e[i]];if(g&&(_[i]=+!!o),c[r]=(c[r+1]<<1|1)&o,t&&(c[r]|=(y[r+1]|y[r])<<1|1|y[r+1]),c[r]&S&&(b=h(t,i),b<=p)){if(p=b,m=i,m<=f)break;a=Math.max(1,2*f-m)}}if(h(t+1,f)>p)break;y=c}let C={isMatch:m>=0,score:Math.max(.001,b)};if(g){let e=Vt(_,s);e.length?c&&(C.indices=e):C.isMatch=!1}return C}function Wt(e){let t={};for(let n=0,r=e.length;n<r;n+=1){let i=e.charAt(n);t[i]=(t[i]||0)|1<<r-n-1}return t}function Gt(e){if(e.length<=1)return e;e.sort((e,t)=>e[0]-t[0]||e[1]-t[1]);let t=[e[0]];for(let n=1,r=e.length;n<r;n+=1){let r=t[t.length-1],i=e[n];i[0]<=r[1]+1?r[1]=Math.max(r[1],i[1]):t.push(i)}return t}var Kt={ł:`l`,Ł:`L`,đ:`d`,Đ:`D`,ø:`o`,Ø:`O`,ħ:`h`,Ħ:`H`,ŧ:`t`,Ŧ:`T`,ı:`i`,ß:`ss`},qt=RegExp(`[`+Object.keys(Kt).join(``)+`]`,`g`),Jt=String.prototype.normalize?e=>e.normalize(`NFD`).replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,``).replace(qt,e=>Kt[e]):e=>e,Yt=class{constructor(e,{location:t=$.location,threshold:n=$.threshold,distance:r=$.distance,includeMatches:i=$.includeMatches,findAllMatches:a=$.findAllMatches,minMatchCharLength:o=$.minMatchCharLength,isCaseSensitive:s=$.isCaseSensitive,ignoreDiacritics:c=$.ignoreDiacritics,ignoreLocation:l=$.ignoreLocation}={}){if(this.options={location:t,threshold:n,distance:r,includeMatches:i,findAllMatches:a,minMatchCharLength:o,isCaseSensitive:s,ignoreDiacritics:c,ignoreLocation:l},e=s?e:e.toLowerCase(),e=c?Jt(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;let u=(e,t)=>{this.chunks.push({pattern:e,alphabet:Wt(e),startIndex:t})},d=this.pattern.length;if(d>Ht){let e=0,t=d%Ht,n=d-t;for(;e<n;)u(this.pattern.substr(e,Ht),e),e+=Ht;if(t){let e=d-Ht;u(this.pattern.substr(e),e)}}else u(this.pattern,0)}searchIn(e){let{isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=t?e:e.toLowerCase(),e=n?Jt(e):e,this.pattern===e){let t={isMatch:!0,score:0};return r&&(t.indices=[[0,e.length-1]]),t}let{location:i,distance:a,threshold:o,findAllMatches:s,minMatchCharLength:c,ignoreLocation:l}=this.options,u=[],d=0,f=!1;this.chunks.forEach(({pattern:t,alphabet:n,startIndex:p})=>{let{isMatch:m,score:h,indices:g}=Ut(e,t,n,{location:i+p,distance:a,threshold:o,findAllMatches:s,minMatchCharLength:c,includeMatches:r,ignoreLocation:l});m&&(f=!0),d+=h,m&&g&&u.push(...g)});let p={isMatch:f,score:f?d/this.chunks.length:1};return f&&r&&(p.indices=Gt(u)),p}},Xt=class{constructor(e){this.pattern=e}static isMultiMatch(e){return Zt(e,this.multiRegex)}static isSingleMatch(e){return Zt(e,this.singleRegex)}search(e){return{isMatch:!1,score:1}}};function Zt(e,t){let n=e.match(t);return n?n[1]:null}var Qt=class extends Xt{constructor(e){super(e)}static get type(){return`exact`}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){let t=e===this.pattern;return{isMatch:t,score:+!t,indices:[0,this.pattern.length-1]}}},$t=class extends Xt{constructor(e){super(e)}static get type(){return`inverse-exact`}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){let t=e.indexOf(this.pattern)===-1;return{isMatch:t,score:+!t,indices:[0,e.length-1]}}},en=class extends Xt{constructor(e){super(e)}static get type(){return`prefix-exact`}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){let t=e.startsWith(this.pattern);return{isMatch:t,score:+!t,indices:[0,this.pattern.length-1]}}},tn=class extends Xt{constructor(e){super(e)}static get type(){return`inverse-prefix-exact`}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){let t=!e.startsWith(this.pattern);return{isMatch:t,score:+!t,indices:[0,e.length-1]}}},nn=class extends Xt{constructor(e){super(e)}static get type(){return`suffix-exact`}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){let t=e.endsWith(this.pattern);return{isMatch:t,score:+!t,indices:[e.length-this.pattern.length,e.length-1]}}},rn=class extends Xt{constructor(e){super(e)}static get type(){return`inverse-suffix-exact`}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){let t=!e.endsWith(this.pattern);return{isMatch:t,score:+!t,indices:[0,e.length-1]}}},an=class extends Xt{constructor(e,{location:t=$.location,threshold:n=$.threshold,distance:r=$.distance,includeMatches:i=$.includeMatches,findAllMatches:a=$.findAllMatches,minMatchCharLength:o=$.minMatchCharLength,isCaseSensitive:s=$.isCaseSensitive,ignoreDiacritics:c=$.ignoreDiacritics,ignoreLocation:l=$.ignoreLocation}={}){super(e),this._bitapSearch=new Yt(e,{location:t,threshold:n,distance:r,includeMatches:i,findAllMatches:a,minMatchCharLength:o,isCaseSensitive:s,ignoreDiacritics:c,ignoreLocation:l})}static get type(){return`fuzzy`}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}},on=class extends Xt{constructor(e){super(e)}static get type(){return`include`}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let t=0,n,r=[],i=this.pattern.length;for(;(n=e.indexOf(this.pattern,t))>-1;)t=n+i,r.push([n,t-1]);let a=!!r.length;return{isMatch:a,score:+!a,indices:r}}},sn=[Qt,on,en,tn,rn,nn,$t,an],cn=sn.length,ln=`\0`,un=`|`;function dn(e){let t=[],n=e.length,r=0;for(;r<n;){for(;r<n&&e[r]===` `;)r++;if(r>=n)break;let i=r;for(;i<n&&e[i]!==` `&&e[i]!==`"`;)i++;if(i<n&&e[i]===`"`){for(i++;i<n;){if(e[i]===`"`){let t=i+1;if(t>=n||e[t]===` `){i++;break}if(e[t]===`$`&&(t+1>=n||e[t+1]===` `)){i+=2;break}}i++}t.push(e.substring(r,i)),r=i}else{for(;i<n&&e[i]!==` `;)i++;t.push(e.substring(r,i)),r=i}}return t}function fn(e,t={}){return e.replace(/\\\|/g,ln).split(un).map(e=>{let n=dn(e.replace(/\u0000/g,`|`).trim()).filter(e=>e&&!!e.trim()),r=[];for(let e=0,i=n.length;e<i;e+=1){let i=n[e],a=!1,o=-1;for(;!a&&++o<cn;){let e=sn[o],n=e.isMultiMatch(i);n&&(r.push(new e(n,t)),a=!0)}if(!a)for(o=-1;++o<cn;){let e=sn[o],n=e.isSingleMatch(i);if(n){r.push(new e(n,t));break}}}return r})}var pn=new Set([an.type,on.type]),mn=class{constructor(e,{isCaseSensitive:t=$.isCaseSensitive,ignoreDiacritics:n=$.ignoreDiacritics,includeMatches:r=$.includeMatches,minMatchCharLength:i=$.minMatchCharLength,ignoreLocation:a=$.ignoreLocation,findAllMatches:o=$.findAllMatches,location:s=$.location,threshold:c=$.threshold,distance:l=$.distance}={}){this.query=null,this.options={isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r,minMatchCharLength:i,findAllMatches:o,ignoreLocation:a,location:s,threshold:c,distance:l},e=t?e:e.toLowerCase(),e=n?Jt(e):e,this.pattern=e,this.query=fn(this.pattern,this.options)}static condition(e,t){return t.useExtendedSearch}searchIn(e){let t=this.query;if(!t)return{isMatch:!1,score:1};let{includeMatches:n,isCaseSensitive:r,ignoreDiacritics:i}=this.options;e=r?e:e.toLowerCase(),e=i?Jt(e):e;let a=0,o=[],s=0,c=!1;for(let r=0,i=t.length;r<i;r+=1){let i=t[r];o.length=0,a=0,c=!1;for(let t=0,r=i.length;t<r;t+=1){let r=i[t],{isMatch:l,indices:u,score:d}=r.search(e);if(l){a+=1,s+=d;let e=r.constructor.type;e.startsWith(`inverse`)&&(c=!0),n&&(pn.has(e)?o.push(...u):o.push(u))}else{s=0,a=0,o.length=0,c=!1;break}}if(a){let e={isMatch:!0,score:s/a};return c&&(e.hasInverse=!0),n&&(e.indices=Gt(o)),e}}return{isMatch:!1,score:1}}},hn=[];function gn(...e){hn.push(...e)}function _n(e,t){for(let n=0,r=hn.length;n<r;n+=1){let r=hn[n];if(r.condition(e,t))return new r(e,t)}return new Yt(e,t)}var vn={AND:`$and`,OR:`$or`},yn={PATH:`$path`,PATTERN:`$val`},bn=e=>!!(e[vn.AND]||e[vn.OR]),xn=e=>!!e[yn.PATH],Sn=e=>!ut(e)&&gt(e)&&!bn(e),Cn=e=>({[vn.AND]:Object.keys(e).map(t=>({[t]:e[t]}))});function wn(e,t,{auto:n=!0}={}){let r=e=>{if(pt(e)){let r={keyId:null,pattern:e};return n&&(r.searcher=_n(e,t)),r}let i=Object.keys(e),a=xn(e);if(!a&&i.length>1&&!bn(e))return r(Cn(e));if(Sn(e)){let r=a?e[yn.PATH]:i[0],o=a?e[yn.PATTERN]:e[r];if(!pt(o))throw Error(St(r));let s={keyId:At(r),pattern:o};return n&&(s.searcher=_n(o,t)),s}let o={children:[],operator:i[0]};return i.forEach(t=>{let n=e[t];ut(n)&&n.forEach(e=>{o.children.push(r(e))})}),o};return bn(e)||(e=Cn(e)),r(e)}function Tn(e,{ignoreFieldNorm:t=$.ignoreFieldNorm}){let n=1;return e.forEach(({key:e,norm:r,score:i})=>{let a=e?e.weight:null;n*=(i===0&&a?2**-52:i)**+((a||1)*(t?1:r))}),n}function En(e,{ignoreFieldNorm:t=$.ignoreFieldNorm}){e.forEach(e=>{e.score=Tn(e.matches,{ignoreFieldNorm:t})})}var Dn=class{constructor(e){this.limit=e,this.heap=[]}get size(){return this.heap.length}shouldInsert(e){return this.size<this.limit||e<this.heap[0].score}insert(e){this.size<this.limit?(this.heap.push(e),this._bubbleUp(this.size-1)):e.score<this.heap[0].score&&(this.heap[0]=e,this._sinkDown(0))}extractSorted(e){return this.heap.sort(e)}_bubbleUp(e){let t=this.heap;for(;e>0;){let n=e-1>>1;if(t[e].score<=t[n].score)break;let r=t[e];t[e]=t[n],t[n]=r,e=n}}_sinkDown(e){let t=this.heap,n=t.length,r=e;do{e=r;let i=2*e+1,a=2*e+2;if(i<n&&t[i].score>t[r].score&&(r=i),a<n&&t[a].score>t[r].score&&(r=a),r!==e){let n=t[e];t[e]=t[r],t[r]=n}}while(r!==e)}};function On(e,t){let n=e.matches;t.matches=[],vt(n)&&n.forEach(e=>{if(!vt(e.indices)||!e.indices.length)return;let{indices:n,value:r}=e,i={indices:n,value:r};e.key&&(i.key=e.key.src),e.idx>-1&&(i.refIndex=e.idx),t.matches.push(i)})}function kn(e,t){t.score=e.score}function An(e,t,{includeMatches:n=$.includeMatches,includeScore:r=$.includeScore}={}){let i=[];return n&&i.push(On),r&&i.push(kn),e.map(e=>{let{idx:n}=e,r={item:t[n],refIndex:n};return i.length&&i.forEach(t=>{t(e,r)}),r})}var jn=/\b\w+\b/g;function Mn({isCaseSensitive:e=!1,ignoreDiacritics:t=!1}={}){return{tokenize(n){return e||(n=n.toLowerCase()),t&&(n=Jt(n)),n.match(jn)||[]}}}function Nn(e,t,n){let r=new Map,i=new Map,a=0;function o(e,t,o,s){let c=n.tokenize(e);if(!c.length)return;a++;let l=new Map;for(let e of c)l.set(e,(l.get(e)||0)+1);for(let[e,n]of l){let a={docIdx:t,keyIdx:o,subIdx:s,tf:n},c=r.get(e);c||(c=[],r.set(e,c)),c.push(a),i.set(e,(i.get(e)||0)+1)}}for(let n of e){let{i:e,v:r,$:i}=n;if(r!==void 0){o(r,e,-1,-1);continue}if(i)for(let n=0;n<t;n++){let t=i[n];if(t)if(Array.isArray(t))for(let r of t)o(r.v,e,n,r.i??-1);else o(t.v,e,n,-1)}}return{terms:r,fieldCount:a,df:i}}function Pn(e,t,n,r){let{i,v:a,$:o}=t;function s(t,n,a){let o=r.tokenize(t);if(!o.length)return;e.fieldCount++;let s=new Map;for(let e of o)s.set(e,(s.get(e)||0)+1);for(let[t,r]of s){let o={docIdx:i,keyIdx:n,subIdx:a,tf:r},s=e.terms.get(t);s||(s=[],e.terms.set(t,s)),s.push(o),e.df.set(t,(e.df.get(t)||0)+1)}}if(a!==void 0){s(a,-1,-1);return}if(o)for(let e=0;e<n;e++){let t=o[e];if(t)if(Array.isArray(t))for(let n of t)s(n.v,e,n.i??-1);else s(t.v,e,-1)}}function Fn(e,t){for(let[n,r]of e.terms){let i=r.filter(e=>e.docIdx!==t),a=r.length-i.length;a>0&&(e.fieldCount-=a,e.df.set(n,(e.df.get(n)||0)-a),i.length===0?(e.terms.delete(n),e.df.delete(n)):e.terms.set(n,i))}}var In=class{constructor(e,t,n){this.options={...$,...t},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new Dt(this.options.keys),this._docs=e,this._myIndex=null,this._invertedIndex=null,this.setCollection(e,n),this._lastQuery=null,this._lastSearcher=null}_getSearcher(e){if(this._lastQuery===e)return this._lastSearcher;let t=_n(e,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=e,this._lastSearcher=t,t}setCollection(e,t){if(this._docs=e,t&&!(t instanceof Rt))throw Error(xt);if(this._myIndex=t||zt(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){let e=Mn({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});this._invertedIndex=Nn(this._myIndex.records,this._myIndex.keys.length,e)}}add(e){if(vt(e)&&(this._docs.push(e),this._myIndex.add(e),this._invertedIndex)){let e=this._myIndex.records[this._myIndex.records.length-1],t=Mn({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});Pn(this._invertedIndex,e,this._myIndex.keys.length,t)}}remove(e=()=>!1){let t=[],n=[];for(let r=0,i=this._docs.length;r<i;r+=1)e(this._docs[r],r)&&(t.push(this._docs[r]),n.push(r));if(n.length){if(this._invertedIndex)for(let e of n)Fn(this._invertedIndex,e);for(let e=n.length-1;e>=0;--e)this._docs.splice(n[e],1);this._myIndex.removeAll(n)}return t}removeAt(e){this._invertedIndex&&Fn(this._invertedIndex,e);let t=this._docs.splice(e,1)[0];return this._myIndex.removeAt(e),t}getIndex(){return this._myIndex}search(e,t){let{limit:n=-1}=t||{},{includeMatches:r,includeScore:i,shouldSort:a,sortFn:o,ignoreFieldNorm:s}=this.options;if(pt(e)&&!e.trim()){let e=this._docs.map((e,t)=>({item:e,refIndex:t}));return mt(n)&&n>-1&&(e=e.slice(0,n)),e}let c=mt(n)&&n>0&&pt(e),l;if(c){let t=new Dn(n);pt(this._docs[0])?this._searchStringList(e,{heap:t,ignoreFieldNorm:s}):this._searchObjectList(e,{heap:t,ignoreFieldNorm:s}),l=t.extractSorted(o)}else l=pt(e)?pt(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e),En(l,{ignoreFieldNorm:s}),a&&l.sort(o),mt(n)&&n>-1&&(l=l.slice(0,n));return An(l,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(e,{heap:t,ignoreFieldNorm:n}={}){let r=this._getSearcher(e),{records:i}=this._myIndex,a=t?null:[];return i.forEach(({v:e,i,n:o})=>{if(!vt(e))return;let{isMatch:s,score:c,indices:l}=r.searchIn(e);if(s){let r={item:e,idx:i,matches:[{score:c,value:e,norm:o,indices:l}]};t?(r.score=Tn(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):a.push(r)}}),a}_searchLogical(e){let t=wn(e,this.options),n=(e,t,r)=>{if(!(`children`in e)){let{keyId:n,searcher:i}=e,a;return n===null?(a=[],this._myIndex.keys.forEach((e,n)=>{a.push(...this._findMatches({key:e,value:t[n],searcher:i}))})):a=this._findMatches({key:this._keyStore.get(n),value:this._myIndex.getValueForItemAtKeyId(t,n),searcher:i}),a&&a.length?[{idx:r,item:t,matches:a}]:[]}let{children:i,operator:a}=e,o=[];for(let e=0,s=i.length;e<s;e+=1){let s=i[e],c=n(s,t,r);if(c.length)o.push(...c);else if(a===vn.AND)return[]}return o},r=this._myIndex.records,i=new Map,a=[];return r.forEach(({$:e,i:r})=>{if(vt(e)){let o=n(t,e,r);o.length&&(i.has(r)||(i.set(r,{idx:r,item:e,matches:[]}),a.push(i.get(r))),o.forEach(({matches:e})=>{i.get(r).matches.push(...e)}))}}),a}_searchObjectList(e,{heap:t,ignoreFieldNorm:n}={}){let r=this._getSearcher(e),{keys:i,records:a}=this._myIndex,o=t?null:[];return a.forEach(({$:e,i:a})=>{if(!vt(e))return;let s=[],c=!1,l=!1;if(i.forEach((t,n)=>{let i=this._findMatches({key:t,value:e[n],searcher:r});i.length?(s.push(...i),i[0].hasInverse&&(l=!0)):c=!0}),!(l&&c)&&s.length){let r={idx:a,item:e,matches:s};t?(r.score=Tn(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):o.push(r)}}),o}_findMatches({key:e,value:t,searcher:n}){if(!vt(t))return[];let r=[];if(ut(t))t.forEach(({v:t,i,n:a})=>{if(!vt(t))return;let{isMatch:o,score:s,indices:c,hasInverse:l}=n.searchIn(t);o&&r.push({score:s,key:e,value:t,idx:i,norm:a,indices:c,hasInverse:l})});else{let{v:i,n:a}=t,{isMatch:o,score:s,indices:c,hasInverse:l}=n.searchIn(i);o&&r.push({score:s,key:e,value:i,norm:a,indices:c,hasInverse:l})}return r}},Ln=class{static condition(e,t){return t.useTokenSearch}constructor(e,t){this.options=t,this.analyzer=Mn({isCaseSensitive:t.isCaseSensitive,ignoreDiacritics:t.ignoreDiacritics});let n=this.analyzer.tokenize(e),{df:r,fieldCount:i}=t._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(let e of n){this.termSearchers.push(new Yt(e,{location:t.location,threshold:t.threshold,distance:t.distance,includeMatches:t.includeMatches,findAllMatches:t.findAllMatches,minMatchCharLength:t.minMatchCharLength,isCaseSensitive:t.isCaseSensitive,ignoreDiacritics:t.ignoreDiacritics,ignoreLocation:!0}));let n=r.get(e)||0,a=Math.log(1+(i-n+.5)/(n+.5));this.idfWeights.push(a)}}searchIn(e){if(!this.termSearchers.length)return{isMatch:!1,score:1};let t=[],n=0,r=0,i=0;for(let a=0;a<this.termSearchers.length;a++){let o=this.termSearchers[a].searchIn(e),s=this.idfWeights[a];r+=s,o.isMatch&&(i++,n+=s*(1-o.score),o.indices&&t.push(...o.indices))}if(i===0)return{isMatch:!1,score:1};let a=r>0?1-n/r:0,o={isMatch:!0,score:Math.max(.001,a)};return this.options.includeMatches&&t.length&&(o.indices=Gt(t)),o}};In.version=`7.3.0`,In.createIndex=zt,In.parseIndex=Bt,In.config=$,In.match=function(e,t,n){return _n(e,{...$,...n}).searchIn(t)},In.parseQuery=wn,gn(mn),gn(Ln),In.use=function(...e){e.forEach(e=>gn(e))};var Rn=[{text:`text-red-400`,bgCircle:`bg-red-400`,bgCard:`bg-red-500/[0.08]`,borderCard:`border-red-500/30`,bgLight:`bg-red-500/15`,bgHover:`hover:bg-red-500`,bgAlt:`bg-red-500/[0.04]`,name:`Red`},{text:`text-orange-400`,bgCircle:`bg-orange-400`,bgCard:`bg-orange-500/[0.08]`,borderCard:`border-orange-500/30`,bgLight:`bg-orange-500/15`,bgHover:`hover:bg-orange-500`,bgAlt:`bg-orange-500/[0.04]`,name:`Orange`},{text:`text-yellow-400`,bgCircle:`bg-yellow-400`,bgCard:`bg-yellow-500/[0.08]`,borderCard:`border-yellow-500/30`,bgLight:`bg-yellow-500/15`,bgHover:`hover:bg-yellow-500`,bgAlt:`bg-yellow-500/[0.04]`,name:`Yellow`},{text:`text-green-400`,bgCircle:`bg-green-400`,bgCard:`bg-green-500/[0.08]`,borderCard:`border-green-500/30`,bgLight:`bg-green-500/15`,bgHover:`hover:bg-green-500`,bgAlt:`bg-green-500/[0.04]`,name:`Green`},{text:`text-blue-400`,bgCircle:`bg-blue-400`,bgCard:`bg-blue-500/[0.08]`,borderCard:`border-blue-500/30`,bgLight:`bg-blue-500/15`,bgHover:`hover:bg-blue-500`,bgAlt:`bg-blue-500/[0.04]`,name:`Blue`},{text:`text-accent`,bgCircle:`bg-accent`,bgCard:`bg-accent/[0.08]`,borderCard:`border-accent/30`,bgLight:`bg-accent/15`,bgHover:`hover:bg-accent`,bgAlt:`bg-accent/[0.04]`,name:`Purple`},{text:`text-pink-400`,bgCircle:`bg-pink-400`,bgCard:`bg-pink-500/[0.08]`,borderCard:`border-pink-500/30`,bgLight:`bg-pink-500/15`,bgHover:`hover:bg-pink-500`,bgAlt:`bg-pink-500/[0.04]`,name:`Pink`},{text:`text-foreground/60`,bgCircle:`bg-foreground/30`,bgCard:`bg-foreground/[0.04]`,borderCard:`border-[var(--panel-border)]/50`,bgLight:`bg-foreground/15`,bgHover:`hover:bg-foreground/30`,bgAlt:`bg-foreground/[0.02]`,name:`Default`}];function zn({title:e=`Table View`,subtitle:n=`/templates/table`,backUrl:a=`/templates`,tableCollection:o=`pub_table_data`,config:l,customContent:u}){let{user:d}=A(),f=!!l,p=l?.isInternal||l?.isShared;l?.isPrivate&&l?.isAdmin;let m=l?.isAdmin||p,h=f?m:!0,g=l?.showButton!==!1,_=l?.buttonText||`+`,v=l?.buttonStyle||`secondary`,y=l?.showExportButton!==!1,[b,x]=(0,r.useState)([]),[S,C]=(0,r.useState)(`demo`),[w,T]=(0,r.useState)(!1),[E,D]=(0,r.useState)(!1),[O,k]=(0,r.useState)(``),[j,M]=(0,r.useState)(!1),[N,P]=(0,r.useState)(null),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)(``),[ee,z]=(0,r.useState)(``),[te,B]=(0,r.useState)(null),[ne,V]=(0,r.useState)(null),[H,U]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=o.startsWith(`user_`);if(e&&!d)return;try{let e=localStorage.getItem(`fbos_tables_${o}`);e&&x(JSON.parse(e))}catch{}let n=(0,i.onSnapshot)(e&&d?(0,i.query)((0,i.collection)(t.Pt,o),(0,i.where)(`uid`,`==`,d.uid)):(0,i.collection)(t.Pt,o),e=>{let n=[];if(e.forEach(e=>{n.push({id:e.id,...e.data()})}),n.length===0){let e={name:`Unnamed Table`,columns:[`Column 1`,`Column 2`,`Column 3`,`Column 4`],...d?{uid:d.uid}:{},rows:[{id:`1`,"Column 1":``,"Column 2":``,"Column 3":``,"Column 4":``},{id:`2`,"Column 1":``,"Column 2":``,"Column 3":``,"Column 4":``}]};(0,i.setDoc)((0,i.doc)(t.Pt,o,`demo`),e)}else{let e=n.sort((e,t)=>(e.name||``).localeCompare(t.name||``));x(e),localStorage.setItem(`fbos_tables_${o}`,JSON.stringify(e))}});return()=>n()},[o,d]);let G=b.find(e=>e.id===S)||b[0]||{columns:[],rows:[]},K=async e=>{G.id&&(d&&o.startsWith(`user_`)&&(e.uid=d.uid),await(0,i.setDoc)((0,i.doc)(t.Pt,o,G.id),e,{merge:!0}))},q=()=>{if(!G.rows||G.rows.length===0)return;let e=G.columns.join(`,`),t=G.rows.map(e=>G.columns.map(t=>`"${e[t]||``}"`).join(`,`)).join(`
30
+ `),n=new Blob([`${e}\n${t}`],{type:`text/csv`}),r=window.URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`export_${G.name||`table`}.csv`,i.click(),window.URL.revokeObjectURL(r)},J=(e,t,n)=>{K({...G,rows:G.rows.map(r=>r.id===e?{...r,[t]:n}:r)})},Y=()=>{let e={id:Date.now().toString()};G.columns.forEach(t=>e[t]=``),K({...G,rows:[...G.rows||[],e]})},re=e=>{K({...G,rows:G.rows.filter(t=>t.id!==e)})},ie=()=>{let e=`Column ${(G.columns?.length||0)+1}`;G.columns?.includes(e)||(K({...G,columns:[...G.columns||[],e]}),setTimeout(()=>{let e=document.getElementById(`table-scroll-container`);e&&e.scrollTo({left:e.scrollWidth,behavior:`smooth`})},100))},ae=e=>{let t=(G.columns||[]).filter(t=>t!==e),n=(G.rows||[]).map(t=>{let n={...t};return delete n[e],n}),r={...G.colColors||{}};delete r[e],K({...G,columns:t,rows:n,colColors:r})},oe=async e=>{e.trim()&&G.id&&e!==G.name&&await(0,i.setDoc)((0,i.doc)(t.Pt,o,G.id),{name:e},{merge:!0})},se=async()=>{M(!0),T(!1);let e=`tbl_${Date.now()}`;await(0,i.setDoc)((0,i.doc)(t.Pt,o,e),{name:`Unnamed Table`,columns:[`Column 1`,`Column 2`,`Column 3`],...d?{uid:d.uid}:{},rows:[]}),setTimeout(()=>{C(e),M(!1)},600)},X=e=>{let t=ee.trim();if(t&&t!==e&&!G.columns?.includes(t)){let n=G.columns.map(n=>n===e?t:n),r=(G.rows||[]).map(n=>{let r={...n};return r[t]=r[e]||``,delete r[e],r}),i={...G.colColors||{}};i[e]&&(i[t]=i[e],delete i[e]),K({...G,columns:n,rows:r,colColors:i})}I(null)},ce=G.rows||[];return L.trim()!==``&&(ce=new In(ce.map(e=>({...e,_creatorMatch:`Guest`})),{keys:(G.columns||[]).concat([`_creatorMatch`]),threshold:.4,ignoreLocation:!0}).search(L).map(e=>{let{_creatorMatch:t,...n}=e.item;return 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)(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}),n&&(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`}),n]})]}),f&&(0,s.jsx)(`div`,{className:`mb-6`,children:(0,s.jsx)(W,{})}),(0,s.jsxs)(`div`,{className:`flex justify-between items-center mb-6 border-b border-[var(--panel-border)] pb-6 relative z-20`,children:[!f&&a&&(0,s.jsxs)(c.Link,{to:a,className:`px-4 md:px-5 py-2.5 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold hover:bg-foreground/5 transition-all flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4`}),` `,(0,s.jsx)(`span`,{className:`hidden sm:inline`,children:`Go Back`})]}),f&&(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:l?.tabTitle||l?.tabName||e}),(0,s.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[b.length,` `,b.length===1?`table`:`tables`]})]}),(0,s.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[y&&(0,s.jsx)(t.r,{variant:`secondary`,onClick:q,className:`px-3 py-2.5 font-bold rounded-xl shadow-sm border border-[var(--panel-border)] flex items-center gap-2`,children:(0,s.jsx)(t.rt,{className:`w-4 h-4`})}),g&&(0,s.jsx)(t.r,{variant:v===`primary`?void 0:`secondary`,onClick:Y,className:`px-3 py-2.5 font-bold rounded-xl border border-[var(--panel-border)] shadow-sm flex items-center gap-2`,children:_===`+`?(0,s.jsx)(t.k,{className:`w-4 h-4`}):_})]})]}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative z-10 block`,children:[(0,s.jsx)(`div`,{className:`absolute top-0 right-0 w-[400px] h-[400px] bg-accent/5 blur-[100px] rounded-full pointer-events-none -z-10`}),(0,s.jsxs)(`div`,{className:`p-4 md:px-6 border-b border-[var(--panel-border)]/50 flex flex-col sm:flex-row items-start sm:items-center justify-between bg-foreground/[0.01] gap-4`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col w-full sm:w-auto relative`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 relative`,children:[(0,s.jsxs)(`div`,{className:`relative flex items-center`,children:[E?(0,s.jsx)(`div`,{contentEditable:!0,suppressContentEditableWarning:!0,onBlur:e=>{D(!1),oe(e.currentTarget.textContent||``)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},className:`bg-transparent border-b-2 border-accent outline-none text-[16px] font-bold text-foreground inline-block min-w-[20px] whitespace-nowrap px-1 py-0.5`,children:G.name||`Unnamed Table`}):(0,s.jsx)(`h3`,{className:`font-bold text-[16px] text-foreground/90 cursor-pointer hover:text-accent transition-colors truncate max-w-[200px]`,onClick:()=>D(!0),title:`Click to rename table`,children:G.name||`Unnamed Table`}),(0,s.jsx)(t.s,{children:w&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>T(!1)}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:`absolute top-[120%] left-0 w-[220px] bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] rounded-2xl shadow-2xl z-50 py-2 flex flex-col`,children:[(0,s.jsx)(`div`,{className:`px-4 py-2 text-[10px] font-bold uppercase tracking-wider text-foreground/40 border-b border-[var(--panel-border)] mb-1`,children:`Your Tables`}),(0,s.jsx)(`div`,{className:`max-h-[250px] overflow-y-auto styled-scrollbars z-50 relative`,children:b.map(e=>(0,s.jsx)(`button`,{onClick:()=>{C(e.id),T(!1)},className:`w-full px-4 py-2 text-[13px] font-bold text-left hover:bg-foreground/[0.03] transition-colors truncate ${S===e.id?`text-accent bg-accent/5`:`text-foreground/70`}`,children:e.name||`Unnamed Table`},e.id))}),(0,s.jsx)(`div`,{className:`w-full h-[1px] bg-[var(--panel-border)]/50 my-1`}),(0,s.jsxs)(`button`,{onClick:se,className:`w-full px-4 py-2.5 text-[13px] font-bold text-left text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors flex items-center gap-2`,children:[(0,s.jsx)(t.k,{className:`w-4 h-4`}),` Create New Table`]})]})]})})]}),(0,s.jsx)(`button`,{onClick:()=>T(!w),className:`p-1 px-1.5 rounded-lg hover:bg-foreground/5 transition-colors text-foreground/40 hover:text-foreground shrink-0 border border-transparent hover:border-[var(--panel-border)]`,children:(0,s.jsx)(t.gt,{className:`w-4 h-4 transition-transform ${w?`rotate-180 text-accent`:``}`})})]}),(0,s.jsxs)(`span`,{className:`opacity-40 text-[11px] font-bold mt-1 uppercase tracking-wider`,children:[(G.rows||[]).length,` Records`]})]}),(0,s.jsxs)(`div`,{className:`relative w-full sm:max-w-[300px]`,children:[(0,s.jsx)(t.E,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-foreground/40`}),(0,s.jsx)(`input`,{type:`text`,placeholder:`Search active records...`,value:L,onChange:e=>R(e.target.value),className:`w-full bg-background border border-[var(--panel-border)] rounded-xl py-2.5 px-9 text-[13px] font-medium text-foreground focus:outline-none focus:border-accent transition-colors shadow-inner`})]})]}),(0,s.jsx)(`div`,{id:`table-scroll-container`,className:`overflow-x-auto w-full block min-h-[300px] relative styled-scrollbars`,children:u?(0,s.jsx)(`div`,{className:`fbos-content-slot p-4 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:(0,s.jsx)(u,{config:l,actions:{tables:b,activeTable:G,collection:o,user:d,saveTable:async(e,n)=>{x(t=>t.find(t=>t.id===e)?t.map(t=>t.id===e?{...t,...n}:t):[...t,{id:e,...n}]),await(0,i.setDoc)((0,i.doc)(t.Pt,o,e),n,{merge:!0})},deleteTable:async e=>{x(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Pt,o,e))},updateCell:(e,t,n)=>J(e,t,n),addRow:()=>Y(),addColumn:()=>ie()}})}):(0,s.jsx)(t.s,{mode:`wait`,children:j?(0,s.jsxs)(t.o.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 flex flex-col items-center justify-center bg-background/40 backdrop-blur-[2px] z-50`,children:[(0,s.jsx)(`div`,{className:`w-8 h-8 rounded-full border-2 border-accent border-r-transparent animate-spin mb-4`}),(0,s.jsx)(`p`,{className:`text-[11px] font-bold text-foreground/50 uppercase tracking-widest`,children:`Generating Table`})]},`loader`):(0,s.jsxs)(t.o.table,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full text-left border-collapse table-auto relative min-w-[800px]`,children:[(0,s.jsx)(`thead`,{children:(0,s.jsxs)(`tr`,{className:`border-b border-[var(--panel-border)] transition-colors ${G.headerColor?Rn.find(e=>e.text===G.headerColor)?.bgAlt:`bg-foreground/[0.02]`}`,children:[(0,s.jsx)(`th`,{className:`py-4 px-6 text-[12px] font-bold uppercase tracking-wider whitespace-nowrap text-foreground/50 w-32 border-r border-[var(--panel-border)]/20 ${h?``:`hidden`}`,children:`Creator`}),(G.columns||[]).map((e,n)=>{let r=(G.colColors||{})[e],i=(G.colorTimestamps||{})[`col_${e}`]||0;G.headerColor;let a=(G.colorTimestamps||{}).header||0,o=`bg-transparent`,c=`text-foreground/50`;if(r&&r!==`none`&&i>=a){let e=Rn.find(e=>e.text===r);e&&(o=e.bgCard,c=e.text)}return(0,s.jsx)(`th`,{className:`py-3 px-6 text-[12px] font-bold uppercase tracking-wider relative group h-[53px] min-w-[120px] ${c} ${o} border-r border-[var(--panel-border)]/20 last:border-r-0 select-none align-middle`,children:(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-2 w-full h-full`,children:[F===e?(0,s.jsx)(`div`,{className:`flex-1 min-w-[50px]`,children:(0,s.jsx)(`span`,{contentEditable:!0,suppressContentEditableWarning:!0,onBlur:t=>{I(null),z(t.currentTarget.textContent||``),(t.currentTarget.textContent||``).trim()!==``&&X(e)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},className:`bg-transparent outline-none border-b border-accent/40 font-bold text-[12px] uppercase tracking-wider p-0 m-0 ${c} block w-full whitespace-nowrap overflow-hidden cursor-text`,ref:e=>{e&&requestAnimationFrame(()=>{e.focus()})},children:ee})}):(0,s.jsx)(`div`,{className:`flex items-center gap-2 flex-1 overflow-hidden`,onClick:()=>{I(e),z(e)},children:(0,s.jsx)(`span`,{className:`truncate cursor-text`,children:e})}),(0,s.jsxs)(`div`,{className:`relative shrink-0 flex items-center h-full gap-0.5`,children:[(0,s.jsx)(`button`,{onClick:()=>V(ne===e?null:e),className:`p-1.5 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity hover:bg-foreground/10 ${r&&r!==`none`?`!opacity-100`:``} text-current`,children:(0,s.jsx)(t.j,{className:`w-4 h-4`})}),(G.columns||[]).length>1&&(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ae(e)},className:`p-1.5 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500/10 text-foreground/30 hover:text-red-500`,title:`Delete column`,children:(0,s.jsx)(t.v,{className:`w-3.5 h-3.5`})}),ne===e&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>V(null)}),(0,s.jsxs)(`div`,{className:`absolute top-8 right-0 flex gap-1.5 bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-50 items-center`,children:[(0,s.jsx)(`button`,{onClick:t=>{t.preventDefault(),t.stopPropagation();let n={...G.colColors||{},[e]:`none`},r={...G.colorTimestamps||{},[`col_${e}`]:Date.now()};K({...G,colColors:n,colorTimestamps:r}),V(null)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Remove Color`,children:(0,s.jsx)(t.d,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Rn.map(t=>(0,s.jsx)(`button`,{onClick:n=>{n.preventDefault(),n.stopPropagation();let r={...G.colColors||{},[e]:t.text},i={...G.colorTimestamps||{},[`col_${e}`]:Date.now()};K({...G,colColors:r,colorTimestamps:i}),V(null)},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50 shrink-0`},t.name))]})]})]})]})},`col_${n}_${e}`)}),(0,s.jsx)(`th`,{className:`py-4 px-4 w-14 border-l border-[var(--panel-border)]/30 relative`,children:(0,s.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 relative z-20`,children:[(0,s.jsx)(`button`,{onClick:()=>U(!H),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${G.headerColor?Rn.find(e=>e.text===G.headerColor)?.text:`text-foreground/30`}`,children:(0,s.jsx)(t.j,{className:`w-4 h-4`})}),H&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>U(!1)}),(0,s.jsxs)(`div`,{className:`absolute top-6 right-8 flex gap-1.5 bg-background/90 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-50 items-center`,children:[(0,s.jsx)(`button`,{onClick:()=>{K({...G,headerColor:``}),U(!1)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Remove Header Color`,children:(0,s.jsx)(t.d,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Rn.map(e=>(0,s.jsx)(`button`,{onClick:()=>{let t={...G.colorTimestamps||{},header:Date.now()};K({...G,headerColor:e.text,colorTimestamps:t}),U(!1)},className:`w-4 h-4 rounded-full ${e.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50`},e.name))]})]}),(0,s.jsx)(`button`,{onClick:ie,className:`p-1.5 rounded-lg text-foreground/40 hover:text-accent hover:bg-accent/10 transition-colors flex items-center justify-center`,children:(0,s.jsx)(t.k,{className:`w-4 h-4`})})]})})]})}),(0,s.jsxs)(`tbody`,{children:[ce.map((e,n)=>{let r=n%2==1,i=(G.rowColors||{})[e.id],a=i?r?Rn.find(e=>e.text===i)?.bgAlt:Rn.find(e=>e.text===i)?.bgCard:r?`bg-foreground/[0.02]`:`bg-transparent`;return(0,s.jsxs)(`tr`,{className:`border-b border-[var(--panel-border)]/30 hover:bg-foreground/[0.04] transition-colors group`,children:[(0,s.jsx)(`td`,{className:`py-4 px-6 whitespace-nowrap h-[53px] border-r border-[var(--panel-border)]/20 ${a} ${h?``:`hidden`}`,children:(0,s.jsx)(`div`,{className:`flex items-center gap-2`,children:f&&d?(0,s.jsxs)(s.Fragment,{children:[d.photoURL?(0,s.jsx)(`img`,{src:d.photoURL,className:`w-5 h-5 rounded-full shrink-0 object-cover`}):(0,s.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/20 text-accent flex items-center justify-center text-[10px] font-bold shrink-0`,children:(d.displayName||d.email||`U`)[0].toUpperCase()}),(0,s.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/80 tracking-tight shrink-0`,children:d.displayName||d.email?.split(`@`)[0]||`User`})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/20 text-accent flex items-center justify-center text-[10px] font-bold shrink-0 shadow-inner group-hover:scale-110 transition-transform`,children:`G`}),(0,s.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/80 tracking-tight shrink-0`,children:`Guest`})]})})}),(G.columns||[]).map(t=>{let i=N?.id===e.id&&N?.field===t,a=(G.colColors||{})[t],o=(G.colorTimestamps||{})[`col_${t}`]||0,c=(G.rowColors||{})[e.id],l=(G.colorTimestamps||{})[`row_${e.id}`]||0,u=``;u=l>o?c===`none`?``:c:o>l?a===`none`?``:a:c===`none`?``:c||a||``,u===`none`&&(u=``);let d=u?Rn.find(e=>e.text===u):null,f=d?r?d.bgAlt:d.bgCard:r?`bg-foreground/[0.02]`:`bg-transparent`,p=d?d.text:`text-foreground/80`;return(0,s.jsxs)(`td`,{className:`py-4 px-6 whitespace-pre-wrap min-w-[120px] text-[14px] font-medium relative ${f} align-top border-r border-[var(--panel-border)]/10 last:border-r-0`,onClick:()=>!i&&P({id:e.id,field:t}),children:[i?(0,s.jsx)(`textarea`,{autoFocus:!0,value:e[t]||``,onChange:n=>J(e.id,t,n.target.value),onBlur:()=>P(null),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&P(null)},className:`absolute inset-0 bg-transparent !border-0 !outline-none focus:!outline-none focus:!ring-0 !ring-0 !shadow-none focus:!shadow-none p-4 px-6 text-[14px] font-medium w-full h-full caret-accent ${p} z-20 resize-none styled-scrollbars`}):null,(0,s.jsx)(`span`,{className:`block w-full min-h-[20px] break-words transition-all ${i?`opacity-0`:`opacity-100`} ${p} ${t===`Status`&&e[t]===`Active`&&!u?`text-green-500`:``}`,children:e[t]||(0,s.jsx)(`span`,{className:`opacity-30 italic font-normal`,children:`empty`})})]},`cell_${e.id||n}_${t}`)}),(0,s.jsx)(`td`,{className:`py-4 px-4 whitespace-nowrap text-right h-[53px] ${a} relative z-10`,children:(0,s.jsxs)(`div`,{className:`flex items-center justify-end gap-1 opacity-20 group-hover:opacity-100 transition-opacity relative`,children:[(0,s.jsx)(`button`,{onClick:()=>B(te===e.id?null:e.id),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${i?Rn.find(e=>e.text===i)?.text:`text-foreground/40`}`,children:(0,s.jsx)(t.j,{className:`w-4 h-4`})}),te===e.id&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>B(null)}),(0,s.jsxs)(`div`,{className:`absolute top-6 right-8 flex gap-1.5 bg-background/90 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-50 items-center`,children:[(0,s.jsx)(`button`,{onClick:t=>{t.preventDefault(),t.stopPropagation();let n={...G.rowColors||{},[e.id]:`none`},r={...G.colorTimestamps||{},[`row_${e.id}`]:Date.now()};K({...G,rowColors:n,colorTimestamps:r}),B(null)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Remove Row Color`,children:(0,s.jsx)(t.d,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Rn.map(t=>(0,s.jsx)(`button`,{onClick:()=>{let n={...G.colorTimestamps||{},[`row_${e.id}`]:Date.now()};K({...G,rowColors:{...G.rowColors||{},[e.id]:t.text},colorTimestamps:n}),B(null)},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50`},t.name))]})]}),(0,s.jsx)(`button`,{onClick:()=>re(e.id),className:`p-2 ml-auto rounded-lg text-foreground/20 hover:text-red-500 hover:bg-red-500/10 transition-colors flex items-center justify-center`,children:(0,s.jsx)(t.v,{className:`w-4 h-4`})})]})})]},e.id||`row_${n}`)}),ce.length===0&&(0,s.jsx)(`tr`,{children:(0,s.jsxs)(`td`,{colSpan:(G.columns||[]).length+2,className:`py-12 text-center text-foreground/40 text-[14px] font-medium border border-[var(--panel-border)] m-4 rounded-xl border-dashed`,children:[`No records found in `,G.name||`this table`,`.`]})}),(0,s.jsx)(`tr`,{children:(0,s.jsx)(`td`,{colSpan:(G.columns||[]).length+2,className:`py-2 px-4 border-none bg-foreground/[0.01]`,children:(0,s.jsx)(`div`,{className:`flex items-center gap-4`,children:(0,s.jsx)(`button`,{onClick:Y,className:`p-1.5 rounded-lg text-foreground/40 hover:text-accent hover:bg-accent/10 transition-colors flex items-center justify-center ml-2 border border-transparent hover:border-accent/20`,children:(0,s.jsx)(t.k,{className:`w-4 h-4`})})})})})]})]},`table`)})})]})]})}var Bn=[{text:`text-red-400`,bgCircle:`bg-red-400`,bgCard:`bg-red-500/[0.08]`,borderCard:`border-red-500/30`,bgLight:`bg-red-500/15`,bgHover:`hover:bg-red-500`,bgAlt:`bg-red-500/[0.04]`,name:`Red`},{text:`text-orange-400`,bgCircle:`bg-orange-400`,bgCard:`bg-orange-500/[0.08]`,borderCard:`border-orange-500/30`,bgLight:`bg-orange-500/15`,bgHover:`hover:bg-orange-500`,bgAlt:`bg-orange-500/[0.04]`,name:`Orange`},{text:`text-yellow-400`,bgCircle:`bg-yellow-400`,bgCard:`bg-yellow-500/[0.08]`,borderCard:`border-yellow-500/30`,bgLight:`bg-yellow-500/15`,bgHover:`hover:bg-yellow-500`,bgAlt:`bg-yellow-500/[0.04]`,name:`Yellow`},{text:`text-green-400`,bgCircle:`bg-green-400`,bgCard:`bg-green-500/[0.08]`,borderCard:`border-green-500/30`,bgLight:`bg-green-500/15`,bgHover:`hover:bg-green-500`,bgAlt:`bg-green-500/[0.04]`,name:`Green`},{text:`text-blue-400`,bgCircle:`bg-blue-400`,bgCard:`bg-blue-500/[0.08]`,borderCard:`border-blue-500/30`,bgLight:`bg-blue-500/15`,bgHover:`hover:bg-blue-500`,bgAlt:`bg-blue-500/[0.04]`,name:`Blue`},{text:`text-accent`,bgCircle:`bg-accent`,bgCard:`bg-accent/[0.08]`,borderCard:`border-accent/30`,bgLight:`bg-accent/15`,bgHover:`hover:bg-accent`,bgAlt:`bg-accent/[0.04]`,name:`Purple`},{text:`text-pink-400`,bgCircle:`bg-pink-400`,bgCard:`bg-pink-500/[0.08]`,borderCard:`border-pink-500/30`,bgLight:`bg-pink-500/15`,bgHover:`hover:bg-pink-500`,bgAlt:`bg-pink-500/[0.04]`,name:`Pink`},{text:`text-foreground/60`,bgCircle:`bg-foreground/30`,bgCard:`bg-foreground/[0.04]`,borderCard:`border-[var(--panel-border)]/50`,bgLight:`bg-foreground/15`,bgHover:`hover:bg-foreground/30`,bgAlt:`bg-foreground/[0.02]`,name:`Default`}],Vn={dateStr:``,title:``,description:``,time:`12:00`,duration:`60`,color:``,guestEmail:``,customFields:{}};function Hn({title:e=`Calendar View`,subtitle:n=`/templates/calendar`,backUrl:o=`/templates`,eventsCollection:l=`pub_events`,defaultTimeFormat:u=`12h`,config:d,customContent:f}){let p=!!(d?.isPrivate||d?.isAdmin||d?.isInternal||d?.isShared);d?.isAdmin,d?.isInternal||d?.isShared,d?.isPrivate;let m=d?.showButton!==!1,h=d?.buttonText||`+`,g=d?.buttonStyle||`primary`,_=d?.showViewsButton!==!1,v=d?.viewsButtonStyle||`secondary`,y=d?.defaultView||`calendar`,b=d?.customFields||[],x=l.startsWith(`user_`)?`user`:l.startsWith(`mem_`)?`internal`:l.startsWith(`admin_`)?`admin_only`:`public`,[S,C]=(0,r.useState)(()=>{try{let e=localStorage.getItem(`cal_view_${l}`);if(e===`list`||e===`month`)return e}catch{}return y===`board`?`list`:`month`}),[w,T]=(0,r.useState)([]),[E,D]=(0,r.useState)(!1),[O,k]=(0,r.useState)(null),[A,j]=(0,r.useState)(!1),[M,N]=(0,r.useState)(!1),[P,F]=(0,r.useState)(null),[I,L]=(0,r.useState)(Vn),[R,ee]=(0,r.useState)(new Date),[z,te]=(0,r.useState)(null),[B,ne]=(0,r.useState)(null),[V,H]=(0,r.useState)(!1),U=`cal_24h_${l}`,[G,K]=(0,r.useState)(()=>{try{let e=localStorage.getItem(U);if(e!==null)return e===`true`}catch{}return u===`24h`}),q=()=>{let e=!G;K(e);try{localStorage.setItem(U,String(e))}catch{}};(0,r.useEffect)(()=>{try{localStorage.setItem(`cal_view_${l}`,S)}catch{}},[S,l,x]);let J=()=>{let e=S===`month`?`list`:`month`;C(e);try{localStorage.setItem(`cal_view_${l}`,e)}catch{}},Y=()=>{try{return sessionStorage.getItem(`cal_guest_email`)||``}catch{return``}},ie=e=>{try{sessionStorage.setItem(`cal_guest_email`,e)}catch{}};(0,r.useEffect)(()=>(0,a.onAuthStateChanged)(t.Nt,async e=>{if(te(e),e&&x===`admin_only`)try{let n=await(0,i.getDoc)((0,i.doc)(t.Pt,`user_profiles`,e.uid));n.exists()&&ne(n.data())}catch{}H(!0)}),[x]),(0,r.useEffect)(()=>{if(!V)return;if(x!==`public`&&!z){T([]);return}try{let e=localStorage.getItem(`fbos_cal_${l}`);e&&T(JSON.parse(e))}catch{}let e=(0,i.onSnapshot)(x===`user`&&z?(0,i.query)((0,i.collection)(t.Pt,l),(0,i.where)(`uid`,`==`,z.uid)):(0,i.collection)(t.Pt,l),e=>{let t=[];e.forEach(e=>t.push({id:e.id,...e.data()})),T(t),localStorage.setItem(`fbos_cal_${l}`,JSON.stringify(t))},e=>console.error(`Calendar events:`,e));return()=>e()},[l,x,z?.uid,V]);let ae=e=>!!z&&z.uid===e.uid,oe=e=>x===`public`?!1:x===`user`?!!z:ae(e),se=e=>{if(!e)return``;if(G)return e;let[t,n]=e.split(`:`),r=parseInt(t,10),i=r>=12?`PM`:`AM`;return r=r%12||12,`${r}:${n} ${i}`},X=e=>{if(!e)return`60m`;let t=parseInt(e,10);return isNaN(t)?e:t>=60?t%60==0?`${t/60}h`:`${Math.floor(t/60)}h ${t%60}m`:`${t}m`},ce=e=>{let[t,n]=(e||`12:00`).split(`:`),r=parseInt(t,10)||0,i=parseInt(n,10)||0,a=r>=12?`PM`:`AM`;return r=r%12||12,{h:r,m:i,ampm:a}},Z=(e,t,n)=>{let r=e%12;return n===`PM`&&(r+=12),`${r.toString().padStart(2,`0`)}:${t.toString().padStart(2,`0`)}`},Q=e=>{let t=e.getTimezoneOffset()*6e4;return new Date(e.getTime()-t).toISOString().split(`T`)[0]},le=()=>Q(new Date),ue=new Date(R.getFullYear(),R.getMonth(),1),de=new Date(R.getFullYear(),R.getMonth()+1,0),fe=ue.getDay(),pe=de.getDate(),me=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],he=Array.from({length:42},(e,t)=>{let n=t-fe+1,r=new Date(R.getFullYear(),R.getMonth(),n);return{day:r.getDate(),dateStr:Q(r),isCurrentMonth:n>0&&n<=pe}}),ge=()=>ee(S===`month`?new Date(R.getFullYear(),R.getMonth()-1,1):new Date(R.getFullYear(),R.getMonth(),R.getDate()-1)),_e=()=>ee(S===`month`?new Date(R.getFullYear(),R.getMonth()+1,1):new Date(R.getFullYear(),R.getMonth(),R.getDate()+1)),ve=e=>{if(x!==`public`&&!z)return;let t=new Date;t.setDate(t.getDate()+1);let n=new Date().getHours().toString().padStart(2,`0`);L({...Vn,dateStr:e||Q(t),time:`${n}:00`,guestEmail:x===`public`?Y():``,customFields:{}}),D(!0)},ye=e=>{let t=e.time;if(t){let[e,n]=t.split(`:`);e&&n&&(t=`${e.padStart(2,`0`)}:${n}`)}L({id:e.id,uid:e.uid,dateStr:e.dateStr,title:e.title,description:e.description||``,time:t||`12:00`,duration:e.duration||`60`,color:e.color||``,guestEmail:e.creatorEmail||``,customFields:e.customFields||{}}),D(!0)},be=async e=>{if(e.preventDefault(),I.title.trim()){j(!0);try{let e={dateStr:I.dateStr,title:I.title.trim(),description:I.description.trim(),time:I.time,duration:I.duration||`60`};if(I.color&&(e.color=I.color),b.length>0&&(e.customFields=I.customFields),!I.id)if(x===`public`){let t=I.guestEmail.trim();e.creatorEmail=t,ie(t)}else x===`user`||x===`internal`?(e.uid=z?.uid,e.creatorEmail=z?.email||``,e.creatorName=z?.displayName||``,e.creatorAvatar=z?.photoURL||``):x===`admin_only`&&(e.uid=z?.uid,e.creatorEmail=B?.email||z?.email||``,e.creatorName=B?.displayName||B?.name||``,e.creatorAvatar=B?.avatar||B?.avatarUrl||z?.photoURL||``);I.id?(await(0,i.setDoc)((0,i.doc)(t.Pt,l,I.id),e,{merge:!0}),O?.id===I.id&&k({...O,...e})):await(0,i.setDoc)((0,i.doc)(t.Pt,l,`ev_${Date.now()}`),e,{merge:!0}),D(!1)}catch(e){console.error(e)}j(!1)}},xe=async()=>{if(P){N(!0);try{await(0,i.deleteDoc)((0,i.doc)(t.Pt,l,P.id)),O?.id===P.id&&k(null),F(null),D(!1)}catch{}N(!1)}},Se=e=>{if(x===`user`||!e.creatorEmail&&!e.creatorName)return null;let t=(e.creatorName||e.creatorEmail||`?`).charAt(0).toUpperCase(),n=Bn.find(t=>t.text===e.color);return(0,s.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 p-3 rounded-xl bg-foreground/[0.03] border border-[var(--panel-border)]/50`,children:[e.creatorAvatar?(0,s.jsx)(`img`,{src:e.creatorAvatar,alt:``,className:`w-8 h-8 rounded-full object-cover shrink-0`}):(0,s.jsx)(`div`,{className:`w-8 h-8 rounded-full ${n?.bgCircle||`bg-accent`} flex items-center justify-center text-[13px] font-extrabold text-white shrink-0`,children:t}),(0,s.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[e.creatorName&&(0,s.jsx)(`span`,{className:`text-[13px] font-bold text-foreground/90 truncate`,children:e.creatorName}),e.creatorEmail&&(0,s.jsx)(`span`,{className:`text-[12px] text-foreground/50 truncate`,children:e.creatorEmail})]})]})},Ce=e=>{if(x===`user`||x===`public`||!e.creatorName&&!e.creatorEmail)return null;let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||``,n=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,s.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[e.creatorAvatar?(0,s.jsx)(`img`,{src:e.creatorAvatar,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:n}),(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}),e.creatorEmail&&(0,s.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,e.creatorEmail]})]})]})};if(V&&x!==`public`&&!z)return(0,s.jsx)(`main`,{className:`flex-1 w-full flex items-center justify-center min-h-screen p-8`,children:(0,s.jsxs)(`div`,{className:`text-center glass-panel border border-[var(--panel-border)] rounded-3xl p-12 max-w-sm w-full`,children:[(0,s.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-accent/10 border border-accent/20 flex items-center justify-center mx-auto mb-4`,children:(0,s.jsx)(t.P,{className:`w-7 h-7 text-accent`})}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold mb-2`,children:`Sign in required`}),(0,s.jsx)(`p`,{className:`text-foreground/50 text-[14px] mb-6`,children:`You need to be signed in to access this calendar.`}),(0,s.jsx)(c.Link,{to:`/login`,className:`inline-flex items-center justify-center gap-2 px-6 py-2.5 rounded-xl btn-primary font-bold text-[14px] w-full`,children:`Sign In`})]})});if(!V&&x!==`public`)return(0,s.jsx)(`main`,{className:`flex-1 w-full flex items-center justify-center min-h-screen`,children:(0,s.jsx)(t.L,{className:`w-8 h-8 animate-spin text-accent`})});let we=(x===`public`||!!z)&&m,Te=()=>(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:d?.tabTitle||d?.tabName||e}),(0,s.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[w.length,` `,w.length===1?`event`:`events`,` · `,S===`month`?`Month`:`Board`,` View`]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:q,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer btn-secondary text-[12px] font-extrabold`,children:G?`24h`:`12h`}),_&&(0,s.jsx)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:J,title:S===`month`?`Switch to Board`:`Switch to Calendar`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${v===`primary`?`btn-primary`:`btn-secondary`}`,children:S===`month`?(0,s.jsx)(t.V,{className:`w-4 h-4`}):(0,s.jsx)(t.bt,{className:`w-4 h-4`})}),we&&(0,s.jsx)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>ve(),className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${h===`+`?`w-10`:`px-5`} ${g===`primary`?`btn-primary`:`btn-secondary`}`,children:h===`+`?(0,s.jsx)(t.k,{className:`w-4 h-4`}):(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:h})})]})]}),Ee=()=>(0,s.jsxs)(`div`,{className:`p-4 md:p-6 border-b border-[var(--panel-border)]/50 flex items-center justify-between bg-foreground/[0.01]`,children:[(0,s.jsx)(`h3`,{className:`text-xl font-extrabold tracking-tight ml-2`,children:S===`month`?R.toLocaleString(`default`,{month:`long`,year:`numeric`}):R.toLocaleString(`default`,{month:`long`,day:`numeric`,year:`numeric`})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,s.jsx)(`button`,{onClick:()=>ee(new Date),className:`px-4 py-2 text-[13px] font-bold border border-[var(--panel-border)] rounded-xl mr-2 hover:bg-foreground/5 transition-colors`,children:`Today`}),(0,s.jsx)(`button`,{onClick:ge,className:`p-2 rounded-xl text-foreground/50 hover:text-foreground hover:bg-foreground/5 transition-colors border border-transparent hover:border-[var(--panel-border)]`,children:(0,s.jsx)(t.ht,{className:`w-5 h-5`})}),(0,s.jsx)(`button`,{onClick:_e,className:`p-2 rounded-xl text-foreground/50 hover:text-foreground hover:bg-foreground/5 transition-colors border border-transparent hover:border-[var(--panel-border)]`,children:(0,s.jsx)(t.mt,{className:`w-5 h-5`})})]})]}),De=()=>(0,s.jsxs)(s.Fragment,{children:[Ee(),f?(0,s.jsx)(`div`,{className:`fbos-content-slot p-4 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:(0,s.jsx)(f,{config:d,actions:{events:w,loading:!V,collection:l,currentUser:z,saveEvent:async e=>{let n=e.id||`ev_${Date.now()}`;T(t=>t.find(e=>e.id===n)?t.map(t=>t.id===n?{...t,...e}:t):[...t,{id:n,...e}]),await(0,i.setDoc)((0,i.doc)(t.Pt,l,n),e,{merge:!0})},deleteEvent:async e=>{T(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Pt,l,e))},openAddModal:e=>ve(e),openEditModal:e=>ye(e),setViewingEvent:e=>k(e)}})}):S===`month`?(0,s.jsx)(`div`,{className:`overflow-x-auto w-full flex-1`,children:(0,s.jsxs)(`div`,{className:`min-w-[800px] h-full flex flex-col`,children:[(0,s.jsx)(`div`,{className:`grid grid-cols-7 border-b border-[var(--panel-border)]/50 bg-foreground/[0.02]`,children:me.map(e=>(0,s.jsx)(`div`,{className:`py-3 text-center text-[12px] font-bold uppercase tracking-wider text-foreground/40`,children:e},e))}),(0,s.jsx)(`div`,{className:`grid grid-cols-7 auto-rows-auto bg-[var(--panel-border)] gap-[1px] relative flex-1`,children:he.map((e,n)=>{let r=e.dateStr===le(),i=w.filter(t=>t.dateStr===e.dateStr);return(0,s.jsxs)(`div`,{onClick:()=>e.isCurrentMonth&&we&&ve(e.dateStr),className:`min-h-[140px] p-2 bg-[var(--panel-bg)] flex flex-col relative group
31
+ ${e.isCurrentMonth?we?`hover:bg-foreground/[0.03] transition-colors cursor-cell`:``:`opacity-30 bg-background/50 pointer-events-none`}`,children:[(0,s.jsx)(`div`,{className:`flex justify-between items-start mb-2 shrink-0`,children:(0,s.jsx)(`span`,{className:`w-8 h-8 rounded-full flex items-center justify-center text-[14px] font-bold ${r?`bg-accent text-white shadow-lg shadow-accent/20`:`text-foreground/70 group-hover:text-foreground`}`,children:e.day})}),(0,s.jsx)(`div`,{className:`flex flex-col gap-1.5 flex-1 w-full relative z-10 pb-1`,children:i.map(e=>{let n=Bn.find(t=>t.text===e.color),r=oe(e);return(0,s.jsxs)(`div`,{className:`px-2 py-1.5 rounded-lg border transition-colors shadow-sm cursor-pointer group/ev relative ${n?n.bgCard+` `+n.borderCard:`bg-accent/20 border-accent/30 hover:bg-accent/40`}`,onClick:t=>{t.stopPropagation(),k(e)},children:[(0,s.jsx)(`p`,{className:`text-[12px] font-bold truncate leading-tight ${r?`pr-5`:``} ${n?n.text:`text-foreground`}`,children:e.title}),(0,s.jsx)(`p`,{className:`text-[10px] text-foreground/70 mt-0.5`,children:se(e.time)}),r&&(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ye(e)},className:`absolute top-1 right-1 opacity-0 group-hover/ev:opacity-100 p-1 text-foreground/60 hover:bg-foreground/10 hover:text-foreground transition-all rounded`,children:(0,s.jsx)(t.A,{className:`w-3 h-3`})})]},e.id)})})]},n)})}),(0,s.jsx)(`style`,{children:`
32
32
  .styled-scrollbars::-webkit-scrollbar{width:4px}
33
33
  .styled-scrollbars::-webkit-scrollbar-thumb{background:color-mix(in srgb,var(--accent-color) 30%,transparent);border-radius:4px}
34
34
  input[type="time"]::-webkit-calendar-picker-indicator{display:none!important}
35
35
  input[type="date"]{color-scheme:dark}
36
36
  input[type="date"]::-webkit-calendar-picker-indicator{cursor:pointer;opacity:.5;transition:opacity .2s}
37
37
  input[type="date"]::-webkit-calendar-picker-indicator:hover{opacity:1}
38
- `})]})}):(0,s.jsxs)(`div`,{className:`flex flex-col p-4 md:p-8 overflow-y-auto w-full flex-1 gap-4`,children:[w.filter(e=>e.dateStr===Q(R)).sort((e,t)=>e.time.localeCompare(t.time)).map(e=>{let n=new Date(e.dateStr+`T12:00:00`),r=zn.find(t=>t.text===e.color),i=oe(e);return(0,s.jsxs)(`div`,{onClick:()=>k(e),className:`p-4 rounded-2xl border flex flex-col cursor-pointer transition-colors group ${r?r.bgCard+` `+r.borderCard+` hover:brightness-110`:`bg-foreground/[0.01] border-[var(--panel-border)]/70 hover:border-accent/40 hover:bg-foreground/[0.02]`}`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,s.jsxs)(`div`,{className:`w-11 h-11 md:w-12 md:h-12 rounded-xl flex flex-col items-center justify-center border transition-colors shadow-sm ${r?r.bgCard+` `+r.borderCard:`bg-foreground/5 border-[var(--panel-border)] group-hover:bg-accent/10 group-hover:border-accent/30`}`,children:[(0,s.jsx)(`span`,{className:`text-[10px] font-bold uppercase leading-none mb-0.5 ${r?r.text:`text-foreground/40 group-hover:text-accent/60`}`,children:n.toLocaleString(`default`,{month:`short`})}),(0,s.jsx)(`span`,{className:`text-[18px] font-black leading-none ${r?r.text:`group-hover:text-accent`}`,children:n.getDate()})]}),(0,s.jsx)(`div`,{className:`h-6 w-px bg-[var(--panel-border)] hidden sm:block group-hover:bg-accent/30 transition-colors`})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-1 min-w-0 flex-1`,children:[(0,s.jsx)(`h4`,{className:`text-[15px] md:text-[16px] font-extrabold tracking-tight truncate ${r?r.text:`text-foreground group-hover:text-accent`}`,children:e.title}),(0,s.jsxs)(`div`,{className:`flex items-center gap-3 text-[12px] text-foreground/50 font-medium`,children:[(0,s.jsx)(`span`,{children:se(e.time)}),(0,s.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,s.jsx)(t.ct,{className:`w-3 h-3`}),X(e.duration)]})]})]}),i&&(0,s.jsxs)(`div`,{className:`ml-auto pl-2 flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ye(e)},className:`p-2.5 rounded-xl text-foreground/50 hover:bg-foreground/10 hover:text-foreground transition-colors`,children:(0,s.jsx)(t.A,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),F(e)},className:`p-2.5 rounded-xl text-foreground/30 hover:bg-red-500/10 hover:text-red-500 transition-colors`,children:(0,s.jsx)(t.v,{className:`w-4 h-4`})})]})]}),p&&Ce(e)]},e.id)}),w.filter(e=>e.dateStr===Q(R)).length===0&&(0,s.jsx)(`div`,{className:`p-12 text-center text-foreground/40 font-medium`,children:`No events scheduled for this day.`})]})]}),Oe=()=>(0,s.jsxs)(t.s,{children:[O&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>k(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(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:`w-full max-w-[500px] p-6 sm:p-8 rounded-3xl glass-popover border shadow-2xl relative z-10 ${zn.find(e=>e.text===O.color)?.borderCard||`border-[var(--panel-border)]`}`,children:[(0,s.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 bg-background/50 backdrop-blur-3xl p-1 rounded-2xl border border-[var(--panel-border)]/50 shadow-sm z-50`,children:[oe(O)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`button`,{onClick:()=>{k(null),ye(O)},className:`p-2 rounded-xl text-foreground/50 hover:bg-foreground/10 hover:text-foreground transition-all`,title:`Edit`,children:(0,s.jsx)(t.A,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{F(O),k(null)},className:`p-2 rounded-xl text-foreground/50 hover:bg-red-500/10 hover:text-red-500 transition-all`,title:`Delete`,children:(0,s.jsx)(t.v,{className:`w-4 h-4`})}),(0,s.jsx)(`div`,{className:`w-px h-6 bg-[var(--panel-border)]/50 mx-1`})]}),(0,s.jsx)(`button`,{onClick:()=>k(null),className:`p-2 rounded-xl text-foreground/40 hover:bg-foreground/10 hover:text-foreground transition-all`,children:(0,s.jsx)(t.d,{className:`w-5 h-5`})})]}),(0,s.jsxs)(`div`,{className:`mb-6 pr-32`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,s.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${zn.find(e=>e.text===O.color)?.bgCircle||`bg-accent`}`}),(0,s.jsx)(`span`,{className:`text-[11px] font-bold tracking-[0.2em] uppercase ${zn.find(e=>e.text===O.color)?.text||`text-accent`}`,children:`Event Details`})]}),(0,s.jsx)(`h3`,{className:`text-3xl font-black mb-3 tracking-tight leading-tight break-words ${zn.find(e=>e.text===O.color)?.text||`text-foreground`}`,children:O.title}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2 mt-4`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2.5 text-[14px] text-foreground/70 font-medium`,children:[(0,s.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.bt,{className:`w-4 h-4 text-foreground/50`})}),new Date(O.dateStr+`T12:00:00`).toLocaleDateString(`default`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2.5 text-[14px] text-foreground/70 font-medium`,children:[(0,s.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.ct,{className:`w-4 h-4 text-foreground/50`})}),se(O.time),` `,(0,s.jsxs)(`span`,{className:`text-foreground/40 text-[12px] ml-1`,children:[`(`,X(O.duration),`)`]})]})]}),Se(O)]}),(0,s.jsx)(`div`,{className:`w-full h-px bg-gradient-to-r from-[var(--panel-border)]/0 via-[var(--panel-border)] to-[var(--panel-border)]/0 mb-6`}),O.description?(0,s.jsx)(`div`,{className:`bg-foreground/[0.02] border border-[var(--panel-border)]/50 rounded-2xl py-3 px-4 mb-4 w-full overflow-hidden`,children:(0,s.jsx)(`div`,{className:`text-[14px] text-foreground/80 font-medium whitespace-pre-wrap leading-tight break-words`,children:O.description})}):(0,s.jsx)(`div`,{className:`p-4 mb-4 rounded-2xl border border-dashed border-[var(--panel-border)] bg-foreground/[0.01] text-center`,children:(0,s.jsx)(`p`,{className:`text-[12px] font-medium text-foreground/40`,children:`No description provided for this event.`})}),O.customFields&&Object.entries(O.customFields).filter(([,e])=>e).length>0&&(0,s.jsx)(`div`,{className:`flex flex-col gap-2 mb-2`,children:Object.entries(O.customFields).filter(([,e])=>e).map(([e,t])=>(0,s.jsxs)(`div`,{className:`flex items-start gap-2 text-[13px]`,children:[(0,s.jsxs)(`span`,{className:`font-bold text-foreground/50 capitalize shrink-0`,children:[e,`:`]}),(0,s.jsx)(`span`,{className:`text-foreground/80 font-medium break-words min-w-0`,children:t})]},e))})]})]},`view-modal`),E&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>D(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(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:`w-full max-w-[500px] p-6 sm:p-8 rounded-3xl glass-popover border border-[var(--panel-border)] shadow-2xl relative z-10 max-h-[90vh] overflow-y-auto styled-scrollbars`,children:[(0,s.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1`,children:[I.id&&oe({uid:I.uid})&&(0,s.jsx)(`button`,{onClick:()=>{D(!1),F({id:I.id,...I})},className:`p-2 rounded-xl text-foreground/30 hover:bg-red-500/10 hover:text-red-500 transition-all`,children:(0,s.jsx)(t.v,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>D(!1),className:`p-2 rounded-xl text-foreground/40 hover:bg-foreground/10 hover:text-foreground transition-all`,children:(0,s.jsx)(t.d,{className:`w-5 h-5`})})]}),(0,s.jsxs)(`div`,{className:`mb-6 pr-12`,children:[(0,s.jsx)(`h3`,{className:`text-2xl font-extrabold mb-1 tracking-tight`,children:I.id?`Edit Event`:`Add Event`}),(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/50`,children:I.id?`Modify your scheduled calendar block.`:`Schedule a new calendar block.`})]}),(0,s.jsxs)(`form`,{onSubmit:be,className:`space-y-4`,children:[x===`public`&&!I.id&&(0,s.jsx)(t.i,{label:`Your Email`,type:`email`,value:I.guestEmail,onChange:e=>L({...I,guestEmail:e.target.value}),placeholder:`you@example.com`,required:!0}),(0,s.jsx)(t.i,{label:`Event Title`,value:I.title,onChange:e=>L({...I,title:e.target.value}),placeholder:`e.g. Design Sync`,required:!0}),(0,s.jsxs)(`div`,{className:`flex flex-col w-full relative`,children:[(0,s.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Description`}),(0,s.jsx)(`textarea`,{value:I.description,onChange:e=>L({...I,description:e.target.value}),placeholder:`e.g. Discussing the new features...`,className:`block min-h-[80px] w-full rounded-xl text-[15px] text-foreground px-4 py-3 transition-all duration-300 placeholder:text-foreground/40 focus:outline-none focus:border-accent glow-focus glass-panel styled-scrollbars resize-none`})]}),b.map(e=>(0,s.jsx)(t.i,{label:e,value:I.customFields[e]||``,onChange:t=>L({...I,customFields:{...I.customFields,[e]:t.target.value}}),placeholder:`Enter ${e.toLowerCase()}...`},e)),(0,s.jsx)(`style`,{children:`
38
+ `})]})}):(0,s.jsxs)(`div`,{className:`flex flex-col p-4 md:p-8 overflow-y-auto w-full flex-1 gap-4`,children:[w.filter(e=>e.dateStr===Q(R)).sort((e,t)=>e.time.localeCompare(t.time)).map(e=>{let n=new Date(e.dateStr+`T12:00:00`),r=Bn.find(t=>t.text===e.color),i=oe(e);return(0,s.jsxs)(`div`,{onClick:()=>k(e),className:`p-4 rounded-2xl border flex flex-col cursor-pointer transition-colors group ${r?r.bgCard+` `+r.borderCard+` hover:brightness-110`:`bg-foreground/[0.01] border-[var(--panel-border)]/70 hover:border-accent/40 hover:bg-foreground/[0.02]`}`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,s.jsxs)(`div`,{className:`w-11 h-11 md:w-12 md:h-12 rounded-xl flex flex-col items-center justify-center border transition-colors shadow-sm ${r?r.bgCard+` `+r.borderCard:`bg-foreground/5 border-[var(--panel-border)] group-hover:bg-accent/10 group-hover:border-accent/30`}`,children:[(0,s.jsx)(`span`,{className:`text-[10px] font-bold uppercase leading-none mb-0.5 ${r?r.text:`text-foreground/40 group-hover:text-accent/60`}`,children:n.toLocaleString(`default`,{month:`short`})}),(0,s.jsx)(`span`,{className:`text-[18px] font-black leading-none ${r?r.text:`group-hover:text-accent`}`,children:n.getDate()})]}),(0,s.jsx)(`div`,{className:`h-6 w-px bg-[var(--panel-border)] hidden sm:block group-hover:bg-accent/30 transition-colors`})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-1 min-w-0 flex-1`,children:[(0,s.jsx)(`h4`,{className:`text-[15px] md:text-[16px] font-extrabold tracking-tight truncate ${r?r.text:`text-foreground group-hover:text-accent`}`,children:e.title}),(0,s.jsxs)(`div`,{className:`flex items-center gap-3 text-[12px] text-foreground/50 font-medium`,children:[(0,s.jsx)(`span`,{children:se(e.time)}),(0,s.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,s.jsx)(t.ct,{className:`w-3 h-3`}),X(e.duration)]})]})]}),i&&(0,s.jsxs)(`div`,{className:`ml-auto pl-2 flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ye(e)},className:`p-2.5 rounded-xl text-foreground/50 hover:bg-foreground/10 hover:text-foreground transition-colors`,children:(0,s.jsx)(t.A,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),F(e)},className:`p-2.5 rounded-xl text-foreground/30 hover:bg-red-500/10 hover:text-red-500 transition-colors`,children:(0,s.jsx)(t.v,{className:`w-4 h-4`})})]})]}),p&&Ce(e)]},e.id)}),w.filter(e=>e.dateStr===Q(R)).length===0&&(0,s.jsx)(`div`,{className:`p-12 text-center text-foreground/40 font-medium`,children:`No events scheduled for this day.`})]})]}),Oe=()=>(0,s.jsxs)(t.s,{children:[O&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>k(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(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:`w-full max-w-[500px] p-6 sm:p-8 rounded-3xl glass-popover border shadow-2xl relative z-10 ${Bn.find(e=>e.text===O.color)?.borderCard||`border-[var(--panel-border)]`}`,children:[(0,s.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 bg-background/50 backdrop-blur-3xl p-1 rounded-2xl border border-[var(--panel-border)]/50 shadow-sm z-50`,children:[oe(O)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`button`,{onClick:()=>{k(null),ye(O)},className:`p-2 rounded-xl text-foreground/50 hover:bg-foreground/10 hover:text-foreground transition-all`,title:`Edit`,children:(0,s.jsx)(t.A,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{F(O),k(null)},className:`p-2 rounded-xl text-foreground/50 hover:bg-red-500/10 hover:text-red-500 transition-all`,title:`Delete`,children:(0,s.jsx)(t.v,{className:`w-4 h-4`})}),(0,s.jsx)(`div`,{className:`w-px h-6 bg-[var(--panel-border)]/50 mx-1`})]}),(0,s.jsx)(`button`,{onClick:()=>k(null),className:`p-2 rounded-xl text-foreground/40 hover:bg-foreground/10 hover:text-foreground transition-all`,children:(0,s.jsx)(t.d,{className:`w-5 h-5`})})]}),(0,s.jsxs)(`div`,{className:`mb-6 pr-32`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,s.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${Bn.find(e=>e.text===O.color)?.bgCircle||`bg-accent`}`}),(0,s.jsx)(`span`,{className:`text-[11px] font-bold tracking-[0.2em] uppercase ${Bn.find(e=>e.text===O.color)?.text||`text-accent`}`,children:`Event Details`})]}),(0,s.jsx)(`h3`,{className:`text-3xl font-black mb-3 tracking-tight leading-tight break-words ${Bn.find(e=>e.text===O.color)?.text||`text-foreground`}`,children:O.title}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2 mt-4`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-2.5 text-[14px] text-foreground/70 font-medium`,children:[(0,s.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.bt,{className:`w-4 h-4 text-foreground/50`})}),new Date(O.dateStr+`T12:00:00`).toLocaleDateString(`default`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2.5 text-[14px] text-foreground/70 font-medium`,children:[(0,s.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-foreground/5 border border-[var(--panel-border)] flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.ct,{className:`w-4 h-4 text-foreground/50`})}),se(O.time),` `,(0,s.jsxs)(`span`,{className:`text-foreground/40 text-[12px] ml-1`,children:[`(`,X(O.duration),`)`]})]})]}),Se(O)]}),(0,s.jsx)(`div`,{className:`w-full h-px bg-gradient-to-r from-[var(--panel-border)]/0 via-[var(--panel-border)] to-[var(--panel-border)]/0 mb-6`}),O.description?(0,s.jsx)(`div`,{className:`bg-foreground/[0.02] border border-[var(--panel-border)]/50 rounded-2xl py-3 px-4 mb-4 w-full overflow-hidden`,children:(0,s.jsx)(`div`,{className:`text-[14px] text-foreground/80 font-medium whitespace-pre-wrap leading-tight break-words`,children:O.description})}):(0,s.jsx)(`div`,{className:`p-4 mb-4 rounded-2xl border border-dashed border-[var(--panel-border)] bg-foreground/[0.01] text-center`,children:(0,s.jsx)(`p`,{className:`text-[12px] font-medium text-foreground/40`,children:`No description provided for this event.`})}),O.customFields&&Object.entries(O.customFields).filter(([,e])=>e).length>0&&(0,s.jsx)(`div`,{className:`flex flex-col gap-2 mb-2`,children:Object.entries(O.customFields).filter(([,e])=>e).map(([e,t])=>(0,s.jsxs)(`div`,{className:`flex items-start gap-2 text-[13px]`,children:[(0,s.jsxs)(`span`,{className:`font-bold text-foreground/50 capitalize shrink-0`,children:[e,`:`]}),(0,s.jsx)(`span`,{className:`text-foreground/80 font-medium break-words min-w-0`,children:t})]},e))})]})]},`view-modal`),E&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.o.div,{onClick:()=>D(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(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:`w-full max-w-[500px] p-6 sm:p-8 rounded-3xl glass-popover border border-[var(--panel-border)] shadow-2xl relative z-10 max-h-[90vh] overflow-y-auto styled-scrollbars`,children:[(0,s.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1`,children:[I.id&&oe({uid:I.uid})&&(0,s.jsx)(`button`,{onClick:()=>{D(!1),F({id:I.id,...I})},className:`p-2 rounded-xl text-foreground/30 hover:bg-red-500/10 hover:text-red-500 transition-all`,children:(0,s.jsx)(t.v,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>D(!1),className:`p-2 rounded-xl text-foreground/40 hover:bg-foreground/10 hover:text-foreground transition-all`,children:(0,s.jsx)(t.d,{className:`w-5 h-5`})})]}),(0,s.jsxs)(`div`,{className:`mb-6 pr-12`,children:[(0,s.jsx)(`h3`,{className:`text-2xl font-extrabold mb-1 tracking-tight`,children:I.id?`Edit Event`:`Add Event`}),(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/50`,children:I.id?`Modify your scheduled calendar block.`:`Schedule a new calendar block.`})]}),(0,s.jsxs)(`form`,{onSubmit:be,className:`space-y-4`,children:[x===`public`&&!I.id&&(0,s.jsx)(t.i,{label:`Your Email`,type:`email`,value:I.guestEmail,onChange:e=>L({...I,guestEmail:e.target.value}),placeholder:`you@example.com`,required:!0}),(0,s.jsx)(t.i,{label:`Event Title`,value:I.title,onChange:e=>L({...I,title:e.target.value}),placeholder:`e.g. Design Sync`,required:!0}),(0,s.jsxs)(`div`,{className:`flex flex-col w-full relative`,children:[(0,s.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Description`}),(0,s.jsx)(`textarea`,{value:I.description,onChange:e=>L({...I,description:e.target.value}),placeholder:`e.g. Discussing the new features...`,className:`block min-h-[80px] w-full rounded-xl text-[15px] text-foreground px-4 py-3 transition-all duration-300 placeholder:text-foreground/40 focus:outline-none focus:border-accent glow-focus glass-panel styled-scrollbars resize-none`})]}),b.map(e=>(0,s.jsx)(t.i,{label:e,value:I.customFields[e]||``,onChange:t=>L({...I,customFields:{...I.customFields,[e]:t.target.value}}),placeholder:`Enter ${e.toLowerCase()}...`},e)),(0,s.jsx)(`style`,{children:`
39
39
  input[type="date"]::-webkit-calendar-picker-indicator{background:transparent;bottom:0;color:transparent;cursor:pointer;height:auto;left:0;position:absolute;right:0;top:0;width:auto;z-index:10}
40
40
  input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}
41
41
  input[type="number"]{-moz-appearance:textfield}
42
- `}),(0,s.jsxs)(`div`,{className:`relative group/date flex flex-col w-full`,children:[(0,s.jsx)(t.i,{type:`date`,label:`Date`,required:!0,value:I.dateStr,onChange:e=>L({...I,dateStr:e.target.value}),className:`pr-10`}),(0,s.jsx)(`div`,{className:`absolute right-4 bottom-4 pointer-events-none group-focus-within/date:text-accent text-foreground/40 transition-colors`,children:(0,s.jsx)(t.bt,{className:`w-4 h-4`})})]}),(0,s.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[G?(0,s.jsx)(t.i,{type:`time`,label:`Time`,value:I.time,onChange:e=>L({...I,time:e.target.value}),required:!0}):(()=>{let{h:e,m:t,ampm:n}=ce(I.time);return(0,s.jsxs)(`div`,{className:`flex flex-col w-full`,children:[(0,s.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Time`}),(0,s.jsxs)(`div`,{className:`flex items-center h-12 glass-panel border border-[var(--panel-border)] rounded-xl px-3 gap-1 focus-within:border-accent transition-colors`,children:[(0,s.jsx)(`input`,{type:`number`,min:1,max:12,value:e,onChange:e=>L({...I,time:Z(Math.min(12,Math.max(1,parseInt(e.target.value)||12)),t,n)}),className:`w-8 text-center bg-transparent focus:outline-none text-foreground font-bold text-[15px] [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none`}),(0,s.jsx)(`span`,{className:`text-foreground/40 font-bold text-[15px] select-none`,children:`:`}),(0,s.jsx)(`input`,{type:`number`,min:0,max:59,value:t.toString().padStart(2,`0`),onChange:t=>L({...I,time:Z(e,Math.min(59,Math.max(0,parseInt(t.target.value)||0)),n)}),className:`w-8 text-center bg-transparent focus:outline-none text-foreground font-bold text-[15px] [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none`}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>L({...I,time:Z(e,t,n===`AM`?`PM`:`AM`)}),className:`ml-auto px-2 py-0.5 rounded-md bg-accent/10 text-accent text-[11px] font-extrabold uppercase tracking-wider hover:bg-accent/20 transition-colors shrink-0`,children:n})]})]})})(),(0,s.jsx)(t.i,{type:`number`,min:`1`,max:`1440`,label:`Duration (min)`,value:I.duration,onChange:e=>L({...I,duration:e.target.value}),placeholder:`60`,required:!0})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,s.jsx)(`label`,{className:`text-[11px] font-bold text-foreground/50 uppercase tracking-widest mt-1`,children:`Event Color`}),(0,s.jsx)(`div`,{className:`flex gap-2 items-center relative z-10 w-full h-[46px]`,children:zn.map(e=>(0,s.jsx)(`button`,{type:`button`,onClick:()=>L({...I,color:I.color===e.text?``:e.text}),className:`w-6 h-6 rounded-full shrink-0 ${e.bgCircle} hover:scale-110 transition-transform flex items-center justify-center border border-[var(--panel-border)]`,children:I.color===e.text&&(0,s.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full bg-background`})},e.name))})]}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsx)(t.r,{type:`submit`,isLoading:A,className:`w-full py-3`,children:I.id?`Save Changes`:`Create Event`})})]})]})]},`edit-modal`),(0,s.jsx)(re,{isOpen:!!P,title:`Confirm Deletion`,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:P?.title}),` This action is permanent.`]}),onConfirm:xe,onCancel:()=>{F(null)},isProcessing:M,confirmText:`Yes, Delete`})]});return p?(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,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:d?.tabTitle||d?.tabName||e}),n&&(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`}),n]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(ne,{}),(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:[Te(),De()]})]}),Oe()]}):(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-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}),n&&(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`}),n]})]}),(0,s.jsxs)(`div`,{className:`flex justify-between items-center mb-6 border-b border-[var(--panel-border)] pb-6 relative z-20`,children:[o?(0,s.jsxs)(c.Link,{to:o,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`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4`}),` Go Back`]}):(0,s.jsx)(`div`,{}),(0,s.jsxs)(`div`,{className:`flex gap-2`,children:[(0,s.jsx)(t.r,{variant:`secondary`,onClick:q,className:`px-3 h-10 text-[12px] font-bold rounded-xl flex items-center justify-center border-[var(--panel-border)] border shrink-0 hover:bg-foreground/5 shadow-sm text-foreground/70`,children:G?`24h`:`12h`}),(0,s.jsx)(t.r,{variant:`secondary`,onClick:J,className:`w-10 h-10 p-0 text-[14px] font-bold rounded-xl flex items-center justify-center border-[var(--panel-border)] border shrink-0`,children:S===`month`?(0,s.jsx)(t.V,{className:`w-4 h-4 text-foreground/70`}):(0,s.jsx)(t.bt,{className:`w-4 h-4 text-foreground/70`})}),we&&(0,s.jsxs)(t.r,{onClick:()=>ve(),className:`px-6 py-2.5 text-[14px] font-bold rounded-xl shadow-lg flex items-center gap-2`,children:[(0,s.jsx)(t.k,{className:`w-4 h-4`}),` Event`]})]})]}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative flex flex-col flex-1`,children:[(0,s.jsx)(`div`,{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[800px] h-[800px] bg-accent/5 blur-[120px] rounded-full pointer-events-none -z-10`}),De()]}),Oe()]})}var Hn=[{name:`Purple Standard`,preview:[`#2e1065`,`#cdc1ff`],dark:{buttonText:`#ffffff`,background:`#07070f`,backgroundSecondary:`#0a0a18`,accent:`#a78bfa`,gradient:[`#6d28d9`,`#a78bfa`],text:[`#f0eeff`,`#c4b5fd`,`#a78bfa`]},light:{buttonText:`#ffffff`,background:`#fcfaff`,backgroundSecondary:`#f7f3ff`,accent:`#7c3aed`,gradient:[`#5b21b6`,`#a78bfa`],text:[`#2e1065`,`#6d28d9`,`#cdc1ff`]}},{name:`Royal Navy`,preview:[`#1e3a8a`,`#60a5fa`],dark:{buttonText:`#ffffff`,background:`#050b14`,backgroundSecondary:`#0a192f`,accent:`#60a5fa`,gradient:[`#1d4ed8`,`#60a5fa`],text:[`#dbeafe`,`#93c5fd`,`#60a5fa`]},light:{buttonText:`#ffffff`,background:`#f8fafc`,backgroundSecondary:`#f1f5f9`,accent:`#2563eb`,gradient:[`#1e3a8a`,`#60a5fa`],text:[`#1e3a8a`,`#2563eb`,`#60a5fa`]}},{name:`Emerald Green`,preview:[`#064e3b`,`#10b981`],dark:{buttonText:`#ffffff`,background:`#050806`,backgroundSecondary:`#0a2218`,accent:`#34d399`,gradient:[`#047857`,`#34d399`],text:[`#d1fae5`,`#6ee7b7`,`#34d399`]},light:{buttonText:`#ffffff`,background:`#f6fbf8`,backgroundSecondary:`#eff7f2`,accent:`#059669`,gradient:[`#064e3b`,`#10b981`],text:[`#064e3b`,`#059669`,`#10b981`]}},{name:`Gold`,preview:[`#854d0e`,`#eab308`],dark:{buttonText:`#000000`,background:`#0f0905`,backgroundSecondary:`#1c1208`,accent:`#fcd34d`,gradient:[`#ca8a04`,`#facc15`],text:[`#fefce8`,`#fef08a`,`#facc15`]},light:{buttonText:`#ffffff`,background:`#fbfaf6`,backgroundSecondary:`#f5f2eb`,accent:`#d97706`,gradient:[`#854d0e`,`#eab308`],text:[`#854d0e`,`#ca8a04`,`#eab308`]}},{name:`Silver`,preview:[`#1e293b`,`#94a3b8`],dark:{buttonText:`#ffffff`,background:`#090e17`,backgroundSecondary:`#101725`,accent:`#cbd5e1`,gradient:[`#475569`,`#94a3b8`],text:[`#e2e8f0`,`#94a3b8`,`#cbd5e1`]},light:{buttonText:`#ffffff`,background:`#f8fafc`,backgroundSecondary:`#e2e8f0`,accent:`#64748b`,gradient:[`#1e293b`,`#94a3b8`],text:[`#1e293b`,`#475569`,`#94a3b8`]}},{name:`Barbie Pink`,preview:[`#d946ef`,`#f472b6`],dark:{buttonText:`#ffffff`,background:`#0c030a`,backgroundSecondary:`#1a0515`,accent:`#ff80ff`,gradient:[`#c026d3`,`#f472b6`],text:[`#ffeeff`,`#ffb3ff`,`#ff80ff`]},light:{buttonText:`#ffffff`,background:`#fcf5fa`,backgroundSecondary:`#f5ebf2`,accent:`#d946ef`,gradient:[`#c026d3`,`#ec4899`],text:[`#a21caf`,`#c026d3`,`#ec4899`]}},{name:`Orange`,preview:[`#7c2d12`,`#f97316`],dark:{buttonText:`#ffffff`,background:`#0a0200`,backgroundSecondary:`#1c0b05`,accent:`#fb923c`,gradient:[`#c2410c`,`#fb923c`],text:[`#fff7ed`,`#fdba74`,`#fb923c`]},light:{buttonText:`#ffffff`,background:`#fdf6f2`,backgroundSecondary:`#f5ebe4`,accent:`#ea580c`,gradient:[`#7c2d12`,`#f97316`],text:[`#7c2d12`,`#ea580c`,`#f97316`]}},{name:`Red`,preview:[`#7f1d1d`,`#ef4444`],dark:{buttonText:`#ffffff`,background:`#0a0000`,backgroundSecondary:`#2e0a0a`,accent:`#ef4444`,gradient:[`#b91c1c`,`#f87171`],text:[`#fef2f2`,`#fecaca`,`#f87171`]},light:{buttonText:`#ffffff`,background:`#fdf5f5`,backgroundSecondary:`#f5ebeb`,accent:`#dc2626`,gradient:[`#7f1d1d`,`#ef4444`],text:[`#7f1d1d`,`#dc2626`,`#ef4444`]}},{name:`Black & White`,preview:[`#ffffff`,`#000000`],dark:{buttonText:`#000000`,background:`#000000`,backgroundSecondary:`#111111`,accent:`#ffffff`,gradient:[`#ffffff`,`#e5e7eb`],text:[`#ffffff`,`#f3f4f6`,`#ffffff`]},light:{buttonText:`#ffffff`,background:`#ffffff`,backgroundSecondary:`#f3f4f6`,accent:`#000000`,gradient:[`#000000`,`#1f2937`],text:[`#000000`,`#1f2937`,`#374151`]}}],Un=[`Inter`,`Outfit`,`Roboto`,`Space Grotesk`,`Plus Jakarta Sans`,`System UI`],Wn=[{key:`light`,label:`Light mode`,icon:t.x,description:`How the site looks for someone with light mode on.`},{key:`dark`,label:`Dark mode`,icon:t.M,description:`How the site looks for someone with dark mode on.`}],Gn=oe,Kn=`flex items-center gap-2 w-full h-10 px-1.5 rounded-[var(--input-radius,0.75rem)] border border-[var(--panel-border)] bg-[var(--panel-bg)] transition-all focus-within:border-accent hover:border-accent/40`,qn=`border border-[var(--panel-border)]/60 dark:border-0`,Jn=`pointer-events-none absolute inset-0 rounded-[inherit] dark:ring-1 dark:ring-inset dark:ring-white/15`,Yn=e=>JSON.parse(JSON.stringify(e)),Xn=e=>{let t=(e||``).replace(`#`,``).trim();return t.length===3?[0,1,2].map(e=>parseInt(t[e]+t[e],16)):t.length===6?[0,2,4].map(e=>parseInt(t.substring(e,e+2),16)):null},Zn=(e,t,n)=>{let r=e=>Math.max(0,Math.min(255,Math.round(e)));return`#${[e,t,n].map(e=>r(e).toString(16).padStart(2,`0`)).join(``)}`},Qn=e=>{let t=(e||``).trim();if(t.startsWith(`#`)){let e=Xn(t);return e?Zn(e[0],e[1],e[2]):null}let n=t.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i);return n?Zn(parseFloat(n[1]),parseFloat(n[2]),parseFloat(n[3])):null},$n=(e,t)=>{let n=Xn(e);return n?Zn(n[0]*t,n[1]*t,n[2]*t):e},er=e=>e?Array.isArray(e)?e.length===1?e[0]:`linear-gradient(135deg, ${e.join(`, `)})`:e:``,tr=(e,t)=>{let n=Xn(Qn(t)||t);if(!n)return{};let r=e=>`rgba(${n[0]}, ${n[1]}, ${n[2]}, ${e})`;return{panelBg:e===`dark`?r(`0.05`):`rgba(255, 255, 255, 0.70)`,panelBorder:r(e===`dark`?`0.15`:`0.08`),glowColor:r(e===`dark`?`0.40`:`0.30`),selectionBg:r(e===`dark`?`0.40`:`0.30`)}};function nr({label:e,hint:t,value:n,over:r,onChange:i}){let a=Qn(n)||`#7c3aed`;return(0,s.jsxs)(`div`,{className:`flex flex-col gap-1.5 p-3.5 sm:p-4 ${ie}`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,s.jsx)(`label`,{className:`text-[12.5px] font-bold text-foreground truncate`,children:e}),(0,s.jsxs)(`label`,{className:`relative w-7 h-7 rounded-lg cursor-pointer overflow-hidden shrink-0 shadow-2xs transition-all hover:scale-105 active:scale-95 flex items-center justify-center focus-within:ring-2 focus-within:ring-accent ${qn}`,title:`Pick a colour for ${e}`,children:[(0,s.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-0`,style:{backgroundColor:r||`transparent`}}),(0,s.jsx)(`span`,{"aria-hidden":!0,"data-testid":`color-swatch`,className:`absolute inset-0`,style:{backgroundColor:n||`transparent`}}),(0,s.jsx)(`input`,{type:`color`,"aria-label":`${e} colour picker`,value:a,onChange:e=>i(e.target.value),className:`absolute inset-0 w-full h-full opacity-0 cursor-pointer p-0 border-0`}),(0,s.jsx)(`span`,{"aria-hidden":!0,className:Jn})]})]}),t&&(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/45 font-medium leading-snug truncate`,children:t}),(0,s.jsx)(`input`,{type:`text`,"aria-label":e,value:n??``,onChange:e=>i(e.target.value),className:Gn})]})}function rr({label:e,hint:n,value:r,onChange:i}){let a=Array.isArray(r)&&r.length?r:[`#7c3aed`,`#6d28d9`],o=(e,t)=>{let n=[...a];n[e]=t,i(n)};return(0,s.jsxs)(`div`,{className:`flex flex-col gap-2.5 p-3.5 sm:p-4 ${ie}`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,s.jsx)(`label`,{className:`text-[12.5px] font-bold text-foreground truncate`,children:e}),(0,s.jsx)(`div`,{"data-testid":`gradient-preview`,className:`w-16 h-5 rounded-lg border border-[var(--panel-border)]/60 dark:border-0 shrink-0 shadow-2xs overflow-hidden`,style:{background:er(a)}})]}),n&&(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/45 font-medium leading-snug`,children:n}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2 pt-1.5`,children:[a.map((n,r)=>(0,s.jsxs)(`div`,{className:Kn,children:[(0,s.jsxs)(`label`,{className:`relative w-6 h-6 rounded-md cursor-pointer overflow-hidden shrink-0 transition-all hover:scale-105 active:scale-95 flex items-center justify-center ${qn}`,style:{backgroundColor:n||`transparent`},title:`Pick colour ${r+1} for ${e}`,children:[(0,s.jsx)(`input`,{type:`color`,"aria-label":`${e} colour ${r+1} picker`,value:Qn(n)||`#7c3aed`,onChange:e=>o(r,e.target.value),className:`absolute inset-0 w-full h-full opacity-0 cursor-pointer p-0 border-0`}),(0,s.jsx)(`span`,{"aria-hidden":!0,className:Jn})]}),(0,s.jsx)(`input`,{type:`text`,"aria-label":`${e} colour ${r+1}`,value:n,onChange:e=>o(r,e.target.value),className:`flex-1 min-w-0 h-full bg-transparent border-0 px-0 text-[12px] font-semibold text-foreground outline-none`}),a.length>2&&(0,s.jsx)(`button`,{type:`button`,onClick:()=>i(a.filter((e,t)=>t!==r)),"aria-label":`Remove colour ${r+1} from ${e}`,className:`w-6 h-6 rounded-md flex items-center justify-center text-foreground/35 hover:text-red-500 hover:bg-red-500/10 transition-colors cursor-pointer shrink-0`,children:(0,s.jsx)(t.d,{className:`w-3.5 h-3.5`})})]},r)),a.length<6&&(0,s.jsxs)(`button`,{type:`button`,onClick:()=>i([...a,$n(a[a.length-1]||`#6d28d9`,.9)]),className:`w-full h-9 px-3 rounded-lg border border-dashed border-accent/40 hover:border-accent bg-accent/[0.03] hover:bg-accent/10 text-accent text-[11.5px] font-bold flex items-center justify-center gap-1.5 transition-all active:scale-[0.99] cursor-pointer shadow-2xs mt-0.5`,children:[(0,s.jsx)(t.k,{className:`w-3.5 h-3.5`}),`Add another colour`]})]})]})}function ir({label:e,hint:t,value:n,onChange:r}){let i=Number.isFinite(n)?n:0;return(0,s.jsx)(ue,{label:e,hint:t,action:(0,s.jsxs)(`span`,{className:`text-[11px] font-bold text-foreground/50 tabular-nums shrink-0`,children:[Math.round(i*16),`px`]}),children:(0,s.jsx)(`input`,{type:`range`,min:0,max:3,step:.125,value:i,"aria-label":e,onChange:e=>r(parseFloat(e.target.value)),className:`w-full accent-accent cursor-pointer`})})}function ar({label:e,hint:n,value:r,fallback:i,onChange:a}){return(0,s.jsx)(ue,{label:e,hint:n,action:r===i?void 0:(0,s.jsx)(Q,{icon:t.D,onClick:()=>a(i),children:`Put the original back`}),children:(0,s.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,s.jsx)(`div`,{className:`w-10 h-10 rounded-lg shrink-0 overflow-hidden flex items-center justify-center bg-foreground/5 ${qn}`,children:r?(0,s.jsx)(`img`,{src:r,alt:e,className:`w-full h-full object-contain`}):(0,s.jsx)(t.J,{className:`w-4 h-4 text-foreground/30`})}),(0,s.jsx)(`input`,{type:`text`,"aria-label":e,value:r??``,placeholder:`https://...`,onChange:e=>a(e.target.value),className:Gn})]})})}function or({title:e,onReset:n}){return(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pt-2 first:pt-0`,children:[(0,s.jsx)(`span`,{className:`text-[11px] font-black uppercase tracking-wider text-foreground/40`,children:e}),(0,s.jsx)(Q,{icon:t.D,onClick:n,children:`Reset`})]})}var sr=[`accent`,`foreground`,`background`,`backgroundSecondary`,`textGradient`,`notificationIconColor`],cr=[`buttonGradient`,`buttonHoverGradient`,`buttonText`,`secondaryButton`],lr=[`panelBg`,`panelBorder`,`glowColor`,`selectionBg`,`selectionText`],ur=[`appName`,`defaultTheme`,`showThemeToggle`,`logoUrl`,`faviconUrl`],dr=[`fontFamily`,`cornerRounding`,`cornerRadii`];function fr(){let{activeConfig:e,theme:n}=t.At(),a=t.Mt(),o=(0,r.useMemo)(()=>Yn(a?.themeConfig||t.Lt),[a]),[l,u]=(0,r.useState)(null),[d,f]=(0,r.useState)(!1),[p,m]=(0,r.useState)(null),[h,g]=(0,r.useState)(!1),[_,v]=(0,r.useState)(!1),[y,b]=(0,r.useState)(!1),[x,S]=(0,r.useState)(null);(0,r.useEffect)(()=>{let e=(0,i.onSnapshot)((0,i.doc)(t.Pt,`sys_configs`,`theme`),e=>v(e.exists()));return()=>e()},[]);let C=r.default.useRef(null);(0,r.useEffect)(()=>{if(!l&&e){let t=Yn(e);u(t),C.current=JSON.stringify(t)}},[e,l]),(0,r.useEffect)(()=>{try{let e=sessionStorage.getItem(`fbos_theme_scrollY`);e&&requestAnimationFrame(()=>window.scrollTo(0,parseInt(e,10)))}catch{}let e=()=>{try{sessionStorage.setItem(`fbos_theme_scrollY`,String(window.scrollY))}catch{}};return window.addEventListener(`scroll`,e,{passive:!0}),()=>window.removeEventListener(`scroll`,e)},[]),(0,r.useEffect)(()=>{if(!l)return;let e=JSON.stringify(l);if(e===C.current)return;let n=setTimeout(async()=>{f(!0);try{await(0,i.setDoc)((0,i.doc)(t.Pt,`sys_configs`,`theme`),l),C.current=e,m(Date.now())}catch(e){console.error(`Auto-save failed`,e)}f(!1)},300);return()=>clearTimeout(n)},[l]);let w=(e,t)=>u(n=>({...n,[e]:t})),T=(e,t)=>u(n=>({...n,colors:{...n.colors,[e]:{...n.colors?.[e]||{},...t}}})),E=(e,t)=>u(n=>({...n,colors:{...n.colors,[e]:{...n.colors?.[e]||{},secondaryButton:{...n.colors?.[e]?.secondaryButton||{},...t}}}})),D=(e,t)=>T(e,{accent:t,notificationIconColor:t,...tr(e,t)}),O=(e,t,n)=>S({title:e,message:t,apply:n}),k=e=>u(t=>{let n=Yn(t);return e.forEach(e=>{o[e]===void 0?delete n[e]:n[e]=Yn(o[e])}),n}),A=(e,t)=>u(n=>{let r=Yn(n),i=o.colors?.[e]||{};return r.colors=r.colors||{},r.colors[e]=r.colors[e]||{},t.forEach(t=>{i[t]===void 0?delete r.colors[e][t]:r.colors[e][t]=Yn(i[t])}),r}),j=e=>{if(!l)return;let t=Yn(l);t.colors=t.colors||{},[`dark`,`light`].forEach(n=>{let r=e[n],i=t.colors[n]||{};t.colors[n]={...i,accent:r.accent,buttonGradient:[...r.gradient],buttonHoverGradient:[...r.gradient],buttonText:r.buttonText,notificationIconColor:r.accent,textGradient:[...r.text],foreground:r.text[0],background:r.background,backgroundSecondary:r.backgroundSecondary,...tr(n,r.accent),...i.secondaryButton?{secondaryButton:{...i.secondaryButton,text:r.text[0]}}:{}}}),u(t)},M=async()=>{g(!0);try{let e=Yn(o),{deleteDoc:n}=await import(`firebase/firestore`);await n((0,i.doc)(t.Pt,`sys_configs`,`theme`)),localStorage.removeItem(`theme_config_cache`),localStorage.removeItem(`theme-mode`),localStorage.removeItem(`last-seen-default-theme`),C.current=JSON.stringify(e),u(e)}catch{}setTimeout(()=>g(!1),600)},N=()=>{if(!l)return;let e=l,t=e.colors?.dark||{},n=e.colors?.light||{},r=e.cornerRadii||{},i=`/**
42
+ `}),(0,s.jsxs)(`div`,{className:`relative group/date flex flex-col w-full`,children:[(0,s.jsx)(t.i,{type:`date`,label:`Date`,required:!0,value:I.dateStr,onChange:e=>L({...I,dateStr:e.target.value}),className:`pr-10`}),(0,s.jsx)(`div`,{className:`absolute right-4 bottom-4 pointer-events-none group-focus-within/date:text-accent text-foreground/40 transition-colors`,children:(0,s.jsx)(t.bt,{className:`w-4 h-4`})})]}),(0,s.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[G?(0,s.jsx)(t.i,{type:`time`,label:`Time`,value:I.time,onChange:e=>L({...I,time:e.target.value}),required:!0}):(()=>{let{h:e,m:t,ampm:n}=ce(I.time);return(0,s.jsxs)(`div`,{className:`flex flex-col w-full`,children:[(0,s.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Time`}),(0,s.jsxs)(`div`,{className:`flex items-center h-12 glass-panel border border-[var(--panel-border)] rounded-xl px-3 gap-1 focus-within:border-accent transition-colors`,children:[(0,s.jsx)(`input`,{type:`number`,min:1,max:12,value:e,onChange:e=>L({...I,time:Z(Math.min(12,Math.max(1,parseInt(e.target.value)||12)),t,n)}),className:`w-8 text-center bg-transparent focus:outline-none text-foreground font-bold text-[15px] [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none`}),(0,s.jsx)(`span`,{className:`text-foreground/40 font-bold text-[15px] select-none`,children:`:`}),(0,s.jsx)(`input`,{type:`number`,min:0,max:59,value:t.toString().padStart(2,`0`),onChange:t=>L({...I,time:Z(e,Math.min(59,Math.max(0,parseInt(t.target.value)||0)),n)}),className:`w-8 text-center bg-transparent focus:outline-none text-foreground font-bold text-[15px] [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none`}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>L({...I,time:Z(e,t,n===`AM`?`PM`:`AM`)}),className:`ml-auto px-2 py-0.5 rounded-md bg-accent/10 text-accent text-[11px] font-extrabold uppercase tracking-wider hover:bg-accent/20 transition-colors shrink-0`,children:n})]})]})})(),(0,s.jsx)(t.i,{type:`number`,min:`1`,max:`1440`,label:`Duration (min)`,value:I.duration,onChange:e=>L({...I,duration:e.target.value}),placeholder:`60`,required:!0})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,s.jsx)(`label`,{className:`text-[11px] font-bold text-foreground/50 uppercase tracking-widest mt-1`,children:`Event Color`}),(0,s.jsx)(`div`,{className:`flex gap-2 items-center relative z-10 w-full h-[46px]`,children:Bn.map(e=>(0,s.jsx)(`button`,{type:`button`,onClick:()=>L({...I,color:I.color===e.text?``:e.text}),className:`w-6 h-6 rounded-full shrink-0 ${e.bgCircle} hover:scale-110 transition-transform flex items-center justify-center border border-[var(--panel-border)]`,children:I.color===e.text&&(0,s.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full bg-background`})},e.name))})]}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsx)(t.r,{type:`submit`,isLoading:A,className:`w-full py-3`,children:I.id?`Save Changes`:`Create Event`})})]})]})]},`edit-modal`),(0,s.jsx)(re,{isOpen:!!P,title:`Confirm Deletion`,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:P?.title}),` This action is permanent.`]}),onConfirm:xe,onCancel:()=>{F(null)},isProcessing:M,confirmText:`Yes, Delete`})]});return p?(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,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:d?.tabTitle||d?.tabName||e}),n&&(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`}),n]})]})}),(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:[Te(),De()]})]}),Oe()]}):(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-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}),n&&(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`}),n]})]}),(0,s.jsxs)(`div`,{className:`flex justify-between items-center mb-6 border-b border-[var(--panel-border)] pb-6 relative z-20`,children:[o?(0,s.jsxs)(c.Link,{to:o,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`,children:[(0,s.jsx)(t.wt,{className:`w-4 h-4`}),` Go Back`]}):(0,s.jsx)(`div`,{}),(0,s.jsxs)(`div`,{className:`flex gap-2`,children:[(0,s.jsx)(t.r,{variant:`secondary`,onClick:q,className:`px-3 h-10 text-[12px] font-bold rounded-xl flex items-center justify-center border-[var(--panel-border)] border shrink-0 hover:bg-foreground/5 shadow-sm text-foreground/70`,children:G?`24h`:`12h`}),(0,s.jsx)(t.r,{variant:`secondary`,onClick:J,className:`w-10 h-10 p-0 text-[14px] font-bold rounded-xl flex items-center justify-center border-[var(--panel-border)] border shrink-0`,children:S===`month`?(0,s.jsx)(t.V,{className:`w-4 h-4 text-foreground/70`}):(0,s.jsx)(t.bt,{className:`w-4 h-4 text-foreground/70`})}),we&&(0,s.jsxs)(t.r,{onClick:()=>ve(),className:`px-6 py-2.5 text-[14px] font-bold rounded-xl shadow-lg flex items-center gap-2`,children:[(0,s.jsx)(t.k,{className:`w-4 h-4`}),` Event`]})]})]}),(0,s.jsxs)(t.o.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative flex flex-col flex-1`,children:[(0,s.jsx)(`div`,{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[800px] h-[800px] bg-accent/5 blur-[120px] rounded-full pointer-events-none -z-10`}),De()]}),Oe()]})}var Un=[{name:`Purple Standard`,preview:[`#2e1065`,`#cdc1ff`],dark:{buttonText:`#ffffff`,background:`#07070f`,backgroundSecondary:`#0a0a18`,accent:`#a78bfa`,gradient:[`#6d28d9`,`#a78bfa`],text:[`#f0eeff`,`#c4b5fd`,`#a78bfa`]},light:{buttonText:`#ffffff`,background:`#fcfaff`,backgroundSecondary:`#f7f3ff`,accent:`#7c3aed`,gradient:[`#5b21b6`,`#a78bfa`],text:[`#2e1065`,`#6d28d9`,`#cdc1ff`]}},{name:`Royal Navy`,preview:[`#1e3a8a`,`#60a5fa`],dark:{buttonText:`#ffffff`,background:`#050b14`,backgroundSecondary:`#0a192f`,accent:`#60a5fa`,gradient:[`#1d4ed8`,`#60a5fa`],text:[`#dbeafe`,`#93c5fd`,`#60a5fa`]},light:{buttonText:`#ffffff`,background:`#f8fafc`,backgroundSecondary:`#f1f5f9`,accent:`#2563eb`,gradient:[`#1e3a8a`,`#60a5fa`],text:[`#1e3a8a`,`#2563eb`,`#60a5fa`]}},{name:`Emerald Green`,preview:[`#064e3b`,`#10b981`],dark:{buttonText:`#ffffff`,background:`#050806`,backgroundSecondary:`#0a2218`,accent:`#34d399`,gradient:[`#047857`,`#34d399`],text:[`#d1fae5`,`#6ee7b7`,`#34d399`]},light:{buttonText:`#ffffff`,background:`#f6fbf8`,backgroundSecondary:`#eff7f2`,accent:`#059669`,gradient:[`#064e3b`,`#10b981`],text:[`#064e3b`,`#059669`,`#10b981`]}},{name:`Gold`,preview:[`#854d0e`,`#eab308`],dark:{buttonText:`#000000`,background:`#0f0905`,backgroundSecondary:`#1c1208`,accent:`#fcd34d`,gradient:[`#ca8a04`,`#facc15`],text:[`#fefce8`,`#fef08a`,`#facc15`]},light:{buttonText:`#ffffff`,background:`#fbfaf6`,backgroundSecondary:`#f5f2eb`,accent:`#d97706`,gradient:[`#854d0e`,`#eab308`],text:[`#854d0e`,`#ca8a04`,`#eab308`]}},{name:`Silver`,preview:[`#1e293b`,`#94a3b8`],dark:{buttonText:`#ffffff`,background:`#090e17`,backgroundSecondary:`#101725`,accent:`#cbd5e1`,gradient:[`#475569`,`#94a3b8`],text:[`#e2e8f0`,`#94a3b8`,`#cbd5e1`]},light:{buttonText:`#ffffff`,background:`#f8fafc`,backgroundSecondary:`#e2e8f0`,accent:`#64748b`,gradient:[`#1e293b`,`#94a3b8`],text:[`#1e293b`,`#475569`,`#94a3b8`]}},{name:`Barbie Pink`,preview:[`#d946ef`,`#f472b6`],dark:{buttonText:`#ffffff`,background:`#0c030a`,backgroundSecondary:`#1a0515`,accent:`#ff80ff`,gradient:[`#c026d3`,`#f472b6`],text:[`#ffeeff`,`#ffb3ff`,`#ff80ff`]},light:{buttonText:`#ffffff`,background:`#fcf5fa`,backgroundSecondary:`#f5ebf2`,accent:`#d946ef`,gradient:[`#c026d3`,`#ec4899`],text:[`#a21caf`,`#c026d3`,`#ec4899`]}},{name:`Orange`,preview:[`#7c2d12`,`#f97316`],dark:{buttonText:`#ffffff`,background:`#0a0200`,backgroundSecondary:`#1c0b05`,accent:`#fb923c`,gradient:[`#c2410c`,`#fb923c`],text:[`#fff7ed`,`#fdba74`,`#fb923c`]},light:{buttonText:`#ffffff`,background:`#fdf6f2`,backgroundSecondary:`#f5ebe4`,accent:`#ea580c`,gradient:[`#7c2d12`,`#f97316`],text:[`#7c2d12`,`#ea580c`,`#f97316`]}},{name:`Red`,preview:[`#7f1d1d`,`#ef4444`],dark:{buttonText:`#ffffff`,background:`#0a0000`,backgroundSecondary:`#2e0a0a`,accent:`#ef4444`,gradient:[`#b91c1c`,`#f87171`],text:[`#fef2f2`,`#fecaca`,`#f87171`]},light:{buttonText:`#ffffff`,background:`#fdf5f5`,backgroundSecondary:`#f5ebeb`,accent:`#dc2626`,gradient:[`#7f1d1d`,`#ef4444`],text:[`#7f1d1d`,`#dc2626`,`#ef4444`]}},{name:`Black & White`,preview:[`#ffffff`,`#000000`],dark:{buttonText:`#000000`,background:`#000000`,backgroundSecondary:`#111111`,accent:`#ffffff`,gradient:[`#ffffff`,`#e5e7eb`],text:[`#ffffff`,`#f3f4f6`,`#ffffff`]},light:{buttonText:`#ffffff`,background:`#ffffff`,backgroundSecondary:`#f3f4f6`,accent:`#000000`,gradient:[`#000000`,`#1f2937`],text:[`#000000`,`#1f2937`,`#374151`]}}],Wn=[`Inter`,`Outfit`,`Roboto`,`Space Grotesk`,`Plus Jakarta Sans`,`System UI`],Gn=[{key:`light`,label:`Light mode`,icon:t.x,description:`How the site looks for someone with light mode on.`},{key:`dark`,label:`Dark mode`,icon:t.M,description:`How the site looks for someone with dark mode on.`}],Kn=oe,qn=`flex items-center gap-2 w-full h-10 px-1.5 rounded-[var(--input-radius,0.75rem)] border border-[var(--panel-border)] bg-[var(--panel-bg)] transition-all focus-within:border-accent hover:border-accent/40`,Jn=`border border-[var(--panel-border)]/60 dark:border-0`,Yn=`pointer-events-none absolute inset-0 rounded-[inherit] dark:ring-1 dark:ring-inset dark:ring-white/15`,Xn=e=>JSON.parse(JSON.stringify(e)),Zn=e=>{let t=(e||``).replace(`#`,``).trim();return t.length===3?[0,1,2].map(e=>parseInt(t[e]+t[e],16)):t.length===6?[0,2,4].map(e=>parseInt(t.substring(e,e+2),16)):null},Qn=(e,t,n)=>{let r=e=>Math.max(0,Math.min(255,Math.round(e)));return`#${[e,t,n].map(e=>r(e).toString(16).padStart(2,`0`)).join(``)}`},$n=e=>{let t=(e||``).trim();if(t.startsWith(`#`)){let e=Zn(t);return e?Qn(e[0],e[1],e[2]):null}let n=t.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i);return n?Qn(parseFloat(n[1]),parseFloat(n[2]),parseFloat(n[3])):null},er=(e,t)=>{let n=Zn(e);return n?Qn(n[0]*t,n[1]*t,n[2]*t):e},tr=e=>e?Array.isArray(e)?e.length===1?e[0]:`linear-gradient(135deg, ${e.join(`, `)})`:e:``,nr=(e,t)=>{let n=Zn($n(t)||t);if(!n)return{};let r=e=>`rgba(${n[0]}, ${n[1]}, ${n[2]}, ${e})`;return{panelBg:e===`dark`?r(`0.05`):`rgba(255, 255, 255, 0.70)`,panelBorder:r(e===`dark`?`0.15`:`0.08`),glowColor:r(e===`dark`?`0.40`:`0.30`),selectionBg:r(e===`dark`?`0.40`:`0.30`)}};function rr({label:e,hint:t,value:n,over:r,onChange:i}){let a=$n(n)||`#7c3aed`;return(0,s.jsxs)(`div`,{className:`flex flex-col gap-1.5 p-3.5 sm:p-4 ${ie}`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,s.jsx)(`label`,{className:`text-[12.5px] font-bold text-foreground truncate`,children:e}),(0,s.jsxs)(`label`,{className:`relative w-7 h-7 rounded-lg cursor-pointer overflow-hidden shrink-0 shadow-2xs transition-all hover:scale-105 active:scale-95 flex items-center justify-center focus-within:ring-2 focus-within:ring-accent ${Jn}`,title:`Pick a colour for ${e}`,children:[(0,s.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-0`,style:{backgroundColor:r||`transparent`}}),(0,s.jsx)(`span`,{"aria-hidden":!0,"data-testid":`color-swatch`,className:`absolute inset-0`,style:{backgroundColor:n||`transparent`}}),(0,s.jsx)(`input`,{type:`color`,"aria-label":`${e} colour picker`,value:a,onChange:e=>i(e.target.value),className:`absolute inset-0 w-full h-full opacity-0 cursor-pointer p-0 border-0`}),(0,s.jsx)(`span`,{"aria-hidden":!0,className:Yn})]})]}),t&&(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/45 font-medium leading-snug truncate`,children:t}),(0,s.jsx)(`input`,{type:`text`,"aria-label":e,value:n??``,onChange:e=>i(e.target.value),className:Kn})]})}function ir({label:e,hint:n,value:r,onChange:i}){let a=Array.isArray(r)&&r.length?r:[`#7c3aed`,`#6d28d9`],o=(e,t)=>{let n=[...a];n[e]=t,i(n)};return(0,s.jsxs)(`div`,{className:`flex flex-col gap-2.5 p-3.5 sm:p-4 ${ie}`,children:[(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,s.jsx)(`label`,{className:`text-[12.5px] font-bold text-foreground truncate`,children:e}),(0,s.jsx)(`div`,{"data-testid":`gradient-preview`,className:`w-16 h-5 rounded-lg border border-[var(--panel-border)]/60 dark:border-0 shrink-0 shadow-2xs overflow-hidden`,style:{background:tr(a)}})]}),n&&(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/45 font-medium leading-snug`,children:n}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2 pt-1.5`,children:[a.map((n,r)=>(0,s.jsxs)(`div`,{className:qn,children:[(0,s.jsxs)(`label`,{className:`relative w-6 h-6 rounded-md cursor-pointer overflow-hidden shrink-0 transition-all hover:scale-105 active:scale-95 flex items-center justify-center ${Jn}`,style:{backgroundColor:n||`transparent`},title:`Pick colour ${r+1} for ${e}`,children:[(0,s.jsx)(`input`,{type:`color`,"aria-label":`${e} colour ${r+1} picker`,value:$n(n)||`#7c3aed`,onChange:e=>o(r,e.target.value),className:`absolute inset-0 w-full h-full opacity-0 cursor-pointer p-0 border-0`}),(0,s.jsx)(`span`,{"aria-hidden":!0,className:Yn})]}),(0,s.jsx)(`input`,{type:`text`,"aria-label":`${e} colour ${r+1}`,value:n,onChange:e=>o(r,e.target.value),className:`flex-1 min-w-0 h-full bg-transparent border-0 px-0 text-[12px] font-semibold text-foreground outline-none`}),a.length>2&&(0,s.jsx)(`button`,{type:`button`,onClick:()=>i(a.filter((e,t)=>t!==r)),"aria-label":`Remove colour ${r+1} from ${e}`,className:`w-6 h-6 rounded-md flex items-center justify-center text-foreground/35 hover:text-red-500 hover:bg-red-500/10 transition-colors cursor-pointer shrink-0`,children:(0,s.jsx)(t.d,{className:`w-3.5 h-3.5`})})]},r)),a.length<6&&(0,s.jsxs)(`button`,{type:`button`,onClick:()=>i([...a,er(a[a.length-1]||`#6d28d9`,.9)]),className:`w-full h-9 px-3 rounded-lg border border-dashed border-accent/40 hover:border-accent bg-accent/[0.03] hover:bg-accent/10 text-accent text-[11.5px] font-bold flex items-center justify-center gap-1.5 transition-all active:scale-[0.99] cursor-pointer shadow-2xs mt-0.5`,children:[(0,s.jsx)(t.k,{className:`w-3.5 h-3.5`}),`Add another colour`]})]})]})}function ar({label:e,hint:t,value:n,onChange:r}){let i=Number.isFinite(n)?n:0;return(0,s.jsx)(ue,{label:e,hint:t,action:(0,s.jsxs)(`span`,{className:`text-[11px] font-bold text-foreground/50 tabular-nums shrink-0`,children:[Math.round(i*16),`px`]}),children:(0,s.jsx)(`input`,{type:`range`,min:0,max:3,step:.125,value:i,"aria-label":e,onChange:e=>r(parseFloat(e.target.value)),className:`w-full accent-accent cursor-pointer`})})}function or({label:e,hint:n,value:r,fallback:i,onChange:a}){return(0,s.jsx)(ue,{label:e,hint:n,action:r===i?void 0:(0,s.jsx)(Q,{icon:t.D,onClick:()=>a(i),children:`Put the original back`}),children:(0,s.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,s.jsx)(`div`,{className:`w-10 h-10 rounded-lg shrink-0 overflow-hidden flex items-center justify-center bg-foreground/5 ${Jn}`,children:r?(0,s.jsx)(`img`,{src:r,alt:e,className:`w-full h-full object-contain`}):(0,s.jsx)(t.J,{className:`w-4 h-4 text-foreground/30`})}),(0,s.jsx)(`input`,{type:`text`,"aria-label":e,value:r??``,placeholder:`https://...`,onChange:e=>a(e.target.value),className:Kn})]})})}function sr({title:e,onReset:n}){return(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pt-2 first:pt-0`,children:[(0,s.jsx)(`span`,{className:`text-[11px] font-black uppercase tracking-wider text-foreground/40`,children:e}),(0,s.jsx)(Q,{icon:t.D,onClick:n,children:`Reset`})]})}var cr=[`accent`,`foreground`,`background`,`backgroundSecondary`,`textGradient`,`notificationIconColor`],lr=[`buttonGradient`,`buttonHoverGradient`,`buttonText`,`secondaryButton`],ur=[`panelBg`,`panelBorder`,`glowColor`,`selectionBg`,`selectionText`],dr=[`appName`,`defaultTheme`,`showThemeToggle`,`logoUrl`,`faviconUrl`],fr=[`fontFamily`,`cornerRounding`,`cornerRadii`];function pr(){let{activeConfig:e,theme:n}=t.At(),a=t.Mt(),o=(0,r.useMemo)(()=>Xn(a?.themeConfig||t.Lt),[a]),[l,u]=(0,r.useState)(null),[d,f]=(0,r.useState)(!1),[p,m]=(0,r.useState)(null),[h,g]=(0,r.useState)(!1),[_,v]=(0,r.useState)(!1),[y,b]=(0,r.useState)(!1),[x,S]=(0,r.useState)(null);(0,r.useEffect)(()=>{let e=(0,i.onSnapshot)((0,i.doc)(t.Pt,`sys_configs`,`theme`),e=>v(e.exists()));return()=>e()},[]);let C=r.default.useRef(null);(0,r.useEffect)(()=>{if(!l&&e){let t=Xn(e);u(t),C.current=JSON.stringify(t)}},[e,l]),(0,r.useEffect)(()=>{try{let e=sessionStorage.getItem(`fbos_theme_scrollY`);e&&requestAnimationFrame(()=>window.scrollTo(0,parseInt(e,10)))}catch{}let e=()=>{try{sessionStorage.setItem(`fbos_theme_scrollY`,String(window.scrollY))}catch{}};return window.addEventListener(`scroll`,e,{passive:!0}),()=>window.removeEventListener(`scroll`,e)},[]),(0,r.useEffect)(()=>{if(!l)return;let e=JSON.stringify(l);if(e===C.current)return;let n=setTimeout(async()=>{f(!0);try{await(0,i.setDoc)((0,i.doc)(t.Pt,`sys_configs`,`theme`),l),C.current=e,m(Date.now())}catch(e){console.error(`Auto-save failed`,e)}f(!1)},300);return()=>clearTimeout(n)},[l]);let w=(e,t)=>u(n=>({...n,[e]:t})),T=(e,t)=>u(n=>({...n,colors:{...n.colors,[e]:{...n.colors?.[e]||{},...t}}})),E=(e,t)=>u(n=>({...n,colors:{...n.colors,[e]:{...n.colors?.[e]||{},secondaryButton:{...n.colors?.[e]?.secondaryButton||{},...t}}}})),D=(e,t)=>T(e,{accent:t,notificationIconColor:t,...nr(e,t)}),O=(e,t,n)=>S({title:e,message:t,apply:n}),k=e=>u(t=>{let n=Xn(t);return e.forEach(e=>{o[e]===void 0?delete n[e]:n[e]=Xn(o[e])}),n}),A=(e,t)=>u(n=>{let r=Xn(n),i=o.colors?.[e]||{};return r.colors=r.colors||{},r.colors[e]=r.colors[e]||{},t.forEach(t=>{i[t]===void 0?delete r.colors[e][t]:r.colors[e][t]=Xn(i[t])}),r}),j=e=>{if(!l)return;let t=Xn(l);t.colors=t.colors||{},[`dark`,`light`].forEach(n=>{let r=e[n],i=t.colors[n]||{};t.colors[n]={...i,accent:r.accent,buttonGradient:[...r.gradient],buttonHoverGradient:[...r.gradient],buttonText:r.buttonText,notificationIconColor:r.accent,textGradient:[...r.text],foreground:r.text[0],background:r.background,backgroundSecondary:r.backgroundSecondary,...nr(n,r.accent),...i.secondaryButton?{secondaryButton:{...i.secondaryButton,text:r.text[0]}}:{}}}),u(t)},M=async()=>{g(!0);try{let e=Xn(o),{deleteDoc:n}=await import(`firebase/firestore`);await n((0,i.doc)(t.Pt,`sys_configs`,`theme`)),localStorage.removeItem(`theme_config_cache`),localStorage.removeItem(`theme-mode`),localStorage.removeItem(`last-seen-default-theme`),C.current=JSON.stringify(e),u(e)}catch{}setTimeout(()=>g(!1),600)},N=()=>{if(!l)return;let e=l,t=e.colors?.dark||{},n=e.colors?.light||{},r=e.cornerRadii||{},i=`/**
43
43
  * THEME & BRANDING CONFIGURATION
44
44
  *
45
45
  * This is the central hub for customizing your app's look.
@@ -131,8 +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=Wn.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:Hn.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)(or,{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,sr))}),(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)(nr,{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)(nr,{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)(nr,{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)(nr,{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)(nr,{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)(rr,{label:`Heading colours`,hint:`The colours big headings fade through.`,value:r.textGradient||i.textGradient,onChange:t=>T(e,{textGradient:t})})]}),(0,s.jsx)(or,{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,cr))}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-3 items-start`,children:[(0,s.jsx)(rr,{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)(rr,{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)(nr,{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)(nr,{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)(nr,{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)(nr,{over:a,label:`Quiet button text`,value:r.secondaryButton?.text||i.secondaryButton?.text||`#111827`,onChange:t=>E(e,{text:t})})]})]}),(0,s.jsx)(or,{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,lr))}),(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)(nr,{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)(nr,{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)(nr,{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)(nr,{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)(nr,{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)(ne,{}),(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)(he,{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(ur)),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)(fe,{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)(pe,{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)(ar,{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)(ar,{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`}),`.`]})]}),Wn.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(dr)),children:`Reset`}),children:[(0,s.jsx)(fe,{label:`Typeface`,hint:`The lettering used everywhere on your site.`,value:l.fontFamily||`Inter`,onChange:e=>w(`fontFamily`,e||`Inter`),allowEmpty:!1,options:Un.map(e=>({value:e,label:e}))}),(0,s.jsx)(fe,{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)(ir,{label:`Buttons`,hint:`How round every button is.`,value:l.cornerRadii?.buttonRadius??.75,onChange:e=>w(`cornerRadii`,{...l.cornerRadii||{},buttonRadius:e})}),(0,s.jsx)(ir,{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)(ir,{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)(ir,{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)(Oe,{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 pr={route:`/page_1`,pageName:`New Page`,pageTitle:`My New Page`,template:`none`,form:``},mr={tabName:`New Page`,iconName:``,route:`/new-page`,tabTitle:`Your Page`,template:`none`,form:``},hr={tabName:`New Admin Page`,iconName:``,route:`/new-admin-page`,tabTitle:`Admin Page`,template:`none`,form:``},gr={tabName:`New Team Page`,iconName:``,route:`/new-team-page`,tabTitle:`Team Page`,template:`none`,form:``},_r=[{id:`home`,title:`Home`,path:`/`,type:`public`,isSystem:!0,enabled:!0}],vr=e=>[...e,..._r.filter(t=>!e.some(e=>e.id===t.id))],yr={public:`Anyone`,user:`Signed-in users`,internal:`Your team`,admin:`Admins only`},br=e=>(e||``).trim().toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9_-]/g,``),xr=(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},Sr=()=>Object.fromEntries(M()),Cr=(e,t=!1)=>{let n={};for(let[r,i]of Object.entries(Sr())){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 wr({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:yr[e]}))})})}var Tr=`Add hands you a sentence for your assistant — paste it into the chat and the page is built, ready to rename here.`,Er=[{value:`none`,label:`From scratch`},{value:`board`,label:`Board`},{value:`table`,label:`Table`},{value:`calendar`,label:`Calendar`},{value:`drive`,label:`Files`}],Dr=[`board`,`table`,`calendar`,`drive`],Or=e=>(e||``).split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``),kr=(e,t)=>t?.tabName||t?.pageName||t?.pageId||e.title,Ar=(e,t)=>`src/your-ai-workflow-firebase-os/microcomponents/${Or(kr(e,t))||`Page`}Content.tsx`,jr=(e,t)=>{let n=String(t?.route||``).trim(),r=n?n.startsWith(`/`)?n:`/`+n:e.path,i=String(t?.template||``),a=String(t?.form||``).trim(),o=Dr.includes(i)?` It starts from the ${i} preset — use its data hooks and draw the UI yourself.`:``,s=a?` Its form is called ${a} — show it with <ContactPopup formId='${a}' />; never write a form by hand.`:` It has no form; do not add one.`;return`Fill the page at ${r} — it already exists, so do not create a page, a form, a config file or a web address, and do not edit src/App.tsx or src/main.tsx. Write only one file: ${Ar(e,t)} with a default export.`+o+s+` Here is what it should show: ___`},Mr=(e,t)=>{let n=e===`public`?`anyone — a page on my website`:e===`user`?`signed-in users`:e===`internal`?`my team`:`admins only`,r=e===`public`?`Page`:`Tab`;return`Add a brand-new page for ${n} at the web address ${t} — that address is free, use it exactly. You pick the page's name; I can rename it on my Pages screen later. Create exactly two files, both named from that name — a page called Projects gets projects${r}.config.ts and ProjectsContent.tsx. File 1: src/your-ai-workflow-firebase-os/configs/something${r}.config.ts with export const something${r}Config = ${e===`public`?`{ pageName: 'the name', route: '${t}' }`:`{ tabName: 'the name', route: '${t}', pageType: '${e}', template: 'none', form: '' }`}. File 2: src/your-ai-workflow-firebase-os/microcomponents/SomethingContent.tsx with a default export — the page's content, with no hand-written form in it. Create no other file, write nothing to Firestore, do not edit src/App.tsx or src/main.tsx, and do not register the page anywhere else — the build finds the two files by their names. Here is what the page should show: ___`},Nr=(e,t)=>{let n=e=>{let{_uiKey:t,pageType:n,route:r,...i}=e||{};return i},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},Pr=(e,t)=>{let{_uiKey:n,...r}=e||{};return Object.keys(r).length>0?{...r,pageType:t}:{pageType:t}},Fr=`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`,Ir=`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`,Lr=e=>{let t=typeof window<`u`?window.location.host:``;return t?`${t}${e}`:e},Rr=e=>e.replace(/[_-]+/g,` `).replace(/^./,e=>e.toUpperCase());function zr({page:e,config:t,forms:n,saving:i,onSave:a,addressTaken:o,actions:c}){let l=e.type===`public`,u=l?`pageName`:`tabName`,d=l?`pageTitle`:`tabTitle`,[f,p]=(0,r.useState)(()=>({...t||{}})),[m,h]=(0,r.useState)(``),g=(e,t)=>p(n=>({...n,[e]:t})),_=e=>{p(t=>({...t,...e}));let n={...t||{},...f,...e};delete n._uiKey,a(n)},v=e=>{(t||{})[e]!==f[e]&&_({[e]:f[e]})},y=String(f.route??``).replace(/^\/+/,``);return(0,s.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,s.jsx)(de,{label:l?`Name in the menu`:`Name in the dashboard`,hint:l?`What visitors see in the site menu.`:`What people see in the dashboard menu.`,value:f[u]??``,onChange:e=>g(u,e),onBlur:()=>v(u),placeholder:l?`Pricing`:`Invoices`}),(0,s.jsx)(de,{label:`Page heading`,hint:`The big heading people read at the top of the page.`,value:f[d]??``,onChange:e=>g(d,e),onBlur:()=>v(d),placeholder:`Our prices`}),(0,s.jsx)(de,{label:`Web address`,hint:`Where this page lives, e.g. /pricing`,prefix:`/`,value:y,onChange:e=>{g(`route`,e),m&&h(``)},onBlur:()=>{let n=br(y);if(!n){h(`Give this page a web address, for example pricing`);return}if(o(e.id,n)){h(`Another page already lives at this address. Pick a different one.`);return}h(``),n===String(t?.route??``).replace(/^\/+/,``)?g(`route`,`/`+n):_({route:`/`+n})},error:m,placeholder:`pricing`}),!l&&(0,s.jsx)(De,{label:`Icon`,hint:`Shown next to the name in the dashboard menu.`,value:f.iconName??``,onChange:e=>_({iconName:e})}),!l&&(0,s.jsx)(fe,{label:`Starting layout`,hint:`What the page starts as. Your assistant fills in the rest when you ask.`,value:Er.some(e=>e.value===f.template)?f.template:`none`,onChange:e=>_({template:e}),options:Er,allowEmpty:!1}),(0,s.jsx)(fe,{label:`Form`,hint:l?`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:f.form??``,onChange:e=>_({form:e}),options:n.map(e=>({value:e,label:Rr(e)})),placeholder:`No form`}),(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)(he,{saving:i}),(0,s.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 ml-auto`,children:c})]})]})}function Br(){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 vr(JSON.parse(e))}}catch{}return _r}),[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)(null),[g,_]=(0,r.useState)(()=>{try{if(typeof window<`u`){let e=localStorage.getItem(`fbos_swr_page_configs`);if(e)return JSON.parse(e)}}catch{}return{}}),[v,y]=(0,r.useState)({}),[b,x]=(0,r.useState)({}),[S,C]=(0,r.useState)(null),[T,E]=(0,r.useState)(null),[D,O]=(0,r.useState)(!1),k=(0,r.useRef)(null);(0,r.useEffect)(()=>{function e(e){k.current&&!k.current.contains(e.target)&&p(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let[j,M]=(0,r.useState)(new Set),[N,P]=(0,r.useState)(new Set),[F,I]=(0,r.useState)([]),[L,R]=(0,r.useState)([]),ee=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=ee(e.exists()&&e.data().order||[]);I(t),M(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=ee(e.exists()&&e.data().order||[]);R(t),P(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 z=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=z.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=Sr(),l={...Cr(!0,!0),...Cr(!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=vr(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}),_(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[B,V]=(0,r.useState)([`contact`]),[te,H]=(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)}),V(Array.from(r)),H(Array.from(a))}).catch(e=>{console.warn(`Failed fetching sys_forms in PagesAdmin:`,e),V(Array.from(r)),H(Array.from(a))})},[]);let U=async(e,n,r)=>{n.route&&!n.route.startsWith(`/`)&&(n.route=`/`+n.route);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;y(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}`)),_(t=>{let r={...t};return r[p]=n,delete r[e],r});let r=c===`public`,a=r?`page_order`:`tab_order`,s=r?F:L;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),_(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(()=>{y(t=>({...t,[e]:!1,[p]:!1}))},500)}},W=e=>{let t=e===`public`?`page`:e===`user`?`user-page`:e===`admin`?`admin-page`:`team-page`,n=a.filter(t=>t.type===e).length+1;for(;se(``,`${t}-${n}`);)n++;return`/${t}-${n}`},G=e=>{h(e),p(!1),setTimeout(()=>{document.getElementById(`add-page-${e}`)?.scrollIntoView?.({behavior:`smooth`,block:`center`})},100)};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 K=async(e,n,r)=>{let s=r===`public`,c=s?`page_order`:`tab_order`,l=s?F:L,u=(s?j:N).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})},q=e=>!!e.fromFile&&(e.type===`public`?F:L).some(t=>t.id===e.id&&t.removed),J=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)),y(t=>({...t,[e.id]:!0}));let a=Pr(g[e.id],n);try{await(0,i.setDoc)((0,i.doc)(t.Pt,`sys_tabs`,e.id),a,{merge:!0}),_(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{y(t=>({...t,[e.id]:!1}))}},Y=(e,t)=>{t||C(e)},ie=async()=>{if(S){O(!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`),m=a.find(e=>e.id===S),h=m?.type===`public`?`sys_pages`:`sys_tabs`;if(h===`sys_tabs`&&m){let a=g[S];if(!a)try{let e=await s(i(t.Pt,`sys_tabs`,S));e.exists()&&(a=e.data())}catch{}let o=(a?.tabName||a?.pageId||S).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`}},m=[];for(let i of l)m.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`])m.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(m)}await e(i(t.Pt,h,S));let _=h===`sys_pages`?`page_order`:`tab_order`,v=h===`sys_pages`?F:L,{setDoc:y}=await import(`firebase/firestore`),b=m?.fromFile?[...v.filter(e=>e.id!==S),{id:S,hidden:!0,removed:!0}]:v.filter(e=>e.id!==S);await y(i(t.Pt,`sys_configs`,_),{order:b}),o(e=>e.filter(e=>e.id!==S)),l===S&&u(null)}catch(e){console.error(`Error deleting page:`,e)}O(!1),C(null)}},ae=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={...g[e.id]||{},route:n.path,pageName:n.title};n.type!==`public`&&(r.tabName=n.title,r.pageType=n.type),_(e=>({...e,[t]:r})),u(t),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})},100)},oe=async(e,n)=>{if(e.id===`home`)return;let r=e.type===`public`,o=r?`page_order`:`tab_order`,s=[...r?F:L];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=xr(s,e.id,n,r?`home`:void 0);if(c){r?I(c):R(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)}}},se=(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(g[r.id]?.route??r.path??``).replace(/^\/+/,``).toLowerCase();return i!==``&&i===t||r.id===n})},X=e=>e===`admin`?hr:e===`internal`?gr:e===`public`?pr:mr,ce=async()=>{let e=a.find(e=>e.id===T);if(!e){E(null);return}x(t=>({...t,[e.id]:!0})),await U(e.id,{...X(e.type)}),x(t=>({...t,[e.id]:!1})),E(null)},Z=[{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)(ne,{}),(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:`Every page your assistant has built for you, plus any you add here. Rename them, change where they live, put them in the order you want, hide them or link a different form — everything else is done by asking your assistant.`})}),(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:k,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:()=>G(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:yr[e]},e))]})})]})})]}),(0,s.jsx)(`div`,{ref:z,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:Z.map((e,n)=>{let r=a.filter(e.filter).filter(e=>!q(e)),i=e.id===`public`?F:L,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`?j.has(e.id):N.has(e.id),f=o.filter(e=>!d(e)),p=o.filter(e=>d(e)),_=(n,r)=>{let i=n.id===`home`,a=l===n.id,o=!n.isSystem||i,c=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(o){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 ${o?`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&&(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:()=>oe(n,`up`),className:Fr,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:()=>oe(n,`down`),className:Fr,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:Ir,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:[c,` · Web address `,Lr(n.path)]})]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 self-end sm:self-auto`,children:[n.type!==`public`&&(0,s.jsx)(wr,{value:n.type,busy:v[n.id],onChange:e=>J(n,e)}),!i&&(0,s.jsx)(Q,{icon:r?t.et:t.tt,onClick:e=>{e.stopPropagation(),K(n.id,n.isSystem,n.type)},children:r?`Show`:`Hide`}),o?(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)(Oe,{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&&g[n.id]&&(0,s.jsxs)(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)(`div`,{className:`mb-5`,children:(0,s.jsx)(Oe,{compact:!0,title:`Ask your assistant to fill this page`,prompt:jr(n,g[n.id])})}),(0,s.jsx)(zr,{page:n,config:g[n.id],forms:n.type===`public`?B:te,saving:v[n.id],onSave:e=>U(n.id,e),addressTaken:se,actions:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Q,{icon:t.at,onClick:()=>ae(n),children:`Duplicate`}),!n.fromFile&&Nr(g[n.id],X(n.type))&&(0,s.jsx)(Q,{icon:t.D,tone:`danger`,busy:b[n.id],onClick:()=>E(n.id),children:`Reset`}),!n.isSystem&&(0,s.jsx)(Q,{icon:t.y,tone:`danger`,onClick:()=>Y(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}),m===e.id&&(0,s.jsxs)(`div`,{id:`add-page-${e.id}`,className:`relative mb-4`,children:[(0,s.jsx)(Oe,{compact:!0,title:`Ask your assistant to add this page`,prompt:Mr(e.id,W(e.id))}),(0,s.jsx)(`button`,{type:`button`,"aria-label":`Close`,onClick:()=>h(null),className:`absolute -top-2 -right-2 w-6 h-6 rounded-full glass-popover border border-[var(--panel-border)] flex items-center justify-center text-foreground/45 hover:text-foreground transition-colors cursor-pointer shadow-sm`,children:(0,s.jsx)(t.d,{className:`w-3 h-3`})})]}),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:()=>G(e.id),children:`Add a page`}),(0,s.jsx)(`p`,{className:`text-[12.5px] text-foreground/55 font-medium leading-relaxed`,children:Tr})]}):(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[f.map(e=>_(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=>_(e,!0))})]})]}),n<Z.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:!!S,onCancel:()=>C(null),onConfirm:ie,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:D}),(0,s.jsx)(re,{isOpen:!!T,onCancel:()=>E(null),onConfirm:ce,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:!!T&&!!b[T]})]})}var Vr=new Set([`contact`,`support`]),Hr=[{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`}],Ur={age:`Age`},Wr=e=>Hr.find(t=>t.value===e)?.label||Ur[e||``]||`Short text`,Gr=e=>Hr.some(t=>t.value===e)||!e?Hr:[...Hr,{value:e,label:Wr(e)}],Kr={public:`Anyone`,private:`Signed-in users`},qr=e=>(e||``).toLowerCase().trim().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``),Jr=(e,t)=>{if(!t.includes(e))return e;let n=2;for(;t.includes(`${e}_${n}`);)n++;return`${e}_${n}`},Yr=(e,t,n)=>{if(!(!e.name||e.name===qr(e.label||``)))return e.name;let r=qr(t);return r?Jr(r,n.filter(t=>t!==e).map(e=>e.name)):``},Xr=()=>({name:``,type:`text`,label:``,placeholder:``,required:!1}),Zr={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 Qr({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 $r(){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(!Vr.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=Vr.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 B=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})},V=Object.keys(y).find(e=>y[e]),te=(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:[`· `,Wr(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:Yr(r,e,a)},!1),onBlur:()=>P(e)}),(0,s.jsx)(fe,{label:`Kind of answer`,hint:`Sets the box people type into and what counts as a valid answer.`,value:r.type||`text`,options:Gr(r.type),allowEmpty:!1,onChange:e=>o(e===`select`?{type:e,options:r.options||[]}:{type:e},!0)}),(0,s.jsx)(pe,{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)(Qr,{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)},H=(e,n)=>{let r=T[e]||n,i=Vr.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)(fe,{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,Xr()]),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)=>te(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,Xr()]),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)(Oe,{compact:!0,title:`Ask your assistant to put this form on a page`,prompt:Zr.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`,V?`/${V}`:``]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(ne,{}),(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:Zr.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:()=>B(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:Kr[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:H(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)(Oe,{title:`Everything else is your assistant's job`,prompt:Zr.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 ei({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 ti({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,B]=(0,r.useState)(``),[V,te]=(0,r.useState)(``),[H,U]=(0,r.useState)([]),W=(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),W.current&&(W.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),B(e.name),te(e.note||``);let t=[`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`],n=Object.entries(e).filter(([e])=>!t.includes(e)&&e!==`id`).map(([e,t])=>({key:e,value:String(t??``)}));U(n),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={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=H.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:V.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),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)(ne,{}),(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:W,onChange:q,className:`hidden`}),(0,s.jsxs)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${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:()=>W.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=>B(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:V,onChange:e=>{te(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`})]}),H.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=[...H];t[n].key=e.target.value,U(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=[...H];t[n].value=e.target.value,U(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:()=>U(H.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:()=>U([...H,{key:``,value:``}]),className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground/25 hover:text-foreground/40 transition-colors cursor-pointer mt-4 mb-4`,children:[(0,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 ni({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,B]=(0,r.useState)(``),[V,te]=(0,r.useState)(``),[H,U]=(0,r.useState)([]),W=(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),W.current&&(W.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),B(e.name),te(e.note||``);let t=[`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`],n=Object.entries(e).filter(([e])=>!t.includes(e)&&e!==`id`).map(([e,t])=>({key:e,value:String(t??``)}));U(n),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={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=H.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:V.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),q.current=n}catch(e){console.error(`Error updating record:`,e)}x(!1),ee(null)},pe=async()=>{if(!R||!z.trim())return;let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=H.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:V.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),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)(ne,{}),(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:W,onChange:ae,className:`hidden`}),(0,s.jsxs)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${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:()=>W.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=>B(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:V,onChange:e=>{te(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`})]}),H.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=[...H];t[n].key=e.target.value,U(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=[...H];t[n].value=e.target.value,U(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:()=>U(H.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:()=>U([...H,{key:``,value:``}]),className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground/25 hover:text-foreground/40 transition-colors cursor-pointer mt-4 mb-4`,children:[(0,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 ri({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,B]=(0,r.useState)(``),[V,te]=(0,r.useState)(``),[H,U]=(0,r.useState)([]),W=(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),W.current&&(W.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),B(e.name),te(e.note||``);let t=[`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`],n=Object.entries(e).filter(([e])=>!t.includes(e)&&e!==`id`).map(([e,t])=>({key:e,value:String(t??``)}));U(n),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={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=H.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:V.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),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)(ne,{}),(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:W,onChange:ae,className:`hidden`}),(0,s.jsxs)(t.o.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${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:()=>W.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=>B(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:V,onChange:e=>{te(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`})]}),H.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=[...H];t[n].key=e.target.value,U(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=[...H];t[n].value=e.target.value,U(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:()=>U(H.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:()=>U([...H,{key:``,value:``}]),className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground/25 hover:text-foreground/40 transition-colors cursor-pointer mt-4 mb-4`,children:[(0,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 ii=[`board`,`table`,`calendar`,`drive`],ai=[`inline_form`,`popup_form`],oi=e=>typeof e!=`string`||e===``||e===`none`||e===`custom`||![...ii,...ai].includes(e),si=`src/your-ai-workflow-firebase-os`;function ci(){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 li(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 ${si}/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. ${si}/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(`
135
- `)}function ui({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 di=`w-full block py-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors`,fi=()=>(0,s.jsx)(ui,{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:di,children:`Back to dashboard`})}),pi=()=>(0,s.jsx)(ui,{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:di,children:`Back to dashboard`})}),mi=(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 hi(){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 mi(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 mi({...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=mi(e.value.data(),t),m=e.value.id):e.value.docs&&e.value.docs.length>0&&(f=mi(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=mi({...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)(ne,{}),(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=ci();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)(Oe,{title:`If your assistant just made this page, paste this`,prompt:li(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)(pi,{}):(0,s.jsx)(fi,{});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.tabName,f.contentKey,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(oi(f.template)||v&&![`board`,`table`,`calendar`,`drive`].includes(f.template))return f.isAdmin?(0,s.jsx)(ni,{config:f,customContent:E},D):f.isInternal?(0,s.jsx)(ri,{config:f,customContent:E},D):f.isPrivate?(0,s.jsx)(ti,{config:f,customContent:E},D):(0,s.jsx)(ei,{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||ct,{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||Rn,{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||Vn,{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||Ve,{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 gi=r.default.createContext({}),_i=Object.defineProperty,vi=Object.getOwnPropertySymbols,yi=Object.prototype.hasOwnProperty,bi=Object.prototype.propertyIsEnumerable,xi=(e,t,n)=>t in e?_i(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Si=(e,t)=>{for(var n in t||={})yi.call(t,n)&&xi(e,n,t[n]);if(vi)for(var n of vi(t))bi.call(t,n)&&xi(e,n,t[n]);return e},Ci=(0,r.forwardRef)((e,t)=>{let n=Si(Si({},r.useContext(gi)),e);return r.createElement(`svg`,Si({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`}))}),wi=`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}],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';
136
137
  service cloud.firestore {
137
138
  match /databases/{database}/documents {
138
139
 
@@ -317,7 +318,7 @@ service cloud.firestore {
317
318
  }
318
319
  }
319
320
  }
320
- `,Ti=`rules_version = '2';
321
+ `,Oi=`rules_version = '2';
321
322
  service firebase.storage {
322
323
  match /b/{bucket}/o {
323
324
 
@@ -490,4 +491,4 @@ service firebase.storage {
490
491
  }
491
492
  }
492
493
  }
493
- `,Ei=[{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 Di(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 Oi(e,t){let n=Di(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 ki(e){let t=[],n=[],r=t=>Oi(t,e);for(let{key:e,label:i}of Ei){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 Ai(){return ki().allSet}var ji=Ti;function Mi(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 wi.replace(/(function adminEmails\(\) \{\s*return )\[[^\]]*\];/,`$1[${n}];`)}function Ni(e){return e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean)}var Pi=/^[^@\s]+@[^@\s]+\.[^@\s]+$/;function Fi({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 Ii({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 Li({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 Ri({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=Ni(Oi(`VITE_ADMIN_EMAILS`,n)),o=a.filter(e=>!Pi.test(e)),c=a.length>0&&o.length===0,l=Mi(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)(Ci,{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)(Li,{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)(Li,{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)(Li,{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:[Ei.map(({key:e,shownAs:t})=>(0,s.jsx)(Ii,{name:e,shownAs:t},e)),(0,s.jsx)(Ii,{name:`VITE_ADMIN_EMAILS`,hint:`the email you will sign in with`})]})]}),(0,s.jsx)(Li,{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)(Li,{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)(Fi,{code:l,label:`Copy the rules`})]}),(0,s.jsxs)(Li,{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)(Fi,{code:ji,label:`Copy the storage rules`})]})]}),(0,s.jsx)(`div`,{className:`mt-8 relative z-10`,children:(0,s.jsx)(Oe,{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 zi(){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)(ne,{})}),(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 Bi=()=>(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 Vi({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)(Bi,{}):n?a?(0,s.jsx)(ui,{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:di,children:`Sign Out`})}):n.emailVerified?e===`admin`&&!x(r)?(0,s.jsx)(pi,{}):e===`internal`&&!S(r)?(0,s.jsx)(fi,{}):(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 Hi=({children:e})=>(0,s.jsx)(Vi,{level:`signed-in`,children:e}),Ui=({children:e})=>(0,s.jsx)(Vi,{level:`admin`,children:e});function Wi({children:e}){let{user:t,loading:n,roleResolved:r}=A(),[i]=(0,c.useSearchParams)();return n||!r?(0,s.jsx)(Bi,{}):t&&t.emailVerified?(0,s.jsx)(c.Navigate,{to:i.get(`from`)||`/dashboard`,replace:!0}):(0,s.jsx)(s.Fragment,{children:e})}function Gi({children:e}){let{user:t,loading:n,roleResolved:r}=A();return n||!r?(0,s.jsx)(Bi,{}):t?t.emailVerified?(0,s.jsx)(c.Navigate,{to:`/dashboard`}):(0,s.jsx)(s.Fragment,{children:e}):(0,s.jsx)(c.Navigate,{to:`/`})}function Ki(){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||B;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)(Wi,{children:(0,s.jsx)(e,{})})}),(0,s.jsx)(c.Route,{path:`/register`,element:(0,s.jsx)(Wi,{children:(0,s.jsx)(V,{})})}),(0,s.jsx)(c.Route,{path:`/login`,element:(0,s.jsx)(Wi,{children:(0,s.jsx)(te,{})})}),(0,s.jsx)(c.Route,{path:`/reset-password`,element:(0,s.jsx)(Wi,{children:(0,s.jsx)(K,{})})}),(0,s.jsx)(c.Route,{path:`/verify`,element:(0,s.jsx)(Gi,{children:(0,s.jsx)(H,{})})}),(0,s.jsx)(c.Route,{path:`/guide`,element:(0,s.jsx)(rt,{})}),(0,s.jsx)(c.Route,{path:`/templates`,element:(0,s.jsx)(Ke,{})}),(0,s.jsx)(c.Route,{path:`/templates/inline_form`,element:(0,s.jsx)(it,{})}),(0,s.jsx)(c.Route,{path:`/templates/popup_form`,element:(0,s.jsx)(at,{})}),(0,s.jsx)(c.Route,{path:`/templates/confirmation`,element:(0,s.jsx)(ot,{})}),(0,s.jsx)(c.Route,{path:`/templates/board`,element:(0,s.jsx)(ct,{})}),(0,s.jsx)(c.Route,{path:`/templates/table`,element:(0,s.jsx)(Rn,{})}),(0,s.jsx)(c.Route,{path:`/templates/calendar`,element:(0,s.jsx)(Vn,{})}),(0,s.jsx)(c.Route,{path:`/templates/drive`,element:(0,s.jsx)(Ve,{})}),(0,s.jsx)(c.Route,{path:`/users`,element:(0,s.jsx)(Ui,{children:(0,s.jsx)(Y,{})})}),(0,s.jsx)(c.Route,{path:`/users/:id`,element:(0,s.jsx)(Ui,{children:(0,s.jsx)(Y,{})})}),(0,s.jsx)(c.Route,{path:`/inbox`,element:(0,s.jsx)(Ui,{children:(0,s.jsx)(ze,{})})}),(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)(Ui,{children:(0,s.jsx)(Ge,{})})}),(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)(Ui,{children:(0,s.jsx)(fr,{})})}),(0,s.jsx)(c.Route,{path:`/pages/*`,element:(0,s.jsx)(Ui,{children:(0,s.jsx)(Br,{})})}),(0,s.jsx)(c.Route,{path:`/forms/*`,element:(0,s.jsx)(Ui,{children:(0,s.jsx)($r,{})})}),(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)(Hi,{children:(0,s.jsx)(G,{})})}),(0,s.jsx)(c.Route,{path:`/dashboard`,element:(0,s.jsx)(Hi,{children:(0,s.jsx)(zi,{})})}),(0,s.jsx)(c.Route,{path:`/setup`,element:(0,s.jsx)(Ri,{})}),(0,s.jsx)(c.Route,{path:`*`,element:(0,s.jsx)(hi,{})})]}),(0,s.jsx)(Ki,{})]})})}function Ji(){return(0,s.jsx)(c.BrowserRouter,{children:(0,s.jsx)(Yi,{})})}function Yi(){let e=t.Mt();return e.firebaseConfig&&e.firebaseConfig.apiKey&&e.firebaseConfig.apiKey.trim()!==``&&e.firebaseConfig.projectId&&e.firebaseConfig.projectId.trim()!==``||Ai()?(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)(Ri,{standalone:!0}),(0,s.jsx)(Ki,{})]})}function Xi(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)(Ji,{})})})})}exports.AdminNotifications=N,exports.Button=t.r,exports.ConfirmModal=re,exports.ContactPopup=t.t,exports.CustomSelect=t.n,exports.DashboardNav=ne,exports.FirebaseOS=Xi,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
+ `,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;