your-ai-workflow-firebase-os 1.2.26 → 1.2.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/your-ai-workflow-firebase-os.cjs.js +172 -268
- package/dist/your-ai-workflow-firebase-os.es.js +2064 -2114
- package/package.json +1 -1
- package/src/prompts/pages/publicPage.ts +16 -2
- package/src/prompts/tabs/board/adminboard.ts +5 -30
- package/src/prompts/tabs/board/privateboard.ts +5 -34
- package/src/prompts/tabs/board/publicboard.ts +5 -34
- package/src/prompts/tabs/calendar/admincalendar.ts +5 -30
- package/src/prompts/tabs/calendar/privatecalendar.ts +5 -34
- package/src/prompts/tabs/calendar/publiccalendar.ts +5 -34
- package/src/prompts/tabs/crud/admin.ts +41 -12
- package/src/prompts/tabs/crud/private.ts +39 -11
- package/src/prompts/tabs/crud/shared.ts +39 -11
- package/src/prompts/tabs/table/admintable.ts +5 -30
- package/src/prompts/tabs/table/privatetable.ts +5 -34
- package/src/prompts/tabs/table/publictable.ts +5 -34
- package/src/templates/AdminPageTemplate.tsx +111 -73
- package/src/templates/PrivatePageTemplate.tsx +109 -77
- package/src/templates/SharedPageTemplate.tsx +88 -51
- package/src/prompts/sharedConstants.ts +0 -12
|
@@ -1,326 +1,230 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-DYteiM-1.cjs`),t=require(`./theme.config-0Lvwt5Bo.cjs`),n=require(`./ContactPopup-5mXFBqTs.cjs`),r=require(`./contactForm.config-CXyq-EbM.cjs`),i=require(`./supportForm.config-haLod4rv.cjs`);let a=require(`react`);a=e.i(a,1);let o=require(`firebase/firestore`),s=require(`firebase/auth`),c=require(`firebase/storage`),l=require(`react/jsx-runtime`),u=require(`react-router-dom`),d=require(`react-dom`);var f=(0,a.createContext)({user:null,userRole:null,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 p({children:e}){let t=n.Ct(),[r,i]=(0,a.useState)(null),[c,u]=(0,a.useState)(null),[d,p]=(0,a.useState)(!1),[m,h]=(0,a.useState)(!0),[g,_]=(0,a.useState)(!1),v=a.default.useRef(null),y=a.default.useRef(null);return(0,a.useEffect)(()=>{let e;if(!n.wt){h(!1),_(!0);return}let r=(0,s.onAuthStateChanged)(n.wt,async r=>{if(r?.uid===y.current&&g){i(r);return}if(y.current=r?.uid||null,r){let a=localStorage.getItem(`fbos_role_${r.uid}`);a&&(u(a),_(!0),h(!1)),console.log(`[AuthContext] 1. onAuthStateChanged fired for user:`,r.uid),i(r);try{let i=(0,o.doc)(n.Tt,`user_profiles`,r.uid),a=(await(0,o.getDoc)(i)).data()||{};(0,o.setDoc)(i,{uid:r.uid,email:r.email,displayName:r.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,o.onSnapshot)(i,e=>{if(e.exists()){let n=e.data(),a=n.role||`user`,s=``;try{s={BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_ADMIN_EMAILS:void 0,VITE_FIREBASE_API_KEY:void 0,VITE_FIREBASE_APP_ID:void 0,VITE_FIREBASE_AUTH_DOMAIN:void 0,VITE_FIREBASE_MESSAGING_SENDER_ID:void 0,VITE_FIREBASE_PROJECT_ID:void 0,VITE_FIREBASE_STORAGE_BUCKET:void 0}?.VITE_ADMIN_EMAILS||``}catch{}let c=t.adminEmails||(s?s.split(`,`).map(e=>e.trim().toLowerCase()).filter(Boolean):[]);c.length>0&&!n.role&&c.map(e=>e.toLowerCase()).some(e=>r.email?.toLowerCase()===e)&&(a=`admin`,(0,o.updateDoc)(i,{role:`admin`}).catch(e=>console.error(`Error auto-setting admin role:`,e))),v.current===null&&(v.current=a),u(a),localStorage.setItem(`fbos_role_${r.uid}`,a),p(n.inactive===!0)}_(!0),h(!1)},e=>{console.warn(`[AuthContext] user_profiles snapshot error (safe to ignore during auth transition):`,e),_(!0),h(!1)})}catch(e){console.error(`[AuthContext] ERROR in auth resolution:`,e),_(!0),h(!1)}}else console.log(`[AuthContext] No user currently signed in.`),i(null),u(null),p(!1),_(!0),h(!1),v.current=null,e&&e()});return()=>{r(),e&&e()}},[]),(0,l.jsx)(f.Provider,{value:{user:r,userRole:c,loading:m,signOut:async()=>{await(0,s.signOut)(n.wt),i(null)},registerUser:async(e,t,r,i)=>{let{createUserWithEmailAndPassword:a}=await import(`firebase/auth`),{user:c}=await a(n.wt,e,t),l=`${r} ${i}`.trim();await(0,s.updateProfile)(c,{displayName:l});try{await c.getIdToken(!0),await(0,o.setDoc)((0,o.doc)(n.Tt,`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,s.sendEmailVerification)(c)},refreshUser:async()=>{n.wt.currentUser&&(await n.wt.currentUser.reload(),i(Object.assign(Object.create(Object.getPrototypeOf(n.wt.currentUser)),n.wt.currentUser)))},userInactive:d,roleResolved:g},children:e})}var m=()=>(0,a.useContext)(f);function h(){let[e,t]=(0,a.useState)(!1),[r,i]=(0,a.useState)([]),s=(0,a.useRef)(null),c=(0,u.useNavigate)();(0,a.useEffect)(()=>{function e(e){s.current&&!s.current.contains(e.target)&&t(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let d=(0,a.useRef)({users:[],submissions:[],requests:[]}),f=(e,t)=>{d.current[e]=t;let n=[...d.current.users,...d.current.submissions,...d.current.requests];n.sort((e,t)=>{let n=e.time?.toDate?e.time.toDate().getTime():new Date(e.time).getTime();return((t.time?.toDate?t.time.toDate().getTime():new Date(t.time).getTime())||0)-(n||0)}),i(n.slice(0,8))};(0,a.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,`user_profiles`),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(5)),e=>{f(`users`,e.docs.map(e=>{let t=e.data();return{id:`u_${e.id}`,type:`user`,title:`New user registered`,subtitle:t.email||`Unknown`,time:t.createdAt}}))}),t=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,`user_submissions`),(0,o.orderBy)(`submittedAt`,`desc`),(0,o.limit)(5)),e=>{f(`submissions`,e.docs.map(e=>{let t=e.data();return{id:`s_${e.id}`,type:`submission`,title:`New form submission`,subtitle:t.name||t.email||`Anonymous`,time:t.submittedAt}}))}),r=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,`user_requests`),(0,o.orderBy)(`submittedAt`,`desc`),(0,o.limit)(5)),e=>{f(`requests`,e.docs.map(e=>{let t=e.data();return{id:`r_${e.id}`,type:`request`,title:`New support request`,subtitle:t.name||t.submitterName||t.contactEmail||t.email||`Anonymous`,time:t.submittedAt}}))});return()=>{e(),t(),r()}},[]);let[p,m]=(0,a.useState)(()=>typeof window<`u`?parseInt(localStorage.getItem(`admin_notifications_last_read`)||`0`,10):0),h=()=>{let n=!e;if(t(n),n){let e=Date.now();m(e),typeof window<`u`&&localStorage.setItem(`admin_notifications_last_read`,e.toString())}},g=r.some(e=>{if(!e.time)return!0;let t=e.time?.toDate?e.time.toDate().getTime():new Date(e.time).getTime();return t>p||isNaN(t)}),_=e=>{t(!1),c(e===`user`?`/users`:e===`submission`?`/submissions`:`/requests`)},v=e=>{if(!e)return``;let t=e.toDate?e.toDate():new Date(e);return new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`,hour:`numeric`,minute:`numeric`}).format(t)};return(0,l.jsxs)(`div`,{className:`relative z-50 flex-shrink-0 mr-1 md:mr-2`,ref:s,children:[(0,l.jsxs)(`button`,{onClick:h,className:`p-2 rounded-xl glass-panel transition-all border border-transparent relative text-notification-icon hover:bg-foreground/5 hover:border-[var(--panel-border)]`,"aria-label":`Admin Notifications`,children:[(0,l.jsx)(n.mt,{className:`w-4 h-4 md:w-5 md:h-5`}),g&&(0,l.jsx)(`span`,{className:`absolute top-1.5 right-1.5 w-2 h-2 bg-red-500 rounded-full animate-pulse`})]}),(0,l.jsx)(n.a,{children:e&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:-5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98,y:-5},className:`absolute top-full mt-2 right-[-60px] md:right-0 w-[320px] md:w-[400px] glass-panel border border-[var(--panel-border)] rounded-2xl shadow-2xl z-50 flex flex-col origin-top-right overflow-hidden bg-[var(--panel-bg)]`,children:[(0,l.jsxs)(`div`,{className:`px-4 border-b border-[var(--panel-border)]/50 pb-3 pt-4 flex items-center justify-between`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] text-foreground tracking-wide`,children:`Notifications`}),(0,l.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,l.jsx)(`div`,{className:`max-h-[350px] overflow-y-auto w-full p-2 flex flex-col gap-1`,children:r.length===0?(0,l.jsx)(`div`,{className:`p-6 text-center text-foreground/40 text-[13px] font-medium`,children:`No recent activity.`}):r.map(e=>(0,l.jsxs)(`button`,{onClick:()=>_(e.type),className:`w-full flex items-start gap-3 p-3 rounded-xl hover:bg-foreground/5 transition-all text-left group border border-transparent hover:border-[var(--panel-border)]`,children:[(0,l.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,l.jsx)(n.d,{className:`w-4 h-4`}):e.type===`submission`?(0,l.jsx)(n.k,{className:`w-4 h-4`}):(0,l.jsx)(n.tt,{className:`w-4 h-4`})}),(0,l.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0 pr-2`,children:[(0,l.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground group-hover:text-accent transition-colors truncate`,children:e.title}),(0,l.jsx)(`span`,{className:`text-[12px] text-foreground/60 truncate`,children:e.subtitle}),(0,l.jsx)(`span`,{className:`text-[10px] font-mono tracking-wide text-foreground/40 mt-1`,children:v(e.time)})]})]},e.id))})]})})]})}var g=[{id:`contact`,hidden:!1},{id:`templates`,hidden:!1},{id:`setup`,hidden:!1}],_=e=>(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden}),v=[{id:`pages`,hidden:!1},{id:`forms`,hidden:!1},{id:`drive`,hidden:!1},{id:`users`,hidden:!1},{id:`theme`,hidden:!1},{id:`submissions`,hidden:!1},{id:`requests`,hidden:!1},{id:`settings`,hidden:!1},{id:`profile`,hidden:!1},{id:`support`,hidden:!0}],y={route:`/support`,template:`popup_form`,form:`support`,tabName:`Support`,iconName:``},b={templates:{label:`Templates`,path:`/templates`},setup:{label:`Setup`,path:`/setup`},contact:{label:`Contact`,path:`/contact`}};function x({customMenu:e,standalone:t}){let{user:r,userRole:i,signOut:s}=m(),c=(0,u.useNavigate)(),[d,f]=(0,a.useState)(!1),[p,v]=(0,a.useState)(null),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(!1),[T,E]=(0,a.useState)(!1),D=r?.displayName||r?.email?.split(`@`)[0]||`User`,ee=D.charAt(0).toUpperCase()+D.slice(1),{theme:O,toggleTheme:k,activeConfig:A}=n.xt(),te=async()=>{await s(),c(`/`),f(!1)},[j,M]=(0,a.useState)({...b}),[N,P]=(0,a.useState)(g);(0,a.useEffect)(()=>{if(!n.Tt)return;let e=(0,o.onSnapshot)((0,o.collection)(n.Tt,`sys_pages`),e=>{let t={...b};e.forEach(e=>{let n=e.data();if(n.enabled===!1)return;let r=n.pageName||n.title||b[e.id]?.label||e.id,i=n.route||(e.id===`home`?`/`:`/`+e.id);t[e.id]={label:r,path:i}}),M(t)},e=>{console.warn(`sys_pages snapshot error (safe to ignore during auth transition):`,e)}),t=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`page_order`),e=>{P(e.exists()&&Array.isArray(e.data().order)?_(e.data().order):g)},e=>{console.warn(`page_order snapshot error (safe to ignore during auth transition):`,e)}),r=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_tabs`,`support`),e=>{e.exists()&&e.data().pageName&&I(e.data().pageName)},e=>{console.warn(`support snapshot error (safe to ignore during auth transition):`,e)});return()=>{e(),t(),r()}},[]);let[F,I]=(0,a.useState)(y.tabName),L=(()=>{let e=new Set(N.filter(e=>e.hidden).map(e=>e.id)),t=new Set,n=[];return N.forEach(e=>{if(e.hidden||e.id===`home`)return;let r=j[e.id];r&&(n.push({label:r.label,path:r.path}),t.add(e.id))}),Object.entries(j).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})(),R=e||L,z=(0,a.useRef)(null),B=(0,a.useRef)(null),[V,ne]=(0,a.useState)(R.length);(0,a.useEffect)(()=>{if(t||r)return;let e=()=>{let e=z.current,t=B.current;if(!e||!t)return;let n=e.clientWidth,r=t.querySelectorAll(`[data-measure-nav]`);if(r.length===0){ne(R.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){ne(R.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++}ne(Math.max(s,1))},n=requestAnimationFrame(e);if(typeof ResizeObserver>`u`)return()=>cancelAnimationFrame(n);let i=new ResizeObserver(()=>requestAnimationFrame(e));return z.current&&i.observe(z.current),()=>{cancelAnimationFrame(n),i.disconnect()}},[R.map(e=>e.label).join(`|`),t,r,R.length]);let H=R.slice(0,V),U=R.slice(V);return(0,l.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,l.jsx)(`div`,{className:`flex items-center gap-2 md:gap-4 z-50`,children:(0,l.jsxs)(u.Link,{to:`/`,className:`flex items-center gap-2 md:gap-3 group cursor-pointer z-50`,children:[(0,l.jsx)(`div`,{className:`w-9 h-9 md:w-10 md:h-10 rounded-xl glass-panel flex items-center justify-center glow-hover shadow-lg transition-transform duration-500 group-hover:rotate-[360deg] group-active:scale-95 overflow-hidden`,children:A?.logoUrl?(0,l.jsx)(`img`,{src:A.logoUrl,alt:`Logo`,className:`w-full h-full object-cover`}):(0,l.jsx)(n.X,{className:`w-4 h-4 md:w-5 md:h-5 text-accent`})}),(0,l.jsx)(`span`,{className:`hidden lg:block font-bold text-[22px] tracking-tight text-gradient transition-colors duration-300 drop-shadow-sm`,children:A?.appName||``})]})}),(0,l.jsx)(n.a,{children:x&&(0,l.jsx)(n.t,{formId:`contact`,onClose:()=>S(!1)})}),(0,l.jsx)(n.a,{children:C&&(0,l.jsx)(n.t,{formId:`support`,onClose:()=>w(!1)})}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 md:gap-4 z-50 relative ml-auto flex-1 justify-end`,children:[!t&&!r&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{ref:B,"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:R.map((e,t)=>(0,l.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,l.jsx)(n.st,{className:`w-3 h-3`})]},e.path||t))}),(0,l.jsxs)(`div`,{className:`hidden sm:flex items-center gap-7 mr-6 w-full max-w-full justify-end relative`,ref:z,children:[H.map((e,t)=>(0,l.jsxs)(`div`,{className:`relative shrink-0`,onMouseEnter:()=>v(e.label),onMouseLeave:()=>v(null),children:[e.path?(0,l.jsxs)(u.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,l.jsx)(n.st,{className:`w-3 h-3`})]}):(0,l.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,l.jsx)(n.st,{className:`w-3 h-3`})]}),e.submenu&&p===e.label&&(0,l.jsx)(`div`,{className:`absolute top-[100%] left-0 pt-2 z-50`,children:(0,l.jsx)(n.i.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,l.jsx)(u.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,l.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`}-${t}`)),U.length>0&&(0,l.jsxs)(`div`,{className:`relative flex items-center shrink-0`,onMouseEnter:()=>f(`overflow`),children:[(0,l.jsx)(`button`,{onClick:()=>f(d===`overflow`?!1:`overflow`),className:`p-1 rounded-lg transition-colors flex items-center ${d===`overflow`?`bg-foreground/5 text-accent`:`text-foreground/50 hover:bg-foreground/5 hover:text-accent`}`,children:(0,l.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,l.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,l.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1`}),(0,l.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1`})]})}),(0,l.jsx)(n.a,{children:d===`overflow`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>f(!1)}),(0,l.jsx)(n.i.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 bg-background border border-[var(--panel-border)] rounded-2xl shadow-xl flex flex-col py-2 z-50 origin-top-right`,children:U.map((e,t)=>e.path?(0,l.jsx)(u.Link,{to:e.path,onClick:()=>f(!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,l.jsx)(`button`,{onClick:()=>{e.action&&e.action(),f(!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))})]})})]})]}),A?.showThemeToggle&&(0,l.jsx)(`button`,{onClick:k,className:`p-2 mr-2 rounded-xl glass-panel hover:bg-foreground/5 transition-all text-accent border border-[var(--panel-border)] hover:border-accent/40 shrink-0`,"aria-label":`Toggle Theme`,children:O===`dark`?(0,l.jsx)(n._,{className:`w-4 h-4 md:w-5 md:h-5`}):(0,l.jsx)(n.E,{className:`w-4 h-4 md:w-5 md:h-5`})}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(u.Link,{to:`/login`,className:`hidden sm:flex text-[14px] font-bold tracking-wide text-foreground/80 hover:text-accent transition-colors px-3 py-1.5 shrink-0`,children:`Sign In`}),(0,l.jsx)(u.Link,{to:`/register`,className:`hidden sm:flex text-[13px] md:text-[14px] font-bold tracking-wide px-4 py-1.5 md:px-5 md:py-2 rounded-xl btn-primary transition-all duration-300 hover:shadow-lg hover:-translate-y-0.5 active:scale-95 items-center justify-center ml-2`,children:`Get Started`}),(0,l.jsxs)(`div`,{className:`relative sm:hidden ml-1`,children:[(0,l.jsx)(`button`,{onClick:()=>f(d===`guest`?!1:`guest`),className:`p-2 rounded-xl glass-panel glow-hover border transition-all ${d===`guest`?`border-accent bg-foreground/5`:`border-[var(--panel-border)] hover:bg-foreground/5`}`,children:(0,l.jsx)(n.O,{className:`w-5 h-5 text-accent/80`})}),(0,l.jsx)(n.a,{children:d===`guest`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>f(!1)}),(0,l.jsxs)(n.i.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-panel border border-[var(--panel-border)] rounded-2xl shadow-2xl z-50 flex flex-col gap-1 origin-top-right`,children:[(0,l.jsxs)(u.Link,{to:`/templates`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.P,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Templates`})]}),(0,l.jsxs)(u.Link,{to:`/setup`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.y,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Setup`})]}),(0,l.jsxs)(u.Link,{to:`/contact`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all w-full text-left`,children:[(0,l.jsx)(n.k,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Contact`})]}),(0,l.jsxs)(`div`,{className:`pt-2 mt-1 border-t border-[var(--panel-border)]/50 flex flex-col gap-1`,children:[(0,l.jsxs)(u.Link,{to:`/login`,onClick:()=>f(!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,l.jsx)(n.A,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Sign In`})]}),(0,l.jsx)(u.Link,{to:`/register`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl btn-primary w-full shadow-lg hover:-translate-y-0.5 transition-transform text-white`,children:(0,l.jsx)(`span`,{className:`text-[14px] font-bold mx-auto`,children:`Get Started`})})]})]})]})})]})]})]}),!t&&r&&(0,l.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2 mr-1`,children:[i===`admin`&&(0,l.jsx)(h,{}),A?.showThemeToggle&&(0,l.jsx)(`button`,{onClick:k,className:`p-2 ml-1 rounded-xl glass-panel hover:bg-foreground/5 transition-all text-accent border border-[var(--panel-border)] hover:border-accent/40`,"aria-label":`Toggle Theme`,children:O===`dark`?(0,l.jsx)(n._,{className:`w-4 h-4 md:w-5 md:h-5`}):(0,l.jsx)(n.E,{className:`w-4 h-4 md:w-5 md:h-5`})})]}),(0,l.jsxs)(`div`,{className:`relative z-50 flex items-center gap-3`,children:[(0,l.jsxs)(`div`,{className:`relative flex-shrink-0`,children:[(0,l.jsxs)(`button`,{onClick:()=>f(d===`user`?!1:`user`),className:`flex items-center gap-2 group p-1 sm:pr-2.5 rounded-full glass-panel hover:bg-foreground/5 transition-all duration-300 border ${d===`user`?`border-accent/40 bg-foreground/5`:`border-transparent hover:border-[var(--panel-border)]`}`,children:[(0,l.jsx)(`div`,{className:`w-8 h-8 md:w-9 md:h-9 rounded-full bg-accent/10 flex items-center justify-center overflow-hidden border border-[var(--panel-border)] group-hover:border-accent/30 transition-colors shrink-0 text-accent`,children:r.photoURL&&!T?(0,l.jsx)(`img`,{src:r.photoURL,alt:`Profile`,className:`w-full h-full object-cover`,onError:()=>E(!0)}):(0,l.jsx)(n.d,{className:`w-4 h-4 md:w-5 md:h-5 text-accent`})}),(0,l.jsxs)(`div`,{className:`hidden sm:flex flex-col text-left mr-1 justify-center min-w-[70px] max-w-[160px]`,children:[(0,l.jsx)(`span`,{className:`text-[12px] font-extrabold leading-tight text-foreground truncate w-full`,children:ee}),(0,l.jsx)(`span`,{className:`text-[10px] font-mono tracking-wider leading-tight text-accent truncate w-full mt-0.5 uppercase font-bold`,children:i===`admin`?`Admin`:`Free User`})]})]}),(0,l.jsx)(n.a,{children:d===`user`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>f(!1)}),(0,l.jsxs)(n.i.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-panel border border-[var(--panel-border)] rounded-2xl p-2 shadow-2xl z-50 flex flex-col origin-top-right`,children:[(0,l.jsxs)(`div`,{className:`p-3 border-b border-[var(--panel-border)]/50 mb-1 flex flex-col gap-1.5`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[15px] text-foreground truncate`,children:ee}),(0,l.jsx)(`span`,{className:`text-[12px] text-foreground/50 truncate font-mono`,children:r.email})]}),(0,l.jsxs)(`div`,{className:`py-1`,children:[(0,l.jsxs)(u.Link,{to:`/profile`,onClick:()=>f(!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,l.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,l.jsx)(n.d,{className:`w-3 h-3 text-accent`})}),`Profile Settings`]}),(0,l.jsxs)(u.Link,{to:`/drive`,onClick:()=>f(!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,l.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,l.jsx)(n.H,{className:`w-3 h-3 text-accent`})}),`Drive`]}),i===`admin`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(u.Link,{to:`/users`,onClick:()=>f(!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,l.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,l.jsx)(n.u,{className:`w-3 h-3 text-accent`})}),`Users`]}),(0,l.jsxs)(u.Link,{to:`/submissions`,onClick:()=>f(!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,l.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,l.jsx)(n.k,{className:`w-3 h-3 text-accent`})}),`Submissions`]}),(0,l.jsxs)(u.Link,{to:`/requests`,onClick:()=>f(!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,l.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,l.jsx)(n.tt,{className:`w-3 h-3 text-accent`})}),`Requests`]}),(0,l.jsxs)(u.Link,{to:`/settings`,onClick:()=>f(!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,l.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,l.jsx)(n.y,{className:`w-3 h-3 text-accent`})}),`Settings`]}),(0,l.jsxs)(u.Link,{to:`/pages`,onClick:()=>f(!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,l.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,l.jsx)(n.L,{className:`w-3 h-3 text-accent`})}),`Pages`]})]}),i!==`admin`&&(0,l.jsxs)(u.Link,{to:`/support`,onClick:()=>f(!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,l.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,l.jsx)(n.tt,{className:`w-3 h-3 text-accent`})}),F]})]}),(0,l.jsx)(`div`,{className:`pt-1 mt-1 border-t border-[var(--panel-border)]/50`,children:(0,l.jsxs)(`button`,{onClick:te,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,l.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,l.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,l.jsx)(`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`}),(0,l.jsx)(`polyline`,{points:`16 17 21 12 16 7`}),(0,l.jsx)(`line`,{x1:`21`,y1:`12`,x2:`9`,y2:`12`})]})}),`Sign Out`]})})]})]})})]}),(0,l.jsxs)(`div`,{className:`relative sm:hidden`,children:[(0,l.jsx)(`button`,{onClick:()=>f(d===`nav`?!1:`nav`),className:`p-2 rounded-xl glass-panel glow-hover border transition-all ${d===`nav`?`border-accent bg-foreground/5`:`border-[var(--panel-border)] hover:bg-foreground/5`}`,children:(0,l.jsx)(n.O,{className:`w-5 h-5 text-accent/80`})}),(0,l.jsx)(n.a,{children:d===`nav`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>f(!1)}),(0,l.jsxs)(n.i.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-panel border border-[var(--panel-border)] rounded-2xl shadow-2xl z-50 flex flex-col gap-1 origin-top-right`,children:[(0,l.jsxs)(u.Link,{to:`/profile`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.d,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Profile Settings`})]}),(0,l.jsxs)(u.Link,{to:`/drive`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.H,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Drive`})]}),(0,l.jsxs)(u.Link,{to:`/dashboard`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.I,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Dashboard`})]}),i===`admin`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(u.Link,{to:`/users`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.u,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Users`})]}),(0,l.jsxs)(u.Link,{to:`/submissions`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.k,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Submissions`})]}),(0,l.jsxs)(u.Link,{to:`/requests`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.tt,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Requests`})]}),(0,l.jsxs)(u.Link,{to:`/settings`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.y,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Settings`})]})]}),i!==`admin`&&(0,l.jsxs)(u.Link,{to:`/support`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all w-full text-left`,children:[(0,l.jsx)(n.tt,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Support`})]}),(0,l.jsx)(`div`,{className:`pt-1 mt-1 border-t border-[var(--panel-border)]/50`,children:(0,l.jsx)(`button`,{onClick:te,className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-red-500/10 text-red-500/80 hover:text-red-500 transition-all w-full`,children:(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Sign Out`})})})]})]})})]})]})]}),t&&(0,l.jsx)(l.Fragment,{children:A?.showThemeToggle&&(0,l.jsx)(`button`,{onClick:k,className:`p-2 ml-1 rounded-xl glass-panel hover:bg-foreground/5 transition-all text-accent border border-[var(--panel-border)] hover:border-accent/40`,"aria-label":`Toggle Theme`,children:O===`dark`?(0,l.jsx)(n._,{className:`w-4 h-4`}):(0,l.jsx)(n.E,{className:`w-4 h-4`})})})]})]})}var S={hero:{title:`Firebase OS.`,showSubtitle:!0,subtitle:`The Open-Source Firebase Starter`,text:`A production-ready Firebase backend template with Auth, Firestore prefix rules, and a clean dashboard — ready for vibe-coded apps.`,buttons:{primary:{text:`Start Building Free`,action:`register`},secondary:{text:`Sign In`,action:`sign_in`}}}};function C(){let[e,t]=(0,a.useState)(null),r=n.Ct()?.defaultConfigs?.home||S,[i,s]=(0,a.useState)(()=>{try{let e=localStorage.getItem(`fbos_home_config`);if(e)return JSON.parse(e)}catch{}return r}),[c,d]=(0,a.useState)(!0);if((0,a.useEffect)(()=>(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_pages`,`home`),e=>{if(e.exists()){let t=e.data();s(t),localStorage.setItem(`fbos_home_config`,JSON.stringify(t))}else s(r),localStorage.removeItem(`fbos_home_config`)}),[]),!c)return null;let f=i||S,p=f?.hero?.showSubtitle??!0;f?.hero?.subtitleEmoji;let m=f?.hero?.title||f?.heroTitle||`The Open-Source Firebase Starter`,h=f?.hero?.subtitle||f?.heroSubtitle||`The Open-Source Firebase Starter`,g=f?.hero?.text||f?.heroText||`A production-ready Firebase backend template with Auth, Firestore prefix rules, and a clean dashboard — ready for vibe-coded apps.`;f?.hero?.buttons?.primary?.text||f?.primaryBtnText,f?.hero?.buttons?.primary?.action||f?.primaryBtnAction;let _=f?.hero?.buttons?.primary||{},v=f?.hero?.buttons?.secondary||{},y=(e,n,r,i)=>{let a=e.text||n,o=e.action||r,s=i.replace(/rounded-\[.*?\]|rounded-\w+/g,``).replace(/border /g,``).replace(/border-\[.*?\]/g,``),c={borderRadius:`var(--btn-radius, 0.75rem)`};if(o===`form`){let n=e.form||`contact`;return(0,l.jsx)(`button`,{onClick:()=>t(n),className:s,style:c,children:a})}if(o===`redirect`){let t=e.url||`/`;return t.startsWith(`http`)?(0,l.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:s,style:c,children:a}):(0,l.jsx)(u.Link,{to:t,className:s,style:c,children:a})}return(0,l.jsx)(u.Link,{to:{sign_in:`/login`,register:`/register`}[o]||`/register`,className:s,style:c,children:a})};return(0,l.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,l.jsxs)(n.i.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},transition:{duration:.8},className:`text-center mb-8 md:mb-12`,children:[p&&(0,l.jsxs)(n.i.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:[h===S.hero.subtitle&&(0,l.jsx)(n.s,{className:`w-4 h-4 text-accent`}),` `,h]}),(0,l.jsx)(n.i.h1,{className:`text-5xl sm:text-6xl md:text-7xl lg:text-[5.5rem] font-extrabold tracking-tight mb-6 md:mb-8 text-gradient animate-float leading-[1.1] md:leading-[1.15] px-2`,children:m}),(0,l.jsx)(`p`,{className:`text-[15px] sm:text-lg md:text-xl lg:text-[22px] 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:g}),(0,l.jsxs)(n.i.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:[y(_,`Start Building Free`,`register`,`w-full sm:w-auto 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`),y(v,`Sign In`,`sign_in`,`w-full sm:w-auto px-6 md:px-8 py-3 md:py-3.5 rounded-xl font-semibold tracking-wide btn-secondary text-[15px] transition-all duration-300 flex items-center justify-center hover:-translate-y-1`)]})]}),(0,l.jsx)(n.a,{children:e&&(0,l.jsx)(n.t,{onClose:()=>t(null),formId:e})})]})}function w(){let[e,t]=(0,a.useState)(!1),[r,i]=(0,a.useState)(null),o=(0,u.useNavigate)(),{registerUser:c}=m();return(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mt-6 md:mt-8 mb-8`,children:(0,l.jsxs)(n.i.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,l.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,l.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,l.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight`,children:`Create an account`}),(0,l.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Join Firebase OS and start building today.`})]}),r&&(0,l.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:r}),(0,l.jsxs)(`form`,{className:`space-y-4`,onSubmit:async e=>{e.preventDefault(),t(!0),i(null);let n=new FormData(e.currentTarget),r=n.get(`email`),a=n.get(`password`),s=n.get(`firstName`),d=n.get(`lastName`);if(a.length<6){i(`Password must be at least 6 characters.`),t(!1);return}try{await c(r,a,s,d),o(`/verify`)}catch(e){e?.code===`auth/email-already-in-use`?i((0,l.jsxs)(`span`,{children:[`An account with this email already exists.`,` `,(0,l.jsx)(u.Link,{to:`/login?email=${encodeURIComponent(r)}`,className:`font-bold underline hover:text-accent transition-colors`,children:`Sign in?`})]})):e?.code===`auth/weak-password`?i(`Password must be at least 6 characters.`):i(e?.message||`An error occurred during registration.`)}finally{t(!1)}},children:[(0,l.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,l.jsx)(n.r,{name:`firstName`,label:`First Name`,type:`text`,placeholder:`John`,required:!0}),(0,l.jsx)(n.r,{name:`lastName`,label:`Last Name`,type:`text`,placeholder:`Doe`,required:!0})]}),(0,l.jsx)(n.r,{name:`email`,label:`Email`,type:`email`,placeholder:`name@example.com`,required:!0}),(0,l.jsx)(n.r,{name:`password`,label:`Password`,type:`password`,placeholder:`••••••••`,required:!0}),(0,l.jsx)(`div`,{className:`pt-2`,children:(0,l.jsxs)(n.n,{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,l.jsx)(n.ht,{className:`ml-2 w-4 h-4 group-hover:translate-x-1 transition-transform shrink-0`})]})})]}),(0,l.jsxs)(`div`,{className:`mt-6 pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:[(0,l.jsxs)(n.n,{variant:`secondary`,onClick:async()=>{t(!0);try{await(0,s.signInWithPopup)(n.wt,new s.GoogleAuthProvider)}catch(e){e instanceof Error&&i(e.message)}finally{t(!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,l.jsxs)(`svg`,{className:`w-5 h-5 mr-3`,viewBox:`0 0 24 24`,children:[(0,l.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,l.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,l.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,l.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,l.jsxs)(`p`,{className:`text-[14px] text-foreground/70 font-medium pt-2 tracking-wide`,children:[`Already have an account? `,(0,l.jsx)(u.Link,{to:`/login`,className:`text-accent hover:underline font-bold ml-1`,children:`Sign in`})]})]})]})})}function T(){let[e,t]=(0,a.useState)(!1),[r,i]=(0,a.useState)(null),[o]=(0,u.useSearchParams)(),c=(0,u.useNavigate)(),[d]=(0,a.useState)(o.get(`email`)||``);return(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mt-6 md:mt-8 mb-8`,children:(0,l.jsxs)(n.i.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,l.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,l.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,l.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight`,children:`Welcome back`}),(0,l.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Sign in to Firebase OS.`})]}),r&&(0,l.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:r}),(0,l.jsxs)(`form`,{className:`space-y-4`,onSubmit:async e=>{e.preventDefault(),t(!0),i(null);let r=new FormData(e.currentTarget),a=r.get(`email`),d=r.get(`password`);try{await(0,s.signInWithEmailAndPassword)(n.wt,a,d),c(o.get(`from`)||`/dashboard`,{replace:!0})}catch(e){e?.code===`auth/invalid-credential`||e?.code===`auth/user-not-found`||e?.code===`auth/wrong-password`?i((0,l.jsxs)(`span`,{children:[`Email or Password are incorrect.`,` `,(0,l.jsx)(u.Link,{to:`/reset-password`,className:`font-bold underline hover:text-red-400 transition-colors`,children:`Reset password?`})]})):i(e?.message||`Invalid credentials.`),t(!1)}},children:[(0,l.jsx)(n.r,{name:`email`,label:`Email`,type:`email`,defaultValue:d,placeholder:`name@example.com`,required:!0}),(0,l.jsxs)(`div`,{className:`space-y-2`,children:[(0,l.jsxs)(`div`,{className:`flex justify-between items-center pr-1`,children:[(0,l.jsx)(`label`,{className:`text-[14px] md:text-[15px] tracking-wide font-medium text-foreground/80 select-none pb-1`,children:`Password`}),(0,l.jsx)(u.Link,{to:`/reset-password`,className:`text-[13px] md:text-[14px] text-accent hover:underline font-bold tracking-wide`,children:`Forgot Password?`})]}),(0,l.jsx)(n.r,{name:`password`,type:`password`,placeholder:`••••••••`,required:!0})]}),(0,l.jsx)(`div`,{className:`pt-2`,children:(0,l.jsxs)(n.n,{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,l.jsx)(n.ht,{className:`ml-2 w-4 h-4 group-hover:translate-x-1 transition-transform shrink-0`})]})})]}),(0,l.jsxs)(`div`,{className:`mt-6 pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:[(0,l.jsxs)(n.n,{variant:`secondary`,onClick:async()=>{t(!0);try{await(0,s.signInWithPopup)(n.wt,new s.GoogleAuthProvider),c(o.get(`from`)||`/dashboard`,{replace:!0})}catch(e){e instanceof Error&&i(e.message)}finally{t(!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,l.jsxs)(`svg`,{className:`w-5 h-5 mr-3`,viewBox:`0 0 24 24`,children:[(0,l.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,l.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,l.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,l.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,l.jsxs)(`p`,{className:`text-[14px] text-foreground/70 font-medium pt-2 tracking-wide`,children:[`New here? `,(0,l.jsx)(u.Link,{to:`/register`,className:`text-accent hover:underline font-bold ml-1`,children:`Create account`})]})]})]})})}function E(){let{user:e,refreshUser:t}=m(),r=(0,u.useNavigate)(),[i,o]=(0,a.useState)(!1),[c,d]=(0,a.useState)(!1),[f,p]=(0,a.useState)(``);return(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mb-16`,children:(0,l.jsxs)(n.i.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,l.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,l.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,l.jsx)(n.k,{className:`w-7 h-7 md:w-8 md:h-8 text-accent opacity-90`})}),(0,l.jsx)(`h1`,{className:`text-2xl md:text-3xl font-extrabold mb-3 text-foreground tracking-tight`,children:`Verify your email`}),(0,l.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,l.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.`]}),f&&(0,l.jsx)(`div`,{className:`p-3 md:p-4 mb-5 md:mb-6 text-[13px] md:text-[14px] font-medium 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,l.jsxs)(`div`,{className:`flex flex-col gap-3 max-w-[360px] mx-auto`,children:[(0,l.jsx)(n.n,{variant:`primary`,onClick:async()=>{o(!0),p(``);try{if(n.wt.currentUser){if(await n.wt.currentUser.reload(),!n.wt.currentUser.emailVerified){p(`Email is not verified yet. Please check your inbox.`),o(!1);return}await n.wt.currentUser.getIdToken(!0),await t(),r(`/dashboard`)}}catch{p(`Something went wrong. Please try again.`),o(!1)}},isLoading:i,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,l.jsx)(n.n,{variant:`ghost`,onClick:async()=>{if(e){d(!0),p(``);try{await(0,s.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:c,className:`w-full py-2.5 md:py-3 text-[13px] md:text-[14px] font-semibold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,children:`Resend verification link`})]})]})})}var D={pages:{path:`/pages`,label:`Pages`,icon:n.L,roles:[`admin`]},forms:{path:`/forms`,label:`Forms`,icon:n.S,roles:[`admin`]},drive:{path:`/drive`,label:`Drive`,icon:n.H,roles:[`admin`,`user`,`editor`,`guest`]},users:{path:`/users`,label:`Users`,icon:n.u,roles:[`admin`]},theme:{path:`/theme`,label:`Theme`,icon:n.T,roles:[`admin`]},submissions:{path:`/submissions`,label:`Submissions`,icon:n.k,roles:[`admin`]},requests:{path:`/requests`,label:`Requests`,icon:n.tt,roles:[`admin`]},settings:{path:`/settings`,label:`Settings`,icon:n.y,roles:[`admin`]},profile:{path:`/profile`,label:`Profile`,icon:n.d,roles:[`admin`,`user`,`editor`,`guest`]},support:{path:`/support`,label:`Support`,icon:n.tt,roles:[`user`,`editor`,`guest`]}};function ee({customTabs:e=[]}){let{pathname:t}=(0,u.useLocation)(),{userRole:r}=m(),[i,s]=(0,a.useState)(!1),c=(0,a.useRef)(null),[d,f]=(0,a.useState)({}),[p,h]=(0,a.useState)(v);(0,a.useEffect)(()=>{try{let e=localStorage.getItem(`fbos_nav_tabs`);e&&f(JSON.parse(e));let t=localStorage.getItem(`fbos_nav_order`);t&&h(JSON.parse(t))}catch{}let e=(0,o.onSnapshot)((0,o.collection)(n.Tt,`sys_tabs`),e=>{let t={};e.forEach(e=>{t[e.id]=e.data()}),f(t),localStorage.setItem(`fbos_nav_tabs`,JSON.stringify(t))},e=>{console.warn(`sys_tabs snapshot error:`,e)}),t=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`tab_order`),e=>{let t=e.exists()&&Array.isArray(e.data().order)?_(e.data().order):v;h(t),localStorage.setItem(`fbos_nav_order`,JSON.stringify(t))},e=>{console.warn(`tab_order snapshot error:`,e)});return()=>{e(),t()}},[]),(0,a.useEffect)(()=>{function e(e){c.current&&!c.current.contains(e.target)&&s(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let g=[...(()=>{let e={};Object.entries(D).forEach(([t,n])=>{e[t]={id:t,...n,exact:!0}}),Object.entries(d).forEach(([t,r])=>{let i=e[t],a=i?.icon??n.L;if(r?.iconName){let e=r.iconName.trim(),t=e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);n.o[t]?a=n.o[t]:n.o[e]&&(a=n.o[e])}let o=i?.roles??[`admin`];r?.pageType===`admin`?o=[`admin`]:r?.pageType===`shared`?o=[`admin`,`editor`,`user`]:r?.pageType===`private`?o=[`admin`,`user`]:r?.pageType===`public`&&(o=[`admin`,`user`,`editor`,`guest`]),e[t]={id:t,path:r?.route?r.route.startsWith(`/`)?r.route:`/`+r.route:i?.path??`/`+t,label:r?.tabName||r?.pageTitle||r?.pageName||i?.label||t,icon:a,roles:o,exact:!0}});let t=[],r=new Set;p.forEach(n=>{n.hidden||e[n.id]&&(t.push(e[n.id]),r.add(n.id))});let i=[],a=[];return Object.keys(e).forEach(t=>{if(r.has(t))return;let n=p.find(e=>e.id===t);n?.hidden||(t in d&&!n?i.push(e[t]):a.push(e[t]))}),i.length>0&&t.unshift(...i),a.length>0&&t.push(...a),t})(),...e.map(e=>({...e,id:e.path}))].filter(e=>e.id===`support`&&r===`admin`?!1:Array.isArray(e.roles)?e.roles.includes(r||`guest`):!1),y=(0,a.useRef)(null),b=(0,a.useRef)(null),[x,S]=(0,a.useState)(g.length);(0,a.useEffect)(()=>{let e=()=>{let e=y.current,t=b.current;if(!e||!t)return;let n=e.clientWidth;if(n===0)return;let r=t.querySelectorAll(`[data-measure-tab]`);if(r.length===0){S(g.length);return}let i=0,a=!0;for(let e=0;e<r.length;e++)if(i+=r[e].offsetWidth+(e>0?40:0),i>n){a=!1;break}if(a){S(g.length);return}let o=0,s=0;for(let e=0;e<r.length;e++){let t=r[e].offsetWidth,i=o+t+(e>0?40:0);if(i+52>n)break;o=i,s++}S(Math.max(s,1))},t=requestAnimationFrame(e);if(typeof ResizeObserver>`u`)return()=>cancelAnimationFrame(t);let n=new ResizeObserver(()=>requestAnimationFrame(e));return y.current&&n.observe(y.current),()=>{cancelAnimationFrame(t),n.disconnect()}},[g.map(e=>e.id+e.label).join(`|`),g.length]);let C=g.slice(0,x),w=g.slice(x),T=e=>e.exact?t===e.path:t.startsWith(e.path),E=w.some(e=>T(e));return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{ref:b,"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,l.jsxs)(`span`,{"data-measure-tab":!0,className:`flex items-center gap-2 text-[14.5px] font-semibold shrink-0 pb-3`,children:[(0,l.jsx)(t,{className:`w-[18px] h-[18px]`}),e.label]},e.path||e.id)})}),(0,l.jsxs)(`div`,{ref:y,className:`w-full flex items-center gap-6 md:gap-10 mb-8 border-b border-[var(--panel-border)] px-1 whitespace-nowrap relative`,children:[C.map(e=>{let t=T(e),n=e.icon;return(0,l.jsxs)(u.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,l.jsx)(n,{className:`w-[18px] h-[18px]`}),e.label]},e.path||e.id)}),w.length>0&&(0,l.jsxs)(`div`,{className:`relative shrink-0 ml-auto`,ref:c,children:[(0,l.jsx)(`button`,{onClick:()=>s(!i),className:`flex items-center justify-center transition-all duration-300 pb-3 -mb-[1px] border-b-2 cursor-pointer ${E?`text-accent border-accent`:`text-foreground/50 hover:text-foreground/80 border-transparent`}`,title:`More items`,children:(0,l.jsx)(n.J,{className:`w-5 h-5`})}),(0,l.jsx)(n.a,{children:i&&(0,l.jsx)(n.i.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] bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] rounded-2xl shadow-xl z-50 flex flex-col py-2 overflow-hidden`,children:w.map(e=>{let t=T(e),n=e.icon;return(0,l.jsxs)(u.Link,{to:e.path||`/`,onClick:()=>s(!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,l.jsx)(n,{className:`w-4 h-4`}),e.label]},e.path||e.id)})})})]})]})]})}function O(){let{user:e,refreshUser:t}=m(),[r,i]=(0,a.useState)(e?.displayName||``),[u,d]=(0,a.useState)(e?.email||``),[f,p]=(0,a.useState)(e?.photoURL||``),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(null),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(``),[C,w]=(0,a.useState)(!1),[T,E]=(0,a.useState)(!1),[D,O]=(0,a.useState)(!0);a.default.useEffect(()=>{i(e?.displayName||``),d(e?.email||``),p(e?.photoURL||``)},[e?.uid,e?.displayName,e?.email,e?.photoURL]);let k=async t=>{if(e)try{let r=[`mem_files`,`admin_files`];(await(0,o.getDocs)((0,o.collection)(n.Tt,`sys_tabs`))).forEach(e=>{let t=e.data(),n=(t.tabName||e.id).toLowerCase().replace(/[^a-z0-9]+/g,`_`);t.pageType===`shared`&&r.push(`mem_${n}_records`),t.pageType===`admin`&&r.push(`admin_${n}_records`)});for(let i of r)try{let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,i),(0,o.where)(`uid`,`==`,e.uid)));if(r.empty)continue;let a=(0,o.writeBatch)(n.Tt);r.docs.forEach(e=>a.update(e.ref,{creatorAvatar:t})),await a.commit()}catch{}}catch(e){console.error(`Error propagating avatar to records:`,e)}};return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Profile Settings`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/profile`]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 animate-in fade-in duration-500 pb-20`,children:[(0,l.jsx)(`div`,{className:`flex justify-start`,children:(0,l.jsx)(ee,{})}),(0,l.jsx)(n.a,{children:_&&(0,l.jsxs)(n.i.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,l.jsx)(n.nt,{className:`w-5 h-5 shrink-0`}):(0,l.jsx)(n.rt,{className:`w-5 h-5 shrink-0`}),(0,l.jsx)(`span`,{className:`text-[14px] font-semibold tracking-wide leading-relaxed`,children:_.text})]})}),(0,l.jsx)(`form`,{onSubmit:async i=>{if(i.preventDefault(),e){g(!0),v(null);try{r!==e.displayName&&await(0,s.updateProfile)(e,{displayName:r});let i=!1;if(u!==e.email){let t=await(0,s.fetchSignInMethodsForEmail)(n.wt,u);if(t&&t.length>0)throw Error(`An account with this email already exists.`);await(0,s.verifyBeforeUpdateEmail)(e,u),i=!0}if(y){if(y!==x)throw Error(`Passwords do not match.`);if(y.length<6)throw Error(`Password must be at least 6 characters.`);await(0,s.updatePassword)(e,y),b(``),S(``)}await t(),v(i?{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,l.jsxs)(`div`,{className:`glass-panel w-full p-8 md:p-12 rounded-3xl border border-[var(--panel-border)] shadow-2xl space-y-8 min-h-[500px]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-6 pb-6 border-b border-[var(--panel-border)]/50`,children:[(0,l.jsxs)(`div`,{className:`w-24 h-24 md:w-28 md:h-28 rounded-full glass-panel border-4 border-[var(--panel-border)] shadow-xl bg-accent/10 flex items-center justify-center relative overflow-hidden shrink-0 group transition-transform duration-300 hover:scale-[1.02]`,children:[(T||f&&D&&!C)&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-accent/5 backdrop-blur-sm z-10`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),f&&!C?(0,l.jsx)(`img`,{src:f,alt:`Avatar`,className:`w-full h-full object-cover transition-opacity duration-300 ${D?`opacity-0`:`opacity-100`}`,onLoad:()=>O(!1),onError:()=>{w(!0),O(!1)}}):(0,l.jsx)(n.d,{className:`w-10 h-10 md:w-12 md:h-12 text-accent`}),!T&&(0,l.jsxs)(`div`,{className:`absolute inset-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2 z-10 backdrop-blur-sm`,children:[(0,l.jsxs)(`label`,{className:`flex flex-col items-center justify-center cursor-pointer p-2 rounded-full hover:bg-white/20 transition-colors text-white`,title:`Upload Photo`,children:[(0,l.jsx)(n.ut,{className:`w-5 h-5`}),(0,l.jsx)(`input`,{type:`file`,accept:`image/*`,onChange:async r=>{let i=r.target.files?.[0];if(!(!i||!e)){if(i.size>2*1024*1024){v({text:`File too large. Please select an image under 2MB.`,type:`error`});return}E(!0),w(!1),O(!0);try{let r=(0,c.ref)(n.Dt,`user_avatars/${e.uid}/file.png`);await(0,c.uploadBytes)(r,i,{customMetadata:{ownerId:e.uid}});let a=await(0,c.getDownloadURL)(r);await(0,s.updateProfile)(e,{photoURL:a}),await(0,o.updateDoc)((0,o.doc)(n.Tt,`user_profiles`,e.uid),{avatar:a}),p(a),await t(),k(a),v({text:`Avatar successfully updated!`,type:`success`})}catch(e){console.error(e),v({text:`Failed to upload photo.`,type:`error`})}finally{E(!1)}}},className:`hidden`})]}),f&&(0,l.jsx)(`button`,{type:`button`,onClick:async()=>{if(e){E(!0),w(!1),O(!1);try{await(0,c.deleteObject)((0,c.ref)(n.Dt,`user_avatars/${e.uid}/file.png`)).catch(e=>console.error(e)),await(0,s.updateProfile)(e,{photoURL:``}),await(0,o.updateDoc)((0,o.doc)(n.Tt,`user_profiles`,e.uid),{avatar:``}),p(``),await t(),k(``),v({text:`Avatar removed.`,type:`success`})}catch(e){console.error(e),v({text:`Failed to delete photo.`,type:`error`})}finally{E(!1)}}},className:`p-2 rounded-full hover:bg-red-500/80 text-white transition-colors`,title:`Delete Photo`,children:(0,l.jsx)(n.h,{className:`w-5 h-5`})})]})]}),(0,l.jsxs)(`div`,{className:`flex-1 text-left`,children:[(0,l.jsx)(`h3`,{className:`font-extrabold text-2xl text-foreground mb-1`,children:r||`Firebase OS User`}),(0,l.jsx)(`div`,{className:`text-[12px] font-mono uppercase tracking-widest text-accent bg-accent/10 px-2.5 py-1 rounded-md border border-accent/20 inline-block`,children:e?.emailVerified?`Verified Account`:`Unverified`}),(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/40 mt-2 font-medium`,children:e?.email})]})]}),(0,l.jsxs)(`div`,{className:`space-y-6`,children:[(0,l.jsx)(`h3`,{className:`text-[16px] font-extrabold text-foreground flex items-center gap-2`,children:`Account Details`}),(0,l.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-5 md:gap-6`,children:[(0,l.jsx)(n.r,{name:`name`,value:r,onChange:e=>i(e.target.value),label:`Display Name`,placeholder:`John Doe`}),(0,l.jsxs)(`div`,{className:`flex flex-col`,children:[(0,l.jsx)(n.r,{name:`email`,type:`email`,value:u,onChange:e=>d(e.target.value),label:`Email Address`,placeholder:`name@example.com`,required:!0}),(0,l.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,l.jsxs)(`div`,{className:`pt-6 border-t border-[var(--panel-border)]/50`,children:[(0,l.jsx)(`h3`,{className:`text-[15px] font-bold text-foreground mb-4 flex items-center gap-2`,children:`Change Password`}),(0,l.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-5 md:gap-6`,children:[(0,l.jsx)(n.r,{name:`password`,type:`password`,label:`New Password`,value:y,onChange:e=>b(e.target.value),placeholder:`Minimum 6 characters`}),(0,l.jsx)(n.r,{name:`confirmPassword`,type:`password`,label:`Confirm Password`,value:x,onChange:e=>S(e.target.value),placeholder:`Repeat password`})]})]}),(0,l.jsx)(`div`,{className:`pt-8 border-t border-[var(--panel-border)]/50 flex justify-start w-full`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:h,className:`px-12 py-3 md:py-2.5 text-[14px] md:text-[15px] font-bold tracking-wide rounded-xl hover:-translate-y-0.5`,children:`Save Changes`})})]})})]})]})}function k(){let[e,t]=(0,a.useState)(!1),[r,i]=(0,a.useState)(null),[o,c]=(0,a.useState)(0),[d,f]=(0,a.useState)(0);return(0,a.useEffect)(()=>{let e;return o>0&&(e=setInterval(()=>c(e=>e-1),1e3)),()=>clearInterval(e)},[o]),(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mb-16 mt-6 md:mt-8`,children:(0,l.jsxs)(n.i.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,l.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,l.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,l.jsx)(n.R,{className:`w-7 h-7 md:w-8 md:h-8 text-accent opacity-90`})}),(0,l.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,l.jsx)(`h3`,{className:`text-2xl md:text-3xl font-extrabold mb-2 md:mb-3 text-foreground tracking-tight`,children:`Reset Password`}),(0,l.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Enter your email to receive a recovery link.`})]}),r&&(0,l.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:r}),(0,l.jsxs)(`form`,{className:`space-y-4 text-left max-w-[360px] mx-auto`,onSubmit:async e=>{e.preventDefault(),t(!0),i(null);let r=new FormData(e.currentTarget).get(`email`);try{await(0,s.sendPasswordResetEmail)(n.wt,r)}catch(e){console.error(e)}finally{i(`If an account exists, a password reset link has been sent. Please check your inbox (and spam folder).`);let e=d+1;f(e),c(e===1?60:120),t(!1)}},children:[(0,l.jsx)(n.r,{name:`email`,label:`Work Email`,type:`email`,placeholder:`name@company.com`,required:!0}),(0,l.jsx)(`div`,{className:`pt-2`,children:(0,l.jsx)(n.n,{type:`submit`,className:`w-full py-2.5 md:py-3 text-[14px] font-bold tracking-wide rounded-xl md:rounded-xl transition-all ${o>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:o>0,children:o>0?`Resend link in ${(e=>`${Math.floor(e/60)}:${(e%60).toString().padStart(2,`0`)}`)(o)}`:d>0?`Resend reset password link`:`Send Reset Link`})})]}),(0,l.jsx)(`div`,{className:`mt-6 pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:(0,l.jsxs)(u.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,l.jsx)(n.gt,{className:`w-4 h-4 mr-2`}),`Back to Sign In`]})})]})})}function A(){let{user:e,userRole:t}=m(),[r,i]=(0,a.useState)(!0),s=(0,u.useNavigate)(),{id:d}=(0,u.useParams)(),[f,p]=(0,a.useState)([]),[h,g]=(0,a.useState)(null),[_,v]=(0,a.useState)(!1),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(!1),C=d?f.find(e=>e.id===d)||null:f.length>0?f[0]:null,w=e=>{s(e?`/users/${e.id}`:`/users`)};(0,a.useEffect)(()=>{i(!0);let e=(0,o.onSnapshot)((0,o.collection)(n.Tt,`user_profiles`),e=>{let t=[];e.forEach(e=>{t.push({id:e.id,...e.data()})}),p(t),i(!1),!d&&t.length>0&&s(`/users/${t[0].id}`,{replace:!0})},e=>{console.error(`Error fetching users:`,e),i(!1)});return()=>e()},[d,s]);let T=f.find(t=>t.id===e?.uid),E=e=>e.id===T?.id?!1:e.role!==`admin`||!T?.createdAt?!0:e.createdAt?new Date(T.createdAt).getTime()<=new Date(e.createdAt).getTime():!1,D=async(e,r)=>{if(!(t!==`admin`||!E(e)))try{await(0,o.updateDoc)((0,o.doc)(n.Tt,`user_profiles`,e.id),{role:r?`admin`:null}),g({text:`User role updated successfully`,type:`success`}),setTimeout(()=>g(null),3e3)}catch(e){g({text:e.message,type:`error`}),setTimeout(()=>g(null),3e3)}},O=async(e,r)=>{if(!(t!==`admin`||!E(e)))try{await(0,o.updateDoc)((0,o.doc)(n.Tt,`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)}},k=async()=>{if(v(!1),!(!C||!E(C)||y===C.displayName))try{await(0,o.updateDoc)((0,o.doc)(n.Tt,`user_profiles`,C.id),{displayName:y}),g({text:`Name updated successfully`,type:`success`}),setTimeout(()=>g(null),3e3)}catch(e){g({text:e.message,type:`error`}),setTimeout(()=>g(null),3e3)}},A=async e=>{let t=e.target.files?.[0];if(!(!t||!C||!E(C))){if(t.size>2*1024*1024){g({text:`File too large.`,type:`error`});return}S(!0);try{let e=(0,c.ref)(n.Dt,`user_avatars/${C.id}/file.png`);await(0,c.uploadBytes)(e,t);let r=await(0,c.getDownloadURL)(e);await(0,o.updateDoc)((0,o.doc)(n.Tt,`user_profiles`,C.id),{avatar:r}),g({text:`Avatar successfully updated.`,type:`success`}),setTimeout(()=>g(null),3e3)}catch{g({text:`Failed to upload photo.`,type:`error`})}S(!1)}},[te,j]=(0,a.useState)(!1);return(0,a.useEffect)(()=>{let e;return r&&f.length===0?e=setTimeout(()=>j(!0),150):j(!1),()=>clearTimeout(e)},[r,f.length]),r&&f.length===0?te?(0,l.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,l.jsx)(n.M,{className:`w-8 h-8 animate-spin text-accent`})}):null:(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Users`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/users`]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 animate-in fade-in duration-500 pb-20`,children:[(0,l.jsx)(n.a,{children:h&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:`p-4 text-[14px] font-medium border ${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)]`} rounded-xl flex items-center gap-2`,children:[h.type===`success`&&(0,l.jsx)(n.nt,{className:`w-4 h-4 shrink-0`}),h.text]})}),(0,l.jsx)(`div`,{className:`flex justify-start`,children:(0,l.jsx)(ee,{})}),(0,l.jsx)(`div`,{className:`glass-panel rounded-3xl border border-[var(--panel-border)] shadow-sm`,children:f.length===0?(0,l.jsx)(`div`,{className:`p-8 text-center text-foreground/50 text-[14px]`,children:`No members found.`}):(0,l.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 min-h-[500px]`,children:[(0,l.jsxs)(`div`,{className:`md:col-span-1 border-r md:border-r-[var(--panel-border)] border-b md:border-b-0 border-[var(--panel-border)] flex flex-col hide-scrollbar bg-black/5 dark:bg-white/5 rounded-t-3xl md:rounded-tr-none md:rounded-l-3xl`,children:[(0,l.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,l.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-2`,children:f.map(e=>(0,l.jsxs)(`div`,{onClick:()=>w(e),className:`p-4 py-5 rounded-2xl border transition-all flex items-center gap-4 cursor-pointer ${C?.id===e.id?`bg-accent/10 border-accent/40 shadow-sm`:`glass-panel border-transparent hover:border-[var(--panel-border)]`} ${e.inactive?`opacity-50 grayscale`:``}`,children:[(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full overflow-hidden bg-accent/20 shrink-0 flex items-center justify-center border border-[var(--panel-border)]`,children:e.avatar||e.photoURL?(0,l.jsx)(`img`,{src:e.avatar||e.photoURL,alt:``,className:`w-full h-full object-cover`}):(0,l.jsx)(n.d,{className:`w-5 h-5 text-accent`})}),(0,l.jsxs)(`div`,{className:`flex flex-col truncate`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] truncate`,children:e.displayName||`No Name`}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/50 truncate font-mono mt-0.5`,children:e.email})]})]},e.id))})]}),(0,l.jsx)(`div`,{className:`md:col-span-2 flex flex-col p-6 md:p-10 relative`,children:C?(0,l.jsxs)(`div`,{className:`animate-in fade-in duration-300 w-full max-w-lg`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-6 md:gap-8 mb-10`,children:[(0,l.jsxs)(`div`,{className:`w-24 h-24 rounded-full glass-panel border-4 border-[var(--panel-border)] shadow-xl bg-accent/10 flex items-center justify-center relative overflow-hidden shrink-0 group`,children:[x?(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`}):C.avatar||C.photoURL?(0,l.jsx)(`img`,{src:C.avatar||C.photoURL,alt:`Avatar`,className:`w-full h-full object-cover`}):(0,l.jsx)(n.d,{className:`w-10 h-10 text-accent`}),!x&&E(C)&&(0,l.jsx)(`div`,{className:`absolute inset-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center z-10 backdrop-blur-md`,children:(0,l.jsxs)(`label`,{className:`flex flex-col items-center justify-center cursor-pointer p-2 hover:bg-white/20 transition-colors text-white rounded-full`,title:`Upload Photo`,children:[(0,l.jsx)(n.ut,{className:`w-5 h-5`}),(0,l.jsx)(`input`,{type:`file`,accept:`image/*`,onChange:A,className:`hidden`})]})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col flex-1 w-full relative`,children:[_?(0,l.jsx)(`input`,{autoFocus:!0,value:y,onChange:e=>b(e.target.value),onBlur:k,onKeyDown:e=>e.key===`Enter`&&k(),className:`text-2xl md:text-3xl font-extrabold mb-1 bg-transparent border-b-2 border-accent outline-none text-foreground w-full py-1`}):(0,l.jsx)(`h3`,{onDoubleClick:()=>{E(C)&&(b(C.displayName||``),v(!0))},className:`text-2xl md:text-3xl font-extrabold mb-1 select-none ${E(C)?`cursor-pointer hover:text-accent transition-colors`:``}`,title:E(C)?`Double-click to edit`:``,children:C.displayName||`No Name`}),(0,l.jsx)(`p`,{className:`text-[14px] font-mono text-foreground/50`,children:C.email}),!E(C)&&C.id!==T?.id&&(0,l.jsx)(`div`,{className:`mt-3 inline-block self-start px-3 py-1.5 rounded-lg bg-foreground/5 border border-[var(--panel-border)] text-[11px] font-bold text-foreground/50 tracking-wide uppercase`,children:`Privileged Admin Account`})]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,l.jsxs)(`div`,{className:`p-4 rounded-2xl glass-panel border border-[var(--panel-border)] flex items-center justify-between`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] text-foreground`,children:`Admin Access`}),(0,l.jsx)(`span`,{className:`text-[12px] text-foreground/50`,children:`Toggle system privileges`})]}),(0,l.jsx)(`button`,{type:`button`,disabled:!E(C),onClick:()=>D(C,C.role!==`admin`),className:`relative inline-flex h-7 w-12 items-center rounded-full transition-colors focus:outline-none shadow-inner ${C.role===`admin`?`bg-accent`:`bg-foreground/20`} ${E(C)?`cursor-pointer`:`opacity-50 cursor-not-allowed`}`,children:(0,l.jsx)(`span`,{className:`inline-block h-5 w-5 transform rounded-full bg-white transition-transform shadow-md ${C.role===`admin`?`translate-x-6`:`translate-x-1`}`})})]}),(0,l.jsxs)(`div`,{className:`p-4 rounded-2xl glass-panel border flex items-center justify-between ${C.inactive?`border-amber-500/30 bg-amber-500/5`:`border-red-500/20 bg-red-500/5`}`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] ${C.inactive?`text-amber-500`:`text-red-500`}`,children:C.inactive?`Reactivate User`:`Deactivate User`}),(0,l.jsx)(`span`,{className:`text-[12px] ${C.inactive?`text-amber-500/70`:`text-red-500/70`}`,children:`Block access to this app`})]}),(0,l.jsx)(`button`,{type:`button`,disabled:!E(C),onClick:()=>O(C,!C.inactive),className:`relative inline-flex h-7 w-12 items-center rounded-full transition-colors focus:outline-none shadow-inner ${C.inactive?`bg-amber-500`:`bg-red-500/20`} ${E(C)?`cursor-pointer`:`opacity-50 cursor-not-allowed`}`,children:(0,l.jsx)(`span`,{className:`inline-block h-5 w-5 transform rounded-full bg-white transition-transform shadow-md ${C.inactive?`translate-x-6`:`translate-x-1`}`})})]})]})]}):(0,l.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center opacity-30 pointer-events-none`,children:[(0,l.jsx)(n.u,{className:`w-12 h-12 mb-4`}),(0,l.jsx)(`p`,{className:`font-bold tracking-widest uppercase text-[12px]`,children:`Select a User`})]})})]})})]})]})}function te({isOpen:e,title:t,message:r,confirmText:i=`Delete`,cancelText:a=`Cancel`,onConfirm:o,onCancel:s,isProcessing:c=!1,disableConfirm:u=!1}){return(0,l.jsx)(n.a,{children:e&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!c&&s(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`w-full max-w-[400px] p-6 rounded-3xl glass-panel border border-[var(--panel-border)] shadow-2xl relative z-10 text-center`,children:(0,l.jsxs)(`div`,{className:`w-full flex flex-col items-center`,children:[(0,l.jsx)(`h3`,{className:`text-xl font-extrabold mb-2 text-foreground tracking-tight`,children:t}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 leading-relaxed mb-6`,children:r}),(0,l.jsxs)(`div`,{className:`flex items-center gap-3 w-full`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:s,disabled:c,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:a}),(0,l.jsx)(n.n,{onClick:o,disabled:c||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:c?(0,l.jsx)(n.M,{className:`w-5 h-5 animate-spin mx-auto`}):i})]})]})})]})})}var j=[`pages`,`forms`,`drive`,`users`,`theme`,`submissions`,`requests`,`settings`,`profile`,`support`],M={pages:`Pages`,forms:`Forms`,drive:`Drive`,users:`Users`,theme:`Theme`,submissions:`Submissions`,requests:`Requests`,settings:`Settings`,profile:`Profile`,support:`Request Support`},N=new Set([`home`]),P=new Set([`settings`]);function F(){let[e,t]=(0,a.useState)(`menu`),[r,i]=(0,a.useState)({}),[s,c]=(0,a.useState)({}),[u,d]=(0,a.useState)(g),[f,p]=(0,a.useState)(v),[m,h]=(0,a.useState)(!1),[y,b]=(0,a.useState)(null),[x,S]=(0,a.useState)(!1);(0,a.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.collection)(n.Tt,`sys_pages`),e=>{let t={};e.forEach(e=>{let n=e.data();t[e.id]={id:e.id,title:n.pageName||n.title||e.id,path:n.route||(e.id===`home`?`/`:`/`+e.id),type:`public`,isSystem:[`home`,`templates`,`contact`,`setup`].includes(e.id)}}),t.setup||={id:`setup`,title:`Setup`,path:`/setup`,type:`public`,isSystem:!0},t.templates||={id:`templates`,title:`Templates`,path:`/templates`,type:`public`,isSystem:!0},t.contact||={id:`contact`,title:`Contact`,path:`/contact`,type:`public`,isSystem:!0},i(t)}),t=(0,o.onSnapshot)((0,o.collection)(n.Tt,`sys_tabs`),e=>{let t={};e.forEach(e=>{let n=e.data();t[e.id]={id:e.id,title:n.pageName||n.tabName||n.title||M[e.id]||e.id,path:n.route||`/`+e.id,type:n.pageType||`admin`,isSystem:j.includes(e.id)}}),j.forEach(e=>{t[e]||(t[e]={id:e,title:M[e]||e,path:`/`+e,type:`admin`,isSystem:!0})}),c(t)}),r=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`page_order`),e=>{d(e.exists()?_(e.data().order||[]):g)}),a=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`tab_order`),e=>{p(e.exists()?_(e.data().order||[]):v)});return()=>{e(),t(),r(),a()}},[]);let C=async(e,t)=>{if((t?P:N).has(e))return;let i=t?f:u,a=t?`tab_order`:`page_order`,c=i.filter(e=>(t?s:r)[e.id]||(t?j.includes(e.id):[`home`,`contact`].includes(e.id))),l=c.some(t=>t.id===e)?c.map(t=>t.id===e?{...t,hidden:!t.hidden}:t):[...c,{id:e,hidden:!0}];await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,a),{order:l})},w=(e,t)=>{e.isSystem||b({info:e,isTab:t})},T=async()=>{if(!y)return;S(!0);let e=y.isTab?`sys_tabs`:`sys_pages`,t=y.isTab?`tab_order`:`page_order`,r=y.isTab?f:u;try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,e,y.info.id));let i=r.filter(e=>e.id!==y.info.id);await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,t),{order:i})}catch(e){console.error(`Delete failed`,e)}S(!1),b(null)},E=async(e,t,i)=>{let a=e?f:u,c=e?s:r,l=e?`tab_order`:`page_order`,d=a.filter(t=>c[t.id]||(e?j.includes(t.id):[`home`,`contact`].includes(t.id)));Object.keys(c).forEach(e=>{d.some(t=>t.id===e)||d.push({id:e,hidden:!1})});let p=d.findIndex(e=>e.id===t);if(p===-1)return;let m=+(!e&&d[0]?.id===`home`),h=i===`up`?Math.max(m,p-1):Math.min(d.length-1,p+1);if(p===h)return;let g=[...d],[_]=g.splice(p,1);g.splice(h,0,_),await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,l),{order:g})},D=async()=>{if(!m){h(!0);try{let e=new Set(g.map(e=>e.id)),t=new Set(v.map(e=>e.id)),r=u.filter(t=>!e.has(t.id)),i=f.filter(e=>!t.has(e.id)),a=[...r.map(e=>({...e,hidden:!1})),...g],s=[...i.map(e=>({...e,hidden:!1})),...v],c=(0,o.writeBatch)(n.Tt);c.set((0,o.doc)(n.Tt,`sys_configs`,`page_order`),{order:a}),c.set((0,o.doc)(n.Tt,`sys_configs`,`tab_order`),{order:s}),await c.commit()}finally{setTimeout(()=>h(!1),600)}}},O=e=>{let t=e?f:u,n=e?s:r,i=t.filter(t=>n[t.id]||(e?j.includes(t.id):[`home`,`contact`].includes(t.id))),a=new Set(i.map(e=>e.id)),o=Object.keys(n).filter(e=>!a.has(e)).map(e=>({id:e,hidden:!1})),c=[...i,...o];return e||(c=c.filter(e=>e.id!==`home`)),c};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Settings`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/settings`]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 animate-in fade-in duration-500`,children:[(0,l.jsx)(`div`,{className:`flex justify-start`,children:(0,l.jsx)(ee,{})}),(0,l.jsxs)(`div`,{className:`glass-panel rounded-3xl border border-[var(--panel-border)] shadow-sm grid grid-cols-1 md:grid-cols-3 min-h-[500px]`,children:[(0,l.jsxs)(`div`,{className:`md:col-span-1 border-r md:border-r-[var(--panel-border)] border-b md:border-b-0 border-[var(--panel-border)] flex flex-col bg-black/5 dark:bg-white/5 rounded-t-3xl md:rounded-tr-none md:rounded-l-3xl`,children:[(0,l.jsx)(`div`,{className:`p-6 pb-4 font-bold text-[13px] text-foreground/40 uppercase tracking-widest`,children:`Configuration`}),(0,l.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-4 pb-4 space-y-1`,children:[(0,l.jsxs)(`button`,{onClick:()=>t(`menu`),className:`w-full p-3 rounded-xl transition-all flex items-center gap-3 cursor-pointer ${e===`menu`?`bg-accent/10 text-accent font-bold`:`bg-transparent text-foreground/70 hover:bg-foreground/5 hover:text-foreground font-medium`}`,children:[(0,l.jsx)(n.O,{className:`w-4 h-4 shrink-0`}),(0,l.jsx)(`span`,{className:`text-[14px]`,children:`Menu Settings`})]}),(0,l.jsxs)(`button`,{onClick:()=>t(`tabs`),className:`w-full p-3 rounded-xl transition-all flex items-center gap-3 cursor-pointer ${e===`tabs`?`bg-accent/10 text-accent font-bold`:`bg-transparent text-foreground/70 hover:bg-foreground/5 hover:text-foreground font-medium`}`,children:[(0,l.jsx)(n.pt,{className:`w-4 h-4 shrink-0`}),(0,l.jsx)(`span`,{className:`text-[14px]`,children:`Tabs Settings`})]})]})]}),(0,l.jsx)(`div`,{className:`md:col-span-2 flex flex-col p-6 md:p-10`,children:(0,l.jsxs)(`div`,{className:`animate-in fade-in duration-300 w-full`,children:[(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-8`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col`,children:[(0,l.jsx)(`h3`,{className:`text-2xl md:text-3xl font-extrabold text-foreground tracking-tighter mb-2`,children:e===`menu`?`Menu Settings`:`Dashboard Tabs`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/60 max-w-xl`,children:e===`menu`?`Reorder or hide public menu items. Changes take effect instantly for all visitors.`:`Manage visibility and order of all internal dashboard tabs.`})]}),(0,l.jsx)(`button`,{onClick:D,disabled:m,title:`Reset order and visibility to defaults`,className:`p-3 h-fit bg-foreground/5 hover:bg-foreground/10 text-foreground/70 active:scale-95 disabled:opacity-50 disabled:pointer-events-none rounded-xl transition-all font-bold text-[13px] flex items-center justify-center border border-transparent hover:border-[var(--panel-border)] shadow-sm shrink-0`,children:m?(0,l.jsx)(n.M,{className:`w-5 h-5 text-foreground/50 animate-spin`}):(0,l.jsx)(n.x,{className:`w-5 h-5 text-foreground/50`})})]}),(e=>{let t=e?s:r,i=e?P:N,a=O(e);return(0,l.jsx)(`div`,{className:`flex flex-col gap-3`,children:a.map((r,o)=>{let s=t[r.id],c=s?.title||M[r.id]||r.id,u=s?.path||`/`+r.id,d=s?.isSystem??j.includes(r.id),f=i.has(r.id),p=o===0,m=o===a.length-1;return(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-4 glass-panel border border-[var(--panel-border)] rounded-2xl transition-all duration-200 ${r.hidden?`opacity-40`:`opacity-100`}`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col items-center w-6`,children:[(0,l.jsx)(`button`,{disabled:p,onClick:()=>E(e,r.id,`up`),className:`text-foreground/40 hover:text-accent disabled:opacity-20`,children:(0,l.jsx)(n.it,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{disabled:m,onClick:()=>E(e,r.id,`down`),className:`text-foreground/40 hover:text-accent disabled:opacity-20 -mt-1`,children:(0,l.jsx)(n.st,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col`,children:[(0,l.jsx)(`span`,{className:`font-bold text-foreground text-[14px]`,children:c}),(0,l.jsx)(`span`,{className:`text-[12px] font-mono text-foreground/50`,children:u})]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-3`,children:[!f&&(0,l.jsx)(`button`,{onClick:()=>C(r.id,e),title:r.hidden?`Show this page`:`Hide this page`,className:`p-2 rounded-xl transition-colors ${r.hidden?`hover:bg-foreground/5 text-foreground/40`:`hover:bg-accent/10 text-accent`}`,children:r.hidden?(0,l.jsx)(n.q,{className:`w-4 h-4`}):(0,l.jsx)(n.K,{className:`w-4 h-4`})}),s&&!d&&(0,l.jsx)(`button`,{onClick:()=>w(s,e),className:`p-2 rounded-xl hover:bg-red-500/10 text-foreground/40 hover:text-red-500 transition-colors`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})})]})]},r.id)})})})(e===`tabs`)]})})]})]})]}),(0,l.jsx)(te,{isOpen:!!y,onCancel:()=>b(null),onConfirm:T,title:`Delete Item`,message:`Are you sure you want to delete "${y?.info?.title??``}"? This cannot be undone.`,confirmText:`Delete`,isProcessing:x})]})}function I(){let[e,t]=(0,a.useState)([]),[r,i]=(0,a.useState)(!0),[s,c]=(0,a.useState)(null),[u,d]=(0,a.useState)(!1),[f,p]=(0,a.useState)(null);(0,a.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,`user_submissions`),(0,o.orderBy)(`submittedAt`,`desc`)),async e=>{let r=[];for(let t of e.docs){let e=t.data(),i=``;if(e.uid&&e.uid!==`guest`)try{let t=await(0,o.getDoc)((0,o.doc)(n.Tt,`user_profiles`,e.uid));if(t.exists()){let n=t.data();n.avatar&&(i=n.avatar),n.name&&!e.name&&(e.name=n.name),n.email&&!e.email&&(e.email=n.email)}}catch(e){console.error(`Failed to fetch avatar`,e)}r.push({...e,id:t.id,avatarUrl:i})}t(r),i(!1)},e=>{console.error(`Error fetching submissions:`,e),i(!1)});return()=>e()},[]);let m=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)},h=e=>{c(t=>t===e?null:e)},g=async(e,t=!1)=>{p(e);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,`user_submissions`,e),{isArchived:!t}),!t&&s===e&&c(null)}catch(e){console.error(`Failed to archive/unarchive`,e)}p(null)},_=e.filter(e=>!e.isArchived),v=e.filter(e=>e.isArchived);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Form Submissions`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/submissions`]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-4 flex-1 min-h-[500px]`,children:[(0,l.jsx)(`div`,{className:`flex justify-start`,children:(0,l.jsx)(ee,{})}),(0,l.jsxs)(`div`,{className:`w-full flex-1 flex flex-col glass-panel rounded-3xl p-6 md:p-10 relative overflow-hidden border border-[var(--panel-border)] shadow-2xl bg-[var(--panel-bg)]`,children:[(0,l.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,l.jsx)(`div`,{className:`relative z-10 flex-1 flex flex-col`,children:r?(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[500px]`,children:(0,l.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`})}):e.length===0?(0,l.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center p-8`,children:[(0,l.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,l.jsx)(n.D,{className:`w-6 h-6 outline-none`})}),(0,l.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground mb-2`,children:`No Submissions`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/50 font-medium max-w-md`,children:`Try submitting a form on the public layout to see it appear here.`})]}):(0,l.jsxs)(`div`,{className:`flex flex-col gap-3 pb-8`,children:[_.length===0&&(0,l.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,l.jsx)(`p`,{className:`text-[14px] font-bold text-foreground/50`,children:`All submissions have been archived.`})}),(0,l.jsx)(n.a,{children:_.map((e,t)=>{let r=s===e.id;return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:t*.05},className:`glass-panel border border-[var(--panel-border)] rounded-2xl flex flex-col overflow-hidden hover:border-accent/40 transition-all duration-300`,children:[(0,l.jsxs)(`div`,{role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&h(e.id)},onClick:()=>h(e.id),className:`w-full flex items-center justify-between p-4 md:px-6 hover:bg-foreground/[0.02] transition-colors text-left cursor-pointer`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-4 flex-1 min-w-0`,children:[(0,l.jsx)(`div`,{className:`relative shrink-0`,children:(0,l.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-accent/10 text-accent flex items-center justify-center font-bold border border-accent/20 shadow-sm`,children:(0,l.jsx)(n.k,{className:`w-4 h-4`})})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 justify-center`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] md:text-[15px] text-foreground truncate`,children:e.name||e.full_name||`Anonymous Submission`}),e.formId&&(0,l.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:e.formId.replace(/_/g,` `)})]}),(0,l.jsx)(`span`,{className:`text-[13px] text-foreground/50 truncate flex items-center gap-1.5 font-medium mt-0.5`,children:e.email||e.contactEmail||`No email provided`})]})]}),(0,l.jsxs)(`div`,{className:`hidden md:flex items-center gap-4 ml-6 shrink-0`,children:[(0,l.jsx)(`div`,{className:`text-[12px] font-medium text-foreground/40`,children:m(e.submittedAt)}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),g(e.id,!1)},disabled:f===e.id,className:`p-1.5 rounded-lg text-foreground/30 hover:text-orange-500 hover:bg-orange-500/10 transition-colors`,title:`Archive Submission`,children:f===e.id?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(n._t,{className:`w-4 h-4`})}),(0,l.jsx)(`div`,{className:`p-1.5 rounded-xl glass-panel transition-transform ${r?`rotate-180 bg-foreground/5`:``}`,children:(0,l.jsx)(n.st,{className:`w-4 h-4 text-foreground/50`})})]})]}),(0,l.jsx)(n.a,{children:r&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-4 md:p-6 pt-0 mt-2 border-t border-[var(--panel-border)]/30`,children:[(0,l.jsx)(`div`,{className:`md:hidden text-[12px] font-medium text-foreground/40 w-fit mb-4`,children:m(e.submittedAt)}),Object.entries(e).filter(([e])=>![`id`,`uid`,`submittedAt`,`avatarUrl`,`name`,`full_name`,`email`,`contactEmail`].includes(e)&&!e.toLowerCase().startsWith(`submitter`)&&e.toLowerCase()!==`formid`).map(([e,t])=>(0,l.jsxs)(`div`,{className:`bg-foreground/[0.02] rounded-2xl p-5 border border-[var(--panel-border)] relative mb-3`,children:[(0,l.jsx)(`div`,{className:`flex items-center gap-2 mb-3 text-foreground/60 w-full justify-between`,children:(0,l.jsx)(`div`,{className:`flex items-center gap-2 text-accent`,children:(0,l.jsx)(`span`,{className:`text-[12px] font-bold uppercase tracking-widest text-accent`,children:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())})})}),(0,l.jsx)(`p`,{className:`text-[14px] md:text-[15px] text-foreground/80 leading-relaxed whitespace-pre-wrap font-medium`,children:typeof t==`boolean`?t?`Yes`:`No`:e.toLowerCase()===`budget`&&t?`$${t}`:String(t||`No data provided`)})]},e))]})})})]},e.id)})}),v.length>0&&(0,l.jsxs)(`div`,{className:`mt-6 pt-4 border-t border-[var(--panel-border)]/30`,children:[(0,l.jsx)(`div`,{className:`flex justify-center`,children:(0,l.jsxs)(`button`,{onClick:()=>d(!u),className:`flex items-center gap-2 text-[11px] font-bold text-foreground/40 hover:text-foreground/70 transition-colors py-2 uppercase tracking-widest outline-none`,children:[u?`Hide`:`View`,` `,v.length,` Archived Submission`,v.length===1?``:`s`,(0,l.jsx)(n.st,{className:`w-3.5 h-3.5 transition-transform duration-300 ${u?`rotate-180`:``}`})]})}),(0,l.jsx)(n.a,{children:u&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4`,children:(0,l.jsx)(`div`,{className:`flex flex-col gap-3`,children:v.map((e,t)=>{let r=s===e.id;return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:t*.05},className:`glass-panel border border-[var(--panel-border)] rounded-2xl flex flex-col overflow-hidden opacity-50 grayscale hover:opacity-100 hover:grayscale-0 hover:border-accent/40 transition-all duration-300`,children:[(0,l.jsxs)(`div`,{role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&h(e.id)},onClick:()=>h(e.id),className:`w-full flex items-center justify-between p-4 md:px-6 hover:bg-foreground/[0.02] transition-colors text-left cursor-pointer`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-4 flex-1 min-w-0`,children:[(0,l.jsx)(`div`,{className:`relative shrink-0 grayscale`,children:(0,l.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-accent/10 text-accent flex items-center justify-center font-bold border border-accent/20 shadow-sm`,children:(0,l.jsx)(n.k,{className:`w-4 h-4`})})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 justify-center`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] md:text-[15px] text-foreground truncate`,children:e.name||e.full_name||`Anonymous Submission`}),e.formId&&(0,l.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:e.formId.replace(/_/g,` `)})]}),(0,l.jsx)(`span`,{className:`text-[13px] text-foreground/50 truncate flex items-center gap-1.5 font-medium mt-0.5`,children:e.email||e.contactEmail||`No email provided`})]})]}),(0,l.jsxs)(`div`,{className:`hidden md:flex items-center gap-6 ml-6 shrink-0`,children:[(0,l.jsx)(`div`,{className:`text-[12px] font-medium text-foreground/40`,children:m(e.submittedAt)}),(0,l.jsx)(`div`,{className:`p-2 rounded-xl glass-panel transition-transform ${r?`rotate-180 bg-foreground/5`:``}`,children:(0,l.jsx)(n.st,{className:`w-4 h-4 text-foreground/50`})})]})]}),(0,l.jsx)(n.a,{children:r&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-4 md:p-6 pt-0 mt-2 border-t border-[var(--panel-border)]/30`,children:[(0,l.jsx)(`div`,{className:`md:hidden text-[12px] font-medium text-foreground/40 w-fit mb-4`,children:m(e.submittedAt)}),Object.entries(e).filter(([e])=>![`id`,`uid`,`submittedAt`,`avatarUrl`,`name`,`full_name`,`email`,`contactEmail`,`isArchived`].includes(e)&&!e.toLowerCase().startsWith(`submitter`)&&e.toLowerCase()!==`formid`).map(([e,t])=>(0,l.jsxs)(`div`,{className:`bg-foreground/[0.02] rounded-2xl p-5 border border-[var(--panel-border)] relative mb-3`,children:[(0,l.jsx)(`div`,{className:`flex items-center gap-2 mb-3 text-foreground/60 w-full justify-between`,children:(0,l.jsx)(`div`,{className:`flex items-center gap-2 text-accent`,children:(0,l.jsx)(`span`,{className:`text-[12px] font-bold uppercase tracking-widest text-accent`,children:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())})})}),(0,l.jsx)(`p`,{className:`text-[14px] md:text-[15px] text-foreground/80 leading-relaxed whitespace-pre-wrap font-medium`,children:typeof t==`boolean`?t?`Yes`:`No`:e.toLowerCase()===`budget`&&t?`$${t}`:String(t||`No data provided`)})]},e)),(0,l.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,l.jsxs)(`button`,{onClick:()=>g(e.id,e.isArchived),disabled:f===e.id,className:`flex items-center gap-2 px-4 py-2.5 rounded-xl text-[13px] font-bold text-foreground/70 hover:text-emerald-500 bg-foreground/5 hover:bg-emerald-500/10 transition-colors border border-transparent shadow-sm`,children:[f===e.id?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(n.vt,{className:`w-4 h-4`}),`Unarchive Submission`]})})]})})})]},e.id)})})})})]})]})})]})]})]})}function L(){let[e,t]=(0,a.useState)([]),[r,i]=(0,a.useState)(!0),[s,c]=(0,a.useState)(null),[d,f]=(0,a.useState)(!1),[p,m]=(0,a.useState)(null);(0,a.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,`user_requests`),(0,o.orderBy)(`submittedAt`,`desc`)),async e=>{let r=[];for(let t of e.docs){let e=t.data(),i=``;if(e.uid&&e.uid!==`guest`)try{let t=await(0,o.getDoc)((0,o.doc)(n.Tt,`user_profiles`,e.uid));if(t.exists()){let n=t.data();(n.avatar||n.photoURL)&&(i=n.avatar||n.photoURL),n.displayName&&!e.name&&(e.name=n.displayName),n.email&&!e.email&&(e.email=n.email),n.email&&!e.contactEmail&&(e.contactEmail=n.email)}}catch(e){console.error(`Failed to fetch avatar`,e)}r.push({...e,id:t.id,avatarUrl:i})}t(r),i(!1)},e=>{console.error(`Error fetching requests:`,e),i(!1)});return()=>e()},[]);let h=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)},g=e=>{c(t=>t===e?null:e)},_=async(e,t=!1)=>{m(e);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,`user_requests`,e),{isArchived:!t}),!t&&s===e&&c(null)}catch(e){console.error(`Failed to archive/unarchive`,e)}m(null)},v=e.filter(e=>!e.isArchived),y=e.filter(e=>e.isArchived);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`User Requests`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/requests`]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-4 flex-1 min-h-[500px]`,children:[(0,l.jsx)(`div`,{className:`flex justify-start`,children:(0,l.jsx)(ee,{})}),(0,l.jsxs)(`div`,{className:`w-full flex-1 flex flex-col glass-panel rounded-3xl p-6 md:p-10 relative overflow-hidden border border-[var(--panel-border)] shadow-2xl bg-[var(--panel-bg)]`,children:[(0,l.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,l.jsx)(`div`,{className:`relative z-10 flex-1 flex flex-col`,children:r?(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[500px]`,children:(0,l.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`})}):e.length===0?(0,l.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center p-8`,children:[(0,l.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,l.jsx)(n.tt,{className:`w-6 h-6 outline-none`})}),(0,l.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground mb-2`,children:`No User Requests`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/50 font-medium max-w-md`,children:`User support tickets will appear here once submitted.`})]}):(0,l.jsxs)(`div`,{className:`flex flex-col gap-3 pb-8`,children:[v.length===0&&(0,l.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,l.jsx)(`p`,{className:`text-[14px] font-bold text-foreground/50`,children:`All requests have been archived.`})}),(0,l.jsx)(n.a,{children:v.map((e,t)=>{let r=s===e.id;return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:t*.05},className:`glass-panel border border-[var(--panel-border)] rounded-2xl flex flex-col overflow-hidden hover:border-accent/40 transition-all duration-300`,children:[(0,l.jsxs)(`div`,{role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&g(e.id)},onClick:()=>g(e.id),className:`w-full flex items-center justify-between p-4 md:px-6 hover:bg-foreground/[0.02] transition-colors text-left cursor-pointer`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-4 flex-1 min-w-0`,children:[(0,l.jsx)(`div`,{className:`relative shrink-0`,children:e.avatarUrl||e.submitterAvatar?(0,l.jsx)(`img`,{src:e.avatarUrl||e.submitterAvatar,alt:e.submitterName||e.name,className:`w-10 h-10 rounded-full object-cover border border-[var(--panel-border)] shadow-sm`}):(0,l.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-accent/10 text-accent flex items-center justify-center font-bold border border-accent/20 shadow-sm uppercase`,children:(e.submitterName||e.name||e.contactEmail||e.email||`U`)[0]})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[e.uid===`guest`?(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] md:text-[15px] text-foreground truncate`,children:e.name||`Anonymous User`}),e.formId&&(0,l.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:e.formId.replace(/_/g,` `)})]}):(0,l.jsxs)(u.Link,{to:`/users/${e.uid}`,onClick:e=>e.stopPropagation(),className:`w-fit font-bold text-[14px] md:text-[15px] text-foreground truncate hover:text-accent flex items-center gap-2`,children:[e.submitterName||e.name||`Anonymous User`,e.formId&&(0,l.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:e.formId.replace(/_/g,` `)})]}),(0,l.jsxs)(`span`,{className:`text-[13px] text-foreground/50 truncate flex items-center gap-1.5 font-medium mt-0.5`,children:[(0,l.jsx)(n.k,{className:`w-3.5 h-3.5`}),` `,e.contactEmail||e.email||`No email provided`]})]})]}),(0,l.jsxs)(`div`,{className:`hidden md:flex items-center gap-4 ml-6 shrink-0`,children:[(0,l.jsx)(`div`,{className:`text-[12px] font-medium text-foreground/40`,children:h(e.submittedAt)}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),_(e.id,!1)},disabled:p===e.id,className:`p-1.5 rounded-lg text-foreground/30 hover:text-orange-500 hover:bg-orange-500/10 transition-colors`,title:`Archive Request`,children:p===e.id?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(n._t,{className:`w-4 h-4`})}),(0,l.jsx)(`div`,{className:`p-1.5 rounded-xl glass-panel transition-transform ${r?`rotate-180 bg-foreground/5`:``}`,children:(0,l.jsx)(n.st,{className:`w-4 h-4 text-foreground/50`})})]})]}),(0,l.jsx)(n.a,{children:r&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-4 md:p-6 pt-0 mt-2 border-t border-[var(--panel-border)]/30`,children:[(0,l.jsx)(`div`,{className:`md:hidden text-[12px] font-medium text-foreground/40 w-fit mb-4`,children:h(e.submittedAt)}),e.topic&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mb-4 text-[13px] text-foreground/70 bg-foreground/5 px-4 py-2.5 rounded-xl w-fit border border-[var(--panel-border)]`,children:[(0,l.jsx)(n.rt,{className:`w-4 h-4 text-accent`}),(0,l.jsx)(`span`,{className:`font-medium text-accent`,children:`Topic:`}),(0,l.jsx)(`span`,{className:`font-bold`,children:e.topic})]}),Object.entries(e).filter(([e])=>![`id`,`uid`,`submittedAt`,`avatarUrl`,`name`,`full_name`,`email`,`contactEmail`,`topic`].includes(e)&&!e.toLowerCase().startsWith(`submitter`)&&e.toLowerCase()!==`formid`).map(([e,t])=>(0,l.jsxs)(`div`,{className:`bg-foreground/[0.02] rounded-2xl p-5 border border-[var(--panel-border)] relative mb-3`,children:[(0,l.jsx)(`div`,{className:`flex items-center gap-2 mb-3 text-foreground/60 w-full justify-between`,children:(0,l.jsx)(`div`,{className:`flex items-center gap-2 text-accent`,children:(0,l.jsx)(`span`,{className:`text-[12px] font-bold uppercase tracking-widest text-accent`,children:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())})})}),(0,l.jsx)(`p`,{className:`text-[14px] md:text-[15px] text-foreground/80 leading-relaxed whitespace-pre-wrap font-medium`,children:typeof t==`boolean`?t?`Yes`:`No`:e.toLowerCase()===`budget`&&t?`$${t}`:String(t||`No data provided`)})]},e))]})})})]},e.id)})}),y.length>0&&(0,l.jsxs)(`div`,{className:`mt-6 pt-4 border-t border-[var(--panel-border)]/30`,children:[(0,l.jsx)(`div`,{className:`flex justify-center`,children:(0,l.jsxs)(`button`,{onClick:()=>f(!d),className:`flex items-center gap-2 text-[11px] font-bold text-foreground/40 hover:text-foreground/70 transition-colors py-2 uppercase tracking-widest outline-none`,children:[d?`Hide`:`View`,` `,y.length,` Archived Request`,y.length===1?``:`s`,(0,l.jsx)(n.st,{className:`w-3.5 h-3.5 transition-transform duration-300 ${d?`rotate-180`:``}`})]})}),(0,l.jsx)(n.a,{children:d&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4`,children:(0,l.jsx)(`div`,{className:`flex flex-col gap-3`,children:y.map((e,t)=>{let r=s===e.id;return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:t*.05},className:`glass-panel border border-[var(--panel-border)] rounded-2xl flex flex-col overflow-hidden opacity-50 grayscale hover:opacity-100 hover:grayscale-0 hover:border-accent/40 transition-all duration-300`,children:[(0,l.jsxs)(`div`,{role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&g(e.id)},onClick:()=>g(e.id),className:`w-full flex items-center justify-between p-4 md:px-6 hover:bg-foreground/[0.02] transition-colors text-left cursor-pointer`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-4 flex-1 min-w-0`,children:[(0,l.jsx)(`div`,{className:`relative shrink-0 grayscale`,children:e.avatarUrl||e.submitterAvatar?(0,l.jsx)(`img`,{src:e.avatarUrl||e.submitterAvatar,alt:e.submitterName||e.name,className:`w-10 h-10 rounded-full object-cover border border-[var(--panel-border)] shadow-sm`}):(0,l.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-accent/10 text-accent flex items-center justify-center font-bold border border-accent/20 shadow-sm uppercase`,children:(e.submitterName||e.name||e.contactEmail||e.email||`U`)[0]})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[e.uid===`guest`?(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] md:text-[15px] text-foreground truncate`,children:e.name||`Anonymous User`}),e.formId&&(0,l.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:e.formId.replace(/_/g,` `)})]}):(0,l.jsxs)(`div`,{className:`w-fit font-bold text-[14px] md:text-[15px] text-foreground truncate flex items-center gap-2`,children:[e.submitterName||e.name||`Anonymous User`,e.formId&&(0,l.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:e.formId.replace(/_/g,` `)})]}),(0,l.jsxs)(`span`,{className:`text-[13px] text-foreground/50 truncate flex items-center gap-1.5 font-medium mt-0.5`,children:[(0,l.jsx)(n.k,{className:`w-3.5 h-3.5`}),` `,e.contactEmail||e.email||`No email provided`]})]})]}),(0,l.jsxs)(`div`,{className:`hidden md:flex items-center gap-6 ml-6 shrink-0`,children:[(0,l.jsx)(`div`,{className:`text-[12px] font-medium text-foreground/40`,children:h(e.submittedAt)}),(0,l.jsx)(`div`,{className:`p-2 rounded-xl glass-panel transition-transform ${r?`rotate-180 bg-foreground/5`:``}`,children:(0,l.jsx)(n.st,{className:`w-4 h-4 text-foreground/50`})})]})]}),(0,l.jsx)(n.a,{children:r&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-4 md:p-6 pt-0 mt-2 border-t border-[var(--panel-border)]/30`,children:[(0,l.jsx)(`div`,{className:`md:hidden text-[12px] font-medium text-foreground/40 w-fit mb-4`,children:h(e.submittedAt)}),e.topic&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mb-4 text-[13px] text-foreground/70 bg-foreground/5 px-4 py-2.5 rounded-xl w-fit border border-[var(--panel-border)]`,children:[(0,l.jsx)(n.rt,{className:`w-4 h-4 text-accent`}),(0,l.jsx)(`span`,{className:`font-medium text-accent`,children:`Topic:`}),(0,l.jsx)(`span`,{className:`font-bold`,children:e.topic})]}),Object.entries(e).filter(([e])=>![`id`,`uid`,`submittedAt`,`avatarUrl`,`name`,`full_name`,`email`,`contactEmail`,`topic`,`isArchived`].includes(e)&&!e.toLowerCase().startsWith(`submitter`)&&e.toLowerCase()!==`formid`).map(([e,t])=>(0,l.jsxs)(`div`,{className:`bg-foreground/[0.02] rounded-2xl p-5 border border-[var(--panel-border)] relative mb-3`,children:[(0,l.jsx)(`div`,{className:`flex items-center gap-2 mb-3 text-foreground/60 w-full justify-between`,children:(0,l.jsx)(`div`,{className:`flex items-center gap-2 text-accent`,children:(0,l.jsx)(`span`,{className:`text-[12px] font-bold uppercase tracking-widest text-accent`,children:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())})})}),(0,l.jsx)(`p`,{className:`text-[14px] md:text-[15px] text-foreground/80 leading-relaxed whitespace-pre-wrap font-medium`,children:typeof t==`boolean`?t?`Yes`:`No`:e.toLowerCase()===`budget`&&t?`$${t}`:String(t||`No data provided`)})]},e)),(0,l.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,l.jsxs)(`button`,{onClick:()=>_(e.id,e.isArchived),disabled:p===e.id,className:`flex items-center gap-2 px-4 py-2.5 rounded-xl text-[13px] font-bold text-foreground/70 hover:text-emerald-500 bg-foreground/5 hover:bg-emerald-500/10 transition-colors border border-transparent shadow-sm`,children:[p===e.id?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(n.vt,{className:`w-4 h-4`}),`Unarchive Request`]})})]})})})]},e.id)})})})})]})]})})]})]})]})}function R(){let{user:e,userRole:t}=m(),[r,i]=(0,a.useState)([]),[s,f]=(0,a.useState)(!1),p=(0,u.useNavigate)(),{"*":h}=(0,u.useParams)(),g=h?h.split(`/`).filter(Boolean):[],_=g[0]||`private`,v=null,y=null;_===`users`?(v=g[1]||null,y=g[2]||null):y=g[1]||null;let b={public:`pub_`,shared:`mem_`,private:`user_`,admin:`admin_`,users:`users_`},x={pub_:`public`,mem_:`shared`,user_:`private`,admin_:`admin`,users_:`users`},S=b[_]||`user_`,C=e=>{p(`/drive/${x[e]}`)},[w,T]=(0,a.useState)([]);(0,a.useEffect)(()=>{S===`users_`&&t===`admin`&&w.length===0&&(0,o.getDocs)((0,o.collection)(n.Tt,`user_profiles`)).then(e=>{T(e.docs.map(e=>({id:e.id,...e.data()})))})},[S,t,w.length]);let[E,D]=(0,a.useState)(!1),[O,k]=(0,a.useState)(null),[A,j]=(0,a.useState)(``),[M,N]=(0,a.useState)(`user_`),[P,F]=(0,a.useState)(!1),[I,L]=(0,a.useState)(!1),[R,z]=(0,a.useState)(!1),B=(0,a.useRef)(null),V=e=>{e.preventDefault(),e.stopPropagation(),z(!0)},ne=e=>{e.preventDefault(),e.stopPropagation(),z(!1)},H=e=>{if(e.preventDefault(),e.stopPropagation(),z(!1),e.dataTransfer.files&&e.dataTransfer.files[0]){let t=e.dataTransfer.files[0];k(t),j(t.name),N(S),F(!0)}},U=y&&r.find(e=>e._id===y)||null,W=e=>{le(!0),p(e?S===`users_`&&v?`/drive/users/${v}/${e._id}`:`/drive/${x[S]}/${e._id}`:S===`users_`&&v?`/drive/users/${v}`:`/drive/${x[S]}`)},[G,K]=(0,a.useState)(null),[re,ie]=(0,a.useState)(!1),[q,J]=(0,a.useState)(null),[Y,ae]=(0,a.useState)(!1),[oe,se]=(0,a.useState)(null),[ce,le]=(0,a.useState)(!0),[ue,de]=(0,a.useState)({}),[fe,X]=(0,a.useState)(!1);(0,a.useEffect)(()=>(U||q||G||P||fe?document.body.style.overflow=`hidden`:document.body.style.overflow=``,()=>{document.body.style.overflow=``}),[U,q,G,P,fe]),(0,a.useEffect)(()=>{if(!s&&y&&!r.some(e=>e._id===y)){X(!0);let e=setTimeout(()=>{X(!1),p(S===`users_`&&v?`/drive/users/${v}`:`/drive/${x[S]}`)},2500);return()=>clearTimeout(e)}else X(!1)},[s,y,r,S,p,v]),(0,a.useEffect)(()=>{if(!e)return;f(!0);let r=(t===`admin`?[`pub_`,`mem_`,`user_`,`admin_`]:[`pub_`,`mem_`,`user_`]).map(r=>{let a;return a=r===`user_`&&t!==`admin`?(0,o.query)((0,o.collection)(n.Tt,`${r}files`),(0,o.where)(`uid`,`==`,e.uid)):(0,o.query)((0,o.collection)(n.Tt,`${r}files`),(0,o.orderBy)(`createdAt`,`desc`)),(0,o.onSnapshot)(a,e=>{let t=(e.docs||[]).map(e=>({_id:e.id,accessPrefix:r,...e.data()}));i(e=>[...e.filter(e=>e.accessPrefix!==r),...t].sort((e,t)=>{let n=e.createdAt?.toMillis?e.createdAt.toMillis():0;return(t.createdAt?.toMillis?t.createdAt.toMillis():0)-n})),f(!1)},e=>{console.warn(`Error listening to ${r}files:`,e)})});return()=>r.forEach(e=>e())},[e?.uid,t]);let pe=e=>{if(e.target.files&&e.target.files[0]){let t=e.target.files[0];k(t),j(t.name)}},me=e=>{if(e.preventDefault(),e.dataTransfer.files&&e.dataTransfer.files[0]){let t=e.dataTransfer.files[0];k(t),j(t.name)}},Z=async r=>{if(r.preventDefault(),!(!O||!A)){D(!0);try{let r=(0,c.ref)(n.Dt,`${M}files/${`${Date.now()}_${O.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,c.uploadBytes)(r,O,{customMetadata:{ownerId:e.uid}});let i=await(0,c.getDownloadURL)(r);await(0,o.addDoc)((0,o.collection)(n.Tt,`${M}files`),{fileName:A,fileType:O.type||`unknown`,fileSize:O.size,downloadURL:i,uid:e.uid,uploaderEmail:e.email||`user`,uploaderRole:t||`user`,createdAt:(0,o.serverTimestamp)()}),F(!1),k(null),j(``),C(M)}catch(e){console.error(e),alert(`Upload failed: ${e.message}`)}D(!1)}},he=async()=>{if(q){ae(!0);try{try{await(0,c.deleteObject)((0,c.ref)(n.Dt,q.url))}catch(e){console.warn(`Storage item missing:`,e)}await(0,o.deleteDoc)((0,o.doc)(n.Tt,`${q.prefix}files`,q.id)),i(e=>e.filter(e=>e._id!==q.id)),J(null)}catch(e){alert(e.message)}ae(!1)}},ge=async()=>{if(!G||!G.name.trim()){K(null);return}let e=r.find(e=>e._id===G.id);if(e&&e.fileName===G.name.trim()){K(null);return}ie(!0);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,`${G.prefix}files`,G.id),{fileName:G.name.trim()}),i(e=>e.map(e=>e._id===G.id?{...e,fileName:G.name.trim()}:e)),K(null)}catch(e){console.error(`Rename failed:`,e)}ie(!1)},_e=(e,t)=>{navigator.clipboard.writeText(e),se(t),setTimeout(()=>se(null),2e3)},ve=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},Q=n=>e?n.accessPrefix===`mem_`?n.uid===e.uid?!0:t===`admin`?n.uploaderRole!==`admin`:!1:n.accessPrefix===`admin_`?n.uid===e.uid:n.accessPrefix===`pub_`?t===`admin`:n.uid===e.uid||t===`admin`:!1,ye=(e,t,r=!1)=>{let i=r?`w-16 h-16`:`w-10 h-10`,a=r?`w-8 h-8`:`w-5 h-5`;return e.startsWith(`image/`)?r?(0,l.jsx)(`img`,{src:t,alt:`preview`,className:`w-full h-full object-contain rounded-lg`}):(0,l.jsx)(`div`,{className:`${i} bg-cover bg-center rounded-lg`,style:{backgroundImage:`url(${t})`}}):e.includes(`video`)||e.includes(`audio`)?(0,l.jsx)(`div`,{className:`${i} flex items-center justify-center bg-purple-500/10 text-purple-500 rounded-lg`,children:(0,l.jsx)(n.l,{className:a})}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,l.jsx)(`div`,{className:`${i} flex items-center justify-center bg-blue-500/10 text-blue-500 rounded-lg`,children:(0,l.jsx)(n.G,{className:a})}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,l.jsx)(`div`,{className:`${i} flex items-center justify-center bg-yellow-500/10 text-yellow-500 rounded-lg`,children:(0,l.jsx)(n._t,{className:a})}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,l.jsx)(`div`,{className:`${i} flex items-center justify-center bg-emerald-500/10 text-emerald-500 rounded-lg`,children:(0,l.jsx)(n.Q,{className:a})}):(0,l.jsx)(`div`,{className:`${i} flex items-center justify-center bg-foreground/5 text-foreground/40 rounded-lg`,children:(0,l.jsx)(n.W,{className:a})})},be=[{id:`user_`,label:`Private`,icon:n.j,description:`This is a private folder availbale to all users in your app. Each user can see their own files. Admins can see all everyone's files here.`},{id:`mem_`,label:`Shared`,icon:n.u,description:`This is a shared folder that all signed-in users can see. Every user can upload files here and view other member's files. However, editing and deletion are strictly restricted to the original creator of the file.`},{id:`pub_`,label:`Public`,icon:n.U,description:`This admin-only folder is for assets like logos, banners, or favicons. Files here are view-only for everyone; only admins can upload or delete them.`},{id:`admin_`,label:`Admin Shared`,icon:n.v,description:`This is a shared folder for app administrators. Admins can view everything here, but they can only edit or delete files that they themselves uploaded.`},{id:`users_`,label:`User Uploads`,icon:n.X,description:`View all underlying private user uploads securely. Select a user to explore their files.`}].filter(e=>t===`admin`?!0:e.id===`user_`||e.id===`mem_`),xe=[];xe=S===`users_`?r.filter(e=>e.accessPrefix===`user_`&&e.uid===v):S===`user_`?r.filter(t=>t.accessPrefix===`user_`&&t.uid===e?.uid):r.filter(e=>e.accessPrefix===S);let Se=be.find(e=>e.id===S);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 flex flex-col pt-12 min-h-screen relative overflow-visible`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Drive`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/drive`]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,onDragOver:V,onDragLeave:ne,onDrop:H,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(`div`,{className:`flex flex-row glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl min-h-[600px] bg-background`,children:[(0,l.jsxs)(`div`,{className:`w-[280px] border-r border-[var(--panel-border)] bg-foreground/[0.01] p-4 flex flex-col shrink-0 overflow-y-auto hide-scrollbar`,children:[(0,l.jsx)(`div`,{className:`text-[11px] font-extrabold text-foreground/40 uppercase tracking-widest pl-4 mb-4 mt-2`,children:`Locations`}),(0,l.jsx)(`div`,{className:`flex flex-col gap-2`,children:be.map(e=>(0,l.jsxs)(`button`,{onClick:()=>C(e.id),className:`w-full flex items-center gap-3 px-4 py-3.5 rounded-2xl transition-all font-bold text-[14px] text-left ${S===e.id?`bg-accent/15 text-accent shadow-sm border border-accent/20`:`text-foreground/70 hover:bg-foreground/5 hover:text-foreground border border-transparent`}`,children:[(0,l.jsx)(e.icon,{className:`w-5 h-5 ${S===e.id?`text-accent`:`text-foreground/40`}`}),e.label]},e.id))})]}),(0,l.jsxs)(`div`,{className:`flex-1 flex flex-col relative w-full h-full min-w-0`,children:[(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex items-start justify-between gap-6 shrink-0 border-b border-[var(--panel-border)]/50 bg-background/50`,children:[(0,l.jsxs)(`div`,{className:`flex-1 max-w-xl`,children:[(0,l.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground tracking-tight flex items-center gap-3`,children:Se?.label}),(0,l.jsx)(`p`,{className:`text-[13px] mt-3 text-foreground/60 leading-relaxed font-medium`,children:Se?.description})]}),S!==`users_`&&(0,l.jsxs)(n.n,{onClick:()=>{N(S),F(!0)},className:`flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-bold shadow-md hover:shadow-lg transition-all glow-hover border-transparent !border-0 outline-none ring-0`,children:[(0,l.jsx)(n.C,{className:`w-4 h-4`}),` Add File Here`]})]}),(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[300px]`,children:[s&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm rounded-b-[2rem]`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),S===`users_`&&!v?(0,l.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 pb-20`,children:[w.map(e=>(0,l.jsxs)(`div`,{onClick:()=>p(`/drive/users/${e.id}`),className:`flex items-center gap-4 bg-background border border-[var(--panel-border)] p-5 rounded-2xl cursor-pointer hover:border-accent/50 hover:shadow-md transition-all group`,children:[(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-foreground/5 flex items-center justify-center shrink-0 border border-[var(--panel-border)]`,children:e.photoURL?(0,l.jsx)(`img`,{src:e.photoURL,alt:`avatar`,className:`w-full h-full rounded-full object-cover`}):(0,l.jsx)(n.d,{className:`w-5 h-5 text-foreground/40`})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,l.jsxs)(`span`,{className:`font-bold text-foreground truncate group-hover:text-accent transition-colors text-[14px]`,children:[e.firstName,` `,e.lastName]}),(0,l.jsx)(`span`,{className:`text-[12px] font-medium text-foreground/50 truncate mt-0.5`,children:e.email})]})]},e.id)),w.length===0&&(0,l.jsxs)(`div`,{className:`col-span-full py-12 flex flex-col items-center justify-center text-center`,children:[(0,l.jsx)(n.d,{className:`w-12 h-12 text-foreground/10 mb-4`}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold text-foreground/50`,children:`No users found`})]})]}):xe.length>0?(0,l.jsx)(`div`,{className:`grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 pb-20`,children:xe.map(e=>(0,l.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 hover:shadow-md h-[190px] relative`,children:[(0,l.jsxs)(`div`,{className:`absolute top-2 right-2 flex flex-col gap-1 opacity-0 group-hover:opacity-100 transition-opacity z-10 bg-background/90 backdrop-blur-md rounded-lg p-1 border border-[var(--panel-border)] shadow-xl`,children:[(0,l.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,l.jsx)(n.Y,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),_e(e.accessPrefix===`pub_`?e.downloadURL:`${window.location.origin}/drive/${x[e.accessPrefix]}/${e._id}`,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:oe===e._id?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),Q(e)&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),K({id:e._id,name:e.fileName,prefix:e.accessPrefix})},className:`p-1.5 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-purple-500 transition-colors`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),J({id:e._id,url:e.downloadURL,name:e.fileName,prefix:e.accessPrefix})},className:`p-1.5 hover:bg-red-500/10 rounded-md text-foreground/60 hover:text-red-500 transition-colors`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})})]})]}),(0,l.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 rounded-t-[calc(1rem-1px)]`,onClick:()=>W(e),children:e.fileType.startsWith(`image/`)?(0,l.jsxs)(l.Fragment,{children:[ue[e._id]!==!1&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-accent/5 backdrop-blur-sm z-0`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})}),(0,l.jsx)(`img`,{src:e.downloadURL,alt:``,className:`absolute inset-0 w-full h-full object-cover transition-opacity duration-300 group-hover:scale-105 ${ue[e._id]===!1?`opacity-100`:`opacity-0`}`,onLoad:()=>de(t=>({...t,[e._id]:!1})),onError:()=>de(t=>({...t,[e._id]:!1}))})]}):ye(e.fileType,e.downloadURL,!0)}),(0,l.jsxs)(`div`,{className:`p-3 flex flex-col justify-center flex-1 min-w-0`,onClick:()=>!G&&W(e),children:[G?.id===e._id?(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,value:G.name,onChange:e=>K({...G,name:e.target.value}),onBlur:()=>ge(),onKeyDown:e=>{e.key===`Enter`&&ge(),e.key===`Escape`&&K(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,l.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,l.jsx)(`span`,{className:`text-[11px] text-foreground/40 font-bold uppercase tracking-wider mt-1 select-none`,children:ve(e.fileSize)})]})]},e._id))}):!s&&(0,l.jsxs)(`div`,{onDragOver:e=>e.preventDefault(),onDrop:e=>{if(e.preventDefault(),e.dataTransfer.files&&e.dataTransfer.files[0]){let t=e.dataTransfer.files[0];k(t),j(t.name),N(S),F(!0)}},onClick:()=>{N(S),F(!0)},className:`absolute inset-0 m-6 flex flex-col items-center justify-center text-foreground/40 transition-colors cursor-pointer group`,children:[(0,l.jsx)(`p`,{className:`text-[20px] font-bold text-foreground/50 group-hover:text-foreground/70 transition-colors`,children:`Folder is empty`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium mt-1 text-foreground/40 group-hover:text-foreground/60 transition-colors`,children:`Click here or drag and drop a file to upload`})]})]})]})]})]}),(0,l.jsx)(n.a,{children:P&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!E&&F(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`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,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 border-b border-[var(--panel-border)]/50 relative z-20`,children:[(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsxs)(`button`,{onClick:()=>L(!I),className:`flex items-center gap-2 group outline-none`,children:[(0,l.jsx)(`span`,{className:`text-[16px] font-extrabold text-foreground tracking-tight`,children:`Upload to`}),(0,l.jsx)(`span`,{className:`bg-accent/10 group-hover:bg-accent/20 text-accent px-2 py-1 rounded-md text-[13px] font-bold transition-colors flex items-center gap-1 shadow-sm`,children:be.find(e=>e.id===M)?.label})]}),(0,l.jsx)(n.a,{children:I&&(0,l.jsxs)(a.default.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-[90]`,onClick:()=>L(!1)}),(0,l.jsx)(n.i.div,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},exit:{opacity:0,y:-5},className:`absolute top-full left-0 mt-3 w-48 bg-background border border-[var(--panel-border)] rounded-xl shadow-2xl py-1 overflow-hidden z-[100]`,children:be.map(e=>(0,l.jsxs)(`button`,{type:`button`,onClick:()=>{N(e.id),L(!1)},className:`w-full text-left px-4 py-3 hover:bg-foreground/5 text-[13px] font-bold text-foreground flex items-center gap-3 transition-colors outline-none`,children:[(0,l.jsx)(e.icon,{className:`w-4 h-4 text-foreground/50`}),e.label]},e.id))})]})})]}),(0,l.jsx)(`button`,{onClick:()=>!E&&F(!1),className:`text-foreground/40 hover:text-foreground transition-colors`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})})]}),O?(0,l.jsxs)(`form`,{onSubmit:Z,className:`p-6 flex flex-col gap-6 relative z-10 rounded-b-[2rem]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-4 bg-foreground/[0.03] p-4 rounded-2xl border border-[var(--panel-border)] shadow-sm`,children:[ye(O.type,URL.createObjectURL(O)),(0,l.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-[13px] font-bold text-foreground truncate`,children:O.name}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold uppercase tracking-wider mt-1`,children:ve(O.size)})]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>!E&&k(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,l.jsx)(n.h,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,l.jsx)(`label`,{className:`text-[11px] font-bold text-foreground/50 uppercase tracking-widest pl-1`,children:`Edit File Name`}),(0,l.jsx)(`input`,{type:`text`,required:!0,value:A,onChange:e=>j(e.target.value),disabled:E,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 shadow-sm`})]}),(0,l.jsx)(`div`,{className:`flex justify-end pt-4 mt-2 border-t border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:E,className:`w-full py-4 rounded-xl text-[14px] font-bold shadow-lg`,children:E?`Uploading to Drive...`:`Save to ${be.find(e=>e.id===M)?.label}`})})]}):(0,l.jsxs)(`div`,{onDragOver:e=>e.preventDefault(),onDrop:me,className:`p-12 flex flex-col items-center justify-center rounded-b-[2rem]`,children:[(0,l.jsx)(`div`,{className:`w-20 h-20 rounded-full bg-foreground/5 flex items-center justify-center mb-5 border-2 border-dashed border-[var(--panel-border)]`,children:(0,l.jsx)(n.$,{className:`w-8 h-8 text-foreground/40`})}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold text-foreground mb-1`,children:`Drag and drop file here`}),(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/50 font-medium mb-8`,children:`or click to browse local files`}),(0,l.jsx)(`input`,{type:`file`,ref:B,onChange:pe,className:`hidden`}),(0,l.jsx)(n.n,{onClick:()=>B.current?.click(),className:`px-8 py-3 rounded-full font-bold shadow-md btn-primary transition-colors`,children:`Browse Files`})]})]})]})}),typeof window<`u`&&(0,d.createPortal)((0,l.jsx)(n.a,{children:U&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,l.jsx)(n.i.div,{onClick:()=>W(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(`button`,{onClick:()=>W(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`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-[var(--panel-border)]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 bg-background/80 backdrop-blur-md border-b border-[var(--panel-border)] shrink-0 shadow-sm z-20`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:U.fileName}),(0,l.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[U.fileType,` • `,ve(U.fileSize),U.accessPrefix===`mem_`&&(U.uploaderEmail||U.uid)&&` • From: ${U.uploaderEmail||U.uid}`]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:()=>_e(U.accessPrefix===`pub_`?U.downloadURL:`${window.location.origin}/drive/${x[U.accessPrefix]}/${U._id}`,U._id),className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 transition-colors rounded-xl shadow-sm hover:text-emerald-500`,title:`Copy Link`,children:oe===U._id?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),Q(U)&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:()=>{W(null),K({id:U._id,name:U.fileName,prefix:U.accessPrefix})},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-purple-500 transition-colors rounded-xl shadow-sm`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{W(null),J({id:U._id,url:U.downloadURL,name:U.fileName,prefix:U.accessPrefix})},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})})]}),(0,l.jsx)(`a`,{href:U.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>W(null),children:(0,l.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[ce&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none fade-in`,children:(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-background/80 backdrop-blur-md shadow-xl flex items-center justify-center border border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})})}),U.fileType.startsWith(`image/`)?(0,l.jsx)(`img`,{onLoad:()=>le(!1),src:U.downloadURL,alt:U.fileName,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 ${ce?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):U.fileType.startsWith(`video/`)?(0,l.jsx)(`video`,{onLoadedData:()=>le(!1),src:U.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 ${ce?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):U.fileType===`application/pdf`?(0,l.jsx)(`iframe`,{onLoad:()=>le(!1),src:U.downloadURL,className:`w-full h-full border-none bg-white rounded-lg relative z-10 transition-opacity duration-500 ${ce?`opacity-0`:`opacity-100`}`,title:`PDF Preview`}):(0,l.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center text-foreground/40 text-center relative z-10`,onClick:e=>{e.stopPropagation(),le(!1)},children:[(0,l.jsx)(n.W,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,l.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,l.jsx)(`span`,{className:`text-[14px] mt-2 text-foreground/60 font-medium max-w-xs`,children:`This file format cannot be previewed. Please download it instead.`})]})]})})]})]})}),document.body),(0,l.jsx)(n.a,{children:fe&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/90 backdrop-blur-xl`}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:`relative z-10 w-full max-w-sm flex flex-col items-center pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-red-500/20 bg-background/80 p-8 text-center`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-red-500/10 flex items-center justify-center mb-6`,children:(0,l.jsx)(n.c,{className:`w-8 h-8 text-red-500`})}),(0,l.jsx)(`h3`,{className:`text-xl font-bold text-foreground mb-2`,children:`Access Denied`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/60 font-medium leading-relaxed`,children:`You don't have access to this file, or it may have been deleted.`}),(0,l.jsx)(`div`,{className:`w-5 h-5 border-2 border-accent/20 border-t-accent rounded-full animate-spin mt-6`})]})]})}),(0,l.jsx)(te,{isOpen:!!q,title:`Confirm Deletion`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:q?.name}),` This action is permanent.`]}),onConfirm:he,onCancel:()=>J(null),isProcessing:Y,confirmText:`Yes, Delete`}),(0,l.jsx)(n.a,{children:R&&(0,l.jsx)(n.i.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,l.jsxs)(n.i.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.9,opacity:0},className:`w-full max-w-lg aspect-video bg-background/80 border-2 border-dashed border-accent p-12 rounded-[40px] shadow-2xl flex flex-col items-center justify-center gap-6 relative`,children:[(0,l.jsx)(`div`,{className:`absolute inset-0 bg-accent/5 rounded-[38px] animate-pulse`}),(0,l.jsx)(`div`,{className:`w-20 h-20 rounded-full bg-accent/10 flex items-center justify-center text-accent shadow-[0_0_40px_rgba(var(--accent-rgb),0.2)]`,children:(0,l.jsx)(n.$,{className:`w-10 h-10 animate-bounce`})}),(0,l.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-2 relative z-10`,children:[(0,l.jsx)(`span`,{className:`text-[24px] font-extrabold text-foreground tracking-tight`,children:`Drop files to upload`}),(0,l.jsx)(`span`,{className:`text-[14px] font-medium text-foreground/50`,children:`Your files will be staged for review`})]})]})})})]})}function z(){let e=[{id:`form`,title:`Inline Form`,description:`A static, embedded contact form designed directly into the page layout.`,icon:n.P,path:`/templates/inline_form`},{id:`popup`,title:`Modal Popup Form`,description:`A centralized popup contact form that visually blurs the background context.`,icon:n.yt,path:`/templates/popup_form`},{id:`confirmation`,title:`Action Confirmation`,description:`A classic confirmation dialog styled for decisive user actions.`,icon:n.lt,path:`/templates/confirmation`},{id:`board`,title:`Board View`,description:`A modern, drag-and-drop styled Kanban board aesthetic for task management.`,icon:n.z,path:`/templates/board`},{id:`table`,title:`Data Table`,description:`A clean, column-based data table optimized for large datasets and bulk actions.`,icon:n.g,path:`/templates/table`},{id:`calendar`,title:`Calendar View`,description:`A structured monthly calendar grid for scheduling and date-based resource planning.`,icon:n.dt,path:`/templates/calendar`}];return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-10 text-center`,children:[(0,l.jsx)(`h1`,{className:`w-fit mx-auto inline-block text-4xl md:text-5xl lg:text-[4.8rem] leading-[1.1] font-extrabold tracking-tight mb-4 text-gradient animate-float`,children:`Premium Templates`}),(0,l.jsx)(`p`,{className:`text-foreground/60 text-lg font-medium max-w-2xl mx-auto`,children:`Explore our collection of fully functional, beautifully designed boilerplate components.`})]}),(0,l.jsxs)(`div`,{className:`w-full max-w-4xl mx-auto flex flex-col gap-4 relative`,children:[(0,l.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,t)=>{let r=e.icon;return(0,l.jsx)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:t*.05},children:(0,l.jsxs)(u.Link,{to:e.path,className:`flex items-center gap-6 w-full p-4 md:px-6 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,l.jsx)(`div`,{className:`w-12 h-12 rounded-xl bg-accent/10 flex items-center justify-center text-accent shrink-0 border border-accent/20 group-hover:scale-105 transition-transform`,children:(0,l.jsx)(r,{className:`w-5 h-5`})}),(0,l.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,l.jsx)(`h3`,{className:`text-[15px] font-bold text-foreground truncate`,children:e.title}),(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/50 truncate font-medium`,children:e.description})]}),(0,l.jsxs)(`div`,{className:`hidden md:flex items-center gap-2 text-[13px] font-bold px-5 py-2.5 rounded-xl btn-primary shrink-0 transition-transform shadow-lg group-hover:-translate-y-0.5`,children:[`View `,(0,l.jsx)(`span`,{className:`font-black leading-none ml-0.5`,children:`→`})]})]})},e.id)})]})]})}function B(){let[e,t]=(0,a.useState)({favoriteService:``,satisfactionRating:``,detailedThoughts:``}),[r,i]=(0,a.useState)(`idle`);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12`,children:[(0,l.jsx)(`div`,{className:`w-full max-w-5xl mx-auto mb-6`,children:(0,l.jsxs)(u.Link,{to:`/templates`,className:`inline-flex items-center gap-2 text-foreground/50 hover:text-accent transition-colors font-medium text-[14px]`,children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` Back to Templates`]})}),(0,l.jsx)(`div`,{className:`w-full max-w-5xl mx-auto mt-6`,children:(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`w-full max-w-[500px] p-6 sm:p-8 lg:p-10 rounded-3xl md:rounded-3xl glass-panel relative glow-hover shadow-[0_8px_32px_rgba(0,0,0,0.08)] z-10 mx-auto`,children:[(0,l.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,l.jsx)(`div`,{className:`relative z-10 w-full`,children:r===`success`?(0,l.jsxs)(n.i.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,l.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,l.jsx)(n.nt,{className:`w-8 h-8`})}),(0,l.jsx)(`h4`,{className:`text-lg font-bold text-foreground mb-2`,children:`Simulation Complete!`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/60 leading-relaxed`,children:`Your test data was sent successfully. Log in as an admin and check the Submissions tab!`})]}):r===`loading`?(0,l.jsxs)(n.i.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,l.jsx)(`div`,{className:`w-10 h-10 border-4 border-accent border-r-transparent rounded-full animate-spin mb-4`}),(0,l.jsx)(`h4`,{className:`text-lg font-bold text-foreground tracking-tight`,children:`Processing`}),(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/50 mt-1`,children:`Simulating submission...`})]}):(0,l.jsxs)(n.i.div,{initial:{opacity:0},animate:{opacity:1},children:[(0,l.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,l.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight break-words`,children:`Inline Form Template`}),(0,l.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,l.jsxs)(`form`,{onSubmit:async r=>{r.preventDefault(),i(`loading`);try{let r=n.wt.currentUser?.uid||`guest`;await(0,o.addDoc)((0,o.collection)(n.Tt,`user_submissions`),{uid:r,...e,type:`template_simulation`,submittedAt:(0,o.serverTimestamp)()}),i(`success`),setTimeout(()=>{i(`idle`),t({favoriteService:``,satisfactionRating:``,detailedThoughts:``})},3e3)}catch{i(`error`)}},className:`space-y-4 w-full`,children:[(0,l.jsx)(n.r,{label:`Favorite Service`,placeholder:`e.g. Design Consulting`,value:e.favoriteService,onChange:n=>t({...e,favoriteService:n.target.value})}),(0,l.jsx)(n.r,{label:`Satisfaction Rating`,type:`number`,placeholder:`1 to 10`,value:e.satisfactionRating,onChange:n=>t({...e,satisfactionRating:n.target.value})}),(0,l.jsxs)(`div`,{className:`flex flex-col w-full relative`,children:[(0,l.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Detailed Thoughts`}),(0,l.jsx)(`textarea`,{rows:3,placeholder:`Type something here...`,value:e.detailedThoughts,onChange:n=>t({...e,detailedThoughts:n.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,l.jsx)(`div`,{className:`pt-2`,children:(0,l.jsx)(n.n,{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 V(){let[e,t]=(0,a.useState)(!1),[r,i]=(0,a.useState)({concept:``,featureRequest:``,notes:``}),[s,c]=(0,a.useState)(`idle`);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Popup Form`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/popup_form`]})]}),(0,l.jsx)(`div`,{className:`flex justify-between items-center mb-6 border-b border-[var(--panel-border)] pb-6 relative z-20`,children:(0,l.jsxs)(u.Link,{to:`/templates`,className:`px-5 py-2 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold hover:bg-foreground/5 transition-all flex items-center gap-2 text-foreground/70`,children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` Go Back`]})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative flex flex-col w-full min-h-[150px] p-6 lg:p-10`,children:[(0,l.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,l.jsx)(`div`,{className:`flex h-full w-full justify-end items-start relative z-10`,children:(0,l.jsxs)(n.n,{onClick:()=>t(!0),className:`px-6 py-2.5 text-[14px] font-bold rounded-xl shadow-lg flex items-center justify-center gap-2 btn-primary transition-all hover:-translate-y-1`,children:[(0,l.jsx)(n.C,{className:`w-4 h-4`}),` Open Form`]})})]}),(0,l.jsx)(n.a,{children:e&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-xl cursor-pointer`,onClick:()=>t(!1)}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`w-full max-w-[500px] p-6 sm:p-8 lg:p-10 rounded-3xl md:rounded-3xl glass-panel relative glow-hover shadow-[0_8px_32px_rgba(0,0,0,0.08)] z-10 mx-4 max-h-[95vh] overflow-y-auto no-scrollbar`,children:[(0,l.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,l.jsxs)(`div`,{className:`relative z-10 w-full`,children:[(0,l.jsx)(`button`,{onClick:()=>t(!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,l.jsx)(n.c,{className:`w-5 h-5`})}),s===`success`?(0,l.jsxs)(n.i.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,l.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,l.jsx)(n.nt,{className:`w-8 h-8`})}),(0,l.jsx)(`h4`,{className:`text-xl font-bold text-foreground mb-2`,children:`Simulation Complete!`}),(0,l.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 check the Submissions tab!`})]}):s===`loading`?(0,l.jsxs)(n.i.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,l.jsx)(`div`,{className:`w-10 h-10 border-4 border-accent border-r-transparent rounded-full animate-spin mb-4`}),(0,l.jsx)(`h4`,{className:`text-lg font-bold text-foreground tracking-tight`,children:`Processing`}),(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/50 mt-1`,children:`Simulating submission...`})]}):(0,l.jsxs)(n.i.div,{initial:{opacity:0},animate:{opacity:1},children:[(0,l.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,l.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight break-words`,children:`Popup Template`}),(0,l.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,l.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),c(`loading`);try{let e=n.wt.currentUser?.uid||`guest`;await(0,o.addDoc)((0,o.collection)(n.Tt,`user_submissions`),{uid:e,...r,type:`template_simulation`,submittedAt:(0,o.serverTimestamp)()}),c(`success`),setTimeout(()=>{c(`idle`),i({concept:``,featureRequest:``,notes:``}),t(!1)},3e3)}catch{c(`error`)}},className:`space-y-4 w-full`,children:[(0,l.jsx)(n.r,{label:`Concept Name`,placeholder:`e.g. Project Apollo`,value:r.concept,onChange:e=>i({...r,concept:e.target.value})}),(0,l.jsx)(n.r,{label:`Feature Request`,placeholder:`e.g. Real-time sync`,value:r.featureRequest,onChange:e=>i({...r,featureRequest:e.target.value})}),(0,l.jsxs)(`div`,{className:`flex flex-col w-full relative`,children:[(0,l.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Simulated Notes`}),(0,l.jsx)(`textarea`,{rows:3,placeholder:`Type something here...`,value:r.notes,onChange:e=>i({...r,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,l.jsx)(`div`,{className:`pt-2`,children:(0,l.jsx)(n.n,{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 ne(){let[e,t]=(0,a.useState)(void 0);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 items-center`,children:[(0,l.jsx)(`div`,{className:`w-full max-w-5xl mb-8`,children:(0,l.jsxs)(u.Link,{to:`/templates`,className:`inline-flex items-center gap-2 text-foreground/50 hover:text-accent transition-colors font-medium text-[14px]`,children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` Back to Templates`]})}),(0,l.jsxs)(`div`,{className:`w-full max-w-5xl mx-auto mt-2 glass-panel rounded-3xl border border-[var(--panel-border)] p-6 md:p-10 relative overflow-hidden shadow-2xl`,children:[(0,l.jsx)(`div`,{className:`flex items-center justify-between mb-8 pb-6 border-b border-[var(--panel-border)]/50`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h3`,{className:`text-2xl font-extrabold text-foreground tracking-tight`,children:`System Files`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/50 mt-1`,children:`Review and manage core application assets.`})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,l.jsxs)(`div`,{className:`glass-panel p-5 rounded-2xl border border-[var(--panel-border)]/50 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-4 w-full sm:w-auto`,children:[(0,l.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-red-500/10 flex items-center justify-center text-red-500 shrink-0`,children:(0,l.jsx)(n.p,{className:`w-5 h-5`})}),(0,l.jsxs)(`div`,{className:`min-w-0 pr-2`,children:[(0,l.jsx)(`h4`,{className:`font-bold text-[14px] sm:text-[15px] text-foreground truncate`,children:`Critical Configuration File`}),(0,l.jsx)(`p`,{className:`text-[12px] sm:text-[13px] text-foreground/50 font-medium mt-0.5 truncate`,children:`Size: 4.2 MB • Modified 2 hours ago`})]})]}),(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>t(null),className:`w-full sm:w-auto shrink-0 flex items-center justify-center px-6 py-3 sm:py-2.5 text-[13px] font-bold rounded-xl text-red-500 hover:bg-red-500/10 hover:border-red-500/20 bg-red-500/5 sm:bg-transparent`,children:`Delete File`})]}),(0,l.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 opacity-50 pointer-events-none mt-2`,children:[1,2].map(e=>(0,l.jsxs)(`div`,{className:`glass-panel p-5 rounded-2xl border border-[var(--panel-border)]/20 flex items-center gap-4`,children:[(0,l.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-foreground/5 shrink-0`}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-2 flex-1`,children:[(0,l.jsx)(`div`,{className:`w-32 h-3 rounded-full bg-foreground/10`}),(0,l.jsx)(`div`,{className:`w-20 h-2 rounded-full bg-foreground/5`})]})]},e))})]})]}),(0,l.jsx)(n.a,{children:e!==void 0&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-xl`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`w-full max-w-[400px] p-6 rounded-3xl glass-panel border border-[var(--panel-border)] shadow-2xl relative z-10 text-center`,children:(0,l.jsx)(n.a,{mode:`wait`,children:e===null?(0,l.jsxs)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full flex flex-col items-center`,children:[(0,l.jsx)(`h3`,{className:`text-xl font-extrabold mb-2 text-foreground tracking-tight`,children:`Confirm Deletion`}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 leading-relaxed mb-6`,children:`Are you entirely sure you wish to delete this configuration? This action is permanent.`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-3 w-full`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>t(!1),className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:`Cancel`}),(0,l.jsx)(n.n,{onClick:()=>t(!0),className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl bg-red-500 hover:bg-red-600 border-none text-white shadow-xl hover:shadow-red-500/20 glow-hover`,children:`Yes, Delete`})]})]},`confirm`):e===!0?(0,l.jsxs)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full flex flex-col items-center py-2`,children:[(0,l.jsxs)(`h3`,{className:`text-xl font-extrabold mb-1 text-green-500 tracking-tight flex items-center gap-2`,children:[(0,l.jsx)(n.ct,{className:`w-5 h-5`}),` Verified`]}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mb-6`,children:`Action successfully executed.`}),(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>t(void 0),className:`px-6 py-2 rounded-xl text-[13px] font-bold`,children:`Close Panel`})]},`success`):(0,l.jsxs)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full flex flex-col items-center py-2`,children:[(0,l.jsxs)(`h3`,{className:`text-xl font-extrabold mb-1 text-foreground/80 tracking-tight flex items-center gap-2`,children:[(0,l.jsx)(n.c,{className:`w-5 h-5`}),` Aborted`]}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mb-6`,children:`Cancellation securely caught.`}),(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>t(void 0),className:`px-6 py-2 rounded-xl text-[13px] font-bold`,children:`Close Panel`})]},`error`)})})]})})]})}var H=(e,t=[])=>{let n=`${(e.pageName||e.pageId||`custom_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`).split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}Content`;return`Create file: src/your-ai-workflow-firebase-os/microcomponents/${n}.tsx
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-DYteiM-1.cjs`),t=require(`./theme.config-0Lvwt5Bo.cjs`),n=require(`./ContactPopup-5mXFBqTs.cjs`),r=require(`./contactForm.config-CXyq-EbM.cjs`),i=require(`./supportForm.config-haLod4rv.cjs`);let a=require(`react`);a=e.i(a,1);let o=require(`firebase/firestore`),s=require(`firebase/auth`),c=require(`firebase/storage`),l=require(`react/jsx-runtime`),u=require(`react-router-dom`),d=require(`react-dom`);var f=(0,a.createContext)({user:null,userRole:null,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 p({children:e}){let t=n.Ct(),[r,i]=(0,a.useState)(null),[c,u]=(0,a.useState)(null),[d,p]=(0,a.useState)(!1),[m,h]=(0,a.useState)(!0),[g,_]=(0,a.useState)(!1),v=a.default.useRef(null),y=a.default.useRef(null);return(0,a.useEffect)(()=>{let e;if(!n.wt){h(!1),_(!0);return}let r=(0,s.onAuthStateChanged)(n.wt,async r=>{if(r?.uid===y.current&&g){i(r);return}if(y.current=r?.uid||null,r){let a=localStorage.getItem(`fbos_role_${r.uid}`);a&&(u(a),_(!0),h(!1)),console.log(`[AuthContext] 1. onAuthStateChanged fired for user:`,r.uid),i(r);try{let i=(0,o.doc)(n.Tt,`user_profiles`,r.uid),a=(await(0,o.getDoc)(i)).data()||{};(0,o.setDoc)(i,{uid:r.uid,email:r.email,displayName:r.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,o.onSnapshot)(i,e=>{if(e.exists()){let n=e.data(),a=n.role||`user`,s=``;try{s={BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_ADMIN_EMAILS:void 0,VITE_FIREBASE_API_KEY:void 0,VITE_FIREBASE_APP_ID:void 0,VITE_FIREBASE_AUTH_DOMAIN:void 0,VITE_FIREBASE_MESSAGING_SENDER_ID:void 0,VITE_FIREBASE_PROJECT_ID:void 0,VITE_FIREBASE_STORAGE_BUCKET:void 0}?.VITE_ADMIN_EMAILS||``}catch{}let c=t.adminEmails||(s?s.split(`,`).map(e=>e.trim().toLowerCase()).filter(Boolean):[]);c.length>0&&!n.role&&c.map(e=>e.toLowerCase()).some(e=>r.email?.toLowerCase()===e)&&(a=`admin`,(0,o.updateDoc)(i,{role:`admin`}).catch(e=>console.error(`Error auto-setting admin role:`,e))),v.current===null&&(v.current=a),u(a),localStorage.setItem(`fbos_role_${r.uid}`,a),p(n.inactive===!0)}_(!0),h(!1)},e=>{console.warn(`[AuthContext] user_profiles snapshot error (safe to ignore during auth transition):`,e),_(!0),h(!1)})}catch(e){console.error(`[AuthContext] ERROR in auth resolution:`,e),_(!0),h(!1)}}else console.log(`[AuthContext] No user currently signed in.`),i(null),u(null),p(!1),_(!0),h(!1),v.current=null,e&&e()});return()=>{r(),e&&e()}},[]),(0,l.jsx)(f.Provider,{value:{user:r,userRole:c,loading:m,signOut:async()=>{await(0,s.signOut)(n.wt),i(null)},registerUser:async(e,t,r,i)=>{let{createUserWithEmailAndPassword:a}=await import(`firebase/auth`),{user:c}=await a(n.wt,e,t),l=`${r} ${i}`.trim();await(0,s.updateProfile)(c,{displayName:l});try{await c.getIdToken(!0),await(0,o.setDoc)((0,o.doc)(n.Tt,`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,s.sendEmailVerification)(c)},refreshUser:async()=>{n.wt.currentUser&&(await n.wt.currentUser.reload(),i(Object.assign(Object.create(Object.getPrototypeOf(n.wt.currentUser)),n.wt.currentUser)))},userInactive:d,roleResolved:g},children:e})}var m=()=>(0,a.useContext)(f);function h(){let[e,t]=(0,a.useState)(!1),[r,i]=(0,a.useState)([]),s=(0,a.useRef)(null),c=(0,u.useNavigate)();(0,a.useEffect)(()=>{function e(e){s.current&&!s.current.contains(e.target)&&t(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let d=(0,a.useRef)({users:[],submissions:[],requests:[]}),f=(e,t)=>{d.current[e]=t;let n=[...d.current.users,...d.current.submissions,...d.current.requests];n.sort((e,t)=>{let n=e.time?.toDate?e.time.toDate().getTime():new Date(e.time).getTime();return((t.time?.toDate?t.time.toDate().getTime():new Date(t.time).getTime())||0)-(n||0)}),i(n.slice(0,8))};(0,a.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,`user_profiles`),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(5)),e=>{f(`users`,e.docs.map(e=>{let t=e.data();return{id:`u_${e.id}`,type:`user`,title:`New user registered`,subtitle:t.email||`Unknown`,time:t.createdAt}}))}),t=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,`user_submissions`),(0,o.orderBy)(`submittedAt`,`desc`),(0,o.limit)(5)),e=>{f(`submissions`,e.docs.map(e=>{let t=e.data();return{id:`s_${e.id}`,type:`submission`,title:`New form submission`,subtitle:t.name||t.email||`Anonymous`,time:t.submittedAt}}))}),r=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,`user_requests`),(0,o.orderBy)(`submittedAt`,`desc`),(0,o.limit)(5)),e=>{f(`requests`,e.docs.map(e=>{let t=e.data();return{id:`r_${e.id}`,type:`request`,title:`New support request`,subtitle:t.name||t.submitterName||t.contactEmail||t.email||`Anonymous`,time:t.submittedAt}}))});return()=>{e(),t(),r()}},[]);let[p,m]=(0,a.useState)(()=>typeof window<`u`?parseInt(localStorage.getItem(`admin_notifications_last_read`)||`0`,10):0),h=()=>{let n=!e;if(t(n),n){let e=Date.now();m(e),typeof window<`u`&&localStorage.setItem(`admin_notifications_last_read`,e.toString())}},g=r.some(e=>{if(!e.time)return!0;let t=e.time?.toDate?e.time.toDate().getTime():new Date(e.time).getTime();return t>p||isNaN(t)}),_=e=>{t(!1),c(e===`user`?`/users`:e===`submission`?`/submissions`:`/requests`)},v=e=>{if(!e)return``;let t=e.toDate?e.toDate():new Date(e);return new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`,hour:`numeric`,minute:`numeric`}).format(t)};return(0,l.jsxs)(`div`,{className:`relative z-50 flex-shrink-0 mr-1 md:mr-2`,ref:s,children:[(0,l.jsxs)(`button`,{onClick:h,className:`p-2 rounded-xl glass-panel transition-all border border-transparent relative text-notification-icon hover:bg-foreground/5 hover:border-[var(--panel-border)]`,"aria-label":`Admin Notifications`,children:[(0,l.jsx)(n.mt,{className:`w-4 h-4 md:w-5 md:h-5`}),g&&(0,l.jsx)(`span`,{className:`absolute top-1.5 right-1.5 w-2 h-2 bg-red-500 rounded-full animate-pulse`})]}),(0,l.jsx)(n.a,{children:e&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:-5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98,y:-5},className:`absolute top-full mt-2 right-[-60px] md:right-0 w-[320px] md:w-[400px] glass-panel border border-[var(--panel-border)] rounded-2xl shadow-2xl z-50 flex flex-col origin-top-right overflow-hidden bg-[var(--panel-bg)]`,children:[(0,l.jsxs)(`div`,{className:`px-4 border-b border-[var(--panel-border)]/50 pb-3 pt-4 flex items-center justify-between`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] text-foreground tracking-wide`,children:`Notifications`}),(0,l.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,l.jsx)(`div`,{className:`max-h-[350px] overflow-y-auto w-full p-2 flex flex-col gap-1`,children:r.length===0?(0,l.jsx)(`div`,{className:`p-6 text-center text-foreground/40 text-[13px] font-medium`,children:`No recent activity.`}):r.map(e=>(0,l.jsxs)(`button`,{onClick:()=>_(e.type),className:`w-full flex items-start gap-3 p-3 rounded-xl hover:bg-foreground/5 transition-all text-left group border border-transparent hover:border-[var(--panel-border)]`,children:[(0,l.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,l.jsx)(n.d,{className:`w-4 h-4`}):e.type===`submission`?(0,l.jsx)(n.k,{className:`w-4 h-4`}):(0,l.jsx)(n.tt,{className:`w-4 h-4`})}),(0,l.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0 pr-2`,children:[(0,l.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground group-hover:text-accent transition-colors truncate`,children:e.title}),(0,l.jsx)(`span`,{className:`text-[12px] text-foreground/60 truncate`,children:e.subtitle}),(0,l.jsx)(`span`,{className:`text-[10px] font-mono tracking-wide text-foreground/40 mt-1`,children:v(e.time)})]})]},e.id))})]})})]})}var g=[{id:`contact`,hidden:!1},{id:`templates`,hidden:!1},{id:`setup`,hidden:!1}],_=e=>(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden}),v=[{id:`pages`,hidden:!1},{id:`forms`,hidden:!1},{id:`drive`,hidden:!1},{id:`users`,hidden:!1},{id:`theme`,hidden:!1},{id:`submissions`,hidden:!1},{id:`requests`,hidden:!1},{id:`settings`,hidden:!1},{id:`profile`,hidden:!1},{id:`support`,hidden:!0}],y={route:`/support`,template:`popup_form`,form:`support`,tabName:`Support`,iconName:``},b={templates:{label:`Templates`,path:`/templates`},setup:{label:`Setup`,path:`/setup`},contact:{label:`Contact`,path:`/contact`}};function x({customMenu:e,standalone:t}){let{user:r,userRole:i,signOut:s}=m(),c=(0,u.useNavigate)(),[d,f]=(0,a.useState)(!1),[p,v]=(0,a.useState)(null),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(!1),[T,E]=(0,a.useState)(!1),D=r?.displayName||r?.email?.split(`@`)[0]||`User`,ee=D.charAt(0).toUpperCase()+D.slice(1),{theme:O,toggleTheme:k,activeConfig:A}=n.xt(),te=async()=>{await s(),c(`/`),f(!1)},[j,ne]=(0,a.useState)({...b}),[M,N]=(0,a.useState)(g);(0,a.useEffect)(()=>{if(!n.Tt)return;let e=(0,o.onSnapshot)((0,o.collection)(n.Tt,`sys_pages`),e=>{let t={...b};e.forEach(e=>{let n=e.data();if(n.enabled===!1)return;let r=n.pageName||n.title||b[e.id]?.label||e.id,i=n.route||(e.id===`home`?`/`:`/`+e.id);t[e.id]={label:r,path:i}}),ne(t)},e=>{console.warn(`sys_pages snapshot error (safe to ignore during auth transition):`,e)}),t=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`page_order`),e=>{N(e.exists()&&Array.isArray(e.data().order)?_(e.data().order):g)},e=>{console.warn(`page_order snapshot error (safe to ignore during auth transition):`,e)}),r=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_tabs`,`support`),e=>{e.exists()&&e.data().pageName&&F(e.data().pageName)},e=>{console.warn(`support snapshot error (safe to ignore during auth transition):`,e)});return()=>{e(),t(),r()}},[]);let[P,F]=(0,a.useState)(y.tabName),I=(()=>{let e=new Set(M.filter(e=>e.hidden).map(e=>e.id)),t=new Set,n=[];return M.forEach(e=>{if(e.hidden||e.id===`home`)return;let r=j[e.id];r&&(n.push({label:r.label,path:r.path}),t.add(e.id))}),Object.entries(j).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})(),L=e||I,R=(0,a.useRef)(null),z=(0,a.useRef)(null),[re,B]=(0,a.useState)(L.length);(0,a.useEffect)(()=>{if(t||r)return;let e=()=>{let e=R.current,t=z.current;if(!e||!t)return;let n=e.clientWidth,r=t.querySelectorAll(`[data-measure-nav]`);if(r.length===0){B(L.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){B(L.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++}B(Math.max(s,1))},n=requestAnimationFrame(e);if(typeof ResizeObserver>`u`)return()=>cancelAnimationFrame(n);let i=new ResizeObserver(()=>requestAnimationFrame(e));return R.current&&i.observe(R.current),()=>{cancelAnimationFrame(n),i.disconnect()}},[L.map(e=>e.label).join(`|`),t,r,L.length]);let ie=L.slice(0,re),V=L.slice(re);return(0,l.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,l.jsx)(`div`,{className:`flex items-center gap-2 md:gap-4 z-50`,children:(0,l.jsxs)(u.Link,{to:`/`,className:`flex items-center gap-2 md:gap-3 group cursor-pointer z-50`,children:[(0,l.jsx)(`div`,{className:`w-9 h-9 md:w-10 md:h-10 rounded-xl glass-panel flex items-center justify-center glow-hover shadow-lg transition-transform duration-500 group-hover:rotate-[360deg] group-active:scale-95 overflow-hidden`,children:A?.logoUrl?(0,l.jsx)(`img`,{src:A.logoUrl,alt:`Logo`,className:`w-full h-full object-cover`}):(0,l.jsx)(n.X,{className:`w-4 h-4 md:w-5 md:h-5 text-accent`})}),(0,l.jsx)(`span`,{className:`hidden lg:block font-bold text-[22px] tracking-tight text-gradient transition-colors duration-300 drop-shadow-sm`,children:A?.appName||``})]})}),(0,l.jsx)(n.a,{children:x&&(0,l.jsx)(n.t,{formId:`contact`,onClose:()=>S(!1)})}),(0,l.jsx)(n.a,{children:C&&(0,l.jsx)(n.t,{formId:`support`,onClose:()=>w(!1)})}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 md:gap-4 z-50 relative ml-auto flex-1 justify-end`,children:[!t&&!r&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{ref:z,"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:L.map((e,t)=>(0,l.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,l.jsx)(n.st,{className:`w-3 h-3`})]},e.path||t))}),(0,l.jsxs)(`div`,{className:`hidden sm:flex items-center gap-7 mr-6 w-full max-w-full justify-end relative`,ref:R,children:[ie.map((e,t)=>(0,l.jsxs)(`div`,{className:`relative shrink-0`,onMouseEnter:()=>v(e.label),onMouseLeave:()=>v(null),children:[e.path?(0,l.jsxs)(u.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,l.jsx)(n.st,{className:`w-3 h-3`})]}):(0,l.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,l.jsx)(n.st,{className:`w-3 h-3`})]}),e.submenu&&p===e.label&&(0,l.jsx)(`div`,{className:`absolute top-[100%] left-0 pt-2 z-50`,children:(0,l.jsx)(n.i.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,l.jsx)(u.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,l.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`}-${t}`)),V.length>0&&(0,l.jsxs)(`div`,{className:`relative flex items-center shrink-0`,onMouseEnter:()=>f(`overflow`),children:[(0,l.jsx)(`button`,{onClick:()=>f(d===`overflow`?!1:`overflow`),className:`p-1 rounded-lg transition-colors flex items-center ${d===`overflow`?`bg-foreground/5 text-accent`:`text-foreground/50 hover:bg-foreground/5 hover:text-accent`}`,children:(0,l.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,l.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,l.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1`}),(0,l.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1`})]})}),(0,l.jsx)(n.a,{children:d===`overflow`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>f(!1)}),(0,l.jsx)(n.i.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 bg-background border border-[var(--panel-border)] rounded-2xl shadow-xl flex flex-col py-2 z-50 origin-top-right`,children:V.map((e,t)=>e.path?(0,l.jsx)(u.Link,{to:e.path,onClick:()=>f(!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,l.jsx)(`button`,{onClick:()=>{e.action&&e.action(),f(!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))})]})})]})]}),A?.showThemeToggle&&(0,l.jsx)(`button`,{onClick:k,className:`p-2 mr-2 rounded-xl glass-panel hover:bg-foreground/5 transition-all text-accent border border-[var(--panel-border)] hover:border-accent/40 shrink-0`,"aria-label":`Toggle Theme`,children:O===`dark`?(0,l.jsx)(n._,{className:`w-4 h-4 md:w-5 md:h-5`}):(0,l.jsx)(n.E,{className:`w-4 h-4 md:w-5 md:h-5`})}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(u.Link,{to:`/login`,className:`hidden sm:flex text-[14px] font-bold tracking-wide text-foreground/80 hover:text-accent transition-colors px-3 py-1.5 shrink-0`,children:`Sign In`}),(0,l.jsx)(u.Link,{to:`/register`,className:`hidden sm:flex text-[13px] md:text-[14px] font-bold tracking-wide px-4 py-1.5 md:px-5 md:py-2 rounded-xl btn-primary transition-all duration-300 hover:shadow-lg hover:-translate-y-0.5 active:scale-95 items-center justify-center ml-2`,children:`Get Started`}),(0,l.jsxs)(`div`,{className:`relative sm:hidden ml-1`,children:[(0,l.jsx)(`button`,{onClick:()=>f(d===`guest`?!1:`guest`),className:`p-2 rounded-xl glass-panel glow-hover border transition-all ${d===`guest`?`border-accent bg-foreground/5`:`border-[var(--panel-border)] hover:bg-foreground/5`}`,children:(0,l.jsx)(n.O,{className:`w-5 h-5 text-accent/80`})}),(0,l.jsx)(n.a,{children:d===`guest`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>f(!1)}),(0,l.jsxs)(n.i.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-panel border border-[var(--panel-border)] rounded-2xl shadow-2xl z-50 flex flex-col gap-1 origin-top-right`,children:[(0,l.jsxs)(u.Link,{to:`/templates`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.P,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Templates`})]}),(0,l.jsxs)(u.Link,{to:`/setup`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.y,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Setup`})]}),(0,l.jsxs)(u.Link,{to:`/contact`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all w-full text-left`,children:[(0,l.jsx)(n.k,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Contact`})]}),(0,l.jsxs)(`div`,{className:`pt-2 mt-1 border-t border-[var(--panel-border)]/50 flex flex-col gap-1`,children:[(0,l.jsxs)(u.Link,{to:`/login`,onClick:()=>f(!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,l.jsx)(n.A,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Sign In`})]}),(0,l.jsx)(u.Link,{to:`/register`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl btn-primary w-full shadow-lg hover:-translate-y-0.5 transition-transform text-white`,children:(0,l.jsx)(`span`,{className:`text-[14px] font-bold mx-auto`,children:`Get Started`})})]})]})]})})]})]})]}),!t&&r&&(0,l.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2 mr-1`,children:[i===`admin`&&(0,l.jsx)(h,{}),A?.showThemeToggle&&(0,l.jsx)(`button`,{onClick:k,className:`p-2 ml-1 rounded-xl glass-panel hover:bg-foreground/5 transition-all text-accent border border-[var(--panel-border)] hover:border-accent/40`,"aria-label":`Toggle Theme`,children:O===`dark`?(0,l.jsx)(n._,{className:`w-4 h-4 md:w-5 md:h-5`}):(0,l.jsx)(n.E,{className:`w-4 h-4 md:w-5 md:h-5`})})]}),(0,l.jsxs)(`div`,{className:`relative z-50 flex items-center gap-3`,children:[(0,l.jsxs)(`div`,{className:`relative flex-shrink-0`,children:[(0,l.jsxs)(`button`,{onClick:()=>f(d===`user`?!1:`user`),className:`flex items-center gap-2 group p-1 sm:pr-2.5 rounded-full glass-panel hover:bg-foreground/5 transition-all duration-300 border ${d===`user`?`border-accent/40 bg-foreground/5`:`border-transparent hover:border-[var(--panel-border)]`}`,children:[(0,l.jsx)(`div`,{className:`w-8 h-8 md:w-9 md:h-9 rounded-full bg-accent/10 flex items-center justify-center overflow-hidden border border-[var(--panel-border)] group-hover:border-accent/30 transition-colors shrink-0 text-accent`,children:r.photoURL&&!T?(0,l.jsx)(`img`,{src:r.photoURL,alt:`Profile`,className:`w-full h-full object-cover`,onError:()=>E(!0)}):(0,l.jsx)(n.d,{className:`w-4 h-4 md:w-5 md:h-5 text-accent`})}),(0,l.jsxs)(`div`,{className:`hidden sm:flex flex-col text-left mr-1 justify-center min-w-[70px] max-w-[160px]`,children:[(0,l.jsx)(`span`,{className:`text-[12px] font-extrabold leading-tight text-foreground truncate w-full`,children:ee}),(0,l.jsx)(`span`,{className:`text-[10px] font-mono tracking-wider leading-tight text-accent truncate w-full mt-0.5 uppercase font-bold`,children:i===`admin`?`Admin`:`Free User`})]})]}),(0,l.jsx)(n.a,{children:d===`user`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>f(!1)}),(0,l.jsxs)(n.i.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-panel border border-[var(--panel-border)] rounded-2xl p-2 shadow-2xl z-50 flex flex-col origin-top-right`,children:[(0,l.jsxs)(`div`,{className:`p-3 border-b border-[var(--panel-border)]/50 mb-1 flex flex-col gap-1.5`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[15px] text-foreground truncate`,children:ee}),(0,l.jsx)(`span`,{className:`text-[12px] text-foreground/50 truncate font-mono`,children:r.email})]}),(0,l.jsxs)(`div`,{className:`py-1`,children:[(0,l.jsxs)(u.Link,{to:`/profile`,onClick:()=>f(!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,l.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,l.jsx)(n.d,{className:`w-3 h-3 text-accent`})}),`Profile Settings`]}),(0,l.jsxs)(u.Link,{to:`/drive`,onClick:()=>f(!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,l.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,l.jsx)(n.H,{className:`w-3 h-3 text-accent`})}),`Drive`]}),i===`admin`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(u.Link,{to:`/users`,onClick:()=>f(!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,l.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,l.jsx)(n.u,{className:`w-3 h-3 text-accent`})}),`Users`]}),(0,l.jsxs)(u.Link,{to:`/submissions`,onClick:()=>f(!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,l.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,l.jsx)(n.k,{className:`w-3 h-3 text-accent`})}),`Submissions`]}),(0,l.jsxs)(u.Link,{to:`/requests`,onClick:()=>f(!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,l.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,l.jsx)(n.tt,{className:`w-3 h-3 text-accent`})}),`Requests`]}),(0,l.jsxs)(u.Link,{to:`/settings`,onClick:()=>f(!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,l.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,l.jsx)(n.y,{className:`w-3 h-3 text-accent`})}),`Settings`]}),(0,l.jsxs)(u.Link,{to:`/pages`,onClick:()=>f(!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,l.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,l.jsx)(n.L,{className:`w-3 h-3 text-accent`})}),`Pages`]})]}),i!==`admin`&&(0,l.jsxs)(u.Link,{to:`/support`,onClick:()=>f(!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,l.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,l.jsx)(n.tt,{className:`w-3 h-3 text-accent`})}),P]})]}),(0,l.jsx)(`div`,{className:`pt-1 mt-1 border-t border-[var(--panel-border)]/50`,children:(0,l.jsxs)(`button`,{onClick:te,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,l.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,l.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,l.jsx)(`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`}),(0,l.jsx)(`polyline`,{points:`16 17 21 12 16 7`}),(0,l.jsx)(`line`,{x1:`21`,y1:`12`,x2:`9`,y2:`12`})]})}),`Sign Out`]})})]})]})})]}),(0,l.jsxs)(`div`,{className:`relative sm:hidden`,children:[(0,l.jsx)(`button`,{onClick:()=>f(d===`nav`?!1:`nav`),className:`p-2 rounded-xl glass-panel glow-hover border transition-all ${d===`nav`?`border-accent bg-foreground/5`:`border-[var(--panel-border)] hover:bg-foreground/5`}`,children:(0,l.jsx)(n.O,{className:`w-5 h-5 text-accent/80`})}),(0,l.jsx)(n.a,{children:d===`nav`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>f(!1)}),(0,l.jsxs)(n.i.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-panel border border-[var(--panel-border)] rounded-2xl shadow-2xl z-50 flex flex-col gap-1 origin-top-right`,children:[(0,l.jsxs)(u.Link,{to:`/profile`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.d,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Profile Settings`})]}),(0,l.jsxs)(u.Link,{to:`/drive`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.H,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Drive`})]}),(0,l.jsxs)(u.Link,{to:`/dashboard`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.I,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Dashboard`})]}),i===`admin`&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(u.Link,{to:`/users`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.u,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Users`})]}),(0,l.jsxs)(u.Link,{to:`/submissions`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.k,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Submissions`})]}),(0,l.jsxs)(u.Link,{to:`/requests`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.tt,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Requests`})]}),(0,l.jsxs)(u.Link,{to:`/settings`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all`,children:[(0,l.jsx)(n.y,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Settings`})]})]}),i!==`admin`&&(0,l.jsxs)(u.Link,{to:`/support`,onClick:()=>f(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all w-full text-left`,children:[(0,l.jsx)(n.tt,{className:`w-4 h-4 text-accent/70`}),` `,(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Support`})]}),(0,l.jsx)(`div`,{className:`pt-1 mt-1 border-t border-[var(--panel-border)]/50`,children:(0,l.jsx)(`button`,{onClick:te,className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-red-500/10 text-red-500/80 hover:text-red-500 transition-all w-full`,children:(0,l.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Sign Out`})})})]})]})})]})]})]}),t&&(0,l.jsx)(l.Fragment,{children:A?.showThemeToggle&&(0,l.jsx)(`button`,{onClick:k,className:`p-2 ml-1 rounded-xl glass-panel hover:bg-foreground/5 transition-all text-accent border border-[var(--panel-border)] hover:border-accent/40`,"aria-label":`Toggle Theme`,children:O===`dark`?(0,l.jsx)(n._,{className:`w-4 h-4`}):(0,l.jsx)(n.E,{className:`w-4 h-4`})})})]})]})}var S={hero:{title:`Firebase OS.`,showSubtitle:!0,subtitle:`The Open-Source Firebase Starter`,text:`A production-ready Firebase backend template with Auth, Firestore prefix rules, and a clean dashboard — ready for vibe-coded apps.`,buttons:{primary:{text:`Start Building Free`,action:`register`},secondary:{text:`Sign In`,action:`sign_in`}}}};function C(){let[e,t]=(0,a.useState)(null),r=n.Ct()?.defaultConfigs?.home||S,[i,s]=(0,a.useState)(()=>{try{let e=localStorage.getItem(`fbos_home_config`);if(e)return JSON.parse(e)}catch{}return r}),[c,d]=(0,a.useState)(!0);if((0,a.useEffect)(()=>(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_pages`,`home`),e=>{if(e.exists()){let t=e.data();s(t),localStorage.setItem(`fbos_home_config`,JSON.stringify(t))}else s(r),localStorage.removeItem(`fbos_home_config`)}),[]),!c)return null;let f=i||S,p=f?.hero?.showSubtitle??!0;f?.hero?.subtitleEmoji;let m=f?.hero?.title||f?.heroTitle||`The Open-Source Firebase Starter`,h=f?.hero?.subtitle||f?.heroSubtitle||`The Open-Source Firebase Starter`,g=f?.hero?.text||f?.heroText||`A production-ready Firebase backend template with Auth, Firestore prefix rules, and a clean dashboard — ready for vibe-coded apps.`;f?.hero?.buttons?.primary?.text||f?.primaryBtnText,f?.hero?.buttons?.primary?.action||f?.primaryBtnAction;let _=f?.hero?.buttons?.primary||{},v=f?.hero?.buttons?.secondary||{},y=(e,n,r,i)=>{let a=e.text||n,o=e.action||r,s=i.replace(/rounded-\[.*?\]|rounded-\w+/g,``).replace(/border /g,``).replace(/border-\[.*?\]/g,``),c={borderRadius:`var(--btn-radius, 0.75rem)`};if(o===`form`){let n=e.form||`contact`;return(0,l.jsx)(`button`,{onClick:()=>t(n),className:s,style:c,children:a})}if(o===`redirect`){let t=e.url||`/`;return t.startsWith(`http`)?(0,l.jsx)(`a`,{href:t,target:`_blank`,rel:`noopener noreferrer`,className:s,style:c,children:a}):(0,l.jsx)(u.Link,{to:t,className:s,style:c,children:a})}return(0,l.jsx)(u.Link,{to:{sign_in:`/login`,register:`/register`}[o]||`/register`,className:s,style:c,children:a})};return(0,l.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,l.jsxs)(n.i.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},transition:{duration:.8},className:`text-center mb-8 md:mb-12`,children:[p&&(0,l.jsxs)(n.i.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:[h===S.hero.subtitle&&(0,l.jsx)(n.s,{className:`w-4 h-4 text-accent`}),` `,h]}),(0,l.jsx)(n.i.h1,{className:`text-5xl sm:text-6xl md:text-7xl lg:text-[5.5rem] font-extrabold tracking-tight mb-6 md:mb-8 text-gradient animate-float leading-[1.1] md:leading-[1.15] px-2`,children:m}),(0,l.jsx)(`p`,{className:`text-[15px] sm:text-lg md:text-xl lg:text-[22px] 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:g}),(0,l.jsxs)(n.i.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:[y(_,`Start Building Free`,`register`,`w-full sm:w-auto 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`),y(v,`Sign In`,`sign_in`,`w-full sm:w-auto px-6 md:px-8 py-3 md:py-3.5 rounded-xl font-semibold tracking-wide btn-secondary text-[15px] transition-all duration-300 flex items-center justify-center hover:-translate-y-1`)]})]}),(0,l.jsx)(n.a,{children:e&&(0,l.jsx)(n.t,{onClose:()=>t(null),formId:e})})]})}function w(){let[e,t]=(0,a.useState)(!1),[r,i]=(0,a.useState)(null),o=(0,u.useNavigate)(),{registerUser:c}=m();return(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mt-6 md:mt-8 mb-8`,children:(0,l.jsxs)(n.i.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,l.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,l.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,l.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight`,children:`Create an account`}),(0,l.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Join Firebase OS and start building today.`})]}),r&&(0,l.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:r}),(0,l.jsxs)(`form`,{className:`space-y-4`,onSubmit:async e=>{e.preventDefault(),t(!0),i(null);let n=new FormData(e.currentTarget),r=n.get(`email`),a=n.get(`password`),s=n.get(`firstName`),d=n.get(`lastName`);if(a.length<6){i(`Password must be at least 6 characters.`),t(!1);return}try{await c(r,a,s,d),o(`/verify`)}catch(e){e?.code===`auth/email-already-in-use`?i((0,l.jsxs)(`span`,{children:[`An account with this email already exists.`,` `,(0,l.jsx)(u.Link,{to:`/login?email=${encodeURIComponent(r)}`,className:`font-bold underline hover:text-accent transition-colors`,children:`Sign in?`})]})):e?.code===`auth/weak-password`?i(`Password must be at least 6 characters.`):i(e?.message||`An error occurred during registration.`)}finally{t(!1)}},children:[(0,l.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,l.jsx)(n.r,{name:`firstName`,label:`First Name`,type:`text`,placeholder:`John`,required:!0}),(0,l.jsx)(n.r,{name:`lastName`,label:`Last Name`,type:`text`,placeholder:`Doe`,required:!0})]}),(0,l.jsx)(n.r,{name:`email`,label:`Email`,type:`email`,placeholder:`name@example.com`,required:!0}),(0,l.jsx)(n.r,{name:`password`,label:`Password`,type:`password`,placeholder:`••••••••`,required:!0}),(0,l.jsx)(`div`,{className:`pt-2`,children:(0,l.jsxs)(n.n,{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,l.jsx)(n.ht,{className:`ml-2 w-4 h-4 group-hover:translate-x-1 transition-transform shrink-0`})]})})]}),(0,l.jsxs)(`div`,{className:`mt-6 pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:[(0,l.jsxs)(n.n,{variant:`secondary`,onClick:async()=>{t(!0);try{await(0,s.signInWithPopup)(n.wt,new s.GoogleAuthProvider)}catch(e){e instanceof Error&&i(e.message)}finally{t(!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,l.jsxs)(`svg`,{className:`w-5 h-5 mr-3`,viewBox:`0 0 24 24`,children:[(0,l.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,l.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,l.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,l.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,l.jsxs)(`p`,{className:`text-[14px] text-foreground/70 font-medium pt-2 tracking-wide`,children:[`Already have an account? `,(0,l.jsx)(u.Link,{to:`/login`,className:`text-accent hover:underline font-bold ml-1`,children:`Sign in`})]})]})]})})}function T(){let[e,t]=(0,a.useState)(!1),[r,i]=(0,a.useState)(null),[o]=(0,u.useSearchParams)(),c=(0,u.useNavigate)(),[d]=(0,a.useState)(o.get(`email`)||``);return(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mt-6 md:mt-8 mb-8`,children:(0,l.jsxs)(n.i.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,l.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,l.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,l.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight`,children:`Welcome back`}),(0,l.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Sign in to Firebase OS.`})]}),r&&(0,l.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:r}),(0,l.jsxs)(`form`,{className:`space-y-4`,onSubmit:async e=>{e.preventDefault(),t(!0),i(null);let r=new FormData(e.currentTarget),a=r.get(`email`),d=r.get(`password`);try{await(0,s.signInWithEmailAndPassword)(n.wt,a,d),c(o.get(`from`)||`/dashboard`,{replace:!0})}catch(e){e?.code===`auth/invalid-credential`||e?.code===`auth/user-not-found`||e?.code===`auth/wrong-password`?i((0,l.jsxs)(`span`,{children:[`Email or Password are incorrect.`,` `,(0,l.jsx)(u.Link,{to:`/reset-password`,className:`font-bold underline hover:text-red-400 transition-colors`,children:`Reset password?`})]})):i(e?.message||`Invalid credentials.`),t(!1)}},children:[(0,l.jsx)(n.r,{name:`email`,label:`Email`,type:`email`,defaultValue:d,placeholder:`name@example.com`,required:!0}),(0,l.jsxs)(`div`,{className:`space-y-2`,children:[(0,l.jsxs)(`div`,{className:`flex justify-between items-center pr-1`,children:[(0,l.jsx)(`label`,{className:`text-[14px] md:text-[15px] tracking-wide font-medium text-foreground/80 select-none pb-1`,children:`Password`}),(0,l.jsx)(u.Link,{to:`/reset-password`,className:`text-[13px] md:text-[14px] text-accent hover:underline font-bold tracking-wide`,children:`Forgot Password?`})]}),(0,l.jsx)(n.r,{name:`password`,type:`password`,placeholder:`••••••••`,required:!0})]}),(0,l.jsx)(`div`,{className:`pt-2`,children:(0,l.jsxs)(n.n,{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,l.jsx)(n.ht,{className:`ml-2 w-4 h-4 group-hover:translate-x-1 transition-transform shrink-0`})]})})]}),(0,l.jsxs)(`div`,{className:`mt-6 pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:[(0,l.jsxs)(n.n,{variant:`secondary`,onClick:async()=>{t(!0);try{await(0,s.signInWithPopup)(n.wt,new s.GoogleAuthProvider),c(o.get(`from`)||`/dashboard`,{replace:!0})}catch(e){e instanceof Error&&i(e.message)}finally{t(!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,l.jsxs)(`svg`,{className:`w-5 h-5 mr-3`,viewBox:`0 0 24 24`,children:[(0,l.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,l.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,l.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,l.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,l.jsxs)(`p`,{className:`text-[14px] text-foreground/70 font-medium pt-2 tracking-wide`,children:[`New here? `,(0,l.jsx)(u.Link,{to:`/register`,className:`text-accent hover:underline font-bold ml-1`,children:`Create account`})]})]})]})})}function E(){let{user:e,refreshUser:t}=m(),r=(0,u.useNavigate)(),[i,o]=(0,a.useState)(!1),[c,d]=(0,a.useState)(!1),[f,p]=(0,a.useState)(``);return(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mb-16`,children:(0,l.jsxs)(n.i.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,l.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,l.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,l.jsx)(n.k,{className:`w-7 h-7 md:w-8 md:h-8 text-accent opacity-90`})}),(0,l.jsx)(`h1`,{className:`text-2xl md:text-3xl font-extrabold mb-3 text-foreground tracking-tight`,children:`Verify your email`}),(0,l.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,l.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.`]}),f&&(0,l.jsx)(`div`,{className:`p-3 md:p-4 mb-5 md:mb-6 text-[13px] md:text-[14px] font-medium 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,l.jsxs)(`div`,{className:`flex flex-col gap-3 max-w-[360px] mx-auto`,children:[(0,l.jsx)(n.n,{variant:`primary`,onClick:async()=>{o(!0),p(``);try{if(n.wt.currentUser){if(await n.wt.currentUser.reload(),!n.wt.currentUser.emailVerified){p(`Email is not verified yet. Please check your inbox.`),o(!1);return}await n.wt.currentUser.getIdToken(!0),await t(),r(`/dashboard`)}}catch{p(`Something went wrong. Please try again.`),o(!1)}},isLoading:i,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,l.jsx)(n.n,{variant:`ghost`,onClick:async()=>{if(e){d(!0),p(``);try{await(0,s.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:c,className:`w-full py-2.5 md:py-3 text-[13px] md:text-[14px] font-semibold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,children:`Resend verification link`})]})]})})}var D={pages:{path:`/pages`,label:`Pages`,icon:n.L,roles:[`admin`]},forms:{path:`/forms`,label:`Forms`,icon:n.S,roles:[`admin`]},drive:{path:`/drive`,label:`Drive`,icon:n.H,roles:[`admin`,`user`,`editor`,`guest`]},users:{path:`/users`,label:`Users`,icon:n.u,roles:[`admin`]},theme:{path:`/theme`,label:`Theme`,icon:n.T,roles:[`admin`]},submissions:{path:`/submissions`,label:`Submissions`,icon:n.k,roles:[`admin`]},requests:{path:`/requests`,label:`Requests`,icon:n.tt,roles:[`admin`]},settings:{path:`/settings`,label:`Settings`,icon:n.y,roles:[`admin`]},profile:{path:`/profile`,label:`Profile`,icon:n.d,roles:[`admin`,`user`,`editor`,`guest`]},support:{path:`/support`,label:`Support`,icon:n.tt,roles:[`user`,`editor`,`guest`]}};function ee({customTabs:e=[]}){let{pathname:t}=(0,u.useLocation)(),{userRole:r}=m(),[i,s]=(0,a.useState)(!1),c=(0,a.useRef)(null),[d,f]=(0,a.useState)({}),[p,h]=(0,a.useState)(v);(0,a.useEffect)(()=>{try{let e=localStorage.getItem(`fbos_nav_tabs`);e&&f(JSON.parse(e));let t=localStorage.getItem(`fbos_nav_order`);t&&h(JSON.parse(t))}catch{}let e=(0,o.onSnapshot)((0,o.collection)(n.Tt,`sys_tabs`),e=>{let t={};e.forEach(e=>{t[e.id]=e.data()}),f(t),localStorage.setItem(`fbos_nav_tabs`,JSON.stringify(t))},e=>{console.warn(`sys_tabs snapshot error:`,e)}),t=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`tab_order`),e=>{let t=e.exists()&&Array.isArray(e.data().order)?_(e.data().order):v;h(t),localStorage.setItem(`fbos_nav_order`,JSON.stringify(t))},e=>{console.warn(`tab_order snapshot error:`,e)});return()=>{e(),t()}},[]),(0,a.useEffect)(()=>{function e(e){c.current&&!c.current.contains(e.target)&&s(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let g=[...(()=>{let e={};Object.entries(D).forEach(([t,n])=>{e[t]={id:t,...n,exact:!0}}),Object.entries(d).forEach(([t,r])=>{let i=e[t],a=i?.icon??n.L;if(r?.iconName){let e=r.iconName.trim(),t=e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);n.o[t]?a=n.o[t]:n.o[e]&&(a=n.o[e])}let o=i?.roles??[`admin`];r?.pageType===`admin`?o=[`admin`]:r?.pageType===`shared`?o=[`admin`,`editor`,`user`]:r?.pageType===`private`?o=[`admin`,`user`]:r?.pageType===`public`&&(o=[`admin`,`user`,`editor`,`guest`]),e[t]={id:t,path:r?.route?r.route.startsWith(`/`)?r.route:`/`+r.route:i?.path??`/`+t,label:r?.tabName||r?.pageTitle||r?.pageName||i?.label||t,icon:a,roles:o,exact:!0}});let t=[],r=new Set;p.forEach(n=>{n.hidden||e[n.id]&&(t.push(e[n.id]),r.add(n.id))});let i=[],a=[];return Object.keys(e).forEach(t=>{if(r.has(t))return;let n=p.find(e=>e.id===t);n?.hidden||(t in d&&!n?i.push(e[t]):a.push(e[t]))}),i.length>0&&t.unshift(...i),a.length>0&&t.push(...a),t})(),...e.map(e=>({...e,id:e.path}))].filter(e=>e.id===`support`&&r===`admin`?!1:Array.isArray(e.roles)?e.roles.includes(r||`guest`):!1),y=(0,a.useRef)(null),b=(0,a.useRef)(null),[x,S]=(0,a.useState)(g.length);(0,a.useEffect)(()=>{let e=()=>{let e=y.current,t=b.current;if(!e||!t)return;let n=e.clientWidth;if(n===0)return;let r=t.querySelectorAll(`[data-measure-tab]`);if(r.length===0){S(g.length);return}let i=0,a=!0;for(let e=0;e<r.length;e++)if(i+=r[e].offsetWidth+(e>0?40:0),i>n){a=!1;break}if(a){S(g.length);return}let o=0,s=0;for(let e=0;e<r.length;e++){let t=r[e].offsetWidth,i=o+t+(e>0?40:0);if(i+52>n)break;o=i,s++}S(Math.max(s,1))},t=requestAnimationFrame(e);if(typeof ResizeObserver>`u`)return()=>cancelAnimationFrame(t);let n=new ResizeObserver(()=>requestAnimationFrame(e));return y.current&&n.observe(y.current),()=>{cancelAnimationFrame(t),n.disconnect()}},[g.map(e=>e.id+e.label).join(`|`),g.length]);let C=g.slice(0,x),w=g.slice(x),T=e=>e.exact?t===e.path:t.startsWith(e.path),E=w.some(e=>T(e));return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{ref:b,"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,l.jsxs)(`span`,{"data-measure-tab":!0,className:`flex items-center gap-2 text-[14.5px] font-semibold shrink-0 pb-3`,children:[(0,l.jsx)(t,{className:`w-[18px] h-[18px]`}),e.label]},e.path||e.id)})}),(0,l.jsxs)(`div`,{ref:y,className:`w-full flex items-center gap-6 md:gap-10 mb-8 border-b border-[var(--panel-border)] px-1 whitespace-nowrap relative`,children:[C.map(e=>{let t=T(e),n=e.icon;return(0,l.jsxs)(u.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,l.jsx)(n,{className:`w-[18px] h-[18px]`}),e.label]},e.path||e.id)}),w.length>0&&(0,l.jsxs)(`div`,{className:`relative shrink-0 ml-auto`,ref:c,children:[(0,l.jsx)(`button`,{onClick:()=>s(!i),className:`flex items-center justify-center transition-all duration-300 pb-3 -mb-[1px] border-b-2 cursor-pointer ${E?`text-accent border-accent`:`text-foreground/50 hover:text-foreground/80 border-transparent`}`,title:`More items`,children:(0,l.jsx)(n.J,{className:`w-5 h-5`})}),(0,l.jsx)(n.a,{children:i&&(0,l.jsx)(n.i.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] bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] rounded-2xl shadow-xl z-50 flex flex-col py-2 overflow-hidden`,children:w.map(e=>{let t=T(e),n=e.icon;return(0,l.jsxs)(u.Link,{to:e.path||`/`,onClick:()=>s(!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,l.jsx)(n,{className:`w-4 h-4`}),e.label]},e.path||e.id)})})})]})]})]})}function O(){let{user:e,refreshUser:t}=m(),[r,i]=(0,a.useState)(e?.displayName||``),[u,d]=(0,a.useState)(e?.email||``),[f,p]=(0,a.useState)(e?.photoURL||``),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(null),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(``),[C,w]=(0,a.useState)(!1),[T,E]=(0,a.useState)(!1),[D,O]=(0,a.useState)(!0);a.default.useEffect(()=>{i(e?.displayName||``),d(e?.email||``),p(e?.photoURL||``)},[e?.uid,e?.displayName,e?.email,e?.photoURL]);let k=async t=>{if(e)try{let r=[`mem_files`,`admin_files`];(await(0,o.getDocs)((0,o.collection)(n.Tt,`sys_tabs`))).forEach(e=>{let t=e.data(),n=(t.tabName||e.id).toLowerCase().replace(/[^a-z0-9]+/g,`_`);t.pageType===`shared`&&r.push(`mem_${n}_records`),t.pageType===`admin`&&r.push(`admin_${n}_records`)});for(let i of r)try{let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,i),(0,o.where)(`uid`,`==`,e.uid)));if(r.empty)continue;let a=(0,o.writeBatch)(n.Tt);r.docs.forEach(e=>a.update(e.ref,{creatorAvatar:t})),await a.commit()}catch{}}catch(e){console.error(`Error propagating avatar to records:`,e)}};return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Profile Settings`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/profile`]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 animate-in fade-in duration-500 pb-20`,children:[(0,l.jsx)(`div`,{className:`flex justify-start`,children:(0,l.jsx)(ee,{})}),(0,l.jsx)(n.a,{children:_&&(0,l.jsxs)(n.i.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,l.jsx)(n.nt,{className:`w-5 h-5 shrink-0`}):(0,l.jsx)(n.rt,{className:`w-5 h-5 shrink-0`}),(0,l.jsx)(`span`,{className:`text-[14px] font-semibold tracking-wide leading-relaxed`,children:_.text})]})}),(0,l.jsx)(`form`,{onSubmit:async i=>{if(i.preventDefault(),e){g(!0),v(null);try{r!==e.displayName&&await(0,s.updateProfile)(e,{displayName:r});let i=!1;if(u!==e.email){let t=await(0,s.fetchSignInMethodsForEmail)(n.wt,u);if(t&&t.length>0)throw Error(`An account with this email already exists.`);await(0,s.verifyBeforeUpdateEmail)(e,u),i=!0}if(y){if(y!==x)throw Error(`Passwords do not match.`);if(y.length<6)throw Error(`Password must be at least 6 characters.`);await(0,s.updatePassword)(e,y),b(``),S(``)}await t(),v(i?{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,l.jsxs)(`div`,{className:`glass-panel w-full p-8 md:p-12 rounded-3xl border border-[var(--panel-border)] shadow-2xl space-y-8 min-h-[500px]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-6 pb-6 border-b border-[var(--panel-border)]/50`,children:[(0,l.jsxs)(`div`,{className:`w-24 h-24 md:w-28 md:h-28 rounded-full glass-panel border-4 border-[var(--panel-border)] shadow-xl bg-accent/10 flex items-center justify-center relative overflow-hidden shrink-0 group transition-transform duration-300 hover:scale-[1.02]`,children:[(T||f&&D&&!C)&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-accent/5 backdrop-blur-sm z-10`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),f&&!C?(0,l.jsx)(`img`,{src:f,alt:`Avatar`,className:`w-full h-full object-cover transition-opacity duration-300 ${D?`opacity-0`:`opacity-100`}`,onLoad:()=>O(!1),onError:()=>{w(!0),O(!1)}}):(0,l.jsx)(n.d,{className:`w-10 h-10 md:w-12 md:h-12 text-accent`}),!T&&(0,l.jsxs)(`div`,{className:`absolute inset-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2 z-10 backdrop-blur-sm`,children:[(0,l.jsxs)(`label`,{className:`flex flex-col items-center justify-center cursor-pointer p-2 rounded-full hover:bg-white/20 transition-colors text-white`,title:`Upload Photo`,children:[(0,l.jsx)(n.ut,{className:`w-5 h-5`}),(0,l.jsx)(`input`,{type:`file`,accept:`image/*`,onChange:async r=>{let i=r.target.files?.[0];if(!(!i||!e)){if(i.size>2*1024*1024){v({text:`File too large. Please select an image under 2MB.`,type:`error`});return}E(!0),w(!1),O(!0);try{let r=(0,c.ref)(n.Dt,`user_avatars/${e.uid}/file.png`);await(0,c.uploadBytes)(r,i,{customMetadata:{ownerId:e.uid}});let a=await(0,c.getDownloadURL)(r);await(0,s.updateProfile)(e,{photoURL:a}),await(0,o.updateDoc)((0,o.doc)(n.Tt,`user_profiles`,e.uid),{avatar:a}),p(a),await t(),k(a),v({text:`Avatar successfully updated!`,type:`success`})}catch(e){console.error(e),v({text:`Failed to upload photo.`,type:`error`})}finally{E(!1)}}},className:`hidden`})]}),f&&(0,l.jsx)(`button`,{type:`button`,onClick:async()=>{if(e){E(!0),w(!1),O(!1);try{await(0,c.deleteObject)((0,c.ref)(n.Dt,`user_avatars/${e.uid}/file.png`)).catch(e=>console.error(e)),await(0,s.updateProfile)(e,{photoURL:``}),await(0,o.updateDoc)((0,o.doc)(n.Tt,`user_profiles`,e.uid),{avatar:``}),p(``),await t(),k(``),v({text:`Avatar removed.`,type:`success`})}catch(e){console.error(e),v({text:`Failed to delete photo.`,type:`error`})}finally{E(!1)}}},className:`p-2 rounded-full hover:bg-red-500/80 text-white transition-colors`,title:`Delete Photo`,children:(0,l.jsx)(n.h,{className:`w-5 h-5`})})]})]}),(0,l.jsxs)(`div`,{className:`flex-1 text-left`,children:[(0,l.jsx)(`h3`,{className:`font-extrabold text-2xl text-foreground mb-1`,children:r||`Firebase OS User`}),(0,l.jsx)(`div`,{className:`text-[12px] font-mono uppercase tracking-widest text-accent bg-accent/10 px-2.5 py-1 rounded-md border border-accent/20 inline-block`,children:e?.emailVerified?`Verified Account`:`Unverified`}),(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/40 mt-2 font-medium`,children:e?.email})]})]}),(0,l.jsxs)(`div`,{className:`space-y-6`,children:[(0,l.jsx)(`h3`,{className:`text-[16px] font-extrabold text-foreground flex items-center gap-2`,children:`Account Details`}),(0,l.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-5 md:gap-6`,children:[(0,l.jsx)(n.r,{name:`name`,value:r,onChange:e=>i(e.target.value),label:`Display Name`,placeholder:`John Doe`}),(0,l.jsxs)(`div`,{className:`flex flex-col`,children:[(0,l.jsx)(n.r,{name:`email`,type:`email`,value:u,onChange:e=>d(e.target.value),label:`Email Address`,placeholder:`name@example.com`,required:!0}),(0,l.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,l.jsxs)(`div`,{className:`pt-6 border-t border-[var(--panel-border)]/50`,children:[(0,l.jsx)(`h3`,{className:`text-[15px] font-bold text-foreground mb-4 flex items-center gap-2`,children:`Change Password`}),(0,l.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-5 md:gap-6`,children:[(0,l.jsx)(n.r,{name:`password`,type:`password`,label:`New Password`,value:y,onChange:e=>b(e.target.value),placeholder:`Minimum 6 characters`}),(0,l.jsx)(n.r,{name:`confirmPassword`,type:`password`,label:`Confirm Password`,value:x,onChange:e=>S(e.target.value),placeholder:`Repeat password`})]})]}),(0,l.jsx)(`div`,{className:`pt-8 border-t border-[var(--panel-border)]/50 flex justify-start w-full`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:h,className:`px-12 py-3 md:py-2.5 text-[14px] md:text-[15px] font-bold tracking-wide rounded-xl hover:-translate-y-0.5`,children:`Save Changes`})})]})})]})]})}function k(){let[e,t]=(0,a.useState)(!1),[r,i]=(0,a.useState)(null),[o,c]=(0,a.useState)(0),[d,f]=(0,a.useState)(0);return(0,a.useEffect)(()=>{let e;return o>0&&(e=setInterval(()=>c(e=>e-1),1e3)),()=>clearInterval(e)},[o]),(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mb-16 mt-6 md:mt-8`,children:(0,l.jsxs)(n.i.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,l.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,l.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,l.jsx)(n.R,{className:`w-7 h-7 md:w-8 md:h-8 text-accent opacity-90`})}),(0,l.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,l.jsx)(`h3`,{className:`text-2xl md:text-3xl font-extrabold mb-2 md:mb-3 text-foreground tracking-tight`,children:`Reset Password`}),(0,l.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Enter your email to receive a recovery link.`})]}),r&&(0,l.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:r}),(0,l.jsxs)(`form`,{className:`space-y-4 text-left max-w-[360px] mx-auto`,onSubmit:async e=>{e.preventDefault(),t(!0),i(null);let r=new FormData(e.currentTarget).get(`email`);try{await(0,s.sendPasswordResetEmail)(n.wt,r)}catch(e){console.error(e)}finally{i(`If an account exists, a password reset link has been sent. Please check your inbox (and spam folder).`);let e=d+1;f(e),c(e===1?60:120),t(!1)}},children:[(0,l.jsx)(n.r,{name:`email`,label:`Work Email`,type:`email`,placeholder:`name@company.com`,required:!0}),(0,l.jsx)(`div`,{className:`pt-2`,children:(0,l.jsx)(n.n,{type:`submit`,className:`w-full py-2.5 md:py-3 text-[14px] font-bold tracking-wide rounded-xl md:rounded-xl transition-all ${o>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:o>0,children:o>0?`Resend link in ${(e=>`${Math.floor(e/60)}:${(e%60).toString().padStart(2,`0`)}`)(o)}`:d>0?`Resend reset password link`:`Send Reset Link`})})]}),(0,l.jsx)(`div`,{className:`mt-6 pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:(0,l.jsxs)(u.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,l.jsx)(n.gt,{className:`w-4 h-4 mr-2`}),`Back to Sign In`]})})]})})}function A(){let{user:e,userRole:t}=m(),[r,i]=(0,a.useState)(!0),s=(0,u.useNavigate)(),{id:d}=(0,u.useParams)(),[f,p]=(0,a.useState)([]),[h,g]=(0,a.useState)(null),[_,v]=(0,a.useState)(!1),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(!1),C=d?f.find(e=>e.id===d)||null:f.length>0?f[0]:null,w=e=>{s(e?`/users/${e.id}`:`/users`)};(0,a.useEffect)(()=>{i(!0);let e=(0,o.onSnapshot)((0,o.collection)(n.Tt,`user_profiles`),e=>{let t=[];e.forEach(e=>{t.push({id:e.id,...e.data()})}),p(t),i(!1),!d&&t.length>0&&s(`/users/${t[0].id}`,{replace:!0})},e=>{console.error(`Error fetching users:`,e),i(!1)});return()=>e()},[d,s]);let T=f.find(t=>t.id===e?.uid),E=e=>e.id===T?.id?!1:e.role!==`admin`||!T?.createdAt?!0:e.createdAt?new Date(T.createdAt).getTime()<=new Date(e.createdAt).getTime():!1,D=async(e,r)=>{if(!(t!==`admin`||!E(e)))try{await(0,o.updateDoc)((0,o.doc)(n.Tt,`user_profiles`,e.id),{role:r?`admin`:null}),g({text:`User role updated successfully`,type:`success`}),setTimeout(()=>g(null),3e3)}catch(e){g({text:e.message,type:`error`}),setTimeout(()=>g(null),3e3)}},O=async(e,r)=>{if(!(t!==`admin`||!E(e)))try{await(0,o.updateDoc)((0,o.doc)(n.Tt,`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)}},k=async()=>{if(v(!1),!(!C||!E(C)||y===C.displayName))try{await(0,o.updateDoc)((0,o.doc)(n.Tt,`user_profiles`,C.id),{displayName:y}),g({text:`Name updated successfully`,type:`success`}),setTimeout(()=>g(null),3e3)}catch(e){g({text:e.message,type:`error`}),setTimeout(()=>g(null),3e3)}},A=async e=>{let t=e.target.files?.[0];if(!(!t||!C||!E(C))){if(t.size>2*1024*1024){g({text:`File too large.`,type:`error`});return}S(!0);try{let e=(0,c.ref)(n.Dt,`user_avatars/${C.id}/file.png`);await(0,c.uploadBytes)(e,t);let r=await(0,c.getDownloadURL)(e);await(0,o.updateDoc)((0,o.doc)(n.Tt,`user_profiles`,C.id),{avatar:r}),g({text:`Avatar successfully updated.`,type:`success`}),setTimeout(()=>g(null),3e3)}catch{g({text:`Failed to upload photo.`,type:`error`})}S(!1)}},[te,j]=(0,a.useState)(!1);return(0,a.useEffect)(()=>{let e;return r&&f.length===0?e=setTimeout(()=>j(!0),150):j(!1),()=>clearTimeout(e)},[r,f.length]),r&&f.length===0?te?(0,l.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,l.jsx)(n.M,{className:`w-8 h-8 animate-spin text-accent`})}):null:(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Users`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/users`]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 animate-in fade-in duration-500 pb-20`,children:[(0,l.jsx)(n.a,{children:h&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:`p-4 text-[14px] font-medium border ${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)]`} rounded-xl flex items-center gap-2`,children:[h.type===`success`&&(0,l.jsx)(n.nt,{className:`w-4 h-4 shrink-0`}),h.text]})}),(0,l.jsx)(`div`,{className:`flex justify-start`,children:(0,l.jsx)(ee,{})}),(0,l.jsx)(`div`,{className:`glass-panel rounded-3xl border border-[var(--panel-border)] shadow-sm`,children:f.length===0?(0,l.jsx)(`div`,{className:`p-8 text-center text-foreground/50 text-[14px]`,children:`No members found.`}):(0,l.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 min-h-[500px]`,children:[(0,l.jsxs)(`div`,{className:`md:col-span-1 border-r md:border-r-[var(--panel-border)] border-b md:border-b-0 border-[var(--panel-border)] flex flex-col hide-scrollbar bg-black/5 dark:bg-white/5 rounded-t-3xl md:rounded-tr-none md:rounded-l-3xl`,children:[(0,l.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,l.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-2`,children:f.map(e=>(0,l.jsxs)(`div`,{onClick:()=>w(e),className:`p-4 py-5 rounded-2xl border transition-all flex items-center gap-4 cursor-pointer ${C?.id===e.id?`bg-accent/10 border-accent/40 shadow-sm`:`glass-panel border-transparent hover:border-[var(--panel-border)]`} ${e.inactive?`opacity-50 grayscale`:``}`,children:[(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full overflow-hidden bg-accent/20 shrink-0 flex items-center justify-center border border-[var(--panel-border)]`,children:e.avatar||e.photoURL?(0,l.jsx)(`img`,{src:e.avatar||e.photoURL,alt:``,className:`w-full h-full object-cover`}):(0,l.jsx)(n.d,{className:`w-5 h-5 text-accent`})}),(0,l.jsxs)(`div`,{className:`flex flex-col truncate`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] truncate`,children:e.displayName||`No Name`}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/50 truncate font-mono mt-0.5`,children:e.email})]})]},e.id))})]}),(0,l.jsx)(`div`,{className:`md:col-span-2 flex flex-col p-6 md:p-10 relative`,children:C?(0,l.jsxs)(`div`,{className:`animate-in fade-in duration-300 w-full max-w-lg`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-6 md:gap-8 mb-10`,children:[(0,l.jsxs)(`div`,{className:`w-24 h-24 rounded-full glass-panel border-4 border-[var(--panel-border)] shadow-xl bg-accent/10 flex items-center justify-center relative overflow-hidden shrink-0 group`,children:[x?(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`}):C.avatar||C.photoURL?(0,l.jsx)(`img`,{src:C.avatar||C.photoURL,alt:`Avatar`,className:`w-full h-full object-cover`}):(0,l.jsx)(n.d,{className:`w-10 h-10 text-accent`}),!x&&E(C)&&(0,l.jsx)(`div`,{className:`absolute inset-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center z-10 backdrop-blur-md`,children:(0,l.jsxs)(`label`,{className:`flex flex-col items-center justify-center cursor-pointer p-2 hover:bg-white/20 transition-colors text-white rounded-full`,title:`Upload Photo`,children:[(0,l.jsx)(n.ut,{className:`w-5 h-5`}),(0,l.jsx)(`input`,{type:`file`,accept:`image/*`,onChange:A,className:`hidden`})]})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col flex-1 w-full relative`,children:[_?(0,l.jsx)(`input`,{autoFocus:!0,value:y,onChange:e=>b(e.target.value),onBlur:k,onKeyDown:e=>e.key===`Enter`&&k(),className:`text-2xl md:text-3xl font-extrabold mb-1 bg-transparent border-b-2 border-accent outline-none text-foreground w-full py-1`}):(0,l.jsx)(`h3`,{onDoubleClick:()=>{E(C)&&(b(C.displayName||``),v(!0))},className:`text-2xl md:text-3xl font-extrabold mb-1 select-none ${E(C)?`cursor-pointer hover:text-accent transition-colors`:``}`,title:E(C)?`Double-click to edit`:``,children:C.displayName||`No Name`}),(0,l.jsx)(`p`,{className:`text-[14px] font-mono text-foreground/50`,children:C.email}),!E(C)&&C.id!==T?.id&&(0,l.jsx)(`div`,{className:`mt-3 inline-block self-start px-3 py-1.5 rounded-lg bg-foreground/5 border border-[var(--panel-border)] text-[11px] font-bold text-foreground/50 tracking-wide uppercase`,children:`Privileged Admin Account`})]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,l.jsxs)(`div`,{className:`p-4 rounded-2xl glass-panel border border-[var(--panel-border)] flex items-center justify-between`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] text-foreground`,children:`Admin Access`}),(0,l.jsx)(`span`,{className:`text-[12px] text-foreground/50`,children:`Toggle system privileges`})]}),(0,l.jsx)(`button`,{type:`button`,disabled:!E(C),onClick:()=>D(C,C.role!==`admin`),className:`relative inline-flex h-7 w-12 items-center rounded-full transition-colors focus:outline-none shadow-inner ${C.role===`admin`?`bg-accent`:`bg-foreground/20`} ${E(C)?`cursor-pointer`:`opacity-50 cursor-not-allowed`}`,children:(0,l.jsx)(`span`,{className:`inline-block h-5 w-5 transform rounded-full bg-white transition-transform shadow-md ${C.role===`admin`?`translate-x-6`:`translate-x-1`}`})})]}),(0,l.jsxs)(`div`,{className:`p-4 rounded-2xl glass-panel border flex items-center justify-between ${C.inactive?`border-amber-500/30 bg-amber-500/5`:`border-red-500/20 bg-red-500/5`}`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] ${C.inactive?`text-amber-500`:`text-red-500`}`,children:C.inactive?`Reactivate User`:`Deactivate User`}),(0,l.jsx)(`span`,{className:`text-[12px] ${C.inactive?`text-amber-500/70`:`text-red-500/70`}`,children:`Block access to this app`})]}),(0,l.jsx)(`button`,{type:`button`,disabled:!E(C),onClick:()=>O(C,!C.inactive),className:`relative inline-flex h-7 w-12 items-center rounded-full transition-colors focus:outline-none shadow-inner ${C.inactive?`bg-amber-500`:`bg-red-500/20`} ${E(C)?`cursor-pointer`:`opacity-50 cursor-not-allowed`}`,children:(0,l.jsx)(`span`,{className:`inline-block h-5 w-5 transform rounded-full bg-white transition-transform shadow-md ${C.inactive?`translate-x-6`:`translate-x-1`}`})})]})]})]}):(0,l.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center opacity-30 pointer-events-none`,children:[(0,l.jsx)(n.u,{className:`w-12 h-12 mb-4`}),(0,l.jsx)(`p`,{className:`font-bold tracking-widest uppercase text-[12px]`,children:`Select a User`})]})})]})})]})]})}function te({isOpen:e,title:t,message:r,confirmText:i=`Delete`,cancelText:a=`Cancel`,onConfirm:o,onCancel:s,isProcessing:c=!1,disableConfirm:u=!1}){return(0,l.jsx)(n.a,{children:e&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!c&&s(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`w-full max-w-[400px] p-6 rounded-3xl glass-panel border border-[var(--panel-border)] shadow-2xl relative z-10 text-center`,children:(0,l.jsxs)(`div`,{className:`w-full flex flex-col items-center`,children:[(0,l.jsx)(`h3`,{className:`text-xl font-extrabold mb-2 text-foreground tracking-tight`,children:t}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 leading-relaxed mb-6`,children:r}),(0,l.jsxs)(`div`,{className:`flex items-center gap-3 w-full`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:s,disabled:c,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:a}),(0,l.jsx)(n.n,{onClick:o,disabled:c||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:c?(0,l.jsx)(n.M,{className:`w-5 h-5 animate-spin mx-auto`}):i})]})]})})]})})}var j=[`pages`,`forms`,`drive`,`users`,`theme`,`submissions`,`requests`,`settings`,`profile`,`support`],ne={pages:`Pages`,forms:`Forms`,drive:`Drive`,users:`Users`,theme:`Theme`,submissions:`Submissions`,requests:`Requests`,settings:`Settings`,profile:`Profile`,support:`Request Support`},M=new Set([`home`]),N=new Set([`settings`]);function P(){let[e,t]=(0,a.useState)(`menu`),[r,i]=(0,a.useState)({}),[s,c]=(0,a.useState)({}),[u,d]=(0,a.useState)(g),[f,p]=(0,a.useState)(v),[m,h]=(0,a.useState)(!1),[y,b]=(0,a.useState)(null),[x,S]=(0,a.useState)(!1);(0,a.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.collection)(n.Tt,`sys_pages`),e=>{let t={};e.forEach(e=>{let n=e.data();t[e.id]={id:e.id,title:n.pageName||n.title||e.id,path:n.route||(e.id===`home`?`/`:`/`+e.id),type:`public`,isSystem:[`home`,`templates`,`contact`,`setup`].includes(e.id)}}),t.setup||={id:`setup`,title:`Setup`,path:`/setup`,type:`public`,isSystem:!0},t.templates||={id:`templates`,title:`Templates`,path:`/templates`,type:`public`,isSystem:!0},t.contact||={id:`contact`,title:`Contact`,path:`/contact`,type:`public`,isSystem:!0},i(t)}),t=(0,o.onSnapshot)((0,o.collection)(n.Tt,`sys_tabs`),e=>{let t={};e.forEach(e=>{let n=e.data();t[e.id]={id:e.id,title:n.pageName||n.tabName||n.title||ne[e.id]||e.id,path:n.route||`/`+e.id,type:n.pageType||`admin`,isSystem:j.includes(e.id)}}),j.forEach(e=>{t[e]||(t[e]={id:e,title:ne[e]||e,path:`/`+e,type:`admin`,isSystem:!0})}),c(t)}),r=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`page_order`),e=>{d(e.exists()?_(e.data().order||[]):g)}),a=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`tab_order`),e=>{p(e.exists()?_(e.data().order||[]):v)});return()=>{e(),t(),r(),a()}},[]);let C=async(e,t)=>{if((t?N:M).has(e))return;let i=t?f:u,a=t?`tab_order`:`page_order`,c=i.filter(e=>(t?s:r)[e.id]||(t?j.includes(e.id):[`home`,`contact`].includes(e.id))),l=c.some(t=>t.id===e)?c.map(t=>t.id===e?{...t,hidden:!t.hidden}:t):[...c,{id:e,hidden:!0}];await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,a),{order:l})},w=(e,t)=>{e.isSystem||b({info:e,isTab:t})},T=async()=>{if(!y)return;S(!0);let e=y.isTab?`sys_tabs`:`sys_pages`,t=y.isTab?`tab_order`:`page_order`,r=y.isTab?f:u;try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,e,y.info.id));let i=r.filter(e=>e.id!==y.info.id);await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,t),{order:i})}catch(e){console.error(`Delete failed`,e)}S(!1),b(null)},E=async(e,t,i)=>{let a=e?f:u,c=e?s:r,l=e?`tab_order`:`page_order`,d=a.filter(t=>c[t.id]||(e?j.includes(t.id):[`home`,`contact`].includes(t.id)));Object.keys(c).forEach(e=>{d.some(t=>t.id===e)||d.push({id:e,hidden:!1})});let p=d.findIndex(e=>e.id===t);if(p===-1)return;let m=+(!e&&d[0]?.id===`home`),h=i===`up`?Math.max(m,p-1):Math.min(d.length-1,p+1);if(p===h)return;let g=[...d],[_]=g.splice(p,1);g.splice(h,0,_),await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,l),{order:g})},D=async()=>{if(!m){h(!0);try{let e=new Set(g.map(e=>e.id)),t=new Set(v.map(e=>e.id)),r=u.filter(t=>!e.has(t.id)),i=f.filter(e=>!t.has(e.id)),a=[...r.map(e=>({...e,hidden:!1})),...g],s=[...i.map(e=>({...e,hidden:!1})),...v],c=(0,o.writeBatch)(n.Tt);c.set((0,o.doc)(n.Tt,`sys_configs`,`page_order`),{order:a}),c.set((0,o.doc)(n.Tt,`sys_configs`,`tab_order`),{order:s}),await c.commit()}finally{setTimeout(()=>h(!1),600)}}},O=e=>{let t=e?f:u,n=e?s:r,i=t.filter(t=>n[t.id]||(e?j.includes(t.id):[`home`,`contact`].includes(t.id))),a=new Set(i.map(e=>e.id)),o=Object.keys(n).filter(e=>!a.has(e)).map(e=>({id:e,hidden:!1})),c=[...i,...o];return e||(c=c.filter(e=>e.id!==`home`)),c};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Settings`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/settings`]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 animate-in fade-in duration-500`,children:[(0,l.jsx)(`div`,{className:`flex justify-start`,children:(0,l.jsx)(ee,{})}),(0,l.jsxs)(`div`,{className:`glass-panel rounded-3xl border border-[var(--panel-border)] shadow-sm grid grid-cols-1 md:grid-cols-3 min-h-[500px]`,children:[(0,l.jsxs)(`div`,{className:`md:col-span-1 border-r md:border-r-[var(--panel-border)] border-b md:border-b-0 border-[var(--panel-border)] flex flex-col bg-black/5 dark:bg-white/5 rounded-t-3xl md:rounded-tr-none md:rounded-l-3xl`,children:[(0,l.jsx)(`div`,{className:`p-6 pb-4 font-bold text-[13px] text-foreground/40 uppercase tracking-widest`,children:`Configuration`}),(0,l.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-4 pb-4 space-y-1`,children:[(0,l.jsxs)(`button`,{onClick:()=>t(`menu`),className:`w-full p-3 rounded-xl transition-all flex items-center gap-3 cursor-pointer ${e===`menu`?`bg-accent/10 text-accent font-bold`:`bg-transparent text-foreground/70 hover:bg-foreground/5 hover:text-foreground font-medium`}`,children:[(0,l.jsx)(n.O,{className:`w-4 h-4 shrink-0`}),(0,l.jsx)(`span`,{className:`text-[14px]`,children:`Menu Settings`})]}),(0,l.jsxs)(`button`,{onClick:()=>t(`tabs`),className:`w-full p-3 rounded-xl transition-all flex items-center gap-3 cursor-pointer ${e===`tabs`?`bg-accent/10 text-accent font-bold`:`bg-transparent text-foreground/70 hover:bg-foreground/5 hover:text-foreground font-medium`}`,children:[(0,l.jsx)(n.pt,{className:`w-4 h-4 shrink-0`}),(0,l.jsx)(`span`,{className:`text-[14px]`,children:`Tabs Settings`})]})]})]}),(0,l.jsx)(`div`,{className:`md:col-span-2 flex flex-col p-6 md:p-10`,children:(0,l.jsxs)(`div`,{className:`animate-in fade-in duration-300 w-full`,children:[(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-8`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col`,children:[(0,l.jsx)(`h3`,{className:`text-2xl md:text-3xl font-extrabold text-foreground tracking-tighter mb-2`,children:e===`menu`?`Menu Settings`:`Dashboard Tabs`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/60 max-w-xl`,children:e===`menu`?`Reorder or hide public menu items. Changes take effect instantly for all visitors.`:`Manage visibility and order of all internal dashboard tabs.`})]}),(0,l.jsx)(`button`,{onClick:D,disabled:m,title:`Reset order and visibility to defaults`,className:`p-3 h-fit bg-foreground/5 hover:bg-foreground/10 text-foreground/70 active:scale-95 disabled:opacity-50 disabled:pointer-events-none rounded-xl transition-all font-bold text-[13px] flex items-center justify-center border border-transparent hover:border-[var(--panel-border)] shadow-sm shrink-0`,children:m?(0,l.jsx)(n.M,{className:`w-5 h-5 text-foreground/50 animate-spin`}):(0,l.jsx)(n.x,{className:`w-5 h-5 text-foreground/50`})})]}),(e=>{let t=e?s:r,i=e?N:M,a=O(e);return(0,l.jsx)(`div`,{className:`flex flex-col gap-3`,children:a.map((r,o)=>{let s=t[r.id],c=s?.title||ne[r.id]||r.id,u=s?.path||`/`+r.id,d=s?.isSystem??j.includes(r.id),f=i.has(r.id),p=o===0,m=o===a.length-1;return(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-4 glass-panel border border-[var(--panel-border)] rounded-2xl transition-all duration-200 ${r.hidden?`opacity-40`:`opacity-100`}`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col items-center w-6`,children:[(0,l.jsx)(`button`,{disabled:p,onClick:()=>E(e,r.id,`up`),className:`text-foreground/40 hover:text-accent disabled:opacity-20`,children:(0,l.jsx)(n.it,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{disabled:m,onClick:()=>E(e,r.id,`down`),className:`text-foreground/40 hover:text-accent disabled:opacity-20 -mt-1`,children:(0,l.jsx)(n.st,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col`,children:[(0,l.jsx)(`span`,{className:`font-bold text-foreground text-[14px]`,children:c}),(0,l.jsx)(`span`,{className:`text-[12px] font-mono text-foreground/50`,children:u})]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-3`,children:[!f&&(0,l.jsx)(`button`,{onClick:()=>C(r.id,e),title:r.hidden?`Show this page`:`Hide this page`,className:`p-2 rounded-xl transition-colors ${r.hidden?`hover:bg-foreground/5 text-foreground/40`:`hover:bg-accent/10 text-accent`}`,children:r.hidden?(0,l.jsx)(n.q,{className:`w-4 h-4`}):(0,l.jsx)(n.K,{className:`w-4 h-4`})}),s&&!d&&(0,l.jsx)(`button`,{onClick:()=>w(s,e),className:`p-2 rounded-xl hover:bg-red-500/10 text-foreground/40 hover:text-red-500 transition-colors`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})})]})]},r.id)})})})(e===`tabs`)]})})]})]})]}),(0,l.jsx)(te,{isOpen:!!y,onCancel:()=>b(null),onConfirm:T,title:`Delete Item`,message:`Are you sure you want to delete "${y?.info?.title??``}"? This cannot be undone.`,confirmText:`Delete`,isProcessing:x})]})}function F(){let[e,t]=(0,a.useState)([]),[r,i]=(0,a.useState)(!0),[s,c]=(0,a.useState)(null),[u,d]=(0,a.useState)(!1),[f,p]=(0,a.useState)(null);(0,a.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,`user_submissions`),(0,o.orderBy)(`submittedAt`,`desc`)),async e=>{let r=[];for(let t of e.docs){let e=t.data(),i=``;if(e.uid&&e.uid!==`guest`)try{let t=await(0,o.getDoc)((0,o.doc)(n.Tt,`user_profiles`,e.uid));if(t.exists()){let n=t.data();n.avatar&&(i=n.avatar),n.name&&!e.name&&(e.name=n.name),n.email&&!e.email&&(e.email=n.email)}}catch(e){console.error(`Failed to fetch avatar`,e)}r.push({...e,id:t.id,avatarUrl:i})}t(r),i(!1)},e=>{console.error(`Error fetching submissions:`,e),i(!1)});return()=>e()},[]);let m=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)},h=e=>{c(t=>t===e?null:e)},g=async(e,t=!1)=>{p(e);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,`user_submissions`,e),{isArchived:!t}),!t&&s===e&&c(null)}catch(e){console.error(`Failed to archive/unarchive`,e)}p(null)},_=e.filter(e=>!e.isArchived),v=e.filter(e=>e.isArchived);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Form Submissions`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/submissions`]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-4 flex-1 min-h-[500px]`,children:[(0,l.jsx)(`div`,{className:`flex justify-start`,children:(0,l.jsx)(ee,{})}),(0,l.jsxs)(`div`,{className:`w-full flex-1 flex flex-col glass-panel rounded-3xl p-6 md:p-10 relative overflow-hidden border border-[var(--panel-border)] shadow-2xl bg-[var(--panel-bg)]`,children:[(0,l.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,l.jsx)(`div`,{className:`relative z-10 flex-1 flex flex-col`,children:r?(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[500px]`,children:(0,l.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`})}):e.length===0?(0,l.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center p-8`,children:[(0,l.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,l.jsx)(n.D,{className:`w-6 h-6 outline-none`})}),(0,l.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground mb-2`,children:`No Submissions`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/50 font-medium max-w-md`,children:`Try submitting a form on the public layout to see it appear here.`})]}):(0,l.jsxs)(`div`,{className:`flex flex-col gap-3 pb-8`,children:[_.length===0&&(0,l.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,l.jsx)(`p`,{className:`text-[14px] font-bold text-foreground/50`,children:`All submissions have been archived.`})}),(0,l.jsx)(n.a,{children:_.map((e,t)=>{let r=s===e.id;return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:t*.05},className:`glass-panel border border-[var(--panel-border)] rounded-2xl flex flex-col overflow-hidden hover:border-accent/40 transition-all duration-300`,children:[(0,l.jsxs)(`div`,{role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&h(e.id)},onClick:()=>h(e.id),className:`w-full flex items-center justify-between p-4 md:px-6 hover:bg-foreground/[0.02] transition-colors text-left cursor-pointer`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-4 flex-1 min-w-0`,children:[(0,l.jsx)(`div`,{className:`relative shrink-0`,children:(0,l.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-accent/10 text-accent flex items-center justify-center font-bold border border-accent/20 shadow-sm`,children:(0,l.jsx)(n.k,{className:`w-4 h-4`})})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 justify-center`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] md:text-[15px] text-foreground truncate`,children:e.name||e.full_name||`Anonymous Submission`}),e.formId&&(0,l.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:e.formId.replace(/_/g,` `)})]}),(0,l.jsx)(`span`,{className:`text-[13px] text-foreground/50 truncate flex items-center gap-1.5 font-medium mt-0.5`,children:e.email||e.contactEmail||`No email provided`})]})]}),(0,l.jsxs)(`div`,{className:`hidden md:flex items-center gap-4 ml-6 shrink-0`,children:[(0,l.jsx)(`div`,{className:`text-[12px] font-medium text-foreground/40`,children:m(e.submittedAt)}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),g(e.id,!1)},disabled:f===e.id,className:`p-1.5 rounded-lg text-foreground/30 hover:text-orange-500 hover:bg-orange-500/10 transition-colors`,title:`Archive Submission`,children:f===e.id?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(n._t,{className:`w-4 h-4`})}),(0,l.jsx)(`div`,{className:`p-1.5 rounded-xl glass-panel transition-transform ${r?`rotate-180 bg-foreground/5`:``}`,children:(0,l.jsx)(n.st,{className:`w-4 h-4 text-foreground/50`})})]})]}),(0,l.jsx)(n.a,{children:r&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-4 md:p-6 pt-0 mt-2 border-t border-[var(--panel-border)]/30`,children:[(0,l.jsx)(`div`,{className:`md:hidden text-[12px] font-medium text-foreground/40 w-fit mb-4`,children:m(e.submittedAt)}),Object.entries(e).filter(([e])=>![`id`,`uid`,`submittedAt`,`avatarUrl`,`name`,`full_name`,`email`,`contactEmail`].includes(e)&&!e.toLowerCase().startsWith(`submitter`)&&e.toLowerCase()!==`formid`).map(([e,t])=>(0,l.jsxs)(`div`,{className:`bg-foreground/[0.02] rounded-2xl p-5 border border-[var(--panel-border)] relative mb-3`,children:[(0,l.jsx)(`div`,{className:`flex items-center gap-2 mb-3 text-foreground/60 w-full justify-between`,children:(0,l.jsx)(`div`,{className:`flex items-center gap-2 text-accent`,children:(0,l.jsx)(`span`,{className:`text-[12px] font-bold uppercase tracking-widest text-accent`,children:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())})})}),(0,l.jsx)(`p`,{className:`text-[14px] md:text-[15px] text-foreground/80 leading-relaxed whitespace-pre-wrap font-medium`,children:typeof t==`boolean`?t?`Yes`:`No`:e.toLowerCase()===`budget`&&t?`$${t}`:String(t||`No data provided`)})]},e))]})})})]},e.id)})}),v.length>0&&(0,l.jsxs)(`div`,{className:`mt-6 pt-4 border-t border-[var(--panel-border)]/30`,children:[(0,l.jsx)(`div`,{className:`flex justify-center`,children:(0,l.jsxs)(`button`,{onClick:()=>d(!u),className:`flex items-center gap-2 text-[11px] font-bold text-foreground/40 hover:text-foreground/70 transition-colors py-2 uppercase tracking-widest outline-none`,children:[u?`Hide`:`View`,` `,v.length,` Archived Submission`,v.length===1?``:`s`,(0,l.jsx)(n.st,{className:`w-3.5 h-3.5 transition-transform duration-300 ${u?`rotate-180`:``}`})]})}),(0,l.jsx)(n.a,{children:u&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4`,children:(0,l.jsx)(`div`,{className:`flex flex-col gap-3`,children:v.map((e,t)=>{let r=s===e.id;return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:t*.05},className:`glass-panel border border-[var(--panel-border)] rounded-2xl flex flex-col overflow-hidden opacity-50 grayscale hover:opacity-100 hover:grayscale-0 hover:border-accent/40 transition-all duration-300`,children:[(0,l.jsxs)(`div`,{role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&h(e.id)},onClick:()=>h(e.id),className:`w-full flex items-center justify-between p-4 md:px-6 hover:bg-foreground/[0.02] transition-colors text-left cursor-pointer`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-4 flex-1 min-w-0`,children:[(0,l.jsx)(`div`,{className:`relative shrink-0 grayscale`,children:(0,l.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-accent/10 text-accent flex items-center justify-center font-bold border border-accent/20 shadow-sm`,children:(0,l.jsx)(n.k,{className:`w-4 h-4`})})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 justify-center`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] md:text-[15px] text-foreground truncate`,children:e.name||e.full_name||`Anonymous Submission`}),e.formId&&(0,l.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:e.formId.replace(/_/g,` `)})]}),(0,l.jsx)(`span`,{className:`text-[13px] text-foreground/50 truncate flex items-center gap-1.5 font-medium mt-0.5`,children:e.email||e.contactEmail||`No email provided`})]})]}),(0,l.jsxs)(`div`,{className:`hidden md:flex items-center gap-6 ml-6 shrink-0`,children:[(0,l.jsx)(`div`,{className:`text-[12px] font-medium text-foreground/40`,children:m(e.submittedAt)}),(0,l.jsx)(`div`,{className:`p-2 rounded-xl glass-panel transition-transform ${r?`rotate-180 bg-foreground/5`:``}`,children:(0,l.jsx)(n.st,{className:`w-4 h-4 text-foreground/50`})})]})]}),(0,l.jsx)(n.a,{children:r&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-4 md:p-6 pt-0 mt-2 border-t border-[var(--panel-border)]/30`,children:[(0,l.jsx)(`div`,{className:`md:hidden text-[12px] font-medium text-foreground/40 w-fit mb-4`,children:m(e.submittedAt)}),Object.entries(e).filter(([e])=>![`id`,`uid`,`submittedAt`,`avatarUrl`,`name`,`full_name`,`email`,`contactEmail`,`isArchived`].includes(e)&&!e.toLowerCase().startsWith(`submitter`)&&e.toLowerCase()!==`formid`).map(([e,t])=>(0,l.jsxs)(`div`,{className:`bg-foreground/[0.02] rounded-2xl p-5 border border-[var(--panel-border)] relative mb-3`,children:[(0,l.jsx)(`div`,{className:`flex items-center gap-2 mb-3 text-foreground/60 w-full justify-between`,children:(0,l.jsx)(`div`,{className:`flex items-center gap-2 text-accent`,children:(0,l.jsx)(`span`,{className:`text-[12px] font-bold uppercase tracking-widest text-accent`,children:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())})})}),(0,l.jsx)(`p`,{className:`text-[14px] md:text-[15px] text-foreground/80 leading-relaxed whitespace-pre-wrap font-medium`,children:typeof t==`boolean`?t?`Yes`:`No`:e.toLowerCase()===`budget`&&t?`$${t}`:String(t||`No data provided`)})]},e)),(0,l.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,l.jsxs)(`button`,{onClick:()=>g(e.id,e.isArchived),disabled:f===e.id,className:`flex items-center gap-2 px-4 py-2.5 rounded-xl text-[13px] font-bold text-foreground/70 hover:text-emerald-500 bg-foreground/5 hover:bg-emerald-500/10 transition-colors border border-transparent shadow-sm`,children:[f===e.id?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(n.vt,{className:`w-4 h-4`}),`Unarchive Submission`]})})]})})})]},e.id)})})})})]})]})})]})]})]})}function I(){let[e,t]=(0,a.useState)([]),[r,i]=(0,a.useState)(!0),[s,c]=(0,a.useState)(null),[d,f]=(0,a.useState)(!1),[p,m]=(0,a.useState)(null);(0,a.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,`user_requests`),(0,o.orderBy)(`submittedAt`,`desc`)),async e=>{let r=[];for(let t of e.docs){let e=t.data(),i=``;if(e.uid&&e.uid!==`guest`)try{let t=await(0,o.getDoc)((0,o.doc)(n.Tt,`user_profiles`,e.uid));if(t.exists()){let n=t.data();(n.avatar||n.photoURL)&&(i=n.avatar||n.photoURL),n.displayName&&!e.name&&(e.name=n.displayName),n.email&&!e.email&&(e.email=n.email),n.email&&!e.contactEmail&&(e.contactEmail=n.email)}}catch(e){console.error(`Failed to fetch avatar`,e)}r.push({...e,id:t.id,avatarUrl:i})}t(r),i(!1)},e=>{console.error(`Error fetching requests:`,e),i(!1)});return()=>e()},[]);let h=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)},g=e=>{c(t=>t===e?null:e)},_=async(e,t=!1)=>{m(e);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,`user_requests`,e),{isArchived:!t}),!t&&s===e&&c(null)}catch(e){console.error(`Failed to archive/unarchive`,e)}m(null)},v=e.filter(e=>!e.isArchived),y=e.filter(e=>e.isArchived);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`User Requests`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/requests`]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-4 flex-1 min-h-[500px]`,children:[(0,l.jsx)(`div`,{className:`flex justify-start`,children:(0,l.jsx)(ee,{})}),(0,l.jsxs)(`div`,{className:`w-full flex-1 flex flex-col glass-panel rounded-3xl p-6 md:p-10 relative overflow-hidden border border-[var(--panel-border)] shadow-2xl bg-[var(--panel-bg)]`,children:[(0,l.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,l.jsx)(`div`,{className:`relative z-10 flex-1 flex flex-col`,children:r?(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[500px]`,children:(0,l.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`})}):e.length===0?(0,l.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center p-8`,children:[(0,l.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,l.jsx)(n.tt,{className:`w-6 h-6 outline-none`})}),(0,l.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground mb-2`,children:`No User Requests`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/50 font-medium max-w-md`,children:`User support tickets will appear here once submitted.`})]}):(0,l.jsxs)(`div`,{className:`flex flex-col gap-3 pb-8`,children:[v.length===0&&(0,l.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,l.jsx)(`p`,{className:`text-[14px] font-bold text-foreground/50`,children:`All requests have been archived.`})}),(0,l.jsx)(n.a,{children:v.map((e,t)=>{let r=s===e.id;return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:t*.05},className:`glass-panel border border-[var(--panel-border)] rounded-2xl flex flex-col overflow-hidden hover:border-accent/40 transition-all duration-300`,children:[(0,l.jsxs)(`div`,{role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&g(e.id)},onClick:()=>g(e.id),className:`w-full flex items-center justify-between p-4 md:px-6 hover:bg-foreground/[0.02] transition-colors text-left cursor-pointer`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-4 flex-1 min-w-0`,children:[(0,l.jsx)(`div`,{className:`relative shrink-0`,children:e.avatarUrl||e.submitterAvatar?(0,l.jsx)(`img`,{src:e.avatarUrl||e.submitterAvatar,alt:e.submitterName||e.name,className:`w-10 h-10 rounded-full object-cover border border-[var(--panel-border)] shadow-sm`}):(0,l.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-accent/10 text-accent flex items-center justify-center font-bold border border-accent/20 shadow-sm uppercase`,children:(e.submitterName||e.name||e.contactEmail||e.email||`U`)[0]})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[e.uid===`guest`?(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] md:text-[15px] text-foreground truncate`,children:e.name||`Anonymous User`}),e.formId&&(0,l.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:e.formId.replace(/_/g,` `)})]}):(0,l.jsxs)(u.Link,{to:`/users/${e.uid}`,onClick:e=>e.stopPropagation(),className:`w-fit font-bold text-[14px] md:text-[15px] text-foreground truncate hover:text-accent flex items-center gap-2`,children:[e.submitterName||e.name||`Anonymous User`,e.formId&&(0,l.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:e.formId.replace(/_/g,` `)})]}),(0,l.jsxs)(`span`,{className:`text-[13px] text-foreground/50 truncate flex items-center gap-1.5 font-medium mt-0.5`,children:[(0,l.jsx)(n.k,{className:`w-3.5 h-3.5`}),` `,e.contactEmail||e.email||`No email provided`]})]})]}),(0,l.jsxs)(`div`,{className:`hidden md:flex items-center gap-4 ml-6 shrink-0`,children:[(0,l.jsx)(`div`,{className:`text-[12px] font-medium text-foreground/40`,children:h(e.submittedAt)}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),_(e.id,!1)},disabled:p===e.id,className:`p-1.5 rounded-lg text-foreground/30 hover:text-orange-500 hover:bg-orange-500/10 transition-colors`,title:`Archive Request`,children:p===e.id?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(n._t,{className:`w-4 h-4`})}),(0,l.jsx)(`div`,{className:`p-1.5 rounded-xl glass-panel transition-transform ${r?`rotate-180 bg-foreground/5`:``}`,children:(0,l.jsx)(n.st,{className:`w-4 h-4 text-foreground/50`})})]})]}),(0,l.jsx)(n.a,{children:r&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-4 md:p-6 pt-0 mt-2 border-t border-[var(--panel-border)]/30`,children:[(0,l.jsx)(`div`,{className:`md:hidden text-[12px] font-medium text-foreground/40 w-fit mb-4`,children:h(e.submittedAt)}),e.topic&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mb-4 text-[13px] text-foreground/70 bg-foreground/5 px-4 py-2.5 rounded-xl w-fit border border-[var(--panel-border)]`,children:[(0,l.jsx)(n.rt,{className:`w-4 h-4 text-accent`}),(0,l.jsx)(`span`,{className:`font-medium text-accent`,children:`Topic:`}),(0,l.jsx)(`span`,{className:`font-bold`,children:e.topic})]}),Object.entries(e).filter(([e])=>![`id`,`uid`,`submittedAt`,`avatarUrl`,`name`,`full_name`,`email`,`contactEmail`,`topic`].includes(e)&&!e.toLowerCase().startsWith(`submitter`)&&e.toLowerCase()!==`formid`).map(([e,t])=>(0,l.jsxs)(`div`,{className:`bg-foreground/[0.02] rounded-2xl p-5 border border-[var(--panel-border)] relative mb-3`,children:[(0,l.jsx)(`div`,{className:`flex items-center gap-2 mb-3 text-foreground/60 w-full justify-between`,children:(0,l.jsx)(`div`,{className:`flex items-center gap-2 text-accent`,children:(0,l.jsx)(`span`,{className:`text-[12px] font-bold uppercase tracking-widest text-accent`,children:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())})})}),(0,l.jsx)(`p`,{className:`text-[14px] md:text-[15px] text-foreground/80 leading-relaxed whitespace-pre-wrap font-medium`,children:typeof t==`boolean`?t?`Yes`:`No`:e.toLowerCase()===`budget`&&t?`$${t}`:String(t||`No data provided`)})]},e))]})})})]},e.id)})}),y.length>0&&(0,l.jsxs)(`div`,{className:`mt-6 pt-4 border-t border-[var(--panel-border)]/30`,children:[(0,l.jsx)(`div`,{className:`flex justify-center`,children:(0,l.jsxs)(`button`,{onClick:()=>f(!d),className:`flex items-center gap-2 text-[11px] font-bold text-foreground/40 hover:text-foreground/70 transition-colors py-2 uppercase tracking-widest outline-none`,children:[d?`Hide`:`View`,` `,y.length,` Archived Request`,y.length===1?``:`s`,(0,l.jsx)(n.st,{className:`w-3.5 h-3.5 transition-transform duration-300 ${d?`rotate-180`:``}`})]})}),(0,l.jsx)(n.a,{children:d&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4`,children:(0,l.jsx)(`div`,{className:`flex flex-col gap-3`,children:y.map((e,t)=>{let r=s===e.id;return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:t*.05},className:`glass-panel border border-[var(--panel-border)] rounded-2xl flex flex-col overflow-hidden opacity-50 grayscale hover:opacity-100 hover:grayscale-0 hover:border-accent/40 transition-all duration-300`,children:[(0,l.jsxs)(`div`,{role:`button`,tabIndex:0,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&g(e.id)},onClick:()=>g(e.id),className:`w-full flex items-center justify-between p-4 md:px-6 hover:bg-foreground/[0.02] transition-colors text-left cursor-pointer`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-4 flex-1 min-w-0`,children:[(0,l.jsx)(`div`,{className:`relative shrink-0 grayscale`,children:e.avatarUrl||e.submitterAvatar?(0,l.jsx)(`img`,{src:e.avatarUrl||e.submitterAvatar,alt:e.submitterName||e.name,className:`w-10 h-10 rounded-full object-cover border border-[var(--panel-border)] shadow-sm`}):(0,l.jsx)(`div`,{className:`w-10 h-10 rounded-full bg-accent/10 text-accent flex items-center justify-center font-bold border border-accent/20 shadow-sm uppercase`,children:(e.submitterName||e.name||e.contactEmail||e.email||`U`)[0]})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[e.uid===`guest`?(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`font-bold text-[14px] md:text-[15px] text-foreground truncate`,children:e.name||`Anonymous User`}),e.formId&&(0,l.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:e.formId.replace(/_/g,` `)})]}):(0,l.jsxs)(`div`,{className:`w-fit font-bold text-[14px] md:text-[15px] text-foreground truncate flex items-center gap-2`,children:[e.submitterName||e.name||`Anonymous User`,e.formId&&(0,l.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:e.formId.replace(/_/g,` `)})]}),(0,l.jsxs)(`span`,{className:`text-[13px] text-foreground/50 truncate flex items-center gap-1.5 font-medium mt-0.5`,children:[(0,l.jsx)(n.k,{className:`w-3.5 h-3.5`}),` `,e.contactEmail||e.email||`No email provided`]})]})]}),(0,l.jsxs)(`div`,{className:`hidden md:flex items-center gap-6 ml-6 shrink-0`,children:[(0,l.jsx)(`div`,{className:`text-[12px] font-medium text-foreground/40`,children:h(e.submittedAt)}),(0,l.jsx)(`div`,{className:`p-2 rounded-xl glass-panel transition-transform ${r?`rotate-180 bg-foreground/5`:``}`,children:(0,l.jsx)(n.st,{className:`w-4 h-4 text-foreground/50`})})]})]}),(0,l.jsx)(n.a,{children:r&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-4 md:p-6 pt-0 mt-2 border-t border-[var(--panel-border)]/30`,children:[(0,l.jsx)(`div`,{className:`md:hidden text-[12px] font-medium text-foreground/40 w-fit mb-4`,children:h(e.submittedAt)}),e.topic&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mb-4 text-[13px] text-foreground/70 bg-foreground/5 px-4 py-2.5 rounded-xl w-fit border border-[var(--panel-border)]`,children:[(0,l.jsx)(n.rt,{className:`w-4 h-4 text-accent`}),(0,l.jsx)(`span`,{className:`font-medium text-accent`,children:`Topic:`}),(0,l.jsx)(`span`,{className:`font-bold`,children:e.topic})]}),Object.entries(e).filter(([e])=>![`id`,`uid`,`submittedAt`,`avatarUrl`,`name`,`full_name`,`email`,`contactEmail`,`topic`,`isArchived`].includes(e)&&!e.toLowerCase().startsWith(`submitter`)&&e.toLowerCase()!==`formid`).map(([e,t])=>(0,l.jsxs)(`div`,{className:`bg-foreground/[0.02] rounded-2xl p-5 border border-[var(--panel-border)] relative mb-3`,children:[(0,l.jsx)(`div`,{className:`flex items-center gap-2 mb-3 text-foreground/60 w-full justify-between`,children:(0,l.jsx)(`div`,{className:`flex items-center gap-2 text-accent`,children:(0,l.jsx)(`span`,{className:`text-[12px] font-bold uppercase tracking-widest text-accent`,children:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())})})}),(0,l.jsx)(`p`,{className:`text-[14px] md:text-[15px] text-foreground/80 leading-relaxed whitespace-pre-wrap font-medium`,children:typeof t==`boolean`?t?`Yes`:`No`:e.toLowerCase()===`budget`&&t?`$${t}`:String(t||`No data provided`)})]},e)),(0,l.jsx)(`div`,{className:`mt-6 flex justify-end`,children:(0,l.jsxs)(`button`,{onClick:()=>_(e.id,e.isArchived),disabled:p===e.id,className:`flex items-center gap-2 px-4 py-2.5 rounded-xl text-[13px] font-bold text-foreground/70 hover:text-emerald-500 bg-foreground/5 hover:bg-emerald-500/10 transition-colors border border-transparent shadow-sm`,children:[p===e.id?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(n.vt,{className:`w-4 h-4`}),`Unarchive Request`]})})]})})})]},e.id)})})})})]})]})})]})]})]})}function L(){let{user:e,userRole:t}=m(),[r,i]=(0,a.useState)([]),[s,f]=(0,a.useState)(!1),p=(0,u.useNavigate)(),{"*":h}=(0,u.useParams)(),g=h?h.split(`/`).filter(Boolean):[],_=g[0]||`private`,v=null,y=null;_===`users`?(v=g[1]||null,y=g[2]||null):y=g[1]||null;let b={public:`pub_`,shared:`mem_`,private:`user_`,admin:`admin_`,users:`users_`},x={pub_:`public`,mem_:`shared`,user_:`private`,admin_:`admin`,users_:`users`},S=b[_]||`user_`,C=e=>{p(`/drive/${x[e]}`)},[w,T]=(0,a.useState)([]);(0,a.useEffect)(()=>{S===`users_`&&t===`admin`&&w.length===0&&(0,o.getDocs)((0,o.collection)(n.Tt,`user_profiles`)).then(e=>{T(e.docs.map(e=>({id:e.id,...e.data()})))})},[S,t,w.length]);let[E,D]=(0,a.useState)(!1),[O,k]=(0,a.useState)(null),[A,j]=(0,a.useState)(``),[ne,M]=(0,a.useState)(`user_`),[N,P]=(0,a.useState)(!1),[F,I]=(0,a.useState)(!1),[L,R]=(0,a.useState)(!1),z=(0,a.useRef)(null),re=e=>{e.preventDefault(),e.stopPropagation(),R(!0)},B=e=>{e.preventDefault(),e.stopPropagation(),R(!1)},ie=e=>{if(e.preventDefault(),e.stopPropagation(),R(!1),e.dataTransfer.files&&e.dataTransfer.files[0]){let t=e.dataTransfer.files[0];k(t),j(t.name),M(S),P(!0)}},V=y&&r.find(e=>e._id===y)||null,ae=e=>{le(!0),p(e?S===`users_`&&v?`/drive/users/${v}/${e._id}`:`/drive/${x[S]}/${e._id}`:S===`users_`&&v?`/drive/users/${v}`:`/drive/${x[S]}`)},[H,U]=(0,a.useState)(null),[W,oe]=(0,a.useState)(!1),[G,K]=(0,a.useState)(null),[se,q]=(0,a.useState)(!1),[J,Y]=(0,a.useState)(null),[ce,le]=(0,a.useState)(!0),[ue,de]=(0,a.useState)({}),[X,Z]=(0,a.useState)(!1);(0,a.useEffect)(()=>(V||G||H||N||X?document.body.style.overflow=`hidden`:document.body.style.overflow=``,()=>{document.body.style.overflow=``}),[V,G,H,N,X]),(0,a.useEffect)(()=>{if(!s&&y&&!r.some(e=>e._id===y)){Z(!0);let e=setTimeout(()=>{Z(!1),p(S===`users_`&&v?`/drive/users/${v}`:`/drive/${x[S]}`)},2500);return()=>clearTimeout(e)}else Z(!1)},[s,y,r,S,p,v]),(0,a.useEffect)(()=>{if(!e)return;f(!0);let r=(t===`admin`?[`pub_`,`mem_`,`user_`,`admin_`]:[`pub_`,`mem_`,`user_`]).map(r=>{let a;return a=r===`user_`&&t!==`admin`?(0,o.query)((0,o.collection)(n.Tt,`${r}files`),(0,o.where)(`uid`,`==`,e.uid)):(0,o.query)((0,o.collection)(n.Tt,`${r}files`),(0,o.orderBy)(`createdAt`,`desc`)),(0,o.onSnapshot)(a,e=>{let t=(e.docs||[]).map(e=>({_id:e.id,accessPrefix:r,...e.data()}));i(e=>[...e.filter(e=>e.accessPrefix!==r),...t].sort((e,t)=>{let n=e.createdAt?.toMillis?e.createdAt.toMillis():0;return(t.createdAt?.toMillis?t.createdAt.toMillis():0)-n})),f(!1)},e=>{console.warn(`Error listening to ${r}files:`,e)})});return()=>r.forEach(e=>e())},[e?.uid,t]);let fe=e=>{if(e.target.files&&e.target.files[0]){let t=e.target.files[0];k(t),j(t.name)}},pe=e=>{if(e.preventDefault(),e.dataTransfer.files&&e.dataTransfer.files[0]){let t=e.dataTransfer.files[0];k(t),j(t.name)}},me=async r=>{if(r.preventDefault(),!(!O||!A)){D(!0);try{let r=(0,c.ref)(n.Dt,`${ne}files/${`${Date.now()}_${O.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,c.uploadBytes)(r,O,{customMetadata:{ownerId:e.uid}});let i=await(0,c.getDownloadURL)(r);await(0,o.addDoc)((0,o.collection)(n.Tt,`${ne}files`),{fileName:A,fileType:O.type||`unknown`,fileSize:O.size,downloadURL:i,uid:e.uid,uploaderEmail:e.email||`user`,uploaderRole:t||`user`,createdAt:(0,o.serverTimestamp)()}),P(!1),k(null),j(``),C(ne)}catch(e){console.error(e),alert(`Upload failed: ${e.message}`)}D(!1)}},he=async()=>{if(G){q(!0);try{try{await(0,c.deleteObject)((0,c.ref)(n.Dt,G.url))}catch(e){console.warn(`Storage item missing:`,e)}await(0,o.deleteDoc)((0,o.doc)(n.Tt,`${G.prefix}files`,G.id)),i(e=>e.filter(e=>e._id!==G.id)),K(null)}catch(e){alert(e.message)}q(!1)}},Q=async()=>{if(!H||!H.name.trim()){U(null);return}let e=r.find(e=>e._id===H.id);if(e&&e.fileName===H.name.trim()){U(null);return}oe(!0);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,`${H.prefix}files`,H.id),{fileName:H.name.trim()}),i(e=>e.map(e=>e._id===H.id?{...e,fileName:H.name.trim()}:e)),U(null)}catch(e){console.error(`Rename failed:`,e)}oe(!1)},ge=(e,t)=>{navigator.clipboard.writeText(e),Y(t),setTimeout(()=>Y(null),2e3)},_e=e=>{if(e===0)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=n=>e?n.accessPrefix===`mem_`?n.uid===e.uid?!0:t===`admin`?n.uploaderRole!==`admin`:!1:n.accessPrefix===`admin_`?n.uid===e.uid:n.accessPrefix===`pub_`?t===`admin`:n.uid===e.uid||t===`admin`:!1,ye=(e,t,r=!1)=>{let i=r?`w-16 h-16`:`w-10 h-10`,a=r?`w-8 h-8`:`w-5 h-5`;return e.startsWith(`image/`)?r?(0,l.jsx)(`img`,{src:t,alt:`preview`,className:`w-full h-full object-contain rounded-lg`}):(0,l.jsx)(`div`,{className:`${i} bg-cover bg-center rounded-lg`,style:{backgroundImage:`url(${t})`}}):e.includes(`video`)||e.includes(`audio`)?(0,l.jsx)(`div`,{className:`${i} flex items-center justify-center bg-purple-500/10 text-purple-500 rounded-lg`,children:(0,l.jsx)(n.l,{className:a})}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,l.jsx)(`div`,{className:`${i} flex items-center justify-center bg-blue-500/10 text-blue-500 rounded-lg`,children:(0,l.jsx)(n.G,{className:a})}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,l.jsx)(`div`,{className:`${i} flex items-center justify-center bg-yellow-500/10 text-yellow-500 rounded-lg`,children:(0,l.jsx)(n._t,{className:a})}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,l.jsx)(`div`,{className:`${i} flex items-center justify-center bg-emerald-500/10 text-emerald-500 rounded-lg`,children:(0,l.jsx)(n.Q,{className:a})}):(0,l.jsx)(`div`,{className:`${i} flex items-center justify-center bg-foreground/5 text-foreground/40 rounded-lg`,children:(0,l.jsx)(n.W,{className:a})})},be=[{id:`user_`,label:`Private`,icon:n.j,description:`This is a private folder availbale to all users in your app. Each user can see their own files. Admins can see all everyone's files here.`},{id:`mem_`,label:`Shared`,icon:n.u,description:`This is a shared folder that all signed-in users can see. Every user can upload files here and view other member's files. However, editing and deletion are strictly restricted to the original creator of the file.`},{id:`pub_`,label:`Public`,icon:n.U,description:`This admin-only folder is for assets like logos, banners, or favicons. Files here are view-only for everyone; only admins can upload or delete them.`},{id:`admin_`,label:`Admin Shared`,icon:n.v,description:`This is a shared folder for app administrators. Admins can view everything here, but they can only edit or delete files that they themselves uploaded.`},{id:`users_`,label:`User Uploads`,icon:n.X,description:`View all underlying private user uploads securely. Select a user to explore their files.`}].filter(e=>t===`admin`?!0:e.id===`user_`||e.id===`mem_`),xe=[];xe=S===`users_`?r.filter(e=>e.accessPrefix===`user_`&&e.uid===v):S===`user_`?r.filter(t=>t.accessPrefix===`user_`&&t.uid===e?.uid):r.filter(e=>e.accessPrefix===S);let Se=be.find(e=>e.id===S);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 flex flex-col pt-12 min-h-screen relative overflow-visible`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Drive`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/drive`]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,onDragOver:re,onDragLeave:B,onDrop:ie,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(`div`,{className:`flex flex-row glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl min-h-[600px] bg-background`,children:[(0,l.jsxs)(`div`,{className:`w-[280px] border-r border-[var(--panel-border)] bg-foreground/[0.01] p-4 flex flex-col shrink-0 overflow-y-auto hide-scrollbar`,children:[(0,l.jsx)(`div`,{className:`text-[11px] font-extrabold text-foreground/40 uppercase tracking-widest pl-4 mb-4 mt-2`,children:`Locations`}),(0,l.jsx)(`div`,{className:`flex flex-col gap-2`,children:be.map(e=>(0,l.jsxs)(`button`,{onClick:()=>C(e.id),className:`w-full flex items-center gap-3 px-4 py-3.5 rounded-2xl transition-all font-bold text-[14px] text-left ${S===e.id?`bg-accent/15 text-accent shadow-sm border border-accent/20`:`text-foreground/70 hover:bg-foreground/5 hover:text-foreground border border-transparent`}`,children:[(0,l.jsx)(e.icon,{className:`w-5 h-5 ${S===e.id?`text-accent`:`text-foreground/40`}`}),e.label]},e.id))})]}),(0,l.jsxs)(`div`,{className:`flex-1 flex flex-col relative w-full h-full min-w-0`,children:[(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex items-start justify-between gap-6 shrink-0 border-b border-[var(--panel-border)]/50 bg-background/50`,children:[(0,l.jsxs)(`div`,{className:`flex-1 max-w-xl`,children:[(0,l.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground tracking-tight flex items-center gap-3`,children:Se?.label}),(0,l.jsx)(`p`,{className:`text-[13px] mt-3 text-foreground/60 leading-relaxed font-medium`,children:Se?.description})]}),S!==`users_`&&(0,l.jsxs)(n.n,{onClick:()=>{M(S),P(!0)},className:`flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-bold shadow-md hover:shadow-lg transition-all glow-hover border-transparent !border-0 outline-none ring-0`,children:[(0,l.jsx)(n.C,{className:`w-4 h-4`}),` Add File Here`]})]}),(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[300px]`,children:[s&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm rounded-b-[2rem]`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),S===`users_`&&!v?(0,l.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 pb-20`,children:[w.map(e=>(0,l.jsxs)(`div`,{onClick:()=>p(`/drive/users/${e.id}`),className:`flex items-center gap-4 bg-background border border-[var(--panel-border)] p-5 rounded-2xl cursor-pointer hover:border-accent/50 hover:shadow-md transition-all group`,children:[(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-foreground/5 flex items-center justify-center shrink-0 border border-[var(--panel-border)]`,children:e.photoURL?(0,l.jsx)(`img`,{src:e.photoURL,alt:`avatar`,className:`w-full h-full rounded-full object-cover`}):(0,l.jsx)(n.d,{className:`w-5 h-5 text-foreground/40`})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,l.jsxs)(`span`,{className:`font-bold text-foreground truncate group-hover:text-accent transition-colors text-[14px]`,children:[e.firstName,` `,e.lastName]}),(0,l.jsx)(`span`,{className:`text-[12px] font-medium text-foreground/50 truncate mt-0.5`,children:e.email})]})]},e.id)),w.length===0&&(0,l.jsxs)(`div`,{className:`col-span-full py-12 flex flex-col items-center justify-center text-center`,children:[(0,l.jsx)(n.d,{className:`w-12 h-12 text-foreground/10 mb-4`}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold text-foreground/50`,children:`No users found`})]})]}):xe.length>0?(0,l.jsx)(`div`,{className:`grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 pb-20`,children:xe.map(e=>(0,l.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 hover:shadow-md h-[190px] relative`,children:[(0,l.jsxs)(`div`,{className:`absolute top-2 right-2 flex flex-col gap-1 opacity-0 group-hover:opacity-100 transition-opacity z-10 bg-background/90 backdrop-blur-md rounded-lg p-1 border border-[var(--panel-border)] shadow-xl`,children:[(0,l.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,l.jsx)(n.Y,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ge(e.accessPrefix===`pub_`?e.downloadURL:`${window.location.origin}/drive/${x[e.accessPrefix]}/${e._id}`,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:J===e._id?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),ve(e)&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),U({id:e._id,name:e.fileName,prefix:e.accessPrefix})},className:`p-1.5 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-purple-500 transition-colors`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),K({id:e._id,url:e.downloadURL,name:e.fileName,prefix:e.accessPrefix})},className:`p-1.5 hover:bg-red-500/10 rounded-md text-foreground/60 hover:text-red-500 transition-colors`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})})]})]}),(0,l.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 rounded-t-[calc(1rem-1px)]`,onClick:()=>ae(e),children:e.fileType.startsWith(`image/`)?(0,l.jsxs)(l.Fragment,{children:[ue[e._id]!==!1&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-accent/5 backdrop-blur-sm z-0`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})}),(0,l.jsx)(`img`,{src:e.downloadURL,alt:``,className:`absolute inset-0 w-full h-full object-cover transition-opacity duration-300 group-hover:scale-105 ${ue[e._id]===!1?`opacity-100`:`opacity-0`}`,onLoad:()=>de(t=>({...t,[e._id]:!1})),onError:()=>de(t=>({...t,[e._id]:!1}))})]}):ye(e.fileType,e.downloadURL,!0)}),(0,l.jsxs)(`div`,{className:`p-3 flex flex-col justify-center flex-1 min-w-0`,onClick:()=>!H&&ae(e),children:[H?.id===e._id?(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,value:H.name,onChange:e=>U({...H,name:e.target.value}),onBlur:()=>Q(),onKeyDown:e=>{e.key===`Enter`&&Q(),e.key===`Escape`&&U(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,l.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,l.jsx)(`span`,{className:`text-[11px] text-foreground/40 font-bold uppercase tracking-wider mt-1 select-none`,children:_e(e.fileSize)})]})]},e._id))}):!s&&(0,l.jsxs)(`div`,{onDragOver:e=>e.preventDefault(),onDrop:e=>{if(e.preventDefault(),e.dataTransfer.files&&e.dataTransfer.files[0]){let t=e.dataTransfer.files[0];k(t),j(t.name),M(S),P(!0)}},onClick:()=>{M(S),P(!0)},className:`absolute inset-0 m-6 flex flex-col items-center justify-center text-foreground/40 transition-colors cursor-pointer group`,children:[(0,l.jsx)(`p`,{className:`text-[20px] font-bold text-foreground/50 group-hover:text-foreground/70 transition-colors`,children:`Folder is empty`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium mt-1 text-foreground/40 group-hover:text-foreground/60 transition-colors`,children:`Click here or drag and drop a file to upload`})]})]})]})]})]}),(0,l.jsx)(n.a,{children:N&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!E&&P(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`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,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 border-b border-[var(--panel-border)]/50 relative z-20`,children:[(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsxs)(`button`,{onClick:()=>I(!F),className:`flex items-center gap-2 group outline-none`,children:[(0,l.jsx)(`span`,{className:`text-[16px] font-extrabold text-foreground tracking-tight`,children:`Upload to`}),(0,l.jsx)(`span`,{className:`bg-accent/10 group-hover:bg-accent/20 text-accent px-2 py-1 rounded-md text-[13px] font-bold transition-colors flex items-center gap-1 shadow-sm`,children:be.find(e=>e.id===ne)?.label})]}),(0,l.jsx)(n.a,{children:F&&(0,l.jsxs)(a.default.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-[90]`,onClick:()=>I(!1)}),(0,l.jsx)(n.i.div,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},exit:{opacity:0,y:-5},className:`absolute top-full left-0 mt-3 w-48 bg-background border border-[var(--panel-border)] rounded-xl shadow-2xl py-1 overflow-hidden z-[100]`,children:be.map(e=>(0,l.jsxs)(`button`,{type:`button`,onClick:()=>{M(e.id),I(!1)},className:`w-full text-left px-4 py-3 hover:bg-foreground/5 text-[13px] font-bold text-foreground flex items-center gap-3 transition-colors outline-none`,children:[(0,l.jsx)(e.icon,{className:`w-4 h-4 text-foreground/50`}),e.label]},e.id))})]})})]}),(0,l.jsx)(`button`,{onClick:()=>!E&&P(!1),className:`text-foreground/40 hover:text-foreground transition-colors`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})})]}),O?(0,l.jsxs)(`form`,{onSubmit:me,className:`p-6 flex flex-col gap-6 relative z-10 rounded-b-[2rem]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-4 bg-foreground/[0.03] p-4 rounded-2xl border border-[var(--panel-border)] shadow-sm`,children:[ye(O.type,URL.createObjectURL(O)),(0,l.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-[13px] font-bold text-foreground truncate`,children:O.name}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold uppercase tracking-wider mt-1`,children:_e(O.size)})]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>!E&&k(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,l.jsx)(n.h,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,l.jsx)(`label`,{className:`text-[11px] font-bold text-foreground/50 uppercase tracking-widest pl-1`,children:`Edit File Name`}),(0,l.jsx)(`input`,{type:`text`,required:!0,value:A,onChange:e=>j(e.target.value),disabled:E,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 shadow-sm`})]}),(0,l.jsx)(`div`,{className:`flex justify-end pt-4 mt-2 border-t border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:E,className:`w-full py-4 rounded-xl text-[14px] font-bold shadow-lg`,children:E?`Uploading to Drive...`:`Save to ${be.find(e=>e.id===ne)?.label}`})})]}):(0,l.jsxs)(`div`,{onDragOver:e=>e.preventDefault(),onDrop:pe,className:`p-12 flex flex-col items-center justify-center rounded-b-[2rem]`,children:[(0,l.jsx)(`div`,{className:`w-20 h-20 rounded-full bg-foreground/5 flex items-center justify-center mb-5 border-2 border-dashed border-[var(--panel-border)]`,children:(0,l.jsx)(n.$,{className:`w-8 h-8 text-foreground/40`})}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold text-foreground mb-1`,children:`Drag and drop file here`}),(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/50 font-medium mb-8`,children:`or click to browse local files`}),(0,l.jsx)(`input`,{type:`file`,ref:z,onChange:fe,className:`hidden`}),(0,l.jsx)(n.n,{onClick:()=>z.current?.click(),className:`px-8 py-3 rounded-full font-bold shadow-md btn-primary transition-colors`,children:`Browse Files`})]})]})]})}),typeof window<`u`&&(0,d.createPortal)((0,l.jsx)(n.a,{children:V&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,l.jsx)(n.i.div,{onClick:()=>ae(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(`button`,{onClick:()=>ae(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`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-[var(--panel-border)]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 bg-background/80 backdrop-blur-md border-b border-[var(--panel-border)] shrink-0 shadow-sm z-20`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:V.fileName}),(0,l.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[V.fileType,` • `,_e(V.fileSize),V.accessPrefix===`mem_`&&(V.uploaderEmail||V.uid)&&` • From: ${V.uploaderEmail||V.uid}`]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:()=>ge(V.accessPrefix===`pub_`?V.downloadURL:`${window.location.origin}/drive/${x[V.accessPrefix]}/${V._id}`,V._id),className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 transition-colors rounded-xl shadow-sm hover:text-emerald-500`,title:`Copy Link`,children:J===V._id?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),ve(V)&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:()=>{ae(null),U({id:V._id,name:V.fileName,prefix:V.accessPrefix})},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-purple-500 transition-colors rounded-xl shadow-sm`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{ae(null),K({id:V._id,url:V.downloadURL,name:V.fileName,prefix:V.accessPrefix})},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})})]}),(0,l.jsx)(`a`,{href:V.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>ae(null),children:(0,l.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[ce&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none fade-in`,children:(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-background/80 backdrop-blur-md shadow-xl flex items-center justify-center border border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})})}),V.fileType.startsWith(`image/`)?(0,l.jsx)(`img`,{onLoad:()=>le(!1),src:V.downloadURL,alt:V.fileName,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 ${ce?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):V.fileType.startsWith(`video/`)?(0,l.jsx)(`video`,{onLoadedData:()=>le(!1),src:V.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 ${ce?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):V.fileType===`application/pdf`?(0,l.jsx)(`iframe`,{onLoad:()=>le(!1),src:V.downloadURL,className:`w-full h-full border-none bg-white rounded-lg relative z-10 transition-opacity duration-500 ${ce?`opacity-0`:`opacity-100`}`,title:`PDF Preview`}):(0,l.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center text-foreground/40 text-center relative z-10`,onClick:e=>{e.stopPropagation(),le(!1)},children:[(0,l.jsx)(n.W,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,l.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,l.jsx)(`span`,{className:`text-[14px] mt-2 text-foreground/60 font-medium max-w-xs`,children:`This file format cannot be previewed. Please download it instead.`})]})]})})]})]})}),document.body),(0,l.jsx)(n.a,{children:X&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/90 backdrop-blur-xl`}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:`relative z-10 w-full max-w-sm flex flex-col items-center pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-red-500/20 bg-background/80 p-8 text-center`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-red-500/10 flex items-center justify-center mb-6`,children:(0,l.jsx)(n.c,{className:`w-8 h-8 text-red-500`})}),(0,l.jsx)(`h3`,{className:`text-xl font-bold text-foreground mb-2`,children:`Access Denied`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/60 font-medium leading-relaxed`,children:`You don't have access to this file, or it may have been deleted.`}),(0,l.jsx)(`div`,{className:`w-5 h-5 border-2 border-accent/20 border-t-accent rounded-full animate-spin mt-6`})]})]})}),(0,l.jsx)(te,{isOpen:!!G,title:`Confirm Deletion`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:G?.name}),` This action is permanent.`]}),onConfirm:he,onCancel:()=>K(null),isProcessing:se,confirmText:`Yes, Delete`}),(0,l.jsx)(n.a,{children:L&&(0,l.jsx)(n.i.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,l.jsxs)(n.i.div,{initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.9,opacity:0},className:`w-full max-w-lg aspect-video bg-background/80 border-2 border-dashed border-accent p-12 rounded-[40px] shadow-2xl flex flex-col items-center justify-center gap-6 relative`,children:[(0,l.jsx)(`div`,{className:`absolute inset-0 bg-accent/5 rounded-[38px] animate-pulse`}),(0,l.jsx)(`div`,{className:`w-20 h-20 rounded-full bg-accent/10 flex items-center justify-center text-accent shadow-[0_0_40px_rgba(var(--accent-rgb),0.2)]`,children:(0,l.jsx)(n.$,{className:`w-10 h-10 animate-bounce`})}),(0,l.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-2 relative z-10`,children:[(0,l.jsx)(`span`,{className:`text-[24px] font-extrabold text-foreground tracking-tight`,children:`Drop files to upload`}),(0,l.jsx)(`span`,{className:`text-[14px] font-medium text-foreground/50`,children:`Your files will be staged for review`})]})]})})})]})}function R(){let e=[{id:`form`,title:`Inline Form`,description:`A static, embedded contact form designed directly into the page layout.`,icon:n.P,path:`/templates/inline_form`},{id:`popup`,title:`Modal Popup Form`,description:`A centralized popup contact form that visually blurs the background context.`,icon:n.yt,path:`/templates/popup_form`},{id:`confirmation`,title:`Action Confirmation`,description:`A classic confirmation dialog styled for decisive user actions.`,icon:n.lt,path:`/templates/confirmation`},{id:`board`,title:`Board View`,description:`A modern, drag-and-drop styled Kanban board aesthetic for task management.`,icon:n.z,path:`/templates/board`},{id:`table`,title:`Data Table`,description:`A clean, column-based data table optimized for large datasets and bulk actions.`,icon:n.g,path:`/templates/table`},{id:`calendar`,title:`Calendar View`,description:`A structured monthly calendar grid for scheduling and date-based resource planning.`,icon:n.dt,path:`/templates/calendar`}];return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-10 text-center`,children:[(0,l.jsx)(`h1`,{className:`w-fit mx-auto inline-block text-4xl md:text-5xl lg:text-[4.8rem] leading-[1.1] font-extrabold tracking-tight mb-4 text-gradient animate-float`,children:`Premium Templates`}),(0,l.jsx)(`p`,{className:`text-foreground/60 text-lg font-medium max-w-2xl mx-auto`,children:`Explore our collection of fully functional, beautifully designed boilerplate components.`})]}),(0,l.jsxs)(`div`,{className:`w-full max-w-4xl mx-auto flex flex-col gap-4 relative`,children:[(0,l.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,t)=>{let r=e.icon;return(0,l.jsx)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:t*.05},children:(0,l.jsxs)(u.Link,{to:e.path,className:`flex items-center gap-6 w-full p-4 md:px-6 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,l.jsx)(`div`,{className:`w-12 h-12 rounded-xl bg-accent/10 flex items-center justify-center text-accent shrink-0 border border-accent/20 group-hover:scale-105 transition-transform`,children:(0,l.jsx)(r,{className:`w-5 h-5`})}),(0,l.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,l.jsx)(`h3`,{className:`text-[15px] font-bold text-foreground truncate`,children:e.title}),(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/50 truncate font-medium`,children:e.description})]}),(0,l.jsxs)(`div`,{className:`hidden md:flex items-center gap-2 text-[13px] font-bold px-5 py-2.5 rounded-xl btn-primary shrink-0 transition-transform shadow-lg group-hover:-translate-y-0.5`,children:[`View `,(0,l.jsx)(`span`,{className:`font-black leading-none ml-0.5`,children:`→`})]})]})},e.id)})]})]})}function z(){let[e,t]=(0,a.useState)({favoriteService:``,satisfactionRating:``,detailedThoughts:``}),[r,i]=(0,a.useState)(`idle`);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12`,children:[(0,l.jsx)(`div`,{className:`w-full max-w-5xl mx-auto mb-6`,children:(0,l.jsxs)(u.Link,{to:`/templates`,className:`inline-flex items-center gap-2 text-foreground/50 hover:text-accent transition-colors font-medium text-[14px]`,children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` Back to Templates`]})}),(0,l.jsx)(`div`,{className:`w-full max-w-5xl mx-auto mt-6`,children:(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`w-full max-w-[500px] p-6 sm:p-8 lg:p-10 rounded-3xl md:rounded-3xl glass-panel relative glow-hover shadow-[0_8px_32px_rgba(0,0,0,0.08)] z-10 mx-auto`,children:[(0,l.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,l.jsx)(`div`,{className:`relative z-10 w-full`,children:r===`success`?(0,l.jsxs)(n.i.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,l.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,l.jsx)(n.nt,{className:`w-8 h-8`})}),(0,l.jsx)(`h4`,{className:`text-lg font-bold text-foreground mb-2`,children:`Simulation Complete!`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/60 leading-relaxed`,children:`Your test data was sent successfully. Log in as an admin and check the Submissions tab!`})]}):r===`loading`?(0,l.jsxs)(n.i.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,l.jsx)(`div`,{className:`w-10 h-10 border-4 border-accent border-r-transparent rounded-full animate-spin mb-4`}),(0,l.jsx)(`h4`,{className:`text-lg font-bold text-foreground tracking-tight`,children:`Processing`}),(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/50 mt-1`,children:`Simulating submission...`})]}):(0,l.jsxs)(n.i.div,{initial:{opacity:0},animate:{opacity:1},children:[(0,l.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,l.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight break-words`,children:`Inline Form Template`}),(0,l.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,l.jsxs)(`form`,{onSubmit:async r=>{r.preventDefault(),i(`loading`);try{let r=n.wt.currentUser?.uid||`guest`;await(0,o.addDoc)((0,o.collection)(n.Tt,`user_submissions`),{uid:r,...e,type:`template_simulation`,submittedAt:(0,o.serverTimestamp)()}),i(`success`),setTimeout(()=>{i(`idle`),t({favoriteService:``,satisfactionRating:``,detailedThoughts:``})},3e3)}catch{i(`error`)}},className:`space-y-4 w-full`,children:[(0,l.jsx)(n.r,{label:`Favorite Service`,placeholder:`e.g. Design Consulting`,value:e.favoriteService,onChange:n=>t({...e,favoriteService:n.target.value})}),(0,l.jsx)(n.r,{label:`Satisfaction Rating`,type:`number`,placeholder:`1 to 10`,value:e.satisfactionRating,onChange:n=>t({...e,satisfactionRating:n.target.value})}),(0,l.jsxs)(`div`,{className:`flex flex-col w-full relative`,children:[(0,l.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Detailed Thoughts`}),(0,l.jsx)(`textarea`,{rows:3,placeholder:`Type something here...`,value:e.detailedThoughts,onChange:n=>t({...e,detailedThoughts:n.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,l.jsx)(`div`,{className:`pt-2`,children:(0,l.jsx)(n.n,{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 re(){let[e,t]=(0,a.useState)(!1),[r,i]=(0,a.useState)({concept:``,featureRequest:``,notes:``}),[s,c]=(0,a.useState)(`idle`);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Popup Form`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/popup_form`]})]}),(0,l.jsx)(`div`,{className:`flex justify-between items-center mb-6 border-b border-[var(--panel-border)] pb-6 relative z-20`,children:(0,l.jsxs)(u.Link,{to:`/templates`,className:`px-5 py-2 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold hover:bg-foreground/5 transition-all flex items-center gap-2 text-foreground/70`,children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` Go Back`]})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative flex flex-col w-full min-h-[150px] p-6 lg:p-10`,children:[(0,l.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,l.jsx)(`div`,{className:`flex h-full w-full justify-end items-start relative z-10`,children:(0,l.jsxs)(n.n,{onClick:()=>t(!0),className:`px-6 py-2.5 text-[14px] font-bold rounded-xl shadow-lg flex items-center justify-center gap-2 btn-primary transition-all hover:-translate-y-1`,children:[(0,l.jsx)(n.C,{className:`w-4 h-4`}),` Open Form`]})})]}),(0,l.jsx)(n.a,{children:e&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-xl cursor-pointer`,onClick:()=>t(!1)}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`w-full max-w-[500px] p-6 sm:p-8 lg:p-10 rounded-3xl md:rounded-3xl glass-panel relative glow-hover shadow-[0_8px_32px_rgba(0,0,0,0.08)] z-10 mx-4 max-h-[95vh] overflow-y-auto no-scrollbar`,children:[(0,l.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,l.jsxs)(`div`,{className:`relative z-10 w-full`,children:[(0,l.jsx)(`button`,{onClick:()=>t(!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,l.jsx)(n.c,{className:`w-5 h-5`})}),s===`success`?(0,l.jsxs)(n.i.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,l.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,l.jsx)(n.nt,{className:`w-8 h-8`})}),(0,l.jsx)(`h4`,{className:`text-xl font-bold text-foreground mb-2`,children:`Simulation Complete!`}),(0,l.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 check the Submissions tab!`})]}):s===`loading`?(0,l.jsxs)(n.i.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,l.jsx)(`div`,{className:`w-10 h-10 border-4 border-accent border-r-transparent rounded-full animate-spin mb-4`}),(0,l.jsx)(`h4`,{className:`text-lg font-bold text-foreground tracking-tight`,children:`Processing`}),(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/50 mt-1`,children:`Simulating submission...`})]}):(0,l.jsxs)(n.i.div,{initial:{opacity:0},animate:{opacity:1},children:[(0,l.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,l.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight break-words`,children:`Popup Template`}),(0,l.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,l.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),c(`loading`);try{let e=n.wt.currentUser?.uid||`guest`;await(0,o.addDoc)((0,o.collection)(n.Tt,`user_submissions`),{uid:e,...r,type:`template_simulation`,submittedAt:(0,o.serverTimestamp)()}),c(`success`),setTimeout(()=>{c(`idle`),i({concept:``,featureRequest:``,notes:``}),t(!1)},3e3)}catch{c(`error`)}},className:`space-y-4 w-full`,children:[(0,l.jsx)(n.r,{label:`Concept Name`,placeholder:`e.g. Project Apollo`,value:r.concept,onChange:e=>i({...r,concept:e.target.value})}),(0,l.jsx)(n.r,{label:`Feature Request`,placeholder:`e.g. Real-time sync`,value:r.featureRequest,onChange:e=>i({...r,featureRequest:e.target.value})}),(0,l.jsxs)(`div`,{className:`flex flex-col w-full relative`,children:[(0,l.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Simulated Notes`}),(0,l.jsx)(`textarea`,{rows:3,placeholder:`Type something here...`,value:r.notes,onChange:e=>i({...r,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,l.jsx)(`div`,{className:`pt-2`,children:(0,l.jsx)(n.n,{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 B(){let[e,t]=(0,a.useState)(void 0);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 items-center`,children:[(0,l.jsx)(`div`,{className:`w-full max-w-5xl mb-8`,children:(0,l.jsxs)(u.Link,{to:`/templates`,className:`inline-flex items-center gap-2 text-foreground/50 hover:text-accent transition-colors font-medium text-[14px]`,children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` Back to Templates`]})}),(0,l.jsxs)(`div`,{className:`w-full max-w-5xl mx-auto mt-2 glass-panel rounded-3xl border border-[var(--panel-border)] p-6 md:p-10 relative overflow-hidden shadow-2xl`,children:[(0,l.jsx)(`div`,{className:`flex items-center justify-between mb-8 pb-6 border-b border-[var(--panel-border)]/50`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h3`,{className:`text-2xl font-extrabold text-foreground tracking-tight`,children:`System Files`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/50 mt-1`,children:`Review and manage core application assets.`})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,l.jsxs)(`div`,{className:`glass-panel p-5 rounded-2xl border border-[var(--panel-border)]/50 flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-4 w-full sm:w-auto`,children:[(0,l.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-red-500/10 flex items-center justify-center text-red-500 shrink-0`,children:(0,l.jsx)(n.p,{className:`w-5 h-5`})}),(0,l.jsxs)(`div`,{className:`min-w-0 pr-2`,children:[(0,l.jsx)(`h4`,{className:`font-bold text-[14px] sm:text-[15px] text-foreground truncate`,children:`Critical Configuration File`}),(0,l.jsx)(`p`,{className:`text-[12px] sm:text-[13px] text-foreground/50 font-medium mt-0.5 truncate`,children:`Size: 4.2 MB • Modified 2 hours ago`})]})]}),(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>t(null),className:`w-full sm:w-auto shrink-0 flex items-center justify-center px-6 py-3 sm:py-2.5 text-[13px] font-bold rounded-xl text-red-500 hover:bg-red-500/10 hover:border-red-500/20 bg-red-500/5 sm:bg-transparent`,children:`Delete File`})]}),(0,l.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4 opacity-50 pointer-events-none mt-2`,children:[1,2].map(e=>(0,l.jsxs)(`div`,{className:`glass-panel p-5 rounded-2xl border border-[var(--panel-border)]/20 flex items-center gap-4`,children:[(0,l.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-foreground/5 shrink-0`}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-2 flex-1`,children:[(0,l.jsx)(`div`,{className:`w-32 h-3 rounded-full bg-foreground/10`}),(0,l.jsx)(`div`,{className:`w-20 h-2 rounded-full bg-foreground/5`})]})]},e))})]})]}),(0,l.jsx)(n.a,{children:e!==void 0&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-xl`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`w-full max-w-[400px] p-6 rounded-3xl glass-panel border border-[var(--panel-border)] shadow-2xl relative z-10 text-center`,children:(0,l.jsx)(n.a,{mode:`wait`,children:e===null?(0,l.jsxs)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full flex flex-col items-center`,children:[(0,l.jsx)(`h3`,{className:`text-xl font-extrabold mb-2 text-foreground tracking-tight`,children:`Confirm Deletion`}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 leading-relaxed mb-6`,children:`Are you entirely sure you wish to delete this configuration? This action is permanent.`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-3 w-full`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>t(!1),className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:`Cancel`}),(0,l.jsx)(n.n,{onClick:()=>t(!0),className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl bg-red-500 hover:bg-red-600 border-none text-white shadow-xl hover:shadow-red-500/20 glow-hover`,children:`Yes, Delete`})]})]},`confirm`):e===!0?(0,l.jsxs)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full flex flex-col items-center py-2`,children:[(0,l.jsxs)(`h3`,{className:`text-xl font-extrabold mb-1 text-green-500 tracking-tight flex items-center gap-2`,children:[(0,l.jsx)(n.ct,{className:`w-5 h-5`}),` Verified`]}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mb-6`,children:`Action successfully executed.`}),(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>t(void 0),className:`px-6 py-2 rounded-xl text-[13px] font-bold`,children:`Close Panel`})]},`success`):(0,l.jsxs)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full flex flex-col items-center py-2`,children:[(0,l.jsxs)(`h3`,{className:`text-xl font-extrabold mb-1 text-foreground/80 tracking-tight flex items-center gap-2`,children:[(0,l.jsx)(n.c,{className:`w-5 h-5`}),` Aborted`]}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mb-6`,children:`Cancellation securely caught.`}),(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>t(void 0),className:`px-6 py-2 rounded-xl text-[13px] font-bold`,children:`Close Panel`})]},`error`)})})]})})]})}var ie=(e,t=[])=>{let n=`${(e.pageName||e.pageId||`custom_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`).split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}Content`;return`Create file: src/your-ai-workflow-firebase-os/microcomponents/${n}.tsx
|
|
2
2
|
|
|
3
|
+
\`\`\`tsx
|
|
3
4
|
export default function ${n}({ config }: { config: any }) {
|
|
4
|
-
return (
|
|
5
|
+
return (
|
|
6
|
+
<div className="flex flex-col gap-6">
|
|
7
|
+
<div className="bg-background border border-[var(--panel-border)] rounded-2xl p-8 text-center">
|
|
8
|
+
<h2 className="text-xl font-bold text-foreground mb-2">Section Title</h2>
|
|
9
|
+
<p className="text-[13px] text-foreground/50">Content here.</p>
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
|
+
);
|
|
5
13
|
}
|
|
6
|
-
|
|
7
|
-
Styles — sections: \`className="glass-panel border border-[var(--panel-border)] rounded-2xl p-8"\`. Text: \`text-foreground\`, \`text-foreground/60\`. Accent: \`text-accent\`, \`bg-accent/10\`. Buttons: \`className="btn-primary px-6 py-3 rounded-xl font-bold"\`.
|
|
8
|
-
No page titles, no nav, no routing. Default export only.
|
|
9
|
-
|
|
10
|
-
[WHAT TO BUILD?]`},U="### Theme & Styling (Dynamic Firestore Theme)\nOur application uses a dynamic theme engine. You MUST use these global CSS variable tokens to ensure your design matches the user's active theme:\n- **Colors**: `var(--bg-color)`, `var(--fg-color)`, `var(--accent-color)`, `var(--accent-deep)`, `var(--panel-bg)`, `var(--panel-border)`.\n- **Text**: Use the `text-foreground` (standard), `text-accent` (primary), and `text-gradient` (headings) classes.\n- **Glassmorphism**: Always use the `.glass-panel` utility class for containers/cards.",W=`- **<Button />**, **<Input />**, **<ConfirmModal />**, **<DashboardNav />**, **<ContactPopup />**, **<CustomSelect />**.`,G=`- **<Button />**, **<Input />**, **<ConfirmModal />**, **<DashboardNav />**, **<CustomSelect />**.`,K=(e,t,n,r=[])=>`I need your help modifying the core Calendar Template which currently powers the "${e?.tabTitle||e?.tabName||t}" tab.
|
|
11
|
-
|
|
12
|
-
This is a core template located at \`src/templates/TemplateCalendar.tsx\`. Any changes you make here will affect ALL calendar views across the application. Do not completely rewrite it from scratch; instead, carefully integrate the requested features into the existing architecture.
|
|
13
|
-
|
|
14
|
-
### ── Current Tab Configuration (Context) ────────────────────────────────────
|
|
15
|
-
\`\`\`json
|
|
16
|
-
${JSON.stringify({tabName:e?.tabName,tabTitle:e?.tabTitle,defaultView:e?.defaultView,customFields:e?.customFields,showButton:e?.showButton},null,2)}
|
|
17
|
-
\`\`\`
|
|
18
|
-
|
|
19
|
-
### ── Data Architecture ───────────────────────────────────────────────────────
|
|
20
|
-
The current tab is configured with:
|
|
21
|
-
- **Firestore Collection**: \`${n}\`
|
|
22
|
-
- **Access Level**: PRIVATE.
|
|
23
|
-
|
|
24
|
-
### ── Form Selection ─────────────────────────────────────────────────────────
|
|
25
|
-
Available PRIVATE forms:
|
|
26
|
-
${r.length>0?r.map(e=>`- ${e}`).join(`
|
|
27
|
-
`):`- No active private forms found`}
|
|
28
|
-
|
|
29
|
-
### ── Your Mission ────────────────────────────────────────────────────────────
|
|
30
|
-
1. **Modify the Core Template**: Carefully edit \`src/templates/TemplateCalendar.tsx\`.
|
|
31
|
-
2. **Handle UX/UI**: Integrate your changes natively with the existing state, UI elements, and data sync logic without breaking existing functionality.
|
|
32
|
-
|
|
33
|
-
### ── Architecture & Reusable Components ────────────────────────────────────
|
|
34
|
-
${W}
|
|
35
|
-
|
|
36
|
-
${U}
|
|
37
|
-
|
|
38
|
-
[DESCRIBE FEATURE TO ADD HERE]`,re=(e,t,n,r=[])=>`I need your help modifying the core Calendar Template which currently powers the "${e?.tabTitle||e?.tabName||t}" tab.
|
|
39
|
-
|
|
40
|
-
This is a core template located at \`src/templates/TemplateCalendar.tsx\`. Any changes you make here will affect ALL calendar views across the application. Do not completely rewrite it from scratch; instead, carefully integrate the requested features into the existing architecture.
|
|
41
|
-
|
|
42
|
-
### ── Current Tab Configuration (Context) ────────────────────────────────────
|
|
43
|
-
\`\`\`json
|
|
44
|
-
${JSON.stringify({tabName:e?.tabName,tabTitle:e?.tabTitle,defaultView:e?.defaultView,customFields:e?.customFields,showButton:e?.showButton},null,2)}
|
|
45
|
-
\`\`\`
|
|
46
|
-
|
|
47
|
-
### ── Data Architecture ───────────────────────────────────────────────────────
|
|
48
|
-
The current tab is configured with:
|
|
49
|
-
- **Firestore Collection**: \`${n}\`
|
|
50
|
-
- **Access Level**: ADMIN ONLY.
|
|
51
|
-
|
|
52
|
-
### ── Your Mission ────────────────────────────────────────────────────────────
|
|
53
|
-
1. **Modify the Core Template**: Carefully edit \`src/templates/TemplateCalendar.tsx\`.
|
|
54
|
-
2. **Handle UX/UI**: Integrate your changes natively with the existing state, UI elements, and data sync logic without breaking existing functionality.
|
|
55
|
-
|
|
56
|
-
### ── Architecture & Reusable Components ────────────────────────────────────
|
|
57
|
-
${G}
|
|
58
|
-
|
|
59
|
-
${U}
|
|
60
|
-
|
|
61
|
-
[DESCRIBE FEATURE TO ADD HERE]`,ie=(e,t,n,r=[])=>`I need your help modifying the core Calendar Template which currently powers the "${e?.tabTitle||e?.tabName||t}" tab.
|
|
62
|
-
|
|
63
|
-
This is a core template located at \`src/templates/TemplateCalendar.tsx\`. Any changes you make here will affect ALL calendar views across the application. Do not completely rewrite it from scratch; instead, carefully integrate the requested features into the existing architecture.
|
|
64
|
-
|
|
65
|
-
### ── Current Tab Configuration (Context) ────────────────────────────────────
|
|
66
|
-
\`\`\`json
|
|
67
|
-
${JSON.stringify({tabName:e?.tabName,tabTitle:e?.tabTitle,defaultView:e?.defaultView,customFields:e?.customFields,showButton:e?.showButton},null,2)}
|
|
68
|
-
\`\`\`
|
|
69
|
-
|
|
70
|
-
### ── Data Architecture ───────────────────────────────────────────────────────
|
|
71
|
-
The current tab is configured with:
|
|
72
|
-
- **Firestore Collection**: \`${n}\`
|
|
73
|
-
- **Access Level**: PUBLIC/SHARED.
|
|
74
|
-
|
|
75
|
-
### ── Form Selection ─────────────────────────────────────────────────────────
|
|
76
|
-
Available PUBLIC forms:
|
|
77
|
-
${r.length>0?r.map(e=>`- ${e}`).join(`
|
|
78
|
-
`):`- No active public forms found`}
|
|
79
|
-
|
|
80
|
-
### ── Your Mission ────────────────────────────────────────────────────────────
|
|
81
|
-
1. **Modify the Core Template**: Carefully edit \`src/templates/TemplateCalendar.tsx\`.
|
|
82
|
-
2. **Handle UX/UI**: Integrate your changes natively with the existing state, UI elements, and data sync logic without breaking existing functionality.
|
|
83
|
-
|
|
84
|
-
### ── Architecture & Reusable Components ────────────────────────────────────
|
|
85
|
-
${W}
|
|
86
|
-
|
|
87
|
-
${U}
|
|
88
|
-
|
|
89
|
-
[DESCRIBE FEATURE TO ADD HERE]`,q=(e,t,n,r,i=[])=>`I need your help modifying the core Board Template which currently powers the "${e?.tabTitle||e?.tabName||t}" tab.
|
|
90
|
-
|
|
91
|
-
This is a core template located at \`src/templates/TemplateBoard.tsx\`. Any changes you make here will affect ALL board views across the application. Do not completely rewrite it from scratch; instead, carefully integrate the requested features into the existing architecture.
|
|
92
|
-
|
|
93
|
-
### ── Current Tab Configuration (Context) ────────────────────────────────────
|
|
94
|
-
\`\`\`json
|
|
95
|
-
${JSON.stringify({tabName:e?.tabName,tabTitle:e?.tabTitle,showButton:e?.showButton,buttonStyle:e?.buttonStyle},null,2)}
|
|
96
|
-
\`\`\`
|
|
97
|
-
|
|
98
|
-
### ── Data Architecture ───────────────────────────────────────────────────────
|
|
99
|
-
The current tab is configured with:
|
|
100
|
-
- **Tasks Collection**: \`${n}\`
|
|
101
|
-
- **Categories Collection**: \`${r}\`
|
|
102
|
-
- **Access Level**: PRIVATE.
|
|
103
|
-
|
|
104
|
-
### ── Form Selection ─────────────────────────────────────────────────────────
|
|
105
|
-
Available PRIVATE forms:
|
|
106
|
-
${i.length>0?i.map(e=>`- ${e}`).join(`
|
|
107
|
-
`):`- No active private forms found`}
|
|
108
|
-
|
|
109
|
-
### ── Your Mission ────────────────────────────────────────────────────────────
|
|
110
|
-
1. **Modify the Core Template**: Carefully edit \`src/templates/TemplateBoard.tsx\`.
|
|
111
|
-
2. **Handle UX/UI**: Integrate your changes natively with the existing state, drag-and-drop logic, and UI elements.
|
|
112
|
-
|
|
113
|
-
### ── Architecture & Reusable Components ────────────────────────────────────
|
|
114
|
-
${W}
|
|
115
|
-
|
|
116
|
-
${U}
|
|
117
|
-
|
|
118
|
-
[DESCRIBE FEATURE TO ADD HERE]`,J=(e,t,n,r)=>`I need your help modifying the core Board Template which currently powers the "${e?.tabTitle||e?.tabName||t}" tab.
|
|
119
|
-
|
|
120
|
-
This is a core template located at \`src/templates/TemplateBoard.tsx\`. Any changes you make here will affect ALL board views across the application. Do not completely rewrite it from scratch; instead, carefully integrate the requested features into the existing architecture.
|
|
121
|
-
|
|
122
|
-
### ── Current Tab Configuration (Context) ────────────────────────────────────
|
|
123
|
-
\`\`\`json
|
|
124
|
-
${JSON.stringify({tabName:e?.tabName,tabTitle:e?.tabTitle,showButton:e?.showButton,buttonStyle:e?.buttonStyle},null,2)}
|
|
125
14
|
\`\`\`
|
|
126
15
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
-
|
|
130
|
-
-
|
|
131
|
-
-
|
|
16
|
+
Design rules:
|
|
17
|
+
- Match the dark glassmorphism aesthetic. NO bg-white, NO text-gray-*, NO bg-indigo-*.
|
|
18
|
+
- Sections: \`bg-background border border-[var(--panel-border)] rounded-2xl\`. Text: \`text-foreground\`, \`text-foreground/50\`. Accent: \`text-accent\`, \`bg-accent/10\`.
|
|
19
|
+
- Buttons: \`btn-primary rounded-xl\`. No other button styles.
|
|
20
|
+
- Keep it minimal and clean.
|
|
132
21
|
|
|
133
|
-
|
|
134
|
-
1. **Modify the Core Template**: Carefully edit \`src/templates/TemplateBoard.tsx\`.
|
|
135
|
-
2. **Handle UX/UI**: Integrate your changes natively with the existing state, drag-and-drop logic, and UI elements.
|
|
136
|
-
|
|
137
|
-
### ── Architecture & Reusable Components ────────────────────────────────────
|
|
138
|
-
${G}
|
|
139
|
-
|
|
140
|
-
${U}
|
|
141
|
-
|
|
142
|
-
[DESCRIBE FEATURE TO ADD HERE]`,Y=(e,t,n,r,i=[])=>`I need your help modifying the core Board Template which currently powers the "${e?.tabTitle||e?.tabName||t}" tab.
|
|
143
|
-
|
|
144
|
-
This is a core template located at \`src/templates/TemplateBoard.tsx\`. Any changes you make here will affect ALL board views across the application. Do not completely rewrite it from scratch; instead, carefully integrate the requested features into the existing architecture.
|
|
145
|
-
|
|
146
|
-
### ── Current Tab Configuration (Context) ────────────────────────────────────
|
|
147
|
-
\`\`\`json
|
|
148
|
-
${JSON.stringify({tabName:e?.tabName,tabTitle:e?.tabTitle,showButton:e?.showButton,buttonStyle:e?.buttonStyle},null,2)}
|
|
149
|
-
\`\`\`
|
|
150
|
-
|
|
151
|
-
### ── Data Architecture ───────────────────────────────────────────────────────
|
|
152
|
-
The current tab is configured with:
|
|
153
|
-
- **Tasks Collection**: \`${n}\`
|
|
154
|
-
- **Categories Collection**: \`${r}\`
|
|
155
|
-
- **Access Level**: PUBLIC/SHARED.
|
|
22
|
+
No page titles, no nav, no routing. Default export only.
|
|
156
23
|
|
|
157
|
-
|
|
158
|
-
Available PUBLIC forms:
|
|
159
|
-
${i.length>0?i.map(e=>`- ${e}`).join(`
|
|
160
|
-
`):`- No active public forms found`}
|
|
24
|
+
[WHAT TO BUILD?]`},V=(e,t,n,r=[])=>`Modify file: src/templates/TemplateCalendar.tsx — powers the "${e?.tabName}" calendar tab.
|
|
161
25
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
2. **Handle UX/UI**: Integrate your changes natively with the existing state, drag-and-drop logic, and UI elements.
|
|
26
|
+
Events: \`${n}\`. Access: Private (user's own data only).
|
|
27
|
+
Integrate changes into the existing code. Do not rewrite from scratch.
|
|
165
28
|
|
|
166
|
-
|
|
167
|
-
${W}
|
|
29
|
+
[DESCRIBE FEATURE TO ADD]`,ae=(e,t,n,r=[])=>`Modify file: src/templates/TemplateCalendar.tsx — powers the "${e?.tabName}" calendar tab.
|
|
168
30
|
|
|
169
|
-
|
|
31
|
+
Events: \`${n}\`. Access: Admin only.
|
|
32
|
+
Integrate changes into the existing code. Do not rewrite from scratch.
|
|
170
33
|
|
|
171
|
-
[DESCRIBE FEATURE TO ADD
|
|
34
|
+
[DESCRIBE FEATURE TO ADD]`,H=(e,t,n,r=[])=>`Modify file: src/templates/TemplateCalendar.tsx — powers the "${e?.tabName}" calendar tab.
|
|
172
35
|
|
|
173
|
-
|
|
36
|
+
Events: \`${n}\`. Access: Public/Shared.
|
|
37
|
+
Integrate changes into the existing code. Do not rewrite from scratch.
|
|
174
38
|
|
|
175
|
-
|
|
176
|
-
\`\`\`json
|
|
177
|
-
${JSON.stringify({tabName:e?.tabName,tabTitle:e?.tabTitle,showButton:e?.showButton,buttonStyle:e?.buttonStyle,showExportButton:e?.showExportButton},null,2)}
|
|
178
|
-
\`\`\`
|
|
39
|
+
[DESCRIBE FEATURE TO ADD]`,U=(e,t,n,r,i=[])=>`Modify file: src/templates/TemplateBoard.tsx — powers the "${e?.tabName}" board tab.
|
|
179
40
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
- **Table Data Collection**: \`${n}\`
|
|
183
|
-
- **Access Level**: PRIVATE.
|
|
41
|
+
Tasks: \`${n}\`, Categories: \`${r}\`. Access: Private (user's own data only).
|
|
42
|
+
Integrate changes into the existing code. Do not rewrite from scratch.
|
|
184
43
|
|
|
185
|
-
|
|
186
|
-
Available PRIVATE forms:
|
|
187
|
-
${r.length>0?r.map(e=>`- ${e}`).join(`
|
|
188
|
-
`):`- No active private forms found`}
|
|
44
|
+
[DESCRIBE FEATURE TO ADD]`,W=(e,t,n,r)=>`Modify file: src/templates/TemplateBoard.tsx — powers the "${e?.tabName}" board tab.
|
|
189
45
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
2. **Handle UX/UI**: Integrate your changes natively with the existing state (columns, rows, colors) and UI elements.
|
|
46
|
+
Tasks: \`${n}\`, Categories: \`${r}\`. Access: Admin only.
|
|
47
|
+
Integrate changes into the existing code. Do not rewrite from scratch.
|
|
193
48
|
|
|
194
|
-
|
|
195
|
-
${W}
|
|
49
|
+
[DESCRIBE FEATURE TO ADD]`,oe=(e,t,n,r,i=[])=>`Modify file: src/templates/TemplateBoard.tsx — powers the "${e?.tabName}" board tab.
|
|
196
50
|
|
|
197
|
-
|
|
51
|
+
Tasks: \`${n}\`, Categories: \`${r}\`. Access: Public/Shared.
|
|
52
|
+
Integrate changes into the existing code. Do not rewrite from scratch.
|
|
198
53
|
|
|
199
|
-
[DESCRIBE FEATURE TO ADD
|
|
54
|
+
[DESCRIBE FEATURE TO ADD]`,G=(e,t,n,r=[])=>`Modify file: src/templates/TemplateTable.tsx — powers the "${e?.tabName}" table tab.
|
|
200
55
|
|
|
201
|
-
|
|
56
|
+
Collection: \`${n}\`. Access: Private (user's own data only).
|
|
57
|
+
Integrate changes into the existing code. Do not rewrite from scratch.
|
|
202
58
|
|
|
203
|
-
|
|
204
|
-
\`\`\`json
|
|
205
|
-
${JSON.stringify({tabName:e?.tabName,tabTitle:e?.tabTitle,showButton:e?.showButton,buttonStyle:e?.buttonStyle,showExportButton:e?.showExportButton},null,2)}
|
|
206
|
-
\`\`\`
|
|
59
|
+
[DESCRIBE FEATURE TO ADD]`,K=(e,t,n)=>`Modify file: src/templates/TemplateTable.tsx — powers the "${e?.tabName}" table tab.
|
|
207
60
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
- **Table Data Collection**: \`${n}\`
|
|
211
|
-
- **Access Level**: ADMIN ONLY.
|
|
61
|
+
Collection: \`${n}\`. Access: Admin only.
|
|
62
|
+
Integrate changes into the existing code. Do not rewrite from scratch.
|
|
212
63
|
|
|
213
|
-
|
|
214
|
-
1. **Modify the Core Template**: Carefully edit \`src/templates/TemplateTable.tsx\`.
|
|
215
|
-
2. **Handle UX/UI**: Integrate your changes natively with the existing state (columns, rows, colors) and UI elements.
|
|
64
|
+
[DESCRIBE FEATURE TO ADD]`,se=(e,t,n,r=[])=>`Modify file: src/templates/TemplateTable.tsx — powers the "${e?.tabName}" table tab.
|
|
216
65
|
|
|
217
|
-
|
|
218
|
-
|
|
66
|
+
Collection: \`${n}\`. Access: Public/Shared.
|
|
67
|
+
Integrate changes into the existing code. Do not rewrite from scratch.
|
|
219
68
|
|
|
220
|
-
|
|
69
|
+
[DESCRIBE FEATURE TO ADD]`,q=(e,t)=>{let n=`${(e.tabName||e.pageId||`shared_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`).split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}Content`;return`Create file: src/your-ai-workflow-firebase-os/microcomponents/${n}.tsx
|
|
221
70
|
|
|
222
|
-
|
|
71
|
+
This tab already has working Add/Upload/Delete buttons. You are enhancing it — not rebuilding it.
|
|
223
72
|
|
|
224
|
-
|
|
73
|
+
\`\`\`tsx
|
|
74
|
+
import { useEffect } from 'react';
|
|
225
75
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
76
|
+
export default function ${n}({ config, actions }: { config: any; actions: any }) {
|
|
77
|
+
const { records, loading, setAddForm, setFileHandler } = actions;
|
|
78
|
+
|
|
79
|
+
// 1. Customize the Add button's form (replaces default Name + Note popup)
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
actions.setAddForm(({ onSave, onClose, saving }: any) => (
|
|
82
|
+
<div className="p-5 flex flex-col gap-3">
|
|
83
|
+
<span className="text-[14px] font-bold text-foreground">New Entry</span>
|
|
84
|
+
<input className="w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] rounded-xl text-foreground outline-none" placeholder="Name *" />
|
|
85
|
+
<button onClick={() => onSave({ name: 'value' })} className="btn-primary px-4 py-2 rounded-xl text-sm font-bold">Save</button>
|
|
86
|
+
</div>
|
|
87
|
+
));
|
|
88
|
+
}, []);
|
|
89
|
+
|
|
90
|
+
// 2. Render records as styled cards
|
|
91
|
+
return (
|
|
92
|
+
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
93
|
+
{records.map((r: any) => (
|
|
94
|
+
<div key={r.id} className="bg-background border border-[var(--panel-border)] rounded-2xl p-5 hover:border-accent/30 hover:shadow-lg transition-all">
|
|
95
|
+
<p className="text-[14px] font-bold text-foreground">{r.name}</p>
|
|
96
|
+
<p className="text-[12px] text-foreground/50">{r.note}</p>
|
|
97
|
+
</div>
|
|
98
|
+
))}
|
|
99
|
+
</div>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
229
102
|
\`\`\`
|
|
230
103
|
|
|
231
|
-
|
|
232
|
-
The current tab is configured with:
|
|
233
|
-
- **Table Data Collection**: \`${n}\`
|
|
234
|
-
- **Access Level**: PUBLIC/SHARED.
|
|
104
|
+
Collection: \`${t}\` — shared between all members.
|
|
235
105
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
`):`- No active public forms found`}
|
|
106
|
+
Actions: \`setAddForm(Component)\` — replaces popup form. Component gets \`{ onSave, onClose, saving }\`. Call \`onSave({ name, ...anyFields })\`.
|
|
107
|
+
\`setFileHandler((file, url, meta) => {})\` — hook after file upload.
|
|
108
|
+
\`records\` — live array. \`saveRecord(data)\` / \`deleteRecord(id)\` — direct CRUD.
|
|
240
109
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
110
|
+
Design rules:
|
|
111
|
+
- Match the dark glassmorphism aesthetic. NO bg-white, NO text-gray-*, NO bg-indigo-*.
|
|
112
|
+
- Cards: \`bg-background border border-[var(--panel-border)] rounded-2xl\`. Text: \`text-foreground\`, \`text-foreground/50\`. Accent: \`text-accent\`, \`bg-accent/10\`.
|
|
113
|
+
- Inputs: \`bg-foreground/[0.03] border border-[var(--panel-border)] rounded-xl text-foreground\`.
|
|
114
|
+
- Buttons: \`btn-primary rounded-xl\`. No other button styles.
|
|
115
|
+
- Keep it minimal and clean. No shadows-on-shadows. No rainbow colors.
|
|
244
116
|
|
|
245
|
-
|
|
246
|
-
${W}
|
|
117
|
+
[WHAT TO BUILD?]`},J=(e,t)=>{let n=`${(e.tabName||e.pageId||`admin_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`).split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}Content`;return`Create file: src/your-ai-workflow-firebase-os/microcomponents/${n}.tsx
|
|
247
118
|
|
|
248
|
-
|
|
119
|
+
This tab already has working Add/Upload/Delete buttons. You are enhancing it — not rebuilding it.
|
|
249
120
|
|
|
250
|
-
|
|
121
|
+
\`\`\`tsx
|
|
122
|
+
import { useEffect } from 'react';
|
|
251
123
|
|
|
252
124
|
export default function ${n}({ config, actions }: { config: any; actions: any }) {
|
|
253
|
-
const { records,
|
|
254
|
-
|
|
125
|
+
const { records, loading, setAddForm, setFileHandler } = actions;
|
|
126
|
+
|
|
127
|
+
// 1. Customize the Add button's form (replaces default Name + Note popup)
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
actions.setAddForm(({ onSave, onClose, saving }: any) => (
|
|
130
|
+
<div className="p-5 flex flex-col gap-3">
|
|
131
|
+
<span className="text-[14px] font-bold text-foreground">New Lead</span>
|
|
132
|
+
{/* Add your fields here */}
|
|
133
|
+
<input className="w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] rounded-xl text-foreground outline-none" placeholder="Name *" />
|
|
134
|
+
<button onClick={() => onSave({ name: 'value' })} className="btn-primary px-4 py-2 rounded-xl text-sm font-bold">Save</button>
|
|
135
|
+
</div>
|
|
136
|
+
));
|
|
137
|
+
}, []);
|
|
138
|
+
|
|
139
|
+
// 2. Render records as styled cards
|
|
140
|
+
return (
|
|
141
|
+
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
142
|
+
{records.map((r: any) => (
|
|
143
|
+
<div key={r.id} className="bg-background border border-[var(--panel-border)] rounded-2xl p-5 hover:border-accent/30 hover:shadow-lg transition-all">
|
|
144
|
+
<p className="text-[14px] font-bold text-foreground">{r.name}</p>
|
|
145
|
+
<p className="text-[12px] text-foreground/50">{r.note}</p>
|
|
146
|
+
</div>
|
|
147
|
+
))}
|
|
148
|
+
</div>
|
|
149
|
+
);
|
|
255
150
|
}
|
|
151
|
+
\`\`\`
|
|
256
152
|
|
|
257
|
-
Collection: \`${t}
|
|
258
|
-
|
|
259
|
-
Available actions from \`actions\` prop:
|
|
260
|
-
- \`records\` — live array of all members' records
|
|
261
|
-
- \`saveRecord({ name, note, ...fields })\` — save a record with any custom fields
|
|
262
|
-
- \`deleteRecord(id)\` — delete by ID
|
|
263
|
-
- \`uploadFile()\` — trigger file upload dialog
|
|
264
|
-
- \`user\` — current Firebase user
|
|
265
|
-
- \`loading\` — boolean
|
|
266
|
-
|
|
267
|
-
Styles — cards: \`glass-panel border border-[var(--panel-border)] rounded-2xl p-6\`. Text: \`text-foreground\`, \`text-foreground/60\`. Accent: \`text-accent\`, \`bg-accent/10\`. Buttons: \`btn-primary px-4 py-2 rounded-xl text-sm font-bold\`.
|
|
268
|
-
No page titles, no nav, no routing. Default export only.
|
|
269
|
-
|
|
270
|
-
[WHAT TO BUILD?]`},le=(e,t)=>{let n=`${(e.tabName||e.pageId||`admin_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`).split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}Content`;return`Create file: src/your-ai-workflow-firebase-os/microcomponents/${n}.tsx
|
|
153
|
+
Collection: \`${t}\`. Access: Admin.
|
|
271
154
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
155
|
+
Actions: \`setAddForm(Component)\` — replaces popup form. Component gets \`{ onSave, onClose, saving }\`. Call \`onSave({ name, ...anyFields })\`.
|
|
156
|
+
\`setFileHandler((file, url, meta) => {})\` — hook after file upload.
|
|
157
|
+
\`records\` — live array. \`saveRecord(data)\` / \`deleteRecord(id)\` — direct CRUD.
|
|
276
158
|
|
|
277
|
-
|
|
159
|
+
Design rules:
|
|
160
|
+
- Match the dark glassmorphism aesthetic. NO bg-white, NO text-gray-*, NO bg-indigo-*.
|
|
161
|
+
- Cards: \`bg-background border border-[var(--panel-border)] rounded-2xl\`. Text: \`text-foreground\`, \`text-foreground/50\`. Accent: \`text-accent\`, \`bg-accent/10\`.
|
|
162
|
+
- Inputs: \`bg-foreground/[0.03] border border-[var(--panel-border)] rounded-xl text-foreground\`.
|
|
163
|
+
- Buttons: \`btn-primary rounded-xl\`. No other button styles.
|
|
164
|
+
- Keep it minimal and clean. No shadows-on-shadows. No rainbow colors.
|
|
278
165
|
|
|
279
|
-
|
|
280
|
-
- \`records\` — live array of saved records
|
|
281
|
-
- \`saveRecord({ name, note, ...fields })\` — save a record with any custom fields
|
|
282
|
-
- \`deleteRecord(id)\` — delete by ID
|
|
283
|
-
- \`uploadFile()\` — trigger file upload dialog
|
|
284
|
-
- \`user\` — current Firebase user
|
|
285
|
-
- \`loading\` — boolean
|
|
166
|
+
[WHAT TO BUILD?]`},Y=(e,t)=>{let n=`${(e.tabName||e.pageId||`private_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`).split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}Content`;return`Create file: src/your-ai-workflow-firebase-os/microcomponents/${n}.tsx
|
|
286
167
|
|
|
287
|
-
|
|
288
|
-
No page titles, no nav, no routing. Default export only.
|
|
168
|
+
This tab already has working Add/Upload/Delete buttons. You are enhancing it — not rebuilding it.
|
|
289
169
|
|
|
290
|
-
|
|
170
|
+
\`\`\`tsx
|
|
171
|
+
import { useEffect } from 'react';
|
|
291
172
|
|
|
292
173
|
export default function ${n}({ config, actions }: { config: any; actions: any }) {
|
|
293
|
-
const { records,
|
|
294
|
-
|
|
174
|
+
const { records, loading, setAddForm, setFileHandler } = actions;
|
|
175
|
+
|
|
176
|
+
// 1. Customize the Add button's form (replaces default Name + Note popup)
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
actions.setAddForm(({ onSave, onClose, saving }: any) => (
|
|
179
|
+
<div className="p-5 flex flex-col gap-3">
|
|
180
|
+
<span className="text-[14px] font-bold text-foreground">New Entry</span>
|
|
181
|
+
<input className="w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] rounded-xl text-foreground outline-none" placeholder="Name *" />
|
|
182
|
+
<button onClick={() => onSave({ name: 'value' })} className="btn-primary px-4 py-2 rounded-xl text-sm font-bold">Save</button>
|
|
183
|
+
</div>
|
|
184
|
+
));
|
|
185
|
+
}, []);
|
|
186
|
+
|
|
187
|
+
// 2. Render records as styled cards
|
|
188
|
+
return (
|
|
189
|
+
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
190
|
+
{records.map((r: any) => (
|
|
191
|
+
<div key={r.id} className="bg-background border border-[var(--panel-border)] rounded-2xl p-5 hover:border-accent/30 hover:shadow-lg transition-all">
|
|
192
|
+
<p className="text-[14px] font-bold text-foreground">{r.name}</p>
|
|
193
|
+
<p className="text-[12px] text-foreground/50">{r.note}</p>
|
|
194
|
+
</div>
|
|
195
|
+
))}
|
|
196
|
+
</div>
|
|
197
|
+
);
|
|
295
198
|
}
|
|
199
|
+
\`\`\`
|
|
296
200
|
|
|
297
201
|
Collection: \`${t}\` — private per user (auto-filtered by uid).
|
|
298
202
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
- \`deleteRecord(id)\` — delete by ID
|
|
303
|
-
- \`uploadFile()\` — trigger file upload dialog
|
|
304
|
-
- \`user\` — current Firebase user
|
|
305
|
-
- \`loading\` — boolean
|
|
203
|
+
Actions: \`setAddForm(Component)\` — replaces popup form. Component gets \`{ onSave, onClose, saving }\`. Call \`onSave({ name, ...anyFields })\`.
|
|
204
|
+
\`setFileHandler((file, url, meta) => {})\` — hook after file upload.
|
|
205
|
+
\`records\` — live array. \`saveRecord(data)\` / \`deleteRecord(id)\` — direct CRUD.
|
|
306
206
|
|
|
307
|
-
|
|
308
|
-
|
|
207
|
+
Design rules:
|
|
208
|
+
- Match the dark glassmorphism aesthetic. NO bg-white, NO text-gray-*, NO bg-indigo-*.
|
|
209
|
+
- Cards: \`bg-background border border-[var(--panel-border)] rounded-2xl\`. Text: \`text-foreground\`, \`text-foreground/50\`. Accent: \`text-accent\`, \`bg-accent/10\`.
|
|
210
|
+
- Inputs: \`bg-foreground/[0.03] border border-[var(--panel-border)] rounded-xl text-foreground\`.
|
|
211
|
+
- Buttons: \`btn-primary rounded-xl\`. No other button styles.
|
|
212
|
+
- Keep it minimal and clean. No shadows-on-shadows. No rainbow colors.
|
|
309
213
|
|
|
310
|
-
[WHAT TO BUILD?]`},de=[{text:`text-red-400`,bgCircle:`bg-red-400`,bgCard:`bg-red-500/[0.08]`,borderCard:`border-red-500/30`,bgLight:`bg-red-500/15`,bgHover:`hover:bg-red-500`,bgAlt:`bg-red-500/[0.04]`,name:`Red`},{text:`text-orange-400`,bgCircle:`bg-orange-400`,bgCard:`bg-orange-500/[0.08]`,borderCard:`border-orange-500/30`,bgLight:`bg-orange-500/15`,bgHover:`hover:bg-orange-500`,bgAlt:`bg-orange-500/[0.04]`,name:`Orange`},{text:`text-yellow-400`,bgCircle:`bg-yellow-400`,bgCard:`bg-yellow-500/[0.08]`,borderCard:`border-yellow-500/30`,bgLight:`bg-yellow-500/15`,bgHover:`hover:bg-yellow-500`,bgAlt:`bg-yellow-500/[0.04]`,name:`Yellow`},{text:`text-green-400`,bgCircle:`bg-green-400`,bgCard:`bg-green-500/[0.08]`,borderCard:`border-green-500/30`,bgLight:`bg-green-500/15`,bgHover:`hover:bg-green-500`,bgAlt:`bg-green-500/[0.04]`,name:`Green`},{text:`text-blue-400`,bgCircle:`bg-blue-400`,bgCard:`bg-blue-500/[0.08]`,borderCard:`border-blue-500/30`,bgLight:`bg-blue-500/15`,bgHover:`hover:bg-blue-500`,bgAlt:`bg-blue-500/[0.04]`,name:`Blue`},{text:`text-accent`,bgCircle:`bg-accent`,bgCard:`bg-accent/[0.08]`,borderCard:`border-accent/30`,bgLight:`bg-accent/15`,bgHover:`hover:bg-accent`,bgAlt:`bg-accent/[0.04]`,name:`Purple`},{text:`text-pink-400`,bgCircle:`bg-pink-400`,bgCard:`bg-pink-500/[0.08]`,borderCard:`border-pink-500/30`,bgLight:`bg-pink-500/15`,bgHover:`hover:bg-pink-500`,bgAlt:`bg-pink-500/[0.04]`,name:`Pink`},{text:`text-foreground/60`,bgCircle:`bg-foreground/30`,bgCard:`bg-foreground/[0.04]`,borderCard:`border-[var(--panel-border)]/50`,bgLight:`bg-foreground/15`,bgHover:`hover:bg-foreground/30`,bgAlt:`bg-foreground/[0.02]`,name:`Default`}];function fe({title:e=`Board View`,subtitle:t=`/templates/board`,backUrl:r=`/templates`,tasksCollection:i=`pub_tasks`,categoriesCollection:s=`pub_categories`,config:c}){let{user:d}=m(),f=!!c;c?.isPrivate&&!c?.isAdmin&&c?.isShared;let p=c?.isAdmin||c?.isShared,h=f?p:!0,g=c?.showButton!==!1,_=c?.buttonText||`+`,v=c?.buttonStyle||`primary`,y=c?.keyName||`key`,b=c?.valueName||`value`,[x,S]=(0,a.useState)([]),[C,w]=(0,a.useState)([]),[T,E]=(0,a.useState)([]),[D,O]=(0,a.useState)(null),[k,A]=(0,a.useState)(null),[j,M]=(0,a.useState)({name:``}),[N,P]=(0,a.useState)([]),[F,I]=(0,a.useState)(null),[L,R]=(0,a.useState)(null),[z,B]=(0,a.useState)(null),[V,ne]=(0,a.useState)(null),[H,U]=(0,a.useState)(!1),[W,G]=(0,a.useState)(null),[K,re]=(0,a.useState)(``),[ie,ae]=(0,a.useState)(null),[oe,se]=(0,a.useState)(!1),ce=c?.isAdmin?J(c,e,i,s):c?.isPrivate?q(c,e,i,s,T):Y(c,e,i,s,T),le=()=>{navigator.clipboard.writeText(ce),se(!0),setTimeout(()=>se(!1),2e3)};(0,a.useEffect)(()=>{let e=c?.isShared,t=c?.isAdmin,r=c?.isPrivate&&!t&&!e,a=!t&&!e&&!r;r||a?(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{let t=a?`public`:`private`;E(e.docs.filter(e=>e.data().formType===t).map(e=>e.id))}):E([]);let l=i.startsWith(`user_`),u=s.startsWith(`user_`);if(l&&!d)return;try{let e=localStorage.getItem(`fbos_board_tasks_${i}`);e&&S(JSON.parse(e));let t=localStorage.getItem(`fbos_board_cats_${s}`);t&&w(JSON.parse(t))}catch{}let f=(0,o.onSnapshot)(l&&d?(0,o.query)((0,o.collection)(n.Tt,i),(0,o.where)(`uid`,`==`,d.uid)):(0,o.collection)(n.Tt,i),e=>{let t=[];e.forEach(e=>{let n=e.data();t.push({id:e.id,categoryId:n.categoryId,name:n.name||n.text||`Unnamed Item`,fields:n.fields||(n.value?[{key:`Label`,value:n.value}]:[]),order:n.order||0})});let n=t.sort((e,t)=>(e.order||0)-(t.order||0));S(n),localStorage.setItem(`fbos_board_tasks_${i}`,JSON.stringify(n))}),p=(0,o.onSnapshot)(u&&d?(0,o.query)((0,o.collection)(n.Tt,s),(0,o.where)(`uid`,`==`,d.uid)):(0,o.collection)(n.Tt,s),e=>{let t=[];if(e.forEach(e=>{t.push({id:e.id,...e.data()})}),t.length===0){let e=[{id:`todo`,title:`To Do`,createdAt:Date.now()-2e3},{id:`in_progress`,title:`In Progress`,createdAt:Date.now()-1e3},{id:`review`,title:`Review`,createdAt:Date.now()}],t=d?{uid:d.uid}:{};e.forEach(e=>(0,o.setDoc)((0,o.doc)(n.Tt,s,e.id),{...t,title:e.title,createdAt:e.createdAt}))}else w(t),localStorage.setItem(`fbos_board_cats_${s}`,JSON.stringify(t))});return()=>{f(),p()}},[i,s,d]);let ue=(e,t)=>{t?(A(t.id),M({id:t.id,name:t.name}),P(t.fields?.length?[...t.fields,{key:``,value:``}]:[{key:``,value:``}])):(O(e),M({name:``}),P([{key:``,value:``}]))},fe=(e,t,n)=>{let r=[...N];r[e]={key:t,value:n},e===N.length-1&&(t.trim()!==``||n.trim()!==``)&&r.push({key:``,value:``}),P(r)},X=(e,t)=>{e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`taskId`,t),I(t)},pe=(e,t)=>{e.preventDefault(),e.stopPropagation(),t!==F&&R(t)},me=(e,t)=>{e.preventDefault(),e.stopPropagation(),B(t)},Z=e=>{e.preventDefault(),R(null),B(null)},he=async(e,t,r)=>{e.preventDefault(),e.stopPropagation(),R(null),B(null);let a=e.dataTransfer.getData(`taskId`);if(!a||a===r){I(null);return}let s=x.find(e=>e.id===a);if(!s)return;let c=x.filter(e=>e.categoryId===t).sort((e,t)=>(e.order||0)-(t.order||0));if(s.categoryId===t?(c=c.filter(e=>e.id!==a),c.push(s)):c.push({...s,categoryId:t}),r){let e=c.findIndex(e=>e.id===r),t=c.findIndex(e=>e.id===a),[n]=c.splice(t,1);c.splice(e,0,n)}c.forEach((e,r)=>{let a={categoryId:t,order:r};d&&(a.uid=d.uid),(0,o.setDoc)((0,o.doc)(n.Tt,i,e.id),a,{merge:!0})}),I(null)},ge=async e=>{let t=j.id||`item_${Date.now()}`,r=j.name.trim(),a=r||`Untitled Item`,s=N.filter(e=>e.key.trim()!==``||e.value.trim()!==``),c=!0,l=j.id?x.find(e=>e.id===j.id):null;if(l){let e=JSON.stringify(l.fields||[]),t=JSON.stringify(s);l.name===a&&e===t&&(c=!1)}else !r&&s.length===0&&(c=!1);if(!c){O(null),A(null);return}ne(j.id||`new`);let u={categoryId:e,name:a,fields:s};d&&!j.id&&(u.uid=d.uid),await(0,o.setDoc)((0,o.doc)(n.Tt,i,t),u,{merge:!0}),setTimeout(()=>{O(null),A(null),ne(null)},400)},_e=(e,t)=>{ae({type:`item`,id:e,title:t})},ve=async()=>{let e=`cat_${Date.now()}`,t={title:``,createdAt:Date.now()};d&&(t.uid=d.uid),await(0,o.setDoc)((0,o.doc)(n.Tt,s,e),t),G(e),re(``),setTimeout(()=>{let e=document.getElementById(`board-container`);e&&e.scrollTo({left:e.scrollWidth,behavior:`smooth`})},150)},Q=async e=>{K.trim()?await(0,o.setDoc)((0,o.doc)(n.Tt,s,e),{title:K},{merge:!0}):await(0,o.deleteDoc)((0,o.doc)(n.Tt,s,e)),G(null)},ye=(e,t)=>{ae({type:`category`,id:e,title:t})},be=async()=>{if(ie){U(!0);try{if(ie.type===`item`)await(0,o.deleteDoc)((0,o.doc)(n.Tt,i,ie.id)),A(null);else{let e=x.filter(e=>e.categoryId===ie.id);for(let t of e)await(0,o.deleteDoc)((0,o.doc)(n.Tt,i,t.id));await(0,o.deleteDoc)((0,o.doc)(n.Tt,s,ie.id))}}catch{}U(!1),ae(null)}},xe=[...C].sort((e,t)=>(e.createdAt||0)-(t.createdAt||0));return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen overflow-x-hidden`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e}),t&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),t]})]}),f&&(0,l.jsx)(`div`,{className:`mb-6`,children:(0,l.jsx)(ee,{})}),(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between items-start sm:items-center mb-6 border-b border-[var(--panel-border)] pb-6 gap-4 relative z-20 shrink-0`,children:[!f&&r&&(0,l.jsxs)(u.Link,{to:r,className:`px-5 py-2 hover:bg-foreground/5 transition-all flex items-center gap-2`,style:{borderRadius:`var(--btn-radius, 0.75rem)`},children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` Go Back`]}),f&&(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:c?.tabTitle||c?.tabName||e}),(0,l.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[x.length,` `,x.length===1?`item`:`items`,` · `,xe.length,` `,xe.length===1?`category`:`categories`]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 w-full sm:w-auto`,children:[c?.showPrompt&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:le,title:oe?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${oe?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary shadow-lg`}`,children:oe?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),g&&(0,l.jsx)(n.n,{variant:v===`secondary`?`secondary`:void 0,onClick:ve,className:`flex-1 sm:flex-none px-3 py-2.5 text-[14px] font-bold rounded-xl shadow-lg hover:-translate-y-0.5 transition-all shrink-0`,children:_===`+`?(0,l.jsx)(n.C,{className:`w-4 h-4`}):_})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative z-40 min-h-0`,children:(0,l.jsxs)(`div`,{id:`board-container`,className:`w-full h-full flex flex-row gap-4 md:gap-6 overflow-x-auto pb-4 snap-x snap-mandatory styled-scrollbars items-start`,children:[xe.map((e,t)=>{let r=x.filter(t=>t.categoryId===e.id);r.sort((e,t)=>(e.order||0)-(t.order||0));let i=de.find(t=>t.text===e.color)||de.find(e=>e.text===`text-accent`);return i.text,i.bgLight,i.bgHover,(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:t*.1},className:`w-[300px] md:w-[320px] shrink-0 flex flex-col max-h-full rounded-3xl p-4 snap-center relative border transition-colors ${de.find(t=>t.text===e.color)?.bgCard||`bg-foreground/[0.02]`} ${de.find(t=>t.text===e.color)?.borderCard||`border-[var(--panel-border)]/50`}`,children:[(0,l.jsx)(`div`,{className:`flex items-center justify-between mb-4 px-2 relative z-[200]`,children:(0,l.jsxs)(`h3`,{className:`font-bold text-[14px] flex items-center w-full text-foreground/80 group relative z-[200]`,children:[W===e.id?(0,l.jsxs)(`div`,{className:`relative flex-1 w-full flex items-center pr-8 z-[200]`,children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),Q(e.id)}}),(0,l.jsx)(`input`,{value:K,onChange:e=>re(e.target.value),onBlur:t=>{t.relatedTarget?.closest(`.category-color-picker`)||Q(e.id)},onKeyDown:t=>t.key===`Enter`&&Q(e.id),className:`bg-transparent border-none outline-none font-bold text-[14px] w-full p-0 ${e.color||`text-foreground/80`}`,placeholder:`Category name`}),(0,l.jsxs)(`div`,{className:`absolute top-8 left-0 flex gap-1.5 bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-[100] category-color-picker items-center`,tabIndex:-1,children:[(0,l.jsx)(`button`,{onClick:async t=>{t.preventDefault(),t.stopPropagation(),await(0,o.setDoc)((0,o.doc)(n.Tt,`pub_categories`,e.id),{color:``},{merge:!0}),G(null)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Reset Category Color`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})}),(0,l.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),de.map(t=>(0,l.jsx)(`button`,{onMouseDown:async r=>{r.preventDefault(),await(0,o.setDoc)((0,o.doc)(n.Tt,`pub_categories`,e.id),{color:t.text},{merge:!0})},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50 shrink-0`},t.name))]})]}):(0,l.jsxs)(`div`,{className:`flex items-center gap-2 w-full cursor-pointer hover:text-foreground transition-colors pr-8`,onClick:()=>{G(e.id),re(e.title)},children:[(0,l.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${de.find(t=>t.text===e.color)?.bgCircle||`bg-foreground/20`} transition-colors shrink-0`}),(0,l.jsx)(`span`,{className:`truncate flex-1 max-w-[200px] ${e.color||``}`,children:e.title||`Untitled Category`}),(0,l.jsx)(`span`,{className:`text-[11px] bg-foreground/10 text-foreground/60 px-1.5 py-0.5 rounded-md font-medium shrink-0`,children:r.length})]}),C.length>1&&(0,l.jsx)(`button`,{onClick:()=>ye(e.id,e.title),className:`absolute right-0 opacity-0 group-hover:opacity-100 text-foreground/30 hover:text-red-500 transition-all shrink-0`,children:(0,l.jsx)(n.m,{className:`w-3.5 h-3.5`})})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-2.5 flex-1 overflow-y-auto styled-scrollbars pr-1 relative min-h-[150px] rounded-xl transition-all ${z===e.id&&!L?`bg-foreground/5 scale-[1.01] border-dashed border border-accent/20`:``}`,onDragOver:t=>me(t,e.id),onDragLeave:Z,onDrop:t=>he(t,e.id),children:[(0,l.jsx)(n.a,{children:r.map(t=>k===t.id?(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-md border border-accent/40 transition-all flex flex-col gap-2 relative z-[100]`,children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),ge(e.id)}}),(0,l.jsx)(`textarea`,{placeholder:`Write an item name...`,className:`no-glow bg-transparent border-none outline-none text-[13px] text-foreground/90 font-medium leading-snug resize-none w-full min-h-[40px] relative z-10`,value:j.name,onChange:e=>M({...j,name:e.target.value}),onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),ge(e.id))}}),(0,l.jsx)(`div`,{className:`flex flex-col gap-2 mt-1 relative z-10 w-full`,children:N.map((t,n)=>(0,l.jsxs)(`div`,{className:`flex items-start bg-foreground/[0.04] border border-[var(--panel-border)]/50 rounded-[8px] px-2.5 py-1.5 w-full`,children:[(0,l.jsx)(`input`,{placeholder:y,value:t.key,onChange:e=>fe(n,e.target.value,t.value),onKeyDown:t=>t.key===`Enter`&&ge(e.id),className:`no-glow bg-transparent outline-none text-[11px] text-foreground/50 font-bold placeholder:text-foreground/30 relative top-[1px] shrink-0`,style:{width:`${Math.max(3,t.key.length||y.length)}ch`}}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative top-[1px]`,children:`:`}),(0,l.jsx)(`textarea`,{rows:1,placeholder:b,value:t.value,onChange:e=>fe(n,t.key,e.target.value),onInput:e=>{let t=e.target;t.style.height=`auto`,t.style.height=t.scrollHeight+`px`},onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),ge(e.id))},className:`no-glow bg-transparent outline-none text-[12px] text-foreground/90 font-medium flex-1 min-w-[40px] placeholder:opacity-40 resize-none overflow-hidden leading-tight relative top-[1px]`})]},n))}),V===t.id&&(0,l.jsx)(`div`,{className:`flex items-center justify-end pt-1`,children:(0,l.jsx)(`div`,{className:`w-3 h-3 border-2 border-accent border-t-transparent rounded-full animate-spin`})})]},t.id):(0,l.jsxs)(n.i.div,{draggable:!0,onDragStart:e=>X(e,t.id),onDragOver:e=>pe(e,t.id),onDragLeave:Z,onDrop:n=>he(n,e.id,t.id),initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-sm hover:shadow-md cursor-grab active:cursor-grabbing hover:border-accent/40 transition-all group flex flex-col gap-2 relative z-10 border ${L===t.id?`border-accent border-t-2 translate-y-1`:`border-[var(--panel-border)]`} ${F===t.id?`opacity-30 scale-95 border-dashed border-2`:``}`,children:[(0,l.jsxs)(`div`,{className:`absolute top-2 right-2 flex items-center gap-1.5 opacity-0 group-hover:opacity-100 transition-opacity bg-background/90 backdrop-blur-md border border-[var(--panel-border)] rounded-lg p-1 z-20 shadow-md`,children:[(0,l.jsx)(`button`,{onClick:n=>{n.stopPropagation(),ue(e.id,t)},className:`p-1 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-accent transition-colors`,children:(0,l.jsx)(n.w,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),_e(t.id,t.name)},className:`p-1 hover:bg-red-500/10 rounded-md text-foreground/60 hover:text-red-500 transition-colors`,children:(0,l.jsx)(n.m,{className:`w-3.5 h-3.5`})})]}),(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/90 font-medium leading-snug break-words pr-12`,children:t.name}),t.fields&&t.fields.length>0&&(0,l.jsx)(`div`,{className:`flex flex-row flex-wrap gap-2 mt-2`,children:t.fields.map((e,t)=>(0,l.jsxs)(`div`,{className:`inline-flex bg-foreground/[0.04] border border-[var(--panel-border)]/50 rounded-[8px] px-2.5 py-1.5 max-w-full`,children:[(0,l.jsxs)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative -top-[1px] shrink-0 break-all`,children:[e.key,`:`]}),(0,l.jsx)(`span`,{className:`text-[12px] text-foreground/90 font-medium break-words leading-tight min-w-0`,children:e.value})]},t))}),(0,l.jsxs)(`div`,{className:`flex items-end justify-between mt-3 pt-3 border-t border-[var(--panel-border)]/50 w-full gap-2`,children:[h&&f&&d?(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 pr-2 border-r border-[var(--panel-border)] border-dashed mr-auto`,children:[d.photoURL?(0,l.jsx)(`img`,{src:d.photoURL,className:`w-4 h-4 rounded-full shrink-0 object-cover`}):(0,l.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-accent/20 text-accent flex items-center justify-center text-[9px] font-bold shrink-0`,children:(d.displayName||d.email||`U`)[0].toUpperCase()}),(0,l.jsx)(`span`,{className:`text-[10px] font-bold text-foreground/60 truncate max-w-[80px]`,children:d.displayName||d.email?.split(`@`)[0]||`User`})]}):(0,l.jsx)(`div`,{className:`flex items-center gap-2 pr-2 border-r border-[var(--panel-border)] border-dashed mr-auto`}),(0,l.jsx)(`span`,{className:`text-[10px] text-foreground/40 font-bold text-right pt-0.5 shrink-0 max-w-[50%] truncate flex-1`,children:t.id.startsWith(`item_`)?new Date(parseInt(t.id.split(`_`)[1])).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}):`Recently Added`})]})]},t.id))}),D===e.id?(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-md border border-accent/40 transition-all flex flex-col gap-2 relative z-[100] mt-1`,children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),ge(e.id)}}),(0,l.jsx)(`textarea`,{placeholder:`Write an item name...`,className:`no-glow bg-transparent border-none outline-none text-[13px] text-foreground/90 font-medium leading-snug resize-none w-full min-h-[40px] relative z-10`,value:j.name,onChange:e=>M({...j,name:e.target.value}),onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),ge(e.id))},autoFocus:!0}),(0,l.jsx)(`div`,{className:`flex flex-col gap-2 mt-1 relative z-10 w-full`,children:N.map((t,n)=>(0,l.jsxs)(`div`,{className:`flex items-start bg-foreground/[0.04] border border-[var(--panel-border)]/50 rounded-[8px] px-2.5 py-1.5 w-full`,children:[(0,l.jsx)(`input`,{placeholder:y,style:{width:`${Math.max(3,t.key.length||y.length)}ch`},value:t.key,onChange:e=>fe(n,e.target.value,t.value),onKeyDown:t=>t.key===`Enter`&&ge(e.id),className:`no-glow bg-transparent outline-none text-[11px] text-foreground/50 font-bold placeholder:text-foreground/30 relative top-[1px]`}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative top-[1px]`,children:`:`}),(0,l.jsx)(`textarea`,{rows:1,placeholder:b,value:t.value,onChange:e=>fe(n,t.key,e.target.value),onInput:e=>{let t=e.target;t.style.height=`auto`,t.style.height=t.scrollHeight+`px`},onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),ge(e.id))},className:`no-glow bg-transparent outline-none text-[12px] text-foreground/90 font-medium flex-1 min-w-[40px] placeholder:opacity-40 resize-none overflow-hidden leading-tight relative top-[1px]`})]},n))}),V===`new`&&(0,l.jsx)(`div`,{className:`flex items-center justify-end pt-1`,children:(0,l.jsx)(`div`,{className:`w-3 h-3 border-2 border-accent border-t-transparent rounded-full animate-spin`})})]}):(0,l.jsxs)(`button`,{onClick:()=>ue(e.id),className:`flex items-center gap-2 justify-center w-full py-2.5 mt-1 rounded-xl border border-transparent text-[12px] font-bold text-foreground/40 hover:text-foreground hover:bg-foreground/[0.03] transition-all shrink-0`,children:[(0,l.jsx)(n.C,{className:`w-4 h-4`}),` Add Item`]})]})]},e.id)}),(0,l.jsx)(`div`,{className:`w-[10px] shrink-0 pointer-events-none`})]})}),(0,l.jsx)(`style`,{children:`.styled-scrollbars::-webkit-scrollbar { width: 6px; height: 6px; } .styled-scrollbars::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--accent-color) 20%, transparent); border-radius: 4px; } .styled-scrollbars::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--accent-color) 40%, transparent); }`}),(0,l.jsx)(te,{isOpen:!!ie,title:`Confirm Deletion`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:ie?.title}),` This action is permanent.`]}),onConfirm:be,onCancel:()=>ae(null),isProcessing:H,confirmText:`Yes, Delete`})]})}function X(e){return Array.isArray?Array.isArray(e):be(e)===`[object Array]`}function pe(e){if(typeof e==`string`)return e;if(typeof e==`bigint`)return e.toString();let t=e+``;return t==`0`&&1/e==-1/0?`-0`:t}function me(e){return e==null?``:pe(e)}function Z(e){return typeof e==`string`}function he(e){return typeof e==`number`}function ge(e){return e===!0||e===!1||ve(e)&&be(e)==`[object Boolean]`}function _e(e){return typeof e==`object`}function ve(e){return _e(e)&&e!==null}function Q(e){return e!=null}function ye(e){return!e.trim().length}function be(e){return e==null?e===void 0?`[object Undefined]`:`[object Null]`:Object.prototype.toString.call(e)}var xe=`Incorrect 'index' type`,Se=e=>`Invalid value for key ${e}`,Ce=e=>`Pattern length exceeds max of ${e}.`,we=e=>`Missing ${e} property in key`,Te=e=>`Property 'weight' in key '${e}' must be a positive integer`,Ee=Object.prototype.hasOwnProperty,De=class{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(e=>{let n=Oe(e);this._keys.push(n),this._keyMap[n.id]=n,t+=n.weight}),this._keys.forEach(e=>{e.weight/=t})}get(e){return this._keyMap[e]}keys(){return this._keys}toJSON(){return JSON.stringify(this._keys)}};function Oe(e){let t=null,n=null,r=null,i=1,a=null;if(Z(e)||X(e))r=e,t=ke(e),n=Ae(e);else{if(!Ee.call(e,`name`))throw Error(we(`name`));let o=e.name;if(r=o,Ee.call(e,`weight`)&&(i=e.weight,i<=0))throw Error(Te(o));t=ke(o),n=Ae(o),a=e.getFn}return{path:t,id:n,weight:i,src:r,getFn:a}}function ke(e){return X(e)?e:e.split(`.`)}function Ae(e){return X(e)?e.join(`.`):e}function je(e,t){let n=[],r=!1,i=(e,t,a,o)=>{if(Q(e))if(!t[a])n.push(o===void 0?e:{v:e,i:o});else{let s=e[t[a]];if(!Q(s))return;if(a===t.length-1&&(Z(s)||he(s)||ge(s)||typeof s==`bigint`))n.push(o===void 0?me(s):{v:me(s),i:o});else if(X(s)){r=!0;for(let e=0,n=s.length;e<n;e+=1)i(s[e],t,a+1,e)}else t.length&&i(s,t,a+1,o)}};return i(e,Z(t)?t.split(`.`):t,0),r?n:n[0]}var Me={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Ne={isCaseSensitive:!1,ignoreDiacritics:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(e,t)=>e.score===t.score?e.idx<t.idx?-1:1:e.score<t.score?-1:1},Pe={location:0,threshold:.6,distance:100},Fe={useExtendedSearch:!1,useTokenSearch:!1,getFn:je,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1},$=Object.freeze({...Ne,...Me,...Pe,...Fe}),Ie=/[^ ]+/g;function Le(e=1,t=3){let n=new Map,r=10**t;return{get(t){let i=t.match(Ie).length;if(n.has(i))return n.get(i);let a=1/i**(.5*e),o=parseFloat(Math.round(a*r)/r);return n.set(i,o),o},clear(){n.clear()}}}var Re=class{constructor({getFn:e=$.getFn,fieldNormWeight:t=$.fieldNormWeight}={}){this.norm=Le(t,3),this.getFn=e,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((e,t)=>{this._keysMap[e.id]=t})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,Z(this.docs[0])?this.docs.forEach((e,t)=>{this._addString(e,t)}):this.docs.forEach((e,t)=>{this._addObject(e,t)}),this.norm.clear())}add(e){let t=this.size();Z(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,n=this.size();t<n;t+=1)--this.records[t].i}removeAll(e){for(let t=e.length-1;t>=0;--t)this.records.splice(e[t],1);for(let e=0,t=this.records.length;e<t;e+=1)this.records[e].i=e}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_addString(e,t){if(!Q(e)||ye(e))return;let n={v:e,i:t,n:this.norm.get(e)};this.records.push(n)}_addObject(e,t){let n={i:t,$:{}};this.keys.forEach((t,r)=>{let i=t.getFn?t.getFn(e):this.getFn(e,t.path);if(Q(i)){if(X(i)){let e=[];for(let t=0,n=i.length;t<n;t+=1){let n=i[t];if(Q(n)){if(Z(n)){if(!ye(n)){let r={v:n,i:t,n:this.norm.get(n)};e.push(r)}}else if(Q(n.v)){let t=Z(n.v)?n.v:me(n.v);if(!ye(t)){let r={v:t,i:n.i,n:this.norm.get(t)};e.push(r)}}}}n.$[r]=e}else if(Z(i)&&!ye(i)){let e={v:i,n:this.norm.get(i)};n.$[r]=e}}}),this.records.push(n)}toJSON(){return{keys:this.keys.map(({getFn:e,...t})=>t),records:this.records}}};function ze(e,t,{getFn:n=$.getFn,fieldNormWeight:r=$.fieldNormWeight}={}){let i=new Re({getFn:n,fieldNormWeight:r});return i.setKeys(e.map(Oe)),i.setSources(t),i.create(),i}function Be(e,{getFn:t=$.getFn,fieldNormWeight:n=$.fieldNormWeight}={}){let{keys:r,records:i}=e,a=new Re({getFn:t,fieldNormWeight:n});return a.setKeys(r),a.setIndexRecords(i),a}function Ve(e=[],t=$.minMatchCharLength){let n=[],r=-1,i=-1,a=0;for(let o=e.length;a<o;a+=1){let o=e[a];o&&r===-1?r=a:!o&&r!==-1&&(i=a-1,i-r+1>=t&&n.push([r,i]),r=-1)}return e[a-1]&&a-r>=t&&n.push([r,a-1]),n}var He=32;function Ue(e,t,n,{location:r=$.location,distance:i=$.distance,threshold:a=$.threshold,findAllMatches:o=$.findAllMatches,minMatchCharLength:s=$.minMatchCharLength,includeMatches:c=$.includeMatches,ignoreLocation:l=$.ignoreLocation}={}){if(t.length>He)throw Error(Ce(He));let u=t.length,d=e.length,f=Math.max(0,Math.min(r,d)),p=a,m=f,h=(e,t)=>{let n=e/u;if(l)return n;let r=Math.abs(f-t);return i?n+r/i:r?1:n},g=s>1||c,_=g?Array(d):[],v;for(;(v=e.indexOf(t,m))>-1;){let e=h(0,v);if(p=Math.min(e,p),m=v+u,g){let e=0;for(;e<u;)_[v+e]=1,e+=1}}m=-1;let y=[],b=1,x=u+d,S=1<<u-1;for(let t=0;t<u;t+=1){let r=0,i=x;for(;r<i;)h(t,f+i)<=p?r=i:x=i,i=Math.floor((x-r)/2+r);x=i;let a=Math.max(1,f-i+1),s=o?d:Math.min(f+i,d)+u,c=Array(s+2);c[s+1]=(1<<t)-1;for(let r=s;r>=a;--r){let i=r-1,o=n[e[i]];if(g&&(_[i]=+!!o),c[r]=(c[r+1]<<1|1)&o,t&&(c[r]|=(y[r+1]|y[r])<<1|1|y[r+1]),c[r]&S&&(b=h(t,i),b<=p)){if(p=b,m=i,m<=f)break;a=Math.max(1,2*f-m)}}if(h(t+1,f)>p)break;y=c}let C={isMatch:m>=0,score:Math.max(.001,b)};if(g){let e=Ve(_,s);e.length?c&&(C.indices=e):C.isMatch=!1}return C}function We(e){let t={};for(let n=0,r=e.length;n<r;n+=1){let i=e.charAt(n);t[i]=(t[i]||0)|1<<r-n-1}return t}function Ge(e){if(e.length<=1)return e;e.sort((e,t)=>e[0]-t[0]||e[1]-t[1]);let t=[e[0]];for(let n=1,r=e.length;n<r;n+=1){let r=t[t.length-1],i=e[n];i[0]<=r[1]+1?r[1]=Math.max(r[1],i[1]):t.push(i)}return t}var Ke={ł:`l`,Ł:`L`,đ:`d`,Đ:`D`,ø:`o`,Ø:`O`,ħ:`h`,Ħ:`H`,ŧ:`t`,Ŧ:`T`,ı:`i`,ß:`ss`},qe=RegExp(`[`+Object.keys(Ke).join(``)+`]`,`g`),Je=String.prototype.normalize?e=>e.normalize(`NFD`).replace(/[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]/g,``).replace(qe,e=>Ke[e]):e=>e,Ye=class{constructor(e,{location:t=$.location,threshold:n=$.threshold,distance:r=$.distance,includeMatches:i=$.includeMatches,findAllMatches:a=$.findAllMatches,minMatchCharLength:o=$.minMatchCharLength,isCaseSensitive:s=$.isCaseSensitive,ignoreDiacritics:c=$.ignoreDiacritics,ignoreLocation:l=$.ignoreLocation}={}){if(this.options={location:t,threshold:n,distance:r,includeMatches:i,findAllMatches:a,minMatchCharLength:o,isCaseSensitive:s,ignoreDiacritics:c,ignoreLocation:l},e=s?e:e.toLowerCase(),e=c?Je(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;let u=(e,t)=>{this.chunks.push({pattern:e,alphabet:We(e),startIndex:t})},d=this.pattern.length;if(d>He){let e=0,t=d%He,n=d-t;for(;e<n;)u(this.pattern.substr(e,He),e),e+=He;if(t){let e=d-He;u(this.pattern.substr(e),e)}}else u(this.pattern,0)}searchIn(e){let{isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r}=this.options;if(e=t?e:e.toLowerCase(),e=n?Je(e):e,this.pattern===e){let t={isMatch:!0,score:0};return r&&(t.indices=[[0,e.length-1]]),t}let{location:i,distance:a,threshold:o,findAllMatches:s,minMatchCharLength:c,ignoreLocation:l}=this.options,u=[],d=0,f=!1;this.chunks.forEach(({pattern:t,alphabet:n,startIndex:p})=>{let{isMatch:m,score:h,indices:g}=Ue(e,t,n,{location:i+p,distance:a,threshold:o,findAllMatches:s,minMatchCharLength:c,includeMatches:r,ignoreLocation:l});m&&(f=!0),d+=h,m&&g&&u.push(...g)});let p={isMatch:f,score:f?d/this.chunks.length:1};return f&&r&&(p.indices=Ge(u)),p}},Xe=class{constructor(e){this.pattern=e}static isMultiMatch(e){return Ze(e,this.multiRegex)}static isSingleMatch(e){return Ze(e,this.singleRegex)}search(e){return{isMatch:!1,score:1}}};function Ze(e,t){let n=e.match(t);return n?n[1]:null}var Qe=class extends Xe{constructor(e){super(e)}static get type(){return`exact`}static get multiRegex(){return/^="(.*)"$/}static get singleRegex(){return/^=(.*)$/}search(e){let t=e===this.pattern;return{isMatch:t,score:+!t,indices:[0,this.pattern.length-1]}}},$e=class extends Xe{constructor(e){super(e)}static get type(){return`inverse-exact`}static get multiRegex(){return/^!"(.*)"$/}static get singleRegex(){return/^!(.*)$/}search(e){let t=e.indexOf(this.pattern)===-1;return{isMatch:t,score:+!t,indices:[0,e.length-1]}}},et=class extends Xe{constructor(e){super(e)}static get type(){return`prefix-exact`}static get multiRegex(){return/^\^"(.*)"$/}static get singleRegex(){return/^\^(.*)$/}search(e){let t=e.startsWith(this.pattern);return{isMatch:t,score:+!t,indices:[0,this.pattern.length-1]}}},tt=class extends Xe{constructor(e){super(e)}static get type(){return`inverse-prefix-exact`}static get multiRegex(){return/^!\^"(.*)"$/}static get singleRegex(){return/^!\^(.*)$/}search(e){let t=!e.startsWith(this.pattern);return{isMatch:t,score:+!t,indices:[0,e.length-1]}}},nt=class extends Xe{constructor(e){super(e)}static get type(){return`suffix-exact`}static get multiRegex(){return/^"(.*)"\$$/}static get singleRegex(){return/^(.*)\$$/}search(e){let t=e.endsWith(this.pattern);return{isMatch:t,score:+!t,indices:[e.length-this.pattern.length,e.length-1]}}},rt=class extends Xe{constructor(e){super(e)}static get type(){return`inverse-suffix-exact`}static get multiRegex(){return/^!"(.*)"\$$/}static get singleRegex(){return/^!(.*)\$$/}search(e){let t=!e.endsWith(this.pattern);return{isMatch:t,score:+!t,indices:[0,e.length-1]}}},it=class extends Xe{constructor(e,{location:t=$.location,threshold:n=$.threshold,distance:r=$.distance,includeMatches:i=$.includeMatches,findAllMatches:a=$.findAllMatches,minMatchCharLength:o=$.minMatchCharLength,isCaseSensitive:s=$.isCaseSensitive,ignoreDiacritics:c=$.ignoreDiacritics,ignoreLocation:l=$.ignoreLocation}={}){super(e),this._bitapSearch=new Ye(e,{location:t,threshold:n,distance:r,includeMatches:i,findAllMatches:a,minMatchCharLength:o,isCaseSensitive:s,ignoreDiacritics:c,ignoreLocation:l})}static get type(){return`fuzzy`}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}},at=class extends Xe{constructor(e){super(e)}static get type(){return`include`}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let t=0,n,r=[],i=this.pattern.length;for(;(n=e.indexOf(this.pattern,t))>-1;)t=n+i,r.push([n,t-1]);let a=!!r.length;return{isMatch:a,score:+!a,indices:r}}},ot=[Qe,at,et,tt,rt,nt,$e,it],st=ot.length,ct=`\0`,lt=`|`;function ut(e){let t=[],n=e.length,r=0;for(;r<n;){for(;r<n&&e[r]===` `;)r++;if(r>=n)break;let i=r;for(;i<n&&e[i]!==` `&&e[i]!==`"`;)i++;if(i<n&&e[i]===`"`){for(i++;i<n;){if(e[i]===`"`){let t=i+1;if(t>=n||e[t]===` `){i++;break}if(e[t]===`$`&&(t+1>=n||e[t+1]===` `)){i+=2;break}}i++}t.push(e.substring(r,i)),r=i}else{for(;i<n&&e[i]!==` `;)i++;t.push(e.substring(r,i)),r=i}}return t}function dt(e,t={}){return e.replace(/\\\|/g,ct).split(lt).map(e=>{let n=ut(e.replace(/\u0000/g,`|`).trim()).filter(e=>e&&!!e.trim()),r=[];for(let e=0,i=n.length;e<i;e+=1){let i=n[e],a=!1,o=-1;for(;!a&&++o<st;){let e=ot[o],n=e.isMultiMatch(i);n&&(r.push(new e(n,t)),a=!0)}if(!a)for(o=-1;++o<st;){let e=ot[o],n=e.isSingleMatch(i);if(n){r.push(new e(n,t));break}}}return r})}var ft=new Set([it.type,at.type]),pt=class{constructor(e,{isCaseSensitive:t=$.isCaseSensitive,ignoreDiacritics:n=$.ignoreDiacritics,includeMatches:r=$.includeMatches,minMatchCharLength:i=$.minMatchCharLength,ignoreLocation:a=$.ignoreLocation,findAllMatches:o=$.findAllMatches,location:s=$.location,threshold:c=$.threshold,distance:l=$.distance}={}){this.query=null,this.options={isCaseSensitive:t,ignoreDiacritics:n,includeMatches:r,minMatchCharLength:i,findAllMatches:o,ignoreLocation:a,location:s,threshold:c,distance:l},e=t?e:e.toLowerCase(),e=n?Je(e):e,this.pattern=e,this.query=dt(this.pattern,this.options)}static condition(e,t){return t.useExtendedSearch}searchIn(e){let t=this.query;if(!t)return{isMatch:!1,score:1};let{includeMatches:n,isCaseSensitive:r,ignoreDiacritics:i}=this.options;e=r?e:e.toLowerCase(),e=i?Je(e):e;let a=0,o=[],s=0,c=!1;for(let r=0,i=t.length;r<i;r+=1){let i=t[r];o.length=0,a=0,c=!1;for(let t=0,r=i.length;t<r;t+=1){let r=i[t],{isMatch:l,indices:u,score:d}=r.search(e);if(l){a+=1,s+=d;let e=r.constructor.type;e.startsWith(`inverse`)&&(c=!0),n&&(ft.has(e)?o.push(...u):o.push(u))}else{s=0,a=0,o.length=0,c=!1;break}}if(a){let e={isMatch:!0,score:s/a};return c&&(e.hasInverse=!0),n&&(e.indices=Ge(o)),e}}return{isMatch:!1,score:1}}},mt=[];function ht(...e){mt.push(...e)}function gt(e,t){for(let n=0,r=mt.length;n<r;n+=1){let r=mt[n];if(r.condition(e,t))return new r(e,t)}return new Ye(e,t)}var _t={AND:`$and`,OR:`$or`},vt={PATH:`$path`,PATTERN:`$val`},yt=e=>!!(e[_t.AND]||e[_t.OR]),bt=e=>!!e[vt.PATH],xt=e=>!X(e)&&_e(e)&&!yt(e),St=e=>({[_t.AND]:Object.keys(e).map(t=>({[t]:e[t]}))});function Ct(e,t,{auto:n=!0}={}){let r=e=>{if(Z(e)){let r={keyId:null,pattern:e};return n&&(r.searcher=gt(e,t)),r}let i=Object.keys(e),a=bt(e);if(!a&&i.length>1&&!yt(e))return r(St(e));if(xt(e)){let r=a?e[vt.PATH]:i[0],o=a?e[vt.PATTERN]:e[r];if(!Z(o))throw Error(Se(r));let s={keyId:Ae(r),pattern:o};return n&&(s.searcher=gt(o,t)),s}let o={children:[],operator:i[0]};return i.forEach(t=>{let n=e[t];X(n)&&n.forEach(e=>{o.children.push(r(e))})}),o};return yt(e)||(e=St(e)),r(e)}function wt(e,{ignoreFieldNorm:t=$.ignoreFieldNorm}){let n=1;return e.forEach(({key:e,norm:r,score:i})=>{let a=e?e.weight:null;n*=(i===0&&a?2**-52:i)**+((a||1)*(t?1:r))}),n}function Tt(e,{ignoreFieldNorm:t=$.ignoreFieldNorm}){e.forEach(e=>{e.score=wt(e.matches,{ignoreFieldNorm:t})})}var Et=class{constructor(e){this.limit=e,this.heap=[]}get size(){return this.heap.length}shouldInsert(e){return this.size<this.limit||e<this.heap[0].score}insert(e){this.size<this.limit?(this.heap.push(e),this._bubbleUp(this.size-1)):e.score<this.heap[0].score&&(this.heap[0]=e,this._sinkDown(0))}extractSorted(e){return this.heap.sort(e)}_bubbleUp(e){let t=this.heap;for(;e>0;){let n=e-1>>1;if(t[e].score<=t[n].score)break;let r=t[e];t[e]=t[n],t[n]=r,e=n}}_sinkDown(e){let t=this.heap,n=t.length,r=e;do{e=r;let i=2*e+1,a=2*e+2;if(i<n&&t[i].score>t[r].score&&(r=i),a<n&&t[a].score>t[r].score&&(r=a),r!==e){let n=t[e];t[e]=t[r],t[r]=n}}while(r!==e)}};function Dt(e,t){let n=e.matches;t.matches=[],Q(n)&&n.forEach(e=>{if(!Q(e.indices)||!e.indices.length)return;let{indices:n,value:r}=e,i={indices:n,value:r};e.key&&(i.key=e.key.src),e.idx>-1&&(i.refIndex=e.idx),t.matches.push(i)})}function Ot(e,t){t.score=e.score}function kt(e,t,{includeMatches:n=$.includeMatches,includeScore:r=$.includeScore}={}){let i=[];return n&&i.push(Dt),r&&i.push(Ot),e.map(e=>{let{idx:n}=e,r={item:t[n],refIndex:n};return i.length&&i.forEach(t=>{t(e,r)}),r})}var At=/\b\w+\b/g;function jt({isCaseSensitive:e=!1,ignoreDiacritics:t=!1}={}){return{tokenize(n){return e||(n=n.toLowerCase()),t&&(n=Je(n)),n.match(At)||[]}}}function Mt(e,t,n){let r=new Map,i=new Map,a=0;function o(e,t,o,s){let c=n.tokenize(e);if(!c.length)return;a++;let l=new Map;for(let e of c)l.set(e,(l.get(e)||0)+1);for(let[e,n]of l){let a={docIdx:t,keyIdx:o,subIdx:s,tf:n},c=r.get(e);c||(c=[],r.set(e,c)),c.push(a),i.set(e,(i.get(e)||0)+1)}}for(let n of e){let{i:e,v:r,$:i}=n;if(r!==void 0){o(r,e,-1,-1);continue}if(i)for(let n=0;n<t;n++){let t=i[n];if(t)if(Array.isArray(t))for(let r of t)o(r.v,e,n,r.i??-1);else o(t.v,e,n,-1)}}return{terms:r,fieldCount:a,df:i}}function Nt(e,t,n,r){let{i,v:a,$:o}=t;function s(t,n,a){let o=r.tokenize(t);if(!o.length)return;e.fieldCount++;let s=new Map;for(let e of o)s.set(e,(s.get(e)||0)+1);for(let[t,r]of s){let o={docIdx:i,keyIdx:n,subIdx:a,tf:r},s=e.terms.get(t);s||(s=[],e.terms.set(t,s)),s.push(o),e.df.set(t,(e.df.get(t)||0)+1)}}if(a!==void 0){s(a,-1,-1);return}if(o)for(let e=0;e<n;e++){let t=o[e];if(t)if(Array.isArray(t))for(let n of t)s(n.v,e,n.i??-1);else s(t.v,e,-1)}}function Pt(e,t){for(let[n,r]of e.terms){let i=r.filter(e=>e.docIdx!==t),a=r.length-i.length;a>0&&(e.fieldCount-=a,e.df.set(n,(e.df.get(n)||0)-a),i.length===0?(e.terms.delete(n),e.df.delete(n)):e.terms.set(n,i))}}var Ft=class{constructor(e,t,n){this.options={...$,...t},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new De(this.options.keys),this._docs=e,this._myIndex=null,this._invertedIndex=null,this.setCollection(e,n),this._lastQuery=null,this._lastSearcher=null}_getSearcher(e){if(this._lastQuery===e)return this._lastSearcher;let t=gt(e,this._invertedIndex?{...this.options,_invertedIndex:this._invertedIndex}:this.options);return this._lastQuery=e,this._lastSearcher=t,t}setCollection(e,t){if(this._docs=e,t&&!(t instanceof Re))throw Error(xe);if(this._myIndex=t||ze(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){let e=jt({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});this._invertedIndex=Mt(this._myIndex.records,this._myIndex.keys.length,e)}}add(e){if(Q(e)&&(this._docs.push(e),this._myIndex.add(e),this._invertedIndex)){let e=this._myIndex.records[this._myIndex.records.length-1],t=jt({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});Nt(this._invertedIndex,e,this._myIndex.keys.length,t)}}remove(e=()=>!1){let t=[],n=[];for(let r=0,i=this._docs.length;r<i;r+=1)e(this._docs[r],r)&&(t.push(this._docs[r]),n.push(r));if(n.length){if(this._invertedIndex)for(let e of n)Pt(this._invertedIndex,e);for(let e=n.length-1;e>=0;--e)this._docs.splice(n[e],1);this._myIndex.removeAll(n)}return t}removeAt(e){this._invertedIndex&&Pt(this._invertedIndex,e);let t=this._docs.splice(e,1)[0];return this._myIndex.removeAt(e),t}getIndex(){return this._myIndex}search(e,t){let{limit:n=-1}=t||{},{includeMatches:r,includeScore:i,shouldSort:a,sortFn:o,ignoreFieldNorm:s}=this.options;if(Z(e)&&!e.trim()){let e=this._docs.map((e,t)=>({item:e,refIndex:t}));return he(n)&&n>-1&&(e=e.slice(0,n)),e}let c=he(n)&&n>0&&Z(e),l;if(c){let t=new Et(n);Z(this._docs[0])?this._searchStringList(e,{heap:t,ignoreFieldNorm:s}):this._searchObjectList(e,{heap:t,ignoreFieldNorm:s}),l=t.extractSorted(o)}else l=Z(e)?Z(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e),Tt(l,{ignoreFieldNorm:s}),a&&l.sort(o),he(n)&&n>-1&&(l=l.slice(0,n));return kt(l,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(e,{heap:t,ignoreFieldNorm:n}={}){let r=this._getSearcher(e),{records:i}=this._myIndex,a=t?null:[];return i.forEach(({v:e,i,n:o})=>{if(!Q(e))return;let{isMatch:s,score:c,indices:l}=r.searchIn(e);if(s){let r={item:e,idx:i,matches:[{score:c,value:e,norm:o,indices:l}]};t?(r.score=wt(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):a.push(r)}}),a}_searchLogical(e){let t=Ct(e,this.options),n=(e,t,r)=>{if(!(`children`in e)){let{keyId:n,searcher:i}=e,a;return n===null?(a=[],this._myIndex.keys.forEach((e,n)=>{a.push(...this._findMatches({key:e,value:t[n],searcher:i}))})):a=this._findMatches({key:this._keyStore.get(n),value:this._myIndex.getValueForItemAtKeyId(t,n),searcher:i}),a&&a.length?[{idx:r,item:t,matches:a}]:[]}let{children:i,operator:a}=e,o=[];for(let e=0,s=i.length;e<s;e+=1){let s=i[e],c=n(s,t,r);if(c.length)o.push(...c);else if(a===_t.AND)return[]}return o},r=this._myIndex.records,i=new Map,a=[];return r.forEach(({$:e,i:r})=>{if(Q(e)){let o=n(t,e,r);o.length&&(i.has(r)||(i.set(r,{idx:r,item:e,matches:[]}),a.push(i.get(r))),o.forEach(({matches:e})=>{i.get(r).matches.push(...e)}))}}),a}_searchObjectList(e,{heap:t,ignoreFieldNorm:n}={}){let r=this._getSearcher(e),{keys:i,records:a}=this._myIndex,o=t?null:[];return a.forEach(({$:e,i:a})=>{if(!Q(e))return;let s=[],c=!1,l=!1;if(i.forEach((t,n)=>{let i=this._findMatches({key:t,value:e[n],searcher:r});i.length?(s.push(...i),i[0].hasInverse&&(l=!0)):c=!0}),!(l&&c)&&s.length){let r={idx:a,item:e,matches:s};t?(r.score=wt(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):o.push(r)}}),o}_findMatches({key:e,value:t,searcher:n}){if(!Q(t))return[];let r=[];if(X(t))t.forEach(({v:t,i,n:a})=>{if(!Q(t))return;let{isMatch:o,score:s,indices:c,hasInverse:l}=n.searchIn(t);o&&r.push({score:s,key:e,value:t,idx:i,norm:a,indices:c,hasInverse:l})});else{let{v:i,n:a}=t,{isMatch:o,score:s,indices:c,hasInverse:l}=n.searchIn(i);o&&r.push({score:s,key:e,value:i,norm:a,indices:c,hasInverse:l})}return r}},It=class{static condition(e,t){return t.useTokenSearch}constructor(e,t){this.options=t,this.analyzer=jt({isCaseSensitive:t.isCaseSensitive,ignoreDiacritics:t.ignoreDiacritics});let n=this.analyzer.tokenize(e),{df:r,fieldCount:i}=t._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(let e of n){this.termSearchers.push(new Ye(e,{location:t.location,threshold:t.threshold,distance:t.distance,includeMatches:t.includeMatches,findAllMatches:t.findAllMatches,minMatchCharLength:t.minMatchCharLength,isCaseSensitive:t.isCaseSensitive,ignoreDiacritics:t.ignoreDiacritics,ignoreLocation:!0}));let n=r.get(e)||0,a=Math.log(1+(i-n+.5)/(n+.5));this.idfWeights.push(a)}}searchIn(e){if(!this.termSearchers.length)return{isMatch:!1,score:1};let t=[],n=0,r=0,i=0;for(let a=0;a<this.termSearchers.length;a++){let o=this.termSearchers[a].searchIn(e),s=this.idfWeights[a];r+=s,o.isMatch&&(i++,n+=s*(1-o.score),o.indices&&t.push(...o.indices))}if(i===0)return{isMatch:!1,score:1};let a=r>0?1-n/r:0,o={isMatch:!0,score:Math.max(.001,a)};return this.options.includeMatches&&t.length&&(o.indices=Ge(t)),o}};Ft.version=`7.3.0`,Ft.createIndex=ze,Ft.parseIndex=Be,Ft.config=$,Ft.match=function(e,t,n){return gt(e,{...$,...n}).searchIn(t)},Ft.parseQuery=Ct,ht(pt),ht(It),Ft.use=function(...e){e.forEach(e=>ht(e))};var Lt=[{text:`text-red-400`,bgCircle:`bg-red-400`,bgCard:`bg-red-500/[0.08]`,borderCard:`border-red-500/30`,bgLight:`bg-red-500/15`,bgHover:`hover:bg-red-500`,bgAlt:`bg-red-500/[0.04]`,name:`Red`},{text:`text-orange-400`,bgCircle:`bg-orange-400`,bgCard:`bg-orange-500/[0.08]`,borderCard:`border-orange-500/30`,bgLight:`bg-orange-500/15`,bgHover:`hover:bg-orange-500`,bgAlt:`bg-orange-500/[0.04]`,name:`Orange`},{text:`text-yellow-400`,bgCircle:`bg-yellow-400`,bgCard:`bg-yellow-500/[0.08]`,borderCard:`border-yellow-500/30`,bgLight:`bg-yellow-500/15`,bgHover:`hover:bg-yellow-500`,bgAlt:`bg-yellow-500/[0.04]`,name:`Yellow`},{text:`text-green-400`,bgCircle:`bg-green-400`,bgCard:`bg-green-500/[0.08]`,borderCard:`border-green-500/30`,bgLight:`bg-green-500/15`,bgHover:`hover:bg-green-500`,bgAlt:`bg-green-500/[0.04]`,name:`Green`},{text:`text-blue-400`,bgCircle:`bg-blue-400`,bgCard:`bg-blue-500/[0.08]`,borderCard:`border-blue-500/30`,bgLight:`bg-blue-500/15`,bgHover:`hover:bg-blue-500`,bgAlt:`bg-blue-500/[0.04]`,name:`Blue`},{text:`text-accent`,bgCircle:`bg-accent`,bgCard:`bg-accent/[0.08]`,borderCard:`border-accent/30`,bgLight:`bg-accent/15`,bgHover:`hover:bg-accent`,bgAlt:`bg-accent/[0.04]`,name:`Purple`},{text:`text-pink-400`,bgCircle:`bg-pink-400`,bgCard:`bg-pink-500/[0.08]`,borderCard:`border-pink-500/30`,bgLight:`bg-pink-500/15`,bgHover:`hover:bg-pink-500`,bgAlt:`bg-pink-500/[0.04]`,name:`Pink`},{text:`text-foreground/60`,bgCircle:`bg-foreground/30`,bgCard:`bg-foreground/[0.04]`,borderCard:`border-[var(--panel-border)]/50`,bgLight:`bg-foreground/15`,bgHover:`hover:bg-foreground/30`,bgAlt:`bg-foreground/[0.02]`,name:`Default`}];function Rt({title:e=`Table View`,subtitle:t=`/templates/table`,backUrl:r=`/templates`,tableCollection:i=`pub_table_data`,config:s}){let{user:c}=m(),d=!!s;s?.isPrivate&&!s?.isAdmin&&s?.isShared;let f=s?.isAdmin||s?.isShared,p=d?f:!0,h=s?.showButton!==!1,g=s?.buttonText||`+`,_=s?.buttonStyle||`secondary`,v=s?.showExportButton!==!1,y=s?.showPrompt,[b,x]=(0,a.useState)([]),[S,C]=(0,a.useState)(`demo`),[w,T]=(0,a.useState)(!1),[E,D]=(0,a.useState)(!1),[O,k]=(0,a.useState)(``),[A,te]=(0,a.useState)(!1),[j,M]=(0,a.useState)(!1),[N,P]=(0,a.useState)([]),F=s?.isAdmin?oe(s,e,i):s?.isPrivate?ae(s,e,i,N):se(s,e,i,N),I=()=>{navigator.clipboard.writeText(F),M(!0),setTimeout(()=>M(!1),2e3)},[L,R]=(0,a.useState)(null),[z,B]=(0,a.useState)(null),[V,ne]=(0,a.useState)(``),[H,U]=(0,a.useState)(``),[W,G]=(0,a.useState)(null),[K,re]=(0,a.useState)(null),[ie,q]=(0,a.useState)(!1);(0,a.useEffect)(()=>{let e=s?.isShared,t=s?.isAdmin,r=s?.isPrivate&&!t&&!e,a=!t&&!e&&!r;r||a?(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{let t=a?`public`:`private`;P(e.docs.filter(e=>e.data().formType===t).map(e=>e.id))}):P([]);let l=i.startsWith(`user_`);if(l&&!c)return;try{let e=localStorage.getItem(`fbos_tables_${i}`);e&&x(JSON.parse(e))}catch{}let u=(0,o.onSnapshot)(l&&c?(0,o.query)((0,o.collection)(n.Tt,i),(0,o.where)(`uid`,`==`,c.uid)):(0,o.collection)(n.Tt,i),e=>{let t=[];if(e.forEach(e=>{t.push({id:e.id,...e.data()})}),t.length===0){let e={name:`Unnamed Table`,columns:[`Column 1`,`Column 2`,`Column 3`,`Column 4`],...c?{uid:c.uid}:{},rows:[{id:`1`,"Column 1":``,"Column 2":``,"Column 3":``,"Column 4":``},{id:`2`,"Column 1":``,"Column 2":``,"Column 3":``,"Column 4":``}]};(0,o.setDoc)((0,o.doc)(n.Tt,i,`demo`),e)}else{let e=t.sort((e,t)=>(e.name||``).localeCompare(t.name||``));x(e),localStorage.setItem(`fbos_tables_${i}`,JSON.stringify(e))}});return()=>u()},[i,c]);let J=b.find(e=>e.id===S)||b[0]||{columns:[],rows:[]},Y=async e=>{J.id&&(c&&i.startsWith(`user_`)&&(e.uid=c.uid),await(0,o.setDoc)((0,o.doc)(n.Tt,i,J.id),e,{merge:!0}))},ce=()=>{if(!J.rows||J.rows.length===0)return;let e=J.columns.join(`,`),t=J.rows.map(e=>J.columns.map(t=>`"${e[t]||``}"`).join(`,`)).join(`
|
|
311
|
-
`),n=new Blob([`${e}\n${t}`],{type:`text/csv`}),r=window.URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`export_${J.name||`table`}.csv`,i.click(),window.URL.revokeObjectURL(r)},le=(e,t,n)=>{Y({...J,rows:J.rows.map(r=>r.id===e?{...r,[t]:n}:r)})},ue=()=>{let e={id:Date.now().toString()};J.columns.forEach(t=>e[t]=``),Y({...J,rows:[...J.rows||[],e]})},de=e=>{Y({...J,rows:J.rows.filter(t=>t.id!==e)})},fe=()=>{let e=`Column ${(J.columns?.length||0)+1}`;J.columns?.includes(e)||(Y({...J,columns:[...J.columns||[],e]}),setTimeout(()=>{let e=document.getElementById(`table-scroll-container`);e&&e.scrollTo({left:e.scrollWidth,behavior:`smooth`})},100))},X=e=>{let t=(J.columns||[]).filter(t=>t!==e),n=(J.rows||[]).map(t=>{let n={...t};return delete n[e],n}),r={...J.colColors||{}};delete r[e],Y({...J,columns:t,rows:n,colColors:r})},pe=async e=>{e.trim()&&J.id&&e!==J.name&&await(0,o.setDoc)((0,o.doc)(n.Tt,i,J.id),{name:e},{merge:!0})},me=async()=>{te(!0),T(!1);let e=`tbl_${Date.now()}`;await(0,o.setDoc)((0,o.doc)(n.Tt,i,e),{name:`Unnamed Table`,columns:[`Column 1`,`Column 2`,`Column 3`],...c?{uid:c.uid}:{},rows:[]}),setTimeout(()=>{C(e),te(!1)},600)},Z=e=>{let t=H.trim();if(t&&t!==e&&!J.columns?.includes(t)){let n=J.columns.map(n=>n===e?t:n),r=(J.rows||[]).map(n=>{let r={...n};return r[t]=r[e]||``,delete r[e],r}),i={...J.colColors||{}};i[e]&&(i[t]=i[e],delete i[e]),Y({...J,columns:n,rows:r,colColors:i})}B(null)},he=J.rows||[];return V.trim()!==``&&(he=new Ft(he.map(e=>({...e,_creatorMatch:`Guest`})),{keys:(J.columns||[]).concat([`_creatorMatch`]),threshold:.4,ignoreLocation:!0}).search(V).map(e=>{let{_creatorMatch:t,...n}=e.item;return n})),(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e}),t&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),t]})]}),d&&(0,l.jsx)(`div`,{className:`mb-6`,children:(0,l.jsx)(ee,{})}),(0,l.jsxs)(`div`,{className:`flex justify-between items-center mb-6 border-b border-[var(--panel-border)] pb-6 relative z-20`,children:[!d&&r&&(0,l.jsxs)(u.Link,{to:r,className:`px-4 md:px-5 py-2.5 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold hover:bg-foreground/5 transition-all flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` `,(0,l.jsx)(`span`,{className:`hidden sm:inline`,children:`Go Back`})]}),d&&(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:s?.tabTitle||s?.tabName||e}),(0,l.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[b.length,` `,b.length===1?`table`:`tables`]})]}),(0,l.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[y&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:I,title:j?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${j?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary shadow-lg`}`,children:j?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),v&&(0,l.jsx)(n.n,{variant:`secondary`,onClick:ce,className:`px-3 py-2.5 font-bold rounded-xl shadow-sm border border-[var(--panel-border)] flex items-center gap-2`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})}),h&&(0,l.jsx)(n.n,{variant:_===`primary`?void 0:`secondary`,onClick:ue,className:`px-3 py-2.5 font-bold rounded-xl border border-[var(--panel-border)] shadow-sm flex items-center gap-2`,children:g===`+`?(0,l.jsx)(n.C,{className:`w-4 h-4`}):g})]})]}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative z-10 block`,children:[(0,l.jsx)(`div`,{className:`absolute top-0 right-0 w-[400px] h-[400px] bg-accent/5 blur-[100px] rounded-full pointer-events-none -z-10`}),(0,l.jsxs)(`div`,{className:`p-4 md:px-6 border-b border-[var(--panel-border)]/50 flex flex-col sm:flex-row items-start sm:items-center justify-between bg-foreground/[0.01] gap-4`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col w-full sm:w-auto relative`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 relative`,children:[(0,l.jsxs)(`div`,{className:`relative flex items-center`,children:[E?(0,l.jsx)(`div`,{contentEditable:!0,suppressContentEditableWarning:!0,onBlur:e=>{D(!1),pe(e.currentTarget.textContent||``)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},className:`bg-transparent border-b-2 border-accent outline-none text-[16px] font-bold text-foreground inline-block min-w-[20px] whitespace-nowrap px-1 py-0.5`,children:J.name||`Unnamed Table`}):(0,l.jsx)(`h3`,{className:`font-bold text-[16px] text-foreground/90 cursor-pointer hover:text-accent transition-colors truncate max-w-[200px]`,onClick:()=>D(!0),title:`Click to rename table`,children:J.name||`Unnamed Table`}),(0,l.jsx)(n.a,{children:w&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>T(!1)}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:`absolute top-[120%] left-0 w-[220px] bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] rounded-2xl shadow-2xl z-50 py-2 flex flex-col`,children:[(0,l.jsx)(`div`,{className:`px-4 py-2 text-[10px] font-bold uppercase tracking-wider text-foreground/40 border-b border-[var(--panel-border)] mb-1`,children:`Your Tables`}),(0,l.jsx)(`div`,{className:`max-h-[250px] overflow-y-auto styled-scrollbars z-50 relative`,children:b.map(e=>(0,l.jsx)(`button`,{onClick:()=>{C(e.id),T(!1)},className:`w-full px-4 py-2 text-[13px] font-bold text-left hover:bg-foreground/[0.03] transition-colors truncate ${S===e.id?`text-accent bg-accent/5`:`text-foreground/70`}`,children:e.name||`Unnamed Table`},e.id))}),(0,l.jsx)(`div`,{className:`w-full h-[1px] bg-[var(--panel-border)]/50 my-1`}),(0,l.jsxs)(`button`,{onClick:me,className:`w-full px-4 py-2.5 text-[13px] font-bold text-left text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors flex items-center gap-2`,children:[(0,l.jsx)(n.C,{className:`w-4 h-4`}),` Create New Table`]})]})]})})]}),(0,l.jsx)(`button`,{onClick:()=>T(!w),className:`p-1 px-1.5 rounded-lg hover:bg-foreground/5 transition-colors text-foreground/40 hover:text-foreground shrink-0 border border-transparent hover:border-[var(--panel-border)]`,children:(0,l.jsx)(n.st,{className:`w-4 h-4 transition-transform ${w?`rotate-180 text-accent`:``}`})})]}),(0,l.jsxs)(`span`,{className:`opacity-40 text-[11px] font-bold mt-1 uppercase tracking-wider`,children:[(J.rows||[]).length,` Records`]})]}),(0,l.jsxs)(`div`,{className:`relative w-full sm:max-w-[300px]`,children:[(0,l.jsx)(n.b,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-foreground/40`}),(0,l.jsx)(`input`,{type:`text`,placeholder:`Search active records...`,value:V,onChange:e=>ne(e.target.value),className:`w-full bg-background border border-[var(--panel-border)] rounded-xl py-2.5 px-9 text-[13px] font-medium text-foreground focus:outline-none focus:border-accent transition-colors shadow-inner`})]})]}),(0,l.jsx)(`div`,{id:`table-scroll-container`,className:`overflow-x-auto w-full block min-h-[300px] relative styled-scrollbars`,children:(0,l.jsx)(n.a,{mode:`wait`,children:A?(0,l.jsxs)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 flex flex-col items-center justify-center bg-background/40 backdrop-blur-[2px] z-50`,children:[(0,l.jsx)(`div`,{className:`w-8 h-8 rounded-full border-2 border-accent border-r-transparent animate-spin mb-4`}),(0,l.jsx)(`p`,{className:`text-[11px] font-bold text-foreground/50 uppercase tracking-widest`,children:`Generating Table`})]},`loader`):(0,l.jsxs)(n.i.table,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full text-left border-collapse table-auto relative min-w-[800px]`,children:[(0,l.jsx)(`thead`,{children:(0,l.jsxs)(`tr`,{className:`border-b border-[var(--panel-border)] transition-colors ${J.headerColor?Lt.find(e=>e.text===J.headerColor)?.bgAlt:`bg-foreground/[0.02]`}`,children:[(0,l.jsx)(`th`,{className:`py-4 px-6 text-[12px] font-bold uppercase tracking-wider whitespace-nowrap text-foreground/50 w-32 border-r border-[var(--panel-border)]/20 ${p?``:`hidden`}`,children:`Creator`}),(J.columns||[]).map((e,t)=>{let r=(J.colColors||{})[e],i=(J.colorTimestamps||{})[`col_${e}`]||0;J.headerColor;let a=(J.colorTimestamps||{}).header||0,o=`bg-transparent`,s=`text-foreground/50`;if(r&&r!==`none`&&i>=a){let e=Lt.find(e=>e.text===r);e&&(o=e.bgCard,s=e.text)}return(0,l.jsx)(`th`,{className:`py-3 px-6 text-[12px] font-bold uppercase tracking-wider relative group h-[53px] min-w-[120px] ${s} ${o} border-r border-[var(--panel-border)]/20 last:border-r-0 select-none align-middle`,children:(0,l.jsxs)(`div`,{className:`flex items-center justify-between gap-2 w-full h-full`,children:[z===e?(0,l.jsx)(`div`,{className:`flex-1 min-w-[50px]`,children:(0,l.jsx)(`span`,{contentEditable:!0,suppressContentEditableWarning:!0,onBlur:t=>{B(null),U(t.currentTarget.textContent||``),(t.currentTarget.textContent||``).trim()!==``&&Z(e)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},className:`bg-transparent outline-none border-b border-accent/40 font-bold text-[12px] uppercase tracking-wider p-0 m-0 ${s} block w-full whitespace-nowrap overflow-hidden cursor-text`,ref:e=>{e&&requestAnimationFrame(()=>{e.focus()})},children:H})}):(0,l.jsx)(`div`,{className:`flex items-center gap-2 flex-1 overflow-hidden`,onClick:()=>{B(e),U(e)},children:(0,l.jsx)(`span`,{className:`truncate cursor-text`,children:e})}),(0,l.jsxs)(`div`,{className:`relative shrink-0 flex items-center h-full gap-0.5`,children:[(0,l.jsx)(`button`,{onClick:()=>re(K===e?null:e),className:`p-1.5 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity hover:bg-foreground/10 ${r&&r!==`none`?`!opacity-100`:``} text-current`,children:(0,l.jsx)(n.T,{className:`w-4 h-4`})}),(J.columns||[]).length>1&&(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),X(e)},className:`p-1.5 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500/10 text-foreground/30 hover:text-red-500`,title:`Delete column`,children:(0,l.jsx)(n.m,{className:`w-3.5 h-3.5`})}),K===e&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>re(null)}),(0,l.jsxs)(`div`,{className:`absolute top-8 right-0 flex gap-1.5 bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-50 items-center`,children:[(0,l.jsx)(`button`,{onClick:t=>{t.preventDefault(),t.stopPropagation();let n={...J.colColors||{},[e]:`none`},r={...J.colorTimestamps||{},[`col_${e}`]:Date.now()};Y({...J,colColors:n,colorTimestamps:r}),re(null)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Remove Color`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})}),(0,l.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Lt.map(t=>(0,l.jsx)(`button`,{onClick:n=>{n.preventDefault(),n.stopPropagation();let r={...J.colColors||{},[e]:t.text},i={...J.colorTimestamps||{},[`col_${e}`]:Date.now()};Y({...J,colColors:r,colorTimestamps:i}),re(null)},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50 shrink-0`},t.name))]})]})]})]})},`col_${t}_${e}`)}),(0,l.jsx)(`th`,{className:`py-4 px-4 w-14 border-l border-[var(--panel-border)]/30 relative`,children:(0,l.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 relative z-20`,children:[(0,l.jsx)(`button`,{onClick:()=>q(!ie),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${J.headerColor?Lt.find(e=>e.text===J.headerColor)?.text:`text-foreground/30`}`,children:(0,l.jsx)(n.T,{className:`w-4 h-4`})}),ie&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>q(!1)}),(0,l.jsxs)(`div`,{className:`absolute top-6 right-8 flex gap-1.5 bg-background/90 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-50 items-center`,children:[(0,l.jsx)(`button`,{onClick:()=>{Y({...J,headerColor:``}),q(!1)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Remove Header Color`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})}),(0,l.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Lt.map(e=>(0,l.jsx)(`button`,{onClick:()=>{let t={...J.colorTimestamps||{},header:Date.now()};Y({...J,headerColor:e.text,colorTimestamps:t}),q(!1)},className:`w-4 h-4 rounded-full ${e.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50`},e.name))]})]}),(0,l.jsx)(`button`,{onClick:fe,className:`p-1.5 rounded-lg text-foreground/40 hover:text-accent hover:bg-accent/10 transition-colors flex items-center justify-center`,children:(0,l.jsx)(n.C,{className:`w-4 h-4`})})]})})]})}),(0,l.jsxs)(`tbody`,{children:[he.map((e,t)=>{let r=t%2==1,i=(J.rowColors||{})[e.id],a=i?r?Lt.find(e=>e.text===i)?.bgAlt:Lt.find(e=>e.text===i)?.bgCard:r?`bg-foreground/[0.02]`:`bg-transparent`;return(0,l.jsxs)(`tr`,{className:`border-b border-[var(--panel-border)]/30 hover:bg-foreground/[0.04] transition-colors group`,children:[(0,l.jsx)(`td`,{className:`py-4 px-6 whitespace-nowrap h-[53px] border-r border-[var(--panel-border)]/20 ${a} ${p?``:`hidden`}`,children:(0,l.jsx)(`div`,{className:`flex items-center gap-2`,children:d&&c?(0,l.jsxs)(l.Fragment,{children:[c.photoURL?(0,l.jsx)(`img`,{src:c.photoURL,className:`w-5 h-5 rounded-full shrink-0 object-cover`}):(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/20 text-accent flex items-center justify-center text-[10px] font-bold shrink-0`,children:(c.displayName||c.email||`U`)[0].toUpperCase()}),(0,l.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/80 tracking-tight shrink-0`,children:c.displayName||c.email?.split(`@`)[0]||`User`})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/20 text-accent flex items-center justify-center text-[10px] font-bold shrink-0 shadow-inner group-hover:scale-110 transition-transform`,children:`G`}),(0,l.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/80 tracking-tight shrink-0`,children:`Guest`})]})})}),(J.columns||[]).map(n=>{let i=L?.id===e.id&&L?.field===n,a=(J.colColors||{})[n],o=(J.colorTimestamps||{})[`col_${n}`]||0,s=(J.rowColors||{})[e.id],c=(J.colorTimestamps||{})[`row_${e.id}`]||0,u=``;u=c>o?s===`none`?``:s:o>c?a===`none`?``:a:s===`none`?``:s||a||``,u===`none`&&(u=``);let d=u?Lt.find(e=>e.text===u):null,f=d?r?d.bgAlt:d.bgCard:r?`bg-foreground/[0.02]`:`bg-transparent`,p=d?d.text:`text-foreground/80`;return(0,l.jsxs)(`td`,{className:`py-4 px-6 whitespace-pre-wrap min-w-[120px] text-[14px] font-medium relative ${f} align-top border-r border-[var(--panel-border)]/10 last:border-r-0`,onClick:()=>!i&&R({id:e.id,field:n}),children:[i?(0,l.jsx)(`textarea`,{autoFocus:!0,value:e[n]||``,onChange:t=>le(e.id,n,t.target.value),onBlur:()=>R(null),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&R(null)},className:`absolute inset-0 bg-transparent !border-0 !outline-none focus:!outline-none focus:!ring-0 !ring-0 !shadow-none focus:!shadow-none p-4 px-6 text-[14px] font-medium w-full h-full caret-accent ${p} z-20 resize-none styled-scrollbars`}):null,(0,l.jsx)(`span`,{className:`block w-full min-h-[20px] break-words transition-all ${i?`opacity-0`:`opacity-100`} ${p} ${n===`Status`&&e[n]===`Active`&&!u?`text-green-500`:``}`,children:e[n]||(0,l.jsx)(`span`,{className:`opacity-30 italic font-normal`,children:`empty`})})]},`cell_${e.id||t}_${n}`)}),(0,l.jsx)(`td`,{className:`py-4 px-4 whitespace-nowrap text-right h-[53px] ${a} relative z-10`,children:(0,l.jsxs)(`div`,{className:`flex items-center justify-end gap-1 opacity-20 group-hover:opacity-100 transition-opacity relative`,children:[(0,l.jsx)(`button`,{onClick:()=>G(W===e.id?null:e.id),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${i?Lt.find(e=>e.text===i)?.text:`text-foreground/40`}`,children:(0,l.jsx)(n.T,{className:`w-4 h-4`})}),W===e.id&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>G(null)}),(0,l.jsxs)(`div`,{className:`absolute top-6 right-8 flex gap-1.5 bg-background/90 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-50 items-center`,children:[(0,l.jsx)(`button`,{onClick:t=>{t.preventDefault(),t.stopPropagation();let n={...J.rowColors||{},[e.id]:`none`},r={...J.colorTimestamps||{},[`row_${e.id}`]:Date.now()};Y({...J,rowColors:n,colorTimestamps:r}),G(null)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Remove Row Color`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})}),(0,l.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Lt.map(t=>(0,l.jsx)(`button`,{onClick:()=>{let n={...J.colorTimestamps||{},[`row_${e.id}`]:Date.now()};Y({...J,rowColors:{...J.rowColors||{},[e.id]:t.text},colorTimestamps:n}),G(null)},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50`},t.name))]})]}),(0,l.jsx)(`button`,{onClick:()=>de(e.id),className:`p-2 ml-auto rounded-lg text-foreground/20 hover:text-red-500 hover:bg-red-500/10 transition-colors flex items-center justify-center`,children:(0,l.jsx)(n.m,{className:`w-4 h-4`})})]})})]},e.id||`row_${t}`)}),he.length===0&&(0,l.jsx)(`tr`,{children:(0,l.jsxs)(`td`,{colSpan:(J.columns||[]).length+2,className:`py-12 text-center text-foreground/40 text-[14px] font-medium border border-[var(--panel-border)] m-4 rounded-xl border-dashed`,children:[`No records found in `,J.name||`this table`,`.`]})}),(0,l.jsx)(`tr`,{children:(0,l.jsx)(`td`,{colSpan:(J.columns||[]).length+2,className:`py-2 px-4 border-none bg-foreground/[0.01]`,children:(0,l.jsx)(`div`,{className:`flex items-center gap-4`,children:(0,l.jsx)(`button`,{onClick:ue,className:`p-1.5 rounded-lg text-foreground/40 hover:text-accent hover:bg-accent/10 transition-colors flex items-center justify-center ml-2 border border-transparent hover:border-accent/20`,children:(0,l.jsx)(n.C,{className:`w-4 h-4`})})})})})]})]},`table`)})})]})]})}var zt=[{text:`text-red-400`,bgCircle:`bg-red-400`,bgCard:`bg-red-500/[0.08]`,borderCard:`border-red-500/30`,bgLight:`bg-red-500/15`,bgHover:`hover:bg-red-500`,bgAlt:`bg-red-500/[0.04]`,name:`Red`},{text:`text-orange-400`,bgCircle:`bg-orange-400`,bgCard:`bg-orange-500/[0.08]`,borderCard:`border-orange-500/30`,bgLight:`bg-orange-500/15`,bgHover:`hover:bg-orange-500`,bgAlt:`bg-orange-500/[0.04]`,name:`Orange`},{text:`text-yellow-400`,bgCircle:`bg-yellow-400`,bgCard:`bg-yellow-500/[0.08]`,borderCard:`border-yellow-500/30`,bgLight:`bg-yellow-500/15`,bgHover:`hover:bg-yellow-500`,bgAlt:`bg-yellow-500/[0.04]`,name:`Yellow`},{text:`text-green-400`,bgCircle:`bg-green-400`,bgCard:`bg-green-500/[0.08]`,borderCard:`border-green-500/30`,bgLight:`bg-green-500/15`,bgHover:`hover:bg-green-500`,bgAlt:`bg-green-500/[0.04]`,name:`Green`},{text:`text-blue-400`,bgCircle:`bg-blue-400`,bgCard:`bg-blue-500/[0.08]`,borderCard:`border-blue-500/30`,bgLight:`bg-blue-500/15`,bgHover:`hover:bg-blue-500`,bgAlt:`bg-blue-500/[0.04]`,name:`Blue`},{text:`text-accent`,bgCircle:`bg-accent`,bgCard:`bg-accent/[0.08]`,borderCard:`border-accent/30`,bgLight:`bg-accent/15`,bgHover:`hover:bg-accent`,bgAlt:`bg-accent/[0.04]`,name:`Purple`},{text:`text-pink-400`,bgCircle:`bg-pink-400`,bgCard:`bg-pink-500/[0.08]`,borderCard:`border-pink-500/30`,bgLight:`bg-pink-500/15`,bgHover:`hover:bg-pink-500`,bgAlt:`bg-pink-500/[0.04]`,name:`Pink`},{text:`text-foreground/60`,bgCircle:`bg-foreground/30`,bgCard:`bg-foreground/[0.04]`,borderCard:`border-[var(--panel-border)]/50`,bgLight:`bg-foreground/15`,bgHover:`hover:bg-foreground/30`,bgAlt:`bg-foreground/[0.02]`,name:`Default`}],Bt={dateStr:``,title:``,description:``,time:`12:00`,duration:`60`,color:``,guestEmail:``,customFields:{}};function Vt({title:e=`Calendar View`,subtitle:t=`/templates/calendar`,backUrl:r=`/templates`,eventsCollection:i=`pub_events`,defaultTimeFormat:c=`12h`,config:d}){let f=!!(d?.isPrivate||d?.isAdmin||d?.isShared);d?.isAdmin,d?.isShared,d?.isPrivate;let p=d?.showButton!==!1,m=d?.buttonText||`+`,h=d?.buttonStyle||`primary`,g=d?.showViewsButton!==!1,_=d?.viewsButtonStyle||`secondary`,v=d?.showPrompt!==!1,y=d?.defaultView||`calendar`,b=d?.customFields||[],x=i.startsWith(`user_`)?`private`:i.startsWith(`mem_`)?`shared`:i.startsWith(`admin_`)?`admin_only`:`public`,[S,C]=(0,a.useState)(()=>{try{let e=localStorage.getItem(`cal_view_${i}`);if(e===`list`||e===`month`)return e}catch{}return y===`board`?`list`:`month`}),[w,T]=(0,a.useState)([]),[E,D]=(0,a.useState)([]),[O,k]=(0,a.useState)(!1),[A,j]=(0,a.useState)(null),[M,N]=(0,a.useState)(!1),[P,F]=(0,a.useState)(!1),[I,L]=(0,a.useState)(null),[R,z]=(0,a.useState)(Bt),[B,V]=(0,a.useState)(new Date),[ne,H]=(0,a.useState)(!1),[U,W]=(0,a.useState)(null),[G,q]=(0,a.useState)(null),[J,Y]=(0,a.useState)(!1),ae=`cal_24h_${i}`,[oe,se]=(0,a.useState)(()=>{try{let e=localStorage.getItem(ae);if(e!==null)return e===`true`}catch{}return c===`24h`}),ce=()=>{let e=!oe;se(e);try{localStorage.setItem(ae,String(e))}catch{}};(0,a.useEffect)(()=>{try{localStorage.setItem(`cal_view_${i}`,S)}catch{}x===`public`||x===`private`?(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{let t=x===`public`?`public`:`private`;T(e.docs.filter(e=>e.data().formType===t).map(e=>e.id))}):T([])},[S,i,x]);let le=()=>{let e=S===`month`?`list`:`month`;C(e);try{localStorage.setItem(`cal_view_${i}`,e)}catch{}},ue=()=>{try{return sessionStorage.getItem(`cal_guest_email`)||``}catch{return``}},de=e=>{try{sessionStorage.setItem(`cal_guest_email`,e)}catch{}};(0,a.useEffect)(()=>(0,s.onAuthStateChanged)(n.wt,async e=>{if(W(e),e&&x===`admin_only`)try{let t=await(0,o.getDoc)((0,o.doc)(n.Tt,`user_profiles`,e.uid));t.exists()&&q(t.data())}catch{}Y(!0)}),[x]),(0,a.useEffect)(()=>{if(!J)return;if(x!==`public`&&!U){D([]);return}try{let e=localStorage.getItem(`fbos_cal_${i}`);e&&D(JSON.parse(e))}catch{}let e=(0,o.onSnapshot)(x===`private`&&U?(0,o.query)((0,o.collection)(n.Tt,i),(0,o.where)(`uid`,`==`,U.uid)):(0,o.collection)(n.Tt,i),e=>{let t=[];e.forEach(e=>t.push({id:e.id,...e.data()})),D(t),localStorage.setItem(`fbos_cal_${i}`,JSON.stringify(t))},e=>console.error(`Calendar events:`,e));return()=>e()},[i,x,U?.uid,J]);let fe=e=>!!U&&U.uid===e.uid,X=e=>x===`public`?!1:x===`private`?!!U:fe(e),pe=e=>{if(!e)return``;if(oe)return e;let[t,n]=e.split(`:`),r=parseInt(t,10),i=r>=12?`PM`:`AM`;return r=r%12||12,`${r}:${n} ${i}`},me=e=>{if(!e)return`60m`;let t=parseInt(e,10);return isNaN(t)?e:t>=60?t%60==0?`${t/60}h`:`${Math.floor(t/60)}h ${t%60}m`:`${t}m`},Z=e=>{let[t,n]=(e||`12:00`).split(`:`),r=parseInt(t,10)||0,i=parseInt(n,10)||0,a=r>=12?`PM`:`AM`;return r=r%12||12,{h:r,m:i,ampm:a}},he=(e,t,n)=>{let r=e%12;return n===`PM`&&(r+=12),`${r.toString().padStart(2,`0`)}:${t.toString().padStart(2,`0`)}`},ge=e=>{let t=e.getTimezoneOffset()*6e4;return new Date(e.getTime()-t).toISOString().split(`T`)[0]},_e=()=>ge(new Date),ve=new Date(B.getFullYear(),B.getMonth(),1),Q=new Date(B.getFullYear(),B.getMonth()+1,0),ye=ve.getDay(),be=Q.getDate(),xe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],Se=Array.from({length:42},(e,t)=>{let n=t-ye+1,r=new Date(B.getFullYear(),B.getMonth(),n);return{day:r.getDate(),dateStr:ge(r),isCurrentMonth:n>0&&n<=be}}),Ce=()=>V(S===`month`?new Date(B.getFullYear(),B.getMonth()-1,1):new Date(B.getFullYear(),B.getMonth(),B.getDate()-1)),we=()=>V(S===`month`?new Date(B.getFullYear(),B.getMonth()+1,1):new Date(B.getFullYear(),B.getMonth(),B.getDate()+1)),Te=e=>{if(x!==`public`&&!U)return;let t=new Date;t.setDate(t.getDate()+1);let n=new Date().getHours().toString().padStart(2,`0`);z({...Bt,dateStr:e||ge(t),time:`${n}:00`,guestEmail:x===`public`?ue():``,customFields:{}}),k(!0)},Ee=e=>{let t=e.time;if(t){let[e,n]=t.split(`:`);e&&n&&(t=`${e.padStart(2,`0`)}:${n}`)}z({id:e.id,uid:e.uid,dateStr:e.dateStr,title:e.title,description:e.description||``,time:t||`12:00`,duration:e.duration||`60`,color:e.color||``,guestEmail:e.creatorEmail||``,customFields:e.customFields||{}}),k(!0)},De=async e=>{if(e.preventDefault(),R.title.trim()){N(!0);try{let e={dateStr:R.dateStr,title:R.title.trim(),description:R.description.trim(),time:R.time,duration:R.duration||`60`};if(R.color&&(e.color=R.color),b.length>0&&(e.customFields=R.customFields),!R.id)if(x===`public`){let t=R.guestEmail.trim();e.creatorEmail=t,de(t)}else x===`private`||x===`shared`?(e.uid=U?.uid,e.creatorEmail=U?.email||``,e.creatorName=U?.displayName||``,e.creatorAvatar=U?.photoURL||``):x===`admin_only`&&(e.uid=U?.uid,e.creatorEmail=G?.email||U?.email||``,e.creatorName=G?.displayName||G?.name||``,e.creatorAvatar=G?.avatar||G?.avatarUrl||U?.photoURL||``);R.id?(await(0,o.setDoc)((0,o.doc)(n.Tt,i,R.id),e,{merge:!0}),A?.id===R.id&&j({...A,...e})):await(0,o.setDoc)((0,o.doc)(n.Tt,i,`ev_${Date.now()}`),e,{merge:!0}),k(!1)}catch(e){console.error(e)}N(!1)}},Oe=async()=>{if(I){F(!0);try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,i,I.id)),A?.id===I.id&&j(null),L(null),k(!1)}catch{}F(!1)}},ke=e=>{if(x===`private`||!e.creatorEmail&&!e.creatorName)return null;let t=(e.creatorName||e.creatorEmail||`?`).charAt(0).toUpperCase(),n=zt.find(t=>t.text===e.color);return(0,l.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 p-3 rounded-xl bg-foreground/[0.03] border border-[var(--panel-border)]/50`,children:[e.creatorAvatar?(0,l.jsx)(`img`,{src:e.creatorAvatar,alt:``,className:`w-8 h-8 rounded-full object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`w-8 h-8 rounded-full ${n?.bgCircle||`bg-accent`} flex items-center justify-center text-[13px] font-extrabold text-white shrink-0`,children:t}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[e.creatorName&&(0,l.jsx)(`span`,{className:`text-[13px] font-bold text-foreground/90 truncate`,children:e.creatorName}),e.creatorEmail&&(0,l.jsx)(`span`,{className:`text-[12px] text-foreground/50 truncate`,children:e.creatorEmail})]})]})},Ae=e=>{if(x===`private`||x===`public`||!e.creatorName&&!e.creatorEmail)return null;let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||``,n=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[e.creatorAvatar?(0,l.jsx)(`img`,{src:e.creatorAvatar,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/15 text-accent flex items-center justify-center text-[8px] font-extrabold shrink-0`,children:n}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),e.creatorEmail&&(0,l.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,e.creatorEmail]})]})]})},je=x===`admin_only`?re(d,e,i,w):x===`private`?K(d,e,i,w):ie(d,e,i,w),Me=()=>{navigator.clipboard.writeText(je),H(!0),setTimeout(()=>H(!1),2e3)};if(J&&x!==`public`&&!U)return(0,l.jsx)(`main`,{className:`flex-1 w-full flex items-center justify-center min-h-screen p-8`,children:(0,l.jsxs)(`div`,{className:`text-center glass-panel border border-[var(--panel-border)] rounded-3xl p-12 max-w-sm w-full`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-accent/10 border border-accent/20 flex items-center justify-center mx-auto mb-4`,children:(0,l.jsx)(n.k,{className:`w-7 h-7 text-accent`})}),(0,l.jsx)(`h2`,{className:`text-2xl font-extrabold mb-2`,children:`Sign in required`}),(0,l.jsx)(`p`,{className:`text-foreground/50 text-[14px] mb-6`,children:`You need to be signed in to access this calendar.`}),(0,l.jsx)(u.Link,{to:`/login`,className:`inline-flex items-center justify-center gap-2 px-6 py-2.5 rounded-xl btn-primary font-bold text-[14px] w-full`,children:`Sign In`})]})});if(!J&&x!==`public`)return(0,l.jsx)(`main`,{className:`flex-1 w-full flex items-center justify-center min-h-screen`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 animate-spin text-accent`})});let Ne=(x===`public`||!!U)&&p,Pe=()=>(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:d?.tabTitle||d?.tabName||e}),(0,l.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[E.length,` `,E.length===1?`event`:`events`,` · `,S===`month`?`Month`:`Board`,` View`]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[v&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:Me,title:ne?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${ne?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:ne?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:ce,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer btn-secondary text-[12px] font-extrabold`,children:oe?`24h`:`12h`}),g&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:le,title:S===`month`?`Switch to Board`:`Switch to Calendar`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${_===`primary`?`btn-primary`:`btn-secondary`}`,children:S===`month`?(0,l.jsx)(n.F,{className:`w-4 h-4`}):(0,l.jsx)(n.dt,{className:`w-4 h-4`})}),Ne&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>Te(),className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${m===`+`?`w-10`:`px-5`} ${h===`primary`?`btn-primary`:`btn-secondary`}`,children:m===`+`?(0,l.jsx)(n.C,{className:`w-4 h-4`}):(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:m})})]})]}),Fe=()=>(0,l.jsxs)(`div`,{className:`p-4 md:p-6 border-b border-[var(--panel-border)]/50 flex items-center justify-between bg-foreground/[0.01]`,children:[(0,l.jsx)(`h3`,{className:`text-xl font-extrabold tracking-tight ml-2`,children:S===`month`?B.toLocaleString(`default`,{month:`long`,year:`numeric`}):B.toLocaleString(`default`,{month:`long`,day:`numeric`,year:`numeric`})}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,l.jsx)(`button`,{onClick:()=>V(new Date),className:`px-4 py-2 text-[13px] font-bold border border-[var(--panel-border)] rounded-xl mr-2 hover:bg-foreground/5 transition-colors`,children:`Today`}),(0,l.jsx)(`button`,{onClick:Ce,className:`p-2 rounded-xl text-foreground/50 hover:text-foreground hover:bg-foreground/5 transition-colors border border-transparent hover:border-[var(--panel-border)]`,children:(0,l.jsx)(n.ot,{className:`w-5 h-5`})}),(0,l.jsx)(`button`,{onClick:we,className:`p-2 rounded-xl text-foreground/50 hover:text-foreground hover:bg-foreground/5 transition-colors border border-transparent hover:border-[var(--panel-border)]`,children:(0,l.jsx)(n.at,{className:`w-5 h-5`})})]})]}),$=()=>(0,l.jsxs)(l.Fragment,{children:[Fe(),S===`month`?(0,l.jsx)(`div`,{className:`overflow-x-auto w-full flex-1`,children:(0,l.jsxs)(`div`,{className:`min-w-[800px] h-full flex flex-col`,children:[(0,l.jsx)(`div`,{className:`grid grid-cols-7 border-b border-[var(--panel-border)]/50 bg-foreground/[0.02]`,children:xe.map(e=>(0,l.jsx)(`div`,{className:`py-3 text-center text-[12px] font-bold uppercase tracking-wider text-foreground/40`,children:e},e))}),(0,l.jsx)(`div`,{className:`grid grid-cols-7 auto-rows-auto bg-[var(--panel-border)] gap-[1px] relative flex-1`,children:Se.map((e,t)=>{let r=e.dateStr===_e(),i=E.filter(t=>t.dateStr===e.dateStr);return(0,l.jsxs)(`div`,{onClick:()=>e.isCurrentMonth&&Ne&&Te(e.dateStr),className:`min-h-[140px] p-2 bg-[var(--panel-bg)] flex flex-col relative group
|
|
312
|
-
${e.isCurrentMonth
|
|
214
|
+
[WHAT TO BUILD?]`},ce=[{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 le({title:e=`Board View`,subtitle:t=`/templates/board`,backUrl:r=`/templates`,tasksCollection:i=`pub_tasks`,categoriesCollection:s=`pub_categories`,config:c}){let{user:d}=m(),f=!!c;c?.isPrivate&&!c?.isAdmin&&c?.isShared;let p=c?.isAdmin||c?.isShared,h=f?p:!0,g=c?.showButton!==!1,_=c?.buttonText||`+`,v=c?.buttonStyle||`primary`,y=c?.keyName||`key`,b=c?.valueName||`value`,[x,S]=(0,a.useState)([]),[C,w]=(0,a.useState)([]),[T,E]=(0,a.useState)([]),[D,O]=(0,a.useState)(null),[k,A]=(0,a.useState)(null),[j,ne]=(0,a.useState)({name:``}),[M,N]=(0,a.useState)([]),[P,F]=(0,a.useState)(null),[I,L]=(0,a.useState)(null),[R,z]=(0,a.useState)(null),[re,B]=(0,a.useState)(null),[ie,V]=(0,a.useState)(!1),[ae,H]=(0,a.useState)(null),[G,K]=(0,a.useState)(``),[se,q]=(0,a.useState)(null),[J,Y]=(0,a.useState)(!1),le=c?.isAdmin?W(c,e,i,s):c?.isPrivate?U(c,e,i,s,T):oe(c,e,i,s,T),ue=()=>{navigator.clipboard.writeText(le),Y(!0),setTimeout(()=>Y(!1),2e3)};(0,a.useEffect)(()=>{let e=c?.isShared,t=c?.isAdmin,r=c?.isPrivate&&!t&&!e,a=!t&&!e&&!r;r||a?(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{let t=a?`public`:`private`;E(e.docs.filter(e=>e.data().formType===t).map(e=>e.id))}):E([]);let l=i.startsWith(`user_`),u=s.startsWith(`user_`);if(l&&!d)return;try{let e=localStorage.getItem(`fbos_board_tasks_${i}`);e&&S(JSON.parse(e));let t=localStorage.getItem(`fbos_board_cats_${s}`);t&&w(JSON.parse(t))}catch{}let f=(0,o.onSnapshot)(l&&d?(0,o.query)((0,o.collection)(n.Tt,i),(0,o.where)(`uid`,`==`,d.uid)):(0,o.collection)(n.Tt,i),e=>{let t=[];e.forEach(e=>{let n=e.data();t.push({id:e.id,categoryId:n.categoryId,name:n.name||n.text||`Unnamed Item`,fields:n.fields||(n.value?[{key:`Label`,value:n.value}]:[]),order:n.order||0})});let n=t.sort((e,t)=>(e.order||0)-(t.order||0));S(n),localStorage.setItem(`fbos_board_tasks_${i}`,JSON.stringify(n))}),p=(0,o.onSnapshot)(u&&d?(0,o.query)((0,o.collection)(n.Tt,s),(0,o.where)(`uid`,`==`,d.uid)):(0,o.collection)(n.Tt,s),e=>{let t=[];if(e.forEach(e=>{t.push({id:e.id,...e.data()})}),t.length===0){let e=[{id:`todo`,title:`To Do`,createdAt:Date.now()-2e3},{id:`in_progress`,title:`In Progress`,createdAt:Date.now()-1e3},{id:`review`,title:`Review`,createdAt:Date.now()}],t=d?{uid:d.uid}:{};e.forEach(e=>(0,o.setDoc)((0,o.doc)(n.Tt,s,e.id),{...t,title:e.title,createdAt:e.createdAt}))}else w(t),localStorage.setItem(`fbos_board_cats_${s}`,JSON.stringify(t))});return()=>{f(),p()}},[i,s,d]);let de=(e,t)=>{t?(A(t.id),ne({id:t.id,name:t.name}),N(t.fields?.length?[...t.fields,{key:``,value:``}]:[{key:``,value:``}])):(O(e),ne({name:``}),N([{key:``,value:``}]))},X=(e,t,n)=>{let r=[...M];r[e]={key:t,value:n},e===M.length-1&&(t.trim()!==``||n.trim()!==``)&&r.push({key:``,value:``}),N(r)},Z=(e,t)=>{e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`taskId`,t),F(t)},fe=(e,t)=>{e.preventDefault(),e.stopPropagation(),t!==P&&L(t)},pe=(e,t)=>{e.preventDefault(),e.stopPropagation(),z(t)},me=e=>{e.preventDefault(),L(null),z(null)},he=async(e,t,r)=>{e.preventDefault(),e.stopPropagation(),L(null),z(null);let a=e.dataTransfer.getData(`taskId`);if(!a||a===r){F(null);return}let s=x.find(e=>e.id===a);if(!s)return;let c=x.filter(e=>e.categoryId===t).sort((e,t)=>(e.order||0)-(t.order||0));if(s.categoryId===t?(c=c.filter(e=>e.id!==a),c.push(s)):c.push({...s,categoryId:t}),r){let e=c.findIndex(e=>e.id===r),t=c.findIndex(e=>e.id===a),[n]=c.splice(t,1);c.splice(e,0,n)}c.forEach((e,r)=>{let a={categoryId:t,order:r};d&&(a.uid=d.uid),(0,o.setDoc)((0,o.doc)(n.Tt,i,e.id),a,{merge:!0})}),F(null)},Q=async e=>{let t=j.id||`item_${Date.now()}`,r=j.name.trim(),a=r||`Untitled Item`,s=M.filter(e=>e.key.trim()!==``||e.value.trim()!==``),c=!0,l=j.id?x.find(e=>e.id===j.id):null;if(l){let e=JSON.stringify(l.fields||[]),t=JSON.stringify(s);l.name===a&&e===t&&(c=!1)}else !r&&s.length===0&&(c=!1);if(!c){O(null),A(null);return}B(j.id||`new`);let u={categoryId:e,name:a,fields:s};d&&!j.id&&(u.uid=d.uid),await(0,o.setDoc)((0,o.doc)(n.Tt,i,t),u,{merge:!0}),setTimeout(()=>{O(null),A(null),B(null)},400)},ge=(e,t)=>{q({type:`item`,id:e,title:t})},_e=async()=>{let e=`cat_${Date.now()}`,t={title:``,createdAt:Date.now()};d&&(t.uid=d.uid),await(0,o.setDoc)((0,o.doc)(n.Tt,s,e),t),H(e),K(``),setTimeout(()=>{let e=document.getElementById(`board-container`);e&&e.scrollTo({left:e.scrollWidth,behavior:`smooth`})},150)},ve=async e=>{G.trim()?await(0,o.setDoc)((0,o.doc)(n.Tt,s,e),{title:G},{merge:!0}):await(0,o.deleteDoc)((0,o.doc)(n.Tt,s,e)),H(null)},ye=(e,t)=>{q({type:`category`,id:e,title:t})},be=async()=>{if(se){V(!0);try{if(se.type===`item`)await(0,o.deleteDoc)((0,o.doc)(n.Tt,i,se.id)),A(null);else{let e=x.filter(e=>e.categoryId===se.id);for(let t of e)await(0,o.deleteDoc)((0,o.doc)(n.Tt,i,t.id));await(0,o.deleteDoc)((0,o.doc)(n.Tt,s,se.id))}}catch{}V(!1),q(null)}},xe=[...C].sort((e,t)=>(e.createdAt||0)-(t.createdAt||0));return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen overflow-x-hidden`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e}),t&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),t]})]}),f&&(0,l.jsx)(`div`,{className:`mb-6`,children:(0,l.jsx)(ee,{})}),(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between items-start sm:items-center mb-6 border-b border-[var(--panel-border)] pb-6 gap-4 relative z-20 shrink-0`,children:[!f&&r&&(0,l.jsxs)(u.Link,{to:r,className:`px-5 py-2 hover:bg-foreground/5 transition-all flex items-center gap-2`,style:{borderRadius:`var(--btn-radius, 0.75rem)`},children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` Go Back`]}),f&&(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:c?.tabTitle||c?.tabName||e}),(0,l.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[x.length,` `,x.length===1?`item`:`items`,` · `,xe.length,` `,xe.length===1?`category`:`categories`]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 w-full sm:w-auto`,children:[c?.showPrompt&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:ue,title:J?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${J?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary shadow-lg`}`,children:J?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),g&&(0,l.jsx)(n.n,{variant:v===`secondary`?`secondary`:void 0,onClick:_e,className:`flex-1 sm:flex-none px-3 py-2.5 text-[14px] font-bold rounded-xl shadow-lg hover:-translate-y-0.5 transition-all shrink-0`,children:_===`+`?(0,l.jsx)(n.C,{className:`w-4 h-4`}):_})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative z-40 min-h-0`,children:(0,l.jsxs)(`div`,{id:`board-container`,className:`w-full h-full flex flex-row gap-4 md:gap-6 overflow-x-auto pb-4 snap-x snap-mandatory styled-scrollbars items-start`,children:[xe.map((e,t)=>{let r=x.filter(t=>t.categoryId===e.id);r.sort((e,t)=>(e.order||0)-(t.order||0));let i=ce.find(t=>t.text===e.color)||ce.find(e=>e.text===`text-accent`);return i.text,i.bgLight,i.bgHover,(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:t*.1},className:`w-[300px] md:w-[320px] shrink-0 flex flex-col max-h-full rounded-3xl p-4 snap-center relative border transition-colors ${ce.find(t=>t.text===e.color)?.bgCard||`bg-foreground/[0.02]`} ${ce.find(t=>t.text===e.color)?.borderCard||`border-[var(--panel-border)]/50`}`,children:[(0,l.jsx)(`div`,{className:`flex items-center justify-between mb-4 px-2 relative z-[200]`,children:(0,l.jsxs)(`h3`,{className:`font-bold text-[14px] flex items-center w-full text-foreground/80 group relative z-[200]`,children:[ae===e.id?(0,l.jsxs)(`div`,{className:`relative flex-1 w-full flex items-center pr-8 z-[200]`,children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),ve(e.id)}}),(0,l.jsx)(`input`,{value:G,onChange:e=>K(e.target.value),onBlur:t=>{t.relatedTarget?.closest(`.category-color-picker`)||ve(e.id)},onKeyDown:t=>t.key===`Enter`&&ve(e.id),className:`bg-transparent border-none outline-none font-bold text-[14px] w-full p-0 ${e.color||`text-foreground/80`}`,placeholder:`Category name`}),(0,l.jsxs)(`div`,{className:`absolute top-8 left-0 flex gap-1.5 bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-[100] category-color-picker items-center`,tabIndex:-1,children:[(0,l.jsx)(`button`,{onClick:async t=>{t.preventDefault(),t.stopPropagation(),await(0,o.setDoc)((0,o.doc)(n.Tt,`pub_categories`,e.id),{color:``},{merge:!0}),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:`Reset Category Color`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})}),(0,l.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),ce.map(t=>(0,l.jsx)(`button`,{onMouseDown:async r=>{r.preventDefault(),await(0,o.setDoc)((0,o.doc)(n.Tt,`pub_categories`,e.id),{color:t.text},{merge:!0})},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50 shrink-0`},t.name))]})]}):(0,l.jsxs)(`div`,{className:`flex items-center gap-2 w-full cursor-pointer hover:text-foreground transition-colors pr-8`,onClick:()=>{H(e.id),K(e.title)},children:[(0,l.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${ce.find(t=>t.text===e.color)?.bgCircle||`bg-foreground/20`} transition-colors shrink-0`}),(0,l.jsx)(`span`,{className:`truncate flex-1 max-w-[200px] ${e.color||``}`,children:e.title||`Untitled Category`}),(0,l.jsx)(`span`,{className:`text-[11px] bg-foreground/10 text-foreground/60 px-1.5 py-0.5 rounded-md font-medium shrink-0`,children:r.length})]}),C.length>1&&(0,l.jsx)(`button`,{onClick:()=>ye(e.id,e.title),className:`absolute right-0 opacity-0 group-hover:opacity-100 text-foreground/30 hover:text-red-500 transition-all shrink-0`,children:(0,l.jsx)(n.m,{className:`w-3.5 h-3.5`})})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-2.5 flex-1 overflow-y-auto styled-scrollbars pr-1 relative min-h-[150px] rounded-xl transition-all ${R===e.id&&!I?`bg-foreground/5 scale-[1.01] border-dashed border border-accent/20`:``}`,onDragOver:t=>pe(t,e.id),onDragLeave:me,onDrop:t=>he(t,e.id),children:[(0,l.jsx)(n.a,{children:r.map(t=>k===t.id?(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-md border border-accent/40 transition-all flex flex-col gap-2 relative z-[100]`,children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),Q(e.id)}}),(0,l.jsx)(`textarea`,{placeholder:`Write an item name...`,className:`no-glow bg-transparent border-none outline-none text-[13px] text-foreground/90 font-medium leading-snug resize-none w-full min-h-[40px] relative z-10`,value:j.name,onChange:e=>ne({...j,name:e.target.value}),onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),Q(e.id))}}),(0,l.jsx)(`div`,{className:`flex flex-col gap-2 mt-1 relative z-10 w-full`,children:M.map((t,n)=>(0,l.jsxs)(`div`,{className:`flex items-start bg-foreground/[0.04] border border-[var(--panel-border)]/50 rounded-[8px] px-2.5 py-1.5 w-full`,children:[(0,l.jsx)(`input`,{placeholder:y,value:t.key,onChange:e=>X(n,e.target.value,t.value),onKeyDown:t=>t.key===`Enter`&&Q(e.id),className:`no-glow bg-transparent outline-none text-[11px] text-foreground/50 font-bold placeholder:text-foreground/30 relative top-[1px] shrink-0`,style:{width:`${Math.max(3,t.key.length||y.length)}ch`}}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative top-[1px]`,children:`:`}),(0,l.jsx)(`textarea`,{rows:1,placeholder:b,value:t.value,onChange:e=>X(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(),Q(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))}),re===t.id&&(0,l.jsx)(`div`,{className:`flex items-center justify-end pt-1`,children:(0,l.jsx)(`div`,{className:`w-3 h-3 border-2 border-accent border-t-transparent rounded-full animate-spin`})})]},t.id):(0,l.jsxs)(n.i.div,{draggable:!0,onDragStart:e=>Z(e,t.id),onDragOver:e=>fe(e,t.id),onDragLeave:me,onDrop:n=>he(n,e.id,t.id),initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-sm hover:shadow-md cursor-grab active:cursor-grabbing hover:border-accent/40 transition-all group flex flex-col gap-2 relative z-10 border ${I===t.id?`border-accent border-t-2 translate-y-1`:`border-[var(--panel-border)]`} ${P===t.id?`opacity-30 scale-95 border-dashed border-2`:``}`,children:[(0,l.jsxs)(`div`,{className:`absolute top-2 right-2 flex items-center gap-1.5 opacity-0 group-hover:opacity-100 transition-opacity bg-background/90 backdrop-blur-md border border-[var(--panel-border)] rounded-lg p-1 z-20 shadow-md`,children:[(0,l.jsx)(`button`,{onClick:n=>{n.stopPropagation(),de(e.id,t)},className:`p-1 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-accent transition-colors`,children:(0,l.jsx)(n.w,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ge(t.id,t.name)},className:`p-1 hover:bg-red-500/10 rounded-md text-foreground/60 hover:text-red-500 transition-colors`,children:(0,l.jsx)(n.m,{className:`w-3.5 h-3.5`})})]}),(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/90 font-medium leading-snug break-words pr-12`,children:t.name}),t.fields&&t.fields.length>0&&(0,l.jsx)(`div`,{className:`flex flex-row flex-wrap gap-2 mt-2`,children:t.fields.map((e,t)=>(0,l.jsxs)(`div`,{className:`inline-flex bg-foreground/[0.04] border border-[var(--panel-border)]/50 rounded-[8px] px-2.5 py-1.5 max-w-full`,children:[(0,l.jsxs)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative -top-[1px] shrink-0 break-all`,children:[e.key,`:`]}),(0,l.jsx)(`span`,{className:`text-[12px] text-foreground/90 font-medium break-words leading-tight min-w-0`,children:e.value})]},t))}),(0,l.jsxs)(`div`,{className:`flex items-end justify-between mt-3 pt-3 border-t border-[var(--panel-border)]/50 w-full gap-2`,children:[h&&f&&d?(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 pr-2 border-r border-[var(--panel-border)] border-dashed mr-auto`,children:[d.photoURL?(0,l.jsx)(`img`,{src:d.photoURL,className:`w-4 h-4 rounded-full shrink-0 object-cover`}):(0,l.jsx)(`div`,{className:`w-4 h-4 rounded-full bg-accent/20 text-accent flex items-center justify-center text-[9px] font-bold shrink-0`,children:(d.displayName||d.email||`U`)[0].toUpperCase()}),(0,l.jsx)(`span`,{className:`text-[10px] font-bold text-foreground/60 truncate max-w-[80px]`,children:d.displayName||d.email?.split(`@`)[0]||`User`})]}):(0,l.jsx)(`div`,{className:`flex items-center gap-2 pr-2 border-r border-[var(--panel-border)] border-dashed mr-auto`}),(0,l.jsx)(`span`,{className:`text-[10px] text-foreground/40 font-bold text-right pt-0.5 shrink-0 max-w-[50%] truncate flex-1`,children:t.id.startsWith(`item_`)?new Date(parseInt(t.id.split(`_`)[1])).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}):`Recently Added`})]})]},t.id))}),D===e.id?(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-md border border-accent/40 transition-all flex flex-col gap-2 relative z-[100] mt-1`,children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),Q(e.id)}}),(0,l.jsx)(`textarea`,{placeholder:`Write an item name...`,className:`no-glow bg-transparent border-none outline-none text-[13px] text-foreground/90 font-medium leading-snug resize-none w-full min-h-[40px] relative z-10`,value:j.name,onChange:e=>ne({...j,name:e.target.value}),onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),Q(e.id))},autoFocus:!0}),(0,l.jsx)(`div`,{className:`flex flex-col gap-2 mt-1 relative z-10 w-full`,children:M.map((t,n)=>(0,l.jsxs)(`div`,{className:`flex items-start bg-foreground/[0.04] border border-[var(--panel-border)]/50 rounded-[8px] px-2.5 py-1.5 w-full`,children:[(0,l.jsx)(`input`,{placeholder:y,style:{width:`${Math.max(3,t.key.length||y.length)}ch`},value:t.key,onChange:e=>X(n,e.target.value,t.value),onKeyDown:t=>t.key===`Enter`&&Q(e.id),className:`no-glow bg-transparent outline-none text-[11px] text-foreground/50 font-bold placeholder:text-foreground/30 relative top-[1px]`}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative top-[1px]`,children:`:`}),(0,l.jsx)(`textarea`,{rows:1,placeholder:b,value:t.value,onChange:e=>X(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(),Q(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))}),re===`new`&&(0,l.jsx)(`div`,{className:`flex items-center justify-end pt-1`,children:(0,l.jsx)(`div`,{className:`w-3 h-3 border-2 border-accent border-t-transparent rounded-full animate-spin`})})]}):(0,l.jsxs)(`button`,{onClick:()=>de(e.id),className:`flex items-center gap-2 justify-center w-full py-2.5 mt-1 rounded-xl border border-transparent text-[12px] font-bold text-foreground/40 hover:text-foreground hover:bg-foreground/[0.03] transition-all shrink-0`,children:[(0,l.jsx)(n.C,{className:`w-4 h-4`}),` Add Item`]})]})]},e.id)}),(0,l.jsx)(`div`,{className:`w-[10px] shrink-0 pointer-events-none`})]})}),(0,l.jsx)(`style`,{children:`.styled-scrollbars::-webkit-scrollbar { width: 6px; height: 6px; } .styled-scrollbars::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--accent-color) 20%, transparent); border-radius: 4px; } .styled-scrollbars::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--accent-color) 40%, transparent); }`}),(0,l.jsx)(te,{isOpen:!!se,title:`Confirm Deletion`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:se?.title}),` This action is permanent.`]}),onConfirm:be,onCancel:()=>q(null),isProcessing:ie,confirmText:`Yes, Delete`})]})}function ue(e){return Array.isArray?Array.isArray(e):_e(e)===`[object Array]`}function de(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 X(e){return e==null?``:de(e)}function Z(e){return typeof e==`string`}function fe(e){return typeof e==`number`}function pe(e){return e===!0||e===!1||he(e)&&_e(e)==`[object Boolean]`}function me(e){return typeof e==`object`}function he(e){return me(e)&&e!==null}function Q(e){return e!=null}function ge(e){return!e.trim().length}function _e(e){return e==null?e===void 0?`[object Undefined]`:`[object Null]`:Object.prototype.toString.call(e)}var ve=`Incorrect 'index' type`,ye=e=>`Invalid value for key ${e}`,be=e=>`Pattern length exceeds max of ${e}.`,xe=e=>`Missing ${e} property in key`,Se=e=>`Property 'weight' in key '${e}' must be a positive integer`,Ce=Object.prototype.hasOwnProperty,we=class{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(e=>{let n=Te(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 Te(e){let t=null,n=null,r=null,i=1,a=null;if(Z(e)||ue(e))r=e,t=Ee(e),n=De(e);else{if(!Ce.call(e,`name`))throw Error(xe(`name`));let o=e.name;if(r=o,Ce.call(e,`weight`)&&(i=e.weight,i<=0))throw Error(Se(o));t=Ee(o),n=De(o),a=e.getFn}return{path:t,id:n,weight:i,src:r,getFn:a}}function Ee(e){return ue(e)?e:e.split(`.`)}function De(e){return ue(e)?e.join(`.`):e}function Oe(e,t){let n=[],r=!1,i=(e,t,a,o)=>{if(Q(e))if(!t[a])n.push(o===void 0?e:{v:e,i:o});else{let s=e[t[a]];if(!Q(s))return;if(a===t.length-1&&(Z(s)||fe(s)||pe(s)||typeof s==`bigint`))n.push(o===void 0?X(s):{v:X(s),i:o});else if(ue(s)){r=!0;for(let e=0,n=s.length;e<n;e+=1)i(s[e],t,a+1,e)}else t.length&&i(s,t,a+1,o)}};return i(e,Z(t)?t.split(`.`):t,0),r?n:n[0]}var ke={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Ae={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},je={location:0,threshold:.6,distance:100},Me={useExtendedSearch:!1,useTokenSearch:!1,getFn:Oe,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1},$=Object.freeze({...Ae,...ke,...je,...Me}),Ne=/[^ ]+/g;function Pe(e=1,t=3){let n=new Map,r=10**t;return{get(t){let i=t.match(Ne).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 Fe=class{constructor({getFn:e=$.getFn,fieldNormWeight:t=$.fieldNormWeight}={}){this.norm=Pe(t,3),this.getFn=e,this.isCreated=!1,this.docs=[],this.keys=[],this._keysMap={},this.setIndexRecords()}setSources(e=[]){this.docs=e}setIndexRecords(e=[]){this.records=e}setKeys(e=[]){this.keys=e,this._keysMap={},e.forEach((e,t)=>{this._keysMap[e.id]=t})}create(){this.isCreated||!this.docs.length||(this.isCreated=!0,Z(this.docs[0])?this.docs.forEach((e,t)=>{this._addString(e,t)}):this.docs.forEach((e,t)=>{this._addObject(e,t)}),this.norm.clear())}add(e){let t=this.size();Z(e)?this._addString(e,t):this._addObject(e,t)}removeAt(e){this.records.splice(e,1);for(let t=e,n=this.size();t<n;t+=1)--this.records[t].i}removeAll(e){for(let t=e.length-1;t>=0;--t)this.records.splice(e[t],1);for(let e=0,t=this.records.length;e<t;e+=1)this.records[e].i=e}getValueForItemAtKeyId(e,t){return e[this._keysMap[t]]}size(){return this.records.length}_addString(e,t){if(!Q(e)||ge(e))return;let n={v:e,i:t,n:this.norm.get(e)};this.records.push(n)}_addObject(e,t){let n={i:t,$:{}};this.keys.forEach((t,r)=>{let i=t.getFn?t.getFn(e):this.getFn(e,t.path);if(Q(i)){if(ue(i)){let e=[];for(let t=0,n=i.length;t<n;t+=1){let n=i[t];if(Q(n)){if(Z(n)){if(!ge(n)){let r={v:n,i:t,n:this.norm.get(n)};e.push(r)}}else if(Q(n.v)){let t=Z(n.v)?n.v:X(n.v);if(!ge(t)){let r={v:t,i:n.i,n:this.norm.get(t)};e.push(r)}}}}n.$[r]=e}else if(Z(i)&&!ge(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 Ie(e,t,{getFn:n=$.getFn,fieldNormWeight:r=$.fieldNormWeight}={}){let i=new Fe({getFn:n,fieldNormWeight:r});return i.setKeys(e.map(Te)),i.setSources(t),i.create(),i}function Le(e,{getFn:t=$.getFn,fieldNormWeight:n=$.fieldNormWeight}={}){let{keys:r,records:i}=e,a=new Fe({getFn:t,fieldNormWeight:n});return a.setKeys(r),a.setIndexRecords(i),a}function Re(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 ze=32;function Be(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>ze)throw Error(be(ze));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=Re(_,s);e.length?c&&(C.indices=e):C.isMatch=!1}return C}function Ve(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 He(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 Ue={ł:`l`,Ł:`L`,đ:`d`,Đ:`D`,ø:`o`,Ø:`O`,ħ:`h`,Ħ:`H`,ŧ:`t`,Ŧ:`T`,ı:`i`,ß:`ss`},We=RegExp(`[`+Object.keys(Ue).join(``)+`]`,`g`),Ge=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(We,e=>Ue[e]):e=>e,Ke=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?Ge(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;let u=(e,t)=>{this.chunks.push({pattern:e,alphabet:Ve(e),startIndex:t})},d=this.pattern.length;if(d>ze){let e=0,t=d%ze,n=d-t;for(;e<n;)u(this.pattern.substr(e,ze),e),e+=ze;if(t){let e=d-ze;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?Ge(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}=Be(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=He(u)),p}},qe=class{constructor(e){this.pattern=e}static isMultiMatch(e){return Je(e,this.multiRegex)}static isSingleMatch(e){return Je(e,this.singleRegex)}search(e){return{isMatch:!1,score:1}}};function Je(e,t){let n=e.match(t);return n?n[1]:null}var Ye=class extends qe{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]}}},Xe=class extends qe{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]}}},Ze=class extends qe{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]}}},Qe=class extends qe{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]}}},$e=class extends qe{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]}}},et=class extends qe{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]}}},tt=class extends qe{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 Ke(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)}},nt=class extends qe{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}}},rt=[Ye,nt,Ze,Qe,et,$e,Xe,tt],it=rt.length,at=`\0`,ot=`|`;function st(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 ct(e,t={}){return e.replace(/\\\|/g,at).split(ot).map(e=>{let n=st(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<it;){let e=rt[o],n=e.isMultiMatch(i);n&&(r.push(new e(n,t)),a=!0)}if(!a)for(o=-1;++o<it;){let e=rt[o],n=e.isSingleMatch(i);if(n){r.push(new e(n,t));break}}}return r})}var lt=new Set([tt.type,nt.type]),ut=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?Ge(e):e,this.pattern=e,this.query=ct(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?Ge(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&&(lt.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=He(o)),e}}return{isMatch:!1,score:1}}},dt=[];function ft(...e){dt.push(...e)}function pt(e,t){for(let n=0,r=dt.length;n<r;n+=1){let r=dt[n];if(r.condition(e,t))return new r(e,t)}return new Ke(e,t)}var mt={AND:`$and`,OR:`$or`},ht={PATH:`$path`,PATTERN:`$val`},gt=e=>!!(e[mt.AND]||e[mt.OR]),_t=e=>!!e[ht.PATH],vt=e=>!ue(e)&&me(e)&&!gt(e),yt=e=>({[mt.AND]:Object.keys(e).map(t=>({[t]:e[t]}))});function bt(e,t,{auto:n=!0}={}){let r=e=>{if(Z(e)){let r={keyId:null,pattern:e};return n&&(r.searcher=pt(e,t)),r}let i=Object.keys(e),a=_t(e);if(!a&&i.length>1&&!gt(e))return r(yt(e));if(vt(e)){let r=a?e[ht.PATH]:i[0],o=a?e[ht.PATTERN]:e[r];if(!Z(o))throw Error(ye(r));let s={keyId:De(r),pattern:o};return n&&(s.searcher=pt(o,t)),s}let o={children:[],operator:i[0]};return i.forEach(t=>{let n=e[t];ue(n)&&n.forEach(e=>{o.children.push(r(e))})}),o};return gt(e)||(e=yt(e)),r(e)}function xt(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 St(e,{ignoreFieldNorm:t=$.ignoreFieldNorm}){e.forEach(e=>{e.score=xt(e.matches,{ignoreFieldNorm:t})})}var Ct=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 wt(e,t){let n=e.matches;t.matches=[],Q(n)&&n.forEach(e=>{if(!Q(e.indices)||!e.indices.length)return;let{indices:n,value:r}=e,i={indices:n,value:r};e.key&&(i.key=e.key.src),e.idx>-1&&(i.refIndex=e.idx),t.matches.push(i)})}function Tt(e,t){t.score=e.score}function Et(e,t,{includeMatches:n=$.includeMatches,includeScore:r=$.includeScore}={}){let i=[];return n&&i.push(wt),r&&i.push(Tt),e.map(e=>{let{idx:n}=e,r={item:t[n],refIndex:n};return i.length&&i.forEach(t=>{t(e,r)}),r})}var Dt=/\b\w+\b/g;function Ot({isCaseSensitive:e=!1,ignoreDiacritics:t=!1}={}){return{tokenize(n){return e||(n=n.toLowerCase()),t&&(n=Ge(n)),n.match(Dt)||[]}}}function kt(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 At(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 jt(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 Mt=class{constructor(e,t,n){this.options={...$,...t},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new we(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=pt(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 Fe))throw Error(ve);if(this._myIndex=t||Ie(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){let e=Ot({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});this._invertedIndex=kt(this._myIndex.records,this._myIndex.keys.length,e)}}add(e){if(Q(e)&&(this._docs.push(e),this._myIndex.add(e),this._invertedIndex)){let e=this._myIndex.records[this._myIndex.records.length-1],t=Ot({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});At(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)jt(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&&jt(this._invertedIndex,e);let t=this._docs.splice(e,1)[0];return this._myIndex.removeAt(e),t}getIndex(){return this._myIndex}search(e,t){let{limit:n=-1}=t||{},{includeMatches:r,includeScore:i,shouldSort:a,sortFn:o,ignoreFieldNorm:s}=this.options;if(Z(e)&&!e.trim()){let e=this._docs.map((e,t)=>({item:e,refIndex:t}));return fe(n)&&n>-1&&(e=e.slice(0,n)),e}let c=fe(n)&&n>0&&Z(e),l;if(c){let t=new Ct(n);Z(this._docs[0])?this._searchStringList(e,{heap:t,ignoreFieldNorm:s}):this._searchObjectList(e,{heap:t,ignoreFieldNorm:s}),l=t.extractSorted(o)}else l=Z(e)?Z(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e),St(l,{ignoreFieldNorm:s}),a&&l.sort(o),fe(n)&&n>-1&&(l=l.slice(0,n));return Et(l,this._docs,{includeMatches:r,includeScore:i})}_searchStringList(e,{heap:t,ignoreFieldNorm:n}={}){let r=this._getSearcher(e),{records:i}=this._myIndex,a=t?null:[];return i.forEach(({v:e,i,n:o})=>{if(!Q(e))return;let{isMatch:s,score:c,indices:l}=r.searchIn(e);if(s){let r={item:e,idx:i,matches:[{score:c,value:e,norm:o,indices:l}]};t?(r.score=xt(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):a.push(r)}}),a}_searchLogical(e){let t=bt(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===mt.AND)return[]}return o},r=this._myIndex.records,i=new Map,a=[];return r.forEach(({$:e,i:r})=>{if(Q(e)){let o=n(t,e,r);o.length&&(i.has(r)||(i.set(r,{idx:r,item:e,matches:[]}),a.push(i.get(r))),o.forEach(({matches:e})=>{i.get(r).matches.push(...e)}))}}),a}_searchObjectList(e,{heap:t,ignoreFieldNorm:n}={}){let r=this._getSearcher(e),{keys:i,records:a}=this._myIndex,o=t?null:[];return a.forEach(({$:e,i:a})=>{if(!Q(e))return;let s=[],c=!1,l=!1;if(i.forEach((t,n)=>{let i=this._findMatches({key:t,value:e[n],searcher:r});i.length?(s.push(...i),i[0].hasInverse&&(l=!0)):c=!0}),!(l&&c)&&s.length){let r={idx:a,item:e,matches:s};t?(r.score=xt(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):o.push(r)}}),o}_findMatches({key:e,value:t,searcher:n}){if(!Q(t))return[];let r=[];if(ue(t))t.forEach(({v:t,i,n:a})=>{if(!Q(t))return;let{isMatch:o,score:s,indices:c,hasInverse:l}=n.searchIn(t);o&&r.push({score:s,key:e,value:t,idx:i,norm:a,indices:c,hasInverse:l})});else{let{v:i,n:a}=t,{isMatch:o,score:s,indices:c,hasInverse:l}=n.searchIn(i);o&&r.push({score:s,key:e,value:i,norm:a,indices:c,hasInverse:l})}return r}},Nt=class{static condition(e,t){return t.useTokenSearch}constructor(e,t){this.options=t,this.analyzer=Ot({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 Ke(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=He(t)),o}};Mt.version=`7.3.0`,Mt.createIndex=Ie,Mt.parseIndex=Le,Mt.config=$,Mt.match=function(e,t,n){return pt(e,{...$,...n}).searchIn(t)},Mt.parseQuery=bt,ft(ut),ft(Nt),Mt.use=function(...e){e.forEach(e=>ft(e))};var Pt=[{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 Ft({title:e=`Table View`,subtitle:t=`/templates/table`,backUrl:r=`/templates`,tableCollection:i=`pub_table_data`,config:s}){let{user:c}=m(),d=!!s;s?.isPrivate&&!s?.isAdmin&&s?.isShared;let f=s?.isAdmin||s?.isShared,p=d?f:!0,h=s?.showButton!==!1,g=s?.buttonText||`+`,_=s?.buttonStyle||`secondary`,v=s?.showExportButton!==!1,y=s?.showPrompt,[b,x]=(0,a.useState)([]),[S,C]=(0,a.useState)(`demo`),[w,T]=(0,a.useState)(!1),[E,D]=(0,a.useState)(!1),[O,k]=(0,a.useState)(``),[A,te]=(0,a.useState)(!1),[j,ne]=(0,a.useState)(!1),[M,N]=(0,a.useState)([]),P=s?.isAdmin?K(s,e,i):s?.isPrivate?G(s,e,i,M):se(s,e,i,M),F=()=>{navigator.clipboard.writeText(P),ne(!0),setTimeout(()=>ne(!1),2e3)},[I,L]=(0,a.useState)(null),[R,z]=(0,a.useState)(null),[re,B]=(0,a.useState)(``),[ie,V]=(0,a.useState)(``),[ae,H]=(0,a.useState)(null),[U,W]=(0,a.useState)(null),[oe,q]=(0,a.useState)(!1);(0,a.useEffect)(()=>{let e=s?.isShared,t=s?.isAdmin,r=s?.isPrivate&&!t&&!e,a=!t&&!e&&!r;r||a?(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{let t=a?`public`:`private`;N(e.docs.filter(e=>e.data().formType===t).map(e=>e.id))}):N([]);let l=i.startsWith(`user_`);if(l&&!c)return;try{let e=localStorage.getItem(`fbos_tables_${i}`);e&&x(JSON.parse(e))}catch{}let u=(0,o.onSnapshot)(l&&c?(0,o.query)((0,o.collection)(n.Tt,i),(0,o.where)(`uid`,`==`,c.uid)):(0,o.collection)(n.Tt,i),e=>{let t=[];if(e.forEach(e=>{t.push({id:e.id,...e.data()})}),t.length===0){let e={name:`Unnamed Table`,columns:[`Column 1`,`Column 2`,`Column 3`,`Column 4`],...c?{uid:c.uid}:{},rows:[{id:`1`,"Column 1":``,"Column 2":``,"Column 3":``,"Column 4":``},{id:`2`,"Column 1":``,"Column 2":``,"Column 3":``,"Column 4":``}]};(0,o.setDoc)((0,o.doc)(n.Tt,i,`demo`),e)}else{let e=t.sort((e,t)=>(e.name||``).localeCompare(t.name||``));x(e),localStorage.setItem(`fbos_tables_${i}`,JSON.stringify(e))}});return()=>u()},[i,c]);let J=b.find(e=>e.id===S)||b[0]||{columns:[],rows:[]},Y=async e=>{J.id&&(c&&i.startsWith(`user_`)&&(e.uid=c.uid),await(0,o.setDoc)((0,o.doc)(n.Tt,i,J.id),e,{merge:!0}))},ce=()=>{if(!J.rows||J.rows.length===0)return;let e=J.columns.join(`,`),t=J.rows.map(e=>J.columns.map(t=>`"${e[t]||``}"`).join(`,`)).join(`
|
|
215
|
+
`),n=new Blob([`${e}\n${t}`],{type:`text/csv`}),r=window.URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`export_${J.name||`table`}.csv`,i.click(),window.URL.revokeObjectURL(r)},le=(e,t,n)=>{Y({...J,rows:J.rows.map(r=>r.id===e?{...r,[t]:n}:r)})},ue=()=>{let e={id:Date.now().toString()};J.columns.forEach(t=>e[t]=``),Y({...J,rows:[...J.rows||[],e]})},de=e=>{Y({...J,rows:J.rows.filter(t=>t.id!==e)})},X=()=>{let e=`Column ${(J.columns?.length||0)+1}`;J.columns?.includes(e)||(Y({...J,columns:[...J.columns||[],e]}),setTimeout(()=>{let e=document.getElementById(`table-scroll-container`);e&&e.scrollTo({left:e.scrollWidth,behavior:`smooth`})},100))},Z=e=>{let t=(J.columns||[]).filter(t=>t!==e),n=(J.rows||[]).map(t=>{let n={...t};return delete n[e],n}),r={...J.colColors||{}};delete r[e],Y({...J,columns:t,rows:n,colColors:r})},fe=async e=>{e.trim()&&J.id&&e!==J.name&&await(0,o.setDoc)((0,o.doc)(n.Tt,i,J.id),{name:e},{merge:!0})},pe=async()=>{te(!0),T(!1);let e=`tbl_${Date.now()}`;await(0,o.setDoc)((0,o.doc)(n.Tt,i,e),{name:`Unnamed Table`,columns:[`Column 1`,`Column 2`,`Column 3`],...c?{uid:c.uid}:{},rows:[]}),setTimeout(()=>{C(e),te(!1)},600)},me=e=>{let t=ie.trim();if(t&&t!==e&&!J.columns?.includes(t)){let n=J.columns.map(n=>n===e?t:n),r=(J.rows||[]).map(n=>{let r={...n};return r[t]=r[e]||``,delete r[e],r}),i={...J.colColors||{}};i[e]&&(i[t]=i[e],delete i[e]),Y({...J,columns:n,rows:r,colColors:i})}z(null)},he=J.rows||[];return re.trim()!==``&&(he=new Mt(he.map(e=>({...e,_creatorMatch:`Guest`})),{keys:(J.columns||[]).concat([`_creatorMatch`]),threshold:.4,ignoreLocation:!0}).search(re).map(e=>{let{_creatorMatch:t,...n}=e.item;return n})),(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e}),t&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),t]})]}),d&&(0,l.jsx)(`div`,{className:`mb-6`,children:(0,l.jsx)(ee,{})}),(0,l.jsxs)(`div`,{className:`flex justify-between items-center mb-6 border-b border-[var(--panel-border)] pb-6 relative z-20`,children:[!d&&r&&(0,l.jsxs)(u.Link,{to:r,className:`px-4 md:px-5 py-2.5 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold hover:bg-foreground/5 transition-all flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` `,(0,l.jsx)(`span`,{className:`hidden sm:inline`,children:`Go Back`})]}),d&&(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:s?.tabTitle||s?.tabName||e}),(0,l.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[b.length,` `,b.length===1?`table`:`tables`]})]}),(0,l.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[y&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:F,title:j?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${j?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary shadow-lg`}`,children:j?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),v&&(0,l.jsx)(n.n,{variant:`secondary`,onClick:ce,className:`px-3 py-2.5 font-bold rounded-xl shadow-sm border border-[var(--panel-border)] flex items-center gap-2`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})}),h&&(0,l.jsx)(n.n,{variant:_===`primary`?void 0:`secondary`,onClick:ue,className:`px-3 py-2.5 font-bold rounded-xl border border-[var(--panel-border)] shadow-sm flex items-center gap-2`,children:g===`+`?(0,l.jsx)(n.C,{className:`w-4 h-4`}):g})]})]}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative z-10 block`,children:[(0,l.jsx)(`div`,{className:`absolute top-0 right-0 w-[400px] h-[400px] bg-accent/5 blur-[100px] rounded-full pointer-events-none -z-10`}),(0,l.jsxs)(`div`,{className:`p-4 md:px-6 border-b border-[var(--panel-border)]/50 flex flex-col sm:flex-row items-start sm:items-center justify-between bg-foreground/[0.01] gap-4`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col w-full sm:w-auto relative`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 relative`,children:[(0,l.jsxs)(`div`,{className:`relative flex items-center`,children:[E?(0,l.jsx)(`div`,{contentEditable:!0,suppressContentEditableWarning:!0,onBlur:e=>{D(!1),fe(e.currentTarget.textContent||``)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},className:`bg-transparent border-b-2 border-accent outline-none text-[16px] font-bold text-foreground inline-block min-w-[20px] whitespace-nowrap px-1 py-0.5`,children:J.name||`Unnamed Table`}):(0,l.jsx)(`h3`,{className:`font-bold text-[16px] text-foreground/90 cursor-pointer hover:text-accent transition-colors truncate max-w-[200px]`,onClick:()=>D(!0),title:`Click to rename table`,children:J.name||`Unnamed Table`}),(0,l.jsx)(n.a,{children:w&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>T(!1)}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:`absolute top-[120%] left-0 w-[220px] bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] rounded-2xl shadow-2xl z-50 py-2 flex flex-col`,children:[(0,l.jsx)(`div`,{className:`px-4 py-2 text-[10px] font-bold uppercase tracking-wider text-foreground/40 border-b border-[var(--panel-border)] mb-1`,children:`Your Tables`}),(0,l.jsx)(`div`,{className:`max-h-[250px] overflow-y-auto styled-scrollbars z-50 relative`,children:b.map(e=>(0,l.jsx)(`button`,{onClick:()=>{C(e.id),T(!1)},className:`w-full px-4 py-2 text-[13px] font-bold text-left hover:bg-foreground/[0.03] transition-colors truncate ${S===e.id?`text-accent bg-accent/5`:`text-foreground/70`}`,children:e.name||`Unnamed Table`},e.id))}),(0,l.jsx)(`div`,{className:`w-full h-[1px] bg-[var(--panel-border)]/50 my-1`}),(0,l.jsxs)(`button`,{onClick:pe,className:`w-full px-4 py-2.5 text-[13px] font-bold text-left text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors flex items-center gap-2`,children:[(0,l.jsx)(n.C,{className:`w-4 h-4`}),` Create New Table`]})]})]})})]}),(0,l.jsx)(`button`,{onClick:()=>T(!w),className:`p-1 px-1.5 rounded-lg hover:bg-foreground/5 transition-colors text-foreground/40 hover:text-foreground shrink-0 border border-transparent hover:border-[var(--panel-border)]`,children:(0,l.jsx)(n.st,{className:`w-4 h-4 transition-transform ${w?`rotate-180 text-accent`:``}`})})]}),(0,l.jsxs)(`span`,{className:`opacity-40 text-[11px] font-bold mt-1 uppercase tracking-wider`,children:[(J.rows||[]).length,` Records`]})]}),(0,l.jsxs)(`div`,{className:`relative w-full sm:max-w-[300px]`,children:[(0,l.jsx)(n.b,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-foreground/40`}),(0,l.jsx)(`input`,{type:`text`,placeholder:`Search active records...`,value:re,onChange:e=>B(e.target.value),className:`w-full bg-background border border-[var(--panel-border)] rounded-xl py-2.5 px-9 text-[13px] font-medium text-foreground focus:outline-none focus:border-accent transition-colors shadow-inner`})]})]}),(0,l.jsx)(`div`,{id:`table-scroll-container`,className:`overflow-x-auto w-full block min-h-[300px] relative styled-scrollbars`,children:(0,l.jsx)(n.a,{mode:`wait`,children:A?(0,l.jsxs)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 flex flex-col items-center justify-center bg-background/40 backdrop-blur-[2px] z-50`,children:[(0,l.jsx)(`div`,{className:`w-8 h-8 rounded-full border-2 border-accent border-r-transparent animate-spin mb-4`}),(0,l.jsx)(`p`,{className:`text-[11px] font-bold text-foreground/50 uppercase tracking-widest`,children:`Generating Table`})]},`loader`):(0,l.jsxs)(n.i.table,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`w-full text-left border-collapse table-auto relative min-w-[800px]`,children:[(0,l.jsx)(`thead`,{children:(0,l.jsxs)(`tr`,{className:`border-b border-[var(--panel-border)] transition-colors ${J.headerColor?Pt.find(e=>e.text===J.headerColor)?.bgAlt:`bg-foreground/[0.02]`}`,children:[(0,l.jsx)(`th`,{className:`py-4 px-6 text-[12px] font-bold uppercase tracking-wider whitespace-nowrap text-foreground/50 w-32 border-r border-[var(--panel-border)]/20 ${p?``:`hidden`}`,children:`Creator`}),(J.columns||[]).map((e,t)=>{let r=(J.colColors||{})[e],i=(J.colorTimestamps||{})[`col_${e}`]||0;J.headerColor;let a=(J.colorTimestamps||{}).header||0,o=`bg-transparent`,s=`text-foreground/50`;if(r&&r!==`none`&&i>=a){let e=Pt.find(e=>e.text===r);e&&(o=e.bgCard,s=e.text)}return(0,l.jsx)(`th`,{className:`py-3 px-6 text-[12px] font-bold uppercase tracking-wider relative group h-[53px] min-w-[120px] ${s} ${o} border-r border-[var(--panel-border)]/20 last:border-r-0 select-none align-middle`,children:(0,l.jsxs)(`div`,{className:`flex items-center justify-between gap-2 w-full h-full`,children:[R===e?(0,l.jsx)(`div`,{className:`flex-1 min-w-[50px]`,children:(0,l.jsx)(`span`,{contentEditable:!0,suppressContentEditableWarning:!0,onBlur:t=>{z(null),V(t.currentTarget.textContent||``),(t.currentTarget.textContent||``).trim()!==``&&me(e)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},className:`bg-transparent outline-none border-b border-accent/40 font-bold text-[12px] uppercase tracking-wider p-0 m-0 ${s} block w-full whitespace-nowrap overflow-hidden cursor-text`,ref:e=>{e&&requestAnimationFrame(()=>{e.focus()})},children:ie})}):(0,l.jsx)(`div`,{className:`flex items-center gap-2 flex-1 overflow-hidden`,onClick:()=>{z(e),V(e)},children:(0,l.jsx)(`span`,{className:`truncate cursor-text`,children:e})}),(0,l.jsxs)(`div`,{className:`relative shrink-0 flex items-center h-full gap-0.5`,children:[(0,l.jsx)(`button`,{onClick:()=>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,l.jsx)(n.T,{className:`w-4 h-4`})}),(J.columns||[]).length>1&&(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),Z(e)},className:`p-1.5 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500/10 text-foreground/30 hover:text-red-500`,title:`Delete column`,children:(0,l.jsx)(n.m,{className:`w-3.5 h-3.5`})}),U===e&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>W(null)}),(0,l.jsxs)(`div`,{className:`absolute top-8 right-0 flex gap-1.5 bg-background/95 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-50 items-center`,children:[(0,l.jsx)(`button`,{onClick:t=>{t.preventDefault(),t.stopPropagation();let n={...J.colColors||{},[e]:`none`},r={...J.colorTimestamps||{},[`col_${e}`]:Date.now()};Y({...J,colColors:n,colorTimestamps:r}),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,l.jsx)(n.c,{className:`w-3 h-3`})}),(0,l.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Pt.map(t=>(0,l.jsx)(`button`,{onClick:n=>{n.preventDefault(),n.stopPropagation();let r={...J.colColors||{},[e]:t.text},i={...J.colorTimestamps||{},[`col_${e}`]:Date.now()};Y({...J,colColors:r,colorTimestamps:i}),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_${t}_${e}`)}),(0,l.jsx)(`th`,{className:`py-4 px-4 w-14 border-l border-[var(--panel-border)]/30 relative`,children:(0,l.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 relative z-20`,children:[(0,l.jsx)(`button`,{onClick:()=>q(!oe),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${J.headerColor?Pt.find(e=>e.text===J.headerColor)?.text:`text-foreground/30`}`,children:(0,l.jsx)(n.T,{className:`w-4 h-4`})}),oe&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>q(!1)}),(0,l.jsxs)(`div`,{className:`absolute top-6 right-8 flex gap-1.5 bg-background/90 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-50 items-center`,children:[(0,l.jsx)(`button`,{onClick:()=>{Y({...J,headerColor:``}),q(!1)},className:`w-4 h-4 rounded-full flex items-center justify-center bg-foreground/10 hover:bg-red-500/20 hover:text-red-500 text-foreground/40 transition-colors border border-[var(--panel-border)]/50 shrink-0`,title:`Remove Header Color`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})}),(0,l.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Pt.map(e=>(0,l.jsx)(`button`,{onClick:()=>{let t={...J.colorTimestamps||{},header:Date.now()};Y({...J,headerColor:e.text,colorTimestamps:t}),q(!1)},className:`w-4 h-4 rounded-full ${e.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50`},e.name))]})]}),(0,l.jsx)(`button`,{onClick:X,className:`p-1.5 rounded-lg text-foreground/40 hover:text-accent hover:bg-accent/10 transition-colors flex items-center justify-center`,children:(0,l.jsx)(n.C,{className:`w-4 h-4`})})]})})]})}),(0,l.jsxs)(`tbody`,{children:[he.map((e,t)=>{let r=t%2==1,i=(J.rowColors||{})[e.id],a=i?r?Pt.find(e=>e.text===i)?.bgAlt:Pt.find(e=>e.text===i)?.bgCard:r?`bg-foreground/[0.02]`:`bg-transparent`;return(0,l.jsxs)(`tr`,{className:`border-b border-[var(--panel-border)]/30 hover:bg-foreground/[0.04] transition-colors group`,children:[(0,l.jsx)(`td`,{className:`py-4 px-6 whitespace-nowrap h-[53px] border-r border-[var(--panel-border)]/20 ${a} ${p?``:`hidden`}`,children:(0,l.jsx)(`div`,{className:`flex items-center gap-2`,children:d&&c?(0,l.jsxs)(l.Fragment,{children:[c.photoURL?(0,l.jsx)(`img`,{src:c.photoURL,className:`w-5 h-5 rounded-full shrink-0 object-cover`}):(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/20 text-accent flex items-center justify-center text-[10px] font-bold shrink-0`,children:(c.displayName||c.email||`U`)[0].toUpperCase()}),(0,l.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/80 tracking-tight shrink-0`,children:c.displayName||c.email?.split(`@`)[0]||`User`})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/20 text-accent flex items-center justify-center text-[10px] font-bold shrink-0 shadow-inner group-hover:scale-110 transition-transform`,children:`G`}),(0,l.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/80 tracking-tight shrink-0`,children:`Guest`})]})})}),(J.columns||[]).map(n=>{let i=I?.id===e.id&&I?.field===n,a=(J.colColors||{})[n],o=(J.colorTimestamps||{})[`col_${n}`]||0,s=(J.rowColors||{})[e.id],c=(J.colorTimestamps||{})[`row_${e.id}`]||0,u=``;u=c>o?s===`none`?``:s:o>c?a===`none`?``:a:s===`none`?``:s||a||``,u===`none`&&(u=``);let d=u?Pt.find(e=>e.text===u):null,f=d?r?d.bgAlt:d.bgCard:r?`bg-foreground/[0.02]`:`bg-transparent`,p=d?d.text:`text-foreground/80`;return(0,l.jsxs)(`td`,{className:`py-4 px-6 whitespace-pre-wrap min-w-[120px] text-[14px] font-medium relative ${f} align-top border-r border-[var(--panel-border)]/10 last:border-r-0`,onClick:()=>!i&&L({id:e.id,field:n}),children:[i?(0,l.jsx)(`textarea`,{autoFocus:!0,value:e[n]||``,onChange:t=>le(e.id,n,t.target.value),onBlur:()=>L(null),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&L(null)},className:`absolute inset-0 bg-transparent !border-0 !outline-none focus:!outline-none focus:!ring-0 !ring-0 !shadow-none focus:!shadow-none p-4 px-6 text-[14px] font-medium w-full h-full caret-accent ${p} z-20 resize-none styled-scrollbars`}):null,(0,l.jsx)(`span`,{className:`block w-full min-h-[20px] break-words transition-all ${i?`opacity-0`:`opacity-100`} ${p} ${n===`Status`&&e[n]===`Active`&&!u?`text-green-500`:``}`,children:e[n]||(0,l.jsx)(`span`,{className:`opacity-30 italic font-normal`,children:`empty`})})]},`cell_${e.id||t}_${n}`)}),(0,l.jsx)(`td`,{className:`py-4 px-4 whitespace-nowrap text-right h-[53px] ${a} relative z-10`,children:(0,l.jsxs)(`div`,{className:`flex items-center justify-end gap-1 opacity-20 group-hover:opacity-100 transition-opacity relative`,children:[(0,l.jsx)(`button`,{onClick:()=>H(ae===e.id?null:e.id),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${i?Pt.find(e=>e.text===i)?.text:`text-foreground/40`}`,children:(0,l.jsx)(n.T,{className:`w-4 h-4`})}),ae===e.id&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>H(null)}),(0,l.jsxs)(`div`,{className:`absolute top-6 right-8 flex gap-1.5 bg-background/90 backdrop-blur-xl border border-[var(--panel-border)] p-2 rounded-xl shadow-xl z-50 items-center`,children:[(0,l.jsx)(`button`,{onClick:t=>{t.preventDefault(),t.stopPropagation();let n={...J.rowColors||{},[e.id]:`none`},r={...J.colorTimestamps||{},[`row_${e.id}`]:Date.now()};Y({...J,rowColors:n,colorTimestamps:r}),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,l.jsx)(n.c,{className:`w-3 h-3`})}),(0,l.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Pt.map(t=>(0,l.jsx)(`button`,{onClick:()=>{let n={...J.colorTimestamps||{},[`row_${e.id}`]:Date.now()};Y({...J,rowColors:{...J.rowColors||{},[e.id]:t.text},colorTimestamps:n}),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,l.jsx)(`button`,{onClick:()=>de(e.id),className:`p-2 ml-auto rounded-lg text-foreground/20 hover:text-red-500 hover:bg-red-500/10 transition-colors flex items-center justify-center`,children:(0,l.jsx)(n.m,{className:`w-4 h-4`})})]})})]},e.id||`row_${t}`)}),he.length===0&&(0,l.jsx)(`tr`,{children:(0,l.jsxs)(`td`,{colSpan:(J.columns||[]).length+2,className:`py-12 text-center text-foreground/40 text-[14px] font-medium border border-[var(--panel-border)] m-4 rounded-xl border-dashed`,children:[`No records found in `,J.name||`this table`,`.`]})}),(0,l.jsx)(`tr`,{children:(0,l.jsx)(`td`,{colSpan:(J.columns||[]).length+2,className:`py-2 px-4 border-none bg-foreground/[0.01]`,children:(0,l.jsx)(`div`,{className:`flex items-center gap-4`,children:(0,l.jsx)(`button`,{onClick:ue,className:`p-1.5 rounded-lg text-foreground/40 hover:text-accent hover:bg-accent/10 transition-colors flex items-center justify-center ml-2 border border-transparent hover:border-accent/20`,children:(0,l.jsx)(n.C,{className:`w-4 h-4`})})})})})]})]},`table`)})})]})]})}var It=[{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`}],Lt={dateStr:``,title:``,description:``,time:`12:00`,duration:`60`,color:``,guestEmail:``,customFields:{}};function Rt({title:e=`Calendar View`,subtitle:t=`/templates/calendar`,backUrl:r=`/templates`,eventsCollection:i=`pub_events`,defaultTimeFormat:c=`12h`,config:d}){let f=!!(d?.isPrivate||d?.isAdmin||d?.isShared);d?.isAdmin,d?.isShared,d?.isPrivate;let p=d?.showButton!==!1,m=d?.buttonText||`+`,h=d?.buttonStyle||`primary`,g=d?.showViewsButton!==!1,_=d?.viewsButtonStyle||`secondary`,v=d?.showPrompt!==!1,y=d?.defaultView||`calendar`,b=d?.customFields||[],x=i.startsWith(`user_`)?`private`:i.startsWith(`mem_`)?`shared`:i.startsWith(`admin_`)?`admin_only`:`public`,[S,C]=(0,a.useState)(()=>{try{let e=localStorage.getItem(`cal_view_${i}`);if(e===`list`||e===`month`)return e}catch{}return y===`board`?`list`:`month`}),[w,T]=(0,a.useState)([]),[E,D]=(0,a.useState)([]),[O,k]=(0,a.useState)(!1),[A,j]=(0,a.useState)(null),[ne,M]=(0,a.useState)(!1),[N,P]=(0,a.useState)(!1),[F,I]=(0,a.useState)(null),[L,R]=(0,a.useState)(Lt),[z,re]=(0,a.useState)(new Date),[B,ie]=(0,a.useState)(!1),[U,W]=(0,a.useState)(null),[oe,G]=(0,a.useState)(null),[K,se]=(0,a.useState)(!1),q=`cal_24h_${i}`,[J,Y]=(0,a.useState)(()=>{try{let e=localStorage.getItem(q);if(e!==null)return e===`true`}catch{}return c===`24h`}),ce=()=>{let e=!J;Y(e);try{localStorage.setItem(q,String(e))}catch{}};(0,a.useEffect)(()=>{try{localStorage.setItem(`cal_view_${i}`,S)}catch{}x===`public`||x===`private`?(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{let t=x===`public`?`public`:`private`;T(e.docs.filter(e=>e.data().formType===t).map(e=>e.id))}):T([])},[S,i,x]);let le=()=>{let e=S===`month`?`list`:`month`;C(e);try{localStorage.setItem(`cal_view_${i}`,e)}catch{}},ue=()=>{try{return sessionStorage.getItem(`cal_guest_email`)||``}catch{return``}},de=e=>{try{sessionStorage.setItem(`cal_guest_email`,e)}catch{}};(0,a.useEffect)(()=>(0,s.onAuthStateChanged)(n.wt,async e=>{if(W(e),e&&x===`admin_only`)try{let t=await(0,o.getDoc)((0,o.doc)(n.Tt,`user_profiles`,e.uid));t.exists()&&G(t.data())}catch{}se(!0)}),[x]),(0,a.useEffect)(()=>{if(!K)return;if(x!==`public`&&!U){D([]);return}try{let e=localStorage.getItem(`fbos_cal_${i}`);e&&D(JSON.parse(e))}catch{}let e=(0,o.onSnapshot)(x===`private`&&U?(0,o.query)((0,o.collection)(n.Tt,i),(0,o.where)(`uid`,`==`,U.uid)):(0,o.collection)(n.Tt,i),e=>{let t=[];e.forEach(e=>t.push({id:e.id,...e.data()})),D(t),localStorage.setItem(`fbos_cal_${i}`,JSON.stringify(t))},e=>console.error(`Calendar events:`,e));return()=>e()},[i,x,U?.uid,K]);let X=e=>!!U&&U.uid===e.uid,Z=e=>x===`public`?!1:x===`private`?!!U:X(e),fe=e=>{if(!e)return``;if(J)return e;let[t,n]=e.split(`:`),r=parseInt(t,10),i=r>=12?`PM`:`AM`;return r=r%12||12,`${r}:${n} ${i}`},pe=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`},me=e=>{let[t,n]=(e||`12:00`).split(`:`),r=parseInt(t,10)||0,i=parseInt(n,10)||0,a=r>=12?`PM`:`AM`;return r=r%12||12,{h:r,m:i,ampm:a}},he=(e,t,n)=>{let r=e%12;return n===`PM`&&(r+=12),`${r.toString().padStart(2,`0`)}:${t.toString().padStart(2,`0`)}`},Q=e=>{let t=e.getTimezoneOffset()*6e4;return new Date(e.getTime()-t).toISOString().split(`T`)[0]},ge=()=>Q(new Date),_e=new Date(z.getFullYear(),z.getMonth(),1),ve=new Date(z.getFullYear(),z.getMonth()+1,0),ye=_e.getDay(),be=ve.getDate(),xe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],Se=Array.from({length:42},(e,t)=>{let n=t-ye+1,r=new Date(z.getFullYear(),z.getMonth(),n);return{day:r.getDate(),dateStr:Q(r),isCurrentMonth:n>0&&n<=be}}),Ce=()=>re(S===`month`?new Date(z.getFullYear(),z.getMonth()-1,1):new Date(z.getFullYear(),z.getMonth(),z.getDate()-1)),we=()=>re(S===`month`?new Date(z.getFullYear(),z.getMonth()+1,1):new Date(z.getFullYear(),z.getMonth(),z.getDate()+1)),Te=e=>{if(x!==`public`&&!U)return;let t=new Date;t.setDate(t.getDate()+1);let n=new Date().getHours().toString().padStart(2,`0`);R({...Lt,dateStr:e||Q(t),time:`${n}:00`,guestEmail:x===`public`?ue():``,customFields:{}}),k(!0)},Ee=e=>{let t=e.time;if(t){let[e,n]=t.split(`:`);e&&n&&(t=`${e.padStart(2,`0`)}:${n}`)}R({id:e.id,uid:e.uid,dateStr:e.dateStr,title:e.title,description:e.description||``,time:t||`12:00`,duration:e.duration||`60`,color:e.color||``,guestEmail:e.creatorEmail||``,customFields:e.customFields||{}}),k(!0)},De=async e=>{if(e.preventDefault(),L.title.trim()){M(!0);try{let e={dateStr:L.dateStr,title:L.title.trim(),description:L.description.trim(),time:L.time,duration:L.duration||`60`};if(L.color&&(e.color=L.color),b.length>0&&(e.customFields=L.customFields),!L.id)if(x===`public`){let t=L.guestEmail.trim();e.creatorEmail=t,de(t)}else x===`private`||x===`shared`?(e.uid=U?.uid,e.creatorEmail=U?.email||``,e.creatorName=U?.displayName||``,e.creatorAvatar=U?.photoURL||``):x===`admin_only`&&(e.uid=U?.uid,e.creatorEmail=oe?.email||U?.email||``,e.creatorName=oe?.displayName||oe?.name||``,e.creatorAvatar=oe?.avatar||oe?.avatarUrl||U?.photoURL||``);L.id?(await(0,o.setDoc)((0,o.doc)(n.Tt,i,L.id),e,{merge:!0}),A?.id===L.id&&j({...A,...e})):await(0,o.setDoc)((0,o.doc)(n.Tt,i,`ev_${Date.now()}`),e,{merge:!0}),k(!1)}catch(e){console.error(e)}M(!1)}},Oe=async()=>{if(F){P(!0);try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,i,F.id)),A?.id===F.id&&j(null),I(null),k(!1)}catch{}P(!1)}},ke=e=>{if(x===`private`||!e.creatorEmail&&!e.creatorName)return null;let t=(e.creatorName||e.creatorEmail||`?`).charAt(0).toUpperCase(),n=It.find(t=>t.text===e.color);return(0,l.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 p-3 rounded-xl bg-foreground/[0.03] border border-[var(--panel-border)]/50`,children:[e.creatorAvatar?(0,l.jsx)(`img`,{src:e.creatorAvatar,alt:``,className:`w-8 h-8 rounded-full object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`w-8 h-8 rounded-full ${n?.bgCircle||`bg-accent`} flex items-center justify-center text-[13px] font-extrabold text-white shrink-0`,children:t}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[e.creatorName&&(0,l.jsx)(`span`,{className:`text-[13px] font-bold text-foreground/90 truncate`,children:e.creatorName}),e.creatorEmail&&(0,l.jsx)(`span`,{className:`text-[12px] text-foreground/50 truncate`,children:e.creatorEmail})]})]})},Ae=e=>{if(x===`private`||x===`public`||!e.creatorName&&!e.creatorEmail)return null;let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||``,n=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[e.creatorAvatar?(0,l.jsx)(`img`,{src:e.creatorAvatar,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/15 text-accent flex items-center justify-center text-[8px] font-extrabold shrink-0`,children:n}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),e.creatorEmail&&(0,l.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,e.creatorEmail]})]})]})},je=x===`admin_only`?ae(d,e,i,w):x===`private`?V(d,e,i,w):H(d,e,i,w),Me=()=>{navigator.clipboard.writeText(je),ie(!0),setTimeout(()=>ie(!1),2e3)};if(K&&x!==`public`&&!U)return(0,l.jsx)(`main`,{className:`flex-1 w-full flex items-center justify-center min-h-screen p-8`,children:(0,l.jsxs)(`div`,{className:`text-center glass-panel border border-[var(--panel-border)] rounded-3xl p-12 max-w-sm w-full`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-full bg-accent/10 border border-accent/20 flex items-center justify-center mx-auto mb-4`,children:(0,l.jsx)(n.k,{className:`w-7 h-7 text-accent`})}),(0,l.jsx)(`h2`,{className:`text-2xl font-extrabold mb-2`,children:`Sign in required`}),(0,l.jsx)(`p`,{className:`text-foreground/50 text-[14px] mb-6`,children:`You need to be signed in to access this calendar.`}),(0,l.jsx)(u.Link,{to:`/login`,className:`inline-flex items-center justify-center gap-2 px-6 py-2.5 rounded-xl btn-primary font-bold text-[14px] w-full`,children:`Sign In`})]})});if(!K&&x!==`public`)return(0,l.jsx)(`main`,{className:`flex-1 w-full flex items-center justify-center min-h-screen`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 animate-spin text-accent`})});let $=(x===`public`||!!U)&&p,Ne=()=>(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:d?.tabTitle||d?.tabName||e}),(0,l.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[E.length,` `,E.length===1?`event`:`events`,` · `,S===`month`?`Month`:`Board`,` View`]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[v&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:Me,title:B?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${B?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:B?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:ce,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer btn-secondary text-[12px] font-extrabold`,children:J?`24h`:`12h`}),g&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:le,title:S===`month`?`Switch to Board`:`Switch to Calendar`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${_===`primary`?`btn-primary`:`btn-secondary`}`,children:S===`month`?(0,l.jsx)(n.F,{className:`w-4 h-4`}):(0,l.jsx)(n.dt,{className:`w-4 h-4`})}),$&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>Te(),className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${m===`+`?`w-10`:`px-5`} ${h===`primary`?`btn-primary`:`btn-secondary`}`,children:m===`+`?(0,l.jsx)(n.C,{className:`w-4 h-4`}):(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:m})})]})]}),Pe=()=>(0,l.jsxs)(`div`,{className:`p-4 md:p-6 border-b border-[var(--panel-border)]/50 flex items-center justify-between bg-foreground/[0.01]`,children:[(0,l.jsx)(`h3`,{className:`text-xl font-extrabold tracking-tight ml-2`,children:S===`month`?z.toLocaleString(`default`,{month:`long`,year:`numeric`}):z.toLocaleString(`default`,{month:`long`,day:`numeric`,year:`numeric`})}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,l.jsx)(`button`,{onClick:()=>re(new Date),className:`px-4 py-2 text-[13px] font-bold border border-[var(--panel-border)] rounded-xl mr-2 hover:bg-foreground/5 transition-colors`,children:`Today`}),(0,l.jsx)(`button`,{onClick:Ce,className:`p-2 rounded-xl text-foreground/50 hover:text-foreground hover:bg-foreground/5 transition-colors border border-transparent hover:border-[var(--panel-border)]`,children:(0,l.jsx)(n.ot,{className:`w-5 h-5`})}),(0,l.jsx)(`button`,{onClick:we,className:`p-2 rounded-xl text-foreground/50 hover:text-foreground hover:bg-foreground/5 transition-colors border border-transparent hover:border-[var(--panel-border)]`,children:(0,l.jsx)(n.at,{className:`w-5 h-5`})})]})]}),Fe=()=>(0,l.jsxs)(l.Fragment,{children:[Pe(),S===`month`?(0,l.jsx)(`div`,{className:`overflow-x-auto w-full flex-1`,children:(0,l.jsxs)(`div`,{className:`min-w-[800px] h-full flex flex-col`,children:[(0,l.jsx)(`div`,{className:`grid grid-cols-7 border-b border-[var(--panel-border)]/50 bg-foreground/[0.02]`,children:xe.map(e=>(0,l.jsx)(`div`,{className:`py-3 text-center text-[12px] font-bold uppercase tracking-wider text-foreground/40`,children:e},e))}),(0,l.jsx)(`div`,{className:`grid grid-cols-7 auto-rows-auto bg-[var(--panel-border)] gap-[1px] relative flex-1`,children:Se.map((e,t)=>{let r=e.dateStr===ge(),i=E.filter(t=>t.dateStr===e.dateStr);return(0,l.jsxs)(`div`,{onClick:()=>e.isCurrentMonth&&$&&Te(e.dateStr),className:`min-h-[140px] p-2 bg-[var(--panel-bg)] flex flex-col relative group
|
|
216
|
+
${e.isCurrentMonth?$?`hover:bg-foreground/[0.03] transition-colors cursor-cell`:``:`opacity-30 bg-background/50 pointer-events-none`}`,children:[(0,l.jsx)(`div`,{className:`flex justify-between items-start mb-2 shrink-0`,children:(0,l.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,l.jsx)(`div`,{className:`flex flex-col gap-1.5 flex-1 w-full relative z-10 pb-1`,children:i.map(e=>{let t=It.find(t=>t.text===e.color),r=Z(e);return(0,l.jsxs)(`div`,{className:`px-2 py-1.5 rounded-lg border transition-colors shadow-sm cursor-pointer group/ev relative ${t?t.bgCard+` `+t.borderCard:`bg-accent/20 border-accent/30 hover:bg-accent/40`}`,onClick:t=>{t.stopPropagation(),j(e)},children:[(0,l.jsx)(`p`,{className:`text-[12px] font-bold truncate leading-tight ${r?`pr-5`:``} ${t?t.text:`text-foreground`}`,children:e.title}),(0,l.jsx)(`p`,{className:`text-[10px] text-foreground/70 mt-0.5`,children:fe(e.time)}),r&&(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),Ee(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,l.jsx)(n.w,{className:`w-3 h-3`})})]},e.id)})})]},t)})}),(0,l.jsx)(`style`,{children:`
|
|
313
217
|
.styled-scrollbars::-webkit-scrollbar{width:4px}
|
|
314
218
|
.styled-scrollbars::-webkit-scrollbar-thumb{background:color-mix(in srgb,var(--accent-color) 30%,transparent);border-radius:4px}
|
|
315
219
|
input[type="time"]::-webkit-calendar-picker-indicator{display:none!important}
|
|
316
220
|
input[type="date"]{color-scheme:dark}
|
|
317
221
|
input[type="date"]::-webkit-calendar-picker-indicator{cursor:pointer;opacity:.5;transition:opacity .2s}
|
|
318
222
|
input[type="date"]::-webkit-calendar-picker-indicator:hover{opacity:1}
|
|
319
|
-
`})]})}):(0,l.jsxs)(`div`,{className:`flex flex-col p-4 md:p-8 overflow-y-auto w-full flex-1 gap-4`,children:[E.filter(e=>e.dateStr===
|
|
223
|
+
`})]})}):(0,l.jsxs)(`div`,{className:`flex flex-col p-4 md:p-8 overflow-y-auto w-full flex-1 gap-4`,children:[E.filter(e=>e.dateStr===Q(z)).sort((e,t)=>e.time.localeCompare(t.time)).map(e=>{let t=new Date(e.dateStr+`T12:00:00`),r=It.find(t=>t.text===e.color),i=Z(e);return(0,l.jsxs)(`div`,{onClick:()=>j(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,l.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,l.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,l.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:t.toLocaleString(`default`,{month:`short`})}),(0,l.jsx)(`span`,{className:`text-[18px] font-black leading-none ${r?r.text:`group-hover:text-accent`}`,children:t.getDate()})]}),(0,l.jsx)(`div`,{className:`h-6 w-px bg-[var(--panel-border)] hidden sm:block group-hover:bg-accent/30 transition-colors`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-1 min-w-0 flex-1`,children:[(0,l.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,l.jsxs)(`div`,{className:`flex items-center gap-3 text-[12px] text-foreground/50 font-medium`,children:[(0,l.jsx)(`span`,{children:fe(e.time)}),(0,l.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,l.jsx)(n.et,{className:`w-3 h-3`}),pe(e.duration)]})]})]}),i&&(0,l.jsxs)(`div`,{className:`ml-auto pl-2 flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),Ee(e)},className:`p-2.5 rounded-xl text-foreground/50 hover:bg-foreground/10 hover:text-foreground transition-colors`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),I(e)},className:`p-2.5 rounded-xl text-foreground/30 hover:bg-red-500/10 hover:text-red-500 transition-colors`,children:(0,l.jsx)(n.m,{className:`w-4 h-4`})})]})]}),f&&Ae(e)]},e.id)}),E.filter(e=>e.dateStr===Q(z)).length===0&&(0,l.jsx)(`div`,{className:`p-12 text-center text-foreground/40 font-medium`,children:`No events scheduled for this day.`})]})]}),Ie=()=>(0,l.jsxs)(n.a,{children:[A&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`w-full max-w-[500px] p-6 sm:p-8 rounded-3xl glass-panel border shadow-2xl relative z-10 ${It.find(e=>e.text===A.color)?.bgCard||`bg-background`} ${It.find(e=>e.text===A.color)?.borderCard||`border-[var(--panel-border)]`}`,children:[(0,l.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:[Z(A)&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:()=>{j(null),Ee(A)},className:`p-2 rounded-xl text-foreground/50 hover:bg-foreground/10 hover:text-foreground transition-all`,title:`Edit`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{I(A),j(null)},className:`p-2 rounded-xl text-foreground/50 hover:bg-red-500/10 hover:text-red-500 transition-all`,title:`Delete`,children:(0,l.jsx)(n.m,{className:`w-4 h-4`})}),(0,l.jsx)(`div`,{className:`w-px h-6 bg-[var(--panel-border)]/50 mx-1`})]}),(0,l.jsx)(`button`,{onClick:()=>j(null),className:`p-2 rounded-xl text-foreground/40 hover:bg-foreground/10 hover:text-foreground transition-all`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})})]}),(0,l.jsxs)(`div`,{className:`mb-6 pr-32`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,l.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${It.find(e=>e.text===A.color)?.bgCircle||`bg-accent`}`}),(0,l.jsx)(`span`,{className:`text-[11px] font-bold tracking-[0.2em] uppercase ${It.find(e=>e.text===A.color)?.text||`text-accent`}`,children:`Event Details`})]}),(0,l.jsx)(`h3`,{className:`text-3xl font-black mb-3 tracking-tight leading-tight break-words ${It.find(e=>e.text===A.color)?.text||`text-foreground`}`,children:A.title}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-2 mt-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2.5 text-[14px] text-foreground/70 font-medium`,children:[(0,l.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,l.jsx)(n.dt,{className:`w-4 h-4 text-foreground/50`})}),new Date(A.dateStr+`T12:00:00`).toLocaleDateString(`default`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2.5 text-[14px] text-foreground/70 font-medium`,children:[(0,l.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,l.jsx)(n.et,{className:`w-4 h-4 text-foreground/50`})}),fe(A.time),` `,(0,l.jsxs)(`span`,{className:`text-foreground/40 text-[12px] ml-1`,children:[`(`,pe(A.duration),`)`]})]})]}),ke(A)]}),(0,l.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`}),A.description?(0,l.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,l.jsx)(`div`,{className:`text-[14px] text-foreground/80 font-medium whitespace-pre-wrap leading-tight break-words`,children:A.description})}):(0,l.jsx)(`div`,{className:`p-4 mb-4 rounded-2xl border border-dashed border-[var(--panel-border)] bg-foreground/[0.01] text-center`,children:(0,l.jsx)(`p`,{className:`text-[12px] font-medium text-foreground/40`,children:`No description provided for this event.`})}),A.customFields&&Object.entries(A.customFields).filter(([,e])=>e).length>0&&(0,l.jsx)(`div`,{className:`flex flex-col gap-2 mb-2`,children:Object.entries(A.customFields).filter(([,e])=>e).map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex items-start gap-2 text-[13px]`,children:[(0,l.jsxs)(`span`,{className:`font-bold text-foreground/50 capitalize shrink-0`,children:[e,`:`]}),(0,l.jsx)(`span`,{className:`text-foreground/80 font-medium break-words min-w-0`,children:t})]},e))})]})]},`view-modal`),O&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>k(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`w-full max-w-[500px] p-6 sm:p-8 rounded-3xl glass-panel border border-[var(--panel-border)] shadow-2xl relative z-10 max-h-[90vh] overflow-y-auto styled-scrollbars`,children:[(0,l.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1`,children:[L.id&&Z({uid:L.uid})&&(0,l.jsx)(`button`,{onClick:()=>{k(!1),I({id:L.id,...L})},className:`p-2 rounded-xl text-foreground/30 hover:bg-red-500/10 hover:text-red-500 transition-all`,children:(0,l.jsx)(n.m,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>k(!1),className:`p-2 rounded-xl text-foreground/40 hover:bg-foreground/10 hover:text-foreground transition-all`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})})]}),(0,l.jsxs)(`div`,{className:`mb-6 pr-12`,children:[(0,l.jsx)(`h3`,{className:`text-2xl font-extrabold mb-1 tracking-tight`,children:L.id?`Edit Event`:`Add Event`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/50`,children:L.id?`Modify your scheduled calendar block.`:`Schedule a new calendar block.`})]}),(0,l.jsxs)(`form`,{onSubmit:De,className:`space-y-4`,children:[x===`public`&&!L.id&&(0,l.jsx)(n.r,{label:`Your Email`,type:`email`,value:L.guestEmail,onChange:e=>R({...L,guestEmail:e.target.value}),placeholder:`you@example.com`,required:!0}),(0,l.jsx)(n.r,{label:`Event Title`,value:L.title,onChange:e=>R({...L,title:e.target.value}),placeholder:`e.g. Design Sync`,required:!0}),(0,l.jsxs)(`div`,{className:`flex flex-col w-full relative`,children:[(0,l.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Description`}),(0,l.jsx)(`textarea`,{value:L.description,onChange:e=>R({...L,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,l.jsx)(n.r,{label:e,value:L.customFields[e]||``,onChange:t=>R({...L,customFields:{...L.customFields,[e]:t.target.value}}),placeholder:`Enter ${e.toLowerCase()}...`},e)),(0,l.jsx)(`style`,{children:`
|
|
320
224
|
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}
|
|
321
225
|
input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}
|
|
322
226
|
input[type="number"]{-moz-appearance:textfield}
|
|
323
|
-
`}),(0,l.jsxs)(`div`,{className:`relative group/date flex flex-col w-full`,children:[(0,l.jsx)(n.r,{type:`date`,label:`Date`,required:!0,value:R.dateStr,onChange:e=>z({...R,dateStr:e.target.value}),className:`pr-10`}),(0,l.jsx)(`div`,{className:`absolute right-4 bottom-4 pointer-events-none group-focus-within/date:text-accent text-foreground/40 transition-colors`,children:(0,l.jsx)(n.dt,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[oe?(0,l.jsx)(n.r,{type:`time`,label:`Time`,value:R.time,onChange:e=>z({...R,time:e.target.value}),required:!0}):(()=>{let{h:e,m:t,ampm:n}=Z(R.time);return(0,l.jsxs)(`div`,{className:`flex flex-col w-full`,children:[(0,l.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Time`}),(0,l.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,l.jsx)(`input`,{type:`number`,min:1,max:12,value:e,onChange:e=>z({...R,time:he(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,l.jsx)(`span`,{className:`text-foreground/40 font-bold text-[15px] select-none`,children:`:`}),(0,l.jsx)(`input`,{type:`number`,min:0,max:59,value:t.toString().padStart(2,`0`),onChange:t=>z({...R,time:he(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,l.jsx)(`button`,{type:`button`,onClick:()=>z({...R,time:he(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,l.jsx)(n.r,{type:`number`,min:`1`,max:`1440`,label:`Duration (min)`,value:R.duration,onChange:e=>z({...R,duration:e.target.value}),placeholder:`60`,required:!0})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,l.jsx)(`label`,{className:`text-[11px] font-bold text-foreground/50 uppercase tracking-widest mt-1`,children:`Event Color`}),(0,l.jsx)(`div`,{className:`flex gap-2 items-center relative z-10 w-full h-[46px]`,children:zt.map(e=>(0,l.jsx)(`button`,{type:`button`,onClick:()=>z({...R,color:R.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:R.color===e.text&&(0,l.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full bg-background`})},e.name))})]}),(0,l.jsx)(`div`,{className:`pt-2`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:M,className:`w-full py-3`,children:R.id?`Save Changes`:`Create Event`})})]})]})]},`edit-modal`),(0,l.jsx)(te,{isOpen:!!I,title:`Confirm Deletion`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:I?.title}),` This action is permanent.`]}),onConfirm:Oe,onCancel:()=>{L(null)},isProcessing:P,confirmText:`Yes, Delete`})]});return f?(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:d?.tabTitle||d?.tabName||e}),t&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),t]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[Pe(),$()]})]}),Ie()]}):(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e}),t&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),t]})]}),(0,l.jsxs)(`div`,{className:`flex justify-between items-center mb-6 border-b border-[var(--panel-border)] pb-6 relative z-20`,children:[r?(0,l.jsxs)(u.Link,{to:r,className:`px-5 py-2 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold hover:bg-foreground/5 transition-all flex items-center gap-2`,children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` Go Back`]}):(0,l.jsx)(`div`,{}),(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:ce,className:`px-3 h-10 text-[12px] font-bold rounded-xl flex items-center justify-center border-[var(--panel-border)] border shrink-0 hover:bg-foreground/5 shadow-sm text-foreground/70`,children:oe?`24h`:`12h`}),(0,l.jsx)(n.n,{variant:`secondary`,onClick:le,className:`w-10 h-10 p-0 text-[14px] font-bold rounded-xl flex items-center justify-center border-[var(--panel-border)] border shrink-0`,children:S===`month`?(0,l.jsx)(n.F,{className:`w-4 h-4 text-foreground/70`}):(0,l.jsx)(n.dt,{className:`w-4 h-4 text-foreground/70`})}),Ne&&(0,l.jsxs)(n.n,{onClick:()=>Te(),className:`px-6 py-2.5 text-[14px] font-bold rounded-xl shadow-lg flex items-center gap-2`,children:[(0,l.jsx)(n.C,{className:`w-4 h-4`}),` Event`]})]})]}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative flex flex-col flex-1`,children:[(0,l.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`}),$()]}),Ie()]})}var Ht={appName:`The main name of your application shown in headers and titles.`,defaultTheme:`Choose how the app starts immediately on load.`,showThemeToggle:`Allow users to manually toggle dark mode on/off.`,logoUrl:`Direct URL to your app's main logo. Need to upload one?`,faviconUrl:`Direct URL to your app's favicon. Need to upload one?`,background:`Main background canvas color under all content.`,foreground:`Primary typography color used across the app.`,accent:`The primary brand color for highlights, buttons, and links.`,panelBg:`Background color of glass cards and panels.`,panelBorder:`Borders of panels, inputs, and dropdowns.`,glowColor:`The global glow shadow applied to borders of focused inputs.`,buttonHoverGradient:`Start and end hex for primary button hover effects.`,textGradient:`Three tone gradient applied to large headers.`,buttonRadius:`Border radius for standard buttons.`,cardRadius:`Curvature of main content panels.`,inputRadius:`Rounding applied to form inputs.`,modalRadius:`Global popup containers and dashboard content cards.`,blurIntensity:`Glassmorphism backdrop-blur amounts.`,notificationIconColor:`Color applied to notification badging.`,fontFamily:`Choose the main typography of your brand.`,home:`Complete customization of the landing page settings.`,title:`Main heading displayed on the Landing Page or Form.`,subtitle:`Smaller colored overline text above the main title.`,text:`The descriptive paragraph text under the hero headers or buttons.`,primary:`Main call-to-action block settings.`,secondary:`Secondary ghost button block settings.`,sections:`Toggle visibility of landing page sectors.`,contactForm:`Customize the form wrapper and its labels.`,nameLabel:`Placeholder/Label for the Name input.`,emailLabel:`Placeholder/Label for the Email input.`,messageLabel:`Placeholder/Label for the Message textarea.`,submitText:`Text for the form submit button.`,action:`Where the button routes the user.`,form:`Which public form to open. Note: Form submissions will securely map to the Submissions tab in your admin dashboard.`,url:`External http link or internal /route destination.`},Ut=[{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`]}}],Wt={defaultTheme:[`system`,`light`,`dark`],cornerRounding:[`default`,`custom`],action:[`sign_in`,`register`,`redirect`,`form`],type:[`text`,`email`,`tel`,`textarea`],form:[`contact`],formType:[`public`,`private`],submitPage:[`submissions`,`requests`],fontFamily:[`Inter`,`Outfit`,`Roboto`,`Space Grotesk`,`Plus Jakarta Sans`,`System UI`]};n.Tt&&(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{let t=[];e.forEach(e=>{e.data().formType!==`private`&&t.push(e.id)}),t.length>0&&Object.assign(Wt,{form:t})}).catch(()=>{});var Gt=({value:e,onChange:t,onBlur:n,onFocus:r,className:i,isNumber:o,handleBlurOrEnter:s,placeholder:c,disabled:u})=>{let[d,f]=a.default.useState(e),[p,m]=a.default.useState(!1),h=a.default.useRef(null);a.default.useEffect(()=>{f(e)},[e]),(0,a.useEffect)(()=>{!p&&h.current&&(h.current.scrollLeft=0)},[d,p]);let g=typeof i==`string`?i.match(/(?:max-w-\[[^\]]+\]|sm:max-w-\[[^\]]+\]|md:max-w-\[[^\]]+\])\s*/g):null,_=g?g.join(` `):`max-w-[200px] sm:max-w-[300px]`,v=typeof i==`string`?i.replace(/(?:max-w-\[[^\]]+\]|sm:max-w-\[[^\]]+\]|md:max-w-\[[^\]]+\]|text-ellipsis)\s*/g,``):``,y=v.trim();return(0,l.jsx)(`div`,{className:`relative inline-grid group/autoresize ${_}`,children:(0,l.jsxs)(`div`,{className:`col-start-1 row-start-1 overflow-x-auto overflow-y-hidden pb-[1px] styled-scrollbars-mini inline-grid items-center`,children:[(0,l.jsx)(`span`,{className:`${v} invisible whitespace-pre col-start-1 row-start-1 border-none p-0 inline-block px-[2px]`,"aria-hidden":`true`,children:d||c||(o?`0`:` `)}),(0,l.jsx)(`input`,{disabled:u,ref:h,type:o?`number`:`text`,value:d,placeholder:c,spellCheck:!1,className:`${y} col-start-1 row-start-1 w-full min-w-[20px] transition-all duration-200 ${u?`cursor-not-allowed opacity-50 select-none`:``} ${p?`relative z-50 bg-background shadow-md`:``}`,onDoubleClick:e=>{u||e.currentTarget.select()},onPaste:()=>{setTimeout(()=>{h.current&&(h.current.scrollLeft=0)},10)},onChange:e=>{u||f(e.target.value)},onKeyDown:n=>{if(!u&&n.key===`Enter`){let r=o?parseFloat(n.currentTarget.value)||0:n.currentTarget.value;r!==e&&t(r),s&&s(n),n.currentTarget.blur()}},onBlur:r=>{if(u)return;m(!1);let i=o?parseFloat(r.currentTarget.value)||0:r.currentTarget.value;i!==e&&t(i),s&&s(r),n&&n(r),r.currentTarget.scrollLeft=0},onFocus:e=>{u||(m(!0),r&&r(e))}})]})})},Kt=({objectKey:e,displayKey:r,value:i,onChange:o,depth:s=0,isLast:c=!1,keysToRender:d,isGlobalSaving:f,customExplanations:p,customEnums:m,disabledKeys:h=[],hideInnerLoader:g=!1,meta:_={}})=>{let v=r||e,y=typeof i==`object`&&!!i&&!Array.isArray(i),b=Array.isArray(i),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(e===`colors`||e===`fields`),[T,E]=(0,a.useState)(!1),[D,ee]=(0,a.useState)(!1),O=a.default.useRef(null),[k,A]=a.default.useState(null),te=a.default.useRef(null);(0,a.useEffect)(()=>{f||E(!1)},[f]);let j=e=>{O.current=e.currentTarget.value},M=e=>{`key`in e&&e.key===`Enter`&&e.currentTarget.blur(),(`type`in e&&e.type===`blur`||`key`in e&&e.key===`Enter`)&&(O.current!==null&&O.current!==e.currentTarget.value&&(g||E(!0)),O.current=null)};a.default.useEffect(()=>{A(null)},[i]);let N=p?.[e]||Ht[e],P=m?.[e]||Wt[e],F=Array.isArray(h)&&h.includes(e),I=t=>(0,l.jsxs)(`div`,{className:`flex flex-col text-[14px] font-mono leading-relaxed my-0.5`,style:{marginLeft:s>0?32:0},children:[N&&(0,l.jsxs)(`span`,{className:`text-foreground/40 text-[12px] font-mono italic select-none mt-2 mb-0.5 flex flex-wrap items-center gap-1`,children:[`// `,N.split(/(https?:\/\/[^\s,]+)/g).map((e,t)=>e.startsWith(`http`)?(0,l.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`text-accent hover:text-accentDeep underline underline-offset-2 cursor-pointer transition-colors pointer-events-auto`,children:e},t):(0,l.jsx)(`span`,{children:e},t)),(e===`logoUrl`||e===`faviconUrl`)&&(0,l.jsx)(u.Link,{to:`/drive/public`,className:`text-accent flex items-center gap-1 hover:text-accentDeep underline underline-offset-2 ml-1 cursor-pointer transition-colors`,children:`Open Drive / Public`})]}),t]});if(y){let t=d?[...d]:Object.keys(i);return t=t.filter(e=>!(e===`showThemeToggle`&&i.defaultTheme!==`system`||e===`cornerRadii`&&i.cornerRounding!==`custom`||e===`url`&&`action`in i&&i.action!==`redirect`||e===`form`&&`action`in i&&i.action!==`form`||e===`currencySymbol`&&i.type!==`currency`||e===`options`&&i.type!==`select`)),i.action===`redirect`&&!t.includes(`url`)&&i.showButton!==!1&&t.push(`url`),i.action===`form`&&!t.includes(`form`)&&i.showButton!==!1&&t.push(`form`),i.type===`currency`&&!t.includes(`currencySymbol`)&&t.push(`currencySymbol`),i.type===`select`&&!t.includes(`options`)&&t.push(`options`),I((0,l.jsxs)(`div`,{className:`flex flex-col group/obj`,children:[e?(0,l.jsxs)(`div`,{className:`flex items-center gap-1 hover:bg-foreground/[0.04] rounded-lg pl-0.5 pr-2 py-0.5 -ml-[18px] w-fit transition-colors ${C?`cursor-pointer`:``}`,onClick:()=>C&&w(!1),children:[(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),w(!C)},className:`text-foreground/30 hover:text-foreground/80 transition-colors w-4 flex items-center justify-center font-black text-[10px]`,title:C?`Unfold`:`Fold`,children:C?`►`:`▼`}),(0,l.jsxs)(`span`,{className:`text-accent font-extrabold`,children:[`"`,v,`"`]}),(0,l.jsx)(`span`,{className:`text-foreground/50`,children:`:`}),` `,(0,l.jsx)(`span`,{className:`text-foreground/70 font-bold`,children:C?`{...}`:`{`})]}):s>0?(0,l.jsx)(`div`,{className:`text-foreground/70 font-bold px-2`,children:`{`}):null,!C&&(0,l.jsx)(`div`,{className:`flex flex-col ${s>0?`border-l border-[var(--panel-border)]/30 ml-2 pl-1`:``}`,children:t.map((e,t,n)=>e===`subtitle`&&i.showSubtitle===!1||e===`url`&&`action`in i&&i.action!==`redirect`||e===`form`&&`action`in i&&i.action!==`form`?null:(0,l.jsx)(Kt,{objectKey:e,value:i[e],onChange:t=>{let n={...i,[e]:t};e===`action`&&t===`form`&&!n.form&&(n.form=`contact`),e===`action`&&t===`redirect`&&!n.url&&(n.url=`/`),e===`type`&&t===`currency`&&!n.currencySymbol&&(n.currencySymbol=`$`),e===`type`&&t===`select`&&!n.options&&(n.options=[`Option 1`,`Option 2`]),o(n)},depth:s+1,isLast:t===n.length-1,isGlobalSaving:f,customExplanations:p,customEnums:m,disabledKeys:h,hideInnerLoader:g,meta:_},e))}),e&&!C&&(0,l.jsxs)(`div`,{className:`px-2 mt-1`,children:[(0,l.jsx)(`span`,{className:`text-foreground/70 font-bold`,children:`}`}),!c&&(0,l.jsx)(`span`,{className:`text-foreground/50`,children:`,`})]}),e&&C&&!c&&(0,l.jsx)(`span`,{className:`text-foreground/50 -mt-1 ml-2`,children:`,`})]}))}if(b)return I((0,l.jsxs)(`div`,{className:`flex flex-col group/arr`,children:[e?(0,l.jsxs)(`div`,{className:`flex items-center gap-1 hover:bg-foreground/[0.04] rounded-lg pl-0.5 pr-2 py-0.5 -ml-[18px] w-fit transition-colors ${C?`cursor-pointer`:``}`,onClick:()=>C&&w(!1),children:[(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),w(!C)},className:`text-foreground/30 hover:text-foreground/80 transition-colors w-4 flex items-center justify-center font-black text-[10px]`,title:C?`Unfold`:`Fold`,children:C?`►`:`▼`}),(0,l.jsxs)(`span`,{className:`text-accent font-extrabold`,children:[`"`,v,`"`]}),(0,l.jsx)(`span`,{className:`text-foreground/50`,children:`:`}),` `,(0,l.jsx)(`span`,{className:`text-foreground/70 font-bold`,children:C?`[...]`:`[`})]}):(0,l.jsx)(`div`,{className:`flex items-center gap-1 group-hover/arr:bg-foreground/[0.02] rounded-lg px-2 py-0.5 -ml-2 w-fit transition-colors`,children:(0,l.jsx)(`span`,{className:`text-foreground/70 font-bold`,children:`[`})}),!C&&(0,l.jsxs)(`div`,{className:`flex flex-col border-l border-[var(--panel-border)]/30 ml-2 mt-1 pl-1`,style:{marginLeft:32},children:[i.map((e,t)=>{if(typeof e==`object`&&e)return(0,l.jsxs)(`div`,{className:`pl-2 border-l border-[var(--panel-border)]/20 mt-1 mb-1 relative group/arr-item`,children:[(0,l.jsx)(`button`,{onClick:()=>{let e=[...i];e.splice(t,1),o(e)},className:`absolute -left-[11px] top-1.5 w-5 h-5 bg-background border border-[var(--panel-border)] text-red-500 hover:bg-red-500/10 rounded flex items-center justify-center opacity-0 group-hover/arr-item:opacity-100 transition-all font-bold text-[14px] leading-none z-20`,title:`Remove Item`,children:`×`}),(0,l.jsx)(Kt,{value:e,onChange:e=>{let n=[...i];n[t]=e,o(n)},depth:s+1,isLast:t===i.length-1,isGlobalSaving:f,customExplanations:p,customEnums:m,disabledKeys:h})]},t);let r=typeof e==`string`&&(e.startsWith(`#`)||e.startsWith(`rgba`)||e.startsWith(`rgb`));return(0,l.jsxs)(`div`,{className:`flex items-center gap-1 group/item w-fit relative z-10 my-0.5`,children:[(0,l.jsx)(`button`,{onClick:()=>{let e=[...i];e.splice(t,1),o(e)},className:`absolute -left-6 top-1/2 -translate-y-1/2 w-4 h-4 text-red-500 hover:bg-red-500/10 rounded flex items-center justify-center opacity-0 group-hover/item:opacity-100 transition-all font-bold text-[14px] leading-none`,title:`Remove Item`,children:`×`}),(0,l.jsxs)(`span`,{className:`text-foreground/40 text-[11px] w-4 select-none font-bold`,children:[t,`:`]}),(0,l.jsx)(`span`,{className:`text-foreground/40 shrink-0`,children:`"`}),r&&(0,l.jsxs)(`div`,{className:`relative w-5 h-5 rounded-full overflow-hidden border border-[var(--panel-border)] shrink-0 mx-1 group/item hover:border-accent transition-colors bg-[var(--background)]`,children:[(0,l.jsx)(`input`,{type:`color`,value:e.length===7&&e.startsWith(`#`)?e:`#000000`,onChange:e=>{let n=[...i];n[t]=e.target.value,o(n)},className:`absolute -inset-8 w-24 h-24 cursor-pointer opacity-0`}),(0,l.jsx)(`div`,{className:`absolute inset-0 pointer-events-none transition-transform group-hover/item:scale-110`,style:{backgroundColor:e}})]}),(0,l.jsx)(Gt,{value:e,isNumber:typeof e==`number`,onChange:e=>{let n=[...i];n[t]=e,o(n)},onFocus:j,handleBlurOrEnter:M,className:`no-glow bg-transparent text-foreground font-bold outline-none focus:outline-none focus:ring-0 p-0 m-0 transition-colors max-w-[200px] sm:max-w-[300px] text-ellipsis placeholder:text-foreground/20`}),(0,l.jsx)(`span`,{className:`text-foreground/40 shrink-0`,children:`"`}),(0,l.jsx)(`span`,{className:`text-foreground/50 shrink-0`,children:t<i.length-1?`,`:``}),T&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40 shrink-0`})]},t)}),(!(i.length>0&&typeof i[0]==`string`&&(i[0].startsWith(`#`)||i[0].startsWith(`rgba`)||i[0].startsWith(`color-mix`)))||i.length<6)&&(0,l.jsx)(`button`,{onClick:()=>{let t=[...i],n=``;if(e===`fields`){let e=t.map(e=>e.name);n=_?.formType===`private`?e.includes(`issue_type`)?e.includes(`urgency`)?e.includes(`description`)?e.includes(`device`)?e.includes(`subscribe`)?{type:`text`,name:`custom_field_${t.length}`,label:`Custom Field`,required:!1,placeholder:``}:{type:`checkbox`,name:`subscribe`,label:`Receive status updates via email`,required:!1}:{type:`text`,name:`device`,label:`Device / OS`,required:!1,placeholder:`e.g., iPhone 15, Windows 11`}:{type:`textarea`,name:`description`,label:`Description`,required:!0,placeholder:`Please provide detailed information...`}:{type:`select`,name:`urgency`,label:`Urgency Level`,required:!0,options:[`Low`,`Medium`,`High`,`Critical`]}:{type:`select`,name:`issue_type`,label:`Issue Type`,required:!0,options:[`Bug Report`,`Feature Request`,`Billing`,`General Question`]}:e.includes(`name`)?e.includes(`email`)?e.includes(`phone`)?e.includes(`questions`)?e.includes(`budget`)?e.includes(`service_type`)?e.includes(`subscribe`)?e.includes(`age`)?{type:`text`,name:`custom_field_${t.length}`,label:`Custom Field`,required:!1,placeholder:``}:{type:`age`,name:`age`,label:`Age`,required:!1,placeholder:`e.g. 25`}:{type:`checkbox`,name:`subscribe`,label:`Subscribe to newsletter`,required:!1}:{type:`select`,name:`service_type`,label:`Service Interested In`,required:!1,options:[`Consulting`,`Development`,`Design`]}:{type:`currency`,name:`budget`,label:`Budget`,required:!1,placeholder:`e.g. 5000`,currencySymbol:`$`}:{type:`textarea`,name:`questions`,label:`Questions`,required:!1,placeholder:`How can we help you?`}:{type:`tel`,name:`phone`,label:`Phone Number`,required:!1,placeholder:`+1 (555) 000-0000`}:{type:`email`,name:`email`,label:`Email Address`,required:!0,placeholder:`you@example.com`}:{type:`text`,name:`name`,label:`Full Name`,required:!0,placeholder:`Enter your name`}}else if(typeof t[0]==`string`)if(t[0].startsWith(`#`)||t[0].startsWith(`rgba`)||t[0].startsWith(`rgb`)||t[0].startsWith(`color-mix`))n=t[t.length-1];else{let e=[`Marketing`,`Support`,`Analysis`,`Strategy`,`Maintenance`];n=e[Math.min(t.length,e.length)-1]||`Option ${t.length+1}`}else n=t.length>0?JSON.parse(JSON.stringify(t[t.length-1])):``,n&&typeof n==`object`&&(n.name&&=`${n.name}_${t.length}`,n.label&&=`${n.label} ${t.length}`);t.push(n),o(t)},className:`mt-2 mb-1 w-fit flex items-center gap-1.5 px-3 py-1 bg-accent/10 hover:bg-accent/20 text-accent font-extrabold text-[11px] uppercase tracking-wider rounded-md transition-colors border border-accent/20`,children:`+ Add Item`})]}),e&&!C&&(0,l.jsxs)(`div`,{className:`px-2 mt-1`,children:[(0,l.jsx)(`span`,{className:`text-foreground/70 font-bold`,children:`]`}),!c&&(0,l.jsx)(`span`,{className:`text-foreground/50`,children:`,`})]}),!e&&(0,l.jsxs)(`div`,{className:`px-2 mt-1`,children:[(0,l.jsx)(`span`,{className:`text-foreground/70 font-bold`,children:`]`}),!c&&(0,l.jsx)(`span`,{className:`text-foreground/50`,children:`,`})]}),e&&C&&!c&&(0,l.jsx)(`span`,{className:`text-foreground/50 -mt-1 ml-2`,children:`,`})]}));if(typeof i==`boolean`)return I((0,l.jsxs)(`div`,{className:`flex items-center gap-1 group w-fit relative z-10 my-0.5`,children:[(0,l.jsxs)(`span`,{className:`text-accent font-extrabold shrink-0`,children:[`"`,v,`"`]}),(0,l.jsx)(`span`,{className:`text-foreground/50 shrink-0`,children:`:`}),(0,l.jsx)(`button`,{disabled:F||T,onClick:()=>{g||E(!0),o(!i)},className:`px-3 py-1 rounded-md text-[12px] font-extrabold transition-colors ml-1 uppercase tracking-wider ${i?`bg-emerald-500/20 text-emerald-500`:`bg-red-500/20 text-red-500`} ${F||T?`opacity-50 cursor-not-allowed`:`hover:scale-[1.02] active:scale-[0.98]`}`,children:i?`true`:`false`}),T&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40 ml-1`}),!c&&(0,l.jsx)(`span`,{className:`text-foreground/50`,children:`,`})]}));let L=typeof i==`string`&&(i.startsWith(`#`)||i.startsWith(`rgba`)||i.startsWith(`rgb`)),R=typeof i==`string`&&e&&String(e).endsWith(`Url`);return I((0,l.jsxs)(`div`,{className:`flex items-center gap-1 group relative z-10 my-0.5 ${R?`w-full pr-0 sm:pr-8`:`w-fit`}`,children:[(0,l.jsxs)(`span`,{className:`text-accent font-extrabold shrink-0`,children:[`"`,v,`"`]}),(0,l.jsx)(`span`,{className:`text-foreground/50 shrink-0`,children:`:`}),P?(0,l.jsxs)(`div`,{className:`flex items-center gap-1 ml-1 relative group/enum`,ref:te,children:[(0,l.jsx)(`span`,{className:`text-foreground/40`,children:`"`}),(0,l.jsx)(`button`,{disabled:F||T,title:F?`Cannot be edited`:`Click to cycle options`,tabIndex:0,onClick:()=>{if(F)return;let e=k===null?i:k,t=P[(P.indexOf(e)+1)%P.length];A(t),g||E(!0),o(t)},className:`${F||T?`bg-foreground/5 text-foreground/40 cursor-not-allowed opacity-50`:`bg-accent/10 hover:bg-accent/20 text-accent cursor-pointer shadow-sm hover:scale-[1.02] active:scale-[0.98]`} outline-none px-3 py-1 rounded-md transition-all font-extrabold uppercase tracking-wider text-[11px] border border-transparent`,children:k===null?i:k}),T&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40 ml-1`}),(0,l.jsx)(`span`,{className:`text-foreground/40`,children:`"`})]}):(0,l.jsxs)(`div`,{className:`flex items-center gap-0.5 ml-1 flex-1 min-w-0`,children:[(0,l.jsx)(`span`,{className:`text-foreground/40 shrink-0`,children:`"`}),L&&(0,l.jsxs)(`div`,{className:`relative w-5 h-5 rounded-full overflow-hidden border border-[var(--panel-border)] shrink-0 mx-1 group/item hover:border-accent transition-colors bg-[var(--background)]`,children:[(0,l.jsx)(`input`,{type:`color`,value:i.length===7&&i.startsWith(`#`)?i:`#000000`,onFocus:j,onBlur:e=>{o(e.target.value),O.current=null},onChange:e=>o(e.target.value),className:`absolute -inset-8 w-24 h-24 cursor-pointer opacity-0`}),(0,l.jsx)(`div`,{className:`absolute inset-0 pointer-events-none transition-transform group-hover/item:scale-110`,style:{backgroundColor:i}})]}),(0,l.jsx)(Gt,{disabled:F,value:i,isNumber:typeof i==`number`,placeholder:R?`https://...`:void 0,className:`no-glow bg-transparent font-extrabold outline-none focus:outline-none focus:ring-0 p-0 m-0 transition-colors leading-none ${R?`text-accent/80 font-medium placeholder:text-accent/30`:`text-foreground`} ${F?`opacity-50 grayscale pointer-events-none`:``}`,onFocus:j,handleBlurOrEnter:e=>{let t=e.currentTarget.value;R&&t&&t!==`none`&&!t.includes(`http`)&&!t.includes(`www.`)&&!t.startsWith(`/`)&&(t=``,o(``),ee(!0),setTimeout(()=>ee(!1),2500)),O.current!==null&&O.current!==t&&E(!0),O.current=null,M(e)},onChange:e=>o(e)}),(0,l.jsx)(`span`,{className:`text-foreground/40 shrink-0`,children:`"`}),D?(0,l.jsx)(`span`,{className:`text-red-500 font-bold ml-1.5 text-[10px] tracking-widest uppercase`,children:`invalid`}):T&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40 ml-1.5 shrink-0`}),(e===`logoUrl`||e===`faviconUrl`)&&(0,l.jsx)(`button`,{onClick:()=>o(e===`logoUrl`?t.t.logoUrl:t.t.faviconUrl),className:`w-4 h-4 ml-2 bg-red-500/10 hover:bg-red-500/20 text-red-500 rounded flex items-center justify-center transition-colors text-[10px] font-bold`,title:`Reset to default icon`,children:`✕`})]}),!c&&(0,l.jsx)(`span`,{className:`text-foreground/50 shrink-0`,children:`,`}),e&&[`inputRadius`,`modalRadius`,`badgeRadius`,`buttonRadius`,`cardRadius`].includes(e)&&(0,l.jsxs)(`span`,{className:`text-foreground/30 text-[10px] font-medium ml-2 tracking-wide whitespace-nowrap hidden md:inline-block pointer-events-none`,children:[`// `,e===`inputRadius`?`Forms & text fields`:e===`modalRadius`?`Popups & dialogs`:e===`badgeRadius`?`Tags & pills`:e===`buttonRadius`?`Interactive buttons`:`Big panels & cards`]})]}))};function qt(){let{activeConfig:e}=n.xt(),t=n.Ct(),[r,i]=(0,a.useState)(null),[s,c]=(0,a.useState)(!1),[u,d]=(0,a.useState)(!1),f=a.default.useRef(null);(0,a.useEffect)(()=>{if(!r&&e){let t=JSON.parse(JSON.stringify(e));i(t),f.current=JSON.stringify(t)}},[e]);let[p,m]=(0,a.useState)(!1),[h,g]=(0,a.useState)(!1);(0,a.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,a.useEffect)(()=>{if(!r)return;let e=JSON.stringify(r);if(e===f.current)return;let t=setTimeout(async()=>{c(!0);try{await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,`theme`),r),f.current=e}catch(e){console.error(`Auto-save failed`,e)}c(!1)},300);return()=>clearTimeout(t)},[r]);let _=async()=>{d(!0);try{let e=t?.themeConfig;e||=(await Promise.resolve().then(()=>require(`./theme.config-0Lvwt5Bo.cjs`)).then(e=>e.n)).themeConfig;let r=JSON.parse(JSON.stringify(e)),{deleteDoc:a}=await import(`firebase/firestore`);await a((0,o.doc)(n.Tt,`sys_configs`,`theme`)),localStorage.removeItem(`theme_config_cache`),f.current=JSON.stringify(r),i(r)}catch{}setTimeout(()=>{d(!1),g(!1)},1e3)},v=e=>{if(!e)return`167, 139, 250`;let t=0,n=0,r=0;return e.length===4?(t=parseInt(e[1]+e[1],16),n=parseInt(e[2]+e[2],16),r=parseInt(e[3]+e[3],16)):e.length===7&&(t=parseInt(e.substring(1,3),16),n=parseInt(e.substring(3,5),16),r=parseInt(e.substring(5,7),16)),`${t}, ${n}, ${r}`},y=e=>{if(!r)return;let t=JSON.parse(JSON.stringify(r));if(t.colors&&t.colors.dark){let n=v(e.dark.accent);t.colors.dark.accent=e.dark.accent,t.colors.dark.buttonGradient=e.dark.gradient,t.colors.dark.buttonHoverGradient=e.dark.gradient,t.colors.dark.buttonText=e.dark.buttonText,t.colors.dark.notificationIconColor=e.dark.accent,t.colors.dark.textGradient=e.dark.text,t.colors.dark.foreground=e.dark.text[0],t.colors.dark.background=e.dark.background,t.colors.dark.backgroundSecondary=e.dark.backgroundSecondary,t.colors.dark.panelBg=`rgba(${n}, 0.05)`,t.colors.dark.panelBorder=`rgba(${n}, 0.15)`,t.colors.dark.glowColor=`rgba(${n}, 0.40)`,t.colors.dark.selectionBg=`rgba(${n}, 0.40)`,t.colors.dark.secondaryButton&&(t.colors.dark.secondaryButton.text=e.dark.text[0])}if(t.colors&&t.colors.light){let n=v(e.light.accent);t.colors.light.accent=e.light.accent,t.colors.light.buttonGradient=e.light.gradient,t.colors.light.buttonHoverGradient=e.light.gradient,t.colors.light.buttonText=e.light.buttonText,t.colors.light.notificationIconColor=e.light.accent,t.colors.light.textGradient=e.light.text,t.colors.light.foreground=e.light.text[0],t.colors.light.background=e.light.background,t.colors.light.backgroundSecondary=e.light.backgroundSecondary,t.colors.light.panelBg=`rgba(255, 255, 255, 0.70)`,t.colors.light.panelBorder=`rgba(${n}, 0.08)`,t.colors.light.glowColor=`rgba(${n}, 0.30)`,t.colors.light.selectionBg=`rgba(${n}, 0.30)`,t.colors.light.secondaryButton&&(t.colors.light.secondaryButton.text=e.light.text[0])}i(t)},b=()=>{if(r){let e=r,t=e.colors?.dark||{},n=e.colors?.light||{};e.fontCustomization;let i=e.cornerRadii||{},a=`/**
|
|
227
|
+
`}),(0,l.jsxs)(`div`,{className:`relative group/date flex flex-col w-full`,children:[(0,l.jsx)(n.r,{type:`date`,label:`Date`,required:!0,value:L.dateStr,onChange:e=>R({...L,dateStr:e.target.value}),className:`pr-10`}),(0,l.jsx)(`div`,{className:`absolute right-4 bottom-4 pointer-events-none group-focus-within/date:text-accent text-foreground/40 transition-colors`,children:(0,l.jsx)(n.dt,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[J?(0,l.jsx)(n.r,{type:`time`,label:`Time`,value:L.time,onChange:e=>R({...L,time:e.target.value}),required:!0}):(()=>{let{h:e,m:t,ampm:n}=me(L.time);return(0,l.jsxs)(`div`,{className:`flex flex-col w-full`,children:[(0,l.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Time`}),(0,l.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,l.jsx)(`input`,{type:`number`,min:1,max:12,value:e,onChange:e=>R({...L,time:he(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,l.jsx)(`span`,{className:`text-foreground/40 font-bold text-[15px] select-none`,children:`:`}),(0,l.jsx)(`input`,{type:`number`,min:0,max:59,value:t.toString().padStart(2,`0`),onChange:t=>R({...L,time:he(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,l.jsx)(`button`,{type:`button`,onClick:()=>R({...L,time:he(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,l.jsx)(n.r,{type:`number`,min:`1`,max:`1440`,label:`Duration (min)`,value:L.duration,onChange:e=>R({...L,duration:e.target.value}),placeholder:`60`,required:!0})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,l.jsx)(`label`,{className:`text-[11px] font-bold text-foreground/50 uppercase tracking-widest mt-1`,children:`Event Color`}),(0,l.jsx)(`div`,{className:`flex gap-2 items-center relative z-10 w-full h-[46px]`,children:It.map(e=>(0,l.jsx)(`button`,{type:`button`,onClick:()=>R({...L,color:L.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:L.color===e.text&&(0,l.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full bg-background`})},e.name))})]}),(0,l.jsx)(`div`,{className:`pt-2`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:ne,className:`w-full py-3`,children:L.id?`Save Changes`:`Create Event`})})]})]})]},`edit-modal`),(0,l.jsx)(te,{isOpen:!!F,title:`Confirm Deletion`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:F?.title}),` This action is permanent.`]}),onConfirm:Oe,onCancel:()=>{I(null)},isProcessing:N,confirmText:`Yes, Delete`})]});return f?(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:d?.tabTitle||d?.tabName||e}),t&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),t]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[Ne(),Fe()]})]}),Ie()]}):(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e}),t&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),t]})]}),(0,l.jsxs)(`div`,{className:`flex justify-between items-center mb-6 border-b border-[var(--panel-border)] pb-6 relative z-20`,children:[r?(0,l.jsxs)(u.Link,{to:r,className:`px-5 py-2 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold hover:bg-foreground/5 transition-all flex items-center gap-2`,children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` Go Back`]}):(0,l.jsx)(`div`,{}),(0,l.jsxs)(`div`,{className:`flex gap-2`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:ce,className:`px-3 h-10 text-[12px] font-bold rounded-xl flex items-center justify-center border-[var(--panel-border)] border shrink-0 hover:bg-foreground/5 shadow-sm text-foreground/70`,children:J?`24h`:`12h`}),(0,l.jsx)(n.n,{variant:`secondary`,onClick:le,className:`w-10 h-10 p-0 text-[14px] font-bold rounded-xl flex items-center justify-center border-[var(--panel-border)] border shrink-0`,children:S===`month`?(0,l.jsx)(n.F,{className:`w-4 h-4 text-foreground/70`}):(0,l.jsx)(n.dt,{className:`w-4 h-4 text-foreground/70`})}),$&&(0,l.jsxs)(n.n,{onClick:()=>Te(),className:`px-6 py-2.5 text-[14px] font-bold rounded-xl shadow-lg flex items-center gap-2`,children:[(0,l.jsx)(n.C,{className:`w-4 h-4`}),` Event`]})]})]}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative flex flex-col flex-1`,children:[(0,l.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`}),Fe()]}),Ie()]})}var zt={appName:`The main name of your application shown in headers and titles.`,defaultTheme:`Choose how the app starts immediately on load.`,showThemeToggle:`Allow users to manually toggle dark mode on/off.`,logoUrl:`Direct URL to your app's main logo. Need to upload one?`,faviconUrl:`Direct URL to your app's favicon. Need to upload one?`,background:`Main background canvas color under all content.`,foreground:`Primary typography color used across the app.`,accent:`The primary brand color for highlights, buttons, and links.`,panelBg:`Background color of glass cards and panels.`,panelBorder:`Borders of panels, inputs, and dropdowns.`,glowColor:`The global glow shadow applied to borders of focused inputs.`,buttonHoverGradient:`Start and end hex for primary button hover effects.`,textGradient:`Three tone gradient applied to large headers.`,buttonRadius:`Border radius for standard buttons.`,cardRadius:`Curvature of main content panels.`,inputRadius:`Rounding applied to form inputs.`,modalRadius:`Global popup containers and dashboard content cards.`,blurIntensity:`Glassmorphism backdrop-blur amounts.`,notificationIconColor:`Color applied to notification badging.`,fontFamily:`Choose the main typography of your brand.`,home:`Complete customization of the landing page settings.`,title:`Main heading displayed on the Landing Page or Form.`,subtitle:`Smaller colored overline text above the main title.`,text:`The descriptive paragraph text under the hero headers or buttons.`,primary:`Main call-to-action block settings.`,secondary:`Secondary ghost button block settings.`,sections:`Toggle visibility of landing page sectors.`,contactForm:`Customize the form wrapper and its labels.`,nameLabel:`Placeholder/Label for the Name input.`,emailLabel:`Placeholder/Label for the Email input.`,messageLabel:`Placeholder/Label for the Message textarea.`,submitText:`Text for the form submit button.`,action:`Where the button routes the user.`,form:`Which public form to open. Note: Form submissions will securely map to the Submissions tab in your admin dashboard.`,url:`External http link or internal /route destination.`},Bt=[{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`]}}],Vt={defaultTheme:[`system`,`light`,`dark`],cornerRounding:[`default`,`custom`],action:[`sign_in`,`register`,`redirect`,`form`],type:[`text`,`email`,`tel`,`textarea`],form:[`contact`],formType:[`public`,`private`],submitPage:[`submissions`,`requests`],fontFamily:[`Inter`,`Outfit`,`Roboto`,`Space Grotesk`,`Plus Jakarta Sans`,`System UI`]};n.Tt&&(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{let t=[];e.forEach(e=>{e.data().formType!==`private`&&t.push(e.id)}),t.length>0&&Object.assign(Vt,{form:t})}).catch(()=>{});var Ht=({value:e,onChange:t,onBlur:n,onFocus:r,className:i,isNumber:o,handleBlurOrEnter:s,placeholder:c,disabled:u})=>{let[d,f]=a.default.useState(e),[p,m]=a.default.useState(!1),h=a.default.useRef(null);a.default.useEffect(()=>{f(e)},[e]),(0,a.useEffect)(()=>{!p&&h.current&&(h.current.scrollLeft=0)},[d,p]);let g=typeof i==`string`?i.match(/(?:max-w-\[[^\]]+\]|sm:max-w-\[[^\]]+\]|md:max-w-\[[^\]]+\])\s*/g):null,_=g?g.join(` `):`max-w-[200px] sm:max-w-[300px]`,v=typeof i==`string`?i.replace(/(?:max-w-\[[^\]]+\]|sm:max-w-\[[^\]]+\]|md:max-w-\[[^\]]+\]|text-ellipsis)\s*/g,``):``,y=v.trim();return(0,l.jsx)(`div`,{className:`relative inline-grid group/autoresize ${_}`,children:(0,l.jsxs)(`div`,{className:`col-start-1 row-start-1 overflow-x-auto overflow-y-hidden pb-[1px] styled-scrollbars-mini inline-grid items-center`,children:[(0,l.jsx)(`span`,{className:`${v} invisible whitespace-pre col-start-1 row-start-1 border-none p-0 inline-block px-[2px]`,"aria-hidden":`true`,children:d||c||(o?`0`:` `)}),(0,l.jsx)(`input`,{disabled:u,ref:h,type:o?`number`:`text`,value:d,placeholder:c,spellCheck:!1,className:`${y} col-start-1 row-start-1 w-full min-w-[20px] transition-all duration-200 ${u?`cursor-not-allowed opacity-50 select-none`:``} ${p?`relative z-50 bg-background shadow-md`:``}`,onDoubleClick:e=>{u||e.currentTarget.select()},onPaste:()=>{setTimeout(()=>{h.current&&(h.current.scrollLeft=0)},10)},onChange:e=>{u||f(e.target.value)},onKeyDown:n=>{if(!u&&n.key===`Enter`){let r=o?parseFloat(n.currentTarget.value)||0:n.currentTarget.value;r!==e&&t(r),s&&s(n),n.currentTarget.blur()}},onBlur:r=>{if(u)return;m(!1);let i=o?parseFloat(r.currentTarget.value)||0:r.currentTarget.value;i!==e&&t(i),s&&s(r),n&&n(r),r.currentTarget.scrollLeft=0},onFocus:e=>{u||(m(!0),r&&r(e))}})]})})},Ut=({objectKey:e,displayKey:r,value:i,onChange:o,depth:s=0,isLast:c=!1,keysToRender:d,isGlobalSaving:f,customExplanations:p,customEnums:m,disabledKeys:h=[],hideInnerLoader:g=!1,meta:_={}})=>{let v=r||e,y=typeof i==`object`&&!!i&&!Array.isArray(i),b=Array.isArray(i),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(e===`colors`||e===`fields`),[T,E]=(0,a.useState)(!1),[D,ee]=(0,a.useState)(!1),O=a.default.useRef(null),[k,A]=a.default.useState(null),te=a.default.useRef(null);(0,a.useEffect)(()=>{f||E(!1)},[f]);let j=e=>{O.current=e.currentTarget.value},ne=e=>{`key`in e&&e.key===`Enter`&&e.currentTarget.blur(),(`type`in e&&e.type===`blur`||`key`in e&&e.key===`Enter`)&&(O.current!==null&&O.current!==e.currentTarget.value&&(g||E(!0)),O.current=null)};a.default.useEffect(()=>{A(null)},[i]);let M=p?.[e]||zt[e],N=m?.[e]||Vt[e],P=Array.isArray(h)&&h.includes(e),F=t=>(0,l.jsxs)(`div`,{className:`flex flex-col text-[14px] font-mono leading-relaxed my-0.5`,style:{marginLeft:s>0?32:0},children:[M&&(0,l.jsxs)(`span`,{className:`text-foreground/40 text-[12px] font-mono italic select-none mt-2 mb-0.5 flex flex-wrap items-center gap-1`,children:[`// `,M.split(/(https?:\/\/[^\s,]+)/g).map((e,t)=>e.startsWith(`http`)?(0,l.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`text-accent hover:text-accentDeep underline underline-offset-2 cursor-pointer transition-colors pointer-events-auto`,children:e},t):(0,l.jsx)(`span`,{children:e},t)),(e===`logoUrl`||e===`faviconUrl`)&&(0,l.jsx)(u.Link,{to:`/drive/public`,className:`text-accent flex items-center gap-1 hover:text-accentDeep underline underline-offset-2 ml-1 cursor-pointer transition-colors`,children:`Open Drive / Public`})]}),t]});if(y){let t=d?[...d]:Object.keys(i);return t=t.filter(e=>!(e===`showThemeToggle`&&i.defaultTheme!==`system`||e===`cornerRadii`&&i.cornerRounding!==`custom`||e===`url`&&`action`in i&&i.action!==`redirect`||e===`form`&&`action`in i&&i.action!==`form`||e===`currencySymbol`&&i.type!==`currency`||e===`options`&&i.type!==`select`)),i.action===`redirect`&&!t.includes(`url`)&&i.showButton!==!1&&t.push(`url`),i.action===`form`&&!t.includes(`form`)&&i.showButton!==!1&&t.push(`form`),i.type===`currency`&&!t.includes(`currencySymbol`)&&t.push(`currencySymbol`),i.type===`select`&&!t.includes(`options`)&&t.push(`options`),F((0,l.jsxs)(`div`,{className:`flex flex-col group/obj`,children:[e?(0,l.jsxs)(`div`,{className:`flex items-center gap-1 hover:bg-foreground/[0.04] rounded-lg pl-0.5 pr-2 py-0.5 -ml-[18px] w-fit transition-colors ${C?`cursor-pointer`:``}`,onClick:()=>C&&w(!1),children:[(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),w(!C)},className:`text-foreground/30 hover:text-foreground/80 transition-colors w-4 flex items-center justify-center font-black text-[10px]`,title:C?`Unfold`:`Fold`,children:C?`►`:`▼`}),(0,l.jsxs)(`span`,{className:`text-accent font-extrabold`,children:[`"`,v,`"`]}),(0,l.jsx)(`span`,{className:`text-foreground/50`,children:`:`}),` `,(0,l.jsx)(`span`,{className:`text-foreground/70 font-bold`,children:C?`{...}`:`{`})]}):s>0?(0,l.jsx)(`div`,{className:`text-foreground/70 font-bold px-2`,children:`{`}):null,!C&&(0,l.jsx)(`div`,{className:`flex flex-col ${s>0?`border-l border-[var(--panel-border)]/30 ml-2 pl-1`:``}`,children:t.map((e,t,n)=>e===`subtitle`&&i.showSubtitle===!1||e===`url`&&`action`in i&&i.action!==`redirect`||e===`form`&&`action`in i&&i.action!==`form`?null:(0,l.jsx)(Ut,{objectKey:e,value:i[e],onChange:t=>{let n={...i,[e]:t};e===`action`&&t===`form`&&!n.form&&(n.form=`contact`),e===`action`&&t===`redirect`&&!n.url&&(n.url=`/`),e===`type`&&t===`currency`&&!n.currencySymbol&&(n.currencySymbol=`$`),e===`type`&&t===`select`&&!n.options&&(n.options=[`Option 1`,`Option 2`]),o(n)},depth:s+1,isLast:t===n.length-1,isGlobalSaving:f,customExplanations:p,customEnums:m,disabledKeys:h,hideInnerLoader:g,meta:_},e))}),e&&!C&&(0,l.jsxs)(`div`,{className:`px-2 mt-1`,children:[(0,l.jsx)(`span`,{className:`text-foreground/70 font-bold`,children:`}`}),!c&&(0,l.jsx)(`span`,{className:`text-foreground/50`,children:`,`})]}),e&&C&&!c&&(0,l.jsx)(`span`,{className:`text-foreground/50 -mt-1 ml-2`,children:`,`})]}))}if(b)return F((0,l.jsxs)(`div`,{className:`flex flex-col group/arr`,children:[e?(0,l.jsxs)(`div`,{className:`flex items-center gap-1 hover:bg-foreground/[0.04] rounded-lg pl-0.5 pr-2 py-0.5 -ml-[18px] w-fit transition-colors ${C?`cursor-pointer`:``}`,onClick:()=>C&&w(!1),children:[(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),w(!C)},className:`text-foreground/30 hover:text-foreground/80 transition-colors w-4 flex items-center justify-center font-black text-[10px]`,title:C?`Unfold`:`Fold`,children:C?`►`:`▼`}),(0,l.jsxs)(`span`,{className:`text-accent font-extrabold`,children:[`"`,v,`"`]}),(0,l.jsx)(`span`,{className:`text-foreground/50`,children:`:`}),` `,(0,l.jsx)(`span`,{className:`text-foreground/70 font-bold`,children:C?`[...]`:`[`})]}):(0,l.jsx)(`div`,{className:`flex items-center gap-1 group-hover/arr:bg-foreground/[0.02] rounded-lg px-2 py-0.5 -ml-2 w-fit transition-colors`,children:(0,l.jsx)(`span`,{className:`text-foreground/70 font-bold`,children:`[`})}),!C&&(0,l.jsxs)(`div`,{className:`flex flex-col border-l border-[var(--panel-border)]/30 ml-2 mt-1 pl-1`,style:{marginLeft:32},children:[i.map((e,t)=>{if(typeof e==`object`&&e)return(0,l.jsxs)(`div`,{className:`pl-2 border-l border-[var(--panel-border)]/20 mt-1 mb-1 relative group/arr-item`,children:[(0,l.jsx)(`button`,{onClick:()=>{let e=[...i];e.splice(t,1),o(e)},className:`absolute -left-[11px] top-1.5 w-5 h-5 bg-background border border-[var(--panel-border)] text-red-500 hover:bg-red-500/10 rounded flex items-center justify-center opacity-0 group-hover/arr-item:opacity-100 transition-all font-bold text-[14px] leading-none z-20`,title:`Remove Item`,children:`×`}),(0,l.jsx)(Ut,{value:e,onChange:e=>{let n=[...i];n[t]=e,o(n)},depth:s+1,isLast:t===i.length-1,isGlobalSaving:f,customExplanations:p,customEnums:m,disabledKeys:h})]},t);let r=typeof e==`string`&&(e.startsWith(`#`)||e.startsWith(`rgba`)||e.startsWith(`rgb`));return(0,l.jsxs)(`div`,{className:`flex items-center gap-1 group/item w-fit relative z-10 my-0.5`,children:[(0,l.jsx)(`button`,{onClick:()=>{let e=[...i];e.splice(t,1),o(e)},className:`absolute -left-6 top-1/2 -translate-y-1/2 w-4 h-4 text-red-500 hover:bg-red-500/10 rounded flex items-center justify-center opacity-0 group-hover/item:opacity-100 transition-all font-bold text-[14px] leading-none`,title:`Remove Item`,children:`×`}),(0,l.jsxs)(`span`,{className:`text-foreground/40 text-[11px] w-4 select-none font-bold`,children:[t,`:`]}),(0,l.jsx)(`span`,{className:`text-foreground/40 shrink-0`,children:`"`}),r&&(0,l.jsxs)(`div`,{className:`relative w-5 h-5 rounded-full overflow-hidden border border-[var(--panel-border)] shrink-0 mx-1 group/item hover:border-accent transition-colors bg-[var(--background)]`,children:[(0,l.jsx)(`input`,{type:`color`,value:e.length===7&&e.startsWith(`#`)?e:`#000000`,onChange:e=>{let n=[...i];n[t]=e.target.value,o(n)},className:`absolute -inset-8 w-24 h-24 cursor-pointer opacity-0`}),(0,l.jsx)(`div`,{className:`absolute inset-0 pointer-events-none transition-transform group-hover/item:scale-110`,style:{backgroundColor:e}})]}),(0,l.jsx)(Ht,{value:e,isNumber:typeof e==`number`,onChange:e=>{let n=[...i];n[t]=e,o(n)},onFocus:j,handleBlurOrEnter:ne,className:`no-glow bg-transparent text-foreground font-bold outline-none focus:outline-none focus:ring-0 p-0 m-0 transition-colors max-w-[200px] sm:max-w-[300px] text-ellipsis placeholder:text-foreground/20`}),(0,l.jsx)(`span`,{className:`text-foreground/40 shrink-0`,children:`"`}),(0,l.jsx)(`span`,{className:`text-foreground/50 shrink-0`,children:t<i.length-1?`,`:``}),T&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40 shrink-0`})]},t)}),(!(i.length>0&&typeof i[0]==`string`&&(i[0].startsWith(`#`)||i[0].startsWith(`rgba`)||i[0].startsWith(`color-mix`)))||i.length<6)&&(0,l.jsx)(`button`,{onClick:()=>{let t=[...i],n=``;if(e===`fields`){let e=t.map(e=>e.name);n=_?.formType===`private`?e.includes(`issue_type`)?e.includes(`urgency`)?e.includes(`description`)?e.includes(`device`)?e.includes(`subscribe`)?{type:`text`,name:`custom_field_${t.length}`,label:`Custom Field`,required:!1,placeholder:``}:{type:`checkbox`,name:`subscribe`,label:`Receive status updates via email`,required:!1}:{type:`text`,name:`device`,label:`Device / OS`,required:!1,placeholder:`e.g., iPhone 15, Windows 11`}:{type:`textarea`,name:`description`,label:`Description`,required:!0,placeholder:`Please provide detailed information...`}:{type:`select`,name:`urgency`,label:`Urgency Level`,required:!0,options:[`Low`,`Medium`,`High`,`Critical`]}:{type:`select`,name:`issue_type`,label:`Issue Type`,required:!0,options:[`Bug Report`,`Feature Request`,`Billing`,`General Question`]}:e.includes(`name`)?e.includes(`email`)?e.includes(`phone`)?e.includes(`questions`)?e.includes(`budget`)?e.includes(`service_type`)?e.includes(`subscribe`)?e.includes(`age`)?{type:`text`,name:`custom_field_${t.length}`,label:`Custom Field`,required:!1,placeholder:``}:{type:`age`,name:`age`,label:`Age`,required:!1,placeholder:`e.g. 25`}:{type:`checkbox`,name:`subscribe`,label:`Subscribe to newsletter`,required:!1}:{type:`select`,name:`service_type`,label:`Service Interested In`,required:!1,options:[`Consulting`,`Development`,`Design`]}:{type:`currency`,name:`budget`,label:`Budget`,required:!1,placeholder:`e.g. 5000`,currencySymbol:`$`}:{type:`textarea`,name:`questions`,label:`Questions`,required:!1,placeholder:`How can we help you?`}:{type:`tel`,name:`phone`,label:`Phone Number`,required:!1,placeholder:`+1 (555) 000-0000`}:{type:`email`,name:`email`,label:`Email Address`,required:!0,placeholder:`you@example.com`}:{type:`text`,name:`name`,label:`Full Name`,required:!0,placeholder:`Enter your name`}}else if(typeof t[0]==`string`)if(t[0].startsWith(`#`)||t[0].startsWith(`rgba`)||t[0].startsWith(`rgb`)||t[0].startsWith(`color-mix`))n=t[t.length-1];else{let e=[`Marketing`,`Support`,`Analysis`,`Strategy`,`Maintenance`];n=e[Math.min(t.length,e.length)-1]||`Option ${t.length+1}`}else n=t.length>0?JSON.parse(JSON.stringify(t[t.length-1])):``,n&&typeof n==`object`&&(n.name&&=`${n.name}_${t.length}`,n.label&&=`${n.label} ${t.length}`);t.push(n),o(t)},className:`mt-2 mb-1 w-fit flex items-center gap-1.5 px-3 py-1 bg-accent/10 hover:bg-accent/20 text-accent font-extrabold text-[11px] uppercase tracking-wider rounded-md transition-colors border border-accent/20`,children:`+ Add Item`})]}),e&&!C&&(0,l.jsxs)(`div`,{className:`px-2 mt-1`,children:[(0,l.jsx)(`span`,{className:`text-foreground/70 font-bold`,children:`]`}),!c&&(0,l.jsx)(`span`,{className:`text-foreground/50`,children:`,`})]}),!e&&(0,l.jsxs)(`div`,{className:`px-2 mt-1`,children:[(0,l.jsx)(`span`,{className:`text-foreground/70 font-bold`,children:`]`}),!c&&(0,l.jsx)(`span`,{className:`text-foreground/50`,children:`,`})]}),e&&C&&!c&&(0,l.jsx)(`span`,{className:`text-foreground/50 -mt-1 ml-2`,children:`,`})]}));if(typeof i==`boolean`)return F((0,l.jsxs)(`div`,{className:`flex items-center gap-1 group w-fit relative z-10 my-0.5`,children:[(0,l.jsxs)(`span`,{className:`text-accent font-extrabold shrink-0`,children:[`"`,v,`"`]}),(0,l.jsx)(`span`,{className:`text-foreground/50 shrink-0`,children:`:`}),(0,l.jsx)(`button`,{disabled:P||T,onClick:()=>{g||E(!0),o(!i)},className:`px-3 py-1 rounded-md text-[12px] font-extrabold transition-colors ml-1 uppercase tracking-wider ${i?`bg-emerald-500/20 text-emerald-500`:`bg-red-500/20 text-red-500`} ${P||T?`opacity-50 cursor-not-allowed`:`hover:scale-[1.02] active:scale-[0.98]`}`,children:i?`true`:`false`}),T&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40 ml-1`}),!c&&(0,l.jsx)(`span`,{className:`text-foreground/50`,children:`,`})]}));let I=typeof i==`string`&&(i.startsWith(`#`)||i.startsWith(`rgba`)||i.startsWith(`rgb`)),L=typeof i==`string`&&e&&String(e).endsWith(`Url`);return F((0,l.jsxs)(`div`,{className:`flex items-center gap-1 group relative z-10 my-0.5 ${L?`w-full pr-0 sm:pr-8`:`w-fit`}`,children:[(0,l.jsxs)(`span`,{className:`text-accent font-extrabold shrink-0`,children:[`"`,v,`"`]}),(0,l.jsx)(`span`,{className:`text-foreground/50 shrink-0`,children:`:`}),N?(0,l.jsxs)(`div`,{className:`flex items-center gap-1 ml-1 relative group/enum`,ref:te,children:[(0,l.jsx)(`span`,{className:`text-foreground/40`,children:`"`}),(0,l.jsx)(`button`,{disabled:P||T,title:P?`Cannot be edited`:`Click to cycle options`,tabIndex:0,onClick:()=>{if(P)return;let e=k===null?i:k,t=N[(N.indexOf(e)+1)%N.length];A(t),g||E(!0),o(t)},className:`${P||T?`bg-foreground/5 text-foreground/40 cursor-not-allowed opacity-50`:`bg-accent/10 hover:bg-accent/20 text-accent cursor-pointer shadow-sm hover:scale-[1.02] active:scale-[0.98]`} outline-none px-3 py-1 rounded-md transition-all font-extrabold uppercase tracking-wider text-[11px] border border-transparent`,children:k===null?i:k}),T&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40 ml-1`}),(0,l.jsx)(`span`,{className:`text-foreground/40`,children:`"`})]}):(0,l.jsxs)(`div`,{className:`flex items-center gap-0.5 ml-1 flex-1 min-w-0`,children:[(0,l.jsx)(`span`,{className:`text-foreground/40 shrink-0`,children:`"`}),I&&(0,l.jsxs)(`div`,{className:`relative w-5 h-5 rounded-full overflow-hidden border border-[var(--panel-border)] shrink-0 mx-1 group/item hover:border-accent transition-colors bg-[var(--background)]`,children:[(0,l.jsx)(`input`,{type:`color`,value:i.length===7&&i.startsWith(`#`)?i:`#000000`,onFocus:j,onBlur:e=>{o(e.target.value),O.current=null},onChange:e=>o(e.target.value),className:`absolute -inset-8 w-24 h-24 cursor-pointer opacity-0`}),(0,l.jsx)(`div`,{className:`absolute inset-0 pointer-events-none transition-transform group-hover/item:scale-110`,style:{backgroundColor:i}})]}),(0,l.jsx)(Ht,{disabled:P,value:i,isNumber:typeof i==`number`,placeholder:L?`https://...`:void 0,className:`no-glow bg-transparent font-extrabold outline-none focus:outline-none focus:ring-0 p-0 m-0 transition-colors leading-none ${L?`text-accent/80 font-medium placeholder:text-accent/30`:`text-foreground`} ${P?`opacity-50 grayscale pointer-events-none`:``}`,onFocus:j,handleBlurOrEnter:e=>{let t=e.currentTarget.value;L&&t&&t!==`none`&&!t.includes(`http`)&&!t.includes(`www.`)&&!t.startsWith(`/`)&&(t=``,o(``),ee(!0),setTimeout(()=>ee(!1),2500)),O.current!==null&&O.current!==t&&E(!0),O.current=null,ne(e)},onChange:e=>o(e)}),(0,l.jsx)(`span`,{className:`text-foreground/40 shrink-0`,children:`"`}),D?(0,l.jsx)(`span`,{className:`text-red-500 font-bold ml-1.5 text-[10px] tracking-widest uppercase`,children:`invalid`}):T&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40 ml-1.5 shrink-0`}),(e===`logoUrl`||e===`faviconUrl`)&&(0,l.jsx)(`button`,{onClick:()=>o(e===`logoUrl`?t.t.logoUrl:t.t.faviconUrl),className:`w-4 h-4 ml-2 bg-red-500/10 hover:bg-red-500/20 text-red-500 rounded flex items-center justify-center transition-colors text-[10px] font-bold`,title:`Reset to default icon`,children:`✕`})]}),!c&&(0,l.jsx)(`span`,{className:`text-foreground/50 shrink-0`,children:`,`}),e&&[`inputRadius`,`modalRadius`,`badgeRadius`,`buttonRadius`,`cardRadius`].includes(e)&&(0,l.jsxs)(`span`,{className:`text-foreground/30 text-[10px] font-medium ml-2 tracking-wide whitespace-nowrap hidden md:inline-block pointer-events-none`,children:[`// `,e===`inputRadius`?`Forms & text fields`:e===`modalRadius`?`Popups & dialogs`:e===`badgeRadius`?`Tags & pills`:e===`buttonRadius`?`Interactive buttons`:`Big panels & cards`]})]}))};function Wt(){let{activeConfig:e}=n.xt(),t=n.Ct(),[r,i]=(0,a.useState)(null),[s,c]=(0,a.useState)(!1),[u,d]=(0,a.useState)(!1),f=a.default.useRef(null);(0,a.useEffect)(()=>{if(!r&&e){let t=JSON.parse(JSON.stringify(e));i(t),f.current=JSON.stringify(t)}},[e]);let[p,m]=(0,a.useState)(!1),[h,g]=(0,a.useState)(!1);(0,a.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,a.useEffect)(()=>{if(!r)return;let e=JSON.stringify(r);if(e===f.current)return;let t=setTimeout(async()=>{c(!0);try{await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,`theme`),r),f.current=e}catch(e){console.error(`Auto-save failed`,e)}c(!1)},300);return()=>clearTimeout(t)},[r]);let _=async()=>{d(!0);try{let e=t?.themeConfig;e||=(await Promise.resolve().then(()=>require(`./theme.config-0Lvwt5Bo.cjs`)).then(e=>e.n)).themeConfig;let r=JSON.parse(JSON.stringify(e)),{deleteDoc:a}=await import(`firebase/firestore`);await a((0,o.doc)(n.Tt,`sys_configs`,`theme`)),localStorage.removeItem(`theme_config_cache`),f.current=JSON.stringify(r),i(r)}catch{}setTimeout(()=>{d(!1),g(!1)},1e3)},v=e=>{if(!e)return`167, 139, 250`;let t=0,n=0,r=0;return e.length===4?(t=parseInt(e[1]+e[1],16),n=parseInt(e[2]+e[2],16),r=parseInt(e[3]+e[3],16)):e.length===7&&(t=parseInt(e.substring(1,3),16),n=parseInt(e.substring(3,5),16),r=parseInt(e.substring(5,7),16)),`${t}, ${n}, ${r}`},y=e=>{if(!r)return;let t=JSON.parse(JSON.stringify(r));if(t.colors&&t.colors.dark){let n=v(e.dark.accent);t.colors.dark.accent=e.dark.accent,t.colors.dark.buttonGradient=e.dark.gradient,t.colors.dark.buttonHoverGradient=e.dark.gradient,t.colors.dark.buttonText=e.dark.buttonText,t.colors.dark.notificationIconColor=e.dark.accent,t.colors.dark.textGradient=e.dark.text,t.colors.dark.foreground=e.dark.text[0],t.colors.dark.background=e.dark.background,t.colors.dark.backgroundSecondary=e.dark.backgroundSecondary,t.colors.dark.panelBg=`rgba(${n}, 0.05)`,t.colors.dark.panelBorder=`rgba(${n}, 0.15)`,t.colors.dark.glowColor=`rgba(${n}, 0.40)`,t.colors.dark.selectionBg=`rgba(${n}, 0.40)`,t.colors.dark.secondaryButton&&(t.colors.dark.secondaryButton.text=e.dark.text[0])}if(t.colors&&t.colors.light){let n=v(e.light.accent);t.colors.light.accent=e.light.accent,t.colors.light.buttonGradient=e.light.gradient,t.colors.light.buttonHoverGradient=e.light.gradient,t.colors.light.buttonText=e.light.buttonText,t.colors.light.notificationIconColor=e.light.accent,t.colors.light.textGradient=e.light.text,t.colors.light.foreground=e.light.text[0],t.colors.light.background=e.light.background,t.colors.light.backgroundSecondary=e.light.backgroundSecondary,t.colors.light.panelBg=`rgba(255, 255, 255, 0.70)`,t.colors.light.panelBorder=`rgba(${n}, 0.08)`,t.colors.light.glowColor=`rgba(${n}, 0.30)`,t.colors.light.selectionBg=`rgba(${n}, 0.30)`,t.colors.light.secondaryButton&&(t.colors.light.secondaryButton.text=e.light.text[0])}i(t)},b=()=>{if(r){let e=r,t=e.colors?.dark||{},n=e.colors?.light||{};e.fontCustomization;let i=e.cornerRadii||{},a=`/**
|
|
324
228
|
* THEME & BRANDING CONFIGURATION
|
|
325
229
|
*
|
|
326
230
|
* This is the central hub for customizing your app's look.
|
|
@@ -412,7 +316,7 @@ export const themeConfig = {
|
|
|
412
316
|
cardRadius: ${i.cardRadius||1.5}, // 24px (2xl, 3xl)
|
|
413
317
|
modalRadius: ${i.modalRadius||2.5}, // Global popups and main internal boxes
|
|
414
318
|
}
|
|
415
|
-
};`;navigator.clipboard.writeText(a),m(!0),setTimeout(()=>m(!1),2e3)}};return(0,a.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key===`a`&&document.activeElement===document.body&&e.preventDefault(),(e.ctrlKey||e.metaKey)&&e.key===`c`&&!window.getSelection()?.toString()&&r&&b()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]),(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Theme`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/theme`]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-6 md:p-10 shadow-2xl relative overflow-hidden bg-background flex flex-col min-h-[600px]`,children:[(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Theme Config`}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`Changes here immediately format natively. Save to update your Live Preview panel entirely.`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:_,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-xl flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:u?(0,l.jsx)(n.M,{className:`w-4 h-4 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-4 h-4 text-foreground/60 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(n.n,{variant:`secondary`,onClick:b,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors`,title:`Copy Config (Ctrl+C)`,children:p?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-4 h-4 text-foreground/60 hover:text-foreground transition-colors`})})]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 w-full relative z-10 items-start`,children:[u&&(0,l.jsx)(`div`,{className:`absolute inset-0 bg-background/60 backdrop-blur-[2px] z-50 flex items-center justify-center rounded-3xl pointer-events-none transition-all duration-300`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 animate-spin text-accent`})}),(0,l.jsxs)(`div`,{className:`w-full glass-panel border border-[var(--panel-border)] rounded-3xl p-6 md:p-8 shadow-inner overflow-hidden relative bg-background`,children:[(0,l.jsx)(`h3`,{className:`text-lg font-extrabold text-foreground tracking-tight mb-4 flex items-center gap-3`,children:`Branding & Colours`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-3 overflow-x-auto hide-scrollbars pb-4 pt-2 mb-6 border-b border-[var(--panel-border)]/50 shrink-0`,children:[(0,l.jsx)(`div`,{className:`text-[12px] font-bold text-foreground/40 shrink-0 uppercase tracking-widest pl-1 mr-2`,children:`Presets`}),Ut.map(e=>{let t=r?.colors?.dark?.accent===e.dark.accent&&r?.colors?.dark?.buttonGradient?.[0]===e.dark.gradient[0],n=e.name===`Black & White`;return(0,l.jsx)(`button`,{onClick:()=>y(e),className:`w-9 h-9 rounded-full shrink-0 outline-none transition-all shadow-sm relative group overflow-visible ${t?`ring-[3px] ring-foreground ring-offset-2 ring-offset-[var(--background)] scale-110 z-10`:`opacity-80 hover:opacity-100 hover:ring-2 hover:ring-foreground/30 hover:ring-offset-2 hover:ring-offset-[var(--background)] hover:scale-105`}`,title:e.name,children:(0,l.jsx)(`div`,{className:`absolute inset-0 rounded-full`,style:n?{backgroundColor:`#ffffff`,border:`3px solid #000000`,boxShadow:`inset 0 0 0 1px rgba(0,0,0,0.1)`}:{backgroundImage:`linear-gradient(135deg, ${e.preview[0]}, ${e.preview[1]})`}})},e.name)})]}),(0,l.jsx)(`div`,{className:`w-full relative min-h-[100px]`,children:r?(0,l.jsxs)(`div`,{className:`flex flex-col pl-2`,children:[(0,l.jsxs)(`span`,{className:`text-yellow-500 font-mono text-[13px] mb-2`,children:[`export const themeConfig = `,`{`]}),(0,l.jsx)(Kt,{value:r,keysToRender:[`appName`,`defaultTheme`,`showThemeToggle`,`logoUrl`,`faviconUrl`,`cornerRounding`,`cornerRadii`,`fontFamily`],onChange:e=>i(e),isLast:!1,isGlobalSaving:s}),(0,l.jsx)(`div`,{className:`mt-4`,children:(0,l.jsx)(Kt,{objectKey:`colors`,value:r.colors,onChange:e=>i({...r,colors:e}),isLast:!1,isGlobalSaving:s})})]}):(0,l.jsx)(`div`,{className:`flex items-center justify-center w-full h-full text-foreground/40 font-mono text-[13px] animate-pulse py-10`,children:`Loading Data Tree...`})})]})]})]})]})]})}var Jt={route:`/page_1`,pageName:`New Public Page`,template:`none`,pageTitle:`My Custom Page`,copyPrompt:!0,showButton:!0,buttonText:`Open Form`,action:`form`,form:`contact`},Yt={tabName:`New Private Page`,iconName:``,route:`/new-private-page`,template:`none`,form:`support`,showPrompt:!0,tabTitle:`Private Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},Xt={tabName:`Admin Tab`,iconName:``,route:`/admin-tab`,template:`none`,form:``,showPrompt:!0,tabTitle:`Admin Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},Zt={tabName:`Shared Tab`,iconName:``,route:`/shared-tab`,template:`none`,form:``,showPrompt:!0,tabTitle:`Shared Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},Qt=[{id:`home`,title:`Home Page`,path:`/`,type:`public`,isSystem:!0,enabled:!0}],$t=({enabled:e,onChange:t,disabled:r,className:i=``})=>(0,l.jsx)(`button`,{disabled:r,onClick:()=>t(!e),title:e?`Page Active`:`Page Hidden`,className:`p-1.5 transition-colors rounded-lg flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity ${i} ${e?`text-accent hover:bg-accent/10`:`text-foreground/40 hover:bg-foreground/5`} ${r?`!opacity-50 cursor-not-allowed`:`cursor-pointer`}`,children:e?(0,l.jsx)(n.K,{className:`w-4 h-4`}):(0,l.jsx)(n.q,{className:`w-4 h-4`})});function en(){let{userRole:e}=m(),t=(0,u.useLocation)(),r=n.Ct(),[i,s]=(0,a.useState)(Qt),[c,d]=(0,a.useState)(()=>{try{return sessionStorage.getItem(`fbos_pages_expandedId`)||null}catch{return null}}),f=(0,a.useRef)(c),[p,h]=(0,a.useState)(!1),[g,_]=(0,a.useState)({}),[v,y]=(0,a.useState)({}),[b,x]=(0,a.useState)({}),[C,w]=(0,a.useState)(null),[T,E]=(0,a.useState)(!1),D=(0,a.useRef)(null);(0,a.useEffect)(()=>{function e(e){D.current&&!D.current.contains(e.target)&&h(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let[O,k]=(0,a.useState)(null),[A,j]=(0,a.useState)(!1),[M,N]=(0,a.useState)(!1),[P,F]=(0,a.useState)(new Set),[I,L]=(0,a.useState)(new Set),[R,z]=(0,a.useState)([]),[B,V]=(0,a.useState)([]),ne=e=>(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden});(0,a.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`page_order`),e=>{let t=ne(e.exists()&&e.data().order||[]);z(t),F(new Set(t.filter(e=>e.hidden).map(e=>e.id)))}),t=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`tab_order`),e=>{let t=ne(e.exists()&&e.data().order||[]);V(t),L(new Set(t.filter(e=>e.hidden).map(e=>e.id)))});return()=>{e(),t()}},[]),(0,a.useEffect)(()=>{let e=t.pathname.split(`/pages/`)[1]?.split(`/`)[0];e&&!c&&i.some(t=>t.id===e)&&d(e)},[t.pathname,i]),(0,a.useEffect)(()=>{f.current=c;try{c?sessionStorage.setItem(`fbos_pages_expandedId`,c):sessionStorage.removeItem(`fbos_pages_expandedId`)}catch{}},[c]);let H=(0,a.useRef)(null);(0,a.useEffect)(()=>{let e=H.current;if(!e)return;try{let t=sessionStorage.getItem(`fbos_pages_scrollY`);t&&(e.scrollTop=parseInt(t,10))}catch{}let t=()=>{try{sessionStorage.setItem(`fbos_pages_scrollY`,String(e.scrollTop))}catch{}};return e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[]),(0,a.useEffect)(()=>{let e=(e,t)=>{if(!t)return e;let n=Object.fromEntries(Object.entries(t).filter(([e,t])=>t!=null&&t!==``));return{...e,...n}},t=r?.defaultConfigs?.home||S,i=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_pages`,`home`),n=>{n.exists()?k(e(t,n.data())):k(t)});return()=>{i()}},[r]),(0,a.useEffect)(()=>{(async()=>{try{let[e,t]=await Promise.all([(0,o.getDocs)((0,o.collection)(n.Tt,`sys_pages`)),(0,o.getDocs)((0,o.collection)(n.Tt,`sys_tabs`))]),r=[`home`,`contact`,`support`,`theme`,`page_order`,`tab_order`],i=[],a={};e.forEach(e=>{if(!r.includes(e.id)){let t=e.data();i.push({id:e.id,title:t.pageName||t.title||e.id,path:t.route||`/`+e.id,type:`public`,isSystem:!1,enabled:t.enabled!==!1}),a[e.id]=t}}),t.forEach(e=>{if(!r.includes(e.id)){let t=e.data(),n=t.pageType||`private`;i.push({id:e.id,title:t.tabName||t.title||e.id,path:t.route||`/`+e.id,type:n,isSystem:!1,enabled:t.enabled!==!1}),a[e.id]=t}}),i.length>0&&(s(e=>{let t=e.filter(e=>e.isSystem||e.id.startsWith(`draft_`)),n=i.filter(e=>!t.some(t=>t.id===e.id));return[...t,...n]}),_(e=>({...e,...a})))}catch(e){console.error(`Error loading custom pages`,e)}})()},[]);let[U,W]=(0,a.useState)([`contact`]),[G,K]=(0,a.useState)([`support`]);(0,a.useEffect)(()=>{(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{let t=[],n=[];e.forEach(e=>{e.data().formType===`private`?n.push(e.id):t.push(e.id)}),t.length>0&&W(t),n.length>0&&K(n)}).catch(console.error)},[]);let[re,ie]=(0,a.useState)(null),q=(e,t)=>{let n;n=e===`home`?`export const defaultHomeConfig = ${JSON.stringify(t,null,2)};\n`:JSON.stringify(t,null,2),navigator.clipboard.writeText(n),ie(e),setTimeout(()=>ie(null),2e3)},J=async(e,t)=>{t.route&&!t.route.startsWith(`/`)&&(t.route=`/`+t.route);let r=i.find(t=>t.id===e)?.type,a=r===`public`?`sys_pages`:`sys_tabs`;r&&r!==`public`&&(t.pageType=r);let c=[`home`].includes(e)?e:t.route?t.route.replace(/^\/+/,``).replace(/[^a-zA-Z0-9_\-]/g,`_`).toLowerCase():e;e===`home`?j(!0):y(t=>({...t,[e]:!0,[c]:!0}));try{if(c!==e&&c.trim()!==``&&c!==`draft`){try{let{deleteDoc:t}=await import(`firebase/firestore`);await t((0,o.doc)(n.Tt,a,e))}catch{}await(0,o.setDoc)((0,o.doc)(n.Tt,a,c),t),s(n=>n.map(n=>n.id===e?{...n,id:c,_uiKey:n._uiKey||e,path:t.route,title:t.pageName||t.tabName||t.title||n.title}:n)),f.current===e&&(d(c),window.history.replaceState(null,``,`/pages/${c}`)),_(n=>{let r={...n};return r[c]=t,delete r[e],r});let i=r===`public`,l=i?`page_order`:`tab_order`,u=i?R:B;if(!u.some(e=>e.id===c)){let t=[{id:c,hidden:!1},...u.filter(t=>t.id!==e)];try{await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,l),{order:t})}catch(e){console.error(`Failed to update tab order:`,e)}}}else await(0,o.setDoc)((0,o.doc)(n.Tt,a,e),t),e===`home`?k(t):(_(n=>({...n,[e]:t})),s(n=>n.map(n=>n.id===e?{...n,path:t.route||n.path,title:t.pageName||t.tabName||t.title||n.title}:n)))}catch(t){console.error(`Failed to save ${e} config:`,t)}finally{setTimeout(()=>{e===`home`?j(!1):y(t=>({...t,[e]:!1,[c]:!1}))},500)}},Y=async e=>{e.stopPropagation(),N(!0);try{let{deleteDoc:e}=await import(`firebase/firestore`);await e((0,o.doc)(n.Tt,`sys_pages`,`home`)),localStorage.removeItem(`fbos_home_config`),k(r?.defaultConfigs?.home||S)}catch(e){console.error(`Failed to reset home config:`,e)}setTimeout(()=>N(!1),500)},ae=async(e,t,n)=>{e.stopPropagation(),x(e=>({...e,[t]:!0})),await J(t,n),setTimeout(()=>x(e=>({...e,[t]:!1})),500)},oe=e=>{let t=`draft_`+Math.floor(Math.random()*1e4);s([...i,{id:t,title:`New Tab`,path:`/draft`,type:e,isSystem:!1,enabled:!0}]);let n=i.filter(t=>t.type===e&&!t.id.startsWith(`draft_`)).length+1,r={};e===`public`?r={...Jt,route:`/page-${n}`}:e===`private`?r={...Yt,route:`/private-tab-${n}`}:e===`admin`?r={...Xt,route:`/admin-tab-${n}`}:e===`shared`&&(r={...Zt,route:`/shared-tab-${n}`}),_(e=>({...e,[t]:r})),d(t),h(!1),J(t,{...r,pageType:e===`public`?void 0:e}),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})},100)};if(e!==`admin`)return(0,l.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,l.jsx)(n.v,{className:`w-12 h-12 text-red-500 mb-4`}),(0,l.jsx)(`h2`,{className:`text-2xl font-bold`,children:`Access Denied`}),(0,l.jsx)(`p`,{className:`text-foreground/60`,children:`You do not have permission to view pages configuration.`})]})});let se=async(e,t,r)=>{let a=r===`public`,c=a?`page_order`:`tab_order`,l=a?R:B,u=(a?P:I).has(e);s(i.map(t=>t.id===e?{...t,enabled:u}:t));let d=[...l],f=d.findIndex(t=>t.id===e);f===-1?d.push({id:e,hidden:!0}):d[f]={...d[f],hidden:!u},await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,c),{order:d})},ce=(e,t)=>{t||w(e)},le=async()=>{if(C){E(!0);try{let{deleteDoc:e,collection:t,getDocs:r,doc:a,getDoc:o,query:l,where:u}=await import(`firebase/firestore`),{ref:f,deleteObject:p}=await import(`firebase/storage`),m=i.find(e=>e.id===C),h=m?.type===`public`?`sys_pages`:`sys_tabs`;if(h===`sys_tabs`&&m){let i=g[C];if(!i)try{let e=await o(a(n.Tt,`sys_tabs`,C));e.exists()&&(i=e.data())}catch{}let s=(i?.tabName||i?.pageId||C).toLowerCase().replace(/[^a-z0-9]+/g,`_`),c=[`admin_${s}_records`,`mem_${s}_records`,`user_${s}_records`],d={[`admin_${s}_records`]:{prefix:`admin_files`,driveCollection:`admin_files`},[`mem_${s}_records`]:{prefix:`mem_files`,driveCollection:`mem_files`},[`user_${s}_records`]:{prefix:`user_files`,driveCollection:`user_files`}},m=[];for(let i of c)m.push((async()=>{try{let a=await r(t(n.Tt,i)),o=d[i],s=[];for(let i of a.docs){let a=i.data();a.recordType===`file`&&a.downloadURL&&o&&s.push((async()=>{try{let i=`${o.prefix}%2F`,s=a.downloadURL.split(i)[1]?.split(`?`)[0];s&&await p(f(n.Dt,`${o.prefix}/${decodeURIComponent(s)}`)).catch(()=>{});let c=await r(l(t(n.Tt,o.driveCollection),u(`downloadURL`,`==`,a.downloadURL)));await Promise.all(c.docs.map(t=>e(t.ref)))}catch(e){console.error(`Error deleting storage file:`,e)}})())}await Promise.all(s),await Promise.all(a.docs.map(t=>e(t.ref)));try{localStorage.removeItem(`fbos_records_${i}`)}catch{}}catch(e){console.error(`Error cleaning up collection ${i}:`,e)}})());for(let i of[`admin_files`,`mem_files`,`user_files`])m.push((async()=>{try{let a=await r(l(t(n.Tt,i),u(`sourceTab`,`==`,s)));await Promise.all(a.docs.map(async t=>{let r=t.data();if(r.downloadURL)try{let e=`${i}%2F`,t=r.downloadURL.split(e)[1]?.split(`?`)[0];t&&await p(f(n.Dt,`${i}/${decodeURIComponent(t)}`)).catch(()=>{})}catch{}await e(t.ref)}))}catch{}})());await Promise.all(m)}await e(a(n.Tt,h,C));let _=h===`sys_pages`?`page_order`:`tab_order`,v=h===`sys_pages`?R:B,{setDoc:y}=await import(`firebase/firestore`),b=v.filter(e=>e.id!==C);await y(a(n.Tt,`sys_configs`,_),{order:b}),s(e=>e.filter(e=>e.id!==C)),c===C&&d(null)}catch(e){console.error(`Error deleting page:`,e)}E(!1),w(null)}},ue=e=>{let t=e.id+`_`+Math.floor(Math.random()*1e3),n={...e,id:t,title:`${e.title} (Copy)`,path:`${e.path}_copy`,isSystem:!1,enabled:!0};s(e=>[...e,n]);let r=g[e.id];!r&&e.id===`home`&&(r=O);let i={...r||{},route:n.path,pageName:n.title};n.type!==`public`&&(i.tabName=n.title,i.pageType=n.type),_(e=>({...e,[t]:i})),d(t),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})},100)},de=[{id:`public`,title:`Public Pages`,icon:n.U,color:`bg-amber-500`,description:`Creates external menu items. Invisible to signed-in dashboard users.`,filter:e=>e.type===`public`},{id:`private`,title:`Private Pages`,icon:n.j,color:`bg-emerald-500`,description:`Internal dashboard tabs for regular users.`,filter:e=>e.type===`private`},{id:`shared`,title:`Shared Pages`,icon:n.K,color:`bg-blue-500`,description:`Dashboard tabs visible to all members, editors, and admins.`,filter:e=>e.type===`shared`},{id:`admin`,title:`Admin Pages`,icon:n.v,color:`bg-red-500`,description:`Internal dashboard tabs for admin users only.`,filter:e=>e.type===`admin`}],[fe,X]=(0,a.useState)(!1),[pe,me]=(0,a.useState)(!1);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Pages`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/pages`,c?`/${c}`:``]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(`div`,{className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-6 pt-6 md:px-10 md:pt-10`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Architecture`}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`Manage the structure of your application tabs and public pages.`})]}),(0,l.jsxs)(`div`,{className:`relative z-50 shrink-0 flex items-center gap-1`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>X(!0),className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,title:`Reset Defaults`,children:(0,l.jsx)(n.x,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>h(!p),className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,title:`Add New Page`,children:(0,l.jsx)(n.C,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,l.jsx)(n.a,{children:p&&(0,l.jsx)(n.i.div,{ref:D,initial:{opacity:0,y:10,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.95},className:`absolute top-full mt-2 right-0 w-48 glass-panel border border-[var(--panel-border)] rounded-2xl p-2 shadow-xl z-50 flex flex-col gap-1`,children:[`public`,`private`,`shared`,`admin`].map(e=>(0,l.jsxs)(`button`,{onClick:()=>{oe(e),h(!1)},className:`text-left px-3 py-2 text-[13px] font-bold uppercase tracking-wider text-foreground/70 hover:text-foreground hover:bg-foreground/5 rounded-lg transition-colors cursor-pointer`,children:[e,` Page`]},e))})})]})]})]}),(0,l.jsxs)(`div`,{ref:H,className:`px-6 md:px-10 pb-6 md:pb-10 flex flex-col pt-0 gap-10 overflow-y-auto mt-2 relative min-h-[400px]`,children:[(0,l.jsx)(n.a,{children:pe&&(0,l.jsx)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-[2px] rounded-3xl`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-6 glass-panel rounded-2xl shadow-xl`,children:[(0,l.jsx)(n.M,{className:`w-8 h-8 md:w-10 md:h-10 animate-spin text-accent mb-4`}),(0,l.jsx)(`span`,{className:`text-sm font-bold text-foreground`,children:`Synchronizing Architecture...`})]})})}),de.map((e,t)=>{let r=i.filter(e.filter),a=e.id===`public`?R:B,o=r.sort((e,t)=>{let n=a.findIndex(t=>t.id===e.id),r=a.findIndex(e=>e.id===t.id);return n===-1&&r===-1?0:n===-1?1:r===-1?-1:n-r}),s=e.icon,u=e=>e.type===`public`?P.has(e.id):I.has(e.id),f=o.filter(e=>!u(e)),p=o.filter(e=>u(e)),m=e=>{if(!e)return[];let t=[`route`,`pageName`,`template`];return e.template===`none`?(t.push(`pageTitle`,`copyPrompt`),t.push(`showButton`),e.showButton!==!1&&(t.push(`buttonText`,`action`),e.action===`form`?t.push(`form`):e.action===`redirect`&&t.push(`redirectUrl`))):(e.template===`popup_form`||e.template===`inline_form`)&&(t.push(`showButton`),e.showButton!==!1&&t.push(`form`)),t},h=e=>{if(!e)return[];let t=[`tabName`,`iconName`,`route`,`template`];return e.template===`popup_form`||e.template===`inline_form`?(t.push(`showButton`),e.showButton!==!1&&t.push(`form`)):e.template===`none`?(t.push(`showPrompt`,`tabTitle`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonStyle`,`buttonText`,`buttonAction`),t.push(`storage`),e.storage!==!1&&t.push(`buttonStorageIcon`,`buttonStorageText`,`buttonStorageStyle`,`buttonStorageAction`)):e.template===`calendar`?(t.push(`tabTitle`,`showPrompt`),t.push(`defaultView`,`defaultTimeFormat`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`showViewsButton`),e.showViewsButton!==!1&&t.push(`viewsButtonStyle`)):e.template===`table`?(t.push(`tabTitle`,`showPrompt`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`showExportButton`),e.showExportButton!==!1&&t.push(`exportButtonIcon`)):e.template===`board`&&(t.push(`tabTitle`,`showPrompt`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`keyName`,`valueName`)),t},_=(t,r,i)=>{let a=t.id===`home`,o=c===t.id,s=a||!t.isSystem;return(0,l.jsxs)(`div`,{id:`page-${t.id}`,onClick:e=>{if(s){let e=o?null:t.id;d(e),window.history.replaceState(null,``,e?`/pages/${e}`:`/pages`)}},className:`group flex flex-col py-4 px-5 glass-panel border transition-all rounded-2xl hover:shadow-sm ${s?`cursor-pointer hover:border-accent/40`:``} ${i?`opacity-40 grayscale bg-foreground/[0.01] border-[var(--panel-border)]/50`:`border-transparent hover:border-[var(--panel-border)]`}`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-center justify-between w-full gap-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-1 w-full flex-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground truncate`,children:t.title}),a&&A&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-accent ml-2`})]}),(0,l.jsxs)(`div`,{className:`text-[11px] font-medium font-mono px-2 py-0.5 rounded w-fit ml-6 border ${i?`text-foreground/50 border-foreground/10 bg-foreground/5`:`text-accent/70 bg-accent/5 border-accent/10`}`,children:[window.location.host,t.path]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-4 shrink-0`,children:[!t.isSystem||[`contact`,`support`,`templates`].includes(t.id)?(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ue(t)},className:`p-1.5 hover:bg-accent/10 text-foreground/40 hover:text-accent transition-colors rounded-lg flex items-center justify-center shrink-0`,title:`Duplicate Page`,children:(0,l.jsx)(n.Z,{className:`w-4 h-4`})}):(0,l.jsx)(`div`,{className:`w-[28px] shrink-0`}),(0,l.jsx)(`div`,{className:`flex items-center justify-end w-8 shrink-0`,children:t.id===`home`?(0,l.jsx)(`div`,{className:`w-[28px] shrink-0`}):(0,l.jsx)($t,{enabled:!u(t),onChange:()=>se(t.id,t.isSystem,t.type)})}),t.isSystem?(0,l.jsx)(`div`,{className:`w-[28px] shrink-0`}):(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ce(t.id,t.isSystem)},className:`p-1.5 hover:bg-red-500/10 text-foreground/30 hover:text-red-500 transition-colors rounded-lg flex items-center justify-center shrink-0`,title:`Delete Page`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),s?(0,l.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 shrink-0 ${o?`rotate-180`:``}`,children:(0,l.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,l.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}):(0,l.jsx)(`div`,{className:`w-[24px] shrink-0`})]})]}),(0,l.jsxs)(n.a,{children:[o&&a&&O&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50 pb-4`,onClick:e=>e.stopPropagation(),children:(0,l.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 py-6 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,l.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,l.jsx)(`button`,{onClick:Y,className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:M?(0,l.jsx)(n.M,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),q(`home`,O)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:re===`home`?(0,l.jsx)(n.nt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,l.jsx)(Kt,{value:O,keysToRender:[`hero`],onChange:e=>J(`home`,e),isLast:!0,isGlobalSaving:A,customEnums:{form:U},customExplanations:{form:`User can click to switch to any public form we have in the forms tab. Private forms are not an option here. Add a new form in forms with a link that actually works.`}})]})}),o&&!t.isSystem&&g[t.id]&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50 pb-4`,onClick:e=>e.stopPropagation(),children:(0,l.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 py-6 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,l.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,l.jsx)(`button`,{onClick:e=>ae(e,t.id,t.type===`admin`?Xt:t.type===`shared`?Zt:t.type===`public`?Jt:Yt),className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:b[t.id]?(0,l.jsx)(n.M,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),q(t.id,g[t.id])},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:re===t.id?(0,l.jsx)(n.nt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,l.jsx)(Kt,{value:g[t.id],keysToRender:t.type===`public`?m(g[t.id]):h(g[t.id]),onChange:e=>J(t.id,e),isLast:!0,isGlobalSaving:v[t.id],customEnums:{form:t.type===`public`?U:G,template:t.type===`public`?[`none`,`popup_form`,`inline_form`]:t.type===`admin`||t.type===`shared`?[`none`,`calendar`,`table`,`board`]:[`none`,`calendar`,`table`,`board`,`popup_form`,`inline_form`],action:[`save_Info`,`form`],defaultTimeFormat:[`12h`,`24h`],defaultView:[`calendar`,`board`],buttonStyle:[`primary`,`secondary`],buttonAction:[`save_info`],viewsButtonStyle:[`primary`,`secondary`],buttonStorageStyle:[`primary`,`secondary`],buttonStorageAction:[`upload_file`]},customExplanations:{tabName:`Defines the tab label in the dashboard navigation.`,iconName:`Visit https://lucide.dev/icons/, find an icon, and paste its exact name (e.g. 'book-open', 'server', 'cloud-upload').`,route:`The URL path for this tab (e.g. '/my-tab'). Must start with /.`,template:`Page layout type. 'none' gives you a freeform dashboard with add/upload buttons.`,form:`Which form to display. Only applies to popup_form or inline_form templates. Go to /forms to edit forms.`,tabTitle:`The heading that appears at the top of the page content area.`,showPrompt:`Shows the developer AI prompt copy button in the header.`,showButton:`Toggles the + add record button in the header.`,buttonStyle:`Visual style of the add button: 'primary' (accent) or 'secondary' (subtle).`,buttonText:`Label on the add button. Use '+' for a minimal icon-only button.`,buttonAction:`'save_info' saves a name + note record to the tab's Firestore collection.`,storage:`Enables the file upload button for this tab.`,buttonStorageIcon:`Icon name from https://lucide.dev/icons/ for the upload button (e.g. 'upload', 'cloud-upload').`,buttonStorageText:`Label next to the upload icon. Leave empty for icon-only.`,buttonStorageStyle:`'primary' or 'secondary' visual style for the upload button.`,buttonStorageAction:t.type===`admin`?`'upload_file' uploads to admin_files/ in Storage and mirrors metadata to admin_files collection (Drive > Admin).`:t.type===`shared`?`'upload_file' uploads to mem_files/ in Storage and mirrors metadata to mem_files collection (Drive > Shared).`:`'upload_file' uploads to user_files/ in Storage and mirrors metadata to user_files collection (Drive > Private).`,defaultView:`Starting view: 'calendar' (month grid) or 'board' (event list). Users can switch between them.`,defaultTimeFormat:`12h or 24h time format. Users can toggle this in the toolbar.`,showViewsButton:`Show the calendar/board view toggle button in the toolbar.`,viewsButtonStyle:`'primary' or 'secondary' visual style for the view toggle.`,showExportButton:`Show the CSV export/download button in the table toolbar.`,exportButtonIcon:`Icon name from https://lucide.dev/icons/ for the export button (e.g. 'download', 'import').`,keyName:`Label for the key/title field in board items (e.g. 'Task', 'Name').`,valueName:`Label for the value/description field in board items (e.g. 'Notes', 'Details').`},hideInnerLoader:!0})]})})]})]},`${e.id}-${t._uiKey||t.id}`)};return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex flex-col relative`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-3 mb-2 border-b border-[var(--panel-border)]/50 pb-4`,children:[(0,l.jsx)(`div`,{className:`w-8 h-8 rounded-xl glass-panel border border-[var(--panel-border)] flex items-center justify-center -ml-1 shadow-sm`,children:(0,l.jsx)(s,{className:`w-4 h-4 text-accent`})}),(0,l.jsx)(`h2`,{className:`text-xl font-extrabold tracking-tight text-foreground`,children:e.title})]}),(0,l.jsx)(`p`,{className:`text-[13px] leading-relaxed text-foreground/50 font-medium max-w-3xl mb-4 ml-[2px]`,children:e.description}),o.length===0?(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 opacity-40 glass-panel rounded-2xl border border-[var(--panel-border)]/50 border-dashed`,children:[(0,l.jsx)(n.L,{className:`w-5 h-5 mb-2`}),(0,l.jsx)(`p`,{className:`text-[12px] font-bold`,children:`This section is currently empty.`})]}):(0,l.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[f.map(e=>_(e,o.findIndex(t=>t.id===e.id),!1)),p.length>0&&(0,l.jsxs)(`details`,{className:`mt-4 group/details`,children:[(0,l.jsxs)(`summary`,{className:`text-[11px] font-bold uppercase tracking-wider text-foreground/40 cursor-pointer list-none flex items-center gap-2 select-none hover:text-foreground/70 transition-colors w-fit pb-1 ml-1 outline-none`,children:[(0,l.jsx)(n.st,{className:`w-3.5 h-3.5 group-open/details:-rotate-180 transition-transform`}),`Hidden pages (`,p.length,`)`]}),(0,l.jsx)(`div`,{className:`flex flex-col gap-4 mt-4`,children:p.map(e=>_(e,o.findIndex(t=>t.id===e.id),!0))})]})]}),t<de.length-1&&(0,l.jsx)(`div`,{className:`w-full border-t border-[var(--panel-border)]/70 my-10`})]},e.id)})]})]})]}),(0,l.jsx)(te,{isOpen:fe,onCancel:()=>X(!1),onConfirm:async()=>{me(!0);try{let{deleteDoc:e}=await import(`firebase/firestore`);await Promise.all([e((0,o.doc)(n.Tt,`sys_pages`,`home`))]),k(S)}catch(e){console.error(`Error resetting defaults:`,e)}setTimeout(()=>{me(!1),X(!1)},1e3)},title:`Reset System Pages`,message:`Are you sure you want to reset all system page configurations? Custom pages and their order will remain intact.`,confirmText:`Reset`,isProcessing:pe}),(0,l.jsx)(te,{isOpen:!!C,onCancel:()=>w(null),onConfirm:le,title:`Delete Page`,message:`Are you sure you want to delete this page? This action cannot be undone and will remove all associated configurations.`,confirmText:`Remove Page`,isProcessing:T})]})}var tn={contact:r.t,support:i.t};function nn(){let{userRole:e}=m(),t=(0,u.useNavigate)();(0,u.useLocation)();let[r,i]=(0,a.useState)({}),[s,c]=(0,a.useState)(!0),[d,f]=(0,a.useState)({}),p=n.Ct(),h=()=>({...tn,contact:p?.defaultConfigs?.contactForm||tn.contact,support:p?.defaultConfigs?.supportForm||tn.support}),[g,_]=(0,a.useState)(null),[v,y]=(0,a.useState)({}),[b,x]=(0,a.useState)(null),[S,C]=(0,a.useState)(!1),[w,T]=(0,a.useState)(null),E=(e,t)=>{let n;n=e===`contact`?`export const contactFormConfig = ${JSON.stringify(t,null,2)};\n`:e===`support`?`export const supportFormConfig = ${JSON.stringify(t,null,2)};\n`:JSON.stringify(t,null,2),navigator.clipboard.writeText(n),T(e),setTimeout(()=>T(null),2e3)};(0,a.useEffect)(()=>{D()},[]);let D=async()=>{try{let e=await(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)),t={};e.forEach(e=>{if(e.id!==`pubForm`&&e.id!==`userForm`){let n=e.data();n._uiKey||=Math.random().toString(36).substring(7),t[e.id]=n}});try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,`pubForm`)),await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,`userForm`))}catch{}let r=h();for(let[e,i]of Object.entries(r))if(!t[e]){await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),i);let r={...i};r._uiKey=Math.random().toString(36).substring(7),t[e]=r}else if(!t[e].fields||t[e].fields.length===0){let i=r[e];t[e].fields=i.fields||[],await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),t[e])}let a=window.location.pathname.split(`/forms/`)[1]?.split(`/`)[0];a&&t[a]&&y({[a]:!0}),i(t)}catch(e){console.error(`Failed to load forms:`,e)}finally{c(!1)}},O=async(e,t)=>{let a={...t};r[e]?._uiKey&&(a._uiKey=r[e]._uiKey),e===`contact`?(a.systemName=`contact`,a.formType=`public`,a.submitPage=`submissions`):e===`support`&&(a.systemName=`support`,a.formType=`private`,a.submitPage=`requests`);let s=a.systemName||e;if(s!==e&&s.trim()!==``){i(t=>{let n={};for(let r of Object.keys(t))r===e?n[s]=a:n[r]=t[r];return n}),v[e]&&y(t=>{let n={};for(let r of Object.keys(t))r===e?n[s]=t[r]:n[r]=t[r];return n}),f(e=>({...e,[s]:!0}));try{await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,s),a),await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,e))}catch(e){console.error(`Failed to migrate form map ID:`,e)}finally{setTimeout(()=>{f(e=>({...e,[s]:!1}))},500)}}else{i(t=>({...t,[e]:a})),f(t=>({...t,[e]:!0}));try{await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),a)}catch(e){console.error(`Failed to save form:`,e)}finally{setTimeout(()=>{f(t=>({...t,[e]:!1}))},500)}}},[k,A]=(0,a.useState)(!1),j=async()=>{if(k)return;A(!0);let e=`new_form_${Date.now().toString().slice(-4)}`,r={title:`New Custom Form`,systemName:e,formType:`public`,submitPage:`submissions`,redirectTo:``,submitText:`Submit`,fields:[],enabled:!0,_uiKey:Math.random().toString(36).substring(7)};try{f(t=>({...t,[e]:!0})),await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),r),i(t=>({[e]:r,...t})),y(t=>({[e]:!0,...t})),t(`/forms/${e}`)}catch(e){console.error(`Failed to create form`,e)}finally{f(t=>({...t,[e]:!1})),A(!1)}},M=async e=>{if(!(e===`contact`||e===`support`)){C(!0);try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,e)),i(t=>{let n={...t};return delete n[e],n}),t(`/forms`)}catch(e){console.error(`Failed to delete form`,e)}finally{C(!1),x(null)}}};if(e!==`admin`)return(0,l.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,l.jsx)(n.p,{className:`w-12 h-12 text-red-500 mb-4`}),(0,l.jsx)(`h2`,{className:`text-2xl font-bold bg-clip-text text-transparent bg-gradient-to-br from-red-400 to-red-600`,children:`Access Restricted`}),(0,l.jsx)(`p`,{className:`text-foreground/60 max-w-sm text-center mt-2 font-medium leading-relaxed`,children:`This area is exclusively for system administrators.`})]})});let N=e=>{y(t=>{let n={...t,[e]:!t[e]};if(n[e])window.history.replaceState(null,``,`/forms/${e}`);else{let e=Object.keys(n).filter(e=>n[e]);e.length>0?window.history.replaceState(null,``,`/forms/${e[0]}`):window.history.replaceState(null,``,`/forms`)}return n})},P=Object.keys(v).find(e=>v[e]);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Forms`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/forms`,P?`/${P}`:``]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(`div`,{className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-6 pt-6 md:px-10 md:pt-10 bg-background/50`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Custom Forms`}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`This is the central page where you configure and manage your application's forms. Easily add and customize the fields for your users.`})]}),(0,l.jsx)(`div`,{className:`relative z-50 shrink-0 flex items-center justify-end`,children:(0,l.jsx)(n.n,{variant:`secondary`,onClick:j,title:`Add Custom Form`,disabled:k,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,children:k?(0,l.jsx)(n.M,{className:`w-4 h-4 text-foreground/60 animate-spin`}):(0,l.jsx)(n.C,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})})})]}),(0,l.jsx)(`div`,{className:`p-6 md:p-8 flex flex-col gap-4 overflow-y-auto`,children:s?(0,l.jsx)(`div`,{className:`flex items-center justify-center p-12 glass-panel rounded-3xl border border-[var(--panel-border)]`,children:(0,l.jsx)(n.M,{className:`w-6 h-6 animate-spin text-accent`})}):Object.keys(r).length===0?(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-12 glass-panel rounded-3xl border border-[var(--panel-border)] border-dashed opacity-50`,children:[(0,l.jsx)(n.S,{className:`w-6 h-6 mb-3 text-foreground/40`}),(0,l.jsx)(`p`,{className:`text-[13px] font-bold`,children:`No forms currently configured.`})]}):(0,l.jsx)(n.a,{children:Object.entries(r).map(([e,t])=>{let r=v[e],i=d[e];return(0,l.jsxs)(n.i.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,y:-10},onClick:()=>N(e),className:`group flex flex-col p-3 px-4 glass-panel border transition-all rounded-2xl hover:shadow-sm cursor-pointer hover:border-accent/40 ${r?`border-[var(--panel-border)] bg-background/50`:`border-transparent hover:border-[var(--panel-border)]`} flex-shrink-0 ${t.enabled===!1?`opacity-40 grayscale bg-foreground/[0.01] border-[var(--panel-border)]/50`:``}`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between w-full`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col gap-1 w-full sm:w-auto pr-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground break-words ml-1 leading-snug`,children:t.title||`Untitled Form`}),i&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-accent ml-2 shrink-0`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5 ml-1`,children:[(0,l.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest border border-[var(--panel-border)] bg-foreground/5 text-foreground/60 px-2 py-0.5 rounded-md`,children:t.systemName||e}),(0,l.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest border px-2 py-0.5 rounded-md shrink-0 ${t.formType===`private`?`text-blue-500 bg-blue-500/10 border-blue-500/20`:`text-green-500 bg-green-500/10 border-green-500/20`}`,children:t.formType||`public`})]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-4 w-full sm:w-auto justify-end mt-2 sm:mt-0 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),_(t)},className:`p-1.5 hover:bg-accent/10 text-foreground/40 hover:text-accent transition-colors rounded-lg flex items-center justify-center mr-2`,title:`Preview Form`,children:(0,l.jsx)(n.K,{className:`w-4 h-4`})}),e!==`contact`&&e!==`support`?(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),x(e)},className:`p-1.5 hover:bg-red-500/10 text-foreground/30 hover:text-red-500 transition-colors rounded-lg opacity-0 group-hover:opacity-100 flex items-center justify-center mr-2`,title:`Delete Form`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}):(0,l.jsx)(`div`,{className:`w-7 mr-2 shrink-0`}),(0,l.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 ${r?`rotate-180`:``}`,children:(0,l.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,l.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})})]})]}),(0,l.jsx)(n.a,{children:r&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50`,onClick:e=>e.stopPropagation(),children:(0,l.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,l.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,l.jsx)(`button`,{onClick:async t=>{if(t.stopPropagation(),e===`contact`||e===`support`){f(t=>({...t,[e]:!0}));try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,e)),localStorage.removeItem(`fbos_form_${e}`),await D()}catch(e){console.error(`Reset failed:`,e)}setTimeout(()=>f(t=>({...t,[e]:!1})),500)}else O(e,h()[e]||h().contact)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:i?(0,l.jsx)(n.M,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(`button`,{onClick:n=>{n.stopPropagation(),E(e,t)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:w===e?(0,l.jsx)(n.nt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,l.jsx)(Kt,{value:{systemName:t.systemName||e,formType:t.formType||`public`,submitPage:t.submitPage||(t.formType===`private`?`requests`:`submissions`),redirectTo:t.redirectTo||``,title:t.title||``,buttonName:t.buttonName||t.submitText||``,fields:t.fields||[]},keysToRender:[`systemName`,`formType`,`submitPage`,`redirectTo`,`title`,`buttonName`,`fields`],meta:{formType:t.formType||`public`},onChange:n=>{n.formType===t.formType?n.submitPage!==t.submitPage&&(n.formType=n.submitPage===`requests`?`private`:`public`):n.submitPage=n.formType===`public`?`submissions`:`requests`,O(e,{...t,...n,submitText:n.buttonName})},isLast:!0,isGlobalSaving:i,disabledKeys:e===`contact`||e===`support`?[`systemName`,`formType`,`submitPage`]:[],customEnums:{type:[`text`,`email`,`tel`,`textarea`,`number`,`select`,`checkbox`,`currency`,`age`]},customExplanations:{formType:e===`contact`?`Public means its for not signed in users. Private is disabled for contact so don't allow the user to change it.`:e===`support`?`This means that the form is available to signed in users only.`:`Public means it's for non-signed in users.`,submitPage:e===`contact`?`Means the form submissions go to this folder. User can't change that since it's directly linked. Public is tied to submissions.`:e===`support`?`Can't change since all private forms go there.`:`Where to route data submissions.`,redirectTo:`If not added form will just show a success message. If added, in 30 seconds after success user is redirected.`}})]})})})]},t._uiKey||e)})})})]})]}),(0,l.jsx)(te,{isOpen:!!b,onCancel:()=>x(null),onConfirm:()=>{b&&M(b)},title:`Delete Form`,message:`Are you sure you want to permanently delete "${b}"? This action cannot be reversed.`,confirmText:`Delete form`,isProcessing:S}),g&&(0,l.jsx)(n.t,{formConfig:g,onClose:()=>_(null)})]})}function rn({config:e,customContent:t}){let{config:r}=n.xt(),[i,s]=(0,a.useState)(!1),[c,u]=(0,a.useState)(null),[d,f]=(0,a.useState)([]);(0,a.useEffect)(()=>{document.title=e.pageName||e.pageTitle||r.appName||`Firebase OS`,(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{f(e.docs.filter(e=>e.data().formType===`public`).map(e=>e.id))})},[e.pageName,e.pageTitle,r.appName]);let p=H(e,d);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 relative min-h-screen`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.pageTitle||e.pageName||`New Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]}),(0,l.jsxs)(`div`,{className:`flex justify-between items-center mb-6 pt-2 border-b border-[var(--panel-border)] pb-6 relative z-20 overflow-x-auto no-scrollbar gap-4`,children:[(0,l.jsxs)(`button`,{onClick:()=>window.history.back(),className:`px-5 py-2 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold hover:bg-foreground/5 transition-all flex items-center gap-2 cursor-pointer shadow-sm text-foreground/70 whitespace-nowrap shrink-0`,children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` Go Back`]}),(0,l.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[e.copyPrompt&&(0,l.jsxs)(`button`,{onClick:()=>{navigator.clipboard.writeText(p),s(!0),setTimeout(()=>s(!1),2e3)},title:`Copy Developer Prompt`,className:`px-6 py-2.5 rounded-xl border border-[var(--panel-border)] bg-background flex items-center gap-2 hover:bg-foreground/5 hover:text-accent transition-all cursor-pointer text-[14px] font-bold tracking-wide shadow-sm whitespace-nowrap`,children:[(0,l.jsx)(n.ft,{className:`w-4 h-4`}),(0,l.jsx)(`span`,{className:`hidden sm:inline`,children:i?`Copied!`:`Copy Prompt`})]}),e.showButton&&(0,l.jsx)(`button`,{onClick:()=>{e.action===`redirect`?window.location.href=e.url||`/`:e.action===`form`&&u(e.form||`contact`)},className:`px-6 py-2.5 rounded-xl font-bold tracking-wide transition-all duration-300 flex items-center justify-center btn-primary shadow-xl hover:-translate-y-1 active:scale-95 text-[14px] whitespace-nowrap`,children:e.buttonText||`Action Button`})]})]}),(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl shadow-2xl relative flex flex-col flex-1 bg-background/50 h-full min-h-[400px]`,children:t?(0,l.jsx)(`div`,{className:`flex-1 p-4 md:p-8`,children:(0,l.jsx)(t,{config:e})}):(0,l.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center opacity-40 glass-panel border border-[var(--panel-border)]/50 border-dashed m-4 md:m-8 rounded-2xl p-8 py-20 text-center`,children:[(0,l.jsx)(n.ft,{className:`w-8 h-8 md:w-12 md:h-12 mb-4 text-foreground/80 opacity-50`}),(0,l.jsx)(`p`,{className:`text-[14px] font-bold mb-2`,children:`Click copy prompt at the top to start adding changes`}),(0,l.jsx)(`div`,{className:`mt-8 text-left bg-background p-6 rounded-2xl text-[12px] font-mono whitespace-pre-wrap max-w-2xl border border-[var(--panel-border)]/50 text-foreground/60 shadow-inner`,children:p})]})}),(0,l.jsx)(n.a,{children:c&&(0,l.jsx)(n.t,{onClose:()=>u(null),formId:c})})]})}function an({config:e,customContent:t}){let{user:r}=m(),{config:i}=n.xt(),[s,u]=(0,a.useState)([]),[f,p]=(0,a.useState)(!0),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(``),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(!1),[T,E]=(0,a.useState)(!1),[D,O]=(0,a.useState)(null),[k,A]=(0,a.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;P(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[N,P]=(0,a.useState)(!0),[F,I]=(0,a.useState)(!1),[L,R]=(0,a.useState)(null),[z,B]=(0,a.useState)(``),[V,ne]=(0,a.useState)(``),[H,U]=(0,a.useState)([]),W=(0,a.useRef)(null),G=(e.tabName||e.pageId||`private_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),K=`user_${G}_records`;(0,a.useEffect)(()=>{document.title=e.tabTitle||e.tabName||i.appName||`Firebase OS`,(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{})},[e.tabTitle,e.tabName,i.appName]),(0,a.useEffect)(()=>{if(!r)return;try{let e=localStorage.getItem(`fbos_records_${K}`);e?(u(JSON.parse(e)),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}});(async()=>{try{let t=e((await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,K),(0,o.where)(`uid`,`==`,r.uid),(0,o.limit)(150)))).docs);t.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),u(t),p(!1),localStorage.setItem(`fbos_records_${K}`,JSON.stringify(t))}catch(e){console.error(`Error fetching records:`,e),p(!1)}})()},[r,K]),(0,a.useEffect)(()=>{f||localStorage.setItem(`fbos_records_${K}`,JSON.stringify(s))},[s,f,K]);let re=async e=>{if(e.preventDefault(),!(!r||!_.trim())){S(!0);try{let e=await(0,o.addDoc)((0,o.collection)(n.Tt,K),{name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,createdAt:(0,o.serverTimestamp)()});u(t=>[{id:e.id,name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,createdAt:Date.now()},...t]),v(``),b(``),g(!1)}catch(e){console.error(`Error saving record:`,e)}S(!1)}},ie=async e=>{let t=e.target.files?.[0];if(!(!t||!r)){E(!0);try{let e=(0,c.ref)(n.Dt,`user_files/${`${Date.now()}_${t.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,c.uploadBytes)(e,t,{customMetadata:{ownerId:r.uid}});let i=await(0,c.getDownloadURL)(e);await(0,o.addDoc)((0,o.collection)(n.Tt,`user_files`),{fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,uid:r.uid,uploaderEmail:r.email||`user`,sourceTab:G,accessPrefix:`user_`,createdAt:(0,o.serverTimestamp)()});let a=await(0,o.addDoc)((0,o.collection)(n.Tt,K),{name:t.name,note:`${t.type||`File`} · ${ve(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,createdAt:(0,o.serverTimestamp)()});u(e=>[{id:a.id,name:t.name,note:`${t.type||`File`} · ${ve(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type,fileSize:t.size,downloadURL:i,createdAt:Date.now()},...e])}catch(e){console.error(`Error uploading file:`,e)}E(!1),W.current&&(W.current.value=``)}},q=async()=>{if(D){I(!0);try{let e=s.find(e=>e.id===D);if(await(0,o.deleteDoc)((0,o.doc)(n.Tt,K,D)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`user_files%2F`)[1]?.split(`?`)[0];t&&await(0,c.deleteObject)((0,c.ref)(n.Dt,`user_files/${decodeURIComponent(t)}`)).catch(()=>{});let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`user_files`),(0,o.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of r.docs)await(0,o.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up user file:`,e)}u(e=>e.filter(e=>e.id!==D)),O(null)}catch(e){console.error(`Error deleting record:`,e)}I(!1)}},[J,Y]=(0,a.useState)(null),[ae,oe]=(0,a.useState)(``),[se,ce]=(0,a.useState)(!1),[le,de]=(0,a.useState)(null),fe=(0,a.useRef)([]),X=e=>{if(e.recordType===`file`){Y(e.id),oe(e.name);return}R(e.id),B(e.name),ne(e.note||``);let t=[`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`],n=Object.entries(e).filter(([e])=>!t.includes(e)&&e!==`id`).map(([e,t])=>({key:e,value:String(t??``)}));U(n),fe.current=n.map(e=>e.key)},pe=async()=>{if(!J||!ae.trim()){Y(null);return}let e=s.find(e=>e.id===J);if(e&&e.name===ae.trim()){Y(null);return}ce(!0);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,K,J),{name:ae.trim()}),u(e=>e.map(e=>e.id===J?{...e,name:ae.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}ce(!1),Y(null)},me=async()=>{await Z(),R(null)},Z=async()=>{if(!L||!z.trim())return;S(!0);let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=fe.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,K,L),{name:z.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==L)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),fe.current=t}catch(e){console.error(`Error saving record:`,e)}S(!1)},he=(e,t)=>e?e.startsWith(`image/`)?t?(0,l.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${t})`}}):(0,l.jsx)(n.V,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,l.jsx)(n.l,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,l.jsx)(n.G,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,l.jsx)(n._t,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,l.jsx)(n.Q,{className:`w-4 h-4`}):(0,l.jsx)(n.W,{className:`w-4 h-4`}):(0,l.jsx)(n.G,{className:`w-4 h-4`}),ge=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-purple-500/10 text-purple-500`:e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?`bg-blue-500/10 text-blue-500`:e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?`bg-yellow-500/10 text-yellow-500`:e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?`bg-emerald-500/10 text-emerald-500`:`bg-foreground/5 text-foreground/40`:`bg-foreground/5 text-foreground/40`,_e=e=>{if(!e)return`FILE`;let t={"application/pdf":`PDF`,"application/zip":`ZIP`,"application/x-zip-compressed":`ZIP`,"application/x-rar-compressed":`RAR`,"application/x-7z-compressed":`7Z`,"application/json":`JSON`,"application/xml":`XML`,"application/javascript":`JS`,"application/typescript":`TS`,"application/msword":`DOC`,"application/vnd.openxmlformats-officedocument.wordprocessingml.document":`DOCX`,"application/vnd.ms-excel":`XLS`,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":`XLSX`,"application/vnd.ms-powerpoint":`PPT`,"application/vnd.openxmlformats-officedocument.presentationml.presentation":`PPTX`,"application/rtf":`RTF`,"application/x-tar":`TAR`,"application/gzip":`GZ`,"text/plain":`TXT`,"text/html":`HTML`,"text/css":`CSS`,"text/csv":`CSV`,"text/markdown":`MD`},n=e.toLowerCase();if(t[n])return t[n];let r=n.split(`/`);return r[r.length-1].replace(/^x-/,``).replace(/^vnd\..*\./,``).toUpperCase().slice(0,10)},ve=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},Q=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},ye=ue(e,K),be=()=>{navigator.clipboard.writeText(ye),w(!0),setTimeout(()=>w(!1),2e3)},xe=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),r=t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return n.o[r]?n.o[r]:n.o[t]?n.o[t]:n.f||n.C})(),Se=e.buttonStyle!==`secondary`,Ce=e.buttonStorageStyle===`primary`;return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Private Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${s.length} ${s.length===1?`item`:`items`}`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:be,title:C?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${C?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:C?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),e.storage!==!1&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`input`,{type:`file`,ref:W,onChange:ie,className:`hidden`}),(0,l.jsxs)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${Ce?`btn-primary`:`btn-secondary`}`,children:[T?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(xe,{className:`w-4 h-4`}),e.buttonStorageText&&(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>g(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${Se?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,l.jsx)(n.C,{className:`w-4 h-4`}):(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),t?(0,l.jsx)(t,{config:e,actions:{records:s,loading:f,collection:K,user:r,saveRecord:async e=>{await(0,o.addDoc)((0,o.collection)(n.Tt,K),{uid:r.uid,recordType:`record`,createdAt:(0,o.serverTimestamp)(),...e})},deleteRecord:async e=>{await(0,o.deleteDoc)((0,o.doc)(n.Tt,K,e))},uploadFile:()=>W.current?.click(),openAddForm:()=>g(!0)}}):(0,l.jsxs)(l.Fragment,{children:[!f&&s.length===0&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,l.jsx)(n.C,{className:`w-6 h-6 text-accent/40`})}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files to get started`})]}),!f&&s.length>0&&(0,l.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,l.jsx)(n.a,{children:s.map((e,t)=>{let r=L===e.id;return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},transition:{delay:t*.03,duration:.25},onClick:()=>X(e),className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative cursor-pointer ${r?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,l.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),de(e.id),setTimeout(()=>de(null),2e3)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-emerald-500 hover:bg-emerald-500/10 transition-all cursor-pointer`,title:`Copy Link`,children:le===e.id?(0,l.jsx)(n.ct,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-3.5 h-3.5`})})]}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),X(e)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,l.jsx)(n.w,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),O(e.id)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-3.5 h-3.5`})})]}),(0,l.jsxs)(`div`,{className:`flex items-start gap-3 mb-3`,children:[(0,l.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&j(e)},className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`cursor-pointer hover:scale-105 transition-transform ${ge(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?he(e.fileType,e.downloadURL):(0,l.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[J===e.id?(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,value:ae,onChange:e=>oe(e.target.value),onBlur:()=>pe(),onKeyDown:e=>{e.key===`Enter`&&pe(),e.key===`Escape`&&Y(null)},onClick:e=>e.stopPropagation(),className:`no-glow text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full pr-12`}):(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>j(e)}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:Q(e.createdAt)})]})]}),e.note&&(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),Object.entries(e).filter(([e])=>![`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`].includes(e)&&e!==`id`).slice(0,3).map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,l.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e))]},e.id)})})})]})]}),!t&&(0,l.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,l.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,l.jsx)(n.B,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,l.jsxs)(`span`,{children:[`Each user sees their own data only · Edit and delete available on all items · Records: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:K}),` · Files: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`user_files`}),` → Drive / Private`]})]})})]})]}),(0,l.jsx)(n.a,{children:h&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!x&&g(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`form`,{onSubmit:re,className:`p-5 flex flex-col gap-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>!x&&g(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:_,onChange:e=>v(e.target.value),placeholder:`Name *`,disabled:x,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),placeholder:`Note (optional)`,disabled:x,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:x,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:x?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,d.createPortal)((0,l.jsx)(n.a,{children:M&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,l.jsx)(n.i.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(`button`,{onClick:()=>j(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-[var(--panel-border)]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 bg-background/80 backdrop-blur-md border-b border-[var(--panel-border)] shrink-0 shadow-sm z-20`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:M.fileName||M.name}),(0,l.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[_e(M.fileType),` • `,ve(M.fileSize||0)]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.downloadURL),de(`preview`),setTimeout(()=>de(null),2e3)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 transition-colors rounded-xl shadow-sm hover:text-emerald-500 cursor-pointer`,title:`Copy Link`,children:le===`preview`?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),Y(M.id),oe(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),O(M.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),(0,l.jsx)(`a`,{href:M.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>j(null),children:(0,l.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[N&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-background/80 backdrop-blur-md shadow-xl flex items-center justify-center border border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,l.jsx)(`img`,{onLoad:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,alt:M.fileName||M.name,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full object-contain drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] rounded-lg pointer-events-auto transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType?.startsWith(`video/`)?(0,l.jsx)(`video`,{onLoadedData:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,controls:!0,autoPlay:!0,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full outline-none bg-black/40 rounded-lg pointer-events-auto drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType===`application/pdf`?(0,l.jsx)(`iframe`,{onLoad:()=>P(!1),src:M.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,l.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center text-foreground/40 text-center relative z-10`,onClick:e=>{e.stopPropagation(),P(!1)},children:[(0,l.jsx)(n.G,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,l.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,l.jsx)(`span`,{className:`text-[14px] mt-2 text-foreground/60 font-medium max-w-xs`,children:`This file format cannot be previewed. Please download it instead.`})]})]})})]})]})}),document.body),(0,l.jsx)(n.a,{children:L&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>me(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[440px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),x&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>me(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NAME`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>B(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>Z(),placeholder:`Name *`,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NOTE`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{ne(e.target.value),e.target.style.height=`auto`,e.target.style.height=e.target.scrollHeight+`px`},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),e.target.blur())},onBlur:()=>Z(),placeholder:`Add a note...`,rows:1,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50 resize-none overflow-hidden`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),H.map((e,t)=>(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let n=[...H];n[t].key=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>Z(),className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none placeholder:text-foreground/15 pt-3 pb-0.5 caret-foreground/40`}),(0,l.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let n=[...H];n[t].value=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>Z(),className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pt-1.5 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>U(H.filter((e,n)=>n!==t)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})})]},t)),(0,l.jsxs)(`button`,{type:`button`,onClick:()=>U([...H,{key:``,value:``}]),className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground/25 hover:text-foreground/40 transition-colors cursor-pointer mt-4 mb-4`,children:[(0,l.jsx)(n.C,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,l.jsx)(te,{isOpen:!!D,onCancel:()=>O(null),onConfirm:q,title:`Delete Record`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:s.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:F})]})}function on({config:e,customContent:t}){let{user:r}=m(),{config:i}=n.xt(),[s,u]=(0,a.useState)([]),[f,p]=(0,a.useState)(!0),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(``),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(!1),[T,E]=(0,a.useState)(!1),[D,O]=(0,a.useState)(null),[k,A]=(0,a.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;P(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[N,P]=(0,a.useState)(!0),[F,I]=(0,a.useState)(!1),[L,R]=(0,a.useState)(null),[z,B]=(0,a.useState)(``),[V,ne]=(0,a.useState)(``),[H,U]=(0,a.useState)([]),W=(0,a.useRef)(null),[G,K]=(0,a.useState)(null),re=(0,a.useRef)([]),ie=(e.tabName||e.pageId||`admin_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),q=`admin_${ie}_records`;(0,a.useEffect)(()=>{document.title=e.tabTitle||e.tabName||i.appName||`Firebase OS`},[e.tabTitle,e.tabName,i.appName]);let J=()=>({name:r.displayName||r.email?.split(`@`)[0]||`Admin`,email:r.email||``,avatar:r.photoURL||``});(0,a.useEffect)(()=>{if(!r)return;try{let e=localStorage.getItem(`fbos_records_${q}`);e?(u(JSON.parse(e)),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}}),t=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,q),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(150)),t=>{let n=e(t.docs);u(n),p(!1),localStorage.setItem(`fbos_records_${q}`,JSON.stringify(n))},t=>{console.error(`Error listening to admin records:`,t);let r=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,q),(0,o.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),u(n),p(!1),localStorage.setItem(`fbos_records_${q}`,JSON.stringify(n))});return()=>r()});return()=>t()},[r,q]);let Y=async e=>{if(e.preventDefault(),!(!r||!_.trim())){S(!0);try{let e=J();await(0,o.addDoc)((0,o.collection)(n.Tt,q),{name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()}),v(``),b(``),g(!1)}catch(e){console.error(`Error saving admin record:`,e)}S(!1)}},ae=async e=>{let t=e.target.files?.[0];if(!(!t||!r)){E(!0);try{let e=(0,c.ref)(n.Dt,`admin_files/${`${Date.now()}_${t.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,c.uploadBytes)(e,t,{customMetadata:{ownerId:r.uid}});let i=await(0,c.getDownloadURL)(e),a=J();await(0,o.addDoc)((0,o.collection)(n.Tt,`admin_files`),{fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,uid:r.uid,uploaderEmail:r.email||`admin`,sourceTab:ie,accessPrefix:`admin_`,creatorName:a.name,creatorEmail:a.email,creatorAvatar:a.avatar,createdAt:(0,o.serverTimestamp)()}),await(0,o.addDoc)((0,o.collection)(n.Tt,q),{name:t.name,note:`${t.type||`File`} · ${Q(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,creatorName:a.name,creatorEmail:a.email,creatorAvatar:a.avatar,createdAt:(0,o.serverTimestamp)()})}catch(e){console.error(`Error uploading admin file:`,e)}E(!1),W.current&&(W.current.value=``)}},oe=async()=>{if(D){I(!0);try{let e=s.find(e=>e.id===D);if(await(0,o.deleteDoc)((0,o.doc)(n.Tt,q,D)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`admin_files%2F`)[1]?.split(`?`)[0];t&&await(0,c.deleteObject)((0,c.ref)(n.Dt,`admin_files/${decodeURIComponent(t)}`)).catch(()=>{});let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`admin_files`),(0,o.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of r.docs)await(0,o.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up admin file:`,e)}O(null)}catch(e){console.error(`Error deleting admin record:`,e)}I(!1)}},[se,ce]=(0,a.useState)(null),[ue,de]=(0,a.useState)(``),[fe,X]=(0,a.useState)(!1),pe=e=>{if(e.recordType===`file`){ce(e.id),de(e.name);return}R(e.id),B(e.name),ne(e.note||``);let t=[`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`],n=Object.entries(e).filter(([e])=>!t.includes(e)&&e!==`id`).map(([e,t])=>({key:e,value:String(t??``)}));U(n),re.current=n.map(e=>e.key)},me=async()=>{if(!se||!ue.trim()){ce(null);return}let e=s.find(e=>e.id===se);if(e&&e.name===ue.trim()){ce(null);return}X(!0);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,se),{name:ue.trim()}),u(e=>e.map(e=>e.id===se?{...e,name:ue.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}X(!1),ce(null)},Z=async()=>{if(!L||!z.trim()){R(null);return}S(!0);let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=re.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,L),{name:z.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==L)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),re.current=t}catch(e){console.error(`Error updating record:`,e)}S(!1),R(null)},he=async()=>{if(!L||!z.trim())return;let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=re.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,L),{name:z.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==L)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),re.current=t}catch(e){console.error(`Error silently saving record:`,e)}},ge=(e,t)=>e?e.startsWith(`image/`)?t?(0,l.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${t})`}}):(0,l.jsx)(n.V,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,l.jsx)(n.l,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,l.jsx)(n.G,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,l.jsx)(n._t,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,l.jsx)(n.Q,{className:`w-4 h-4`}):(0,l.jsx)(n.W,{className:`w-4 h-4`}):(0,l.jsx)(n.G,{className:`w-4 h-4`}),_e=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-purple-500/10 text-purple-500`:e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?`bg-blue-500/10 text-blue-500`:e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?`bg-yellow-500/10 text-yellow-500`:e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?`bg-emerald-500/10 text-emerald-500`:`bg-foreground/5 text-foreground/40`:`bg-foreground/5 text-foreground/40`,ve=e=>{if(!e)return`FILE`;let t={"application/pdf":`PDF`,"application/zip":`ZIP`,"application/x-zip-compressed":`ZIP`,"application/x-rar-compressed":`RAR`,"application/x-7z-compressed":`7Z`,"application/json":`JSON`,"application/xml":`XML`,"application/javascript":`JS`,"application/typescript":`TS`,"application/msword":`DOC`,"application/vnd.openxmlformats-officedocument.wordprocessingml.document":`DOCX`,"application/vnd.ms-excel":`XLS`,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":`XLSX`,"application/vnd.ms-powerpoint":`PPT`,"application/vnd.openxmlformats-officedocument.presentationml.presentation":`PPTX`,"application/rtf":`RTF`,"application/x-tar":`TAR`,"application/gzip":`GZ`,"text/plain":`TXT`,"text/html":`HTML`,"text/css":`CSS`,"text/csv":`CSV`,"text/markdown":`MD`},n=e.toLowerCase();if(t[n])return t[n];let r=n.split(`/`);return r[r.length-1].replace(/^x-/,``).replace(/^vnd\..*\./,``).toUpperCase().slice(0,10)},Q=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},ye=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},be=le(e,q),xe=()=>{navigator.clipboard.writeText(be),w(!0),setTimeout(()=>w(!1),2e3)},Se=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),r=t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return n.o[r]?n.o[r]:n.o[t]?n.o[t]:n.f||n.C})(),Ce=e.buttonStyle!==`secondary`,we=e.buttonStorageStyle===`primary`,Te=e=>e.uid===r?.uid,Ee=({record:e})=>{let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||`Admin`,n=e.creatorEmail||``,r=e.creatorAvatar||``,i=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,l.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/15 text-accent flex items-center justify-center text-[8px] font-extrabold shrink-0`,children:i}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,l.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Admin Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${s.length} ${s.length===1?`item`:`items`}`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:xe,title:C?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${C?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:C?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),e.storage!==!1&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`input`,{type:`file`,ref:W,onChange:ae,className:`hidden`}),(0,l.jsxs)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${we?`btn-primary`:`btn-secondary`}`,children:[T?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(Se,{className:`w-4 h-4`}),e.buttonStorageText&&(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>g(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${Ce?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,l.jsx)(n.C,{className:`w-4 h-4`}):(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),t?(0,l.jsx)(t,{config:e,actions:{records:s,loading:f,collection:q,user:r,saveRecord:async e=>{let t=J();await(0,o.addDoc)((0,o.collection)(n.Tt,q),{uid:r.uid,recordType:`record`,creatorName:t.name,creatorEmail:t.email,creatorAvatar:t.avatar,createdAt:(0,o.serverTimestamp)(),...e})},deleteRecord:async e=>{await(0,o.deleteDoc)((0,o.doc)(n.Tt,q,e))},uploadFile:()=>W.current?.click(),openAddForm:()=>g(!0)}}):(0,l.jsxs)(l.Fragment,{children:[!f&&s.length===0&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,l.jsx)(n.C,{className:`w-6 h-6 text-accent/40`})}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All admins can view and contribute.`})]}),!f&&s.length>0&&(0,l.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,l.jsx)(n.a,{children:s.map((e,t)=>{let r=L===e.id,i=Te(e);return(0,l.jsxs)(n.i.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>pe(e),className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative cursor-pointer ${r?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,l.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),K(e.id),setTimeout(()=>K(null),2e3)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-emerald-500 hover:bg-emerald-500/10 transition-all cursor-pointer`,title:`Copy Link`,children:G===e.id?(0,l.jsx)(n.ct,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-3.5 h-3.5`})})]}),i&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),pe(e)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,l.jsx)(n.w,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),O(e.id)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-3.5 h-3.5`})})]})]}),(0,l.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,l.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&j(e)},className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`cursor-pointer hover:scale-105 transition-transform ${_e(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?ge(e.fileType,e.downloadURL):(0,l.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[se===e.id?(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,value:ue,onChange:e=>de(e.target.value),onBlur:()=>me(),onKeyDown:e=>{e.key===`Enter`&&me(),e.key===`Escape`&&ce(null)},onClick:e=>e.stopPropagation(),className:`no-glow text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full pr-12`}):(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>j(e)}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ye(e.createdAt)})]})]}),e.note&&(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),Object.entries(e).filter(([e])=>![`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`].includes(e)&&e!==`id`).slice(0,3).map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,l.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,l.jsx)(Ee,{record:e})]},e.id)})})})]})]}),!t&&(0,l.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,l.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,l.jsx)(n.B,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,l.jsxs)(`span`,{children:[`Shared between all admins · Edit and delete available on your own items only · Records: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:q}),` · Files: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`admin_files`}),` → Drive / Admin`]})]})})]})]}),(0,l.jsx)(n.a,{children:h&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!x&&g(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`form`,{onSubmit:Y,className:`p-5 flex flex-col gap-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>!x&&g(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:_,onChange:e=>v(e.target.value),placeholder:`Name *`,disabled:x,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),placeholder:`Note (optional)`,disabled:x,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:x,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:x?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,d.createPortal)((0,l.jsx)(n.a,{children:M&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,l.jsx)(n.i.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(`button`,{onClick:()=>j(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-[var(--panel-border)]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 bg-background/80 backdrop-blur-md border-b border-[var(--panel-border)] shrink-0 shadow-sm z-20`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:M.fileName||M.name}),(0,l.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[ve(M.fileType),` • `,Q(M.fileSize||0)]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.downloadURL),K(`preview`),setTimeout(()=>K(null),2e3)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 transition-colors rounded-xl shadow-sm hover:text-emerald-500 cursor-pointer`,title:`Copy Link`,children:G===`preview`?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),ce(M.id),de(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),O(M.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),(0,l.jsx)(`a`,{href:M.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>j(null),children:(0,l.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[N&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-background/80 backdrop-blur-md shadow-xl flex items-center justify-center border border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,l.jsx)(`img`,{onLoad:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,alt:M.fileName||M.name,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full object-contain drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] rounded-lg pointer-events-auto transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType?.startsWith(`video/`)?(0,l.jsx)(`video`,{onLoadedData:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,controls:!0,autoPlay:!0,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full outline-none bg-black/40 rounded-lg pointer-events-auto drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType===`application/pdf`?(0,l.jsx)(`iframe`,{onLoad:()=>P(!1),src:M.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,l.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center text-foreground/40 text-center relative z-10`,onClick:e=>{e.stopPropagation(),P(!1)},children:[(0,l.jsx)(n.G,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,l.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,l.jsx)(`span`,{className:`text-[14px] mt-2 text-foreground/60 font-medium max-w-xs`,children:`This file format cannot be previewed. Please download it instead.`})]})]})})]})]})}),document.body),(0,l.jsx)(n.a,{children:L&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>Z(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[440px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),x&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>Z(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NAME`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>B(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),placeholder:`Name *`,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NOTE`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{ne(e.target.value),e.target.style.height=`auto`,e.target.style.height=e.target.scrollHeight+`px`},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),e.target.blur())},onBlur:()=>he(),placeholder:`Add a note...`,rows:1,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50 resize-none overflow-hidden`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),H.map((e,t)=>(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let n=[...H];n[t].key=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none placeholder:text-foreground/15 pt-3 pb-0.5 caret-foreground/40`}),(0,l.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let n=[...H];n[t].value=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pt-1.5 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>U(H.filter((e,n)=>n!==t)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})})]},t)),(0,l.jsxs)(`button`,{type:`button`,onClick:()=>U([...H,{key:``,value:``}]),className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground/25 hover:text-foreground/40 transition-colors cursor-pointer mt-4 mb-4`,children:[(0,l.jsx)(n.C,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,l.jsx)(te,{isOpen:!!D,onCancel:()=>O(null),onConfirm:oe,title:`Delete Record`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:s.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:F})]})}function sn({config:e,customContent:t}){let{user:r}=m(),{config:i}=n.xt(),[s,u]=(0,a.useState)([]),[f,p]=(0,a.useState)(!0),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(``),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(!1),[T,E]=(0,a.useState)(!1),[D,O]=(0,a.useState)(null),[k,A]=(0,a.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;P(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[N,P]=(0,a.useState)(!0),[F,I]=(0,a.useState)(!1),[L,R]=(0,a.useState)(null),[z,B]=(0,a.useState)(``),[V,ne]=(0,a.useState)(``),[H,U]=(0,a.useState)([]),W=(0,a.useRef)(null),[G,K]=(0,a.useState)(null),re=(0,a.useRef)([]),ie=(e.tabName||e.pageId||`shared_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),q=`mem_${ie}_records`;(0,a.useEffect)(()=>{document.title=e.tabTitle||e.tabName||i.appName||`Firebase OS`},[e.tabTitle,e.tabName,i.appName]),(0,a.useEffect)(()=>{if(!r)return;try{let e=localStorage.getItem(`fbos_records_${q}`);e?(u(JSON.parse(e)),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}}),t=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,q),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(150)),t=>{let n=e(t.docs);u(n),p(!1),localStorage.setItem(`fbos_records_${q}`,JSON.stringify(n))},t=>{console.error(`Error listening to shared records:`,t);let r=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,q),(0,o.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),u(n),p(!1),localStorage.setItem(`fbos_records_${q}`,JSON.stringify(n))});return()=>r()});return()=>t()},[r,q]);let J=()=>({name:r.displayName||r.email?.split(`@`)[0]||`Member`,email:r.email||``,avatar:r.photoURL||``}),Y=async e=>{if(e.preventDefault(),!(!r||!_.trim())){S(!0);try{let e=J();await(0,o.addDoc)((0,o.collection)(n.Tt,q),{name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()}),v(``),b(``),g(!1)}catch(e){console.error(`Error saving shared record:`,e)}S(!1)}},ae=async e=>{let t=e.target.files?.[0];if(!(!t||!r)){E(!0);try{let e=(0,c.ref)(n.Dt,`mem_files/${`${Date.now()}_${t.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`);await(0,c.uploadBytes)(e,t,{customMetadata:{ownerId:r.uid}});let i=await(0,c.getDownloadURL)(e),a=J();await(0,o.addDoc)((0,o.collection)(n.Tt,`mem_files`),{fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,uid:r.uid,uploaderEmail:r.email||`member`,sourceTab:ie,accessPrefix:`mem_`,creatorName:a.name,creatorEmail:a.email,creatorAvatar:a.avatar,createdAt:(0,o.serverTimestamp)()}),await(0,o.addDoc)((0,o.collection)(n.Tt,q),{name:t.name,note:`${t.type||`File`} · ${Q(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:i,creatorName:a.name,creatorEmail:a.email,creatorAvatar:a.avatar,createdAt:(0,o.serverTimestamp)()})}catch(e){console.error(`Error uploading shared file:`,e)}E(!1),W.current&&(W.current.value=``)}},oe=async()=>{if(D){I(!0);try{let e=s.find(e=>e.id===D);if(await(0,o.deleteDoc)((0,o.doc)(n.Tt,q,D)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`mem_files%2F`)[1]?.split(`?`)[0];t&&await(0,c.deleteObject)((0,c.ref)(n.Dt,`mem_files/${decodeURIComponent(t)}`)).catch(()=>{});let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`mem_files`),(0,o.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of r.docs)await(0,o.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up shared file:`,e)}O(null)}catch(e){console.error(`Error deleting shared record:`,e)}I(!1)}},[se,le]=(0,a.useState)(null),[ue,de]=(0,a.useState)(``),[fe,X]=(0,a.useState)(!1),pe=e=>{if(e.recordType===`file`){le(e.id),de(e.name);return}R(e.id),B(e.name),ne(e.note||``);let t=[`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`],n=Object.entries(e).filter(([e])=>!t.includes(e)&&e!==`id`).map(([e,t])=>({key:e,value:String(t??``)}));U(n),re.current=n.map(e=>e.key)},me=async()=>{if(!se||!ue.trim()){le(null);return}let e=s.find(e=>e.id===se);if(e&&e.name===ue.trim()){le(null);return}X(!0);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,se),{name:ue.trim()}),u(e=>e.map(e=>e.id===se?{...e,name:ue.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}X(!1),le(null)},Z=async()=>{await he(),R(null)},he=async()=>{if(!L||!z.trim())return;S(!0);let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=re.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,L),{name:z.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==L)return e;let t={...e,name:z.trim(),note:V.trim()};return r.forEach(e=>{delete t[e]}),H.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),re.current=t}catch(e){console.error(`Error saving record:`,e)}S(!1)},ge=(e,t)=>e?e.startsWith(`image/`)?t?(0,l.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${t})`}}):(0,l.jsx)(n.V,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,l.jsx)(n.l,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,l.jsx)(n.G,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,l.jsx)(n._t,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,l.jsx)(n.Q,{className:`w-4 h-4`}):(0,l.jsx)(n.W,{className:`w-4 h-4`}):(0,l.jsx)(n.G,{className:`w-4 h-4`}),_e=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-purple-500/10 text-purple-500`:e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?`bg-blue-500/10 text-blue-500`:e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?`bg-yellow-500/10 text-yellow-500`:e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?`bg-emerald-500/10 text-emerald-500`:`bg-foreground/5 text-foreground/40`:`bg-foreground/5 text-foreground/40`,ve=e=>{if(!e)return`FILE`;let t={"application/pdf":`PDF`,"application/zip":`ZIP`,"application/x-zip-compressed":`ZIP`,"application/x-rar-compressed":`RAR`,"application/x-7z-compressed":`7Z`,"application/json":`JSON`,"application/xml":`XML`,"application/javascript":`JS`,"application/typescript":`TS`,"application/msword":`DOC`,"application/vnd.openxmlformats-officedocument.wordprocessingml.document":`DOCX`,"application/vnd.ms-excel":`XLS`,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":`XLSX`,"application/vnd.ms-powerpoint":`PPT`,"application/vnd.openxmlformats-officedocument.presentationml.presentation":`PPTX`,"application/rtf":`RTF`,"application/x-tar":`TAR`,"application/gzip":`GZ`,"text/plain":`TXT`,"text/html":`HTML`,"text/css":`CSS`,"text/csv":`CSV`,"text/markdown":`MD`},n=e.toLowerCase();if(t[n])return t[n];let r=n.split(`/`);return r[r.length-1].replace(/^x-/,``).replace(/^vnd\..*\./,``).toUpperCase().slice(0,10)},Q=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},ye=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},be=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),r=t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return n.o[r]?n.o[r]:n.o[t]?n.o[t]:n.f||n.C})(),xe=e.buttonStyle!==`secondary`,Se=e.buttonStorageStyle===`primary`,Ce=e=>e.uid===r?.uid,we=ce(e,q),Te=()=>{navigator.clipboard.writeText(we),w(!0),setTimeout(()=>w(!1),2e3)},Ee=({record:e})=>{let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||`Member`,n=e.creatorEmail||``,r=e.creatorAvatar||``,i=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,l.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/15 text-accent flex items-center justify-center text-[8px] font-extrabold shrink-0`,children:i}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,l.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Shared Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${s.length} ${s.length===1?`item`:`items`} · Shared`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:Te,title:C?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${C?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:C?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),e.storage!==!1&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`input`,{type:`file`,ref:W,onChange:ae,className:`hidden`}),(0,l.jsxs)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${Se?`btn-primary`:`btn-secondary`}`,children:[T?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(be,{className:`w-4 h-4`}),e.buttonStorageText&&(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>g(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${xe?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,l.jsx)(n.C,{className:`w-4 h-4`}):(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),t?(0,l.jsx)(t,{config:e,actions:{records:s,loading:f,collection:q,user:r,saveRecord:async e=>{let t=J();await(0,o.addDoc)((0,o.collection)(n.Tt,q),{uid:r.uid,recordType:`record`,creatorName:t.name,creatorEmail:t.email,creatorAvatar:t.avatar,createdAt:(0,o.serverTimestamp)(),...e})},deleteRecord:async e=>{await(0,o.deleteDoc)((0,o.doc)(n.Tt,q,e))},uploadFile:()=>W.current?.click(),openAddForm:()=>g(!0)}}):(0,l.jsxs)(l.Fragment,{children:[!f&&s.length===0&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,l.jsx)(n.C,{className:`w-6 h-6 text-accent/40`})}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All team members can view and contribute.`})]}),!f&&s.length>0&&(0,l.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,l.jsx)(n.a,{children:s.map(e=>{let t=L===e.id,r=Ce(e);return(0,l.jsxs)(n.i.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>r?pe(e):null,className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative ${r?`cursor-pointer`:``} ${t?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,l.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),K(e.id),setTimeout(()=>K(null),2e3)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-emerald-500 hover:bg-emerald-500/10 transition-all cursor-pointer`,title:`Copy Link`,children:G===e.id?(0,l.jsx)(n.ct,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-3.5 h-3.5`})})]}),r&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),pe(e)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,l.jsx)(n.w,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),O(e.id)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-3.5 h-3.5`})})]})]}),(0,l.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,l.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&j(e)},className:`w-9 h-9 rounded-xl flex items-center justify-center shrink-0 ${e.recordType===`file`?`cursor-pointer hover:scale-105 transition-transform ${_e(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?ge(e.fileType,e.downloadURL):(0,l.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[se===e.id?(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,value:ue,onChange:e=>de(e.target.value),onBlur:()=>me(),onKeyDown:e=>{e.key===`Enter`&&me(),e.key===`Escape`&&le(null)},onClick:e=>e.stopPropagation(),className:`no-glow text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full pr-12`}):(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>j(e)}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:ye(e.createdAt)})]})]}),e.note&&(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),Object.entries(e).filter(([e])=>![`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`].includes(e)&&e!==`id`).slice(0,3).map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,l.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,l.jsx)(Ee,{record:e})]},e.id)})})})]})]}),!t&&(0,l.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,l.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,l.jsx)(n.B,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,l.jsxs)(`span`,{children:[`Shared between all members · Edit and delete available on your own items only · Records: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:q}),` · Files: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`mem_files`}),` → Drive / Shared`]})]})})]})]}),(0,l.jsx)(n.a,{children:h&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!x&&g(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`form`,{onSubmit:Y,className:`p-5 flex flex-col gap-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>!x&&g(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:_,onChange:e=>v(e.target.value),placeholder:`Name *`,disabled:x,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),placeholder:`Note (optional)`,disabled:x,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:x,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:x?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,d.createPortal)((0,l.jsx)(n.a,{children:M&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,l.jsx)(n.i.div,{onClick:()=>j(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(`button`,{onClick:()=>j(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-[var(--panel-border)]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 bg-background/80 backdrop-blur-md border-b border-[var(--panel-border)] shrink-0 shadow-sm z-20`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:M.fileName||M.name}),(0,l.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[ve(M.fileType),` • `,Q(M.fileSize||0)]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.downloadURL),K(`preview`),setTimeout(()=>K(null),2e3)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 transition-colors rounded-xl shadow-sm hover:text-emerald-500 cursor-pointer`,title:`Copy Link`,children:G===`preview`?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),le(M.id),de(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{j(null),O(M.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),(0,l.jsx)(`a`,{href:M.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>j(null),children:(0,l.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[N&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-background/80 backdrop-blur-md shadow-xl flex items-center justify-center border border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,l.jsx)(`img`,{onLoad:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,alt:M.fileName||M.name,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full object-contain drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] rounded-lg pointer-events-auto transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType?.startsWith(`video/`)?(0,l.jsx)(`video`,{onLoadedData:()=>P(!1),onError:()=>P(!1),src:M.downloadURL,controls:!0,autoPlay:!0,className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-auto h-auto max-w-full max-h-full outline-none bg-black/40 rounded-lg pointer-events-auto drop-shadow-[0_0_40px_rgba(0,0,0,0.5)] transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):M.fileType===`application/pdf`?(0,l.jsx)(`iframe`,{onLoad:()=>P(!1),src:M.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${N?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,l.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center text-foreground/40 text-center relative z-10`,onClick:e=>{e.stopPropagation(),P(!1)},children:[(0,l.jsx)(n.G,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,l.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,l.jsx)(`span`,{className:`text-[14px] mt-2 text-foreground/60 font-medium max-w-xs`,children:`This file format cannot be previewed. Please download it instead.`})]})]})})]})]})}),document.body),(0,l.jsx)(n.a,{children:L&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>Z(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[440px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),x&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>Z(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NAME`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>B(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),placeholder:`Name *`,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NOTE`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{ne(e.target.value),e.target.style.height=`auto`,e.target.style.height=e.target.scrollHeight+`px`},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),e.target.blur())},onBlur:()=>he(),placeholder:`Add a note...`,rows:1,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50 resize-none overflow-hidden`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),H.map((e,t)=>(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let n=[...H];n[t].key=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none placeholder:text-foreground/15 pt-3 pb-0.5 caret-foreground/40`}),(0,l.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let n=[...H];n[t].value=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>he(),className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pt-1.5 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>U(H.filter((e,n)=>n!==t)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})})]},t)),(0,l.jsxs)(`button`,{type:`button`,onClick:()=>U([...H,{key:``,value:``}]),className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground/25 hover:text-foreground/40 transition-colors cursor-pointer mt-4 mb-4`,children:[(0,l.jsx)(n.C,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,l.jsx)(te,{isOpen:!!D,onCancel:()=>O(null),onConfirm:oe,title:`Delete Record`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:s.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:F})]})}function cn(){let e=(0,u.useLocation)(),{user:t}=m(),r=n.Ct(),[i,s]=(0,a.useState)(null),[c,d]=(0,a.useState)(!0);(0,a.useEffect)(()=>{let t=!0,r=localStorage.getItem(`fbos_route_${e.pathname}`);if(r)try{let e=JSON.parse(r);s(e),d(!1);let t=e.pageName||e.tabName||e.title;t&&(document.title=t)}catch{}return(async()=>{try{let r=e.pathname;r.startsWith(`/`)&&(r=r.substring(1));let[i,a,c,l,u,f]=await Promise.allSettled([(0,o.getDoc)((0,o.doc)(n.Tt,`sys_pages`,r)),(0,o.getDoc)((0,o.doc)(n.Tt,`sys_tabs`,r)),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_pages`),(0,o.where)(`route`,`==`,e.pathname),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_pages`),(0,o.where)(`route`,`==`,r),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_tabs`),(0,o.where)(`route`,`==`,e.pathname),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_tabs`),(0,o.where)(`route`,`==`,r),(0,o.limit)(1)))]),p=null,m=null,h=(e,t)=>{if(!p&&e.status===`fulfilled`){if(e.value.exists&&e.value.exists()){let n=e.value.data();p={...n,isPrivate:t,isAdmin:n.pageType===`admin`,isShared:n.pageType===`shared`},m=e.value.id}else if(e.value.docs&&e.value.docs.length>0){let n=e.value.docs[0].data();p={...n,isPrivate:t,isAdmin:n.pageType===`admin`,isShared:n.pageType===`shared`},m=e.value.docs[0].id}}};if(h(i,!1),h(c,!1),h(l,!1),h(a,!0),h(u,!0),h(f,!0),p||(e.pathname===`/contact`?(p={route:`/contact`,template:`popup_form`,form:`contact`},m=`contact`):e.pathname===`/support`&&(p={route:`/support`,template:`popup_form`,form:`support`},m=`support`)),!t)return;if(p){if((m===`contact`||m===`support`)&&!p.form&&(p.form=m),p.pageId=m,localStorage.setItem(`fbos_route_${e.pathname}`,JSON.stringify(p)),p.form){try{let e=localStorage.getItem(`fbos_form_${p.form}`);e&&(p.formConfigOverride=JSON.parse(e))}catch{}(0,o.getDoc)((0,o.doc)(n.Tt,`sys_forms`,p.form)).then(async e=>{if(t)if(e.exists()){let t={...e.data(),id:e.id};s(e=>({...e,formConfigOverride:t})),localStorage.setItem(`fbos_form_${p.form}`,JSON.stringify(t))}else{let e;if(p.form===`contact`){let{contactFormConfig:t}=await Promise.resolve().then(()=>require(`./contactForm.config-CXyq-EbM.cjs`)).then(e=>e.n);e=t}else if(p.form===`support`){let{supportFormConfig:t}=await Promise.resolve().then(()=>require(`./supportForm.config-haLod4rv.cjs`)).then(e=>e.n);e=t}e&&(s(t=>({...t,formConfigOverride:e})),localStorage.setItem(`fbos_form_${p.form}`,JSON.stringify(e)))}})}let r=p.pageName||p.tabName||p.title;r&&(document.title=r),s(p),d(!1)}else s(`not-found`),d(!1),localStorage.removeItem(`fbos_route_${e.pathname}`)}catch{t&&c&&(s(`not-found`),d(!1))}})(),()=>{t=!1}},[e.pathname]);let[f,p]=(0,a.useState)(!1);if((0,a.useEffect)(()=>{let e;return c?e=setTimeout(()=>p(!0),150):p(!1),()=>clearTimeout(e)},[c]),c)return f?t?(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(`div`,{className:`mb-6`,children:[(0,l.jsx)(`div`,{className:`h-10 w-56 rounded-xl bg-foreground/5 animate-pulse mt-1`}),(0,l.jsx)(`div`,{className:`h-3 w-24 rounded bg-foreground/5 animate-pulse mt-3`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsx)(`div`,{className:`flex-1 glass-panel border border-[var(--panel-border)] rounded-3xl flex items-center justify-center min-h-[400px] bg-background shadow-2xl`,children:(0,l.jsx)(n.M,{className:`w-6 h-6 animate-spin text-accent`})})]})]}):(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[60vh] z-10`,children:(0,l.jsx)(n.M,{className:`w-6 h-6 animate-spin text-accent`})}):null;if(i===`not-found`)return(0,l.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1 text-center`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 bg-red-500/10 text-red-500 rounded-full flex items-center justify-center mb-6`,children:(0,l.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-8 h-8`,children:[(0,l.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,l.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,l.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]})}),(0,l.jsx)(`h2`,{className:`text-3xl font-bold mb-3 text-foreground`,children:`Page Not Found`}),(0,l.jsx)(`p`,{className:`text-foreground/60 max-w-md`,children:`The route you are looking for does not exist or has been removed.`})]})});if((i.pageId===`support`||i.isPrivate)&&!t)return(0,l.jsx)(u.Navigate,{to:`/login`,state:{from:e}});let h=r.customRoutes?.[e.pathname]||(i&&i.route?r.customRoutes?.[i.route]:null),g=i.pageName?.toLowerCase().replace(/\s+/g,`_`)||i.pageId||`custom_page`,_=`pub_${g}`,v=(i.tabName||i.pageId||i.pageName||`custom`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),y=(r.microcomponents||(typeof window<`u`?window.__FBOS_MICROCOMPONENTS__:void 0))?.[v],b=h||y||void 0;if(i.template===`none`)return i.isAdmin?(0,l.jsx)(on,{config:i,customContent:b}):i.isShared?(0,l.jsx)(sn,{config:i,customContent:b}):i.isPrivate?(0,l.jsx)(an,{config:i,customContent:b}):(0,l.jsx)(rn,{config:i,customContent:b});if(h)return(0,l.jsx)(h,{config:i});if(i.template===`board`){let e=i.isAdmin?`admin_${i.pageId||g}`:i.isShared?`mem_${i.pageId||g}`:i.isPrivate?`user_${i.pageId||g}`:_;return(0,l.jsx)(r.components?.TemplateBoard||fe,{title:i.tabTitle||i.tabName||i.title||i.pageName||`Board`,subtitle:i.route,tasksCollection:`${e}_tasks`,categoriesCollection:`${e}_categories`,config:i})}if(i.template===`table`){let e=i.isAdmin?`admin_${i.pageId||g}`:i.isShared?`mem_${i.pageId||g}`:i.isPrivate?`user_${i.pageId||g}`:_;return(0,l.jsx)(r.components?.TemplateTable||Rt,{title:i.tabTitle||i.tabName||i.title||i.pageName||`Table`,subtitle:i.route,tableCollection:`${e}_table`,config:i})}if(i.template===`calendar`){let e=i.isAdmin?`admin_${i.pageId||g}`:i.isShared?`mem_${i.pageId||g}`:i.isPrivate?`user_${i.pageId||g}`:_;return(0,l.jsx)(r.components?.TemplateCalendar||Vt,{title:i.tabTitle||i.tabName||i.title||i.pageName||`Calendar`,subtitle:i.route,eventsCollection:`${e}_events`,defaultTimeFormat:i.defaultTimeFormat||i.defaulttimeformat||`12h`,config:i})}return i.template===`inline_form`?(0,l.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-start mt-8 relative z-10 w-full min-h-[60vh]`,children:(0,l.jsx)(n.t,{isInline:!0,formId:i.form,formConfig:i.formConfigOverride})}):(0,l.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 w-full min-h-[60vh]`,children:(0,l.jsx)(n.t,{formId:i.form,formConfig:i.formConfigOverride,onClose:()=>window.history.back()})})}var ln=a.default.createContext({}),un=Object.defineProperty,dn=Object.getOwnPropertySymbols,fn=Object.prototype.hasOwnProperty,pn=Object.prototype.propertyIsEnumerable,mn=(e,t,n)=>t in e?un(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,hn=(e,t)=>{for(var n in t||={})fn.call(t,n)&&mn(e,n,t[n]);if(dn)for(var n of dn(t))pn.call(t,n)&&mn(e,n,t[n]);return e},gn=(0,a.forwardRef)((e,t)=>{let n=hn(hn({},a.useContext(ln)),e);return a.createElement(`svg`,hn({width:`1.5em`,height:`1.5em`,strokeWidth:1.5,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,color:`currentColor`,ref:t},n),a.createElement(`path`,{d:`M21.1679 8C19.6247 4.46819 16.1006 2 11.9999 2C6.81459 2 2.55104 5.94668 2.04932 11`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M17 8H21.4C21.7314 8 22 7.73137 22 7.4V3`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M2.88146 16C4.42458 19.5318 7.94874 22 12.0494 22C17.2347 22 21.4983 18.0533 22 13`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M7.04932 16H2.64932C2.31795 16 2.04932 16.2686 2.04932 16.6V21`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}))}),_n=Object.defineProperty,vn=Object.getOwnPropertySymbols,yn=Object.prototype.hasOwnProperty,bn=Object.prototype.propertyIsEnumerable,xn=(e,t,n)=>t in e?_n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Sn=(e,t)=>{for(var n in t||={})yn.call(t,n)&&xn(e,n,t[n]);if(vn)for(var n of vn(t))bn.call(t,n)&&xn(e,n,t[n]);return e},Cn=(0,a.forwardRef)((e,t)=>{let n=Sn(Sn({},a.useContext(ln)),e);return a.createElement(`svg`,Sn({width:`1.5em`,height:`1.5em`,viewBox:`0 0 24 24`,strokeWidth:1.5,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,color:`currentColor`,ref:t},n),a.createElement(`path`,{d:`M22 12C22 17.5228 17.5228 22 12 22C10.1786 22 8.47087 21.513 7 20.6622L2 21.5L2.83209 16C2.29689 14.7751 2 13.4222 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M12.9604 13.8683L15.0399 13.4624L17 14.2149V16.0385C17 16.6449 16.4783 17.1073 15.8901 16.9783C14.3671 16.6444 11.5997 15.8043 9.67826 13.8683C7.84859 12.0248 7.22267 9.45734 7.01039 8.04128C6.92535 7.47406 7.3737 7 7.94306 7H9.83707L10.572 8.96888L10.1832 11.0701`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}))}),wn=`rules_version = '2';
|
|
319
|
+
};`;navigator.clipboard.writeText(a),m(!0),setTimeout(()=>m(!1),2e3)}};return(0,a.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key===`a`&&document.activeElement===document.body&&e.preventDefault(),(e.ctrlKey||e.metaKey)&&e.key===`c`&&!window.getSelection()?.toString()&&r&&b()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]),(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Theme`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/theme`]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-6 md:p-10 shadow-2xl relative overflow-hidden bg-background flex flex-col min-h-[600px]`,children:[(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Theme Config`}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`Changes here immediately format natively. Save to update your Live Preview panel entirely.`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:_,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-xl flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:u?(0,l.jsx)(n.M,{className:`w-4 h-4 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-4 h-4 text-foreground/60 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(n.n,{variant:`secondary`,onClick:b,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors`,title:`Copy Config (Ctrl+C)`,children:p?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-4 h-4 text-foreground/60 hover:text-foreground transition-colors`})})]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 w-full relative z-10 items-start`,children:[u&&(0,l.jsx)(`div`,{className:`absolute inset-0 bg-background/60 backdrop-blur-[2px] z-50 flex items-center justify-center rounded-3xl pointer-events-none transition-all duration-300`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 animate-spin text-accent`})}),(0,l.jsxs)(`div`,{className:`w-full glass-panel border border-[var(--panel-border)] rounded-3xl p-6 md:p-8 shadow-inner overflow-hidden relative bg-background`,children:[(0,l.jsx)(`h3`,{className:`text-lg font-extrabold text-foreground tracking-tight mb-4 flex items-center gap-3`,children:`Branding & Colours`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-3 overflow-x-auto hide-scrollbars pb-4 pt-2 mb-6 border-b border-[var(--panel-border)]/50 shrink-0`,children:[(0,l.jsx)(`div`,{className:`text-[12px] font-bold text-foreground/40 shrink-0 uppercase tracking-widest pl-1 mr-2`,children:`Presets`}),Bt.map(e=>{let t=r?.colors?.dark?.accent===e.dark.accent&&r?.colors?.dark?.buttonGradient?.[0]===e.dark.gradient[0],n=e.name===`Black & White`;return(0,l.jsx)(`button`,{onClick:()=>y(e),className:`w-9 h-9 rounded-full shrink-0 outline-none transition-all shadow-sm relative group overflow-visible ${t?`ring-[3px] ring-foreground ring-offset-2 ring-offset-[var(--background)] scale-110 z-10`:`opacity-80 hover:opacity-100 hover:ring-2 hover:ring-foreground/30 hover:ring-offset-2 hover:ring-offset-[var(--background)] hover:scale-105`}`,title:e.name,children:(0,l.jsx)(`div`,{className:`absolute inset-0 rounded-full`,style:n?{backgroundColor:`#ffffff`,border:`3px solid #000000`,boxShadow:`inset 0 0 0 1px rgba(0,0,0,0.1)`}:{backgroundImage:`linear-gradient(135deg, ${e.preview[0]}, ${e.preview[1]})`}})},e.name)})]}),(0,l.jsx)(`div`,{className:`w-full relative min-h-[100px]`,children:r?(0,l.jsxs)(`div`,{className:`flex flex-col pl-2`,children:[(0,l.jsxs)(`span`,{className:`text-yellow-500 font-mono text-[13px] mb-2`,children:[`export const themeConfig = `,`{`]}),(0,l.jsx)(Ut,{value:r,keysToRender:[`appName`,`defaultTheme`,`showThemeToggle`,`logoUrl`,`faviconUrl`,`cornerRounding`,`cornerRadii`,`fontFamily`],onChange:e=>i(e),isLast:!1,isGlobalSaving:s}),(0,l.jsx)(`div`,{className:`mt-4`,children:(0,l.jsx)(Ut,{objectKey:`colors`,value:r.colors,onChange:e=>i({...r,colors:e}),isLast:!1,isGlobalSaving:s})})]}):(0,l.jsx)(`div`,{className:`flex items-center justify-center w-full h-full text-foreground/40 font-mono text-[13px] animate-pulse py-10`,children:`Loading Data Tree...`})})]})]})]})]})]})}var Gt={route:`/page_1`,pageName:`New Public Page`,template:`none`,pageTitle:`My Custom Page`,copyPrompt:!0,showButton:!0,buttonText:`Open Form`,action:`form`,form:`contact`},Kt={tabName:`New Private Page`,iconName:``,route:`/new-private-page`,template:`none`,form:`support`,showPrompt:!0,tabTitle:`Private Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},qt={tabName:`Admin Tab`,iconName:``,route:`/admin-tab`,template:`none`,form:``,showPrompt:!0,tabTitle:`Admin Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},Jt={tabName:`Shared Tab`,iconName:``,route:`/shared-tab`,template:`none`,form:``,showPrompt:!0,tabTitle:`Shared Dashboard`,showButton:!0,buttonStyle:`primary`,buttonText:`+`,buttonAction:`save_info`,storage:!0,buttonStorageIcon:`upload`,buttonStorageText:``,buttonStorageStyle:`secondary`,buttonStorageAction:`upload_file`,defaultView:`calendar`,defaultTimeFormat:`12h`,showViewsButton:!0,viewsButtonStyle:`secondary`,showExportButton:!0,exportButtonIcon:`download-square`,keyName:`key`,valueName:`value`},Yt=[{id:`home`,title:`Home Page`,path:`/`,type:`public`,isSystem:!0,enabled:!0}],Xt=({enabled:e,onChange:t,disabled:r,className:i=``})=>(0,l.jsx)(`button`,{disabled:r,onClick:()=>t(!e),title:e?`Page Active`:`Page Hidden`,className:`p-1.5 transition-colors rounded-lg flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity ${i} ${e?`text-accent hover:bg-accent/10`:`text-foreground/40 hover:bg-foreground/5`} ${r?`!opacity-50 cursor-not-allowed`:`cursor-pointer`}`,children:e?(0,l.jsx)(n.K,{className:`w-4 h-4`}):(0,l.jsx)(n.q,{className:`w-4 h-4`})});function Zt(){let{userRole:e}=m(),t=(0,u.useLocation)(),r=n.Ct(),[i,s]=(0,a.useState)(Yt),[c,d]=(0,a.useState)(()=>{try{return sessionStorage.getItem(`fbos_pages_expandedId`)||null}catch{return null}}),f=(0,a.useRef)(c),[p,h]=(0,a.useState)(!1),[g,_]=(0,a.useState)({}),[v,y]=(0,a.useState)({}),[b,x]=(0,a.useState)({}),[C,w]=(0,a.useState)(null),[T,E]=(0,a.useState)(!1),D=(0,a.useRef)(null);(0,a.useEffect)(()=>{function e(e){D.current&&!D.current.contains(e.target)&&h(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let[O,k]=(0,a.useState)(null),[A,j]=(0,a.useState)(!1),[ne,M]=(0,a.useState)(!1),[N,P]=(0,a.useState)(new Set),[F,I]=(0,a.useState)(new Set),[L,R]=(0,a.useState)([]),[z,re]=(0,a.useState)([]),B=e=>(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden});(0,a.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`page_order`),e=>{let t=B(e.exists()&&e.data().order||[]);R(t),P(new Set(t.filter(e=>e.hidden).map(e=>e.id)))}),t=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_configs`,`tab_order`),e=>{let t=B(e.exists()&&e.data().order||[]);re(t),I(new Set(t.filter(e=>e.hidden).map(e=>e.id)))});return()=>{e(),t()}},[]),(0,a.useEffect)(()=>{let e=t.pathname.split(`/pages/`)[1]?.split(`/`)[0];e&&!c&&i.some(t=>t.id===e)&&d(e)},[t.pathname,i]),(0,a.useEffect)(()=>{f.current=c;try{c?sessionStorage.setItem(`fbos_pages_expandedId`,c):sessionStorage.removeItem(`fbos_pages_expandedId`)}catch{}},[c]);let ie=(0,a.useRef)(null);(0,a.useEffect)(()=>{let e=ie.current;if(!e)return;try{let t=sessionStorage.getItem(`fbos_pages_scrollY`);t&&(e.scrollTop=parseInt(t,10))}catch{}let t=()=>{try{sessionStorage.setItem(`fbos_pages_scrollY`,String(e.scrollTop))}catch{}};return e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[]),(0,a.useEffect)(()=>{let e=(e,t)=>{if(!t)return e;let n=Object.fromEntries(Object.entries(t).filter(([e,t])=>t!=null&&t!==``));return{...e,...n}},t=r?.defaultConfigs?.home||S,i=(0,o.onSnapshot)((0,o.doc)(n.Tt,`sys_pages`,`home`),n=>{n.exists()?k(e(t,n.data())):k(t)});return()=>{i()}},[r]),(0,a.useEffect)(()=>{(async()=>{try{let[e,t]=await Promise.all([(0,o.getDocs)((0,o.collection)(n.Tt,`sys_pages`)),(0,o.getDocs)((0,o.collection)(n.Tt,`sys_tabs`))]),r=[`home`,`contact`,`support`,`theme`,`page_order`,`tab_order`],i=[],a={};e.forEach(e=>{if(!r.includes(e.id)){let t=e.data();i.push({id:e.id,title:t.pageName||t.title||e.id,path:t.route||`/`+e.id,type:`public`,isSystem:!1,enabled:t.enabled!==!1}),a[e.id]=t}}),t.forEach(e=>{if(!r.includes(e.id)){let t=e.data(),n=t.pageType||`private`;i.push({id:e.id,title:t.tabName||t.title||e.id,path:t.route||`/`+e.id,type:n,isSystem:!1,enabled:t.enabled!==!1}),a[e.id]=t}}),i.length>0&&(s(e=>{let t=e.filter(e=>e.isSystem||e.id.startsWith(`draft_`)),n=i.filter(e=>!t.some(t=>t.id===e.id));return[...t,...n]}),_(e=>({...e,...a})))}catch(e){console.error(`Error loading custom pages`,e)}})()},[]);let[V,ae]=(0,a.useState)([`contact`]),[H,U]=(0,a.useState)([`support`]);(0,a.useEffect)(()=>{(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{let t=[],n=[];e.forEach(e=>{e.data().formType===`private`?n.push(e.id):t.push(e.id)}),t.length>0&&ae(t),n.length>0&&U(n)}).catch(console.error)},[]);let[W,oe]=(0,a.useState)(null),G=(e,t)=>{let n;n=e===`home`?`export const defaultHomeConfig = ${JSON.stringify(t,null,2)};\n`:JSON.stringify(t,null,2),navigator.clipboard.writeText(n),oe(e),setTimeout(()=>oe(null),2e3)},K=async(e,t)=>{t.route&&!t.route.startsWith(`/`)&&(t.route=`/`+t.route);let r=i.find(t=>t.id===e)?.type,a=r===`public`?`sys_pages`:`sys_tabs`;r&&r!==`public`&&(t.pageType=r);let c=[`home`].includes(e)?e:t.route?t.route.replace(/^\/+/,``).replace(/[^a-zA-Z0-9_\-]/g,`_`).toLowerCase():e;e===`home`?j(!0):y(t=>({...t,[e]:!0,[c]:!0}));try{if(c!==e&&c.trim()!==``&&c!==`draft`){try{let{deleteDoc:t}=await import(`firebase/firestore`);await t((0,o.doc)(n.Tt,a,e))}catch{}await(0,o.setDoc)((0,o.doc)(n.Tt,a,c),t),s(n=>n.map(n=>n.id===e?{...n,id:c,_uiKey:n._uiKey||e,path:t.route,title:t.pageName||t.tabName||t.title||n.title}:n)),f.current===e&&(d(c),window.history.replaceState(null,``,`/pages/${c}`)),_(n=>{let r={...n};return r[c]=t,delete r[e],r});let i=r===`public`,l=i?`page_order`:`tab_order`,u=i?L:z;if(!u.some(e=>e.id===c)){let t=[{id:c,hidden:!1},...u.filter(t=>t.id!==e)];try{await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,l),{order:t})}catch(e){console.error(`Failed to update tab order:`,e)}}}else await(0,o.setDoc)((0,o.doc)(n.Tt,a,e),t),e===`home`?k(t):(_(n=>({...n,[e]:t})),s(n=>n.map(n=>n.id===e?{...n,path:t.route||n.path,title:t.pageName||t.tabName||t.title||n.title}:n)))}catch(t){console.error(`Failed to save ${e} config:`,t)}finally{setTimeout(()=>{e===`home`?j(!1):y(t=>({...t,[e]:!1,[c]:!1}))},500)}},se=async e=>{e.stopPropagation(),M(!0);try{let{deleteDoc:e}=await import(`firebase/firestore`);await e((0,o.doc)(n.Tt,`sys_pages`,`home`)),localStorage.removeItem(`fbos_home_config`),k(r?.defaultConfigs?.home||S)}catch(e){console.error(`Failed to reset home config:`,e)}setTimeout(()=>M(!1),500)},q=async(e,t,n)=>{e.stopPropagation(),x(e=>({...e,[t]:!0})),await K(t,n),setTimeout(()=>x(e=>({...e,[t]:!1})),500)},J=e=>{let t=`draft_`+Math.floor(Math.random()*1e4);s([...i,{id:t,title:`New Tab`,path:`/draft`,type:e,isSystem:!1,enabled:!0}]);let n=i.filter(t=>t.type===e&&!t.id.startsWith(`draft_`)).length+1,r={};e===`public`?r={...Gt,route:`/page-${n}`}:e===`private`?r={...Kt,route:`/private-tab-${n}`}:e===`admin`?r={...qt,route:`/admin-tab-${n}`}:e===`shared`&&(r={...Jt,route:`/shared-tab-${n}`}),_(e=>({...e,[t]:r})),d(t),h(!1),K(t,{...r,pageType:e===`public`?void 0:e}),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})},100)};if(e!==`admin`)return(0,l.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,l.jsx)(n.v,{className:`w-12 h-12 text-red-500 mb-4`}),(0,l.jsx)(`h2`,{className:`text-2xl font-bold`,children:`Access Denied`}),(0,l.jsx)(`p`,{className:`text-foreground/60`,children:`You do not have permission to view pages configuration.`})]})});let Y=async(e,t,r)=>{let a=r===`public`,c=a?`page_order`:`tab_order`,l=a?L:z,u=(a?N:F).has(e);s(i.map(t=>t.id===e?{...t,enabled:u}:t));let d=[...l],f=d.findIndex(t=>t.id===e);f===-1?d.push({id:e,hidden:!0}):d[f]={...d[f],hidden:!u},await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_configs`,c),{order:d})},ce=(e,t)=>{t||w(e)},le=async()=>{if(C){E(!0);try{let{deleteDoc:e,collection:t,getDocs:r,doc:a,getDoc:o,query:l,where:u}=await import(`firebase/firestore`),{ref:f,deleteObject:p}=await import(`firebase/storage`),m=i.find(e=>e.id===C),h=m?.type===`public`?`sys_pages`:`sys_tabs`;if(h===`sys_tabs`&&m){let i=g[C];if(!i)try{let e=await o(a(n.Tt,`sys_tabs`,C));e.exists()&&(i=e.data())}catch{}let s=(i?.tabName||i?.pageId||C).toLowerCase().replace(/[^a-z0-9]+/g,`_`),c=[`admin_${s}_records`,`mem_${s}_records`,`user_${s}_records`],d={[`admin_${s}_records`]:{prefix:`admin_files`,driveCollection:`admin_files`},[`mem_${s}_records`]:{prefix:`mem_files`,driveCollection:`mem_files`},[`user_${s}_records`]:{prefix:`user_files`,driveCollection:`user_files`}},m=[];for(let i of c)m.push((async()=>{try{let a=await r(t(n.Tt,i)),o=d[i],s=[];for(let i of a.docs){let a=i.data();a.recordType===`file`&&a.downloadURL&&o&&s.push((async()=>{try{let i=`${o.prefix}%2F`,s=a.downloadURL.split(i)[1]?.split(`?`)[0];s&&await p(f(n.Dt,`${o.prefix}/${decodeURIComponent(s)}`)).catch(()=>{});let c=await r(l(t(n.Tt,o.driveCollection),u(`downloadURL`,`==`,a.downloadURL)));await Promise.all(c.docs.map(t=>e(t.ref)))}catch(e){console.error(`Error deleting storage file:`,e)}})())}await Promise.all(s),await Promise.all(a.docs.map(t=>e(t.ref)));try{localStorage.removeItem(`fbos_records_${i}`)}catch{}}catch(e){console.error(`Error cleaning up collection ${i}:`,e)}})());for(let i of[`admin_files`,`mem_files`,`user_files`])m.push((async()=>{try{let a=await r(l(t(n.Tt,i),u(`sourceTab`,`==`,s)));await Promise.all(a.docs.map(async t=>{let r=t.data();if(r.downloadURL)try{let e=`${i}%2F`,t=r.downloadURL.split(e)[1]?.split(`?`)[0];t&&await p(f(n.Dt,`${i}/${decodeURIComponent(t)}`)).catch(()=>{})}catch{}await e(t.ref)}))}catch{}})());await Promise.all(m)}await e(a(n.Tt,h,C));let _=h===`sys_pages`?`page_order`:`tab_order`,v=h===`sys_pages`?L:z,{setDoc:y}=await import(`firebase/firestore`),b=v.filter(e=>e.id!==C);await y(a(n.Tt,`sys_configs`,_),{order:b}),s(e=>e.filter(e=>e.id!==C)),c===C&&d(null)}catch(e){console.error(`Error deleting page:`,e)}E(!1),w(null)}},ue=e=>{let t=e.id+`_`+Math.floor(Math.random()*1e3),n={...e,id:t,title:`${e.title} (Copy)`,path:`${e.path}_copy`,isSystem:!1,enabled:!0};s(e=>[...e,n]);let r=g[e.id];!r&&e.id===`home`&&(r=O);let i={...r||{},route:n.path,pageName:n.title};n.type!==`public`&&(i.tabName=n.title,i.pageType=n.type),_(e=>({...e,[t]:i})),d(t),setTimeout(()=>{document.getElementById(`page-${t}`)?.scrollIntoView({behavior:`smooth`,block:`center`})},100)},de=[{id:`public`,title:`Public Pages`,icon:n.U,color:`bg-amber-500`,description:`Creates external menu items. Invisible to signed-in dashboard users.`,filter:e=>e.type===`public`},{id:`private`,title:`Private Pages`,icon:n.j,color:`bg-emerald-500`,description:`Internal dashboard tabs for regular users.`,filter:e=>e.type===`private`},{id:`shared`,title:`Shared Pages`,icon:n.K,color:`bg-blue-500`,description:`Dashboard tabs visible to all members, editors, and admins.`,filter:e=>e.type===`shared`},{id:`admin`,title:`Admin Pages`,icon:n.v,color:`bg-red-500`,description:`Internal dashboard tabs for admin users only.`,filter:e=>e.type===`admin`}],[X,Z]=(0,a.useState)(!1),[fe,pe]=(0,a.useState)(!1);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Pages`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/pages`,c?`/${c}`:``]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(`div`,{className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-6 pt-6 md:px-10 md:pt-10`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Architecture`}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`Manage the structure of your application tabs and public pages.`})]}),(0,l.jsxs)(`div`,{className:`relative z-50 shrink-0 flex items-center gap-1`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>Z(!0),className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,title:`Reset Defaults`,children:(0,l.jsx)(n.x,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,l.jsxs)(`div`,{className:`relative`,children:[(0,l.jsx)(n.n,{variant:`secondary`,onClick:()=>h(!p),className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,title:`Add New Page`,children:(0,l.jsx)(n.C,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})}),(0,l.jsx)(n.a,{children:p&&(0,l.jsx)(n.i.div,{ref:D,initial:{opacity:0,y:10,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.95},className:`absolute top-full mt-2 right-0 w-48 glass-panel border border-[var(--panel-border)] rounded-2xl p-2 shadow-xl z-50 flex flex-col gap-1`,children:[`public`,`private`,`shared`,`admin`].map(e=>(0,l.jsxs)(`button`,{onClick:()=>{J(e),h(!1)},className:`text-left px-3 py-2 text-[13px] font-bold uppercase tracking-wider text-foreground/70 hover:text-foreground hover:bg-foreground/5 rounded-lg transition-colors cursor-pointer`,children:[e,` Page`]},e))})})]})]})]}),(0,l.jsxs)(`div`,{ref:ie,className:`px-6 md:px-10 pb-6 md:pb-10 flex flex-col pt-0 gap-10 overflow-y-auto mt-2 relative min-h-[400px]`,children:[(0,l.jsx)(n.a,{children:fe&&(0,l.jsx)(n.i.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-[2px] rounded-3xl`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-6 glass-panel rounded-2xl shadow-xl`,children:[(0,l.jsx)(n.M,{className:`w-8 h-8 md:w-10 md:h-10 animate-spin text-accent mb-4`}),(0,l.jsx)(`span`,{className:`text-sm font-bold text-foreground`,children:`Synchronizing Architecture...`})]})})}),de.map((e,t)=>{let r=i.filter(e.filter),a=e.id===`public`?L:z,o=r.sort((e,t)=>{let n=a.findIndex(t=>t.id===e.id),r=a.findIndex(e=>e.id===t.id);return n===-1&&r===-1?0:n===-1?1:r===-1?-1:n-r}),s=e.icon,u=e=>e.type===`public`?N.has(e.id):F.has(e.id),f=o.filter(e=>!u(e)),p=o.filter(e=>u(e)),m=e=>{if(!e)return[];let t=[`route`,`pageName`,`template`];return e.template===`none`?(t.push(`pageTitle`,`copyPrompt`),t.push(`showButton`),e.showButton!==!1&&(t.push(`buttonText`,`action`),e.action===`form`?t.push(`form`):e.action===`redirect`&&t.push(`redirectUrl`))):(e.template===`popup_form`||e.template===`inline_form`)&&(t.push(`showButton`),e.showButton!==!1&&t.push(`form`)),t},h=e=>{if(!e)return[];let t=[`tabName`,`iconName`,`route`,`template`];return e.template===`popup_form`||e.template===`inline_form`?(t.push(`showButton`),e.showButton!==!1&&t.push(`form`)):e.template===`none`?(t.push(`showPrompt`,`tabTitle`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonStyle`,`buttonText`,`buttonAction`),t.push(`storage`),e.storage!==!1&&t.push(`buttonStorageIcon`,`buttonStorageText`,`buttonStorageStyle`,`buttonStorageAction`)):e.template===`calendar`?(t.push(`tabTitle`,`showPrompt`),t.push(`defaultView`,`defaultTimeFormat`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`showViewsButton`),e.showViewsButton!==!1&&t.push(`viewsButtonStyle`)):e.template===`table`?(t.push(`tabTitle`,`showPrompt`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`showExportButton`),e.showExportButton!==!1&&t.push(`exportButtonIcon`)):e.template===`board`&&(t.push(`tabTitle`,`showPrompt`),t.push(`showButton`),e.showButton!==!1&&t.push(`buttonText`,`buttonStyle`),t.push(`keyName`,`valueName`)),t},_=(t,r,i)=>{let a=t.id===`home`,o=c===t.id,s=a||!t.isSystem;return(0,l.jsxs)(`div`,{id:`page-${t.id}`,onClick:e=>{if(s){let e=o?null:t.id;d(e),window.history.replaceState(null,``,e?`/pages/${e}`:`/pages`)}},className:`group flex flex-col py-4 px-5 glass-panel border transition-all rounded-2xl hover:shadow-sm ${s?`cursor-pointer hover:border-accent/40`:``} ${i?`opacity-40 grayscale bg-foreground/[0.01] border-[var(--panel-border)]/50`:`border-transparent hover:border-[var(--panel-border)]`}`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-center justify-between w-full gap-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-1 w-full flex-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground truncate`,children:t.title}),a&&A&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-accent ml-2`})]}),(0,l.jsxs)(`div`,{className:`text-[11px] font-medium font-mono px-2 py-0.5 rounded w-fit ml-6 border ${i?`text-foreground/50 border-foreground/10 bg-foreground/5`:`text-accent/70 bg-accent/5 border-accent/10`}`,children:[window.location.host,t.path]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-4 shrink-0`,children:[!t.isSystem||[`contact`,`support`,`templates`].includes(t.id)?(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ue(t)},className:`p-1.5 hover:bg-accent/10 text-foreground/40 hover:text-accent transition-colors rounded-lg flex items-center justify-center shrink-0`,title:`Duplicate Page`,children:(0,l.jsx)(n.Z,{className:`w-4 h-4`})}):(0,l.jsx)(`div`,{className:`w-[28px] shrink-0`}),(0,l.jsx)(`div`,{className:`flex items-center justify-end w-8 shrink-0`,children:t.id===`home`?(0,l.jsx)(`div`,{className:`w-[28px] shrink-0`}):(0,l.jsx)(Xt,{enabled:!u(t),onChange:()=>Y(t.id,t.isSystem,t.type)})}),t.isSystem?(0,l.jsx)(`div`,{className:`w-[28px] shrink-0`}):(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),ce(t.id,t.isSystem)},className:`p-1.5 hover:bg-red-500/10 text-foreground/30 hover:text-red-500 transition-colors rounded-lg flex items-center justify-center shrink-0`,title:`Delete Page`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),s?(0,l.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 shrink-0 ${o?`rotate-180`:``}`,children:(0,l.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,l.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}):(0,l.jsx)(`div`,{className:`w-[24px] shrink-0`})]})]}),(0,l.jsxs)(n.a,{children:[o&&a&&O&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50 pb-4`,onClick:e=>e.stopPropagation(),children:(0,l.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 py-6 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,l.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,l.jsx)(`button`,{onClick:se,className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:ne?(0,l.jsx)(n.M,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),G(`home`,O)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:W===`home`?(0,l.jsx)(n.nt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,l.jsx)(Ut,{value:O,keysToRender:[`hero`],onChange:e=>K(`home`,e),isLast:!0,isGlobalSaving:A,customEnums:{form:V},customExplanations:{form:`User can click to switch to any public form we have in the forms tab. Private forms are not an option here. Add a new form in forms with a link that actually works.`}})]})}),o&&!t.isSystem&&g[t.id]&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50 pb-4`,onClick:e=>e.stopPropagation(),children:(0,l.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 py-6 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,l.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,l.jsx)(`button`,{onClick:e=>q(e,t.id,t.type===`admin`?qt:t.type===`shared`?Jt:t.type===`public`?Gt:Kt),className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:b[t.id]?(0,l.jsx)(n.M,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),G(t.id,g[t.id])},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:W===t.id?(0,l.jsx)(n.nt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,l.jsx)(Ut,{value:g[t.id],keysToRender:t.type===`public`?m(g[t.id]):h(g[t.id]),onChange:e=>K(t.id,e),isLast:!0,isGlobalSaving:v[t.id],customEnums:{form:t.type===`public`?V:H,template:t.type===`public`?[`none`,`popup_form`,`inline_form`]:t.type===`admin`||t.type===`shared`?[`none`,`calendar`,`table`,`board`]:[`none`,`calendar`,`table`,`board`,`popup_form`,`inline_form`],action:[`save_Info`,`form`],defaultTimeFormat:[`12h`,`24h`],defaultView:[`calendar`,`board`],buttonStyle:[`primary`,`secondary`],buttonAction:[`save_info`],viewsButtonStyle:[`primary`,`secondary`],buttonStorageStyle:[`primary`,`secondary`],buttonStorageAction:[`upload_file`]},customExplanations:{tabName:`Defines the tab label in the dashboard navigation.`,iconName:`Visit https://lucide.dev/icons/, find an icon, and paste its exact name (e.g. 'book-open', 'server', 'cloud-upload').`,route:`The URL path for this tab (e.g. '/my-tab'). Must start with /.`,template:`Page layout type. 'none' gives you a freeform dashboard with add/upload buttons.`,form:`Which form to display. Only applies to popup_form or inline_form templates. Go to /forms to edit forms.`,tabTitle:`The heading that appears at the top of the page content area.`,showPrompt:`Shows the developer AI prompt copy button in the header.`,showButton:`Toggles the + add record button in the header.`,buttonStyle:`Visual style of the add button: 'primary' (accent) or 'secondary' (subtle).`,buttonText:`Label on the add button. Use '+' for a minimal icon-only button.`,buttonAction:`'save_info' saves a name + note record to the tab's Firestore collection.`,storage:`Enables the file upload button for this tab.`,buttonStorageIcon:`Icon name from https://lucide.dev/icons/ for the upload button (e.g. 'upload', 'cloud-upload').`,buttonStorageText:`Label next to the upload icon. Leave empty for icon-only.`,buttonStorageStyle:`'primary' or 'secondary' visual style for the upload button.`,buttonStorageAction:t.type===`admin`?`'upload_file' uploads to admin_files/ in Storage and mirrors metadata to admin_files collection (Drive > Admin).`:t.type===`shared`?`'upload_file' uploads to mem_files/ in Storage and mirrors metadata to mem_files collection (Drive > Shared).`:`'upload_file' uploads to user_files/ in Storage and mirrors metadata to user_files collection (Drive > Private).`,defaultView:`Starting view: 'calendar' (month grid) or 'board' (event list). Users can switch between them.`,defaultTimeFormat:`12h or 24h time format. Users can toggle this in the toolbar.`,showViewsButton:`Show the calendar/board view toggle button in the toolbar.`,viewsButtonStyle:`'primary' or 'secondary' visual style for the view toggle.`,showExportButton:`Show the CSV export/download button in the table toolbar.`,exportButtonIcon:`Icon name from https://lucide.dev/icons/ for the export button (e.g. 'download', 'import').`,keyName:`Label for the key/title field in board items (e.g. 'Task', 'Name').`,valueName:`Label for the value/description field in board items (e.g. 'Notes', 'Details').`},hideInnerLoader:!0})]})})]})]},`${e.id}-${t._uiKey||t.id}`)};return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex flex-col relative`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-3 mb-2 border-b border-[var(--panel-border)]/50 pb-4`,children:[(0,l.jsx)(`div`,{className:`w-8 h-8 rounded-xl glass-panel border border-[var(--panel-border)] flex items-center justify-center -ml-1 shadow-sm`,children:(0,l.jsx)(s,{className:`w-4 h-4 text-accent`})}),(0,l.jsx)(`h2`,{className:`text-xl font-extrabold tracking-tight text-foreground`,children:e.title})]}),(0,l.jsx)(`p`,{className:`text-[13px] leading-relaxed text-foreground/50 font-medium max-w-3xl mb-4 ml-[2px]`,children:e.description}),o.length===0?(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 opacity-40 glass-panel rounded-2xl border border-[var(--panel-border)]/50 border-dashed`,children:[(0,l.jsx)(n.L,{className:`w-5 h-5 mb-2`}),(0,l.jsx)(`p`,{className:`text-[12px] font-bold`,children:`This section is currently empty.`})]}):(0,l.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[f.map(e=>_(e,o.findIndex(t=>t.id===e.id),!1)),p.length>0&&(0,l.jsxs)(`details`,{className:`mt-4 group/details`,children:[(0,l.jsxs)(`summary`,{className:`text-[11px] font-bold uppercase tracking-wider text-foreground/40 cursor-pointer list-none flex items-center gap-2 select-none hover:text-foreground/70 transition-colors w-fit pb-1 ml-1 outline-none`,children:[(0,l.jsx)(n.st,{className:`w-3.5 h-3.5 group-open/details:-rotate-180 transition-transform`}),`Hidden pages (`,p.length,`)`]}),(0,l.jsx)(`div`,{className:`flex flex-col gap-4 mt-4`,children:p.map(e=>_(e,o.findIndex(t=>t.id===e.id),!0))})]})]}),t<de.length-1&&(0,l.jsx)(`div`,{className:`w-full border-t border-[var(--panel-border)]/70 my-10`})]},e.id)})]})]})]}),(0,l.jsx)(te,{isOpen:X,onCancel:()=>Z(!1),onConfirm:async()=>{pe(!0);try{let{deleteDoc:e}=await import(`firebase/firestore`);await Promise.all([e((0,o.doc)(n.Tt,`sys_pages`,`home`))]),k(S)}catch(e){console.error(`Error resetting defaults:`,e)}setTimeout(()=>{pe(!1),Z(!1)},1e3)},title:`Reset System Pages`,message:`Are you sure you want to reset all system page configurations? Custom pages and their order will remain intact.`,confirmText:`Reset`,isProcessing:fe}),(0,l.jsx)(te,{isOpen:!!C,onCancel:()=>w(null),onConfirm:le,title:`Delete Page`,message:`Are you sure you want to delete this page? This action cannot be undone and will remove all associated configurations.`,confirmText:`Remove Page`,isProcessing:T})]})}var Qt={contact:r.t,support:i.t};function $t(){let{userRole:e}=m(),t=(0,u.useNavigate)();(0,u.useLocation)();let[r,i]=(0,a.useState)({}),[s,c]=(0,a.useState)(!0),[d,f]=(0,a.useState)({}),p=n.Ct(),h=()=>({...Qt,contact:p?.defaultConfigs?.contactForm||Qt.contact,support:p?.defaultConfigs?.supportForm||Qt.support}),[g,_]=(0,a.useState)(null),[v,y]=(0,a.useState)({}),[b,x]=(0,a.useState)(null),[S,C]=(0,a.useState)(!1),[w,T]=(0,a.useState)(null),E=(e,t)=>{let n;n=e===`contact`?`export const contactFormConfig = ${JSON.stringify(t,null,2)};\n`:e===`support`?`export const supportFormConfig = ${JSON.stringify(t,null,2)};\n`:JSON.stringify(t,null,2),navigator.clipboard.writeText(n),T(e),setTimeout(()=>T(null),2e3)};(0,a.useEffect)(()=>{D()},[]);let D=async()=>{try{let e=await(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)),t={};e.forEach(e=>{if(e.id!==`pubForm`&&e.id!==`userForm`){let n=e.data();n._uiKey||=Math.random().toString(36).substring(7),t[e.id]=n}});try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,`pubForm`)),await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,`userForm`))}catch{}let r=h();for(let[e,i]of Object.entries(r))if(!t[e]){await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),i);let r={...i};r._uiKey=Math.random().toString(36).substring(7),t[e]=r}else if(!t[e].fields||t[e].fields.length===0){let i=r[e];t[e].fields=i.fields||[],await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),t[e])}let a=window.location.pathname.split(`/forms/`)[1]?.split(`/`)[0];a&&t[a]&&y({[a]:!0}),i(t)}catch(e){console.error(`Failed to load forms:`,e)}finally{c(!1)}},O=async(e,t)=>{let a={...t};r[e]?._uiKey&&(a._uiKey=r[e]._uiKey),e===`contact`?(a.systemName=`contact`,a.formType=`public`,a.submitPage=`submissions`):e===`support`&&(a.systemName=`support`,a.formType=`private`,a.submitPage=`requests`);let s=a.systemName||e;if(s!==e&&s.trim()!==``){i(t=>{let n={};for(let r of Object.keys(t))r===e?n[s]=a:n[r]=t[r];return n}),v[e]&&y(t=>{let n={};for(let r of Object.keys(t))r===e?n[s]=t[r]:n[r]=t[r];return n}),f(e=>({...e,[s]:!0}));try{await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,s),a),await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,e))}catch(e){console.error(`Failed to migrate form map ID:`,e)}finally{setTimeout(()=>{f(e=>({...e,[s]:!1}))},500)}}else{i(t=>({...t,[e]:a})),f(t=>({...t,[e]:!0}));try{await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),a)}catch(e){console.error(`Failed to save form:`,e)}finally{setTimeout(()=>{f(t=>({...t,[e]:!1}))},500)}}},[k,A]=(0,a.useState)(!1),j=async()=>{if(k)return;A(!0);let e=`new_form_${Date.now().toString().slice(-4)}`,r={title:`New Custom Form`,systemName:e,formType:`public`,submitPage:`submissions`,redirectTo:``,submitText:`Submit`,fields:[],enabled:!0,_uiKey:Math.random().toString(36).substring(7)};try{f(t=>({...t,[e]:!0})),await(0,o.setDoc)((0,o.doc)(n.Tt,`sys_forms`,e),r),i(t=>({[e]:r,...t})),y(t=>({[e]:!0,...t})),t(`/forms/${e}`)}catch(e){console.error(`Failed to create form`,e)}finally{f(t=>({...t,[e]:!1})),A(!1)}},ne=async e=>{if(!(e===`contact`||e===`support`)){C(!0);try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,e)),i(t=>{let n={...t};return delete n[e],n}),t(`/forms`)}catch(e){console.error(`Failed to delete form`,e)}finally{C(!1),x(null)}}};if(e!==`admin`)return(0,l.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1`,children:[(0,l.jsx)(n.p,{className:`w-12 h-12 text-red-500 mb-4`}),(0,l.jsx)(`h2`,{className:`text-2xl font-bold bg-clip-text text-transparent bg-gradient-to-br from-red-400 to-red-600`,children:`Access Restricted`}),(0,l.jsx)(`p`,{className:`text-foreground/60 max-w-sm text-center mt-2 font-medium leading-relaxed`,children:`This area is exclusively for system administrators.`})]})});let M=e=>{y(t=>{let n={...t,[e]:!t[e]};if(n[e])window.history.replaceState(null,``,`/forms/${e}`);else{let e=Object.keys(n).filter(e=>n[e]);e.length>0?window.history.replaceState(null,``,`/forms/${e[0]}`):window.history.replaceState(null,``,`/forms`)}return n})},N=Object.keys(v).find(e=>v[e]);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Forms`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/forms`,N?`/${N}`:``]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(`div`,{className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-6 mb-6 pb-6 border-b border-[var(--panel-border)]/50 relative z-10 shrink-0 px-6 pt-6 md:px-10 md:pt-10 bg-background/50`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Custom Forms`}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60 mt-2 leading-relaxed`,children:`This is the central page where you configure and manage your application's forms. Easily add and customize the fields for your users.`})]}),(0,l.jsx)(`div`,{className:`relative z-50 shrink-0 flex items-center justify-end`,children:(0,l.jsx)(n.n,{variant:`secondary`,onClick:j,title:`Add Custom Form`,disabled:k,className:`w-10 h-10 p-0 border-transparent bg-transparent hover:bg-foreground/5 rounded-xl flex items-center justify-center shrink-0 transition-colors group cursor-pointer`,children:k?(0,l.jsx)(n.M,{className:`w-4 h-4 text-foreground/60 animate-spin`}):(0,l.jsx)(n.C,{className:`w-4 h-4 text-foreground/60 group-hover:text-foreground transition-colors`})})})]}),(0,l.jsx)(`div`,{className:`p-6 md:p-8 flex flex-col gap-4 overflow-y-auto`,children:s?(0,l.jsx)(`div`,{className:`flex items-center justify-center p-12 glass-panel rounded-3xl border border-[var(--panel-border)]`,children:(0,l.jsx)(n.M,{className:`w-6 h-6 animate-spin text-accent`})}):Object.keys(r).length===0?(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center p-12 glass-panel rounded-3xl border border-[var(--panel-border)] border-dashed opacity-50`,children:[(0,l.jsx)(n.S,{className:`w-6 h-6 mb-3 text-foreground/40`}),(0,l.jsx)(`p`,{className:`text-[13px] font-bold`,children:`No forms currently configured.`})]}):(0,l.jsx)(n.a,{children:Object.entries(r).map(([e,t])=>{let r=v[e],i=d[e];return(0,l.jsxs)(n.i.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,y:-10},onClick:()=>M(e),className:`group flex flex-col p-3 px-4 glass-panel border transition-all rounded-2xl hover:shadow-sm cursor-pointer hover:border-accent/40 ${r?`border-[var(--panel-border)] bg-background/50`:`border-transparent hover:border-[var(--panel-border)]`} flex-shrink-0 ${t.enabled===!1?`opacity-40 grayscale bg-foreground/[0.01] border-[var(--panel-border)]/50`:``}`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between w-full`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col gap-1 w-full sm:w-auto pr-4`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`h3`,{className:`text-[14px] font-bold text-foreground break-words ml-1 leading-snug`,children:t.title||`Untitled Form`}),i&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-accent ml-2 shrink-0`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5 ml-1`,children:[(0,l.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest border border-[var(--panel-border)] bg-foreground/5 text-foreground/60 px-2 py-0.5 rounded-md`,children:t.systemName||e}),(0,l.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest border px-2 py-0.5 rounded-md shrink-0 ${t.formType===`private`?`text-blue-500 bg-blue-500/10 border-blue-500/20`:`text-green-500 bg-green-500/10 border-green-500/20`}`,children:t.formType||`public`})]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-4 w-full sm:w-auto justify-end mt-2 sm:mt-0 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:e=>{e.stopPropagation(),_(t)},className:`p-1.5 hover:bg-accent/10 text-foreground/40 hover:text-accent transition-colors rounded-lg flex items-center justify-center mr-2`,title:`Preview Form`,children:(0,l.jsx)(n.K,{className:`w-4 h-4`})}),e!==`contact`&&e!==`support`?(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),x(e)},className:`p-1.5 hover:bg-red-500/10 text-foreground/30 hover:text-red-500 transition-colors rounded-lg opacity-0 group-hover:opacity-100 flex items-center justify-center mr-2`,title:`Delete Form`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}):(0,l.jsx)(`div`,{className:`w-7 mr-2 shrink-0`}),(0,l.jsx)(`div`,{className:`p-1.5 transition-transform duration-300 text-foreground/40 ${r?`rotate-180`:``}`,children:(0,l.jsx)(`svg`,{width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,l.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})})]})]}),(0,l.jsx)(n.a,{children:r&&(0,l.jsx)(n.i.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4 pt-4 border-t border-[var(--panel-border)]/50`,onClick:e=>e.stopPropagation(),children:(0,l.jsxs)(`div`,{className:`flex flex-col font-mono text-[13px] leading-relaxed relative bg-background/50 p-4 rounded-xl border border-[var(--panel-border)] shadow-inner`,children:[(0,l.jsxs)(`div`,{className:`absolute top-4 right-4 flex items-center gap-1 z-20`,children:[(0,l.jsx)(`button`,{onClick:async t=>{if(t.stopPropagation(),e===`contact`||e===`support`){f(t=>({...t,[e]:!0}));try{await(0,o.deleteDoc)((0,o.doc)(n.Tt,`sys_forms`,e)),localStorage.removeItem(`fbos_form_${e}`),await D()}catch(e){console.error(`Reset failed:`,e)}setTimeout(()=>f(t=>({...t,[e]:!1})),500)}else O(e,h()[e]||h().contact)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-red-500/10 rounded-lg flex items-center justify-center shrink-0 transition-colors group`,title:`Reset to Defaults`,children:i?(0,l.jsx)(n.M,{className:`w-3.5 h-3.5 text-red-500 animate-spin`}):(0,l.jsx)(n.x,{className:`w-3.5 h-3.5 text-foreground/40 group-hover:text-red-500 transition-colors`})}),(0,l.jsx)(`button`,{onClick:n=>{n.stopPropagation(),E(e,t)},className:`w-8 h-8 p-0 border-transparent bg-transparent hover:bg-foreground/10 rounded-lg flex items-center justify-center shrink-0 transition-colors`,title:`Copy JSON`,children:w===e?(0,l.jsx)(n.nt,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.Z,{className:`w-3.5 h-3.5 text-foreground/40 hover:text-foreground transition-colors`})})]}),(0,l.jsx)(Ut,{value:{systemName:t.systemName||e,formType:t.formType||`public`,submitPage:t.submitPage||(t.formType===`private`?`requests`:`submissions`),redirectTo:t.redirectTo||``,title:t.title||``,buttonName:t.buttonName||t.submitText||``,fields:t.fields||[]},keysToRender:[`systemName`,`formType`,`submitPage`,`redirectTo`,`title`,`buttonName`,`fields`],meta:{formType:t.formType||`public`},onChange:n=>{n.formType===t.formType?n.submitPage!==t.submitPage&&(n.formType=n.submitPage===`requests`?`private`:`public`):n.submitPage=n.formType===`public`?`submissions`:`requests`,O(e,{...t,...n,submitText:n.buttonName})},isLast:!0,isGlobalSaving:i,disabledKeys:e===`contact`||e===`support`?[`systemName`,`formType`,`submitPage`]:[],customEnums:{type:[`text`,`email`,`tel`,`textarea`,`number`,`select`,`checkbox`,`currency`,`age`]},customExplanations:{formType:e===`contact`?`Public means its for not signed in users. Private is disabled for contact so don't allow the user to change it.`:e===`support`?`This means that the form is available to signed in users only.`:`Public means it's for non-signed in users.`,submitPage:e===`contact`?`Means the form submissions go to this folder. User can't change that since it's directly linked. Public is tied to submissions.`:e===`support`?`Can't change since all private forms go there.`:`Where to route data submissions.`,redirectTo:`If not added form will just show a success message. If added, in 30 seconds after success user is redirected.`}})]})})})]},t._uiKey||e)})})})]})]}),(0,l.jsx)(te,{isOpen:!!b,onCancel:()=>x(null),onConfirm:()=>{b&&ne(b)},title:`Delete Form`,message:`Are you sure you want to permanently delete "${b}"? This action cannot be reversed.`,confirmText:`Delete form`,isProcessing:S}),g&&(0,l.jsx)(n.t,{formConfig:g,onClose:()=>_(null)})]})}function en({config:e,customContent:t}){let{config:r}=n.xt(),[i,s]=(0,a.useState)(!1),[c,u]=(0,a.useState)(null),[d,f]=(0,a.useState)([]);(0,a.useEffect)(()=>{document.title=e.pageName||e.pageTitle||r.appName||`Firebase OS`,(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{f(e.docs.filter(e=>e.data().formType===`public`).map(e=>e.id))})},[e.pageName,e.pageTitle,r.appName]);let p=ie(e,d);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 relative min-h-screen`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.pageTitle||e.pageName||`New Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]}),(0,l.jsxs)(`div`,{className:`flex justify-between items-center mb-6 pt-2 border-b border-[var(--panel-border)] pb-6 relative z-20 overflow-x-auto no-scrollbar gap-4`,children:[(0,l.jsxs)(`button`,{onClick:()=>window.history.back(),className:`px-5 py-2 border border-[var(--panel-border)] rounded-xl text-[13px] font-bold hover:bg-foreground/5 transition-all flex items-center gap-2 cursor-pointer shadow-sm text-foreground/70 whitespace-nowrap shrink-0`,children:[(0,l.jsx)(n.gt,{className:`w-4 h-4`}),` Go Back`]}),(0,l.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[e.copyPrompt&&(0,l.jsxs)(`button`,{onClick:()=>{navigator.clipboard.writeText(p),s(!0),setTimeout(()=>s(!1),2e3)},title:`Copy Developer Prompt`,className:`px-6 py-2.5 rounded-xl border border-[var(--panel-border)] bg-background flex items-center gap-2 hover:bg-foreground/5 hover:text-accent transition-all cursor-pointer text-[14px] font-bold tracking-wide shadow-sm whitespace-nowrap`,children:[(0,l.jsx)(n.ft,{className:`w-4 h-4`}),(0,l.jsx)(`span`,{className:`hidden sm:inline`,children:i?`Copied!`:`Copy Prompt`})]}),e.showButton&&(0,l.jsx)(`button`,{onClick:()=>{e.action===`redirect`?window.location.href=e.url||`/`:e.action===`form`&&u(e.form||`contact`)},className:`px-6 py-2.5 rounded-xl font-bold tracking-wide transition-all duration-300 flex items-center justify-center btn-primary shadow-xl hover:-translate-y-1 active:scale-95 text-[14px] whitespace-nowrap`,children:e.buttonText||`Action Button`})]})]}),(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl shadow-2xl relative flex flex-col flex-1 bg-background/50 h-full min-h-[400px]`,children:t?(0,l.jsx)(`div`,{className:`flex-1 p-4 md:p-8`,children:(0,l.jsx)(t,{config:e})}):(0,l.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center opacity-40 glass-panel border border-[var(--panel-border)]/50 border-dashed m-4 md:m-8 rounded-2xl p-8 py-20 text-center`,children:[(0,l.jsx)(n.ft,{className:`w-8 h-8 md:w-12 md:h-12 mb-4 text-foreground/80 opacity-50`}),(0,l.jsx)(`p`,{className:`text-[14px] font-bold mb-2`,children:`Click copy prompt at the top to start adding changes`}),(0,l.jsx)(`div`,{className:`mt-8 text-left bg-background p-6 rounded-2xl text-[12px] font-mono whitespace-pre-wrap max-w-2xl border border-[var(--panel-border)]/50 text-foreground/60 shadow-inner`,children:p})]})}),(0,l.jsx)(n.a,{children:c&&(0,l.jsx)(n.t,{onClose:()=>u(null),formId:c})})]})}function tn({config:e,customContent:t}){let{user:r}=m(),{config:i}=n.xt(),[s,u]=(0,a.useState)([]),[f,p]=(0,a.useState)(!0),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(``),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(null),T=(0,a.useRef)(null),[E,D]=(0,a.useState)(!1),[O,k]=(0,a.useState)(!1),[A,j]=(0,a.useState)(null),[ne,M]=(0,a.useState)(null),N=e=>{if(M(e),e){let t=e.fileType||``;I(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},P=ne,[F,I]=(0,a.useState)(!0),[L,R]=(0,a.useState)(!1),[z,re]=(0,a.useState)(null),[B,ie]=(0,a.useState)(``),[V,ae]=(0,a.useState)(``),[H,U]=(0,a.useState)([]),W=(0,a.useRef)(null),oe=(e.tabName||e.pageId||`private_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),G=`user_${oe}_records`;(0,a.useEffect)(()=>{document.title=e.tabTitle||e.tabName||i.appName||`Firebase OS`,(0,o.getDocs)((0,o.collection)(n.Tt,`sys_forms`)).then(e=>{})},[e.tabTitle,e.tabName,i.appName]),(0,a.useEffect)(()=>{if(!r)return;try{let e=localStorage.getItem(`fbos_records_${G}`);e?(u(JSON.parse(e)),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}});(async()=>{try{let t=e((await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,G),(0,o.where)(`uid`,`==`,r.uid),(0,o.limit)(150)))).docs);t.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),u(t),p(!1),localStorage.setItem(`fbos_records_${G}`,JSON.stringify(t))}catch(e){console.error(`Error fetching records:`,e),p(!1)}})()},[r,G]),(0,a.useEffect)(()=>{f||localStorage.setItem(`fbos_records_${G}`,JSON.stringify(s))},[s,f,G]);let K=async e=>{if(e.preventDefault(),!(!r||!_.trim())){S(!0);try{let e=await(0,o.addDoc)((0,o.collection)(n.Tt,G),{name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,createdAt:(0,o.serverTimestamp)()});u(t=>[{id:e.id,name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,createdAt:Date.now()},...t]),v(``),b(``),g(!1)}catch(e){console.error(`Error saving record:`,e)}S(!1)}},se=async e=>{let t=e.target.files?.[0];if(!(!t||!r)){k(!0);try{let e=`user_files/${`${Date.now()}_${t.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,i=(0,c.ref)(n.Dt,e);await(0,c.uploadBytes)(i,t,{customMetadata:{ownerId:r.uid}});let a=await(0,c.getDownloadURL)(i);if(T.current)T.current(t,a,{uid:r.uid,storagePath:e});else{await(0,o.addDoc)((0,o.collection)(n.Tt,`user_files`),{fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:a,uid:r.uid,uploaderEmail:r.email||`user`,sourceTab:oe,accessPrefix:`user_`,createdAt:(0,o.serverTimestamp)()});let e=await(0,o.addDoc)((0,o.collection)(n.Tt,G),{name:t.name,note:`${t.type||`File`} · ${be(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:a,createdAt:(0,o.serverTimestamp)()});u(n=>[{id:e.id,name:t.name,note:`${t.type||`File`} · ${be(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type,fileSize:t.size,downloadURL:a,createdAt:Date.now()},...n])}}catch(e){console.error(`Error uploading file:`,e)}k(!1),W.current&&(W.current.value=``)}},q=async()=>{if(A){R(!0);try{let e=s.find(e=>e.id===A);if(await(0,o.deleteDoc)((0,o.doc)(n.Tt,G,A)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`user_files%2F`)[1]?.split(`?`)[0];t&&await(0,c.deleteObject)((0,c.ref)(n.Dt,`user_files/${decodeURIComponent(t)}`)).catch(()=>{});let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`user_files`),(0,o.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of r.docs)await(0,o.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up user file:`,e)}u(e=>e.filter(e=>e.id!==A)),j(null)}catch(e){console.error(`Error deleting record:`,e)}R(!1)}},[J,ce]=(0,a.useState)(null),[le,ue]=(0,a.useState)(``),[de,X]=(0,a.useState)(!1),[Z,fe]=(0,a.useState)(null),pe=(0,a.useRef)([]),me=e=>{if(e.recordType===`file`){ce(e.id),ue(e.name);return}re(e.id),ie(e.name),ae(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),pe.current=n.map(e=>e.key)},he=async()=>{if(!J||!le.trim()){ce(null);return}let e=s.find(e=>e.id===J);if(e&&e.name===le.trim()){ce(null);return}X(!0);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,G,J),{name:le.trim()}),u(e=>e.map(e=>e.id===J?{...e,name:le.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}X(!1),ce(null)},Q=async()=>{await ge(),re(null)},ge=async()=>{if(!z||!B.trim())return;S(!0);let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=pe.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,G,z),{name:B.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==z)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})),pe.current=t}catch(e){console.error(`Error saving record:`,e)}S(!1)},_e=(e,t)=>e?e.startsWith(`image/`)?t?(0,l.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${t})`}}):(0,l.jsx)(n.V,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,l.jsx)(n.l,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,l.jsx)(n.G,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,l.jsx)(n._t,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,l.jsx)(n.Q,{className:`w-4 h-4`}):(0,l.jsx)(n.W,{className:`w-4 h-4`}):(0,l.jsx)(n.G,{className:`w-4 h-4`}),ve=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`,ye=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)},be=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},xe=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},Se=Y(e,G),Ce=()=>{navigator.clipboard.writeText(Se),D(!0),setTimeout(()=>D(!1),2e3)},we=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),r=t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return n.o[r]?n.o[r]:n.o[t]?n.o[t]:n.f||n.C})(),Te=e.buttonStyle!==`secondary`,Ee=e.buttonStorageStyle===`primary`;return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Private Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${s.length} ${s.length===1?`item`:`items`}`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:Ce,title:E?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${E?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:E?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),e.storage!==!1&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`input`,{type:`file`,ref:W,onChange:se,className:`hidden`}),(0,l.jsxs)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:O,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`} ${Ee?`btn-primary`:`btn-secondary`}`,children:[O?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(we,{className:`w-4 h-4`}),e.buttonStorageText&&(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>g(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${Te?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,l.jsx)(n.C,{className:`w-4 h-4`}):(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),t?(0,l.jsx)(t,{config:e,actions:{records:s,loading:f,collection:G,user:r,saveRecord:async e=>{await(0,o.addDoc)((0,o.collection)(n.Tt,G),{uid:r.uid,recordType:`record`,createdAt:(0,o.serverTimestamp)(),...e})},deleteRecord:async e=>{await(0,o.deleteDoc)((0,o.doc)(n.Tt,G,e))},uploadFile:()=>W.current?.click(),openAddForm:()=>g(!0),setAddForm:e=>w(()=>e),setFileHandler:e=>{T.current=e}}}):(0,l.jsxs)(l.Fragment,{children:[!f&&s.length===0&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,l.jsx)(n.C,{className:`w-6 h-6 text-accent/40`})}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files to get started`})]}),!f&&s.length>0&&(0,l.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,l.jsx)(n.a,{children:s.map((e,t)=>{let r=z===e.id;return(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},transition:{delay:t*.03,duration:.25},onClick:()=>me(e),className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative cursor-pointer ${r?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,l.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),fe(e.id),setTimeout(()=>fe(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:Z===e.id?(0,l.jsx)(n.ct,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-3.5 h-3.5`})})]}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),me(e)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,l.jsx)(n.w,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),j(e.id)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-3.5 h-3.5`})})]}),(0,l.jsxs)(`div`,{className:`flex items-start gap-3 mb-3`,children:[(0,l.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&N(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 ${ve(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?_e(e.fileType,e.downloadURL):(0,l.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[J===e.id?(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,value:le,onChange:e=>ue(e.target.value),onBlur:()=>he(),onKeyDown:e=>{e.key===`Enter`&&he(),e.key===`Escape`&&ce(null)},onClick:e=>e.stopPropagation(),className:`no-glow text-[14px] font-bold text-foreground bg-transparent border-b border-accent/30 outline-none pb-0.5 w-full pr-12`}):(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>N(e)}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:xe(e.createdAt)})]})]}),e.note&&(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),Object.entries(e).filter(([e])=>![`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`].includes(e)&&e!==`id`).slice(0,3).map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,l.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e))]},e.id)})})})]})]}),!t&&(0,l.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,l.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,l.jsx)(n.B,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,l.jsxs)(`span`,{children:[`Each user sees their own data only · Edit and delete available on all items · Records: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:G}),` · Files: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`user_files`}),` → Drive / Private`]})]})})]})]}),(0,l.jsx)(n.a,{children:h&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!x&&g(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:C?a.default.createElement(C,{onSave:async e=>{S(!0);try{await(0,o.addDoc)((0,o.collection)(n.Tt,G),{uid:r.uid,recordType:`record`,createdAt:(0,o.serverTimestamp)(),...e}),g(!1)}catch(e){console.error(`Error saving record:`,e)}S(!1)},onClose:()=>!x&&g(!1),saving:x}):(0,l.jsxs)(`form`,{onSubmit:K,className:`p-5 flex flex-col gap-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>!x&&g(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:_,onChange:e=>v(e.target.value),placeholder:`Name *`,disabled:x,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),placeholder:`Note (optional)`,disabled:x,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:x,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:x?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,d.createPortal)((0,l.jsx)(n.a,{children:P&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,l.jsx)(n.i.div,{onClick:()=>N(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(`button`,{onClick:()=>N(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-[var(--panel-border)]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 bg-background/80 backdrop-blur-md border-b border-[var(--panel-border)] shrink-0 shadow-sm z-20`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:P.fileName||P.name}),(0,l.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[ye(P.fileType),` • `,be(P.fileSize||0)]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(P.downloadURL),fe(`preview`),setTimeout(()=>fe(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:Z===`preview`?(0,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{N(null),ce(P.id),ue(P.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{N(null),j(P.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),(0,l.jsx)(`a`,{href:P.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>N(null),children:(0,l.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[F&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-background/80 backdrop-blur-md shadow-xl flex items-center justify-center border border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})})}),P.fileType?.startsWith(`image/`)?(0,l.jsx)(`img`,{onLoad:()=>I(!1),onError:()=>I(!1),src:P.downloadURL,alt:P.fileName||P.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 ${F?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):P.fileType?.startsWith(`video/`)?(0,l.jsx)(`video`,{onLoadedData:()=>I(!1),onError:()=>I(!1),src:P.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 ${F?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):P.fileType===`application/pdf`?(0,l.jsx)(`iframe`,{onLoad:()=>I(!1),src:P.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${F?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,l.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center text-foreground/40 text-center relative z-10`,onClick:e=>{e.stopPropagation(),I(!1)},children:[(0,l.jsx)(n.G,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,l.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,l.jsx)(`span`,{className:`text-[14px] mt-2 text-foreground/60 font-medium max-w-xs`,children:`This file format cannot be previewed. Please download it instead.`})]})]})})]})]})}),document.body),(0,l.jsx)(n.a,{children:z&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>Q(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[440px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),x&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>Q(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NAME`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`input`,{autoFocus:!0,required:!0,value:B,onChange:e=>ie(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>ge(),placeholder:`Name *`,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NOTE`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{ae(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:()=>ge(),placeholder:`Add a note...`,rows:1,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50 resize-none overflow-hidden`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),H.map((e,t)=>(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let n=[...H];n[t].key=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>ge(),className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none placeholder:text-foreground/15 pt-3 pb-0.5 caret-foreground/40`}),(0,l.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let n=[...H];n[t].value=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>ge(),className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pt-1.5 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>U(H.filter((e,n)=>n!==t)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})})]},t)),(0,l.jsxs)(`button`,{type:`button`,onClick:()=>U([...H,{key:``,value:``}]),className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground/25 hover:text-foreground/40 transition-colors cursor-pointer mt-4 mb-4`,children:[(0,l.jsx)(n.C,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,l.jsx)(te,{isOpen:!!A,onCancel:()=>j(null),onConfirm:q,title:`Delete Record`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:s.find(e=>e.id===A)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:L})]})}function nn({config:e,customContent:t}){let{user:r}=m(),{config:i}=n.xt(),[s,u]=(0,a.useState)([]),[f,p]=(0,a.useState)(!0),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(``),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(null),T=(0,a.useRef)(null),[E,D]=(0,a.useState)(!1),[O,k]=(0,a.useState)(!1),[A,j]=(0,a.useState)(null),[ne,M]=(0,a.useState)(null),N=e=>{if(M(e),e){let t=e.fileType||``;I(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},P=ne,[F,I]=(0,a.useState)(!0),[L,R]=(0,a.useState)(!1),[z,re]=(0,a.useState)(null),[B,ie]=(0,a.useState)(``),[V,ae]=(0,a.useState)(``),[H,U]=(0,a.useState)([]),W=(0,a.useRef)(null),[oe,G]=(0,a.useState)(null),K=(0,a.useRef)([]),se=(e.tabName||e.pageId||`admin_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),q=`admin_${se}_records`;(0,a.useEffect)(()=>{document.title=e.tabTitle||e.tabName||i.appName||`Firebase OS`},[e.tabTitle,e.tabName,i.appName]);let Y=()=>({name:r.displayName||r.email?.split(`@`)[0]||`Admin`,email:r.email||``,avatar:r.photoURL||``});(0,a.useEffect)(()=>{if(!r)return;try{let e=localStorage.getItem(`fbos_records_${q}`);e?(u(JSON.parse(e)),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}}),t=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,q),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(150)),t=>{let n=e(t.docs);u(n),p(!1),localStorage.setItem(`fbos_records_${q}`,JSON.stringify(n))},t=>{console.error(`Error listening to admin records:`,t);let r=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,q),(0,o.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),u(n),p(!1),localStorage.setItem(`fbos_records_${q}`,JSON.stringify(n))});return()=>r()});return()=>t()},[r,q]);let ce=async e=>{if(e.preventDefault(),!(!r||!_.trim())){S(!0);try{let e=Y();await(0,o.addDoc)((0,o.collection)(n.Tt,q),{name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()}),v(``),b(``),g(!1)}catch(e){console.error(`Error saving admin record:`,e)}S(!1)}},le=async e=>{let t=e.target.files?.[0];if(!(!t||!r)){k(!0);try{let e=`admin_files/${`${Date.now()}_${t.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,i=(0,c.ref)(n.Dt,e);await(0,c.uploadBytes)(i,t,{customMetadata:{ownerId:r.uid}});let a=await(0,c.getDownloadURL)(i);if(T.current)T.current(t,a,{uid:r.uid,storagePath:e});else{let e=Y();await(0,o.addDoc)((0,o.collection)(n.Tt,`admin_files`),{fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:a,uid:r.uid,uploaderEmail:r.email||`admin`,sourceTab:se,accessPrefix:`admin_`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()}),await(0,o.addDoc)((0,o.collection)(n.Tt,q),{name:t.name,note:`${t.type||`File`} · ${xe(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:a,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()})}}catch(e){console.error(`Error uploading admin file:`,e)}k(!1),W.current&&(W.current.value=``)}},ue=async()=>{if(A){R(!0);try{let e=s.find(e=>e.id===A);if(await(0,o.deleteDoc)((0,o.doc)(n.Tt,q,A)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`admin_files%2F`)[1]?.split(`?`)[0];t&&await(0,c.deleteObject)((0,c.ref)(n.Dt,`admin_files/${decodeURIComponent(t)}`)).catch(()=>{});let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`admin_files`),(0,o.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of r.docs)await(0,o.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up admin file:`,e)}j(null)}catch(e){console.error(`Error deleting admin record:`,e)}R(!1)}},[de,X]=(0,a.useState)(null),[Z,fe]=(0,a.useState)(``),[pe,me]=(0,a.useState)(!1),he=e=>{if(e.recordType===`file`){X(e.id),fe(e.name);return}re(e.id),ie(e.name),ae(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),K.current=n.map(e=>e.key)},Q=async()=>{if(!de||!Z.trim()){X(null);return}let e=s.find(e=>e.id===de);if(e&&e.name===Z.trim()){X(null);return}me(!0);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,de),{name:Z.trim()}),u(e=>e.map(e=>e.id===de?{...e,name:Z.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}me(!1),X(null)},ge=async()=>{if(!z||!B.trim()){re(null);return}S(!0);let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=K.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,z),{name:B.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==z)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})),K.current=t}catch(e){console.error(`Error updating record:`,e)}S(!1),re(null)},_e=async()=>{if(!z||!B.trim())return;let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=K.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,q,z),{name:B.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==z)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})),K.current=t}catch(e){console.error(`Error silently saving record:`,e)}},ve=(e,t)=>e?e.startsWith(`image/`)?t?(0,l.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${t})`}}):(0,l.jsx)(n.V,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,l.jsx)(n.l,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,l.jsx)(n.G,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,l.jsx)(n._t,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,l.jsx)(n.Q,{className:`w-4 h-4`}):(0,l.jsx)(n.W,{className:`w-4 h-4`}):(0,l.jsx)(n.G,{className:`w-4 h-4`}),ye=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`,be=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)},xe=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]},Se=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},Ce=J(e,q),we=()=>{navigator.clipboard.writeText(Ce),D(!0),setTimeout(()=>D(!1),2e3)},Te=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),r=t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return n.o[r]?n.o[r]:n.o[t]?n.o[t]:n.f||n.C})(),Ee=e.buttonStyle!==`secondary`,De=e.buttonStorageStyle===`primary`,Oe=e=>e.uid===r?.uid,ke=({record:e})=>{let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||`Admin`,n=e.creatorEmail||``,r=e.creatorAvatar||``,i=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,l.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/15 text-accent flex items-center justify-center text-[8px] font-extrabold shrink-0`,children:i}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,l.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Admin Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${s.length} ${s.length===1?`item`:`items`}`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:we,title:E?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${E?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:E?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),e.storage!==!1&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`input`,{type:`file`,ref:W,onChange:le,className:`hidden`}),(0,l.jsxs)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:O,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`} ${De?`btn-primary`:`btn-secondary`}`,children:[O?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(Te,{className:`w-4 h-4`}),e.buttonStorageText&&(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>g(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${Ee?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,l.jsx)(n.C,{className:`w-4 h-4`}):(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),t?(0,l.jsx)(t,{config:e,actions:{records:s,loading:f,collection:q,user:r,saveRecord:async e=>{let t=Y();await(0,o.addDoc)((0,o.collection)(n.Tt,q),{uid:r.uid,recordType:`record`,creatorName:t.name,creatorEmail:t.email,creatorAvatar:t.avatar,createdAt:(0,o.serverTimestamp)(),...e})},deleteRecord:async e=>{await(0,o.deleteDoc)((0,o.doc)(n.Tt,q,e))},uploadFile:()=>W.current?.click(),openAddForm:()=>g(!0),setAddForm:e=>w(()=>e),setFileHandler:e=>{T.current=e}}}):(0,l.jsxs)(l.Fragment,{children:[!f&&s.length===0&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,l.jsx)(n.C,{className:`w-6 h-6 text-accent/40`})}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All admins can view and contribute.`})]}),!f&&s.length>0&&(0,l.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,l.jsx)(n.a,{children:s.map((e,t)=>{let r=z===e.id,i=Oe(e);return(0,l.jsxs)(n.i.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>he(e),className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative cursor-pointer ${r?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,l.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),G(e.id),setTimeout(()=>G(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,l.jsx)(n.ct,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-3.5 h-3.5`})})]}),i&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),he(e)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,l.jsx)(n.w,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),j(e.id)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-3.5 h-3.5`})})]})]}),(0,l.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,l.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&N(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 ${ye(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?ve(e.fileType,e.downloadURL):(0,l.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[de===e.id?(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,value:Z,onChange:e=>fe(e.target.value),onBlur:()=>Q(),onKeyDown:e=>{e.key===`Enter`&&Q(),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,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>N(e)}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:Se(e.createdAt)})]})]}),e.note&&(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),Object.entries(e).filter(([e])=>![`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`].includes(e)&&e!==`id`).slice(0,3).map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,l.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,l.jsx)(ke,{record:e})]},e.id)})})})]})]}),!t&&(0,l.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,l.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,l.jsx)(n.B,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,l.jsxs)(`span`,{children:[`Shared between all admins · Edit and delete available on your own items only · Records: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:q}),` · Files: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`admin_files`}),` → Drive / Admin`]})]})})]})]}),(0,l.jsx)(n.a,{children:h&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!x&&g(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:C?a.default.createElement(C,{onSave:async e=>{S(!0);try{let t=Y();await(0,o.addDoc)((0,o.collection)(n.Tt,q),{uid:r.uid,recordType:`record`,creatorName:t.name,creatorEmail:t.email,creatorAvatar:t.avatar,createdAt:(0,o.serverTimestamp)(),...e}),g(!1)}catch(e){console.error(`Error saving record:`,e)}S(!1)},onClose:()=>!x&&g(!1),saving:x}):(0,l.jsxs)(`form`,{onSubmit:ce,className:`p-5 flex flex-col gap-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>!x&&g(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:_,onChange:e=>v(e.target.value),placeholder:`Name *`,disabled:x,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),placeholder:`Note (optional)`,disabled:x,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:x,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:x?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,d.createPortal)((0,l.jsx)(n.a,{children:P&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,l.jsx)(n.i.div,{onClick:()=>N(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(`button`,{onClick:()=>N(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-[var(--panel-border)]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 bg-background/80 backdrop-blur-md border-b border-[var(--panel-border)] shrink-0 shadow-sm z-20`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:P.fileName||P.name}),(0,l.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[be(P.fileType),` • `,xe(P.fileSize||0)]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(P.downloadURL),G(`preview`),setTimeout(()=>G(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,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{N(null),X(P.id),fe(P.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{N(null),j(P.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),(0,l.jsx)(`a`,{href:P.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>N(null),children:(0,l.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[F&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-background/80 backdrop-blur-md shadow-xl flex items-center justify-center border border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})})}),P.fileType?.startsWith(`image/`)?(0,l.jsx)(`img`,{onLoad:()=>I(!1),onError:()=>I(!1),src:P.downloadURL,alt:P.fileName||P.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 ${F?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):P.fileType?.startsWith(`video/`)?(0,l.jsx)(`video`,{onLoadedData:()=>I(!1),onError:()=>I(!1),src:P.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 ${F?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):P.fileType===`application/pdf`?(0,l.jsx)(`iframe`,{onLoad:()=>I(!1),src:P.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${F?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,l.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center text-foreground/40 text-center relative z-10`,onClick:e=>{e.stopPropagation(),I(!1)},children:[(0,l.jsx)(n.G,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,l.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,l.jsx)(`span`,{className:`text-[14px] mt-2 text-foreground/60 font-medium max-w-xs`,children:`This file format cannot be previewed. Please download it instead.`})]})]})})]})]})}),document.body),(0,l.jsx)(n.a,{children:z&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>ge(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[440px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),x&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>ge(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NAME`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`input`,{autoFocus:!0,required:!0,value:B,onChange:e=>ie(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>_e(),placeholder:`Name *`,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NOTE`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{ae(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:()=>_e(),placeholder:`Add a note...`,rows:1,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50 resize-none overflow-hidden`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),H.map((e,t)=>(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let n=[...H];n[t].key=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>_e(),className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none placeholder:text-foreground/15 pt-3 pb-0.5 caret-foreground/40`}),(0,l.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let n=[...H];n[t].value=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>_e(),className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pt-1.5 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>U(H.filter((e,n)=>n!==t)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})})]},t)),(0,l.jsxs)(`button`,{type:`button`,onClick:()=>U([...H,{key:``,value:``}]),className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground/25 hover:text-foreground/40 transition-colors cursor-pointer mt-4 mb-4`,children:[(0,l.jsx)(n.C,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,l.jsx)(te,{isOpen:!!A,onCancel:()=>j(null),onConfirm:ue,title:`Delete Record`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:s.find(e=>e.id===A)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:L})]})}function rn({config:e,customContent:t}){let{user:r}=m(),{config:i}=n.xt(),[s,u]=(0,a.useState)([]),[f,p]=(0,a.useState)(!0),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(``),[y,b]=(0,a.useState)(``),[x,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(null),T=(0,a.useRef)(null),[E,D]=(0,a.useState)(!1),[O,k]=(0,a.useState)(!1),[A,j]=(0,a.useState)(null),[ne,M]=(0,a.useState)(null),N=e=>{if(M(e),e){let t=e.fileType||``;I(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},P=ne,[F,I]=(0,a.useState)(!0),[L,R]=(0,a.useState)(!1),[z,re]=(0,a.useState)(null),[B,ie]=(0,a.useState)(``),[V,ae]=(0,a.useState)(``),[H,U]=(0,a.useState)([]),W=(0,a.useRef)(null),[oe,G]=(0,a.useState)(null),K=(0,a.useRef)([]),se=(e.tabName||e.pageId||`shared_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),J=`mem_${se}_records`;(0,a.useEffect)(()=>{document.title=e.tabTitle||e.tabName||i.appName||`Firebase OS`},[e.tabTitle,e.tabName,i.appName]),(0,a.useEffect)(()=>{if(!r)return;try{let e=localStorage.getItem(`fbos_records_${J}`);e?(u(JSON.parse(e)),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}}),t=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,J),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(150)),t=>{let n=e(t.docs);u(n),p(!1),localStorage.setItem(`fbos_records_${J}`,JSON.stringify(n))},t=>{console.error(`Error listening to shared records:`,t);let r=(0,o.onSnapshot)((0,o.query)((0,o.collection)(n.Tt,J),(0,o.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),u(n),p(!1),localStorage.setItem(`fbos_records_${J}`,JSON.stringify(n))});return()=>r()});return()=>t()},[r,J]);let Y=()=>({name:r.displayName||r.email?.split(`@`)[0]||`Member`,email:r.email||``,avatar:r.photoURL||``}),ce=async e=>{if(e.preventDefault(),!(!r||!_.trim())){S(!0);try{let e=Y();await(0,o.addDoc)((0,o.collection)(n.Tt,J),{name:_.trim(),note:y.trim(),uid:r.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()}),v(``),b(``),g(!1)}catch(e){console.error(`Error saving shared record:`,e)}S(!1)}},le=async e=>{let t=e.target.files?.[0];if(!(!t||!r)){k(!0);try{let e=`mem_files/${`${Date.now()}_${t.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,i=(0,c.ref)(n.Dt,e);await(0,c.uploadBytes)(i,t,{customMetadata:{ownerId:r.uid}});let a=await(0,c.getDownloadURL)(i);if(T.current)T.current(t,a,{uid:r.uid,storagePath:e});else{let e=Y();await(0,o.addDoc)((0,o.collection)(n.Tt,`mem_files`),{fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:a,uid:r.uid,uploaderEmail:r.email||`member`,sourceTab:se,accessPrefix:`mem_`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()}),await(0,o.addDoc)((0,o.collection)(n.Tt,J),{name:t.name,note:`${t.type||`File`} · ${xe(t.size)}`,uid:r.uid,recordType:`file`,fileName:t.name,fileType:t.type||`unknown`,fileSize:t.size,downloadURL:a,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()})}}catch(e){console.error(`Error uploading shared file:`,e)}k(!1),W.current&&(W.current.value=``)}},ue=async()=>{if(A){R(!0);try{let e=s.find(e=>e.id===A);if(await(0,o.deleteDoc)((0,o.doc)(n.Tt,J,A)),e?.recordType===`file`&&e.downloadURL)try{let t=e.downloadURL.split(`mem_files%2F`)[1]?.split(`?`)[0];t&&await(0,c.deleteObject)((0,c.ref)(n.Dt,`mem_files/${decodeURIComponent(t)}`)).catch(()=>{});let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`mem_files`),(0,o.where)(`downloadURL`,`==`,e.downloadURL)));for(let e of r.docs)await(0,o.deleteDoc)(e.ref)}catch(e){console.error(`Error cleaning up shared file:`,e)}j(null)}catch(e){console.error(`Error deleting shared record:`,e)}R(!1)}},[de,X]=(0,a.useState)(null),[Z,fe]=(0,a.useState)(``),[pe,me]=(0,a.useState)(!1),he=e=>{if(e.recordType===`file`){X(e.id),fe(e.name);return}re(e.id),ie(e.name),ae(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),K.current=n.map(e=>e.key)},Q=async()=>{if(!de||!Z.trim()){X(null);return}let e=s.find(e=>e.id===de);if(e&&e.name===Z.trim()){X(null);return}me(!0);try{await(0,o.updateDoc)((0,o.doc)(n.Tt,J,de),{name:Z.trim()}),u(e=>e.map(e=>e.id===de?{...e,name:Z.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}me(!1),X(null)},ge=async()=>{await _e(),re(null)},_e=async()=>{if(!z||!B.trim())return;S(!0);let e={};H.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let t=H.map(e=>e.key.trim()).filter(Boolean),r=K.current.filter(e=>!t.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(n.Tt,J,z),{name:B.trim(),note:V.trim(),...e}),u(e=>e.map(e=>{if(e.id!==z)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})),K.current=t}catch(e){console.error(`Error saving record:`,e)}S(!1)},ve=(e,t)=>e?e.startsWith(`image/`)?t?(0,l.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${t})`}}):(0,l.jsx)(n.V,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,l.jsx)(n.l,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,l.jsx)(n.G,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,l.jsx)(n._t,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,l.jsx)(n.Q,{className:`w-4 h-4`}):(0,l.jsx)(n.W,{className:`w-4 h-4`}):(0,l.jsx)(n.G,{className:`w-4 h-4`}),ye=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`,be=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)},xe=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]},Se=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},Ce=(()=>{let t=(e.buttonStorageIcon||`upload`).trim(),r=t.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return n.o[r]?n.o[r]:n.o[t]?n.o[t]:n.f||n.C})(),we=e.buttonStyle!==`secondary`,Te=e.buttonStorageStyle===`primary`,Ee=e=>e.uid===r?.uid,De=q(e,J),Oe=()=>{navigator.clipboard.writeText(De),D(!0),setTimeout(()=>D(!1),2e3)},ke=({record:e})=>{let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||`Member`,n=e.creatorEmail||``,r=e.creatorAvatar||``,i=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,l.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,l.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,l.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-accent/15 text-accent flex items-center justify-center text-[8px] font-extrabold shrink-0`,children:i}),(0,l.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,l.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:e.tabTitle||e.tabName||`Shared Page`}),e.route&&(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 shadow-2xl bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,l.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${s.length} ${s.length===1?`item`:`items`} · Shared`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.showPrompt&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:Oe,title:E?`Copied!`:`Copy Developer Prompt`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${E?`bg-emerald-500/10 text-emerald-500`:`btn-secondary`}`,children:E?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.ft,{className:`w-4 h-4`})}),e.storage!==!1&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`input`,{type:`file`,ref:W,onChange:le,className:`hidden`}),(0,l.jsxs)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>W.current?.click(),disabled:O,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`} ${Te?`btn-primary`:`btn-secondary`}`,children:[O?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(Ce,{className:`w-4 h-4`}),e.buttonStorageText&&(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})]}),e.showButton!==!1&&(0,l.jsx)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>g(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${we?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,l.jsx)(n.C,{className:`w-4 h-4`}):(0,l.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,l.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,l.jsx)(n.M,{className:`w-8 h-8 text-accent animate-spin`})}),t?(0,l.jsx)(t,{config:e,actions:{records:s,loading:f,collection:J,user:r,saveRecord:async e=>{let t=Y();await(0,o.addDoc)((0,o.collection)(n.Tt,J),{uid:r.uid,recordType:`record`,creatorName:t.name,creatorEmail:t.email,creatorAvatar:t.avatar,createdAt:(0,o.serverTimestamp)(),...e})},deleteRecord:async e=>{await(0,o.deleteDoc)((0,o.doc)(n.Tt,J,e))},uploadFile:()=>W.current?.click(),openAddForm:()=>g(!0),setAddForm:e=>w(()=>e),setFileHandler:e=>{T.current=e}}}):(0,l.jsxs)(l.Fragment,{children:[!f&&s.length===0&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`flex-1 flex flex-col items-center justify-center border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-20 text-center min-h-[350px]`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-accent/5 border border-accent/10 flex items-center justify-center mb-5`,children:(0,l.jsx)(n.C,{className:`w-6 h-6 text-accent/40`})}),(0,l.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,l.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All team members can view and contribute.`})]}),!f&&s.length>0&&(0,l.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,l.jsx)(n.a,{children:s.map(e=>{let t=z===e.id,r=Ee(e);return(0,l.jsxs)(n.i.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>r?he(e):null,className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative ${r?`cursor-pointer`:``} ${t?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,l.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),G(e.id),setTimeout(()=>G(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,l.jsx)(n.ct,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`a`,{href:e.downloadURL,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`p-1.5 rounded-lg text-foreground/25 hover:text-blue-500 hover:bg-blue-500/10 transition-all`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-3.5 h-3.5`})})]}),r&&(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),he(e)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,l.jsx)(n.w,{className:`w-3.5 h-3.5`})}),(0,l.jsx)(`button`,{onClick:t=>{t.stopPropagation(),j(e.id)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-red-500 hover:bg-red-500/10 transition-all cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-3.5 h-3.5`})})]})]}),(0,l.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,l.jsx)(`div`,{onClick:t=>{t.stopPropagation(),e.recordType===`file`&&N(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 ${ye(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?ve(e.fileType,e.downloadURL):(0,l.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[de===e.id?(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,value:Z,onChange:e=>fe(e.target.value),onBlur:()=>Q(),onKeyDown:e=>{e.key===`Enter`&&Q(),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,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,l.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>N(e)}),(0,l.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:Se(e.createdAt)})]})]}),e.note&&(0,l.jsx)(`p`,{className:`text-[13px] text-foreground/55 font-medium leading-relaxed line-clamp-3 mb-1`,children:e.note}),Object.entries(e).filter(([e])=>![`name`,`note`,`uid`,`recordType`,`fileName`,`fileType`,`fileSize`,`downloadURL`,`createdAt`,`creatorName`,`creatorEmail`,`creatorAvatar`].includes(e)&&e!==`id`).slice(0,3).map(([e,t])=>(0,l.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,l.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,l.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,l.jsx)(ke,{record:e})]},e.id)})})})]})]}),!t&&(0,l.jsx)(`div`,{className:`px-6 md:px-8 py-4 border-t border-[var(--panel-border)]/30 bg-background/30 shrink-0`,children:(0,l.jsxs)(`div`,{className:`flex items-start gap-2 text-[11px] text-foreground/30 font-medium leading-relaxed`,children:[(0,l.jsx)(n.B,{className:`w-3.5 h-3.5 shrink-0 mt-0.5`}),(0,l.jsxs)(`span`,{children:[`Shared between all members · Edit and delete available on your own items only · Records: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:J}),` · Files: `,(0,l.jsx)(`code`,{className:`text-foreground/40 font-mono text-[10px]`,children:`mem_files`}),` → Drive / Shared`]})]})})]})]}),(0,l.jsx)(n.a,{children:h&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>!x&&g(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:C?a.default.createElement(C,{onSave:async e=>{S(!0);try{let t=Y();await(0,o.addDoc)((0,o.collection)(n.Tt,J),{uid:r.uid,recordType:`record`,creatorName:t.name,creatorEmail:t.email,creatorAvatar:t.avatar,createdAt:(0,o.serverTimestamp)(),...e}),g(!1)}catch(e){console.error(`Error saving record:`,e)}S(!1)},onClose:()=>!x&&g(!1),saving:x}):(0,l.jsxs)(`form`,{onSubmit:ce,className:`p-5 flex flex-col gap-3`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>!x&&g(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:_,onChange:e=>v(e.target.value),placeholder:`Name *`,disabled:x,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),placeholder:`Note (optional)`,disabled:x,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,l.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,l.jsx)(n.n,{type:`submit`,isLoading:x,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:x?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,d.createPortal)((0,l.jsx)(n.a,{children:P&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,l.jsx)(n.i.div,{onClick:()=>N(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,l.jsx)(`button`,{onClick:()=>N(null),className:`absolute top-6 right-6 z-[160] w-12 h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all cursor-pointer outline-none`,children:(0,l.jsx)(n.c,{className:`w-5 h-5`})}),(0,l.jsxs)(n.i.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col pointer-events-auto shadow-2xl rounded-3xl overflow-hidden glass-panel border border-[var(--panel-border)]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between p-6 bg-background/80 backdrop-blur-md border-b border-[var(--panel-border)] shrink-0 shadow-sm z-20`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,l.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:P.fileName||P.name}),(0,l.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[be(P.fileType),` • `,xe(P.fileSize||0)]})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(P.downloadURL),G(`preview`),setTimeout(()=>G(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,l.jsx)(n.ct,{className:`w-4 h-4 text-emerald-500`}):(0,l.jsx)(n.N,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{N(null),X(P.id),fe(P.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,l.jsx)(n.w,{className:`w-4 h-4`})}),(0,l.jsx)(`button`,{onClick:()=>{N(null),j(P.id)},className:`p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Delete`,children:(0,l.jsx)(n.h,{className:`w-4 h-4`})}),(0,l.jsx)(`a`,{href:P.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-1`,title:`Download`,children:(0,l.jsx)(n.Y,{className:`w-4 h-4`})})]})]}),(0,l.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>N(null),children:(0,l.jsxs)(`div`,{className:`absolute inset-x-4 inset-y-8 md:inset-x-12 md:inset-y-12 flex items-center justify-center`,children:[F&&(0,l.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,l.jsx)(`div`,{className:`w-12 h-12 rounded-full bg-background/80 backdrop-blur-md shadow-xl flex items-center justify-center border border-[var(--panel-border)]/50`,children:(0,l.jsx)(n.M,{className:`w-5 h-5 text-accent animate-spin`})})}),P.fileType?.startsWith(`image/`)?(0,l.jsx)(`img`,{onLoad:()=>I(!1),onError:()=>I(!1),src:P.downloadURL,alt:P.fileName||P.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 ${F?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):P.fileType?.startsWith(`video/`)?(0,l.jsx)(`video`,{onLoadedData:()=>I(!1),onError:()=>I(!1),src:P.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 ${F?`opacity-0`:`opacity-100`}`,onClick:e=>e.stopPropagation()}):P.fileType===`application/pdf`?(0,l.jsx)(`iframe`,{onLoad:()=>I(!1),src:P.downloadURL,className:`w-full h-full border-none rounded-lg relative z-10 transition-opacity duration-500 ${F?`opacity-0`:`opacity-100`}`,style:{backgroundColor:`white`},title:`PDF Preview`,onClick:e=>e.stopPropagation()}):(0,l.jsxs)(`div`,{className:`w-full h-full flex flex-col items-center justify-center text-foreground/40 text-center relative z-10`,onClick:e=>{e.stopPropagation(),I(!1)},children:[(0,l.jsx)(n.G,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,l.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,l.jsx)(`span`,{className:`text-[14px] mt-2 text-foreground/60 font-medium max-w-xs`,children:`This file format cannot be previewed. Please download it instead.`})]})]})})]})]})}),document.body),(0,l.jsx)(n.a,{children:z&&(0,l.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,l.jsx)(n.i.div,{onClick:()=>ge(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,l.jsx)(n.i.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[440px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:(0,l.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),x&&(0,l.jsx)(n.M,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>ge(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-4 h-4`})})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NAME`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`input`,{autoFocus:!0,required:!0,value:B,onChange:e=>ie(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>_e(),placeholder:`Name *`,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{readOnly:!0,value:`NOTE`,className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none pt-3 pb-0.5`}),(0,l.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{ae(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:()=>_e(),placeholder:`Add a note...`,rows:1,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50 resize-none overflow-hidden`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),H.map((e,t)=>(0,l.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,l.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let n=[...H];n[t].key=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>_e(),className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none placeholder:text-foreground/15 pt-3 pb-0.5 caret-foreground/40`}),(0,l.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let n=[...H];n[t].value=e.target.value,U(n)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>_e(),className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pt-1.5 pb-1 caret-foreground/50`}),(0,l.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,l.jsx)(`button`,{type:`button`,onClick:()=>U(H.filter((e,n)=>n!==t)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,l.jsx)(n.c,{className:`w-3 h-3`})})]},t)),(0,l.jsxs)(`button`,{type:`button`,onClick:()=>U([...H,{key:``,value:``}]),className:`flex items-center gap-1.5 text-[11px] font-medium text-foreground/25 hover:text-foreground/40 transition-colors cursor-pointer mt-4 mb-4`,children:[(0,l.jsx)(n.C,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,l.jsx)(te,{isOpen:!!A,onCancel:()=>j(null),onConfirm:ue,title:`Delete Record`,message:(0,l.jsxs)(l.Fragment,{children:[`Are you sure you want to delete `,(0,l.jsx)(`strong`,{className:`text-foreground block my-0.5 text-left overflow-hidden text-ellipsis whitespace-nowrap max-w-full`,children:s.find(e=>e.id===A)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:L})]})}function an(){let e=(0,u.useLocation)(),{user:t}=m(),r=n.Ct(),[i,s]=(0,a.useState)(null),[c,d]=(0,a.useState)(!0);(0,a.useEffect)(()=>{let t=!0,r=localStorage.getItem(`fbos_route_${e.pathname}`);if(r)try{let e=JSON.parse(r);s(e),d(!1);let t=e.pageName||e.tabName||e.title;t&&(document.title=t)}catch{}return(async()=>{try{let r=e.pathname;r.startsWith(`/`)&&(r=r.substring(1));let[i,a,c,l,u,f]=await Promise.allSettled([(0,o.getDoc)((0,o.doc)(n.Tt,`sys_pages`,r)),(0,o.getDoc)((0,o.doc)(n.Tt,`sys_tabs`,r)),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_pages`),(0,o.where)(`route`,`==`,e.pathname),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_pages`),(0,o.where)(`route`,`==`,r),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_tabs`),(0,o.where)(`route`,`==`,e.pathname),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(n.Tt,`sys_tabs`),(0,o.where)(`route`,`==`,r),(0,o.limit)(1)))]),p=null,m=null,h=(e,t)=>{if(!p&&e.status===`fulfilled`){if(e.value.exists&&e.value.exists()){let n=e.value.data();p={...n,isPrivate:t,isAdmin:n.pageType===`admin`,isShared:n.pageType===`shared`},m=e.value.id}else if(e.value.docs&&e.value.docs.length>0){let n=e.value.docs[0].data();p={...n,isPrivate:t,isAdmin:n.pageType===`admin`,isShared:n.pageType===`shared`},m=e.value.docs[0].id}}};if(h(i,!1),h(c,!1),h(l,!1),h(a,!0),h(u,!0),h(f,!0),p||(e.pathname===`/contact`?(p={route:`/contact`,template:`popup_form`,form:`contact`},m=`contact`):e.pathname===`/support`&&(p={route:`/support`,template:`popup_form`,form:`support`},m=`support`)),!t)return;if(p){if((m===`contact`||m===`support`)&&!p.form&&(p.form=m),p.pageId=m,localStorage.setItem(`fbos_route_${e.pathname}`,JSON.stringify(p)),p.form){try{let e=localStorage.getItem(`fbos_form_${p.form}`);e&&(p.formConfigOverride=JSON.parse(e))}catch{}(0,o.getDoc)((0,o.doc)(n.Tt,`sys_forms`,p.form)).then(async e=>{if(t)if(e.exists()){let t={...e.data(),id:e.id};s(e=>({...e,formConfigOverride:t})),localStorage.setItem(`fbos_form_${p.form}`,JSON.stringify(t))}else{let e;if(p.form===`contact`){let{contactFormConfig:t}=await Promise.resolve().then(()=>require(`./contactForm.config-CXyq-EbM.cjs`)).then(e=>e.n);e=t}else if(p.form===`support`){let{supportFormConfig:t}=await Promise.resolve().then(()=>require(`./supportForm.config-haLod4rv.cjs`)).then(e=>e.n);e=t}e&&(s(t=>({...t,formConfigOverride:e})),localStorage.setItem(`fbos_form_${p.form}`,JSON.stringify(e)))}})}let r=p.pageName||p.tabName||p.title;r&&(document.title=r),s(p),d(!1)}else s(`not-found`),d(!1),localStorage.removeItem(`fbos_route_${e.pathname}`)}catch{t&&c&&(s(`not-found`),d(!1))}})(),()=>{t=!1}},[e.pathname]);let[f,p]=(0,a.useState)(!1);if((0,a.useEffect)(()=>{let e;return c?e=setTimeout(()=>p(!0),150):p(!1),()=>clearTimeout(e)},[c]),c)return f?t?(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(`div`,{className:`mb-6`,children:[(0,l.jsx)(`div`,{className:`h-10 w-56 rounded-xl bg-foreground/5 animate-pulse mt-1`}),(0,l.jsx)(`div`,{className:`h-3 w-24 rounded bg-foreground/5 animate-pulse mt-3`})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,l.jsx)(ee,{}),(0,l.jsx)(`div`,{className:`flex-1 glass-panel border border-[var(--panel-border)] rounded-3xl flex items-center justify-center min-h-[400px] bg-background shadow-2xl`,children:(0,l.jsx)(n.M,{className:`w-6 h-6 animate-spin text-accent`})})]})]}):(0,l.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[60vh] z-10`,children:(0,l.jsx)(n.M,{className:`w-6 h-6 animate-spin text-accent`})}):null;if(i===`not-found`)return(0,l.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col pt-12 min-h-screen`,children:(0,l.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1 text-center`,children:[(0,l.jsx)(`div`,{className:`w-16 h-16 bg-red-500/10 text-red-500 rounded-full flex items-center justify-center mb-6`,children:(0,l.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-8 h-8`,children:[(0,l.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,l.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,l.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]})}),(0,l.jsx)(`h2`,{className:`text-3xl font-bold mb-3 text-foreground`,children:`Page Not Found`}),(0,l.jsx)(`p`,{className:`text-foreground/60 max-w-md`,children:`The route you are looking for does not exist or has been removed.`})]})});if((i.pageId===`support`||i.isPrivate)&&!t)return(0,l.jsx)(u.Navigate,{to:`/login`,state:{from:e}});let h=r.customRoutes?.[e.pathname]||(i&&i.route?r.customRoutes?.[i.route]:null),g=i.pageName?.toLowerCase().replace(/\s+/g,`_`)||i.pageId||`custom_page`,_=`pub_${g}`,v=(i.tabName||i.pageId||i.pageName||`custom`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),y=(r.microcomponents||(typeof window<`u`?window.__FBOS_MICROCOMPONENTS__:void 0))?.[v],b=h||y||void 0;if(i.template===`none`)return i.isAdmin?(0,l.jsx)(nn,{config:i,customContent:b}):i.isShared?(0,l.jsx)(rn,{config:i,customContent:b}):i.isPrivate?(0,l.jsx)(tn,{config:i,customContent:b}):(0,l.jsx)(en,{config:i,customContent:b});if(h)return(0,l.jsx)(h,{config:i});if(i.template===`board`){let e=i.isAdmin?`admin_${i.pageId||g}`:i.isShared?`mem_${i.pageId||g}`:i.isPrivate?`user_${i.pageId||g}`:_;return(0,l.jsx)(r.components?.TemplateBoard||le,{title:i.tabTitle||i.tabName||i.title||i.pageName||`Board`,subtitle:i.route,tasksCollection:`${e}_tasks`,categoriesCollection:`${e}_categories`,config:i})}if(i.template===`table`){let e=i.isAdmin?`admin_${i.pageId||g}`:i.isShared?`mem_${i.pageId||g}`:i.isPrivate?`user_${i.pageId||g}`:_;return(0,l.jsx)(r.components?.TemplateTable||Ft,{title:i.tabTitle||i.tabName||i.title||i.pageName||`Table`,subtitle:i.route,tableCollection:`${e}_table`,config:i})}if(i.template===`calendar`){let e=i.isAdmin?`admin_${i.pageId||g}`:i.isShared?`mem_${i.pageId||g}`:i.isPrivate?`user_${i.pageId||g}`:_;return(0,l.jsx)(r.components?.TemplateCalendar||Rt,{title:i.tabTitle||i.tabName||i.title||i.pageName||`Calendar`,subtitle:i.route,eventsCollection:`${e}_events`,defaultTimeFormat:i.defaultTimeFormat||i.defaulttimeformat||`12h`,config:i})}return i.template===`inline_form`?(0,l.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-start mt-8 relative z-10 w-full min-h-[60vh]`,children:(0,l.jsx)(n.t,{isInline:!0,formId:i.form,formConfig:i.formConfigOverride})}):(0,l.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 w-full min-h-[60vh]`,children:(0,l.jsx)(n.t,{formId:i.form,formConfig:i.formConfigOverride,onClose:()=>window.history.back()})})}var on=a.default.createContext({}),sn=Object.defineProperty,cn=Object.getOwnPropertySymbols,ln=Object.prototype.hasOwnProperty,un=Object.prototype.propertyIsEnumerable,dn=(e,t,n)=>t in e?sn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,fn=(e,t)=>{for(var n in t||={})ln.call(t,n)&&dn(e,n,t[n]);if(cn)for(var n of cn(t))un.call(t,n)&&dn(e,n,t[n]);return e},pn=(0,a.forwardRef)((e,t)=>{let n=fn(fn({},a.useContext(on)),e);return a.createElement(`svg`,fn({width:`1.5em`,height:`1.5em`,strokeWidth:1.5,viewBox:`0 0 24 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,color:`currentColor`,ref:t},n),a.createElement(`path`,{d:`M21.1679 8C19.6247 4.46819 16.1006 2 11.9999 2C6.81459 2 2.55104 5.94668 2.04932 11`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M17 8H21.4C21.7314 8 22 7.73137 22 7.4V3`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M2.88146 16C4.42458 19.5318 7.94874 22 12.0494 22C17.2347 22 21.4983 18.0533 22 13`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M7.04932 16H2.64932C2.31795 16 2.04932 16.2686 2.04932 16.6V21`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}))}),mn=Object.defineProperty,hn=Object.getOwnPropertySymbols,gn=Object.prototype.hasOwnProperty,_n=Object.prototype.propertyIsEnumerable,vn=(e,t,n)=>t in e?mn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,yn=(e,t)=>{for(var n in t||={})gn.call(t,n)&&vn(e,n,t[n]);if(hn)for(var n of hn(t))_n.call(t,n)&&vn(e,n,t[n]);return e},bn=(0,a.forwardRef)((e,t)=>{let n=yn(yn({},a.useContext(on)),e);return a.createElement(`svg`,yn({width:`1.5em`,height:`1.5em`,viewBox:`0 0 24 24`,strokeWidth:1.5,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,color:`currentColor`,ref:t},n),a.createElement(`path`,{d:`M22 12C22 17.5228 17.5228 22 12 22C10.1786 22 8.47087 21.513 7 20.6622L2 21.5L2.83209 16C2.29689 14.7751 2 13.4222 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12Z`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}),a.createElement(`path`,{d:`M12.9604 13.8683L15.0399 13.4624L17 14.2149V16.0385C17 16.6449 16.4783 17.1073 15.8901 16.9783C14.3671 16.6444 11.5997 15.8043 9.67826 13.8683C7.84859 12.0248 7.22267 9.45734 7.01039 8.04128C6.92535 7.47406 7.3737 7 7.94306 7H9.83707L10.572 8.96888L10.1832 11.0701`,stroke:`currentColor`,strokeLinecap:`round`,strokeLinejoin:`round`}))}),xn=`rules_version = '2';
|
|
416
320
|
service cloud.firestore {
|
|
417
321
|
match /databases/{database}/documents {
|
|
418
322
|
|
|
@@ -473,7 +377,7 @@ service cloud.firestore {
|
|
|
473
377
|
}
|
|
474
378
|
}
|
|
475
379
|
}
|
|
476
|
-
`,
|
|
380
|
+
`,Sn=`rules_version = '2';
|
|
477
381
|
service firebase.storage {
|
|
478
382
|
match /b/{bucket}/o {
|
|
479
383
|
function isAuth() { return request.auth != null; }
|
|
@@ -508,20 +412,20 @@ service firebase.storage {
|
|
|
508
412
|
}
|
|
509
413
|
}
|
|
510
414
|
}
|
|
511
|
-
`,
|
|
415
|
+
`,Cn=[{key:`VITE_FIREBASE_API_KEY`,label:`API Key`},{key:`VITE_FIREBASE_AUTH_DOMAIN`,label:`Auth Domain`},{key:`VITE_FIREBASE_PROJECT_ID`,label:`Project ID`},{key:`VITE_FIREBASE_STORAGE_BUCKET`,label:`Storage Bucket`},{key:`VITE_FIREBASE_MESSAGING_SENDER_ID`,label:`Messaging Sender ID`},{key:`VITE_FIREBASE_APP_ID`,label:`App ID`}];function wn(e){let t;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{}try{let t=localStorage.getItem(`firebase_config`);if(t){let n=JSON.parse(t),r={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`,VITE_ADMIN_EMAILS:`adminEmails`}[e];if(r&&n[r])return n[r]}}catch{}return``}function Tn(){let e=[],t=[];for(let{key:n,label:r}of Cn){let i=wn(n);i?i.trim()===``&&t.push(r):e.push(r)}let n=wn(`VITE_ADMIN_EMAILS`),r=!n||n.trim()===``,i=[...e,...t];return{allSet:i.length===0,missing:i,empty:t,missingAdminEmails:r}}function En(){return Tn().allSet}var Dn=xn,On=Sn,kn=`VITE_FIREBASE_API_KEY=AIzaSyDxJ...
|
|
512
416
|
VITE_FIREBASE_AUTH_DOMAIN=myproject.firebaseapp.com
|
|
513
417
|
VITE_FIREBASE_PROJECT_ID=myproject
|
|
514
418
|
VITE_FIREBASE_STORAGE_BUCKET=myproject.firebasestorage.app
|
|
515
419
|
VITE_FIREBASE_MESSAGING_SENDER_ID=123456789012
|
|
516
420
|
VITE_FIREBASE_APP_ID=1:123456789012:web:abcdef123456
|
|
517
|
-
VITE_ADMIN_EMAILS=your@email.com,other@email.com`;function
|
|
421
|
+
VITE_ADMIN_EMAILS=your@email.com,other@email.com`;function An({code:e,label:t}){let[r,i]=a.default.useState(!1);return(0,l.jsxs)(n.i.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>{navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),2e3)},className:`inline-flex items-center gap-2 px-4 py-2 mt-2 rounded-xl text-[13px] font-bold tracking-wide transition-all ${r?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary shadow-sm`}`,children:[r?(0,l.jsx)(n.ct,{className:`w-4 h-4`}):(0,l.jsx)(n.Z,{className:`w-4 h-4`}),r?`Copied to Clipboard!`:t]})}function jn({code:e}){let[t,r]=a.default.useState(!1);return(0,l.jsxs)(`div`,{className:`my-5 glass-panel border border-[var(--panel-border)] rounded-2xl overflow-hidden shadow-inner bg-background`,children:[(0,l.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2.5 border-b border-[var(--panel-border)]/50 bg-foreground/[0.02]`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,l.jsx)(n.y,{className:`w-3.5 h-3.5 text-foreground/30`}),(0,l.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-widest text-foreground/30`,children:`.env`})]}),(0,l.jsxs)(`button`,{onClick:()=>{navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),2e3)},className:`text-[11px] font-bold uppercase tracking-wider flex items-center gap-1.5 transition-colors ${t?`text-emerald-500`:`text-accent hover:text-accent-deep`}`,children:[t?(0,l.jsx)(n.ct,{className:`w-3.5 h-3.5`}):(0,l.jsx)(n.Z,{className:`w-3.5 h-3.5`}),t?`Copied`:`Copy`]})]}),(0,l.jsx)(`pre`,{className:`p-4 md:p-5 overflow-x-auto text-[13px] leading-[1.8] font-mono styled-scrollbars`,children:(0,l.jsx)(`code`,{children:e.split(`
|
|
518
422
|
`).map((e,t)=>{let n=e.indexOf(`=`);if(n===-1)return(0,l.jsxs)(`span`,{className:`text-foreground/30`,children:[e,`
|
|
519
423
|
`]},t);let r=e.substring(0,n),i=e.substring(n+1);return(0,l.jsxs)(`span`,{children:[(0,l.jsx)(`span`,{className:`text-accent`,children:r}),(0,l.jsx)(`span`,{className:`text-foreground/30`,children:`=`}),(0,l.jsx)(`span`,{className:`text-foreground/60`,children:i}),`
|
|
520
|
-
`]},t)})})})]})}function
|
|
424
|
+
`]},t)})})})]})}function Mn({title:e,children:t}){return(0,l.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,l.jsx)(`div`,{className:`flex items-center gap-3 mb-4`,children:(0,l.jsx)(`h3`,{className:`text-[17px] md:text-[19px] font-extrabold text-foreground tracking-tight`,children:e})}),(0,l.jsx)(`div`,{className:`text-[14px] md:text-[15px] text-foreground/70 leading-relaxed space-y-4`,children:t})]})}function Nn({standalone:e}){let[r,i]=(0,a.useState)(()=>{let e=localStorage.getItem(`theme-mode`);return e===`light`?!1:e===`dark`?!0:window.matchMedia(`(prefers-color-scheme: dark)`).matches}),[o,s]=(0,a.useState)(null),[c,u]=(0,a.useState)(!1);return(0,a.useEffect)(()=>{e&&document.documentElement.setAttribute(`data-theme`,r?`dark`:`light`)},[r,e]),(0,a.useEffect)(()=>{if(e&&t.t.faviconUrl){let e=document.querySelector(`link[rel*='icon']`);e||(e=document.createElement(`link`),e.rel=`icon`,document.head.appendChild(e)),e.href=t.t.faviconUrl}},[e]),(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col min-h-screen`,children:[(0,l.jsx)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:`Setup`}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/setup`]})]})}),(0,l.jsx)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-6 md:p-10 shadow-2xl relative overflow-hidden bg-background flex flex-col`,children:[(0,l.jsxs)(`div`,{className:`mb-8 pb-6 border-b border-[var(--panel-border)]/50 relative z-10`,children:[(0,l.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,l.jsxs)(`div`,{children:[(0,l.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight`,children:`Firebase Configuration`}),(0,l.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/50 mt-2 leading-relaxed`,children:`Follow these steps to connect your Firebase project. Takes about 5 minutes.`})]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,l.jsx)(n.i.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,l.jsx)(n.k,{className:`w-4 h-4`})}),(0,l.jsx)(n.i.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,l.jsx)(bn,{className:`w-4 h-4 text-foreground/80`})}),(0,l.jsxs)(n.i.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>{u(!0),s(null),setTimeout(()=>{let e=Tn();s({missing:e.missing,empty:e.empty,missingAdminEmails:e.missingAdminEmails}),e.allSet&&setTimeout(()=>{window.location.href=`/`},1800),u(!1)},800)},disabled:c,className:`h-10 px-4 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer btn-primary shadow-lg disabled:opacity-50 disabled:cursor-not-allowed ml-2`,title:`Verify Configuration`,children:[c?(0,l.jsx)(n.M,{className:`w-4 h-4 animate-spin`}):(0,l.jsx)(pn,{className:`w-4 h-4`}),(0,l.jsx)(`span`,{className:`text-[13px] font-bold hidden sm:block`,children:`Verify Setup`})]})]})]}),o&&o.missing.length>0&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},className:`flex flex-col gap-2 mt-2 bg-red-500/5 border border-red-500/10 p-4 rounded-2xl`,children:[(0,l.jsxs)(`div`,{className:`flex items-center gap-2.5 text-[13px]`,children:[(0,l.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-red-500/10 border border-red-500/20 flex items-center justify-center shrink-0`,children:(0,l.jsx)(n.rt,{className:`w-4 h-4 text-red-500`})}),(0,l.jsx)(`span`,{className:`font-bold text-foreground/70`,children:o.empty&&o.empty.length>0?(0,l.jsxs)(l.Fragment,{children:[`These values are `,(0,l.jsx)(`span`,{className:`text-red-500`,children:`empty`}),` — fill them in your `,(0,l.jsx)(`code`,{className:`text-accent text-[12px]`,children:`.env`}),` file and restart the dev server`]}):(0,l.jsxs)(l.Fragment,{children:[`Missing values — update `,(0,l.jsx)(`code`,{className:`text-accent text-[12px]`,children:`.env`}),` and restart dev server`]})})]}),(0,l.jsx)(`div`,{className:`flex flex-wrap gap-1.5 ml-10`,children:o.missing.map(e=>(0,l.jsx)(`span`,{className:`px-2.5 py-1 text-[11px] font-bold uppercase tracking-wider rounded-lg bg-red-500/10 border border-red-500/20 text-red-500`,children:e},e))})]}),o&&o.missing.length===0&&o.missingAdminEmails&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},className:`flex items-center gap-2.5 mt-2 bg-yellow-500/5 border border-yellow-500/10 p-4 rounded-2xl`,children:[(0,l.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-yellow-500/10 border border-yellow-500/20 flex items-center justify-center shrink-0`,children:(0,l.jsx)(n.rt,{className:`w-4 h-4 text-yellow-500`})}),(0,l.jsx)(`span`,{className:`text-[13px] font-bold text-yellow-500`,children:`Warning: No Admin Emails configured. App is operational. Redirecting…`})]}),o&&o.missing.length===0&&!o.missingAdminEmails&&(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},className:`flex items-center gap-2.5 mt-2 bg-emerald-500/5 border border-emerald-500/10 p-4 rounded-2xl`,children:[(0,l.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-emerald-500/10 border border-emerald-500/20 flex items-center justify-center shrink-0`,children:(0,l.jsx)(n.nt,{className:`w-4 h-4 text-emerald-500`})}),(0,l.jsx)(`span`,{className:`text-[13px] font-bold text-emerald-500`,children:`All configured — redirecting…`})]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col relative z-10 p-6 md:p-8 bg-foreground/[0.015] rounded-3xl border border-[var(--panel-border)]/50 mt-4`,children:[(0,l.jsx)(Mn,{title:`Create a Firebase Project`,children:(0,l.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,l.jsxs)(`li`,{children:[`Navigate to`,` `,(0,l.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,l.jsx)(`strong`,{children:`Add Project`}),`.`]}),(0,l.jsxs)(`li`,{children:[`Enter a project name and click `,(0,l.jsx)(`strong`,{children:`Continue`}),`.`]}),(0,l.jsxs)(`li`,{children:[`Disable `,(0,l.jsx)(`strong`,{children:`Enable Gemini in Firebase`}),` (if prompted).`]}),(0,l.jsxs)(`li`,{children:[`Disable `,(0,l.jsx)(`strong`,{children:`Enable Google Analytics for this project`}),`.`]}),(0,l.jsxs)(`li`,{children:[`Click `,(0,l.jsx)(`strong`,{children:`Create Project`}),`. Wait for the project to be created, then click `,(0,l.jsx)(`strong`,{children:`Continue`}),`.`]})]})}),(0,l.jsxs)(Mn,{title:`Add a Web App`,children:[(0,l.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,l.jsxs)(`li`,{children:[`On your Firebase project dashboard, click the `,(0,l.jsx)(`strong`,{children:`+ Add App`}),` button under the name of the project, then select the `,(0,l.jsx)(`strong`,{children:`</> Web`}),` icon.`]}),(0,l.jsxs)(`li`,{children:[`Give your app a simple nickname (e.g., `,(0,l.jsx)(`span`,{className:`text-accent`,children:`MyApp`}),`). You don't need to check "Firebase Hosting".`]}),(0,l.jsxs)(`li`,{children:[`Click `,(0,l.jsx)(`strong`,{children:`Register App`}),`.`]}),(0,l.jsxs)(`li`,{children:[`Firebase will show you an SDK script block containing an object with keys like `,(0,l.jsx)(`code`,{className:`text-[12px] bg-foreground/5 rounded px-2 py-0.5`,children:`apiKey`}),`, `,(0,l.jsx)(`code`,{className:`text-[12px] bg-foreground/5 rounded px-2 py-0.5`,children:`authDomain`}),`, etc. Keep this tab open.`]})]}),(0,l.jsx)(`pre`,{className:`mt-4 p-4 md:p-5 overflow-x-auto text-[13px] leading-[1.8] font-mono styled-scrollbars glass-panel border border-[var(--panel-border)] rounded-2xl bg-background shadow-inner text-foreground/60`,children:(0,l.jsx)(`code`,{children:`const firebaseConfig = {
|
|
521
425
|
apiKey: "AIzaSy...",
|
|
522
426
|
authDomain: "myproject.firebaseapp.com",
|
|
523
427
|
projectId: "myproject",
|
|
524
428
|
storageBucket: "myproject.firebasestorage.app",
|
|
525
429
|
messagingSenderId: "123456789012",
|
|
526
430
|
appId: "1:123456789012:web:abcdef123456"
|
|
527
|
-
};`})})]}),(0,l.jsxs)(Fn,{title:`Configure your .env or Google AI Studio Secrets`,children:[(0,l.jsxs)(`p`,{className:`mb-3 text-foreground/80`,children:[`Configure your `,(0,l.jsx)(`code`,{className:`text-accent font-bold text-[13px]`,children:`.env`}),` file `,(0,l.jsx)(`strong`,{children:`OR`}),` add each variable as a secret to Google AI Studio (you will see a popup to add these variables). Map the keys from your Firebase Web SDK to the `,(0,l.jsx)(`code`,{className:`bg-foreground/5 rounded px-2 py-0.5 font-mono text-[11px]`,children:`VITE_ FIREBASE_`}),` variables.`]}),(0,l.jsxs)(`p`,{className:`text-[13px] bg-accent/10 border border-accent/20 p-3 rounded-xl mb-2 text-foreground/80`,children:[(0,l.jsx)(`strong`,{children:`Important:`}),` Provide your own emails in `,(0,l.jsx)(`code`,{className:`bg-background/80 rounded px-1.5 py-0.5 font-mono text-[11px]`,children:`VITE_ADMIN_EMAILS`}),` separated by commas. These users will automatically get full admin privileges upon their first registration. No quotes or spaces!`]}),(0,l.jsx)(Pn,{code:Mn})]}),(0,l.jsx)(Fn,{title:`Enable Authentication`,children:(0,l.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,l.jsxs)(`li`,{children:[`In Firebase console Sidebar, go to `,(0,l.jsx)(`strong`,{children:`Security`}),` → `,(0,l.jsx)(`strong`,{children:`Authentication`}),`. Click `,(0,l.jsx)(`strong`,{children:`Get Started`}),`.`]}),(0,l.jsxs)(`li`,{children:[`Click the `,(0,l.jsx)(`strong`,{children:`Sign-in method`}),` tab.`]}),(0,l.jsxs)(`li`,{children:[`Enable `,(0,l.jsx)(`strong`,{children:`Email/Password`}),` (no need to enable email links).`]}),(0,l.jsxs)(`li`,{children:[`Enable `,(0,l.jsx)(`strong`,{children:`Google`}),` (make sure to select the support email and save).`]}),(0,l.jsxs)(`li`,{children:[`Enable `,(0,l.jsx)(`strong`,{children:`Anonymous`}),`.`]}),(0,l.jsxs)(`li`,{children:[`Head over to `,(0,l.jsx)(`strong`,{children:`Templates`}),` at the top, click on the pencil icon next to the from address and click `,(0,l.jsx)(`strong`,{children:`Customise Domain`}),`. Enter the records into your domain registrar. This is necessary for emails not to go to spam.`]}),(0,l.jsxs)(`li`,{children:[(0,l.jsx)(`strong`,{children:`If testing in AI Studio:`}),` Head over to `,(0,l.jsx)(`strong`,{children:`Settings`}),` → `,(0,l.jsx)(`strong`,{children:`Authorized domains`}),`. Right-click any link in the menu (e.g. Templates) and copy the link. Click `,(0,l.jsx)(`strong`,{children:`Add domain`}),`, paste the link (it will look something like `,(0,l.jsx)(`code`,{className:`text-[12px]`,children:`ais-dev-...run.app`}),`), and save.`]})]})}),(0,l.jsxs)(Fn,{title:`Create Firestore Database`,children:[(0,l.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80 mb-4`,children:[(0,l.jsxs)(`li`,{children:[`In the Sidebar, go to `,(0,l.jsx)(`strong`,{children:`Database and Storage`}),` → `,(0,l.jsx)(`strong`,{children:`Firestore`}),`. Click `,(0,l.jsx)(`strong`,{children:`Create database`}),`.`]}),(0,l.jsxs)(`li`,{children:[`Select `,(0,l.jsx)(`strong`,{children:`Standard Edition`}),` (if asked), choose a Database ID and a location closest to your users. Start in `,(0,l.jsx)(`strong`,{children:`Production mode`}),` and click Continue.`]}),(0,l.jsxs)(`li`,{children:[`Go to the `,(0,l.jsx)(`strong`,{children:`Rules`}),` tab, paste the rules below, and click `,(0,l.jsx)(`strong`,{children:`Publish`}),`.`]})]}),(0,l.jsx)(Nn,{code:An,label:`Copy Firestore Rules`})]}),(0,l.jsxs)(Fn,{title:`Configure Storage`,children:[(0,l.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80 mb-4`,children:[(0,l.jsxs)(`li`,{children:[`In the Sidebar, go to `,(0,l.jsx)(`strong`,{children:`Database and Storage`}),` → `,(0,l.jsx)(`strong`,{children:`Storage`}),`. Before getting started, you must upgrade your project. Click `,(0,l.jsx)(`strong`,{children:`Upgrade Project`}),` to upgrade to the pay-as-you-go `,(0,l.jsx)(`strong`,{children:`Blaze plan`}),` (it only costs $0.026 per GB a month, which is extremely cheap for profile photos, and you pay per amount of storage). Create a cloud billing account or select an already configured one. Add a budget amount (e.g., $20 USD), link the billing account, and continue.`]}),(0,l.jsxs)(`li`,{children:[`Now click `,(0,l.jsx)(`strong`,{children:`Get started`}),`. Choose a no cost location and continue. Start in `,(0,l.jsx)(`strong`,{children:`Production mode`}),` and click `,(0,l.jsx)(`strong`,{children:`Create`}),`.`]}),(0,l.jsxs)(`li`,{children:[`Once created, copy the bucket URL (e.g. `,(0,l.jsx)(`code`,{className:`text-[12px] bg-foreground/5 rounded px-1.5 py-0.5`,children:`your-project.firebasestorage.app`}),`) and paste it into `,(0,l.jsx)(`code`,{className:`text-[12px] bg-foreground/5 rounded px-1.5 py-0.5`,children:`VITE_FIREBASE_STORAGE_BUCKET`}),` in your `,(0,l.jsx)(`code`,{className:`text-[13px] font-bold`,children:`.env`}),`. If using AI Studio, go to the settings icon → Secrets and paste it there.`]}),(0,l.jsxs)(`li`,{children:[`Go to the `,(0,l.jsx)(`strong`,{children:`Rules`}),` tab, paste the rules below, and click `,(0,l.jsx)(`strong`,{children:`Publish`}),`.`]})]}),(0,l.jsx)(Nn,{code:jn,label:`Copy Storage Rules`})]})]})]})})]})}function Ln(){let{user:e}=m(),t=(e?.displayName||e?.email?.split(`@`)[0]||`there`).split(` `)[0],r=t.charAt(0).toUpperCase()+t.slice(1);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,l.jsxs)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:[`Welcome back, `,r,`.`]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/dashboard`]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-4 flex-1 min-h-[500px]`,children:[(0,l.jsx)(`div`,{className:`flex justify-start`,children:(0,l.jsx)(ee,{})}),(0,l.jsxs)(`div`,{className:`w-full flex-1 glass-panel rounded-3xl p-8 md:p-12 flex items-center justify-center relative overflow-hidden border border-[var(--panel-border)] shadow-2xl bg-[var(--panel-bg)]`,children:[(0,l.jsx)(`div`,{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-64 h-64 bg-accent/10 blur-[100px] rounded-full pointer-events-none`}),(0,l.jsx)(n.a,{mode:`wait`,children:(0,l.jsxs)(n.i.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,l.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,l.jsx)(n.X,{className:`w-6 h-6`})}),(0,l.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground mb-2`,children:`No data added here yet`}),(0,l.jsx)(`p`,{className:`text-foreground/40 font-medium`,children:`Keep moving forward, your data will appear here.`})]})})]})]})]})}var Rn=()=>(0,l.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,l.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,l.jsx)(n.X,{className:`w-6 h-6 text-accent animate-pulse`})}),(0,l.jsxs)(`div`,{className:`flex items-center gap-3 glass-panel px-5 py-2.5 rounded-full border border-[var(--panel-border)]`,children:[(0,l.jsx)(`div`,{className:`w-4 h-4 border-2 border-accent border-t-transparent rounded-full animate-spin`}),(0,l.jsx)(`span`,{className:`text-[13px] font-bold tracking-widest uppercase text-foreground/70`,children:`Connecting`})]})]});function zn({children:e}){let{user:t,loading:n,userInactive:r,signOut:i,roleResolved:a}=m(),o=(0,u.useLocation)();return n||!a?(0,l.jsx)(Rn,{}):t?r?(0,l.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,l.jsxs)(`div`,{className:`glass-panel p-8 md:p-10 rounded-3xl border border-red-500/20 text-center shadow-xl max-w-sm w-full relative overflow-hidden`,children:[(0,l.jsx)(`div`,{className:`absolute inset-0 bg-red-500/5`}),(0,l.jsx)(`h2`,{className:`text-2xl font-black text-red-500 mb-3 relative z-10 tracking-tight`,children:`Access Denied`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/70 font-medium leading-relaxed relative z-10 mb-6`,children:`You don't have access to this app. Please contact the administrator.`}),(0,l.jsx)(`button`,{onClick:()=>i(),className:`w-full relative z-10 py-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors`,children:`Sign Out`})]})}):t.emailVerified?(0,l.jsx)(l.Fragment,{children:e}):(0,l.jsx)(u.Navigate,{to:`/verify`}):(0,l.jsx)(u.Navigate,{to:`/login?from=${encodeURIComponent(o.pathname)}`})}function Bn({children:e}){let{user:t,loading:n,roleResolved:r}=m(),[i]=(0,u.useSearchParams)();return n||!r?(0,l.jsx)(Rn,{}):t&&t.emailVerified?(0,l.jsx)(u.Navigate,{to:i.get(`from`)||`/dashboard`,replace:!0}):(0,l.jsx)(l.Fragment,{children:e})}function Vn({children:e}){let{user:t,loading:n,roleResolved:r}=m();return n||!r?(0,l.jsx)(Rn,{}):t?t.emailVerified?(0,l.jsx)(u.Navigate,{to:`/dashboard`}):(0,l.jsx)(l.Fragment,{children:e}):(0,l.jsx)(u.Navigate,{to:`/`})}function Hn({children:e}){let{user:t,userRole:n,loading:r,userInactive:i,signOut:a,roleResolved:o}=m(),s=(0,u.useLocation)();return r||!o?(0,l.jsx)(Rn,{}):t?i?(0,l.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,l.jsxs)(`div`,{className:`glass-panel p-8 md:p-10 rounded-3xl border border-red-500/20 text-center shadow-xl max-w-sm w-full relative overflow-hidden`,children:[(0,l.jsx)(`div`,{className:`absolute inset-0 bg-red-500/5`}),(0,l.jsx)(`h2`,{className:`text-2xl font-black text-red-500 mb-3 relative z-10 tracking-tight`,children:`Access Denied`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/70 font-medium leading-relaxed relative z-10 mb-6`,children:`You don't have access to this app. Please contact the administrator.`}),(0,l.jsx)(`button`,{onClick:()=>a(),className:`w-full relative z-10 py-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors`,children:`Sign Out`})]})}):t.emailVerified?n===`admin`?(0,l.jsx)(l.Fragment,{children:e}):(0,l.jsx)(u.Navigate,{to:`/dashboard`}):(0,l.jsx)(u.Navigate,{to:`/verify`}):(0,l.jsx)(u.Navigate,{to:`/login?from=${encodeURIComponent(s.pathname)}`})}function Un(){return(0,l.jsxs)(`div`,{className:`fixed top-0 left-0 w-full h-full pointer-events-none -z-0 overflow-hidden`,children:[(0,l.jsx)(n.i.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,l.jsx)(n.i.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 Wn(){let e=n.Ct().components?.Home||C;return(0,l.jsx)(p,{children:(0,l.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,l.jsx)(x,{}),(0,l.jsxs)(u.Routes,{children:[(0,l.jsx)(u.Route,{path:`/`,element:(0,l.jsx)(Bn,{children:(0,l.jsx)(e,{})})}),(0,l.jsx)(u.Route,{path:`/register`,element:(0,l.jsx)(Bn,{children:(0,l.jsx)(w,{})})}),(0,l.jsx)(u.Route,{path:`/login`,element:(0,l.jsx)(Bn,{children:(0,l.jsx)(T,{})})}),(0,l.jsx)(u.Route,{path:`/reset-password`,element:(0,l.jsx)(Bn,{children:(0,l.jsx)(k,{})})}),(0,l.jsx)(u.Route,{path:`/verify`,element:(0,l.jsx)(Vn,{children:(0,l.jsx)(E,{})})}),(0,l.jsx)(u.Route,{path:`/templates`,element:(0,l.jsx)(z,{})}),(0,l.jsx)(u.Route,{path:`/templates/inline_form`,element:(0,l.jsx)(B,{})}),(0,l.jsx)(u.Route,{path:`/templates/popup_form`,element:(0,l.jsx)(V,{})}),(0,l.jsx)(u.Route,{path:`/templates/confirmation`,element:(0,l.jsx)(ne,{})}),(0,l.jsx)(u.Route,{path:`/templates/board`,element:(0,l.jsx)(fe,{})}),(0,l.jsx)(u.Route,{path:`/templates/table`,element:(0,l.jsx)(Rt,{})}),(0,l.jsx)(u.Route,{path:`/templates/calendar`,element:(0,l.jsx)(Vt,{})}),(0,l.jsx)(u.Route,{path:`/users`,element:(0,l.jsx)(Hn,{children:(0,l.jsx)(A,{})})}),(0,l.jsx)(u.Route,{path:`/users/:id`,element:(0,l.jsx)(Hn,{children:(0,l.jsx)(A,{})})}),(0,l.jsx)(u.Route,{path:`/submissions`,element:(0,l.jsx)(Hn,{children:(0,l.jsx)(I,{})})}),(0,l.jsx)(u.Route,{path:`/requests`,element:(0,l.jsx)(Hn,{children:(0,l.jsx)(L,{})})}),(0,l.jsx)(u.Route,{path:`/drive/*`,element:(0,l.jsx)(zn,{children:(0,l.jsx)(R,{})})}),(0,l.jsx)(u.Route,{path:`/theme`,element:(0,l.jsx)(Hn,{children:(0,l.jsx)(qt,{})})}),(0,l.jsx)(u.Route,{path:`/pages/*`,element:(0,l.jsx)(Hn,{children:(0,l.jsx)(en,{})})}),(0,l.jsx)(u.Route,{path:`/forms/*`,element:(0,l.jsx)(Hn,{children:(0,l.jsx)(nn,{})})}),(0,l.jsx)(u.Route,{path:`/settings`,element:(0,l.jsx)(Hn,{children:(0,l.jsx)(F,{})})}),(0,l.jsx)(u.Route,{path:`/profile`,element:(0,l.jsx)(zn,{children:(0,l.jsx)(O,{})})}),(0,l.jsx)(u.Route,{path:`/dashboard`,element:(0,l.jsx)(zn,{children:(0,l.jsx)(Ln,{})})}),(0,l.jsx)(u.Route,{path:`/setup`,element:(0,l.jsx)(In,{})}),(0,l.jsx)(u.Route,{path:`*`,element:(0,l.jsx)(cn,{})})]}),(0,l.jsx)(Un,{})]})})}function Gn(){return(0,l.jsx)(u.BrowserRouter,{children:(0,l.jsx)(Kn,{})})}function Kn(){let e=n.Ct();return e.firebaseConfig&&e.firebaseConfig.apiKey&&e.firebaseConfig.apiKey.trim()!==``&&e.firebaseConfig.projectId&&e.firebaseConfig.projectId.trim()!==``||kn()?(0,l.jsx)(Wn,{}):(0,l.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,l.jsx)(x,{standalone:!0}),(0,l.jsx)(In,{standalone:!0}),(0,l.jsx)(Un,{})]})}function qn(e){let t=e.firebaseConfig;return t&&t.apiKey&&t.apiKey.trim()!==``&&t.projectId&&t.projectId.trim()!==``&&n.Et(t),(0,l.jsx)(n.St,{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,l.jsx)(n.bt,{children:(0,l.jsx)(`div`,{className:`firebase-os flex-1 flex flex-col min-h-screen`,style:{background:`var(--bg-gradient)`,color:`var(--fg-color)`},children:(0,l.jsx)(Gn,{})})})})}exports.ContactPopup=n.t,exports.FirebaseOS=qn,Object.defineProperty(exports,`auth`,{enumerable:!0,get:function(){return n.wt}}),Object.defineProperty(exports,`db`,{enumerable:!0,get:function(){return n.Tt}}),exports.defaultHomeConfig=S,Object.defineProperty(exports,`storage`,{enumerable:!0,get:function(){return n.Dt}}),exports.useAuth=m,exports.useConfig=n.Ct,exports.useTheme=n.xt;
|
|
431
|
+
};`})})]}),(0,l.jsxs)(Mn,{title:`Configure your .env or Google AI Studio Secrets`,children:[(0,l.jsxs)(`p`,{className:`mb-3 text-foreground/80`,children:[`Configure your `,(0,l.jsx)(`code`,{className:`text-accent font-bold text-[13px]`,children:`.env`}),` file `,(0,l.jsx)(`strong`,{children:`OR`}),` add each variable as a secret to Google AI Studio (you will see a popup to add these variables). Map the keys from your Firebase Web SDK to the `,(0,l.jsx)(`code`,{className:`bg-foreground/5 rounded px-2 py-0.5 font-mono text-[11px]`,children:`VITE_ FIREBASE_`}),` variables.`]}),(0,l.jsxs)(`p`,{className:`text-[13px] bg-accent/10 border border-accent/20 p-3 rounded-xl mb-2 text-foreground/80`,children:[(0,l.jsx)(`strong`,{children:`Important:`}),` Provide your own emails in `,(0,l.jsx)(`code`,{className:`bg-background/80 rounded px-1.5 py-0.5 font-mono text-[11px]`,children:`VITE_ADMIN_EMAILS`}),` separated by commas. These users will automatically get full admin privileges upon their first registration. No quotes or spaces!`]}),(0,l.jsx)(jn,{code:kn})]}),(0,l.jsx)(Mn,{title:`Enable Authentication`,children:(0,l.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,l.jsxs)(`li`,{children:[`In Firebase console Sidebar, go to `,(0,l.jsx)(`strong`,{children:`Security`}),` → `,(0,l.jsx)(`strong`,{children:`Authentication`}),`. Click `,(0,l.jsx)(`strong`,{children:`Get Started`}),`.`]}),(0,l.jsxs)(`li`,{children:[`Click the `,(0,l.jsx)(`strong`,{children:`Sign-in method`}),` tab.`]}),(0,l.jsxs)(`li`,{children:[`Enable `,(0,l.jsx)(`strong`,{children:`Email/Password`}),` (no need to enable email links).`]}),(0,l.jsxs)(`li`,{children:[`Enable `,(0,l.jsx)(`strong`,{children:`Google`}),` (make sure to select the support email and save).`]}),(0,l.jsxs)(`li`,{children:[`Enable `,(0,l.jsx)(`strong`,{children:`Anonymous`}),`.`]}),(0,l.jsxs)(`li`,{children:[`Head over to `,(0,l.jsx)(`strong`,{children:`Templates`}),` at the top, click on the pencil icon next to the from address and click `,(0,l.jsx)(`strong`,{children:`Customise Domain`}),`. Enter the records into your domain registrar. This is necessary for emails not to go to spam.`]}),(0,l.jsxs)(`li`,{children:[(0,l.jsx)(`strong`,{children:`If testing in AI Studio:`}),` Head over to `,(0,l.jsx)(`strong`,{children:`Settings`}),` → `,(0,l.jsx)(`strong`,{children:`Authorized domains`}),`. Right-click any link in the menu (e.g. Templates) and copy the link. Click `,(0,l.jsx)(`strong`,{children:`Add domain`}),`, paste the link (it will look something like `,(0,l.jsx)(`code`,{className:`text-[12px]`,children:`ais-dev-...run.app`}),`), and save.`]})]})}),(0,l.jsxs)(Mn,{title:`Create Firestore Database`,children:[(0,l.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80 mb-4`,children:[(0,l.jsxs)(`li`,{children:[`In the Sidebar, go to `,(0,l.jsx)(`strong`,{children:`Database and Storage`}),` → `,(0,l.jsx)(`strong`,{children:`Firestore`}),`. Click `,(0,l.jsx)(`strong`,{children:`Create database`}),`.`]}),(0,l.jsxs)(`li`,{children:[`Select `,(0,l.jsx)(`strong`,{children:`Standard Edition`}),` (if asked), choose a Database ID and a location closest to your users. Start in `,(0,l.jsx)(`strong`,{children:`Production mode`}),` and click Continue.`]}),(0,l.jsxs)(`li`,{children:[`Go to the `,(0,l.jsx)(`strong`,{children:`Rules`}),` tab, paste the rules below, and click `,(0,l.jsx)(`strong`,{children:`Publish`}),`.`]})]}),(0,l.jsx)(An,{code:Dn,label:`Copy Firestore Rules`})]}),(0,l.jsxs)(Mn,{title:`Configure Storage`,children:[(0,l.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80 mb-4`,children:[(0,l.jsxs)(`li`,{children:[`In the Sidebar, go to `,(0,l.jsx)(`strong`,{children:`Database and Storage`}),` → `,(0,l.jsx)(`strong`,{children:`Storage`}),`. Before getting started, you must upgrade your project. Click `,(0,l.jsx)(`strong`,{children:`Upgrade Project`}),` to upgrade to the pay-as-you-go `,(0,l.jsx)(`strong`,{children:`Blaze plan`}),` (it only costs $0.026 per GB a month, which is extremely cheap for profile photos, and you pay per amount of storage). Create a cloud billing account or select an already configured one. Add a budget amount (e.g., $20 USD), link the billing account, and continue.`]}),(0,l.jsxs)(`li`,{children:[`Now click `,(0,l.jsx)(`strong`,{children:`Get started`}),`. Choose a no cost location and continue. Start in `,(0,l.jsx)(`strong`,{children:`Production mode`}),` and click `,(0,l.jsx)(`strong`,{children:`Create`}),`.`]}),(0,l.jsxs)(`li`,{children:[`Once created, copy the bucket URL (e.g. `,(0,l.jsx)(`code`,{className:`text-[12px] bg-foreground/5 rounded px-1.5 py-0.5`,children:`your-project.firebasestorage.app`}),`) and paste it into `,(0,l.jsx)(`code`,{className:`text-[12px] bg-foreground/5 rounded px-1.5 py-0.5`,children:`VITE_FIREBASE_STORAGE_BUCKET`}),` in your `,(0,l.jsx)(`code`,{className:`text-[13px] font-bold`,children:`.env`}),`. If using AI Studio, go to the settings icon → Secrets and paste it there.`]}),(0,l.jsxs)(`li`,{children:[`Go to the `,(0,l.jsx)(`strong`,{children:`Rules`}),` tab, paste the rules below, and click `,(0,l.jsx)(`strong`,{children:`Publish`}),`.`]})]}),(0,l.jsx)(An,{code:On,label:`Copy Storage Rules`})]})]})]})})]})}function Pn(){let{user:e}=m(),t=(e?.displayName||e?.email?.split(`@`)[0]||`there`).split(` `)[0],r=t.charAt(0).toUpperCase()+t.slice(1);return(0,l.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 md:p-8 z-10 flex flex-col`,children:[(0,l.jsxs)(n.i.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,l.jsxs)(`h1`,{className:`w-fit inline-block text-3xl md:text-4xl lg:text-5xl font-extrabold tracking-tight mb-3 text-gradient mt-1`,children:[`Welcome back, `,r,`.`]}),(0,l.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,l.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/dashboard`]})]}),(0,l.jsxs)(`div`,{className:`flex flex-col gap-4 flex-1 min-h-[500px]`,children:[(0,l.jsx)(`div`,{className:`flex justify-start`,children:(0,l.jsx)(ee,{})}),(0,l.jsxs)(`div`,{className:`w-full flex-1 glass-panel rounded-3xl p-8 md:p-12 flex items-center justify-center relative overflow-hidden border border-[var(--panel-border)] shadow-2xl bg-[var(--panel-bg)]`,children:[(0,l.jsx)(`div`,{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-64 h-64 bg-accent/10 blur-[100px] rounded-full pointer-events-none`}),(0,l.jsx)(n.a,{mode:`wait`,children:(0,l.jsxs)(n.i.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,l.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,l.jsx)(n.X,{className:`w-6 h-6`})}),(0,l.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground mb-2`,children:`No data added here yet`}),(0,l.jsx)(`p`,{className:`text-foreground/40 font-medium`,children:`Keep moving forward, your data will appear here.`})]})})]})]})]})}var Fn=()=>(0,l.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,l.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,l.jsx)(n.X,{className:`w-6 h-6 text-accent animate-pulse`})}),(0,l.jsxs)(`div`,{className:`flex items-center gap-3 glass-panel px-5 py-2.5 rounded-full border border-[var(--panel-border)]`,children:[(0,l.jsx)(`div`,{className:`w-4 h-4 border-2 border-accent border-t-transparent rounded-full animate-spin`}),(0,l.jsx)(`span`,{className:`text-[13px] font-bold tracking-widest uppercase text-foreground/70`,children:`Connecting`})]})]});function In({children:e}){let{user:t,loading:n,userInactive:r,signOut:i,roleResolved:a}=m(),o=(0,u.useLocation)();return n||!a?(0,l.jsx)(Fn,{}):t?r?(0,l.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,l.jsxs)(`div`,{className:`glass-panel p-8 md:p-10 rounded-3xl border border-red-500/20 text-center shadow-xl max-w-sm w-full relative overflow-hidden`,children:[(0,l.jsx)(`div`,{className:`absolute inset-0 bg-red-500/5`}),(0,l.jsx)(`h2`,{className:`text-2xl font-black text-red-500 mb-3 relative z-10 tracking-tight`,children:`Access Denied`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/70 font-medium leading-relaxed relative z-10 mb-6`,children:`You don't have access to this app. Please contact the administrator.`}),(0,l.jsx)(`button`,{onClick:()=>i(),className:`w-full relative z-10 py-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors`,children:`Sign Out`})]})}):t.emailVerified?(0,l.jsx)(l.Fragment,{children:e}):(0,l.jsx)(u.Navigate,{to:`/verify`}):(0,l.jsx)(u.Navigate,{to:`/login?from=${encodeURIComponent(o.pathname)}`})}function Ln({children:e}){let{user:t,loading:n,roleResolved:r}=m(),[i]=(0,u.useSearchParams)();return n||!r?(0,l.jsx)(Fn,{}):t&&t.emailVerified?(0,l.jsx)(u.Navigate,{to:i.get(`from`)||`/dashboard`,replace:!0}):(0,l.jsx)(l.Fragment,{children:e})}function Rn({children:e}){let{user:t,loading:n,roleResolved:r}=m();return n||!r?(0,l.jsx)(Fn,{}):t?t.emailVerified?(0,l.jsx)(u.Navigate,{to:`/dashboard`}):(0,l.jsx)(l.Fragment,{children:e}):(0,l.jsx)(u.Navigate,{to:`/`})}function zn({children:e}){let{user:t,userRole:n,loading:r,userInactive:i,signOut:a,roleResolved:o}=m(),s=(0,u.useLocation)();return r||!o?(0,l.jsx)(Fn,{}):t?i?(0,l.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,l.jsxs)(`div`,{className:`glass-panel p-8 md:p-10 rounded-3xl border border-red-500/20 text-center shadow-xl max-w-sm w-full relative overflow-hidden`,children:[(0,l.jsx)(`div`,{className:`absolute inset-0 bg-red-500/5`}),(0,l.jsx)(`h2`,{className:`text-2xl font-black text-red-500 mb-3 relative z-10 tracking-tight`,children:`Access Denied`}),(0,l.jsx)(`p`,{className:`text-[14px] text-foreground/70 font-medium leading-relaxed relative z-10 mb-6`,children:`You don't have access to this app. Please contact the administrator.`}),(0,l.jsx)(`button`,{onClick:()=>a(),className:`w-full relative z-10 py-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors`,children:`Sign Out`})]})}):t.emailVerified?n===`admin`?(0,l.jsx)(l.Fragment,{children:e}):(0,l.jsx)(u.Navigate,{to:`/dashboard`}):(0,l.jsx)(u.Navigate,{to:`/verify`}):(0,l.jsx)(u.Navigate,{to:`/login?from=${encodeURIComponent(s.pathname)}`})}function Bn(){return(0,l.jsxs)(`div`,{className:`fixed top-0 left-0 w-full h-full pointer-events-none -z-0 overflow-hidden`,children:[(0,l.jsx)(n.i.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,l.jsx)(n.i.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 Vn(){let e=n.Ct().components?.Home||C;return(0,l.jsx)(p,{children:(0,l.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,l.jsx)(x,{}),(0,l.jsxs)(u.Routes,{children:[(0,l.jsx)(u.Route,{path:`/`,element:(0,l.jsx)(Ln,{children:(0,l.jsx)(e,{})})}),(0,l.jsx)(u.Route,{path:`/register`,element:(0,l.jsx)(Ln,{children:(0,l.jsx)(w,{})})}),(0,l.jsx)(u.Route,{path:`/login`,element:(0,l.jsx)(Ln,{children:(0,l.jsx)(T,{})})}),(0,l.jsx)(u.Route,{path:`/reset-password`,element:(0,l.jsx)(Ln,{children:(0,l.jsx)(k,{})})}),(0,l.jsx)(u.Route,{path:`/verify`,element:(0,l.jsx)(Rn,{children:(0,l.jsx)(E,{})})}),(0,l.jsx)(u.Route,{path:`/templates`,element:(0,l.jsx)(R,{})}),(0,l.jsx)(u.Route,{path:`/templates/inline_form`,element:(0,l.jsx)(z,{})}),(0,l.jsx)(u.Route,{path:`/templates/popup_form`,element:(0,l.jsx)(re,{})}),(0,l.jsx)(u.Route,{path:`/templates/confirmation`,element:(0,l.jsx)(B,{})}),(0,l.jsx)(u.Route,{path:`/templates/board`,element:(0,l.jsx)(le,{})}),(0,l.jsx)(u.Route,{path:`/templates/table`,element:(0,l.jsx)(Ft,{})}),(0,l.jsx)(u.Route,{path:`/templates/calendar`,element:(0,l.jsx)(Rt,{})}),(0,l.jsx)(u.Route,{path:`/users`,element:(0,l.jsx)(zn,{children:(0,l.jsx)(A,{})})}),(0,l.jsx)(u.Route,{path:`/users/:id`,element:(0,l.jsx)(zn,{children:(0,l.jsx)(A,{})})}),(0,l.jsx)(u.Route,{path:`/submissions`,element:(0,l.jsx)(zn,{children:(0,l.jsx)(F,{})})}),(0,l.jsx)(u.Route,{path:`/requests`,element:(0,l.jsx)(zn,{children:(0,l.jsx)(I,{})})}),(0,l.jsx)(u.Route,{path:`/drive/*`,element:(0,l.jsx)(In,{children:(0,l.jsx)(L,{})})}),(0,l.jsx)(u.Route,{path:`/theme`,element:(0,l.jsx)(zn,{children:(0,l.jsx)(Wt,{})})}),(0,l.jsx)(u.Route,{path:`/pages/*`,element:(0,l.jsx)(zn,{children:(0,l.jsx)(Zt,{})})}),(0,l.jsx)(u.Route,{path:`/forms/*`,element:(0,l.jsx)(zn,{children:(0,l.jsx)($t,{})})}),(0,l.jsx)(u.Route,{path:`/settings`,element:(0,l.jsx)(zn,{children:(0,l.jsx)(P,{})})}),(0,l.jsx)(u.Route,{path:`/profile`,element:(0,l.jsx)(In,{children:(0,l.jsx)(O,{})})}),(0,l.jsx)(u.Route,{path:`/dashboard`,element:(0,l.jsx)(In,{children:(0,l.jsx)(Pn,{})})}),(0,l.jsx)(u.Route,{path:`/setup`,element:(0,l.jsx)(Nn,{})}),(0,l.jsx)(u.Route,{path:`*`,element:(0,l.jsx)(an,{})})]}),(0,l.jsx)(Bn,{})]})})}function Hn(){return(0,l.jsx)(u.BrowserRouter,{children:(0,l.jsx)(Un,{})})}function Un(){let e=n.Ct();return e.firebaseConfig&&e.firebaseConfig.apiKey&&e.firebaseConfig.apiKey.trim()!==``&&e.firebaseConfig.projectId&&e.firebaseConfig.projectId.trim()!==``||En()?(0,l.jsx)(Vn,{}):(0,l.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,l.jsx)(x,{standalone:!0}),(0,l.jsx)(Nn,{standalone:!0}),(0,l.jsx)(Bn,{})]})}function Wn(e){let t=e.firebaseConfig;return t&&t.apiKey&&t.apiKey.trim()!==``&&t.projectId&&t.projectId.trim()!==``&&n.Et(t),(0,l.jsx)(n.St,{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,l.jsx)(n.bt,{children:(0,l.jsx)(`div`,{className:`firebase-os flex-1 flex flex-col min-h-screen`,style:{background:`var(--bg-gradient)`,color:`var(--fg-color)`},children:(0,l.jsx)(Hn,{})})})})}exports.ContactPopup=n.t,exports.FirebaseOS=Wn,Object.defineProperty(exports,`auth`,{enumerable:!0,get:function(){return n.wt}}),Object.defineProperty(exports,`db`,{enumerable:!0,get:function(){return n.Tt}}),exports.defaultHomeConfig=S,Object.defineProperty(exports,`storage`,{enumerable:!0,get:function(){return n.Dt}}),exports.useAuth=m,exports.useConfig=n.Ct,exports.useTheme=n.xt;
|