your-ai-workflow-firebase-os 1.2.55 → 1.2.57

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,27 +1,27 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-DYteiM-1.cjs`),t=require(`./ContactPopup-BykgWURi.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.Yt,"./supportForm.config.ts":t.qt}),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=()=>{document.querySelectorAll(`.fbos-content-slot style`).forEach(e=>{e.disabled&&e.media===`not all`||(e.disabled=!0,e.media=`not all`,typeof console<`u`&&console.warn(`FirebaseOS: a <style> tag inside a content file is global CSS and was disabled — style with theme classes (bg-background, text-foreground, glass-panel, btn-primary) instead.`))})},g=e=>{for(let t=e;t;t=t.parentElement){if(t.classList.contains(`fbos-content-slot`))return!1;if(getComputedStyle(t).position===`fixed`)return!0}return!1},_=()=>{if(typeof window>`u`)return;let e=window.innerHeight*.6;document.querySelectorAll(`.fbos-content-slot *`).forEach(t=>{if(!t.clientHeight||t.clientHeight<e||t.scrollHeight<=t.clientHeight+2)return;let n=getComputedStyle(t);n.overflowY!==`visible`&&(n.webkitLineClamp&&n.webkitLineClamp!==`none`||g(t)||(t.style.setProperty(`max-height`,`none`,`important`),t.style.setProperty(`height`,`auto`,`important`),t.scrollHeight>t.clientHeight+2&&t.style.setProperty(`overflow-y`,`visible`,`important`),typeof console<`u`&&console.warn(`FirebaseOS: a box in a content file was as tall as the screen and hid the rest of the page, which left the bottom unreachable on a phone — it was allowed to grow. Let the page be as long as it needs: no h-screen, max-h-screen or overflow-hidden around the whole page.`)))})},v=()=>{(0,r.useEffect)(()=>{if(typeof document>`u`||typeof MutationObserver>`u`)return;let e=()=>{h(),_()};e();let t=new MutationObserver(e);return t.observe(document.body,{childList:!0,subtree:!0}),window.addEventListener(`resize`,e),window.addEventListener(`orientationchange`,e),()=>{t.disconnect(),window.removeEventListener(`resize`,e),window.removeEventListener(`orientationchange`,e)}},[])},y=[`free`,`internal`,`admin`],b=[`user`,`internal`,`admin`],x={free:`Free`,internal:`Internal`,admin:`Admin`};function S(e){return e===`admin`?`admin`:e===`internal`?`internal`:`free`}function C(e){return e===`free`?`user`:e}var w=e=>S(e)===`admin`,T=e=>S(e)!==`free`;function E(e){return e===`admin`?`admin`:e===`public`?`public`:e===`internal`||e===`shared`?`internal`:`user`}function D(e){let t=E(e);return t===`public`?`user`:t}function O(e,t){switch(E(t)){case`public`:return!0;case`admin`:return w(e);case`internal`:return T(e);case`user`:return!0}}function k(e,t=!0){if(!t)return`guest`;let n=S(e);return n===`free`?`user`:n}function A(e){switch(E(e)){case`public`:return[`admin`,`internal`,`user`,`guest`];case`admin`:return[`admin`];case`internal`:return[`admin`,`internal`];case`user`:return[`admin`,`internal`,`user`]}}var j=(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 M({children:e}){let[n,o]=(0,r.useState)(null),[c,l]=(0,r.useState)(null),[u,d]=(0,r.useState)(!1),[f,p]=(0,r.useState)(!0),[m,h]=(0,r.useState)(!1),g=r.default.useRef(null),_=r.default.useRef(null),v=r.default.useRef(new Set),y=e=>(0,i.updateDoc)((0,i.doc)(t.Ht,`user_profiles`,e),{role:`admin`}),b=async e=>{if(!v.current.has(e)){v.current.add(e);try{await y(e)}catch(n){if(n?.code!==`permission-denied`){console.error(`Error claiming the admin role:`,n);return}try{if(!t.Vt.currentUser)return;await t.Vt.currentUser.getIdToken(!0),await y(e)}catch(e){e?.code!==`permission-denied`&&console.error(`Error claiming the admin role:`,e)}}}};return(0,r.useEffect)(()=>{let e;if(!t.Vt){p(!1),h(!0);return}(0,a.getRedirectResult)(t.Vt).catch(()=>{});let n=(0,a.onAuthStateChanged)(t.Vt,async n=>{if(n?.uid===_.current&&m){o(n);return}if(_.current=n?.uid||null,n){let r=localStorage.getItem(`fbos_role_${n.uid}`);r&&(l(r),h(!0),p(!1)),console.log(`[AuthContext] 1. onAuthStateChanged fired for user:`,n.uid),o(n);try{let r=(0,i.doc)(t.Ht,`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.Vt.currentUser?.emailVerified&&b(n.uid),g.current===null&&(g.current=i),l(i),localStorage.setItem(`fbos_role_${n.uid}`,i),d(r.inactive===!0)}h(!0),p(!1)},e=>{console.warn(`[AuthContext] user_profiles snapshot error (safe to ignore during auth transition):`,e),h(!0),p(!1)})}catch(e){console.error(`[AuthContext] ERROR in auth resolution:`,e),h(!0),p(!1)}}else console.log(`[AuthContext] No user currently signed in.`),o(null),l(null),d(!1),h(!0),p(!1),g.current=null,e&&e()});return()=>{n(),e&&e()}},[]),(0,r.useEffect)(()=>{if(!n?.emailVerified||c===`admin`)return;let e=!1;return(0,i.getDoc)((0,i.doc)(t.Ht,`user_profiles`,n.uid)).then(t=>{!e&&t.exists()&&!t.data().role&&b(n.uid)}).catch(()=>{}),()=>{e=!0}},[n?.uid,n?.emailVerified,c]),(0,s.jsx)(j.Provider,{value:{user:n,userRole:c,accessLevel:S(c),isInternal:T(c),isAdmin:w(c),loading:f,signOut:async()=>{await(0,a.signOut)(t.Vt),o(null)},registerUser:async(e,n,r,o)=>{let{createUserWithEmailAndPassword:s}=await import(`firebase/auth`),{user:c}=await s(t.Vt,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.Ht,`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.Vt.currentUser&&(await t.Vt.currentUser.reload(),o(Object.assign(Object.create(t.Vt.currentUser),{photoURL:t.Vt.currentUser.photoURL,displayName:t.Vt.currentUser.displayName,email:t.Vt.currentUser.email,emailVerified:t.Vt.currentUser.emailVerified})))},userInactive:u,roleResolved:m},children:e})}var N=()=>(0,r.useContext)(j);function P(){return(typeof window<`u`?window.__FBOS_PAGES__:null)||{}}function F(e=P()){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 I(){let[e,n]=(0,r.useState)(!1),[a,o]=(0,r.useState)([]),l=(0,r.useRef)(null),u=(0,r.useRef)(null),[d,f]=(0,r.useState)(null),p=(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 m=(0,r.useRef)({users:[],submissions:[],requests:[]}),h=(e,t)=>{m.current[e]=t;let n=[...m.current.users,...m.current.submissions,...m.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))},g=(e,t)=>{console.warn(`AdminNotifications: ${e} are not readable by this account.`,t),h(e,[])};(0,r.useEffect)(()=>{let e=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Ht,`user_profiles`),(0,i.orderBy)(`createdAt`,`desc`),(0,i.limit)(5)),e=>{h(`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}}))},e=>g(`users`,e)),n=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Ht,`user_submissions`),(0,i.orderBy)(`submittedAt`,`desc`),(0,i.limit)(5)),e=>{h(`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}}))},e=>g(`submissions`,e)),r=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Ht,`user_requests`),(0,i.orderBy)(`submittedAt`,`desc`),(0,i.limit)(5)),e=>{h(`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}}))},e=>g(`requests`,e));return()=>{e(),n(),r()}},[]);let[_,v]=(0,r.useState)(()=>typeof window<`u`?parseInt(localStorage.getItem(`admin_notifications_last_read`)||`0`,10):0),y=()=>{let t=!e;if(n(t),t){let e=u.current?.getBoundingClientRect();f(typeof window<`u`&&window.innerWidth<640&&e?e.bottom+8:null);let t=Date.now();v(t),typeof window<`u`&&localStorage.setItem(`admin_notifications_last_read`,t.toString())}},b=a.some(e=>{if(!e.time)return!0;let t=e.time?.toDate?e.time.toDate().getTime():new Date(e.time).getTime();return t>_||isNaN(t)}),x=e=>{n(!1),p(e===`user`?`/users`:e===`submission`?`/submissions`:`/requests`)},S=e=>{if(!e)return``;let t=e.toDate?e.toDate():new Date(e),n=Date.now()-t.getTime();if(isNaN(n))return``;let r=Math.floor(n/6e4);if(r<1)return`now`;if(r<60)return`${r}m`;let i=Math.floor(r/60);if(i<24)return`${i}h`;let a=Math.floor(i/24);return a<7?`${a}d`:new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`}).format(t)};return(0,s.jsxs)(`div`,{className:`relative z-50 flex-shrink-0`,ref:l,children:[(0,s.jsxs)(`button`,{ref:u,onClick:y,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] transition-all relative text-foreground/60 hover:bg-foreground/5 hover:text-foreground flex items-center justify-center shadow-sm cursor-pointer`,"aria-label":`Admin Notifications`,children:[(0,s.jsx)(t.Ot,{className:`w-4 h-4`}),b&&(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.m,{children:e&&(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:-5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98,y:-5},className:`${d===null?`absolute top-full mt-2 right-0`:`fixed right-4`} w-[min(320px,calc(100vw-2rem))] md:w-[400px] glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col origin-top-right overflow-hidden`,style:d===null?void 0:{top:d},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:()=>x(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.S,{className:`w-4 h-4`}):e.type===`submission`?(0,s.jsx)(t.U,{className:`w-4 h-4`}):(0,s.jsx)(t._t,{className:`w-4 h-4`})}),(0,s.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,s.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground group-hover:text-accent transition-colors truncate flex-1 min-w-0`,children:e.title}),(0,s.jsx)(`span`,{className:`text-[10px] font-mono tracking-wide text-foreground/40 shrink-0`,children:S(e.time)})]}),(0,s.jsx)(`span`,{className:`text-[12px] text-foreground/60 truncate`,children:e.subtitle})]})]},e.id))})]})})]})}var L=[{id:`guide`,hidden:!1},{id:`contact`,hidden:!1},{id:`templates`,hidden:!1},{id:`setup`,hidden:!1}],R={drive:`assets`,submissions:`inbox`,requests:`inbox`},z=e=>{let t=(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden}).map(e=>({...e,id:R[e.id]||e.id}));return t.filter((e,n)=>t.findIndex(t=>t.id===e.id)===n)},B=[{id:`pages`,hidden:!1},{id:`forms`,hidden:!1},{id:`inbox`,hidden:!1},{id:`users`,hidden:!1},{id:`theme`,hidden:!1},{id:`assets`,hidden:!1}],ee={route:`/support`,template:`popup_form`,form:`support`,tabName:`Support`,iconName:``},V={"/guide":t.vt,"/templates":t.Y,"/setup":t.M,"/contact":t.U},te=e=>e&&V[e]||t.Q,H={guide:{label:`Guide`,path:`/guide`},templates:{label:`Templates`,path:`/templates`},setup:{label:`Setup`,path:`/setup`},contact:{label:`Contact`,path:`/contact`}};function U({customMenu:e,standalone:n}){let{user:a,userRole:o,signOut:l}=N(),u=w(o),d=S(o),f=d===`free`?`Free User`:x[d],p=(0,c.useNavigate)(),[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(null),[v,y]=(0,r.useState)(!1),[b,C]=(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:A,activeConfig:j}=t.Rt(),M=async()=>{await l(),p(`/`),h(!1)},[P,R]=(0,r.useState)({...H}),[B,V]=(0,r.useState)(L);(0,r.useEffect)(()=>{if(!t.Ht)return;let e=(0,i.onSnapshot)((0,i.collection)(t.Ht,`sys_pages`),e=>{let t={...H};for(let[e,n]of F()){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||H[e.id]?.label||e.id,i=n.route||(e.id===`home`?`/`:`/`+e.id);t[e.id]={label:r,path:i}}),R(t)},e=>{console.warn(`sys_pages snapshot error (safe to ignore during auth transition):`,e)}),n=(0,i.onSnapshot)((0,i.doc)(t.Ht,`sys_configs`,`page_order`),e=>{V(e.exists()&&Array.isArray(e.data().order)?z(e.data().order):L)},e=>{console.warn(`page_order snapshot error (safe to ignore during auth transition):`,e)}),r=(0,i.onSnapshot)((0,i.doc)(t.Ht,`sys_tabs`,`support`),e=>{e.exists()&&e.data().pageName&&W(e.data().pageName)},e=>{console.warn(`support snapshot error (safe to ignore during auth transition):`,e)});return()=>{e(),n(),r()}},[]);let[U,W]=(0,r.useState)(ee.tabName),G=(()=>{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=P[e.id];r&&(n.push({label:r.label,path:r.path}),t.add(e.id))}),Object.entries(P).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})(),K=e||G,q=(0,r.useRef)(null),J=(0,r.useRef)(null),[Y,ne]=(0,r.useState)(()=>typeof window<`u`&&window.innerWidth<640);(0,r.useEffect)(()=>{if(typeof window>`u`)return;let e=()=>{let e=window.innerWidth<640;ne(t=>(t!==e&&h(!1),e))};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let[re,ie]=(0,r.useState)(K.length);(0,r.useEffect)(()=>{if(n||Y)return;let e=()=>{let e=q.current,t=J.current;if(!e||!t)return;let n=e.clientWidth,r=t.querySelectorAll(`[data-measure-nav]`);if(r.length===0){ie(K.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){ie(K.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++}ie(Math.max(s,1))},t=requestAnimationFrame(e);if(typeof ResizeObserver>`u`)return()=>cancelAnimationFrame(t);let r=new ResizeObserver(()=>requestAnimationFrame(e));return q.current&&r.observe(q.current),()=>{cancelAnimationFrame(t),r.disconnect()}},[K.map(e=>e.label).join(`|`),n,Y,K.length]);let ae=K.slice(0,re),X=K.slice(re);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 min-w-0 z-50`,children:(0,s.jsxs)(c.Link,{to:`/`,className:`flex items-center gap-2.5 md:gap-3 group cursor-pointer z-50 min-w-0`,children:[(0,s.jsx)(`div`,{className:`w-9 h-9 rounded-lg glass-panel flex items-center justify-center glow-hover shadow-lg transition-transform duration-500 group-hover:rotate-180 group-active:scale-95 overflow-hidden shrink-0`,children:j?.logoUrl?(0,s.jsx)(`img`,{src:j.logoUrl,alt:`Logo`,className:`w-full h-full object-contain`}):(0,s.jsx)(t.ft,{className:`w-4 h-4 text-accent`})}),(0,s.jsx)(`span`,{className:`font-bold text-[18px] md:text-[22px] tracking-tight text-gradient transition-all duration-300 drop-shadow-sm truncate`,children:j?.appName||``})]})}),(0,s.jsx)(t.m,{children:v&&(0,s.jsx)(t.t,{formId:`contact`,onClose:()=>y(!1)})}),(0,s.jsx)(t.m,{children:b&&(0,s.jsx)(t.t,{formId:`support`,onClose:()=>C(!1)})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2.5 md:gap-4 z-50 relative ml-auto flex-1 min-w-0 justify-end`,children:[!n&&!a&&!Y&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{ref:J,"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:K.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.wt,{className:`w-3 h-3`})]},e.path||n))}),(0,s.jsxs)(`div`,{className:`flex items-center gap-7 mr-6 flex-1 min-w-0 justify-end relative`,ref:q,children:[ae.map((e,n)=>(0,s.jsxs)(`div`,{className:`relative shrink-0`,onMouseEnter:()=>_(e.label),onMouseLeave:()=>_(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.wt,{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.wt,{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.p.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}`)),X.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.m,{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.p.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:X.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))})]})})]})]})]}),!n&&!a&&(0,s.jsxs)(s.Fragment,{children:[j?.showThemeToggle&&(0,s.jsx)(`button`,{onClick:A,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] hover:bg-foreground/5 transition-all text-foreground/60 hover:text-foreground flex items-center justify-center shadow-sm shrink-0 cursor-pointer`,"aria-label":`Toggle Theme`,children:k===`dark`?(0,s.jsx)(t.O,{className:`w-4 h-4`}):(0,s.jsx)(t.V,{className:`w-4 h-4`})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2.5 shrink-0`,children:[!Y&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(c.Link,{to:`/login`,className:`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:`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 shrink-0`,children:`Get Started`})]}),Y&&(0,s.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>h(m===`guest`?!1:`guest`),"aria-label":`Open menu`,"aria-expanded":m===`guest`,className:`w-9 h-9 rounded-xl glass-panel glow-hover border transition-all flex items-center justify-center ${m===`guest`?`border-accent bg-foreground/5`:`border-[var(--panel-border)] hover:bg-foreground/5`}`,children:(0,s.jsx)(t.H,{className:`w-5 h-5 text-accent/80`})}),(0,s.jsx)(t.m,{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.p.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:[K.map((e,t)=>{let n=te(e.path);return e.path?(0,s.jsxs)(c.Link,{to:e.path,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 min-w-0`,children:[(0,s.jsx)(n,{className:`w-4 h-4 text-accent/70 shrink-0`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold truncate`,children:e.label})]},`${e.path}-${t}`):(0,s.jsxs)(`button`,{onClick:()=>{e.action&&e.action(),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 min-w-0`,children:[(0,s.jsx)(n,{className:`w-4 h-4 text-accent/70 shrink-0`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold truncate`,children:e.label})]},`${e.label}-${t}`)}),(0,s.jsx)(`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.W,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Sign In`})]})})]})]})})]})]})]}),!n&&a&&(0,s.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[o===`admin`&&(0,s.jsx)(I,{}),j?.showThemeToggle&&(0,s.jsx)(`button`,{onClick:A,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] hover:bg-foreground/5 transition-all text-foreground/60 hover:text-foreground flex items-center justify-center shadow-sm shrink-0 cursor-pointer`,"aria-label":`Toggle Theme`,children:k===`dark`?(0,s.jsx)(t.O,{className:`w-4 h-4`}):(0,s.jsx)(t.V,{className:`w-4 h-4`})}),(0,s.jsxs)(`div`,{className:`relative z-50 flex-shrink-0`,children:[(0,s.jsxs)(`button`,{onClick:()=>h(m===`user`?!1:`user`),className:`flex items-center gap-2 group p-0.5 sm:p-1 sm:pr-2.5 rounded-full hover:bg-foreground/5 transition-all duration-300 cursor-pointer sm:border ${m===`user`?`sm:border-accent/50 sm:bg-foreground/5`:`sm:border-[var(--panel-border)] sm:hover:border-accent/30`}`,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 sm:border-0 transition-colors shrink-0 text-accent ${m===`user`?`border-accent/50`:`border-[var(--panel-border)] group-hover:border-accent/30`}`,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.S,{className:`w-4 h-4 md:w-5 md:h-5 text-accent`})}),(0,s.jsxs)(`div`,{className:`max-sm: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.m,{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.p.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:`/dashboard`,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.Z,{className:`w-3 h-3 text-accent`})}),`Dashboard`]}),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.rt,{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.x,{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.tt,{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.Q,{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._t,{className:`w-3 h-3 text-accent`})}),U]}),(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.S,{className:`w-3 h-3 text-accent`})}),`Profile Settings`]})]}),(0,s.jsx)(`div`,{className:`pt-1 mt-1 border-t border-[var(--panel-border)]/50`,children:(0,s.jsxs)(`button`,{onClick:M,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`]})})]})]})})]})]}),n&&(0,s.jsx)(s.Fragment,{children:j?.showThemeToggle&&(0,s.jsx)(`button`,{onClick:A,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] hover:bg-foreground/5 transition-all text-foreground/60 hover:text-foreground flex items-center justify-center shadow-sm shrink-0 cursor-pointer`,"aria-label":`Toggle Theme`,children:k===`dark`?(0,s.jsx)(t.O,{className:`w-4 h-4`}):(0,s.jsx)(t.V,{className:`w-4 h-4`})})})]})]})}function W(){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.p.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.p.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._,{className:`w-4 h-4 text-accent`}),` The Open-Source Firebase Starter`]}),(0,s.jsx)(t.p.h1,{className:`text-4xl sm:text-5xl md:text-6xl lg:text-[4.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.p.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.m,{children:e&&(0,s.jsx)(t.t,{onClose:()=>n(null),formId:e})})]})}var G=[{id:`length`,label:`At least 8 characters`,ok:e=>e.length>=8},{id:`case`,label:`An uppercase and a lowercase letter`,ok:e=>/[a-z]/.test(e)&&/[A-Z]/.test(e)},{id:`number`,label:`A number`,ok:e=>/[0-9]/.test(e)}],K=new Set(`password1.password12.password123.password1234.passw0rd1.p@ssword1.p@ssw0rd1.test1234.test12345.testing123.test123456.qwerty123.qwerty1234.abcd1234.abc12345.welcome1.welcome123.admin123.admin1234.letmein123.iloveyou1.monkey123.football1.changeme1.secret123.summer2024.summer2025`.split(`.`)),q=e=>e.toLowerCase().replace(/[\s._-]/g,``),J=e=>K.has(q(e||``)),Y=e=>G.map(t=>({rule:t,met:t.ok(e||``)}));function ne(e){let t=e||``;if(!t)return`Choose a password.`;let n=G.find(e=>!e.ok(t));return n?`Your password needs ${n.label.toLowerCase()}.`:J(t)?`That password is one of the first anyone would guess. Please pick another.`:``}function re(e,t){return t?e===t?``:`Both passwords must be the same.`:`Type your password a second time.`}function ie({value:e,className:n=``}){return(0,s.jsx)(`ul`,{className:`flex flex-col gap-1 ml-1 ${n}`,"aria-label":`Password requirements`,children:Y(e).map(({rule:e,met:n})=>(0,s.jsxs)(`li`,{className:`flex items-center gap-2 text-[12.5px] font-medium transition-colors ${n?`text-emerald-500`:`text-foreground/45`}`,children:[n?(0,s.jsx)(t.Tt,{className:`w-3.5 h-3.5 shrink-0`}):(0,s.jsx)(`span`,{className:`w-3.5 flex justify-center shrink-0`,children:(0,s.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-foreground/25`})}),e.label]},e.id))})}function ae(){let[e,n]=(0,r.useState)(!1),[i,o]=(0,r.useState)(null),[l,u]=(0,r.useState)(``),[d,f]=(0,r.useState)(``),[p,m]=(0,r.useState)(``),[h,g]=(0,r.useState)(``),_=(0,c.useNavigate)(),{registerUser:v}=N();return(0,s.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mt-6 mb-8 md:mt-0 md:mb-0 md:pt-8 md:pb-32`,children:(0,s.jsxs)(t.p.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(`firstName`),a=t.get(`lastName`),u=ne(l),f=u?``:re(l,d);if(m(u),g(f),u||f){o(u||f),n(!1);return}try{await v(r,l,i,a),_(`/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(ne(l)||`Please choose a stronger password.`):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.l,{name:`firstName`,label:`First Name`,type:`text`,placeholder:`John`,required:!0}),(0,s.jsx)(t.l,{name:`lastName`,label:`Last Name`,type:`text`,placeholder:`Doe`,required:!0})]}),(0,s.jsx)(t.l,{name:`email`,label:`Email`,type:`email`,placeholder:`name@example.com`,required:!0}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,s.jsx)(t.l,{name:`password`,label:`Password`,type:`password`,placeholder:`••••••••`,autoComplete:`new-password`,value:l,onChange:e=>{u(e.target.value),p&&m(``),h&&e.target.value===d&&g(``)},onBlur:()=>m(l?ne(l):``),error:p,required:!0}),l&&(0,s.jsx)(ie,{value:l})]}),l&&(0,s.jsx)(t.l,{name:`confirmPassword`,label:`Confirm password`,type:`password`,placeholder:`••••••••`,autoComplete:`new-password`,value:d,onChange:e=>{f(e.target.value),h&&g(``)},onBlur:()=>g(d?re(l,d):``),error:h,required:!0}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsxs)(t.c,{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.jt,{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.c,{variant:`secondary`,onClick:async()=>{n(!0),o(null);try{if(!t.Vt)throw Error(`Firebase is not initialized. Check your configuration.`);let e=new a.GoogleAuthProvider;try{await(0,a.signInWithPopup)(t.Vt,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.Vt,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 X(){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 mb-8 md:mt-0 md:mb-0 md:pt-8 md:pb-32`,children:(0,s.jsxs)(t.p.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.Vt)throw Error(`Firebase is not initialized. Check your configuration.`);await(0,a.signInWithEmailAndPassword)(t.Vt,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.l,{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.l,{name:`password`,type:`password`,placeholder:`••••••••`,required:!0})]}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsxs)(t.c,{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.jt,{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.c,{variant:`secondary`,onClick:async()=>{n(!0),o(null);try{if(!t.Vt)throw Error(`Firebase is not initialized. Check your configuration.`);let e=new a.GoogleAuthProvider;try{await(0,a.signInWithPopup)(t.Vt,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.Vt,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 oe(){let{user:e,refreshUser:n}=N(),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.p.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.U,{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.c,{variant:`primary`,onClick:async()=>{l(!0),p(``);try{if(t.Vt.currentUser){if(await t.Vt.currentUser.reload(),!t.Vt.currentUser.emailVerified){p(`Email is not verified yet. Please check your inbox.`),l(!1);return}await t.Vt.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.c,{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`})]})]})})}function Z(...e){return t.u(t.d(e))}var se=.72,ce=({className:e,children:t,...n})=>{let i=(0,r.useRef)(null);return(0,r.useLayoutEffect)(()=>{let e=i.current,t=e?.parentElement;if(!e||!t)return;let n=()=>{e.style.removeProperty(`font-size`),e.removeAttribute(`data-fold`);let n=t.clientWidth,r=e.scrollWidth;if(!n||r<=n)return;let i=parseFloat(window.getComputedStyle(e).fontSize)||24,a=n/r;e.style.setProperty(`font-size`,`${(i*Math.max(a,se)).toFixed(2)}px`,`important`),a<se&&e.setAttribute(`data-fold`,``)};if(n(),document.fonts?.ready.then(n).catch(()=>{}),typeof ResizeObserver>`u`)return;let r=new ResizeObserver(n);return r.observe(t),()=>r.disconnect()},[t]),(0,s.jsx)(`h1`,{ref:i,className:Z(`page-title w-fit inline-block tracking-tight mb-3 mt-1 text-gradient`,e),...n,children:t})};ce.displayName=`PageTitle`;var le=A(`admin`),ue={pages:{path:`/pages`,label:`Pages`,icon:t.Q,roles:le},forms:{path:`/forms`,label:`Forms`,icon:t.I,roles:le},inbox:{path:`/inbox`,label:`Inbox`,icon:t.tt,roles:le},users:{path:`/users`,label:`Users`,icon:t.x,roles:le},theme:{path:`/theme`,label:`Theme`,icon:t.B,roles:le},assets:{path:`/assets`,label:`Assets`,icon:t.rt,roles:le}};function de({customTabs:e=[]}){let{pathname:n}=(0,c.useLocation)(),{user:a,userRole:o}=N(),[l,u]=(0,r.useState)(!1),d=(0,r.useRef)(null),[f,p]=(0,r.useState)({}),[m,h]=(0,r.useState)(B);(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.Ht,`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.Ht,`sys_configs`,`tab_order`),e=>{let t=e.exists()&&Array.isArray(e.data().order)?z(e.data().order):B;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(ue).forEach(([t,n])=>{e[t]={id:t,...n,exact:!0}});let n={...f};for(let[e,t]of F())t.isPublic||(n[e]={...t.config,...f[e]});Object.entries(n).forEach(([n,r])=>{let i=e[n],a=i?.icon??t.Q;if(r?.iconName){let e=r.iconName.trim(),n=e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);t.h[n]?a=t.h[n]:t.h[e]&&(a=t.h[e])}let o=i?.roles??le;r?.pageType&&(o=A(D(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||i.has(t.id)||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=k(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=parseFloat(getComputedStyle(e).columnGap)||40,i=t.querySelectorAll(`[data-measure-tab]`);if(i.length===0){b(g.length);return}let a=0,o=!0;for(let e=0;e<i.length;e++)if(a+=i[e].offsetWidth+(e>0?r:0),a>n){o=!1;break}if(o){b(g.length);return}let s=0,c=0;for(let e=0;e<i.length;e++){let t=i[e].offsetWidth,a=s+t+(e>0?r:0);if(a+52>n)break;s=a,c++}b(Math.max(c,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),w=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-5 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 ${w?`text-accent border-accent`:`text-foreground/50 hover:text-foreground/80 border-transparent`}`,title:`More items`,children:(0,s.jsx)(t.ut,{className:`w-5 h-5`})}),(0,s.jsx)(t.m,{children:l&&(0,s.jsx)(t.p.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 fe(){let{user:e,refreshUser:n,isInternal:c}=N(),[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)(``),[C,w]=(0,r.useState)(``),[T,D]=(0,r.useState)(!1),[O,k]=(0,r.useState)(!1),[A,j]=(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 M=async n=>{if(e)try{if(!c)return;let r=[`mem_files`,`admin_files`];(await(0,i.getDocs)((0,i.collection)(t.Ht,`sys_tabs`))).forEach(e=>{let t=e.data(),n=(t.tabName||e.id).toLowerCase().replace(/[^a-z0-9]+/g,`_`),i=E(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.Ht,a),(0,i.where)(`uid`,`==`,e.uid)));if(r.empty)continue;let o=(0,i.writeBatch)(t.Ht);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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-5 sm:mb-8`,children:[(0,s.jsx)(ce,{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-4 sm:gap-6 animate-in fade-in duration-500 pb-20`,children:[(0,s.jsx)(`div`,{className:`flex justify-start`,children:(0,s.jsx)(de,{})}),(0,s.jsx)(t.m,{children:_&&(0,s.jsxs)(t.p.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.yt,{className:`w-5 h-5 shrink-0`}):(0,s.jsx)(t.bt,{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.Vt,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){let t=ne(y);if(t)throw Error(t);let n=re(y,x);if(n)throw w(n),Error(n);await(0,a.updatePassword)(e,y),b(``),S(``),w(``)}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-5 sm:p-8 md:p-12 rounded-3xl border border-[var(--panel-border)] shadow-2xl space-y-8 md:min-h-[500px]`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-4 sm:gap-5 pb-6 border-b border-[var(--panel-border)]/50`,children:[(0,s.jsxs)(`div`,{className:`relative shrink-0 group/avatar`,children:[(0,s.jsxs)(`div`,{className:`w-16 h-16 sm:w-20 sm:h-20 rounded-full glass-panel border-2 border-[var(--panel-border)] shadow-lg bg-accent/10 flex items-center justify-center relative overflow-hidden`,children:[(O||p&&A&&!T)&&(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.K,{className:`w-6 h-6 text-accent animate-spin`})}),p&&!T?(0,s.jsx)(`img`,{src:p,alt:`Avatar`,className:`w-full h-full object-cover transition-opacity duration-300 ${A?`opacity-0`:`opacity-100`}`,onLoad:()=>j(!1),onError:()=>{D(!0),j(!1)}}):(0,s.jsx)(t.S,{className:`w-7 h-7 sm:w-8 sm:h-8 text-accent`})]}),!O&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(`label`,{title:p?`Change photo`:`Upload photo`,className:`absolute inset-0 rounded-full bg-background/60 backdrop-blur-[2px] opacity-0 group-hover/avatar:opacity-100 focus-within:opacity-100 flex items-center justify-center cursor-pointer transition-opacity z-20`,children:[(0,s.jsx)(t.Et,{className:`w-4 h-4 text-foreground`}),(0,s.jsx)(`input`,{type:`file`,accept:`image/*`,"aria-label":`Upload photo`,onChange:async r=>{let s=r.target.files?.[0];if(!s||!e)return;let c=await t.o(s,{maxSide:512});if(c.size>2*1024*1024){v({text:`File too large. Please select an image under 2MB.`,type:`error`});return}k(!0),D(!1),j(!0);try{let r=(0,o.ref)(t.Wt,`user_avatars/${e.uid}/file.png`);await(0,o.uploadBytes)(r,c,{customMetadata:{ownerId:e.uid}});let s=await(0,o.getDownloadURL)(r);m(s);let l=(0,i.doc)(t.Ht,`user_profiles`,e.uid);await Promise.all([(0,a.updateProfile)(e,{photoURL:s}),(0,i.updateDoc)(l,{avatar:s}),M(s)]),await n(),v({text:`Avatar successfully updated!`,type:`success`})}catch(e){console.error(e),v({text:`Failed to upload photo.`,type:`error`})}finally{k(!1)}},className:`hidden`})]}),p&&(0,s.jsx)(`button`,{type:`button`,onClick:async()=>{if(e){k(!0),D(!1),j(!1);try{let r=(0,o.ref)(t.Wt,`user_avatars/${e.uid}/file.png`);m(``),k(!1);let s=(0,i.doc)(t.Ht,`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:``}),M(``)]),await n(),v({text:`Avatar removed.`,type:`success`})}catch(e){console.error(e),v({text:`Failed to delete photo.`,type:`error`}),k(!1)}}},title:`Remove photo`,"aria-label":`Remove photo`,className:`hidden group-hover/avatar:flex absolute -top-1 -right-1 w-6 h-6 rounded-full bg-background border border-[var(--panel-border)] text-foreground/50 hover:text-red-500 hover:border-red-500/40 items-center justify-center shadow-sm cursor-pointer z-30`,children:(0,s.jsx)(t.E,{className:`w-3 h-3`})})]})]}),(0,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsx)(`h3`,{className:`font-extrabold text-lg sm:text-xl text-foreground mb-1 truncate`,children:l||`User`}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/40 mt-1 font-medium break-words`,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.l,{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.l,{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.l,{name:`password`,type:`password`,label:`New Password`,autoComplete:`new-password`,value:y,onChange:e=>{b(e.target.value),C&&e.target.value===x&&w(``)},placeholder:`At least 8 characters`}),(0,s.jsx)(t.l,{name:`confirmPassword`,type:`password`,label:`Confirm New Password`,autoComplete:`new-password`,value:x,onChange:e=>{S(e.target.value),C&&w(``)},onBlur:()=>w(x?re(y,x):``),error:C,placeholder:`Type it a second time`})]}),y&&(0,s.jsx)(ie,{value:y,className:`mt-3`})]}),(0,s.jsx)(`div`,{className:`pt-6 md:pt-8 border-t border-[var(--panel-border)]/50 flex justify-start w-full`,children:(0,s.jsx)(t.c,{type:`submit`,isLoading:h,className:`w-full sm:w-auto sm: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 pe(){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-0 md:mb-0 md:pt-8 md:pb-32`,children:(0,s.jsxs)(t.p.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.$,{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.Vt,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.l,{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.c,{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.Mt,{className:`w-4 h-4 mr-2`}),`Back to Sign In`]})})]})})}var me={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`},he=({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 ${me[e]}`,children:x[e]}),ge=`(max-width: 767px)`,_e=()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(ge).matches;function ve(){let[e,t]=(0,r.useState)(_e);return(0,r.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(ge),n=()=>t(e.matches);return n(),e.addEventListener?.(`change`,n),()=>e.removeEventListener?.(`change`,n)},[]),e}function ye(){let{user:e,userRole:n}=N(),[a,l]=(0,r.useState)(!0),u=(0,c.useNavigate)(),{id:d}=(0,c.useParams)(),f=ve(),[p,m]=(0,r.useState)([]),[h,g]=(0,r.useState)(null),[_,v]=(0,r.useState)(!1),[b,w]=(0,r.useState)(``),[T,E]=(0,r.useState)(!1),D=d?p.find(e=>e.id===d)||null:p.length>0?p[0]:null,O=e=>{u(e?`/users/${e.id}`:`/users`)};(0,r.useEffect)(()=>{l(!0);let e=(0,i.onSnapshot)((0,i.collection)(t.Ht,`user_profiles`),e=>{let t=[];e.forEach(e=>{t.push({id:e.id,...e.data()})}),m(t),l(!1),!d&&t.length>0&&!_e()&&u(`/users/${t[0].id}`,{replace:!0})},e=>{console.error(`Error fetching users:`,e),l(!1)});return()=>e()},[d,u]);let k=p.find(t=>t.id===e?.uid),A=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,j=async(e,r)=>{if(!(n!==`admin`||!A(e))&&S(e.role)!==r)try{await(0,i.updateDoc)((0,i.doc)(t.Ht,`user_profiles`,e.id),{role:C(r)}),g({text:`Access level set to ${x[r]}`,type:`success`}),setTimeout(()=>g(null),3e3)}catch(e){g({text:e.message,type:`error`}),setTimeout(()=>g(null),3e3)}},M=async(e,r)=>{if(!(n!==`admin`||!A(e)))try{await(0,i.updateDoc)((0,i.doc)(t.Ht,`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(v(!1),!(!D||!A(D)||b===D.displayName))try{await(0,i.updateDoc)((0,i.doc)(t.Ht,`user_profiles`,D.id),{displayName:b}),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||!A(D))return;let r=await t.o(n,{maxSide:512});if(r.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.Wt,`user_avatars/${D.id}/file.png`);await(0,o.uploadBytes)(e,r);let n=await(0,o.getDownloadURL)(e);m(e=>e.map(e=>e.id===D.id?{...e,avatar:n}:e)),await(0,i.updateDoc)((0,i.doc)(t.Ht,`user_profiles`,D.id),{avatar:n}),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);if((0,r.useEffect)(()=>{let e;return a&&p.length===0?e=setTimeout(()=>L(!0),150):L(!1),()=>clearTimeout(e)},[a,p.length]),a&&p.length===0)return 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.K,{className:`w-8 h-8 animate-spin text-accent`})}):null;let R=f&&!!d,z=!R,B=!f||!!d;return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto z-10 flex flex-col min-h-screen p-4 pt-2 md:p-8 md:pt-4`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,s.jsx)(ce,{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 animate-in fade-in duration-500 gap-6 ${R?`flex-1 pb-6`:`pb-20`}`,children:[(0,s.jsx)(t.m,{children:h&&(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:`p-4 text-[14px] font-medium border rounded-xl ${h.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)]`} flex items-center gap-2`,children:[h.type===`success`&&(0,s.jsx)(t.yt,{className:`w-4 h-4 shrink-0`}),h.text]})}),(0,s.jsx)(`div`,{className:`flex justify-start`,children:(0,s.jsx)(de,{})}),(0,s.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] bg-[var(--panel-bg)] overflow-hidden rounded-3xl shadow-2xl ${R?`flex-1 flex flex-col`:``}`,children:p.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 md:min-h-[500px] ${R?`flex-1`:``}`,children:[z&&(0,s.jsxs)(`div`,{className:`flex md:col-span-1 border-r md:border-r-[var(--panel-border)] border-b md:border-b-0 border-[var(--panel-border)] 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 md:max-h-[520px]`,children:p.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-foreground/[0.06] 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/10 shrink-0 flex items-center justify-center border border-accent/20`,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.S,{className:`w-5 h-5 text-accent`})}),(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] truncate`,children:e.displayName||`No Name`}),(0,s.jsx)(he,{level:S(e.role)})]}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/50 truncate font-mono mt-0.5`,children:e.email})]}),f&&(0,s.jsx)(t.St,{className:`w-4 h-4 text-foreground/25 shrink-0`})]},e.id))})]}),B&&(0,s.jsx)(`div`,{className:`flex md:col-span-2 flex-col relative ${R?`px-4 pt-4 pb-10`:`p-5 sm:p-6 md:p-10`}`,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 flex-row items-center gap-3 sm:gap-6 md:gap-8 mb-8 sm:mb-10`,children:[R&&(0,s.jsx)(`button`,{type:`button`,onClick:()=>O(null),"aria-label":`Back to all users`,className:`shrink-0 -ml-1.5 w-7 h-7 flex items-center justify-center rounded-lg text-foreground/40 hover:text-foreground active:bg-foreground/5 transition-colors cursor-pointer`,children:(0,s.jsx)(t.Mt,{className:`w-5 h-5`})}),(0,s.jsxs)(`div`,{className:`relative shrink-0 group/avatar`,children:[(0,s.jsx)(`div`,{className:`w-14 h-14 sm:w-24 sm:h-24 rounded-full glass-panel border-2 sm:border-4 border-[var(--panel-border)] shadow-lg sm:shadow-xl bg-accent/10 flex items-center justify-center overflow-hidden`,children:T?(0,s.jsx)(t.K,{className:`w-5 h-5 sm:w-8 sm: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.S,{className:`w-6 h-6 sm:w-10 sm:h-10 text-accent`})}),!T&&A(D)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(`label`,{title:`Change photo`,className:`max-sm:hidden sm:flex absolute -bottom-0.5 -right-0.5 w-9 h-9 rounded-full btn-primary text-white items-center justify-center cursor-pointer shadow-lg border-2 border-[var(--bg-color)] hover:scale-105 active:scale-95 transition-transform z-10`,children:[(0,s.jsx)(t.Et,{className:`w-4 h-4`}),(0,s.jsx)(`input`,{type:`file`,accept:`image/*`,"aria-label":`Change photo`,onChange:F,className:`hidden`})]}),(0,s.jsxs)(`label`,{title:`Change photo`,className:`flex sm:hidden absolute inset-0 rounded-full bg-background/60 backdrop-blur-[2px] opacity-0 group-hover/avatar:opacity-100 focus-within:opacity-100 items-center justify-center cursor-pointer transition-opacity z-10`,children:[(0,s.jsx)(t.Et,{className:`w-4 h-4 text-foreground`}),(0,s.jsx)(`input`,{type:`file`,accept:`image/*`,"aria-label":`Change photo`,onChange:F,className:`hidden`})]})]})]}),(0,s.jsxs)(`div`,{className:`flex flex-col flex-1 w-full min-w-0 relative`,children:[_?(0,s.jsx)(`input`,{autoFocus:!0,value:b,onChange:e=>w(e.target.value),onBlur:P,onKeyDown:e=>e.key===`Enter`&&P(),className:`text-xl sm: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:()=>{A(D)&&(w(D.displayName||``),v(!0))},className:`text-xl sm:text-2xl md:text-3xl font-extrabold mb-1 select-none break-words ${A(D)?`cursor-pointer hover:text-accent transition-colors`:``}`,title:A(D)?`Double-click to edit`:``,children:D.displayName||`No Name`}),(0,s.jsx)(`p`,{className:`text-[13px] sm:text-[14px] font-mono text-foreground/50 break-all`,children:D.email}),!A(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.G,{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.jsx)(`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 ${A(D)?``:`opacity-50`}`,children:y.map(e=>{let t=S(D.role)===e;return(0,s.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t,disabled:!A(D),onClick:()=>j(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`} ${A(D)?`cursor-pointer`:`cursor-not-allowed`}`,children:x[e]},e)})})]})}),(0,s.jsxs)(`div`,{className:`p-4 rounded-2xl glass-panel border flex items-center justify-between gap-3 ${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:!A(D),onClick:()=>M(D,!D.inactive),className:`relative inline-flex h-7 w-12 shrink-0 items-center rounded-full transition-colors focus:outline-none shadow-inner ${D.inactive?`bg-amber-500`:`bg-red-500/20`} ${A(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.x,{className:`w-12 h-12 mb-4`}),(0,s.jsx)(`p`,{className:`font-bold tracking-widest uppercase text-[12px]`,children:`Select a User`})]})})]})})]})]})}function be({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.m,{children:e&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.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.p.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.c,{variant:`secondary`,onClick:c,disabled:l,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:a}),(0,s.jsx)(t.c,{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.K,{className:`w-5 h-5 animate-spin mx-auto`}):i})]})]})})]})})}var xe=`rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)] transition-colors hover:border-accent/40`,Se=`inline-flex items-center justify-center gap-1.5 h-8 px-2.5 sm:h-9 sm:px-3 shrink-0 whitespace-nowrap 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`,Ce=`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`,we=`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`,Te=`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`,Ee=`text-[12.5px] sm:text-[13px] font-medium text-foreground/50 select-none`;function De({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.K,{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,compact:u}){return(0,s.jsxs)(`button`,{type:`button`,title:l,onClick:r,disabled:i||a,className:`${Se} ${o===`danger`?`hover:text-red-500 hover:border-red-500/40 hover:bg-red-500/[0.06]`:``} ${u?`max-sm:w-8 max-sm:px-0 max-sm:gap-0 max-sm:border-transparent max-sm:hover:border-transparent max-sm:hover:bg-foreground/[0.06]`:``} ${c}`,children:[a?(0,s.jsx)(t.K,{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,u?(0,s.jsx)(`span`,{className:`max-sm:hidden sm:inline-flex items-center gap-1.5`,children:n}):n]})}function Oe({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)]/60 bg-foreground/[0.015] overflow-hidden transition-all`,children:[(0,s.jsxs)(`div`,{className:`w-full px-4 sm:px-5 py-4 grid grid-cols-[auto_minmax(0,1fr)_auto_auto] items-center gap-x-3 sm:gap-x-3.5 gap-y-0.5 text-left`,children:[e&&(0,s.jsx)(`div`,{className:`row-start-1 col-start-1 row-span-2 self-center w-10 h-10 rounded-2xl flex items-center justify-center shrink-0 border border-[var(--panel-border)]/50 bg-accent/10 text-accent`,children:(0,s.jsx)(e,{className:`w-5 h-5`})}),(0,s.jsx)(`span`,{className:`row-start-1 col-start-2 min-w-0 text-[15px] font-bold text-foreground tracking-tight leading-tight truncate self-end`,children:n}),a&&(0,s.jsx)(`div`,{className:`row-start-1 row-span-2 col-start-3 self-center justify-self-end flex items-center gap-1 sm: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:`row-start-1 col-start-4 row-span-2 self-center w-8 h-8 rounded-xl border border-[var(--panel-border)]/60 hover:border-accent/40 flex items-center justify-center text-foreground/50 hover:text-foreground hover:bg-foreground/5 transition-all cursor-pointer justify-self-end`,children:(0,s.jsx)(t.wt,{className:`w-4 h-4 transition-transform duration-200 ${f?`rotate-180`:``}`})}),i&&(0,s.jsx)(`span`,{className:`row-start-2 col-start-2 min-w-0 text-[12px] text-foreground/50 font-normal leading-snug truncate self-start`,children:i})]}),(0,s.jsx)(t.m,{initial:!1,children:f&&(0,s.jsx)(t.p.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)]/40 p-4 sm:p-5 flex flex-col gap-5 bg-background/30`,children:o})})})]})}function ke({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 sm:mb-1.5 ml-1`,children:[(0,s.jsx)(`label`,{className:Ee,children:e}),n]}),r,t&&!i&&(0,s.jsx)(`span`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug mt-1 sm: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 sm:mt-1.5 px-1`,children:i})]})}function Ae({label:e,hint:t,value:n,onChange:r,onBlur:i,placeholder:a,prefix:o,error:c,disabled:l,action:u}){return(0,s.jsx)(ke,{label:e,hint:t,error:c,action:u,children:o?(0,s.jsxs)(`div`,{className:`${we} ${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:`${Te} 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:`${Ce} ${c?`is-invalid border-red-500/60`:``}`})})}function je({value:e,className:t=``,...n}){let i=(0,r.useRef)(null),a=r.default.useCallback(()=>{let e=i.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight+(e.offsetHeight-e.clientHeight)}px`)},[]);return(0,r.useLayoutEffect)(a,[a,e]),(0,r.useEffect)(()=>{let e=i.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(a);return e.parentElement&&t.observe(e.parentElement),()=>t.disconnect()},[a]),(0,s.jsx)(`textarea`,{ref:i,rows:1,value:e??``,onInput:a,className:`${t} resize-none overflow-hidden`,...n})}function Me({label:e,hint:t,value:n,onChange:r,onBlur:i,placeholder:a}){return(0,s.jsx)(ke,{label:e,hint:t,children:(0,s.jsx)(je,{value:n??``,placeholder:a,onChange:e=>r(e.target.value),onBlur:i,"aria-label":e,className:`${Ce.replace(`h-11 `,``)} min-h-11 py-2.5 leading-5`})})}function Ne({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)(ke,{label:e,hint:n,children:(0,s.jsx)(t.s,{ariaLabel:e,value:r??``,options:u,onChange:i,disabled:l,className:`console-select`,dense:!0,portal:!0,direction:`auto`})})}function Pe({label:e,hint:t,enabled:n,onChange:r,disabled:i,hintWideOnly:a}){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-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug${a?` max-sm:hidden`:``}`,children:t})]}),(0,s.jsx)(Fe,{enabled:n,onChange:r,disabled:i,label:e})]})}function Fe({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 Ie({saving:e,savedAt:t}){return e?(0,s.jsx)(De,{state:`saving`,label:`Saving`}):t?(0,s.jsx)(De,{state:`saved`,label:`Saved`}):null}var Le=e=>e.trim().split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),Re=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/([A-Z])([A-Z][a-z])/g,`$1-$2`).toLowerCase(),ze=e=>{let t=e.replace(/-/g,` `);return t.charAt(0).toUpperCase()+t.slice(1)},Be=(()=>{let e=t.g,n=e?Object.keys(e):[];return n.length===0&&(n=Object.keys(t.h).filter(e=>/^[A-Z]/.test(e)&&!/Icon$/.test(e)&&!/^Lucide/.test(e)&&e!==`IconNode`)),Array.from(new Set(n.map(Re))).sort()})(),Ve=`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(`.`),He={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`]},Ue=(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 Ge(e,t=96,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 He[e]||[])s(t,70);if(e.endsWith(`s`))for(let t of He[e.slice(0,-1)]||[])s(t,70)}if(o.size===0&&r.length>=3)for(let e of n)e.split(`-`).some(e=>Ue(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=Ve.indexOf(e);return t===-1?Ve.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 Ke(e){if(!e)return t.Q;let n=e.trim(),r=t.h;return r[Le(n)]||r[n]||t.Q}function qe({name:e,className:t}){return(0,r.createElement)(Ke(e),{className:t})}function Je({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)(()=>Ge(o),[o]),d=o.trim().length>0;return(0,s.jsx)(ke,{label:e,hint:n,children:(0,s.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,s.jsxs)(`div`,{className:we,children:[l&&!d?(0,s.jsxs)(`span`,{className:`inline-flex items-center gap-2 mr-2.5 shrink-0 min-w-0 text-accent`,children:[(0,s.jsx)(`span`,{className:`w-7 h-7 -ml-1 rounded-lg bg-accent/[0.08] border border-accent/25 flex items-center justify-center shrink-0`,children:(0,s.jsx)(qe,{name:l,className:`w-4 h-4`})}),(0,s.jsx)(`span`,{className:`text-[13px] font-semibold truncate`,children:ze(Re(l))}),(0,s.jsx)(t.Tt,{className:`w-3.5 h-3.5 shrink-0`})]}):(0,s.jsx)(t.P,{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:l?`Type a word to change it`:`Type a word, e.g. calendar`,"aria-label":`Search icons`,className:`${Te} 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 max-h-56 overflow-y-auto`,children:u.length>0?(0,s.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>{let t=Re(l).toLowerCase()===e;return(0,s.jsx)(`button`,{type:`button`,title:ze(e),"aria-label":ze(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)] ring-2 ring-accent/40`:`text-foreground/60 hover:text-foreground hover:bg-foreground/[0.06]`}`,children:(0,s.jsx)(qe,{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.`})})]})})}var Ye=/(<[A-Z][A-Za-z0-9]*(?:\s[^<>]*)?\/?>|src\/[A-Za-z0-9_./-]*[A-Za-z0-9_-]|'[A-Za-z0-9_@./-]+')/g,Xe=/(https?:\/\/[^\s]+)/g,Ze=e=>e.split(Xe).flatMap((e,t)=>t%2==1?[{text:e,kind:`value`}]:e.split(Ye).map((e,t)=>({text:e,kind:t%2==1?`code`:void 0}))).filter(e=>e.text),Qe=/exactly: |Here is what [^:]*: |It should ask for: |Where the form belongs on the page: |a button that says /,$e=e=>{let t=Qe.exec(e);if(!t)return Ze(e);let n=t.index+t[0].length,r=e.slice(0,n),i=e.slice(n),a=i.indexOf(` — `);return[...Ze(r),{text:a===-1?i:i.slice(0,a),kind:`value`},...Ze(a===-1?``:i.slice(a))]},et=`text-accent font-semibold bg-accent/[0.08] rounded-[4px] px-1 -mx-[1px] [overflow-wrap:anywhere]`,tt=`font-mono text-[0.92em] text-foreground/75 bg-foreground/[0.055] border border-[var(--panel-border)]/60 rounded-[4px] px-1 py-[1px] [overflow-wrap:anywhere]`;function nt({text:e}){return(0,s.jsx)(s.Fragment,{children:$e(e).map((e,t)=>e.kind?(0,s.jsx)(`span`,{className:e.kind===`value`?et:tt,children:e.text},t):(0,s.jsx)(r.default.Fragment,{children:e.text},t))})}function rt({title:e=`Ask your assistant`,description:n,prompt:i,compact:a=!1,locked:o=!1,onCopied:c}){let[l,u]=(0,r.useState)(!1),d=i.includes(`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-DYteiM-1.cjs`),t=require(`./ContactPopup-BykgWURi.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.Yt,"./supportForm.config.ts":t.qt}),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=()=>{document.querySelectorAll(`.fbos-content-slot style`).forEach(e=>{e.disabled&&e.media===`not all`||(e.disabled=!0,e.media=`not all`,typeof console<`u`&&console.warn(`FirebaseOS: a <style> tag inside a content file is global CSS and was disabled — style with theme classes (bg-background, text-foreground, glass-panel, btn-primary) instead.`))})},g=e=>{for(let t=e;t;t=t.parentElement){if(t.classList.contains(`fbos-content-slot`))return!1;if(getComputedStyle(t).position===`fixed`)return!0}return!1},_=()=>{if(typeof window>`u`)return;let e=window.innerHeight*.6;document.querySelectorAll(`.fbos-content-slot *`).forEach(t=>{if(!t.clientHeight||t.clientHeight<e||t.scrollHeight<=t.clientHeight+2)return;let n=getComputedStyle(t);n.overflowY!==`visible`&&(n.webkitLineClamp&&n.webkitLineClamp!==`none`||g(t)||(t.style.setProperty(`max-height`,`none`,`important`),t.style.setProperty(`height`,`auto`,`important`),t.scrollHeight>t.clientHeight+2&&t.style.setProperty(`overflow-y`,`visible`,`important`),typeof console<`u`&&console.warn(`FirebaseOS: a box in a content file was as tall as the screen and hid the rest of the page, which left the bottom unreachable on a phone — it was allowed to grow. Let the page be as long as it needs: no h-screen, max-h-screen or overflow-hidden around the whole page.`)))})},v=()=>{(0,r.useEffect)(()=>{if(typeof document>`u`||typeof MutationObserver>`u`)return;let e=()=>{h(),_()};e();let t=new MutationObserver(e);return t.observe(document.body,{childList:!0,subtree:!0}),window.addEventListener(`resize`,e),window.addEventListener(`orientationchange`,e),()=>{t.disconnect(),window.removeEventListener(`resize`,e),window.removeEventListener(`orientationchange`,e)}},[])},y=[`free`,`internal`,`admin`],b=[`user`,`internal`,`admin`],x={free:`Free`,internal:`Internal`,admin:`Admin`};function S(e){return e===`admin`?`admin`:e===`internal`?`internal`:`free`}function C(e){return e===`free`?`user`:e}var w=e=>S(e)===`admin`,T=e=>S(e)!==`free`;function E(e){return e===`admin`?`admin`:e===`public`?`public`:e===`internal`||e===`shared`?`internal`:`user`}function D(e){let t=E(e);return t===`public`?`user`:t}function O(e,t){switch(E(t)){case`public`:return!0;case`admin`:return w(e);case`internal`:return T(e);case`user`:return!0}}function k(e,t=!0){if(!t)return`guest`;let n=S(e);return n===`free`?`user`:n}function A(e){switch(E(e)){case`public`:return[`admin`,`internal`,`user`,`guest`];case`admin`:return[`admin`];case`internal`:return[`admin`,`internal`];case`user`:return[`admin`,`internal`,`user`]}}var j=(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 M({children:e}){let[n,o]=(0,r.useState)(null),[c,l]=(0,r.useState)(null),[u,d]=(0,r.useState)(!1),[f,p]=(0,r.useState)(!0),[m,h]=(0,r.useState)(!1),g=r.default.useRef(null),_=r.default.useRef(null),v=r.default.useRef(new Set),y=e=>(0,i.updateDoc)((0,i.doc)(t.Ht,`user_profiles`,e),{role:`admin`}),b=async e=>{if(!v.current.has(e)){v.current.add(e);try{await y(e)}catch(n){if(n?.code!==`permission-denied`){console.error(`Error claiming the admin role:`,n);return}try{if(!t.Vt.currentUser)return;await t.Vt.currentUser.getIdToken(!0),await y(e)}catch(e){e?.code!==`permission-denied`&&console.error(`Error claiming the admin role:`,e)}}}};return(0,r.useEffect)(()=>{let e;if(!t.Vt){p(!1),h(!0);return}(0,a.getRedirectResult)(t.Vt).catch(()=>{});let n=(0,a.onAuthStateChanged)(t.Vt,async n=>{if(n?.uid===_.current&&m){o(n);return}if(_.current=n?.uid||null,n){let r=localStorage.getItem(`fbos_role_${n.uid}`);r&&(l(r),h(!0),p(!1)),console.log(`[AuthContext] 1. onAuthStateChanged fired for user:`,n.uid),o(n);try{let r=(0,i.doc)(t.Ht,`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.Vt.currentUser?.emailVerified&&b(n.uid),g.current===null&&(g.current=i),l(i),localStorage.setItem(`fbos_role_${n.uid}`,i),d(r.inactive===!0)}h(!0),p(!1)},e=>{console.warn(`[AuthContext] user_profiles snapshot error (safe to ignore during auth transition):`,e),h(!0),p(!1)})}catch(e){console.error(`[AuthContext] ERROR in auth resolution:`,e),h(!0),p(!1)}}else console.log(`[AuthContext] No user currently signed in.`),o(null),l(null),d(!1),h(!0),p(!1),g.current=null,e&&e()});return()=>{n(),e&&e()}},[]),(0,r.useEffect)(()=>{if(!n?.emailVerified||c===`admin`)return;let e=!1;return(0,i.getDoc)((0,i.doc)(t.Ht,`user_profiles`,n.uid)).then(t=>{!e&&t.exists()&&!t.data().role&&b(n.uid)}).catch(()=>{}),()=>{e=!0}},[n?.uid,n?.emailVerified,c]),(0,s.jsx)(j.Provider,{value:{user:n,userRole:c,accessLevel:S(c),isInternal:T(c),isAdmin:w(c),loading:f,signOut:async()=>{await(0,a.signOut)(t.Vt),o(null)},registerUser:async(e,n,r,o)=>{let{createUserWithEmailAndPassword:s}=await import(`firebase/auth`),{user:c}=await s(t.Vt,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.Ht,`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.Vt.currentUser&&(await t.Vt.currentUser.reload(),o(Object.assign(Object.create(t.Vt.currentUser),{photoURL:t.Vt.currentUser.photoURL,displayName:t.Vt.currentUser.displayName,email:t.Vt.currentUser.email,emailVerified:t.Vt.currentUser.emailVerified})))},userInactive:u,roleResolved:m},children:e})}var N=()=>(0,r.useContext)(j);function P(){return(typeof window<`u`?window.__FBOS_PAGES__:null)||{}}function F(e=P()){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 I(){let[e,n]=(0,r.useState)(!1),[a,o]=(0,r.useState)([]),l=(0,r.useRef)(null),u=(0,r.useRef)(null),[d,f]=(0,r.useState)(null),p=(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 m=(0,r.useRef)({users:[],submissions:[],requests:[]}),h=(e,t)=>{m.current[e]=t;let n=[...m.current.users,...m.current.submissions,...m.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))},g=(e,t)=>{console.warn(`AdminNotifications: ${e} are not readable by this account.`,t),h(e,[])};(0,r.useEffect)(()=>{let e=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Ht,`user_profiles`),(0,i.orderBy)(`createdAt`,`desc`),(0,i.limit)(5)),e=>{h(`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}}))},e=>g(`users`,e)),n=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Ht,`user_submissions`),(0,i.orderBy)(`submittedAt`,`desc`),(0,i.limit)(5)),e=>{h(`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}}))},e=>g(`submissions`,e)),r=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Ht,`user_requests`),(0,i.orderBy)(`submittedAt`,`desc`),(0,i.limit)(5)),e=>{h(`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}}))},e=>g(`requests`,e));return()=>{e(),n(),r()}},[]);let[_,v]=(0,r.useState)(()=>typeof window<`u`?parseInt(localStorage.getItem(`admin_notifications_last_read`)||`0`,10):0),y=()=>{let t=!e;if(n(t),t){let e=u.current?.getBoundingClientRect();f(typeof window<`u`&&window.innerWidth<640&&e?e.bottom+8:null);let t=Date.now();v(t),typeof window<`u`&&localStorage.setItem(`admin_notifications_last_read`,t.toString())}},b=a.some(e=>{if(!e.time)return!0;let t=e.time?.toDate?e.time.toDate().getTime():new Date(e.time).getTime();return t>_||isNaN(t)}),x=e=>{n(!1),p(e===`user`?`/users`:e===`submission`?`/submissions`:`/requests`)},S=e=>{if(!e)return``;let t=e.toDate?e.toDate():new Date(e),n=Date.now()-t.getTime();if(isNaN(n))return``;let r=Math.floor(n/6e4);if(r<1)return`now`;if(r<60)return`${r}m`;let i=Math.floor(r/60);if(i<24)return`${i}h`;let a=Math.floor(i/24);return a<7?`${a}d`:new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`}).format(t)};return(0,s.jsxs)(`div`,{className:`relative z-50 flex-shrink-0`,ref:l,children:[(0,s.jsxs)(`button`,{ref:u,onClick:y,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] transition-all relative text-foreground/60 hover:bg-foreground/5 hover:text-foreground flex items-center justify-center shadow-sm cursor-pointer`,"aria-label":`Admin Notifications`,children:[(0,s.jsx)(t.Ot,{className:`w-4 h-4`}),b&&(0,s.jsx)(`span`,{className:`absolute top-1.5 right-1.5 w-2 h-2 bg-[var(--notification-icon-color)] rounded-full animate-pulse`})]}),(0,s.jsx)(t.m,{children:e&&(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:-5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98,y:-5},className:`${d===null?`absolute top-full mt-2 right-0`:`fixed right-4`} w-[min(320px,calc(100vw-2rem))] md:w-[400px] glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col origin-top-right overflow-hidden`,style:d===null?void 0:{top:d},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:()=>x(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.S,{className:`w-4 h-4`}):e.type===`submission`?(0,s.jsx)(t.U,{className:`w-4 h-4`}):(0,s.jsx)(t._t,{className:`w-4 h-4`})}),(0,s.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,s.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,s.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground group-hover:text-accent transition-colors truncate flex-1 min-w-0`,children:e.title}),(0,s.jsx)(`span`,{className:`text-[10px] font-mono tracking-wide text-foreground/40 shrink-0`,children:S(e.time)})]}),(0,s.jsx)(`span`,{className:`text-[12px] text-foreground/60 truncate`,children:e.subtitle})]})]},e.id))})]})})]})}var L=[{id:`guide`,hidden:!1},{id:`contact`,hidden:!1},{id:`templates`,hidden:!1},{id:`setup`,hidden:!1}],R={drive:`assets`,submissions:`inbox`,requests:`inbox`},z=e=>{let t=(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden}).map(e=>({...e,id:R[e.id]||e.id}));return t.filter((e,n)=>t.findIndex(t=>t.id===e.id)===n)},B=[{id:`pages`,hidden:!1},{id:`forms`,hidden:!1},{id:`inbox`,hidden:!1},{id:`users`,hidden:!1},{id:`theme`,hidden:!1},{id:`assets`,hidden:!1}],ee={route:`/support`,template:`popup_form`,form:`support`,tabName:`Support`,iconName:``},V={"/guide":t.vt,"/templates":t.Y,"/setup":t.M,"/contact":t.U},te=e=>e&&V[e]||t.Q,H={guide:{label:`Guide`,path:`/guide`},templates:{label:`Templates`,path:`/templates`},setup:{label:`Setup`,path:`/setup`},contact:{label:`Contact`,path:`/contact`}};function U({customMenu:e,standalone:n}){let{user:a,userRole:o,signOut:l}=N(),u=w(o),d=S(o),f=d===`free`?`Free User`:x[d],p=(0,c.useNavigate)(),[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(null),[v,y]=(0,r.useState)(!1),[b,C]=(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:A,activeConfig:j}=t.Rt(),M=async()=>{await l(),p(`/`),h(!1)},[P,R]=(0,r.useState)({...H}),[B,V]=(0,r.useState)(L);(0,r.useEffect)(()=>{if(!t.Ht)return;let e=(0,i.onSnapshot)((0,i.collection)(t.Ht,`sys_pages`),e=>{let t={...H};for(let[e,n]of F()){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||H[e.id]?.label||e.id,i=n.route||(e.id===`home`?`/`:`/`+e.id);t[e.id]={label:r,path:i}}),R(t)},e=>{console.warn(`sys_pages snapshot error (safe to ignore during auth transition):`,e)}),n=(0,i.onSnapshot)((0,i.doc)(t.Ht,`sys_configs`,`page_order`),e=>{V(e.exists()&&Array.isArray(e.data().order)?z(e.data().order):L)},e=>{console.warn(`page_order snapshot error (safe to ignore during auth transition):`,e)}),r=(0,i.onSnapshot)((0,i.doc)(t.Ht,`sys_tabs`,`support`),e=>{e.exists()&&e.data().pageName&&W(e.data().pageName)},e=>{console.warn(`support snapshot error (safe to ignore during auth transition):`,e)});return()=>{e(),n(),r()}},[]);let[U,W]=(0,r.useState)(ee.tabName),G=(()=>{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=P[e.id];r&&(n.push({label:r.label,path:r.path}),t.add(e.id))}),Object.entries(P).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})(),K=e||G,q=(0,r.useRef)(null),J=(0,r.useRef)(null),[Y,ne]=(0,r.useState)(()=>typeof window<`u`&&window.innerWidth<640);(0,r.useEffect)(()=>{if(typeof window>`u`)return;let e=()=>{let e=window.innerWidth<640;ne(t=>(t!==e&&h(!1),e))};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let[re,ie]=(0,r.useState)(K.length);(0,r.useEffect)(()=>{if(n||Y)return;let e=()=>{let e=q.current,t=J.current;if(!e||!t)return;let n=e.clientWidth,r=t.querySelectorAll(`[data-measure-nav]`);if(r.length===0){ie(K.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){ie(K.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++}ie(Math.max(s,1))},t=requestAnimationFrame(e);if(typeof ResizeObserver>`u`)return()=>cancelAnimationFrame(t);let r=new ResizeObserver(()=>requestAnimationFrame(e));return q.current&&r.observe(q.current),()=>{cancelAnimationFrame(t),r.disconnect()}},[K.map(e=>e.label).join(`|`),n,Y,K.length]);let ae=K.slice(0,re),X=K.slice(re);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 min-w-0 z-50`,children:(0,s.jsxs)(c.Link,{to:`/`,className:`flex items-center gap-2.5 md:gap-3 group cursor-pointer z-50 min-w-0`,children:[(0,s.jsx)(`div`,{className:`w-9 h-9 rounded-lg glass-panel flex items-center justify-center glow-hover shadow-lg transition-transform duration-500 group-hover:rotate-180 group-active:scale-95 overflow-hidden shrink-0`,children:j?.logoUrl?(0,s.jsx)(`img`,{src:j.logoUrl,alt:`Logo`,className:`w-full h-full object-contain`}):(0,s.jsx)(t.ft,{className:`w-4 h-4 text-accent`})}),(0,s.jsx)(`span`,{className:`font-bold text-[18px] md:text-[22px] tracking-tight text-gradient transition-all duration-300 drop-shadow-sm truncate`,children:j?.appName||``})]})}),(0,s.jsx)(t.m,{children:v&&(0,s.jsx)(t.t,{formId:`contact`,onClose:()=>y(!1)})}),(0,s.jsx)(t.m,{children:b&&(0,s.jsx)(t.t,{formId:`support`,onClose:()=>C(!1)})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2.5 md:gap-4 z-50 relative ml-auto flex-1 min-w-0 justify-end`,children:[!n&&!a&&!Y&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{ref:J,"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:K.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.wt,{className:`w-3 h-3`})]},e.path||n))}),(0,s.jsxs)(`div`,{className:`flex items-center gap-7 mr-6 flex-1 min-w-0 justify-end relative`,ref:q,children:[ae.map((e,n)=>(0,s.jsxs)(`div`,{className:`relative shrink-0`,onMouseEnter:()=>_(e.label),onMouseLeave:()=>_(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.wt,{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.wt,{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.p.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}`)),X.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.m,{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.p.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:X.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))})]})})]})]})]}),!n&&!a&&(0,s.jsxs)(s.Fragment,{children:[j?.showThemeToggle&&(0,s.jsx)(`button`,{onClick:A,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] hover:bg-foreground/5 transition-all text-foreground/60 hover:text-foreground flex items-center justify-center shadow-sm shrink-0 cursor-pointer`,"aria-label":`Toggle Theme`,children:k===`dark`?(0,s.jsx)(t.O,{className:`w-4 h-4`}):(0,s.jsx)(t.V,{className:`w-4 h-4`})}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2.5 shrink-0`,children:[!Y&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(c.Link,{to:`/login`,className:`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:`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 shrink-0`,children:`Get Started`})]}),Y&&(0,s.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>h(m===`guest`?!1:`guest`),"aria-label":`Open menu`,"aria-expanded":m===`guest`,className:`w-9 h-9 rounded-xl glass-panel glow-hover border transition-all flex items-center justify-center ${m===`guest`?`border-accent bg-foreground/5`:`border-[var(--panel-border)] hover:bg-foreground/5`}`,children:(0,s.jsx)(t.H,{className:`w-5 h-5 text-accent/80`})}),(0,s.jsx)(t.m,{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.p.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:[K.map((e,t)=>{let n=te(e.path);return e.path?(0,s.jsxs)(c.Link,{to:e.path,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 min-w-0`,children:[(0,s.jsx)(n,{className:`w-4 h-4 text-accent/70 shrink-0`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold truncate`,children:e.label})]},`${e.path}-${t}`):(0,s.jsxs)(`button`,{onClick:()=>{e.action&&e.action(),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 min-w-0`,children:[(0,s.jsx)(n,{className:`w-4 h-4 text-accent/70 shrink-0`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold truncate`,children:e.label})]},`${e.label}-${t}`)}),(0,s.jsx)(`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.W,{className:`w-4 h-4 text-accent/70`}),` `,(0,s.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Sign In`})]})})]})]})})]})]})]}),!n&&a&&(0,s.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[o===`admin`&&(0,s.jsx)(I,{}),j?.showThemeToggle&&(0,s.jsx)(`button`,{onClick:A,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] hover:bg-foreground/5 transition-all text-foreground/60 hover:text-foreground flex items-center justify-center shadow-sm shrink-0 cursor-pointer`,"aria-label":`Toggle Theme`,children:k===`dark`?(0,s.jsx)(t.O,{className:`w-4 h-4`}):(0,s.jsx)(t.V,{className:`w-4 h-4`})}),(0,s.jsxs)(`div`,{className:`relative z-50 flex-shrink-0`,children:[(0,s.jsxs)(`button`,{onClick:()=>h(m===`user`?!1:`user`),className:`flex items-center gap-2 group p-0.5 sm:p-1 sm:pr-2.5 rounded-full hover:bg-foreground/5 transition-all duration-300 cursor-pointer sm:border ${m===`user`?`sm:border-accent/50 sm:bg-foreground/5`:`sm:border-[var(--panel-border)] sm:hover:border-accent/30`}`,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 sm:border-0 transition-colors shrink-0 text-accent ${m===`user`?`border-accent/50`:`border-[var(--panel-border)] group-hover:border-accent/30`}`,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.S,{className:`w-4 h-4 md:w-5 md:h-5 text-accent`})}),(0,s.jsxs)(`div`,{className:`max-sm: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.m,{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.p.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:`/dashboard`,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.Z,{className:`w-3 h-3 text-accent`})}),`Dashboard`]}),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.rt,{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.x,{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.tt,{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.Q,{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._t,{className:`w-3 h-3 text-accent`})}),U]}),(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.S,{className:`w-3 h-3 text-accent`})}),`Profile Settings`]})]}),(0,s.jsx)(`div`,{className:`pt-1 mt-1 border-t border-[var(--panel-border)]/50`,children:(0,s.jsxs)(`button`,{onClick:M,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`]})})]})]})})]})]}),n&&(0,s.jsx)(s.Fragment,{children:j?.showThemeToggle&&(0,s.jsx)(`button`,{onClick:A,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] hover:bg-foreground/5 transition-all text-foreground/60 hover:text-foreground flex items-center justify-center shadow-sm shrink-0 cursor-pointer`,"aria-label":`Toggle Theme`,children:k===`dark`?(0,s.jsx)(t.O,{className:`w-4 h-4`}):(0,s.jsx)(t.V,{className:`w-4 h-4`})})})]})]})}function W(){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.p.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.p.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._,{className:`w-4 h-4 text-accent`}),` The Open-Source Firebase Starter`]}),(0,s.jsx)(t.p.h1,{className:`text-4xl sm:text-5xl md:text-6xl lg:text-[4.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.p.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.m,{children:e&&(0,s.jsx)(t.t,{onClose:()=>n(null),formId:e})})]})}var G=[{id:`length`,label:`At least 8 characters`,ok:e=>e.length>=8},{id:`case`,label:`An uppercase and a lowercase letter`,ok:e=>/[a-z]/.test(e)&&/[A-Z]/.test(e)},{id:`number`,label:`A number`,ok:e=>/[0-9]/.test(e)}],K=new Set(`password1.password12.password123.password1234.passw0rd1.p@ssword1.p@ssw0rd1.test1234.test12345.testing123.test123456.qwerty123.qwerty1234.abcd1234.abc12345.welcome1.welcome123.admin123.admin1234.letmein123.iloveyou1.monkey123.football1.changeme1.secret123.summer2024.summer2025`.split(`.`)),q=e=>e.toLowerCase().replace(/[\s._-]/g,``),J=e=>K.has(q(e||``)),Y=e=>G.map(t=>({rule:t,met:t.ok(e||``)}));function ne(e){let t=e||``;if(!t)return`Choose a password.`;let n=G.find(e=>!e.ok(t));return n?`Your password needs ${n.label.toLowerCase()}.`:J(t)?`That password is one of the first anyone would guess. Please pick another.`:``}function re(e,t){return t?e===t?``:`Both passwords must be the same.`:`Type your password a second time.`}function ie({value:e,className:n=``}){return(0,s.jsx)(`ul`,{className:`flex flex-col gap-1 ml-1 ${n}`,"aria-label":`Password requirements`,children:Y(e).map(({rule:e,met:n})=>(0,s.jsxs)(`li`,{className:`flex items-center gap-2 text-[12.5px] font-medium transition-colors ${n?`text-emerald-500`:`text-foreground/45`}`,children:[n?(0,s.jsx)(t.Tt,{className:`w-3.5 h-3.5 shrink-0`}):(0,s.jsx)(`span`,{className:`w-3.5 flex justify-center shrink-0`,children:(0,s.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-foreground/25`})}),e.label]},e.id))})}function ae(){let[e,n]=(0,r.useState)(!1),[i,o]=(0,r.useState)(null),[l,u]=(0,r.useState)(``),[d,f]=(0,r.useState)(``),[p,m]=(0,r.useState)(``),[h,g]=(0,r.useState)(``),_=(0,c.useNavigate)(),{registerUser:v}=N();return(0,s.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mt-6 mb-8 md:mt-0 md:mb-0 md:pt-8 md:pb-32`,children:(0,s.jsxs)(t.p.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(`firstName`),a=t.get(`lastName`),u=ne(l),f=u?``:re(l,d);if(m(u),g(f),u||f){o(u||f),n(!1);return}try{await v(r,l,i,a),_(`/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(ne(l)||`Please choose a stronger password.`):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.l,{name:`firstName`,label:`First Name`,type:`text`,placeholder:`John`,required:!0}),(0,s.jsx)(t.l,{name:`lastName`,label:`Last Name`,type:`text`,placeholder:`Doe`,required:!0})]}),(0,s.jsx)(t.l,{name:`email`,label:`Email`,type:`email`,placeholder:`name@example.com`,required:!0}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,s.jsx)(t.l,{name:`password`,label:`Password`,type:`password`,placeholder:`••••••••`,autoComplete:`new-password`,value:l,onChange:e=>{u(e.target.value),p&&m(``),h&&e.target.value===d&&g(``)},onBlur:()=>m(l?ne(l):``),error:p,required:!0}),l&&(0,s.jsx)(ie,{value:l})]}),l&&(0,s.jsx)(t.l,{name:`confirmPassword`,label:`Confirm password`,type:`password`,placeholder:`••••••••`,autoComplete:`new-password`,value:d,onChange:e=>{f(e.target.value),h&&g(``)},onBlur:()=>g(d?re(l,d):``),error:h,required:!0}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsxs)(t.c,{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.jt,{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.c,{variant:`secondary`,onClick:async()=>{n(!0),o(null);try{if(!t.Vt)throw Error(`Firebase is not initialized. Check your configuration.`);let e=new a.GoogleAuthProvider;try{await(0,a.signInWithPopup)(t.Vt,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.Vt,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 X(){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 mb-8 md:mt-0 md:mb-0 md:pt-8 md:pb-32`,children:(0,s.jsxs)(t.p.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.Vt)throw Error(`Firebase is not initialized. Check your configuration.`);await(0,a.signInWithEmailAndPassword)(t.Vt,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.l,{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.l,{name:`password`,type:`password`,placeholder:`••••••••`,required:!0})]}),(0,s.jsx)(`div`,{className:`pt-2`,children:(0,s.jsxs)(t.c,{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.jt,{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.c,{variant:`secondary`,onClick:async()=>{n(!0),o(null);try{if(!t.Vt)throw Error(`Firebase is not initialized. Check your configuration.`);let e=new a.GoogleAuthProvider;try{await(0,a.signInWithPopup)(t.Vt,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.Vt,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 oe(){let{user:e,refreshUser:n}=N(),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.p.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.U,{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.c,{variant:`primary`,onClick:async()=>{l(!0),p(``);try{if(t.Vt.currentUser){if(await t.Vt.currentUser.reload(),!t.Vt.currentUser.emailVerified){p(`Email is not verified yet. Please check your inbox.`),l(!1);return}await t.Vt.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.c,{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`})]})]})})}function Z(...e){return t.u(t.d(e))}var se=.72,ce=({className:e,children:t,...n})=>{let i=(0,r.useRef)(null);return(0,r.useLayoutEffect)(()=>{let e=i.current,t=e?.parentElement;if(!e||!t)return;let n=()=>{e.style.removeProperty(`font-size`),e.removeAttribute(`data-fold`);let n=t.clientWidth,r=e.scrollWidth;if(!n||r<=n)return;let i=parseFloat(window.getComputedStyle(e).fontSize)||24,a=n/r;e.style.setProperty(`font-size`,`${(i*Math.max(a,se)).toFixed(2)}px`,`important`),a<se&&e.setAttribute(`data-fold`,``)};if(n(),document.fonts?.ready.then(n).catch(()=>{}),typeof ResizeObserver>`u`)return;let r=new ResizeObserver(n);return r.observe(t),()=>r.disconnect()},[t]),(0,s.jsx)(`h1`,{ref:i,className:Z(`page-title w-fit inline-block tracking-tight mb-3 mt-1 text-gradient`,e),...n,children:t})};ce.displayName=`PageTitle`;var le=A(`admin`),ue={pages:{path:`/pages`,label:`Pages`,icon:t.Q,roles:le},forms:{path:`/forms`,label:`Forms`,icon:t.I,roles:le},inbox:{path:`/inbox`,label:`Inbox`,icon:t.tt,roles:le},users:{path:`/users`,label:`Users`,icon:t.x,roles:le},theme:{path:`/theme`,label:`Theme`,icon:t.B,roles:le},assets:{path:`/assets`,label:`Assets`,icon:t.rt,roles:le}};function de({customTabs:e=[]}){let{pathname:n}=(0,c.useLocation)(),{user:a,userRole:o}=N(),[l,u]=(0,r.useState)(!1),d=(0,r.useRef)(null),[f,p]=(0,r.useState)({}),[m,h]=(0,r.useState)(B);(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.Ht,`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.Ht,`sys_configs`,`tab_order`),e=>{let t=e.exists()&&Array.isArray(e.data().order)?z(e.data().order):B;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(ue).forEach(([t,n])=>{e[t]={id:t,...n,exact:!0}});let n={...f};for(let[e,t]of F())t.isPublic||(n[e]={...t.config,...f[e]});Object.entries(n).forEach(([n,r])=>{let i=e[n],a=i?.icon??t.Q;if(r?.iconName){let e=r.iconName.trim(),n=e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);t.h[n]?a=t.h[n]:t.h[e]&&(a=t.h[e])}let o=i?.roles??le;r?.pageType&&(o=A(D(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||i.has(t.id)||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=k(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=parseFloat(getComputedStyle(e).columnGap)||40,i=t.querySelectorAll(`[data-measure-tab]`);if(i.length===0){b(g.length);return}let a=0,o=!0;for(let e=0;e<i.length;e++)if(a+=i[e].offsetWidth+(e>0?r:0),a>n){o=!1;break}if(o){b(g.length);return}let s=0,c=0;for(let e=0;e<i.length;e++){let t=i[e].offsetWidth,a=s+t+(e>0?r:0);if(a+52>n)break;s=a,c++}b(Math.max(c,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),w=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-5 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 ${w?`text-accent border-accent`:`text-foreground/50 hover:text-foreground/80 border-transparent`}`,title:`More items`,children:(0,s.jsx)(t.ut,{className:`w-5 h-5`})}),(0,s.jsx)(t.m,{children:l&&(0,s.jsx)(t.p.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 fe(){let{user:e,refreshUser:n,isInternal:c}=N(),[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)(``),[C,w]=(0,r.useState)(``),[T,D]=(0,r.useState)(!1),[O,k]=(0,r.useState)(!1),[A,j]=(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 M=async n=>{if(e)try{if(!c)return;let r=[`mem_files`,`admin_files`];(await(0,i.getDocs)((0,i.collection)(t.Ht,`sys_tabs`))).forEach(e=>{let t=e.data(),n=(t.tabName||e.id).toLowerCase().replace(/[^a-z0-9]+/g,`_`),i=E(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.Ht,a),(0,i.where)(`uid`,`==`,e.uid)));if(r.empty)continue;let o=(0,i.writeBatch)(t.Ht);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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-5 sm:mb-8`,children:[(0,s.jsx)(ce,{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-4 sm:gap-6 animate-in fade-in duration-500 pb-20`,children:[(0,s.jsx)(`div`,{className:`flex justify-start`,children:(0,s.jsx)(de,{})}),(0,s.jsx)(t.m,{children:_&&(0,s.jsxs)(t.p.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.yt,{className:`w-5 h-5 shrink-0`}):(0,s.jsx)(t.bt,{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.Vt,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){let t=ne(y);if(t)throw Error(t);let n=re(y,x);if(n)throw w(n),Error(n);await(0,a.updatePassword)(e,y),b(``),S(``),w(``)}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-5 sm:p-8 md:p-12 rounded-3xl border border-[var(--panel-border)] shadow-2xl space-y-8 md:min-h-[500px]`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-4 sm:gap-5 pb-6 border-b border-[var(--panel-border)]/50`,children:[(0,s.jsxs)(`div`,{className:`relative shrink-0 group/avatar`,children:[(0,s.jsxs)(`div`,{className:`w-16 h-16 sm:w-20 sm:h-20 rounded-full glass-panel border-2 border-[var(--panel-border)] shadow-lg bg-accent/10 flex items-center justify-center relative overflow-hidden`,children:[(O||p&&A&&!T)&&(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.K,{className:`w-6 h-6 text-accent animate-spin`})}),p&&!T?(0,s.jsx)(`img`,{src:p,alt:`Avatar`,className:`w-full h-full object-cover transition-opacity duration-300 ${A?`opacity-0`:`opacity-100`}`,onLoad:()=>j(!1),onError:()=>{D(!0),j(!1)}}):(0,s.jsx)(t.S,{className:`w-7 h-7 sm:w-8 sm:h-8 text-accent`})]}),!O&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(`label`,{title:p?`Change photo`:`Upload photo`,className:`absolute inset-0 rounded-full bg-background/60 backdrop-blur-[2px] opacity-0 group-hover/avatar:opacity-100 focus-within:opacity-100 flex items-center justify-center cursor-pointer transition-opacity z-20`,children:[(0,s.jsx)(t.Et,{className:`w-4 h-4 text-foreground`}),(0,s.jsx)(`input`,{type:`file`,accept:`image/*`,"aria-label":`Upload photo`,onChange:async r=>{let s=r.target.files?.[0];if(!s||!e)return;let c=await t.o(s,{maxSide:512});if(c.size>2*1024*1024){v({text:`File too large. Please select an image under 2MB.`,type:`error`});return}k(!0),D(!1),j(!0);try{let r=(0,o.ref)(t.Wt,`user_avatars/${e.uid}/file.png`);await(0,o.uploadBytes)(r,c,{customMetadata:{ownerId:e.uid}});let s=await(0,o.getDownloadURL)(r);m(s);let l=(0,i.doc)(t.Ht,`user_profiles`,e.uid);await Promise.all([(0,a.updateProfile)(e,{photoURL:s}),(0,i.updateDoc)(l,{avatar:s}),M(s)]),await n(),v({text:`Avatar successfully updated!`,type:`success`})}catch(e){console.error(e),v({text:`Failed to upload photo.`,type:`error`})}finally{k(!1)}},className:`hidden`})]}),p&&(0,s.jsx)(`button`,{type:`button`,onClick:async()=>{if(e){k(!0),D(!1),j(!1);try{let r=(0,o.ref)(t.Wt,`user_avatars/${e.uid}/file.png`);m(``),k(!1);let s=(0,i.doc)(t.Ht,`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:``}),M(``)]),await n(),v({text:`Avatar removed.`,type:`success`})}catch(e){console.error(e),v({text:`Failed to delete photo.`,type:`error`}),k(!1)}}},title:`Remove photo`,"aria-label":`Remove photo`,className:`hidden group-hover/avatar:flex absolute -top-1 -right-1 w-6 h-6 rounded-full bg-background border border-[var(--panel-border)] text-foreground/50 hover:text-red-500 hover:border-red-500/40 items-center justify-center shadow-sm cursor-pointer z-30`,children:(0,s.jsx)(t.E,{className:`w-3 h-3`})})]})]}),(0,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsx)(`h3`,{className:`font-extrabold text-lg sm:text-xl text-foreground mb-1 truncate`,children:l||`User`}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/40 mt-1 font-medium break-words`,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.l,{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.l,{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.l,{name:`password`,type:`password`,label:`New Password`,autoComplete:`new-password`,value:y,onChange:e=>{b(e.target.value),C&&e.target.value===x&&w(``)},placeholder:`At least 8 characters`}),(0,s.jsx)(t.l,{name:`confirmPassword`,type:`password`,label:`Confirm New Password`,autoComplete:`new-password`,value:x,onChange:e=>{S(e.target.value),C&&w(``)},onBlur:()=>w(x?re(y,x):``),error:C,placeholder:`Type it a second time`})]}),y&&(0,s.jsx)(ie,{value:y,className:`mt-3`})]}),(0,s.jsx)(`div`,{className:`pt-6 md:pt-8 border-t border-[var(--panel-border)]/50 flex justify-start w-full`,children:(0,s.jsx)(t.c,{type:`submit`,isLoading:h,className:`w-full sm:w-auto sm: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 pe(){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-0 md:mb-0 md:pt-8 md:pb-32`,children:(0,s.jsxs)(t.p.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.$,{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.Vt,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.l,{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.c,{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.Mt,{className:`w-4 h-4 mr-2`}),`Back to Sign In`]})})]})})}var me=`(max-width: 767px)`,he=()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(me).matches;function ge(){let[e,t]=(0,r.useState)(he);return(0,r.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(me),n=()=>t(e.matches);return n(),e.addEventListener?.(`change`,n),()=>e.removeEventListener?.(`change`,n)},[]),e}function _e(){let{user:e,userRole:n}=N(),[a,l]=(0,r.useState)(!0),u=(0,c.useNavigate)(),{id:d}=(0,c.useParams)(),f=ge(),[p,m]=(0,r.useState)([]),[h,g]=(0,r.useState)(null),[_,v]=(0,r.useState)(!1),[b,w]=(0,r.useState)(``),[T,E]=(0,r.useState)(!1),D=d?p.find(e=>e.id===d)||null:p.length>0?p[0]:null,O=e=>{u(e?`/users/${e.id}`:`/users`)};(0,r.useEffect)(()=>{l(!0);let e=(0,i.onSnapshot)((0,i.collection)(t.Ht,`user_profiles`),e=>{let t=[];e.forEach(e=>{t.push({id:e.id,...e.data()})}),m(t),l(!1),!d&&t.length>0&&!he()&&u(`/users/${t[0].id}`,{replace:!0})},e=>{console.error(`Error fetching users:`,e),l(!1)});return()=>e()},[d,u]);let k=p.find(t=>t.id===e?.uid),A=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,j=async(e,r)=>{if(!(n!==`admin`||!A(e))&&S(e.role)!==r)try{await(0,i.updateDoc)((0,i.doc)(t.Ht,`user_profiles`,e.id),{role:C(r)}),g({text:`Access level set to ${x[r]}`,type:`success`}),setTimeout(()=>g(null),3e3)}catch(e){g({text:e.message,type:`error`}),setTimeout(()=>g(null),3e3)}},M=async(e,r)=>{if(!(n!==`admin`||!A(e)))try{await(0,i.updateDoc)((0,i.doc)(t.Ht,`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(v(!1),!(!D||!A(D)||b===D.displayName))try{await(0,i.updateDoc)((0,i.doc)(t.Ht,`user_profiles`,D.id),{displayName:b}),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||!A(D))return;let r=await t.o(n,{maxSide:512});if(r.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.Wt,`user_avatars/${D.id}/file.png`);await(0,o.uploadBytes)(e,r);let n=await(0,o.getDownloadURL)(e);m(e=>e.map(e=>e.id===D.id?{...e,avatar:n}:e)),await(0,i.updateDoc)((0,i.doc)(t.Ht,`user_profiles`,D.id),{avatar:n}),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);if((0,r.useEffect)(()=>{let e;return a&&p.length===0?e=setTimeout(()=>L(!0),150):L(!1),()=>clearTimeout(e)},[a,p.length]),a&&p.length===0)return 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.K,{className:`w-8 h-8 animate-spin text-accent`})}):null;let R=f&&!!d,z=!R,B=!f||!!d;return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto z-10 flex flex-col min-h-screen p-4 pt-2 md:p-8 md:pt-4`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,s.jsx)(ce,{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 animate-in fade-in duration-500 gap-6 ${R?`flex-1 pb-6`:`pb-20`}`,children:[(0,s.jsx)(t.m,{children:h&&(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:`p-4 text-[14px] font-medium border rounded-xl ${h.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)]`} flex items-center gap-2`,children:[h.type===`success`&&(0,s.jsx)(t.yt,{className:`w-4 h-4 shrink-0`}),h.text]})}),(0,s.jsx)(`div`,{className:`flex justify-start`,children:(0,s.jsx)(de,{})}),(0,s.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] bg-[var(--panel-bg)] overflow-hidden rounded-3xl shadow-2xl ${R?`flex-1 flex flex-col`:``}`,children:p.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 md:min-h-[500px] ${R?`flex-1`:``}`,children:[z&&(0,s.jsxs)(`div`,{className:`flex md:col-span-1 border-r md:border-r-[var(--panel-border)] border-b md:border-b-0 border-[var(--panel-border)] 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 md:max-h-[520px]`,children:p.map(e=>(0,s.jsxs)(`div`,{onClick:()=>O(e),className:`p-3.5 rounded-2xl border transition-all flex items-center gap-3 cursor-pointer ${D?.id===e.id?`bg-foreground/[0.06] border-accent/40 shadow-sm`:`glass-panel border-[var(--panel-border)] hover:border-accent/40`} ${e.inactive?`opacity-50 grayscale`:``}`,children:[(0,s.jsx)(`div`,{className:`w-9 h-9 rounded-full overflow-hidden bg-accent/10 shrink-0 flex items-center justify-center border border-accent/20 shadow-sm`,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.S,{className:`w-4 h-4 text-accent`})}),(0,s.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,s.jsx)(`span`,{className:`font-bold text-[14px] text-foreground truncate`,children:e.displayName||`No Name`}),(0,s.jsx)(`span`,{className:`text-[12px] text-foreground/50 truncate font-medium mt-0.5`,children:e.email})]}),f&&(0,s.jsx)(t.St,{className:`w-4 h-4 text-foreground/25 shrink-0`})]},e.id))})]}),B&&(0,s.jsx)(`div`,{className:`flex md:col-span-2 flex-col relative ${R?`px-4 pt-4 pb-10`:`p-5 sm:p-6 md:p-10`}`,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 flex-row items-center gap-3 sm:gap-6 md:gap-8 mb-8 sm:mb-10`,children:[R&&(0,s.jsx)(`button`,{type:`button`,onClick:()=>O(null),"aria-label":`Back to all users`,className:`shrink-0 -ml-1.5 w-7 h-7 flex items-center justify-center rounded-lg text-foreground/40 hover:text-foreground active:bg-foreground/5 transition-colors cursor-pointer`,children:(0,s.jsx)(t.Mt,{className:`w-5 h-5`})}),(0,s.jsxs)(`div`,{className:`relative shrink-0 group/avatar`,children:[(0,s.jsx)(`div`,{className:`w-14 h-14 sm:w-24 sm:h-24 rounded-full glass-panel border-2 sm:border-4 border-[var(--panel-border)] shadow-lg sm:shadow-xl bg-accent/10 flex items-center justify-center overflow-hidden`,children:T?(0,s.jsx)(t.K,{className:`w-5 h-5 sm:w-8 sm: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.S,{className:`w-6 h-6 sm:w-10 sm:h-10 text-accent`})}),!T&&A(D)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(`label`,{title:`Change photo`,className:`max-sm:hidden sm:flex absolute -bottom-0.5 -right-0.5 w-9 h-9 rounded-full btn-primary text-white items-center justify-center cursor-pointer shadow-lg border-2 border-[var(--bg-color)] hover:scale-105 active:scale-95 transition-transform z-10`,children:[(0,s.jsx)(t.Et,{className:`w-4 h-4`}),(0,s.jsx)(`input`,{type:`file`,accept:`image/*`,"aria-label":`Change photo`,onChange:F,className:`hidden`})]}),(0,s.jsxs)(`label`,{title:`Change photo`,className:`flex sm:hidden absolute inset-0 rounded-full bg-background/60 backdrop-blur-[2px] opacity-0 group-hover/avatar:opacity-100 focus-within:opacity-100 items-center justify-center cursor-pointer transition-opacity z-10`,children:[(0,s.jsx)(t.Et,{className:`w-4 h-4 text-foreground`}),(0,s.jsx)(`input`,{type:`file`,accept:`image/*`,"aria-label":`Change photo`,onChange:F,className:`hidden`})]})]})]}),(0,s.jsxs)(`div`,{className:`flex flex-col flex-1 w-full min-w-0 relative`,children:[_?(0,s.jsx)(`input`,{autoFocus:!0,value:b,onChange:e=>w(e.target.value),onBlur:P,onKeyDown:e=>e.key===`Enter`&&P(),className:`text-xl sm: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:()=>{A(D)&&(w(D.displayName||``),v(!0))},className:`text-xl sm:text-2xl md:text-3xl font-extrabold mb-1 select-none break-words ${A(D)?`cursor-pointer hover:text-accent transition-colors`:``}`,title:A(D)?`Double-click to edit`:``,children:D.displayName||`No Name`}),(0,s.jsx)(`p`,{className:`text-[13px] sm:text-[14px] font-mono text-foreground/50 break-all`,children:D.email}),!A(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.G,{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.jsx)(`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 ${A(D)?``:`opacity-50`}`,children:y.map(e=>{let t=S(D.role)===e;return(0,s.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t,disabled:!A(D),onClick:()=>j(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`} ${A(D)?`cursor-pointer`:`cursor-not-allowed`}`,children:x[e]},e)})})]})}),(0,s.jsxs)(`div`,{className:`p-4 rounded-2xl glass-panel border flex items-center justify-between gap-3 ${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:!A(D),onClick:()=>M(D,!D.inactive),className:`relative inline-flex h-7 w-12 shrink-0 items-center rounded-full transition-colors focus:outline-none shadow-inner ${D.inactive?`bg-amber-500`:`bg-red-500/20`} ${A(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.x,{className:`w-12 h-12 mb-4`}),(0,s.jsx)(`p`,{className:`font-bold tracking-widest uppercase text-[12px]`,children:`Select a User`})]})})]})})]})]})}function ve({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.m,{children:e&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.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.p.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.c,{variant:`secondary`,onClick:c,disabled:l,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:a}),(0,s.jsx)(t.c,{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.K,{className:`w-5 h-5 animate-spin mx-auto`}):i})]})]})})]})})}var ye=`rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)] transition-colors hover:border-accent/40`,be=`inline-flex items-center justify-center gap-1.5 h-8 px-2.5 sm:h-9 sm:px-3 shrink-0 whitespace-nowrap 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`,xe=`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`,Ce=`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`,we=`text-[12.5px] sm:text-[13px] font-medium text-foreground/50 select-none`;function Te({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.K,{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,compact:u}){return(0,s.jsxs)(`button`,{type:`button`,title:l,onClick:r,disabled:i||a,className:`${be} ${o===`danger`?`hover:text-red-500 hover:border-red-500/40 hover:bg-red-500/[0.06]`:``} ${u?`max-sm:w-8 max-sm:px-0 max-sm:gap-0 max-sm:border-transparent max-sm:hover:border-transparent max-sm:hover:bg-foreground/[0.06]`:``} ${c}`,children:[a?(0,s.jsx)(t.K,{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,u?(0,s.jsx)(`span`,{className:`max-sm:hidden sm:inline-flex items-center gap-1.5`,children:n}):n]})}function Ee({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)]/60 bg-foreground/[0.015] overflow-hidden transition-all`,children:[(0,s.jsxs)(`div`,{className:`w-full px-4 sm:px-5 py-4 grid grid-cols-[auto_minmax(0,1fr)_auto_auto] items-center gap-x-3 sm:gap-x-3.5 gap-y-0.5 text-left`,children:[e&&(0,s.jsx)(`div`,{className:`row-start-1 col-start-1 row-span-2 self-center w-10 h-10 rounded-2xl flex items-center justify-center shrink-0 border border-[var(--panel-border)]/50 bg-accent/10 text-accent`,children:(0,s.jsx)(e,{className:`w-5 h-5`})}),(0,s.jsx)(`span`,{className:`row-start-1 col-start-2 min-w-0 text-[15px] font-bold text-foreground tracking-tight leading-tight truncate self-end`,children:n}),a&&(0,s.jsx)(`div`,{className:`row-start-1 row-span-2 col-start-3 self-center justify-self-end flex items-center gap-1 sm: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:`row-start-1 col-start-4 row-span-2 self-center w-8 h-8 rounded-xl border border-[var(--panel-border)]/60 hover:border-accent/40 flex items-center justify-center text-foreground/50 hover:text-foreground hover:bg-foreground/5 transition-all cursor-pointer justify-self-end`,children:(0,s.jsx)(t.wt,{className:`w-4 h-4 transition-transform duration-200 ${f?`rotate-180`:``}`})}),i&&(0,s.jsx)(`span`,{className:`row-start-2 col-start-2 min-w-0 text-[12px] text-foreground/50 font-normal leading-snug truncate self-start`,children:i})]}),(0,s.jsx)(t.m,{initial:!1,children:f&&(0,s.jsx)(t.p.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)]/40 p-4 sm:p-5 flex flex-col gap-5 bg-background/30`,children:o})})})]})}function De({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 sm:mb-1.5 ml-1`,children:[(0,s.jsx)(`label`,{className:we,children:e}),n]}),r,t&&!i&&(0,s.jsx)(`span`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug mt-1 sm: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 sm:mt-1.5 px-1`,children:i})]})}function Oe({label:e,hint:t,value:n,onChange:r,onBlur:i,placeholder:a,prefix:o,error:c,disabled:l,action:u}){return(0,s.jsx)(De,{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:`${Ce} 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:`${xe} ${c?`is-invalid border-red-500/60`:``}`})})}function ke({value:e,className:t=``,...n}){let i=(0,r.useRef)(null),a=r.default.useCallback(()=>{let e=i.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight+(e.offsetHeight-e.clientHeight)}px`)},[]);return(0,r.useLayoutEffect)(a,[a,e]),(0,r.useEffect)(()=>{let e=i.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(a);return e.parentElement&&t.observe(e.parentElement),()=>t.disconnect()},[a]),(0,s.jsx)(`textarea`,{ref:i,rows:1,value:e??``,onInput:a,className:`${t} resize-none overflow-hidden`,...n})}function Ae({label:e,hint:t,value:n,onChange:r,onBlur:i,placeholder:a}){return(0,s.jsx)(De,{label:e,hint:t,children:(0,s.jsx)(ke,{value:n??``,placeholder:a,onChange:e=>r(e.target.value),onBlur:i,"aria-label":e,className:`${xe.replace(`h-11 `,``)} min-h-11 py-2.5 leading-5`})})}function je({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)(De,{label:e,hint:n,children:(0,s.jsx)(t.s,{ariaLabel:e,value:r??``,options:u,onChange:i,disabled:l,className:`console-select`,dense:!0,portal:!0,direction:`auto`})})}function Me({label:e,hint:t,enabled:n,onChange:r,disabled:i,hintWideOnly:a}){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-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug${a?` max-sm:hidden`:``}`,children:t})]}),(0,s.jsx)(Ne,{enabled:n,onChange:r,disabled:i,label:e})]})}function Ne({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 Pe({saving:e,savedAt:t}){return e?(0,s.jsx)(Te,{state:`saving`,label:`Saving`}):t?(0,s.jsx)(Te,{state:`saved`,label:`Saved`}):null}var Fe=e=>e.trim().split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),Ie=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/([A-Z])([A-Z][a-z])/g,`$1-$2`).toLowerCase(),Le=e=>{let t=e.replace(/-/g,` `);return t.charAt(0).toUpperCase()+t.slice(1)},Re=(()=>{let e=t.g,n=e?Object.keys(e):[];return n.length===0&&(n=Object.keys(t.h).filter(e=>/^[A-Z]/.test(e)&&!/Icon$/.test(e)&&!/^Lucide/.test(e)&&e!==`IconNode`)),Array.from(new Set(n.map(Ie))).sort()})(),ze=`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(`.`),Be={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`]},Ve=(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]},He=(e,t)=>{let n=0;for(let r of t)r===e[n]&&n++;return n===e.length};function Ue(e,t=96,n=Re){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 Be[e]||[])s(t,70);if(e.endsWith(`s`))for(let t of Be[e.slice(0,-1)]||[])s(t,70)}if(o.size===0&&r.length>=3)for(let e of n)e.split(`-`).some(e=>Ve(r,e)<=(r.length>5?2:1))?s(e,40):r.length>=4&&He(r,e.replace(/-/g,``))&&s(e,20);let c=e=>{let t=ze.indexOf(e);return t===-1?ze.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 We(e){if(!e)return t.Q;let n=e.trim(),r=t.h;return r[Fe(n)]||r[n]||t.Q}function Ge({name:e,className:t}){return(0,r.createElement)(We(e),{className:t})}function Ke({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)(()=>Ue(o),[o]),d=o.trim().length>0;return(0,s.jsx)(De,{label:e,hint:n,children:(0,s.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,s.jsxs)(`div`,{className:Se,children:[l&&!d?(0,s.jsxs)(`span`,{className:`inline-flex items-center gap-2 mr-2.5 shrink-0 min-w-0 text-accent`,children:[(0,s.jsx)(`span`,{className:`w-7 h-7 -ml-1 rounded-lg bg-accent/[0.08] border border-accent/25 flex items-center justify-center shrink-0`,children:(0,s.jsx)(Ge,{name:l,className:`w-4 h-4`})}),(0,s.jsx)(`span`,{className:`text-[13px] font-semibold truncate`,children:Le(Ie(l))}),(0,s.jsx)(t.Tt,{className:`w-3.5 h-3.5 shrink-0`})]}):(0,s.jsx)(t.P,{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:l?`Type a word to change it`:`Type a word, e.g. calendar`,"aria-label":`Search icons`,className:`${Ce} 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 max-h-56 overflow-y-auto`,children:u.length>0?(0,s.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>{let t=Ie(l).toLowerCase()===e;return(0,s.jsx)(`button`,{type:`button`,title:Le(e),"aria-label":Le(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)] ring-2 ring-accent/40`:`text-foreground/60 hover:text-foreground hover:bg-foreground/[0.06]`}`,children:(0,s.jsx)(Ge,{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.`})})]})})}var qe=/(<[A-Z][A-Za-z0-9]*(?:\s[^<>]*)?\/?>|src\/[A-Za-z0-9_./-]*[A-Za-z0-9_-]|'[A-Za-z0-9_@./-]+')/g,Je=/(https?:\/\/[^\s]+)/g,Ye=e=>e.split(Je).flatMap((e,t)=>t%2==1?[{text:e,kind:`value`}]:e.split(qe).map((e,t)=>({text:e,kind:t%2==1?`code`:void 0}))).filter(e=>e.text),Xe=/exactly: |Here is what [^:]*: |It should ask for: |Where the form belongs on the page: |a button that says /,Ze=e=>{let t=Xe.exec(e);if(!t)return Ye(e);let n=t.index+t[0].length,r=e.slice(0,n),i=e.slice(n),a=i.indexOf(` — `);return[...Ye(r),{text:a===-1?i:i.slice(0,a),kind:`value`},...Ye(a===-1?``:i.slice(a))]},Qe=`text-accent font-semibold bg-accent/[0.08] rounded-[4px] px-1 -mx-[1px] [overflow-wrap:anywhere]`,$e=`font-mono text-[0.92em] text-foreground/75 bg-foreground/[0.055] border border-[var(--panel-border)]/60 rounded-[4px] px-1 py-[1px] [overflow-wrap:anywhere]`;function et({text:e}){return(0,s.jsx)(s.Fragment,{children:Ze(e).map((e,t)=>e.kind?(0,s.jsx)(`span`,{className:e.kind===`value`?Qe:$e,children:e.text},t):(0,s.jsx)(r.default.Fragment,{children:e.text},t))})}function tt({title:e=`Ask your assistant`,description:n,prompt:i,compact:a=!1,locked:o=!1,onCopied:c}){let[l,u]=(0,r.useState)(!1),d=i.includes(`
2
2
  `);return o?null:(0,s.jsxs)(`div`,{className:`flex flex-col gap-2 min-w-0 max-w-full 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),u(!0),setTimeout(()=>u(!1),2e3),c&&setTimeout(c,550)},"aria-label":l?`Copied`:`Copy`,className:`inline-flex items-center justify-center gap-1.5 h-8 w-8 px-0 sm:w-auto sm:px-3 rounded-[var(--btn-radius,0.75rem)] text-[12px] font-semibold shrink-0 border ${l?`copy-btn-done border-emerald-500/30 bg-emerald-500/10 text-emerald-500 cursor-pointer`:`copy-btn cursor-pointer`}`,children:[l?(0,s.jsx)(t.Tt,{className:`copy-icon w-3.5 h-3.5`}):(0,s.jsx)(t.pt,{className:`copy-icon w-3.5 h-3.5`}),(0,s.jsx)(`span`,{className:`max-sm:hidden`,children:l?`Copied`:`Copy`})]})]}),n&&(0,s.jsx)(`p`,{className:`text-[12.5px] text-foreground/50 font-medium leading-relaxed break-words`,children:n}),(0,s.jsx)(`div`,{className:`text-[13.5px] font-medium leading-relaxed break-words [overflow-wrap:anywhere]`,children:d?(0,s.jsx)(`div`,{className:`flex flex-col gap-2 text-foreground/80`,children:i.split(`
3
- `).filter(e=>e.trim()).map((e,t)=>(0,s.jsx)(`p`,{className:`min-w-0`,children:(0,s.jsx)(nt,{text:e})},t))}):(0,s.jsxs)(`p`,{className:`text-foreground/80`,children:[`“`,(0,s.jsx)(nt,{text:i}),`”`]})})]})}var it=`w-11 h-11 shrink-0 rounded-[var(--input-radius,0.75rem)] overflow-hidden border border-[var(--panel-border)]`,at=e=>{try{return(decodeURIComponent(new URL(e).pathname).split(`/`).pop()||``).replace(/^\d{10,}_/,``)||`Your picture`}catch{return`Your picture`}};function ot({label:e,hint:n,value:i,onChange:a,accept:o=`image/*`,action:c,clearable:l=!0,tips:u,onBusyChange:d}){let{user:f}=N(),[p,m]=(0,r.useState)(!1),[h,g]=(0,r.useState)(``),[_,v]=(0,r.useState)(!1),[y,b]=(0,r.useState)(!1),x=(0,s.jsx)(`input`,{type:`file`,accept:o,"aria-label":i?`Replace ${e}`:`Upload ${e}`,disabled:p,onChange:async e=>{let n=e.target.files?.[0];if(e.target.value=``,!(!n||p)){m(!0),d?.(!0),g(``);try{a(await t.a(n,f))}catch(e){g(t.i(e))}m(!1),d?.(!1),b(!1)}},className:`sr-only`});return(0,s.jsxs)(ke,{label:e,hint:n,error:h,action:c,children:[i&&!p?(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(`div`,{className:`${we} min-w-0`,children:(0,s.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[14px] text-foreground/60 select-none`,children:at(i)})}),(0,s.jsxs)(`div`,{className:`${it} relative group/pic`,children:[(0,s.jsx)(`button`,{type:`button`,onClick:()=>b(e=>!e),"aria-label":`Change ${e}`,"aria-expanded":y,className:`block w-full h-full cursor-pointer`,children:(0,s.jsx)(`img`,{src:i,alt:e,className:`w-full h-full object-cover`})}),(0,s.jsxs)(`div`,{className:`absolute inset-0 flex items-center justify-center gap-1 bg-background/85 transition-opacity duration-200 ${y?`opacity-100`:`opacity-0 pointer-events-none group-hover/pic:opacity-100 group-hover/pic:pointer-events-auto focus-within:opacity-100 focus-within:pointer-events-auto`}`,children:[(0,s.jsxs)(`label`,{title:`Replace ${e}`,className:`w-6 h-6 rounded-md flex items-center justify-center text-foreground/60 hover:text-accent hover:bg-foreground/10 transition-colors cursor-pointer`,children:[(0,s.jsx)(t.ht,{className:`w-3.5 h-3.5`}),x]}),l&&(0,s.jsx)(`button`,{type:`button`,onClick:()=>{g(``),b(!1),a(``)},"aria-label":`Remove ${e}`,title:`Remove ${e}`,className:`w-6 h-6 rounded-md flex items-center justify-center text-foreground/60 hover:text-red-500 hover:bg-red-500/10 transition-colors cursor-pointer`,children:(0,s.jsx)(t.v,{className:`w-3.5 h-3.5`})})]})]})]}):(0,s.jsxs)(`label`,{title:`Upload ${e}`,className:`group/up flex items-center gap-2 ${p?`pointer-events-none`:`cursor-pointer`}`,children:[(0,s.jsx)(`span`,{className:`${we} select-none text-[14px] ${p?`text-foreground/50`:`text-foreground/35`} group-hover/up:border-accent/40 group-focus-within/up:border-accent`,children:p?`Uploading your picture…`:`Upload a picture`}),(0,s.jsx)(`span`,{"aria-hidden":!0,className:`${it} flex items-center justify-center bg-[var(--panel-bg)] text-foreground/40 group-hover/up:text-accent group-hover/up:border-accent/40 transition-colors`,children:p?(0,s.jsx)(t.K,{className:`w-4 h-4 animate-spin text-accent`}):(0,s.jsx)(t.ht,{className:`w-4 h-4`})}),x]}),!!u?.length&&(0,s.jsxs)(`div`,{className:`mt-2 px-1`,children:[(0,s.jsxs)(`button`,{type:`button`,onClick:()=>v(e=>!e),"aria-expanded":_,className:`inline-flex items-center gap-1 text-[11.5px] font-semibold text-foreground/40 hover:text-foreground/70 transition-colors cursor-pointer`,children:[(0,s.jsx)(t.St,{className:`w-3 h-3 shrink-0 transition-transform duration-200 ${_?`rotate-90`:``}`}),`Which picture should I upload?`]}),_&&(0,s.jsx)(`ul`,{className:`flex flex-col gap-1 mt-1.5 ml-4`,children:u.map(e=>(0,s.jsxs)(`li`,{className:`text-[11.5px] text-foreground/40 font-medium leading-snug flex gap-1.5`,children:[(0,s.jsx)(`span`,{"aria-hidden":!0,className:`text-accent/60`,children:`•`}),e]},e))})]})]})}var st=[`A wide picture sits best across a page — about 1600 by 900.`,`JPG or PNG. Any size — a big photo is shrunk for you as it uploads, so the page still opens quickly.`,`Your own photo beats a stock one. People can tell.`,`No writing baked into the picture — your assistant sets the words, so they stay readable on a phone.`],ct=[`A wide picture, not a square one — it sits in a short bar about 40px tall.`,`PNG with a see-through background looks right on both the light and the dark theme.`],lt=[`A square picture — 64 by 64 is plenty.`,`One shape or one letter. A whole logo turns to mush at this size.`],ut=e=>typeof e==`string`&&/^https?:\/\/\S+$/.test(e.trim())&&RegExp(`(/|%2F)pub_form_uploads(/|%2F)`,`i`).test(e),dt={anyone:{collectionName:`user_submissions`,chip:`Anyone`,filterLabel:`From anyone`},signedIn:{collectionName:`user_requests`,chip:`Signed-in user`,filterLabel:`From signed-in users`}},ft=[`id`,`source`,`uid`,`submittedAt`,`avatarUrl`,`isArchived`,`name`,`full_name`,`email`,`contactEmail`,`topic`],pt=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},mt=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)},ht=e=>{let t=new Date(e);return new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime()},gt=e=>{let t=pt(e);if(!t)return`Older`;let n=Math.round((ht(Date.now())-ht(t))/864e5);return n<=0?`Today`:n===1?`Yesterday`:n<7?`This week`:n<30?`This month`:`Older`},_t=e=>e.reduce((e,t)=>{let n=gt(t),r=e[e.length-1];return r&&r.label===n?r.items.push(t):e.push({label:n,items:[t]}),e},[]);function vt({label:e}){return(0,s.jsxs)(`div`,{className:`md:hidden flex items-center gap-3 pt-1 first:pt-0 select-none`,children:[(0,s.jsx)(`span`,{className:`text-[10.5px] font-bold uppercase tracking-[0.18em] text-foreground/35 shrink-0`,children:e}),(0,s.jsx)(`span`,{className:`h-px flex-1 bg-[var(--panel-border)]/60`})]})}var yt=e=>e.submitterName||e.name||e.full_name||`Anonymous`,bt=e=>e.contactEmail||e.email||`No email provided`;function xt(e){let[n,a]=(0,r.useState)([]),[o,s]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{let n=!1,r=dt[e].collectionName,o=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Ht,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.Ht,`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 St({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:dt[e].chip})}function Ct({item:e,isExpanded:n,onToggle:r,onArchive:i,onDelete:a,busy:o,dimmed:l}){let u=yt(e),d=e.avatarUrl||e.submitterAvatar,f=!!e.uid&&e.uid!==`guest`,p=Object.entries(e).filter(([e])=>!ft.includes(e)&&!e.toLowerCase().startsWith(`submitter`)&&e.toLowerCase()!==`formid`),m=e.topic?[[`topic`,e.topic],...p]:p,h=p.map(([,e])=>typeof e==`string`&&!ut(e)?e.trim():``).find(Boolean)||e.topic||``;return(0,s.jsxs)(t.p.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-3.5 md:px-5`,children:[(0,s.jsxs)(`button`,{type:`button`,onClick:r,"aria-expanded":n,className:`flex items-center gap-3 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-9 h-9 rounded-full object-cover border border-[var(--panel-border)] shadow-sm`}):(0,s.jsx)(`div`,{className:`w-9 h-9 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.jsx)(`span`,{className:`font-bold text-[14px] text-foreground truncate`,children:u}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/50 truncate flex items-center gap-1.5 font-medium mt-0.5`,children:[(0,s.jsx)(t.U,{className:`w-3.5 h-3.5 shrink-0`}),` `,bt(e)]}),!n&&h&&(0,s.jsx)(`span`,{className:`max-md:hidden text-[12.5px] text-foreground/40 truncate mt-0.5`,children:h})]})]}),(0,s.jsx)(`button`,{type:`button`,onClick:r,tabIndex:-1,"aria-hidden":`true`,className:`md:hidden w-8 h-8 -mr-1 flex items-center justify-center rounded-lg text-foreground/30 hover:text-accent hover:bg-foreground/5 transition-colors shrink-0 cursor-pointer`,children:(0,s.jsx)(t.wt,{className:`w-4 h-4 transition-transform duration-300 ${n?`rotate-180`:``}`})}),(0,s.jsxs)(`div`,{className:`max-md:hidden md:flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`div`,{className:`text-[12px] font-medium text-foreground/40 tabular-nums`,children:mt(e.submittedAt)}),(0,s.jsx)(Q,{icon:e.isArchived?t.At:t.Pt,onClick:i,busy:o,children:e.isArchived?`Restore`:`Archive`}),(0,s.jsx)(Q,{icon:t.E,tone:`danger`,onClick:a,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.wt,{className:`w-4 h-4`})})]})]}),(0,s.jsx)(t.m,{children:n&&(0,s.jsx)(t.p.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:`px-3.5 md:px-5 py-4 border-t border-[var(--panel-border)]/40`,children:[(0,s.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-3`,children:[(0,s.jsx)(St,{source:e.source}),e.formId&&(0,s.jsx)(`span`,{className:`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.jsx)(`span`,{className:`md:hidden text-[11px] font-medium text-foreground/40 shrink-0`,children:mt(e.submittedAt)})]}),m.length>0?(0,s.jsx)(`div`,{className:`rounded-xl border border-[var(--panel-border)]/60 bg-foreground/[0.02] divide-y divide-[var(--panel-border)]/40 overflow-hidden`,children:m.map(([e,n])=>(0,s.jsxs)(`div`,{className:`px-3.5 md:px-4 py-3`,children:[(0,s.jsx)(`span`,{className:`block text-[11px] font-bold uppercase tracking-widest text-foreground/40 mb-1`,children:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}),ut(n)?(0,s.jsxs)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-2 text-[14px] font-semibold text-accent hover:underline break-all [overflow-wrap:anywhere]`,children:[(0,s.jsx)(t.z,{className:`w-4 h-4 shrink-0`}),t.r(n)]}):(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/85 leading-relaxed whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:typeof n==`boolean`?n?`Yes`:`No`:e.toLowerCase()===`budget`&&n?`$${n}`:String(n??``)||`No data provided`})]},e))}):(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/40 font-medium`,children:`This form only asked for a name and email.`}),f&&(0,s.jsx)(c.Link,{to:`/users/${e.uid}`,className:`inline-flex mt-3 text-[12.5px] font-bold text-accent hover:underline`,children:`Open this person’s profile`}),(0,s.jsxs)(`div`,{className:`md:hidden flex items-center justify-end gap-2 mt-4`,children:[(0,s.jsx)(Q,{icon:e.isArchived?t.At:t.Pt,onClick:i,busy:o,children:e.isArchived?`Restore`:`Archive`}),(0,s.jsx)(Q,{icon:t.E,tone:`danger`,onClick:a,children:`Delete`})]})]})})})]})}function wt(){let e=xt(`anyone`),n=xt(`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)=>pt(t)-pt(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.Ht,dt[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.Ht,dt[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`,short:`All`},{key:`anyone`,label:dt.anyone.filterLabel,short:`Anyone`},{key:`signedIn`,label:dt.signedIn.filterLabel,short:`Signed in`}];return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,s.jsx)(ce,{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)(de,{})}),(0,s.jsxs)(`div`,{className:`w-full flex-1 flex flex-col glass-panel rounded-2xl md:rounded-3xl p-3 sm: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.tt,{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.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.jsxs)(`button`,{type:`button`,onClick:()=>o(e.key),"aria-pressed":a===e.key,"aria-label":e.label,className:`h-8 md:h-9 px-3 md:px-4 rounded-full text-[12px] md: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:[(0,s.jsx)(`span`,{className:`sm:hidden`,children:e.short}),(0,s.jsx)(`span`,{className:`max-sm:hidden`,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.m,{children:_t(x).map(e=>(0,s.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,s.jsx)(vt,{label:e.label}),e.items.map(e=>(0,s.jsx)(Ct,{item:e,isExpanded:c===C(e),onToggle:()=>w(e),onArchive:()=>T(e),onDelete:()=>h(e),busy:f===C(e)},C(e)))]},e.label))}),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.wt,{className:`w-3.5 h-3.5 transition-transform duration-300 ${u?`rotate-180`:``}`})]})}),(0,s.jsx)(t.m,{children:u&&(0,s.jsx)(t.p.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:_t(S).map(e=>(0,s.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,s.jsx)(vt,{label:e.label}),e.items.map(e=>(0,s.jsx)(Ct,{item:e,isExpanded:c===C(e),onToggle:()=>w(e),onArchive:()=>T(e),onDelete:()=>h(e),busy:f===C(e),dimmed:!0},C(e)))]},e.label))})})})]})]})})]})]}),(0,s.jsx)(be,{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 Tt=`inline-flex items-center justify-center w-9 h-9 rounded-full border border-[var(--panel-border)] text-foreground/50 hover:text-accent hover:bg-foreground/5 transition-colors shrink-0 cursor-pointer`,Et=({to:e})=>e?(0,s.jsx)(c.Link,{to:e,"aria-label":`Go back`,title:`Go back`,className:Tt,children:(0,s.jsx)(t.Mt,{className:`w-4 h-4`})}):(0,s.jsx)(`button`,{type:`button`,onClick:()=>window.history.back(),"aria-label":`Go back`,title:`Go back`,className:Tt,children:(0,s.jsx)(t.Mt,{className:`w-4 h-4`})}),Dt=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 Ot({title:e=`Drive`,subtitle:n=`/drive`,backUrl:a=`/templates`,filesCollection:u=`pub_files`,config:d,customContent:f,footer:p}){let{user:m,userRole:h}=N(),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),[A,j]=(0,r.useState)(!1),[M,P]=(0,r.useState)(null),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)({}),[z,B]=(0,r.useState)(!1),[ee,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.Ht,u),(0,i.where)(`uid`,`==`,m.uid)):(0,i.query)((0,i.collection)(t.Ht,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 ne=e=>!!m&&(e.uid===m.uid||_),re=e=>{V(e),H(e.name),K(``),B(!0)},ie=()=>{V(null),K(``),B(!0)},ae=async e=>{if(e.preventDefault(),!(!ee||!te.trim()||!m)){W(!0),K(``);try{let e=await t.o(ee),n=`${v}/${`${Date.now()}_${e.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,r=(0,o.ref)(t.Wt,n);await(0,o.uploadBytes)(r,e,{customMetadata:{ownerId:m.uid}});let a=await(0,o.getDownloadURL)(r);await(0,i.addDoc)((0,i.collection)(t.Ht,u),{fileName:te.trim(),fileType:e.type||`unknown`,fileSize:e.size,downloadURL:a,storagePath:n,uid:m.uid,uploaderEmail:m.email||``,createdAt:(0,i.serverTimestamp)()}),B(!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)}},X=async()=>{if(O){j(!0);try{await Promise.all([(0,o.deleteObject)((0,o.ref)(t.Wt,O.storagePath||O.downloadURL)).catch(e=>console.warn(`Storage object missing:`,e)),(0,i.deleteDoc)((0,i.doc)(t.Ht,u,O._id))]),k(null)}catch(e){console.error(`Delete failed:`,e)}j(!1)}},oe=async()=>{if(!M||!M.name.trim()){P(null);return}try{await(0,i.updateDoc)((0,i.doc)(t.Ht,u,M.id),{fileName:M.name.trim()})}catch(e){console.error(`Rename failed:`,e)}P(null)},Z=(e,t)=>{navigator.clipboard.writeText(e),I(t),setTimeout(()=>I(null),2e3)},se=(e,n=`row`)=>{let r=n===`card`?`w-16 h-16`:`w-10 h-10`,i=n===`card`?`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.b,{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.ot,{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.Ft,{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.mt,{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.at,{className:i})})};return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 flex flex-col 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]&&re(e.dataTransfer.files[0])},children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4 md:mb-6 flex items-center gap-3`,children:[!g&&(0,s.jsx)(Et,{to:a}),(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(ce,{children:e}),(0,s.jsxs)(`div`,{className:`max-sm:hidden sm: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)(de,{})}),(0,s.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl md:rounded-3xl overflow-hidden flex-1 shadow-2xl min-h-[420px] md:min-h-[520px] mb-16 bg-background flex flex-col`,children:[(0,s.jsxs)(`div`,{className:`p-4 md:p-8 flex items-center justify-between gap-3 md:gap-6 border-b border-[var(--panel-border)]/50 bg-background/50`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-lg md:text-2xl font-extrabold text-foreground tracking-tight`,children:`Files`}),(0,s.jsx)(`p`,{className:`max-sm:hidden text-[12px] md:text-[13px] mt-1 md: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.`})]}),!f&&(m?(0,s.jsxs)(t.c,{onClick:ie,title:`Add file`,className:`flex items-center justify-center gap-2 w-9 h-9 p-0 sm:w-auto sm:h-auto sm:px-5 sm:py-2.5 rounded-xl text-[13px] font-bold shadow-md shrink-0`,children:[(0,s.jsx)(t.L,{className:`w-4 h-4`}),` `,(0,s.jsx)(`span`,{className:`max-sm:hidden`,children:`Add file`})]}):(0,s.jsxs)(c.Link,{to:`/login`,title:`Sign in to add a file`,className:`btn-primary flex items-center justify-center gap-2 w-9 h-9 p-0 sm:w-auto sm:h-auto sm:px-5 sm:py-2.5 rounded-xl text-[13px] font-bold shadow-md shrink-0`,children:[(0,s.jsx)(t.L,{className:`w-4 h-4`}),` `,(0,s.jsx)(`span`,{className:`max-sm:hidden`,children:`Add file`})]}))]}),f?(0,s.jsx)(`div`,{className:`fbos-content-slot p-4 md:p-8 flex-1`,children:(0,s.jsx)(f,{files:b,loading:S,user:m,uploadFile:re,deleteFile:k,openUploadModal:ie,config:d})}):(0,s.jsxs)(`div`,{className:`p-4 sm: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.K,{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-3 sm: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 group-focus-within: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.dt,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),Z(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.Tt,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.J,{className:`w-4 h-4`})}),ne(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.R,{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.E,{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.K,{className:`w-5 h-5 text-accent animate-spin`})}),(0,s.jsx)(`img`,{src:e.downloadURL,alt:``,loading:`lazy`,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}))})]}):se(e.fileType,`card`)}),(0,s.jsxs)(`div`,{className:`p-3 flex flex-col justify-center flex-1 min-w-0`,onClick:()=>!M&&T(e),children:[M?.id===e._id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:M.name,onChange:e=>P({...M,name:e.target.value}),onBlur:oe,onKeyDown:e=>{e.key===`Enter`&&oe(),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:Dt(e.fileSize)})]})]},e._id))}):!S&&(0,s.jsxs)(`div`,{onClick:()=>m&&B(!0),className:`min-h-[320px] flex flex-col items-center justify-center text-center cursor-pointer group`,children:[(0,s.jsx)(t.ht,{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.m,{children:z&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.div,{onClick:()=>!U&&B(!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.p.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-4 md: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&&B(!1),className:`text-foreground/40 hover:text-foreground transition-colors`,children:(0,s.jsx)(t.v,{className:`w-5 h-5`})})]}),ee?(0,s.jsxs)(`form`,{onSubmit:ae,className:`p-4 md:p-6 flex flex-col gap-5 md: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:[se(ee.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:ee.name}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold uppercase tracking-wider mt-1`,children:Dt(ee.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.E,{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.c,{type:`submit`,isLoading:U,className:`w-full py-4 rounded-xl text-[14px] font-bold shadow-lg`,children:U?`Uploading…`:`Upload`})]}):(0,s.jsx)(`div`,{className:`p-4 md:p-6`,children:(0,s.jsxs)(`label`,{onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),e.dataTransfer.files?.[0]&&re(e.dataTransfer.files[0])},className:`group flex flex-col items-center justify-center gap-1.5 px-6 py-12 rounded-2xl border-2 border-dashed border-[var(--panel-border)] bg-foreground/[0.015] hover:border-accent/50 hover:bg-accent/[0.03] cursor-pointer text-center transition-all`,children:[(0,s.jsx)(`span`,{className:`w-14 h-14 rounded-full bg-accent/10 text-accent flex items-center justify-center mb-2 group-hover:scale-105 transition-transform`,children:(0,s.jsx)(t.ht,{className:`w-6 h-6`})}),(0,s.jsxs)(`p`,{className:`text-[15px] font-bold text-foreground`,children:[(0,s.jsx)(`span`,{className:`text-accent`,children:`Click to upload`}),` or drag a file in`]}),(0,s.jsx)(`p`,{className:`text-[12.5px] text-foreground/45 font-medium`,children:`Pictures, documents, anything`}),(0,s.jsx)(`input`,{type:`file`,ref:Y,"aria-label":`Upload a file`,onChange:e=>e.target.files?.[0]&&re(e.target.files[0]),className:`hidden`})]})})]})]})}),typeof window<`u`&&(0,l.createPortal)((0,s.jsx)(t.m,{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.p.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-3 right-3 md:top-6 md:right-6 z-[160] w-10 h-10 md:w-12 md: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.v,{className:`w-5 h-5`})}),(0,s.jsxs)(t.p.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-3.5 md: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-3 md:pr-4`,children:[(0,s.jsx)(`span`,{className:`text-[15px] md:text-xl font-extrabold text-foreground truncate`,children:w.fileName}),(0,s.jsxs)(`span`,{className:`text-[10.5px] md:text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-0.5 md:mt-1 truncate`,children:[w.fileType,` • `,Dt(w.fileSize)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5 md:gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>Z(w.downloadURL,w._id),className:`p-2 md: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.Tt,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.J,{className:`w-4 h-4`})}),ne(w)&&(0,s.jsx)(`button`,{onClick:()=>{let e=w;T(null),k(e)},className:`p-2 md: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.E,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:w.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2 md:p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-0.5 md:ml-1`,title:`Download`,children:(0,s.jsx)(t.dt,{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.K,{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.at,{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)(be,{isOpen:!!O,title:`Delete file`,message:(0,s.jsxs)(s.Fragment,{children:[`Delete `,(0,s.jsx)(`strong`,{className:`text-foreground block my-1 break-words max-w-full text-center`,children:O?.fileName}),` This cannot be undone.`]}),onConfirm:X,onCancel:()=>k(null),isProcessing:A,confirmText:`Yes, delete`}),(0,s.jsx)(t.m,{children:q&&(0,s.jsx)(t.p.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.ht,{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 kt=[`mem_files`,`user_files`,`admin_files`],At=e=>!e.sourceTab;function jt(){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(kt.map(async e=>{try{return(await(0,i.getDocs)((0,i.collection)(t.Ht,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&&At(n)&&await(0,o.deleteObject)((0,o.ref)(t.Wt,e)).catch(()=>{}),await(0,i.deleteDoc)((0,i.doc)(t.Ht,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(kt.map(async e=>{try{return(await(0,i.getDocs)((0,i.collection)(t.Ht,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(At).length,_=kt.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.p.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-2xl md:rounded-3xl p-4 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.K,{className:`w-4 h-4 animate-spin`}):(0,s.jsx)(t.E,{className:`w-4 h-4`}),l?`Deleting ${p} of ${e.length}…`:`Clean up all ${e.length} permanently`]})]}),(0,s.jsx)(be,{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 Mt(){let{isAdmin:e}=N();return(0,s.jsx)(Ot,{title:`Assets`,subtitle:`/assets`,filesCollection:`pub_files`,config:{isAdmin:!0,pageId:`assets`},footer:e?(0,s.jsx)(jt,{}):null})}function Nt(){let e=[{id:`board`,title:`Board View`,description:`Cards in columns you drag from one stage to the next.`,icon:t.et,path:`/board`},{id:`table`,title:`Data Table`,description:`Rows and columns for longer lists, with search and sorting.`,icon:t.D,path:`/table`},{id:`calendar`,title:`Calendar View`,description:`A month at a time for anything that belongs on a date.`,icon:t.Dt,path:`/calendar`},{id:`drive`,title:`Drive View`,description:`A file library with upload, preview, rename and delete.`,icon:t.rt,path:`/drive`}];return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-10 text-center`,children:[(0,s.jsx)(ce,{children:`What your assistant can build`}),(0,s.jsxs)(`p`,{className:`text-foreground/60 text-[14px] md:text-[15px] font-medium max-w-2xl mx-auto`,children:[`Every layout below already works — open one to see it.`,` `,(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-3 md: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.jsx)(t.p.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:n*.05},children:(0,s.jsxs)(c.Link,{to:e.path,className:`flex items-center gap-3 md:gap-5 w-full p-3.5 md:px-6 md:py-4 glass-panel border border-[var(--panel-border)] rounded-2xl hover:border-accent/40 transition-all duration-300 group hover:bg-foreground/[0.02]`,children:[(0,s.jsx)(`div`,{className:`w-10 h-10 md:w-12 md: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-[14px] md:text-[15px] font-bold text-foreground truncate`,children:e.title}),(0,s.jsx)(`p`,{className:`text-[12.5px] md:text-[13px] text-foreground/50 truncate font-medium`,children:e.description})]}),(0,s.jsx)(`span`,{"aria-hidden":`true`,className:`w-9 h-9 rounded-full flex items-center justify-center text-foreground/40 border border-[var(--panel-border)] shrink-0 group-hover:text-accent group-hover:border-accent/40 group-hover:translate-x-0.5 transition-all`,children:(0,s.jsx)(t.jt,{className:`w-4 h-4`})})]})},e.id)})]})]})}var Pt=`Xl271wWblkY`,Ft=[{title:`Open the Pages screen and press +`,body:`Pick who the page is for — Anyone, Signed-in users, Your team or Admins only. That one choice decides who can open it and which menu it appears in.`},{title:`Give it an address, a name and a heading`,body:`The web address creates the page the moment you fill it in. A dashboard page also gets an icon and a starting layout: board, table, calendar, files, or from scratch.`},{title:`If it needs a form, add it right there`,body:`In the page’s Form box pick A new form made for this page, say what it should ask, and name the button that opens it. Who can fill it in follows who the page is for, and every answer lands in your Inbox.`},{title:`Add your pictures on the row`,body:`On a page anyone can visit, upload each picture right there and say where on the page it belongs. Pictures never travel through the chat — the sentence you copy carries them for you.`},{title:`Say what you want on it, then copy the sentence`,body:`Write what you would like to see on the page in your own words. The finished sentence appears under it; copy it and paste it into your assistant’s chat. That is the whole hand-over.`},{title:`Change it later with Edit with AI`,body:`Once a page is built, press Edit with AI on its row. The row swaps to three boxes — what to add, what to change, what to take off — and hands you a different sentence: one that edits the page you already have. Nothing you did not mention is touched.`}],It=[{name:`Anyone`,where:`In the site menu`,who:`Everybody, signed in or not. This is your public website.`},{name:`Signed-in users`,where:`In the dashboard`,who:`Anyone who registers. Each person sees only their own information, never anyone else’s.`},{name:`Your team`,where:`In the dashboard`,who:`Only people you marked as team members on the Users screen, plus admins. Everyone on it sees the same information.`},{name:`Admins only`,where:`In the dashboard`,who:`You, and anyone you marked as an admin.`}],Lt=[{title:`Someone registers`,body:`That makes them a signed-in user, nothing more: they can open the pages for signed-in users and see only their own information there.`},{title:`You give them rights on the Users screen`,body:`Mark a person as a team member to open your team’s pages, or as an admin to open everything — your admin screens included. Take either back the same way.`},{title:`The pages do the rest`,body:`Access always follows who a page is for. There is nothing to switch on per person beyond the mark you set — a new team page is open to your whole team the moment it exists.`}],Rt=[{name:`Colours`,body:`Your brand colour, the page background and the text colour, for light mode and for dark mode. Ask the chat for colour codes if you want ideas — then paste them into the boxes yourself.`},{name:`Corners`,body:`How rounded the panels and buttons are. The lettering is not on this list: the site is set in one typeface and there is no setting for it.`},{name:`Your logo`,body:`Upload it once and it appears in the header everywhere. Pictures are shrunk for you as they upload.`},{name:`Light or dark`,body:`Choose which one the site opens in.`}],zt=[{screen:`Pages`,path:`/pages`,body:`Add a page for any audience and give it a form and pictures if it needs them. Rename a page, change its web address or icon, reorder it, hide it or delete it — and press Edit with AI on any row to copy the sentence that changes a page you already have.`},{screen:`Forms`,path:`/forms`,body:`See every form. Add a question or change a form’s title and button text after it is built — forms are created with their pages.`},{screen:`Theme`,path:`/theme`,body:`Colours, 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.`}],Bt=[{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:`Let the Pages screen write the request`,body:`Describe the page on its row and paste the sentence it hands you. It answers every question the assistant would otherwise stop to ask.`},{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."`}],Vt=[{id:`how-it-works`,short:`How it all works`},{id:`add-a-page`,short:`Adding a page`},{id:`audiences`,short:`The four kinds of pages`},{id:`users`,short:`Letting people in`},{id:`theme`,short:`Changing the look`},{id:`yourself`,short:`Where everything lives`},{id:`habits`,short:`Working with the assistant`}];function Ht({children:e}){return(0,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px] mb-3`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e]})}function Ut({id:e,index:n,kicker:r,title:i,children:a}){return(0,s.jsxs)(t.p.section,{id:e,initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.05+n*.03},className:`mb-16 scroll-mt-24`,children:[(0,s.jsx)(Ht,{children:`0${n+1} · ${r}`}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold tracking-tight text-foreground mb-3`,children:i}),a]})}function Wt({children:e}){return(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl mb-4 last:mb-0`,children:e})}function Gt({steps:e}){return(0,s.jsx)(`ol`,{className:`mt-6`,children:e.map((t,n)=>(0,s.jsxs)(`li`,{className:`relative grid grid-cols-[2.25rem_1fr] gap-x-4 pb-8 last:pb-0`,children:[n<e.length-1&&(0,s.jsx)(`span`,{"aria-hidden":!0,className:`absolute left-[1.125rem] top-10 bottom-1 w-px -translate-x-1/2 bg-[var(--panel-border)]`}),(0,s.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-full border border-[var(--panel-border)] bg-[var(--panel-bg)] text-[13px] font-bold text-accent tabular-nums select-none`,children:n+1}),(0,s.jsxs)(`div`,{className:`pt-1.5 min-w-0`,children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold tracking-tight text-foreground`,children:t.title}),(0,s.jsx)(`p`,{className:`mt-1.5 text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl`,children:t.body})]})]},t.title))})}function Kt({lead:e,children:t}){return(0,s.jsx)(`div`,{className:`mt-7 border-l-2 border-accent/50 pl-4`,children:(0,s.jsxs)(`p`,{className:`text-[13.5px] text-foreground/60 font-medium leading-relaxed max-w-2xl`,children:[(0,s.jsx)(`strong`,{className:`font-bold text-foreground/85`,children:e}),` `,t]})})}function qt(){return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-3xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-10 text-center`,children:[(0,s.jsx)(ce,{children:`Guide`}),(0,s.jsx)(`p`,{className:`text-foreground/60 text-[14px] md:text-[15px] font-medium max-w-2xl mx-auto`,children:`Everything you run yourself, everything your assistant builds for you, and the one recipe that makes every page. Ten minutes, start to finish.`})]}),(0,s.jsxs)(t.p.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`mb-10`,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/${Pt}?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.p.nav,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.03},"aria-label":`In this guide`,className:`mb-14`,children:[(0,s.jsx)(Ht,{children:`In this guide`}),(0,s.jsx)(`ol`,{className:`grid gap-x-10 gap-y-1.5 sm:grid-cols-2`,children:Vt.map((e,t)=>(0,s.jsx)(`li`,{children:(0,s.jsxs)(`a`,{href:`#${e.id}`,className:`group flex items-baseline gap-2.5 py-0.5 w-fit`,children:[(0,s.jsxs)(`span`,{className:`text-[11px] font-bold text-foreground/35 tabular-nums`,children:[`0`,t+1]}),(0,s.jsx)(`span`,{className:`text-[14px] font-semibold text-foreground/75 group-hover:text-accent transition-colors`,children:e.short})]})},e.id))})]}),(0,s.jsxs)(Ut,{id:`how-it-works`,index:0,kicker:`Start here`,title:`How it all works`,children:[(0,s.jsx)(Wt,{children:`Your site is a set of pages. Some are open to the world — that is your public website. The rest live in the dashboard, behind a sign-in: pages every registered person can open, pages only your team can open, and pages only admins can open.`}),(0,s.jsx)(Wt,{children:`You run all of it from the admin screens in your menu — Pages, Forms, Theme, Users, Inbox. Everything on those screens changes with a click and takes effect at once: names, addresses, colours, who counts as team, who counts as admin.`}),(0,s.jsxs)(Wt,{children:[`What goes `,(0,s.jsx)(`em`,{className:`not-italic font-bold text-foreground/80`,children:`on`}),` a page is the one thing you do not click together — your assistant builds it. But you never have to work out what to say to it: when you describe a page on the Pages screen, the screen writes the whole request as one sentence. You copy that sentence, paste it into your assistant’s chat, and the page gets built. That copy-and-paste is the entire relationship, and the next chapter walks through it.`]})]}),(0,s.jsxs)(Ut,{id:`add-a-page`,index:1,kicker:`The one recipe`,title:`How to add a page — any kind`,children:[(0,s.jsx)(Wt,{children:`The same six steps make every page: a public one for your website, a board for your team, a table each signed-in person has to themselves. Never ask the chat to create a page out of nowhere — the Pages screen writes a better request than anyone types by hand.`}),(0,s.jsx)(Gt,{steps:Ft}),(0,s.jsxs)(Kt,{lead:`Not sure which layout to pick?`,children:[(0,s.jsx)(c.Link,{to:`/templates`,className:`text-accent font-bold hover:underline`,children:`Look through the templates`}),` `,`to see each one working before you choose.`]})]}),(0,s.jsxs)(Ut,{id:`audiences`,index:2,kicker:`Who it is for`,title:`The four kinds of pages`,children:[(0,s.jsx)(Wt,{children:`Every page is for exactly one audience — the choice you make when you press + on the Pages screen. It decides who can open the page and which menu it appears in. These are the words printed there:`}),(0,s.jsx)(`div`,{className:`mt-6 space-y-6`,children:It.map(e=>(0,s.jsxs)(`div`,{children:[(0,s.jsxs)(`div`,{className:`flex items-baseline gap-2.5 flex-wrap`,children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold tracking-tight text-foreground`,children:e.name}),(0,s.jsx)(`span`,{className:`text-[12px] text-accent font-semibold`,children:e.where})]}),(0,s.jsx)(`p`,{className:`mt-1 text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl`,children:e.who})]},e.name))}),(0,s.jsx)(Kt,{lead:`Careful:`,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)(Ut,{id:`users`,index:3,kicker:`Letting people in`,title:`How users work`,children:[(0,s.jsx)(Wt,{children:`People let themselves in at the front door; you decide who gets further.`}),(0,s.jsx)(Gt,{steps:Lt})]}),(0,s.jsxs)(Ut,{id:`theme`,index:4,kicker:`The look`,title:`How to change the theme`,children:[(0,s.jsxs)(Wt,{children:[`Everything about the look lives on your`,` `,(0,s.jsx)(c.Link,{to:`/theme`,className:`text-accent font-bold hover:underline`,children:`Theme screen`}),`. Change a value there and the whole site follows at once — no assistant needed, nothing to rebuild. Four things are yours to set:`]}),(0,s.jsx)(`div`,{className:`mt-6 space-y-6`,children:Rt.map(e=>(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold tracking-tight text-foreground`,children:e.name}),(0,s.jsx)(`p`,{className:`mt-1 text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl`,children:e.body})]},e.name))})]}),(0,s.jsxs)(Ut,{id:`yourself`,index:5,kicker:`No assistant needed`,title:`Where everything lives`,children:[(0,s.jsx)(Wt,{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:`mt-6 space-y-6`,children:zt.map(e=>(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold tracking-tight w-fit`,children:(0,s.jsx)(c.Link,{to:e.path,className:`text-foreground hover:text-accent transition-colors`,children:e.screen})}),(0,s.jsx)(`p`,{className:`mt-1 text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl`,children:e.body})]},e.screen))}),(0,s.jsx)(Kt,{lead:`Good to know:`,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)(Ut,{id:`habits`,index:6,kicker:`Five habits`,title:`Working with the assistant`,children:[(0,s.jsx)(Wt,{children:`Five habits keep the assistant on track. There is nothing to memorise beyond them.`}),(0,s.jsx)(`div`,{className:`mt-6 space-y-6`,children:Bt.map(e=>(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold tracking-tight text-foreground`,children:e.title}),(0,s.jsx)(`p`,{className:`mt-1 text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl`,children:e.body})]},e.title))})]})]})}function Jt(){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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col`,children:[(0,s.jsx)(`div`,{className:`w-full max-w-5xl mx-auto mb-6`,children:(0,s.jsx)(Et,{to:`/templates`})}),(0,s.jsx)(`div`,{className:`w-full max-w-5xl mx-auto mt-6`,children:(0,s.jsxs)(t.p.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-form 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.p.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.yt,{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.p.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.p.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.Vt.currentUser?.uid||`guest`;await(0,i.addDoc)((0,i.collection)(t.Ht,`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.l,{label:`Favorite Service`,placeholder:`e.g. Design Consulting`,value:e.favoriteService,onChange:t=>n({...e,favoriteService:t.target.value})}),(0,s.jsx)(t.l,{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.c,{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 Yt(){let[e,n]=(0,r.useState)(!1),[a,o]=(0,r.useState)({concept:``,featureRequest:``,notes:``}),[c,l]=(0,r.useState)(`idle`);return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,s.jsx)(`div`,{className:`mb-3`,children:(0,s.jsx)(Et,{to:`/templates`})}),(0,s.jsx)(ce,{children:`Popup Form`}),(0,s.jsxs)(`div`,{className:`max-sm:hidden sm: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.jsxs)(t.p.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.jsxs)(`div`,{className:`flex flex-col sm:flex-row h-full w-full gap-4 sm:gap-6 justify-between sm:items-center relative z-10`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-xl md:text-2xl font-extrabold text-foreground tracking-tight mb-2`,children:`A form in a pop-up`}),(0,s.jsx)(`p`,{className:`text-[13px] md:text-[14px] text-foreground/60 font-medium leading-relaxed max-w-md`,children:`The page stays where it is and the form opens over it, with the background blurred. Close it and nothing is lost.`})]}),(0,s.jsxs)(t.c,{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 shrink-0`,children:[(0,s.jsx)(t.L,{className:`w-4 h-4`}),` Open Form`]})]})]}),(0,s.jsx)(t.m,{children:e&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.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.p.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-popover relative 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.v,{className:`w-5 h-5`})}),c===`success`?(0,s.jsxs)(t.p.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.yt,{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.`})]}):c===`loading`?(0,s.jsxs)(t.p.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.p.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(),l(`loading`);try{let e=t.Vt.currentUser?.uid||`guest`;await(0,i.addDoc)((0,i.collection)(t.Ht,`user_submissions`),{uid:e,...a,type:`template_simulation`,submittedAt:(0,i.serverTimestamp)()}),l(`success`),setTimeout(()=>{l(`idle`),o({concept:``,featureRequest:``,notes:``}),n(!1)},3e3)}catch{l(`error`)}},className:`space-y-4 w-full`,children:[(0,s.jsx)(t.l,{label:`Concept Name`,placeholder:`e.g. Project Apollo`,value:a.concept,onChange:e=>o({...a,concept:e.target.value})}),(0,s.jsx)(t.l,{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.c,{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`})})]})]})]})]})]})})]})}var Xt=[{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 Zt({title:e=`Board View`,subtitle:n=`/board`,backUrl:a=`/templates`,tasksCollection:o=`pub_tasks`,categoriesCollection:c=`pub_categories`,config:l,customContent:u}){let{user:d}=N(),f=!!l,p=l?.isInternal||l?.isShared;l?.isPrivate&&l?.isAdmin;let m=l?.isAdmin||p,h=f?m:!0,g=!!u,_=l?.showButton!==!1&&!g,v=l?.buttonText||`+`,y=l?.buttonStyle||`primary`,b=l?.keyName||`key`,x=l?.valueName||`value`,[S,C]=(0,r.useState)([]),[w,T]=(0,r.useState)([]),[E,D]=(0,r.useState)(null),[O,k]=(0,r.useState)(null),[A,j]=(0,r.useState)({name:``}),[M,P]=(0,r.useState)([]),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)(null),[z,B]=(0,r.useState)(null),[ee,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=c.startsWith(`user_`);if(e&&!d)return;try{let e=localStorage.getItem(`fbos_board_tasks_${o}`);e&&C(JSON.parse(e));let t=localStorage.getItem(`fbos_board_cats_${c}`);t&&T(JSON.parse(t))}catch{}let r=(0,i.onSnapshot)(e&&d?(0,i.query)((0,i.collection)(t.Ht,o),(0,i.where)(`uid`,`==`,d.uid)):(0,i.collection)(t.Ht,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&&d?(0,i.query)((0,i.collection)(t.Ht,c),(0,i.where)(`uid`,`==`,d.uid)):(0,i.collection)(t.Ht,c),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=d?{uid:d.uid}:{};e.forEach(e=>(0,i.setDoc)((0,i.doc)(t.Ht,c,e.id),{...n,title:e.title,createdAt:e.createdAt}))}else T(n),localStorage.setItem(`fbos_board_cats_${c}`,JSON.stringify(n))});return()=>{r(),a()}},[o,c,d]);let Y=(e,t)=>{t?(k(t.id),j({id:t.id,name:t.name}),P(t.fields?.length?[...t.fields,{key:``,value:``}]:[{key:``,value:``}])):(D(e),j({name:``}),P([{key:``,value:``}]))},ne=(e,t,n)=>{let r=[...M];r[e]={key:t,value:n},e===M.length-1&&(t.trim()!==``||n.trim()!==``)&&r.push({key:``,value:``}),P(r)},re=(e,t)=>{e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`taskId`,t),I(t)},ie=(e,t)=>{e.preventDefault(),e.stopPropagation(),t!==F&&R(t)},ae=(e,t)=>{e.preventDefault(),e.stopPropagation(),B(t)},X=e=>{e.preventDefault(),R(null),B(null)},oe=async(e,n,r)=>{e.preventDefault(),e.stopPropagation(),R(null),B(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};d&&(a.uid=d.uid),(0,i.setDoc)((0,i.doc)(t.Ht,o,e.id),a,{merge:!0})}),I(null)},Z=async e=>{let n=A.id||`item_${Date.now()}`,r=A.name.trim(),a=r||`Untitled Item`,s=M.filter(e=>e.key.trim()!==``||e.value.trim()!==``),c=!0,l=A.id?S.find(e=>e.id===A.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(A.id||`new`);let u={categoryId:e,name:a,fields:s};d&&!A.id&&(u.uid=d.uid),await(0,i.setDoc)((0,i.doc)(t.Ht,o,n),u,{merge:!0}),setTimeout(()=>{D(null),k(null),V(null)},400)},se=(e,t)=>{J({type:`item`,id:e,title:t})},le=async()=>{let e=`cat_${Date.now()}`,n={title:``,createdAt:Date.now()};d&&(n.uid=d.uid),await(0,i.setDoc)((0,i.doc)(t.Ht,c,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.Ht,c,e),{color:n},{merge:!0})},fe=async e=>{G.trim()?await(0,i.setDoc)((0,i.doc)(t.Ht,c,e),{title:G},{merge:!0}):await(0,i.deleteDoc)((0,i.doc)(t.Ht,c,e)),W(null)},pe=(e,t)=>{J({type:`category`,id:e,title:t})},me=async()=>{if(q){H(!0);try{if(q.type===`item`)await(0,i.deleteDoc)((0,i.doc)(t.Ht,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.Ht,o,n.id));await(0,i.deleteDoc)((0,i.doc)(t.Ht,c,q.id))}}catch{}H(!1),J(null)}},he=[...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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen overflow-x-hidden`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4 md:mb-6 flex items-center gap-3`,children:[!f&&a&&(0,s.jsx)(Et,{to:a}),(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(ce,{children:e}),n&&(0,s.jsxs)(`div`,{className:`max-sm:hidden sm: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 min-h-0 pb-16`,children:[f&&(0,s.jsx)(de,{}),(0,s.jsxs)(t.p.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 min-h-[400px] shadow-2xl bg-background relative z-10`,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:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm:p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0 relative z-20`,children:[(0,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-lg sm: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:[S.length,` `,S.length===1?`item`:`items`,` · `,he.length,` `,he.length===1?`category`:`categories`]})]}),_&&(0,s.jsx)(t.c,{variant:y===`secondary`?`secondary`:void 0,onClick:le,className:`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.L,{className:`w-4 h-4`}):v})]}),(0,s.jsx)(`div`,{className:`flex-1 w-full relative z-40 min-h-0 flex flex-col`,children:u?(0,s.jsx)(`div`,{className:`fbos-content-slot w-full flex-1 overflow-y-auto p-4 md:p-6`,children:(0,s.jsx)(u,{config:l,actions:{tasks:S,categories:w,collection:o,catCollection:c,user:d,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.Ht,o,r),n,{merge:!0})},deleteTask:async e=>{C(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Ht,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.Ht,c,e),n,{merge:!0})},deleteCategory:async e=>{T(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Ht,c,e))},openInlineEditor:(e,t)=>Y(e,t)}})}):(0,s.jsxs)(`div`,{id:`board-container`,className:`w-full flex-1 min-h-0 flex flex-row gap-4 md:gap-6 overflow-x-auto p-4 md:p-6 snap-x snap-mandatory styled-scrollbars items-start`,children:[he.map((e,n)=>{let r=S.filter(t=>t.categoryId===e.id);r.sort((e,t)=>(e.order||0)-(t.order||0));let i=Xt.find(t=>t.text===e.color)||Xt.find(e=>e.text===`text-accent`);return i.text,i.bgLight,i.bgHover,(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:n*.1},className:`w-[calc(100vw-80px)] sm:w-[300px] md:w-[320px] shrink-0 flex flex-col max-h-full rounded-3xl p-4 snap-center relative border transition-colors ${Xt.find(t=>t.text===e.color)?.bgCard||`bg-foreground/[0.02]`} ${Xt.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(),fe(e.id)}}),(0,s.jsx)(`input`,{value:G,onChange:e=>K(e.target.value),onBlur:t=>{t.relatedTarget?.closest(`.category-color-picker`)||fe(e.id)},onKeyDown:t=>t.key===`Enter`&&fe(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.v,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Xt.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 ${Xt.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:()=>pe(e.id,e.title),className:`absolute right-0 opacity-100 md:opacity-0 md:group-hover:opacity-100 text-foreground/30 hover:text-red-500 transition-all shrink-0`,children:(0,s.jsx)(t.T,{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 ${z===e.id&&!L?`bg-foreground/5 scale-[1.01] border-dashed border border-accent/20`:``}`,onDragOver:t=>ae(t,e.id),onDragLeave:X,onDrop:t=>oe(t,e.id),children:[(0,s.jsx)(t.m,{children:r.map(n=>O===n.id?(0,s.jsxs)(t.p.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:A.name,onChange:e=>j({...A,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:M.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=>ne(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=>ne(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))}),ee===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.p.div,{draggable:!0,onDragStart:e=>re(e,n.id),onDragOver:e=>ie(e,n.id),onDragLeave:X,onDrop:t=>oe(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-100 md:opacity-0 md: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.R,{className:`w-3.5 h-3.5`})}),(0,s.jsx)(`button`,{onClick:e=>{e.stopPropagation(),se(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.T,{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:[h&&f&&d?(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5 pr-2 border-r border-[var(--panel-border)] border-dashed mr-auto`,children:[d.photoURL?(0,s.jsx)(`img`,{src:d.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:(d.displayName||d.email||`U`)[0].toUpperCase()}),(0,s.jsx)(`span`,{className:`text-[10px] font-bold text-foreground/60 truncate max-w-[80px]`,children:d.displayName||d.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.p.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:A.name,onChange:e=>j({...A,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:M.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=>ne(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=>ne(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))}),ee===`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.L,{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)(be,{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:me,onCancel:()=>J(null),isProcessing:te,confirmText:`Yes, Delete`})]})}function Qt(e){return Array.isArray?Array.isArray(e):ln(e)===`[object Array]`}function $t(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 en(e){return e==null?``:$t(e)}function tn(e){return typeof e==`string`}function nn(e){return typeof e==`number`}function rn(e){return e===!0||e===!1||on(e)&&ln(e)==`[object Boolean]`}function an(e){return typeof e==`object`}function on(e){return an(e)&&e!==null}function sn(e){return e!=null}function cn(e){return!e.trim().length}function ln(e){return e==null?e===void 0?`[object Undefined]`:`[object Null]`:Object.prototype.toString.call(e)}var un=`Incorrect 'index' type`,dn=e=>`Invalid value for key ${e}`,fn=e=>`Pattern length exceeds max of ${e}.`,pn=e=>`Missing ${e} property in key`,mn=e=>`Property 'weight' in key '${e}' must be a positive integer`,hn=Object.prototype.hasOwnProperty,gn=class{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(e=>{let n=_n(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 _n(e){let t=null,n=null,r=null,i=1,a=null;if(tn(e)||Qt(e))r=e,t=vn(e),n=yn(e);else{if(!hn.call(e,`name`))throw Error(pn(`name`));let o=e.name;if(r=o,hn.call(e,`weight`)&&(i=e.weight,i<=0))throw Error(mn(o));t=vn(o),n=yn(o),a=e.getFn}return{path:t,id:n,weight:i,src:r,getFn:a}}function vn(e){return Qt(e)?e:e.split(`.`)}function yn(e){return Qt(e)?e.join(`.`):e}function bn(e,t){let n=[],r=!1,i=(e,t,a,o)=>{if(sn(e))if(!t[a])n.push(o===void 0?e:{v:e,i:o});else{let s=e[t[a]];if(!sn(s))return;if(a===t.length-1&&(tn(s)||nn(s)||rn(s)||typeof s==`bigint`))n.push(o===void 0?en(s):{v:en(s),i:o});else if(Qt(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,tn(t)?t.split(`.`):t,0),r?n:n[0]}var xn={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Sn={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},Cn={location:0,threshold:.6,distance:100},wn={useExtendedSearch:!1,useTokenSearch:!1,getFn:bn,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1},$=Object.freeze({...Sn,...xn,...Cn,...wn}),Tn=/[^ ]+/g;function En(e=1,t=3){let n=new Map,r=10**t;return{get(t){let i=t.match(Tn).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 Dn=class{constructor({getFn:e=$.getFn,fieldNormWeight:t=$.fieldNormWeight}={}){this.norm=En(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,tn(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();tn(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(!sn(e)||cn(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(sn(i)){if(Qt(i)){let e=[];for(let t=0,n=i.length;t<n;t+=1){let n=i[t];if(sn(n)){if(tn(n)){if(!cn(n)){let r={v:n,i:t,n:this.norm.get(n)};e.push(r)}}else if(sn(n.v)){let t=tn(n.v)?n.v:en(n.v);if(!cn(t)){let r={v:t,i:n.i,n:this.norm.get(t)};e.push(r)}}}}n.$[r]=e}else if(tn(i)&&!cn(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 On(e,t,{getFn:n=$.getFn,fieldNormWeight:r=$.fieldNormWeight}={}){let i=new Dn({getFn:n,fieldNormWeight:r});return i.setKeys(e.map(_n)),i.setSources(t),i.create(),i}function kn(e,{getFn:t=$.getFn,fieldNormWeight:n=$.fieldNormWeight}={}){let{keys:r,records:i}=e,a=new Dn({getFn:t,fieldNormWeight:n});return a.setKeys(r),a.setIndexRecords(i),a}function An(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 jn=32;function Mn(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>jn)throw Error(fn(jn));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=An(_,s);e.length?c&&(C.indices=e):C.isMatch=!1}return C}function Nn(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 Pn(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 Fn={ł:`l`,Ł:`L`,đ:`d`,Đ:`D`,ø:`o`,Ø:`O`,ħ:`h`,Ħ:`H`,ŧ:`t`,Ŧ:`T`,ı:`i`,ß:`ss`},In=RegExp(`[`+Object.keys(Fn).join(``)+`]`,`g`),Ln=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(In,e=>Fn[e]):e=>e,Rn=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?Ln(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;let u=(e,t)=>{this.chunks.push({pattern:e,alphabet:Nn(e),startIndex:t})},d=this.pattern.length;if(d>jn){let e=0,t=d%jn,n=d-t;for(;e<n;)u(this.pattern.substr(e,jn),e),e+=jn;if(t){let e=d-jn;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?Ln(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}=Mn(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=Pn(u)),p}},zn=class{constructor(e){this.pattern=e}static isMultiMatch(e){return Bn(e,this.multiRegex)}static isSingleMatch(e){return Bn(e,this.singleRegex)}search(e){return{isMatch:!1,score:1}}};function Bn(e,t){let n=e.match(t);return n?n[1]:null}var Vn=class extends zn{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]}}},Hn=class extends zn{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]}}},Un=class extends zn{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]}}},Wn=class extends zn{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]}}},Gn=class extends zn{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]}}},Kn=class extends zn{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]}}},qn=class extends zn{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 Rn(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)}},Jn=class extends zn{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}}},Yn=[Vn,Jn,Un,Wn,Kn,Gn,Hn,qn],Xn=Yn.length,Zn=`\0`,Qn=`|`;function $n(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 er(e,t={}){return e.replace(/\\\|/g,Zn).split(Qn).map(e=>{let n=$n(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<Xn;){let e=Yn[o],n=e.isMultiMatch(i);n&&(r.push(new e(n,t)),a=!0)}if(!a)for(o=-1;++o<Xn;){let e=Yn[o],n=e.isSingleMatch(i);if(n){r.push(new e(n,t));break}}}return r})}var tr=new Set([qn.type,Jn.type]),nr=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?Ln(e):e,this.pattern=e,this.query=er(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?Ln(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&&(tr.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=Pn(o)),e}}return{isMatch:!1,score:1}}},rr=[];function ir(...e){rr.push(...e)}function ar(e,t){for(let n=0,r=rr.length;n<r;n+=1){let r=rr[n];if(r.condition(e,t))return new r(e,t)}return new Rn(e,t)}var or={AND:`$and`,OR:`$or`},sr={PATH:`$path`,PATTERN:`$val`},cr=e=>!!(e[or.AND]||e[or.OR]),lr=e=>!!e[sr.PATH],ur=e=>!Qt(e)&&an(e)&&!cr(e),dr=e=>({[or.AND]:Object.keys(e).map(t=>({[t]:e[t]}))});function fr(e,t,{auto:n=!0}={}){let r=e=>{if(tn(e)){let r={keyId:null,pattern:e};return n&&(r.searcher=ar(e,t)),r}let i=Object.keys(e),a=lr(e);if(!a&&i.length>1&&!cr(e))return r(dr(e));if(ur(e)){let r=a?e[sr.PATH]:i[0],o=a?e[sr.PATTERN]:e[r];if(!tn(o))throw Error(dn(r));let s={keyId:yn(r),pattern:o};return n&&(s.searcher=ar(o,t)),s}let o={children:[],operator:i[0]};return i.forEach(t=>{let n=e[t];Qt(n)&&n.forEach(e=>{o.children.push(r(e))})}),o};return cr(e)||(e=dr(e)),r(e)}function pr(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 mr(e,{ignoreFieldNorm:t=$.ignoreFieldNorm}){e.forEach(e=>{e.score=pr(e.matches,{ignoreFieldNorm:t})})}var hr=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 gr(e,t){let n=e.matches;t.matches=[],sn(n)&&n.forEach(e=>{if(!sn(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 _r(e,t){t.score=e.score}function vr(e,t,{includeMatches:n=$.includeMatches,includeScore:r=$.includeScore}={}){let i=[];return n&&i.push(gr),r&&i.push(_r),e.map(e=>{let{idx:n}=e,r={item:t[n],refIndex:n};return i.length&&i.forEach(t=>{t(e,r)}),r})}var yr=/\b\w+\b/g;function br({isCaseSensitive:e=!1,ignoreDiacritics:t=!1}={}){return{tokenize(n){return e||(n=n.toLowerCase()),t&&(n=Ln(n)),n.match(yr)||[]}}}function xr(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 Sr(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 Cr(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 wr=class{constructor(e,t,n){this.options={...$,...t},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new gn(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=ar(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 Dn))throw Error(un);if(this._myIndex=t||On(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){let e=br({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});this._invertedIndex=xr(this._myIndex.records,this._myIndex.keys.length,e)}}add(e){if(sn(e)&&(this._docs.push(e),this._myIndex.add(e),this._invertedIndex)){let e=this._myIndex.records[this._myIndex.records.length-1],t=br({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});Sr(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)Cr(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&&Cr(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(tn(e)&&!e.trim()){let e=this._docs.map((e,t)=>({item:e,refIndex:t}));return nn(n)&&n>-1&&(e=e.slice(0,n)),e}let c=nn(n)&&n>0&&tn(e),l;if(c){let t=new hr(n);tn(this._docs[0])?this._searchStringList(e,{heap:t,ignoreFieldNorm:s}):this._searchObjectList(e,{heap:t,ignoreFieldNorm:s}),l=t.extractSorted(o)}else l=tn(e)?tn(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e),mr(l,{ignoreFieldNorm:s}),a&&l.sort(o),nn(n)&&n>-1&&(l=l.slice(0,n));return vr(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(!sn(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=pr(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):a.push(r)}}),a}_searchLogical(e){let t=fr(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===or.AND)return[]}return o},r=this._myIndex.records,i=new Map,a=[];return r.forEach(({$:e,i:r})=>{if(sn(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(!sn(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=pr(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):o.push(r)}}),o}_findMatches({key:e,value:t,searcher:n}){if(!sn(t))return[];let r=[];if(Qt(t))t.forEach(({v:t,i,n:a})=>{if(!sn(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}},Tr=class{static condition(e,t){return t.useTokenSearch}constructor(e,t){this.options=t,this.analyzer=br({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 Rn(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=Pn(t)),o}};wr.version=`7.3.0`,wr.createIndex=On,wr.parseIndex=kn,wr.config=$,wr.match=function(e,t,n){return ar(e,{...$,...n}).searchIn(t)},wr.parseQuery=fr,ir(nr),ir(Tr),wr.use=function(...e){e.forEach(e=>ir(e))};var Er=[{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 Dr({title:e=`Table View`,subtitle:n=`/table`,backUrl:a=`/templates`,tableCollection:o=`pub_table_data`,config:c,customContent:l}){let{user:u}=N(),d=!!c,f=c?.isInternal||c?.isShared;c?.isPrivate&&c?.isAdmin;let p=c?.isAdmin||f,m=d?p:!0,h=!!l,g=c?.showButton!==!1&&!h,_=c?.buttonText||`+`,v=c?.buttonStyle||`secondary`,y=c?.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)(``),[A,j]=(0,r.useState)(!1),[M,P]=(0,r.useState)(null),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)(``),[z,B]=(0,r.useState)(!1),[ee,V]=(0,r.useState)(``),[te,H]=(0,r.useState)(null),[U,W]=(0,r.useState)(null),[G,K]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=o.startsWith(`user_`);if(e&&!u)return;try{let e=localStorage.getItem(`fbos_tables_${o}`);e&&x(JSON.parse(e))}catch{}let n=(0,i.onSnapshot)(e&&u?(0,i.query)((0,i.collection)(t.Ht,o),(0,i.where)(`uid`,`==`,u.uid)):(0,i.collection)(t.Ht,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`],...u?{uid:u.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.Ht,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,u]);let q=b.find(e=>e.id===S)||b[0]||{columns:[],rows:[]},J=async e=>{q.id&&(u&&o.startsWith(`user_`)&&(e.uid=u.uid),await(0,i.setDoc)((0,i.doc)(t.Ht,o,q.id),e,{merge:!0}))},Y=()=>{if(!q.rows||q.rows.length===0)return;let e=q.columns.join(`,`),t=q.rows.map(e=>q.columns.map(t=>`"${e[t]||``}"`).join(`,`)).join(`
4
- `),n=new Blob([`${e}\n${t}`],{type:`text/csv`}),r=window.URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`export_${q.name||`table`}.csv`,i.click(),window.URL.revokeObjectURL(r)},ne=(e,t,n)=>{J({...q,rows:q.rows.map(r=>r.id===e?{...r,[t]:n}:r)})},re=()=>{let e={id:Date.now().toString()};q.columns.forEach(t=>e[t]=``),J({...q,rows:[...q.rows||[],e]})},ie=e=>{J({...q,rows:q.rows.filter(t=>t.id!==e)})},ae=()=>{let e=`Column ${(q.columns?.length||0)+1}`;q.columns?.includes(e)||(J({...q,columns:[...q.columns||[],e]}),setTimeout(()=>{let e=document.getElementById(`table-scroll-container`);e&&e.scrollTo({left:e.scrollWidth,behavior:`smooth`})},100))},X=e=>{let t=(q.columns||[]).filter(t=>t!==e),n=(q.rows||[]).map(t=>{let n={...t};return delete n[e],n}),r={...q.colColors||{}};delete r[e],J({...q,columns:t,rows:n,colColors:r})},oe=async e=>{e.trim()&&q.id&&e!==q.name&&await(0,i.setDoc)((0,i.doc)(t.Ht,o,q.id),{name:e},{merge:!0})},Z=async()=>{j(!0),T(!1);let e=`tbl_${Date.now()}`;await(0,i.setDoc)((0,i.doc)(t.Ht,o,e),{name:`Unnamed Table`,columns:[`Column 1`,`Column 2`,`Column 3`],...u?{uid:u.uid}:{},rows:[]}),setTimeout(()=>{C(e),j(!1)},600)},se=e=>{let t=ee.trim();if(t&&t!==e&&!q.columns?.includes(t)){let n=q.columns.map(n=>n===e?t:n),r=(q.rows||[]).map(n=>{let r={...n};return r[t]=r[e]||``,delete r[e],r}),i={...q.colColors||{}};i[e]&&(i[t]=i[e],delete i[e]),J({...q,columns:n,rows:r,colColors:i})}I(null)},le=q.rows||[];return L.trim()!==``&&(le=new wr(le.map(e=>({...e,_creatorMatch:`Guest`})),{keys:(q.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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4 md:mb-6 flex items-center gap-3`,children:[!d&&a&&(0,s.jsx)(Et,{to:a}),(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(ce,{children:e}),n&&(0,s.jsxs)(`div`,{className:`max-sm:hidden sm: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 min-h-0 pb-16`,children:[d&&(0,s.jsx)(de,{}),(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative z-10 flex flex-col flex-1 min-h-[400px]`,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 items-center justify-between bg-foreground/[0.01] gap-3 sm:gap-4`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col min-w-0 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:q.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-[38vw] sm:max-w-[200px]`,onClick:()=>D(!0),title:`Click to rename table`,children:q.name||`Unnamed Table`}),(0,s.jsx)(t.m,{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.p.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:Z,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.L,{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.wt,{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:[(q.rows||[]).length,` Records`]})]}),(0,s.jsx)(`div`,{className:`relative shrink-0 ${z?`flex-1 min-w-[130px] max-w-[300px]`:``}`,children:z?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.P,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-foreground/40`}),(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,"aria-label":`Search records`,placeholder:`Search records...`,value:L,onChange:e=>R(e.target.value),onBlur:()=>{L.trim()||B(!1)},onKeyDown:e=>{e.key===`Escape`&&(R(``),B(!1))},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)(`button`,{type:`button`,onClick:()=>B(!0),"aria-label":`Search records`,title:`Search records`,className:`w-10 h-10 flex items-center justify-center rounded-xl border border-[var(--panel-border)] text-foreground/50 hover:text-accent hover:bg-foreground/5 transition-colors`,children:(0,s.jsx)(t.P,{className:`w-4 h-4`})})}),(0,s.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[y&&(0,s.jsx)(t.c,{variant:`secondary`,onClick:Y,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.dt,{className:`w-4 h-4`})}),g&&(0,s.jsx)(t.c,{variant:v===`primary`?void 0:`secondary`,onClick:re,className:`px-3 py-2.5 font-bold rounded-xl border border-[var(--panel-border)] shadow-sm flex items-center gap-2 whitespace-nowrap`,children:_===`+`?(0,s.jsx)(t.L,{className:`w-4 h-4`}):_})]})]}),(0,s.jsx)(`div`,{id:`table-scroll-container`,className:`overflow-auto w-full flex-1 min-h-[300px] relative styled-scrollbars`,children:l?(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)(l,{config:c,actions:{tables:b,activeTable:q,collection:o,user:u,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.Ht,o,e),n,{merge:!0})},deleteTable:async e=>{x(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Ht,o,e))},updateCell:(e,t,n)=>ne(e,t,n),addRow:()=>re(),addColumn:()=>ae()}})}):(0,s.jsx)(t.m,{mode:`wait`,children:A?(0,s.jsxs)(t.p.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.p.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 ${q.headerColor?Er.find(e=>e.text===q.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 ${m?``:`hidden`}`,children:`Creator`}),(q.columns||[]).map((e,n)=>{let r=(q.colColors||{})[e],i=(q.colorTimestamps||{})[`col_${e}`]||0;q.headerColor;let a=(q.colorTimestamps||{}).header||0,o=`bg-transparent`,c=`text-foreground/50`;if(r&&r!==`none`&&i>=a){let e=Er.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),V(t.currentTarget.textContent||``),(t.currentTarget.textContent||``).trim()!==``&&se(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),V(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:()=>W(U===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.B,{className:`w-4 h-4`})}),(q.columns||[]).length>1&&(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),X(e)},className:`p-1.5 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500/10 text-foreground/30 hover:text-red-500`,title:`Delete column`,children:(0,s.jsx)(t.T,{className:`w-3.5 h-3.5`})}),U===e&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>W(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={...q.colColors||{},[e]:`none`},r={...q.colorTimestamps||{},[`col_${e}`]:Date.now()};J({...q,colColors:n,colorTimestamps:r}),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:`Remove Color`,children:(0,s.jsx)(t.v,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Er.map(t=>(0,s.jsx)(`button`,{onClick:n=>{n.preventDefault(),n.stopPropagation();let r={...q.colColors||{},[e]:t.text},i={...q.colorTimestamps||{},[`col_${e}`]:Date.now()};J({...q,colColors:r,colorTimestamps:i}),W(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:()=>K(!G),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${q.headerColor?Er.find(e=>e.text===q.headerColor)?.text:`text-foreground/30`}`,children:(0,s.jsx)(t.B,{className:`w-4 h-4`})}),G&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>K(!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:()=>{J({...q,headerColor:``}),K(!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.v,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Er.map(e=>(0,s.jsx)(`button`,{onClick:()=>{let t={...q.colorTimestamps||{},header:Date.now()};J({...q,headerColor:e.text,colorTimestamps:t}),K(!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:ae,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.L,{className:`w-4 h-4`})})]})})]})}),(0,s.jsxs)(`tbody`,{children:[le.map((e,n)=>{let r=n%2==1,i=(q.rowColors||{})[e.id],a=i?r?Er.find(e=>e.text===i)?.bgAlt:Er.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} ${m?``:`hidden`}`,children:(0,s.jsx)(`div`,{className:`flex items-center gap-2`,children:d&&u?(0,s.jsxs)(s.Fragment,{children:[u.photoURL?(0,s.jsx)(`img`,{src:u.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:(u.displayName||u.email||`U`)[0].toUpperCase()}),(0,s.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/80 tracking-tight shrink-0`,children:u.displayName||u.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`})]})})}),(q.columns||[]).map(t=>{let i=M?.id===e.id&&M?.field===t,a=(q.colColors||{})[t],o=(q.colorTimestamps||{})[`col_${t}`]||0,c=(q.rowColors||{})[e.id],l=(q.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?Er.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=>ne(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-100 md:opacity-20 md:group-hover:opacity-100 transition-opacity relative`,children:[(0,s.jsx)(`button`,{onClick:()=>H(te===e.id?null:e.id),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${i?Er.find(e=>e.text===i)?.text:`text-foreground/40`}`,children:(0,s.jsx)(t.B,{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:()=>H(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={...q.rowColors||{},[e.id]:`none`},r={...q.colorTimestamps||{},[`row_${e.id}`]:Date.now()};J({...q,rowColors: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 Row Color`,children:(0,s.jsx)(t.v,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Er.map(t=>(0,s.jsx)(`button`,{onClick:()=>{let n={...q.colorTimestamps||{},[`row_${e.id}`]:Date.now()};J({...q,rowColors:{...q.rowColors||{},[e.id]:t.text},colorTimestamps:n}),H(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:()=>ie(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.T,{className:`w-4 h-4`})})]})})]},e.id||`row_${n}`)}),le.length===0&&(0,s.jsx)(`tr`,{children:(0,s.jsxs)(`td`,{colSpan:(q.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 `,q.name||`this table`,`.`]})}),(0,s.jsx)(`tr`,{children:(0,s.jsx)(`td`,{colSpan:(q.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:re,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.L,{className:`w-4 h-4`})})})})})]})]},`table`)})})]})]})]})}var Or=[{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`}],kr={dateStr:``,title:``,description:``,time:`12:00`,duration:`60`,color:``,guestEmail:``,customFields:{}};function Ar({title:e=`Calendar View`,subtitle:n=`/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)(kr),[R,z]=(0,r.useState)(new Date),[B,ee]=(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``}},ne=e=>{try{sessionStorage.setItem(`cal_guest_email`,e)}catch{}};(0,r.useEffect)(()=>(0,a.onAuthStateChanged)(t.Vt,async e=>{if(ee(e),e&&x===`admin_only`)try{let n=await(0,i.getDoc)((0,i.doc)(t.Ht,`user_profiles`,e.uid));n.exists()&&te(n.data())}catch{}U(!0)}),[x]),(0,r.useEffect)(()=>{if(!H)return;if(x!==`public`&&!B){T([]);return}try{let e=localStorage.getItem(`fbos_cal_${l}`);e&&T(JSON.parse(e))}catch{}let e=(0,i.onSnapshot)(x===`user`&&B?(0,i.query)((0,i.collection)(t.Ht,l),(0,i.where)(`uid`,`==`,B.uid)):(0,i.collection)(t.Ht,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,B?.uid,H]);let re=e=>!!B&&B.uid===e.uid,ie=e=>x===`public`?!1:x===`user`?!!B:re(e),ae=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`},oe=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`)}`},se=e=>{let t=e.getTimezoneOffset()*6e4;return new Date(e.getTime()-t).toISOString().split(`T`)[0]},le=()=>se(new Date),ue=new Date(R.getFullYear(),R.getMonth(),1),fe=new Date(R.getFullYear(),R.getMonth()+1,0),pe=ue.getDay(),me=fe.getDate(),he=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],ge=Array.from({length:42},(e,t)=>{let n=t-pe+1,r=new Date(R.getFullYear(),R.getMonth(),n);return{day:r.getDate(),dateStr:se(r),isCurrentMonth:n>0&&n<=me}}),_e=()=>z(S===`month`?new Date(R.getFullYear(),R.getMonth()-1,1):new Date(R.getFullYear(),R.getMonth(),R.getDate()-1)),ve=()=>z(S===`month`?new Date(R.getFullYear(),R.getMonth()+1,1):new Date(R.getFullYear(),R.getMonth(),R.getDate()+1)),ye=e=>{if(x!==`public`&&!B)return;let t=new Date;t.setDate(t.getDate()+1);let n=new Date().getHours().toString().padStart(2,`0`);L({...kr,dateStr:e||se(t),time:`${n}:00`,guestEmail:x===`public`?Y():``,customFields:{}}),D(!0)},xe=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)},Se=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,ne(t)}else x===`user`||x===`internal`?(e.uid=B?.uid,e.creatorEmail=B?.email||``,e.creatorName=B?.displayName||``,e.creatorAvatar=B?.photoURL||``):x===`admin_only`&&(e.uid=B?.uid,e.creatorEmail=V?.email||B?.email||``,e.creatorName=V?.displayName||V?.name||``,e.creatorAvatar=V?.avatar||V?.avatarUrl||B?.photoURL||``);I.id?(await(0,i.setDoc)((0,i.doc)(t.Ht,l,I.id),e,{merge:!0}),O?.id===I.id&&k({...O,...e})):await(0,i.setDoc)((0,i.doc)(t.Ht,l,`ev_${Date.now()}`),e,{merge:!0}),D(!1)}catch(e){console.error(e)}j(!1)}},Ce=async()=>{if(P){N(!0);try{await(0,i.deleteDoc)((0,i.doc)(t.Ht,l,P.id)),O?.id===P.id&&k(null),F(null),D(!1)}catch{}N(!1)}},we=e=>{if(x===`user`||!e.creatorEmail&&!e.creatorName)return null;let t=(e.creatorName||e.creatorEmail||`?`).charAt(0).toUpperCase(),n=Or.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})]})]})},Te=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`&&!B)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.U,{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.K,{className:`w-8 h-8 animate-spin text-accent`})});let Ee=!!f,De=(x===`public`||!!B)&&m&&!Ee,Q=()=>(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm: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.p.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`}),_&&!Ee&&(0,s.jsx)(t.p.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.X,{className:`w-4 h-4`}):(0,s.jsx)(t.Dt,{className:`w-4 h-4`})}),De&&(0,s.jsx)(t.p.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>ye(),title:`Add event`,"aria-label":`Add event`,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.L,{className:`w-4 h-4`}):(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:h})})]})]}),Oe=()=>(0,s.jsxs)(`div`,{className:`p-4 md:p-6 border-b border-[var(--panel-border)]/50 flex flex-wrap items-center justify-between gap-x-3 gap-y-2 bg-foreground/[0.01]`,children:[(0,s.jsx)(`h3`,{className:`text-lg md:text-xl font-extrabold tracking-tight ml-2 min-w-0`,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:()=>z(new Date),className:`px-3 md:px-4 py-2 text-[13px] font-bold border border-[var(--panel-border)] rounded-xl mr-1 md:mr-2 hover:bg-foreground/5 transition-colors`,children:`Today`}),(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.Ct,{className:`w-5 h-5`})}),(0,s.jsx)(`button`,{onClick:ve,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.St,{className:`w-5 h-5`})})]})]}),ke=()=>(0,s.jsxs)(s.Fragment,{children:[Oe(),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:B,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.Ht,l,n),e,{merge:!0})},deleteEvent:async e=>{T(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Ht,l,e))},openAddModal:e=>ye(e),openEditModal:e=>xe(e),setViewingEvent:e=>k(e),currentDate:R,setCurrentDate:z,goToPrev:_e,goToNext:ve,goToToday:()=>z(new Date)}})}):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:he.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:ge.map((e,n)=>{let r=e.dateStr===le(),i=w.filter(t=>t.dateStr===e.dateStr);return(0,s.jsxs)(`div`,{onClick:()=>e.isCurrentMonth&&De&&ye(e.dateStr),className:`min-h-[140px] p-2 bg-[var(--panel-bg)] flex flex-col relative group
5
- ${e.isCurrentMonth?De?`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=Or.find(t=>t.text===e.color),r=ie(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:ae(e.time)}),r&&(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),xe(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.R,{className:`w-3 h-3`})})]},e.id)})})]},n)})}),(0,s.jsx)(`style`,{children:`
3
+ `).filter(e=>e.trim()).map((e,t)=>(0,s.jsx)(`p`,{className:`min-w-0`,children:(0,s.jsx)(et,{text:e})},t))}):(0,s.jsxs)(`p`,{className:`text-foreground/80`,children:[`“`,(0,s.jsx)(et,{text:i}),`”`]})})]})}var nt=`w-11 h-11 shrink-0 rounded-[var(--input-radius,0.75rem)] overflow-hidden border border-[var(--panel-border)]`,rt=e=>{try{return(decodeURIComponent(new URL(e).pathname).split(`/`).pop()||``).replace(/^\d{10,}_/,``)||`Your picture`}catch{return`Your picture`}};function it({label:e,hint:n,value:i,onChange:a,accept:o=`image/*`,action:c,clearable:l=!0,tips:u,onBusyChange:d}){let{user:f}=N(),[p,m]=(0,r.useState)(!1),[h,g]=(0,r.useState)(``),[_,v]=(0,r.useState)(!1),[y,b]=(0,r.useState)(!1),x=(0,s.jsx)(`input`,{type:`file`,accept:o,"aria-label":i?`Replace ${e}`:`Upload ${e}`,disabled:p,onChange:async e=>{let n=e.target.files?.[0];if(e.target.value=``,!(!n||p)){m(!0),d?.(!0),g(``);try{a(await t.a(n,f))}catch(e){g(t.i(e))}m(!1),d?.(!1),b(!1)}},className:`sr-only`});return(0,s.jsxs)(De,{label:e,hint:n,error:h,action:c,children:[i&&!p?(0,s.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,s.jsx)(`div`,{className:`${Se} min-w-0`,children:(0,s.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[14px] text-foreground/60 select-none`,children:rt(i)})}),(0,s.jsxs)(`div`,{className:`${nt} relative group/pic`,children:[(0,s.jsx)(`button`,{type:`button`,onClick:()=>b(e=>!e),"aria-label":`Change ${e}`,"aria-expanded":y,className:`block w-full h-full cursor-pointer`,children:(0,s.jsx)(`img`,{src:i,alt:e,className:`w-full h-full object-cover`})}),(0,s.jsxs)(`div`,{className:`absolute inset-0 flex items-center justify-center gap-1 bg-background/85 transition-opacity duration-200 ${y?`opacity-100`:`opacity-0 pointer-events-none group-hover/pic:opacity-100 group-hover/pic:pointer-events-auto focus-within:opacity-100 focus-within:pointer-events-auto`}`,children:[(0,s.jsxs)(`label`,{title:`Replace ${e}`,className:`w-6 h-6 rounded-md flex items-center justify-center text-foreground/60 hover:text-accent hover:bg-foreground/10 transition-colors cursor-pointer`,children:[(0,s.jsx)(t.ht,{className:`w-3.5 h-3.5`}),x]}),l&&(0,s.jsx)(`button`,{type:`button`,onClick:()=>{g(``),b(!1),a(``)},"aria-label":`Remove ${e}`,title:`Remove ${e}`,className:`w-6 h-6 rounded-md flex items-center justify-center text-foreground/60 hover:text-red-500 hover:bg-red-500/10 transition-colors cursor-pointer`,children:(0,s.jsx)(t.v,{className:`w-3.5 h-3.5`})})]})]})]}):(0,s.jsxs)(`label`,{title:`Upload ${e}`,className:`group/up flex items-center gap-2 ${p?`pointer-events-none`:`cursor-pointer`}`,children:[(0,s.jsx)(`span`,{className:`${Se} select-none text-[14px] ${p?`text-foreground/50`:`text-foreground/35`} group-hover/up:border-accent/40 group-focus-within/up:border-accent`,children:p?`Uploading your picture…`:`Upload a picture`}),(0,s.jsx)(`span`,{"aria-hidden":!0,className:`${nt} flex items-center justify-center bg-[var(--panel-bg)] text-foreground/40 group-hover/up:text-accent group-hover/up:border-accent/40 transition-colors`,children:p?(0,s.jsx)(t.K,{className:`w-4 h-4 animate-spin text-accent`}):(0,s.jsx)(t.ht,{className:`w-4 h-4`})}),x]}),!!u?.length&&(0,s.jsxs)(`div`,{className:`mt-2 px-1`,children:[(0,s.jsxs)(`button`,{type:`button`,onClick:()=>v(e=>!e),"aria-expanded":_,className:`inline-flex items-center gap-1 text-[11.5px] font-semibold text-foreground/40 hover:text-foreground/70 transition-colors cursor-pointer`,children:[(0,s.jsx)(t.St,{className:`w-3 h-3 shrink-0 transition-transform duration-200 ${_?`rotate-90`:``}`}),`Which picture should I upload?`]}),_&&(0,s.jsx)(`ul`,{className:`flex flex-col gap-1 mt-1.5 ml-4`,children:u.map(e=>(0,s.jsxs)(`li`,{className:`text-[11.5px] text-foreground/40 font-medium leading-snug flex gap-1.5`,children:[(0,s.jsx)(`span`,{"aria-hidden":!0,className:`text-accent/60`,children:`•`}),e]},e))})]})]})}var at=[`A wide picture sits best across a page — about 1600 by 900.`,`JPG or PNG. Any size — a big photo is shrunk for you as it uploads, so the page still opens quickly.`,`Your own photo beats a stock one. People can tell.`,`No writing baked into the picture — your assistant sets the words, so they stay readable on a phone.`],ot=[`A wide picture, not a square one — it sits in a short bar about 40px tall.`,`PNG with a see-through background looks right on both the light and the dark theme.`],st=[`A square picture — 64 by 64 is plenty.`,`One shape or one letter. A whole logo turns to mush at this size.`],ct=e=>typeof e==`string`&&/^https?:\/\/\S+$/.test(e.trim())&&RegExp(`(/|%2F)pub_form_uploads(/|%2F)`,`i`).test(e),lt={anyone:{collectionName:`user_submissions`,chip:`Anyone`,filterLabel:`From anyone`},signedIn:{collectionName:`user_requests`,chip:`Signed-in user`,filterLabel:`From signed-in users`}},ut=[`id`,`source`,`uid`,`submittedAt`,`avatarUrl`,`isArchived`,`name`,`full_name`,`email`,`contactEmail`,`topic`],dt=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},ft=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)},pt=e=>{if(!e)return`now`;let t=e.toDate?e.toDate():new Date(e),n=new Date;return t.toDateString()===n.toDateString()?new Intl.DateTimeFormat(`en-US`,{hour:`numeric`,minute:`numeric`}).format(t):new Intl.DateTimeFormat(`en-US`,t.getFullYear()===n.getFullYear()?{month:`short`,day:`numeric`}:{month:`short`,year:`numeric`}).format(t)},mt=e=>{let t=new Date(e);return new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime()},ht=e=>{let t=dt(e);if(!t)return`Older`;let n=Math.round((mt(Date.now())-mt(t))/864e5);return n<=0?`Today`:n===1?`Yesterday`:n<7?`This week`:n<30?`This month`:`Older`},gt=e=>e.reduce((e,t)=>{let n=ht(t),r=e[e.length-1];return r&&r.label===n?r.items.push(t):e.push({label:n,items:[t]}),e},[]);function _t({label:e}){return(0,s.jsxs)(`div`,{className:`md:hidden flex items-center gap-3 pt-1 first:pt-0 select-none`,children:[(0,s.jsx)(`span`,{className:`text-[10.5px] font-bold uppercase tracking-[0.18em] text-foreground/35 shrink-0`,children:e}),(0,s.jsx)(`span`,{className:`h-px flex-1 bg-[var(--panel-border)]/60`})]})}var vt=e=>e.submitterName||e.name||e.full_name||`Anonymous`,yt=e=>e.contactEmail||e.email||`No email provided`;function bt(e){let[n,a]=(0,r.useState)([]),[o,s]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{let n=!1,r=lt[e].collectionName,o=(0,i.onSnapshot)((0,i.query)((0,i.collection)(t.Ht,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.Ht,`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 xt({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:lt[e].chip})}function St({item:e,isExpanded:n,onToggle:r,onArchive:i,onDelete:a,busy:o,dimmed:l}){let u=vt(e),d=e.avatarUrl||e.submitterAvatar,f=!!e.uid&&e.uid!==`guest`,p=Object.entries(e).filter(([e])=>!ut.includes(e)&&!e.toLowerCase().startsWith(`submitter`)&&e.toLowerCase()!==`formid`),m=e.topic?[[`topic`,e.topic],...p]:p;return(0,s.jsxs)(t.p.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-3.5 md:px-5`,children:[(0,s.jsxs)(`button`,{type:`button`,onClick:r,"aria-expanded":n,className:`flex items-center gap-3 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-9 h-9 rounded-full object-cover border border-[var(--panel-border)] shadow-sm`}):(0,s.jsx)(`div`,{className:`w-9 h-9 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.jsx)(`span`,{className:`font-bold text-[14px] text-foreground truncate`,children:u}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/50 truncate flex items-center gap-1.5 font-medium mt-0.5`,children:[(0,s.jsx)(t.U,{className:`w-3.5 h-3.5 shrink-0`}),` `,yt(e)]})]})]}),(0,s.jsx)(`button`,{type:`button`,onClick:r,tabIndex:-1,"aria-hidden":`true`,className:`md:hidden w-8 h-8 -mr-1 flex items-center justify-center rounded-lg text-foreground/30 hover:text-accent hover:bg-foreground/5 transition-colors shrink-0 cursor-pointer`,children:(0,s.jsx)(t.wt,{className:`w-4 h-4 transition-transform duration-300 ${n?`rotate-180`:``}`})}),(0,s.jsxs)(`div`,{className:`max-md:hidden md:flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/35 tabular-nums whitespace-nowrap mr-1`,children:pt(e.submittedAt)}),(0,s.jsx)(Q,{icon:e.isArchived?t.At:t.Pt,onClick:i,busy:o,children:e.isArchived?`Restore`:`Archive`}),(0,s.jsx)(Q,{icon:t.E,tone:`danger`,onClick:a,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.wt,{className:`w-4 h-4`})})]})]}),(0,s.jsx)(t.m,{children:n&&(0,s.jsx)(t.p.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:`px-3.5 md:px-5 py-4 border-t border-[var(--panel-border)]/40`,children:[(0,s.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-3`,children:[(0,s.jsx)(xt,{source:e.source}),e.formId&&(0,s.jsx)(`span`,{className:`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.jsx)(`span`,{className:`text-[11px] font-medium text-foreground/40 shrink-0`,children:ft(e.submittedAt)})]}),m.length>0?(0,s.jsx)(`div`,{className:`rounded-xl border border-[var(--panel-border)]/60 bg-foreground/[0.02] divide-y divide-[var(--panel-border)]/40 overflow-hidden`,children:m.map(([e,n])=>(0,s.jsxs)(`div`,{className:`px-3.5 md:px-4 py-3`,children:[(0,s.jsx)(`span`,{className:`block text-[11px] font-bold uppercase tracking-widest text-foreground/40 mb-1`,children:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}),ct(n)?(0,s.jsxs)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-2 text-[14px] font-semibold text-accent hover:underline break-all [overflow-wrap:anywhere]`,children:[(0,s.jsx)(t.z,{className:`w-4 h-4 shrink-0`}),t.r(n)]}):(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/85 leading-relaxed whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:typeof n==`boolean`?n?`Yes`:`No`:e.toLowerCase()===`budget`&&n?`$${n}`:String(n??``)||`No data provided`})]},e))}):(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/40 font-medium`,children:`This form only asked for a name and email.`}),f&&(0,s.jsx)(c.Link,{to:`/users/${e.uid}`,className:`inline-flex mt-3 text-[12.5px] font-bold text-accent hover:underline`,children:`Open this person’s profile`}),(0,s.jsxs)(`div`,{className:`md:hidden flex items-center justify-end gap-2 mt-4`,children:[(0,s.jsx)(Q,{icon:e.isArchived?t.At:t.Pt,onClick:i,busy:o,children:e.isArchived?`Restore`:`Archive`}),(0,s.jsx)(Q,{icon:t.E,tone:`danger`,onClick:a,children:`Delete`})]})]})})})]})}function Ct(){let e=bt(`anyone`),n=bt(`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)=>dt(t)-dt(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.Ht,lt[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.Ht,lt[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`,short:`All`},{key:`anyone`,label:lt.anyone.filterLabel,short:`Anyone`},{key:`signedIn`,label:lt.signedIn.filterLabel,short:`Signed in`}];return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,s.jsx)(ce,{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)(de,{})}),(0,s.jsxs)(`div`,{className:`w-full flex-1 flex flex-col glass-panel rounded-2xl md:rounded-3xl p-3 sm: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.tt,{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.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.jsxs)(`button`,{type:`button`,onClick:()=>o(e.key),"aria-pressed":a===e.key,"aria-label":e.label,className:`h-8 md:h-9 px-3 md:px-4 rounded-full text-[12px] md: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:[(0,s.jsx)(`span`,{className:`sm:hidden`,children:e.short}),(0,s.jsx)(`span`,{className:`max-sm:hidden`,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.m,{children:gt(x).map(e=>(0,s.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,s.jsx)(_t,{label:e.label}),e.items.map(e=>(0,s.jsx)(St,{item:e,isExpanded:c===C(e),onToggle:()=>w(e),onArchive:()=>T(e),onDelete:()=>h(e),busy:f===C(e)},C(e)))]},e.label))}),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.wt,{className:`w-3.5 h-3.5 transition-transform duration-300 ${u?`rotate-180`:``}`})]})}),(0,s.jsx)(t.m,{children:u&&(0,s.jsx)(t.p.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:gt(S).map(e=>(0,s.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,s.jsx)(_t,{label:e.label}),e.items.map(e=>(0,s.jsx)(St,{item:e,isExpanded:c===C(e),onToggle:()=>w(e),onArchive:()=>T(e),onDelete:()=>h(e),busy:f===C(e),dimmed:!0},C(e)))]},e.label))})})})]})]})})]})]}),(0,s.jsx)(ve,{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 wt=`inline-flex items-center justify-center w-9 h-9 rounded-full border border-[var(--panel-border)] text-foreground/50 hover:text-accent hover:bg-foreground/5 transition-colors shrink-0 cursor-pointer`,Tt=({to:e})=>e?(0,s.jsx)(c.Link,{to:e,"aria-label":`Go back`,title:`Go back`,className:wt,children:(0,s.jsx)(t.Mt,{className:`w-4 h-4`})}):(0,s.jsx)(`button`,{type:`button`,onClick:()=>window.history.back(),"aria-label":`Go back`,title:`Go back`,className:wt,children:(0,s.jsx)(t.Mt,{className:`w-4 h-4`})}),Et=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 Dt({title:e=`Drive`,subtitle:n=`/drive`,backUrl:a=`/templates`,filesCollection:u=`pub_files`,config:d,customContent:f,footer:p}){let{user:m,userRole:h}=N(),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),[A,j]=(0,r.useState)(!1),[M,P]=(0,r.useState)(null),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)({}),[z,B]=(0,r.useState)(!1),[ee,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.Ht,u),(0,i.where)(`uid`,`==`,m.uid)):(0,i.query)((0,i.collection)(t.Ht,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 ne=e=>!!m&&(e.uid===m.uid||_),re=e=>{V(e),H(e.name),K(``),B(!0)},ie=()=>{V(null),K(``),B(!0)},ae=async e=>{if(e.preventDefault(),!(!ee||!te.trim()||!m)){W(!0),K(``);try{let e=await t.o(ee),n=`${v}/${`${Date.now()}_${e.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,r=(0,o.ref)(t.Wt,n);await(0,o.uploadBytes)(r,e,{customMetadata:{ownerId:m.uid}});let a=await(0,o.getDownloadURL)(r);await(0,i.addDoc)((0,i.collection)(t.Ht,u),{fileName:te.trim(),fileType:e.type||`unknown`,fileSize:e.size,downloadURL:a,storagePath:n,uid:m.uid,uploaderEmail:m.email||``,createdAt:(0,i.serverTimestamp)()}),B(!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)}},X=async()=>{if(O){j(!0);try{await Promise.all([(0,o.deleteObject)((0,o.ref)(t.Wt,O.storagePath||O.downloadURL)).catch(e=>console.warn(`Storage object missing:`,e)),(0,i.deleteDoc)((0,i.doc)(t.Ht,u,O._id))]),k(null)}catch(e){console.error(`Delete failed:`,e)}j(!1)}},oe=async()=>{if(!M||!M.name.trim()){P(null);return}try{await(0,i.updateDoc)((0,i.doc)(t.Ht,u,M.id),{fileName:M.name.trim()})}catch(e){console.error(`Rename failed:`,e)}P(null)},Z=(e,t)=>{navigator.clipboard.writeText(e),I(t),setTimeout(()=>I(null),2e3)},se=(e,n=`row`)=>{let r=n===`card`?`w-16 h-16`:`w-10 h-10`,i=n===`card`?`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.b,{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.ot,{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.Ft,{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.mt,{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.at,{className:i})})};return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 flex flex-col 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]&&re(e.dataTransfer.files[0])},children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4 md:mb-6 flex items-center gap-3`,children:[!g&&(0,s.jsx)(Tt,{to:a}),(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(ce,{children:e}),(0,s.jsxs)(`div`,{className:`max-sm:hidden sm: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)(de,{})}),(0,s.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl md:rounded-3xl overflow-hidden flex-1 shadow-2xl min-h-[420px] md:min-h-[520px] mb-16 bg-background flex flex-col`,children:[(0,s.jsxs)(`div`,{className:`p-4 md:p-8 flex items-center justify-between gap-3 md:gap-6 border-b border-[var(--panel-border)]/50 bg-background/50`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-lg md:text-2xl font-extrabold text-foreground tracking-tight`,children:`Files`}),(0,s.jsx)(`p`,{className:`max-sm:hidden text-[12px] md:text-[13px] mt-1 md: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.`})]}),!f&&(m?(0,s.jsxs)(t.c,{onClick:ie,title:`Add file`,className:`flex items-center justify-center gap-2 w-9 h-9 p-0 sm:w-auto sm:h-auto sm:px-5 sm:py-2.5 rounded-xl text-[13px] font-bold shadow-md shrink-0`,children:[(0,s.jsx)(t.L,{className:`w-4 h-4`}),` `,(0,s.jsx)(`span`,{className:`max-sm:hidden`,children:`Add file`})]}):(0,s.jsxs)(c.Link,{to:`/login`,title:`Sign in to add a file`,className:`btn-primary flex items-center justify-center gap-2 w-9 h-9 p-0 sm:w-auto sm:h-auto sm:px-5 sm:py-2.5 rounded-xl text-[13px] font-bold shadow-md shrink-0`,children:[(0,s.jsx)(t.L,{className:`w-4 h-4`}),` `,(0,s.jsx)(`span`,{className:`max-sm:hidden`,children:`Add file`})]}))]}),f?(0,s.jsx)(`div`,{className:`fbos-content-slot p-4 md:p-8 flex-1`,children:(0,s.jsx)(f,{files:b,loading:S,user:m,uploadFile:re,deleteFile:k,openUploadModal:ie,config:d})}):(0,s.jsxs)(`div`,{className:`p-4 sm: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.K,{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-3 sm: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 group-focus-within: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.dt,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),Z(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.Tt,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.J,{className:`w-4 h-4`})}),ne(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.R,{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.E,{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.K,{className:`w-5 h-5 text-accent animate-spin`})}),(0,s.jsx)(`img`,{src:e.downloadURL,alt:``,loading:`lazy`,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}))})]}):se(e.fileType,`card`)}),(0,s.jsxs)(`div`,{className:`p-3 flex flex-col justify-center flex-1 min-w-0`,onClick:()=>!M&&T(e),children:[M?.id===e._id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:M.name,onChange:e=>P({...M,name:e.target.value}),onBlur:oe,onKeyDown:e=>{e.key===`Enter`&&oe(),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:Et(e.fileSize)})]})]},e._id))}):!S&&(0,s.jsxs)(`div`,{onClick:()=>m&&B(!0),className:`min-h-[320px] flex flex-col items-center justify-center text-center cursor-pointer group`,children:[(0,s.jsx)(t.ht,{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.m,{children:z&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.div,{onClick:()=>!U&&B(!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.p.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-4 md: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&&B(!1),className:`text-foreground/40 hover:text-foreground transition-colors`,children:(0,s.jsx)(t.v,{className:`w-5 h-5`})})]}),ee?(0,s.jsxs)(`form`,{onSubmit:ae,className:`p-4 md:p-6 flex flex-col gap-5 md: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:[se(ee.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:ee.name}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold uppercase tracking-wider mt-1`,children:Et(ee.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.E,{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.c,{type:`submit`,isLoading:U,className:`w-full py-4 rounded-xl text-[14px] font-bold shadow-lg`,children:U?`Uploading…`:`Upload`})]}):(0,s.jsx)(`div`,{className:`p-4 md:p-6`,children:(0,s.jsxs)(`label`,{onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),e.dataTransfer.files?.[0]&&re(e.dataTransfer.files[0])},className:`group flex flex-col items-center justify-center gap-1.5 px-6 py-12 rounded-2xl border-2 border-dashed border-[var(--panel-border)] bg-foreground/[0.015] hover:border-accent/50 hover:bg-accent/[0.03] cursor-pointer text-center transition-all`,children:[(0,s.jsx)(`span`,{className:`w-14 h-14 rounded-full bg-accent/10 text-accent flex items-center justify-center mb-2 group-hover:scale-105 transition-transform`,children:(0,s.jsx)(t.ht,{className:`w-6 h-6`})}),(0,s.jsxs)(`p`,{className:`text-[15px] font-bold text-foreground`,children:[(0,s.jsx)(`span`,{className:`text-accent`,children:`Click to upload`}),` or drag a file in`]}),(0,s.jsx)(`p`,{className:`text-[12.5px] text-foreground/45 font-medium`,children:`Pictures, documents, anything`}),(0,s.jsx)(`input`,{type:`file`,ref:Y,"aria-label":`Upload a file`,onChange:e=>e.target.files?.[0]&&re(e.target.files[0]),className:`hidden`})]})})]})]})}),typeof window<`u`&&(0,l.createPortal)((0,s.jsx)(t.m,{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.p.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-3 right-3 md:top-6 md:right-6 z-[160] w-10 h-10 md:w-12 md: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.v,{className:`w-5 h-5`})}),(0,s.jsxs)(t.p.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-3.5 md: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-3 md:pr-4`,children:[(0,s.jsx)(`span`,{className:`text-[15px] md:text-xl font-extrabold text-foreground truncate`,children:w.fileName}),(0,s.jsxs)(`span`,{className:`text-[10.5px] md:text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-0.5 md:mt-1 truncate`,children:[w.fileType,` • `,Et(w.fileSize)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5 md:gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>Z(w.downloadURL,w._id),className:`p-2 md: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.Tt,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.J,{className:`w-4 h-4`})}),ne(w)&&(0,s.jsx)(`button`,{onClick:()=>{let e=w;T(null),k(e)},className:`p-2 md: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.E,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:w.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2 md:p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-0.5 md:ml-1`,title:`Download`,children:(0,s.jsx)(t.dt,{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.K,{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.at,{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)(ve,{isOpen:!!O,title:`Delete file`,message:(0,s.jsxs)(s.Fragment,{children:[`Delete `,(0,s.jsx)(`strong`,{className:`text-foreground block my-1 break-words max-w-full text-center`,children:O?.fileName}),` This cannot be undone.`]}),onConfirm:X,onCancel:()=>k(null),isProcessing:A,confirmText:`Yes, delete`}),(0,s.jsx)(t.m,{children:q&&(0,s.jsx)(t.p.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.ht,{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 Ot=[`mem_files`,`user_files`,`admin_files`],kt=e=>!e.sourceTab;function At(){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(Ot.map(async e=>{try{return(await(0,i.getDocs)((0,i.collection)(t.Ht,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&&kt(n)&&await(0,o.deleteObject)((0,o.ref)(t.Wt,e)).catch(()=>{}),await(0,i.deleteDoc)((0,i.doc)(t.Ht,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(Ot.map(async e=>{try{return(await(0,i.getDocs)((0,i.collection)(t.Ht,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(kt).length,_=Ot.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.p.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-2xl md:rounded-3xl p-4 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.K,{className:`w-4 h-4 animate-spin`}):(0,s.jsx)(t.E,{className:`w-4 h-4`}),l?`Deleting ${p} of ${e.length}…`:`Clean up all ${e.length} permanently`]})]}),(0,s.jsx)(ve,{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 jt(){let{isAdmin:e}=N();return(0,s.jsx)(Dt,{title:`Assets`,subtitle:`/assets`,filesCollection:`pub_files`,config:{isAdmin:!0,pageId:`assets`},footer:e?(0,s.jsx)(At,{}):null})}function Mt(){let e=[{id:`board`,title:`Board View`,description:`Cards in columns you drag from one stage to the next.`,icon:t.et,path:`/board`},{id:`table`,title:`Data Table`,description:`Rows and columns for longer lists, with search and sorting.`,icon:t.D,path:`/table`},{id:`calendar`,title:`Calendar View`,description:`A month at a time for anything that belongs on a date.`,icon:t.Dt,path:`/calendar`},{id:`drive`,title:`Drive View`,description:`A file library with upload, preview, rename and delete.`,icon:t.rt,path:`/drive`}];return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-10 text-center`,children:[(0,s.jsx)(ce,{children:`What your assistant can build`}),(0,s.jsxs)(`p`,{className:`text-foreground/60 text-[14px] md:text-[15px] font-medium max-w-2xl mx-auto`,children:[`Every layout below already works — open one to see it.`,` `,(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-3 md: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.jsx)(t.p.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:n*.05},children:(0,s.jsxs)(c.Link,{to:e.path,className:`flex items-center gap-3 md:gap-5 w-full p-3.5 md:px-6 md:py-4 glass-panel border border-[var(--panel-border)] rounded-2xl hover:border-accent/40 transition-all duration-300 group hover:bg-foreground/[0.02]`,children:[(0,s.jsx)(`div`,{className:`w-10 h-10 md:w-12 md: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-[14px] md:text-[15px] font-bold text-foreground truncate`,children:e.title}),(0,s.jsx)(`p`,{className:`text-[12.5px] md:text-[13px] text-foreground/50 truncate font-medium`,children:e.description})]}),(0,s.jsx)(`span`,{"aria-hidden":`true`,className:`w-9 h-9 rounded-full flex items-center justify-center text-foreground/40 border border-[var(--panel-border)] shrink-0 group-hover:text-accent group-hover:border-accent/40 group-hover:translate-x-0.5 transition-all`,children:(0,s.jsx)(t.jt,{className:`w-4 h-4`})})]})},e.id)})]})]})}var Nt=`Xl271wWblkY`,Pt=[{title:`Open the Pages screen and press +`,body:`Pick who the page is for — Anyone, Signed-in users, Your team or Admins only. That one choice decides who can open it and which menu it appears in.`},{title:`Give it an address, a name and a heading`,body:`The web address creates the page the moment you fill it in. A dashboard page also gets an icon and a starting layout: board, table, calendar, files, or from scratch.`},{title:`If it needs a form, add it right there`,body:`In the page’s Form box pick A new form made for this page, say what it should ask, and name the button that opens it. Who can fill it in follows who the page is for, and every answer lands in your Inbox.`},{title:`Add your pictures on the row`,body:`On a page anyone can visit, upload each picture right there and say where on the page it belongs. Pictures never travel through the chat — the sentence you copy carries them for you.`},{title:`Say what you want on it, then copy the sentence`,body:`Write what you would like to see on the page in your own words. The finished sentence appears under it; copy it and paste it into your assistant’s chat. That is the whole hand-over.`},{title:`Change it later with Edit with AI`,body:`Once a page is built, press Edit with AI on its row. The row swaps to three boxes — what to add, what to change, what to take off — and hands you a different sentence: one that edits the page you already have. Nothing you did not mention is touched.`}],Ft=[{name:`Anyone`,where:`In the site menu`,who:`Everybody, signed in or not. This is your public website.`},{name:`Signed-in users`,where:`In the dashboard`,who:`Anyone who registers. Each person sees only their own information, never anyone else’s.`},{name:`Your team`,where:`In the dashboard`,who:`Only people you marked as team members on the Users screen, plus admins. Everyone on it sees the same information.`},{name:`Admins only`,where:`In the dashboard`,who:`You, and anyone you marked as an admin.`}],It=[{title:`Someone registers`,body:`That makes them a signed-in user, nothing more: they can open the pages for signed-in users and see only their own information there.`},{title:`You give them rights on the Users screen`,body:`Mark a person as a team member to open your team’s pages, or as an admin to open everything — your admin screens included. Take either back the same way.`},{title:`The pages do the rest`,body:`Access always follows who a page is for. There is nothing to switch on per person beyond the mark you set — a new team page is open to your whole team the moment it exists.`}],Lt=[{name:`Colours`,body:`Your brand colour, the page background and the text colour, for light mode and for dark mode. Ask the chat for colour codes if you want ideas — then paste them into the boxes yourself.`},{name:`Corners`,body:`How rounded the panels and buttons are. The lettering is not on this list: the site is set in one typeface and there is no setting for it.`},{name:`Your logo`,body:`Upload it once and it appears in the header everywhere. Pictures are shrunk for you as they upload.`},{name:`Light or dark`,body:`Choose which one the site opens in.`}],Rt=[{screen:`Pages`,path:`/pages`,body:`Add a page for any audience and give it a form and pictures if it needs them. Rename a page, change its web address or icon, reorder it, hide it or delete it — and press Edit with AI on any row to copy the sentence that changes a page you already have.`},{screen:`Forms`,path:`/forms`,body:`See every form. Add a question or change a form’s title and button text after it is built — forms are created with their pages.`},{screen:`Theme`,path:`/theme`,body:`Colours, 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.`}],zt=[{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:`Let the Pages screen write the request`,body:`Describe the page on its row and paste the sentence it hands you. It answers every question the assistant would otherwise stop to ask.`},{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."`}],Bt=[{id:`how-it-works`,short:`How it all works`},{id:`add-a-page`,short:`Adding a page`},{id:`audiences`,short:`The four kinds of pages`},{id:`users`,short:`Letting people in`},{id:`theme`,short:`Changing the look`},{id:`yourself`,short:`Where everything lives`},{id:`habits`,short:`Working with the assistant`}];function Vt({children:e}){return(0,s.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px] mb-3`,children:[(0,s.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e]})}function Ht({id:e,index:n,kicker:r,title:i,children:a}){return(0,s.jsxs)(t.p.section,{id:e,initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.05+n*.03},className:`mb-16 scroll-mt-24`,children:[(0,s.jsx)(Vt,{children:`0${n+1} · ${r}`}),(0,s.jsx)(`h2`,{className:`text-2xl font-extrabold tracking-tight text-foreground mb-3`,children:i}),a]})}function Ut({children:e}){return(0,s.jsx)(`p`,{className:`text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl mb-4 last:mb-0`,children:e})}function Wt({steps:e}){return(0,s.jsx)(`ol`,{className:`mt-6`,children:e.map((t,n)=>(0,s.jsxs)(`li`,{className:`relative grid grid-cols-[2.25rem_1fr] gap-x-4 pb-8 last:pb-0`,children:[n<e.length-1&&(0,s.jsx)(`span`,{"aria-hidden":!0,className:`absolute left-[1.125rem] top-10 bottom-1 w-px -translate-x-1/2 bg-[var(--panel-border)]`}),(0,s.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-full border border-[var(--panel-border)] bg-[var(--panel-bg)] text-[13px] font-bold text-accent tabular-nums select-none`,children:n+1}),(0,s.jsxs)(`div`,{className:`pt-1.5 min-w-0`,children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold tracking-tight text-foreground`,children:t.title}),(0,s.jsx)(`p`,{className:`mt-1.5 text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl`,children:t.body})]})]},t.title))})}function Gt({lead:e,children:t}){return(0,s.jsx)(`div`,{className:`mt-7 border-l-2 border-accent/50 pl-4`,children:(0,s.jsxs)(`p`,{className:`text-[13.5px] text-foreground/60 font-medium leading-relaxed max-w-2xl`,children:[(0,s.jsx)(`strong`,{className:`font-bold text-foreground/85`,children:e}),` `,t]})})}function Kt(){return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-3xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-10 text-center`,children:[(0,s.jsx)(ce,{children:`Guide`}),(0,s.jsx)(`p`,{className:`text-foreground/60 text-[14px] md:text-[15px] font-medium max-w-2xl mx-auto`,children:`Everything you run yourself, everything your assistant builds for you, and the one recipe that makes every page. Ten minutes, start to finish.`})]}),(0,s.jsxs)(t.p.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`mb-10`,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/${Nt}?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.p.nav,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.03},"aria-label":`In this guide`,className:`mb-14`,children:[(0,s.jsx)(Vt,{children:`In this guide`}),(0,s.jsx)(`ol`,{className:`grid gap-x-10 gap-y-1.5 sm:grid-cols-2`,children:Bt.map((e,t)=>(0,s.jsx)(`li`,{children:(0,s.jsxs)(`a`,{href:`#${e.id}`,className:`group flex items-baseline gap-2.5 py-0.5 w-fit`,children:[(0,s.jsxs)(`span`,{className:`text-[11px] font-bold text-foreground/35 tabular-nums`,children:[`0`,t+1]}),(0,s.jsx)(`span`,{className:`text-[14px] font-semibold text-foreground/75 group-hover:text-accent transition-colors`,children:e.short})]})},e.id))})]}),(0,s.jsxs)(Ht,{id:`how-it-works`,index:0,kicker:`Start here`,title:`How it all works`,children:[(0,s.jsx)(Ut,{children:`Your site is a set of pages. Some are open to the world — that is your public website. The rest live in the dashboard, behind a sign-in: pages every registered person can open, pages only your team can open, and pages only admins can open.`}),(0,s.jsx)(Ut,{children:`You run all of it from the admin screens in your menu — Pages, Forms, Theme, Users, Inbox. Everything on those screens changes with a click and takes effect at once: names, addresses, colours, who counts as team, who counts as admin.`}),(0,s.jsxs)(Ut,{children:[`What goes `,(0,s.jsx)(`em`,{className:`not-italic font-bold text-foreground/80`,children:`on`}),` a page is the one thing you do not click together — your assistant builds it. But you never have to work out what to say to it: when you describe a page on the Pages screen, the screen writes the whole request as one sentence. You copy that sentence, paste it into your assistant’s chat, and the page gets built. That copy-and-paste is the entire relationship, and the next chapter walks through it.`]})]}),(0,s.jsxs)(Ht,{id:`add-a-page`,index:1,kicker:`The one recipe`,title:`How to add a page — any kind`,children:[(0,s.jsx)(Ut,{children:`The same six steps make every page: a public one for your website, a board for your team, a table each signed-in person has to themselves. Never ask the chat to create a page out of nowhere — the Pages screen writes a better request than anyone types by hand.`}),(0,s.jsx)(Wt,{steps:Pt}),(0,s.jsxs)(Gt,{lead:`Not sure which layout to pick?`,children:[(0,s.jsx)(c.Link,{to:`/templates`,className:`text-accent font-bold hover:underline`,children:`Look through the templates`}),` `,`to see each one working before you choose.`]})]}),(0,s.jsxs)(Ht,{id:`audiences`,index:2,kicker:`Who it is for`,title:`The four kinds of pages`,children:[(0,s.jsx)(Ut,{children:`Every page is for exactly one audience — the choice you make when you press + on the Pages screen. It decides who can open the page and which menu it appears in. These are the words printed there:`}),(0,s.jsx)(`div`,{className:`mt-6 space-y-6`,children:Ft.map(e=>(0,s.jsxs)(`div`,{children:[(0,s.jsxs)(`div`,{className:`flex items-baseline gap-2.5 flex-wrap`,children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold tracking-tight text-foreground`,children:e.name}),(0,s.jsx)(`span`,{className:`text-[12px] text-accent font-semibold`,children:e.where})]}),(0,s.jsx)(`p`,{className:`mt-1 text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl`,children:e.who})]},e.name))}),(0,s.jsx)(Gt,{lead:`Careful:`,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)(Ht,{id:`users`,index:3,kicker:`Letting people in`,title:`How users work`,children:[(0,s.jsx)(Ut,{children:`People let themselves in at the front door; you decide who gets further.`}),(0,s.jsx)(Wt,{steps:It})]}),(0,s.jsxs)(Ht,{id:`theme`,index:4,kicker:`The look`,title:`How to change the theme`,children:[(0,s.jsxs)(Ut,{children:[`Everything about the look lives on your`,` `,(0,s.jsx)(c.Link,{to:`/theme`,className:`text-accent font-bold hover:underline`,children:`Theme screen`}),`. Change a value there and the whole site follows at once — no assistant needed, nothing to rebuild. Four things are yours to set:`]}),(0,s.jsx)(`div`,{className:`mt-6 space-y-6`,children:Lt.map(e=>(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold tracking-tight text-foreground`,children:e.name}),(0,s.jsx)(`p`,{className:`mt-1 text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl`,children:e.body})]},e.name))})]}),(0,s.jsxs)(Ht,{id:`yourself`,index:5,kicker:`No assistant needed`,title:`Where everything lives`,children:[(0,s.jsx)(Ut,{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:`mt-6 space-y-6`,children:Rt.map(e=>(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold tracking-tight w-fit`,children:(0,s.jsx)(c.Link,{to:e.path,className:`text-foreground hover:text-accent transition-colors`,children:e.screen})}),(0,s.jsx)(`p`,{className:`mt-1 text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl`,children:e.body})]},e.screen))}),(0,s.jsx)(Gt,{lead:`Good to know:`,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)(Ht,{id:`habits`,index:6,kicker:`Five habits`,title:`Working with the assistant`,children:[(0,s.jsx)(Ut,{children:`Five habits keep the assistant on track. There is nothing to memorise beyond them.`}),(0,s.jsx)(`div`,{className:`mt-6 space-y-6`,children:zt.map(e=>(0,s.jsxs)(`div`,{children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold tracking-tight text-foreground`,children:e.title}),(0,s.jsx)(`p`,{className:`mt-1 text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl`,children:e.body})]},e.title))})]})]})}function qt(){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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col`,children:[(0,s.jsx)(`div`,{className:`w-full max-w-5xl mx-auto mb-6`,children:(0,s.jsx)(Tt,{to:`/templates`})}),(0,s.jsx)(`div`,{className:`w-full max-w-5xl mx-auto mt-6`,children:(0,s.jsxs)(t.p.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-form 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.p.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.yt,{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.p.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.p.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.Vt.currentUser?.uid||`guest`;await(0,i.addDoc)((0,i.collection)(t.Ht,`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.l,{label:`Favorite Service`,placeholder:`e.g. Design Consulting`,value:e.favoriteService,onChange:t=>n({...e,favoriteService:t.target.value})}),(0,s.jsx)(t.l,{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.c,{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 Jt(){let[e,n]=(0,r.useState)(!1),[a,o]=(0,r.useState)({concept:``,featureRequest:``,notes:``}),[c,l]=(0,r.useState)(`idle`);return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,s.jsx)(`div`,{className:`mb-3`,children:(0,s.jsx)(Tt,{to:`/templates`})}),(0,s.jsx)(ce,{children:`Popup Form`}),(0,s.jsxs)(`div`,{className:`max-sm:hidden sm: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.jsxs)(t.p.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.jsxs)(`div`,{className:`flex flex-col sm:flex-row h-full w-full gap-4 sm:gap-6 justify-between sm:items-center relative z-10`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-xl md:text-2xl font-extrabold text-foreground tracking-tight mb-2`,children:`A form in a pop-up`}),(0,s.jsx)(`p`,{className:`text-[13px] md:text-[14px] text-foreground/60 font-medium leading-relaxed max-w-md`,children:`The page stays where it is and the form opens over it, with the background blurred. Close it and nothing is lost.`})]}),(0,s.jsxs)(t.c,{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 shrink-0`,children:[(0,s.jsx)(t.L,{className:`w-4 h-4`}),` Open Form`]})]})]}),(0,s.jsx)(t.m,{children:e&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.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.p.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-popover relative 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.v,{className:`w-5 h-5`})}),c===`success`?(0,s.jsxs)(t.p.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.yt,{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.`})]}):c===`loading`?(0,s.jsxs)(t.p.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.p.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(),l(`loading`);try{let e=t.Vt.currentUser?.uid||`guest`;await(0,i.addDoc)((0,i.collection)(t.Ht,`user_submissions`),{uid:e,...a,type:`template_simulation`,submittedAt:(0,i.serverTimestamp)()}),l(`success`),setTimeout(()=>{l(`idle`),o({concept:``,featureRequest:``,notes:``}),n(!1)},3e3)}catch{l(`error`)}},className:`space-y-4 w-full`,children:[(0,s.jsx)(t.l,{label:`Concept Name`,placeholder:`e.g. Project Apollo`,value:a.concept,onChange:e=>o({...a,concept:e.target.value})}),(0,s.jsx)(t.l,{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.c,{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`})})]})]})]})]})]})})]})}var Yt=[{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 Xt({title:e=`Board View`,subtitle:n=`/board`,backUrl:a=`/templates`,tasksCollection:o=`pub_tasks`,categoriesCollection:c=`pub_categories`,config:l,customContent:u}){let{user:d}=N(),f=!!l,p=l?.isInternal||l?.isShared;l?.isPrivate&&l?.isAdmin;let m=l?.isAdmin||p,h=f?m:!0,g=!!u,_=l?.showButton!==!1&&!g,v=l?.buttonText||`+`,y=l?.buttonStyle||`primary`,b=l?.keyName||`key`,x=l?.valueName||`value`,[S,C]=(0,r.useState)([]),[w,T]=(0,r.useState)([]),[E,D]=(0,r.useState)(null),[O,k]=(0,r.useState)(null),[A,j]=(0,r.useState)({name:``}),[M,P]=(0,r.useState)([]),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)(null),[z,B]=(0,r.useState)(null),[ee,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=c.startsWith(`user_`);if(e&&!d)return;try{let e=localStorage.getItem(`fbos_board_tasks_${o}`);e&&C(JSON.parse(e));let t=localStorage.getItem(`fbos_board_cats_${c}`);t&&T(JSON.parse(t))}catch{}let r=(0,i.onSnapshot)(e&&d?(0,i.query)((0,i.collection)(t.Ht,o),(0,i.where)(`uid`,`==`,d.uid)):(0,i.collection)(t.Ht,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&&d?(0,i.query)((0,i.collection)(t.Ht,c),(0,i.where)(`uid`,`==`,d.uid)):(0,i.collection)(t.Ht,c),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=d?{uid:d.uid}:{};e.forEach(e=>(0,i.setDoc)((0,i.doc)(t.Ht,c,e.id),{...n,title:e.title,createdAt:e.createdAt}))}else T(n),localStorage.setItem(`fbos_board_cats_${c}`,JSON.stringify(n))});return()=>{r(),a()}},[o,c,d]);let Y=(e,t)=>{t?(k(t.id),j({id:t.id,name:t.name}),P(t.fields?.length?[...t.fields,{key:``,value:``}]:[{key:``,value:``}])):(D(e),j({name:``}),P([{key:``,value:``}]))},ne=(e,t,n)=>{let r=[...M];r[e]={key:t,value:n},e===M.length-1&&(t.trim()!==``||n.trim()!==``)&&r.push({key:``,value:``}),P(r)},re=(e,t)=>{e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`taskId`,t),I(t)},ie=(e,t)=>{e.preventDefault(),e.stopPropagation(),t!==F&&R(t)},ae=(e,t)=>{e.preventDefault(),e.stopPropagation(),B(t)},X=e=>{e.preventDefault(),R(null),B(null)},oe=async(e,n,r)=>{e.preventDefault(),e.stopPropagation(),R(null),B(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};d&&(a.uid=d.uid),(0,i.setDoc)((0,i.doc)(t.Ht,o,e.id),a,{merge:!0})}),I(null)},Z=async e=>{let n=A.id||`item_${Date.now()}`,r=A.name.trim(),a=r||`Untitled Item`,s=M.filter(e=>e.key.trim()!==``||e.value.trim()!==``),c=!0,l=A.id?S.find(e=>e.id===A.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(A.id||`new`);let u={categoryId:e,name:a,fields:s};d&&!A.id&&(u.uid=d.uid),await(0,i.setDoc)((0,i.doc)(t.Ht,o,n),u,{merge:!0}),setTimeout(()=>{D(null),k(null),V(null)},400)},se=(e,t)=>{J({type:`item`,id:e,title:t})},le=async()=>{let e=`cat_${Date.now()}`,n={title:``,createdAt:Date.now()};d&&(n.uid=d.uid),await(0,i.setDoc)((0,i.doc)(t.Ht,c,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.Ht,c,e),{color:n},{merge:!0})},fe=async e=>{G.trim()?await(0,i.setDoc)((0,i.doc)(t.Ht,c,e),{title:G},{merge:!0}):await(0,i.deleteDoc)((0,i.doc)(t.Ht,c,e)),W(null)},pe=(e,t)=>{J({type:`category`,id:e,title:t})},me=async()=>{if(q){H(!0);try{if(q.type===`item`)await(0,i.deleteDoc)((0,i.doc)(t.Ht,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.Ht,o,n.id));await(0,i.deleteDoc)((0,i.doc)(t.Ht,c,q.id))}}catch{}H(!1),J(null)}},he=[...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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen overflow-x-hidden`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4 md:mb-6 flex items-center gap-3`,children:[!f&&a&&(0,s.jsx)(Tt,{to:a}),(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(ce,{children:e}),n&&(0,s.jsxs)(`div`,{className:`max-sm:hidden sm: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 min-h-0 pb-16`,children:[f&&(0,s.jsx)(de,{}),(0,s.jsxs)(t.p.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 min-h-[400px] shadow-2xl bg-background relative z-10`,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:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm:p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0 relative z-20`,children:[(0,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-lg sm: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:[S.length,` `,S.length===1?`item`:`items`,` · `,he.length,` `,he.length===1?`category`:`categories`]})]}),_&&(0,s.jsx)(t.c,{variant:y===`secondary`?`secondary`:void 0,onClick:le,className:`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.L,{className:`w-4 h-4`}):v})]}),(0,s.jsx)(`div`,{className:`flex-1 w-full relative z-40 min-h-0 flex flex-col`,children:u?(0,s.jsx)(`div`,{className:`fbos-content-slot w-full flex-1 overflow-y-auto p-4 md:p-6`,children:(0,s.jsx)(u,{config:l,actions:{tasks:S,categories:w,collection:o,catCollection:c,user:d,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.Ht,o,r),n,{merge:!0})},deleteTask:async e=>{C(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Ht,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.Ht,c,e),n,{merge:!0})},deleteCategory:async e=>{T(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Ht,c,e))},openInlineEditor:(e,t)=>Y(e,t)}})}):(0,s.jsxs)(`div`,{id:`board-container`,className:`w-full flex-1 min-h-0 flex flex-row gap-4 md:gap-6 overflow-x-auto p-4 md:p-6 snap-x snap-mandatory styled-scrollbars items-start`,children:[he.map((e,n)=>{let r=S.filter(t=>t.categoryId===e.id);r.sort((e,t)=>(e.order||0)-(t.order||0));let i=Yt.find(t=>t.text===e.color)||Yt.find(e=>e.text===`text-accent`);return i.text,i.bgLight,i.bgHover,(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:n*.1},className:`w-[calc(100vw-80px)] sm:w-[300px] md:w-[320px] shrink-0 flex flex-col max-h-full rounded-3xl p-4 snap-center relative border transition-colors ${Yt.find(t=>t.text===e.color)?.bgCard||`bg-foreground/[0.02]`} ${Yt.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(),fe(e.id)}}),(0,s.jsx)(`input`,{value:G,onChange:e=>K(e.target.value),onBlur:t=>{t.relatedTarget?.closest(`.category-color-picker`)||fe(e.id)},onKeyDown:t=>t.key===`Enter`&&fe(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.v,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Yt.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 ${Yt.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:()=>pe(e.id,e.title),className:`absolute right-0 opacity-100 md:opacity-0 md:group-hover:opacity-100 text-foreground/30 hover:text-red-500 transition-all shrink-0`,children:(0,s.jsx)(t.T,{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 ${z===e.id&&!L?`bg-foreground/5 scale-[1.01] border-dashed border border-accent/20`:``}`,onDragOver:t=>ae(t,e.id),onDragLeave:X,onDrop:t=>oe(t,e.id),children:[(0,s.jsx)(t.m,{children:r.map(n=>O===n.id?(0,s.jsxs)(t.p.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:A.name,onChange:e=>j({...A,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:M.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=>ne(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=>ne(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))}),ee===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.p.div,{draggable:!0,onDragStart:e=>re(e,n.id),onDragOver:e=>ie(e,n.id),onDragLeave:X,onDrop:t=>oe(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-100 md:opacity-0 md: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.R,{className:`w-3.5 h-3.5`})}),(0,s.jsx)(`button`,{onClick:e=>{e.stopPropagation(),se(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.T,{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:[h&&f&&d?(0,s.jsxs)(`div`,{className:`flex items-center gap-1.5 pr-2 border-r border-[var(--panel-border)] border-dashed mr-auto`,children:[d.photoURL?(0,s.jsx)(`img`,{src:d.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:(d.displayName||d.email||`U`)[0].toUpperCase()}),(0,s.jsx)(`span`,{className:`text-[10px] font-bold text-foreground/60 truncate max-w-[80px]`,children:d.displayName||d.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.p.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:A.name,onChange:e=>j({...A,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:M.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=>ne(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=>ne(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))}),ee===`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.L,{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)(ve,{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:me,onCancel:()=>J(null),isProcessing:te,confirmText:`Yes, Delete`})]})}function Zt(e){return Array.isArray?Array.isArray(e):cn(e)===`[object Array]`}function Qt(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 $t(e){return e==null?``:Qt(e)}function en(e){return typeof e==`string`}function tn(e){return typeof e==`number`}function nn(e){return e===!0||e===!1||an(e)&&cn(e)==`[object Boolean]`}function rn(e){return typeof e==`object`}function an(e){return rn(e)&&e!==null}function on(e){return e!=null}function sn(e){return!e.trim().length}function cn(e){return e==null?e===void 0?`[object Undefined]`:`[object Null]`:Object.prototype.toString.call(e)}var ln=`Incorrect 'index' type`,un=e=>`Invalid value for key ${e}`,dn=e=>`Pattern length exceeds max of ${e}.`,fn=e=>`Missing ${e} property in key`,pn=e=>`Property 'weight' in key '${e}' must be a positive integer`,mn=Object.prototype.hasOwnProperty,hn=class{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(e=>{let n=gn(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 gn(e){let t=null,n=null,r=null,i=1,a=null;if(en(e)||Zt(e))r=e,t=_n(e),n=vn(e);else{if(!mn.call(e,`name`))throw Error(fn(`name`));let o=e.name;if(r=o,mn.call(e,`weight`)&&(i=e.weight,i<=0))throw Error(pn(o));t=_n(o),n=vn(o),a=e.getFn}return{path:t,id:n,weight:i,src:r,getFn:a}}function _n(e){return Zt(e)?e:e.split(`.`)}function vn(e){return Zt(e)?e.join(`.`):e}function yn(e,t){let n=[],r=!1,i=(e,t,a,o)=>{if(on(e))if(!t[a])n.push(o===void 0?e:{v:e,i:o});else{let s=e[t[a]];if(!on(s))return;if(a===t.length-1&&(en(s)||tn(s)||nn(s)||typeof s==`bigint`))n.push(o===void 0?$t(s):{v:$t(s),i:o});else if(Zt(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,en(t)?t.split(`.`):t,0),r?n:n[0]}var bn={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},xn={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},Sn={location:0,threshold:.6,distance:100},Cn={useExtendedSearch:!1,useTokenSearch:!1,getFn:yn,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1},$=Object.freeze({...xn,...bn,...Sn,...Cn}),wn=/[^ ]+/g;function Tn(e=1,t=3){let n=new Map,r=10**t;return{get(t){let i=t.match(wn).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 En=class{constructor({getFn:e=$.getFn,fieldNormWeight:t=$.fieldNormWeight}={}){this.norm=Tn(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,en(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();en(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(!on(e)||sn(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(on(i)){if(Zt(i)){let e=[];for(let t=0,n=i.length;t<n;t+=1){let n=i[t];if(on(n)){if(en(n)){if(!sn(n)){let r={v:n,i:t,n:this.norm.get(n)};e.push(r)}}else if(on(n.v)){let t=en(n.v)?n.v:$t(n.v);if(!sn(t)){let r={v:t,i:n.i,n:this.norm.get(t)};e.push(r)}}}}n.$[r]=e}else if(en(i)&&!sn(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 Dn(e,t,{getFn:n=$.getFn,fieldNormWeight:r=$.fieldNormWeight}={}){let i=new En({getFn:n,fieldNormWeight:r});return i.setKeys(e.map(gn)),i.setSources(t),i.create(),i}function On(e,{getFn:t=$.getFn,fieldNormWeight:n=$.fieldNormWeight}={}){let{keys:r,records:i}=e,a=new En({getFn:t,fieldNormWeight:n});return a.setKeys(r),a.setIndexRecords(i),a}function kn(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 An=32;function jn(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>An)throw Error(dn(An));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=kn(_,s);e.length?c&&(C.indices=e):C.isMatch=!1}return C}function Mn(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 Nn(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 Pn={ł:`l`,Ł:`L`,đ:`d`,Đ:`D`,ø:`o`,Ø:`O`,ħ:`h`,Ħ:`H`,ŧ:`t`,Ŧ:`T`,ı:`i`,ß:`ss`},Fn=RegExp(`[`+Object.keys(Pn).join(``)+`]`,`g`),In=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(Fn,e=>Pn[e]):e=>e,Ln=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?In(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;let u=(e,t)=>{this.chunks.push({pattern:e,alphabet:Mn(e),startIndex:t})},d=this.pattern.length;if(d>An){let e=0,t=d%An,n=d-t;for(;e<n;)u(this.pattern.substr(e,An),e),e+=An;if(t){let e=d-An;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?In(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}=jn(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=Nn(u)),p}},Rn=class{constructor(e){this.pattern=e}static isMultiMatch(e){return zn(e,this.multiRegex)}static isSingleMatch(e){return zn(e,this.singleRegex)}search(e){return{isMatch:!1,score:1}}};function zn(e,t){let n=e.match(t);return n?n[1]:null}var Bn=class extends Rn{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]}}},Vn=class extends Rn{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]}}},Hn=class extends Rn{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]}}},Un=class extends Rn{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]}}},Wn=class extends Rn{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]}}},Gn=class extends Rn{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]}}},Kn=class extends Rn{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 Ln(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)}},qn=class extends Rn{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}}},Jn=[Bn,qn,Hn,Un,Gn,Wn,Vn,Kn],Yn=Jn.length,Xn=`\0`,Zn=`|`;function Qn(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 $n(e,t={}){return e.replace(/\\\|/g,Xn).split(Zn).map(e=>{let n=Qn(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<Yn;){let e=Jn[o],n=e.isMultiMatch(i);n&&(r.push(new e(n,t)),a=!0)}if(!a)for(o=-1;++o<Yn;){let e=Jn[o],n=e.isSingleMatch(i);if(n){r.push(new e(n,t));break}}}return r})}var er=new Set([Kn.type,qn.type]),tr=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?In(e):e,this.pattern=e,this.query=$n(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?In(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&&(er.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=Nn(o)),e}}return{isMatch:!1,score:1}}},nr=[];function rr(...e){nr.push(...e)}function ir(e,t){for(let n=0,r=nr.length;n<r;n+=1){let r=nr[n];if(r.condition(e,t))return new r(e,t)}return new Ln(e,t)}var ar={AND:`$and`,OR:`$or`},or={PATH:`$path`,PATTERN:`$val`},sr=e=>!!(e[ar.AND]||e[ar.OR]),cr=e=>!!e[or.PATH],lr=e=>!Zt(e)&&rn(e)&&!sr(e),ur=e=>({[ar.AND]:Object.keys(e).map(t=>({[t]:e[t]}))});function dr(e,t,{auto:n=!0}={}){let r=e=>{if(en(e)){let r={keyId:null,pattern:e};return n&&(r.searcher=ir(e,t)),r}let i=Object.keys(e),a=cr(e);if(!a&&i.length>1&&!sr(e))return r(ur(e));if(lr(e)){let r=a?e[or.PATH]:i[0],o=a?e[or.PATTERN]:e[r];if(!en(o))throw Error(un(r));let s={keyId:vn(r),pattern:o};return n&&(s.searcher=ir(o,t)),s}let o={children:[],operator:i[0]};return i.forEach(t=>{let n=e[t];Zt(n)&&n.forEach(e=>{o.children.push(r(e))})}),o};return sr(e)||(e=ur(e)),r(e)}function fr(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 pr(e,{ignoreFieldNorm:t=$.ignoreFieldNorm}){e.forEach(e=>{e.score=fr(e.matches,{ignoreFieldNorm:t})})}var mr=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 hr(e,t){let n=e.matches;t.matches=[],on(n)&&n.forEach(e=>{if(!on(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 gr(e,t){t.score=e.score}function _r(e,t,{includeMatches:n=$.includeMatches,includeScore:r=$.includeScore}={}){let i=[];return n&&i.push(hr),r&&i.push(gr),e.map(e=>{let{idx:n}=e,r={item:t[n],refIndex:n};return i.length&&i.forEach(t=>{t(e,r)}),r})}var vr=/\b\w+\b/g;function yr({isCaseSensitive:e=!1,ignoreDiacritics:t=!1}={}){return{tokenize(n){return e||(n=n.toLowerCase()),t&&(n=In(n)),n.match(vr)||[]}}}function br(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 xr(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 Sr(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 Cr=class{constructor(e,t,n){this.options={...$,...t},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new hn(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=ir(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 En))throw Error(ln);if(this._myIndex=t||Dn(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){let e=yr({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});this._invertedIndex=br(this._myIndex.records,this._myIndex.keys.length,e)}}add(e){if(on(e)&&(this._docs.push(e),this._myIndex.add(e),this._invertedIndex)){let e=this._myIndex.records[this._myIndex.records.length-1],t=yr({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});xr(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)Sr(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&&Sr(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(en(e)&&!e.trim()){let e=this._docs.map((e,t)=>({item:e,refIndex:t}));return tn(n)&&n>-1&&(e=e.slice(0,n)),e}let c=tn(n)&&n>0&&en(e),l;if(c){let t=new mr(n);en(this._docs[0])?this._searchStringList(e,{heap:t,ignoreFieldNorm:s}):this._searchObjectList(e,{heap:t,ignoreFieldNorm:s}),l=t.extractSorted(o)}else l=en(e)?en(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e),pr(l,{ignoreFieldNorm:s}),a&&l.sort(o),tn(n)&&n>-1&&(l=l.slice(0,n));return _r(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(!on(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=fr(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):a.push(r)}}),a}_searchLogical(e){let t=dr(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===ar.AND)return[]}return o},r=this._myIndex.records,i=new Map,a=[];return r.forEach(({$:e,i:r})=>{if(on(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(!on(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=fr(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):o.push(r)}}),o}_findMatches({key:e,value:t,searcher:n}){if(!on(t))return[];let r=[];if(Zt(t))t.forEach(({v:t,i,n:a})=>{if(!on(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}},wr=class{static condition(e,t){return t.useTokenSearch}constructor(e,t){this.options=t,this.analyzer=yr({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 Ln(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=Nn(t)),o}};Cr.version=`7.3.0`,Cr.createIndex=Dn,Cr.parseIndex=On,Cr.config=$,Cr.match=function(e,t,n){return ir(e,{...$,...n}).searchIn(t)},Cr.parseQuery=dr,rr(tr),rr(wr),Cr.use=function(...e){e.forEach(e=>rr(e))};var Tr=[{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 Er({title:e=`Table View`,subtitle:n=`/table`,backUrl:a=`/templates`,tableCollection:o=`pub_table_data`,config:c,customContent:l}){let{user:u}=N(),d=!!c,f=c?.isInternal||c?.isShared;c?.isPrivate&&c?.isAdmin;let p=c?.isAdmin||f,m=d?p:!0,h=!!l,g=c?.showButton!==!1&&!h,_=c?.buttonText||`+`,v=c?.buttonStyle||`secondary`,y=c?.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)(``),[A,j]=(0,r.useState)(!1),[M,P]=(0,r.useState)(null),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)(``),[z,B]=(0,r.useState)(!1),[ee,V]=(0,r.useState)(``),[te,H]=(0,r.useState)(null),[U,W]=(0,r.useState)(null),[G,K]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=o.startsWith(`user_`);if(e&&!u)return;try{let e=localStorage.getItem(`fbos_tables_${o}`);e&&x(JSON.parse(e))}catch{}let n=(0,i.onSnapshot)(e&&u?(0,i.query)((0,i.collection)(t.Ht,o),(0,i.where)(`uid`,`==`,u.uid)):(0,i.collection)(t.Ht,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`],...u?{uid:u.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.Ht,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,u]);let q=b.find(e=>e.id===S)||b[0]||{columns:[],rows:[]},J=async e=>{q.id&&(u&&o.startsWith(`user_`)&&(e.uid=u.uid),await(0,i.setDoc)((0,i.doc)(t.Ht,o,q.id),e,{merge:!0}))},Y=()=>{if(!q.rows||q.rows.length===0)return;let e=q.columns.join(`,`),t=q.rows.map(e=>q.columns.map(t=>`"${e[t]||``}"`).join(`,`)).join(`
4
+ `),n=new Blob([`${e}\n${t}`],{type:`text/csv`}),r=window.URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`export_${q.name||`table`}.csv`,i.click(),window.URL.revokeObjectURL(r)},ne=(e,t,n)=>{J({...q,rows:q.rows.map(r=>r.id===e?{...r,[t]:n}:r)})},re=()=>{let e={id:Date.now().toString()};q.columns.forEach(t=>e[t]=``),J({...q,rows:[...q.rows||[],e]})},ie=e=>{J({...q,rows:q.rows.filter(t=>t.id!==e)})},ae=()=>{let e=`Column ${(q.columns?.length||0)+1}`;q.columns?.includes(e)||(J({...q,columns:[...q.columns||[],e]}),setTimeout(()=>{let e=document.getElementById(`table-scroll-container`);e&&e.scrollTo({left:e.scrollWidth,behavior:`smooth`})},100))},X=e=>{let t=(q.columns||[]).filter(t=>t!==e),n=(q.rows||[]).map(t=>{let n={...t};return delete n[e],n}),r={...q.colColors||{}};delete r[e],J({...q,columns:t,rows:n,colColors:r})},oe=async e=>{e.trim()&&q.id&&e!==q.name&&await(0,i.setDoc)((0,i.doc)(t.Ht,o,q.id),{name:e},{merge:!0})},Z=async()=>{j(!0),T(!1);let e=`tbl_${Date.now()}`;await(0,i.setDoc)((0,i.doc)(t.Ht,o,e),{name:`Unnamed Table`,columns:[`Column 1`,`Column 2`,`Column 3`],...u?{uid:u.uid}:{},rows:[]}),setTimeout(()=>{C(e),j(!1)},600)},se=e=>{let t=ee.trim();if(t&&t!==e&&!q.columns?.includes(t)){let n=q.columns.map(n=>n===e?t:n),r=(q.rows||[]).map(n=>{let r={...n};return r[t]=r[e]||``,delete r[e],r}),i={...q.colColors||{}};i[e]&&(i[t]=i[e],delete i[e]),J({...q,columns:n,rows:r,colColors:i})}I(null)},le=q.rows||[];return L.trim()!==``&&(le=new Cr(le.map(e=>({...e,_creatorMatch:`Guest`})),{keys:(q.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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4 md:mb-6 flex items-center gap-3`,children:[!d&&a&&(0,s.jsx)(Tt,{to:a}),(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(ce,{children:e}),n&&(0,s.jsxs)(`div`,{className:`max-sm:hidden sm: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 min-h-0 pb-16`,children:[d&&(0,s.jsx)(de,{}),(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative z-10 flex flex-col flex-1 min-h-[400px]`,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 items-center justify-between bg-foreground/[0.01] gap-3 sm:gap-4`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col min-w-0 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:q.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-[38vw] sm:max-w-[200px]`,onClick:()=>D(!0),title:`Click to rename table`,children:q.name||`Unnamed Table`}),(0,s.jsx)(t.m,{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.p.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:Z,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.L,{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.wt,{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:[(q.rows||[]).length,` Records`]})]}),(0,s.jsx)(`div`,{className:`relative shrink-0 ${z?`flex-1 min-w-[130px] max-w-[300px]`:``}`,children:z?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(t.P,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-foreground/40`}),(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,"aria-label":`Search records`,placeholder:`Search records...`,value:L,onChange:e=>R(e.target.value),onBlur:()=>{L.trim()||B(!1)},onKeyDown:e=>{e.key===`Escape`&&(R(``),B(!1))},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)(`button`,{type:`button`,onClick:()=>B(!0),"aria-label":`Search records`,title:`Search records`,className:`w-10 h-10 flex items-center justify-center rounded-xl border border-[var(--panel-border)] text-foreground/50 hover:text-accent hover:bg-foreground/5 transition-colors`,children:(0,s.jsx)(t.P,{className:`w-4 h-4`})})}),(0,s.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[y&&(0,s.jsx)(t.c,{variant:`secondary`,onClick:Y,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.dt,{className:`w-4 h-4`})}),g&&(0,s.jsx)(t.c,{variant:v===`primary`?void 0:`secondary`,onClick:re,className:`px-3 py-2.5 font-bold rounded-xl border border-[var(--panel-border)] shadow-sm flex items-center gap-2 whitespace-nowrap`,children:_===`+`?(0,s.jsx)(t.L,{className:`w-4 h-4`}):_})]})]}),(0,s.jsx)(`div`,{id:`table-scroll-container`,className:`overflow-auto w-full flex-1 min-h-[300px] relative styled-scrollbars`,children:l?(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)(l,{config:c,actions:{tables:b,activeTable:q,collection:o,user:u,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.Ht,o,e),n,{merge:!0})},deleteTable:async e=>{x(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Ht,o,e))},updateCell:(e,t,n)=>ne(e,t,n),addRow:()=>re(),addColumn:()=>ae()}})}):(0,s.jsx)(t.m,{mode:`wait`,children:A?(0,s.jsxs)(t.p.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.p.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 ${q.headerColor?Tr.find(e=>e.text===q.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 ${m?``:`hidden`}`,children:`Creator`}),(q.columns||[]).map((e,n)=>{let r=(q.colColors||{})[e],i=(q.colorTimestamps||{})[`col_${e}`]||0;q.headerColor;let a=(q.colorTimestamps||{}).header||0,o=`bg-transparent`,c=`text-foreground/50`;if(r&&r!==`none`&&i>=a){let e=Tr.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),V(t.currentTarget.textContent||``),(t.currentTarget.textContent||``).trim()!==``&&se(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),V(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:()=>W(U===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.B,{className:`w-4 h-4`})}),(q.columns||[]).length>1&&(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),X(e)},className:`p-1.5 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500/10 text-foreground/30 hover:text-red-500`,title:`Delete column`,children:(0,s.jsx)(t.T,{className:`w-3.5 h-3.5`})}),U===e&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>W(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={...q.colColors||{},[e]:`none`},r={...q.colorTimestamps||{},[`col_${e}`]:Date.now()};J({...q,colColors:n,colorTimestamps:r}),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:`Remove Color`,children:(0,s.jsx)(t.v,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Tr.map(t=>(0,s.jsx)(`button`,{onClick:n=>{n.preventDefault(),n.stopPropagation();let r={...q.colColors||{},[e]:t.text},i={...q.colorTimestamps||{},[`col_${e}`]:Date.now()};J({...q,colColors:r,colorTimestamps:i}),W(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:()=>K(!G),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${q.headerColor?Tr.find(e=>e.text===q.headerColor)?.text:`text-foreground/30`}`,children:(0,s.jsx)(t.B,{className:`w-4 h-4`})}),G&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>K(!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:()=>{J({...q,headerColor:``}),K(!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.v,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Tr.map(e=>(0,s.jsx)(`button`,{onClick:()=>{let t={...q.colorTimestamps||{},header:Date.now()};J({...q,headerColor:e.text,colorTimestamps:t}),K(!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:ae,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.L,{className:`w-4 h-4`})})]})})]})}),(0,s.jsxs)(`tbody`,{children:[le.map((e,n)=>{let r=n%2==1,i=(q.rowColors||{})[e.id],a=i?r?Tr.find(e=>e.text===i)?.bgAlt:Tr.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} ${m?``:`hidden`}`,children:(0,s.jsx)(`div`,{className:`flex items-center gap-2`,children:d&&u?(0,s.jsxs)(s.Fragment,{children:[u.photoURL?(0,s.jsx)(`img`,{src:u.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:(u.displayName||u.email||`U`)[0].toUpperCase()}),(0,s.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/80 tracking-tight shrink-0`,children:u.displayName||u.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`})]})})}),(q.columns||[]).map(t=>{let i=M?.id===e.id&&M?.field===t,a=(q.colColors||{})[t],o=(q.colorTimestamps||{})[`col_${t}`]||0,c=(q.rowColors||{})[e.id],l=(q.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?Tr.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=>ne(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-100 md:opacity-20 md:group-hover:opacity-100 transition-opacity relative`,children:[(0,s.jsx)(`button`,{onClick:()=>H(te===e.id?null:e.id),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${i?Tr.find(e=>e.text===i)?.text:`text-foreground/40`}`,children:(0,s.jsx)(t.B,{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:()=>H(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={...q.rowColors||{},[e.id]:`none`},r={...q.colorTimestamps||{},[`row_${e.id}`]:Date.now()};J({...q,rowColors: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 Row Color`,children:(0,s.jsx)(t.v,{className:`w-3 h-3`})}),(0,s.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Tr.map(t=>(0,s.jsx)(`button`,{onClick:()=>{let n={...q.colorTimestamps||{},[`row_${e.id}`]:Date.now()};J({...q,rowColors:{...q.rowColors||{},[e.id]:t.text},colorTimestamps:n}),H(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:()=>ie(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.T,{className:`w-4 h-4`})})]})})]},e.id||`row_${n}`)}),le.length===0&&(0,s.jsx)(`tr`,{children:(0,s.jsxs)(`td`,{colSpan:(q.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 `,q.name||`this table`,`.`]})}),(0,s.jsx)(`tr`,{children:(0,s.jsx)(`td`,{colSpan:(q.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:re,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.L,{className:`w-4 h-4`})})})})})]})]},`table`)})})]})]})]})}var Dr=[{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`}],Or={dateStr:``,title:``,description:``,time:`12:00`,duration:`60`,color:``,guestEmail:``,customFields:{}};function kr({title:e=`Calendar View`,subtitle:n=`/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)(Or),[R,z]=(0,r.useState)(new Date),[B,ee]=(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``}},ne=e=>{try{sessionStorage.setItem(`cal_guest_email`,e)}catch{}};(0,r.useEffect)(()=>(0,a.onAuthStateChanged)(t.Vt,async e=>{if(ee(e),e&&x===`admin_only`)try{let n=await(0,i.getDoc)((0,i.doc)(t.Ht,`user_profiles`,e.uid));n.exists()&&te(n.data())}catch{}U(!0)}),[x]),(0,r.useEffect)(()=>{if(!H)return;if(x!==`public`&&!B){T([]);return}try{let e=localStorage.getItem(`fbos_cal_${l}`);e&&T(JSON.parse(e))}catch{}let e=(0,i.onSnapshot)(x===`user`&&B?(0,i.query)((0,i.collection)(t.Ht,l),(0,i.where)(`uid`,`==`,B.uid)):(0,i.collection)(t.Ht,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,B?.uid,H]);let re=e=>!!B&&B.uid===e.uid,ie=e=>x===`public`?!1:x===`user`?!!B:re(e),ae=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`},oe=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`)}`},se=e=>{let t=e.getTimezoneOffset()*6e4;return new Date(e.getTime()-t).toISOString().split(`T`)[0]},le=()=>se(new Date),ue=new Date(R.getFullYear(),R.getMonth(),1),fe=new Date(R.getFullYear(),R.getMonth()+1,0),pe=ue.getDay(),me=fe.getDate(),he=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],ge=Array.from({length:42},(e,t)=>{let n=t-pe+1,r=new Date(R.getFullYear(),R.getMonth(),n);return{day:r.getDate(),dateStr:se(r),isCurrentMonth:n>0&&n<=me}}),_e=()=>z(S===`month`?new Date(R.getFullYear(),R.getMonth()-1,1):new Date(R.getFullYear(),R.getMonth(),R.getDate()-1)),ye=()=>z(S===`month`?new Date(R.getFullYear(),R.getMonth()+1,1):new Date(R.getFullYear(),R.getMonth(),R.getDate()+1)),be=e=>{if(x!==`public`&&!B)return;let t=new Date;t.setDate(t.getDate()+1);let n=new Date().getHours().toString().padStart(2,`0`);L({...Or,dateStr:e||se(t),time:`${n}:00`,guestEmail:x===`public`?Y():``,customFields:{}}),D(!0)},xe=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)},Se=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,ne(t)}else x===`user`||x===`internal`?(e.uid=B?.uid,e.creatorEmail=B?.email||``,e.creatorName=B?.displayName||``,e.creatorAvatar=B?.photoURL||``):x===`admin_only`&&(e.uid=B?.uid,e.creatorEmail=V?.email||B?.email||``,e.creatorName=V?.displayName||V?.name||``,e.creatorAvatar=V?.avatar||V?.avatarUrl||B?.photoURL||``);I.id?(await(0,i.setDoc)((0,i.doc)(t.Ht,l,I.id),e,{merge:!0}),O?.id===I.id&&k({...O,...e})):await(0,i.setDoc)((0,i.doc)(t.Ht,l,`ev_${Date.now()}`),e,{merge:!0}),D(!1)}catch(e){console.error(e)}j(!1)}},Ce=async()=>{if(P){N(!0);try{await(0,i.deleteDoc)((0,i.doc)(t.Ht,l,P.id)),O?.id===P.id&&k(null),F(null),D(!1)}catch{}N(!1)}},we=e=>{if(x===`user`||!e.creatorEmail&&!e.creatorName)return null;let t=(e.creatorName||e.creatorEmail||`?`).charAt(0).toUpperCase(),n=Dr.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})]})]})},Te=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`&&!B)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.U,{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.K,{className:`w-8 h-8 animate-spin text-accent`})});let Q=!!f,Ee=(x===`public`||!!B)&&m&&!Q,De=()=>(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm: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.p.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`}),_&&!Q&&(0,s.jsx)(t.p.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.X,{className:`w-4 h-4`}):(0,s.jsx)(t.Dt,{className:`w-4 h-4`})}),Ee&&(0,s.jsx)(t.p.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>be(),title:`Add event`,"aria-label":`Add event`,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.L,{className:`w-4 h-4`}):(0,s.jsx)(`span`,{className:`text-[13px] font-bold`,children:h})})]})]}),Oe=()=>(0,s.jsxs)(`div`,{className:`p-4 md:p-6 border-b border-[var(--panel-border)]/50 flex flex-wrap items-center justify-between gap-x-3 gap-y-2 bg-foreground/[0.01]`,children:[(0,s.jsx)(`h3`,{className:`text-lg md:text-xl font-extrabold tracking-tight ml-2 min-w-0`,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:()=>z(new Date),className:`px-3 md:px-4 py-2 text-[13px] font-bold border border-[var(--panel-border)] rounded-xl mr-1 md:mr-2 hover:bg-foreground/5 transition-colors`,children:`Today`}),(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.Ct,{className:`w-5 h-5`})}),(0,s.jsx)(`button`,{onClick:ye,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.St,{className:`w-5 h-5`})})]})]}),ke=()=>(0,s.jsxs)(s.Fragment,{children:[Oe(),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:B,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.Ht,l,n),e,{merge:!0})},deleteEvent:async e=>{T(t=>t.filter(t=>t.id!==e)),await(0,i.deleteDoc)((0,i.doc)(t.Ht,l,e))},openAddModal:e=>be(e),openEditModal:e=>xe(e),setViewingEvent:e=>k(e),currentDate:R,setCurrentDate:z,goToPrev:_e,goToNext:ye,goToToday:()=>z(new Date)}})}):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:he.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:ge.map((e,n)=>{let r=e.dateStr===le(),i=w.filter(t=>t.dateStr===e.dateStr);return(0,s.jsxs)(`div`,{onClick:()=>e.isCurrentMonth&&Ee&&be(e.dateStr),className:`min-h-[140px] p-2 bg-[var(--panel-bg)] flex flex-col relative group
5
+ ${e.isCurrentMonth?Ee?`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=Dr.find(t=>t.text===e.color),r=ie(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:ae(e.time)}),r&&(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),xe(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.R,{className:`w-3 h-3`})})]},e.id)})})]},n)})}),(0,s.jsx)(`style`,{children:`
6
6
  .styled-scrollbars::-webkit-scrollbar{width:4px}
7
7
  .styled-scrollbars::-webkit-scrollbar-thumb{background:color-mix(in srgb,var(--accent-color) 30%,transparent);border-radius:4px}
8
8
  input[type="time"]::-webkit-calendar-picker-indicator{display:none!important}
9
9
  input[type="date"]{color-scheme:dark}
10
10
  input[type="date"]::-webkit-calendar-picker-indicator{cursor:pointer;opacity:.5;transition:opacity .2s}
11
11
  input[type="date"]::-webkit-calendar-picker-indicator:hover{opacity:1}
12
- `})]})}):(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===se(R)).sort((e,t)=>e.time.localeCompare(t.time)).map(e=>{let n=new Date(e.dateStr+`T12:00:00`),r=Or.find(t=>t.text===e.color),i=ie(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)] max-sm:hidden 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:ae(e.time)}),(0,s.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,s.jsx)(t.gt,{className:`w-3 h-3`}),X(e.duration)]})]})]}),i&&(0,s.jsxs)(`div`,{className:`ml-auto pl-2 flex items-center gap-1 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-opacity`,children:[(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),xe(e)},className:`p-2.5 rounded-xl text-foreground/50 hover:bg-foreground/10 hover:text-foreground transition-colors`,children:(0,s.jsx)(t.R,{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.T,{className:`w-4 h-4`})})]})]}),p&&Te(e)]},e.id)}),w.filter(e=>e.dateStr===se(R)).length===0&&(0,s.jsx)(`div`,{className:`p-12 text-center text-foreground/40 font-medium`,children:`No events scheduled for this day.`})]})]}),Ae=()=>(0,s.jsxs)(t.m,{children:[O&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.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.p.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 ${Or.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:[ie(O)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`button`,{onClick:()=>{k(null),xe(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.R,{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.T,{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.v,{className:`w-5 h-5`})})]}),(0,s.jsxs)(`div`,{className:`mb-6 mt-12 sm:mt-0 sm: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 ${Or.find(e=>e.text===O.color)?.bgCircle||`bg-accent`}`}),(0,s.jsx)(`span`,{className:`text-[11px] font-bold tracking-[0.2em] uppercase ${Or.find(e=>e.text===O.color)?.text||`text-accent`}`,children:`Event Details`})]}),(0,s.jsx)(`h3`,{className:`text-xl sm:text-3xl font-black mb-3 tracking-tight leading-tight break-words ${Or.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.Dt,{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.gt,{className:`w-4 h-4 text-foreground/50`})}),ae(O.time),` `,(0,s.jsxs)(`span`,{className:`text-foreground/40 text-[12px] ml-1`,children:[`(`,X(O.duration),`)`]})]})]}),we(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.p.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.p.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&&ie({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.T,{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.v,{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:Se,className:`space-y-4`,children:[x===`public`&&!I.id&&(0,s.jsx)(t.l,{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.l,{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.l,{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:`
12
+ `})]})}):(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===se(R)).sort((e,t)=>e.time.localeCompare(t.time)).map(e=>{let n=new Date(e.dateStr+`T12:00:00`),r=Dr.find(t=>t.text===e.color),i=ie(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)] max-sm:hidden 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:ae(e.time)}),(0,s.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,s.jsx)(t.gt,{className:`w-3 h-3`}),X(e.duration)]})]})]}),i&&(0,s.jsxs)(`div`,{className:`ml-auto pl-2 flex items-center gap-1 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-opacity`,children:[(0,s.jsx)(`button`,{onClick:t=>{t.stopPropagation(),xe(e)},className:`p-2.5 rounded-xl text-foreground/50 hover:bg-foreground/10 hover:text-foreground transition-colors`,children:(0,s.jsx)(t.R,{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.T,{className:`w-4 h-4`})})]})]}),p&&Te(e)]},e.id)}),w.filter(e=>e.dateStr===se(R)).length===0&&(0,s.jsx)(`div`,{className:`p-12 text-center text-foreground/40 font-medium`,children:`No events scheduled for this day.`})]})]}),Ae=()=>(0,s.jsxs)(t.m,{children:[O&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.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.p.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 ${Dr.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:[ie(O)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(`button`,{onClick:()=>{k(null),xe(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.R,{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.T,{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.v,{className:`w-5 h-5`})})]}),(0,s.jsxs)(`div`,{className:`mb-6 mt-12 sm:mt-0 sm: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 ${Dr.find(e=>e.text===O.color)?.bgCircle||`bg-accent`}`}),(0,s.jsx)(`span`,{className:`text-[11px] font-bold tracking-[0.2em] uppercase ${Dr.find(e=>e.text===O.color)?.text||`text-accent`}`,children:`Event Details`})]}),(0,s.jsx)(`h3`,{className:`text-xl sm:text-3xl font-black mb-3 tracking-tight leading-tight break-words ${Dr.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.Dt,{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.gt,{className:`w-4 h-4 text-foreground/50`})}),ae(O.time),` `,(0,s.jsxs)(`span`,{className:`text-foreground/40 text-[12px] ml-1`,children:[`(`,X(O.duration),`)`]})]})]}),we(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.p.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.p.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&&ie({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.T,{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.v,{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:Se,className:`space-y-4`,children:[x===`public`&&!I.id&&(0,s.jsx)(t.l,{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.l,{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.l,{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:`
13
13
  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}
14
14
  input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}
15
15
  input[type="number"]{-moz-appearance:textfield}
16
- `}),(0,s.jsxs)(`div`,{className:`relative group/date flex flex-col w-full`,children:[(0,s.jsx)(t.l,{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.Dt,{className:`w-4 h-4`})})]}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[G?(0,s.jsx)(t.l,{type:`time`,label:`Time`,value:I.time,onChange:e=>L({...I,time:e.target.value}),required:!0}):(()=>{let{h:e,m:t,ampm:n}=oe(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.l,{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:Or.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.c,{type:`submit`,isLoading:A,className:`w-full py-3`,children:I.id?`Save Changes`:`Create Event`})})]})]})]},`edit-modal`),(0,s.jsx)(be,{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:Ce,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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col`,children:[(0,s.jsx)(t.p.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)(ce,{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)(de,{}),(0,s.jsxs)(t.p.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:[Q(),ke()]})]}),Ae()]}):(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4 md:mb-6 flex items-center gap-3`,children:[o&&(0,s.jsx)(Et,{to:o}),(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(ce,{children:e}),n&&(0,s.jsxs)(`div`,{className:`max-sm:hidden sm: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.jsx)(`div`,{className:`flex flex-col gap-6 flex-1 min-h-0 pb-16`,children:(0,s.jsxs)(t.p.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 min-h-[400px] shadow-2xl bg-background relative`,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`}),Q(),ke()]})}),Ae()]})}var jr=[{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`]}}],Mr=[{key:`light`,label:`Light mode`,icon:t.O,description:`How the site looks for someone with light mode on.`},{key:`dark`,label:`Dark mode`,icon:t.V,description:`How the site looks for someone with dark mode on.`}],Nr=Ce,Pr=`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`,Fr=`outline outline-1 outline-[var(--panel-border)]`,Ir=e=>JSON.parse(JSON.stringify(e)),Lr=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e)||typeof t!=`object`||!t||Array.isArray(t))return JSON.stringify(e)===JSON.stringify(t)?void 0:e;let n={};for(let r of Object.keys(e)){let i=Lr(e[r],t[r]);i!==void 0&&(n[r]=i)}return Object.keys(n).length?n:void 0},Rr=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},zr=(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(``)}`},Br=e=>{let t=(e||``).trim();if(t.startsWith(`#`)){let e=Rr(t);return e?zr(e[0],e[1],e[2]):null}let n=t.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i);return n?zr(parseFloat(n[1]),parseFloat(n[2]),parseFloat(n[3])):null},Vr=(e,t)=>{let n=Rr(e);return n?zr(n[0]*t,n[1]*t,n[2]*t):e},Hr=e=>e?Array.isArray(e)?e.length===1?e[0]:`linear-gradient(135deg, ${e.join(`, `)})`:e:``,Ur=(e,t)=>{let n=Rr(Br(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 Wr({label:e,hint:t,value:n,over:r,onChange:i}){let a=Br(n)||`#7c3aed`;return(0,s.jsxs)(`div`,{className:`flex flex-col gap-1.5 p-3.5 sm:p-4 ${xe}`,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 shrink-0 transition-all hover:scale-105 active:scale-95 flex items-center justify-center focus-within:ring-2 focus-within:ring-accent ${Fr}`,title:`Pick a colour for ${e}`,children:[(0,s.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-0 rounded-[inherit]`,style:{backgroundColor:r||`transparent`}}),(0,s.jsx)(`span`,{"aria-hidden":!0,"data-testid":`color-swatch`,className:`absolute inset-0 rounded-[inherit]`,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`})]})]}),t&&(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/45 font-medium leading-snug`,children:t}),(0,s.jsx)(`input`,{type:`text`,"aria-label":e,value:n??``,onChange:e=>i(e.target.value),className:Nr})]})}function Gr({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 ${xe}`,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 shrink-0 ${Fr}`,style:{background:Hr(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:Pr,children:[(0,s.jsx)(`label`,{className:`relative w-6 h-6 rounded-md cursor-pointer shrink-0 transition-all hover:scale-105 active:scale-95 flex items-center justify-center ${Fr}`,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:Br(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)(`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.v,{className:`w-3.5 h-3.5`})})]},r)),a.length<6&&(0,s.jsxs)(`button`,{type:`button`,onClick:()=>i([...a,Vr(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.L,{className:`w-3.5 h-3.5`}),`Add another colour`]})]})]})}function Kr({label:e,hint:t,value:n,onChange:r}){let i=Number.isFinite(n)?n:0;return(0,s.jsx)(ke,{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 qr({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.F,compact:!0,title:`Reset ${e.toLowerCase()}`,onClick:n,children:`Reset`})]})}var Jr=[`accent`,`foreground`,`background`,`backgroundSecondary`,`textGradient`,`notificationIconColor`],Yr=[`buttonGradient`,`buttonHoverGradient`,`buttonText`,`secondaryButton`],Xr=[`panelBg`,`panelBorder`,`glowColor`,`selectionBg`,`selectionText`],Zr=`fbos_theme_ai_draft`,Qr=()=>{try{return JSON.parse(localStorage.getItem(Zr)||`{}`)}catch{return{}}},$r=`Every mode needs these five: background, backgroundSecondary, foreground, accent and buttonText. Set any other colour I have actually named as well — the button fades, the quiet button, panel fill and edge, the highlight, the focus glow, the notification dot, the heading gradient — using my exact values where I gave them. Any colour I have NOT named, delete from the file rather than leaving it there: the app works those out from the five, and a colour left over from the look before is what makes a new theme come out wrong. Never copy a colour from another theme or an example.`,ei=e=>[...[`Design the look of my whole app. Here is what I am after: ${String(e?.brief||``).trim()||`___`}`,`Do it all in one file: src/your-ai-workflow-firebase-os/configs/theme.config.ts — the colours and how rounded things are. Do not restyle by rewriting components, and do not put colours of your own anywhere else.`,`Set the dark colours and the light colours both, so my site reads well either way.`,$r,...ni(e)],...ri].join(`
17
- `),ti=e=>[...[`My app already has a look I am happy with, set in one file: src/your-ai-workflow-firebase-os/configs/theme.config.ts.`,`Change that one file, and change only what I ask for below. Do not restyle by rewriting components, and do not put colours of your own anywhere else.`,`Leave everything else in that file exactly as it is — how rounded things are, and every colour I have not mentioned. Do not tidy up, rebalance or improve anything I did not ask about.`,`If what I ask for is a colour, set it in the dark colours and the light colours both, so my site still reads well either way.`,$r,`Here is what I would like changed: ${String(e?.changes||``).trim()||`___`}`,...ni(e)],...ri].join(`
18
- `),ni=e=>{let t=String(e?.appName||``).trim(),n=String(e?.logoUrl||``).trim(),r=String(e?.faviconUrl||``).trim(),i=[];return t&&i.push(`In that same file, set appName to exactly: ${t}`),n&&i.push(`In that same file, set logoUrl to exactly this link: ${n} — that is my logo for the top bar. Use my link character for character, take my colours from the picture, and never swap it for a placeholder or a picture of your own.`),r&&i.push(r===n?`Set faviconUrl to that same link — it is my browser tab icon too.`:`In that same file, set faviconUrl to exactly this link: ${r} — that is my browser tab icon. Use my link character for character.`),!n&&!r?i.push(`Leave logoUrl and faviconUrl exactly as they are. The logo and the browser tab icon are mine, and my Theme screen is the only place they change.`):n?r||i.push(`Leave faviconUrl exactly as it is — my browser tab icon is mine, and my Theme screen is the only place it changes.`):i.push(`Leave logoUrl exactly as it is — my logo is mine, and my Theme screen is the only place it changes.`),i},ri=[`Tell me what you picked and why, in one short paragraph.`,`If nothing changes on my site after you edit that file, say so — a look I have saved in the app wins over the file, and I can undo that with Start again on my Theme screen.`],ii=(e,t=`design`)=>t===`change`?String(e?.changes||``).trim()?``:`Say what you would like changed, and this sentence is ready to copy.`:String(e?.brief||``).trim()?``:`Say what look you are after, and this sentence is ready to copy.`,ai=[`appName`,`defaultTheme`,`showThemeToggle`],oi=[`cornerRounding`,`cornerRadii`];function si(){let{activeConfig:e,theme:n}=t.Rt(),a=t.Bt(),o=(0,r.useMemo)(()=>Ir(a?.themeConfig||t.Gt),[a]),[l,u]=(0,r.useState)(null),[d,f]=(0,r.useState)(Qr),[p,m]=(0,r.useState)(`design`),h=(e,t)=>f(n=>{let r={...n,[e]:t};try{localStorage.setItem(Zr,JSON.stringify(r))}catch{}return r}),[g,_]=(0,r.useState)(!1),[v,y]=(0,r.useState)(null),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(null),w=r.default.useRef(null);(0,r.useEffect)(()=>{if(!e)return;let t=JSON.stringify(Ir(e)),n=l?JSON.stringify(l):null;n!==t&&(n&&n!==w.current||(w.current=t,u(JSON.parse(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===w.current)return;let n=setTimeout(async()=>{_(!0);try{let n=Lr(l,o);n?await(0,i.setDoc)((0,i.doc)(t.Ht,`sys_configs`,`theme`),n):(await(0,i.deleteDoc)((0,i.doc)(t.Ht,`sys_configs`,`theme`)),localStorage.removeItem(`theme_config_cache`)),w.current=e,y(Date.now())}catch(e){console.error(`Auto-save failed`,e)}_(!1)},300);return()=>clearTimeout(n)},[l,o]);let T=(e,t)=>u(n=>({...n,[e]:t})),E=(e,t)=>u(n=>({...n,colors:{...n.colors,[e]:{...n.colors?.[e]||{},...t}}})),D=(e,t)=>u(n=>({...n,colors:{...n.colors,[e]:{...n.colors?.[e]||{},secondaryButton:{...n.colors?.[e]?.secondaryButton||{},...t}}}})),O=(e,t)=>E(e,{accent:t,notificationIconColor:t,...Ur(e,t)}),k=(e,t,n)=>C({title:e,message:t,apply:n}),A=e=>u(t=>{let n=Ir(t);return e.forEach(e=>{o[e]===void 0?delete n[e]:n[e]=Ir(o[e])}),n}),j=(e,t)=>u(n=>{let r=Ir(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]=Ir(i[t])}),r}),M=e=>{if(!l)return;let t=Ir(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,...Ur(n,r.accent),...i.secondaryButton?{secondaryButton:{...i.secondaryButton,text:r.text[0]}}:{}}}),u(t)},N=async()=>{x(!0);try{let e=Ir(o);await(0,i.deleteDoc)((0,i.doc)(t.Ht,`sys_configs`,`theme`)),localStorage.removeItem(`theme_config_cache`),localStorage.removeItem(`theme-mode`),localStorage.removeItem(`last-seen-default-theme`),localStorage.removeItem(Zr),f({}),m(`design`),w.current=JSON.stringify(e),u(e)}catch{}setTimeout(()=>x(!1),600)},P=e=>{let r=Mr.find(t=>t.key===e),i=l?.colors?.[e]||{},a=o.colors?.[e]||{},c=i.background||a.background||`#ffffff`;return(0,s.jsxs)(Oe,{icon:r.icon,title:r.label,description:r.description,defaultOpen:n===e,actions:(0,s.jsx)(Q,{icon:t.F,compact:!0,title:`Reset ${r.label.toLowerCase()}`,onClick:t=>{t.stopPropagation(),k(`Reset ${r.label.toLowerCase()}?`,`Every colour in ${r.label.toLowerCase()} — the brand colours, the buttons and the panels — goes back to how it started. The other mode is left alone.`,()=>j(e,[...Jr,...Yr,...Xr]))},children:`Reset`}),children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-3 p-3.5 sm:p-4 ${xe}`,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.`})]}),(0,s.jsx)(`div`,{className:`flex items-center gap-3 overflow-x-auto no-scrollbar py-2.5 px-2.5 -mx-2.5`,children:jr.map(t=>{let n=i.accent===t[e].accent&&l?.colors?.[e]?.buttonGradient?.[0]===t[e].gradient[0],r=t.name===`Black & White`;return(0,s.jsx)(`button`,{type:`button`,onClick:()=>M(t),"aria-label":t.name,title:t.name,className:`w-9 h-9 rounded-full shrink-0 transition-all relative cursor-pointer outline-offset-2 ${n?`outline-2 outline-accent scale-110 z-10`:`opacity-80 outline-0 hover:opacity-100 hover:outline-2 hover:outline-foreground/25 hover:scale-105`}`,style:r?{background:`linear-gradient(135deg, #ffffff 0%, #ffffff 50%, #000000 50%, #000000 100%)`}:{backgroundImage:`linear-gradient(135deg, ${t.preview[0]}, ${t.preview[1]})`}},t.name)})})]}),(0,s.jsx)(qr,{title:`Brand and colours`,onReset:()=>k(`Reset the colours?`,`The brand colour, the text and the two backgrounds in ${r.label.toLowerCase()} go back to how they started. Nothing else changes.`,()=>j(e,Jr))}),(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)(Wr,{over:c,label:`Brand colour`,hint:`Links, highlights and the main buttons. Panels follow it too.`,value:i.accent||a.accent||`#7c3aed`,onChange:t=>O(e,t)}),(0,s.jsx)(Wr,{over:c,label:`Text colour`,hint:`Primary typography colour used across the app.`,value:i.foreground||a.foreground||`#111827`,onChange:t=>E(e,{foreground:t})}),(0,s.jsx)(Wr,{over:c,label:`Page background`,hint:`Main background canvas colour under all content.`,value:i.background||a.background||`#ffffff`,onChange:t=>E(e,{background:t})}),(0,s.jsx)(Wr,{over:c,label:`Second background`,hint:`The colour the page background fades into.`,value:i.backgroundSecondary||a.backgroundSecondary||`#f9fafb`,onChange:t=>E(e,{backgroundSecondary:t})}),(0,s.jsx)(Wr,{over:c,label:`Notification dot`,hint:`Colour applied to notification badging.`,value:i.notificationIconColor||i.accent||a.notificationIconColor||`#7c3aed`,onChange:t=>E(e,{notificationIconColor:t})}),(0,s.jsx)(Gr,{label:`Heading colours`,hint:`The colours big headings fade through.`,value:i.textGradient||a.textGradient,onChange:t=>E(e,{textGradient:t})})]}),(0,s.jsx)(qr,{title:`Buttons`,onReset:()=>k(`Reset the buttons?`,`Every button colour in ${r.label.toLowerCase()} goes back to how it started. Nothing else changes.`,()=>j(e,Yr))}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-3 items-start`,children:[(0,s.jsx)(Gr,{label:`Button colours`,hint:`The colours your main buttons fade through.`,value:i.buttonGradient||a.buttonGradient,onChange:t=>E(e,{buttonGradient:t})}),(0,s.jsx)(Gr,{label:`Button colours on hover`,hint:`How a main button looks under the pointer.`,value:i.buttonHoverGradient||a.buttonHoverGradient,onChange:t=>E(e,{buttonHoverGradient:t})}),(0,s.jsx)(Wr,{over:c,label:`Button text`,hint:`The writing on your main buttons.`,value:i.buttonText||a.buttonText||`#ffffff`,onChange:t=>E(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)(Wr,{over:c,label:`Quiet button fill`,value:i.secondaryButton?.bg||a.secondaryButton?.bg||`rgba(0, 0, 0, 0.03)`,onChange:t=>D(e,{bg:t})}),(0,s.jsx)(Wr,{over:c,label:`Quiet button edge`,value:i.secondaryButton?.border||a.secondaryButton?.border||`rgba(0, 0, 0, 0.06)`,onChange:t=>D(e,{border:t})}),(0,s.jsx)(Wr,{over:c,label:`Quiet button text`,value:i.secondaryButton?.text||a.secondaryButton?.text||`#111827`,onChange:t=>D(e,{text:t})})]})]}),(0,s.jsx)(qr,{title:`Panels and highlights`,onReset:()=>k(`Reset the panels?`,`Panels, edges, the focus glow and text highlighting in ${r.label.toLowerCase()} go back to how they started. Nothing else changes.`,()=>j(e,Xr))}),(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)(Wr,{over:c,label:`Panel fill`,hint:`Background colour of cards and panels.`,value:i.panelBg||a.panelBg||`rgba(255, 255, 255, 0.70)`,onChange:t=>E(e,{panelBg:t})}),(0,s.jsx)(Wr,{over:c,label:`Panel edge`,hint:`Borders of panels, inputs and dropdowns.`,value:i.panelBorder||a.panelBorder||`rgba(0, 0, 0, 0.08)`,onChange:t=>E(e,{panelBorder:t})}),(0,s.jsx)(Wr,{over:c,label:`Focus glow`,hint:`The glow around the box someone is typing in.`,value:i.glowColor||a.glowColor||`rgba(124, 58, 237, 0.30)`,onChange:t=>E(e,{glowColor:t})}),(0,s.jsx)(Wr,{over:c,label:`Highlight`,hint:`The colour behind text someone has selected.`,value:i.selectionBg||a.selectionBg||`rgba(124, 58, 237, 0.30)`,onChange:t=>E(e,{selectionBg:t})}),(0,s.jsx)(Wr,{over:c,label:`Highlighted text`,hint:`The colour of the selected text itself.`,value:i.selectionText||a.selectionText||`#ffffff`,onChange:t=>E(e,{selectionText:t})})]})]},e)};return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,s.jsx)(ce,{children:`Theme`}),(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`}),`/theme`]})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(de,{}),(0,s.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-5 md:p-8 shadow-2xl relative bg-background flex flex-col min-h-[600px]`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,s.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-[17px] sm:text-xl font-extrabold text-foreground tracking-tight`,children:p===`change`?`Change it with your assistant`:`Design it with your assistant`}),(0,s.jsxs)(`p`,{className:`text-[12.5px] sm:text-[13.5px] font-medium text-foreground/55 mt-1 sm:mt-1.5`,children:[(0,s.jsx)(`span`,{className:`sm:hidden`,children:`Fill these in for your assistant.`}),(0,s.jsx)(`span`,{className:`max-sm:hidden`,children:p===`change`?`Say what to change, then copy the sentence below into your assistant’s chat. Nothing you do not mention is touched.`:`Fill these in, then copy the sentence below into your assistant’s chat.`})]})]}),(0,s.jsxs)(`div`,{className:`shrink-0 flex items-center gap-2`,children:[(0,s.jsx)(Q,{icon:t.y,compact:!0,title:p===`change`?`Design the whole look instead`:`Change the look you already have`,className:p===`change`?`text-accent border-accent/40 bg-accent/10 max-sm:border-transparent max-sm:bg-accent/10`:``,onClick:()=>m(p===`change`?`design`:`change`),children:`Edit with AI`}),(0,s.jsx)(Q,{icon:t.F,tone:`danger`,compact:!0,busy:b,title:`Start the whole look again`,onClick:()=>k(`Start the whole look again?`,`Every colour and every corner goes back to how it was the day you installed, and your answers in the assistant section above clear too. This cannot be undone.`,N),children:`Start again`})]})]}),(0,s.jsx)(ot,{label:`Logo`,hint:`The picture in the top bar.`,value:d.logoUrl||``,onChange:e=>h(`logoUrl`,e),tips:ct}),(0,s.jsx)(ot,{label:`Browser tab icon`,hint:`The tiny picture on the browser tab.`,value:d.faviconUrl||``,onChange:e=>h(`faviconUrl`,e),tips:lt}),(0,s.jsx)(Ae,{label:`App name`,hint:`It goes in the top bar and on the browser tab.`,value:d.appName||``,onChange:e=>h(`appName`,e),placeholder:`Bright Studio`}),p===`change`?(0,s.jsx)(Me,{label:`What would you like changed?`,hint:`Name just the parts you want moved. Everything else stays as it is.`,value:d.changes||``,onChange:e=>h(`changes`,e),placeholder:`Make the buttons a softer green, and warm up the page background a little. Leave the cards as they are.`}):(0,s.jsx)(Me,{label:`What look would you like?`,hint:`What you do, who it is for, and the feeling you are after.`,value:d.brief||``,onChange:e=>h(`brief`,e),placeholder:`A calm, modern look for a small physiotherapy clinic. Soft greens, lots of white space, nothing shouty. Rounded corners.`}),(0,s.jsx)(rt,{title:`Copy this to your assistant`,prompt:p===`change`?ti(d):ei(d),locked:!!ii(d,p),onCopied:p===`change`?void 0:()=>m(`change`)}),(0,s.jsxs)(`p`,{className:`text-[11.5px] text-foreground/45 font-medium leading-snug px-1`,children:[`Uploads are kept on your`,` `,(0,s.jsx)(c.Link,{to:`/assets`,className:`text-accent font-bold hover:underline`,children:`Assets page`}),` `,`too — edit the fields and copy the sentence again any time.`]})]}),(0,s.jsxs)(`div`,{className:`mt-10 pt-8 border-t border-[var(--panel-border)]/50 mb-5 flex items-start justify-between gap-3`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-[17px] sm:text-xl font-extrabold text-foreground tracking-tight`,children:`Change it by hand`}),(0,s.jsx)(`p`,{className:`text-[12.5px] sm:text-[13.5px] font-medium text-foreground/55 mt-1 sm:mt-1.5`,children:`One setting at a time. Changes show up straight away and save themselves.`})]}),(0,s.jsx)(`div`,{className:`shrink-0 flex items-center gap-2 pt-1`,children:(0,s.jsx)(Ie,{saving:g,savedAt:v})})]}),l?(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,s.jsxs)(Oe,{icon:t.It,title:`Name and how it opens`,description:`What your site is called, and whether it opens light or dark.`,defaultOpen:!1,actions:(0,s.jsx)(Q,{icon:t.F,compact:!0,title:`Reset the name and how it opens`,onClick:()=>k(`Reset the name?`,`The name and the opening mode go back to how they started. Your logo and your browser tab icon are left alone.`,()=>A(ai)),children:`Reset`}),children:[(0,s.jsx)(Ae,{label:`Site name`,hint:`The name people see in the top bar and on the browser tab.`,value:l.appName||``,onChange:e=>T(`appName`,e),placeholder:`Your AI Firebase`}),(0,s.jsx)(ot,{label:`Logo`,hint:`The picture in the top bar — changes straight away.`,value:l.logoUrl||``,onChange:e=>T(`logoUrl`,e),tips:ct,action:(l.logoUrl||``)===(o.logoUrl||``)?void 0:(0,s.jsx)(Q,{icon:t.F,onClick:()=>T(`logoUrl`,o.logoUrl||``),children:`Put the original back`})}),(0,s.jsx)(ot,{label:`Browser tab icon`,hint:`The tiny picture on the browser tab — changes straight away.`,value:l.faviconUrl||``,onChange:e=>T(`faviconUrl`,e),tips:lt,action:(l.faviconUrl||``)===(o.faviconUrl||``)?void 0:(0,s.jsx)(Q,{icon:t.F,onClick:()=>T(`faviconUrl`,o.faviconUrl||``),children:`Put the original back`})}),(0,s.jsx)(Ne,{label:`How the site opens`,hint:`Light, dark, or whichever one the visitor already uses on their device.`,value:l.defaultTheme||`system`,onChange:e=>T(`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=>T(`showThemeToggle`,e)})]}),Mr.map(e=>P(e.key)),(0,s.jsxs)(Oe,{icon:t.k,title:`Corners`,description:`How rounded everything looks.`,defaultOpen:!1,actions:(0,s.jsx)(Q,{icon:t.F,compact:!0,title:`Reset the corners`,onClick:()=>k(`Reset the corners?`,`Every corner goes back to how it started.`,()=>A(oi)),children:`Reset`}),children:[(0,s.jsx)(Ne,{label:`Rounding`,hint:`Keep the rounding we ship with, or set each corner yourself.`,value:l.cornerRounding||`default`,onChange:e=>T(`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)(Kr,{label:`Buttons`,hint:`How round every button is.`,value:l.cornerRadii?.buttonRadius??.75,onChange:e=>T(`cornerRadii`,{...l.cornerRadii||{},buttonRadius:e})}),(0,s.jsx)(Kr,{label:`Boxes people type in`,hint:`Form fields and search boxes.`,value:l.cornerRadii?.inputRadius??.75,onChange:e=>T(`cornerRadii`,{...l.cornerRadii||{},inputRadius:e})}),(0,s.jsx)(Kr,{label:`Cards`,hint:`The panels your content sits on.`,value:l.cornerRadii?.cardRadius??1.5,onChange:e=>T(`cornerRadii`,{...l.cornerRadii||{},cardRadius:e})}),(0,s.jsx)(Kr,{label:`Pop-ups`,hint:`Dialogs and confirmation boxes.`,value:l.cornerRadii?.modalRadius??2.5,onChange:e=>T(`cornerRadii`,{...l.cornerRadii||{},modalRadius:e})})]})]})]}):(0,s.jsx)(`div`,{className:`flex items-center justify-center flex-1 text-foreground/40 py-16`,children:(0,s.jsx)(t.K,{className:`w-6 h-6 animate-spin text-accent`})})]})]}),(0,s.jsx)(be,{isOpen:!!S,title:S?.title||``,message:S?.message||``,confirmText:`Reset`,cancelText:`Keep it`,isProcessing:b,onCancel:()=>C(null),onConfirm:()=>{S?.apply(),C(null)}})]})}function ci({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 li=`w-full block py-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors`,ui=`No access`,di=`You do not have access to view this page. If you think you should, ask whoever runs this app.`,fi=()=>(0,s.jsx)(ci,{tone:`amber`,title:ui,message:di,action:(0,s.jsx)(c.Link,{to:`/dashboard`,className:li,children:`Back to dashboard`})}),pi=fi,mi=fi,hi={route:`/page_1`,pageName:`New Page`,pageTitle:`My New Page`,template:`none`,form:``},gi={tabName:`New Page`,iconName:``,route:`/new-page`,tabTitle:`Your Page`,template:`none`,form:``},_i={tabName:`New Admin Page`,iconName:``,route:`/new-admin-page`,tabTitle:`Admin Page`,template:`none`,form:``},vi={tabName:`New Team Page`,iconName:``,route:`/new-team-page`,tabTitle:`Team Page`,template:`none`,form:``},yi=[{id:`home`,title:`Home`,path:`/`,type:`public`,isSystem:!0,enabled:!0},{id:`contact`,title:`Contact`,path:`/contact`,type:`public`,isSystem:!0,enabled:!0},{id:`guide`,title:`Guide`,path:`/guide`,type:`public`,isSystem:!0,enabled:!0},{id:`templates`,title:`Templates`,path:`/templates`,type:`public`,isSystem:!0,enabled:!0},{id:`setup`,title:`Setup`,path:`/setup`,type:`public`,isSystem:!0,enabled:!0},{id:`dashboard`,title:`Dashboard`,path:`/dashboard`,type:`user`,isSystem:!0,enabled:!0},{id:`support`,title:`Support`,path:`/support`,type:`user`,isSystem:!0,enabled:!0},{id:`profile`,title:`Profile`,path:`/profile`,type:`user`,isSystem:!0,enabled:!0}],bi=new Set([`home`,`dashboard`,`profile`]),xi=e=>[...e,...yi.filter(t=>!e.some(e=>e.id===t.id))],Si={public:`Anyone`,user:`Signed-in users`,internal:`Your team`,admin:`Admins only`},Ci=e=>e.draft?`draft`:e.hidden?`hidden`:`live`,wi={draft:`Draft`,live:`Live`,hidden:`Hidden`},Ti={draft:`Nothing is saved yet. Give it a web address and the page is created.`,live:`This page is live at its web address and listed in the menu.`,hidden:`This page still exists at its web address, but it is out of the menu.`},Ei=e=>(e||``).trim().toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9_-]/g,``),Di=(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},Oi=()=>Object.fromEntries(F()),ki=(e,t=!1)=>{let n={};for(let[r,i]of Object.entries(Oi())){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`:D(o.pageType),isSystem:!1,enabled:o.enabled!==!1,fromFile:!0})}return n};function Ai({value:e,onChange:n,busy:r}){return(0,s.jsx)(`div`,{className:`shrink-0`,onClick:e=>e.stopPropagation(),children:(0,s.jsx)(t.s,{compact:!0,portal:!0,direction:`auto`,className:`console-select`,ariaLabel:`Who can open this page`,value:e,disabled:r,onChange:e=>n(e),options:b.map(e=>({value:e,label:Si[e]}))})})}var ji=`Add it here — its web address, a name, and what you would like to see on it — then copy the sentence for your assistant.`,Mi=`Add it here, then copy the sentence for your assistant.`,Ni=[{value:`none`,label:`From scratch`},{value:`board`,label:`Board`},{value:`table`,label:`Table`},{value:`calendar`,label:`Calendar`},{value:`drive`,label:`Files`}],Pi=[`board`,`table`,`calendar`,`drive`],Fi={board:{is:`a board`,keeps:`its board frame and the card editor that is already in it`,open:`actions.openInlineEditor(columnId)`},table:{is:`a table`,keeps:`its table frame and the row and column controls that are already in it`,open:`actions.addRow()`},calendar:{is:`a calendar`,keeps:`its calendar frame — the month heading, Today, and the arrows — and the add-event form that is already in it`,open:`actions.openAddModal()`},drive:{is:`a file library`,keeps:`its file frame and the upload box that is already in it`,open:`openUploadModal()`}},Ii=e=>{let t=Fi[e];return t?`This page already works as ${t.is} and it stays one: it keeps ${t.keeps}, already styled to match my app. Design only what fills it, and open the one that is already there with ${t.open}. Never build your own add, edit or upload form on this page — one exists, and yours will not match.`:``},Li=e=>(e||``).split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``),Ri=(e,t)=>t?.contentKey||t?.tabName||t?.pageName||t?.pageId||e.title,zi=(e,t)=>`src/your-ai-workflow-firebase-os/microcomponents/${Li(Ri(e,t))||`Page`}Content.tsx`,Bi=(e,t)=>{let n=String(t?.route||``).trim();return n?n.startsWith(`/`)?n:`/`+n:e.path||``},Vi=(e,t)=>Bi(e,t).replace(/^\/+/,``)?String(t?.brief||``).trim()?da(t)?`Say what the form should ask for, and this sentence is ready to copy.`:``:`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.`,Hi=e=>{let t=e=>e.map(e=>({url:String(e?.url||``).trim(),where:String(e?.where||``).trim()})).filter(e=>e.url);if(Array.isArray(e?.images))return t(e.images);let n=String(e?.imageUrl||``).trim();return n?[{url:n,where:String(e?.imageWhere||``).trim()}]:[]},Ui=e=>Array.isArray(e?.images)?e.images.map(e=>({url:String(e?.url||``),where:String(e?.where||``)})):Hi(e),Wi=e=>Hi(e).map(({url:e,where:t})=>t?`Use this picture of mine on the page: ${e} — where it goes: ${t}. Keep its proportions and give it a short description for screen readers. Do not swap it for a placeholder or a picture of your own.`:`Use this picture of mine on the page: ${e} — put it where it works best in your design, keep its proportions, and give it a short description for screen readers. Do not swap it for a placeholder or a picture of your own.`),Gi=e=>{let t=String(e?.pageWish||``).trim(),n=String(e?.pageAdd||``).trim(),r=String(e?.pageChange||``).trim(),i=String(e?.pageRemove||``).trim(),a=[];return t&&a.push(`Here is what I would like on the page: ${t}`),n&&a.push(`Add this: ${n}`),r&&a.push(`Change this: ${r}`),i&&a.push(`Take this off the page: ${i}`),a.push(...Wi(e)),a},Ki=e=>Gi(e).length>0,qi=(e,t)=>{let n=Bi(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=String(t?.formButton||``).trim(),l=String(t?.formSpot||``).trim();String(t?.formFields||``).trim();let u=t?.pageType?`private`:`public`,d=Li(Ri(e,t))||`Page`,f=d.replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase(),p=[`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: ${zi(e,t)}, with a default export. That file is what the page shows.`,`Then add two lines to src/your-ai-workflow-firebase-os/microcomponents/registry.ts so the app loads your file: import ${d}Content from './${d}Content'; and registerMicrocomponent('${f}', ${d}Content); — registerMicrocomponent is imported there from 'your-ai-workflow-firebase-os'. Never remove another page's lines from that file.`,`Make it match the rest of my app: style with the app’s own theme styles so it looks right in light and dark. Do not pick your own colors. Build it from the app’s own pieces — import { SectionHeading, Card, Button } from 'your-ai-workflow-firebase-os': section titles are SectionHeading, boxed sections are Card, buttons are Button — so nothing gets a look of its own. The design should be minimal, modern and clean and match the app.`,`Everything below the page heading is yours to design however you like — one clean column of sections using the full width. Never stack panels inside panels, never let sections overlap, and when the content grows tall let the page scroll.`];return Pi.includes(a)&&p.push(Ii(a)),o===`__new__`||t?.formIsNew?p.push(...Ji(t,u)):o&&(p.push(`Show my form ${ca(o)} on it with <ContactPopup formId='${o}' /> — never write a form by hand.`),c&&p.push(`The form opens from a button that says ${c} — make that button part of the page's design, not an afterthought.`),l&&p.push(`Where the form belongs on the page: ${l}`)),p.push(...Wi(t)),p.push(`Here is what I would like on it: ${s||`___`}`),p.join(`
16
+ `}),(0,s.jsxs)(`div`,{className:`relative group/date flex flex-col w-full`,children:[(0,s.jsx)(t.l,{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.Dt,{className:`w-4 h-4`})})]}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[G?(0,s.jsx)(t.l,{type:`time`,label:`Time`,value:I.time,onChange:e=>L({...I,time:e.target.value}),required:!0}):(()=>{let{h:e,m:t,ampm:n}=oe(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.l,{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:Dr.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.c,{type:`submit`,isLoading:A,className:`w-full py-3`,children:I.id?`Save Changes`:`Create Event`})})]})]})]},`edit-modal`),(0,s.jsx)(ve,{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:Ce,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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col`,children:[(0,s.jsx)(t.p.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)(ce,{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)(de,{}),(0,s.jsxs)(t.p.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:[De(),ke()]})]}),Ae()]}):(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4 md:mb-6 flex items-center gap-3`,children:[o&&(0,s.jsx)(Tt,{to:o}),(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(ce,{children:e}),n&&(0,s.jsxs)(`div`,{className:`max-sm:hidden sm: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.jsx)(`div`,{className:`flex flex-col gap-6 flex-1 min-h-0 pb-16`,children:(0,s.jsxs)(t.p.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 min-h-[400px] shadow-2xl bg-background relative`,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(),ke()]})}),Ae()]})}var Ar=[{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`]}}],jr=[{key:`light`,label:`Light mode`,icon:t.O,description:`How the site looks for someone with light mode on.`},{key:`dark`,label:`Dark mode`,icon:t.V,description:`How the site looks for someone with dark mode on.`}],Mr=xe,Nr=`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`,Pr=`outline outline-1 outline-[var(--panel-border)]`,Fr=e=>JSON.parse(JSON.stringify(e)),Ir=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e)||typeof t!=`object`||!t||Array.isArray(t))return JSON.stringify(e)===JSON.stringify(t)?void 0:e;let n={};for(let r of Object.keys(e)){let i=Ir(e[r],t[r]);i!==void 0&&(n[r]=i)}return Object.keys(n).length?n:void 0},Lr=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},Rr=(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(``)}`},zr=e=>{let t=(e||``).trim();if(t.startsWith(`#`)){let e=Lr(t);return e?Rr(e[0],e[1],e[2]):null}let n=t.match(/^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/i);return n?Rr(parseFloat(n[1]),parseFloat(n[2]),parseFloat(n[3])):null},Br=(e,t)=>{let n=Lr(e);return n?Rr(n[0]*t,n[1]*t,n[2]*t):e},Vr=e=>e?Array.isArray(e)?e.length===1?e[0]:`linear-gradient(135deg, ${e.join(`, `)})`:e:``,Hr=(e,t)=>{let n=Lr(zr(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 Ur({label:e,hint:t,value:n,over:r,onChange:i}){let a=zr(n)||`#7c3aed`;return(0,s.jsxs)(`div`,{className:`flex flex-col gap-1.5 p-3.5 sm:p-4 ${ye}`,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 shrink-0 transition-all hover:scale-105 active:scale-95 flex items-center justify-center focus-within:ring-2 focus-within:ring-accent ${Pr}`,title:`Pick a colour for ${e}`,children:[(0,s.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-0 rounded-[inherit]`,style:{backgroundColor:r||`transparent`}}),(0,s.jsx)(`span`,{"aria-hidden":!0,"data-testid":`color-swatch`,className:`absolute inset-0 rounded-[inherit]`,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`})]})]}),t&&(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/45 font-medium leading-snug`,children:t}),(0,s.jsx)(`input`,{type:`text`,"aria-label":e,value:n??``,onChange:e=>i(e.target.value),className:Mr})]})}function Wr({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 ${ye}`,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 shrink-0 ${Pr}`,style:{background:Vr(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:Nr,children:[(0,s.jsx)(`label`,{className:`relative w-6 h-6 rounded-md cursor-pointer shrink-0 transition-all hover:scale-105 active:scale-95 flex items-center justify-center ${Pr}`,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:zr(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)(`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.v,{className:`w-3.5 h-3.5`})})]},r)),a.length<6&&(0,s.jsxs)(`button`,{type:`button`,onClick:()=>i([...a,Br(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.L,{className:`w-3.5 h-3.5`}),`Add another colour`]})]})]})}function Gr({label:e,hint:t,value:n,onChange:r}){let i=Number.isFinite(n)?n:0;return(0,s.jsx)(De,{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 Kr({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.F,compact:!0,title:`Reset ${e.toLowerCase()}`,onClick:n,children:`Reset`})]})}var qr=[`accent`,`foreground`,`background`,`backgroundSecondary`,`textGradient`,`notificationIconColor`],Jr=[`buttonGradient`,`buttonHoverGradient`,`buttonText`,`secondaryButton`],Yr=[`panelBg`,`panelBorder`,`glowColor`,`selectionBg`,`selectionText`],Xr=`fbos_theme_ai_draft`,Zr=()=>{try{return JSON.parse(localStorage.getItem(Xr)||`{}`)}catch{return{}}},Qr=`Every mode needs these five: background, backgroundSecondary, foreground, accent and buttonText. Set any other colour I have actually named as well — the button fades, the quiet button, panel fill and edge, the highlight, the focus glow, the notification dot, the heading gradient — using my exact values where I gave them. Any colour I have NOT named, delete from the file rather than leaving it there: the app works those out from the five, and a colour left over from the look before is what makes a new theme come out wrong. Never copy a colour from another theme or an example.`,$r=e=>[...[`Design the look of my whole app. Here is what I am after: ${String(e?.brief||``).trim()||`___`}`,`Do it all in one file: src/your-ai-workflow-firebase-os/configs/theme.config.ts — the colours and how rounded things are. Do not restyle by rewriting components, and do not put colours of your own anywhere else.`,`Set the dark colours and the light colours both, so my site reads well either way.`,Qr,...ni(e)],...ri].join(`
17
+ `),ei=e=>[...[`My app already has a look I am happy with, set in one file: src/your-ai-workflow-firebase-os/configs/theme.config.ts.`,`Change that one file, and change only what I ask for below. Do not restyle by rewriting components, and do not put colours of your own anywhere else.`,`Leave everything else in that file exactly as it is — how rounded things are, and every colour I have not mentioned. Do not tidy up, rebalance or improve anything I did not ask about.`,`If what I ask for is a colour, set it in the dark colours and the light colours both, so my site still reads well either way.`,Qr,`Here is what I would like changed: ${String(e?.changes||``).trim()||`___`}`,...ni(e)],...ri].join(`
18
+ `),ti=e=>{let t=e?.defaultTheme||`system`;return t===`light`?`In that same file, set defaultTheme to 'light' so my site always opens in light mode.`:t===`dark`?`In that same file, set defaultTheme to 'dark' so my site always opens in dark mode.`:`In that same file, set defaultTheme to 'system' so my site opens in whichever mode the visitor's device already uses.`},ni=e=>{let t=String(e?.appName||``).trim(),n=String(e?.logoUrl||``).trim(),r=String(e?.faviconUrl||``).trim(),i=[ti(e)];return t&&i.push(`In that same file, set appName to exactly: ${t}`),n&&i.push(`In that same file, set logoUrl to exactly this link: ${n} — that is my logo for the top bar. Use my link character for character, take my colours from the picture, and never swap it for a placeholder or a picture of your own.`),r&&i.push(r===n?`Set faviconUrl to that same link — it is my browser tab icon too.`:`In that same file, set faviconUrl to exactly this link: ${r} — that is my browser tab icon. Use my link character for character.`),!n&&!r?i.push(`Leave logoUrl and faviconUrl exactly as they are. The logo and the browser tab icon are mine, and my Theme screen is the only place they change.`):n?r||i.push(`Leave faviconUrl exactly as it is — my browser tab icon is mine, and my Theme screen is the only place it changes.`):i.push(`Leave logoUrl exactly as it is — my logo is mine, and my Theme screen is the only place it changes.`),i},ri=[`Tell me what you picked and why, in one short paragraph.`,`If nothing changes on my site after you edit that file, say so — a look I have saved in the app wins over the file, and I can undo that with Start again on my Theme screen.`],ii=(e,t=`design`)=>t===`change`?String(e?.changes||``).trim()?``:`Say what you would like changed, and this sentence is ready to copy.`:String(e?.brief||``).trim()?``:`Say what look you are after, and this sentence is ready to copy.`,ai=[`appName`,`defaultTheme`,`showThemeToggle`],oi=[`cornerRounding`,`cornerRadii`];function si(){let{activeConfig:e,theme:n}=t.Rt(),a=t.Bt(),o=(0,r.useMemo)(()=>Fr(a?.themeConfig||t.Gt),[a]),[l,u]=(0,r.useState)(null),[d,f]=(0,r.useState)(Zr),[p,m]=(0,r.useState)(`design`),h=(e,t)=>f(n=>{let r={...n,[e]:t};try{localStorage.setItem(Xr,JSON.stringify(r))}catch{}return r}),[g,_]=(0,r.useState)(!1),[v,y]=(0,r.useState)(null),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(null),w=r.default.useRef(null);(0,r.useEffect)(()=>{if(!e)return;let t=JSON.stringify(Fr(e)),n=l?JSON.stringify(l):null;n!==t&&(n&&n!==w.current||(w.current=t,u(JSON.parse(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===w.current)return;let n=setTimeout(async()=>{_(!0);try{let n=Ir(l,o);n?await(0,i.setDoc)((0,i.doc)(t.Ht,`sys_configs`,`theme`),n):(await(0,i.deleteDoc)((0,i.doc)(t.Ht,`sys_configs`,`theme`)),localStorage.removeItem(`theme_config_cache`)),w.current=e,y(Date.now())}catch(e){console.error(`Auto-save failed`,e)}_(!1)},300);return()=>clearTimeout(n)},[l,o]);let T=(e,t)=>u(n=>({...n,[e]:t})),E=(e,t)=>u(n=>({...n,colors:{...n.colors,[e]:{...n.colors?.[e]||{},...t}}})),D=(e,t)=>u(n=>({...n,colors:{...n.colors,[e]:{...n.colors?.[e]||{},secondaryButton:{...n.colors?.[e]?.secondaryButton||{},...t}}}})),O=(e,t)=>E(e,{accent:t,notificationIconColor:t,...Hr(e,t)}),k=(e,t,n)=>C({title:e,message:t,apply:n}),A=e=>u(t=>{let n=Fr(t);return e.forEach(e=>{o[e]===void 0?delete n[e]:n[e]=Fr(o[e])}),n}),j=(e,t)=>u(n=>{let r=Fr(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]=Fr(i[t])}),r}),M=e=>{if(!l)return;let t=Fr(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,...Hr(n,r.accent),...i.secondaryButton?{secondaryButton:{...i.secondaryButton,text:r.text[0]}}:{}}}),u(t)},N=async()=>{x(!0);try{let e=Fr(o);await(0,i.deleteDoc)((0,i.doc)(t.Ht,`sys_configs`,`theme`)),localStorage.removeItem(`theme_config_cache`),localStorage.removeItem(`theme-mode`),localStorage.removeItem(`last-seen-default-theme`),localStorage.removeItem(Xr),f({}),m(`design`),w.current=JSON.stringify(e),u(e)}catch{}setTimeout(()=>x(!1),600)},P=e=>{let r=jr.find(t=>t.key===e),i=l?.colors?.[e]||{},a=o.colors?.[e]||{},c=i.background||a.background||`#ffffff`;return(0,s.jsxs)(Ee,{icon:r.icon,title:r.label,description:r.description,defaultOpen:n===e,actions:(0,s.jsx)(Q,{icon:t.F,compact:!0,title:`Reset ${r.label.toLowerCase()}`,onClick:t=>{t.stopPropagation(),k(`Reset ${r.label.toLowerCase()}?`,`Every colour in ${r.label.toLowerCase()} — the brand colours, the buttons and the panels — goes back to how it started. The other mode is left alone.`,()=>j(e,[...qr,...Jr,...Yr]))},children:`Reset`}),children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-3 p-3.5 sm:p-4 ${ye}`,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.`})]}),(0,s.jsx)(`div`,{className:`flex items-center gap-3 overflow-x-auto no-scrollbar py-2.5 px-2.5 -mx-2.5`,children:Ar.map(t=>{let n=i.accent===t[e].accent&&l?.colors?.[e]?.buttonGradient?.[0]===t[e].gradient[0],r=t.name===`Black & White`;return(0,s.jsx)(`button`,{type:`button`,onClick:()=>M(t),"aria-label":t.name,title:t.name,className:`w-9 h-9 rounded-full shrink-0 transition-all relative cursor-pointer outline-offset-2 ${n?`outline-2 outline-accent scale-110 z-10`:`opacity-80 outline-0 hover:opacity-100 hover:outline-2 hover:outline-foreground/25 hover:scale-105`}`,style:r?{background:`linear-gradient(135deg, #ffffff 0%, #ffffff 50%, #000000 50%, #000000 100%)`}:{backgroundImage:`linear-gradient(135deg, ${t.preview[0]}, ${t.preview[1]})`}},t.name)})})]}),(0,s.jsx)(Kr,{title:`Brand and colours`,onReset:()=>k(`Reset the colours?`,`The brand colour, the text and the two backgrounds in ${r.label.toLowerCase()} go back to how they started. Nothing else changes.`,()=>j(e,qr))}),(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)(Ur,{over:c,label:`Brand colour`,hint:`Links, highlights and the main buttons. Panels follow it too.`,value:i.accent||a.accent||`#7c3aed`,onChange:t=>O(e,t)}),(0,s.jsx)(Ur,{over:c,label:`Text colour`,hint:`Primary typography colour used across the app.`,value:i.foreground||a.foreground||`#111827`,onChange:t=>E(e,{foreground:t})}),(0,s.jsx)(Ur,{over:c,label:`Page background`,hint:`Main background canvas colour under all content.`,value:i.background||a.background||`#ffffff`,onChange:t=>E(e,{background:t})}),(0,s.jsx)(Ur,{over:c,label:`Second background`,hint:`The colour the page background fades into.`,value:i.backgroundSecondary||a.backgroundSecondary||`#f9fafb`,onChange:t=>E(e,{backgroundSecondary:t})}),(0,s.jsx)(Ur,{over:c,label:`Notification dot`,hint:`Colour applied to notification badging.`,value:i.notificationIconColor||i.accent||a.notificationIconColor||`#7c3aed`,onChange:t=>E(e,{notificationIconColor:t})}),(0,s.jsx)(Wr,{label:`Heading colours`,hint:`The colours big headings fade through.`,value:i.textGradient||a.textGradient,onChange:t=>E(e,{textGradient:t})})]}),(0,s.jsx)(Kr,{title:`Buttons`,onReset:()=>k(`Reset the buttons?`,`Every button colour in ${r.label.toLowerCase()} goes back to how it started. Nothing else changes.`,()=>j(e,Jr))}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-3 items-start`,children:[(0,s.jsx)(Wr,{label:`Button colours`,hint:`The colours your main buttons fade through.`,value:i.buttonGradient||a.buttonGradient,onChange:t=>E(e,{buttonGradient:t})}),(0,s.jsx)(Wr,{label:`Button colours on hover`,hint:`How a main button looks under the pointer.`,value:i.buttonHoverGradient||a.buttonHoverGradient,onChange:t=>E(e,{buttonHoverGradient:t})}),(0,s.jsx)(Ur,{over:c,label:`Button text`,hint:`The writing on your main buttons.`,value:i.buttonText||a.buttonText||`#ffffff`,onChange:t=>E(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)(Ur,{over:c,label:`Quiet button fill`,value:i.secondaryButton?.bg||a.secondaryButton?.bg||`rgba(0, 0, 0, 0.03)`,onChange:t=>D(e,{bg:t})}),(0,s.jsx)(Ur,{over:c,label:`Quiet button edge`,value:i.secondaryButton?.border||a.secondaryButton?.border||`rgba(0, 0, 0, 0.06)`,onChange:t=>D(e,{border:t})}),(0,s.jsx)(Ur,{over:c,label:`Quiet button text`,value:i.secondaryButton?.text||a.secondaryButton?.text||`#111827`,onChange:t=>D(e,{text:t})})]})]}),(0,s.jsx)(Kr,{title:`Panels and highlights`,onReset:()=>k(`Reset the panels?`,`Panels, edges, the focus glow and text highlighting in ${r.label.toLowerCase()} go back to how they started. Nothing else changes.`,()=>j(e,Yr))}),(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)(Ur,{over:c,label:`Panel fill`,hint:`Background colour of cards and panels.`,value:i.panelBg||a.panelBg||`rgba(255, 255, 255, 0.70)`,onChange:t=>E(e,{panelBg:t})}),(0,s.jsx)(Ur,{over:c,label:`Panel edge`,hint:`Borders of panels, inputs and dropdowns.`,value:i.panelBorder||a.panelBorder||`rgba(0, 0, 0, 0.08)`,onChange:t=>E(e,{panelBorder:t})}),(0,s.jsx)(Ur,{over:c,label:`Focus glow`,hint:`The glow around the box someone is typing in.`,value:i.glowColor||a.glowColor||`rgba(124, 58, 237, 0.30)`,onChange:t=>E(e,{glowColor:t})}),(0,s.jsx)(Ur,{over:c,label:`Highlight`,hint:`The colour behind text someone has selected.`,value:i.selectionBg||a.selectionBg||`rgba(124, 58, 237, 0.30)`,onChange:t=>E(e,{selectionBg:t})}),(0,s.jsx)(Ur,{over:c,label:`Highlighted text`,hint:`The colour of the selected text itself.`,value:i.selectionText||a.selectionText||`#ffffff`,onChange:t=>E(e,{selectionText:t})})]})]},e)};return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,s.jsx)(ce,{children:`Theme`}),(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`}),`/theme`]})]}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,s.jsx)(de,{}),(0,s.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-5 md:p-8 shadow-2xl relative bg-background flex flex-col min-h-[600px]`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,s.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-[17px] sm:text-xl font-extrabold text-foreground tracking-tight`,children:p===`change`?`Change it with your assistant`:`Design it with your assistant`}),(0,s.jsxs)(`p`,{className:`text-[12.5px] sm:text-[13.5px] font-medium text-foreground/55 mt-1 sm:mt-1.5`,children:[(0,s.jsx)(`span`,{className:`sm:hidden`,children:`Fill these in for your assistant.`}),(0,s.jsx)(`span`,{className:`max-sm:hidden`,children:p===`change`?`Say what to change, then copy the sentence below into your assistant’s chat. Nothing you do not mention is touched.`:`Fill these in, then copy the sentence below into your assistant’s chat.`})]})]}),(0,s.jsxs)(`div`,{className:`shrink-0 flex items-center gap-2`,children:[(0,s.jsx)(Q,{icon:t.y,compact:!0,title:p===`change`?`Design the whole look instead`:`Change the look you already have`,className:p===`change`?`text-accent border-accent/40 bg-accent/10 max-sm:border-transparent max-sm:bg-accent/10`:``,onClick:()=>m(p===`change`?`design`:`change`),children:`Edit with AI`}),(0,s.jsx)(Q,{icon:t.F,tone:`danger`,compact:!0,busy:b,title:`Start the whole look again`,onClick:()=>k(`Start the whole look again?`,`Every colour and every corner goes back to how it was the day you installed, and your answers in the assistant section above clear too. This cannot be undone.`,N),children:`Start again`})]})]}),(0,s.jsx)(it,{label:`Logo`,hint:`The picture in the top bar.`,value:d.logoUrl||``,onChange:e=>h(`logoUrl`,e),tips:ot}),(0,s.jsx)(it,{label:`Browser tab icon`,hint:`The tiny picture on the browser tab.`,value:d.faviconUrl||``,onChange:e=>h(`faviconUrl`,e),tips:st}),(0,s.jsx)(Oe,{label:`App name`,hint:`It goes in the top bar and on the browser tab.`,value:d.appName||``,onChange:e=>h(`appName`,e),placeholder:`Bright Studio`}),(0,s.jsx)(je,{label:`How the site opens`,hint:`Light, dark, or whichever one the visitor already uses on their device.`,value:d.defaultTheme||`system`,onChange:e=>h(`defaultTheme`,e||`system`),allowEmpty:!1,options:[{value:`system`,label:`Whatever their device uses`},{value:`light`,label:`Always light`},{value:`dark`,label:`Always dark`}]}),p===`change`?(0,s.jsx)(Ae,{label:`What would you like changed?`,hint:`Name just the parts you want moved. Everything else stays as it is.`,value:d.changes||``,onChange:e=>h(`changes`,e),placeholder:`Make the buttons a softer green, and warm up the page background a little. Leave the cards as they are.`}):(0,s.jsx)(Ae,{label:`What look would you like?`,hint:`What you do, who it is for, and the feeling you are after.`,value:d.brief||``,onChange:e=>h(`brief`,e),placeholder:`A calm, modern look for a small physiotherapy clinic. Soft greens, lots of white space, nothing shouty. Rounded corners.`}),(0,s.jsx)(tt,{title:`Copy this to your assistant`,prompt:p===`change`?ei(d):$r(d),locked:!!ii(d,p),onCopied:p===`change`?void 0:()=>m(`change`)}),(0,s.jsxs)(`p`,{className:`text-[11.5px] text-foreground/45 font-medium leading-snug px-1`,children:[`Uploads are kept on your`,` `,(0,s.jsx)(c.Link,{to:`/assets`,className:`text-accent font-bold hover:underline`,children:`Assets page`}),` `,`too — edit the fields and copy the sentence again any time.`]})]}),(0,s.jsxs)(`div`,{className:`mt-10 pt-8 border-t border-[var(--panel-border)]/50 mb-5 flex items-start justify-between gap-3`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-[17px] sm:text-xl font-extrabold text-foreground tracking-tight`,children:`Change it by hand`}),(0,s.jsx)(`p`,{className:`text-[12.5px] sm:text-[13.5px] font-medium text-foreground/55 mt-1 sm:mt-1.5`,children:`One setting at a time. Changes show up straight away and save themselves.`})]}),(0,s.jsx)(`div`,{className:`shrink-0 flex items-center gap-2 pt-1`,children:(0,s.jsx)(Pe,{saving:g,savedAt:v})})]}),l?(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,s.jsxs)(Ee,{icon:t.It,title:`Name and how it opens`,description:`What your site is called, and whether it opens light or dark.`,defaultOpen:!1,actions:(0,s.jsx)(Q,{icon:t.F,compact:!0,title:`Reset the name and how it opens`,onClick:()=>k(`Reset the name?`,`The name and the opening mode go back to how they started. Your logo and your browser tab icon are left alone.`,()=>A(ai)),children:`Reset`}),children:[(0,s.jsx)(Oe,{label:`Site name`,hint:`The name people see in the top bar and on the browser tab.`,value:l.appName||``,onChange:e=>T(`appName`,e),placeholder:`Your AI Firebase`}),(0,s.jsx)(it,{label:`Logo`,hint:`The picture in the top bar — changes straight away.`,value:l.logoUrl||``,onChange:e=>T(`logoUrl`,e),tips:ot,action:(l.logoUrl||``)===(o.logoUrl||``)?void 0:(0,s.jsx)(Q,{icon:t.F,onClick:()=>T(`logoUrl`,o.logoUrl||``),children:`Put the original back`})}),(0,s.jsx)(it,{label:`Browser tab icon`,hint:`The tiny picture on the browser tab — changes straight away.`,value:l.faviconUrl||``,onChange:e=>T(`faviconUrl`,e),tips:st,action:(l.faviconUrl||``)===(o.faviconUrl||``)?void 0:(0,s.jsx)(Q,{icon:t.F,onClick:()=>T(`faviconUrl`,o.faviconUrl||``),children:`Put the original back`})}),(0,s.jsx)(je,{label:`How the site opens`,hint:`Light, dark, or whichever one the visitor already uses on their device.`,value:l.defaultTheme||`system`,onChange:e=>T(`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=>T(`showThemeToggle`,e)})]}),jr.map(e=>P(e.key)),(0,s.jsxs)(Ee,{icon:t.k,title:`Corners`,description:`How rounded everything looks.`,defaultOpen:!1,actions:(0,s.jsx)(Q,{icon:t.F,compact:!0,title:`Reset the corners`,onClick:()=>k(`Reset the corners?`,`Every corner goes back to how it started.`,()=>A(oi)),children:`Reset`}),children:[(0,s.jsx)(je,{label:`Rounding`,hint:`Keep the rounding we ship with, or set each corner yourself.`,value:l.cornerRounding||`default`,onChange:e=>T(`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)(Gr,{label:`Buttons`,hint:`How round every button is.`,value:l.cornerRadii?.buttonRadius??.75,onChange:e=>T(`cornerRadii`,{...l.cornerRadii||{},buttonRadius:e})}),(0,s.jsx)(Gr,{label:`Boxes people type in`,hint:`Form fields and search boxes.`,value:l.cornerRadii?.inputRadius??.75,onChange:e=>T(`cornerRadii`,{...l.cornerRadii||{},inputRadius:e})}),(0,s.jsx)(Gr,{label:`Cards`,hint:`The panels your content sits on.`,value:l.cornerRadii?.cardRadius??1.5,onChange:e=>T(`cornerRadii`,{...l.cornerRadii||{},cardRadius:e})}),(0,s.jsx)(Gr,{label:`Pop-ups`,hint:`Dialogs and confirmation boxes.`,value:l.cornerRadii?.modalRadius??2.5,onChange:e=>T(`cornerRadii`,{...l.cornerRadii||{},modalRadius:e})})]})]})]}):(0,s.jsx)(`div`,{className:`flex items-center justify-center flex-1 text-foreground/40 py-16`,children:(0,s.jsx)(t.K,{className:`w-6 h-6 animate-spin text-accent`})})]})]}),(0,s.jsx)(ve,{isOpen:!!S,title:S?.title||``,message:S?.message||``,confirmText:`Reset`,cancelText:`Keep it`,isProcessing:b,onCancel:()=>C(null),onConfirm:()=>{S?.apply(),C(null)}})]})}function ci({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 li=`w-full block py-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors`,ui=`No access`,di=`You do not have access to view this page. If you think you should, ask whoever runs this app.`,fi=()=>(0,s.jsx)(ci,{tone:`amber`,title:ui,message:di,action:(0,s.jsx)(c.Link,{to:`/dashboard`,className:li,children:`Back to dashboard`})}),pi=fi,mi=fi,hi={route:`/page_1`,pageName:`New Page`,pageTitle:`My New Page`,template:`none`,form:``},gi={tabName:`New Page`,iconName:``,route:`/new-page`,tabTitle:`Your Page`,template:`none`,form:``},_i={tabName:`New Admin Page`,iconName:``,route:`/new-admin-page`,tabTitle:`Admin Page`,template:`none`,form:``},vi={tabName:`New Team Page`,iconName:``,route:`/new-team-page`,tabTitle:`Team Page`,template:`none`,form:``},yi=[{id:`home`,title:`Home`,path:`/`,type:`public`,isSystem:!0,enabled:!0},{id:`contact`,title:`Contact`,path:`/contact`,type:`public`,isSystem:!0,enabled:!0},{id:`guide`,title:`Guide`,path:`/guide`,type:`public`,isSystem:!0,enabled:!0},{id:`templates`,title:`Templates`,path:`/templates`,type:`public`,isSystem:!0,enabled:!0},{id:`setup`,title:`Setup`,path:`/setup`,type:`public`,isSystem:!0,enabled:!0},{id:`dashboard`,title:`Dashboard`,path:`/dashboard`,type:`user`,isSystem:!0,enabled:!0},{id:`support`,title:`Support`,path:`/support`,type:`user`,isSystem:!0,enabled:!0},{id:`profile`,title:`Profile`,path:`/profile`,type:`user`,isSystem:!0,enabled:!0}],bi=new Set([`home`,`dashboard`,`profile`]),xi=e=>[...e,...yi.filter(t=>!e.some(e=>e.id===t.id))],Si={public:`Anyone`,user:`Signed-in users`,internal:`Your team`,admin:`Admins only`},Ci=e=>e.draft?`draft`:e.hidden?`hidden`:`live`,wi={draft:`Draft`,live:`Live`,hidden:`Hidden`},Ti={draft:`Nothing is saved yet. Give it a web address and the page is created.`,live:`This page is live at its web address and listed in the menu.`,hidden:`This page still exists at its web address, but it is out of the menu.`},Ei=e=>(e||``).trim().toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9_-]/g,``),Di=(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},Oi=()=>Object.fromEntries(F()),ki=(e,t=!1)=>{let n={};for(let[r,i]of Object.entries(Oi())){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`:D(o.pageType),isSystem:!1,enabled:o.enabled!==!1,fromFile:!0})}return n};function Ai({value:e,onChange:n,busy:r}){return(0,s.jsx)(`div`,{className:`shrink-0`,onClick:e=>e.stopPropagation(),children:(0,s.jsx)(t.s,{compact:!0,portal:!0,direction:`auto`,className:`console-select`,ariaLabel:`Who can open this page`,value:e,disabled:r,onChange:e=>n(e),options:b.map(e=>({value:e,label:Si[e]}))})})}var ji=`Add it here — its web address, a name, and what you would like to see on it — then copy the sentence for your assistant.`,Mi=`Add it here, then copy the sentence for your assistant.`,Ni=[{value:`none`,label:`From scratch`},{value:`board`,label:`Board`},{value:`table`,label:`Table`},{value:`calendar`,label:`Calendar`},{value:`drive`,label:`Files`}],Pi=[`board`,`table`,`calendar`,`drive`],Fi={board:{is:`a board`,keeps:`its board frame and the card editor that is already in it`,open:`actions.openInlineEditor(columnId)`},table:{is:`a table`,keeps:`its table frame and the row and column controls that are already in it`,open:`actions.addRow()`},calendar:{is:`a calendar`,keeps:`its calendar frame — the month heading, Today, and the arrows — and the add-event form that is already in it`,open:`actions.openAddModal()`},drive:{is:`a file library`,keeps:`its file frame and the upload box that is already in it`,open:`openUploadModal()`}},Ii=e=>{let t=Fi[e];return t?`This page already works as ${t.is} and it stays one: it keeps ${t.keeps}, already styled to match my app. Design only what fills it, and open the one that is already there with ${t.open}. Never build your own add, edit or upload form on this page — one exists, and yours will not match.`:``},Li=e=>(e||``).split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``),Ri=(e,t)=>t?.contentKey||t?.tabName||t?.pageName||t?.pageId||e.title,zi=(e,t)=>`src/your-ai-workflow-firebase-os/microcomponents/${Li(Ri(e,t))||`Page`}Content.tsx`,Bi=(e,t)=>{let n=String(t?.route||``).trim();return n?n.startsWith(`/`)?n:`/`+n:e.path||``},Vi=(e,t)=>Bi(e,t).replace(/^\/+/,``)?String(t?.brief||``).trim()?da(t)?`Say what the form should ask for, and this sentence is ready to copy.`:``:`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.`,Hi=e=>{let t=e=>e.map(e=>({url:String(e?.url||``).trim(),where:String(e?.where||``).trim()})).filter(e=>e.url);if(Array.isArray(e?.images))return t(e.images);let n=String(e?.imageUrl||``).trim();return n?[{url:n,where:String(e?.imageWhere||``).trim()}]:[]},Ui=e=>Array.isArray(e?.images)?e.images.map(e=>({url:String(e?.url||``),where:String(e?.where||``)})):Hi(e),Wi=e=>Hi(e).map(({url:e,where:t})=>t?`Use this picture of mine on the page: ${e} — where it goes: ${t}. Keep its proportions and give it a short description for screen readers. Do not swap it for a placeholder or a picture of your own.`:`Use this picture of mine on the page: ${e} — put it where it works best in your design, keep its proportions, and give it a short description for screen readers. Do not swap it for a placeholder or a picture of your own.`),Gi=e=>{let t=String(e?.pageWish||``).trim(),n=String(e?.pageAdd||``).trim(),r=String(e?.pageChange||``).trim(),i=String(e?.pageRemove||``).trim(),a=[];return t&&a.push(`Here is what I would like on the page: ${t}`),n&&a.push(`Add this: ${n}`),r&&a.push(`Change this: ${r}`),i&&a.push(`Take this off the page: ${i}`),a.push(...Wi(e)),a},Ki=e=>Gi(e).length>0,qi=(e,t)=>{let n=Bi(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=String(t?.formButton||``).trim(),l=String(t?.formSpot||``).trim();String(t?.formFields||``).trim();let u=t?.pageType?`private`:`public`,d=Li(Ri(e,t))||`Page`,f=d.replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase(),p=[`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: ${zi(e,t)}, with a default export. That file is what the page shows.`,`Then add two lines to src/your-ai-workflow-firebase-os/microcomponents/registry.ts so the app loads your file: import ${d}Content from './${d}Content'; and registerMicrocomponent('${f}', ${d}Content); — registerMicrocomponent is imported there from 'your-ai-workflow-firebase-os'. Never remove another page's lines from that file.`,`Make it match the rest of my app: style with the app’s own theme styles so it looks right in light and dark. Do not pick your own colors. Build it from the app’s own pieces — import { SectionHeading, Card, Button } from 'your-ai-workflow-firebase-os': section titles are SectionHeading, boxed sections are Card, buttons are Button — so nothing gets a look of its own. The design should be minimal, modern and clean and match the app.`,`Everything below the page heading is yours to design however you like — one clean column of sections using the full width. Never stack panels inside panels, never let sections overlap, and when the content grows tall let the page scroll.`];return Pi.includes(a)&&p.push(Ii(a)),o===`__new__`||t?.formIsNew?p.push(...Ji(t,u)):o&&(p.push(`Show my form ${ca(o)} on it with <ContactPopup formId='${o}' /> — never write a form by hand.`),c&&p.push(`The form opens from a button that says ${c} — make that button part of the page's design, not an afterthought.`),l&&p.push(`Where the form belongs on the page: ${l}`)),p.push(...Wi(t)),p.push(`Here is what I would like on it: ${s||`___`}`),p.join(`
19
19
  `)},Ji=(e,t)=>{let n=String(e?.form||``),r=n!==`__new__`&&n||la(e)||`page`,i=String(e?.formFields||``).trim(),a=String(e?.formButton||``).trim(),o=String(e?.formSpot||``).trim(),s=[`The page needs a form of its own. Create it as one more file, src/your-ai-workflow-firebase-os/configs/${r}Form.config.ts, the way my app's instructions describe a form, with systemName '${r}' and formType '${t}'. It should ask for: ${i||`___`}`,`Show that form on the page with <ContactPopup formId='${r}' /> — never build a form out of your own inputs.`];return a&&s.push(`The form opens from a button that says ${a} — make that button part of the page's design, not an afterthought.`),o&&s.push(`Where the form belongs on the page: ${o}`),s},Yi=(e,t=!1)=>Ki(e)?t&&!String(e?.formFields||``).trim()?`Say what the form should ask for, and this sentence is ready to copy.`:``:`Say what you would like added, changed or taken off this page, and this sentence is ready to copy.`,Xi=(e,t,n=!1)=>{let r=Bi(e,t),i=String(t?.tabName||t?.pageName||``).trim(),a=i===`New page`?``:i,o=Gi(t),s=t?.pageType?`private`:`public`,c=[`My app already has a page${a?` called ${a}`:``} at ${r}, and the file it shows already exists: ${zi(e,t)}.`,`Change that one file. Do not create a page, a web address, a settings file or a second content file, do not add or remove anything in registry.ts, and do not edit any other file.`,`Keep it matching the rest of my app: style with the app’s own theme styles so it looks right in light and dark. Do not pick your own colors. Anything new you draw uses the app’s own pieces — import { SectionHeading, Card, Button } from 'your-ai-workflow-firebase-os': section titles are SectionHeading, boxed sections are Card, buttons are Button.`,`Keep everything on the page that I have not asked you to change.`],l=Ii(String(t?.template||``));return l&&c.push(l),n&&c.push(...Ji(t,s)),c.push(...o.length?o:[`Here is what I would like changed: ___`]),c.join(`
20
20
  `)},Zi={home:{title:`Change the home page`,ask:`What would you like on the home page?`,example:`A big heading that says Bright Studio, a photo of the shop under it, and a Get in touch button.`,lead:[`My app already has a home page, and it is one file: src/your-ai-workflow-firebase-os/Home.tsx. Change that one file — do not create a page, a web address, a settings file or a HomeContent.tsx, and do not edit any other file.`,`Keep its named export exactly as it is: export function Home. Making it a default export breaks my site.`,`Keep it matching the rest of my app: style with the app’s own theme styles so it looks right in light and dark. Do not pick your own colors. Anything new you draw uses the app’s own pieces — import { SectionHeading, Card, Button } from 'your-ai-workflow-firebase-os': section titles are SectionHeading, boxed sections are Card, buttons are Button.`,`Keep everything on the page that I have not asked you to change.`]},contact:{title:`Change the contact page`,ask:`What would you like on the contact page?`,example:`A line saying we answer within a day, our opening hours, and the form under them.`,lead:[`My app already has a contact page at /contact and a contact form. Do not create a page, do not create a form, and do not change the questions the form asks.`,`Change what the page shows by writing one file: src/your-ai-workflow-firebase-os/microcomponents/ContactContent.tsx, with a default export. Then add two lines to src/your-ai-workflow-firebase-os/microcomponents/registry.ts: import ContactContent from './ContactContent'; and registerMicrocomponent('contact', ContactContent); — never remove another page's lines from that file.`,`Show my form with <ContactPopup formId='contact' /> — add isInline to build it into the page instead of opening it as a pop-up. Never build a form out of your own inputs.`,`Keep it matching the rest of my app: style with the app’s own theme styles so it looks right in light and dark. Do not pick your own colors. Anything new you draw uses the app’s own pieces — import { SectionHeading, Card, Button } from 'your-ai-workflow-firebase-os': section titles are SectionHeading, boxed sections are Card, buttons are Button.`,`Keep everything on the page that I have not asked you to change.`]},dashboard:{title:`Change the dashboard`,ask:`What would you like on the dashboard?`,example:`Three boxes across the top: bookings today, bookings this week, and unread messages.`,lead:[`My app already has a dashboard at /dashboard — the screen a signed-in person lands on. Do not create a page, a web address or a settings file for it, and do not touch src/App.tsx.`,`Fill it by writing one file: src/your-ai-workflow-firebase-os/microcomponents/DashboardContent.tsx, with a default export. Then add two lines to src/your-ai-workflow-firebase-os/microcomponents/registry.ts: import DashboardContent from './DashboardContent'; and registerMicrocomponent('dashboard', DashboardContent); — never remove another page's lines from that file.`,`It draws inside the dashboard’s own panel, under the welcome heading and the menu, so do not write a page heading, a menu or a page wrapper of your own.`,`Keep it matching the rest of my app: style with the app’s own theme styles so it looks right in light and dark. Do not pick your own colors. Anything new you draw uses the app’s own pieces — import { SectionHeading, Card, Button } from 'your-ai-workflow-firebase-os': section titles are SectionHeading, boxed sections are Card, buttons are Button.`]},support:{title:`Change the support page`,ask:`What would you like on the support page?`,example:`A short list of the questions we get asked most, above the form.`,lead:[`My app already has a support page at /support and a support form. Do not create a page, do not create a form, and do not change the questions the form asks.`,`Change what the page shows by writing one file: src/your-ai-workflow-firebase-os/microcomponents/SupportContent.tsx, with a default export. Then add two lines to src/your-ai-workflow-firebase-os/microcomponents/registry.ts: import SupportContent from './SupportContent'; and registerMicrocomponent('support', SupportContent); — never remove another page's lines from that file.`,`Show my form with <ContactPopup formId='support' /> — add isInline to build it into the page instead of opening it as a pop-up. Never build a form out of your own inputs.`,`Keep it matching the rest of my app: style with the app’s own theme styles so it looks right in light and dark. Do not pick your own colors. Anything new you draw uses the app’s own pieces — import { SectionHeading, Card, Button } from 'your-ai-workflow-firebase-os': section titles are SectionHeading, boxed sections are Card, buttons are Button.`,`Keep everything on the page that I have not asked you to change.`]}},Qi=(e,t)=>{let n=Zi[e];if(!n)return``;let r=Gi(t);return[...n.lead,...r.length?r:[`Here is what I would like on the page: ___`]].join(`
21
21
  `)},$i=(e,t)=>{let n=e=>{let{_uiKey:t,pageType:n,route:r,contentKey:i,...a}=e||{};return a},r=n(e),i=n(t),a=new Set([...Object.keys(r),...Object.keys(i)]),o=(e,t)=>e&&typeof e==`object`?JSON.stringify(e)===JSON.stringify(t):(e??``)===(t??``);for(let e of a)if(!o(r[e],i[e]))return!0;return!1},ea=(e,t)=>{let n=Oi(),r=n[e.id]||(t?.contentKey?n[String(t.contentKey)]:void 0)||Object.entries(n).find(([t,n])=>{let r=n.config||{},i=r.route?r.route.startsWith(`/`)?r.route:`/`+r.route:`/`+t;return!!e.path&&i===e.path})?.[1];return r?r.config||{}:null},ta=(e,t)=>{let{_uiKey:n,...r}=e||{};return Object.keys(r).length>0?{...r,pageType:t}:{pageType:t}},na=`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`,ra=`max-sm:hidden sm:inline-flex items-center gap-1.5 text-[11px] font-semibold text-foreground/45 border border-[var(--panel-border)] bg-foreground/[0.02] px-2 py-[3px] rounded-full`,ia={draft:`text-foreground/55 border-[var(--panel-border)] bg-foreground/[0.03]`,live:`text-emerald-500 border-emerald-500/25 bg-emerald-500/[0.07]`,hidden:`text-foreground/45 border-[var(--panel-border)]/70 bg-transparent`},aa={draft:`bg-foreground/30`,live:`bg-emerald-500 shadow-[0_0_5px] shadow-emerald-500/60`,hidden:`bg-foreground/25`};function oa({status:e}){return(0,s.jsxs)(`span`,{title:Ti[e],className:`inline-flex items-center gap-1.5 text-[11px] font-semibold px-2.5 py-[3px] rounded-full border ${ia[e]}`,children:[(0,s.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 ${aa[e]}`}),wi[e]]})}var sa=e=>{let t=typeof window<`u`?window.location.host:``;return t?`${t}${e}`:e},ca=e=>e.replace(/[_-]+/g,` `).replace(/^./,e=>e.toUpperCase()),la=e=>String(e?.contentKey||``).toLowerCase().replace(/-+/g,`_`),ua=e=>String(e?.form||``)===`__new__`||!!e?.formIsNew,da=e=>ua(e)&&!String(e?.formFields||``).trim(),fa=(e,t)=>{let n=String(t?.form||``).trim(),r=n===`__new__`?la(t):n,i=String(t?.formChange||``).trim();return[`My app has a form on the page at ${Bi(e,t)} — its id is '${r}'.`,`Change only that form, like this: ${i||`___`}`,`Change it where it is defined, keeping its id exactly '${r}' — do not make a second form, and do not touch the page or any other file.`].join(`
22
- `)};function pa({images:e,onChange:n}){let i=e.length?e:[{url:``,where:``}],[a,o]=(0,r.useState)({}),c=(e,t)=>n(i.map((n,r)=>r===e?{...n,...t}:n)),l=e=>n(i.length>1?i.filter((t,n)=>n!==e):[{url:``,where:``}]);return(0,s.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[i.map((e,t)=>(0,s.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,s.jsx)(ot,{label:t===0?`A picture for this page`:`Picture ${t+1}`,hint:t===0?`Optional — a picture for your assistant to use on the page.`:void 0,value:e.url,onChange:e=>e?c(t,{url:e}):l(t),onBusyChange:e=>o(n=>({...n,[t]:e})),tips:t===0?st:void 0}),(!!e.url||a[t])&&(0,s.jsxs)(`div`,{className:`flex gap-3 sm:gap-3.5`,children:[(0,s.jsx)(`div`,{"aria-hidden":!0,className:`w-0.5 shrink-0 self-stretch rounded-full bg-[var(--panel-border)] ml-1.5 mb-1`}),(0,s.jsx)(Ae,{label:`What is this picture for?`,hint:`Say where it goes, in your own words — your assistant reads this and puts it there.`,value:e.where,onChange:e=>c(t,{where:e}),placeholder:`Across the top, behind the heading`})]})]},t)),!!i[i.length-1].url&&(0,s.jsx)(Q,{icon:t.L,className:`self-start`,onClick:()=>n([...i,{url:``,where:``}]),children:`Add another picture`})]})}function ma({page:e,config:t,forms:n,saving:i,onSave:a,addressTaken:o,actions:c,footer:l,isNew:u,editing:d}){let f=e.type===`public`,p=f?`pageName`:`tabName`,m=f?`pageTitle`:`tabTitle`,[h,g]=(0,r.useState)(()=>({...t||{}})),[_,v]=(0,r.useState)(``),y=(e,t)=>g(n=>({...n,[e]:t})),b=e=>{g(t=>({...t,...e}));let n={...t||{},...h,...e};delete n._uiKey,a(n)},x=e=>{(t||{})[e]!==h[e]&&b({[e]:h[e]})},S=String(h.route??``).replace(/^\/+/,``),C=()=>{let n=Ei(S);if(!n){v(`Give this page a web address, for example pricing`);return}if(o(e.id,n)){v(`Another page already lives at this address. Pick a different one.`);return}v(``),n===String(t?.route??``).replace(/^\/+/,``)?y(`route`,`/`+n):b({route:`/`+n})},w=Ei(S),T={...t||{},...h,route:w?`/`+w:``,contentKey:t?.contentKey||w||void 0},E=String(h.form??``),D=!!h.formIsNew||E===`__new__`,[O]=(0,r.useState)(()=>!!String(t?.form??``).trim()),k=!!d&&O&&!!E,A=D&&!k;return(0,s.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-5`,children:[(0,s.jsx)(Ae,{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. /photos`,prefix:`/`,value:S,onChange:e=>{y(`route`,e),_&&v(``)},onBlur:C,error:_,placeholder:`photos`}),(0,s.jsx)(Ae,{label:f?`Name in the menu`:`Name in the dashboard`,hint:f?`What visitors see in the site menu.`:`What people see in the dashboard menu.`,value:h[p]??``,onChange:e=>y(p,e),onBlur:()=>x(p),placeholder:`Photos`}),(0,s.jsx)(Ae,{label:`Page heading`,hint:`The big heading people read at the top of the page.`,value:h[m]??``,onChange:e=>y(m,e),onBlur:()=>x(m),placeholder:`Our photos`}),!f&&(0,s.jsx)(Je,{label:`Icon`,hint:`Shown next to the name in the dashboard menu.`,value:h.iconName??``,onChange:e=>b({iconName:e})}),!f&&!d&&(0,s.jsx)(Ne,{label:`Starting layout`,hint:`What the page starts as. Your assistant fills in the rest when you ask.`,value:Ni.some(e=>e.value===h.template)?h.template:`none`,onChange:e=>b({template:e}),options:Ni,allowEmpty:!1}),!k&&(0,s.jsx)(Ne,{label:`Form`,hint:`Answers arrive in your Inbox. Your assistant builds it with the page.`,value:D?`__new__`:E,onChange:e=>b(e===`__new__`?{form:`__new__`}:{form:e,formIsNew:!1}),options:[{value:`__new__`,label:`A new form made for this page`},...n.map(e=>({value:e,label:ca(e)}))],placeholder:`No form`}),A&&(0,s.jsx)(Me,{label:`What should the form ask?`,hint:`The questions in your own words — e.g. name, email, budget, what they need.`,value:h.formFields??``,onChange:e=>y(`formFields`,e),onBlur:()=>x(`formFields`),placeholder:`Name, email, and what they would like to book`}),(A||!d&&!!E)&&(0,s.jsx)(Ae,{label:`The button that opens it`,hint:`What the button that opens the form says.`,value:h.formButton??``,onChange:e=>y(`formButton`,e),onBlur:()=>x(`formButton`),placeholder:`Get in touch`}),(A||!d&&!!E)&&(0,s.jsx)(Ae,{label:`Where the form goes`,hint:`Optional — where on the page it belongs, in your own words.`,value:h.formSpot??``,onChange:e=>y(`formSpot`,e),onBlur:()=>x(`formSpot`),placeholder:`At the bottom, after the packages`}),k&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Me,{label:`Change the form`,hint:`Say what should change about the form, then copy the sentence below.`,value:h.formChange??``,onChange:e=>y(`formChange`,e),onBlur:()=>x(`formChange`),placeholder:`Add a phone number question after the email one`}),(0,s.jsx)(rt,{compact:!0,title:`Copy this to change the form`,prompt:fa(e,T),locked:!String(h.formChange??``).trim()})]}),d?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Me,{label:`What would you like to add?`,hint:`Anything new for the page. Leave it empty if nothing is missing.`,value:h.pageAdd??``,onChange:e=>y(`pageAdd`,e),onBlur:()=>x(`pageAdd`),placeholder:`A section with three reviews from my customers.`}),(0,s.jsx)(Me,{label:`What would you like to change?`,hint:`Your assistant edits the page you have — anything you do not mention stays.`,value:h.pageChange??``,onChange:e=>y(`pageChange`,e),onBlur:()=>x(`pageChange`),placeholder:`Show the albums three to a row, and put a search box above them.`}),(0,s.jsx)(Me,{label:`What would you like to remove?`,hint:`Anything the page should stop showing.`,value:h.pageRemove??``,onChange:e=>y(`pageRemove`,e),onBlur:()=>x(`pageRemove`),placeholder:`The prices — I would rather people ask.`}),f&&(0,s.jsx)(pa,{images:Ui(h),onChange:e=>b({images:e})}),!!String(h.brief??``).trim()&&(0,s.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)] px-4 py-3`,children:[(0,s.jsx)(`p`,{className:`text-[11px] font-bold uppercase tracking-widest text-foreground/40 mb-1.5`,children:`What this page was built from`}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed whitespace-pre-line break-words [overflow-wrap:anywhere]`,children:String(h.brief)})]})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Me,{label:`What would you like to see on this page?`,hint:`What your assistant builds — it goes into the sentence below.`,value:h.brief??``,onChange:e=>y(`brief`,e),onBlur:()=>x(`brief`),placeholder:`A photo gallery where I can upload pictures, put them in albums and open one full screen.`}),f&&(0,s.jsx)(pa,{images:Ui(h),onChange:e=>b({images:e})})]}),l?.(T,{definingForm:A}),(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)(Ie,{saving:i}),(0,s.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 ml-auto`,children:c})]})]})}function ha({page:e,answers:n,saving:i,resetting:a,onSave:o,onReset:c,onCopied:l}){let[u,d]=(0,r.useState)(()=>({...n||{}})),f=(e,t)=>d(n=>({...n,[e]:t})),p=e=>{(n||{})[e]!==u[e]&&o({[e]:u[e]})},m={...n||{},...u},h=Zi[e.id],g=!Ki(m);return(0,s.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-5`,children:[(0,s.jsx)(Me,{label:h.ask,hint:`In your own words. Everything you do not mention stays as it is.`,value:u.pageWish??``,onChange:e=>f(`pageWish`,e),onBlur:()=>p(`pageWish`),placeholder:h.example}),e.type===`public`&&(0,s.jsx)(pa,{images:Ui(u),onChange:e=>{f(`images`,e),o({images:e})}}),(0,s.jsx)(rt,{compact:!0,title:h.title,prompt:Qi(e.id,m),locked:g,onCopied:l}),(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pt-1`,children:[(0,s.jsx)(`div`,{children:Ki(m)&&c&&(0,s.jsx)(Q,{icon:t.F,tone:`danger`,compact:!0,title:`Start again`,busy:a,onClick:c,children:`Reset`})}),(0,s.jsx)(Ie,{saving:i})]})]})}function ga(){let{userRole:e}=N(),n=(0,c.useLocation)(),[a,o]=(0,r.useState)(()=>{try{if(typeof window<`u`){let e=localStorage.getItem(`fbos_swr_pages`);if(e)return xi(JSON.parse(e))}}catch{}return yi}),[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)(null),m=e=>{let t=typeof window<`u`?window.location.origin:``;navigator.clipboard?.writeText(`${t}${e.path}`),p(e.id),setTimeout(()=>p(null),2e3)},[h,g]=(0,r.useState)(null),[_,v]=(0,r.useState)(!1),[y,b]=(0,r.useState)(()=>{try{if(typeof window<`u`){let e=localStorage.getItem(`fbos_swr_page_configs`);if(e)return JSON.parse(e)}}catch{}return{}}),[x,S]=(0,r.useState)({}),[C,w]=(0,r.useState)(()=>{try{let e=localStorage.getItem(`fbos_swr_page_briefs`);if(e)return JSON.parse(e)}catch{}return{}}),T=(0,r.useRef)(C);(0,r.useEffect)(()=>{T.current=C},[C]),(0,r.useEffect)(()=>(0,i.onSnapshot)((0,i.doc)(t.Ht,`sys_configs`,`page_briefs`),e=>{let t=e.exists()?e.data():{};w(t);try{localStorage.setItem(`fbos_swr_page_briefs`,JSON.stringify(t))}catch{}},()=>{}),[]);let E=async(e,n)=>{let r={...T.current[e]||{},...n};w(t=>({...t,[e]:r})),S(t=>({...t,[e]:!0}));try{await(0,i.setDoc)((0,i.doc)(t.Ht,`sys_configs`,`page_briefs`),{[e]:r},{merge:!0})}catch(e){console.error(`Could not save the page answers`,e)}S(t=>({...t,[e]:!1}))},[O,k]=(0,r.useState)({}),[A,j]=(0,r.useState)({}),[M,P]=(0,r.useState)(null),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)(!1),z=(0,r.useRef)(null);(0,r.useEffect)(()=>{function e(e){z.current&&!z.current.contains(e.target)&&v(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let[B,ee]=(0,r.useState)(new Set),[V,te]=(0,r.useState)(new Set),[H,U]=(0,r.useState)([]),[W,G]=(0,r.useState)([]),K=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.Ht,`sys_configs`,`page_order`),e=>{let t=K(e.exists()&&e.data().order||[]);U(t),ee(new Set(t.filter(e=>e.hidden).map(e=>e.id)))}),n=(0,i.onSnapshot)((0,i.doc)(t.Ht,`sys_configs`,`tab_order`),e=>{let t=K(e.exists()&&e.data().order||[]);G(t),te(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 q=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=q.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.Ht,`sys_pages`)),(0,i.getDocs)((0,i.collection)(t.Ht,`sys_tabs`))]),r=[`home`,`drive`,`assets`,`contact`,`guide`,`templates`,`setup`,`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=D(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=Oi(),l={...ki(!0,!0),...ki(!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=xi(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}),b(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[J,Y]=(0,r.useState)([`contact`]),[ne,re]=(0,r.useState)([`support`]);(0,r.useEffect)(()=>{let e=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},n={...t.f,...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.Ht,`sys_forms`)).then(e=>{e.docs.forEach(e=>{e.data().formType===`private`?a.add(e.id):r.add(e.id)}),Y(Array.from(r)),re(Array.from(a))}).catch(e=>{console.warn(`Failed fetching sys_forms in PagesAdmin:`,e),Y(Array.from(r)),re(Array.from(a))})},[]);let ie=async(e,n,r)=>{if(n.route&&!n.route.startsWith(`/`)&&(n.route=`/`+n.route),!String(n.route||``).replace(/^\/+/,``).trim()){b(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},f.form===`__new__`&&(f.form=la(f),f.formIsNew=!0,n={...n,form:f.form,formIsNew:!0}),S(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.Ht,l,e))}catch{}await(0,i.setDoc)((0,i.doc)(t.Ht,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}`)),b(t=>{let r={...t};return r[p]=n,delete r[e],r});let r=c===`public`,a=r?`page_order`:`tab_order`,s=r?H:W;if(!s.some(e=>e.id===p)){let n=[...s.filter(t=>t.id!==e),{id:p,hidden:!1}];try{await(0,i.setDoc)((0,i.doc)(t.Ht,`sys_configs`,a),{order:n})}catch(e){console.error(`Failed to update tab order:`,e)}}}else await(0,i.setDoc)((0,i.doc)(t.Ht,l,e),f),b(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(()=>{S(t=>({...t,[e]:!1,[p]:!1}))},500)}},ae=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:``,formFields:``,formButton:``,formSpot:``,brief:``}:{route:``,tabName:``,tabTitle:``,iconName:``,template:`none`,form:``,formFields:``,formButton:``,formSpot:``,brief:``,pageType:e};o(e=>[...e,n]),b(e=>({...e,[t]:r})),u(t),v(!1),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView?.({behavior:`smooth`,block:`center`})},100)},X=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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:(0,s.jsx)(fi,{})});let oe=async(e,n,r)=>{let s=r===`public`,c=s?`page_order`:`tab_order`,l=s?H:W,u=(s?B:V).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.Ht,`sys_configs`,c),{order:d})},Z=e=>!!e.fromFile&&(e.type===`public`?H:W).some(t=>t.id===e.id&&t.removed),se=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)),S(t=>({...t,[e.id]:!0}));let a=ta(y[e.id],n);try{await(0,i.setDoc)((0,i.doc)(t.Ht,`sys_tabs`,e.id),a,{merge:!0}),b(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{S(t=>({...t,[e.id]:!1}))}},le=(e,t)=>{if(!t){if(X({id:e})){o(t=>t.filter(t=>t.id!==e)),b(t=>{let n={...t};return delete n[e],n}),l===e&&u(null);return}P(e)}},ue=async()=>{if(M){R(!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===M),h=m?.type===`public`?`sys_pages`:`sys_tabs`;if(h===`sys_tabs`&&m){let a=y[M];if(!a)try{let e=await s(i(t.Ht,`sys_tabs`,M));e.exists()&&(a=e.data())}catch{}let o=(a?.tabName||a?.pageId||M).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.Ht,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.Wt,`${o.prefix}/${decodeURIComponent(s)}`)).catch(()=>{});let l=await r(c(n(t.Ht,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.Ht,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.Wt,`${i}/${decodeURIComponent(n)}`)).catch(()=>{})}catch{}await e(n.ref)}))}catch{}})());await Promise.all(m)}await e(i(t.Ht,h,M));let g=h===`sys_pages`?`page_order`:`tab_order`,_=h===`sys_pages`?H:W,{setDoc:v}=await import(`firebase/firestore`),b=m?.fromFile?[..._.filter(e=>e.id!==M),{id:M,hidden:!0,removed:!0}]:_.filter(e=>e.id!==M);await v(i(t.Ht,`sys_configs`,g),{order:b}),o(e=>e.filter(e=>e.id!==M)),l===M&&u(null)}catch(e){console.error(`Error deleting page:`,e)}R(!1),P(null)}},fe=async(e,n)=>{if(e.isSystem)return;let r=e.type===`public`,o=r?`page_order`:`tab_order`,s=[...r?H:W];a.filter(e=>e.type===`public`===r&&!e.isSystem&&!s.some(t=>t.id===e.id)).forEach(e=>s.push({id:e.id,hidden:!1}));let c=Di(s,e.id,n,r?`home`:void 0);if(c){r?U(c):G(c);try{await(0,i.setDoc)((0,i.doc)(t.Ht,`sys_configs`,o),{order:c})}catch(e){console.error(`Failed to reorder pages:`,e)}}},pe=(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(y[r.id]?.route??r.path??``).replace(/^\/+/,``).toLowerCase();return i!==``&&i===t||r.id===n})},me=e=>e===`admin`?_i:e===`internal`?vi:e===`public`?hi:gi,he=async()=>{let e=a.find(e=>e.id===F);if(!e){I(null);return}j(t=>({...t,[e.id]:!0}));let n=y[e.id]||{};if(e.isSystem){try{await(0,i.setDoc)((0,i.doc)(t.Ht,`sys_configs`,`page_briefs`),{[e.id]:(0,i.deleteField)()},{merge:!0}),w(t=>{let n={...t};return delete n[e.id],n}),k(t=>({...t,[e.id]:(t[e.id]||0)+1}))}catch(e){console.error(`Failed to clear the page answers`,e)}j(t=>({...t,[e.id]:!1})),I(null);return}let r=ea(e,n);if(r)try{await(0,i.deleteDoc)((0,i.doc)(t.Ht,e.type===`public`?`sys_pages`:`sys_tabs`,e.id)),b(t=>({...t,[e.id]:r})),o(t=>t.map(t=>t.id===e.id?{...t,fromFile:!0,title:r.pageName||r.tabName||r.pageTitle||r.tabTitle||r.title||t.title,path:r.route?r.route.startsWith(`/`)?r.route:`/`+r.route:t.path}:t))}catch(e){console.error(`Failed to reset the page`,e)}else await ie(e.id,{...me(e.type),...n.contentKey?{contentKey:n.contentKey}:{}});j(t=>({...t,[e.id]:!1})),I(null)},ge=[{id:`public`,title:`Anyone`,icon:t.it,description:`On your website and in the site menu — open to everyone, signed in or not.`,filter:e=>e.type===`public`},{id:`user`,title:`Signed-in users`,icon:t.G,description:`In the dashboard for every signed-in person — each sees only their own.`,filter:e=>e.type===`user`},{id:`internal`,title:`Your team`,icon:t.ct,description:`In the dashboard for admins and your team — invisible to everyone else.`,filter:e=>e.type===`internal`},{id:`admin`,title:`Admins only`,icon:t.A,description:`In the dashboard, for admins alone.`,filter:e=>e.type===`admin`}];return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsx)(t.p.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)(ce,{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)(de,{}),(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-3 sm:gap-6 mb-4 pb-4 md:mb-6 md:pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 md:px-10 md:pt-10`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`div`,{className:`flex items-center min-h-[40px]`,children:(0,s.jsx)(`h2`,{className:`text-lg md:text-xl font-extrabold text-foreground tracking-tight leading-tight truncate`,children:`Your pages`})}),(0,s.jsxs)(`p`,{className:`text-[12.5px] md:text-[14px] font-medium text-foreground/60 leading-relaxed max-w-3xl`,children:[(0,s.jsx)(`span`,{className:`md:hidden`,children:`Add a page, say what goes on it, paste the sentence into your assistant.`}),(0,s.jsx)(`span`,{className:`max-md:hidden`,children:`Add a page here, say what you would like on it, and copy the sentence it writes into your assistant's chat. 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.c,{variant:`secondary`,onClick:()=>v(!_),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.L,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,s.jsx)(t.m,{children:_&&(0,s.jsxs)(t.p.div,{ref:z,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:()=>ae(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:Si[e]},e))]})})]})})]}),(0,s.jsx)(`div`,{ref:q,className:`px-4 sm:px-6 md:px-10 pb-6 md:pb-10 flex flex-col pt-6 sm:pt-7 md:pt-9 gap-4 overflow-y-auto relative min-h-[400px]`,children:ge.map((e,n)=>{let r=a.filter(e.filter).filter(e=>!Z(e)),i=e.id===`public`?H:W,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}),d=e.icon,p=e=>e.type===`public`?B.has(e.id):V.has(e.id),_=o.filter(e=>!p(e)),v=o.filter(e=>p(e)),b=(n,r)=>{let i=n.isSystem?Zi[n.id]:void 0,a=l===n.id,o=X(n),d=Ci({draft:o,hidden:r}),p=!n.isSystem||!!i,_=!n.isSystem&&!o,v=a&&h===n.id,b=e=>{u(n.id),g(e===`edit`?n.id:null),window.history.replaceState(null,``,`/pages/${n.id}`)},S=()=>{u(null),g(null),window.history.replaceState(null,``,`/pages`)},w=o?`Not saved yet — give it a web address`:n.type===`public`?`In the site menu`:`In the dashboard`;return(0,s.jsxs)(`div`,{id:`page-${n.id}`,onClick:()=>{p&&(a?S():b(`settings`))},className:`group flex flex-col p-4 sm:py-4 sm:px-5 glass-panel border transition-all rounded-2xl hover:shadow-sm ${p?`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 items-center justify-between w-full gap-2 sm:gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-start gap-2 flex-1 min-w-0`,children:[!n.isSystem&&!o&&(0,s.jsxs)(`div`,{className:`${a?`max-sm:hidden sm:flex`:`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:()=>fe(n,`up`),className:na,children:(0,s.jsx)(t.xt,{className:`w-3.5 h-3.5`})}),(0,s.jsx)(`button`,{type:`button`,title:`Move down`,"aria-label":`Move ${n.title} down`,onClick:()=>fe(n,`down`),className:na,children:(0,s.jsx)(t.wt,{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-[14.5px] font-bold text-foreground tracking-tight truncate`,children:n.title}),!n.isSystem&&(0,s.jsx)(oa,{status:d}),n.fromFile&&(0,s.jsxs)(`span`,{className:ra,title:`Your assistant wrote this one as a file. Delete hides it and gives you the sentence that removes its files.`,children:[(0,s.jsx)(t.st,{className:`w-3 h-3`}),` Written as a file`]})]}),(0,s.jsx)(`span`,{className:`text-[12px] font-medium text-foreground/45 truncate`,children:w})]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2 shrink-0`,children:[n.type!==`public`&&!o&&(0,s.jsx)(`div`,{className:`max-sm:hidden`,children:(0,s.jsx)(Ai,{value:n.type,busy:x[n.id],onChange:e=>se(n,e)})}),_&&(0,s.jsx)(Q,{icon:t.y,compact:!0,title:`Edit this page with your assistant`,className:v?`text-accent border-accent/40 bg-accent/10 max-sm:border-transparent max-sm:bg-accent/10`:``,onClick:e=>{e.stopPropagation(),b(v?`settings`:`edit`)},children:`Edit with AI`}),!bi.has(n.id)&&!o&&(0,s.jsx)(Q,{icon:r?t.ct:t.lt,compact:!0,title:r?`Show this page`:`Hide this page`,onClick:e=>{e.stopPropagation(),oe(n.id,n.isSystem,n.type)},children:r?`Show`:`Hide`}),p?(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.wt,{className:`w-3.5 h-3.5`})}):(0,s.jsx)(`div`,{className:`w-[24px] shrink-0`})]})]}),n.path&&a&&(0,s.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 mt-1.5`,onClick:e=>e.stopPropagation(),children:[(0,s.jsx)(c.Link,{to:n.path,className:`text-[12px] font-medium text-foreground/45 truncate underline decoration-foreground/20 underline-offset-2 hover:text-accent hover:decoration-accent transition-colors`,title:`Open this page`,children:sa(n.path)}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>m(n),title:`Copy this link`,"aria-label":`Copy the link to ${n.title}`,className:`shrink-0 w-6 h-6 rounded-md flex items-center justify-center text-foreground/35 hover:text-foreground hover:bg-foreground/[0.07] transition-colors cursor-pointer`,children:f===n.id?(0,s.jsx)(t.Tt,{className:`w-3.5 h-3.5 text-accent`}):(0,s.jsx)(t.pt,{className:`w-3.5 h-3.5`})})]}),(0,s.jsxs)(t.m,{children:[a&&i&&(0,s.jsx)(t.p.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)(ha,{page:n,answers:C[n.id],saving:x[n.id],resetting:A[n.id],onSave:e=>E(n.id,e),onReset:()=>I(n.id),onCopied:S},`${n.id}:${O[n.id]||0}`)}),a&&!n.isSystem&&y[n.id]&&(0,s.jsxs)(t.p.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:[n.type!==`public`&&!o&&(0,s.jsxs)(`div`,{className:`sm:hidden flex items-center justify-between gap-3 mb-5`,children:[(0,s.jsx)(`span`,{className:`text-[12px] font-semibold text-foreground/55`,children:`Who can open this page`}),(0,s.jsx)(Ai,{value:n.type,busy:x[n.id],onChange:e=>se(n,e)})]}),(0,s.jsx)(ma,{page:n,config:y[n.id],forms:n.type===`public`?J:ne,saving:x[n.id],isNew:o,editing:v,onSave:e=>ie(n.id,e),addressTaken:pe,footer:(e,{definingForm:t})=>v?(0,s.jsx)(rt,{compact:!0,title:`Copy this to change the page`,prompt:Xi(n,e,t),locked:!!Yi(e,t),onCopied:S}):(0,s.jsx)(rt,{compact:!0,title:`Then copy this into your assistant’s chat`,description:_?`This one builds the page from scratch. If it has been built already, switch to Edit with AI so your assistant changes it instead of starting over.`:void 0,prompt:qi(n,e),locked:!!Vi(n,e),onCopied:S}),actions:(0,s.jsxs)(s.Fragment,{children:[$i(y[n.id],ea(n,y[n.id])??me(n.type))&&(0,s.jsx)(Q,{icon:t.F,tone:`danger`,compact:!0,title:`Reset this page`,busy:A[n.id],onClick:()=>I(n.id),children:`Reset`}),!n.isSystem&&(0,s.jsx)(Q,{icon:t.E,tone:`danger`,compact:!0,title:`Delete this page`,onClick:()=>le(n.id,n.isSystem),children:`Delete`})]})},n._uiKey||n.id)]})]})]},`${e.id}-${n._uiKey||n.id}`)};return(0,s.jsx)(t.p.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex flex-col relative`,children:(0,s.jsx)(Oe,{icon:d,title:e.title,description:e.description,children:o.length===0?(0,s.jsxs)(`div`,{className:`flex flex-col items-start 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.L,onClick:()=>ae(e.id),children:`Add a page`}),(0,s.jsxs)(`p`,{className:`text-[12.5px] text-foreground/55 font-medium leading-relaxed`,children:[(0,s.jsx)(`span`,{className:`sm:hidden`,children:Mi}),(0,s.jsx)(`span`,{className:`max-sm:hidden`,children:ji})]})]}):(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[_.map(e=>b(e,!1)),(0,s.jsx)(`div`,{className:`flex items-center rounded-2xl border border-dashed border-[var(--panel-border)] px-5 py-3`,children:(0,s.jsx)(Q,{icon:t.L,onClick:()=>ae(e.id),children:`Add a page`})}),v.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.wt,{className:`w-3.5 h-3.5 group-open/details:-rotate-180 transition-transform`}),`Hidden pages (`,v.length,`)`]}),(0,s.jsx)(`div`,{className:`flex flex-col gap-4 mt-4`,children:v.map(e=>b(e,!0))})]})]})})},e.id)})})]})]}),(0,s.jsx)(be,{isOpen:!!M,onCancel:()=>P(null),onConfirm:ue,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:L}),(0,s.jsx)(be,{isOpen:!!F,onCancel:()=>I(null),onConfirm:he,title:a.find(e=>e.id===F)?.isSystem?`Start this page again?`:`Reset this page?`,message:(()=>{let e=a.find(e=>e.id===F);return e?.isSystem?`What you have written about this page is cleared, and the pictures you added with it, so you can describe it again from scratch. The page itself stays as your assistant last built it.`:e&&ea(e,y[e.id])?`Its settings go back to how your assistant built the page, and what you wrote about it is cleared. What people have saved on the page is kept.`:`Its name, heading, web address, icon and form go back to how they started, and what you wrote about it is cleared. What people have saved on the page is kept.`})(),confirmText:a.find(e=>e.id===F)?.isSystem?`Start again`:`Reset page`,isProcessing:!!F&&!!A[F]})]})}var _a=new Set([`contact`,`support`]),va=[{value:`text`,label:`Short text`},{value:`textarea`,label:`Long text`},{value:`email`,label:`Email`},{value:`tel`,label:`Phone`},{value:`number`,label:`Number`},{value:`date`,label:`Date`},{value:`currency`,label:`Money`},{value:`checkbox`,label:`Yes-no`},{value:`select`,label:`Choose one`},{value:`file`,label:`File upload`}],ya={age:`Age`},ba=e=>va.find(t=>t.value===e)?.label||ya[e||``]||`Short text`,xa=e=>va.some(t=>t.value===e)||!e?va:[...va,{value:e,label:ba(e)}],Sa={public:`Anyone`,private:`Signed-in users`},Ca=e=>(e||``).toLowerCase().trim().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``),wa=(e,t)=>{if(!t.includes(e))return e;let n=2;for(;t.includes(`${e}_${n}`);)n++;return`${e}_${n}`},Ta=(e,t,n)=>{if(!(!e.name||e.name===Ca(e.label||``)))return e.name;let r=Ca(t);return r?wa(r,n.filter(t=>t!==e).map(e=>e.name)):``},Ea=()=>({name:``,type:`text`,label:``,placeholder:``,required:!1}),Da={firstForm:`Forms are made with their pages — add a page on the Pages screen and pick A new form made for this page. Every form then shows up here.`},Oa=`(max-width: 767px)`,ka=()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(Oa).matches;function Aa(){let[e,t]=(0,r.useState)(ka);return(0,r.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(Oa),n=()=>t(e.matches);return n(),e.addEventListener?.(`change`,n),()=>e.removeEventListener?.(`change`,n)},[]),e}function ja({choices:e,onChange:n}){return(0,s.jsx)(ke,{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:Ce}),(0,s.jsx)(Q,{icon:t.v,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.L,onClick:()=>n([...e,``]),children:`Add choice`})})]})})}function Ma(){let{userRole:e}=N(),n=(0,c.useNavigate)(),a=t.Bt(),o=()=>{let e=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},n={...t.f,contact:a?.defaultConfigs?.contactForm||t.f.contact,support:a?.defaultConfigs?.supportForm||t.f.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.f,contact:a?.defaultConfigs?.contactForm||t.f.contact,support:a?.defaultConfigs?.supportForm||t.f.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=Aa(),[b,x]=(0,r.useState)({}),[S,C]=(0,r.useState)(null),[w,T]=(0,r.useState)(!1),[E,D]=(0,r.useState)({}),O=(0,r.useRef)({}),k=(e,t)=>{O.current={...O.current,[e]:t},D(O.current)};(0,r.useEffect)(()=>{A()},[]);let A=async()=>{try{f(!0);let e=await(0,i.getDocs)((0,i.collection)(t.Ht,`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.Ht,`sys_forms`,`pubForm`)),await(0,i.deleteDoc)((0,i.doc)(t.Ht,`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]&&x({[c]:!0}),O.current={},D({}),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}),b[e]&&x(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.Ht,`sys_forms`,a),r),await(0,i.deleteDoc)((0,i.doc)(t.Ht,`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.Ht,`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)=>k(e,{...t,...n}),P=(e,t,n)=>{let r={...t,...n};k(e,r),j(e,r)},F=e=>{let t=O.current[e];t&&j(e,t)},I=(e,t,n)=>P(e,t,{fields:n}),L=async e=>{if(!_a.has(e)){T(!0);try{await(0,i.deleteDoc)((0,i.doc)(t.Ht,`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{T(!1),C(null)}}},R=async e=>{if(!_.has(e)){C(null);return}T(!0);let n=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},r=_a.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.Ht,`sys_forms`,e)),localStorage.removeItem(`fbos_form_${e}`),localStorage.removeItem(`fbos_custom_form_${e}`),await A(),setTimeout(()=>m(t=>({...t,[e]:!1})),500)):await j(e,o().contact||o().support)}catch(e){console.error(`Reset failed:`,e)}finally{T(!1),C(null)}};if(e!==`admin`)return(0,s.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:(0,s.jsx)(fi,{})});let z=e=>{x(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(b).find(e=>b[e]),ee=(e,n,r,i,a)=>{let o=(t,r)=>{let o=a.map((e,n)=>n===i?{...e,...t}:e);r?I(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]],I(e,n,o)},l=r.type!==`checkbox`&&r.type!==`select`&&r.type!==`date`&&r.type!==`file`;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)(`div`,{className:`flex items-center gap-1.5`,children:[(0,s.jsx)(Q,{icon:t.kt,disabled:i===0,title:`Move up`,onClick:()=>c(-1),children:`Up`}),(0,s.jsx)(Q,{icon:t.Nt,disabled:i===a.length-1,title:`Move down`,onClick:()=>c(1),children:`Down`}),(0,s.jsx)(Q,{icon:t.E,tone:`danger`,title:`Remove question ${i+1}`,onClick:()=>I(e,n,a.filter((e,t)=>t!==i)),children:`Remove`})]})]}),(0,s.jsx)(Ae,{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:Ta(r,e,a)},!1),onBlur:()=>F(e)}),(0,s.jsx)(Ne,{label:`Kind of answer`,hint:`Sets the box people type into and what counts as a valid answer.`,value:r.type||`text`,options:xa(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.`,hintWideOnly:!0,enabled:!!r.required,onChange:e=>o({required:e},!0)}),r.type===`select`&&(0,s.jsx)(ja,{choices:r.options||[],onChange:e=>o({options:e},!0)}),r.type===`file`&&(0,s.jsx)(Ae,{label:`Words on the upload box`,hint:`What the box says before a file is picked. Leave it empty for “Attach a file”.`,value:r.placeholder||``,placeholder:`Attach a file`,onChange:e=>o({placeholder:e},!1),onBlur:()=>F(e)}),r.type===`currency`&&(0,s.jsx)(Ae,{label:`Currency symbol`,hint:`Shown inside the box, before the amount.`,value:r.currencySymbol||``,placeholder:`$`,onChange:e=>o({currencySymbol:e},!1),onBlur:()=>F(e)}),l&&(0,s.jsx)(Ae,{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:()=>F(e)})]},i)},V=(e,n)=>{let r=E[e]||n,i=_a.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)(Oe,{icon:t.w,title:`Basics`,description:`What people see at the top of this form and on its button.`,children:[(0,s.jsx)(Ae,{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:()=>F(e)}),(0,s.jsx)(Ae,{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:()=>F(e)})]}),(0,s.jsx)(Oe,{icon:t.x,title:`Who it is for`,description:`Who can fill this in, and where their answers land.`,children:(0,s.jsx)(Ne,{label:`Who it is for`,hint:`Who can fill this in follows the page this form was made for, so it cannot change here. Changing it after answers arrive would file new answers under the wrong list in your Inbox.`,value:a,allowEmpty:!1,disabled:!0,options:[{value:`public`,label:`Anyone`},{value:`private`,label:`Signed-in users`}],onChange:t=>P(e,r,{formType:t})})}),(0,s.jsx)(Oe,{icon:t.N,title:`After sending`,description:`What happens the moment someone sends this form.`,children:(0,s.jsx)(Ae,{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:()=>F(e)})}),(0,s.jsxs)(Oe,{icon:t.q,title:`Questions`,description:`Everything this form asks for, in the order people answer it.`,actions:(0,s.jsx)(Q,{icon:t.L,compact:!0,title:`Add a question`,onClick:()=>I(e,r,[...o,Ea()]),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)=>ee(e,r,t,n,o)),o.length>0&&(0,s.jsx)(`div`,{className:`flex justify-start`,children:(0,s.jsx)(Q,{icon:t.L,onClick:()=>I(e,r,[...o,Ea()]),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.F,tone:`danger`,compact:!0,title:`Reset this form`,onClick:()=>C({kind:`reset`,id:e}),children:`Reset this form`}),!i&&(0,s.jsx)(Q,{icon:t.E,tone:`danger`,compact:!0,title:`Delete this form`,onClick:()=>C({kind:`delete`,id:e}),children:`Delete this form`})]})]})};return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsx)(t.p.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)(ce,{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)(de,{}),(0,s.jsxs)(`div`,{className:`flex flex-col glass-panel border-y sm:border border-[var(--panel-border)] rounded-none sm:rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background -mx-4 sm:mx-0`,children:[(0,s.jsx)(`div`,{className:`flex items-start justify-between gap-3 sm:gap-6 mb-4 pb-4 md:mb-4 md:pb-5 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-4 pt-5 sm:px-6 sm:pt-6 md:px-10 md:pt-8 bg-background/50`,children:(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-lg md:text-xl font-extrabold text-foreground tracking-tight leading-tight md:leading-7`,children:`Your forms`}),(0,s.jsxs)(`p`,{className:`text-[12.5px] md:text-[14px] font-medium text-foreground/60 mt-1 md:mt-2 leading-relaxed`,children:[(0,s.jsx)(`span`,{className:`md:hidden`,children:`Look a form over and touch it up. Answers arrive in your Inbox.`}),(0,s.jsx)(`span`,{className:`max-md:hidden`,children:`Look a form over and touch it up — its name, button text and questions. New forms are made on the Pages screen, with their page. Answers arrive in your Inbox.`})]})]})}),(0,s.jsx)(`div`,{className:`p-4 sm:p-6 md:px-8 md:pb-8 md:pt-3 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.I,{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)(`p`,{className:`text-[12.5px] text-foreground/55 font-medium leading-relaxed text-center max-w-md`,children:Da.firstForm})]})}):(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,s.jsx)(t.m,{children:Object.entries(l).map(([e,n])=>{let r=E[e]||n,i=b[e],a=p[e],o=(r.fields||[]).length;return(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},transition:{duration:.35,ease:`easeOut`},onClick:()=>z(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-row justify-between w-full gap-2 ${y?`items-start`:`items-center`}`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-1 min-w-0 flex-1 pr-2 sm: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.K,{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.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[11px] font-semibold px-2.5 py-[3px] rounded-full border shrink-0 ${r.formType===`private`?`text-blue-500 border-blue-500/25 bg-blue-500/[0.07]`:`text-emerald-500 border-emerald-500/25 bg-emerald-500/[0.07]`}`,children:[(0,s.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 ${r.formType===`private`?`bg-blue-500`:`bg-emerald-500`}`}),Sa[r.formType||`public`]]}),(0,s.jsx)(`span`,{className:`max-sm:hidden text-[11px] font-medium text-foreground/45`,children:o===1?`1 question`:`${o} questions`})]})]}),y?(0,s.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0 -mt-0.5 -mr-1.5`,children:[(0,s.jsx)(`button`,{type:`button`,title:`Preview this form`,"aria-label":`Preview this form`,onClick:e=>{e.stopPropagation(),g(r)},className:`w-8 h-8 flex items-center justify-center rounded-lg text-foreground/40 hover:text-accent hover:bg-foreground/5 transition-colors cursor-pointer`,children:(0,s.jsx)(t.ct,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{type:`button`,title:i?`Close this form`:`Open this form`,"aria-label":i?`Close this form`:`Open this form`,"aria-expanded":i,onClick:t=>{t.stopPropagation(),z(e)},className:`w-8 h-8 flex items-center justify-center rounded-lg text-foreground/40 hover:text-accent hover:bg-foreground/5 transition-colors cursor-pointer`,children:(0,s.jsx)(t.wt,{className:`w-4 h-4 transition-transform duration-300 ${i?`rotate-180`:``}`})})]}):(0,s.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,s.jsx)(Q,{icon:t.ct,title:`Preview this form`,onClick:e=>{e.stopPropagation(),g(r)},children:`Preview`}),(0,s.jsx)(`button`,{type:`button`,title:i?`Close this form`:`Open this form`,"aria-label":i?`Close this form`:`Open this form`,"aria-expanded":i,onClick:t=>{t.stopPropagation(),z(e)},className:`w-9 h-9 flex items-center justify-center rounded-[var(--btn-radius,0.75rem)] text-foreground/40 hover:text-accent hover:bg-foreground/[0.06] transition-colors cursor-pointer`,children:(0,s.jsx)(t.wt,{className:`w-4 h-4 transition-transform duration-300 ${i?`rotate-180`:``}`})})]})]}),(0,s.jsx)(t.m,{children:i&&(0,s.jsx)(t.p.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.K,{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)(be,{isOpen:!!S,onCancel:()=>C(null),onConfirm:()=>{S&&(S.kind===`delete`?L(S.id):R(S.id))},title:S?.kind===`reset`?`Reset this form`:`Delete this form`,message:S?.kind===`reset`?`Undo every change made to ${l[S.id]?.title||S.id} and put it back the way it shipped. Answers already collected are kept.`:`Permanently delete ${S?l[S.id]?.title||S.id:``}. This cannot be undone. Answers already collected are kept.`,confirmText:S?.kind===`reset`?`Reset form`:`Delete form`,isProcessing:w}),h&&(0,s.jsx)(t.t,{formConfig:h,onClose:()=>g(null)})]})}var Na=`src/your-ai-workflow-firebase-os`;function Pa(){let e=new Set;for(let[t,n]of F()){let r=n?.config?.route,i=typeof r==`string`&&r.trim()?r.startsWith(`/`)?r:`/`+r:`/`+t.toLowerCase();e.add(i)}return[...e].sort()}var Fa=e=>(e||``).split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``);function Ia(e){let t=e?.contentKey||e?.tabName||e?.pageName||e?.pageId||`Page`;return`${Na}/microcomponents/${Fa(String(t))||`Page`}Content.tsx`}function La(e,t){let n=t.replace(/^.*\//,``).replace(/\.tsx$/,``),r=n.replace(/Content$/,``).replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase();return[`My app has a page at ${e} and it is still empty after you said it was done. The ONLY thing that fills this page is one file: ${t}, with a default export, registered in ${Na}/microcomponents/registry.ts.`,`Check these in order and fix whatever is wrong, without asking me questions:`,`1. The file exists at exactly that path and name — not another folder, not another spelling. If you put it somewhere else, move it there.`,`2. It has a default export. A named-only export is silently ignored.`,`3. ${Na}/microcomponents/registry.ts contains these two lines: import ${n} from './${n}'; and registerMicrocomponent('${r}', ${n}); — registerMicrocomponent is imported there from 'your-ai-workflow-firebase-os'. Add them if they are missing, and never remove another page's lines.`,`4. You created nothing else for this page — no config file, no route, no page, and no edit to src/App.tsx or src/main.tsx. Undo any of those you made.`,`Then tell me, in one sentence, which of these was wrong.`].join(`
22
+ `)};function pa({images:e,onChange:n}){let i=e.length?e:[{url:``,where:``}],[a,o]=(0,r.useState)({}),c=(e,t)=>n(i.map((n,r)=>r===e?{...n,...t}:n)),l=e=>n(i.length>1?i.filter((t,n)=>n!==e):[{url:``,where:``}]);return(0,s.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[i.map((e,t)=>(0,s.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,s.jsx)(it,{label:t===0?`A picture for this page`:`Picture ${t+1}`,hint:t===0?`Optional — a picture for your assistant to use on the page.`:void 0,value:e.url,onChange:e=>e?c(t,{url:e}):l(t),onBusyChange:e=>o(n=>({...n,[t]:e})),tips:t===0?at:void 0}),(!!e.url||a[t])&&(0,s.jsxs)(`div`,{className:`flex gap-3 sm:gap-3.5`,children:[(0,s.jsx)(`div`,{"aria-hidden":!0,className:`w-0.5 shrink-0 self-stretch rounded-full bg-[var(--panel-border)] ml-1.5 mb-1`}),(0,s.jsx)(Oe,{label:`What is this picture for?`,hint:`Say where it goes, in your own words — your assistant reads this and puts it there.`,value:e.where,onChange:e=>c(t,{where:e}),placeholder:`Across the top, behind the heading`})]})]},t)),!!i[i.length-1].url&&(0,s.jsx)(Q,{icon:t.L,className:`self-start`,onClick:()=>n([...i,{url:``,where:``}]),children:`Add another picture`})]})}function ma({page:e,config:t,forms:n,saving:i,onSave:a,addressTaken:o,actions:c,footer:l,isNew:u,editing:d}){let f=e.type===`public`,p=f?`pageName`:`tabName`,m=f?`pageTitle`:`tabTitle`,[h,g]=(0,r.useState)(()=>({...t||{}})),[_,v]=(0,r.useState)(``),y=(e,t)=>g(n=>({...n,[e]:t})),b=e=>{g(t=>({...t,...e}));let n={...t||{},...h,...e};delete n._uiKey,a(n)},x=e=>{(t||{})[e]!==h[e]&&b({[e]:h[e]})},S=String(h.route??``).replace(/^\/+/,``),C=()=>{let n=Ei(S);if(!n){v(`Give this page a web address, for example pricing`);return}if(o(e.id,n)){v(`Another page already lives at this address. Pick a different one.`);return}v(``),n===String(t?.route??``).replace(/^\/+/,``)?y(`route`,`/`+n):b({route:`/`+n})},w=Ei(S),T={...t||{},...h,route:w?`/`+w:``,contentKey:t?.contentKey||w||void 0},E=String(h.form??``),D=!!h.formIsNew||E===`__new__`,[O]=(0,r.useState)(()=>!!String(t?.form??``).trim()),k=!!d&&O&&!!E,A=D&&!k;return(0,s.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-5`,children:[(0,s.jsx)(Oe,{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. /photos`,prefix:`/`,value:S,onChange:e=>{y(`route`,e),_&&v(``)},onBlur:C,error:_,placeholder:`photos`}),(0,s.jsx)(Oe,{label:f?`Name in the menu`:`Name in the dashboard`,hint:f?`What visitors see in the site menu.`:`What people see in the dashboard menu.`,value:h[p]??``,onChange:e=>y(p,e),onBlur:()=>x(p),placeholder:`Photos`}),(0,s.jsx)(Oe,{label:`Page heading`,hint:`The big heading people read at the top of the page.`,value:h[m]??``,onChange:e=>y(m,e),onBlur:()=>x(m),placeholder:`Our photos`}),!f&&(0,s.jsx)(Ke,{label:`Icon`,hint:`Shown next to the name in the dashboard menu.`,value:h.iconName??``,onChange:e=>b({iconName:e})}),!f&&!d&&(0,s.jsx)(je,{label:`Starting layout`,hint:`What the page starts as. Your assistant fills in the rest when you ask.`,value:Ni.some(e=>e.value===h.template)?h.template:`none`,onChange:e=>b({template:e}),options:Ni,allowEmpty:!1}),!k&&(0,s.jsx)(je,{label:`Form`,hint:`Answers arrive in your Inbox. Your assistant builds it with the page.`,value:D?`__new__`:E,onChange:e=>b(e===`__new__`?{form:`__new__`}:{form:e,formIsNew:!1}),options:[{value:`__new__`,label:`A new form made for this page`},...n.map(e=>({value:e,label:ca(e)}))],placeholder:`No form`}),A&&(0,s.jsx)(Ae,{label:`What should the form ask?`,hint:`The questions in your own words — e.g. name, email, budget, what they need.`,value:h.formFields??``,onChange:e=>y(`formFields`,e),onBlur:()=>x(`formFields`),placeholder:`Name, email, and what they would like to book`}),(A||!d&&!!E)&&(0,s.jsx)(Oe,{label:`The button that opens it`,hint:`What the button that opens the form says.`,value:h.formButton??``,onChange:e=>y(`formButton`,e),onBlur:()=>x(`formButton`),placeholder:`Get in touch`}),(A||!d&&!!E)&&(0,s.jsx)(Oe,{label:`Where the form goes`,hint:`Optional — where on the page it belongs, in your own words.`,value:h.formSpot??``,onChange:e=>y(`formSpot`,e),onBlur:()=>x(`formSpot`),placeholder:`At the bottom, after the packages`}),k&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Ae,{label:`Change the form`,hint:`Say what should change about the form, then copy the sentence below.`,value:h.formChange??``,onChange:e=>y(`formChange`,e),onBlur:()=>x(`formChange`),placeholder:`Add a phone number question after the email one`}),(0,s.jsx)(tt,{compact:!0,title:`Copy this to change the form`,prompt:fa(e,T),locked:!String(h.formChange??``).trim()})]}),d?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Ae,{label:`What would you like to add?`,hint:`Anything new for the page. Leave it empty if nothing is missing.`,value:h.pageAdd??``,onChange:e=>y(`pageAdd`,e),onBlur:()=>x(`pageAdd`),placeholder:`A section with three reviews from my customers.`}),(0,s.jsx)(Ae,{label:`What would you like to change?`,hint:`Your assistant edits the page you have — anything you do not mention stays.`,value:h.pageChange??``,onChange:e=>y(`pageChange`,e),onBlur:()=>x(`pageChange`),placeholder:`Show the albums three to a row, and put a search box above them.`}),(0,s.jsx)(Ae,{label:`What would you like to remove?`,hint:`Anything the page should stop showing.`,value:h.pageRemove??``,onChange:e=>y(`pageRemove`,e),onBlur:()=>x(`pageRemove`),placeholder:`The prices — I would rather people ask.`}),f&&(0,s.jsx)(pa,{images:Ui(h),onChange:e=>b({images:e})}),!!String(h.brief??``).trim()&&(0,s.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)] px-4 py-3`,children:[(0,s.jsx)(`p`,{className:`text-[11px] font-bold uppercase tracking-widest text-foreground/40 mb-1.5`,children:`What this page was built from`}),(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed whitespace-pre-line break-words [overflow-wrap:anywhere]`,children:String(h.brief)})]})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Ae,{label:`What would you like to see on this page?`,hint:`What your assistant builds — it goes into the sentence below.`,value:h.brief??``,onChange:e=>y(`brief`,e),onBlur:()=>x(`brief`),placeholder:`A photo gallery where I can upload pictures, put them in albums and open one full screen.`}),f&&(0,s.jsx)(pa,{images:Ui(h),onChange:e=>b({images:e})})]}),l?.(T,{definingForm:A}),(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)(Pe,{saving:i}),(0,s.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 ml-auto`,children:c})]})]})}function ha({page:e,answers:n,saving:i,resetting:a,onSave:o,onReset:c,onCopied:l}){let[u,d]=(0,r.useState)(()=>({...n||{}})),f=(e,t)=>d(n=>({...n,[e]:t})),p=e=>{(n||{})[e]!==u[e]&&o({[e]:u[e]})},m={...n||{},...u},h=Zi[e.id],g=!Ki(m);return(0,s.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-5`,children:[(0,s.jsx)(Ae,{label:h.ask,hint:`In your own words. Everything you do not mention stays as it is.`,value:u.pageWish??``,onChange:e=>f(`pageWish`,e),onBlur:()=>p(`pageWish`),placeholder:h.example}),e.type===`public`&&(0,s.jsx)(pa,{images:Ui(u),onChange:e=>{f(`images`,e),o({images:e})}}),(0,s.jsx)(tt,{compact:!0,title:h.title,prompt:Qi(e.id,m),locked:g,onCopied:l}),(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 pt-1`,children:[(0,s.jsx)(`div`,{children:Ki(m)&&c&&(0,s.jsx)(Q,{icon:t.F,tone:`danger`,compact:!0,title:`Start again`,busy:a,onClick:c,children:`Reset`})}),(0,s.jsx)(Pe,{saving:i})]})]})}function ga(){let{userRole:e}=N(),n=(0,c.useLocation)(),[a,o]=(0,r.useState)(()=>{try{if(typeof window<`u`){let e=localStorage.getItem(`fbos_swr_pages`);if(e)return xi(JSON.parse(e))}}catch{}return yi}),[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)(null),m=e=>{let t=typeof window<`u`?window.location.origin:``;navigator.clipboard?.writeText(`${t}${e.path}`),p(e.id),setTimeout(()=>p(null),2e3)},[h,g]=(0,r.useState)(null),[_,v]=(0,r.useState)(!1),[y,b]=(0,r.useState)(()=>{try{if(typeof window<`u`){let e=localStorage.getItem(`fbos_swr_page_configs`);if(e)return JSON.parse(e)}}catch{}return{}}),[x,S]=(0,r.useState)({}),[C,w]=(0,r.useState)(()=>{try{let e=localStorage.getItem(`fbos_swr_page_briefs`);if(e)return JSON.parse(e)}catch{}return{}}),T=(0,r.useRef)(C);(0,r.useEffect)(()=>{T.current=C},[C]),(0,r.useEffect)(()=>(0,i.onSnapshot)((0,i.doc)(t.Ht,`sys_configs`,`page_briefs`),e=>{let t=e.exists()?e.data():{};w(t);try{localStorage.setItem(`fbos_swr_page_briefs`,JSON.stringify(t))}catch{}},()=>{}),[]);let E=async(e,n)=>{let r={...T.current[e]||{},...n};w(t=>({...t,[e]:r})),S(t=>({...t,[e]:!0}));try{await(0,i.setDoc)((0,i.doc)(t.Ht,`sys_configs`,`page_briefs`),{[e]:r},{merge:!0})}catch(e){console.error(`Could not save the page answers`,e)}S(t=>({...t,[e]:!1}))},[O,k]=(0,r.useState)({}),[A,j]=(0,r.useState)({}),[M,P]=(0,r.useState)(null),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)(!1),z=(0,r.useRef)(null);(0,r.useEffect)(()=>{function e(e){z.current&&!z.current.contains(e.target)&&v(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let[B,ee]=(0,r.useState)(new Set),[V,te]=(0,r.useState)(new Set),[H,U]=(0,r.useState)([]),[W,G]=(0,r.useState)([]),K=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.Ht,`sys_configs`,`page_order`),e=>{let t=K(e.exists()&&e.data().order||[]);U(t),ee(new Set(t.filter(e=>e.hidden).map(e=>e.id)))}),n=(0,i.onSnapshot)((0,i.doc)(t.Ht,`sys_configs`,`tab_order`),e=>{let t=K(e.exists()&&e.data().order||[]);G(t),te(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 q=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=q.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.Ht,`sys_pages`)),(0,i.getDocs)((0,i.collection)(t.Ht,`sys_tabs`))]),r=[`home`,`drive`,`assets`,`contact`,`guide`,`templates`,`setup`,`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=D(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=Oi(),l={...ki(!0,!0),...ki(!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=xi(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}),b(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[J,Y]=(0,r.useState)([`contact`]),[ne,re]=(0,r.useState)([`support`]);(0,r.useEffect)(()=>{let e=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},n={...t.f,...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.Ht,`sys_forms`)).then(e=>{e.docs.forEach(e=>{e.data().formType===`private`?a.add(e.id):r.add(e.id)}),Y(Array.from(r)),re(Array.from(a))}).catch(e=>{console.warn(`Failed fetching sys_forms in PagesAdmin:`,e),Y(Array.from(r)),re(Array.from(a))})},[]);let ie=async(e,n,r)=>{if(n.route&&!n.route.startsWith(`/`)&&(n.route=`/`+n.route),!String(n.route||``).replace(/^\/+/,``).trim()){b(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},f.form===`__new__`&&(f.form=la(f),f.formIsNew=!0,n={...n,form:f.form,formIsNew:!0}),S(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.Ht,l,e))}catch{}await(0,i.setDoc)((0,i.doc)(t.Ht,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}`)),b(t=>{let r={...t};return r[p]=n,delete r[e],r});let r=c===`public`,a=r?`page_order`:`tab_order`,s=r?H:W;if(!s.some(e=>e.id===p)){let n=[...s.filter(t=>t.id!==e),{id:p,hidden:!1}];try{await(0,i.setDoc)((0,i.doc)(t.Ht,`sys_configs`,a),{order:n})}catch(e){console.error(`Failed to update tab order:`,e)}}}else await(0,i.setDoc)((0,i.doc)(t.Ht,l,e),f),b(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(()=>{S(t=>({...t,[e]:!1,[p]:!1}))},500)}},ae=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:``,formFields:``,formButton:``,formSpot:``,brief:``}:{route:``,tabName:``,tabTitle:``,iconName:``,template:`none`,form:``,formFields:``,formButton:``,formSpot:``,brief:``,pageType:e};o(e=>[...e,n]),b(e=>({...e,[t]:r})),u(t),v(!1),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView?.({behavior:`smooth`,block:`center`})},100)},X=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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:(0,s.jsx)(fi,{})});let oe=async(e,n,r)=>{let s=r===`public`,c=s?`page_order`:`tab_order`,l=s?H:W,u=(s?B:V).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.Ht,`sys_configs`,c),{order:d})},Z=e=>!!e.fromFile&&(e.type===`public`?H:W).some(t=>t.id===e.id&&t.removed),se=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)),S(t=>({...t,[e.id]:!0}));let a=ta(y[e.id],n);try{await(0,i.setDoc)((0,i.doc)(t.Ht,`sys_tabs`,e.id),a,{merge:!0}),b(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{S(t=>({...t,[e.id]:!1}))}},le=(e,t)=>{if(!t){if(X({id:e})){o(t=>t.filter(t=>t.id!==e)),b(t=>{let n={...t};return delete n[e],n}),l===e&&u(null);return}P(e)}},ue=async()=>{if(M){R(!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===M),h=m?.type===`public`?`sys_pages`:`sys_tabs`;if(h===`sys_tabs`&&m){let a=y[M];if(!a)try{let e=await s(i(t.Ht,`sys_tabs`,M));e.exists()&&(a=e.data())}catch{}let o=(a?.tabName||a?.pageId||M).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.Ht,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.Wt,`${o.prefix}/${decodeURIComponent(s)}`)).catch(()=>{});let l=await r(c(n(t.Ht,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.Ht,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.Wt,`${i}/${decodeURIComponent(n)}`)).catch(()=>{})}catch{}await e(n.ref)}))}catch{}})());await Promise.all(m)}await e(i(t.Ht,h,M));let g=h===`sys_pages`?`page_order`:`tab_order`,_=h===`sys_pages`?H:W,{setDoc:v}=await import(`firebase/firestore`),b=m?.fromFile?[..._.filter(e=>e.id!==M),{id:M,hidden:!0,removed:!0}]:_.filter(e=>e.id!==M);await v(i(t.Ht,`sys_configs`,g),{order:b}),o(e=>e.filter(e=>e.id!==M)),l===M&&u(null)}catch(e){console.error(`Error deleting page:`,e)}R(!1),P(null)}},fe=async(e,n)=>{if(e.isSystem)return;let r=e.type===`public`,o=r?`page_order`:`tab_order`,s=[...r?H:W];a.filter(e=>e.type===`public`===r&&!e.isSystem&&!s.some(t=>t.id===e.id)).forEach(e=>s.push({id:e.id,hidden:!1}));let c=Di(s,e.id,n,r?`home`:void 0);if(c){r?U(c):G(c);try{await(0,i.setDoc)((0,i.doc)(t.Ht,`sys_configs`,o),{order:c})}catch(e){console.error(`Failed to reorder pages:`,e)}}},pe=(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(y[r.id]?.route??r.path??``).replace(/^\/+/,``).toLowerCase();return i!==``&&i===t||r.id===n})},me=e=>e===`admin`?_i:e===`internal`?vi:e===`public`?hi:gi,he=async()=>{let e=a.find(e=>e.id===F);if(!e){I(null);return}j(t=>({...t,[e.id]:!0}));let n=y[e.id]||{};if(e.isSystem){try{await(0,i.setDoc)((0,i.doc)(t.Ht,`sys_configs`,`page_briefs`),{[e.id]:(0,i.deleteField)()},{merge:!0}),w(t=>{let n={...t};return delete n[e.id],n}),k(t=>({...t,[e.id]:(t[e.id]||0)+1}))}catch(e){console.error(`Failed to clear the page answers`,e)}j(t=>({...t,[e.id]:!1})),I(null);return}let r=ea(e,n);if(r)try{await(0,i.deleteDoc)((0,i.doc)(t.Ht,e.type===`public`?`sys_pages`:`sys_tabs`,e.id)),b(t=>({...t,[e.id]:r})),o(t=>t.map(t=>t.id===e.id?{...t,fromFile:!0,title:r.pageName||r.tabName||r.pageTitle||r.tabTitle||r.title||t.title,path:r.route?r.route.startsWith(`/`)?r.route:`/`+r.route:t.path}:t))}catch(e){console.error(`Failed to reset the page`,e)}else await ie(e.id,{...me(e.type),...n.contentKey?{contentKey:n.contentKey}:{}});j(t=>({...t,[e.id]:!1})),I(null)},ge=[{id:`public`,title:`Anyone`,icon:t.it,description:`On your website and in the site menu — open to everyone, signed in or not.`,filter:e=>e.type===`public`},{id:`user`,title:`Signed-in users`,icon:t.G,description:`In the dashboard for every signed-in person — each sees only their own.`,filter:e=>e.type===`user`},{id:`internal`,title:`Your team`,icon:t.ct,description:`In the dashboard for admins and your team — invisible to everyone else.`,filter:e=>e.type===`internal`},{id:`admin`,title:`Admins only`,icon:t.A,description:`In the dashboard, for admins alone.`,filter:e=>e.type===`admin`}];return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsx)(t.p.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)(ce,{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)(de,{}),(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-3 sm:gap-6 mb-4 pb-4 md:mb-6 md:pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-4 pt-4 sm:px-6 sm:pt-6 md:px-10 md:pt-10`,children:[(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`div`,{className:`flex items-center min-h-[40px]`,children:(0,s.jsx)(`h2`,{className:`text-lg md:text-xl font-extrabold text-foreground tracking-tight leading-tight truncate`,children:`Your pages`})}),(0,s.jsxs)(`p`,{className:`text-[12.5px] md:text-[14px] font-medium text-foreground/60 leading-relaxed max-w-3xl`,children:[(0,s.jsx)(`span`,{className:`md:hidden`,children:`Add a page, say what goes on it, paste the sentence into your assistant.`}),(0,s.jsx)(`span`,{className:`max-md:hidden`,children:`Add a page here, say what you would like on it, and copy the sentence it writes into your assistant's chat. 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.c,{variant:`secondary`,onClick:()=>v(!_),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.L,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,s.jsx)(t.m,{children:_&&(0,s.jsxs)(t.p.div,{ref:z,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:()=>ae(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:Si[e]},e))]})})]})})]}),(0,s.jsx)(`div`,{ref:q,className:`px-4 sm:px-6 md:px-10 pb-6 md:pb-10 flex flex-col pt-6 sm:pt-7 md:pt-9 gap-4 overflow-y-auto relative min-h-[400px]`,children:ge.map((e,n)=>{let r=a.filter(e.filter).filter(e=>!Z(e)),i=e.id===`public`?H:W,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}),d=e.icon,p=e=>e.type===`public`?B.has(e.id):V.has(e.id),_=o.filter(e=>!p(e)),v=o.filter(e=>p(e)),b=(n,r)=>{let i=n.isSystem?Zi[n.id]:void 0,a=l===n.id,o=X(n),d=Ci({draft:o,hidden:r}),p=!n.isSystem||!!i,_=!n.isSystem&&!o,v=a&&h===n.id,b=e=>{u(n.id),g(e===`edit`?n.id:null),window.history.replaceState(null,``,`/pages/${n.id}`)},S=()=>{u(null),g(null),window.history.replaceState(null,``,`/pages`)},w=o?`Not saved yet — give it a web address`:n.type===`public`?`In the site menu`:`In the dashboard`;return(0,s.jsxs)(`div`,{id:`page-${n.id}`,onClick:()=>{p&&(a?S():b(`settings`))},className:`group flex flex-col p-4 sm:py-4 sm:px-5 glass-panel border transition-all rounded-2xl hover:shadow-sm ${p?`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 items-center justify-between w-full gap-2 sm:gap-3`,children:[(0,s.jsxs)(`div`,{className:`flex items-start gap-2 flex-1 min-w-0`,children:[!n.isSystem&&!o&&(0,s.jsxs)(`div`,{className:`${a?`max-sm:hidden sm:flex`:`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:()=>fe(n,`up`),className:na,children:(0,s.jsx)(t.xt,{className:`w-3.5 h-3.5`})}),(0,s.jsx)(`button`,{type:`button`,title:`Move down`,"aria-label":`Move ${n.title} down`,onClick:()=>fe(n,`down`),className:na,children:(0,s.jsx)(t.wt,{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-[14.5px] font-bold text-foreground tracking-tight truncate`,children:n.title}),!n.isSystem&&(0,s.jsx)(oa,{status:d}),n.fromFile&&(0,s.jsxs)(`span`,{className:ra,title:`Your assistant wrote this one as a file. Delete hides it and gives you the sentence that removes its files.`,children:[(0,s.jsx)(t.st,{className:`w-3 h-3`}),` Written as a file`]})]}),(0,s.jsx)(`span`,{className:`text-[12px] font-medium text-foreground/45 truncate`,children:w})]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2 shrink-0`,children:[n.type!==`public`&&!o&&(0,s.jsx)(`div`,{className:`max-sm:hidden`,children:(0,s.jsx)(Ai,{value:n.type,busy:x[n.id],onChange:e=>se(n,e)})}),_&&(0,s.jsx)(Q,{icon:t.y,compact:!0,title:`Edit this page with your assistant`,className:v?`text-accent border-accent/40 bg-accent/10 max-sm:border-transparent max-sm:bg-accent/10`:``,onClick:e=>{e.stopPropagation(),b(v?`settings`:`edit`)},children:`Edit with AI`}),!bi.has(n.id)&&!o&&(0,s.jsx)(Q,{icon:r?t.ct:t.lt,compact:!0,title:r?`Show this page`:`Hide this page`,onClick:e=>{e.stopPropagation(),oe(n.id,n.isSystem,n.type)},children:r?`Show`:`Hide`}),p?(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.wt,{className:`w-3.5 h-3.5`})}):(0,s.jsx)(`div`,{className:`w-[24px] shrink-0`})]})]}),n.path&&a&&(0,s.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 mt-1.5`,onClick:e=>e.stopPropagation(),children:[(0,s.jsx)(c.Link,{to:n.path,className:`text-[12px] font-medium text-foreground/45 truncate underline decoration-foreground/20 underline-offset-2 hover:text-accent hover:decoration-accent transition-colors`,title:`Open this page`,children:sa(n.path)}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>m(n),title:`Copy this link`,"aria-label":`Copy the link to ${n.title}`,className:`shrink-0 w-6 h-6 rounded-md flex items-center justify-center text-foreground/35 hover:text-foreground hover:bg-foreground/[0.07] transition-colors cursor-pointer`,children:f===n.id?(0,s.jsx)(t.Tt,{className:`w-3.5 h-3.5 text-accent`}):(0,s.jsx)(t.pt,{className:`w-3.5 h-3.5`})})]}),(0,s.jsxs)(t.m,{children:[a&&i&&(0,s.jsx)(t.p.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)(ha,{page:n,answers:C[n.id],saving:x[n.id],resetting:A[n.id],onSave:e=>E(n.id,e),onReset:()=>I(n.id),onCopied:S},`${n.id}:${O[n.id]||0}`)}),a&&!n.isSystem&&y[n.id]&&(0,s.jsxs)(t.p.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:[n.type!==`public`&&!o&&(0,s.jsxs)(`div`,{className:`sm:hidden flex items-center justify-between gap-3 mb-5`,children:[(0,s.jsx)(`span`,{className:`text-[12px] font-semibold text-foreground/55`,children:`Who can open this page`}),(0,s.jsx)(Ai,{value:n.type,busy:x[n.id],onChange:e=>se(n,e)})]}),(0,s.jsx)(ma,{page:n,config:y[n.id],forms:n.type===`public`?J:ne,saving:x[n.id],isNew:o,editing:v,onSave:e=>ie(n.id,e),addressTaken:pe,footer:(e,{definingForm:t})=>v?(0,s.jsx)(tt,{compact:!0,title:`Copy this to change the page`,prompt:Xi(n,e,t),locked:!!Yi(e,t),onCopied:S}):(0,s.jsx)(tt,{compact:!0,title:`Then copy this into your assistant’s chat`,description:_?`This one builds the page from scratch. If it has been built already, switch to Edit with AI so your assistant changes it instead of starting over.`:void 0,prompt:qi(n,e),locked:!!Vi(n,e),onCopied:S}),actions:(0,s.jsxs)(s.Fragment,{children:[$i(y[n.id],ea(n,y[n.id])??me(n.type))&&(0,s.jsx)(Q,{icon:t.F,tone:`danger`,compact:!0,title:`Reset this page`,busy:A[n.id],onClick:()=>I(n.id),children:`Reset`}),!n.isSystem&&(0,s.jsx)(Q,{icon:t.E,tone:`danger`,compact:!0,title:`Delete this page`,onClick:()=>le(n.id,n.isSystem),children:`Delete`})]})},n._uiKey||n.id)]})]})]},`${e.id}-${n._uiKey||n.id}`)};return(0,s.jsx)(t.p.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex flex-col relative`,children:(0,s.jsx)(Ee,{icon:d,title:e.title,description:e.description,children:o.length===0?(0,s.jsxs)(`div`,{className:`flex flex-col items-start 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.L,onClick:()=>ae(e.id),children:`Add a page`}),(0,s.jsxs)(`p`,{className:`text-[12.5px] text-foreground/55 font-medium leading-relaxed`,children:[(0,s.jsx)(`span`,{className:`sm:hidden`,children:Mi}),(0,s.jsx)(`span`,{className:`max-sm:hidden`,children:ji})]})]}):(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[_.map(e=>b(e,!1)),(0,s.jsx)(`div`,{className:`flex items-center rounded-2xl border border-dashed border-[var(--panel-border)] px-5 py-3`,children:(0,s.jsx)(Q,{icon:t.L,onClick:()=>ae(e.id),children:`Add a page`})}),v.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.wt,{className:`w-3.5 h-3.5 group-open/details:-rotate-180 transition-transform`}),`Hidden pages (`,v.length,`)`]}),(0,s.jsx)(`div`,{className:`flex flex-col gap-4 mt-4`,children:v.map(e=>b(e,!0))})]})]})})},e.id)})})]})]}),(0,s.jsx)(ve,{isOpen:!!M,onCancel:()=>P(null),onConfirm:ue,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:L}),(0,s.jsx)(ve,{isOpen:!!F,onCancel:()=>I(null),onConfirm:he,title:a.find(e=>e.id===F)?.isSystem?`Start this page again?`:`Reset this page?`,message:(()=>{let e=a.find(e=>e.id===F);return e?.isSystem?`What you have written about this page is cleared, and the pictures you added with it, so you can describe it again from scratch. The page itself stays as your assistant last built it.`:e&&ea(e,y[e.id])?`Its settings go back to how your assistant built the page, and what you wrote about it is cleared. What people have saved on the page is kept.`:`Its name, heading, web address, icon and form go back to how they started, and what you wrote about it is cleared. What people have saved on the page is kept.`})(),confirmText:a.find(e=>e.id===F)?.isSystem?`Start again`:`Reset page`,isProcessing:!!F&&!!A[F]})]})}var _a=new Set([`contact`,`support`]),va=[{value:`text`,label:`Short text`},{value:`textarea`,label:`Long text`},{value:`email`,label:`Email`},{value:`tel`,label:`Phone`},{value:`number`,label:`Number`},{value:`date`,label:`Date`},{value:`currency`,label:`Money`},{value:`checkbox`,label:`Yes-no`},{value:`select`,label:`Choose one`},{value:`file`,label:`File upload`}],ya={age:`Age`},ba=e=>va.find(t=>t.value===e)?.label||ya[e||``]||`Short text`,xa=e=>va.some(t=>t.value===e)||!e?va:[...va,{value:e,label:ba(e)}],Sa={public:`Anyone`,private:`Signed-in users`},Ca=e=>(e||``).toLowerCase().trim().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``),wa=(e,t)=>{if(!t.includes(e))return e;let n=2;for(;t.includes(`${e}_${n}`);)n++;return`${e}_${n}`},Ta=(e,t,n)=>{if(!(!e.name||e.name===Ca(e.label||``)))return e.name;let r=Ca(t);return r?wa(r,n.filter(t=>t!==e).map(e=>e.name)):``},Ea=()=>({name:``,type:`text`,label:``,placeholder:``,required:!1}),Da={firstForm:`Forms are made with their pages — add a page on the Pages screen and pick A new form made for this page. Every form then shows up here.`},Oa=`(max-width: 767px)`,ka=()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(Oa).matches;function Aa(){let[e,t]=(0,r.useState)(ka);return(0,r.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(Oa),n=()=>t(e.matches);return n(),e.addEventListener?.(`change`,n),()=>e.removeEventListener?.(`change`,n)},[]),e}function ja({choices:e,onChange:n}){return(0,s.jsx)(De,{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:xe}),(0,s.jsx)(Q,{icon:t.v,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.L,onClick:()=>n([...e,``]),children:`Add choice`})})]})})}function Ma(){let{userRole:e}=N(),n=(0,c.useNavigate)(),a=t.Bt(),o=()=>{let e=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},n={...t.f,contact:a?.defaultConfigs?.contactForm||t.f.contact,support:a?.defaultConfigs?.supportForm||t.f.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.f,contact:a?.defaultConfigs?.contactForm||t.f.contact,support:a?.defaultConfigs?.supportForm||t.f.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=Aa(),[b,x]=(0,r.useState)({}),[S,C]=(0,r.useState)(null),[w,T]=(0,r.useState)(!1),[E,D]=(0,r.useState)({}),O=(0,r.useRef)({}),k=(e,t)=>{O.current={...O.current,[e]:t},D(O.current)};(0,r.useEffect)(()=>{A()},[]);let A=async()=>{try{f(!0);let e=await(0,i.getDocs)((0,i.collection)(t.Ht,`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.Ht,`sys_forms`,`pubForm`)),await(0,i.deleteDoc)((0,i.doc)(t.Ht,`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]&&x({[c]:!0}),O.current={},D({}),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}),b[e]&&x(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.Ht,`sys_forms`,a),r),await(0,i.deleteDoc)((0,i.doc)(t.Ht,`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.Ht,`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)=>k(e,{...t,...n}),P=(e,t,n)=>{let r={...t,...n};k(e,r),j(e,r)},F=e=>{let t=O.current[e];t&&j(e,t)},I=(e,t,n)=>P(e,t,{fields:n}),L=async e=>{if(!_a.has(e)){T(!0);try{await(0,i.deleteDoc)((0,i.doc)(t.Ht,`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{T(!1),C(null)}}},R=async e=>{if(!_.has(e)){C(null);return}T(!0);let n=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},r=_a.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.Ht,`sys_forms`,e)),localStorage.removeItem(`fbos_form_${e}`),localStorage.removeItem(`fbos_custom_form_${e}`),await A(),setTimeout(()=>m(t=>({...t,[e]:!1})),500)):await j(e,o().contact||o().support)}catch(e){console.error(`Reset failed:`,e)}finally{T(!1),C(null)}};if(e!==`admin`)return(0,s.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:(0,s.jsx)(fi,{})});let z=e=>{x(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(b).find(e=>b[e]),ee=(e,n,r,i,a)=>{let o=(t,r)=>{let o=a.map((e,n)=>n===i?{...e,...t}:e);r?I(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]],I(e,n,o)},l=r.type!==`checkbox`&&r.type!==`select`&&r.type!==`date`&&r.type!==`file`;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)(`div`,{className:`flex items-center gap-1.5`,children:[(0,s.jsx)(Q,{icon:t.kt,disabled:i===0,title:`Move up`,onClick:()=>c(-1),children:`Up`}),(0,s.jsx)(Q,{icon:t.Nt,disabled:i===a.length-1,title:`Move down`,onClick:()=>c(1),children:`Down`}),(0,s.jsx)(Q,{icon:t.E,tone:`danger`,title:`Remove question ${i+1}`,onClick:()=>I(e,n,a.filter((e,t)=>t!==i)),children:`Remove`})]})]}),(0,s.jsx)(Oe,{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:Ta(r,e,a)},!1),onBlur:()=>F(e)}),(0,s.jsx)(je,{label:`Kind of answer`,hint:`Sets the box people type into and what counts as a valid answer.`,value:r.type||`text`,options:xa(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.`,hintWideOnly:!0,enabled:!!r.required,onChange:e=>o({required:e},!0)}),r.type===`select`&&(0,s.jsx)(ja,{choices:r.options||[],onChange:e=>o({options:e},!0)}),r.type===`file`&&(0,s.jsx)(Oe,{label:`Words on the upload box`,hint:`What the box says before a file is picked. Leave it empty for “Attach a file”.`,value:r.placeholder||``,placeholder:`Attach a file`,onChange:e=>o({placeholder:e},!1),onBlur:()=>F(e)}),r.type===`currency`&&(0,s.jsx)(Oe,{label:`Currency symbol`,hint:`Shown inside the box, before the amount.`,value:r.currencySymbol||``,placeholder:`$`,onChange:e=>o({currencySymbol:e},!1),onBlur:()=>F(e)}),l&&(0,s.jsx)(Oe,{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:()=>F(e)})]},i)},V=(e,n)=>{let r=E[e]||n,i=_a.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)(Ee,{icon:t.w,title:`Basics`,description:`What people see at the top of this form and on its button.`,children:[(0,s.jsx)(Oe,{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:()=>F(e)}),(0,s.jsx)(Oe,{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:()=>F(e)})]}),(0,s.jsx)(Ee,{icon:t.x,title:`Who it is for`,description:`Who can fill this in, and where their answers land.`,children:(0,s.jsx)(je,{label:`Who it is for`,hint:`Who can fill this in follows the page this form was made for, so it cannot change here. Changing it after answers arrive would file new answers under the wrong list in your Inbox.`,value:a,allowEmpty:!1,disabled:!0,options:[{value:`public`,label:`Anyone`},{value:`private`,label:`Signed-in users`}],onChange:t=>P(e,r,{formType:t})})}),(0,s.jsx)(Ee,{icon:t.N,title:`After sending`,description:`What happens the moment someone sends this form.`,children:(0,s.jsx)(Oe,{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:()=>F(e)})}),(0,s.jsxs)(Ee,{icon:t.q,title:`Questions`,description:`Everything this form asks for, in the order people answer it.`,actions:(0,s.jsx)(Q,{icon:t.L,compact:!0,title:`Add a question`,onClick:()=>I(e,r,[...o,Ea()]),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)=>ee(e,r,t,n,o)),o.length>0&&(0,s.jsx)(`div`,{className:`flex justify-start`,children:(0,s.jsx)(Q,{icon:t.L,onClick:()=>I(e,r,[...o,Ea()]),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.F,tone:`danger`,compact:!0,title:`Reset this form`,onClick:()=>C({kind:`reset`,id:e}),children:`Reset this form`}),!i&&(0,s.jsx)(Q,{icon:t.E,tone:`danger`,compact:!0,title:`Delete this form`,onClick:()=>C({kind:`delete`,id:e}),children:`Delete this form`})]})]})};return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsx)(t.p.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)(ce,{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)(de,{}),(0,s.jsxs)(`div`,{className:`flex flex-col glass-panel border-y sm:border border-[var(--panel-border)] rounded-none sm:rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background -mx-4 sm:mx-0`,children:[(0,s.jsx)(`div`,{className:`flex items-start justify-between gap-3 sm:gap-6 mb-4 pb-4 md:mb-4 md:pb-5 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-4 pt-5 sm:px-6 sm:pt-6 md:px-10 md:pt-8 bg-background/50`,children:(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(`h2`,{className:`text-lg md:text-xl font-extrabold text-foreground tracking-tight leading-tight md:leading-7`,children:`Your forms`}),(0,s.jsxs)(`p`,{className:`text-[12.5px] md:text-[14px] font-medium text-foreground/60 mt-1 md:mt-2 leading-relaxed`,children:[(0,s.jsx)(`span`,{className:`md:hidden`,children:`Look a form over and touch it up. Answers arrive in your Inbox.`}),(0,s.jsx)(`span`,{className:`max-md:hidden`,children:`Look a form over and touch it up — its name, button text and questions. New forms are made on the Pages screen, with their page. Answers arrive in your Inbox.`})]})]})}),(0,s.jsx)(`div`,{className:`p-4 sm:p-6 md:px-8 md:pb-8 md:pt-3 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.I,{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)(`p`,{className:`text-[12.5px] text-foreground/55 font-medium leading-relaxed text-center max-w-md`,children:Da.firstForm})]})}):(0,s.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,s.jsx)(t.m,{children:Object.entries(l).map(([e,n])=>{let r=E[e]||n,i=b[e],a=p[e],o=(r.fields||[]).length;return(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0,y:-12},transition:{duration:.35,ease:`easeOut`},onClick:()=>z(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-row justify-between w-full gap-2 ${y?`items-start`:`items-center`}`,children:[(0,s.jsxs)(`div`,{className:`flex flex-col gap-1 min-w-0 flex-1 pr-2 sm: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.K,{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.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[11px] font-semibold px-2.5 py-[3px] rounded-full border shrink-0 ${r.formType===`private`?`text-blue-500 border-blue-500/25 bg-blue-500/[0.07]`:`text-emerald-500 border-emerald-500/25 bg-emerald-500/[0.07]`}`,children:[(0,s.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 ${r.formType===`private`?`bg-blue-500`:`bg-emerald-500`}`}),Sa[r.formType||`public`]]}),(0,s.jsx)(`span`,{className:`max-sm:hidden text-[11px] font-medium text-foreground/45`,children:o===1?`1 question`:`${o} questions`})]})]}),y?(0,s.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0 -mt-0.5 -mr-1.5`,children:[(0,s.jsx)(`button`,{type:`button`,title:`Preview this form`,"aria-label":`Preview this form`,onClick:e=>{e.stopPropagation(),g(r)},className:`w-8 h-8 flex items-center justify-center rounded-lg text-foreground/40 hover:text-accent hover:bg-foreground/5 transition-colors cursor-pointer`,children:(0,s.jsx)(t.ct,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{type:`button`,title:i?`Close this form`:`Open this form`,"aria-label":i?`Close this form`:`Open this form`,"aria-expanded":i,onClick:t=>{t.stopPropagation(),z(e)},className:`w-8 h-8 flex items-center justify-center rounded-lg text-foreground/40 hover:text-accent hover:bg-foreground/5 transition-colors cursor-pointer`,children:(0,s.jsx)(t.wt,{className:`w-4 h-4 transition-transform duration-300 ${i?`rotate-180`:``}`})})]}):(0,s.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,s.jsx)(Q,{icon:t.ct,title:`Preview this form`,onClick:e=>{e.stopPropagation(),g(r)},children:`Preview`}),(0,s.jsx)(`button`,{type:`button`,title:i?`Close this form`:`Open this form`,"aria-label":i?`Close this form`:`Open this form`,"aria-expanded":i,onClick:t=>{t.stopPropagation(),z(e)},className:`w-9 h-9 flex items-center justify-center rounded-[var(--btn-radius,0.75rem)] text-foreground/40 hover:text-accent hover:bg-foreground/[0.06] transition-colors cursor-pointer`,children:(0,s.jsx)(t.wt,{className:`w-4 h-4 transition-transform duration-300 ${i?`rotate-180`:``}`})})]})]}),(0,s.jsx)(t.m,{children:i&&(0,s.jsx)(t.p.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.K,{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)(ve,{isOpen:!!S,onCancel:()=>C(null),onConfirm:()=>{S&&(S.kind===`delete`?L(S.id):R(S.id))},title:S?.kind===`reset`?`Reset this form`:`Delete this form`,message:S?.kind===`reset`?`Undo every change made to ${l[S.id]?.title||S.id} and put it back the way it shipped. Answers already collected are kept.`:`Permanently delete ${S?l[S.id]?.title||S.id:``}. This cannot be undone. Answers already collected are kept.`,confirmText:S?.kind===`reset`?`Reset form`:`Delete form`,isProcessing:w}),h&&(0,s.jsx)(t.t,{formConfig:h,onClose:()=>g(null)})]})}var Na=`src/your-ai-workflow-firebase-os`;function Pa(){let e=new Set;for(let[t,n]of F()){let r=n?.config?.route,i=typeof r==`string`&&r.trim()?r.startsWith(`/`)?r:`/`+r:`/`+t.toLowerCase();e.add(i)}return[...e].sort()}var Fa=e=>(e||``).split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``);function Ia(e){let t=e?.contentKey||e?.tabName||e?.pageName||e?.pageId||`Page`;return`${Na}/microcomponents/${Fa(String(t))||`Page`}Content.tsx`}function La(e,t){let n=t.replace(/^.*\//,``).replace(/\.tsx$/,``),r=n.replace(/Content$/,``).replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase();return[`My app has a page at ${e} and it is still empty after you said it was done. The ONLY thing that fills this page is one file: ${t}, with a default export, registered in ${Na}/microcomponents/registry.ts.`,`Check these in order and fix whatever is wrong, without asking me questions:`,`1. The file exists at exactly that path and name — not another folder, not another spelling. If you put it somewhere else, move it there.`,`2. It has a default export. A named-only export is silently ignored.`,`3. ${Na}/microcomponents/registry.ts contains these two lines: import ${n} from './${n}'; and registerMicrocomponent('${r}', ${n}); — registerMicrocomponent is imported there from 'your-ai-workflow-firebase-os'. Add them if they are missing, and never remove another page's lines.`,`4. You created nothing else for this page — no config file, no route, no page, and no edit to src/App.tsx or src/main.tsx. Undo any of those you made.`,`Then tell me, in one sentence, which of these was wrong.`].join(`
23
23
  `)}function Ra(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 ${Na}/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. ${Na}/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(`
24
- `)}function za({config:e,customContent:n}){let{config:i}=t.Rt(),{userRole:a}=N();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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col relative min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4 md:mb-6 flex items-center gap-3`,children:[(0,s.jsx)(Et,{}),(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(ce,{children:e.pageTitle||e.pageName||`New Page`}),e.route&&(0,s.jsxs)(`div`,{className:`max-sm:hidden sm: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)(t.p.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 m-4 md:m-8 gap-6`,children:[(0,s.jsxs)(`div`,{className:`w-full glass-panel border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-16 text-center opacity-70`,children:[(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 mx-auto`,children:`Open the Pages screen, say what you would like on it, and copy the sentence there into your assistant's chat.`})]}),w(a)&&(0,s.jsx)(`div`,{className:`w-full max-w-lg`,children:(0,s.jsx)(rt,{compact:!0,title:`Already asked, and it is still empty? Paste this`,prompt:La(e.route||`/`,Ia(e))})})]})})]})}function Ba({config:e,customContent:n}){let{user:a}=N(),{config:c}=t.Rt(),[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,A]=(0,r.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;F(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[P,F]=(0,r.useState)(!0),[I,L]=(0,r.useState)(!1),[R,z]=(0,r.useState)(null),[B,ee]=(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.Ht,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.Ht,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)return;let r=await t.o(n);E(!0);try{let e=`user_files/${`${Date.now()}_${r.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,n=(0,o.ref)(t.Wt,e);await(0,o.uploadBytes)(n,r,{customMetadata:{ownerId:a.uid}});let s=await(0,o.getDownloadURL)(n);if(w.current)w.current(r,s,{uid:a.uid,storagePath:e});else{let e=await(0,i.addDoc)((0,i.collection)(t.Ht,G),{name:r.name,note:`${r.type||`File`} · ${_e(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type||`unknown`,fileSize:r.size,downloadURL:s,createdAt:(0,i.serverTimestamp)()});d(t=>[{id:e.id,name:r.name,note:`${r.type||`File`} · ${_e(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type,fileSize:r.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.Ht,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.Wt,`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,ne]=(0,r.useState)(null),[re,ie]=(0,r.useState)(``),[ae,X]=(0,r.useState)(!1),[oe,Z]=(0,r.useState)(null),se=(0,r.useRef)([]),le=e=>{if(e.recordType===`file`){ne(e.id),ie(e.name);return}z(e.id),ee(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),se.current=n.map(e=>e.key)},ue=async()=>{if(!Y||!re.trim()){ne(null);return}let e=u.find(e=>e.id===Y);if(e&&e.name===re.trim()){ne(null);return}X(!0);try{await(0,i.updateDoc)((0,i.doc)(t.Ht,G,Y),{name:re.trim()}),d(e=>e.map(e=>e.id===Y?{...e,name:re.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}X(!1),ne(null)},fe=async()=>{await pe(),z(null)},pe=async()=>{if(!R||!B.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=se.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,i.deleteField)()});try{await(0,i.updateDoc)((0,i.doc)(t.Ht,G,R),{name:B.trim(),note:V.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:B.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),se.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.nt,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,s.jsx)(t.b,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,s.jsx)(t.ot,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,s.jsx)(t.Ft,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,s.jsx)(t.mt,{className:`w-4 h-4`}):(0,s.jsx)(t.at,{className:`w-4 h-4`}):(0,s.jsx)(t.ot,{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.h[r]?t.h[r]:t.h[n]?t.h[n]:t.C||t.L})(),xe=e.buttonStyle!==`secondary`,Se=e.buttonStorageStyle===`primary`;return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsx)(t.p.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)(ce,{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)(de,{}),(0,s.jsxs)(t.p.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.jsx)(`input`,{type:`file`,ref:W,onChange:q,className:`hidden`}),!n&&(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm: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.jsx)(s.Fragment,{children:(0,s.jsxs)(t.p.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${Se?`btn-primary`:`btn-secondary`}`,children:[T?(0,s.jsx)(t.K,{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.p.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`} ${xe?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,s.jsx)(t.L,{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.K,{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.Ht,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.Ht,G,e),n)},deleteRecord:async e=>{await(0,i.deleteDoc)((0,i.doc)(t.Ht,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.p.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.L,{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.m,{children:u.map((e,n)=>{let r=R===e.id;return(0,s.jsxs)(t.p.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-100 md:opacity-0 md: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:oe===e.id?(0,s.jsx)(t.Tt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,s.jsx)(t.J,{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.dt,{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.R,{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.E,{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`&&j(e)},className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`cursor-pointer hover:scale-105 transition-transform ${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:[Y===e.id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:re,onChange:e=>ie(e.target.value),onBlur:()=>ue(),onKeyDown:e=>{e.key===`Enter`&&ue(),e.key===`Escape`&&ne(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:()=>j(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))]},e.id)})})})]})]})]})]}),(0,s.jsx)(t.m,{children:m&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.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.p.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.Ht,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.v,{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.c,{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.m,{children:M&&(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.p.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,s.jsx)(`button`,{onClick:()=>j(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,s.jsx)(t.v,{className:`w-5 h-5`})}),(0,s.jsxs)(t.p.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:M.fileName||M.name}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[ge(M.fileType),` • `,_e(M.fileSize||0)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.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:oe===`preview`?(0,s.jsx)(t.Tt,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.J,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{j(null),ne(M.id),ie(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,s.jsx)(t.R,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{j(null),O(M.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,s.jsx)(t.E,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:M.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,s.jsx)(t.dt,{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:()=>j(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.K,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,s.jsx)(`img`,{onLoad:()=>F(!1),onError:()=>F(!1),src:M.downloadURL,alt:M.fileName||M.name,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full object-contain drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] rounded-lg pointer-events-auto transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType?.startsWith(`video/`)?(0,s.jsx)(`video`,{onLoadedData:()=>F(!1),onError:()=>F(!1),src:M.downloadURL,controls:!0,autoPlay:!0,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full outline-none bg-black/40 rounded-lg pointer-events-auto drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType===`application/pdf`?(0,s.jsx)(`iframe`,{onLoad:()=>F(!1),src:M.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.ot,{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.m,{children:R&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.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.p.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.K,{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.v,{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:B,onChange:e=>ee(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.v,{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.L,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,s.jsx)(be,{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 Va({config:e,customContent:n}){let{user:a}=N(),{config:c}=t.Rt(),[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,A]=(0,r.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;F(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[P,F]=(0,r.useState)(!0),[I,L]=(0,r.useState)(!1),[R,z]=(0,r.useState)(null),[B,ee]=(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.Ht,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.Ht,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 ne=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Ht,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)}},re=async e=>{let n=e.target.files?.[0];if(!n||!a)return;let r=await t.o(n);E(!0);try{let e=`admin_files/${`${Date.now()}_${r.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,n=(0,o.ref)(t.Wt,e);await(0,o.uploadBytes)(n,r,{customMetadata:{ownerId:a.uid}});let s=await(0,o.getDownloadURL)(n);if(w.current)w.current(r,s,{uid:a.uid,storagePath:e});else{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Ht,J),{name:r.name,note:`${r.type||`File`} · ${ve(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type||`unknown`,fileSize:r.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=``)},ie=async()=>{if(D){L(!0);try{let e=u.find(e=>e.id===D);if(await(0,i.deleteDoc)((0,i.doc)(t.Ht,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.Wt,`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)}},[ae,X]=(0,r.useState)(null),[oe,Z]=(0,r.useState)(``),[se,le]=(0,r.useState)(!1),ue=e=>{if(e.recordType===`file`){X(e.id),Z(e.name);return}z(e.id),ee(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)},fe=async()=>{if(!ae||!oe.trim()){X(null);return}let e=u.find(e=>e.id===ae);if(e&&e.name===oe.trim()){X(null);return}le(!0);try{await(0,i.updateDoc)((0,i.doc)(t.Ht,J,ae),{name:oe.trim()}),d(e=>e.map(e=>e.id===ae?{...e,name:oe.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}le(!1),X(null)},pe=async()=>{if(!R||!B.trim()){z(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.Ht,J,R),{name:B.trim(),note:V.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:B.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),z(null)},me=async()=>{if(!R||!B.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.Ht,J,R),{name:B.trim(),note:V.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:B.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)}},he=(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.nt,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,s.jsx)(t.b,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,s.jsx)(t.ot,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,s.jsx)(t.Ft,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,s.jsx)(t.mt,{className:`w-4 h-4`}):(0,s.jsx)(t.at,{className:`w-4 h-4`}):(0,s.jsx)(t.ot,{className:`w-4 h-4`}),ge=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-purple-500/10 text-purple-500`:e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?`bg-blue-500/10 text-blue-500`:e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?`bg-yellow-500/10 text-yellow-500`:e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?`bg-emerald-500/10 text-emerald-500`:`bg-foreground/5 text-foreground/40`:`bg-foreground/5 text-foreground/40`,_e=e=>{if(!e)return`FILE`;let t={"application/pdf":`PDF`,"application/zip":`ZIP`,"application/x-zip-compressed":`ZIP`,"application/x-rar-compressed":`RAR`,"application/x-7z-compressed":`7Z`,"application/json":`JSON`,"application/xml":`XML`,"application/javascript":`JS`,"application/typescript":`TS`,"application/msword":`DOC`,"application/vnd.openxmlformats-officedocument.wordprocessingml.document":`DOCX`,"application/vnd.ms-excel":`XLS`,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":`XLSX`,"application/vnd.ms-powerpoint":`PPT`,"application/vnd.openxmlformats-officedocument.presentationml.presentation":`PPTX`,"application/rtf":`RTF`,"application/x-tar":`TAR`,"application/gzip":`GZ`,"text/plain":`TXT`,"text/html":`HTML`,"text/css":`CSS`,"text/csv":`CSV`,"text/markdown":`MD`},n=e.toLowerCase();if(t[n])return t[n];let r=n.split(`/`);return r[r.length-1].replace(/^x-/,``).replace(/^vnd\..*\./,``).toUpperCase().slice(0,10)},ve=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},ye=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},xe=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.h[r]?t.h[r]:t.h[n]?t.h[n]:t.C||t.L})(),Se=e.buttonStyle!==`secondary`,Ce=e.buttonStorageStyle===`primary`,we=e=>e.uid===a?.uid,Te=({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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsx)(t.p.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)(ce,{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)(de,{}),(0,s.jsxs)(t.p.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.jsx)(`input`,{type:`file`,ref:W,onChange:re,className:`hidden`}),!n&&(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm: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.jsx)(s.Fragment,{children:(0,s.jsxs)(t.p.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${Ce?`btn-primary`:`btn-secondary`}`,children:[T?(0,s.jsx)(t.K,{className:`w-4 h-4 animate-spin`}):(0,s.jsx)(xe,{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.p.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`} ${Se?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,s.jsx)(t.L,{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.K,{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.Ht,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.Ht,J,e),n)},deleteRecord:async e=>{await(0,i.deleteDoc)((0,i.doc)(t.Ht,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.p.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.L,{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.m,{children:u.map((e,n)=>{let r=R===e.id,i=we(e);return(0,s.jsxs)(t.p.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-100 md:opacity-0 md: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.Tt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,s.jsx)(t.J,{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.dt,{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.R,{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.E,{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`&&j(e)},className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`cursor-pointer hover:scale-105 transition-transform ${ge(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?he(e.fileType,e.downloadURL):(0,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:[ae===e.id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:oe,onChange:e=>Z(e.target.value),onBlur:()=>fe(),onKeyDown:e=>{e.key===`Enter`&&fe(),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:()=>j(e)}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ye(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)(Te,{record:e})]},e.id)})})})]})]})]})]}),(0,s.jsx)(t.m,{children:m&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.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.p.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.Ht,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:ne,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.v,{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.c,{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.m,{children:M&&(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.p.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,s.jsx)(`button`,{onClick:()=>j(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,s.jsx)(t.v,{className:`w-5 h-5`})}),(0,s.jsxs)(t.p.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:M.fileName||M.name}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[_e(M.fileType),` • `,ve(M.fileSize||0)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.downloadURL),K(`preview`),setTimeout(()=>K(null),2e3)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 transition-colors rounded-xl shadow-sm hover:text-emerald-500 cursor-pointer`,title:`Copy Link`,children:G===`preview`?(0,s.jsx)(t.Tt,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.J,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{j(null),X(M.id),Z(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,s.jsx)(t.R,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{j(null),O(M.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,s.jsx)(t.E,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:M.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,s.jsx)(t.dt,{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:()=>j(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.K,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,s.jsx)(`img`,{onLoad:()=>F(!1),onError:()=>F(!1),src:M.downloadURL,alt:M.fileName||M.name,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full object-contain drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] rounded-lg pointer-events-auto transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType?.startsWith(`video/`)?(0,s.jsx)(`video`,{onLoadedData:()=>F(!1),onError:()=>F(!1),src:M.downloadURL,controls:!0,autoPlay:!0,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full outline-none bg-black/40 rounded-lg pointer-events-auto drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType===`application/pdf`?(0,s.jsx)(`iframe`,{onLoad:()=>F(!1),src:M.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.ot,{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.m,{children:R&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.div,{onClick:()=>pe(),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.p.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.K,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>pe(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,s.jsx)(t.v,{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:B,onChange:e=>ee(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>me(),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:()=>me(),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:()=>me(),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:()=>me(),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.v,{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.L,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,s.jsx)(be,{isOpen:!!D,onCancel:()=>O(null),onConfirm:ie,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 Ha({config:e,customContent:n}){let{user:a}=N(),{config:c}=t.Rt(),[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,A]=(0,r.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;F(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[P,F]=(0,r.useState)(!0),[I,L]=(0,r.useState)(!1),[R,z]=(0,r.useState)(null),[B,ee]=(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.Ht,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.Ht,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||``}),ne=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Ht,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)}},re=async e=>{let n=e.target.files?.[0];if(!n||!a)return;let r=await t.o(n);E(!0);try{let e=`mem_files/${`${Date.now()}_${r.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,n=(0,o.ref)(t.Wt,e);await(0,o.uploadBytes)(n,r,{customMetadata:{ownerId:a.uid}});let s=await(0,o.getDownloadURL)(n);if(w.current)w.current(r,s,{uid:a.uid,storagePath:e});else{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Ht,J),{name:r.name,note:`${r.type||`File`} · ${ve(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type||`unknown`,fileSize:r.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=``)},ie=async()=>{if(D){L(!0);try{let e=u.find(e=>e.id===D);if(await(0,i.deleteDoc)((0,i.doc)(t.Ht,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.Wt,`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)}},[ae,X]=(0,r.useState)(null),[oe,Z]=(0,r.useState)(``),[se,le]=(0,r.useState)(!1),ue=e=>{if(e.recordType===`file`){X(e.id),Z(e.name);return}z(e.id),ee(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)},fe=async()=>{if(!ae||!oe.trim()){X(null);return}let e=u.find(e=>e.id===ae);if(e&&e.name===oe.trim()){X(null);return}le(!0);try{await(0,i.updateDoc)((0,i.doc)(t.Ht,J,ae),{name:oe.trim()}),d(e=>e.map(e=>e.id===ae?{...e,name:oe.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}le(!1),X(null)},pe=async()=>{await me(),z(null)},me=async()=>{if(!R||!B.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.Ht,J,R),{name:B.trim(),note:V.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:B.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)},he=(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.nt,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,s.jsx)(t.b,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,s.jsx)(t.ot,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,s.jsx)(t.Ft,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,s.jsx)(t.mt,{className:`w-4 h-4`}):(0,s.jsx)(t.at,{className:`w-4 h-4`}):(0,s.jsx)(t.ot,{className:`w-4 h-4`}),ge=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-purple-500/10 text-purple-500`:e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?`bg-blue-500/10 text-blue-500`:e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?`bg-yellow-500/10 text-yellow-500`:e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?`bg-emerald-500/10 text-emerald-500`:`bg-foreground/5 text-foreground/40`:`bg-foreground/5 text-foreground/40`,_e=e=>{if(!e)return`FILE`;let t={"application/pdf":`PDF`,"application/zip":`ZIP`,"application/x-zip-compressed":`ZIP`,"application/x-rar-compressed":`RAR`,"application/x-7z-compressed":`7Z`,"application/json":`JSON`,"application/xml":`XML`,"application/javascript":`JS`,"application/typescript":`TS`,"application/msword":`DOC`,"application/vnd.openxmlformats-officedocument.wordprocessingml.document":`DOCX`,"application/vnd.ms-excel":`XLS`,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":`XLSX`,"application/vnd.ms-powerpoint":`PPT`,"application/vnd.openxmlformats-officedocument.presentationml.presentation":`PPTX`,"application/rtf":`RTF`,"application/x-tar":`TAR`,"application/gzip":`GZ`,"text/plain":`TXT`,"text/html":`HTML`,"text/css":`CSS`,"text/csv":`CSV`,"text/markdown":`MD`},n=e.toLowerCase();if(t[n])return t[n];let r=n.split(`/`);return r[r.length-1].replace(/^x-/,``).replace(/^vnd\..*\./,``).toUpperCase().slice(0,10)},ve=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},ye=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},xe=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.h[r]?t.h[r]:t.h[n]?t.h[n]:t.C||t.L})(),Se=e.buttonStyle!==`secondary`,Ce=e.buttonStorageStyle===`primary`,we=e=>e.uid===a?.uid,Te=({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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsx)(t.p.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)(ce,{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)(de,{}),(0,s.jsxs)(t.p.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.jsx)(`input`,{type:`file`,ref:W,onChange:re,className:`hidden`}),!n&&(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm: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.jsx)(s.Fragment,{children:(0,s.jsxs)(t.p.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${Ce?`btn-primary`:`btn-secondary`}`,children:[T?(0,s.jsx)(t.K,{className:`w-4 h-4 animate-spin`}):(0,s.jsx)(xe,{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.p.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`} ${Se?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,s.jsx)(t.L,{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.K,{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.Ht,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.Ht,J,e),n)},deleteRecord:async e=>{await(0,i.deleteDoc)((0,i.doc)(t.Ht,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.p.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.L,{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.m,{children:u.map(e=>{let n=R===e.id,r=we(e);return(0,s.jsxs)(t.p.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-100 md:opacity-0 md: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.Tt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,s.jsx)(t.J,{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.dt,{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.R,{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.E,{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`&&j(e)},className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`cursor-pointer hover:scale-105 transition-transform ${ge(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?he(e.fileType,e.downloadURL):(0,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:[ae===e.id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:oe,onChange:e=>Z(e.target.value),onBlur:()=>fe(),onKeyDown:e=>{e.key===`Enter`&&fe(),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:()=>j(e)}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ye(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)(Te,{record:e})]},e.id)})})})]})]})]})]}),(0,s.jsx)(t.m,{children:m&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.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.p.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.Ht,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:ne,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.v,{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.c,{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.m,{children:M&&(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.p.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,s.jsx)(`button`,{onClick:()=>j(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,s.jsx)(t.v,{className:`w-5 h-5`})}),(0,s.jsxs)(t.p.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:M.fileName||M.name}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[_e(M.fileType),` • `,ve(M.fileSize||0)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.downloadURL),K(`preview`),setTimeout(()=>K(null),2e3)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 transition-colors rounded-xl shadow-sm hover:text-emerald-500 cursor-pointer`,title:`Copy Link`,children:G===`preview`?(0,s.jsx)(t.Tt,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.J,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{j(null),X(M.id),Z(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,s.jsx)(t.R,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{j(null),O(M.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,s.jsx)(t.E,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:M.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,s.jsx)(t.dt,{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:()=>j(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.K,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,s.jsx)(`img`,{onLoad:()=>F(!1),onError:()=>F(!1),src:M.downloadURL,alt:M.fileName||M.name,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full object-contain drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] rounded-lg pointer-events-auto transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType?.startsWith(`video/`)?(0,s.jsx)(`video`,{onLoadedData:()=>F(!1),onError:()=>F(!1),src:M.downloadURL,controls:!0,autoPlay:!0,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full outline-none bg-black/40 rounded-lg pointer-events-auto drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType===`application/pdf`?(0,s.jsx)(`iframe`,{onLoad:()=>F(!1),src:M.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.ot,{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.m,{children:R&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.div,{onClick:()=>pe(),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.p.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.K,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>pe(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,s.jsx)(t.v,{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:B,onChange:e=>ee(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>me(),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:()=>me(),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:()=>me(),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:()=>me(),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.v,{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.L,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,s.jsx)(be,{isOpen:!!D,onCancel:()=>O(null),onConfirm:ie,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 Ua=[`board`,`table`,`calendar`,`drive`],Wa=[`inline_form`,`popup_form`],Ga=e=>typeof e!=`string`||e===``||e===`none`||e===`custom`||![...Ua,...Wa].includes(e),Ka=(e,t)=>Ga(e)||t&&!qa(e),qa=e=>typeof e==`string`&&Ua.includes(e),Ja=`/src/your-ai-workflow-firebase-os/microcomponents`,Ya=e=>(e||``).split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``),Xa=e=>{let t=e.replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase();return[t,t.replace(/_/g,``)]},Za=e=>{let t=[e?.contentKey,e?.tabName,e?.pageId,e?.pageName].filter(e=>typeof e==`string`&&e.trim()).map(e=>Ya(e)).filter(Boolean);return[...new Set(t)].map(e=>`${e}Content.tsx`)},Qa=e=>{if(typeof window>`u`)return!1;let t=window.__FBOS_MICROCOMPONENTS__;if(!t)return!1;let n=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_|_$/g,``);return[e?.contentKey,e?.tabName,e?.pageId,e?.pageName].filter(e=>typeof e==`string`&&e.trim()).some(e=>t[n(e)])},$a=new Map,eo=e=>{let t=$a.get(e);return t||(t=import(`${Ja}/${e}`).then(e=>typeof e?.default==`function`||typeof e?.default==`object`?e.default:null).catch(()=>null),$a.set(e,t)),t};async function to(e){if(typeof window>`u`||Qa(e))return null;for(let t of Za(e)){let e=await eo(t);if(!e)continue;let[n,r]=Xa(t.replace(/Content\.tsx$/,``)),i=window.__FBOS_MICROCOMPONENTS__||{};return window.__FBOS_MICROCOMPONENTS__={[n]:e,[r]:e,...i},e}return null}var no=(e,t)=>{let n=t?D(e.pageType):`public`;return{...e,pageType:n,isPrivate:t,isAdmin:n===`admin`,isInternal:n===`internal`,isShared:n===`internal`}};function ro(){let e=(0,c.useLocation)(),{user:n,userRole:a,loading:o,roleResolved:l}=N(),u=t.Bt(),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 no(e,e.isPrivate===!0)}catch{}}let n=(typeof window<`u`?window.__FBOS_PAGES__:null)||{},r=e.replace(/^\//,``);for(let[t,i]of Object.entries(n)){let n=i.config,a=i.isPublic,o=n.route||`/`+t;if(o===e||t===r)return no({...n,route:o,contentKey:n.pageId||t,pageId:t},!a)}return e===`/contact`?{route:`/contact`,template:`popup_form`,form:`contact`,pageId:`contact`,contentKey:`contact`,pageName:`Contact`,formConfigOverride:u.defaultConfigs?.contactForm||t.Jt}:e===`/support`?{route:`/support`,template:`popup_form`,form:`support`,pageId:`support`,contentKey:`support`,pageName:`Support`,formConfigOverride:u.defaultConfigs?.supportForm||t.Kt}: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.Ht,`sys_pages`,r)),(0,i.getDoc)((0,i.doc)(t.Ht,`sys_tabs`,r)),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Ht,`sys_pages`),(0,i.where)(`route`,`==`,e.pathname),(0,i.limit)(1))),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Ht,`sys_pages`),(0,i.where)(`route`,`==`,r),(0,i.limit)(1))),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Ht,`sys_tabs`),(0,i.where)(`route`,`==`,e.pathname),(0,i.limit)(1))),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Ht,`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=no(e.value.data(),t),m=e.value.id):e.value.docs&&e.value.docs.length>0&&(f=no(e.value.docs[0].data(),t),m=e.value.docs[0].id))};if(g(a,!1),g(s,!1),g(c,!1),g(o,!0),g(l,!0),g(d,!0),!f){let t=(typeof window<`u`?window.__FBOS_PAGES__:null)||{};for(let[n,i]of Object.entries(t)){let t=i.config,a=i.isPublic,o=t.route||`/`+n;if(o===e.pathname||n===r){f=no({...t,route:o,contentKey:t.pageId||n,pageId:n},!a),m=n;break}}}if(f||(e.pathname===`/contact`?(f={route:`/contact`,template:`popup_form`,form:`contact`,pageName:`Contact`},m=`contact`):e.pathname===`/support`&&(f={route:`/support`,template:`popup_form`,form:`support`,pageName:`Support`},m=`support`)),!n)return;if(f){if((m===`contact`||m===`support`)&&!f.form&&(f.form=m),f.contentKey||=f.pageId||m,f.pageId=m,localStorage.setItem(`fbos_route_${e.pathname}`,JSON.stringify(f)),f.form){let e=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},r=n=>u.defaultConfigs?.[n]||u.defaultConfigs?.[`${n}Form`]||e[n]||(n===`contact`?t.Jt:n===`support`?t.Kt: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.Ht,`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),[v,y]=(0,r.useState)(null),[b,x]=(0,r.useState)(!1),S=f&&f!==`not-found`&&typeof f==`object`?[f.contentKey,f.tabName,f.pageId,f.pageName].filter(Boolean).join(`|`):``;if((0,r.useEffect)(()=>{if(y(null),!S||Qa(f)){x(!1);return}let e=!1;x(!0),to(f).then(t=>{e||(t&&y(()=>t),x(!1))});let t=setTimeout(()=>{e||x(!1)},4e3);return()=>{e=!0,clearTimeout(t)}},[S]),(0,r.useEffect)(()=>{let e;return m||o||!l||b?e=setTimeout(()=>_(!0),150):_(!1),()=>clearTimeout(e)},[m,o,l,b]),m||o||!l||b)return g?n?(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col 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)(de,{}),(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.K,{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.K,{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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col 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-2xl sm: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.`}),w(a)&&(()=>{let t=Pa();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)(rt,{title:`If your assistant just made this page, paste this`,prompt:Ra(e.pathname)})]})})()]})});if((f.pageId===`support`||f.isPrivate)&&!n)return(0,s.jsx)(c.Navigate,{to:`/login`,state:{from:e}});if(!O(a,f.isPrivate?f.pageType:`public`))return f.isAdmin?(0,s.jsx)(mi,{}):(0,s.jsx)(pi,{});let C=u.customRoutes?.[e.pathname]||(f&&f.route?u.customRoutes?.[f.route]:null),T=f.pageName?.toLowerCase().replace(/\s+/g,`_`)||f.pageId||`custom_page`,E=`pub_${T}`,D=u.microcomponents||(typeof window<`u`?window.__FBOS_MICROCOMPONENTS__:void 0),k=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_|_$/g,``),A=[f.contentKey,f.tabName,f.pageId,f.pageName,f.pageName?.replace(/\s+/g,`_`)].filter(Boolean).map(e=>k(e)).reduce((e,t)=>e||D?.[t],void 0),j=C||A||v||void 0,M=f.route||f.pageId||`custom`;if(Ka(f.template,!!j))return f.isAdmin?(0,s.jsx)(Va,{config:f,customContent:j},M):f.isInternal?(0,s.jsx)(Ha,{config:f,customContent:j},M):f.isPrivate?(0,s.jsx)(Ba,{config:f,customContent:j},M):(0,s.jsx)(za,{config:f,customContent:j},M);if(f.template===`board`){let e=f.isAdmin?`admin_${f.pageId||T}`:f.isInternal?`mem_${f.pageId||T}`:f.isPrivate?`user_${f.pageId||T}`:E;return(0,s.jsx)(u.components?.TemplateBoard||Zt,{title:f.tabTitle||f.tabName||f.title||f.pageName||`Board`,subtitle:f.route,tasksCollection:`${e}_tasks`,categoriesCollection:`${e}_categories`,config:f,customContent:j},M)}if(f.template===`table`){let e=f.isAdmin?`admin_${f.pageId||T}`:f.isInternal?`mem_${f.pageId||T}`:f.isPrivate?`user_${f.pageId||T}`:E;return(0,s.jsx)(u.components?.TemplateTable||Dr,{title:f.tabTitle||f.tabName||f.title||f.pageName||`Table`,subtitle:f.route,tableCollection:`${e}_table`,config:f,customContent:j},M)}if(f.template===`calendar`){let e=f.isAdmin?`admin_${f.pageId||T}`:f.isInternal?`mem_${f.pageId||T}`:f.isPrivate?`user_${f.pageId||T}`:E;return(0,s.jsx)(u.components?.TemplateCalendar||Ar,{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:j},M)}if(f.template===`drive`){let e=f.isAdmin?`admin_${f.pageId||T}`:f.isInternal?`mem_${f.pageId||T}`:f.isPrivate?`user_${f.pageId||T}`:E;return(0,s.jsx)(u.components?.TemplateDrive||Ot,{title:f.tabTitle||f.tabName||f.title||f.pageName||`Drive`,subtitle:f.route,filesCollection:`${e}_files`,config:f,customContent:j},M)}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 io=r.default.createContext({}),ao=Object.defineProperty,oo=Object.getOwnPropertySymbols,so=Object.prototype.hasOwnProperty,co=Object.prototype.propertyIsEnumerable,lo=(e,t,n)=>t in e?ao(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,uo=(e,t)=>{for(var n in t||={})so.call(t,n)&&lo(e,n,t[n]);if(oo)for(var n of oo(t))co.call(t,n)&&lo(e,n,t[n]);return e},fo=(0,r.forwardRef)((e,t)=>{let n=uo(uo({},r.useContext(io)),e);return r.createElement(`svg`,uo({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`}))}),po=`rules_version = '2';
24
+ `)}function za({config:e,customContent:n}){let{config:i}=t.Rt(),{userRole:a}=N();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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col relative min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4 md:mb-6 flex items-center gap-3`,children:[(0,s.jsx)(Tt,{}),(0,s.jsxs)(`div`,{className:`min-w-0`,children:[(0,s.jsx)(ce,{children:e.pageTitle||e.pageName||`New Page`}),e.route&&(0,s.jsxs)(`div`,{className:`max-sm:hidden sm: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)(t.p.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 m-4 md:m-8 gap-6`,children:[(0,s.jsxs)(`div`,{className:`w-full glass-panel border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-16 text-center opacity-70`,children:[(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 mx-auto`,children:`Open the Pages screen, say what you would like on it, and copy the sentence there into your assistant's chat.`})]}),w(a)&&(0,s.jsx)(`div`,{className:`w-full max-w-lg`,children:(0,s.jsx)(tt,{compact:!0,title:`Already asked, and it is still empty? Paste this`,prompt:La(e.route||`/`,Ia(e))})})]})})]})}function Ba({config:e,customContent:n}){let{user:a}=N(),{config:c}=t.Rt(),[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,A]=(0,r.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;F(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[P,F]=(0,r.useState)(!0),[I,L]=(0,r.useState)(!1),[R,z]=(0,r.useState)(null),[B,ee]=(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.Ht,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.Ht,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)return;let r=await t.o(n);E(!0);try{let e=`user_files/${`${Date.now()}_${r.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,n=(0,o.ref)(t.Wt,e);await(0,o.uploadBytes)(n,r,{customMetadata:{ownerId:a.uid}});let s=await(0,o.getDownloadURL)(n);if(w.current)w.current(r,s,{uid:a.uid,storagePath:e});else{let e=await(0,i.addDoc)((0,i.collection)(t.Ht,G),{name:r.name,note:`${r.type||`File`} · ${_e(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type||`unknown`,fileSize:r.size,downloadURL:s,createdAt:(0,i.serverTimestamp)()});d(t=>[{id:e.id,name:r.name,note:`${r.type||`File`} · ${_e(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type,fileSize:r.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.Ht,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.Wt,`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,ne]=(0,r.useState)(null),[re,ie]=(0,r.useState)(``),[ae,X]=(0,r.useState)(!1),[oe,Z]=(0,r.useState)(null),se=(0,r.useRef)([]),le=e=>{if(e.recordType===`file`){ne(e.id),ie(e.name);return}z(e.id),ee(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),se.current=n.map(e=>e.key)},ue=async()=>{if(!Y||!re.trim()){ne(null);return}let e=u.find(e=>e.id===Y);if(e&&e.name===re.trim()){ne(null);return}X(!0);try{await(0,i.updateDoc)((0,i.doc)(t.Ht,G,Y),{name:re.trim()}),d(e=>e.map(e=>e.id===Y?{...e,name:re.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}X(!1),ne(null)},fe=async()=>{await pe(),z(null)},pe=async()=>{if(!R||!B.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=se.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,i.deleteField)()});try{await(0,i.updateDoc)((0,i.doc)(t.Ht,G,R),{name:B.trim(),note:V.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:B.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),se.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.nt,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,s.jsx)(t.b,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,s.jsx)(t.ot,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,s.jsx)(t.Ft,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,s.jsx)(t.mt,{className:`w-4 h-4`}):(0,s.jsx)(t.at,{className:`w-4 h-4`}):(0,s.jsx)(t.ot,{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]},ye=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},be=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.h[r]?t.h[r]:t.h[n]?t.h[n]:t.C||t.L})(),xe=e.buttonStyle!==`secondary`,Se=e.buttonStorageStyle===`primary`;return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsx)(t.p.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)(ce,{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)(de,{}),(0,s.jsxs)(t.p.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.jsx)(`input`,{type:`file`,ref:W,onChange:q,className:`hidden`}),!n&&(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm: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.jsx)(s.Fragment,{children:(0,s.jsxs)(t.p.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${Se?`btn-primary`:`btn-secondary`}`,children:[T?(0,s.jsx)(t.K,{className:`w-4 h-4 animate-spin`}):(0,s.jsx)(be,{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.p.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`} ${xe?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,s.jsx)(t.L,{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.K,{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.Ht,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.Ht,G,e),n)},deleteRecord:async e=>{await(0,i.deleteDoc)((0,i.doc)(t.Ht,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.p.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.L,{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.m,{children:u.map((e,n)=>{let r=R===e.id;return(0,s.jsxs)(t.p.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-100 md:opacity-0 md: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:oe===e.id?(0,s.jsx)(t.Tt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,s.jsx)(t.J,{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.dt,{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.R,{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.E,{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`&&j(e)},className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`cursor-pointer hover:scale-105 transition-transform ${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:[Y===e.id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:re,onChange:e=>ie(e.target.value),onBlur:()=>ue(),onKeyDown:e=>{e.key===`Enter`&&ue(),e.key===`Escape`&&ne(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:()=>j(e)}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ye(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)})})})]})]})]})]}),(0,s.jsx)(t.m,{children:m&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.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.p.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.Ht,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.v,{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.c,{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.m,{children:M&&(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.p.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,s.jsx)(`button`,{onClick:()=>j(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,s.jsx)(t.v,{className:`w-5 h-5`})}),(0,s.jsxs)(t.p.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:M.fileName||M.name}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[ge(M.fileType),` • `,_e(M.fileSize||0)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.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:oe===`preview`?(0,s.jsx)(t.Tt,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.J,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{j(null),ne(M.id),ie(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,s.jsx)(t.R,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{j(null),O(M.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,s.jsx)(t.E,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:M.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,s.jsx)(t.dt,{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:()=>j(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.K,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,s.jsx)(`img`,{onLoad:()=>F(!1),onError:()=>F(!1),src:M.downloadURL,alt:M.fileName||M.name,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full object-contain drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] rounded-lg pointer-events-auto transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType?.startsWith(`video/`)?(0,s.jsx)(`video`,{onLoadedData:()=>F(!1),onError:()=>F(!1),src:M.downloadURL,controls:!0,autoPlay:!0,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full outline-none bg-black/40 rounded-lg pointer-events-auto drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType===`application/pdf`?(0,s.jsx)(`iframe`,{onLoad:()=>F(!1),src:M.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.ot,{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.m,{children:R&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.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.p.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.K,{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.v,{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:B,onChange:e=>ee(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.v,{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.L,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,s.jsx)(ve,{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 Va({config:e,customContent:n}){let{user:a}=N(),{config:c}=t.Rt(),[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,A]=(0,r.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;F(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[P,F]=(0,r.useState)(!0),[I,L]=(0,r.useState)(!1),[R,z]=(0,r.useState)(null),[B,ee]=(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.Ht,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.Ht,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 ne=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Ht,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)}},re=async e=>{let n=e.target.files?.[0];if(!n||!a)return;let r=await t.o(n);E(!0);try{let e=`admin_files/${`${Date.now()}_${r.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,n=(0,o.ref)(t.Wt,e);await(0,o.uploadBytes)(n,r,{customMetadata:{ownerId:a.uid}});let s=await(0,o.getDownloadURL)(n);if(w.current)w.current(r,s,{uid:a.uid,storagePath:e});else{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Ht,J),{name:r.name,note:`${r.type||`File`} · ${ye(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type||`unknown`,fileSize:r.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=``)},ie=async()=>{if(D){L(!0);try{let e=u.find(e=>e.id===D);if(await(0,i.deleteDoc)((0,i.doc)(t.Ht,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.Wt,`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)}},[ae,X]=(0,r.useState)(null),[oe,Z]=(0,r.useState)(``),[se,le]=(0,r.useState)(!1),ue=e=>{if(e.recordType===`file`){X(e.id),Z(e.name);return}z(e.id),ee(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)},fe=async()=>{if(!ae||!oe.trim()){X(null);return}let e=u.find(e=>e.id===ae);if(e&&e.name===oe.trim()){X(null);return}le(!0);try{await(0,i.updateDoc)((0,i.doc)(t.Ht,J,ae),{name:oe.trim()}),d(e=>e.map(e=>e.id===ae?{...e,name:oe.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}le(!1),X(null)},pe=async()=>{if(!R||!B.trim()){z(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.Ht,J,R),{name:B.trim(),note:V.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:B.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),z(null)},me=async()=>{if(!R||!B.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.Ht,J,R),{name:B.trim(),note:V.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:B.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)}},he=(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.nt,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,s.jsx)(t.b,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,s.jsx)(t.ot,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,s.jsx)(t.Ft,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,s.jsx)(t.mt,{className:`w-4 h-4`}):(0,s.jsx)(t.at,{className:`w-4 h-4`}):(0,s.jsx)(t.ot,{className:`w-4 h-4`}),ge=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-purple-500/10 text-purple-500`:e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?`bg-blue-500/10 text-blue-500`:e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?`bg-yellow-500/10 text-yellow-500`:e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?`bg-emerald-500/10 text-emerald-500`:`bg-foreground/5 text-foreground/40`:`bg-foreground/5 text-foreground/40`,_e=e=>{if(!e)return`FILE`;let t={"application/pdf":`PDF`,"application/zip":`ZIP`,"application/x-zip-compressed":`ZIP`,"application/x-rar-compressed":`RAR`,"application/x-7z-compressed":`7Z`,"application/json":`JSON`,"application/xml":`XML`,"application/javascript":`JS`,"application/typescript":`TS`,"application/msword":`DOC`,"application/vnd.openxmlformats-officedocument.wordprocessingml.document":`DOCX`,"application/vnd.ms-excel":`XLS`,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":`XLSX`,"application/vnd.ms-powerpoint":`PPT`,"application/vnd.openxmlformats-officedocument.presentationml.presentation":`PPTX`,"application/rtf":`RTF`,"application/x-tar":`TAR`,"application/gzip":`GZ`,"text/plain":`TXT`,"text/html":`HTML`,"text/css":`CSS`,"text/csv":`CSV`,"text/markdown":`MD`},n=e.toLowerCase();if(t[n])return t[n];let r=n.split(`/`);return r[r.length-1].replace(/^x-/,``).replace(/^vnd\..*\./,``).toUpperCase().slice(0,10)},ye=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]},be=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},xe=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.h[r]?t.h[r]:t.h[n]?t.h[n]:t.C||t.L})(),Se=e.buttonStyle!==`secondary`,Ce=e.buttonStorageStyle===`primary`,we=e=>e.uid===a?.uid,Te=({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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsx)(t.p.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)(ce,{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)(de,{}),(0,s.jsxs)(t.p.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.jsx)(`input`,{type:`file`,ref:W,onChange:re,className:`hidden`}),!n&&(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm: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.jsx)(s.Fragment,{children:(0,s.jsxs)(t.p.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${Ce?`btn-primary`:`btn-secondary`}`,children:[T?(0,s.jsx)(t.K,{className:`w-4 h-4 animate-spin`}):(0,s.jsx)(xe,{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.p.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`} ${Se?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,s.jsx)(t.L,{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.K,{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.Ht,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.Ht,J,e),n)},deleteRecord:async e=>{await(0,i.deleteDoc)((0,i.doc)(t.Ht,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.p.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.L,{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.m,{children:u.map((e,n)=>{let r=R===e.id,i=we(e);return(0,s.jsxs)(t.p.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-100 md:opacity-0 md: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.Tt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,s.jsx)(t.J,{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.dt,{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.R,{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.E,{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`&&j(e)},className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`cursor-pointer hover:scale-105 transition-transform ${ge(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?he(e.fileType,e.downloadURL):(0,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:[ae===e.id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:oe,onChange:e=>Z(e.target.value),onBlur:()=>fe(),onKeyDown:e=>{e.key===`Enter`&&fe(),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:()=>j(e)}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:be(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)(Te,{record:e})]},e.id)})})})]})]})]})]}),(0,s.jsx)(t.m,{children:m&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.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.p.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.Ht,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:ne,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.v,{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.c,{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.m,{children:M&&(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.p.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,s.jsx)(`button`,{onClick:()=>j(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,s.jsx)(t.v,{className:`w-5 h-5`})}),(0,s.jsxs)(t.p.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:M.fileName||M.name}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[_e(M.fileType),` • `,ye(M.fileSize||0)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.downloadURL),K(`preview`),setTimeout(()=>K(null),2e3)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 transition-colors rounded-xl shadow-sm hover:text-emerald-500 cursor-pointer`,title:`Copy Link`,children:G===`preview`?(0,s.jsx)(t.Tt,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.J,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{j(null),X(M.id),Z(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,s.jsx)(t.R,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{j(null),O(M.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,s.jsx)(t.E,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:M.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,s.jsx)(t.dt,{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:()=>j(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.K,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,s.jsx)(`img`,{onLoad:()=>F(!1),onError:()=>F(!1),src:M.downloadURL,alt:M.fileName||M.name,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full object-contain drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] rounded-lg pointer-events-auto transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType?.startsWith(`video/`)?(0,s.jsx)(`video`,{onLoadedData:()=>F(!1),onError:()=>F(!1),src:M.downloadURL,controls:!0,autoPlay:!0,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full outline-none bg-black/40 rounded-lg pointer-events-auto drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType===`application/pdf`?(0,s.jsx)(`iframe`,{onLoad:()=>F(!1),src:M.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.ot,{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.m,{children:R&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.div,{onClick:()=>pe(),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.p.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.K,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>pe(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,s.jsx)(t.v,{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:B,onChange:e=>ee(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>me(),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:()=>me(),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:()=>me(),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:()=>me(),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.v,{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.L,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,s.jsx)(ve,{isOpen:!!D,onCancel:()=>O(null),onConfirm:ie,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 Ha({config:e,customContent:n}){let{user:a}=N(),{config:c}=t.Rt(),[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,A]=(0,r.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;F(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[P,F]=(0,r.useState)(!0),[I,L]=(0,r.useState)(!1),[R,z]=(0,r.useState)(null),[B,ee]=(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.Ht,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.Ht,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||``}),ne=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Ht,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)}},re=async e=>{let n=e.target.files?.[0];if(!n||!a)return;let r=await t.o(n);E(!0);try{let e=`mem_files/${`${Date.now()}_${r.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,n=(0,o.ref)(t.Wt,e);await(0,o.uploadBytes)(n,r,{customMetadata:{ownerId:a.uid}});let s=await(0,o.getDownloadURL)(n);if(w.current)w.current(r,s,{uid:a.uid,storagePath:e});else{let e=Y();await(0,i.addDoc)((0,i.collection)(t.Ht,J),{name:r.name,note:`${r.type||`File`} · ${ye(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type||`unknown`,fileSize:r.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=``)},ie=async()=>{if(D){L(!0);try{let e=u.find(e=>e.id===D);if(await(0,i.deleteDoc)((0,i.doc)(t.Ht,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.Wt,`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)}},[ae,X]=(0,r.useState)(null),[oe,Z]=(0,r.useState)(``),[se,le]=(0,r.useState)(!1),ue=e=>{if(e.recordType===`file`){X(e.id),Z(e.name);return}z(e.id),ee(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)},fe=async()=>{if(!ae||!oe.trim()){X(null);return}let e=u.find(e=>e.id===ae);if(e&&e.name===oe.trim()){X(null);return}le(!0);try{await(0,i.updateDoc)((0,i.doc)(t.Ht,J,ae),{name:oe.trim()}),d(e=>e.map(e=>e.id===ae?{...e,name:oe.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}le(!1),X(null)},pe=async()=>{await me(),z(null)},me=async()=>{if(!R||!B.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.Ht,J,R),{name:B.trim(),note:V.trim(),...e}),d(e=>e.map(e=>{if(e.id!==R)return e;let t={...e,name:B.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)},he=(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.nt,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,s.jsx)(t.b,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,s.jsx)(t.ot,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,s.jsx)(t.Ft,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,s.jsx)(t.mt,{className:`w-4 h-4`}):(0,s.jsx)(t.at,{className:`w-4 h-4`}):(0,s.jsx)(t.ot,{className:`w-4 h-4`}),ge=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-purple-500/10 text-purple-500`:e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?`bg-blue-500/10 text-blue-500`:e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?`bg-yellow-500/10 text-yellow-500`:e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?`bg-emerald-500/10 text-emerald-500`:`bg-foreground/5 text-foreground/40`:`bg-foreground/5 text-foreground/40`,_e=e=>{if(!e)return`FILE`;let t={"application/pdf":`PDF`,"application/zip":`ZIP`,"application/x-zip-compressed":`ZIP`,"application/x-rar-compressed":`RAR`,"application/x-7z-compressed":`7Z`,"application/json":`JSON`,"application/xml":`XML`,"application/javascript":`JS`,"application/typescript":`TS`,"application/msword":`DOC`,"application/vnd.openxmlformats-officedocument.wordprocessingml.document":`DOCX`,"application/vnd.ms-excel":`XLS`,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":`XLSX`,"application/vnd.ms-powerpoint":`PPT`,"application/vnd.openxmlformats-officedocument.presentationml.presentation":`PPTX`,"application/rtf":`RTF`,"application/x-tar":`TAR`,"application/gzip":`GZ`,"text/plain":`TXT`,"text/html":`HTML`,"text/css":`CSS`,"text/csv":`CSV`,"text/markdown":`MD`},n=e.toLowerCase();if(t[n])return t[n];let r=n.split(`/`);return r[r.length-1].replace(/^x-/,``).replace(/^vnd\..*\./,``).toUpperCase().slice(0,10)},ye=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]},be=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},xe=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.h[r]?t.h[r]:t.h[n]?t.h[n]:t.C||t.L})(),Se=e.buttonStyle!==`secondary`,Ce=e.buttonStorageStyle===`primary`,we=e=>e.uid===a?.uid,Te=({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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsx)(t.p.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)(ce,{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)(de,{}),(0,s.jsxs)(t.p.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.jsx)(`input`,{type:`file`,ref:W,onChange:re,className:`hidden`}),!n&&(0,s.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm: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.jsx)(s.Fragment,{children:(0,s.jsxs)(t.p.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${Ce?`btn-primary`:`btn-secondary`}`,children:[T?(0,s.jsx)(t.K,{className:`w-4 h-4 animate-spin`}):(0,s.jsx)(xe,{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.p.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`} ${Se?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,s.jsx)(t.L,{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.K,{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.Ht,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.Ht,J,e),n)},deleteRecord:async e=>{await(0,i.deleteDoc)((0,i.doc)(t.Ht,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.p.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.L,{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.m,{children:u.map(e=>{let n=R===e.id,r=we(e);return(0,s.jsxs)(t.p.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-100 md:opacity-0 md: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.Tt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,s.jsx)(t.J,{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.dt,{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.R,{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.E,{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`&&j(e)},className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`cursor-pointer hover:scale-105 transition-transform ${ge(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?he(e.fileType,e.downloadURL):(0,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:[ae===e.id?(0,s.jsx)(`input`,{autoFocus:!0,type:`text`,value:oe,onChange:e=>Z(e.target.value),onBlur:()=>fe(),onKeyDown:e=>{e.key===`Enter`&&fe(),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:()=>j(e)}),(0,s.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:be(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)(Te,{record:e})]},e.id)})})})]})]})]})]}),(0,s.jsx)(t.m,{children:m&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.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.p.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.Ht,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:ne,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.v,{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.c,{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.m,{children:M&&(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.p.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,s.jsx)(`button`,{onClick:()=>j(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,s.jsx)(t.v,{className:`w-5 h-5`})}),(0,s.jsxs)(t.p.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:M.fileName||M.name}),(0,s.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[_e(M.fileType),` • `,ye(M.fileSize||0)]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.downloadURL),K(`preview`),setTimeout(()=>K(null),2e3)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 transition-colors rounded-xl shadow-sm hover:text-emerald-500 cursor-pointer`,title:`Copy Link`,children:G===`preview`?(0,s.jsx)(t.Tt,{className:`w-4 h-4 text-emerald-500`}):(0,s.jsx)(t.J,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{j(null),X(M.id),Z(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,s.jsx)(t.R,{className:`w-4 h-4`})}),(0,s.jsx)(`button`,{onClick:()=>{j(null),O(M.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,s.jsx)(t.E,{className:`w-4 h-4`})}),(0,s.jsx)(`a`,{href:M.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,s.jsx)(t.dt,{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:()=>j(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.K,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,s.jsx)(`img`,{onLoad:()=>F(!1),onError:()=>F(!1),src:M.downloadURL,alt:M.fileName||M.name,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full object-contain drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] rounded-lg pointer-events-auto transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType?.startsWith(`video/`)?(0,s.jsx)(`video`,{onLoadedData:()=>F(!1),onError:()=>F(!1),src:M.downloadURL,controls:!0,autoPlay:!0,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full outline-none bg-black/40 rounded-lg pointer-events-auto drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] transition-opacity duration-500 ${P?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType===`application/pdf`?(0,s.jsx)(`iframe`,{onLoad:()=>F(!1),src:M.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.ot,{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.m,{children:R&&(0,s.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,s.jsx)(t.p.div,{onClick:()=>pe(),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.p.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.K,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,s.jsx)(`button`,{type:`button`,onClick:()=>pe(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,s.jsx)(t.v,{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:B,onChange:e=>ee(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>me(),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:()=>me(),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:()=>me(),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:()=>me(),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.v,{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.L,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,s.jsx)(ve,{isOpen:!!D,onCancel:()=>O(null),onConfirm:ie,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 Ua=[`board`,`table`,`calendar`,`drive`],Wa=[`inline_form`,`popup_form`],Ga=e=>typeof e!=`string`||e===``||e===`none`||e===`custom`||![...Ua,...Wa].includes(e),Ka=(e,t)=>Ga(e)||t&&!qa(e),qa=e=>typeof e==`string`&&Ua.includes(e),Ja=`/src/your-ai-workflow-firebase-os/microcomponents`,Ya=e=>(e||``).split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``),Xa=e=>{let t=e.replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase();return[t,t.replace(/_/g,``)]},Za=e=>{let t=[e?.contentKey,e?.tabName,e?.pageId,e?.pageName].filter(e=>typeof e==`string`&&e.trim()).map(e=>Ya(e)).filter(Boolean);return[...new Set(t)].map(e=>`${e}Content.tsx`)},Qa=e=>{if(typeof window>`u`)return!1;let t=window.__FBOS_MICROCOMPONENTS__;if(!t)return!1;let n=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_|_$/g,``);return[e?.contentKey,e?.tabName,e?.pageId,e?.pageName].filter(e=>typeof e==`string`&&e.trim()).some(e=>t[n(e)])},$a=new Map,eo=e=>{let t=$a.get(e);return t||(t=import(`${Ja}/${e}`).then(e=>typeof e?.default==`function`||typeof e?.default==`object`?e.default:null).catch(()=>null),$a.set(e,t)),t};async function to(e){if(typeof window>`u`||Qa(e))return null;for(let t of Za(e)){let e=await eo(t);if(!e)continue;let[n,r]=Xa(t.replace(/Content\.tsx$/,``)),i=window.__FBOS_MICROCOMPONENTS__||{};return window.__FBOS_MICROCOMPONENTS__={[n]:e,[r]:e,...i},e}return null}var no=(e,t)=>{let n=t?D(e.pageType):`public`;return{...e,pageType:n,isPrivate:t,isAdmin:n===`admin`,isInternal:n===`internal`,isShared:n===`internal`}};function ro(){let e=(0,c.useLocation)(),{user:n,userRole:a,loading:o,roleResolved:l}=N(),u=t.Bt(),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 no(e,e.isPrivate===!0)}catch{}}let n=(typeof window<`u`?window.__FBOS_PAGES__:null)||{},r=e.replace(/^\//,``);for(let[t,i]of Object.entries(n)){let n=i.config,a=i.isPublic,o=n.route||`/`+t;if(o===e||t===r)return no({...n,route:o,contentKey:n.pageId||t,pageId:t},!a)}return e===`/contact`?{route:`/contact`,template:`popup_form`,form:`contact`,pageId:`contact`,contentKey:`contact`,pageName:`Contact`,formConfigOverride:u.defaultConfigs?.contactForm||t.Jt}:e===`/support`?{route:`/support`,template:`popup_form`,form:`support`,pageId:`support`,contentKey:`support`,pageName:`Support`,formConfigOverride:u.defaultConfigs?.supportForm||t.Kt}: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.Ht,`sys_pages`,r)),(0,i.getDoc)((0,i.doc)(t.Ht,`sys_tabs`,r)),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Ht,`sys_pages`),(0,i.where)(`route`,`==`,e.pathname),(0,i.limit)(1))),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Ht,`sys_pages`),(0,i.where)(`route`,`==`,r),(0,i.limit)(1))),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Ht,`sys_tabs`),(0,i.where)(`route`,`==`,e.pathname),(0,i.limit)(1))),(0,i.getDocs)((0,i.query)((0,i.collection)(t.Ht,`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=no(e.value.data(),t),m=e.value.id):e.value.docs&&e.value.docs.length>0&&(f=no(e.value.docs[0].data(),t),m=e.value.docs[0].id))};if(g(a,!1),g(s,!1),g(c,!1),g(o,!0),g(l,!0),g(d,!0),!f){let t=(typeof window<`u`?window.__FBOS_PAGES__:null)||{};for(let[n,i]of Object.entries(t)){let t=i.config,a=i.isPublic,o=t.route||`/`+n;if(o===e.pathname||n===r){f=no({...t,route:o,contentKey:t.pageId||n,pageId:n},!a),m=n;break}}}if(f||(e.pathname===`/contact`?(f={route:`/contact`,template:`popup_form`,form:`contact`,pageName:`Contact`},m=`contact`):e.pathname===`/support`&&(f={route:`/support`,template:`popup_form`,form:`support`,pageName:`Support`},m=`support`)),!n)return;if(f){if((m===`contact`||m===`support`)&&!f.form&&(f.form=m),f.contentKey||=f.pageId||m,f.pageId=m,localStorage.setItem(`fbos_route_${e.pathname}`,JSON.stringify(f)),f.form){let e=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},r=n=>u.defaultConfigs?.[n]||u.defaultConfigs?.[`${n}Form`]||e[n]||(n===`contact`?t.Jt:n===`support`?t.Kt: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.Ht,`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),[v,y]=(0,r.useState)(null),[b,x]=(0,r.useState)(!1),S=f&&f!==`not-found`&&typeof f==`object`?[f.contentKey,f.tabName,f.pageId,f.pageName].filter(Boolean).join(`|`):``;if((0,r.useEffect)(()=>{if(y(null),!S||Qa(f)){x(!1);return}let e=!1;x(!0),to(f).then(t=>{e||(t&&y(()=>t),x(!1))});let t=setTimeout(()=>{e||x(!1)},4e3);return()=>{e=!0,clearTimeout(t)}},[S]),(0,r.useEffect)(()=>{let e;return m||o||!l||b?e=setTimeout(()=>_(!0),150):_(!1),()=>clearTimeout(e)},[m,o,l,b]),m||o||!l||b)return g?n?(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col 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)(de,{}),(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.K,{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.K,{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 pt-2 md:p-8 md:pt-4 z-10 flex flex-col 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-2xl sm: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.`}),w(a)&&(()=>{let t=Pa();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)(tt,{title:`If your assistant just made this page, paste this`,prompt:Ra(e.pathname)})]})})()]})});if((f.pageId===`support`||f.isPrivate)&&!n)return(0,s.jsx)(c.Navigate,{to:`/login`,state:{from:e}});if(!O(a,f.isPrivate?f.pageType:`public`))return f.isAdmin?(0,s.jsx)(mi,{}):(0,s.jsx)(pi,{});let C=u.customRoutes?.[e.pathname]||(f&&f.route?u.customRoutes?.[f.route]:null),T=f.pageName?.toLowerCase().replace(/\s+/g,`_`)||f.pageId||`custom_page`,E=`pub_${T}`,D=u.microcomponents||(typeof window<`u`?window.__FBOS_MICROCOMPONENTS__:void 0),k=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_|_$/g,``),A=[f.contentKey,f.tabName,f.pageId,f.pageName,f.pageName?.replace(/\s+/g,`_`)].filter(Boolean).map(e=>k(e)).reduce((e,t)=>e||D?.[t],void 0),j=C||A||v||void 0,M=f.route||f.pageId||`custom`;if(Ka(f.template,!!j))return f.isAdmin?(0,s.jsx)(Va,{config:f,customContent:j},M):f.isInternal?(0,s.jsx)(Ha,{config:f,customContent:j},M):f.isPrivate?(0,s.jsx)(Ba,{config:f,customContent:j},M):(0,s.jsx)(za,{config:f,customContent:j},M);if(f.template===`board`){let e=f.isAdmin?`admin_${f.pageId||T}`:f.isInternal?`mem_${f.pageId||T}`:f.isPrivate?`user_${f.pageId||T}`:E;return(0,s.jsx)(u.components?.TemplateBoard||Xt,{title:f.tabTitle||f.tabName||f.title||f.pageName||`Board`,subtitle:f.route,tasksCollection:`${e}_tasks`,categoriesCollection:`${e}_categories`,config:f,customContent:j},M)}if(f.template===`table`){let e=f.isAdmin?`admin_${f.pageId||T}`:f.isInternal?`mem_${f.pageId||T}`:f.isPrivate?`user_${f.pageId||T}`:E;return(0,s.jsx)(u.components?.TemplateTable||Er,{title:f.tabTitle||f.tabName||f.title||f.pageName||`Table`,subtitle:f.route,tableCollection:`${e}_table`,config:f,customContent:j},M)}if(f.template===`calendar`){let e=f.isAdmin?`admin_${f.pageId||T}`:f.isInternal?`mem_${f.pageId||T}`:f.isPrivate?`user_${f.pageId||T}`:E;return(0,s.jsx)(u.components?.TemplateCalendar||kr,{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:j},M)}if(f.template===`drive`){let e=f.isAdmin?`admin_${f.pageId||T}`:f.isInternal?`mem_${f.pageId||T}`:f.isPrivate?`user_${f.pageId||T}`:E;return(0,s.jsx)(u.components?.TemplateDrive||Dt,{title:f.tabTitle||f.tabName||f.title||f.pageName||`Drive`,subtitle:f.route,filesCollection:`${e}_files`,config:f,customContent:j},M)}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 io=r.default.createContext({}),ao=Object.defineProperty,oo=Object.getOwnPropertySymbols,so=Object.prototype.hasOwnProperty,co=Object.prototype.propertyIsEnumerable,lo=(e,t,n)=>t in e?ao(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,uo=(e,t)=>{for(var n in t||={})so.call(t,n)&&lo(e,n,t[n]);if(oo)for(var n of oo(t))co.call(t,n)&&lo(e,n,t[n]);return e},fo=(0,r.forwardRef)((e,t)=>{let n=uo(uo({},r.useContext(io)),e);return r.createElement(`svg`,uo({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`}))}),po=`rules_version = '2';
25
25
  service cloud.firestore {
26
26
  match /databases/{database}/documents {
27
27
 
@@ -389,4 +389,4 @@ service firebase.storage {
389
389
  }
390
390
  }
391
391
  }
392
- `,ho=[{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 go(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 _o(e,t){let n=go(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 vo(e){let t=[],n=[],r=t=>_o(t,e);for(let{key:e,label:i}of ho){let a=r(e);a?a.trim()===``&&n.push(i):t.push(i)}let i=[...t,...n];return{allSet:i.length===0,missing:i,empty:n}}function yo(){return vo().allSet}var bo=mo;function xo(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 po.replace(/(function adminEmails\(\) \{\s*return )\[[^\]]*\];/,`$1[${n}];`)}function So(e){return e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean)}var Co=/^[^@\s]+@[^@\s]+\.[^@\s]+$/;function wo({code:e,label:n,compact:i}){let[a,o]=r.default.useState(!1);return(0,s.jsxs)(t.p.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>{navigator.clipboard?.writeText(e),o(!0),setTimeout(()=>o(!1),2e3)},className:`inline-flex items-center font-bold transition-all shrink-0 cursor-pointer ${i?`gap-1.5 h-9 px-3 rounded-xl text-[12px] self-start sm:self-auto`:`gap-2 px-4 py-2 mt-2 rounded-xl text-[13px] tracking-wide`} ${a?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary${i?``:` shadow-sm`}`}`,children:[a?(0,s.jsx)(t.Tt,{className:i?`w-3.5 h-3.5`:`w-4 h-4`}):(0,s.jsx)(t.pt,{className:i?`w-3.5 h-3.5`:`w-4 h-4`}),a?i?`Copied`:`Copied to Clipboard!`:n]})}function To({name:e,shownAs:n,hint:i}){let[a,o]=r.default.useState(!1);return(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm: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 break-all sm:break-normal sm: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 self-start sm:self-auto 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.Tt,{className:`w-3.5 h-3.5`}):(0,s.jsx)(t.pt,{className:`w-3.5 h-3.5`}),a?`Copied`:`Copy name`]})]})}function Eo({initialEmails:e}){let[n,i]=(0,r.useState)(e),[a,o]=(0,r.useState)(``),[c,l]=(0,r.useState)([]),[u,d]=(0,r.useState)(``),f=e=>{i(e),a&&(o(``),l([])),u&&d(``)},p=()=>{let e=So(n);if(e.length===0){d(`Type an email address first — it is what the rules will name.`);return}let t=e.filter(e=>!Co.test(e));if(t.length>0){d(`That does not look like an email address: ${t.join(`, `)}`);return}d(``),l(e.map(e=>e.trim().toLowerCase())),o(xo(e))};return(0,s.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl p-5 mb-2 flex flex-col gap-4`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-3.5 min-w-0`,children:[(0,s.jsx)(`div`,{className:`w-10 h-10 rounded-2xl flex items-center justify-center shrink-0 border border-[var(--panel-border)]/50 bg-accent/10 text-accent`,children:(0,s.jsx)(t.j,{className:`w-5 h-5`})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold text-foreground tracking-tight leading-tight truncate`,children:`Who runs this app?`}),(0,s.jsx)(`p`,{className:`text-[12px] text-foreground/50 font-normal leading-snug truncate`,children:`The email you sign in with becomes the owner — separate several with commas.`})]})]}),(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center gap-2`,children:[(0,s.jsx)(`input`,{type:`text`,value:n,"aria-label":`The email address you will sign in with`,placeholder:`you@yourcompany.com`,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),p())},className:`w-full h-10 px-3.5 rounded-[var(--input-radius,0.75rem)] border border-[var(--panel-border)] bg-[var(--panel-bg)] text-[13.5px] text-foreground outline-none transition-all duration-300 placeholder:text-foreground/35 hover:border-accent/40 focus:border-accent console-field ${u?`is-invalid border-red-500/60`:``}`}),(0,s.jsx)(`button`,{type:`button`,onClick:p,className:`btn-primary inline-flex items-center justify-center h-10 px-4 rounded-[var(--btn-radius,0.75rem)] text-[12.5px] font-bold text-white shrink-0 cursor-pointer active:scale-[0.98] transition-transform whitespace-nowrap`,children:`Generate the rules`})]}),u&&(0,s.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 leading-snug px-1`,children:u}),a&&(0,s.jsxs)(`div`,{className:`rounded-2xl border border-emerald-500/20 bg-emerald-500/[0.05] px-3.5 py-3 flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-3`,children:[(0,s.jsx)(`span`,{className:`w-7 h-7 rounded-full bg-emerald-500/10 border border-emerald-500/20 flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.Tt,{className:`w-3.5 h-3.5 text-emerald-500`})}),(0,s.jsxs)(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[(0,s.jsxs)(`p`,{"data-admin-emails":!0,className:`text-[13px] font-bold text-foreground leading-snug break-all`,children:[`Ready — they make `,c.join(`, `),` the owner.`]}),(0,s.jsx)(`p`,{className:`text-[12px] font-medium text-foreground/50 leading-snug`,children:`Paste them into Firebase, then sign in with that address — or reload, if you already are.`})]}),(0,s.jsx)(wo,{compact:!0,code:a,label:`Copy the rules`})]})]})}function Do({number:e,title:t,children:n}){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:t})]}),(0,s.jsx)(`div`,{className:`text-[14px] md:text-[15px] text-foreground/70 leading-relaxed space-y-4`,children:n})]})}function Oo({standalone:e}){let n=t.Bt(),[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=So(_o(`VITE_ADMIN_EMAILS`,n)).join(`, `);return(0,r.useEffect)(()=>{e&&document.documentElement.setAttribute(`data-theme`,i?`dark`:`light`)},[i,e]),(0,r.useEffect)(()=>{if(e&&t.Gt.faviconUrl){let e=document.querySelector(`link[rel*='icon']`);e||(e=document.createElement(`link`),e.rel=`icon`,document.head.appendChild(e)),e.href=t.Gt.faviconUrl}},[e]),(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsx)(t.p.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)(ce,{children:`Setup`}),(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`}),`/setup`]})]})}),(0,s.jsx)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:(0,s.jsxs)(t.p.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-4 sm:p-6 md:p-10 shadow-2xl relative overflow-hidden bg-background flex flex-col`,children:[(0,s.jsx)(`div`,{className:`mb-6 pb-4 sm:mb-8 sm:pb-6 border-b border-[var(--panel-border)]/50 relative z-10`,children:(0,s.jsxs)(`div`,{className:`flex max-sm:flex-col max-sm:items-stretch items-center justify-between gap-3 sm:gap-4`,children:[(0,s.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,s.jsx)(`h2`,{className:`text-[17px] sm:text-xl font-extrabold text-foreground tracking-tight truncate`,children:`Connect your app to Firebase`}),(0,s.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1 sm:mt-1.5 leading-snug truncate`,children:[(0,s.jsx)(`span`,{className:`sm:hidden`,children:`Google's free data and sign-in service.`}),(0,s.jsx)(`span`,{className:`max-sm:hidden`,children:`Firebase is Google's free service that stores your data and signs people in — about ten minutes, once.`})]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(t.p.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.U,{className:`w-4 h-4`})}),(0,s.jsx)(t.p.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)(fo,{className:`w-4 h-4 text-foreground/80`})})]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col relative z-10 p-4 sm:p-6 md:p-8 bg-foreground/[0.015] rounded-3xl border border-[var(--panel-border)]/50 mt-4`,children:[(0,s.jsx)(Do,{number:1,title:`Create a Firebase project`,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)(Do,{number:2,title:`Add a web app and copy the six values`,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)(Do,{number:3,title:`Paste the six values into Secrets`,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:`Six rows, and that is all of them. Your own email address is not one of them — you type that straight into step 5 in a moment.`}),(0,s.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl overflow-hidden bg-background`,children:ho.map(({key:e,shownAs:t})=>(0,s.jsx)(To,{name:e,shownAs:t},e))})]}),(0,s.jsx)(Do,{number:4,title:`Turn on sign-in`,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)(Do,{number:5,title:`Create the database and publish its rules`,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.jsxs)(`li`,{children:[`In the box below, type the email address you will sign in with and click `,(0,s.jsx)(`strong`,{children:`Generate the rules`}),`.`]}),(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.jsx)(Eo,{initialEmails:a})]}),(0,s.jsxs)(Do,{number:6,title:`Create storage and publish its rules`,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)(wo,{code:bo,label:`Copy the storage rules`})]})]}),(0,s.jsx)(`div`,{className:`mt-8 relative z-10`,children:(0,s.jsx)(rt,{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?`})})]})})]})}var ko={contentKey:`dashboard`};function Ao(){let{user:e}=N(),n=t.Bt(),[i,a]=(0,r.useState)(null),[o,c]=(0,r.useState)(()=>typeof window<`u`&&!Qa(ko));(0,r.useEffect)(()=>{if(Qa(ko))return;let e=!1;to(ko).then(t=>{e||(t&&a(()=>t),c(!1))});let t=setTimeout(()=>{e||c(!1)},4e3);return()=>{e=!0,clearTimeout(t)}},[]);let l=n.microcomponents?.dashboard||(typeof window<`u`?window.__FBOS_MICROCOMPONENTS__?.dashboard:void 0)||i||void 0,u=(e?.displayName||e?.email?.split(`@`)[0]||`there`).split(` `)[0],d=u.charAt(0).toUpperCase()+u.slice(1);return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,s.jsxs)(ce,{children:[`Welcome back, `,d,`.`]}),(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)(de,{})}),(0,s.jsxs)(`div`,{className:`w-full flex-1 glass-panel rounded-3xl relative overflow-hidden border border-[var(--panel-border)] shadow-2xl bg-[var(--panel-bg)] ${l?`p-6 md:p-8`:`p-8 md:p-12 flex items-center justify-center`}`,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`}),l?(0,s.jsx)(`div`,{className:`fbos-content-slot relative z-10`,children:(0,s.jsx)(l,{})}):o?(0,s.jsx)(t.K,{className:`w-6 h-6 text-accent animate-spin relative z-10`}):(0,s.jsx)(t.m,{mode:`wait`,children:(0,s.jsxs)(t.p.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.ft,{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 jo=()=>(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.ft,{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 Mo({level:e,children:t}){let{user:n,userRole:r,loading:i,userInactive:a,signOut:o,roleResolved:l}=N(),u=(0,c.useLocation)();return i||!l?(0,s.jsx)(jo,{}):n?a?(0,s.jsx)(ci,{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:li,children:`Sign Out`})}):n.emailVerified?e===`admin`&&!w(r)?(0,s.jsx)(mi,{}):e===`internal`&&!T(r)?(0,s.jsx)(pi,{}):(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 No=({children:e})=>(0,s.jsx)(Mo,{level:`signed-in`,children:e}),Po=({children:e})=>(0,s.jsx)(Mo,{level:`admin`,children:e});function Fo({children:e}){let{user:t,loading:n,roleResolved:r}=N(),[i]=(0,c.useSearchParams)();return n||!r?(0,s.jsx)(jo,{}):t&&t.emailVerified?(0,s.jsx)(c.Navigate,{to:i.get(`from`)||`/dashboard`,replace:!0}):(0,s.jsx)(s.Fragment,{children:e})}function Io({children:e}){let{user:t,loading:n,roleResolved:r}=N();return n||!r?(0,s.jsx)(jo,{}):t?t.emailVerified?(0,s.jsx)(c.Navigate,{to:`/dashboard`}):(0,s.jsx)(s.Fragment,{children:e}):(0,s.jsx)(c.Navigate,{to:`/`})}function Lo(){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.p.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.p.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 Ro(){let e=t.Bt().components?.Home||W;return(0,s.jsx)(M,{children:(0,s.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,s.jsx)(U,{}),(0,s.jsxs)(c.Routes,{children:[(0,s.jsx)(c.Route,{path:`/`,element:(0,s.jsx)(Fo,{children:(0,s.jsx)(e,{})})}),(0,s.jsx)(c.Route,{path:`/register`,element:(0,s.jsx)(Fo,{children:(0,s.jsx)(ae,{})})}),(0,s.jsx)(c.Route,{path:`/login`,element:(0,s.jsx)(Fo,{children:(0,s.jsx)(X,{})})}),(0,s.jsx)(c.Route,{path:`/reset-password`,element:(0,s.jsx)(Fo,{children:(0,s.jsx)(pe,{})})}),(0,s.jsx)(c.Route,{path:`/verify`,element:(0,s.jsx)(Io,{children:(0,s.jsx)(oe,{})})}),(0,s.jsx)(c.Route,{path:`/guide`,element:(0,s.jsx)(qt,{})}),(0,s.jsx)(c.Route,{path:`/templates`,element:(0,s.jsx)(Nt,{})}),(0,s.jsx)(c.Route,{path:`/board`,element:(0,s.jsx)(Zt,{})}),(0,s.jsx)(c.Route,{path:`/table`,element:(0,s.jsx)(Dr,{})}),(0,s.jsx)(c.Route,{path:`/calendar`,element:(0,s.jsx)(Ar,{})}),(0,s.jsx)(c.Route,{path:`/drive`,element:(0,s.jsx)(Ot,{})}),(0,s.jsx)(c.Route,{path:`/inline_form`,element:(0,s.jsx)(Jt,{})}),(0,s.jsx)(c.Route,{path:`/popup_form`,element:(0,s.jsx)(Yt,{})}),(0,s.jsx)(c.Route,{path:`/users`,element:(0,s.jsx)(Po,{children:(0,s.jsx)(ye,{})})}),(0,s.jsx)(c.Route,{path:`/users/:id`,element:(0,s.jsx)(Po,{children:(0,s.jsx)(ye,{})})}),(0,s.jsx)(c.Route,{path:`/inbox`,element:(0,s.jsx)(Po,{children:(0,s.jsx)(wt,{})})}),(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)(Po,{children:(0,s.jsx)(Mt,{})})}),(0,s.jsx)(c.Route,{path:`/drive/:rest`,element:(0,s.jsx)(c.Navigate,{to:`/assets`,replace:!0})}),(0,s.jsx)(c.Route,{path:`/theme`,element:(0,s.jsx)(Po,{children:(0,s.jsx)(si,{})})}),(0,s.jsx)(c.Route,{path:`/pages/*`,element:(0,s.jsx)(Po,{children:(0,s.jsx)(ga,{})})}),(0,s.jsx)(c.Route,{path:`/forms/*`,element:(0,s.jsx)(Po,{children:(0,s.jsx)(Ma,{})})}),(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)(No,{children:(0,s.jsx)(fe,{})})}),(0,s.jsx)(c.Route,{path:`/dashboard`,element:(0,s.jsx)(No,{children:(0,s.jsx)(Ao,{})})}),(0,s.jsx)(c.Route,{path:`/setup`,element:(0,s.jsx)(Oo,{})}),(0,s.jsx)(c.Route,{path:`*`,element:(0,s.jsx)(ro,{})})]}),(0,s.jsx)(Lo,{})]})})}function zo(){return(0,s.jsx)(c.BrowserRouter,{children:(0,s.jsx)(Bo,{})})}function Bo(){let e=t.Bt();return e.firebaseConfig&&e.firebaseConfig.apiKey&&e.firebaseConfig.apiKey.trim()!==``&&e.firebaseConfig.projectId&&e.firebaseConfig.projectId.trim()!==``||yo()?(0,s.jsx)(Ro,{}):(0,s.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,s.jsx)(U,{standalone:!0}),(0,s.jsx)(Oo,{standalone:!0}),(0,s.jsx)(Lo,{})]})}function Vo(e){v();let n=e.firebaseConfig;return n&&n.apiKey&&n.apiKey.trim()!==``&&n.projectId&&n.projectId.trim()!==``&&t.Ut(n),(0,s.jsx)(t.zt,{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.Lt,{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)(zo,{})})})})}var Ho=Object.assign({}),Uo={};for(let e in Ho){let t=Ho[e];if(!t?.default)continue;let n=e.replace(`./`,``).replace(`.tsx`,``);if(n===`registry`)continue;let r=n.replace(/Content$/,``).replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase();Uo[r]=t.default,Uo[r.replace(/_/g,``)]=t.default}if(typeof window<`u`){let e=window.__FBOS_MICROCOMPONENTS__||{};window.__FBOS_MICROCOMPONENTS__={...Uo,...e}}var Wo=(e,t)=>{let n=e.toLowerCase().replace(/[^a-z0-9]+/g,`_`),r=n.replace(/_/g,``);if(Uo[n]=t,Uo[r]=t,typeof window<`u`){let e=window.__FBOS_MICROCOMPONENTS__||{};window.__FBOS_MICROCOMPONENTS__={...e,[n]:t,[r]:t}}};function Go(...e){return t.u(t.d(e))}var Ko=({title:e,className:t,children:n,...r})=>(0,s.jsxs)(`div`,{className:Go(`border border-[var(--panel-border)] bg-[var(--panel-bg)] px-5 py-4`,t),style:{borderRadius:`var(--card-radius, 1rem)`},...r,children:[e?(0,s.jsx)(`p`,{className:`text-[12px] font-extrabold tracking-tight text-gradient mb-1.5`,children:e}):null,n]});Ko.displayName=`Card`;function qo(...e){return t.u(t.d(e))}var Jo=({sub:e,className:t,children:n,...r})=>(0,s.jsxs)(`div`,{className:qo(`mb-4`,t),children:[(0,s.jsx)(`h2`,{className:`text-xl md:text-2xl font-extrabold tracking-tight text-foreground`,...r,children:n}),e?(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed mt-1`,children:e}):null]});Jo.displayName=`SectionHeading`,exports.AdminNotifications=I,exports.Button=t.c,exports.Card=Ko,exports.ConfirmModal=be,exports.ContactPopup=t.t,exports.CustomSelect=t.s,exports.DashboardNav=de,exports.FirebaseOS=Vo,exports.Input=t.l,exports.Navbar=U,exports.PhoneInputField=n.t,exports.SectionHeading=Jo,Object.defineProperty(exports,`auth`,{enumerable:!0,get:function(){return t.Vt}}),Object.defineProperty(exports,`db`,{enumerable:!0,get:function(){return t.Ht}}),exports.registerMicrocomponent=Wo,Object.defineProperty(exports,`storage`,{enumerable:!0,get:function(){return t.Wt}}),exports.useAuth=N,exports.useConfig=t.Bt,exports.useTheme=t.Rt;
392
+ `,ho=[{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 go(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 _o(e,t){let n=go(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 vo(e){let t=[],n=[],r=t=>_o(t,e);for(let{key:e,label:i}of ho){let a=r(e);a?a.trim()===``&&n.push(i):t.push(i)}let i=[...t,...n];return{allSet:i.length===0,missing:i,empty:n}}function yo(){return vo().allSet}var bo=mo;function xo(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 po.replace(/(function adminEmails\(\) \{\s*return )\[[^\]]*\];/,`$1[${n}];`)}function So(e){return e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean)}var Co=/^[^@\s]+@[^@\s]+\.[^@\s]+$/;function wo({code:e,label:n,compact:i}){let[a,o]=r.default.useState(!1);return(0,s.jsxs)(t.p.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>{navigator.clipboard?.writeText(e),o(!0),setTimeout(()=>o(!1),2e3)},className:`inline-flex items-center font-bold transition-all shrink-0 cursor-pointer ${i?`gap-1.5 h-9 px-3 rounded-xl text-[12px] self-start sm:self-auto`:`gap-2 px-4 py-2 mt-2 rounded-xl text-[13px] tracking-wide`} ${a?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary${i?``:` shadow-sm`}`}`,children:[a?(0,s.jsx)(t.Tt,{className:i?`w-3.5 h-3.5`:`w-4 h-4`}):(0,s.jsx)(t.pt,{className:i?`w-3.5 h-3.5`:`w-4 h-4`}),a?i?`Copied`:`Copied to Clipboard!`:n]})}function To({name:e,shownAs:n,hint:i}){let[a,o]=r.default.useState(!1);return(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm: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 break-all sm:break-normal sm: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 self-start sm:self-auto 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.Tt,{className:`w-3.5 h-3.5`}):(0,s.jsx)(t.pt,{className:`w-3.5 h-3.5`}),a?`Copied`:`Copy name`]})]})}function Eo({initialEmails:e}){let[n,i]=(0,r.useState)(e),[a,o]=(0,r.useState)(``),[c,l]=(0,r.useState)([]),[u,d]=(0,r.useState)(``),f=e=>{i(e),a&&(o(``),l([])),u&&d(``)},p=()=>{let e=So(n);if(e.length===0){d(`Type an email address first — it is what the rules will name.`);return}let t=e.filter(e=>!Co.test(e));if(t.length>0){d(`That does not look like an email address: ${t.join(`, `)}`);return}d(``),l(e.map(e=>e.trim().toLowerCase())),o(xo(e))};return(0,s.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl p-5 mb-2 flex flex-col gap-4`,children:[(0,s.jsxs)(`div`,{className:`flex items-center gap-3.5 min-w-0`,children:[(0,s.jsx)(`div`,{className:`w-10 h-10 rounded-2xl flex items-center justify-center shrink-0 border border-[var(--panel-border)]/50 bg-accent/10 text-accent`,children:(0,s.jsx)(t.j,{className:`w-5 h-5`})}),(0,s.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,s.jsx)(`h3`,{className:`text-[15px] font-bold text-foreground tracking-tight leading-tight truncate`,children:`Who runs this app?`}),(0,s.jsx)(`p`,{className:`text-[12px] text-foreground/50 font-normal leading-snug truncate`,children:`The email you sign in with becomes the owner — separate several with commas.`})]})]}),(0,s.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center gap-2`,children:[(0,s.jsx)(`input`,{type:`text`,value:n,"aria-label":`The email address you will sign in with`,placeholder:`you@yourcompany.com`,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),p())},className:`w-full h-10 px-3.5 rounded-[var(--input-radius,0.75rem)] border border-[var(--panel-border)] bg-[var(--panel-bg)] text-[13.5px] text-foreground outline-none transition-all duration-300 placeholder:text-foreground/35 hover:border-accent/40 focus:border-accent console-field ${u?`is-invalid border-red-500/60`:``}`}),(0,s.jsx)(`button`,{type:`button`,onClick:p,className:`btn-primary inline-flex items-center justify-center h-10 px-4 rounded-[var(--btn-radius,0.75rem)] text-[12.5px] font-bold text-white shrink-0 cursor-pointer active:scale-[0.98] transition-transform whitespace-nowrap`,children:`Generate the rules`})]}),u&&(0,s.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 leading-snug px-1`,children:u}),a&&(0,s.jsxs)(`div`,{className:`rounded-2xl border border-emerald-500/20 bg-emerald-500/[0.05] px-3.5 py-3 flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-3`,children:[(0,s.jsx)(`span`,{className:`w-7 h-7 rounded-full bg-emerald-500/10 border border-emerald-500/20 flex items-center justify-center shrink-0`,children:(0,s.jsx)(t.Tt,{className:`w-3.5 h-3.5 text-emerald-500`})}),(0,s.jsxs)(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[(0,s.jsxs)(`p`,{"data-admin-emails":!0,className:`text-[13px] font-bold text-foreground leading-snug break-all`,children:[`Ready — they make `,c.join(`, `),` the owner.`]}),(0,s.jsx)(`p`,{className:`text-[12px] font-medium text-foreground/50 leading-snug`,children:`Paste them into Firebase, then sign in with that address — or reload, if you already are.`})]}),(0,s.jsx)(wo,{compact:!0,code:a,label:`Copy the rules`})]})]})}function Do({number:e,title:t,children:n}){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:t})]}),(0,s.jsx)(`div`,{className:`text-[14px] md:text-[15px] text-foreground/70 leading-relaxed space-y-4`,children:n})]})}function Oo({standalone:e}){let n=t.Bt(),[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=So(_o(`VITE_ADMIN_EMAILS`,n)).join(`, `);return(0,r.useEffect)(()=>{e&&document.documentElement.setAttribute(`data-theme`,i?`dark`:`light`)},[i,e]),(0,r.useEffect)(()=>{if(e&&t.Gt.faviconUrl){let e=document.querySelector(`link[rel*='icon']`);e||(e=document.createElement(`link`),e.rel=`icon`,document.head.appendChild(e)),e.href=t.Gt.faviconUrl}},[e]),(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsx)(t.p.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)(ce,{children:`Setup`}),(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`}),`/setup`]})]})}),(0,s.jsx)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:(0,s.jsxs)(t.p.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-4 sm:p-6 md:p-10 shadow-2xl relative overflow-hidden bg-background flex flex-col`,children:[(0,s.jsx)(`div`,{className:`mb-6 pb-4 sm:mb-8 sm:pb-6 border-b border-[var(--panel-border)]/50 relative z-10`,children:(0,s.jsxs)(`div`,{className:`flex max-sm:flex-col max-sm:items-stretch items-center justify-between gap-3 sm:gap-4`,children:[(0,s.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,s.jsx)(`h2`,{className:`text-[17px] sm:text-xl font-extrabold text-foreground tracking-tight truncate`,children:`Connect your app to Firebase`}),(0,s.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1 sm:mt-1.5 leading-snug truncate`,children:[(0,s.jsx)(`span`,{className:`sm:hidden`,children:`Google's free data and sign-in service.`}),(0,s.jsx)(`span`,{className:`max-sm:hidden`,children:`Firebase is Google's free service that stores your data and signs people in — about ten minutes, once.`})]})]}),(0,s.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,s.jsx)(t.p.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.U,{className:`w-4 h-4`})}),(0,s.jsx)(t.p.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)(fo,{className:`w-4 h-4 text-foreground/80`})})]})]})}),(0,s.jsxs)(`div`,{className:`flex flex-col relative z-10 p-4 sm:p-6 md:p-8 bg-foreground/[0.015] rounded-3xl border border-[var(--panel-border)]/50 mt-4`,children:[(0,s.jsx)(Do,{number:1,title:`Create a Firebase project`,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)(Do,{number:2,title:`Add a web app and copy the six values`,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)(Do,{number:3,title:`Paste the six values into Secrets`,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:`Six rows, and that is all of them. Your own email address is not one of them — you type that straight into step 5 in a moment.`}),(0,s.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl overflow-hidden bg-background`,children:ho.map(({key:e,shownAs:t})=>(0,s.jsx)(To,{name:e,shownAs:t},e))})]}),(0,s.jsx)(Do,{number:4,title:`Turn on sign-in`,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)(Do,{number:5,title:`Create the database and publish its rules`,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.jsxs)(`li`,{children:[`In the box below, type the email address you will sign in with and click `,(0,s.jsx)(`strong`,{children:`Generate the rules`}),`.`]}),(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.jsx)(Eo,{initialEmails:a})]}),(0,s.jsxs)(Do,{number:6,title:`Create storage and publish its rules`,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)(wo,{code:bo,label:`Copy the storage rules`})]})]}),(0,s.jsx)(`div`,{className:`mt-8 relative z-10`,children:(0,s.jsx)(tt,{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?`})})]})})]})}var ko={contentKey:`dashboard`};function Ao(){let{user:e}=N(),n=t.Bt(),[i,a]=(0,r.useState)(null),[o,c]=(0,r.useState)(()=>typeof window<`u`&&!Qa(ko));(0,r.useEffect)(()=>{if(Qa(ko))return;let e=!1;to(ko).then(t=>{e||(t&&a(()=>t),c(!1))});let t=setTimeout(()=>{e||c(!1)},4e3);return()=>{e=!0,clearTimeout(t)}},[]);let l=n.microcomponents?.dashboard||(typeof window<`u`?window.__FBOS_MICROCOMPONENTS__?.dashboard:void 0)||i||void 0,u=(e?.displayName||e?.email?.split(`@`)[0]||`there`).split(` `)[0],d=u.charAt(0).toUpperCase()+u.slice(1);return(0,s.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,s.jsxs)(t.p.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,s.jsxs)(ce,{children:[`Welcome back, `,d,`.`]}),(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)(de,{})}),(0,s.jsxs)(`div`,{className:`w-full flex-1 glass-panel rounded-3xl relative overflow-hidden border border-[var(--panel-border)] shadow-2xl bg-[var(--panel-bg)] ${l?`p-6 md:p-8`:`p-8 md:p-12 flex items-center justify-center`}`,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`}),l?(0,s.jsx)(`div`,{className:`fbos-content-slot relative z-10`,children:(0,s.jsx)(l,{})}):o?(0,s.jsx)(t.K,{className:`w-6 h-6 text-accent animate-spin relative z-10`}):(0,s.jsx)(t.m,{mode:`wait`,children:(0,s.jsxs)(t.p.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.ft,{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 jo=()=>(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.ft,{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 Mo({level:e,children:t}){let{user:n,userRole:r,loading:i,userInactive:a,signOut:o,roleResolved:l}=N(),u=(0,c.useLocation)();return i||!l?(0,s.jsx)(jo,{}):n?a?(0,s.jsx)(ci,{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:li,children:`Sign Out`})}):n.emailVerified?e===`admin`&&!w(r)?(0,s.jsx)(mi,{}):e===`internal`&&!T(r)?(0,s.jsx)(pi,{}):(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 No=({children:e})=>(0,s.jsx)(Mo,{level:`signed-in`,children:e}),Po=({children:e})=>(0,s.jsx)(Mo,{level:`admin`,children:e});function Fo({children:e}){let{user:t,loading:n,roleResolved:r}=N(),[i]=(0,c.useSearchParams)();return n||!r?(0,s.jsx)(jo,{}):t&&t.emailVerified?(0,s.jsx)(c.Navigate,{to:i.get(`from`)||`/dashboard`,replace:!0}):(0,s.jsx)(s.Fragment,{children:e})}function Io({children:e}){let{user:t,loading:n,roleResolved:r}=N();return n||!r?(0,s.jsx)(jo,{}):t?t.emailVerified?(0,s.jsx)(c.Navigate,{to:`/dashboard`}):(0,s.jsx)(s.Fragment,{children:e}):(0,s.jsx)(c.Navigate,{to:`/`})}function Lo(){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.p.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.p.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 Ro(){let e=t.Bt().components?.Home||W;return(0,s.jsx)(M,{children:(0,s.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,s.jsx)(U,{}),(0,s.jsxs)(c.Routes,{children:[(0,s.jsx)(c.Route,{path:`/`,element:(0,s.jsx)(Fo,{children:(0,s.jsx)(e,{})})}),(0,s.jsx)(c.Route,{path:`/register`,element:(0,s.jsx)(Fo,{children:(0,s.jsx)(ae,{})})}),(0,s.jsx)(c.Route,{path:`/login`,element:(0,s.jsx)(Fo,{children:(0,s.jsx)(X,{})})}),(0,s.jsx)(c.Route,{path:`/reset-password`,element:(0,s.jsx)(Fo,{children:(0,s.jsx)(pe,{})})}),(0,s.jsx)(c.Route,{path:`/verify`,element:(0,s.jsx)(Io,{children:(0,s.jsx)(oe,{})})}),(0,s.jsx)(c.Route,{path:`/guide`,element:(0,s.jsx)(Kt,{})}),(0,s.jsx)(c.Route,{path:`/templates`,element:(0,s.jsx)(Mt,{})}),(0,s.jsx)(c.Route,{path:`/board`,element:(0,s.jsx)(Xt,{})}),(0,s.jsx)(c.Route,{path:`/table`,element:(0,s.jsx)(Er,{})}),(0,s.jsx)(c.Route,{path:`/calendar`,element:(0,s.jsx)(kr,{})}),(0,s.jsx)(c.Route,{path:`/drive`,element:(0,s.jsx)(Dt,{})}),(0,s.jsx)(c.Route,{path:`/inline_form`,element:(0,s.jsx)(qt,{})}),(0,s.jsx)(c.Route,{path:`/popup_form`,element:(0,s.jsx)(Jt,{})}),(0,s.jsx)(c.Route,{path:`/users`,element:(0,s.jsx)(Po,{children:(0,s.jsx)(_e,{})})}),(0,s.jsx)(c.Route,{path:`/users/:id`,element:(0,s.jsx)(Po,{children:(0,s.jsx)(_e,{})})}),(0,s.jsx)(c.Route,{path:`/inbox`,element:(0,s.jsx)(Po,{children:(0,s.jsx)(Ct,{})})}),(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)(Po,{children:(0,s.jsx)(jt,{})})}),(0,s.jsx)(c.Route,{path:`/drive/:rest`,element:(0,s.jsx)(c.Navigate,{to:`/assets`,replace:!0})}),(0,s.jsx)(c.Route,{path:`/theme`,element:(0,s.jsx)(Po,{children:(0,s.jsx)(si,{})})}),(0,s.jsx)(c.Route,{path:`/pages/*`,element:(0,s.jsx)(Po,{children:(0,s.jsx)(ga,{})})}),(0,s.jsx)(c.Route,{path:`/forms/*`,element:(0,s.jsx)(Po,{children:(0,s.jsx)(Ma,{})})}),(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)(No,{children:(0,s.jsx)(fe,{})})}),(0,s.jsx)(c.Route,{path:`/dashboard`,element:(0,s.jsx)(No,{children:(0,s.jsx)(Ao,{})})}),(0,s.jsx)(c.Route,{path:`/setup`,element:(0,s.jsx)(Oo,{})}),(0,s.jsx)(c.Route,{path:`*`,element:(0,s.jsx)(ro,{})})]}),(0,s.jsx)(Lo,{})]})})}function zo(){return(0,s.jsx)(c.BrowserRouter,{children:(0,s.jsx)(Bo,{})})}function Bo(){let e=t.Bt();return e.firebaseConfig&&e.firebaseConfig.apiKey&&e.firebaseConfig.apiKey.trim()!==``&&e.firebaseConfig.projectId&&e.firebaseConfig.projectId.trim()!==``||yo()?(0,s.jsx)(Ro,{}):(0,s.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,s.jsx)(U,{standalone:!0}),(0,s.jsx)(Oo,{standalone:!0}),(0,s.jsx)(Lo,{})]})}function Vo(e){v();let n=e.firebaseConfig;return n&&n.apiKey&&n.apiKey.trim()!==``&&n.projectId&&n.projectId.trim()!==``&&t.Ut(n),(0,s.jsx)(t.zt,{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.Lt,{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)(zo,{})})})})}var Ho=Object.assign({}),Uo={};for(let e in Ho){let t=Ho[e];if(!t?.default)continue;let n=e.replace(`./`,``).replace(`.tsx`,``);if(n===`registry`)continue;let r=n.replace(/Content$/,``).replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase();Uo[r]=t.default,Uo[r.replace(/_/g,``)]=t.default}if(typeof window<`u`){let e=window.__FBOS_MICROCOMPONENTS__||{};window.__FBOS_MICROCOMPONENTS__={...Uo,...e}}var Wo=(e,t)=>{let n=e.toLowerCase().replace(/[^a-z0-9]+/g,`_`),r=n.replace(/_/g,``);if(Uo[n]=t,Uo[r]=t,typeof window<`u`){let e=window.__FBOS_MICROCOMPONENTS__||{};window.__FBOS_MICROCOMPONENTS__={...e,[n]:t,[r]:t}}};function Go(...e){return t.u(t.d(e))}var Ko=({title:e,className:t,children:n,...r})=>(0,s.jsxs)(`div`,{className:Go(`border border-[var(--panel-border)] bg-[var(--panel-bg)] px-5 py-4`,t),style:{borderRadius:`var(--card-radius, 1rem)`},...r,children:[e?(0,s.jsx)(`p`,{className:`text-[12px] font-extrabold tracking-tight text-gradient mb-1.5`,children:e}):null,n]});Ko.displayName=`Card`;function qo(...e){return t.u(t.d(e))}var Jo=({sub:e,className:t,children:n,...r})=>(0,s.jsxs)(`div`,{className:qo(`mb-4`,t),children:[(0,s.jsx)(`h2`,{className:`text-xl md:text-2xl font-extrabold tracking-tight text-foreground`,...r,children:n}),e?(0,s.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed mt-1`,children:e}):null]});Jo.displayName=`SectionHeading`,exports.AdminNotifications=I,exports.Button=t.c,exports.Card=Ko,exports.ConfirmModal=ve,exports.ContactPopup=t.t,exports.CustomSelect=t.s,exports.DashboardNav=de,exports.FirebaseOS=Vo,exports.Input=t.l,exports.Navbar=U,exports.PhoneInputField=n.t,exports.SectionHeading=Jo,Object.defineProperty(exports,`auth`,{enumerable:!0,get:function(){return t.Vt}}),Object.defineProperty(exports,`db`,{enumerable:!0,get:function(){return t.Ht}}),exports.registerMicrocomponent=Wo,Object.defineProperty(exports,`storage`,{enumerable:!0,get:function(){return t.Wt}}),exports.useAuth=N,exports.useConfig=t.Bt,exports.useTheme=t.Rt;