your-ai-workflow-firebase-os 1.14.21 → 1.14.22
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/{ContactPopup-DrMOJl4b.cjs → ContactPopup-BMpDAMkL.cjs} +1 -1
- package/dist/{ContactPopup-DFF2AR_d.js → ContactPopup-Bb4kow11.js} +2 -2
- package/dist/{PhoneInputField-DjBSFQd9.js → PhoneInputField-MI_-wa7l.js} +1 -1
- package/dist/renderer.cjs.js +1 -1
- package/dist/renderer.es.js +1 -1
- package/dist/your-ai-workflow-firebase-os.cjs.js +7 -7
- package/dist/your-ai-workflow-firebase-os.css +1 -1
- package/dist/your-ai-workflow-firebase-os.es.js +614 -608
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-DYteiM-1.cjs`),t=require(`./ContactPopup-DrMOJl4b.cjs`),n=require(`./PhoneInputField-CkAv_5Lw.cjs`);let r=require(`react`);r=e.i(r,1);let i=require(`react/jsx-runtime`),a=require(`firebase/auth`),o=require(`firebase/firestore`),s=require(`firebase/storage`),c=require(`react-router-dom`),l=require(`react-dom`);var u=Object.assign({"./contactForm.config.ts":t.Ra,"./supportForm.config.ts":t.Ia}),d={};for(let e in u){let t=u[e];if(!t)continue;let n=null;for(let e in t)if(e.endsWith(`FormConfig`)||e.endsWith(`Config`)){n=t[e];break}if(!n&&t?.default&&(n=t.default),!n)continue;let r=e.replace(`./`,``).replace(`.config.ts`,``).replace(/Form$/,``).toLowerCase(),i={...n,systemName:n.systemName||r};d[r]=i,i.systemName&&(d[i.systemName]=i,d[i.systemName.toLowerCase()]=i)}if(typeof window<`u`){let e=window.__FBOS_FORMS__||{};window.__FBOS_FORMS__={...d,...e}}var f=Object.assign({}),p=Object.assign({}),m={};for(let e in f){let t=f[e];if(!t)continue;let n=null;for(let e in t)if(e.endsWith(`TabConfig`)||e.endsWith(`Config`)){n=t[e];break}if(!n&&t?.default&&(n=t.default),!n)continue;let r=e.replace(`./`,``).replace(`.config.ts`,``).replace(/Tab$/,``).toLowerCase(),i={config:{...n,pageId:n.pageId||r,tabName:n.tabName||n.title||r},isPublic:!1};m[r]=i,i.config.pageId&&(m[i.config.pageId]=i,m[i.config.pageId.toLowerCase()]=i)}for(let e in p){let t=p[e];if(!t)continue;let n=null;for(let e in t)if(e.endsWith(`PageConfig`)||e.endsWith(`Config`)){n=t[e];break}if(!n&&t?.default&&(n=t.default),!n)continue;let r=e.replace(`./`,``).replace(`.config.ts`,``).replace(/Page$/,``).toLowerCase(),i={config:{...n,pageId:n.pageId||r,pageName:n.pageName||n.title||r},isPublic:!0};m[r]=i,i.config.pageId&&(m[i.config.pageId]=i,m[i.config.pageId.toLowerCase()]=i)}if(typeof window<`u`){let e=window.__FBOS_PAGES__||{};window.__FBOS_PAGES__={...m,...e}}var h=()=>{document.querySelectorAll(`.fbos-content-slot style, .fbos-home-slot style`).forEach(e=>{e.disabled&&e.media===`not all`||(e.disabled=!0,e.media=`not all`,typeof console<`u`&&console.warn(`FirebaseOS: a <style> tag inside a content file is global CSS and was disabled — style with theme classes (bg-background, text-foreground, glass-panel, btn-primary) instead.`))})},g=e=>{for(let t=e;t;t=t.parentElement){if(t.classList.contains(`fbos-content-slot`)||t.classList.contains(`fbos-home-slot`))return!1;if(getComputedStyle(t).position===`fixed`)return!0}return!1},_=()=>{if(typeof window>`u`)return;let e=window.innerHeight*.6;document.querySelectorAll(`.fbos-content-slot *, .fbos-home-slot *`).forEach(t=>{if(!t.clientHeight||t.clientHeight<e||t.scrollHeight<=t.clientHeight+2)return;let n=getComputedStyle(t);n.overflowY!==`visible`&&(n.webkitLineClamp&&n.webkitLineClamp!==`none`||g(t)||(t.style.setProperty(`max-height`,`none`,`important`),t.style.setProperty(`height`,`auto`,`important`),t.scrollHeight>t.clientHeight+2&&t.style.setProperty(`overflow-y`,`visible`,`important`),typeof console<`u`&&console.warn(`FirebaseOS: a box in a content file was as tall as the screen and hid the rest of the page, which left the bottom unreachable on a phone — it was allowed to grow. Let the page be as long as it needs: no h-screen, max-h-screen or overflow-hidden around the whole page.`)))})},v=()=>{(0,r.useEffect)(()=>{if(typeof document>`u`||typeof MutationObserver>`u`)return;let e=()=>{h(),_()};e();let t=new MutationObserver(e);return t.observe(document.body,{childList:!0,subtree:!0}),window.addEventListener(`resize`,e),window.addEventListener(`orientationchange`,e),()=>{t.disconnect(),window.removeEventListener(`resize`,e),window.removeEventListener(`orientationchange`,e)}},[])};function y(){return(typeof window<`u`?window.__FBOS_PAGES__:null)||{}}function b(e=y()){let t=new Set,n=[];for(let[r,i]of Object.entries(e))!i||t.has(i)||(t.add(i),n.push([r,i]));return n}var x=`mem_notifications`;async function S(e){let{toUid:n,toRole:r,title:i,body:a,link:s}=e||{};if(!i||!n&&!r){console.warn(`notify(): needs a title and either toUid (one person) or toRole ('admin' | 'internal').`,e);return}if(r&&r!==`admin`&&r!==`internal`){console.warn(`notify(): toRole is 'admin' or 'internal' — the bell's notifications live in mem_, which only the team can read, so '${r}' would reach nobody. To reach one person, pass toUid with their uid.`,e);return}let c=t.Ea.currentUser;if(!c){console.warn(`notify(): nobody is signed in, so there is no one to send as.`);return}try{await(0,o.addDoc)((0,o.collection)(t.Da,x),{...n?{toUid:n}:{toRole:r},title:i,body:a||``,link:s||``,uid:c.uid,fromName:c.displayName||c.email||``,createdAt:(0,o.serverTimestamp)()})}catch(e){console.warn(`notify(): the notification was not saved. If the sender is not on your team, re-paste your Firestore rules from /setup — sending from outside the team needs the mem_notifications line added in 1.14.21. A sender who is signed out, unverified or deactivated is refused whatever the rules say.`,e)}}var C=`user_notices`;async function w(e,n){let r=String(e||``).trim();if(!r||!n?.title){console.warn(`leaveNotice(): needs the uid of the person to tell and a title.`,n);return}try{await(0,o.addDoc)((0,o.collection)(t.Da,C),{uid:r,kind:`notice`,title:n.title,body:n.body||``,link:n.link||``,fromName:t.Ea.currentUser?.displayName||t.Ea.currentUser?.email||``,createdAt:Date.now()})}catch(e){console.warn(`leaveNotice(): the notice was not saved — only an admin may leave one.`,e)}}async function T(e,t){for(let n of[...new Set(e.map(e=>String(e||``).trim()).filter(Boolean))])await w(n,t)}function E(e,n,r){if(n?.own===!0)return null;let i=n?.start?t.un(new Date(String(n.start)),r):``,a=t.Yt({scheduleName:n?.scheduleName,memberName:n?.memberName}),o=String(n?.cancelReason||``).trim(),s={id:`b_${e}`,groupKey:n?.entryId?`${n.entryId}__${String(n.start||``)}`:``,type:`booking`,link:`/my-bookings`};return n?.cancelled===!0?String(n.cancelledSide||``)===`booker`?null:{...s,title:`Booking cancelled`,subtitle:[a,i,o].filter(Boolean).join(` · `),time:typeof n.cancelledAt==`number`&&n.cancelledAt>0?n.cancelledAt:n.createdAt}:n?.pending!==!0&&typeof n?.acceptedAt==`number`&&n.acceptedAt>0?{...s,title:`Booking confirmed`,subtitle:[a,i].filter(Boolean).join(` · `),time:n.acceptedAt}:null}function D(e,t){let n=new Map;for(let t of e){let e=t.data()||{};if(e.own===!0)continue;let r=e.entryId?`${e.entryId}__${String(e.start||``)}`:t.id,i=n.get(r);i?i.push({id:t.id,data:e}):n.set(r,[{id:t.id,data:e}])}let r=[];for(let e of n.values()){let n=e.find(e=>e.data.cancelled===!0&&String(e.data.cancelledSide||``)!==`booker`&&String(e.data.cancelReason||``).trim())||e.find(e=>e.data.cancelled===!0);if(n){let e=E(n.id,n.data,t);e&&r.push(e);continue}if(e.every(e=>E(e.id,e.data,t)?.title===`Booking confirmed`)){let n=e.reduce((e,t)=>t.data.acceptedAt>e.data.acceptedAt?t:e),i=E(n.id,n.data,t);i&&r.push(i)}}return r}function O(){let[e,n]=(0,r.useState)(!1),[a,s]=(0,r.useState)([]),l=(0,r.useRef)(null),u=(0,r.useRef)(null),[d,f]=(0,r.useState)(null),p=(0,c.useNavigate)(),{user:m,userRole:h,roleConfirmed:g}=t.na(),_=h===`admin`,v=t.fa(h);(0,r.useEffect)(()=>{function e(e){l.current&&!l.current.contains(e.target)&&n(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let y=(0,r.useRef)({users:[],submissions:[],requests:[],direct:[],rolewide:[],bookings:[],booked:[],bookedByEmail:[],notices:[]}),b=(0,r.useRef)(!1);(0,r.useEffect)(()=>{b.current=!1},[m?.uid]);let S=(e,t)=>{y.current[e]=t;let n=y.current,r=new Set,i=[...n.users,...n.submissions,...n.requests,...n.direct,...n.rolewide,...n.bookings,...n.booked,...n.bookedByEmail,...n.notices].filter(e=>r.has(e.id)?!1:(r.add(e.id),!0));i.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)}),s(i.slice(0,8))},w=(e,t)=>{b.current||(b.current=!0,console.warn(`AdminNotifications: this account could not read one of the notification feeds, so that part of the bell is empty. Most of them are the team's alone, and every one of them asks for a verified address.`,t)),S(e,[])};(0,r.useEffect)(()=>{let e=[];if(g){if(_){let n=(0,o.query)((0,o.collection)(t.Da,`user_profiles`),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(5));e.push((0,o.onSnapshot)(n,e=>{S(`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,link:`/users/${e.id}`}}))},e=>w(`users`,e)));let r=(0,o.query)((0,o.collection)(t.Da,`user_submissions`),(0,o.orderBy)(`submittedAt`,`desc`),(0,o.limit)(5));e.push((0,o.onSnapshot)(r,e=>{S(`submissions`,e.docs.filter(e=>e.data()?.formId!==`booking`&&!t.on(e.data()||{})).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,link:`/inbox?open=${encodeURIComponent(`anyone:${e.id}`)}`}}))},e=>w(`submissions`,e)));let i=(0,o.query)((0,o.collection)(t.Da,`user_requests`),(0,o.orderBy)(`submittedAt`,`desc`),(0,o.limit)(5));e.push((0,o.onSnapshot)(i,e=>{S(`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,link:`/inbox?open=${encodeURIComponent(`signedIn:${e.id}`)}`}}))},e=>w(`requests`,e)))}else S(`users`,[]),S(`submissions`,[]),S(`requests`,[]);if(m?.uid&&(_||v)){let n=e=>{let n=e.data()||{};if(n.own===!0)return null;let r=n.cancelled===!0,i=String(n.cancelledSide||``)!==`booker`&&String(n.cancelledByUid||``)===(m?.uid||``);if(r&&i)return null;let a=n.start?t.un(new Date(String(n.start)),t.an()):``,o=t.cn({name:n.name}),s=String(n.cancelReason||``).trim();return{id:`b_${e.id}`,groupKey:n.entryId?`${n.entryId}__${String(n.start||``)}`:``,type:`booking`,title:r?`Booking cancelled`:n.pending===!0?`Booking to accept`:`New booking`,subtitle:[o,a,r?s:``].filter(Boolean).join(` · `),time:r&&typeof n.cancelledAt==`number`&&n.cancelledAt>0?n.cancelledAt:n.createdAt,link:`/schedule?open=${encodeURIComponent(e.id)}`}},r=e=>{let t=new Set,n=[];for(let r of e)if(r){if(r.groupKey){if(t.has(r.groupKey))continue;t.add(r.groupKey)}n.push(r)}return n},i=_?(0,o.query)((0,o.collection)(t.Da,t.ht),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(5)):(0,o.query)((0,o.collection)(t.Da,t.ht),(0,o.where)(`memberId`,`==`,m.uid));e.push((0,o.onSnapshot)(i,e=>S(`bookings`,r(e.docs.map(n))),e=>w(`bookings`,e)))}else S(`bookings`,[]);if(m?.uid){let n=t.an(),r=e=>D(e.docs,n),i=(0,o.query)((0,o.collection)(t.Da,t.ht),(0,o.where)(`uid`,`==`,m.uid));e.push((0,o.onSnapshot)(i,e=>S(`booked`,r(e)),e=>w(`booked`,e)));let a=String(m.email||``).trim().toLowerCase();if(a){let n=(0,o.query)((0,o.collection)(t.Da,t.ht),(0,o.where)(`email`,`==`,a));e.push((0,o.onSnapshot)(n,e=>S(`bookedByEmail`,r(e)),e=>w(`bookedByEmail`,e)))}else S(`bookedByEmail`,[])}else S(`booked`,[]),S(`bookedByEmail`,[]);if(m?.uid){let n=(0,o.query)((0,o.collection)(t.Da,C),(0,o.where)(`uid`,`==`,m.uid)),r=e=>{let t=e.data()||{};return{id:`n_${e.id}`,type:`message`,title:String(t.title||`Notification`),subtitle:String(t.body||``),time:t.createdAt,link:typeof t.link==`string`&&t.link.startsWith(`/`)?t.link:void 0}};e.push((0,o.onSnapshot)(n,e=>{S(`notices`,e.docs.filter(e=>(e.data()||{}).kind===`notice`).map(r))},e=>w(`notices`,e)))}else S(`notices`,[]);if(m?.uid&&(_||v)){let n=e=>{let t=e.data();return{id:`m_${e.id}`,type:`message`,title:t.title||`Notification`,subtitle:t.body||t.fromName||``,time:t.createdAt,link:typeof t.link==`string`&&t.link.startsWith(`/`)?t.link:void 0}},r=(0,o.query)((0,o.collection)(t.Da,x),(0,o.where)(`toUid`,`==`,m.uid));e.push((0,o.onSnapshot)(r,e=>S(`direct`,e.docs.map(n)),e=>w(`direct`,e)));let i=_?[`admin`,`internal`]:[`internal`],a=(0,o.query)((0,o.collection)(t.Da,x),(0,o.where)(`toRole`,`in`,i));e.push((0,o.onSnapshot)(a,e=>S(`rolewide`,e.docs.map(n)),e=>w(`rolewide`,e)))}else S(`direct`,[]),S(`rolewide`,[]);return()=>e.forEach(e=>e())}},[_,v,m?.uid,m?.email,g]);let[T,E]=(0,r.useState)(()=>typeof window<`u`?parseInt(localStorage.getItem(`admin_notifications_last_read`)||`0`,10):0),O=()=>{let t=!e;if(n(t),t){let e=u.current?.getBoundingClientRect();f(typeof window<`u`&&window.innerWidth<640&&e?e.bottom+8:null);let t=Date.now();E(t),typeof window<`u`&&localStorage.setItem(`admin_notifications_last_read`,t.toString())}},k=a.some(e=>{if(!e.time)return!0;let t=e.time?.toDate?e.time.toDate().getTime():new Date(e.time).getTime();return t>T||isNaN(t)}),A=e=>{n(!1),e.link?p(e.link):e.type===`user`?p(`/users`):e.type===`booking`?p(v?`/schedule`:`/my-bookings`):(e.type===`submission`||e.type===`request`)&&p(`/inbox`)},j=e=>{if(!e)return``;let t=e.toDate?e.toDate():new Date(e),n=Date.now()-t.getTime();if(isNaN(n))return``;let r=Math.floor(n/6e4);if(r<1)return`now`;if(r<60)return`${r}m`;let i=Math.floor(r/60);if(i<24)return`${i}h`;let a=Math.floor(i/24);return a<7?`${a}d`:new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`}).format(t)};return(0,i.jsxs)(`div`,{className:`relative z-50 flex-shrink-0`,ref:l,children:[(0,i.jsxs)(`button`,{ref:u,onClick:O,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] transition-all relative text-foreground/60 hover:bg-foreground/5 hover:text-foreground flex items-center justify-center shadow-sm cursor-pointer`,"aria-label":`Notifications`,children:[(0,i.jsx)(t.Ki,{className:`w-4 h-4`}),k&&(0,i.jsx)(`span`,{className:`absolute top-1.5 right-1.5 w-2 h-2 bg-[var(--notification-icon-color)] rounded-full animate-pulse`})]}),(0,i.jsx)(t.pr,{children:e&&(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:-5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98,y:-5},className:`${d===null?`absolute top-full mt-2 right-0`:`fixed right-4`} w-[min(320px,calc(100vw-2rem))] md:w-[400px] glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col origin-top-right overflow-hidden`,style:d===null?void 0:{top:d},children:[(0,i.jsxs)(`div`,{className:`px-4 border-b border-[var(--panel-border)]/50 pb-3 pt-4 flex items-center justify-between`,children:[(0,i.jsx)(`span`,{className:`font-bold text-[14px] text-foreground tracking-wide`,children:`Notifications`}),(_||v)&&(0,i.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest text-accent bg-accent/10 px-2 py-0.5 rounded-md`,children:_?`Admin`:`Team`})]}),(0,i.jsx)(`div`,{className:`max-h-[350px] overflow-y-auto w-full p-2 flex flex-col gap-1`,children:a.length===0?(0,i.jsx)(`div`,{className:`p-6 text-center text-foreground/40 text-[13px] font-medium`,children:`No recent activity.`}):a.map(e=>(0,i.jsxs)(`button`,{onClick:()=>A(e),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,i.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,i.jsx)(t.Sr,{className:`w-4 h-4`}):e.type===`booking`?(0,i.jsx)(t.Wi,{className:`w-4 h-4`}):e.type===`submission`?(0,i.jsx)(t.Zr,{className:`w-4 h-4`}):e.type===`message`?(0,i.jsx)(t.Ki,{className:`w-4 h-4`}):(0,i.jsx)(t.ji,{className:`w-4 h-4`})}),(0,i.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,i.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground group-hover:text-accent transition-colors truncate flex-1 min-w-0`,children:e.title}),(0,i.jsx)(`span`,{className:`text-[10px] font-mono tracking-wide text-foreground/40 shrink-0`,children:j(e.time)})]}),(0,i.jsx)(`span`,{className:`text-[12px] text-foreground/60 truncate`,children:e.subtitle})]})]},e.id))})]})})]})}var k=[{id:`guide`,hidden:!1},{id:`contact`,hidden:!1},{id:`templates`,hidden:!1}],A={drive:`assets`,submissions:`inbox`,requests:`inbox`},j=new Set([`setup`]),M=e=>{let t=(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden}).map(e=>({...e,id:A[e.id]||e.id})).filter(e=>!j.has(e.id));return t.filter((e,n)=>t.findIndex(t=>t.id===e.id)===n)},N=[{id:`inbox`,hidden:!1},{id:`users`,hidden:!1},{id:`pages`,hidden:!1},{id:`schedule`,hidden:!1},{id:`mybookings`,hidden:!1},{id:`payments`,hidden:!1},{id:`email`,hidden:!1},{id:`forms`,hidden:!1},{id:`theme`,hidden:!1},{id:`assets`,hidden:!1},{id:`publish`,hidden:!1}],P={route:`/support`,template:`popup_form`,form:`support`,tabName:`Support`,iconName:``};function F(e,t,n,r){let i=0,a=!0;for(let r=0;r<e.length;r++)if(i+=e[r]+(r>0?n:0),i>t){a=!1;break}if(a)return e.length;let o=0,s=0;for(let i=0;i<e.length;i++){let a=o+e[i]+(i>0?n:0);if(a+r>t)break;o=a,s++}return Math.max(s,1)}var I=`Could not reach the server. Check your connection and try again.`,L={goTo(e){window.location.href=e}},R=`/api/payments/webhook`,z=e=>e?`${e.replace(/\/$/,``)}${R}`:``;async function B(){try{let e=t.Ea?.currentUser;return e?await e.getIdToken():null}catch{return null}}function V(e){return e?{Authorization:`Bearer ${e}`}:{}}async function H(e,t){try{let t=await e.json();if(t&&typeof t.error==`string`&&t.error)return t.error}catch{}return t}async function U(e){let t=await W(e);return typeof t==`string`?t:(L.goTo(t.url),null)}async function W(e){try{let t=await B(),n=await fetch(`/api/payments/checkout`,{method:`POST`,headers:{"Content-Type":`application/json`,...V(t)},body:JSON.stringify({...e,origin:window.location.origin})});if(!n.ok)return await H(n,`The payment could not be started. Please try again.`);let r=await n.json();return r?.url?{sessionId:String(r.sessionId||``),url:String(r.url)}:`The payment could not be started. Please try again.`}catch{return I}}async function G(){let e=await B();if(!e)return`Sign in to manage your plan.`;try{let t=await fetch(`/api/payments/portal`,{method:`POST`,headers:{"Content-Type":`application/json`,...V(e)},body:JSON.stringify({origin:window.location.origin})});if(!t.ok)return await H(t,`The billing portal could not be opened.`);let n=await t.json();return n?.url?(L.goTo(String(n.url)),null):`The billing portal could not be opened.`}catch{return I}}async function ee(e){let t={paid:!1,paymentStatus:null,amountTotal:null,currency:null,customerEmail:null,metadata:{},error:null};if(!e)return{...t,error:`No payment session to confirm.`};try{let n=await fetch(`/api/payments/session/${encodeURIComponent(e)}`);if(!n.ok)return{...t,error:await H(n,`That payment could not be found.`)};let r=await n.json();return{paid:r?.paid===!0,paymentStatus:r?.paymentStatus??null,amountTotal:r?.amountTotal??null,currency:r?.currency??null,customerEmail:r?.customerEmail??null,metadata:r?.metadata||{},error:null}}catch{return{...t,error:I}}}var K=null;function q(){return K||=fetch(`/api/payments/status`).then(e=>e.json()).then(e=>({configured:e?.configured===!0&&e?.enabled!==!1,mode:e?.mode??null})).catch(()=>(K=null,{configured:!1,mode:null})),K}function J(){K=null}function Y(){let[e,t]=(0,r.useState)({loading:!0,configured:!1,mode:null});return(0,r.useEffect)(()=>{let e=!1;return q().then(n=>{e||t({loading:!1,...n})}),()=>{e=!0}},[]),e}function te(){let[e,t]=(0,r.useState)({loading:!0,active:!1,subscriptions:[],payments:[],error:null});return(0,r.useEffect)(()=>{let e=!1,n=n=>{e||t({loading:!1,...n})};return(async()=>{let e=await B();if(!e)return n({active:!1,subscriptions:[],payments:[],error:null});try{let t=await fetch(`/api/payments/me`,{headers:V(e)});if(!t.ok)return n({active:!1,subscriptions:[],payments:[],error:await H(t,`Your payments could not be loaded.`)});let r=await t.json();return n({active:r?.active===!0,subscriptions:r?.subscriptions||[],payments:r?.payments||[],error:null})}catch{return n({active:!1,subscriptions:[],payments:[],error:I})}})(),()=>{e=!0}},[]),e}function ne(){let[e,t]=(0,r.useState)({loading:!0,charges:[],subscriptions:[],error:null});return(0,r.useEffect)(()=>{let e=!1,n=n=>{e||t({loading:!1,...n})};return(async()=>{let e=await B();if(!e)return n({charges:[],subscriptions:[],error:`Please sign in first.`});try{let t=await fetch(`/api/payments/sales`,{headers:V(e)});if(!t.ok)return n({charges:[],subscriptions:[],error:await H(t,`The sales could not be loaded.`)});let r=await t.json();return n({charges:r?.charges||[],subscriptions:r?.subscriptions||[],error:null})}catch{return n({charges:[],subscriptions:[],error:I})}})(),()=>{e=!0}},[]),e}var re={"/guide":t.Mi,"/templates":t.ai,"/contact":t.Zr},X=e=>e&&re[e]||t.ci;function Z({onNavigate:e}){let{subscriptions:n,payments:r}=te();return n.length===0&&r.length===0?null:(0,i.jsxs)(c.Link,{to:`/billing`,onClick:e,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,i.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,i.jsx)(t.wi,{className:`w-3 h-3 text-accent`})}),`Billing`]})}function Q(){let{subscriptions:e}=te(),t=e.find(e=>e.active&&e.productName)?.productName;return(0,i.jsx)(i.Fragment,{children:t||`Member`})}var ie={guide:{label:`Guide`,path:`/guide`},templates:{label:`Templates`,path:`/templates`},contact:{label:`Contact`,path:`/contact`}},ae=new Set([`setup`]);function oe({customMenu:e,standalone:n}){let{user:a,userRole:s,signOut:l,roleResolved:u}=t.na(),d=u!==!1,f=t.pa(s),p=t.ha(s),m=t.ia[p],[h,g]=(0,r.useState)(!1),[_,v]=(0,r.useState)(null),[y,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(!1),[w,T]=(0,r.useState)(!1),E=a?.displayName||a?.email?.split(`@`)[0]||`User`,D=E.charAt(0).toUpperCase()+E.slice(1),{theme:A,toggleTheme:j,activeConfig:N,canSwitchTheme:I}=t.ja(),L=async()=>{await l(),g(!1)},[R,z]=(0,r.useState)({...ie}),[B,V]=(0,r.useState)(k),[H,U]=(0,r.useState)(P.tabName);(0,r.useEffect)(()=>{if(!t.Da)return;let e=(0,o.onSnapshot)((0,o.collection)(t.Da,`sys_pages`),e=>{let t={...ie};for(let[e,n]of b()){if(!n.isPublic)continue;let r=n.config||{};if(r.enabled===!1)continue;let i=r.route?r.route.startsWith(`/`)?r.route:`/`+r.route:`/`+e;t[e]={label:r.pageName||r.pageTitle||r.title||e,path:i}}e.forEach(e=>{let n=e.data();if(n.enabled===!1)return;let r=n.pageName||n.title||ie[e.id]?.label||e.id,i=n.route||(e.id===`home`?`/`:`/`+e.id);t[e.id]={label:r,path:i}});for(let e of ae)delete t[e];z(t)},e=>{console.warn(`sys_pages snapshot error (safe to ignore during auth transition):`,e)}),n=(0,o.onSnapshot)((0,o.doc)(t.Da,`sys_configs`,`page_order`),e=>{V(e.exists()&&Array.isArray(e.data().order)?M(e.data().order):k)},e=>{console.warn(`page_order snapshot error (safe to ignore during auth transition):`,e)}),r=(0,o.onSnapshot)((0,o.doc)(t.Da,`sys_tabs`,`support`),e=>{e.exists()&&e.data().pageName&&U(e.data().pageName)},e=>{console.warn(`support snapshot error (safe to ignore during auth transition):`,e)});return()=>{e(),n(),r()}},[]);let W=(()=>{let e=new Set(B.filter(e=>e.hidden).map(e=>e.id)),t=new Set,n=[];return B.forEach(e=>{if(e.hidden||e.id===`home`)return;let r=R[e.id];r&&(n.push({label:r.label,path:r.path}),t.add(e.id))}),Object.entries(R).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})(),G=e||W,ee=(0,r.useRef)(null),K=(0,r.useRef)(null),[q,J]=(0,r.useState)(()=>typeof window<`u`&&window.innerWidth<640);(0,r.useEffect)(()=>{if(typeof window>`u`)return;let e=()=>{let e=window.innerWidth<640;J(t=>(t!==e&&g(!1),e))};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let[Y,te]=(0,r.useState)(G.length);(0,r.useEffect)(()=>{if(n||q)return;let e=()=>{let e=ee.current,t=K.current;if(!e||!t)return;let n=e.clientWidth,r=t.querySelectorAll(`[data-measure-nav]`);if(r.length===0){te(G.length);return}te(F(Array.from(r,e=>e.offsetWidth),n,28,50))},t=requestAnimationFrame(e);if(typeof ResizeObserver>`u`)return()=>cancelAnimationFrame(t);let r=new ResizeObserver(()=>requestAnimationFrame(e));return ee.current&&r.observe(ee.current),()=>{cancelAnimationFrame(t),r.disconnect()}},[G.map(e=>e.label).join(`|`),n,q,G.length]);let ne=G.slice(0,Y),re=G.slice(Y);return(0,i.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,i.jsx)(`div`,{className:`flex items-center min-w-0 z-50`,children:(0,i.jsxs)(c.Link,{to:`/`,className:`flex items-center gap-2 md:gap-2.5 lg:gap-3 group cursor-pointer z-50 min-w-0`,children:[(0,i.jsx)(`div`,{className:`w-8 h-8 md:w-9 md:h-9 rounded-lg glass-panel flex items-center justify-center glow-hover shadow-lg transition-transform duration-500 group-hover:rotate-180 group-active:scale-95 overflow-hidden shrink-0`,children:N?.logoUrl?(0,i.jsx)(`img`,{src:N.logoUrl,alt:`Logo`,className:`w-full h-full object-contain max-md:p-0.5`}):(0,i.jsx)(t.Ci,{className:`w-4 h-4 text-accent`})}),(0,i.jsx)(`span`,{className:`font-bold text-[17px] md:text-[19px] lg:text-[22px] tracking-tight text-gradient transition-all duration-300 drop-shadow-sm truncate`,children:N?.appName||``})]})}),(0,i.jsx)(t.pr,{children:y&&(0,i.jsx)(t.t,{formId:`contact`,onClose:()=>x(!1)})}),(0,i.jsx)(t.pr,{children:S&&(0,i.jsx)(t.t,{formId:`support`,onClose:()=>C(!1)})}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2.5 md:gap-4 z-50 relative ml-auto flex-1 min-w-0 justify-end`,children:[!n&&!a&&!q&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`div`,{ref:K,"aria-hidden":`true`,className:`flex items-center gap-7 whitespace-nowrap px-1`,style:{position:`fixed`,top:-9999,left:0,visibility:`hidden`,height:0,pointerEvents:`none`},children:G.map((e,n)=>(0,i.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,i.jsx)(t.Ri,{className:`w-3 h-3`})]},e.path||n))}),(0,i.jsxs)(`div`,{className:`flex items-center gap-7 mr-6 flex-1 min-w-0 justify-end relative`,ref:ee,children:[ne.map((e,n)=>(0,i.jsxs)(`div`,{className:`relative shrink-0`,onMouseEnter:()=>v(e.label),onMouseLeave:()=>v(null),children:[e.path?(0,i.jsxs)(c.Link,{to:e.path,className:`text-[13px] md:text-[14px] font-bold tracking-wide text-foreground/50 hover:text-accent transition-all cursor-pointer flex items-center gap-1.5`,children:[e.label,e.submenu&&(0,i.jsx)(t.Ri,{className:`w-3 h-3`})]}):(0,i.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,i.jsx)(t.Ri,{className:`w-3 h-3`})]}),e.submenu&&_===e.label&&(0,i.jsx)(`div`,{className:`absolute top-[100%] left-0 pt-2 z-50`,children:(0,i.jsx)(t.fr.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,i.jsx)(c.Link,{to:e.path,className:`px-5 py-3 text-[13px] font-medium text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors`,children:e.label},t):(0,i.jsx)(`button`,{onClick:e.action,className:`px-5 py-3 text-left w-full text-[13px] font-medium text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors`,children:e.label},t))})})]},`${e.path||`no-path`}-${n}`)),re.length>0&&(0,i.jsxs)(`div`,{className:`relative flex items-center shrink-0`,onMouseEnter:()=>g(`overflow`),children:[(0,i.jsx)(`button`,{onClick:()=>g(h===`overflow`?!1:`overflow`),className:`p-1 rounded-lg transition-colors flex items-center ${h===`overflow`?`bg-foreground/5 text-accent`:`text-foreground/50 hover:bg-foreground/5 hover:text-accent`}`,children:(0,i.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,i.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,i.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1`}),(0,i.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1`})]})}),(0,i.jsx)(t.pr,{children:h===`overflow`&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>g(!1)}),(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:5,scale:.98},className:`absolute top-[100%] pt-1 right-0 min-w-[200px] max-h-[350px] overflow-y-auto styled-scrollbars glass-popover border border-[var(--panel-border)] rounded-2xl flex flex-col py-2 z-50 origin-top-right`,children:re.map((e,t)=>e.path?(0,i.jsx)(c.Link,{to:e.path,onClick:()=>g(!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,i.jsx)(`button`,{onClick:()=>{e.action&&e.action(),g(!1)},className:`px-5 py-3 text-left w-full text-[13px] font-bold tracking-wide text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors`,children:e.label},t))})]})})]})]})]}),!n&&!a&&(0,i.jsxs)(i.Fragment,{children:[I&&(0,i.jsx)(`button`,{onClick:j,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] hover:bg-foreground/5 transition-all text-foreground/60 hover:text-foreground flex items-center justify-center shadow-sm shrink-0 cursor-pointer`,"aria-label":`Toggle Theme`,children:A===`dark`?(0,i.jsx)(t.Mr,{className:`w-4 h-4`}):(0,i.jsx)(t.Yr,{className:`w-4 h-4`})}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2.5 shrink-0`,children:[!q&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(c.Link,{to:`/login`,className:`flex text-[14px] font-bold tracking-wide text-foreground/80 hover:text-accent transition-colors px-3 py-1.5 shrink-0`,children:`Sign In`}),(0,i.jsx)(c.Link,{to:`/register`,className:`flex text-[13px] md:text-[14px] font-bold tracking-wide px-4 py-1.5 md:px-5 md:py-2 rounded-xl btn-primary transition-all duration-300 hover:shadow-lg hover:-translate-y-0.5 active:scale-95 items-center justify-center ml-2 shrink-0`,children:`Get Started`})]}),q&&(0,i.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,i.jsx)(`button`,{onClick:()=>g(h===`guest`?!1:`guest`),"aria-label":`Open menu`,"aria-expanded":h===`guest`,className:`w-9 h-9 rounded-xl glass-panel glow-hover border transition-all flex items-center justify-center ${h===`guest`?`border-accent bg-foreground/5`:`border-[var(--panel-border)] hover:bg-foreground/5`}`,children:(0,i.jsx)(t.Xr,{className:`w-5 h-5 text-accent/80`})}),(0,i.jsx)(t.pr,{children:h===`guest`&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>g(!1)}),(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:-10,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.95},className:`absolute top-full right-0 mt-3 w-[220px] p-2 glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col gap-1 origin-top-right`,children:[G.map((e,t)=>{let n=X(e.path);return e.path?(0,i.jsxs)(c.Link,{to:e.path,onClick:()=>g(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all min-w-0`,children:[(0,i.jsx)(n,{className:`w-4 h-4 text-accent/70 shrink-0`}),` `,(0,i.jsx)(`span`,{className:`text-[14px] font-semibold truncate`,children:e.label})]},`${e.path}-${t}`):(0,i.jsxs)(`button`,{onClick:()=>{e.action&&e.action(),g(!1)},className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all w-full text-left min-w-0`,children:[(0,i.jsx)(n,{className:`w-4 h-4 text-accent/70 shrink-0`}),` `,(0,i.jsx)(`span`,{className:`text-[14px] font-semibold truncate`,children:e.label})]},`${e.label}-${t}`)}),(0,i.jsx)(`div`,{className:`pt-2 mt-1 border-t border-[var(--panel-border)]/50 flex flex-col gap-1`,children:(0,i.jsxs)(c.Link,{to:`/login`,onClick:()=>g(!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,i.jsx)(t.$r,{className:`w-4 h-4 text-accent/70`}),` `,(0,i.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Sign In`})]})})]})]})})]})]})]}),!n&&a&&(0,i.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[d&&!!a&&(0,i.jsx)(O,{}),I&&(0,i.jsx)(`button`,{onClick:j,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] hover:bg-foreground/5 transition-all text-foreground/60 hover:text-foreground flex items-center justify-center shadow-sm shrink-0 cursor-pointer`,"aria-label":`Toggle Theme`,children:A===`dark`?(0,i.jsx)(t.Mr,{className:`w-4 h-4`}):(0,i.jsx)(t.Yr,{className:`w-4 h-4`})}),(0,i.jsxs)(`div`,{className:`relative z-50 flex-shrink-0`,children:[(0,i.jsxs)(`button`,{onClick:()=>g(h===`user`?!1:`user`),className:`flex items-center gap-2 group p-0.5 sm:p-1 sm:pr-2.5 rounded-full hover:bg-foreground/5 transition-all duration-300 cursor-pointer sm:border ${h===`user`?`sm:border-accent/50 sm:bg-foreground/5`:`sm:border-[var(--panel-border)] sm:hover:border-accent/30`}`,children:[(0,i.jsx)(`div`,{className:`w-8 h-8 md:w-9 md:h-9 rounded-full bg-accent/10 flex items-center justify-center overflow-hidden border sm:border-0 transition-colors shrink-0 text-accent ${h===`user`?`border-accent/50`:`border-[var(--panel-border)] group-hover:border-accent/30`}`,children:a.photoURL&&!w?(0,i.jsx)(`img`,{src:a.photoURL,alt:`Profile`,className:`w-full h-full object-cover`,onError:()=>T(!0)}):(0,i.jsx)(t.Sr,{className:`w-4 h-4 md:w-5 md:h-5 text-accent`})}),(0,i.jsxs)(`div`,{className:`max-sm:hidden sm:flex flex-col text-left mr-1 justify-center min-w-[70px] max-w-[160px]`,children:[(0,i.jsx)(`span`,{className:`text-[12px] font-extrabold leading-tight text-foreground truncate w-full`,children:D}),d?(0,i.jsx)(`span`,{className:`text-[10px] font-mono tracking-wider leading-tight text-accent truncate w-full mt-0.5 uppercase font-bold`,children:p===`free`?(0,i.jsx)(Q,{}):m}):(0,i.jsx)(`span`,{className:`h-[10px] w-12 rounded bg-foreground/10 animate-pulse mt-1`,"aria-hidden":`true`})]})]}),(0,i.jsx)(t.pr,{children:h===`user`&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>g(!1)}),(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:-5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98,y:-5},className:`absolute top-full mt-2 right-0 w-[280px] md:w-[320px] glass-popover border border-[var(--panel-border)] rounded-2xl p-2 z-50 flex flex-col origin-top-right`,children:[(0,i.jsxs)(`div`,{className:`p-3 border-b border-[var(--panel-border)]/50 mb-1 flex flex-col gap-1.5`,children:[(0,i.jsx)(`span`,{className:`font-bold text-[15px] text-foreground truncate`,children:D}),(0,i.jsx)(`span`,{className:`text-[12px] text-foreground/50 truncate font-mono`,children:a.email})]}),(0,i.jsxs)(`div`,{className:`py-1`,children:[(0,i.jsxs)(c.Link,{to:`/dashboard`,onClick:()=>g(!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,i.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,i.jsx)(t.si,{className:`w-3 h-3 text-accent`})}),`Dashboard`]}),f&&(0,i.jsxs)(c.Link,{to:`/assets`,onClick:()=>g(!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,i.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,i.jsx)(t.pi,{className:`w-3 h-3 text-accent`})}),`Assets`]}),s===`admin`&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(c.Link,{to:`/users`,onClick:()=>g(!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,i.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,i.jsx)(t.xr,{className:`w-3 h-3 text-accent`})}),`Users`]}),(0,i.jsxs)(c.Link,{to:`/inbox`,onClick:()=>g(!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,i.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,i.jsx)(t.di,{className:`w-3 h-3 text-accent`})}),`Inbox`]}),(0,i.jsxs)(c.Link,{to:`/pages`,onClick:()=>g(!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,i.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,i.jsx)(t.ci,{className:`w-3 h-3 text-accent`})}),`Pages`]})]}),s!==`admin`&&(0,i.jsxs)(c.Link,{to:`/support`,onClick:()=>g(!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,i.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,i.jsx)(t.ji,{className:`w-3 h-3 text-accent`})}),H]}),(0,i.jsx)(Z,{onNavigate:()=>g(!1)}),(0,i.jsxs)(c.Link,{to:`/profile`,onClick:()=>g(!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,i.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,i.jsx)(t.Sr,{className:`w-3 h-3 text-accent`})}),`Profile Settings`]})]}),(0,i.jsx)(`div`,{className:`pt-1 mt-1 border-t border-[var(--panel-border)]/50`,children:(0,i.jsxs)(`button`,{onClick:L,className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-bold tracking-wide hover:bg-red-500/10 hover:text-red-500 text-foreground/70 transition-all gap-3`,children:[(0,i.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,i.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,i.jsx)(`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`}),(0,i.jsx)(`polyline`,{points:`16 17 21 12 16 7`}),(0,i.jsx)(`line`,{x1:`21`,y1:`12`,x2:`9`,y2:`12`})]})}),`Sign Out`]})})]})]})})]})]}),n&&(0,i.jsx)(i.Fragment,{children:I&&(0,i.jsx)(`button`,{onClick:j,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] hover:bg-foreground/5 transition-all text-foreground/60 hover:text-foreground flex items-center justify-center shadow-sm shrink-0 cursor-pointer`,"aria-label":`Toggle Theme`,children:A===`dark`?(0,i.jsx)(t.Mr,{className:`w-4 h-4`}):(0,i.jsx)(t.Yr,{className:`w-4 h-4`})})})]})]})}function se(){let[e,n]=(0,r.useState)(null);return(0,i.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,i.jsxs)(t.fr.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},transition:{duration:.8},className:`text-center mb-8 md:mb-12`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},transition:{delay:.2},className:`inline-flex items-center gap-2 md:gap-3 px-5 md:px-6 py-2 md:py-2.5 mb-8 md:mb-10 text-[13px] md:text-[15px] font-semibold tracking-wide uppercase rounded-full glass-panel text-foreground glow-hover cursor-pointer`,children:[(0,i.jsx)(t.gr,{className:`w-4 h-4 text-accent`}),` The Open-Source Firebase Starter`]}),(0,i.jsx)(t.fr.h1,{className:`text-4xl sm:text-5xl md:text-6xl lg:text-[4.5rem] font-extrabold tracking-tight mb-6 md:mb-8 text-gradient animate-float leading-[1.1] md:leading-[1.15] px-2`,children:`Your AI Firebase`}),(0,i.jsx)(`p`,{className:`text-[14px] sm:text-[15px] md:text-lg lg:text-xl text-foreground/60 max-w-3xl mx-auto font-medium leading-[1.6] md:leading-[1.7] mb-10 md:mb-14 px-6 md:px-4`,children:`A production-ready Firebase backend template with Auth, Firestore prefix rules, and a clean dashboard — ready for vibe-coded apps.`}),(0,i.jsxs)(t.fr.div,{className:`flex flex-col sm:flex-row items-center justify-center gap-4 sm:gap-6 w-full max-w-2xl mx-auto px-6`,initial:{opacity:0},animate:{opacity:1},transition:{delay:.5},children:[(0,i.jsx)(c.Link,{to:`/register`,style:{borderRadius:`var(--btn-radius, 0.75rem)`},className:`w-full sm:w-auto px-6 md:px-8 py-3 md:py-3.5 font-semibold tracking-wide btn-primary text-[15px] shadow-xl transition-all duration-300 hover:-translate-y-1 active:scale-95 flex items-center justify-center`,children:`Start Building Free`}),(0,i.jsx)(c.Link,{to:`/login`,style:{borderRadius:`var(--btn-radius, 0.75rem)`},className:`w-full sm:w-auto px-6 md:px-8 py-3 md:py-3.5 font-semibold tracking-wide btn-secondary text-[15px] transition-all duration-300 flex items-center justify-center hover:-translate-y-1`,children:`Sign In`})]})]}),(0,i.jsx)(t.pr,{children:e&&(0,i.jsx)(t.t,{onClose:()=>n(null),formId:e})})]})}async function ce(){if(!t.Ea)throw Error(`Firebase is not initialized. Check your configuration.`);let e=new a.GoogleAuthProvider;try{return await(0,a.signInWithPopup)(t.Ea,e),`done`}catch(n){if(n?.code===`auth/popup-blocked`||n?.code===`auth/popup-closed-by-user`||n?.code===`auth/cancelled-popup-request`){let{signInWithRedirect:n}=await import(`firebase/auth`);return await n(t.Ea,e),`redirecting`}throw n}}function le(e,t){let n=e?.code||``;return n===`auth/unauthorized-domain`||(e?.message||``).includes(`requested action is invalid`)?`Google Sign-In failed: your app domain is not authorized. Go to Firebase Console → Authentication → Settings → Authorized domains and add your domain (e.g. localhost or your-app.com).`:n===`auth/network-request-failed`?`Network error — please check your internet connection and Firebase configuration.`:e?.message||t}var ue=[{id:`length`,label:`At least 8 characters`,ok:e=>e.length>=8},{id:`case`,label:`An uppercase and a lowercase letter`,ok:e=>/[a-z]/.test(e)&&/[A-Z]/.test(e)},{id:`number`,label:`A number`,ok:e=>/[0-9]/.test(e)}],de=new Set(`password1.password12.password123.password1234.passw0rd1.p@ssword1.p@ssw0rd1.test1234.test12345.testing123.test123456.qwerty123.qwerty1234.abcd1234.abc12345.welcome1.welcome123.admin123.admin1234.letmein123.iloveyou1.monkey123.football1.changeme1.secret123.summer2024.summer2025`.split(`.`)),fe=e=>e.toLowerCase().replace(/[\s._-]/g,``),pe=e=>de.has(fe(e||``)),me=e=>ue.map(t=>({rule:t,met:t.ok(e||``)}));function he(e){let t=e||``;if(!t)return`Choose a password.`;let n=ue.find(e=>!e.ok(t));return n?`Your password needs ${n.label.toLowerCase()}.`:pe(t)?`That password is one of the first anyone would guess. Please pick another.`:``}function ge(e,t){return t?e===t?``:`Both passwords must be the same.`:`Type your password a second time.`}function _e({value:e,className:n=``}){return(0,i.jsx)(`ul`,{className:`flex flex-col gap-1 ml-1 ${n}`,"aria-label":`Password requirements`,children:me(e).map(({rule:e,met:n})=>(0,i.jsxs)(`li`,{className:`flex items-center gap-2 text-[12.5px] font-medium transition-colors ${n?`text-emerald-500`:`text-foreground/45`}`,children:[n?(0,i.jsx)(t.zi,{className:`w-3.5 h-3.5 shrink-0`}):(0,i.jsx)(`span`,{className:`w-3.5 flex justify-center shrink-0`,children:(0,i.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-foreground/25`})}),e.label]},e.id))})}function ve(){let[e,n]=(0,r.useState)(!1),[a,o]=(0,r.useState)(null),[s,l]=(0,r.useState)(``),[u,d]=(0,r.useState)(``),[f,p]=(0,r.useState)(``),[m,h]=(0,r.useState)(``),g=(0,c.useNavigate)(),{registerUser:_}=t.na();return(0,i.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mt-6 mb-8 md:mt-0 md:mb-0 md:pt-8 md:pb-32`,children:(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5},className:`w-full max-w-[500px] p-5 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,i.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,i.jsxs)(`div`,{className:`mb-5 sm:mb-6 text-center`,children:[(0,i.jsx)(`h3`,{className:`text-[21px] sm:text-3xl font-extrabold mb-1.5 sm:mb-2 text-foreground tracking-tight`,children:`Create an account`}),(0,i.jsx)(`p`,{className:`text-[13.5px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Join Your AI Firebase and start building today.`})]}),a&&(0,i.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:a}),(0,i.jsxs)(`form`,{className:`space-y-3.5 sm:space-y-4`,onSubmit:async e=>{e.preventDefault(),n(!0),o(null);let t=new FormData(e.currentTarget),r=t.get(`email`),a=t.get(`firstName`),l=t.get(`lastName`),d=he(s),f=d?``:ge(s,u);if(p(d),h(f),d||f){o(d||f),n(!1);return}try{await _(r,s,a,l),g(`/verify`)}catch(e){e?.code===`auth/email-already-in-use`?o((0,i.jsxs)(`span`,{children:[`An account with this email already exists.`,` `,(0,i.jsx)(c.Link,{to:`/login?email=${encodeURIComponent(r)}`,className:`font-bold underline hover:text-accent transition-colors`,children:`Sign in?`})]})):e?.code===`auth/weak-password`?o(he(s)||`Please choose a stronger password.`):o(e?.message||`An error occurred during registration.`)}finally{n(!1)}},children:[(0,i.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3.5 sm:gap-4`,children:[(0,i.jsx)(t.lr,{name:`firstName`,label:`First Name`,type:`text`,placeholder:`John`,className:`max-sm:h-11`,required:!0}),(0,i.jsx)(t.lr,{name:`lastName`,label:`Last Name`,type:`text`,placeholder:`Doe`,className:`max-sm:h-11`,required:!0})]}),(0,i.jsx)(t.lr,{name:`email`,label:`Email`,type:`email`,placeholder:`name@example.com`,className:`max-sm:h-11`,required:!0}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,i.jsx)(t.lr,{name:`password`,label:`Password`,type:`password`,placeholder:`••••••••`,className:`max-sm:h-11`,autoComplete:`new-password`,value:s,onChange:e=>{l(e.target.value),f&&p(``),m&&e.target.value===u&&h(``)},onBlur:()=>p(s?he(s):``),error:f,required:!0}),s&&(0,i.jsx)(_e,{value:s})]}),s&&(0,i.jsx)(t.lr,{name:`confirmPassword`,label:`Confirm password`,type:`password`,placeholder:`••••••••`,className:`max-sm:h-11`,autoComplete:`new-password`,value:u,onChange:e=>{d(e.target.value),m&&h(``)},onBlur:()=>h(u?ge(s,u):``),error:m,required:!0}),(0,i.jsx)(`div`,{className:`pt-2`,children:(0,i.jsxs)(t.cr,{type:`submit`,className:`w-full py-2.5 sm:py-3 text-[15px] font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,isLoading:e,children:[`Create Account `,(0,i.jsx)(t.Xi,{className:`ml-2 w-4 h-4 group-hover:translate-x-1 transition-transform shrink-0`})]})})]}),(0,i.jsxs)(`div`,{className:`mt-5 pt-4 sm:mt-6 sm:pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:[(0,i.jsxs)(t.cr,{variant:`secondary`,onClick:async()=>{n(!0),o(null);try{await ce()}catch(e){o(le(e,`Google sign-up failed.`))}finally{n(!1)}},className:`w-full py-2.5 sm:py-3 text-[15px] font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,disabled:e,children:[(0,i.jsxs)(`svg`,{className:`w-5 h-5 mr-3`,viewBox:`0 0 24 24`,children:[(0,i.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,i.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,i.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,i.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,i.jsxs)(`p`,{className:`text-[13.5px] sm:text-[14px] text-foreground/70 font-medium pt-1 sm:pt-2 tracking-wide`,children:[`Already have an account? `,(0,i.jsx)(c.Link,{to:`/login`,className:`text-accent hover:underline font-bold ml-1`,children:`Sign in`})]})]})]})})}function ye(){let[e,n]=(0,r.useState)(!1),[o,s]=(0,r.useState)(null),[l]=(0,c.useSearchParams)(),u=(0,c.useNavigate)(),[d]=(0,r.useState)(l.get(`email`)||``);return(0,i.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mt-6 mb-8 md:mt-0 md:mb-0 md:pt-8 md:pb-32`,children:(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5},className:`w-full max-w-[480px] p-5 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,i.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,i.jsxs)(`div`,{className:`mb-5 sm:mb-6 text-center`,children:[(0,i.jsx)(`h3`,{className:`text-[21px] sm:text-3xl font-extrabold mb-1.5 sm:mb-2 text-foreground tracking-tight`,children:`Welcome back`}),(0,i.jsx)(`p`,{className:`text-[13.5px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Sign in to Your AI Firebase.`})]}),o&&(0,i.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:o}),(0,i.jsxs)(`form`,{className:`space-y-3.5 sm:space-y-4`,onSubmit:async e=>{e.preventDefault(),n(!0),s(null);let r=new FormData(e.currentTarget),o=r.get(`email`),d=r.get(`password`);try{if(!t.Ea)throw Error(`Firebase is not initialized. Check your configuration.`);await(0,a.signInWithEmailAndPassword)(t.Ea,o,d),u(l.get(`from`)||`/dashboard`,{replace:!0})}catch(e){e?.code===`auth/invalid-credential`||e?.code===`auth/user-not-found`||e?.code===`auth/wrong-password`?s((0,i.jsxs)(`span`,{children:[`Email or Password are incorrect.`,` `,(0,i.jsx)(c.Link,{to:`/reset-password`,className:`font-bold underline hover:text-red-400 transition-colors`,children:`Reset password?`})]})):e?.code===`auth/network-request-failed`?s(`Network error — please check your internet connection and Firebase configuration.`):s(e?.message||`Invalid credentials.`),n(!1)}},children:[(0,i.jsx)(t.lr,{name:`email`,label:`Email`,type:`email`,defaultValue:d,placeholder:`name@example.com`,className:`max-sm:h-11`,required:!0}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsxs)(`div`,{className:`flex justify-between items-center pr-1`,children:[(0,i.jsx)(`label`,{className:`text-[14px] md:text-[15px] tracking-wide font-medium text-foreground/80 select-none pb-1`,children:`Password`}),(0,i.jsx)(c.Link,{to:`/reset-password`,className:`text-[13px] md:text-[14px] text-accent hover:underline font-bold tracking-wide`,children:`Forgot Password?`})]}),(0,i.jsx)(t.lr,{name:`password`,type:`password`,placeholder:`••••••••`,className:`max-sm:h-11`,required:!0})]}),(0,i.jsx)(`div`,{className:`pt-2`,children:(0,i.jsxs)(t.cr,{type:`submit`,className:`w-full py-2.5 sm:py-3 text-[15px] sm:text-base font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,isLoading:e,children:[`Sign In `,(0,i.jsx)(t.Xi,{className:`ml-2 w-4 h-4 group-hover:translate-x-1 transition-transform shrink-0`})]})})]}),(0,i.jsxs)(`div`,{className:`mt-5 pt-4 sm:mt-6 sm:pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:[(0,i.jsxs)(t.cr,{variant:`secondary`,onClick:async()=>{n(!0),s(null);try{if(await ce()===`redirecting`)return;u(l.get(`from`)||`/dashboard`,{replace:!0})}catch(e){s(le(e,`Google sign-in failed.`))}finally{n(!1)}},className:`w-full py-2.5 sm:py-3 text-[15px] sm:text-base font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,disabled:e,children:[(0,i.jsxs)(`svg`,{className:`w-5 h-5 mr-3`,viewBox:`0 0 24 24`,children:[(0,i.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,i.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,i.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,i.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,i.jsxs)(`p`,{className:`text-[13.5px] sm:text-[14px] text-foreground/70 font-medium pt-1 sm:pt-2 tracking-wide`,children:[`New here? `,(0,i.jsx)(c.Link,{to:`/register`,className:`text-accent hover:underline font-bold ml-1`,children:`Create account`})]})]})]})})}function be(){let{user:e,refreshUser:n}=t.na(),o=(0,c.useNavigate)(),[s,l]=(0,r.useState)(!1),[u,d]=(0,r.useState)(!1),[f,p]=(0,r.useState)(``);return(0,i.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mb-16`,children:(0,i.jsxs)(t.fr.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,i.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,i.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,i.jsx)(t.Zr,{className:`w-7 h-7 md:w-8 md:h-8 text-accent opacity-90`})}),(0,i.jsx)(`h1`,{className:`text-2xl md:text-3xl font-extrabold mb-3 text-foreground tracking-tight`,children:`Verify your email`}),(0,i.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,i.jsx)(`span`,{className:`font-semibold text-foreground`,children:e?.email}),`. Please check your inbox (and spam folder) to verify your account and access your dashboard.`]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-3 max-w-[360px] mx-auto`,children:[f&&(0,i.jsx)(`div`,{role:`status`,className:`w-full px-4 py-2.5 md:py-3 text-[13px] md:text-[14px] font-semibold leading-snug rounded-xl border ${f.includes(`Failed`)||f.includes(`not verified`)||f.includes(`wrong`)?`text-red-400 bg-red-500/10 border-red-500/20`:`text-emerald-400 bg-emerald-500/10 border-emerald-500/20`}`,children:f}),(0,i.jsx)(t.cr,{variant:`primary`,onClick:async()=>{l(!0),p(``);try{if(t.Ea.currentUser){if(await t.Ea.currentUser.reload(),!t.Ea.currentUser.emailVerified){p(`Email is not verified yet. Please check your inbox.`),l(!1);return}await t.Ea.currentUser.getIdToken(!0),await n(),o(`/dashboard`)}}catch{p(`Something went wrong. Please try again.`),l(!1)}},isLoading:s,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,i.jsx)(t.cr,{variant:`ghost`,onClick:async()=>{if(e){d(!0),p(``);try{await(0,a.sendEmailVerification)(e),p(`Verification email sent! Please check your inbox.`)}catch(e){e?.code===`auth/too-many-requests`?p(`Failed to resend: Please wait a minute before trying again.`):p(e?.message||`Failed to resend. Please try again later.`)}finally{d(!1)}}},isLoading:u,className:`w-full py-2.5 md:py-3 text-[13px] md:text-[14px] font-semibold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,children:`Resend verification link`})]})]})})}var xe=.72;function Se(e){let t=(0,r.useRef)(null);return(0,r.useLayoutEffect)(()=>{let e=t.current,n=e?.parentElement;if(!e||!n)return;let r=()=>{e.style.removeProperty(`font-size`),e.removeAttribute(`data-fold`);let t=n.clientWidth,r=e.scrollWidth;if(!t||r<=t)return;let i=parseFloat(window.getComputedStyle(e).fontSize)||24,a=t/r;e.style.setProperty(`font-size`,`${(i*Math.max(a,xe)).toFixed(2)}px`,`important`),a<.72&&e.setAttribute(`data-fold`,``)};if(r(),document.fonts?.ready.then(r).catch(()=>{}),typeof ResizeObserver>`u`)return;let i=new ResizeObserver(r);return i.observe(n),()=>i.disconnect()},e),t}var Ce=({className:e,children:n,...r})=>(0,i.jsx)(`h1`,{ref:Se([n]),className:t.ur(`page-title w-fit inline-block tracking-tight mb-3 mt-1 text-gradient`,e),...r,children:n});Ce.displayName=`PageTitle`;var we=/^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i,Te=e=>{let t=String(e??``).trim();return we.test(t)?t:``};function Ee(e,t){let n=String(e??``).trim();if(!n||/^data:/i.test(n))return``;try{let e=new URL(n,t||void 0);return/^https?:$/.test(e.protocol)?e.href:``}catch{return``}}function De(e,t){let n=e?.colors?.light||{},r=Array.isArray(n.buttonGradient)?n.buttonGradient.map(Te).filter(Boolean).slice(0,2):[];return{appName:String(e?.appName||``).replace(/\s+/g,` `).trim().slice(0,60),logoUrl:Ee(e?.logoUrl,t),appUrl:Ee(t,``),accent:Te(n.accent),foreground:Te(n.foreground),buttonText:Te(n.buttonText),buttonGradient:r,panelBg:Te(n.panelBg),panelBorder:Te(n.panelBorder)}}function Oe(e){return{appName:String(e?.appName||``),logoUrl:String(e?.logoUrl||``),appUrl:String(e?.appUrl||``),accent:String(e?.accent||``),foreground:String(e?.foreground||``),buttonText:String(e?.buttonText||``),buttonGradient:Array.isArray(e?.buttonGradient)?e.buttonGradient.map(String):[],panelBg:String(e?.panelBg||``),panelBorder:String(e?.panelBorder||``)}}var ke=``,Ae=e=>/^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/i.test(e);function je(){let e=null;try{e=t.ja().activeConfig}catch{e=null}let n=!!t.na()?.isAdmin,i=typeof window<`u`?window.location.origin:``,a=e&&n?JSON.stringify(De(e,i)):``;(0,r.useEffect)(()=>{if(!a||!t.Da||a===ke)return;let e=!1;return(async()=>{try{let n=(0,o.doc)(t.Da,`sys_configs`,`emailBrand`),r=await(0,o.getDoc)(n);if(e)return;let s=r.exists()?Oe(r.data()):null,c=JSON.parse(a);Ae(i)&&s?.appUrl&&(c.appUrl=s.appUrl),(!s||JSON.stringify(s)!==JSON.stringify(c))&&await(0,o.setDoc)(n,c),ke=a}catch{}})(),()=>{e=!0}},[a])}var Me=t.Sa(`admin`),Ne={inbox:{path:`/inbox`,label:`Inbox`,icon:t.di,roles:Me},users:{path:`/users`,label:`Users`,icon:t.xr,roles:Me},pages:{path:`/pages`,label:`Pages`,icon:t.ci,roles:Me},schedule:{path:`/schedule`,label:`Schedule`,icon:t.Wi,roles:t.Sa(`internal`)},mybookings:{path:`/my-bookings`,label:`My bookings`,icon:t.Gi,roles:t.Sa(`user`)},payments:{path:`/payments`,label:`Payments`,icon:t.wi,roles:Me},email:{path:`/email`,label:`Email`,icon:t.Zr,roles:Me},forms:{path:`/forms`,label:`Forms`,icon:t.Br,roles:Me},theme:{path:`/theme`,label:`Theme`,icon:t.Jr,roles:Me},assets:{path:`/assets`,label:`Assets`,icon:t.pi,roles:Me},publish:{path:`/publish`,label:`Publish App`,icon:t.zr,roles:Me}};function Pe(e){try{let t=localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Fe({customTabs:e=[]}){let{pathname:n}=(0,c.useLocation)(),{user:a,userRole:s,roleResolved:l}=t.na();je();let u=t.v(``,a?.email||``).bookings.length>0,[d,f]=(0,r.useState)(!1),p=(0,r.useRef)(null),[m,h]=(0,r.useState)(()=>Pe(`fbos_nav_tabs`)??{}),[g,_]=(0,r.useState)(()=>{let e=Pe(`fbos_nav_order`);return Array.isArray(e)?M(e):N}),[v,y]=(0,r.useState)(()=>Pe(`fbos_nav_tabs`)!==null),[x,S]=(0,r.useState)(()=>Pe(`fbos_nav_order`)!==null);(0,r.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.collection)(t.Da,`sys_tabs`),e=>{let t={};e.forEach(e=>{t[e.id]=e.data()}),h(t),y(!0),localStorage.setItem(`fbos_nav_tabs`,JSON.stringify(t))},e=>{console.warn(`sys_tabs snapshot error:`,e),y(!0)}),n=(0,o.onSnapshot)((0,o.doc)(t.Da,`sys_configs`,`tab_order`),e=>{let t=e.exists()&&Array.isArray(e.data().order)?M(e.data().order):N;_(t),S(!0),localStorage.setItem(`fbos_nav_order`,JSON.stringify(t))},e=>{console.warn(`tab_order snapshot error:`,e),S(!0)}),r=setTimeout(()=>{y(!0),S(!0)},3e3);return()=>{e(),n(),clearTimeout(r)}},[]);let C=l!==!1&&v&&x;(0,r.useEffect)(()=>{function e(e){p.current&&!p.current.contains(e.target)&&f(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let w=[...(()=>{let e={};Object.entries(Ne).forEach(([t,n])=>{t===`mybookings`&&!u||(e[t]={id:t,...n,exact:!0})});let n={...m};for(let[e,t]of b())t.isPublic||(n[e]={...t.config,...m[e]});Object.entries(n).forEach(([n,r])=>{let i=e[n],a=i?.icon??t.ci;if(r?.iconName){let e=r.iconName.trim(),n=e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);t.mr[n]?a=t.mr[n]:t.mr[e]&&(a=t.mr[e])}let o=i?.roles??Me;r?.pageType&&(o=t.wa(r)),e[n]={id:n,path:r?.route?r.route.startsWith(`/`)?r.route:`/`+r.route:i?.path??`/`+n,label:r?.tabName||r?.pageTitle||r?.pageName||i?.label||n,icon:a,roles:o,exact:!0}});let r=[],i=new Set;g.forEach(t=>{t.hidden||i.has(t.id)||e[t.id]&&(r.push(e[t.id]),i.add(t.id))});let a=[],o=[];return Object.keys(e).forEach(t=>{if(i.has(t))return;let r=g.find(e=>e.id===t);r?.hidden||(t in n&&!r?a.push(e[t]):o.push(e[t]))}),a.length>0&&r.unshift(...a),o.length>0&&r.push(...o),r})(),...e.map(e=>({...e,id:e.path}))].filter(e=>{let n=t.Ta(s,!!a);return t.Ca(e.roles,n)}),T=(0,r.useRef)(null),E=(0,r.useRef)(null),[D,O]=(0,r.useState)(null);(0,r.useEffect)(()=>{let e=()=>{let e=T.current,t=E.current;if(!e||!t)return;let n=e.clientWidth;if(n===0)return;let r=parseFloat(getComputedStyle(e).columnGap)||40,i=t.querySelectorAll(`[data-measure-tab]`);if(i.length===0){O(w.length);return}O(F(Array.from(i,e=>e.offsetWidth),n,r,52))},t=requestAnimationFrame(e);if(typeof ResizeObserver>`u`)return()=>cancelAnimationFrame(t);let n=new ResizeObserver(()=>requestAnimationFrame(e));return T.current&&n.observe(T.current),()=>{cancelAnimationFrame(t),n.disconnect()}},[w.map(e=>e.id+e.label).join(`|`),w.length,C]);let k=D===null?w:w.slice(0,D),A=D===null?[]:w.slice(D),j=e=>e.exact?n===e.path:n.startsWith(e.path),P=A.some(e=>j(e));return C?w.length===0?null:(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`div`,{ref:E,"aria-hidden":`true`,className:`flex items-center gap-5 md:gap-10 whitespace-nowrap px-1`,style:{position:`fixed`,top:-9999,left:0,visibility:`hidden`,pointerEvents:`none`},children:w.map(e=>{let t=e.icon;return(0,i.jsxs)(`span`,{"data-measure-tab":!0,className:`flex items-center gap-2 text-[13px] md:text-[14.5px] font-semibold shrink-0 pb-2.5 md:pb-3`,children:[(0,i.jsx)(t,{className:`w-4 h-4 md:w-[18px] md:h-[18px]`}),e.label]},e.path||e.id)})}),(0,i.jsxs)(`div`,{ref:T,className:`w-full flex items-center gap-5 md:gap-10 mb-5 border-b border-[var(--panel-border)] px-1 whitespace-nowrap relative`,children:[k.map(e=>{let t=j(e),n=e.icon;return(0,i.jsxs)(c.Link,{to:e.path||`/`,className:`flex items-center gap-2 text-[13px] md:text-[14.5px] font-semibold transition-all duration-300 pb-2.5 md: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,i.jsx)(n,{className:`w-4 h-4 md:w-[18px] md:h-[18px]`}),e.label]},e.path||e.id)}),A.length>0&&(0,i.jsxs)(`div`,{className:`relative shrink-0 ml-auto`,ref:p,children:[(0,i.jsx)(`button`,{onClick:()=>f(!d),className:`flex items-center justify-center transition-all duration-300 pb-2.5 md:pb-3 -mb-[1px] border-b-2 cursor-pointer ${P?`text-accent border-accent`:`text-foreground/50 hover:text-foreground/80 border-transparent`}`,title:`More items`,children:(0,i.jsx)(t.xi,{className:`w-[18px] h-[18px] md:w-5 md:h-5`})}),(0,i.jsx)(t.pr,{children:d&&(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:10},className:`absolute top-[100%] right-0 mt-2 min-w-[200px] glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col py-2 overflow-hidden`,children:A.map(e=>{let t=j(e),n=e.icon;return(0,i.jsxs)(c.Link,{to:e.path||`/`,onClick:()=>f(!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,i.jsx)(n,{className:`w-4 h-4`}),e.label]},e.path||e.id)})})})]})]})]}):(0,i.jsx)(`div`,{className:`w-full flex items-center gap-5 md:gap-10 mb-5 border-b border-[var(--panel-border)] px-1 whitespace-nowrap relative`,children:[56,72,64].map((e,t)=>(0,i.jsxs)(`span`,{className:`flex items-center gap-2 pb-2.5 md:pb-3 h-[30px] md:h-[33px] shrink-0`,"aria-hidden":`true`,children:[(0,i.jsx)(`span`,{className:`w-4 h-4 md:w-[18px] md:h-[18px] rounded-md bg-foreground/5 animate-pulse`}),(0,i.jsx)(`span`,{className:`h-3.5 rounded bg-foreground/5 animate-pulse`,style:{width:e}})]},t))})}function Ie(){let{user:e,refreshUser:n,isInternal:c}=t.na(),[l,u]=(0,r.useState)(e?.displayName||``),[d,f]=(0,r.useState)(e?.email||``),[p,m]=(0,r.useState)(e?.photoURL||``),[h,g]=(0,r.useState)(!1),[_,v]=(0,r.useState)(null),[y,b]=(0,r.useState)(``),[x,S]=(0,r.useState)(``),[C,w]=(0,r.useState)(``),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(!1),[k,A]=(0,r.useState)(!0);r.default.useEffect(()=>{u(e?.displayName||``),f(e?.email||``),m(e?.photoURL||``)},[e?.uid,e?.displayName,e?.email,e?.photoURL]);let j=async n=>{if(e)try{if(!c)return;let r=[`mem_files`,`admin_files`];(await(0,o.getDocs)((0,o.collection)(t.Da,`sys_tabs`))).forEach(e=>{let n=e.data(),i=(n.tabName||e.id).toLowerCase().replace(/[^a-z0-9]+/g,`_`),a=t.ga(n.pageType);a===`internal`&&r.push(`mem_${i}_records`),a===`admin`&&r.push(`admin_${i}_records`)});for(let i of r)try{let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(t.Da,i),(0,o.where)(`uid`,`==`,e.uid)));if(r.empty)continue;let a=(0,o.writeBatch)(t.Da);r.docs.forEach(e=>a.update(e.ref,{creatorAvatar:n})),await a.commit()}catch{}}catch(e){console.error(`Error propagating avatar to records:`,e)}},M=async r=>{if(!e)return;let i=await t.or(r,{maxSide:512});if(i.size>2*1024*1024){v({text:`File too large. Please select an image under 2MB.`,type:`error`});return}O(!0),E(!1),A(!0);try{let r=(0,s.ref)(t.ka,`user_avatars/${e.uid}/file.png`);await(0,s.uploadBytes)(r,i,{customMetadata:{ownerId:e.uid}});let c=await(0,s.getDownloadURL)(r);m(c);let l=(0,o.doc)(t.Da,`user_profiles`,e.uid);await Promise.all([(0,a.updateProfile)(e,{photoURL:c}),(0,o.updateDoc)(l,{avatar:c}),j(c)]),await n(),v({text:`Avatar successfully updated!`,type:`success`})}catch(e){console.error(e),v({text:`Failed to upload photo.`,type:`error`})}finally{O(!1)}},N=e=>{let t=e.target.files?.[0];t&&M(t)},{over:P,dropProps:F}=t.er({accept:`image/*`,disabled:D,onFiles:([e])=>M(e),onReject:()=>v({text:`That is not a picture. Drop a JPG or a PNG.`,type:`error`})}),I=async()=>{if(e){O(!0),E(!1),A(!1);try{let r=(0,s.ref)(t.ka,`user_avatars/${e.uid}/file.png`);m(``),O(!1);let i=(0,o.doc)(t.Da,`user_profiles`,e.uid);await Promise.all([(0,s.deleteObject)(r).catch(e=>console.error(e)),(0,a.updateProfile)(e,{photoURL:``}),(0,o.updateDoc)(i,{avatar:``}),j(``)]),await n(),v({text:`Avatar removed.`,type:`success`})}catch(e){console.error(e),v({text:`Failed to delete photo.`,type:`error`}),O(!1)}}};return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-5 sm:mb-8`,children:[(0,i.jsx)(Ce,{children:`Profile Settings`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/profile`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-6 animate-in fade-in duration-500 pb-20`,children:[(0,i.jsx)(`div`,{className:`flex justify-start`,children:(0,i.jsx)(Fe,{})}),(0,i.jsx)(t.pr,{children:_&&(0,i.jsxs)(t.fr.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,i.jsx)(t.Ni,{className:`w-5 h-5 shrink-0`}):(0,i.jsx)(t.Pi,{className:`w-5 h-5 shrink-0`}),(0,i.jsx)(`span`,{className:`text-[14px] font-semibold tracking-wide leading-relaxed`,children:_.text})]})}),(0,i.jsx)(`form`,{onSubmit:async r=>{if(r.preventDefault(),e){g(!0),v(null);try{l!==e.displayName&&await(0,a.updateProfile)(e,{displayName:l});let r=!1;if(d!==e.email){let n=await(0,a.fetchSignInMethodsForEmail)(t.Ea,d);if(n&&n.length>0)throw Error(`An account with this email already exists.`);await(0,a.verifyBeforeUpdateEmail)(e,d),r=!0}if(y){let t=he(y);if(t)throw Error(t);let n=ge(y,x);if(n)throw w(n),Error(n);await(0,a.updatePassword)(e,y),b(``),S(``),w(``)}await n(),v(r?{text:`Profile updated. A verification link has been sent to your new email address.`,type:`success`}:{text:`Profile successfully updated.`,type:`success`})}catch(e){console.error(e),e.code===`auth/requires-recent-login`?v({text:`For security, please sign out and sign back in before changing your email or password.`,type:`error`}):v({text:e.message||`Failed to update profile.`,type:`error`})}finally{g(!1)}}},className:`w-full flex flex-col`,children:(0,i.jsxs)(`div`,{className:`glass-panel w-full p-5 sm:p-8 md:p-12 rounded-3xl border border-[var(--panel-border)] shadow-2xl space-y-8 md:min-h-[500px]`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-4 sm:gap-5 pb-6 border-b border-[var(--panel-border)]/50`,children:[(0,i.jsxs)(`div`,{...F,className:`relative shrink-0 group/avatar rounded-full transition-shadow ${P?`ring-2 ring-accent ring-offset-2 ring-offset-background`:``}`,children:[(0,i.jsxs)(`div`,{className:`w-16 h-16 sm:w-20 sm:h-20 rounded-full glass-panel border-2 border-[var(--panel-border)] shadow-lg bg-accent/10 flex items-center justify-center relative overflow-hidden`,children:[(D||p&&k&&!T)&&(0,i.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-accent/5 backdrop-blur-sm z-10`,children:(0,i.jsx)(t.ti,{className:`w-6 h-6 text-accent animate-spin`})}),p&&!T?(0,i.jsx)(`img`,{src:p,alt:`Avatar`,className:`w-full h-full object-cover transition-opacity duration-300 ${k?`opacity-0`:`opacity-100`}`,onLoad:()=>A(!1),onError:()=>{E(!0),A(!1)}}):(0,i.jsx)(t.Sr,{className:`w-7 h-7 sm:w-8 sm:h-8 text-accent`})]}),!D&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(`label`,{title:p?`Change photo`:`Upload photo`,className:`absolute inset-0 rounded-full bg-background/60 backdrop-blur-[2px] opacity-0 group-hover/avatar:opacity-100 focus-within:opacity-100 flex items-center justify-center cursor-pointer transition-opacity z-20`,children:[(0,i.jsx)(t.Bi,{className:`w-4 h-4 text-foreground`}),(0,i.jsx)(`input`,{type:`file`,accept:`image/*`,"aria-label":`Upload photo`,onChange:N,className:`hidden`})]}),p&&(0,i.jsx)(`button`,{type:`button`,onClick:I,title:`Remove photo`,"aria-label":`Remove photo`,className:`hidden group-hover/avatar:flex absolute -top-1 -right-1 w-6 h-6 rounded-full bg-background border border-[var(--panel-border)] text-foreground/50 hover:text-red-500 hover:border-red-500/40 items-center justify-center shadow-sm cursor-pointer z-30`,children:(0,i.jsx)(t.Or,{className:`w-3 h-3`})})]})]}),(0,i.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,i.jsx)(`h3`,{className:`font-extrabold text-lg sm:text-xl text-foreground mb-1 truncate`,children:l||`User`}),(0,i.jsx)(`p`,{className:`text-[13px] text-foreground/40 mt-1 font-medium break-words`,children:e?.email})]})]}),(0,i.jsxs)(`div`,{className:`space-y-6`,children:[(0,i.jsx)(`h3`,{className:`text-[16px] font-extrabold text-foreground flex items-center gap-2`,children:`Account Details`}),(0,i.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-5 md:gap-6`,children:[(0,i.jsx)(t.lr,{name:`name`,value:l,onChange:e=>u(e.target.value),label:`Display Name`,placeholder:`John Doe`}),(0,i.jsxs)(`div`,{className:`flex flex-col`,children:[(0,i.jsx)(t.lr,{name:`email`,type:`email`,value:d,onChange:e=>f(e.target.value),label:`Email Address`,placeholder:`name@example.com`,required:!0}),(0,i.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,i.jsxs)(`div`,{className:`pt-6 border-t border-[var(--panel-border)]/50`,children:[(0,i.jsx)(`h3`,{className:`text-[15px] font-bold text-foreground mb-4 flex items-center gap-2`,children:`Change Password`}),(0,i.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-5 md:gap-6`,children:[(0,i.jsx)(t.lr,{name:`password`,type:`password`,label:`New Password`,autoComplete:`new-password`,value:y,onChange:e=>{b(e.target.value),C&&e.target.value===x&&w(``)},placeholder:`At least 8 characters`}),(0,i.jsx)(t.lr,{name:`confirmPassword`,type:`password`,label:`Confirm New Password`,autoComplete:`new-password`,value:x,onChange:e=>{S(e.target.value),C&&w(``)},onBlur:()=>w(x?ge(y,x):``),error:C,placeholder:`Type it a second time`})]}),y&&(0,i.jsx)(_e,{value:y,className:`mt-3`})]}),(0,i.jsx)(`div`,{className:`pt-6 md:pt-8 border-t border-[var(--panel-border)]/50 flex justify-start w-full`,children:(0,i.jsx)(t.cr,{type:`submit`,isLoading:h,className:`w-full sm:w-auto sm:px-12 py-3 md:py-2.5 text-[14px] md:text-[15px] font-bold tracking-wide rounded-xl hover:-translate-y-0.5`,children:`Save Changes`})})]})})]})]})}function Le(){let[e,n]=(0,r.useState)(!1),[o,s]=(0,r.useState)(null),[l,u]=(0,r.useState)(0),[d,f]=(0,r.useState)(0);return(0,r.useEffect)(()=>{let e;return l>0&&(e=setInterval(()=>u(e=>e-1),1e3)),()=>clearInterval(e)},[l]),(0,i.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mb-16 mt-6 md:mt-0 md:mb-0 md:pt-8 md:pb-32`,children:(0,i.jsxs)(t.fr.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,i.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,i.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,i.jsx)(t.li,{className:`w-7 h-7 md:w-8 md:h-8 text-accent opacity-90`})}),(0,i.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,i.jsx)(`h3`,{className:`text-2xl md:text-3xl font-extrabold mb-2 md:mb-3 text-foreground tracking-tight`,children:`Reset Password`}),(0,i.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Enter your email to receive a recovery link.`})]}),o&&(0,i.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:o}),(0,i.jsxs)(`form`,{className:`space-y-4 text-left max-w-[360px] mx-auto`,onSubmit:async e=>{e.preventDefault(),n(!0),s(null);let r=new FormData(e.currentTarget).get(`email`);try{await(0,a.sendPasswordResetEmail)(t.Ea,r)}catch(e){console.error(e)}finally{s(`If an account exists, a reset link has been sent. Check your inbox and spam folder.`);let e=d+1;f(e),u(e===1?60:120),n(!1)}},children:[(0,i.jsx)(t.lr,{name:`email`,label:`Work Email`,type:`email`,placeholder:`name@company.com`,required:!0}),(0,i.jsx)(`div`,{className:`pt-2`,children:(0,i.jsx)(t.cr,{type:`submit`,className:`w-full py-2.5 md:py-3 text-[14px] font-bold tracking-wide rounded-xl transition-all ${l>0?`opacity-60 shadow-none cursor-not-allowed pointer-events-none hover:translate-y-0`:`hover:-translate-y-0.5`}`,isLoading:e,disabled:l>0,children:l>0?`Resend link in ${(e=>`${Math.floor(e/60)}:${(e%60).toString().padStart(2,`0`)}`)(l)}`:d>0?`Resend reset password link`:`Send Reset Link`})})]}),(0,i.jsx)(`div`,{className:`mt-6 pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:(0,i.jsxs)(c.Link,{to:`/login`,className:`inline-flex items-center text-[13px] md:text-[14px] text-foreground/70 font-medium hover:text-accent transition-colors tracking-wide`,children:[(0,i.jsx)(t.Zi,{className:`w-4 h-4 mr-2`}),`Back to Sign In`]})})]})})}var Re=`(max-width: 767px)`,ze=()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(Re).matches;function Be(){let[e,t]=(0,r.useState)(ze);return(0,r.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(Re),n=()=>t(e.matches);return n(),e.addEventListener?.(`change`,n),()=>e.removeEventListener?.(`change`,n)},[]),e}function Ve({isOpen:e,title:n,message:r,confirmText:a=`Delete`,cancelText:o=`Cancel`,onConfirm:s,onCancel:c,isProcessing:l=!1,disableConfirm:u=!1}){return(0,i.jsx)(t.pr,{children:e&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>!l&&c(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(0,i.jsx)(t.fr.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`w-full max-w-[400px] p-6 rounded-3xl glass-popover border border-[var(--panel-border)] shadow-2xl relative z-10 text-center`,children:(0,i.jsxs)(`div`,{className:`w-full flex flex-col items-center`,children:[(0,i.jsx)(`h3`,{className:`text-xl font-extrabold mb-2 text-foreground tracking-tight`,children:n}),(0,i.jsx)(`p`,{className:`w-full text-[14px] font-medium text-foreground/60 leading-relaxed mb-6 break-words`,children:r}),(0,i.jsxs)(`div`,{className:`flex items-center gap-3 w-full`,children:[(0,i.jsx)(t.cr,{variant:`secondary`,onClick:c,disabled:l,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:o}),(0,i.jsx)(t.cr,{onClick:s,disabled:l||u,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl bg-red-500 hover:bg-red-600 border-none text-white shadow-xl hover:shadow-red-500/20 glow-hover`,children:l?(0,i.jsx)(t.ti,{className:`w-5 h-5 animate-spin mx-auto`}):a})]})]})})]})})}var He=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/([A-Z])([A-Z][a-z])/g,`$1-$2`).toLowerCase(),Ue=(()=>{let e=t.hr,n=e?Object.keys(e):[];return n.length===0&&(n=Object.keys(t.mr).filter(e=>/^[A-Z]/.test(e)&&!/Icon$/.test(e)&&!/^Lucide/.test(e)&&e!==`IconNode`)),Array.from(new Set(n.map(He))).sort()})(),We=`layers.house.layout-dashboard.list.table.kanban.calendar.clock.file-text.files.folder.hard-drive.upload.download.paperclip.book-open.notebook-pen.users.user.user-plus.contact.building.briefcase.handshake.mail.message-square.message-circle.send.inbox.bell.megaphone.phone.shopping-cart.package.truck.receipt.credit-card.banknote.wallet.tag.percent.chart-bar.chart-line.chart-pie.trending-up.target.gauge.activity.settings.sliders-horizontal.wrench.shield.lock.key.eye.search.star.heart.bookmark.flag.pin.map-pin.globe.circle-check.circle-alert.info.circle-question-mark.life-buoy.sparkles.zap.rocket.camera.image.video.music.mic.palette.pen-tool.scissors.stethoscope.graduation-cap.utensils.plane.car.dumbbell.leaf.sun.moon`.split(`.`),Ge={money:[`banknote`,`wallet`,`credit-card`,`coins`,`dollar-sign`,`receipt`],cash:[`banknote`,`coins`,`wallet`],payment:[`credit-card`,`banknote`,`receipt`],invoice:[`receipt`,`file-text`],price:[`tag`,`dollar-sign`,`receipt`],people:[`users`,`user`,`contact`],customer:[`users`,`contact`,`user-round`],client:[`users`,`contact`,`briefcase`],team:[`users`,`users-round`],staff:[`users`,`id-card`],chat:[`message-circle`,`message-square`,`messages-square`],message:[`message-circle`,`mail`,`send`],email:[`mail`,`send`,`inbox`],task:[`list-checks`,`square-check`,`clipboard-check`],todo:[`list-checks`,`square-check`],project:[`kanban`,`folder-kanban`,`briefcase`],board:[`kanban`,`layout-dashboard`],photo:[`image`,`camera`,`images`],picture:[`image`,`images`],document:[`file-text`,`files`,`file`],doc:[`file-text`,`file`],shop:[`shopping-cart`,`store`,`shopping-bag`],store:[`store`,`shopping-bag`,`shopping-cart`],order:[`shopping-cart`,`package`,`receipt`],delivery:[`truck`,`package`],home:[`house`,`house-heart`],booking:[`calendar-check`,`calendar`,`clock`],appointment:[`calendar-clock`,`calendar`,`clock`],schedule:[`calendar-days`,`calendar`,`clock`],event:[`calendar`,`party-popper`,`ticket`],report:[`chart-bar`,`chart-line`,`file-chart-column`],stats:[`chart-bar`,`chart-line`,`chart-pie`],analytics:[`chart-line`,`chart-bar`,`activity`],help:[`circle-question-mark`,`life-buoy`,`info`],support:[`life-buoy`,`headset`,`circle-question-mark`],idea:[`lightbulb`,`sparkles`],health:[`heart-pulse`,`stethoscope`,`activity`],food:[`utensils`,`chef-hat`,`pizza`],travel:[`plane`,`map`,`luggage`],location:[`map-pin`,`map`,`globe`],address:[`map-pin`,`house`],security:[`shield`,`lock`,`key`],password:[`key`,`lock`],settings:[`settings`,`sliders-horizontal`,`wrench`],file:[`file`,`file-text`,`files`,`folder`],upload:[`upload`,`cloud-upload`],video:[`video`,`film`,`clapperboard`],school:[`graduation-cap`,`book-open`,`school`],course:[`graduation-cap`,`book-open`],gym:[`dumbbell`,`activity`],garden:[`leaf`,`flower`,`sprout`],car:[`car`,`car-front`],pet:[`paw-print`,`dog`,`cat`],note:[`notebook-pen`,`sticky-note`,`pencil`],write:[`pencil`,`pen-tool`,`notebook-pen`],time:[`clock`,`timer`,`hourglass`],star:[`star`,`sparkles`],favourite:[`star`,`heart`,`bookmark`],favorite:[`star`,`heart`,`bookmark`],album:[`images`,`image`,`camera`],gallery:[`images`,`image`,`camera`],profile:[`circle-user`,`user-round`,`id-card`],account:[`circle-user`,`user-round`,`id-card`],member:[`users`,`user-round`,`id-card`],membership:[`id-card`,`users`,`award`],subscription:[`credit-card`,`repeat`,`wallet`],plan:[`clipboard-list`,`layout-list`,`credit-card`],ticket:[`ticket`,`tickets`,`inbox`],request:[`inbox`,`send`,`file-text`],progress:[`trending-up`,`gauge`,`activity`],result:[`chart-bar`,`clipboard-check`,`trophy`],score:[`trophy`,`target`,`star`],library:[`library`,`book-open`,`folder`],lesson:[`graduation-cap`,`book-open`],session:[`calendar-clock`,`clock`,`video`],service:[`wrench`,`handshake`,`briefcase`],statement:[`file-text`,`receipt`,`banknote`],saved:[`bookmark`,`heart`,`star`],list:[`list`,`list-checks`,`layout-list`],detail:[`file-text`,`info`],referral:[`user-plus`,`share`,`gift`],reward:[`gift`,`trophy`,`award`],badge:[`award`,`badge`,`medal`],certificate:[`award`,`file-badge`,`scroll`],download:[`download`,`cloud-download`],history:[`history`,`clock`,`rotate-ccw`],feedback:[`message-square`,`star`,`thumbs-up`],review:[`star`,`message-square`],wishlist:[`heart`,`bookmark`,`star`],cart:[`shopping-cart`,`shopping-bag`],credit:[`coins`,`wallet`,`credit-card`],dashboard:[`layout-dashboard`,`gauge`],welcome:[`hand`,`house`,`sparkles`],onboarding:[`rocket`,`list-checks`,`user-plus`],benefit:[`gift`,`sparkles`,`award`],perk:[`gift`,`sparkles`],resource:[`folder`,`book-open`,`files`],guide:[`book-open`,`compass`,`map`],faq:[`circle-question-mark`,`message-circle`],contract:[`file-pen`,`file-text`,`scroll`],agreement:[`handshake`,`file-pen`],quote:[`file-text`,`receipt`,`tag`],enquiry:[`message-square`,`mail`],inquiry:[`message-square`,`mail`],application:[`file-text`,`clipboard-list`,`send`],form:[`clipboard-list`,`file-text`],submission:[`inbox`,`send`,`file-text`],record:[`folder`,`file-text`,`database`],log:[`history`,`list`,`file-text`]},Ke=new Set([`my`,`our`,`your`,`their`,`the`,`a`,`an`,`all`,`new`,`page`,`pages`,`of`,`and`,`for`,`to`,`in`,`on`,`at`,`is`,`it`,`this`,`that`]),qe=(e,t)=>{if(Math.abs(e.length-t.length)>2)return 3;let n=Array.from({length:t.length+1},(e,t)=>t);for(let r=1;r<=e.length;r++){let i=n[0];n[0]=r;for(let a=1;a<=t.length;a++){let o=n[a];n[a]=Math.min(n[a]+1,n[a-1]+1,i+(e[r-1]===t[a-1]?0:1)),i=o}}return n[t.length]},Je=(e,t)=>{let n=0;for(let r of t)r===e[n]&&n++;return n===e.length};function Ye(e,t=96,n=Ue){let r=e.trim().toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``);if(!r)return[];let i=r.split(`-`).filter(Boolean),a=new Set(n),o=new Map,s=(e,t)=>{a.has(e)&&o.set(e,Math.max(o.get(e)||0,t))};for(let e of n){let t=e.split(`-`);if(e===r){s(e,100);continue}if(e.startsWith(r)){s(e,90);continue}if(t.some(e=>e===r)){s(e,85);continue}if(t.some(e=>e.startsWith(r))){s(e,75);continue}if(e.includes(r)){s(e,65);continue}if(i.length>1&&i.every(e=>t.some(t=>t.startsWith(e)))){s(e,60);continue}}let c=e=>{(Ge[e]||[]).forEach((e,t)=>s(e,74-t)),e.endsWith(`s`)&&(Ge[e.slice(0,-1)]||[]).forEach((e,t)=>s(e,74-t))};for(let e of i)c(e);if(o.size===0&&i.length>1)for(let e of[...i].reverse()){if(Ke.has(e)||e.length<3)continue;let r=Ye(e,t,n);if(r.length)return r}if(o.size===0&&r.length>=3)for(let e of n)e.split(`-`).some(e=>qe(r,e)<=(r.length>5?2:1))?s(e,40):r.length>=4&&Je(r,e.replace(/-/g,``))&&s(e,20);let l=e=>{let t=We.indexOf(e);return t===-1?We.length:t};return Array.from(o.entries()).sort((e,t)=>t[1]-e[1]||l(e[0])-l(t[0])||e[0].length-t[0].length||e[0].localeCompare(t[0])).slice(0,t).map(([e])=>e)}var Xe=/(<[A-Z][A-Za-z0-9]*(?:\s[^<>]*)?\/?>|src\/[A-Za-z0-9_./-]*[A-Za-z0-9_-]|'[A-Za-z0-9_@./-]+')/g,Ze=/(https?:\/\/[^\s]+)/g,Qe=e=>e.split(Ze).flatMap((e,t)=>t%2==1?[{text:e,kind:`value`}]:e.split(Xe).map((e,t)=>({text:e,kind:t%2==1?`code`:void 0}))).filter(e=>e.text),$e=/exactly: |Here is (?:what|how) [^:]*: |It should ask for: |Where the form belongs on the page: |a button that says /,et=e=>{let t=$e.exec(e);if(!t)return Qe(e);let n=t.index+t[0].length,r=e.slice(0,n),i=e.slice(n),a=i.indexOf(` — `);return[...Qe(r),{text:a===-1?i:i.slice(0,a),kind:`value`},...Qe(a===-1?``:i.slice(a))]},tt=`text-accent font-semibold bg-accent/[0.08] rounded-[4px] px-1 -mx-[1px] [overflow-wrap:anywhere]`,nt=`font-mono text-[0.92em] text-foreground/75 bg-foreground/[0.055] border border-[var(--panel-border)]/60 rounded-[4px] px-1 py-[1px] [overflow-wrap:anywhere]`;function rt({text:e}){return(0,i.jsx)(i.Fragment,{children:et(e).map((e,t)=>e.kind?(0,i.jsx)(`span`,{className:e.kind===`value`?tt:nt,children:e.text},t):(0,i.jsx)(r.default.Fragment,{children:e.text},t))})}function it({title:e=`Ask your assistant`,description:n,prompt:a,compact:o=!1,locked:s=!1,onCopied:c}){let[l,u]=(0,r.useState)(!1),d=a.includes(`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-DYteiM-1.cjs`),t=require(`./ContactPopup-BMpDAMkL.cjs`),n=require(`./PhoneInputField-CkAv_5Lw.cjs`);let r=require(`react`);r=e.i(r,1);let i=require(`react/jsx-runtime`),a=require(`firebase/auth`),o=require(`firebase/firestore`),s=require(`firebase/storage`),c=require(`react-router-dom`),l=require(`react-dom`);var u=Object.assign({"./contactForm.config.ts":t.Ra,"./supportForm.config.ts":t.Ia}),d={};for(let e in u){let t=u[e];if(!t)continue;let n=null;for(let e in t)if(e.endsWith(`FormConfig`)||e.endsWith(`Config`)){n=t[e];break}if(!n&&t?.default&&(n=t.default),!n)continue;let r=e.replace(`./`,``).replace(`.config.ts`,``).replace(/Form$/,``).toLowerCase(),i={...n,systemName:n.systemName||r};d[r]=i,i.systemName&&(d[i.systemName]=i,d[i.systemName.toLowerCase()]=i)}if(typeof window<`u`){let e=window.__FBOS_FORMS__||{};window.__FBOS_FORMS__={...d,...e}}var f=Object.assign({}),p=Object.assign({}),m={};for(let e in f){let t=f[e];if(!t)continue;let n=null;for(let e in t)if(e.endsWith(`TabConfig`)||e.endsWith(`Config`)){n=t[e];break}if(!n&&t?.default&&(n=t.default),!n)continue;let r=e.replace(`./`,``).replace(`.config.ts`,``).replace(/Tab$/,``).toLowerCase(),i={config:{...n,pageId:n.pageId||r,tabName:n.tabName||n.title||r},isPublic:!1};m[r]=i,i.config.pageId&&(m[i.config.pageId]=i,m[i.config.pageId.toLowerCase()]=i)}for(let e in p){let t=p[e];if(!t)continue;let n=null;for(let e in t)if(e.endsWith(`PageConfig`)||e.endsWith(`Config`)){n=t[e];break}if(!n&&t?.default&&(n=t.default),!n)continue;let r=e.replace(`./`,``).replace(`.config.ts`,``).replace(/Page$/,``).toLowerCase(),i={config:{...n,pageId:n.pageId||r,pageName:n.pageName||n.title||r},isPublic:!0};m[r]=i,i.config.pageId&&(m[i.config.pageId]=i,m[i.config.pageId.toLowerCase()]=i)}if(typeof window<`u`){let e=window.__FBOS_PAGES__||{};window.__FBOS_PAGES__={...m,...e}}var h=()=>{document.querySelectorAll(`.fbos-content-slot style, .fbos-home-slot style`).forEach(e=>{e.disabled&&e.media===`not all`||(e.disabled=!0,e.media=`not all`,typeof console<`u`&&console.warn(`FirebaseOS: a <style> tag inside a content file is global CSS and was disabled — style with theme classes (bg-background, text-foreground, glass-panel, btn-primary) instead.`))})},g=e=>{for(let t=e;t;t=t.parentElement){if(t.classList.contains(`fbos-content-slot`)||t.classList.contains(`fbos-home-slot`))return!1;if(getComputedStyle(t).position===`fixed`)return!0}return!1},_=()=>{if(typeof window>`u`)return;let e=window.innerHeight*.6;document.querySelectorAll(`.fbos-content-slot *, .fbos-home-slot *`).forEach(t=>{if(!t.clientHeight||t.clientHeight<e||t.scrollHeight<=t.clientHeight+2)return;let n=getComputedStyle(t);n.overflowY!==`visible`&&(n.webkitLineClamp&&n.webkitLineClamp!==`none`||g(t)||(t.style.setProperty(`max-height`,`none`,`important`),t.style.setProperty(`height`,`auto`,`important`),t.scrollHeight>t.clientHeight+2&&t.style.setProperty(`overflow-y`,`visible`,`important`),typeof console<`u`&&console.warn(`FirebaseOS: a box in a content file was as tall as the screen and hid the rest of the page, which left the bottom unreachable on a phone — it was allowed to grow. Let the page be as long as it needs: no h-screen, max-h-screen or overflow-hidden around the whole page.`)))})},v=()=>{(0,r.useEffect)(()=>{if(typeof document>`u`||typeof MutationObserver>`u`)return;let e=()=>{h(),_()};e();let t=new MutationObserver(e);return t.observe(document.body,{childList:!0,subtree:!0}),window.addEventListener(`resize`,e),window.addEventListener(`orientationchange`,e),()=>{t.disconnect(),window.removeEventListener(`resize`,e),window.removeEventListener(`orientationchange`,e)}},[])};function y(){return(typeof window<`u`?window.__FBOS_PAGES__:null)||{}}function b(e=y()){let t=new Set,n=[];for(let[r,i]of Object.entries(e))!i||t.has(i)||(t.add(i),n.push([r,i]));return n}var x=`mem_notifications`;async function S(e){let{toUid:n,toRole:r,title:i,body:a,link:s}=e||{};if(!i||!n&&!r){console.warn(`notify(): needs a title and either toUid (one person) or toRole ('admin' | 'internal').`,e);return}if(r&&r!==`admin`&&r!==`internal`){console.warn(`notify(): toRole is 'admin' or 'internal' — the bell's notifications live in mem_, which only the team can read, so '${r}' would reach nobody. To reach one person, pass toUid with their uid.`,e);return}let c=t.Ea.currentUser;if(!c){console.warn(`notify(): nobody is signed in, so there is no one to send as.`);return}try{await(0,o.addDoc)((0,o.collection)(t.Da,x),{...n?{toUid:n}:{toRole:r},title:i,body:a||``,link:s||``,uid:c.uid,fromName:c.displayName||c.email||``,createdAt:(0,o.serverTimestamp)()})}catch(e){console.warn(`notify(): the notification was not saved. If the sender is not on your team, re-paste your Firestore rules from /setup — sending from outside the team needs the mem_notifications line added in 1.14.21. A sender who is signed out, unverified or deactivated is refused whatever the rules say.`,e)}}var C=`user_notices`;async function w(e,n){let r=String(e||``).trim();if(!r||!n?.title){console.warn(`leaveNotice(): needs the uid of the person to tell and a title.`,n);return}try{await(0,o.addDoc)((0,o.collection)(t.Da,C),{uid:r,kind:`notice`,title:n.title,body:n.body||``,link:n.link||``,fromName:t.Ea.currentUser?.displayName||t.Ea.currentUser?.email||``,createdAt:Date.now()})}catch(e){console.warn(`leaveNotice(): the notice was not saved — only an admin may leave one.`,e)}}async function T(e,t){for(let n of[...new Set(e.map(e=>String(e||``).trim()).filter(Boolean))])await w(n,t)}function E(e,n,r){if(n?.own===!0)return null;let i=n?.start?t.un(new Date(String(n.start)),r):``,a=t.Yt({scheduleName:n?.scheduleName,memberName:n?.memberName}),o=String(n?.cancelReason||``).trim(),s={id:`b_${e}`,groupKey:n?.entryId?`${n.entryId}__${String(n.start||``)}`:``,type:`booking`,link:`/my-bookings`};return n?.cancelled===!0?String(n.cancelledSide||``)===`booker`?null:{...s,title:`Booking cancelled`,subtitle:[a,i,o].filter(Boolean).join(` · `),time:typeof n.cancelledAt==`number`&&n.cancelledAt>0?n.cancelledAt:n.createdAt}:n?.pending!==!0&&typeof n?.acceptedAt==`number`&&n.acceptedAt>0?{...s,title:`Booking confirmed`,subtitle:[a,i].filter(Boolean).join(` · `),time:n.acceptedAt}:null}function D(e,t){let n=new Map;for(let t of e){let e=t.data()||{};if(e.own===!0)continue;let r=e.entryId?`${e.entryId}__${String(e.start||``)}`:t.id,i=n.get(r);i?i.push({id:t.id,data:e}):n.set(r,[{id:t.id,data:e}])}let r=[];for(let e of n.values()){let n=e.find(e=>e.data.cancelled===!0&&String(e.data.cancelledSide||``)!==`booker`&&String(e.data.cancelReason||``).trim())||e.find(e=>e.data.cancelled===!0);if(n){let e=E(n.id,n.data,t);e&&r.push(e);continue}if(e.every(e=>E(e.id,e.data,t)?.title===`Booking confirmed`)){let n=e.reduce((e,t)=>t.data.acceptedAt>e.data.acceptedAt?t:e),i=E(n.id,n.data,t);i&&r.push(i)}}return r}function O(){let[e,n]=(0,r.useState)(!1),[a,s]=(0,r.useState)([]),l=(0,r.useRef)(null),u=(0,r.useRef)(null),[d,f]=(0,r.useState)(null),p=(0,c.useNavigate)(),{user:m,userRole:h,roleConfirmed:g}=t.na(),_=h===`admin`,v=t.fa(h);(0,r.useEffect)(()=>{function e(e){l.current&&!l.current.contains(e.target)&&n(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let y=(0,r.useRef)({users:[],submissions:[],requests:[],direct:[],rolewide:[],bookings:[],booked:[],bookedByEmail:[],notices:[]}),b=(0,r.useRef)(!1);(0,r.useEffect)(()=>{b.current=!1},[m?.uid]);let S=(e,t)=>{y.current[e]=t;let n=y.current,r=new Set,i=[...n.users,...n.submissions,...n.requests,...n.direct,...n.rolewide,...n.bookings,...n.booked,...n.bookedByEmail,...n.notices].filter(e=>r.has(e.id)?!1:(r.add(e.id),!0));i.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)}),s(i.slice(0,8))},w=(e,t)=>{b.current||(b.current=!0,console.warn(`AdminNotifications: this account could not read one of the notification feeds, so that part of the bell is empty. Most of them are the team's alone, and every one of them asks for a verified address.`,t)),S(e,[])};(0,r.useEffect)(()=>{let e=[];if(g){if(_){let n=(0,o.query)((0,o.collection)(t.Da,`user_profiles`),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(5));e.push((0,o.onSnapshot)(n,e=>{S(`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,link:`/users/${e.id}`}}))},e=>w(`users`,e)));let r=(0,o.query)((0,o.collection)(t.Da,`user_submissions`),(0,o.orderBy)(`submittedAt`,`desc`),(0,o.limit)(5));e.push((0,o.onSnapshot)(r,e=>{S(`submissions`,e.docs.filter(e=>e.data()?.formId!==`booking`&&!t.on(e.data()||{})).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,link:`/inbox?open=${encodeURIComponent(`anyone:${e.id}`)}`}}))},e=>w(`submissions`,e)));let i=(0,o.query)((0,o.collection)(t.Da,`user_requests`),(0,o.orderBy)(`submittedAt`,`desc`),(0,o.limit)(5));e.push((0,o.onSnapshot)(i,e=>{S(`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,link:`/inbox?open=${encodeURIComponent(`signedIn:${e.id}`)}`}}))},e=>w(`requests`,e)))}else S(`users`,[]),S(`submissions`,[]),S(`requests`,[]);if(m?.uid&&(_||v)){let n=e=>{let n=e.data()||{};if(n.own===!0)return null;let r=n.cancelled===!0,i=String(n.cancelledSide||``)!==`booker`&&String(n.cancelledByUid||``)===(m?.uid||``);if(r&&i)return null;let a=n.start?t.un(new Date(String(n.start)),t.an()):``,o=t.cn({name:n.name}),s=String(n.cancelReason||``).trim();return{id:`b_${e.id}`,groupKey:n.entryId?`${n.entryId}__${String(n.start||``)}`:``,type:`booking`,title:r?`Booking cancelled`:n.pending===!0?`Booking to accept`:`New booking`,subtitle:[o,a,r?s:``].filter(Boolean).join(` · `),time:r&&typeof n.cancelledAt==`number`&&n.cancelledAt>0?n.cancelledAt:n.createdAt,link:`/schedule?open=${encodeURIComponent(e.id)}`}},r=e=>{let t=new Set,n=[];for(let r of e)if(r){if(r.groupKey){if(t.has(r.groupKey))continue;t.add(r.groupKey)}n.push(r)}return n},i=_?(0,o.query)((0,o.collection)(t.Da,t.ht),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(5)):(0,o.query)((0,o.collection)(t.Da,t.ht),(0,o.where)(`memberId`,`==`,m.uid));e.push((0,o.onSnapshot)(i,e=>S(`bookings`,r(e.docs.map(n))),e=>w(`bookings`,e)))}else S(`bookings`,[]);if(m?.uid){let n=t.an(),r=e=>D(e.docs,n),i=(0,o.query)((0,o.collection)(t.Da,t.ht),(0,o.where)(`uid`,`==`,m.uid));e.push((0,o.onSnapshot)(i,e=>S(`booked`,r(e)),e=>w(`booked`,e)));let a=String(m.email||``).trim().toLowerCase();if(a){let n=(0,o.query)((0,o.collection)(t.Da,t.ht),(0,o.where)(`email`,`==`,a));e.push((0,o.onSnapshot)(n,e=>S(`bookedByEmail`,r(e)),e=>w(`bookedByEmail`,e)))}else S(`bookedByEmail`,[])}else S(`booked`,[]),S(`bookedByEmail`,[]);if(m?.uid){let n=(0,o.query)((0,o.collection)(t.Da,C),(0,o.where)(`uid`,`==`,m.uid)),r=e=>{let t=e.data()||{};return{id:`n_${e.id}`,type:`message`,title:String(t.title||`Notification`),subtitle:String(t.body||``),time:t.createdAt,link:typeof t.link==`string`&&t.link.startsWith(`/`)?t.link:void 0}};e.push((0,o.onSnapshot)(n,e=>{S(`notices`,e.docs.filter(e=>(e.data()||{}).kind===`notice`).map(r))},e=>w(`notices`,e)))}else S(`notices`,[]);if(m?.uid&&(_||v)){let n=e=>{let t=e.data();return{id:`m_${e.id}`,type:`message`,title:t.title||`Notification`,subtitle:t.body||t.fromName||``,time:t.createdAt,link:typeof t.link==`string`&&t.link.startsWith(`/`)?t.link:void 0}},r=(0,o.query)((0,o.collection)(t.Da,x),(0,o.where)(`toUid`,`==`,m.uid));e.push((0,o.onSnapshot)(r,e=>S(`direct`,e.docs.map(n)),e=>w(`direct`,e)));let i=_?[`admin`,`internal`]:[`internal`],a=(0,o.query)((0,o.collection)(t.Da,x),(0,o.where)(`toRole`,`in`,i));e.push((0,o.onSnapshot)(a,e=>S(`rolewide`,e.docs.map(n)),e=>w(`rolewide`,e)))}else S(`direct`,[]),S(`rolewide`,[]);return()=>e.forEach(e=>e())}},[_,v,m?.uid,m?.email,g]);let[T,E]=(0,r.useState)(()=>typeof window<`u`?parseInt(localStorage.getItem(`admin_notifications_last_read`)||`0`,10):0),O=()=>{let t=!e;if(n(t),t){let e=u.current?.getBoundingClientRect();f(typeof window<`u`&&window.innerWidth<640&&e?e.bottom+8:null);let t=Date.now();E(t),typeof window<`u`&&localStorage.setItem(`admin_notifications_last_read`,t.toString())}},k=a.some(e=>{if(!e.time)return!0;let t=e.time?.toDate?e.time.toDate().getTime():new Date(e.time).getTime();return t>T||isNaN(t)}),A=e=>{n(!1),e.link?p(e.link):e.type===`user`?p(`/users`):e.type===`booking`?p(v?`/schedule`:`/my-bookings`):(e.type===`submission`||e.type===`request`)&&p(`/inbox`)},j=e=>{if(!e)return``;let t=e.toDate?e.toDate():new Date(e),n=Date.now()-t.getTime();if(isNaN(n))return``;let r=Math.floor(n/6e4);if(r<1)return`now`;if(r<60)return`${r}m`;let i=Math.floor(r/60);if(i<24)return`${i}h`;let a=Math.floor(i/24);return a<7?`${a}d`:new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`}).format(t)};return(0,i.jsxs)(`div`,{className:`relative z-50 flex-shrink-0`,ref:l,children:[(0,i.jsxs)(`button`,{ref:u,onClick:O,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] transition-all relative text-foreground/60 hover:bg-foreground/5 hover:text-foreground flex items-center justify-center shadow-sm cursor-pointer`,"aria-label":`Notifications`,children:[(0,i.jsx)(t.Ki,{className:`w-4 h-4`}),k&&(0,i.jsx)(`span`,{className:`absolute top-1.5 right-1.5 w-2 h-2 bg-[var(--notification-icon-color)] rounded-full animate-pulse`})]}),(0,i.jsx)(t.pr,{children:e&&(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:-5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98,y:-5},className:`${d===null?`absolute top-full mt-2 right-0`:`fixed right-4`} w-[min(320px,calc(100vw-2rem))] md:w-[400px] glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col origin-top-right overflow-hidden`,style:d===null?void 0:{top:d},children:[(0,i.jsxs)(`div`,{className:`px-4 border-b border-[var(--panel-border)]/50 pb-3 pt-4 flex items-center justify-between`,children:[(0,i.jsx)(`span`,{className:`font-bold text-[14px] text-foreground tracking-wide`,children:`Notifications`}),(_||v)&&(0,i.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest text-accent bg-accent/10 px-2 py-0.5 rounded-md`,children:_?`Admin`:`Team`})]}),(0,i.jsx)(`div`,{className:`max-h-[350px] overflow-y-auto w-full p-2 flex flex-col gap-1`,children:a.length===0?(0,i.jsx)(`div`,{className:`p-6 text-center text-foreground/40 text-[13px] font-medium`,children:`No recent activity.`}):a.map(e=>(0,i.jsxs)(`button`,{onClick:()=>A(e),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,i.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,i.jsx)(t.Sr,{className:`w-4 h-4`}):e.type===`booking`?(0,i.jsx)(t.Wi,{className:`w-4 h-4`}):e.type===`submission`?(0,i.jsx)(t.Zr,{className:`w-4 h-4`}):e.type===`message`?(0,i.jsx)(t.Ki,{className:`w-4 h-4`}):(0,i.jsx)(t.ji,{className:`w-4 h-4`})}),(0,i.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,i.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground group-hover:text-accent transition-colors truncate flex-1 min-w-0`,children:e.title}),(0,i.jsx)(`span`,{className:`text-[10px] font-mono tracking-wide text-foreground/40 shrink-0`,children:j(e.time)})]}),(0,i.jsx)(`span`,{className:`text-[12px] text-foreground/60 truncate`,children:e.subtitle})]})]},e.id))})]})})]})}var k=[{id:`guide`,hidden:!1},{id:`contact`,hidden:!1},{id:`templates`,hidden:!1}],A={drive:`assets`,submissions:`inbox`,requests:`inbox`},j=new Set([`setup`]),M=e=>{let t=(e||[]).map(e=>typeof e==`string`?{id:e,hidden:!1}:{id:String(e.id),hidden:!!e.hidden}).map(e=>({...e,id:A[e.id]||e.id})).filter(e=>!j.has(e.id));return t.filter((e,n)=>t.findIndex(t=>t.id===e.id)===n)},N=[{id:`inbox`,hidden:!1},{id:`users`,hidden:!1},{id:`pages`,hidden:!1},{id:`schedule`,hidden:!1},{id:`mybookings`,hidden:!1},{id:`payments`,hidden:!1},{id:`email`,hidden:!1},{id:`forms`,hidden:!1},{id:`theme`,hidden:!1},{id:`assets`,hidden:!1},{id:`publish`,hidden:!1}],P={route:`/support`,template:`popup_form`,form:`support`,tabName:`Support`,iconName:``};function F(e,t,n,r){let i=0,a=!0;for(let r=0;r<e.length;r++)if(i+=e[r]+(r>0?n:0),i>t){a=!1;break}if(a)return e.length;let o=0,s=0;for(let i=0;i<e.length;i++){let a=o+e[i]+(i>0?n:0);if(a+r>t)break;o=a,s++}return Math.max(s,1)}var I=`Could not reach the server. Check your connection and try again.`,L={goTo(e){window.location.href=e}},R=`/api/payments/webhook`,z=e=>e?`${e.replace(/\/$/,``)}${R}`:``;async function B(){try{let e=t.Ea?.currentUser;return e?await e.getIdToken():null}catch{return null}}function V(e){return e?{Authorization:`Bearer ${e}`}:{}}async function H(e,t){try{let t=await e.json();if(t&&typeof t.error==`string`&&t.error)return t.error}catch{}return t}async function U(e){let t=await W(e);return typeof t==`string`?t:(L.goTo(t.url),null)}async function W(e){try{let t=await B(),n=await fetch(`/api/payments/checkout`,{method:`POST`,headers:{"Content-Type":`application/json`,...V(t)},body:JSON.stringify({...e,origin:window.location.origin})});if(!n.ok)return await H(n,`The payment could not be started. Please try again.`);let r=await n.json();return r?.url?{sessionId:String(r.sessionId||``),url:String(r.url)}:`The payment could not be started. Please try again.`}catch{return I}}async function G(){let e=await B();if(!e)return`Sign in to manage your plan.`;try{let t=await fetch(`/api/payments/portal`,{method:`POST`,headers:{"Content-Type":`application/json`,...V(e)},body:JSON.stringify({origin:window.location.origin})});if(!t.ok)return await H(t,`The billing portal could not be opened.`);let n=await t.json();return n?.url?(L.goTo(String(n.url)),null):`The billing portal could not be opened.`}catch{return I}}async function ee(e){let t={paid:!1,paymentStatus:null,amountTotal:null,currency:null,customerEmail:null,metadata:{},error:null};if(!e)return{...t,error:`No payment session to confirm.`};try{let n=await fetch(`/api/payments/session/${encodeURIComponent(e)}`);if(!n.ok)return{...t,error:await H(n,`That payment could not be found.`)};let r=await n.json();return{paid:r?.paid===!0,paymentStatus:r?.paymentStatus??null,amountTotal:r?.amountTotal??null,currency:r?.currency??null,customerEmail:r?.customerEmail??null,metadata:r?.metadata||{},error:null}}catch{return{...t,error:I}}}var K=null;function q(){return K||=fetch(`/api/payments/status`).then(e=>e.json()).then(e=>({configured:e?.configured===!0&&e?.enabled!==!1,mode:e?.mode??null})).catch(()=>(K=null,{configured:!1,mode:null})),K}function J(){K=null}function Y(){let[e,t]=(0,r.useState)({loading:!0,configured:!1,mode:null});return(0,r.useEffect)(()=>{let e=!1;return q().then(n=>{e||t({loading:!1,...n})}),()=>{e=!0}},[]),e}function te(){let[e,t]=(0,r.useState)({loading:!0,active:!1,subscriptions:[],payments:[],error:null});return(0,r.useEffect)(()=>{let e=!1,n=n=>{e||t({loading:!1,...n})};return(async()=>{let e=await B();if(!e)return n({active:!1,subscriptions:[],payments:[],error:null});try{let t=await fetch(`/api/payments/me`,{headers:V(e)});if(!t.ok)return n({active:!1,subscriptions:[],payments:[],error:await H(t,`Your payments could not be loaded.`)});let r=await t.json();return n({active:r?.active===!0,subscriptions:r?.subscriptions||[],payments:r?.payments||[],error:null})}catch{return n({active:!1,subscriptions:[],payments:[],error:I})}})(),()=>{e=!0}},[]),e}function ne(){let[e,t]=(0,r.useState)({loading:!0,charges:[],subscriptions:[],error:null});return(0,r.useEffect)(()=>{let e=!1,n=n=>{e||t({loading:!1,...n})};return(async()=>{let e=await B();if(!e)return n({charges:[],subscriptions:[],error:`Please sign in first.`});try{let t=await fetch(`/api/payments/sales`,{headers:V(e)});if(!t.ok)return n({charges:[],subscriptions:[],error:await H(t,`The sales could not be loaded.`)});let r=await t.json();return n({charges:r?.charges||[],subscriptions:r?.subscriptions||[],error:null})}catch{return n({charges:[],subscriptions:[],error:I})}})(),()=>{e=!0}},[]),e}var re={"/guide":t.Mi,"/templates":t.ai,"/contact":t.Zr},X=e=>e&&re[e]||t.ci;function Z({onNavigate:e}){let{subscriptions:n,payments:r}=te();return n.length===0&&r.length===0?null:(0,i.jsxs)(c.Link,{to:`/billing`,onClick:e,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,i.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,i.jsx)(t.wi,{className:`w-3 h-3 text-accent`})}),`Billing`]})}function Q(){let{subscriptions:e}=te(),t=e.find(e=>e.active&&e.productName)?.productName;return(0,i.jsx)(i.Fragment,{children:t||`Member`})}var ie={guide:{label:`Guide`,path:`/guide`},templates:{label:`Templates`,path:`/templates`},contact:{label:`Contact`,path:`/contact`}},ae=new Set([`setup`]);function oe({customMenu:e,standalone:n}){let{user:a,userRole:s,signOut:l,roleResolved:u}=t.na(),d=u!==!1,f=t.pa(s),p=t.ha(s),m=t.ia[p],[h,g]=(0,r.useState)(!1),[_,v]=(0,r.useState)(null),[y,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(!1),[w,T]=(0,r.useState)(!1),E=a?.displayName||a?.email?.split(`@`)[0]||`User`,D=E.charAt(0).toUpperCase()+E.slice(1),{theme:A,toggleTheme:j,activeConfig:N,canSwitchTheme:I}=t.ja(),L=async()=>{await l(),g(!1)},[R,z]=(0,r.useState)({...ie}),[B,V]=(0,r.useState)(k),[H,U]=(0,r.useState)(P.tabName);(0,r.useEffect)(()=>{if(!t.Da)return;let e=(0,o.onSnapshot)((0,o.collection)(t.Da,`sys_pages`),e=>{let t={...ie};for(let[e,n]of b()){if(!n.isPublic)continue;let r=n.config||{};if(r.enabled===!1)continue;let i=r.route?r.route.startsWith(`/`)?r.route:`/`+r.route:`/`+e;t[e]={label:r.pageName||r.pageTitle||r.title||e,path:i}}e.forEach(e=>{let n=e.data();if(n.enabled===!1)return;let r=n.pageName||n.title||ie[e.id]?.label||e.id,i=n.route||(e.id===`home`?`/`:`/`+e.id);t[e.id]={label:r,path:i}});for(let e of ae)delete t[e];z(t)},e=>{console.warn(`sys_pages snapshot error (safe to ignore during auth transition):`,e)}),n=(0,o.onSnapshot)((0,o.doc)(t.Da,`sys_configs`,`page_order`),e=>{V(e.exists()&&Array.isArray(e.data().order)?M(e.data().order):k)},e=>{console.warn(`page_order snapshot error (safe to ignore during auth transition):`,e)}),r=(0,o.onSnapshot)((0,o.doc)(t.Da,`sys_tabs`,`support`),e=>{e.exists()&&e.data().pageName&&U(e.data().pageName)},e=>{console.warn(`support snapshot error (safe to ignore during auth transition):`,e)});return()=>{e(),n(),r()}},[]);let W=(()=>{let e=new Set(B.filter(e=>e.hidden).map(e=>e.id)),t=new Set,n=[];return B.forEach(e=>{if(e.hidden||e.id===`home`)return;let r=R[e.id];r&&(n.push({label:r.label,path:r.path}),t.add(e.id))}),Object.entries(R).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})(),G=e||W,ee=(0,r.useRef)(null),K=(0,r.useRef)(null),[q,J]=(0,r.useState)(()=>typeof window<`u`&&window.innerWidth<640);(0,r.useEffect)(()=>{if(typeof window>`u`)return;let e=()=>{let e=window.innerWidth<640;J(t=>(t!==e&&g(!1),e))};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let[Y,te]=(0,r.useState)(G.length);(0,r.useEffect)(()=>{if(n||q)return;let e=()=>{let e=ee.current,t=K.current;if(!e||!t)return;let n=e.clientWidth,r=t.querySelectorAll(`[data-measure-nav]`);if(r.length===0){te(G.length);return}te(F(Array.from(r,e=>e.offsetWidth),n,28,50))},t=requestAnimationFrame(e);if(typeof ResizeObserver>`u`)return()=>cancelAnimationFrame(t);let r=new ResizeObserver(()=>requestAnimationFrame(e));return ee.current&&r.observe(ee.current),()=>{cancelAnimationFrame(t),r.disconnect()}},[G.map(e=>e.label).join(`|`),n,q,G.length]);let ne=G.slice(0,Y),re=G.slice(Y);return(0,i.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,i.jsx)(`div`,{className:`flex items-center min-w-0 z-50`,children:(0,i.jsxs)(c.Link,{to:`/`,className:`flex items-center gap-2 md:gap-2.5 lg:gap-3 group cursor-pointer z-50 min-w-0`,children:[(0,i.jsx)(`div`,{className:`w-8 h-8 md:w-9 md:h-9 rounded-lg glass-panel flex items-center justify-center glow-hover shadow-lg transition-transform duration-500 group-hover:rotate-180 group-active:scale-95 overflow-hidden shrink-0`,children:N?.logoUrl?(0,i.jsx)(`img`,{src:N.logoUrl,alt:`Logo`,className:`w-full h-full object-contain max-md:p-0.5`}):(0,i.jsx)(t.Ci,{className:`w-4 h-4 text-accent`})}),(0,i.jsx)(`span`,{className:`font-bold text-[17px] md:text-[19px] lg:text-[22px] tracking-tight text-gradient transition-all duration-300 drop-shadow-sm truncate`,children:N?.appName||``})]})}),(0,i.jsx)(t.pr,{children:y&&(0,i.jsx)(t.t,{formId:`contact`,onClose:()=>x(!1)})}),(0,i.jsx)(t.pr,{children:S&&(0,i.jsx)(t.t,{formId:`support`,onClose:()=>C(!1)})}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2.5 md:gap-4 z-50 relative ml-auto flex-1 min-w-0 justify-end`,children:[!n&&!a&&!q&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`div`,{ref:K,"aria-hidden":`true`,className:`flex items-center gap-7 whitespace-nowrap px-1`,style:{position:`fixed`,top:-9999,left:0,visibility:`hidden`,height:0,pointerEvents:`none`},children:G.map((e,n)=>(0,i.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,i.jsx)(t.Ri,{className:`w-3 h-3`})]},e.path||n))}),(0,i.jsxs)(`div`,{className:`flex items-center gap-7 mr-6 flex-1 min-w-0 justify-end relative`,ref:ee,children:[ne.map((e,n)=>(0,i.jsxs)(`div`,{className:`relative shrink-0`,onMouseEnter:()=>v(e.label),onMouseLeave:()=>v(null),children:[e.path?(0,i.jsxs)(c.Link,{to:e.path,className:`text-[13px] md:text-[14px] font-bold tracking-wide text-foreground/50 hover:text-accent transition-all cursor-pointer flex items-center gap-1.5`,children:[e.label,e.submenu&&(0,i.jsx)(t.Ri,{className:`w-3 h-3`})]}):(0,i.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,i.jsx)(t.Ri,{className:`w-3 h-3`})]}),e.submenu&&_===e.label&&(0,i.jsx)(`div`,{className:`absolute top-[100%] left-0 pt-2 z-50`,children:(0,i.jsx)(t.fr.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,i.jsx)(c.Link,{to:e.path,className:`px-5 py-3 text-[13px] font-medium text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors`,children:e.label},t):(0,i.jsx)(`button`,{onClick:e.action,className:`px-5 py-3 text-left w-full text-[13px] font-medium text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors`,children:e.label},t))})})]},`${e.path||`no-path`}-${n}`)),re.length>0&&(0,i.jsxs)(`div`,{className:`relative flex items-center shrink-0`,onMouseEnter:()=>g(`overflow`),children:[(0,i.jsx)(`button`,{onClick:()=>g(h===`overflow`?!1:`overflow`),className:`p-1 rounded-lg transition-colors flex items-center ${h===`overflow`?`bg-foreground/5 text-accent`:`text-foreground/50 hover:bg-foreground/5 hover:text-accent`}`,children:(0,i.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,i.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,i.jsx)(`circle`,{cx:`12`,cy:`5`,r:`1`}),(0,i.jsx)(`circle`,{cx:`12`,cy:`19`,r:`1`})]})}),(0,i.jsx)(t.pr,{children:h===`overflow`&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>g(!1)}),(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:5,scale:.98},className:`absolute top-[100%] pt-1 right-0 min-w-[200px] max-h-[350px] overflow-y-auto styled-scrollbars glass-popover border border-[var(--panel-border)] rounded-2xl flex flex-col py-2 z-50 origin-top-right`,children:re.map((e,t)=>e.path?(0,i.jsx)(c.Link,{to:e.path,onClick:()=>g(!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,i.jsx)(`button`,{onClick:()=>{e.action&&e.action(),g(!1)},className:`px-5 py-3 text-left w-full text-[13px] font-bold tracking-wide text-foreground/70 hover:text-foreground hover:bg-foreground/5 transition-colors`,children:e.label},t))})]})})]})]})]}),!n&&!a&&(0,i.jsxs)(i.Fragment,{children:[I&&(0,i.jsx)(`button`,{onClick:j,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] hover:bg-foreground/5 transition-all text-foreground/60 hover:text-foreground flex items-center justify-center shadow-sm shrink-0 cursor-pointer`,"aria-label":`Toggle Theme`,children:A===`dark`?(0,i.jsx)(t.Mr,{className:`w-4 h-4`}):(0,i.jsx)(t.Yr,{className:`w-4 h-4`})}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2.5 shrink-0`,children:[!q&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(c.Link,{to:`/login`,className:`flex text-[14px] font-bold tracking-wide text-foreground/80 hover:text-accent transition-colors px-3 py-1.5 shrink-0`,children:`Sign In`}),(0,i.jsx)(c.Link,{to:`/register`,className:`flex text-[13px] md:text-[14px] font-bold tracking-wide px-4 py-1.5 md:px-5 md:py-2 rounded-xl btn-primary transition-all duration-300 hover:shadow-lg hover:-translate-y-0.5 active:scale-95 items-center justify-center ml-2 shrink-0`,children:`Get Started`})]}),q&&(0,i.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,i.jsx)(`button`,{onClick:()=>g(h===`guest`?!1:`guest`),"aria-label":`Open menu`,"aria-expanded":h===`guest`,className:`w-9 h-9 rounded-xl glass-panel glow-hover border transition-all flex items-center justify-center ${h===`guest`?`border-accent bg-foreground/5`:`border-[var(--panel-border)] hover:bg-foreground/5`}`,children:(0,i.jsx)(t.Xr,{className:`w-5 h-5 text-accent/80`})}),(0,i.jsx)(t.pr,{children:h===`guest`&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>g(!1)}),(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:-10,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.95},className:`absolute top-full right-0 mt-3 w-[220px] p-2 glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col gap-1 origin-top-right`,children:[G.map((e,t)=>{let n=X(e.path);return e.path?(0,i.jsxs)(c.Link,{to:e.path,onClick:()=>g(!1),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all min-w-0`,children:[(0,i.jsx)(n,{className:`w-4 h-4 text-accent/70 shrink-0`}),` `,(0,i.jsx)(`span`,{className:`text-[14px] font-semibold truncate`,children:e.label})]},`${e.path}-${t}`):(0,i.jsxs)(`button`,{onClick:()=>{e.action&&e.action(),g(!1)},className:`flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-foreground/5 text-foreground/80 hover:text-foreground transition-all w-full text-left min-w-0`,children:[(0,i.jsx)(n,{className:`w-4 h-4 text-accent/70 shrink-0`}),` `,(0,i.jsx)(`span`,{className:`text-[14px] font-semibold truncate`,children:e.label})]},`${e.label}-${t}`)}),(0,i.jsx)(`div`,{className:`pt-2 mt-1 border-t border-[var(--panel-border)]/50 flex flex-col gap-1`,children:(0,i.jsxs)(c.Link,{to:`/login`,onClick:()=>g(!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,i.jsx)(t.$r,{className:`w-4 h-4 text-accent/70`}),` `,(0,i.jsx)(`span`,{className:`text-[14px] font-semibold`,children:`Sign In`})]})})]})]})})]})]})]}),!n&&a&&(0,i.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[d&&!!a&&(0,i.jsx)(O,{}),I&&(0,i.jsx)(`button`,{onClick:j,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] hover:bg-foreground/5 transition-all text-foreground/60 hover:text-foreground flex items-center justify-center shadow-sm shrink-0 cursor-pointer`,"aria-label":`Toggle Theme`,children:A===`dark`?(0,i.jsx)(t.Mr,{className:`w-4 h-4`}):(0,i.jsx)(t.Yr,{className:`w-4 h-4`})}),(0,i.jsxs)(`div`,{className:`relative z-50 flex-shrink-0`,children:[(0,i.jsxs)(`button`,{onClick:()=>g(h===`user`?!1:`user`),className:`flex items-center gap-2 group p-0.5 sm:p-1 sm:pr-2.5 rounded-full hover:bg-foreground/5 transition-all duration-300 cursor-pointer sm:border ${h===`user`?`sm:border-accent/50 sm:bg-foreground/5`:`sm:border-[var(--panel-border)] sm:hover:border-accent/30`}`,children:[(0,i.jsx)(`div`,{className:`w-8 h-8 md:w-9 md:h-9 rounded-full bg-accent/10 flex items-center justify-center overflow-hidden border sm:border-0 transition-colors shrink-0 text-accent ${h===`user`?`border-accent/50`:`border-[var(--panel-border)] group-hover:border-accent/30`}`,children:a.photoURL&&!w?(0,i.jsx)(`img`,{src:a.photoURL,alt:`Profile`,className:`w-full h-full object-cover`,onError:()=>T(!0)}):(0,i.jsx)(t.Sr,{className:`w-4 h-4 md:w-5 md:h-5 text-accent`})}),(0,i.jsxs)(`div`,{className:`max-sm:hidden sm:flex flex-col text-left mr-1 justify-center min-w-[70px] max-w-[160px]`,children:[(0,i.jsx)(`span`,{className:`text-[12px] font-extrabold leading-tight text-foreground truncate w-full`,children:D}),d?(0,i.jsx)(`span`,{className:`text-[10px] font-mono tracking-wider leading-tight text-accent truncate w-full mt-0.5 uppercase font-bold`,children:p===`free`?(0,i.jsx)(Q,{}):m}):(0,i.jsx)(`span`,{className:`h-[10px] w-12 rounded bg-foreground/10 animate-pulse mt-1`,"aria-hidden":`true`})]})]}),(0,i.jsx)(t.pr,{children:h===`user`&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>g(!1)}),(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:-5,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,scale:.98,y:-5},className:`absolute top-full mt-2 right-0 w-[280px] md:w-[320px] glass-popover border border-[var(--panel-border)] rounded-2xl p-2 z-50 flex flex-col origin-top-right`,children:[(0,i.jsxs)(`div`,{className:`p-3 border-b border-[var(--panel-border)]/50 mb-1 flex flex-col gap-1.5`,children:[(0,i.jsx)(`span`,{className:`font-bold text-[15px] text-foreground truncate`,children:D}),(0,i.jsx)(`span`,{className:`text-[12px] text-foreground/50 truncate font-mono`,children:a.email})]}),(0,i.jsxs)(`div`,{className:`py-1`,children:[(0,i.jsxs)(c.Link,{to:`/dashboard`,onClick:()=>g(!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,i.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,i.jsx)(t.si,{className:`w-3 h-3 text-accent`})}),`Dashboard`]}),f&&(0,i.jsxs)(c.Link,{to:`/assets`,onClick:()=>g(!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,i.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,i.jsx)(t.pi,{className:`w-3 h-3 text-accent`})}),`Assets`]}),s===`admin`&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(c.Link,{to:`/users`,onClick:()=>g(!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,i.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,i.jsx)(t.xr,{className:`w-3 h-3 text-accent`})}),`Users`]}),(0,i.jsxs)(c.Link,{to:`/inbox`,onClick:()=>g(!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,i.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,i.jsx)(t.di,{className:`w-3 h-3 text-accent`})}),`Inbox`]}),(0,i.jsxs)(c.Link,{to:`/pages`,onClick:()=>g(!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,i.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,i.jsx)(t.ci,{className:`w-3 h-3 text-accent`})}),`Pages`]})]}),s!==`admin`&&(0,i.jsxs)(c.Link,{to:`/support`,onClick:()=>g(!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,i.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,i.jsx)(t.ji,{className:`w-3 h-3 text-accent`})}),H]}),(0,i.jsx)(Z,{onNavigate:()=>g(!1)}),(0,i.jsxs)(c.Link,{to:`/profile`,onClick:()=>g(!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,i.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,i.jsx)(t.Sr,{className:`w-3 h-3 text-accent`})}),`Profile Settings`]})]}),(0,i.jsx)(`div`,{className:`pt-1 mt-1 border-t border-[var(--panel-border)]/50`,children:(0,i.jsxs)(`button`,{onClick:L,className:`flex items-center w-full px-3 py-2.5 rounded-xl text-[13px] font-bold tracking-wide hover:bg-red-500/10 hover:text-red-500 text-foreground/70 transition-all gap-3`,children:[(0,i.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,i.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,i.jsx)(`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`}),(0,i.jsx)(`polyline`,{points:`16 17 21 12 16 7`}),(0,i.jsx)(`line`,{x1:`21`,y1:`12`,x2:`9`,y2:`12`})]})}),`Sign Out`]})})]})]})})]})]}),n&&(0,i.jsx)(i.Fragment,{children:I&&(0,i.jsx)(`button`,{onClick:j,className:`w-9 h-9 rounded-xl border border-[var(--panel-border)] hover:bg-foreground/5 transition-all text-foreground/60 hover:text-foreground flex items-center justify-center shadow-sm shrink-0 cursor-pointer`,"aria-label":`Toggle Theme`,children:A===`dark`?(0,i.jsx)(t.Mr,{className:`w-4 h-4`}):(0,i.jsx)(t.Yr,{className:`w-4 h-4`})})})]})]})}function se(){let[e,n]=(0,r.useState)(null);return(0,i.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,i.jsxs)(t.fr.div,{initial:{opacity:0,y:30},animate:{opacity:1,y:0},transition:{duration:.8},className:`text-center mb-8 md:mb-12`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},transition:{delay:.2},className:`inline-flex items-center gap-2 md:gap-3 px-5 md:px-6 py-2 md:py-2.5 mb-8 md:mb-10 text-[13px] md:text-[15px] font-semibold tracking-wide uppercase rounded-full glass-panel text-foreground glow-hover cursor-pointer`,children:[(0,i.jsx)(t.gr,{className:`w-4 h-4 text-accent`}),` The Open-Source Firebase Starter`]}),(0,i.jsx)(t.fr.h1,{className:`text-4xl sm:text-5xl md:text-6xl lg:text-[4.5rem] font-extrabold tracking-tight mb-6 md:mb-8 text-gradient animate-float leading-[1.1] md:leading-[1.15] px-2`,children:`Your AI Firebase`}),(0,i.jsx)(`p`,{className:`text-[14px] sm:text-[15px] md:text-lg lg:text-xl text-foreground/60 max-w-3xl mx-auto font-medium leading-[1.6] md:leading-[1.7] mb-10 md:mb-14 px-6 md:px-4`,children:`A production-ready Firebase backend template with Auth, Firestore prefix rules, and a clean dashboard — ready for vibe-coded apps.`}),(0,i.jsxs)(t.fr.div,{className:`flex flex-col sm:flex-row items-center justify-center gap-4 sm:gap-6 w-full max-w-2xl mx-auto px-6`,initial:{opacity:0},animate:{opacity:1},transition:{delay:.5},children:[(0,i.jsx)(c.Link,{to:`/register`,style:{borderRadius:`var(--btn-radius, 0.75rem)`},className:`w-full sm:w-auto px-6 md:px-8 py-3 md:py-3.5 font-semibold tracking-wide btn-primary text-[15px] shadow-xl transition-all duration-300 hover:-translate-y-1 active:scale-95 flex items-center justify-center`,children:`Start Building Free`}),(0,i.jsx)(c.Link,{to:`/login`,style:{borderRadius:`var(--btn-radius, 0.75rem)`},className:`w-full sm:w-auto px-6 md:px-8 py-3 md:py-3.5 font-semibold tracking-wide btn-secondary text-[15px] transition-all duration-300 flex items-center justify-center hover:-translate-y-1`,children:`Sign In`})]})]}),(0,i.jsx)(t.pr,{children:e&&(0,i.jsx)(t.t,{onClose:()=>n(null),formId:e})})]})}async function ce(){if(!t.Ea)throw Error(`Firebase is not initialized. Check your configuration.`);let e=new a.GoogleAuthProvider;try{return await(0,a.signInWithPopup)(t.Ea,e),`done`}catch(n){if(n?.code===`auth/popup-blocked`||n?.code===`auth/popup-closed-by-user`||n?.code===`auth/cancelled-popup-request`){let{signInWithRedirect:n}=await import(`firebase/auth`);return await n(t.Ea,e),`redirecting`}throw n}}function le(e,t){let n=e?.code||``;return n===`auth/unauthorized-domain`||(e?.message||``).includes(`requested action is invalid`)?`Google Sign-In failed: your app domain is not authorized. Go to Firebase Console → Authentication → Settings → Authorized domains and add your domain (e.g. localhost or your-app.com).`:n===`auth/network-request-failed`?`Network error — please check your internet connection and Firebase configuration.`:e?.message||t}var ue=[{id:`length`,label:`At least 8 characters`,ok:e=>e.length>=8},{id:`case`,label:`An uppercase and a lowercase letter`,ok:e=>/[a-z]/.test(e)&&/[A-Z]/.test(e)},{id:`number`,label:`A number`,ok:e=>/[0-9]/.test(e)}],de=new Set(`password1.password12.password123.password1234.passw0rd1.p@ssword1.p@ssw0rd1.test1234.test12345.testing123.test123456.qwerty123.qwerty1234.abcd1234.abc12345.welcome1.welcome123.admin123.admin1234.letmein123.iloveyou1.monkey123.football1.changeme1.secret123.summer2024.summer2025`.split(`.`)),fe=e=>e.toLowerCase().replace(/[\s._-]/g,``),pe=e=>de.has(fe(e||``)),me=e=>ue.map(t=>({rule:t,met:t.ok(e||``)}));function he(e){let t=e||``;if(!t)return`Choose a password.`;let n=ue.find(e=>!e.ok(t));return n?`Your password needs ${n.label.toLowerCase()}.`:pe(t)?`That password is one of the first anyone would guess. Please pick another.`:``}function ge(e,t){return t?e===t?``:`Both passwords must be the same.`:`Type your password a second time.`}function _e({value:e,className:n=``}){return(0,i.jsx)(`ul`,{className:`flex flex-col gap-1 ml-1 ${n}`,"aria-label":`Password requirements`,children:me(e).map(({rule:e,met:n})=>(0,i.jsxs)(`li`,{className:`flex items-center gap-2 text-[12.5px] font-medium transition-colors ${n?`text-emerald-500`:`text-foreground/45`}`,children:[n?(0,i.jsx)(t.zi,{className:`w-3.5 h-3.5 shrink-0`}):(0,i.jsx)(`span`,{className:`w-3.5 flex justify-center shrink-0`,children:(0,i.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-foreground/25`})}),e.label]},e.id))})}function ve(){let[e,n]=(0,r.useState)(!1),[a,o]=(0,r.useState)(null),[s,l]=(0,r.useState)(``),[u,d]=(0,r.useState)(``),[f,p]=(0,r.useState)(``),[m,h]=(0,r.useState)(``),g=(0,c.useNavigate)(),{registerUser:_}=t.na();return(0,i.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mt-6 mb-8 md:mt-0 md:mb-0 md:pt-8 md:pb-32`,children:(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5},className:`w-full max-w-[500px] p-5 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,i.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,i.jsxs)(`div`,{className:`mb-5 sm:mb-6 text-center`,children:[(0,i.jsx)(`h3`,{className:`text-[21px] sm:text-3xl font-extrabold mb-1.5 sm:mb-2 text-foreground tracking-tight`,children:`Create an account`}),(0,i.jsx)(`p`,{className:`text-[13.5px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Join Your AI Firebase and start building today.`})]}),a&&(0,i.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:a}),(0,i.jsxs)(`form`,{className:`space-y-3.5 sm:space-y-4`,onSubmit:async e=>{e.preventDefault(),n(!0),o(null);let t=new FormData(e.currentTarget),r=t.get(`email`),a=t.get(`firstName`),l=t.get(`lastName`),d=he(s),f=d?``:ge(s,u);if(p(d),h(f),d||f){o(d||f),n(!1);return}try{await _(r,s,a,l),g(`/verify`)}catch(e){e?.code===`auth/email-already-in-use`?o((0,i.jsxs)(`span`,{children:[`An account with this email already exists.`,` `,(0,i.jsx)(c.Link,{to:`/login?email=${encodeURIComponent(r)}`,className:`font-bold underline hover:text-accent transition-colors`,children:`Sign in?`})]})):e?.code===`auth/weak-password`?o(he(s)||`Please choose a stronger password.`):o(e?.message||`An error occurred during registration.`)}finally{n(!1)}},children:[(0,i.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3.5 sm:gap-4`,children:[(0,i.jsx)(t.lr,{name:`firstName`,label:`First Name`,type:`text`,placeholder:`John`,className:`max-sm:h-11`,required:!0}),(0,i.jsx)(t.lr,{name:`lastName`,label:`Last Name`,type:`text`,placeholder:`Doe`,className:`max-sm:h-11`,required:!0})]}),(0,i.jsx)(t.lr,{name:`email`,label:`Email`,type:`email`,placeholder:`name@example.com`,className:`max-sm:h-11`,required:!0}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,i.jsx)(t.lr,{name:`password`,label:`Password`,type:`password`,placeholder:`••••••••`,className:`max-sm:h-11`,autoComplete:`new-password`,value:s,onChange:e=>{l(e.target.value),f&&p(``),m&&e.target.value===u&&h(``)},onBlur:()=>p(s?he(s):``),error:f,required:!0}),s&&(0,i.jsx)(_e,{value:s})]}),s&&(0,i.jsx)(t.lr,{name:`confirmPassword`,label:`Confirm password`,type:`password`,placeholder:`••••••••`,className:`max-sm:h-11`,autoComplete:`new-password`,value:u,onChange:e=>{d(e.target.value),m&&h(``)},onBlur:()=>h(u?ge(s,u):``),error:m,required:!0}),(0,i.jsx)(`div`,{className:`pt-2`,children:(0,i.jsxs)(t.cr,{type:`submit`,className:`w-full py-2.5 sm:py-3 text-[15px] font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,isLoading:e,children:[`Create Account `,(0,i.jsx)(t.Xi,{className:`ml-2 w-4 h-4 group-hover:translate-x-1 transition-transform shrink-0`})]})})]}),(0,i.jsxs)(`div`,{className:`mt-5 pt-4 sm:mt-6 sm:pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:[(0,i.jsxs)(t.cr,{variant:`secondary`,onClick:async()=>{n(!0),o(null);try{await ce()}catch(e){o(le(e,`Google sign-up failed.`))}finally{n(!1)}},className:`w-full py-2.5 sm:py-3 text-[15px] font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,disabled:e,children:[(0,i.jsxs)(`svg`,{className:`w-5 h-5 mr-3`,viewBox:`0 0 24 24`,children:[(0,i.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,i.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,i.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,i.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,i.jsxs)(`p`,{className:`text-[13.5px] sm:text-[14px] text-foreground/70 font-medium pt-1 sm:pt-2 tracking-wide`,children:[`Already have an account? `,(0,i.jsx)(c.Link,{to:`/login`,className:`text-accent hover:underline font-bold ml-1`,children:`Sign in`})]})]})]})})}function ye(){let[e,n]=(0,r.useState)(!1),[o,s]=(0,r.useState)(null),[l]=(0,c.useSearchParams)(),u=(0,c.useNavigate)(),[d]=(0,r.useState)(l.get(`email`)||``);return(0,i.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mt-6 mb-8 md:mt-0 md:mb-0 md:pt-8 md:pb-32`,children:(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.5},className:`w-full max-w-[480px] p-5 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,i.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,i.jsxs)(`div`,{className:`mb-5 sm:mb-6 text-center`,children:[(0,i.jsx)(`h3`,{className:`text-[21px] sm:text-3xl font-extrabold mb-1.5 sm:mb-2 text-foreground tracking-tight`,children:`Welcome back`}),(0,i.jsx)(`p`,{className:`text-[13.5px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Sign in to Your AI Firebase.`})]}),o&&(0,i.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:o}),(0,i.jsxs)(`form`,{className:`space-y-3.5 sm:space-y-4`,onSubmit:async e=>{e.preventDefault(),n(!0),s(null);let r=new FormData(e.currentTarget),o=r.get(`email`),d=r.get(`password`);try{if(!t.Ea)throw Error(`Firebase is not initialized. Check your configuration.`);await(0,a.signInWithEmailAndPassword)(t.Ea,o,d),u(l.get(`from`)||`/dashboard`,{replace:!0})}catch(e){e?.code===`auth/invalid-credential`||e?.code===`auth/user-not-found`||e?.code===`auth/wrong-password`?s((0,i.jsxs)(`span`,{children:[`Email or Password are incorrect.`,` `,(0,i.jsx)(c.Link,{to:`/reset-password`,className:`font-bold underline hover:text-red-400 transition-colors`,children:`Reset password?`})]})):e?.code===`auth/network-request-failed`?s(`Network error — please check your internet connection and Firebase configuration.`):s(e?.message||`Invalid credentials.`),n(!1)}},children:[(0,i.jsx)(t.lr,{name:`email`,label:`Email`,type:`email`,defaultValue:d,placeholder:`name@example.com`,className:`max-sm:h-11`,required:!0}),(0,i.jsxs)(`div`,{className:`space-y-2`,children:[(0,i.jsxs)(`div`,{className:`flex justify-between items-center pr-1`,children:[(0,i.jsx)(`label`,{className:`text-[14px] md:text-[15px] tracking-wide font-medium text-foreground/80 select-none pb-1`,children:`Password`}),(0,i.jsx)(c.Link,{to:`/reset-password`,className:`text-[13px] md:text-[14px] text-accent hover:underline font-bold tracking-wide`,children:`Forgot Password?`})]}),(0,i.jsx)(t.lr,{name:`password`,type:`password`,placeholder:`••••••••`,className:`max-sm:h-11`,required:!0})]}),(0,i.jsx)(`div`,{className:`pt-2`,children:(0,i.jsxs)(t.cr,{type:`submit`,className:`w-full py-2.5 sm:py-3 text-[15px] sm:text-base font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,isLoading:e,children:[`Sign In `,(0,i.jsx)(t.Xi,{className:`ml-2 w-4 h-4 group-hover:translate-x-1 transition-transform shrink-0`})]})})]}),(0,i.jsxs)(`div`,{className:`mt-5 pt-4 sm:mt-6 sm:pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:[(0,i.jsxs)(t.cr,{variant:`secondary`,onClick:async()=>{n(!0),s(null);try{if(await ce()===`redirecting`)return;u(l.get(`from`)||`/dashboard`,{replace:!0})}catch(e){s(le(e,`Google sign-in failed.`))}finally{n(!1)}},className:`w-full py-2.5 sm:py-3 text-[15px] sm:text-base font-bold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,disabled:e,children:[(0,i.jsxs)(`svg`,{className:`w-5 h-5 mr-3`,viewBox:`0 0 24 24`,children:[(0,i.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,i.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,i.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,i.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,i.jsxs)(`p`,{className:`text-[13.5px] sm:text-[14px] text-foreground/70 font-medium pt-1 sm:pt-2 tracking-wide`,children:[`New here? `,(0,i.jsx)(c.Link,{to:`/register`,className:`text-accent hover:underline font-bold ml-1`,children:`Create account`})]})]})]})})}function be(){let{user:e,refreshUser:n}=t.na(),o=(0,c.useNavigate)(),[s,l]=(0,r.useState)(!1),[u,d]=(0,r.useState)(!1),[f,p]=(0,r.useState)(``);return(0,i.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mb-16`,children:(0,i.jsxs)(t.fr.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,i.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,i.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,i.jsx)(t.Zr,{className:`w-7 h-7 md:w-8 md:h-8 text-accent opacity-90`})}),(0,i.jsx)(`h1`,{className:`text-2xl md:text-3xl font-extrabold mb-3 text-foreground tracking-tight`,children:`Verify your email`}),(0,i.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,i.jsx)(`span`,{className:`font-semibold text-foreground`,children:e?.email}),`. Please check your inbox (and spam folder) to verify your account and access your dashboard.`]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-3 max-w-[360px] mx-auto`,children:[f&&(0,i.jsx)(`div`,{role:`status`,className:`w-full px-4 py-2.5 md:py-3 text-[13px] md:text-[14px] font-semibold leading-snug rounded-xl border ${f.includes(`Failed`)||f.includes(`not verified`)||f.includes(`wrong`)?`text-red-400 bg-red-500/10 border-red-500/20`:`text-emerald-400 bg-emerald-500/10 border-emerald-500/20`}`,children:f}),(0,i.jsx)(t.cr,{variant:`primary`,onClick:async()=>{l(!0),p(``);try{if(t.Ea.currentUser){if(await t.Ea.currentUser.reload(),!t.Ea.currentUser.emailVerified){p(`Email is not verified yet. Please check your inbox.`),l(!1);return}await t.Ea.currentUser.getIdToken(!0),await n(),o(`/dashboard`)}}catch{p(`Something went wrong. Please try again.`),l(!1)}},isLoading:s,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,i.jsx)(t.cr,{variant:`ghost`,onClick:async()=>{if(e){d(!0),p(``);try{await(0,a.sendEmailVerification)(e),p(`Verification email sent! Please check your inbox.`)}catch(e){e?.code===`auth/too-many-requests`?p(`Failed to resend: Please wait a minute before trying again.`):p(e?.message||`Failed to resend. Please try again later.`)}finally{d(!1)}}},isLoading:u,className:`w-full py-2.5 md:py-3 text-[13px] md:text-[14px] font-semibold tracking-wide rounded-xl transition-all hover:-translate-y-0.5`,children:`Resend verification link`})]})]})})}var xe=.72;function Se(e){let t=(0,r.useRef)(null);return(0,r.useLayoutEffect)(()=>{let e=t.current,n=e?.parentElement;if(!e||!n)return;let r=()=>{e.style.removeProperty(`font-size`),e.removeAttribute(`data-fold`);let t=n.clientWidth,r=e.scrollWidth;if(!t||r<=t)return;let i=parseFloat(window.getComputedStyle(e).fontSize)||24,a=t/r;e.style.setProperty(`font-size`,`${(i*Math.max(a,xe)).toFixed(2)}px`,`important`),a<.72&&e.setAttribute(`data-fold`,``)};if(r(),document.fonts?.ready.then(r).catch(()=>{}),typeof ResizeObserver>`u`)return;let i=new ResizeObserver(r);return i.observe(n),()=>i.disconnect()},e),t}var Ce=({className:e,children:n,...r})=>(0,i.jsx)(`h1`,{ref:Se([n]),className:t.ur(`page-title w-fit inline-block tracking-tight mb-3 mt-1 text-gradient`,e),...r,children:n});Ce.displayName=`PageTitle`;var we=/^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i,Te=e=>{let t=String(e??``).trim();return we.test(t)?t:``};function Ee(e,t){let n=String(e??``).trim();if(!n||/^data:/i.test(n))return``;try{let e=new URL(n,t||void 0);return/^https?:$/.test(e.protocol)?e.href:``}catch{return``}}function De(e,t){let n=e?.colors?.light||{},r=Array.isArray(n.buttonGradient)?n.buttonGradient.map(Te).filter(Boolean).slice(0,2):[];return{appName:String(e?.appName||``).replace(/\s+/g,` `).trim().slice(0,60),logoUrl:Ee(e?.logoUrl,t),appUrl:Ee(t,``),accent:Te(n.accent),foreground:Te(n.foreground),buttonText:Te(n.buttonText),buttonGradient:r,panelBg:Te(n.panelBg),panelBorder:Te(n.panelBorder)}}function Oe(e){return{appName:String(e?.appName||``),logoUrl:String(e?.logoUrl||``),appUrl:String(e?.appUrl||``),accent:String(e?.accent||``),foreground:String(e?.foreground||``),buttonText:String(e?.buttonText||``),buttonGradient:Array.isArray(e?.buttonGradient)?e.buttonGradient.map(String):[],panelBg:String(e?.panelBg||``),panelBorder:String(e?.panelBorder||``)}}var ke=``,Ae=e=>/^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/i.test(e);function je(){let e=null;try{e=t.ja().activeConfig}catch{e=null}let n=!!t.na()?.isAdmin,i=typeof window<`u`?window.location.origin:``,a=e&&n?JSON.stringify(De(e,i)):``;(0,r.useEffect)(()=>{if(!a||!t.Da||a===ke)return;let e=!1;return(async()=>{try{let n=(0,o.doc)(t.Da,`sys_configs`,`emailBrand`),r=await(0,o.getDoc)(n);if(e)return;let s=r.exists()?Oe(r.data()):null,c=JSON.parse(a);Ae(i)&&s?.appUrl&&(c.appUrl=s.appUrl),(!s||JSON.stringify(s)!==JSON.stringify(c))&&await(0,o.setDoc)(n,c),ke=a}catch{}})(),()=>{e=!0}},[a])}var Me=t.Sa(`admin`),Ne={inbox:{path:`/inbox`,label:`Inbox`,icon:t.di,roles:Me},users:{path:`/users`,label:`Users`,icon:t.xr,roles:Me},pages:{path:`/pages`,label:`Pages`,icon:t.ci,roles:Me},schedule:{path:`/schedule`,label:`Schedule`,icon:t.Wi,roles:t.Sa(`internal`)},mybookings:{path:`/my-bookings`,label:`My bookings`,icon:t.Gi,roles:t.Sa(`user`)},payments:{path:`/payments`,label:`Payments`,icon:t.wi,roles:Me},email:{path:`/email`,label:`Email`,icon:t.Zr,roles:Me},forms:{path:`/forms`,label:`Forms`,icon:t.Br,roles:Me},theme:{path:`/theme`,label:`Theme`,icon:t.Jr,roles:Me},assets:{path:`/assets`,label:`Assets`,icon:t.pi,roles:Me},publish:{path:`/publish`,label:`Publish App`,icon:t.zr,roles:Me}};function Pe(e){try{let t=localStorage.getItem(e);return t?JSON.parse(t):null}catch{return null}}function Fe({customTabs:e=[]}){let{pathname:n}=(0,c.useLocation)(),{user:a,userRole:s,roleResolved:l}=t.na();je();let u=t.v(``,a?.email||``).bookings.length>0,[d,f]=(0,r.useState)(!1),p=(0,r.useRef)(null),[m,h]=(0,r.useState)(()=>Pe(`fbos_nav_tabs`)??{}),[g,_]=(0,r.useState)(()=>{let e=Pe(`fbos_nav_order`);return Array.isArray(e)?M(e):N}),[v,y]=(0,r.useState)(()=>Pe(`fbos_nav_tabs`)!==null),[x,S]=(0,r.useState)(()=>Pe(`fbos_nav_order`)!==null);(0,r.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.collection)(t.Da,`sys_tabs`),e=>{let t={};e.forEach(e=>{t[e.id]=e.data()}),h(t),y(!0),localStorage.setItem(`fbos_nav_tabs`,JSON.stringify(t))},e=>{console.warn(`sys_tabs snapshot error:`,e),y(!0)}),n=(0,o.onSnapshot)((0,o.doc)(t.Da,`sys_configs`,`tab_order`),e=>{let t=e.exists()&&Array.isArray(e.data().order)?M(e.data().order):N;_(t),S(!0),localStorage.setItem(`fbos_nav_order`,JSON.stringify(t))},e=>{console.warn(`tab_order snapshot error:`,e),S(!0)}),r=setTimeout(()=>{y(!0),S(!0)},3e3);return()=>{e(),n(),clearTimeout(r)}},[]);let C=l!==!1&&v&&x;(0,r.useEffect)(()=>{function e(e){p.current&&!p.current.contains(e.target)&&f(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[]);let w=[...(()=>{let e={};Object.entries(Ne).forEach(([t,n])=>{t===`mybookings`&&!u||(e[t]={id:t,...n,exact:!0})});let n={...m};for(let[e,t]of b())t.isPublic||(n[e]={...t.config,...m[e]});Object.entries(n).forEach(([n,r])=>{let i=e[n],a=i?.icon??t.ci;if(r?.iconName){let e=r.iconName.trim(),n=e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);t.mr[n]?a=t.mr[n]:t.mr[e]&&(a=t.mr[e])}let o=i?.roles??Me;r?.pageType&&(o=t.wa(r)),e[n]={id:n,path:r?.route?r.route.startsWith(`/`)?r.route:`/`+r.route:i?.path??`/`+n,label:r?.tabName||r?.pageTitle||r?.pageName||i?.label||n,icon:a,roles:o,exact:!0}});let r=[],i=new Set;g.forEach(t=>{t.hidden||i.has(t.id)||e[t.id]&&(r.push(e[t.id]),i.add(t.id))});let a=[],o=[];return Object.keys(e).forEach(t=>{if(i.has(t))return;let r=g.find(e=>e.id===t);r?.hidden||(t in n&&!r?a.push(e[t]):o.push(e[t]))}),a.length>0&&r.unshift(...a),o.length>0&&r.push(...o),r})(),...e.map(e=>({...e,id:e.path}))].filter(e=>{let n=t.Ta(s,!!a);return t.Ca(e.roles,n)}),T=(0,r.useRef)(null),E=(0,r.useRef)(null),[D,O]=(0,r.useState)(null);(0,r.useEffect)(()=>{let e=()=>{let e=T.current,t=E.current;if(!e||!t)return;let n=e.clientWidth;if(n===0)return;let r=parseFloat(getComputedStyle(e).columnGap)||40,i=t.querySelectorAll(`[data-measure-tab]`);if(i.length===0){O(w.length);return}O(F(Array.from(i,e=>e.offsetWidth),n,r,52))},t=requestAnimationFrame(e);if(typeof ResizeObserver>`u`)return()=>cancelAnimationFrame(t);let n=new ResizeObserver(()=>requestAnimationFrame(e));return T.current&&n.observe(T.current),()=>{cancelAnimationFrame(t),n.disconnect()}},[w.map(e=>e.id+e.label).join(`|`),w.length,C]);let k=D===null?w:w.slice(0,D),A=D===null?[]:w.slice(D),j=e=>e.exact?n===e.path:n.startsWith(e.path),P=A.some(e=>j(e));return C?w.length===0?null:(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`div`,{ref:E,"aria-hidden":`true`,className:`flex items-center gap-5 md:gap-10 whitespace-nowrap px-1`,style:{position:`fixed`,top:-9999,left:0,visibility:`hidden`,pointerEvents:`none`},children:w.map(e=>{let t=e.icon;return(0,i.jsxs)(`span`,{"data-measure-tab":!0,className:`flex items-center gap-2 text-[13px] md:text-[14.5px] font-semibold shrink-0 pb-2.5 md:pb-3`,children:[(0,i.jsx)(t,{className:`w-4 h-4 md:w-[18px] md:h-[18px]`}),e.label]},e.path||e.id)})}),(0,i.jsxs)(`div`,{ref:T,className:`w-full flex items-center gap-5 md:gap-10 mb-5 border-b border-[var(--panel-border)] px-1 whitespace-nowrap relative`,children:[k.map(e=>{let t=j(e),n=e.icon;return(0,i.jsxs)(c.Link,{to:e.path||`/`,className:`flex items-center gap-2 text-[13px] md:text-[14.5px] font-semibold transition-all duration-300 pb-2.5 md: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,i.jsx)(n,{className:`w-4 h-4 md:w-[18px] md:h-[18px]`}),e.label]},e.path||e.id)}),A.length>0&&(0,i.jsxs)(`div`,{className:`relative shrink-0 ml-auto`,ref:p,children:[(0,i.jsx)(`button`,{onClick:()=>f(!d),className:`flex items-center justify-center transition-all duration-300 pb-2.5 md:pb-3 -mb-[1px] border-b-2 cursor-pointer ${P?`text-accent border-accent`:`text-foreground/50 hover:text-foreground/80 border-transparent`}`,title:`More items`,children:(0,i.jsx)(t.xi,{className:`w-[18px] h-[18px] md:w-5 md:h-5`})}),(0,i.jsx)(t.pr,{children:d&&(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:10},className:`absolute top-[100%] right-0 mt-2 min-w-[200px] glass-popover border border-[var(--panel-border)] rounded-2xl z-50 flex flex-col py-2 overflow-hidden`,children:A.map(e=>{let t=j(e),n=e.icon;return(0,i.jsxs)(c.Link,{to:e.path||`/`,onClick:()=>f(!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,i.jsx)(n,{className:`w-4 h-4`}),e.label]},e.path||e.id)})})})]})]})]}):(0,i.jsx)(`div`,{className:`w-full flex items-center gap-5 md:gap-10 mb-5 border-b border-[var(--panel-border)] px-1 whitespace-nowrap relative`,children:[56,72,64].map((e,t)=>(0,i.jsxs)(`span`,{className:`flex items-center gap-2 pb-2.5 md:pb-3 h-[30px] md:h-[33px] shrink-0`,"aria-hidden":`true`,children:[(0,i.jsx)(`span`,{className:`w-4 h-4 md:w-[18px] md:h-[18px] rounded-md bg-foreground/5 animate-pulse`}),(0,i.jsx)(`span`,{className:`h-3.5 rounded bg-foreground/5 animate-pulse`,style:{width:e}})]},t))})}function Ie(){let{user:e,refreshUser:n,isInternal:c}=t.na(),[l,u]=(0,r.useState)(e?.displayName||``),[d,f]=(0,r.useState)(e?.email||``),[p,m]=(0,r.useState)(e?.photoURL||``),[h,g]=(0,r.useState)(!1),[_,v]=(0,r.useState)(null),[y,b]=(0,r.useState)(``),[x,S]=(0,r.useState)(``),[C,w]=(0,r.useState)(``),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(!1),[k,A]=(0,r.useState)(!0);r.default.useEffect(()=>{u(e?.displayName||``),f(e?.email||``),m(e?.photoURL||``)},[e?.uid,e?.displayName,e?.email,e?.photoURL]);let j=async n=>{if(e)try{if(!c)return;let r=[`mem_files`,`admin_files`];(await(0,o.getDocs)((0,o.collection)(t.Da,`sys_tabs`))).forEach(e=>{let n=e.data(),i=(n.tabName||e.id).toLowerCase().replace(/[^a-z0-9]+/g,`_`),a=t.ga(n.pageType);a===`internal`&&r.push(`mem_${i}_records`),a===`admin`&&r.push(`admin_${i}_records`)});for(let i of r)try{let r=await(0,o.getDocs)((0,o.query)((0,o.collection)(t.Da,i),(0,o.where)(`uid`,`==`,e.uid)));if(r.empty)continue;let a=(0,o.writeBatch)(t.Da);r.docs.forEach(e=>a.update(e.ref,{creatorAvatar:n})),await a.commit()}catch{}}catch(e){console.error(`Error propagating avatar to records:`,e)}},M=async r=>{if(!e)return;let i=await t.or(r,{maxSide:512});if(i.size>2*1024*1024){v({text:`File too large. Please select an image under 2MB.`,type:`error`});return}O(!0),E(!1),A(!0);try{let r=(0,s.ref)(t.ka,`user_avatars/${e.uid}/file.png`);await(0,s.uploadBytes)(r,i,{customMetadata:{ownerId:e.uid}});let c=await(0,s.getDownloadURL)(r);m(c);let l=(0,o.doc)(t.Da,`user_profiles`,e.uid);await Promise.all([(0,a.updateProfile)(e,{photoURL:c}),(0,o.updateDoc)(l,{avatar:c}),j(c)]),await n(),v({text:`Avatar successfully updated!`,type:`success`})}catch(e){console.error(e),v({text:`Failed to upload photo.`,type:`error`})}finally{O(!1)}},N=e=>{let t=e.target.files?.[0];t&&M(t)},{over:P,dropProps:F}=t.er({accept:`image/*`,disabled:D,onFiles:([e])=>M(e),onReject:()=>v({text:`That is not a picture. Drop a JPG or a PNG.`,type:`error`})}),I=async()=>{if(e){O(!0),E(!1),A(!1);try{let r=(0,s.ref)(t.ka,`user_avatars/${e.uid}/file.png`);m(``),O(!1);let i=(0,o.doc)(t.Da,`user_profiles`,e.uid);await Promise.all([(0,s.deleteObject)(r).catch(e=>console.error(e)),(0,a.updateProfile)(e,{photoURL:``}),(0,o.updateDoc)(i,{avatar:``}),j(``)]),await n(),v({text:`Avatar removed.`,type:`success`})}catch(e){console.error(e),v({text:`Failed to delete photo.`,type:`error`}),O(!1)}}};return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-5 sm:mb-8`,children:[(0,i.jsx)(Ce,{children:`Profile Settings`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/profile`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-6 animate-in fade-in duration-500 pb-20`,children:[(0,i.jsx)(`div`,{className:`flex justify-start`,children:(0,i.jsx)(Fe,{})}),(0,i.jsx)(t.pr,{children:_&&(0,i.jsxs)(t.fr.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,i.jsx)(t.Ni,{className:`w-5 h-5 shrink-0`}):(0,i.jsx)(t.Pi,{className:`w-5 h-5 shrink-0`}),(0,i.jsx)(`span`,{className:`text-[14px] font-semibold tracking-wide leading-relaxed`,children:_.text})]})}),(0,i.jsx)(`form`,{onSubmit:async r=>{if(r.preventDefault(),e){g(!0),v(null);try{l!==e.displayName&&await(0,a.updateProfile)(e,{displayName:l});let r=!1;if(d!==e.email){let n=await(0,a.fetchSignInMethodsForEmail)(t.Ea,d);if(n&&n.length>0)throw Error(`An account with this email already exists.`);await(0,a.verifyBeforeUpdateEmail)(e,d),r=!0}if(y){let t=he(y);if(t)throw Error(t);let n=ge(y,x);if(n)throw w(n),Error(n);await(0,a.updatePassword)(e,y),b(``),S(``),w(``)}await n(),v(r?{text:`Profile updated. A verification link has been sent to your new email address.`,type:`success`}:{text:`Profile successfully updated.`,type:`success`})}catch(e){console.error(e),e.code===`auth/requires-recent-login`?v({text:`For security, please sign out and sign back in before changing your email or password.`,type:`error`}):v({text:e.message||`Failed to update profile.`,type:`error`})}finally{g(!1)}}},className:`w-full flex flex-col`,children:(0,i.jsxs)(`div`,{className:`glass-panel w-full p-5 sm:p-8 md:p-12 rounded-3xl border border-[var(--panel-border)] shadow-2xl space-y-8 md:min-h-[500px]`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-4 sm:gap-5 pb-6 border-b border-[var(--panel-border)]/50`,children:[(0,i.jsxs)(`div`,{...F,className:`relative shrink-0 group/avatar rounded-full transition-shadow ${P?`ring-2 ring-accent ring-offset-2 ring-offset-background`:``}`,children:[(0,i.jsxs)(`div`,{className:`w-16 h-16 sm:w-20 sm:h-20 rounded-full glass-panel border-2 border-[var(--panel-border)] shadow-lg bg-accent/10 flex items-center justify-center relative overflow-hidden`,children:[(D||p&&k&&!T)&&(0,i.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-accent/5 backdrop-blur-sm z-10`,children:(0,i.jsx)(t.ti,{className:`w-6 h-6 text-accent animate-spin`})}),p&&!T?(0,i.jsx)(`img`,{src:p,alt:`Avatar`,className:`w-full h-full object-cover transition-opacity duration-300 ${k?`opacity-0`:`opacity-100`}`,onLoad:()=>A(!1),onError:()=>{E(!0),A(!1)}}):(0,i.jsx)(t.Sr,{className:`w-7 h-7 sm:w-8 sm:h-8 text-accent`})]}),!D&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(`label`,{title:p?`Change photo`:`Upload photo`,className:`absolute inset-0 rounded-full bg-background/60 backdrop-blur-[2px] opacity-0 group-hover/avatar:opacity-100 focus-within:opacity-100 flex items-center justify-center cursor-pointer transition-opacity z-20`,children:[(0,i.jsx)(t.Bi,{className:`w-4 h-4 text-foreground`}),(0,i.jsx)(`input`,{type:`file`,accept:`image/*`,"aria-label":`Upload photo`,onChange:N,className:`hidden`})]}),p&&(0,i.jsx)(`button`,{type:`button`,onClick:I,title:`Remove photo`,"aria-label":`Remove photo`,className:`hidden group-hover/avatar:flex absolute -top-1 -right-1 w-6 h-6 rounded-full bg-background border border-[var(--panel-border)] text-foreground/50 hover:text-red-500 hover:border-red-500/40 items-center justify-center shadow-sm cursor-pointer z-30`,children:(0,i.jsx)(t.Or,{className:`w-3 h-3`})})]})]}),(0,i.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,i.jsx)(`h3`,{className:`font-extrabold text-lg sm:text-xl text-foreground mb-1 truncate`,children:l||`User`}),(0,i.jsx)(`p`,{className:`text-[13px] text-foreground/40 mt-1 font-medium break-words`,children:e?.email})]})]}),(0,i.jsxs)(`div`,{className:`space-y-6`,children:[(0,i.jsx)(`h3`,{className:`text-[16px] font-extrabold text-foreground flex items-center gap-2`,children:`Account Details`}),(0,i.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-5 md:gap-6`,children:[(0,i.jsx)(t.lr,{name:`name`,value:l,onChange:e=>u(e.target.value),label:`Display Name`,placeholder:`John Doe`}),(0,i.jsxs)(`div`,{className:`flex flex-col`,children:[(0,i.jsx)(t.lr,{name:`email`,type:`email`,value:d,onChange:e=>f(e.target.value),label:`Email Address`,placeholder:`name@example.com`,required:!0}),(0,i.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,i.jsxs)(`div`,{className:`pt-6 border-t border-[var(--panel-border)]/50`,children:[(0,i.jsx)(`h3`,{className:`text-[15px] font-bold text-foreground mb-4 flex items-center gap-2`,children:`Change Password`}),(0,i.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-5 md:gap-6`,children:[(0,i.jsx)(t.lr,{name:`password`,type:`password`,label:`New Password`,autoComplete:`new-password`,value:y,onChange:e=>{b(e.target.value),C&&e.target.value===x&&w(``)},placeholder:`At least 8 characters`}),(0,i.jsx)(t.lr,{name:`confirmPassword`,type:`password`,label:`Confirm New Password`,autoComplete:`new-password`,value:x,onChange:e=>{S(e.target.value),C&&w(``)},onBlur:()=>w(x?ge(y,x):``),error:C,placeholder:`Type it a second time`})]}),y&&(0,i.jsx)(_e,{value:y,className:`mt-3`})]}),(0,i.jsx)(`div`,{className:`pt-6 md:pt-8 border-t border-[var(--panel-border)]/50 flex justify-start w-full`,children:(0,i.jsx)(t.cr,{type:`submit`,isLoading:h,className:`w-full sm:w-auto sm:px-12 py-3 md:py-2.5 text-[14px] md:text-[15px] font-bold tracking-wide rounded-xl hover:-translate-y-0.5`,children:`Save Changes`})})]})})]})]})}function Le(){let[e,n]=(0,r.useState)(!1),[o,s]=(0,r.useState)(null),[l,u]=(0,r.useState)(0),[d,f]=(0,r.useState)(0);return(0,r.useEffect)(()=>{let e;return l>0&&(e=setInterval(()=>u(e=>e-1),1e3)),()=>clearInterval(e)},[l]),(0,i.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mb-16 mt-6 md:mt-0 md:mb-0 md:pt-8 md:pb-32`,children:(0,i.jsxs)(t.fr.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,i.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,i.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,i.jsx)(t.li,{className:`w-7 h-7 md:w-8 md:h-8 text-accent opacity-90`})}),(0,i.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,i.jsx)(`h3`,{className:`text-2xl md:text-3xl font-extrabold mb-2 md:mb-3 text-foreground tracking-tight`,children:`Reset Password`}),(0,i.jsx)(`p`,{className:`text-[14px] md:text-[15px] font-medium text-foreground/60 tracking-wide`,children:`Enter your email to receive a recovery link.`})]}),o&&(0,i.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:o}),(0,i.jsxs)(`form`,{className:`space-y-4 text-left max-w-[360px] mx-auto`,onSubmit:async e=>{e.preventDefault(),n(!0),s(null);let r=new FormData(e.currentTarget).get(`email`);try{await(0,a.sendPasswordResetEmail)(t.Ea,r)}catch(e){console.error(e)}finally{s(`If an account exists, a reset link has been sent. Check your inbox and spam folder.`);let e=d+1;f(e),u(e===1?60:120),n(!1)}},children:[(0,i.jsx)(t.lr,{name:`email`,label:`Work Email`,type:`email`,placeholder:`name@company.com`,required:!0}),(0,i.jsx)(`div`,{className:`pt-2`,children:(0,i.jsx)(t.cr,{type:`submit`,className:`w-full py-2.5 md:py-3 text-[14px] font-bold tracking-wide rounded-xl transition-all ${l>0?`opacity-60 shadow-none cursor-not-allowed pointer-events-none hover:translate-y-0`:`hover:-translate-y-0.5`}`,isLoading:e,disabled:l>0,children:l>0?`Resend link in ${(e=>`${Math.floor(e/60)}:${(e%60).toString().padStart(2,`0`)}`)(l)}`:d>0?`Resend reset password link`:`Send Reset Link`})})]}),(0,i.jsx)(`div`,{className:`mt-6 pt-5 border-t border-[var(--panel-border)] space-y-4 text-center`,children:(0,i.jsxs)(c.Link,{to:`/login`,className:`inline-flex items-center text-[13px] md:text-[14px] text-foreground/70 font-medium hover:text-accent transition-colors tracking-wide`,children:[(0,i.jsx)(t.Zi,{className:`w-4 h-4 mr-2`}),`Back to Sign In`]})})]})})}var Re=`(max-width: 767px)`,ze=()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(Re).matches;function Be(){let[e,t]=(0,r.useState)(ze);return(0,r.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(Re),n=()=>t(e.matches);return n(),e.addEventListener?.(`change`,n),()=>e.removeEventListener?.(`change`,n)},[]),e}function Ve({isOpen:e,title:n,message:r,confirmText:a=`Delete`,cancelText:o=`Cancel`,onConfirm:s,onCancel:c,isProcessing:l=!1,disableConfirm:u=!1}){return(0,i.jsx)(t.pr,{children:e&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>!l&&c(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(0,i.jsx)(t.fr.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`w-full max-w-[400px] p-6 rounded-3xl glass-popover border border-[var(--panel-border)] shadow-2xl relative z-10 text-center`,children:(0,i.jsxs)(`div`,{className:`w-full flex flex-col items-center`,children:[(0,i.jsx)(`h3`,{className:`text-xl font-extrabold mb-2 text-foreground tracking-tight`,children:n}),(0,i.jsx)(`p`,{className:`w-full text-[14px] font-medium text-foreground/60 leading-relaxed mb-6 break-words`,children:r}),(0,i.jsxs)(`div`,{className:`flex items-center gap-3 w-full`,children:[(0,i.jsx)(t.cr,{variant:`secondary`,onClick:c,disabled:l,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:o}),(0,i.jsx)(t.cr,{onClick:s,disabled:l||u,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl bg-red-500 hover:bg-red-600 border-none text-white shadow-xl hover:shadow-red-500/20 glow-hover`,children:l?(0,i.jsx)(t.ti,{className:`w-5 h-5 animate-spin mx-auto`}):a})]})]})})]})})}var He=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/([A-Z])([A-Z][a-z])/g,`$1-$2`).toLowerCase(),Ue=(()=>{let e=t.hr,n=e?Object.keys(e):[];return n.length===0&&(n=Object.keys(t.mr).filter(e=>/^[A-Z]/.test(e)&&!/Icon$/.test(e)&&!/^Lucide/.test(e)&&e!==`IconNode`)),Array.from(new Set(n.map(He))).sort()})(),We=`layers.house.layout-dashboard.list.table.kanban.calendar.clock.file-text.files.folder.hard-drive.upload.download.paperclip.book-open.notebook-pen.users.user.user-plus.contact.building.briefcase.handshake.mail.message-square.message-circle.send.inbox.bell.megaphone.phone.shopping-cart.package.truck.receipt.credit-card.banknote.wallet.tag.percent.chart-bar.chart-line.chart-pie.trending-up.target.gauge.activity.settings.sliders-horizontal.wrench.shield.lock.key.eye.search.star.heart.bookmark.flag.pin.map-pin.globe.circle-check.circle-alert.info.circle-question-mark.life-buoy.sparkles.zap.rocket.camera.image.video.music.mic.palette.pen-tool.scissors.stethoscope.graduation-cap.utensils.plane.car.dumbbell.leaf.sun.moon`.split(`.`),Ge={money:[`banknote`,`wallet`,`credit-card`,`coins`,`dollar-sign`,`receipt`],cash:[`banknote`,`coins`,`wallet`],payment:[`credit-card`,`banknote`,`receipt`],invoice:[`receipt`,`file-text`],price:[`tag`,`dollar-sign`,`receipt`],people:[`users`,`user`,`contact`],customer:[`users`,`contact`,`user-round`],client:[`users`,`contact`,`briefcase`],team:[`users`,`users-round`],staff:[`users`,`id-card`],chat:[`message-circle`,`message-square`,`messages-square`],message:[`message-circle`,`mail`,`send`],email:[`mail`,`send`,`inbox`],task:[`list-checks`,`square-check`,`clipboard-check`],todo:[`list-checks`,`square-check`],project:[`kanban`,`folder-kanban`,`briefcase`],board:[`kanban`,`layout-dashboard`],photo:[`image`,`camera`,`images`],picture:[`image`,`images`],document:[`file-text`,`files`,`file`],doc:[`file-text`,`file`],shop:[`shopping-cart`,`store`,`shopping-bag`],store:[`store`,`shopping-bag`,`shopping-cart`],order:[`shopping-cart`,`package`,`receipt`],delivery:[`truck`,`package`],home:[`house`,`house-heart`],booking:[`calendar-check`,`calendar`,`clock`],appointment:[`calendar-clock`,`calendar`,`clock`],schedule:[`calendar-days`,`calendar`,`clock`],event:[`calendar`,`party-popper`,`ticket`],report:[`chart-bar`,`chart-line`,`file-chart-column`],stats:[`chart-bar`,`chart-line`,`chart-pie`],analytics:[`chart-line`,`chart-bar`,`activity`],help:[`circle-question-mark`,`life-buoy`,`info`],support:[`life-buoy`,`headset`,`circle-question-mark`],idea:[`lightbulb`,`sparkles`],health:[`heart-pulse`,`stethoscope`,`activity`],food:[`utensils`,`chef-hat`,`pizza`],travel:[`plane`,`map`,`luggage`],location:[`map-pin`,`map`,`globe`],address:[`map-pin`,`house`],security:[`shield`,`lock`,`key`],password:[`key`,`lock`],settings:[`settings`,`sliders-horizontal`,`wrench`],file:[`file`,`file-text`,`files`,`folder`],upload:[`upload`,`cloud-upload`],video:[`video`,`film`,`clapperboard`],school:[`graduation-cap`,`book-open`,`school`],course:[`graduation-cap`,`book-open`],gym:[`dumbbell`,`activity`],garden:[`leaf`,`flower`,`sprout`],car:[`car`,`car-front`],pet:[`paw-print`,`dog`,`cat`],note:[`notebook-pen`,`sticky-note`,`pencil`],write:[`pencil`,`pen-tool`,`notebook-pen`],time:[`clock`,`timer`,`hourglass`],star:[`star`,`sparkles`],favourite:[`star`,`heart`,`bookmark`],favorite:[`star`,`heart`,`bookmark`],album:[`images`,`image`,`camera`],gallery:[`images`,`image`,`camera`],profile:[`circle-user`,`user-round`,`id-card`],account:[`circle-user`,`user-round`,`id-card`],member:[`users`,`user-round`,`id-card`],membership:[`id-card`,`users`,`award`],subscription:[`credit-card`,`repeat`,`wallet`],plan:[`clipboard-list`,`layout-list`,`credit-card`],ticket:[`ticket`,`tickets`,`inbox`],request:[`inbox`,`send`,`file-text`],progress:[`trending-up`,`gauge`,`activity`],result:[`chart-bar`,`clipboard-check`,`trophy`],score:[`trophy`,`target`,`star`],library:[`library`,`book-open`,`folder`],lesson:[`graduation-cap`,`book-open`],session:[`calendar-clock`,`clock`,`video`],service:[`wrench`,`handshake`,`briefcase`],statement:[`file-text`,`receipt`,`banknote`],saved:[`bookmark`,`heart`,`star`],list:[`list`,`list-checks`,`layout-list`],detail:[`file-text`,`info`],referral:[`user-plus`,`share`,`gift`],reward:[`gift`,`trophy`,`award`],badge:[`award`,`badge`,`medal`],certificate:[`award`,`file-badge`,`scroll`],download:[`download`,`cloud-download`],history:[`history`,`clock`,`rotate-ccw`],feedback:[`message-square`,`star`,`thumbs-up`],review:[`star`,`message-square`],wishlist:[`heart`,`bookmark`,`star`],cart:[`shopping-cart`,`shopping-bag`],credit:[`coins`,`wallet`,`credit-card`],dashboard:[`layout-dashboard`,`gauge`],welcome:[`hand`,`house`,`sparkles`],onboarding:[`rocket`,`list-checks`,`user-plus`],benefit:[`gift`,`sparkles`,`award`],perk:[`gift`,`sparkles`],resource:[`folder`,`book-open`,`files`],guide:[`book-open`,`compass`,`map`],faq:[`circle-question-mark`,`message-circle`],contract:[`file-pen`,`file-text`,`scroll`],agreement:[`handshake`,`file-pen`],quote:[`file-text`,`receipt`,`tag`],enquiry:[`message-square`,`mail`],inquiry:[`message-square`,`mail`],application:[`file-text`,`clipboard-list`,`send`],form:[`clipboard-list`,`file-text`],submission:[`inbox`,`send`,`file-text`],record:[`folder`,`file-text`,`database`],log:[`history`,`list`,`file-text`]},Ke=new Set([`my`,`our`,`your`,`their`,`the`,`a`,`an`,`all`,`new`,`page`,`pages`,`of`,`and`,`for`,`to`,`in`,`on`,`at`,`is`,`it`,`this`,`that`]),qe=(e,t)=>{if(Math.abs(e.length-t.length)>2)return 3;let n=Array.from({length:t.length+1},(e,t)=>t);for(let r=1;r<=e.length;r++){let i=n[0];n[0]=r;for(let a=1;a<=t.length;a++){let o=n[a];n[a]=Math.min(n[a]+1,n[a-1]+1,i+(e[r-1]===t[a-1]?0:1)),i=o}}return n[t.length]},Je=(e,t)=>{let n=0;for(let r of t)r===e[n]&&n++;return n===e.length};function Ye(e,t=96,n=Ue){let r=e.trim().toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``);if(!r)return[];let i=r.split(`-`).filter(Boolean),a=new Set(n),o=new Map,s=(e,t)=>{a.has(e)&&o.set(e,Math.max(o.get(e)||0,t))};for(let e of n){let t=e.split(`-`);if(e===r){s(e,100);continue}if(e.startsWith(r)){s(e,90);continue}if(t.some(e=>e===r)){s(e,85);continue}if(t.some(e=>e.startsWith(r))){s(e,75);continue}if(e.includes(r)){s(e,65);continue}if(i.length>1&&i.every(e=>t.some(t=>t.startsWith(e)))){s(e,60);continue}}let c=e=>{(Ge[e]||[]).forEach((e,t)=>s(e,74-t)),e.endsWith(`s`)&&(Ge[e.slice(0,-1)]||[]).forEach((e,t)=>s(e,74-t))};for(let e of i)c(e);if(o.size===0&&i.length>1)for(let e of[...i].reverse()){if(Ke.has(e)||e.length<3)continue;let r=Ye(e,t,n);if(r.length)return r}if(o.size===0&&r.length>=3)for(let e of n)e.split(`-`).some(e=>qe(r,e)<=(r.length>5?2:1))?s(e,40):r.length>=4&&Je(r,e.replace(/-/g,``))&&s(e,20);let l=e=>{let t=We.indexOf(e);return t===-1?We.length:t};return Array.from(o.entries()).sort((e,t)=>t[1]-e[1]||l(e[0])-l(t[0])||e[0].length-t[0].length||e[0].localeCompare(t[0])).slice(0,t).map(([e])=>e)}var Xe=/(<[A-Z][A-Za-z0-9]*(?:\s[^<>]*)?\/?>|src\/[A-Za-z0-9_./-]*[A-Za-z0-9_-]|'[A-Za-z0-9_@./-]+')/g,Ze=/(https?:\/\/[^\s]+)/g,Qe=e=>e.split(Ze).flatMap((e,t)=>t%2==1?[{text:e,kind:`value`}]:e.split(Xe).map((e,t)=>({text:e,kind:t%2==1?`code`:void 0}))).filter(e=>e.text),$e=/exactly: |Here is (?:what|how) [^:]*: |It should ask for: |Where the form belongs on the page: |a button that says /,et=e=>{let t=$e.exec(e);if(!t)return Qe(e);let n=t.index+t[0].length,r=e.slice(0,n),i=e.slice(n),a=i.indexOf(` — `);return[...Qe(r),{text:a===-1?i:i.slice(0,a),kind:`value`},...Qe(a===-1?``:i.slice(a))]},tt=`text-accent font-semibold bg-accent/[0.08] rounded-[4px] px-1 -mx-[1px] [overflow-wrap:anywhere]`,nt=`font-mono text-[0.92em] text-foreground/75 bg-foreground/[0.055] border border-[var(--panel-border)]/60 rounded-[4px] px-1 py-[1px] [overflow-wrap:anywhere]`;function rt({text:e}){return(0,i.jsx)(i.Fragment,{children:et(e).map((e,t)=>e.kind?(0,i.jsx)(`span`,{className:e.kind===`value`?tt:nt,children:e.text},t):(0,i.jsx)(r.default.Fragment,{children:e.text},t))})}function it({title:e=`Ask your assistant`,description:n,prompt:a,compact:o=!1,locked:s=!1,onCopied:c}){let[l,u]=(0,r.useState)(!1),d=a.includes(`
|
|
2
2
|
`);return s?null:(0,i.jsxs)(`div`,{className:`flex flex-col gap-2 min-w-0 max-w-full rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)] ${o?`px-4 py-3.5`:`px-5 py-4`}`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,i.jsx)(`span`,{className:`text-[12px] font-extrabold tracking-tight text-gradient`,children:e}),(0,i.jsxs)(`button`,{type:`button`,onClick:()=>{navigator.clipboard?.writeText(a),u(!0),setTimeout(()=>u(!1),2e3),c&&setTimeout(c,550)},"aria-label":l?`Copied`:`Copy`,className:`inline-flex items-center justify-center gap-1.5 h-8 w-8 px-0 sm:w-auto sm:px-3 rounded-[var(--btn-radius,0.75rem)] text-[12px] font-semibold shrink-0 border ${l?`copy-btn-done border-emerald-500/30 bg-emerald-500/10 text-emerald-500 cursor-pointer`:`copy-btn cursor-pointer`}`,children:[l?(0,i.jsx)(t.zi,{className:`copy-icon w-3.5 h-3.5`}):(0,i.jsx)(t.Ti,{className:`copy-icon w-3.5 h-3.5`}),(0,i.jsx)(`span`,{className:`max-sm:hidden`,children:l?`Copied`:`Copy`})]})]}),n&&(0,i.jsx)(`p`,{className:`text-[12.5px] text-foreground/50 font-medium leading-relaxed break-words`,children:n}),(0,i.jsx)(`div`,{className:`text-[13.5px] font-medium leading-relaxed break-words [overflow-wrap:anywhere]`,children:d?(0,i.jsx)(`div`,{className:`flex flex-col gap-2 text-foreground/80`,children:a.split(`
|
|
3
3
|
`).filter(e=>e.trim()).map((e,t)=>(0,i.jsx)(`p`,{className:`min-w-0`,children:(0,i.jsx)(rt,{text:e})},t))}):(0,i.jsxs)(`p`,{className:`text-foreground/80`,children:[`“`,(0,i.jsx)(rt,{text:a}),`”`]})})]})}var at=`w-11 h-11 shrink-0 rounded-[var(--input-radius,0.75rem)] overflow-hidden border border-[var(--panel-border)]`,ot=e=>{try{return(decodeURIComponent(new URL(e).pathname).split(`/`).pop()||``).replace(/^\d{10,}_/,``)||`Your picture`}catch{return`Your picture`}};function st({label:e,hint:n,value:a,onChange:o,accept:s=`image/*`,action:c,clearable:l=!0,tips:u,onBusyChange:d}){let{user:f}=t.na(),[p,m]=(0,r.useState)(!1),[h,g]=(0,r.useState)(``),[_,v]=(0,r.useState)(!1),[y,b]=(0,r.useState)(!1),x=async e=>{if(!p){m(!0),d?.(!0),g(``);try{o(await t.ar(e,f))}catch(e){g(t.ir(e))}m(!1),d?.(!1),b(!1)}},S=e=>{let t=e.target.files?.[0];e.target.value=``,t&&x(t)},{over:C,dropProps:w}=t.er({accept:s,disabled:p,onFiles:([e])=>x(e),onReject:()=>g(s.startsWith(`image`)?`That is not a picture — drop a JPG or a PNG.`:`That kind of file does not go here.`)}),T=(0,i.jsx)(`input`,{type:`file`,accept:s,"aria-label":a?`Replace ${e}`:`Upload ${e}`,disabled:p,onChange:S,className:`sr-only`});return(0,i.jsxs)(t.Z,{label:e,hint:n,error:h,action:c,children:[(0,i.jsx)(`div`,{...w,className:`min-w-0`,children:a&&!p?(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`div`,{className:`${t.tt} min-w-0 ${C?`border-accent bg-accent/[0.04]`:``}`,children:(0,i.jsx)(`span`,{className:`flex-1 min-w-0 truncate text-[14px] select-none ${C?`text-accent`:`text-foreground/60`}`,children:C?`Drop it to replace this one`:ot(a)})}),(0,i.jsxs)(`div`,{className:`${at} relative group/pic`,children:[(0,i.jsx)(`button`,{type:`button`,onClick:()=>b(e=>!e),"aria-label":`Change ${e}`,"aria-expanded":y,className:`block w-full h-full cursor-pointer`,children:(0,i.jsx)(`img`,{src:a,alt:e,className:`w-full h-full object-cover`})}),(0,i.jsxs)(`div`,{className:`absolute inset-0 flex items-center justify-center gap-1 bg-background/85 transition-opacity duration-200 ${y?`opacity-100`:`opacity-0 pointer-events-none group-hover/pic:opacity-100 group-hover/pic:pointer-events-auto focus-within:opacity-100 focus-within:pointer-events-auto`}`,children:[(0,i.jsxs)(`label`,{title:`Replace ${e}`,className:`w-6 h-6 rounded-md flex items-center justify-center text-foreground/60 hover:text-accent hover:bg-foreground/10 transition-colors cursor-pointer`,children:[(0,i.jsx)(t.Di,{className:`w-3.5 h-3.5`}),T]}),l&&(0,i.jsx)(`button`,{type:`button`,onClick:()=>{g(``),b(!1),o(``)},"aria-label":`Remove ${e}`,title:`Remove ${e}`,className:`w-6 h-6 rounded-md flex items-center justify-center text-foreground/60 hover:text-red-500 hover:bg-red-500/10 transition-colors cursor-pointer`,children:(0,i.jsx)(t._r,{className:`w-3.5 h-3.5`})})]})]})]}):(0,i.jsxs)(`label`,{title:`Upload ${e}`,className:`group/up flex items-center gap-2 ${p?`pointer-events-none`:`cursor-pointer`}`,children:[(0,i.jsx)(`span`,{className:`${t.tt} select-none text-[14px] truncate ${C?`border-accent bg-accent/[0.04] text-accent`:p?`text-foreground/50`:`text-foreground/35`} group-hover/up:border-accent/40 group-focus-within/up:border-accent`,children:C?`Drop it here`:p?`Uploading your picture…`:`Upload a picture, or drop one here`}),(0,i.jsx)(`span`,{"aria-hidden":!0,className:`${at} flex items-center justify-center bg-[var(--panel-bg)] ${C?`text-accent border-accent`:`text-foreground/40`} group-hover/up:text-accent group-hover/up:border-accent/40 transition-colors`,children:p?(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin text-accent`}):(0,i.jsx)(t.Di,{className:`w-4 h-4`})}),T]})}),!!u?.length&&(0,i.jsxs)(`div`,{className:`mt-2 px-1`,children:[(0,i.jsxs)(`button`,{type:`button`,onClick:()=>v(e=>!e),"aria-expanded":_,className:`inline-flex items-center gap-1 text-[11.5px] font-semibold text-foreground/40 hover:text-foreground/70 transition-colors cursor-pointer`,children:[(0,i.jsx)(t.Ii,{className:`w-3 h-3 shrink-0 transition-transform duration-200 ${_?`rotate-90`:``}`}),`Which picture should I upload?`]}),_&&(0,i.jsx)(`ul`,{className:`flex flex-col gap-1 mt-1.5 ml-4`,children:u.map(e=>(0,i.jsxs)(`li`,{className:`text-[11.5px] text-foreground/40 font-medium leading-snug flex gap-1.5`,children:[(0,i.jsx)(`span`,{"aria-hidden":!0,className:`text-accent/60`,children:`•`}),e]},e))})]})]})}var ct=[`A wide picture sits best across a page — about 1600 by 900.`,`JPG or PNG. Any size — a big photo is shrunk for you as it uploads, so the page still opens quickly.`,`Your own photo beats a stock one. People can tell.`,`No writing baked into the picture — your assistant sets the words, so they stay readable on a phone.`],lt=[`A wide picture, not a square one — it sits in a short bar about 40px tall.`,`PNG with a see-through background looks right on both the light and the dark theme.`],ut=[`A square picture — 64 by 64 is plenty.`,`One shape or one letter. A whole logo turns to mush at this size.`],dt=`sys_roles`,ft=(e,t)=>({id:e,name:String(t?.name||e),...typeof t?.createdAt==`number`?{createdAt:t.createdAt}:{}}),pt=(e,t)=>e.name.localeCompare(t.name),mt=[],ht=e=>{mt=e},gt=()=>mt,_t=(e,t=gt())=>t.find(t=>t.id===e)?.name||e;function vt(e,n=gt()){let r=String(e||``).trim();if(!r)return`Type a name for the role first — Client, say, or Supplier.`;let i=t.ba(r);return i.length<2||!/^[a-z]/.test(i)?`Use a name with at least two letters in it.`:t.oa.has(i)||!t.ma(i)?`${r} is a word the app already uses. Pick another.`:n.some(e=>e.id===i)?`You already have a role called ${n.find(e=>e.id===i).name}.`:``}async function yt(e){let n=String(e||``).trim().slice(0,48),r={id:t.ba(n),name:n,createdAt:Date.now()};return await(0,o.setDoc)((0,o.doc)(t.Da,dt,r.id),{name:r.name,createdAt:r.createdAt}),r}async function bt(e,n){let r=String(n||``).trim().slice(0,48);!t.ma(e)||!r||await(0,o.setDoc)((0,o.doc)(t.Da,dt,e),{name:r},{merge:!0})}function xt(e,t,n=gt()){let r=String(t||``).trim();if(!r)return`A role needs a name.`;let i=n.find(t=>t.id!==e&&t.name.trim().toLowerCase()===r.toLowerCase());return i?`You already have a role called ${i.name}.`:``}async function St(e){let n={people:[],pages:[]};return t.ma(e)?((await(0,o.getDocs)((0,o.query)((0,o.collection)(t.Da,`user_profiles`),(0,o.where)(`role`,`==`,e)))).forEach(e=>n.people.push(e.id)),(await(0,o.getDocs)((0,o.collection)(t.Da,`sys_tabs`))).forEach(r=>{t.ca(r.data()?.roles).includes(e)&&n.pages.push(r.id)}),n):n}async function Ct(e){if(!t.ma(e))return;let n=await(0,o.getDocs)((0,o.query)((0,o.collection)(t.Da,`user_profiles`),(0,o.where)(`role`,`==`,e)));for(let e of n.docs)await(0,o.updateDoc)((0,o.doc)(t.Da,`user_profiles`,e.id),{role:t.ya(`free`)});let r=await(0,o.getDocs)((0,o.collection)(t.Da,`sys_tabs`));for(let n of r.docs){let r=t.ca(n.data()?.roles);if(!r.includes(e))continue;let i=r.filter(t=>t!==e);await(0,o.setDoc)((0,o.doc)(t.Da,`sys_tabs`,n.id),{roles:i.length?i:[`user`]},{merge:!0})}await(0,o.deleteDoc)((0,o.doc)(t.Da,dt,e))}function wt(){let[e,n]=(0,r.useState)(()=>gt());return(0,r.useEffect)(()=>(0,o.onSnapshot)((0,o.collection)(t.Da,dt),e=>{let t=[];e.forEach(e=>t.push(ft(e.id,e.data()))),t.sort(pt),ht(t),n(t)},()=>{}),[]),e}function Tt({roles:e}){let[n,a]=(0,r.useState)(``),[o,s]=(0,r.useState)(``),[c,l]=(0,r.useState)(``),[u,d]=(0,r.useState)(``),[f,p]=(0,r.useState)(null);if(!e.length)return null;let m=async t=>{let n=xt(t.id,o,e);if(n){l(n);return}d(t.id);try{await bt(t.id,o),a(``),l(``)}catch(e){l(e?.message||`The new name could not be saved. Try again.`)}d(``)},h=async e=>{d(e.id);try{p({role:e,standing:await St(e.id)})}catch{p({role:e,standing:{people:[],pages:[]}})}d(``)};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(`div`,{className:`border-t border-[var(--panel-border)] p-4 sm:p-6 flex flex-col gap-4`,children:[(0,i.jsx)(t.ot,{icon:t.kr,title:`Your own roles`,description:`The words you mark people with. Renaming one changes it everywhere; nobody is unmarked.`}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.map(e=>(0,i.jsx)(`div`,{className:`rounded-2xl glass-panel border border-[var(--panel-border)] px-3.5 py-2.5 flex items-center gap-2.5`,children:n===e.id?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`input`,{autoFocus:!0,value:o,disabled:u===e.id,"aria-label":`Rename ${e.name}`,onChange:e=>{s(e.target.value),c&&l(``)},onKeyDown:t=>{t.key===`Enter`&&(t.preventDefault(),m(e)),t.key===`Escape`&&(t.preventDefault(),a(``),l(``))},className:`${t.et} flex-1 min-w-0`}),(0,i.jsx)(t.Q,{icon:t.zi,compact:!0,busy:u===e.id,title:`Save ${o||e.name}`,onClick:()=>m(e),children:`Save`}),(0,i.jsx)(t.Q,{icon:t._r,compact:!0,title:`Keep the name`,onClick:()=>{a(``),l(``)},children:`Cancel`})]}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`span`,{className:`flex-1 min-w-0 text-[13.5px] font-bold text-foreground truncate`,children:e.name}),(0,i.jsx)(t.Q,{icon:t.Gr,compact:!0,title:`Rename ${e.name}`,onClick:()=>{a(e.id),s(e.name),l(``)},children:`Rename`}),(0,i.jsx)(t.Q,{icon:t.Or,tone:`danger`,compact:!0,busy:u===e.id,title:`Remove ${e.name}`,onClick:()=>h(e),children:`Remove`})]})},e.id)),!!c&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 px-1`,children:c}),(0,i.jsx)(`p`,{className:`${t.$} px-1`,children:`Make a new role on the Pages screen, on the row of the page you want to keep for it.`})]})]}),(0,i.jsx)(Ve,{isOpen:!!f,title:f?`Remove ${f.role.name}?`:``,message:f?Et(f.standing):``,confirmText:`Yes, remove it`,cancelText:`Keep it`,isProcessing:u===`removing`,onCancel:()=>p(null),onConfirm:async()=>{if(f){d(`removing`);try{await Ct(f.role.id),p(null)}catch(e){l(e?.message||`The role could not be removed. Try again.`),p(null)}d(``)}}})]})}function Et(e){let t=e.people.length,n=e.pages.length,r=[];return t&&r.push(`${t} ${t===1?`person goes`:`people go`} back to being ${t===1?`a member`:`members`}`),n&&r.push(`${n} ${n===1?`page goes`:`pages go`} back to everybody signed in`),`${r.length?`${r.join(`, and `)}. `:`Nobody is marked with it and no page is kept for it. `}Whatever those pages have saved stays exactly where it is — you and your admins can still read it — but nobody else will, and the word itself is gone from every list.`}function Dt(){let{user:e,userRole:n}=t.na(),a=wt(),[l,u]=(0,r.useState)(!0),d=(0,c.useNavigate)(),{id:f}=(0,c.useParams)(),p=Be(),[m,h]=(0,r.useState)([]),[g,_]=(0,r.useState)(null),[v,y]=(0,r.useState)(!1),[b,x]=(0,r.useState)(``),[S,C]=(0,r.useState)(!1),w=f?m.find(e=>e.id===f)||null:m.length>0?m[0]:null,T=e=>{d(e?`/users/${e.id}`:`/users`)};(0,r.useEffect)(()=>{u(!0);let e=(0,o.onSnapshot)((0,o.collection)(t.Da,`user_profiles`),e=>{let t=[];e.forEach(e=>{t.push({id:e.id,...e.data()})}),h(t),u(!1),!f&&t.length>0&&!ze()&&d(`/users/${t[0].id}`,{replace:!0})},e=>{console.error(`Error fetching users:`,e),u(!1)});return()=>e()},[f,d]);let E=m.find(t=>t.id===e?.uid),D=e=>e.id===E?.id?!1:e.role!==`admin`||!E?.createdAt?!0:e.createdAt?new Date(E.createdAt).getTime()<=new Date(e.createdAt).getTime():!1,O=[...t.ra.map(e=>({value:t.ya(e),label:t.ia[e]})),...a.map(e=>({value:e.id,label:e.name}))],k=e=>t.da(e.role)||t.ya(t.ha(e.role)),A=e=>{let n=t.da(e.role);return n?_t(n,a):t.ia[t.ha(e.role)]},j=async(e,r,i)=>{if(!(n!==`admin`||!D(e))&&k(e)!==r)try{await(0,o.updateDoc)((0,o.doc)(t.Da,`user_profiles`,e.id),{role:r}),_({text:`Access level set to ${i}`,type:`success`}),setTimeout(()=>_(null),3e3)}catch(e){_({text:e.message,type:`error`}),setTimeout(()=>_(null),3e3)}},M=async(e,r)=>{if(!(n!==`admin`||!D(e)))try{await(0,o.updateDoc)((0,o.doc)(t.Da,`user_profiles`,e.id),{inactive:r}),_({text:`User ${r?`deactivated`:`activated`} successfully`,type:`success`}),setTimeout(()=>_(null),3e3)}catch(e){_({text:e.message,type:`error`}),setTimeout(()=>_(null),3e3)}},N=async()=>{if(y(!1),!(!w||!D(w)||b===w.displayName))try{await(0,o.updateDoc)((0,o.doc)(t.Da,`user_profiles`,w.id),{displayName:b}),_({text:`Name updated successfully`,type:`success`}),setTimeout(()=>_(null),3e3)}catch(e){_({text:e.message,type:`error`}),setTimeout(()=>_(null),3e3)}},P=async e=>{if(!w||!D(w))return;let n=await t.or(e,{maxSide:512});if(n.size>2*1024*1024){_({text:`File too large. Please select an image under 2MB.`,type:`error`});return}C(!0);try{let e=(0,s.ref)(t.ka,`user_avatars/${w.id}/file.png`);await(0,s.uploadBytes)(e,n);let r=await(0,s.getDownloadURL)(e);h(e=>e.map(e=>e.id===w.id?{...e,avatar:r}:e)),await(0,o.updateDoc)((0,o.doc)(t.Da,`user_profiles`,w.id),{avatar:r}),_({text:`Avatar successfully updated.`,type:`success`}),setTimeout(()=>_(null),3e3)}catch{_({text:`Failed to upload photo.`,type:`error`})}C(!1)},F=e=>{let t=e.target.files?.[0];t&&P(t)},{over:I,dropProps:L}=t.er({accept:`image/*`,disabled:S||!w||!D(w),onFiles:([e])=>P(e),onReject:()=>_({text:`That is not a picture. Drop a JPG or a PNG.`,type:`error`})}),[R,z]=(0,r.useState)(!1);if((0,r.useEffect)(()=>{let e;return l&&m.length===0?e=setTimeout(()=>z(!0),150):z(!1),()=>clearTimeout(e)},[l,m.length]),l&&m.length===0)return R?(0,i.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,i.jsx)(t.ti,{className:`w-8 h-8 animate-spin text-accent`})}):null;let B=p&&!!f,V=!B,H=!p||!!f;return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto z-10 flex flex-col min-h-screen p-4 pt-2 md:p-8 md:pt-4`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,i.jsx)(Ce,{children:`Users`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/users`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col animate-in fade-in duration-500 gap-6 ${B?`flex-1 pb-6`:`pb-20`}`,children:[(0,i.jsx)(t.pr,{children:g&&(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:`p-4 text-[14px] font-medium border rounded-xl ${g.type===`error`?`text-red-500 bg-red-500/10 border-red-500/20 shadow-[0_0_15px_rgba(239,68,68,0.1)]`:`text-emerald-400 bg-emerald-500/10 border-emerald-500/20 shadow-[0_0_15px_rgba(52,211,153,0.1)]`} flex items-center gap-2`,children:[g.type===`success`&&(0,i.jsx)(t.Ni,{className:`w-4 h-4 shrink-0`}),g.text]})}),(0,i.jsx)(`div`,{className:`flex justify-start`,children:(0,i.jsx)(Fe,{})}),(0,i.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] bg-[var(--panel-bg)] overflow-hidden rounded-3xl shadow-2xl ${B?`flex-1 flex flex-col`:``}`,children:[m.length===0?(0,i.jsx)(`div`,{className:`p-8 text-center text-foreground/50 text-[14px]`,children:`No members found.`}):(0,i.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 md:min-h-[500px] ${B?`flex-1`:``}`,children:[V&&(0,i.jsxs)(`div`,{className:`flex md:col-span-1 border-r md:border-r-[var(--panel-border)] border-b md:border-b-0 border-[var(--panel-border)] flex-col hide-scrollbar bg-foreground/[0.03] rounded-t-3xl md:rounded-tr-none md:rounded-l-3xl`,children:[(0,i.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,i.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-2 md:max-h-[520px]`,children:m.map(e=>(0,i.jsxs)(`div`,{onClick:()=>T(e),className:`p-3.5 rounded-2xl border transition-all flex items-center gap-3 cursor-pointer ${w?.id===e.id?`bg-foreground/[0.06] border-accent/40 shadow-sm`:`glass-panel border-[var(--panel-border)] hover:border-accent/40`} ${e.inactive?`opacity-50 grayscale`:``}`,children:[(0,i.jsx)(`div`,{className:`w-9 h-9 rounded-full overflow-hidden bg-accent/10 shrink-0 flex items-center justify-center border border-accent/20 shadow-sm`,children:e.avatar||e.photoURL?(0,i.jsx)(`img`,{src:e.avatar||e.photoURL,alt:``,className:`w-full h-full object-cover`}):(0,i.jsx)(t.Sr,{className:`w-4 h-4 text-accent`})}),(0,i.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,i.jsx)(`span`,{className:`font-bold text-[14px] text-foreground truncate`,children:e.displayName||`No Name`}),(0,i.jsx)(`span`,{className:`text-[12px] text-foreground/50 truncate font-medium mt-0.5`,children:e.email})]}),p&&(0,i.jsx)(t.Ii,{className:`w-4 h-4 text-foreground/25 shrink-0`})]},e.id))})]}),H&&(0,i.jsx)(`div`,{className:`flex md:col-span-2 flex-col relative ${B?`px-4 pt-4 pb-10`:`p-5 sm:p-6 md:p-10`}`,children:w?(0,i.jsxs)(`div`,{className:`animate-in fade-in duration-300 w-full max-w-lg`,children:[(0,i.jsxs)(`div`,{className:`flex flex-row items-center gap-3 sm:gap-6 md:gap-8 mb-8 sm:mb-10`,children:[B&&(0,i.jsx)(`button`,{type:`button`,onClick:()=>T(null),"aria-label":`Back to all users`,className:`shrink-0 -ml-1.5 w-7 h-7 flex items-center justify-center rounded-lg text-foreground/40 hover:text-foreground active:bg-foreground/5 transition-colors cursor-pointer`,children:(0,i.jsx)(t.Zi,{className:`w-5 h-5`})}),(0,i.jsxs)(`div`,{...L,className:`relative shrink-0 group/avatar rounded-full transition-shadow ${I?`ring-2 ring-accent ring-offset-2 ring-offset-background`:``}`,children:[(0,i.jsx)(`div`,{className:`w-14 h-14 sm:w-24 sm:h-24 rounded-full glass-panel border-2 sm:border-4 border-[var(--panel-border)] shadow-lg sm:shadow-xl bg-accent/10 flex items-center justify-center overflow-hidden`,children:S?(0,i.jsx)(t.ti,{className:`w-5 h-5 sm:w-8 sm:h-8 text-accent animate-spin`}):w.avatar||w.photoURL?(0,i.jsx)(`img`,{src:w.avatar||w.photoURL,alt:`Avatar`,className:`w-full h-full object-cover`}):(0,i.jsx)(t.Sr,{className:`w-6 h-6 sm:w-10 sm:h-10 text-accent`})}),!S&&D(w)&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(`label`,{title:`Change photo`,className:`max-sm:hidden sm:flex absolute -bottom-0.5 -right-0.5 w-9 h-9 rounded-full btn-primary text-white items-center justify-center cursor-pointer shadow-lg border-2 border-[var(--bg-color)] hover:scale-105 active:scale-95 transition-transform z-10`,children:[(0,i.jsx)(t.Bi,{className:`w-4 h-4`}),(0,i.jsx)(`input`,{type:`file`,accept:`image/*`,"aria-label":`Change photo`,onChange:F,className:`hidden`})]}),(0,i.jsxs)(`label`,{title:`Change photo`,className:`flex sm:hidden absolute inset-0 rounded-full bg-background/60 backdrop-blur-[2px] opacity-0 group-hover/avatar:opacity-100 focus-within:opacity-100 items-center justify-center cursor-pointer transition-opacity z-10`,children:[(0,i.jsx)(t.Bi,{className:`w-4 h-4 text-foreground`}),(0,i.jsx)(`input`,{type:`file`,accept:`image/*`,"aria-label":`Change photo`,onChange:F,className:`hidden`})]})]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col flex-1 w-full min-w-0 relative`,children:[v?(0,i.jsx)(`input`,{autoFocus:!0,value:b,onChange:e=>x(e.target.value),onBlur:N,onKeyDown:e=>e.key===`Enter`&&N(),className:`text-xl sm:text-2xl md:text-3xl font-extrabold mb-1 bg-transparent border-b-2 border-accent outline-none text-foreground w-full py-1`}):(0,i.jsx)(`h3`,{onDoubleClick:()=>{D(w)&&(x(w.displayName||``),y(!0))},className:`text-xl sm:text-2xl md:text-3xl font-extrabold mb-1 select-none break-words ${D(w)?`cursor-pointer hover:text-accent transition-colors`:``}`,title:D(w)?`Double-click to edit`:``,children:w.displayName||`No Name`}),(0,i.jsx)(`p`,{className:`text-[13px] sm:text-[14px] font-mono text-foreground/50 break-all`,children:w.email}),(0,i.jsx)(`span`,{className:`mt-2 self-start inline-flex items-center h-6 px-2.5 rounded-full text-[11.5px] font-bold bg-accent/10 text-accent border border-accent/20`,children:A(w)}),!D(w)&&w.id!==E?.id&&(0,i.jsxs)(`p`,{className:`mt-2 flex items-center gap-1.5 text-[12px] font-medium text-foreground/45`,children:[(0,i.jsx)(t.ei,{className:`w-3 h-3 shrink-0`}),`Admin since before you, so only they can change this account.`]})]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,i.jsx)(`div`,{className:`p-4 rounded-2xl glass-panel border border-[var(--panel-border)] flex flex-col gap-3`,children:(0,i.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col`,children:[(0,i.jsx)(`span`,{className:`font-bold text-[14px] text-foreground`,children:`Access level`}),(0,i.jsx)(`span`,{className:`text-[12px] text-foreground/50`,children:`What this person can open`})]}),(0,i.jsx)(`div`,{role:`radiogroup`,"aria-label":`Access level`,className:`flex items-center gap-1.5 flex-wrap ${D(w)?``:`opacity-50`}`,children:O.map(e=>{let t=k(w)===e.value;return(0,i.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t,disabled:!D(w),onClick:()=>j(w,e.value,e.label),className:`h-8 px-3.5 rounded-full text-[12.5px] font-semibold border transition-all ${t?`bg-accent/10 border-accent/40 text-accent`:`border-[var(--panel-border)] text-foreground/55 hover:text-foreground hover:border-accent/30`} ${D(w)?`cursor-pointer`:`cursor-not-allowed`}`,children:e.label},e.value)})})]})}),(0,i.jsxs)(`div`,{className:`p-4 rounded-2xl glass-panel border flex items-center justify-between gap-3 ${w.inactive?`border-amber-500/30 bg-amber-500/5`:`border-red-500/20 bg-red-500/5`}`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col`,children:[(0,i.jsx)(`span`,{className:`font-bold text-[14px] ${w.inactive?`text-amber-500`:`text-red-500`}`,children:w.inactive?`Reactivate User`:`Deactivate User`}),(0,i.jsx)(`span`,{className:`text-[12px] ${w.inactive?`text-amber-500/70`:`text-red-500/70`}`,children:`Block access to this app`})]}),(0,i.jsx)(`button`,{type:`button`,disabled:!D(w),onClick:()=>M(w,!w.inactive),className:`relative inline-flex h-7 w-12 shrink-0 items-center rounded-full transition-colors focus:outline-none shadow-inner ${w.inactive?`bg-amber-500`:`bg-red-500/20`} ${D(w)?`cursor-pointer`:`opacity-50 cursor-not-allowed`}`,children:(0,i.jsx)(`span`,{className:`inline-block h-5 w-5 transform rounded-full bg-white transition-transform shadow-md ${w.inactive?`translate-x-6`:`translate-x-1`}`})})]})]})]}):(0,i.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center opacity-30 pointer-events-none`,children:[(0,i.jsx)(t.xr,{className:`w-12 h-12 mb-4`}),(0,i.jsx)(`p`,{className:`font-bold tracking-widest uppercase text-[12px]`,children:`Select a User`})]})})]}),!B&&(0,i.jsx)(Tt,{roles:a})]})]})]})}var Ot={anyone:{collectionName:`user_submissions`,chip:`Anyone`,filterLabel:`From anyone`},signedIn:{collectionName:`user_requests`,chip:`Signed-in user`,filterLabel:`From signed-in users`}},kt=[`id`,`source`,`uid`,`submittedAt`,`avatarUrl`,`isArchived`,`name`,`full_name`,`email`,`contactEmail`,`topic`],At=e=>{let t=e.submittedAt;if(!t)return 0;if(typeof t.toMillis==`function`)return t.toMillis();if(typeof t.toDate==`function`)return t.toDate().getTime();let n=new Date(t).getTime();return Number.isNaN(n)?0:n},jt=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)},Mt=e=>{if(!e)return`now`;let t=e.toDate?e.toDate():new Date(e),n=new Date;return t.toDateString()===n.toDateString()?new Intl.DateTimeFormat(`en-US`,{hour:`numeric`,minute:`numeric`}).format(t):new Intl.DateTimeFormat(`en-US`,t.getFullYear()===n.getFullYear()?{month:`short`,day:`numeric`}:{month:`short`,year:`numeric`}).format(t)},Nt=e=>{let t=new Date(e);return new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime()},Pt=e=>{let t=At(e);if(!t)return`Older`;let n=Math.round((Nt(Date.now())-Nt(t))/864e5);return n<=0?`Today`:n===1?`Yesterday`:n<7?`This week`:n<30?`This month`:`Older`},Ft=e=>e.reduce((e,t)=>{let n=Pt(t),r=e[e.length-1];return r&&r.label===n?r.items.push(t):e.push({label:n,items:[t]}),e},[]);function It({label:e}){return(0,i.jsxs)(`div`,{className:`md:hidden flex items-center gap-3 pt-1 first:pt-0 select-none`,children:[(0,i.jsx)(`span`,{className:`text-[10.5px] font-bold uppercase tracking-[0.18em] text-foreground/35 shrink-0`,children:e}),(0,i.jsx)(`span`,{className:`h-px flex-1 bg-[var(--panel-border)]/60`})]})}var Lt=e=>e.submitterName||e.name||e.full_name||`Anonymous`,Rt=e=>e.contactEmail||e.email||`No email provided`;function zt(e){let[n,i]=(0,r.useState)([]),[a,s]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{let n=!1,r=Ot[e].collectionName,a=(0,o.onSnapshot)((0,o.query)((0,o.collection)(t.Da,r),(0,o.orderBy)(`submittedAt`,`desc`)),async r=>{let a=[];for(let n of r.docs){let r={...n.data()};if(r.formId===`booking`||t.on(r))continue;let i=``;if(r.uid&&r.uid!==`guest`)try{let e=await(0,o.getDoc)((0,o.doc)(t.Da,`user_profiles`,r.uid));if(e.exists()){let t=e.data();(t.avatar||t.photoURL)&&(i=t.avatar||t.photoURL),r.name||=t.name||t.displayName,r.email||=t.email,r.contactEmail||=t.email}}catch(e){console.error(`Failed to fetch profile`,e)}a.push({...r,id:n.id,source:e,avatarUrl:i})}n||(i(a),s(!1))},e=>{console.error(`Error loading ${r}:`,e),n||s(!1)});return()=>{n=!0,a()}},[e]),{items:n,loading:a}}function Bt({source:e}){return(0,i.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:Ot[e].chip})}function Vt({item:e,isExpanded:n,onToggle:r,onArchive:a,onDelete:o,busy:s,dimmed:l}){let u=Lt(e),d=e.avatarUrl||e.submitterAvatar,f=!!e.uid&&e.uid!==`guest`,p=Object.entries(e).filter(([e])=>!kt.includes(e)&&!e.toLowerCase().startsWith(`submitter`)&&e.toLowerCase()!==`formid`),m=e.topic?[[`topic`,e.topic],...p]:p;return(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-2xl flex flex-col overflow-hidden hover:border-accent/40 transition-all duration-300 ${l?`opacity-60 hover:opacity-100`:``}`,children:[(0,i.jsxs)(`div`,{className:`w-full flex items-center gap-3 p-3.5 md:px-5`,children:[(0,i.jsxs)(`button`,{type:`button`,onClick:r,"aria-expanded":n,className:`flex items-center gap-3 flex-1 min-w-0 text-left cursor-pointer`,children:[(0,i.jsx)(`div`,{className:`relative shrink-0`,children:d?(0,i.jsx)(`img`,{src:d,alt:``,className:`w-9 h-9 rounded-full object-cover border border-[var(--panel-border)] shadow-sm`}):(0,i.jsx)(`div`,{className:`w-9 h-9 rounded-full bg-accent/10 text-accent flex items-center justify-center font-bold border border-accent/20 shadow-sm uppercase`,children:(u||`A`)[0]})}),(0,i.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,i.jsx)(`span`,{className:`font-bold text-[14px] text-foreground truncate`,children:u}),(0,i.jsxs)(`span`,{className:`text-[12px] text-foreground/50 truncate flex items-center gap-1.5 font-medium mt-0.5`,children:[(0,i.jsx)(t.Zr,{className:`w-3.5 h-3.5 shrink-0`}),` `,Rt(e)]})]})]}),(0,i.jsx)(`button`,{type:`button`,onClick:r,tabIndex:-1,"aria-hidden":`true`,className:`md:hidden w-8 h-8 -mr-1 flex items-center justify-center rounded-lg text-foreground/30 hover:text-accent hover:bg-foreground/5 transition-colors shrink-0 cursor-pointer`,children:(0,i.jsx)(t.Ri,{className:`w-4 h-4 transition-transform duration-300 ${n?`rotate-180`:``}`})}),(0,i.jsxs)(`div`,{className:`max-md:hidden md:flex items-center gap-2 shrink-0`,children:[(0,i.jsx)(`span`,{className:`text-[11px] text-foreground/35 tabular-nums whitespace-nowrap mr-1`,children:Mt(e.submittedAt)}),(0,i.jsx)(t.Q,{icon:e.isArchived?t.Yi:t.$i,onClick:a,busy:s,children:e.isArchived?`Restore`:`Archive`}),(0,i.jsx)(t.Q,{icon:t.Or,tone:`danger`,onClick:o,children:`Delete`}),(0,i.jsx)(`button`,{type:`button`,onClick:r,"aria-label":n?`Hide details from ${u}`:`Show details from ${u}`,className:`p-1.5 text-foreground/40 transition-transform duration-300 cursor-pointer ${n?`rotate-180`:``}`,children:(0,i.jsx)(t.Ri,{className:`w-4 h-4`})})]})]}),(0,i.jsx)(t.pr,{children:n&&(0,i.jsx)(t.fr.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden`,children:(0,i.jsxs)(`div`,{className:`px-3.5 md:px-5 py-4 border-t border-[var(--panel-border)]/40`,children:[(0,i.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-3`,children:[(0,i.jsx)(Bt,{source:e.source}),e.formId&&(0,i.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-widest text-foreground/40 bg-foreground/5 px-2 py-0.5 rounded-md border border-[var(--panel-border)] shrink-0`,children:String(e.formId).replace(/_/g,` `)}),(0,i.jsx)(`span`,{className:`text-[11px] font-medium text-foreground/40 shrink-0`,children:jt(e.submittedAt)})]}),m.length>0?(0,i.jsx)(`div`,{className:`rounded-xl border border-[var(--panel-border)]/60 bg-foreground/[0.02] divide-y divide-[var(--panel-border)]/40 overflow-hidden`,children:m.map(([e,n])=>(0,i.jsxs)(`div`,{className:`px-3.5 md:px-4 py-3`,children:[(0,i.jsx)(`span`,{className:`block text-[11px] font-bold uppercase tracking-widest text-foreground/40 mb-1`,children:e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}),t.rr(n)?(0,i.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:t.nr(n).map(e=>(0,i.jsxs)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-2 text-[14px] font-semibold text-accent hover:underline break-all [overflow-wrap:anywhere]`,children:[(0,i.jsx)(t.qr,{className:`w-4 h-4 shrink-0`}),t.tr(e)]},e))}):(0,i.jsx)(`p`,{className:`text-[14px] text-foreground/85 leading-relaxed whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:typeof n==`boolean`?n?`Yes`:`No`:String(n??``)||`No data provided`})]},e))}):(0,i.jsx)(`p`,{className:`text-[13px] text-foreground/40 font-medium`,children:`This form only asked for a name and email.`}),f&&(0,i.jsx)(c.Link,{to:`/users/${e.uid}`,className:`inline-flex mt-3 text-[12.5px] font-bold text-accent hover:underline`,children:`Open this person’s profile`}),(0,i.jsxs)(`div`,{className:`md:hidden flex items-center justify-end gap-2 mt-4`,children:[(0,i.jsx)(t.Q,{icon:e.isArchived?t.Yi:t.$i,onClick:a,busy:s,children:e.isArchived?`Restore`:`Archive`}),(0,i.jsx)(t.Q,{icon:t.Or,tone:`danger`,onClick:o,children:`Delete`})]})]})})})]})}function Ht(){let e=zt(`anyone`),n=zt(`signedIn`),[a,s]=(0,r.useState)(`all`),[l,u]=(0,r.useState)(null),[d,f]=(0,r.useState)(!1),[p,m]=(0,r.useState)(null),[h,g]=(0,r.useState)(null),[_,v]=(0,r.useState)(!1),y=e.loading||n.loading,b=(0,r.useMemo)(()=>[...e.items,...n.items].sort((e,t)=>At(t)-At(e)),[e.items,n.items]),x=a===`all`?b:b.filter(e=>e.source===a),S=x.filter(e=>!e.isArchived),C=x.filter(e=>e.isArchived),w=e=>`${e.source}:${e.id}`,[T,E]=(0,c.useSearchParams)(),D=T.get(`open`);(0,r.useEffect)(()=>{if(!D||y)return;let e=b.find(e=>w(e)===D);e&&(e.isArchived&&f(!0),u(D),E({},{replace:!0}))},[D,y,b]);let O=e=>u(t=>t===w(e)?null:w(e)),k=async e=>{m(w(e));try{await(0,o.updateDoc)((0,o.doc)(t.Da,Ot[e.source].collectionName,e.id),{isArchived:!e.isArchived}),!e.isArchived&&l===w(e)&&u(null)}catch(e){console.error(`Failed to archive`,e)}m(null)},A=async()=>{if(h){v(!0);try{await(0,o.deleteDoc)((0,o.doc)(t.Da,Ot[h.source].collectionName,h.id)),l===w(h)&&u(null),g(null)}catch(e){console.error(`Failed to delete`,e)}v(!1)}},j=[{key:`all`,label:`Everything`,short:`All`},{key:`anyone`,label:Ot.anyone.filterLabel,short:`Anyone`},{key:`signedIn`,label:Ot.signedIn.filterLabel,short:`Signed in`}];return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,i.jsx)(Ce,{children:`Inbox`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/inbox`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-4 flex-1 min-h-[500px]`,children:[(0,i.jsx)(`div`,{className:`flex justify-start`,children:(0,i.jsx)(Fe,{})}),(0,i.jsxs)(`div`,{className:`w-full flex-1 flex flex-col glass-panel rounded-2xl md:rounded-3xl p-3 sm:p-6 md:p-10 relative overflow-hidden border border-[var(--panel-border)] shadow-2xl bg-[var(--panel-bg)]`,children:[(0,i.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,i.jsx)(`div`,{className:`relative z-10 flex-1 flex flex-col`,children:y?(0,i.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[500px]`,children:(0,i.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`})}):b.length===0?(0,i.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center p-8 gap-6`,children:[(0,i.jsx)(`div`,{className:`w-16 h-16 rounded-3xl bg-accent/10 border border-accent/20 flex items-center justify-center text-accent shadow-inner`,children:(0,i.jsx)(t.di,{className:`w-6 h-6`})}),(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground mb-2`,children:`Nothing here yet`}),(0,i.jsx)(`p`,{className:`text-[14px] text-foreground/50 font-medium max-w-md`,children:`Everything people send you through a form on your site lands here.`})]})]}):(0,i.jsxs)(`div`,{className:`flex flex-col gap-3 pb-8`,children:[(0,i.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 mb-2`,children:j.map(e=>(0,i.jsxs)(`button`,{type:`button`,onClick:()=>s(e.key),"aria-pressed":a===e.key,"aria-label":e.label,className:`h-8 md:h-9 px-3 md:px-4 rounded-full text-[12px] md:text-[12.5px] font-bold border transition-all cursor-pointer ${a===e.key?`bg-accent/10 border-accent/40 text-accent`:`border-[var(--panel-border)]/70 bg-background/60 text-foreground/60 hover:text-foreground hover:border-accent/30`}`,children:[(0,i.jsx)(`span`,{className:`sm:hidden`,children:e.short}),(0,i.jsx)(`span`,{className:`max-sm:hidden`,children:e.label})]},e.key))}),S.length===0&&(0,i.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,i.jsx)(`p`,{className:`text-[14px] font-bold text-foreground/50`,children:C.length>0?`Everything here is archived.`:`Nothing matches this filter.`})}),(0,i.jsx)(t.pr,{children:Ft(S).map(e=>(0,i.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,i.jsx)(It,{label:e.label}),e.items.map(e=>(0,i.jsx)(Vt,{item:e,isExpanded:l===w(e),onToggle:()=>O(e),onArchive:()=>k(e),onDelete:()=>g(e),busy:p===w(e)},w(e)))]},e.label))}),C.length>0&&(0,i.jsxs)(`div`,{className:`mt-6 pt-4 border-t border-[var(--panel-border)]/30`,children:[(0,i.jsx)(`div`,{className:`flex justify-center`,children:(0,i.jsxs)(`button`,{type:`button`,onClick:()=>f(e=>!e),className:`flex items-center gap-2 text-[11px] font-bold text-foreground/40 hover:text-foreground/70 transition-colors py-2 uppercase tracking-widest cursor-pointer`,children:[d?`Hide`:`View`,` `,C.length,` archived`,(0,i.jsx)(t.Ri,{className:`w-3.5 h-3.5 transition-transform duration-300 ${d?`rotate-180`:``}`})]})}),(0,i.jsx)(t.pr,{children:d&&(0,i.jsx)(t.fr.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden mt-4`,children:(0,i.jsx)(`div`,{className:`flex flex-col gap-3`,children:Ft(C).map(e=>(0,i.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,i.jsx)(It,{label:e.label}),e.items.map(e=>(0,i.jsx)(Vt,{item:e,isExpanded:l===w(e),onToggle:()=>O(e),onArchive:()=>k(e),onDelete:()=>g(e),busy:p===w(e),dimmed:!0},w(e)))]},e.label))})})})]})]})})]})]}),(0,i.jsx)(Ve,{isOpen:!!h,title:`Delete this message?`,message:`This removes it for good. There is no undo — archive it instead if you only want it out of the way.`,onConfirm:A,onCancel:()=>g(null),isProcessing:_,confirmText:`Yes, delete`})]})}var Ut=`inline-flex items-center justify-center w-9 h-9 rounded-full border border-[var(--panel-border)] text-foreground/50 hover:text-accent hover:bg-foreground/5 transition-colors shrink-0 cursor-pointer`,Wt=({to:e})=>e?(0,i.jsx)(c.Link,{to:e,"aria-label":`Go back`,title:`Go back`,className:Ut,children:(0,i.jsx)(t.Zi,{className:`w-4 h-4`})}):(0,i.jsx)(`button`,{type:`button`,onClick:()=>window.history.back(),"aria-label":`Go back`,title:`Go back`,className:Ut,children:(0,i.jsx)(t.Zi,{className:`w-4 h-4`})}),Gt=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]};function Kt({title:e=`Drive`,subtitle:n=`/drive`,backUrl:a=`/templates`,filesCollection:u=`pub_files`,config:d,customContent:f,footer:p}){let{user:m,userRole:h}=t.na(),g=!!d,_=h===`admin`,v=u,y=u.startsWith(`user_`),[b,x]=(0,r.useState)([]),[S,C]=(0,r.useState)(!0),[w,T]=(0,r.useState)(null),[E,D]=(0,r.useState)(!0),[O,k]=(0,r.useState)(null),[A,j]=(0,r.useState)(!1),[M,N]=(0,r.useState)(null),[P,F]=(0,r.useState)(null),[I,L]=(0,r.useState)({}),[R,z]=(0,r.useState)(!1),[B,V]=(0,r.useState)(null),[H,U]=(0,r.useState)(``),[W,G]=(0,r.useState)(!1),[ee,K]=(0,r.useState)(``),[q,J]=(0,r.useState)(!1),Y=(0,r.useRef)(null);(0,r.useEffect)(()=>{D(!0)},[w?._id]),(0,r.useEffect)(()=>{if(!(y&&!m))return C(!0),(0,o.onSnapshot)(y?(0,o.query)((0,o.collection)(t.Da,u),(0,o.where)(`uid`,`==`,m.uid)):(0,o.query)((0,o.collection)(t.Da,u),(0,o.orderBy)(`createdAt`,`desc`)),e=>{let t=e.docs.map(e=>({_id:e.id,...e.data()}));t.sort((e,t)=>(t.createdAt?.toMillis?.()||0)-(e.createdAt?.toMillis?.()||0)),x(t),C(!1)},e=>{console.warn(`Error listening to ${u}:`,e),C(!1)})},[u,y,m?.uid]);let te=e=>!!m&&(e.uid===m.uid||_),ne=e=>{V(e),U(e.name),K(``),z(!0)},re=()=>{V(null),K(``),z(!0)},X=async e=>{if(e.preventDefault(),!(!B||!H.trim()||!m)){G(!0),K(``);try{let e=await t.or(B),n=`${v}/${`${Date.now()}_${e.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,r=(0,s.ref)(t.ka,n);await(0,s.uploadBytes)(r,e,{customMetadata:{ownerId:m.uid}});let i=await(0,s.getDownloadURL)(r);await(0,o.addDoc)((0,o.collection)(t.Da,u),{fileName:H.trim(),fileType:e.type||`unknown`,fileSize:e.size,downloadURL:i,storagePath:n,uid:m.uid,uploaderEmail:m.email||``,createdAt:(0,o.serverTimestamp)()}),z(!1),V(null),U(``)}catch(e){K(e?.code===`storage/unauthorized`?`You do not have permission to upload here.`:e?.message||`Upload failed. Please try again.`)}G(!1)}},Z=async()=>{if(O){j(!0);try{await Promise.all([(0,s.deleteObject)((0,s.ref)(t.ka,O.storagePath||O.downloadURL)).catch(e=>console.warn(`Storage object missing:`,e)),(0,o.deleteDoc)((0,o.doc)(t.Da,u,O._id))]),k(null)}catch(e){console.error(`Delete failed:`,e)}j(!1)}},Q=async()=>{if(!M||!M.name.trim()){N(null);return}try{await(0,o.updateDoc)((0,o.doc)(t.Da,u,M.id),{fileName:M.name.trim()})}catch(e){console.error(`Rename failed:`,e)}N(null)},ie=(e,t)=>{navigator.clipboard.writeText(e),F(t),setTimeout(()=>F(null),2e3)},ae=(e,n=`row`)=>{let r=n===`card`?`w-16 h-16`:`w-10 h-10`,a=n===`card`?`w-8 h-8`:`w-5 h-5`;return e.includes(`video`)||e.includes(`audio`)?(0,i.jsx)(`div`,{className:`${r} flex items-center justify-center bg-accent/10 text-accent rounded-lg`,children:(0,i.jsx)(t.br,{className:a})}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,i.jsx)(`div`,{className:`${r} flex items-center justify-center bg-blue-500/10 text-blue-500 rounded-lg`,children:(0,i.jsx)(t.gi,{className:a})}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,i.jsx)(`div`,{className:`${r} flex items-center justify-center bg-yellow-500/10 text-yellow-500 rounded-lg`,children:(0,i.jsx)(t.ea,{className:a})}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,i.jsx)(`div`,{className:`${r} flex items-center justify-center bg-emerald-500/10 text-emerald-500 rounded-lg`,children:(0,i.jsx)(t.Ei,{className:a})}):(0,i.jsx)(`div`,{className:`${r} flex items-center justify-center bg-foreground/5 text-foreground/40 rounded-lg`,children:(0,i.jsx)(t.hi,{className:a})})};return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 flex flex-col min-h-screen relative`,onDragOver:e=>{e.preventDefault(),J(!0)},onDragLeave:e=>{e.preventDefault(),J(!1)},onDrop:e=>{e.preventDefault(),J(!1),e.dataTransfer.files?.[0]&&ne(e.dataTransfer.files[0])},children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4 md:mb-6 flex items-center gap-3`,children:[!g&&(0,i.jsx)(Wt,{to:a}),(0,i.jsxs)(`div`,{className:`min-w-0`,children:[(0,i.jsx)(Ce,{children:e}),(0,i.jsxs)(`div`,{className:`max-sm:hidden sm:flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),n]})]})]}),g&&(0,i.jsx)(`div`,{className:`mb-6`,children:(0,i.jsx)(Fe,{})}),(0,i.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl md:rounded-3xl overflow-hidden flex-1 shadow-2xl min-h-[420px] md:min-h-[520px] mb-16 bg-background flex flex-col`,children:[(0,i.jsxs)(`div`,{className:`p-4 md:p-8 flex items-center justify-between gap-3 md:gap-6 border-b border-[var(--panel-border)]/50 bg-background/50`,children:[(0,i.jsxs)(`div`,{className:`min-w-0`,children:[(0,i.jsx)(`h2`,{className:`text-lg md:text-2xl font-extrabold text-foreground tracking-tight`,children:`Files`}),(0,i.jsx)(`p`,{className:`max-sm:hidden text-[12px] md:text-[13px] mt-1 md:mt-2 text-foreground/60 font-medium`,children:y?`Only you can see the files you upload here.`:`Everyone who can open this page can see these files.`})]}),!f&&(m?(0,i.jsxs)(t.cr,{onClick:re,title:`Add file`,className:`flex items-center justify-center gap-2 w-9 h-9 p-0 sm:w-auto sm:h-auto sm:px-5 sm:py-2.5 rounded-xl text-[13px] font-bold shadow-md shrink-0`,children:[(0,i.jsx)(t.Ur,{className:`w-4 h-4`}),` `,(0,i.jsx)(`span`,{className:`max-sm:hidden`,children:`Add file`})]}):(0,i.jsxs)(c.Link,{to:`/login`,title:`Sign in to add a file`,className:`btn-primary flex items-center justify-center gap-2 w-9 h-9 p-0 sm:w-auto sm:h-auto sm:px-5 sm:py-2.5 rounded-xl text-[13px] font-bold shadow-md shrink-0`,children:[(0,i.jsx)(t.Ur,{className:`w-4 h-4`}),` `,(0,i.jsx)(`span`,{className:`max-sm:hidden`,children:`Add file`})]}))]}),f?(0,i.jsx)(`div`,{className:`fbos-content-slot p-4 md:p-8 flex-1`,children:(0,i.jsx)(f,{files:b,loading:S,user:m,uploadFile:ne,deleteFile:k,openUploadModal:re,config:d})}):(0,i.jsxs)(`div`,{className:`p-4 sm:p-6 md:p-8 flex-1 relative`,children:[S&&(0,i.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,i.jsx)(t.ti,{className:`w-8 h-8 text-accent animate-spin`})}),b.length>0?(0,i.jsx)(`div`,{className:`grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3 sm:gap-4`,children:b.map(e=>(0,i.jsxs)(`div`,{className:`flex flex-col bg-background border border-[var(--panel-border)] rounded-2xl hover:border-accent/40 transition-all group overflow-hidden shadow-sm h-[190px] relative`,children:[(0,i.jsxs)(`div`,{className:`absolute top-2 right-2 flex flex-col gap-1 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity z-10 bg-background/90 backdrop-blur-md rounded-lg p-1 border border-[var(--panel-border)] shadow-xl`,children:[(0,i.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,i.jsx)(t.Si,{className:`w-4 h-4`})}),(0,i.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ie(e.downloadURL,e._id)},className:`p-1.5 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-emerald-500 transition-colors`,title:`Copy link`,children:P===e._id?(0,i.jsx)(t.zi,{className:`w-4 h-4 text-emerald-500`}):(0,i.jsx)(t.ri,{className:`w-4 h-4`})}),te(e)&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`button`,{onClick:t=>{t.stopPropagation(),N({id:e._id,name:e.fileName})},className:`p-1.5 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-accent transition-colors`,title:`Rename`,children:(0,i.jsx)(t.Kr,{className:`w-4 h-4`})}),(0,i.jsx)(`button`,{onClick:t=>{t.stopPropagation(),k(e)},className:`p-1.5 hover:bg-red-500/10 rounded-md text-foreground/60 hover:text-red-500 transition-colors`,title:`Delete`,children:(0,i.jsx)(t.Or,{className:`w-4 h-4`})})]})]}),(0,i.jsx)(`div`,{className:`h-[120px] w-full border-b border-[var(--panel-border)]/50 bg-foreground/[0.02] flex items-center justify-center overflow-hidden relative cursor-pointer`,onClick:()=>T(e),children:e.fileType.startsWith(`image/`)?(0,i.jsxs)(i.Fragment,{children:[I[e._id]!==!1&&(0,i.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center bg-accent/5 z-0`,children:(0,i.jsx)(t.ti,{className:`w-5 h-5 text-accent animate-spin`})}),(0,i.jsx)(`img`,{src:e.downloadURL,alt:``,loading:`lazy`,className:`absolute inset-0 w-full h-full object-contain p-2 transition-opacity duration-300 ${I[e._id]===!1?`opacity-100`:`opacity-0`}`,onLoad:()=>L(t=>({...t,[e._id]:!1})),onError:()=>L(t=>({...t,[e._id]:!1}))})]}):ae(e.fileType,`card`)}),(0,i.jsxs)(`div`,{className:`p-3 flex flex-col justify-center flex-1 min-w-0`,onClick:()=>!M&&T(e),children:[M?.id===e._id?(0,i.jsx)(`input`,{autoFocus:!0,type:`text`,value:M.name,onChange:e=>N({...M,name:e.target.value}),onBlur:Q,onKeyDown:e=>{e.key===`Enter`&&Q(),e.key===`Escape`&&N(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,i.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,i.jsx)(`span`,{className:`text-[11px] text-foreground/40 font-bold uppercase tracking-wider mt-1 select-none`,children:Gt(e.fileSize)})]})]},e._id))}):!S&&(0,i.jsxs)(`div`,{onClick:()=>m&&z(!0),className:`min-h-[320px] flex flex-col items-center justify-center text-center cursor-pointer group`,children:[(0,i.jsx)(t.Di,{className:`w-12 h-12 text-foreground/15 mb-4`}),(0,i.jsx)(`p`,{className:`text-[20px] font-bold text-foreground/50 group-hover:text-foreground/70 transition-colors`,children:`No files yet`}),(0,i.jsx)(`p`,{className:`text-[13px] font-medium mt-1 text-foreground/40`,children:m?`Click here or drag a file in to upload`:`Sign in to upload a file`})]})]})]}),p,(0,i.jsx)(t.pr,{children:R&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>!W&&z(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(0,i.jsxs)(t.fr.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,i.jsxs)(`div`,{className:`flex items-center justify-between p-4 md:p-6 border-b border-[var(--panel-border)]/50`,children:[(0,i.jsx)(`span`,{className:`text-[16px] font-extrabold text-foreground tracking-tight`,children:`Upload a file`}),(0,i.jsx)(`button`,{onClick:()=>!W&&z(!1),className:`text-foreground/40 hover:text-foreground transition-colors`,children:(0,i.jsx)(t._r,{className:`w-5 h-5`})})]}),B?(0,i.jsxs)(`form`,{onSubmit:X,className:`p-4 md:p-6 flex flex-col gap-5 md:gap-6`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-4 bg-foreground/[0.03] p-4 rounded-2xl border border-[var(--panel-border)]`,children:[ae(B.type),(0,i.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0 pr-4`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-bold text-foreground truncate`,children:B.name}),(0,i.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold uppercase tracking-wider mt-1`,children:Gt(B.size)})]}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>!W&&V(null),className:`w-8 h-8 flex items-center justify-center text-foreground/40 hover:text-red-500 rounded-xl hover:bg-red-500/10 transition-colors shrink-0`,children:(0,i.jsx)(t.Or,{className:`w-4 h-4`})})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,i.jsx)(`label`,{className:`text-[11px] font-bold text-foreground/50 uppercase tracking-widest pl-1`,children:`File name`}),(0,i.jsx)(`input`,{type:`text`,required:!0,value:H,onChange:e=>U(e.target.value),disabled:W,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`})]}),ee&&(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-red-400 bg-red-500/10 border border-red-500/20 rounded-xl p-3`,children:ee}),(0,i.jsx)(t.cr,{type:`submit`,isLoading:W,className:`w-full py-4 rounded-xl text-[14px] font-bold shadow-lg`,children:W?`Uploading…`:`Upload`})]}):(0,i.jsx)(`div`,{className:`p-4 md:p-6`,children:(0,i.jsxs)(`label`,{onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),e.dataTransfer.files?.[0]&&ne(e.dataTransfer.files[0])},className:`group flex flex-col items-center justify-center gap-1.5 px-6 py-12 rounded-2xl border-2 border-dashed border-[var(--panel-border)] bg-foreground/[0.015] hover:border-accent/50 hover:bg-accent/[0.03] cursor-pointer text-center transition-all`,children:[(0,i.jsx)(`span`,{className:`w-14 h-14 rounded-full bg-accent/10 text-accent flex items-center justify-center mb-2 group-hover:scale-105 transition-transform`,children:(0,i.jsx)(t.Di,{className:`w-6 h-6`})}),(0,i.jsxs)(`p`,{className:`text-[15px] font-bold text-foreground`,children:[(0,i.jsx)(`span`,{className:`text-accent`,children:`Click to upload`}),` or drag a file in`]}),(0,i.jsx)(`p`,{className:`text-[12.5px] text-foreground/45 font-medium`,children:`Pictures, documents, anything`}),(0,i.jsx)(`input`,{type:`file`,ref:Y,"aria-label":`Upload a file`,onChange:e=>e.target.files?.[0]&&ne(e.target.files[0]),className:`hidden`})]})})]})]})}),typeof window<`u`&&(0,l.createPortal)((0,i.jsx)(t.pr,{children:w&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>T(null),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/95 backdrop-blur-xl cursor-pointer`}),(0,i.jsx)(`button`,{onClick:()=>T(null),className:`absolute top-3 right-3 md:top-6 md:right-6 z-[160] w-10 h-10 md:w-12 md:h-12 bg-foreground/10 hover:bg-foreground/20 text-foreground rounded-full flex items-center justify-center backdrop-blur-md transition-all`,children:(0,i.jsx)(t._r,{className:`w-5 h-5`})}),(0,i.jsxs)(t.fr.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},className:`relative z-10 w-full max-w-6xl max-h-[85vh] flex flex-col shadow-2xl rounded-3xl overflow-hidden glass-panel border border-[var(--panel-border)]`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between p-3.5 md:p-6 bg-background/80 backdrop-blur-md border-b border-[var(--panel-border)] shrink-0`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-3 md:pr-4`,children:[(0,i.jsx)(`span`,{className:`text-[15px] md:text-xl font-extrabold text-foreground truncate`,children:w.fileName}),(0,i.jsxs)(`span`,{className:`text-[10.5px] md:text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-0.5 md:mt-1 truncate`,children:[w.fileType,` • `,Gt(w.fileSize)]})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-1.5 md:gap-2 shrink-0`,children:[(0,i.jsx)(`button`,{onClick:()=>ie(w.downloadURL,w._id),className:`p-2 md:p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-emerald-500 transition-colors rounded-xl`,title:`Copy link`,children:P===w._id?(0,i.jsx)(t.zi,{className:`w-4 h-4 text-emerald-500`}):(0,i.jsx)(t.ri,{className:`w-4 h-4`})}),te(w)&&(0,i.jsx)(`button`,{onClick:()=>{let e=w;T(null),k(e)},className:`p-2 md:p-2.5 bg-red-500/10 hover:bg-red-500/20 text-red-500 transition-colors rounded-xl`,title:`Delete`,children:(0,i.jsx)(t.Or,{className:`w-4 h-4`})}),(0,i.jsx)(`a`,{href:w.downloadURL,download:!0,target:`_blank`,rel:`noreferrer`,className:`p-2 md:p-2.5 btn-primary transition-colors rounded-xl shadow-lg ml-0.5 md:ml-1`,title:`Download`,children:(0,i.jsx)(t.Si,{className:`w-4 h-4`})})]})]}),(0,i.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-0 h-[70vh]`,children:(0,i.jsxs)(`div`,{className:`absolute inset-4 md:inset-8 flex items-center justify-center`,children:[E&&(0,i.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center z-50 pointer-events-none`,children:(0,i.jsx)(t.ti,{className:`w-6 h-6 text-accent animate-spin`})}),w.fileType.startsWith(`image/`)?(0,i.jsx)(`img`,{onLoad:()=>D(!1),src:w.downloadURL,alt:w.fileName,className:`block max-w-full max-h-full w-auto h-auto object-contain rounded-lg transition-opacity duration-500 ${E?`opacity-0`:`opacity-100`}`}):w.fileType.startsWith(`video/`)?(0,i.jsx)(`video`,{onLoadedData:()=>D(!1),src:w.downloadURL,controls:!0,className:`max-w-full max-h-full rounded-lg transition-opacity duration-500 ${E?`opacity-0`:`opacity-100`}`}):w.fileType===`application/pdf`?(0,i.jsx)(`iframe`,{onLoad:()=>D(!1),src:w.downloadURL,className:`w-full h-full border-none bg-white rounded-lg transition-opacity duration-500 ${E?`opacity-0`:`opacity-100`}`,title:`PDF preview`}):(0,i.jsxs)(`div`,{className:`flex flex-col items-center justify-center text-foreground/40 text-center`,onClick:()=>D(!1),children:[(0,i.jsx)(t.hi,{className:`w-24 h-24 mb-6 opacity-40`}),(0,i.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview unavailable`}),(0,i.jsx)(`span`,{className:`text-[14px] mt-2 text-foreground/60 font-medium max-w-xs`,children:`This format cannot be previewed. Download it instead.`})]})]})})]})]})}),document.body),(0,i.jsx)(Ve,{isOpen:!!O,title:`Delete file`,message:(0,i.jsxs)(i.Fragment,{children:[`Delete `,(0,i.jsx)(`strong`,{className:`text-foreground block my-1 break-words max-w-full text-center`,children:O?.fileName}),` This cannot be undone.`]}),onConfirm:Z,onCancel:()=>k(null),isProcessing:A,confirmText:`Yes, delete`}),(0,i.jsx)(t.pr,{children:q&&(0,i.jsx)(t.fr.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,i.jsxs)(`div`,{className:`w-full max-w-lg aspect-video bg-background/80 border-2 border-dashed border-accent rounded-[40px] shadow-2xl flex flex-col items-center justify-center gap-6`,children:[(0,i.jsx)(`div`,{className:`w-20 h-20 rounded-full bg-accent/10 flex items-center justify-center text-accent`,children:(0,i.jsx)(t.Di,{className:`w-10 h-10 animate-bounce`})}),(0,i.jsx)(`span`,{className:`text-[24px] font-extrabold text-foreground tracking-tight`,children:`Drop to upload`})]})})})]})}var qt=[`mem_files`,`user_files`,`admin_files`],Jt=e=>!e.sourceTab;function Yt(){let[e,n]=(0,r.useState)(null),[a,c]=(0,r.useState)(!1),[l,u]=(0,r.useState)(!1),[d,f]=(0,r.useState)(``),[p,m]=(0,r.useState)(0);(0,r.useEffect)(()=>{let e=!1;return Promise.all(qt.map(async e=>{try{return(await(0,o.getDocs)((0,o.collection)(t.Da,e))).docs.map(t=>({collectionName:e,id:t.id,...t.data()}))}catch{return[]}})).then(t=>{e||n(t.flat())}),()=>{e=!0}},[]);let h=async()=>{if(!e)return;u(!0),f(``);let r=0;for(let n of e)try{let e=n.storagePath||n.downloadURL;e&&Jt(n)&&await(0,s.deleteObject)((0,s.ref)(t.ka,e)).catch(()=>{}),await(0,o.deleteDoc)((0,o.doc)(t.Da,n.collectionName,n.id)),m(e=>e+1)}catch(e){r+=1,console.error(`Could not delete ${n.collectionName}/${n.id}:`,e)}r>0?(f(`${r} file${r===1?``:`s`} could not be deleted. Reload and try again.`),n((await Promise.all(qt.map(async e=>{try{return(await(0,o.getDocs)((0,o.collection)(t.Da,e))).docs.map(t=>({collectionName:e,id:t.id,...t.data()}))}catch{return[]}}))).flat())):n([]),u(!1),c(!1)};if(!e||e.length===0)return null;let g=e.filter(Jt).length,_=qt.map(t=>({name:t,n:e.filter(e=>e.collectionName===t).length})).filter(e=>e.n>0);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`mt-6 glass-panel border border-amber-500/25 bg-amber-500/[0.03] rounded-2xl md:rounded-3xl p-4 md:p-8`,children:[(0,i.jsxs)(`h3`,{className:`text-[17px] font-extrabold text-foreground tracking-tight mb-2`,children:[e.length,` leftover record`,e.length===1?``:`s`,` from the old Drive`]}),(0,i.jsx)(`p`,{className:`text-[14px] text-foreground/60 leading-relaxed mb-3 max-w-2xl`,children:`Drive used to have Internal, User and Admin folders. They are gone — this page is the only built-in folder now, and each page you have built keeps its own files. Nothing reads these records any more.`}),(0,i.jsxs)(`p`,{className:`text-[14px] text-foreground/60 leading-relaxed mb-3 max-w-2xl`,children:[g>0?`${g} ${g===1?`was`:`were`} uploaded through the old Drive screen, so ${g===1?`its file is`:`their files are`} deleted too. `:``,e.length-g>0?`${e.length-g} belong to files a page still shows, so only the leftover record goes — the ${e.length-g===1?`file stays`:`files stay`} where ${e.length-g===1?`it is`:`they are`}.`:``]}),(0,i.jsx)(`p`,{className:`text-[13px] text-foreground/50 font-medium mb-5`,children:_.map(e=>`${e.n} in ${e.name}`).join(` · `)}),d&&(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-red-400 bg-red-500/10 border border-red-500/20 rounded-xl p-3 mb-4`,children:d}),(0,i.jsxs)(`button`,{onClick:()=>c(!0),disabled:l,className:`inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-[13px] font-bold bg-red-500/10 hover:bg-red-500/20 text-red-500 border border-red-500/20 transition-colors disabled:opacity-50`,children:[l?(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin`}):(0,i.jsx)(t.Or,{className:`w-4 h-4`}),l?`Deleting ${p} of ${e.length}…`:`Clean up all ${e.length} permanently`]})]}),(0,i.jsx)(Ve,{isOpen:a,title:`Delete the old Drive files`,message:(0,i.jsxs)(i.Fragment,{children:[`This permanently deletes `,(0,i.jsxs)(`strong`,{className:`text-foreground`,children:[e.length,` leftover record`,e.length===1?``:`s`]}),` `,`from `,_.map(e=>e.name).join(`, `),g>0&&(0,i.jsxs)(i.Fragment,{children:[`, along with the `,(0,i.jsxs)(`strong`,{className:`text-foreground`,children:[g,` file`,g===1?``:`s`]}),` uploaded through the old Drive screen`]}),`. It cannot be undone, and it covers every user's uploads, not only your own. Files that a page still shows are left alone.`]}),onConfirm:h,onCancel:()=>c(!1),isProcessing:l,confirmText:`Yes, delete them`})]})}function Xt(){let{isAdmin:e}=t.na();return(0,i.jsx)(Kt,{title:`Assets`,subtitle:`/assets`,filesCollection:`pub_files`,config:{isAdmin:!0,pageId:`assets`},footer:e?(0,i.jsx)(Yt,{}):null})}function Zt(){let e=[{id:`board`,title:`Board View`,description:`Cards in columns you drag from one stage to the next.`,icon:t.ui,path:`/board`},{id:`table`,title:`Data Table`,description:`Rows and columns for longer lists, with search and sorting.`,icon:t.jr,path:`/table`},{id:`calendar`,title:`Calendar View`,description:`A month at a time for anything that belongs on a date.`,icon:t.Vi,path:`/calendar`},{id:`drive`,title:`Drive View`,description:`A file library with upload, preview, rename and delete.`,icon:t.pi,path:`/drive`}];return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-10 text-center`,children:[(0,i.jsx)(Ce,{children:`What your assistant can build`}),(0,i.jsxs)(`p`,{className:`text-foreground/60 text-[14px] md:text-[15px] font-medium max-w-2xl mx-auto`,children:[`Every layout below already works — open one to see it.`,` `,(0,i.jsx)(c.Link,{to:`/guide`,className:`text-accent font-bold hover:underline`,children:`Start with the guide`}),`.`]})]}),(0,i.jsxs)(`div`,{className:`w-full max-w-4xl mx-auto flex flex-col gap-3 md:gap-4 relative`,children:[(0,i.jsx)(`div`,{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[80%] h-[80%] bg-accent/5 blur-[120px] rounded-full pointer-events-none -z-10`}),e.map((e,n)=>{let r=e.icon;return(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:n*.05},children:(0,i.jsxs)(c.Link,{to:e.path,className:`flex items-center gap-3 md:gap-5 w-full p-3.5 md:px-6 md:py-4 glass-panel border border-[var(--panel-border)] rounded-2xl hover:border-accent/40 transition-all duration-300 group hover:bg-foreground/[0.02]`,children:[(0,i.jsx)(`div`,{className:`w-10 h-10 md:w-12 md:h-12 rounded-xl bg-accent/10 flex items-center justify-center text-accent shrink-0 border border-accent/20 group-hover:scale-105 transition-transform`,children:(0,i.jsx)(r,{className:`w-5 h-5`})}),(0,i.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,i.jsx)(`h3`,{className:`text-[14px] md:text-[15px] font-bold text-foreground truncate`,children:e.title}),(0,i.jsx)(`p`,{className:`text-[12.5px] md:text-[13px] text-foreground/50 truncate font-medium`,children:e.description})]}),(0,i.jsx)(`span`,{"aria-hidden":`true`,className:`w-9 h-9 rounded-full flex items-center justify-center text-foreground/40 border border-[var(--panel-border)] shrink-0 group-hover:text-accent group-hover:border-accent/40 group-hover:translate-x-0.5 transition-all`,children:(0,i.jsx)(t.Xi,{className:`w-4 h-4`})})]})},e.id)})]})]})}var Qt=`Xl271wWblkY`,$t=[{title:`Open the Pages screen and press +`,body:`Pick Website Pages, for your public site, or Tabs, for the dashboard behind sign-in. A tab starts open to Members — everybody who registers — and its own row carries who can open it: switch it to Your team or Admins only any time, or, staying on Members, tick more than one audience or make a role of your own — Client, say — and keep the page for the people you mark with it.`},{title:`Name the page and say what is on it`,body:`The row opens in sections. The first is the page itself: its name, its web address and one box for what is on it, in your own words — every box shows a real example before you type. The name creates the page the moment you leave its box; the address is made from the name unless you write one, and a dashboard page takes the menu icon your words name. Whatever you skip, your assistant decides.`},{title:`If it needs forms, say so in the Forms section`,body:`Describe every form the page needs, one after the other — what each asks and what happens after — or name forms you already have. Your assistant builds them with the page, decides where each goes and what its button says, and every answer lands in your Inbox.`},{title:`Add your pictures, your booking and a linked page`,body:`Under Pictures, upload each picture — it gets a number — and say how they are used, by number. Under Booking, pick a schedule from the Schedule screen and say how booking works here. Under Linked pages, pick another of your pages — or make a new one right there, with the same sections — and say how the two connect. Pictures never travel through the chat; the sentence you copy carries them for you.`},{title:`Copy the sentence`,body:`Once email or payments are switched on, an Emails and a Payments section appear too. The finished sentence appears under the sections; copy it and paste it into your assistant’s chat. That is the whole hand-over.`},{title:`Change it later in the same place`,body:`Once the sentence is copied, the row knows the page is built: open it again and one box asks what to change, with the same sections under it. The sentence it hands you edits the page you already have — your words, plus only the sections you changed since — and nothing you did not mention is touched. Copying it blanks the box for next time. To rename or move the page, write Name: or Address: on a line of its own in that box.`}],en=[{name:`Website Pages`,where:`In the site menu`,who:`Everybody, signed in or not. This is your public website.`},{name:`Members`,where:`In the dashboard`,who:`Anyone who registers. Each person sees only their own information, never anyone else’s.`},{name:`Your team`,where:`In the dashboard`,who:`Only people you marked as team members on the Users screen, plus admins. Everyone on it sees the same information.`},{name:`Admins only`,where:`In the dashboard`,who:`You, and anyone you marked as an admin.`},{name:`A role of your own`,where:`In the dashboard`,who:`People you marked with a role you invented — Client, Supplier, whatever you need. You make one in the list on a Members page’s row, and mark people with it on the Users screen. They are ordinary Members in every other way; a page kept for a role is theirs alone, nobody else can even follow its address, and everyone marked with it sees the same information on it.`}],tn=[{title:`Someone registers`,body:`That makes them a Member, nothing more: they can open the pages for Members and see only their own information there.`},{title:`You give them rights on the Users screen`,body:`Mark a person as a team member to open your team’s pages, or as an admin to open everything — your admin screens included. Or mark them with a role of your own — Client, Supplier — which opens the pages you kept for that role and nothing else. Take any of them back the same way.`},{title:`The pages do the rest`,body:`Access always follows who a page is for. There is nothing to switch on per person beyond the mark you set — a new team page is open to your whole team the moment it exists.`}],nn=[{name:`Say what you are after`,body:`What you do, who it is for and the feeling you want. Upload your logo — its colours are where the look comes from — and give the site its name. Say whether it should be always light, always dark, or follow the visitor’s device only if you want that changed.`},{name:`Copy the sentence to your assistant`,body:`The Theme screen turns your answers into one sentence. Paste it into your assistant’s chat, and attach your logo picture to the same message — the assistant cannot open the link, and the picture is where it reads the colours.`},{name:`It designs the whole look`,body:`Colours for light and dark, the buttons, the headings, the corners, your logo and the name, all in one file. Ask it to be bold and it will be; ask it for calm and it will be that. There are no colour boxes or sliders to set by hand.`},{name:`Change it the same way`,body:`Once the look is in, the screen asks what you would like changed. Say just that — a softer green, warmer backgrounds — and copy the sentence again. Nothing you do not mention moves.`}],rn=[{screen:`Inbox`,path:`/inbox`,body:`Read every answer people sent through your forms.`},{screen:`Users`,path:`/users`,body:`Mark a person as a team member or an admin — or with a role of your own. Your own roles are kept in a card under the list: rename one and the new word appears everywhere at once, on every card and in every list, with nobody unmarked; remove one and the card first says what that will do — the people marked with it go back to being members, the pages kept for it go back to everybody signed in, and whatever those pages saved stays exactly where it is.`},{screen:`Pages`,path:`/pages`,body:`Press + and fill in the sections: the page itself — its name, its web address and what is on it — then its pictures, its forms (as many as you like, described one after the other), its schedules (whose working hours from the Schedule screen the page is built on — the week itself, one person each, never a meeting you designed — then how they will be used: a rota, who is in on Thursday, or a page people book time on; with more than one person picked you also say who a booking is with — one of them, all of them at once, or both with the visitor choosing — and last, only if they book, what they should be asked first. Nothing here waits on a booking link: the hours themselves are what is booked, read live, so changing your week changes the page), the booking links or booking pages you already made and want a link to on it, with a line on where that link should sit and how it should open, the pages it links to (one you have, or a new one made right there), and, once switched on, its emails and its payments; every box shows a real example before you type, and whatever you skip your assistant decides. Copy the sentence. The moment it is copied the page counts as built and the row asks what should change, with the same sections under it: the sentence carries your words plus only the sections you changed since, a rename or a move is a Name: or Address: line of its own, and copying blanks the box again — the forms box too, which then asks what should change about the forms. The home page, the dashboard, Contact and Support open on the same sections. Reorder, hide or delete a page from its row.`},{screen:`Schedule`,path:`/schedule`,body:`When you and your team are free, and everything built on it. A SCHEDULE is a week of hours with a name — Working hours, Evenings, Studio days — kept in that person’s own time zone, with the days they are away marked on it. Your own are in the first card and everyone else’s — anyone marked Internal or Admin on the Users screen — under their own name in the second, so press the Add a schedule of whoever the hours belong to. It arrives named, weekdays nine to five — hours have no on and off switch, they are simply the week you keep; change the hours, add a second stretch for a break in the middle, and add a day away for a holiday — every meeting booked in those hours loses that day at once, which is the whole point of entering it in one place. A BOOKING LINK, in the card under them, is what turns hours into something people can book: pick which hours it is booked in, what the meeting is called, how long it lasts, how far ahead and with how much notice, what it asks the visitor beyond their name and their email, and a payment if you want one taken first — then copy its link and send it to anyone. They see the free times in their own time zone, pick one, and book. One set of hours carries as many links as you like — a 15-minute intro and a 2-hour workshop on the same week — and they share one availability, so a time taken under one is gone from all of them. The switch on each row is what offers it: leave it off while you set it up, turn it on when you are ready. Under Your booking pages, Create a page makes ONE address that carries several of them: give it a name, a photo and a line about yourself, tick the meetings it should offer, and send that instead — whoever opens it sees what you do and everything you can be booked for, and books it the same way. You can also pick a schedule on the Pages screen under Schedules on that page — what you pick there is somebody’s WEEK, not one of these meetings, because a page built on your hours does not have to be a booking at all: say how it will be used and it is built on them, and leave the question about what people are asked empty when nothing is booked there. A booking link is not needed for any of that and is never asked for: if the page does book, it books those hours themselves, so the times follow your week wherever it is shown. Or, under Booking links there, tick a link or a page you have already made and it goes on that page as a plain link, opening the very one you ticked — say where it should sit and how it opens (a button that says Book time with me, opening in a pop-up) and nothing about it is rebuilt. Or add a Pick-a-time question to any form on the Forms screen. Every booking lands on the Calendar at the top of this screen, where you can cancel it, and in your Inbox like any form entry. That calendar is a month grid of everything booked: pick a day to see who is coming, with Paid beside a booking that was paid for, and Cancel to free the time. As an admin you can read it as your whole team at once, or as any one person — whoever has no schedule yet is greyed in the list — and Add puts an event of your own on the day you picked, in whosever diary you are reading. Taking a booking off the calendar for good is an admin’s alone: it destroys the record in every diary it was booked into and on the other side of it too, so everybody it belonged to is told before it goes, and an event you put on your own day is still yours to delete. Whoever booked reads the very same calendar under My bookings, from their end — what the meeting is and who it is with, never the name of the week it falls in — and cancels from it the same way, saying why. Everybody signed in has the bell, so a cancellation on either side reaches the other without anybody opening a page.`},{screen:`Payments`,path:`/payments`,body:`The Take payments switch at the top turns every Pay button on or off at once — off is a pause, not a disconnect, and your pages keep their settings. Under Payment links, every one-time payment has a page of its own you can send to anyone — add one from a name, a line about it and a price, copy the link, and press Customise this page to have your assistant make a page of your own for it. Check the connection, then describe what you sell under What you sell — things paid for once, each with a name and a price, as many as you like under one entry; or a subscription with plans and their Stripe ids — and press Proceed. That opens the same payment under How your payments work, where one box asks how it works, start to finish: what someone does, pays and gets, and anything you care about along the way — what they tell you first, what happens after, what a plan unlocks; whatever you skip, your assistant decides. Press Proceed once more and the same payment opens under Wire it into your pages: tick the pages this one goes on — where it sells, and where your team sees what it sold — and, if you like, say what should appear there or name a page to add and who will see it. Every payment has its own pages; under them, one request carries all of them, every page and the way your app makes pages, forms and links, so your assistant wires it in one go — and you change any page afterwards from its row on the Pages screen. Connection stands right under the switch and says which Stripe account you are on — Test mode connected while you are practising. Under it sits Go live, always there: flip it and it walks you through your live secret key, your live price ids if you sell subscriptions, and the webhook that keeps receipts and sale alerts sending when a buyer pays and never comes back. That last step waits until your app is published, because Stripe has to be able to reach it from the outside — tick step 3 on the Publish App screen, Add your domains and email sender, and it unlocks itself with your published address ready to copy. Your customers change or cancel their subscriptions on Stripe’s own page — switching plans (monthly to yearly, Basic to Pro) appears there only if you allow it, under Stripe’s Settings, Billing, Customer portal — so there is nothing to ask the assistant to build for cancellations.`},{screen:`Billing`,path:`/billing`,body:`Your buyers’ page, not yours: anyone signed in who has bought something finds what they bought here, with Stripe’s own button to change card, cancel or switch plans. It appears in their menu only after their first purchase — nobody who never bought anything sees it, and there is nothing to build.`},{screen:`Email`,path:`/email`,body:`Connect email, switch it on or off with Send email at the top — off stops every send at once and keeps your settings — send yourself one test email, after which the Connection card only says Connected and the address it sends from (it opens up again if you change the sender), and see what your app can do with it: hear about what happens on a page, confirm to the people who write in, send receipts and sale alerts, and — from a page for your team — write to anyone. Each says where it is switched on — a page on the Pages screen, a payment on the Payments screen. Receipts and sale alerts send themselves — every payment you describe on the Payments screen has both switched on unless you turn them off.`},{screen:`Forms`,path:`/forms`,body:`See every form. Add a question or change a form’s title and button text after it is built — forms are created with their pages.`},{screen:`Theme`,path:`/theme`,body:`Where you tell your assistant what look you want — your logo, the name, how the site opens, and the feeling you are after — and copy the one sentence that has it design the whole thing. Nothing is set by hand here.`},{screen:`Publish App`,path:`/publish`,body:`The last tab, for once your app works for you: how to put it in front of other people, one step at a time — each step appears only when you tick the one before it, and a finished step folds under its checkmark and opens again with a click. Step 1 publishes it in AI Studio and saves the app name you chose there; step 2 connects your own domain through Google Cloud Run and saves the domain; step 3 adds both addresses as authorised domains in Firebase and verifies your email sender, handing you both addresses to copy. If your payments are still on practice cards, a fourth step sends you to Go live on the Payments screen — whose webhook step is the one waiting on step 3 here. Stuck anywhere? The email and WhatsApp buttons at the top reach me.`}],an=[{title:`One page or one form per message`,body:`Describe it completely, then send. Ask for the next one when the first is live.`},{title:`Let the Pages screen write the request`,body:`Describe the page on its row and paste the sentence it hands you. It answers every question the assistant would otherwise stop to ask.`},{title:`Use the exact words you want to see`,body:`Headings, button labels, choices in a list. The assistant copies them; it does not improve them.`},{title:`When something is wrong, describe your screen`,body:`The web address, what you clicked, what happened, what you expected. Not what you think the cause is.`},{title:`Never accept homework`,body:`The assistant makes every change itself. If a reply ends with something for you to edit, paste or run, answer: "Do that for me."`}],on=[{id:`how-it-works`,short:`How it all works`},{id:`add-a-page`,short:`Adding a page`},{id:`audiences`,short:`The four kinds of pages`},{id:`users`,short:`Letting people in`},{id:`theme`,short:`Changing the look`},{id:`yourself`,short:`Where everything lives`},{id:`habits`,short:`Working with the assistant`}];function sn({children:e}){return(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px] mb-3`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e]})}function cn({id:e,index:n,kicker:r,title:a,children:o}){return(0,i.jsxs)(t.fr.section,{id:e,initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.05+n*.03},className:`mb-16 scroll-mt-24`,children:[(0,i.jsx)(sn,{children:`0${n+1} · ${r}`}),(0,i.jsx)(`h2`,{className:`text-2xl font-extrabold tracking-tight text-foreground mb-3`,children:a}),o]})}function ln({children:e}){return(0,i.jsx)(`p`,{className:`text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl mb-4 last:mb-0`,children:e})}function un({steps:e}){return(0,i.jsx)(`ol`,{className:`mt-6`,children:e.map((t,n)=>(0,i.jsxs)(`li`,{className:`relative grid grid-cols-[2.25rem_1fr] gap-x-4 pb-8 last:pb-0`,children:[n<e.length-1&&(0,i.jsx)(`span`,{"aria-hidden":!0,className:`absolute left-[1.125rem] top-10 bottom-1 w-px -translate-x-1/2 bg-[var(--panel-border)]`}),(0,i.jsx)(`span`,{className:`flex h-9 w-9 items-center justify-center rounded-full border border-[var(--panel-border)] bg-[var(--panel-bg)] text-[13px] font-bold text-accent tabular-nums select-none`,children:n+1}),(0,i.jsxs)(`div`,{className:`pt-1.5 min-w-0`,children:[(0,i.jsx)(`h3`,{className:`text-[15px] font-bold tracking-tight text-foreground`,children:t.title}),(0,i.jsx)(`p`,{className:`mt-1.5 text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl`,children:t.body})]})]},t.title))})}function dn({lead:e,children:t}){return(0,i.jsx)(`div`,{className:`mt-7 border-l-2 border-accent/50 pl-4`,children:(0,i.jsxs)(`p`,{className:`text-[13.5px] text-foreground/60 font-medium leading-relaxed max-w-2xl`,children:[(0,i.jsx)(`strong`,{className:`font-bold text-foreground/85`,children:e}),` `,t]})})}function fn(){return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-3xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-10 text-center`,children:[(0,i.jsx)(Ce,{children:`Guide`}),(0,i.jsx)(`p`,{className:`text-foreground/60 text-[14px] md:text-[15px] font-medium max-w-2xl mx-auto`,children:`Everything you run yourself, everything your assistant builds for you, and the one recipe that makes every page. Ten minutes, start to finish.`})]}),(0,i.jsxs)(t.fr.section,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`mb-10`,children:[(0,i.jsx)(`div`,{className:`relative w-full rounded-2xl overflow-hidden border border-[var(--panel-border)] glass-panel`,children:(0,i.jsx)(`div`,{className:`relative w-full aspect-video`,children:(0,i.jsx)(`iframe`,{className:`absolute inset-0 w-full h-full`,src:`https://www.youtube-nocookie.com/embed/${Qt}?start=1`,title:`Watch the guide`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share`,allowFullScreen:!0,loading:`lazy`,referrerPolicy:`strict-origin-when-cross-origin`})})}),(0,i.jsx)(`p`,{className:`mt-3 text-center text-[12.5px] text-foreground/45 font-medium`,children:`Six minutes, from an empty project to a finished site.`})]}),(0,i.jsxs)(t.fr.nav,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:.03},"aria-label":`In this guide`,className:`mb-14`,children:[(0,i.jsx)(sn,{children:`In this guide`}),(0,i.jsx)(`ol`,{className:`grid gap-x-10 gap-y-1.5 sm:grid-cols-2`,children:on.map((e,t)=>(0,i.jsx)(`li`,{children:(0,i.jsxs)(`a`,{href:`#${e.id}`,className:`group flex items-baseline gap-2.5 py-0.5 w-fit`,children:[(0,i.jsxs)(`span`,{className:`text-[11px] font-bold text-foreground/35 tabular-nums`,children:[`0`,t+1]}),(0,i.jsx)(`span`,{className:`text-[14px] font-semibold text-foreground/75 group-hover:text-accent transition-colors`,children:e.short})]})},e.id))})]}),(0,i.jsxs)(cn,{id:`how-it-works`,index:0,kicker:`Start here`,title:`How it all works`,children:[(0,i.jsx)(ln,{children:`Your site is a set of pages. Some are open to the world — that is your public website. The rest live in the dashboard, behind a sign-in: pages every registered person can open, pages only your team can open, and pages only admins can open.`}),(0,i.jsx)(ln,{children:`You run all of it from the admin screens in your menu — the Inbox and Users first, because they fill on their own, then Pages and the screens you set up once. Everything on those screens changes with a click and takes effect at once: names, addresses, colours, who counts as team, who counts as admin.`}),(0,i.jsxs)(ln,{children:[`What goes `,(0,i.jsx)(`em`,{className:`not-italic font-bold text-foreground/80`,children:`on`}),` a page is the one thing you do not click together — your assistant builds it. But you never have to work out what to say to it: when you describe a page on the Pages screen, the screen writes the whole request as one sentence. You copy that sentence, paste it into your assistant’s chat, and the page gets built. That copy-and-paste is the entire relationship, and the next chapter walks through it.`]})]}),(0,i.jsxs)(cn,{id:`add-a-page`,index:1,kicker:`The one recipe`,title:`How to add a page — any kind`,children:[(0,i.jsx)(ln,{children:`The same six steps make every page: a public one for your website, a board for your team, a table each signed-in person has to themselves. Never ask the chat to create a page out of nowhere — the Pages screen writes a better request than anyone types by hand.`}),(0,i.jsx)(un,{steps:$t}),(0,i.jsxs)(dn,{lead:`Not sure which layout to pick?`,children:[(0,i.jsx)(c.Link,{to:`/templates`,className:`text-accent font-bold hover:underline`,children:`Look through the templates`}),` `,`to see each one working before you choose.`]})]}),(0,i.jsxs)(cn,{id:`audiences`,index:2,kicker:`Who it is for`,title:`The four kinds of pages`,children:[(0,i.jsx)(ln,{children:`Every page is for exactly one audience: it decides who can open the page and which menu it appears in. A Tab starts as Members and its own row says who can open it — Members, Your team, Admins only, or a role of your own. These are the words printed there:`}),(0,i.jsx)(`div`,{className:`mt-6 space-y-6`,children:en.map(e=>(0,i.jsxs)(`div`,{children:[(0,i.jsxs)(`div`,{className:`flex items-baseline gap-2.5 flex-wrap`,children:[(0,i.jsx)(`h3`,{className:`text-[15px] font-bold tracking-tight text-foreground`,children:e.name}),(0,i.jsx)(`span`,{className:`text-[12px] text-accent font-semibold`,children:e.where})]}),(0,i.jsx)(`p`,{className:`mt-1 text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl`,children:e.who})]},e.name))}),(0,i.jsx)(dn,{lead:`Careful:`,children:`Registering only makes someone a Member, not a team member. Never put your team’s information on a page for Members — any stranger who registers could open it.`})]}),(0,i.jsxs)(cn,{id:`users`,index:3,kicker:`Letting people in`,title:`How users work`,children:[(0,i.jsx)(ln,{children:`People let themselves in at the front door; you decide who gets further.`}),(0,i.jsx)(un,{steps:tn})]}),(0,i.jsxs)(cn,{id:`theme`,index:4,kicker:`The look`,title:`How to change the theme`,children:[(0,i.jsxs)(ln,{children:[`The look is your assistant’s job, and your`,` `,(0,i.jsx)(c.Link,{to:`/theme`,className:`text-accent font-bold hover:underline`,children:`Theme screen`}),` `,`is where you brief it. There are no colour boxes to fill in: you say what you are after, copy one sentence, and the assistant designs the whole thing. Four steps:`]}),(0,i.jsx)(`div`,{className:`mt-6 space-y-6`,children:nn.map(e=>(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`h3`,{className:`text-[15px] font-bold tracking-tight text-foreground`,children:e.name}),(0,i.jsx)(`p`,{className:`mt-1 text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl`,children:e.body})]},e.name))})]}),(0,i.jsxs)(cn,{id:`yourself`,index:5,kicker:`No assistant needed`,title:`Where everything lives`,children:[(0,i.jsx)(ln,{children:`These are switches and boxes in your admin screens. Asking the assistant for them only gets you sent here.`}),(0,i.jsx)(`div`,{className:`mt-6 space-y-6`,children:rn.map(e=>(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`h3`,{className:`text-[15px] font-bold tracking-tight w-fit`,children:(0,i.jsx)(c.Link,{to:e.path,className:`text-foreground hover:text-accent transition-colors`,children:e.screen})}),(0,i.jsx)(`p`,{className:`mt-1 text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl`,children:e.body})]},e.screen))}),(0,i.jsx)(dn,{lead:`Good to know:`,children:`The Guide, Templates and Contact pages come with the app and are visible on purpose. Hide any of them on the Pages screen with the switch next to its name. Setup is not one of them: it is the walkthrough that connects your app to Firebase, it is finished before anybody signs in, and it is in no menu — type /setup after your address to open it, which is how you come back to re-paste the rules after an update.`})]}),(0,i.jsxs)(cn,{id:`habits`,index:6,kicker:`Five habits`,title:`Working with the assistant`,children:[(0,i.jsx)(ln,{children:`Five habits keep the assistant on track. There is nothing to memorise beyond them.`}),(0,i.jsx)(`div`,{className:`mt-6 space-y-6`,children:an.map(e=>(0,i.jsxs)(`div`,{children:[(0,i.jsx)(`h3`,{className:`text-[15px] font-bold tracking-tight text-foreground`,children:e.title}),(0,i.jsx)(`p`,{className:`mt-1 text-[14px] text-foreground/65 font-medium leading-relaxed max-w-2xl`,children:e.body})]},e.title))})]})]})}function pn(){let[e,n]=(0,r.useState)({favoriteService:``,satisfactionRating:``,detailedThoughts:``}),[a,s]=(0,r.useState)(`idle`);return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col`,children:[(0,i.jsx)(`div`,{className:`w-full max-w-5xl mx-auto mb-6`,children:(0,i.jsx)(Wt,{to:`/templates`})}),(0,i.jsx)(`div`,{className:`w-full max-w-5xl mx-auto mt-6`,children:(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:`w-full max-w-[500px] p-6 sm:p-8 lg:p-10 rounded-3xl md:rounded-3xl glass-form relative glow-hover shadow-[0_8px_32px_rgba(0,0,0,0.08)] z-10 mx-auto`,children:[(0,i.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,i.jsx)(`div`,{className:`relative z-10 w-full`,children:a===`success`?(0,i.jsxs)(t.fr.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,i.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,i.jsx)(t.Ni,{className:`w-8 h-8`})}),(0,i.jsx)(`h4`,{className:`text-lg font-bold text-foreground mb-2`,children:`Simulation Complete!`}),(0,i.jsx)(`p`,{className:`text-[14px] text-foreground/60 leading-relaxed`,children:`Your test data was sent successfully. Log in as an admin and open your Inbox to see it.`})]}):a===`loading`?(0,i.jsxs)(t.fr.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,i.jsx)(`div`,{className:`w-10 h-10 border-4 border-accent border-r-transparent rounded-full animate-spin mb-4`}),(0,i.jsx)(`h4`,{className:`text-lg font-bold text-foreground tracking-tight`,children:`Processing`}),(0,i.jsx)(`p`,{className:`text-[13px] text-foreground/50 mt-1`,children:`Simulating submission...`})]}):(0,i.jsxs)(t.fr.div,{initial:{opacity:0},animate:{opacity:1},children:[(0,i.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,i.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight break-words`,children:`Inline Form Template`}),(0,i.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,i.jsxs)(`form`,{onSubmit:async r=>{r.preventDefault(),s(`loading`);try{let r=t.Ea.currentUser?.uid||`guest`;await(0,o.addDoc)((0,o.collection)(t.Da,`user_submissions`),{uid:r,...e,type:`template_simulation`,submittedAt:(0,o.serverTimestamp)()}),s(`success`),setTimeout(()=>{s(`idle`),n({favoriteService:``,satisfactionRating:``,detailedThoughts:``})},3e3)}catch{s(`error`)}},className:`space-y-4 w-full`,children:[(0,i.jsx)(t.lr,{label:`Favorite Service`,placeholder:`e.g. Design Consulting`,value:e.favoriteService,onChange:t=>n({...e,favoriteService:t.target.value})}),(0,i.jsx)(t.lr,{label:`Satisfaction Rating`,type:`number`,placeholder:`1 to 10`,value:e.satisfactionRating,onChange:t=>n({...e,satisfactionRating:t.target.value})}),(0,i.jsxs)(`div`,{className:`flex flex-col w-full relative`,children:[(0,i.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Detailed Thoughts`}),(0,i.jsx)(`textarea`,{rows:3,placeholder:`Type something here...`,value:e.detailedThoughts,onChange:t=>n({...e,detailedThoughts:t.target.value}),className:`flex w-full rounded-xl text-[15px] text-foreground px-4 py-3 transition-all duration-300 placeholder:text-foreground/40 focus:outline-none focus:border-accent glow-focus disabled:cursor-not-allowed disabled:opacity-50 glass-panel min-h-[100px] resize-none`})]}),(0,i.jsx)(`div`,{className:`pt-2`,children:(0,i.jsx)(t.cr,{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 mn(){let[e,n]=(0,r.useState)(!1),[a,s]=(0,r.useState)({concept:``,featureRequest:``,notes:``}),[c,l]=(0,r.useState)(`idle`);return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4`,children:[(0,i.jsx)(`div`,{className:`mb-3`,children:(0,i.jsx)(Wt,{to:`/templates`})}),(0,i.jsx)(Ce,{children:`Popup Form`}),(0,i.jsxs)(`div`,{className:`max-sm:hidden sm:flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/popup_form`]})]}),(0,i.jsxs)(t.fr.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,i.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,i.jsxs)(`div`,{className:`flex flex-col sm:flex-row h-full w-full gap-4 sm:gap-6 justify-between sm:items-center relative z-10`,children:[(0,i.jsxs)(`div`,{className:`min-w-0`,children:[(0,i.jsx)(`h2`,{className:`text-xl md:text-2xl font-extrabold text-foreground tracking-tight mb-2`,children:`A form in a pop-up`}),(0,i.jsx)(`p`,{className:`text-[13px] md:text-[14px] text-foreground/60 font-medium leading-relaxed max-w-md`,children:`The page stays where it is and the form opens over it, with the background blurred. Close it and nothing is lost.`})]}),(0,i.jsxs)(t.cr,{onClick:()=>n(!0),className:`px-6 py-2.5 text-[14px] font-bold rounded-xl shadow-lg flex items-center justify-center gap-2 btn-primary transition-all hover:-translate-y-1 shrink-0`,children:[(0,i.jsx)(t.Ur,{className:`w-4 h-4`}),` Open Form`]})]})]}),(0,i.jsx)(t.pr,{children:e&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-xl cursor-pointer`,onClick:()=>n(!1)}),(0,i.jsxs)(t.fr.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},className:`w-full max-w-[500px] p-6 sm:p-8 lg:p-10 rounded-3xl md:rounded-3xl glass-popover relative shadow-[0_8px_32px_rgba(0,0,0,0.08)] z-10 mx-4 max-h-[95vh] overflow-y-auto no-scrollbar`,children:[(0,i.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,i.jsxs)(`div`,{className:`relative z-10 w-full`,children:[(0,i.jsx)(`button`,{onClick:()=>n(!1),className:`absolute -top-2 -right-2 w-8 h-8 flex items-center justify-center rounded-full hover:bg-foreground/5 text-foreground/60 hover:text-foreground transition-colors z-20`,children:(0,i.jsx)(t._r,{className:`w-5 h-5`})}),c===`success`?(0,i.jsxs)(t.fr.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,i.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,i.jsx)(t.Ni,{className:`w-8 h-8`})}),(0,i.jsx)(`h4`,{className:`text-xl font-bold text-foreground mb-2`,children:`Simulation Complete!`}),(0,i.jsx)(`p`,{className:`text-[14px] text-foreground/60 leading-relaxed max-w-[280px]`,children:`Your test data was sent successfully. Log in as an admin and open your Inbox to see it.`})]}):c===`loading`?(0,i.jsxs)(t.fr.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,i.jsx)(`div`,{className:`w-10 h-10 border-4 border-accent border-r-transparent rounded-full animate-spin mb-4`}),(0,i.jsx)(`h4`,{className:`text-lg font-bold text-foreground tracking-tight`,children:`Processing`}),(0,i.jsx)(`p`,{className:`text-[13px] text-foreground/50 mt-1`,children:`Simulating submission...`})]}):(0,i.jsxs)(t.fr.div,{initial:{opacity:0},animate:{opacity:1},children:[(0,i.jsxs)(`div`,{className:`mb-6 text-center`,children:[(0,i.jsx)(`h3`,{className:`text-2xl sm:text-3xl font-extrabold mb-2 text-foreground tracking-tight break-words`,children:`Popup Template`}),(0,i.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,i.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),l(`loading`);try{let e=t.Ea.currentUser?.uid||`guest`;await(0,o.addDoc)((0,o.collection)(t.Da,`user_submissions`),{uid:e,...a,type:`template_simulation`,submittedAt:(0,o.serverTimestamp)()}),l(`success`),setTimeout(()=>{l(`idle`),s({concept:``,featureRequest:``,notes:``}),n(!1)},3e3)}catch{l(`error`)}},className:`space-y-4 w-full`,children:[(0,i.jsx)(t.lr,{label:`Concept Name`,placeholder:`e.g. Project Apollo`,value:a.concept,onChange:e=>s({...a,concept:e.target.value})}),(0,i.jsx)(t.lr,{label:`Feature Request`,placeholder:`e.g. Real-time sync`,value:a.featureRequest,onChange:e=>s({...a,featureRequest:e.target.value})}),(0,i.jsxs)(`div`,{className:`flex flex-col w-full relative`,children:[(0,i.jsx)(`label`,{className:`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,children:`Simulated Notes`}),(0,i.jsx)(`textarea`,{rows:3,placeholder:`Type something here...`,value:a.notes,onChange:e=>s({...a,notes:e.target.value}),className:`flex w-full rounded-xl text-[15px] text-foreground px-4 py-3 transition-all duration-300 placeholder:text-foreground/40 focus:outline-none focus:border-accent glow-focus disabled:cursor-not-allowed disabled:opacity-50 glass-panel min-h-[100px] resize-none`})]}),(0,i.jsx)(`div`,{className:`pt-2`,children:(0,i.jsx)(t.cr,{type:`submit`,className:`w-full px-6 md:px-8 py-3 md:py-3.5 rounded-xl font-semibold tracking-wide btn-primary text-[15px] shadow-xl transition-all duration-300 hover:-translate-y-1 active:scale-95 flex items-center justify-center`,isLoading:!1,children:`Trigger Simulation`})})]})]})]})]})]})})]})}var hn=e=>({creatorName:e?.displayName||e?.email?.split(`@`)[0]||``,creatorAvatar:e?.photoURL||``}),gn=(e,t)=>{if(e?.creatorName)return{name:e.creatorName,avatar:e.creatorAvatar||``};if(e?.uid&&t?.uid&&e.uid===t.uid){let e=hn(t);return e.creatorName?{name:e.creatorName,avatar:e.creatorAvatar}:null}return null},_n=[{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 vn({title:e=`Board View`,subtitle:n=`/board`,backUrl:a=`/templates`,tasksCollection:s=`pub_tasks`,categoriesCollection:c=`pub_categories`,config:l,customContent:u}){let{user:d}=t.na(),f=!!l,p=l?.isInternal||l?.isShared;l?.isPrivate&&l?.isAdmin;let m=l?.isAdmin||p,h=f?m||s.startsWith(`role_`):!0,g=(e,t,n,r)=>d?e.startsWith(`user_`)?{...t,uid:d.uid}:n?{uid:d.uid,...r?hn(d):{},...t}:t:t,_=!!u,v=l?.showButton!==!1&&!_,y=l?.buttonText||`+`,b=l?.buttonStyle||`primary`,x=l?.keyName||`key`,S=l?.valueName||`value`,[C,w]=(0,r.useState)([]),[T,E]=(0,r.useState)([]),[D,O]=(0,r.useState)(null),[k,A]=(0,r.useState)(null),[j,M]=(0,r.useState)({name:``}),[N,P]=(0,r.useState)([]),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)(null),[z,B]=(0,r.useState)(null),[V,H]=(0,r.useState)(null),[U,W]=(0,r.useState)(!1),[G,ee]=(0,r.useState)(null),[K,q]=(0,r.useState)(``),[J,Y]=(0,r.useState)(null);(0,r.useEffect)(()=>{let e=s.startsWith(`user_`),n=c.startsWith(`user_`);if(e&&!d)return;try{let e=localStorage.getItem(`fbos_board_tasks_${s}`);e&&w(JSON.parse(e));let t=localStorage.getItem(`fbos_board_cats_${c}`);t&&E(JSON.parse(t))}catch{}let r=(0,o.onSnapshot)(e&&d?(0,o.query)((0,o.collection)(t.Da,s),(0,o.where)(`uid`,`==`,d.uid)):(0,o.collection)(t.Da,s),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,uid:n.uid,creatorName:n.creatorName,creatorAvatar:n.creatorAvatar})});let n=t.sort((e,t)=>(e.order||0)-(t.order||0));w(n),localStorage.setItem(`fbos_board_tasks_${s}`,JSON.stringify(n))}),i=(0,o.onSnapshot)(n&&d?(0,o.query)((0,o.collection)(t.Da,c),(0,o.where)(`uid`,`==`,d.uid)):(0,o.collection)(t.Da,c),e=>{let r=[];if(e.forEach(e=>{r.push({id:e.id,...e.data()})}),r.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()}],r=d?{uid:d.uid}:{},i=n&&d?`_${d.uid}`:``;e.forEach(e=>(0,o.setDoc)((0,o.doc)(t.Da,c,`${e.id}${i}`),{...r,title:e.title,createdAt:e.createdAt}))}else E(r),localStorage.setItem(`fbos_board_cats_${c}`,JSON.stringify(r))});return()=>{r(),i()}},[s,c,d]);let te=(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:``}]))},ne=(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)},re=(e,t)=>{e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`taskId`,t),I(t)},X=(e,t)=>{e.preventDefault(),e.stopPropagation(),t!==F&&R(t)},Z=(e,t)=>{e.preventDefault(),e.stopPropagation(),B(t)},Q=e=>{e.preventDefault(),R(null),B(null)},ie=async(e,n,r)=>{e.preventDefault(),e.stopPropagation(),R(null),B(null);let i=e.dataTransfer.getData(`taskId`);if(!i||i===r){I(null);return}let a=C.find(e=>e.id===i);if(!a)return;let c=C.filter(e=>e.categoryId===n).sort((e,t)=>(e.order||0)-(t.order||0));if(a.categoryId===n?(c=c.filter(e=>e.id!==i),c.push(a)):c.push({...a,categoryId:n}),r){let e=c.findIndex(e=>e.id===r),t=c.findIndex(e=>e.id===i),[n]=c.splice(t,1);c.splice(e,0,n)}c.forEach((e,r)=>{let i={categoryId:n,order:r};d&&s.startsWith(`user_`)&&(i.uid=d.uid),(0,o.setDoc)((0,o.doc)(t.Da,s,e.id),i,{merge:!0})}),I(null)},ae=async e=>{let n=j.id||`item_${Date.now()}`,r=j.name.trim(),i=r||`Untitled Item`,a=N.filter(e=>e.key.trim()!==``||e.value.trim()!==``),c=!0,l=j.id?C.find(e=>e.id===j.id):null;if(l){let e=JSON.stringify(l.fields||[]),t=JSON.stringify(a);l.name===i&&e===t&&(c=!1)}else !r&&a.length===0&&(c=!1);if(!c){O(null),A(null);return}H(j.id||`new`);let u={categoryId:e,name:i,fields:a};d&&!j.id&&Object.assign(u,{uid:d.uid},hn(d)),await(0,o.setDoc)((0,o.doc)(t.Da,s,n),u,{merge:!0}),setTimeout(()=>{O(null),A(null),H(null)},400)},oe=(e,t)=>{Y({type:`item`,id:e,title:t})},se=async()=>{let e=`cat_${Date.now()}`,n={title:``,createdAt:Date.now()};d&&(n.uid=d.uid),await(0,o.setDoc)((0,o.doc)(t.Da,c,e),n),ee(e),q(``),setTimeout(()=>{let e=document.getElementById(`board-container`);e&&e.scrollTo({left:e.scrollWidth,behavior:`smooth`})},150)},ce=async(e,n)=>{E(t=>t.map(t=>t.id===e?{...t,color:n}:t)),await(0,o.setDoc)((0,o.doc)(t.Da,c,e),{color:n},{merge:!0})},le=async e=>{K.trim()?await(0,o.setDoc)((0,o.doc)(t.Da,c,e),{title:K},{merge:!0}):await(0,o.deleteDoc)((0,o.doc)(t.Da,c,e)),ee(null)},ue=(e,t)=>{Y({type:`category`,id:e,title:t})},de=async()=>{if(J){W(!0);try{if(J.type===`item`)await(0,o.deleteDoc)((0,o.doc)(t.Da,s,J.id)),A(null);else{let e=C.filter(e=>e.categoryId===J.id);for(let n of e)await(0,o.deleteDoc)((0,o.doc)(t.Da,s,n.id));await(0,o.deleteDoc)((0,o.doc)(t.Da,c,J.id))}}catch{}W(!1),Y(null)}},fe=[...T].sort((e,t)=>(e.createdAt||0)-(t.createdAt||0));return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen overflow-x-hidden`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4 md:mb-6 flex items-center gap-3`,children:[!f&&a&&(0,i.jsx)(Wt,{to:a}),(0,i.jsxs)(`div`,{className:`min-w-0`,children:[(0,i.jsx)(Ce,{children:e}),n&&(0,i.jsxs)(`div`,{className:`max-sm:hidden sm:flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),n]})]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 min-h-0 pb-16`,children:[f&&(0,i.jsx)(Fe,{}),(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`flex flex-col glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden flex-1 min-h-[400px] shadow-2xl bg-background relative z-10`,children:[(0,i.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,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm:p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0 relative z-20`,children:[(0,i.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,i.jsx)(`h2`,{className:`text-lg sm:text-xl font-extrabold text-foreground tracking-tight truncate`,children:l?.tabTitle||l?.tabName||e}),(0,i.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[C.length,` `,C.length===1?`item`:`items`,` · `,fe.length,` `,fe.length===1?`category`:`categories`]})]}),v&&(0,i.jsx)(t.cr,{variant:b===`secondary`?`secondary`:void 0,onClick:se,className:`px-3 py-2.5 text-[14px] font-bold rounded-xl shadow-lg hover:-translate-y-0.5 transition-all shrink-0`,children:y===`+`?(0,i.jsx)(t.Ur,{className:`w-4 h-4`}):y})]}),(0,i.jsx)(`div`,{className:`flex-1 w-full relative z-40 min-h-0 flex flex-col`,children:u?(0,i.jsx)(`div`,{className:`fbos-content-slot w-full flex-1 overflow-y-auto p-4 md:p-6`,children:(0,i.jsx)(u,{config:l,actions:{tasks:C,categories:T,collection:s,catCollection:c,user:d,saveTask:async(e,n)=>{let r=e||`item_${Date.now()}`,i=g(s,n,!C.some(e=>e.id===r),!0);w(e=>e.find(e=>e.id===r)?e.map(e=>e.id===r?{...e,...i}:e):[...e,{id:r,...i}]),await(0,o.setDoc)((0,o.doc)(t.Da,s,r),i,{merge:!0})},deleteTask:async e=>{w(t=>t.filter(t=>t.id!==e)),await(0,o.deleteDoc)((0,o.doc)(t.Da,s,e))},saveCategory:async(e,n)=>{let r=g(c,n,!T.some(t=>t.id===e),!1);E(t=>t.find(t=>t.id===e)?t.map(t=>t.id===e?{...t,...r}:t):[...t,{id:e,...r}]),await(0,o.setDoc)((0,o.doc)(t.Da,c,e),r,{merge:!0})},deleteCategory:async e=>{E(t=>t.filter(t=>t.id!==e)),await(0,o.deleteDoc)((0,o.doc)(t.Da,c,e))},openInlineEditor:(e,t)=>te(e,t)}})}):(0,i.jsxs)(`div`,{id:`board-container`,className:`w-full flex-1 min-h-0 flex flex-row gap-4 md:gap-6 overflow-x-auto p-4 md:p-6 snap-x snap-mandatory styled-scrollbars items-start`,children:[fe.map((e,n)=>{let r=C.filter(t=>t.categoryId===e.id);r.sort((e,t)=>(e.order||0)-(t.order||0));let a=_n.find(t=>t.text===e.color)||_n.find(e=>e.text===`text-accent`);return a.text,a.bgLight,a.bgHover,(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:n*.1},className:`w-[calc(100vw-80px)] sm:w-[300px] md:w-[320px] shrink-0 flex flex-col max-h-full rounded-3xl p-4 snap-center relative border transition-colors ${_n.find(t=>t.text===e.color)?.bgCard||`bg-foreground/[0.02]`} ${_n.find(t=>t.text===e.color)?.borderCard||`border-[var(--panel-border)]/50`}`,children:[(0,i.jsx)(`div`,{className:`flex items-center justify-between mb-4 px-2 relative z-[200]`,children:(0,i.jsxs)(`h3`,{className:`font-bold text-[14px] flex items-center w-full text-foreground/80 group relative z-[200]`,children:[G===e.id?(0,i.jsxs)(`div`,{className:`relative flex-1 w-full flex items-center pr-8 z-[200]`,children:[(0,i.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),le(e.id)}}),(0,i.jsx)(`input`,{value:K,onChange:e=>q(e.target.value),onBlur:t=>{t.relatedTarget?.closest(`.category-color-picker`)||le(e.id)},onKeyDown:t=>t.key===`Enter`&&le(e.id),className:`bg-transparent border-none outline-none font-bold text-[14px] w-full p-0 ${e.color||`text-foreground/80`}`,placeholder:`Category name`,autoFocus:!0}),(0,i.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,i.jsx)(`button`,{onClick:async t=>{t.preventDefault(),t.stopPropagation(),await ce(e.id,``),ee(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,i.jsx)(t._r,{className:`w-3 h-3`})}),(0,i.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),_n.map(t=>(0,i.jsx)(`button`,{onMouseDown:async n=>{n.preventDefault(),await ce(e.id,t.text)},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50 shrink-0`},t.name))]})]}):(0,i.jsxs)(`div`,{className:`flex items-center gap-2 w-full cursor-pointer hover:text-foreground transition-colors pr-8`,onClick:()=>{ee(e.id),q(e.title)},children:[(0,i.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-full ${_n.find(t=>t.text===e.color)?.bgCircle||`bg-foreground/20`} transition-colors shrink-0`}),(0,i.jsx)(`span`,{className:`truncate flex-1 max-w-[200px] ${e.color||``}`,children:e.title||`Untitled Category`}),(0,i.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})]}),T.length>1&&(0,i.jsx)(`button`,{onClick:()=>ue(e.id,e.title),className:`absolute right-0 opacity-100 md:opacity-0 md:group-hover:opacity-100 text-foreground/30 hover:text-red-500 transition-all shrink-0`,children:(0,i.jsx)(t.Dr,{className:`w-3.5 h-3.5`})})]})}),(0,i.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=>Z(t,e.id),onDragLeave:Q,onDrop:t=>ie(t,e.id),children:[(0,i.jsx)(t.pr,{children:r.map(n=>k===n.id?(0,i.jsxs)(t.fr.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,i.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),ae(e.id)}}),(0,i.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(),ae(e.id))}}),(0,i.jsx)(`div`,{className:`flex flex-col gap-2 mt-1 relative z-10 w-full`,children:N.map((t,n)=>(0,i.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,i.jsx)(`input`,{placeholder:x,value:t.key,onChange:e=>ne(n,e.target.value,t.value),onKeyDown:t=>t.key===`Enter`&&ae(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||x.length)}ch`}}),(0,i.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative top-[1px]`,children:`:`}),(0,i.jsx)(`textarea`,{rows:1,placeholder:S,value:t.value,onChange:e=>ne(n,t.key,e.target.value),onInput:e=>{let t=e.target;t.style.height=`auto`,t.style.height=t.scrollHeight+`px`},onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),ae(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===n.id&&(0,i.jsx)(`div`,{className:`flex items-center justify-end pt-1`,children:(0,i.jsx)(`div`,{className:`w-3 h-3 border-2 border-accent border-t-transparent rounded-full animate-spin`})})]},n.id):(0,i.jsxs)(t.fr.div,{draggable:!0,onDragStart:e=>re(e,n.id),onDragOver:e=>X(e,n.id),onDragLeave:Q,onDrop:t=>ie(t,e.id,n.id),initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},className:`bg-background/80 rounded-xl p-3 shadow-sm hover:shadow-md cursor-grab active:cursor-grabbing hover:border-accent/40 transition-all group flex flex-col gap-2 relative z-10 border ${L===n.id?`border-accent border-t-2 translate-y-1`:`border-[var(--panel-border)]`} ${F===n.id?`opacity-30 scale-95 border-dashed border-2`:``}`,children:[(0,i.jsxs)(`div`,{className:`absolute top-2 right-2 flex items-center gap-1.5 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-opacity bg-background/90 backdrop-blur-md border border-[var(--panel-border)] rounded-lg p-1 z-20 shadow-md`,children:[(0,i.jsx)(`button`,{onClick:t=>{t.stopPropagation(),te(e.id,n)},className:`p-1 hover:bg-foreground/5 rounded-md text-foreground/60 hover:text-accent transition-colors`,children:(0,i.jsx)(t.Kr,{className:`w-3.5 h-3.5`})}),(0,i.jsx)(`button`,{onClick:e=>{e.stopPropagation(),oe(n.id,n.name)},className:`p-1 hover:bg-red-500/10 rounded-md text-foreground/60 hover:text-red-500 transition-colors`,children:(0,i.jsx)(t.Dr,{className:`w-3.5 h-3.5`})})]}),(0,i.jsx)(`p`,{className:`text-[13px] text-foreground/90 font-medium leading-snug break-words pr-12`,children:n.name}),n.fields&&n.fields.length>0&&(0,i.jsx)(`div`,{className:`flex flex-row flex-wrap gap-2 mt-2`,children:n.fields.map((e,t)=>(0,i.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,i.jsxs)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative -top-[1px] shrink-0 break-all`,children:[e.key,`:`]}),(0,i.jsx)(`span`,{className:`text-[12px] text-foreground/90 font-medium break-words leading-tight min-w-0`,children:e.value})]},t))}),(0,i.jsxs)(`div`,{className:`flex items-end justify-between mt-3 pt-3 border-t border-[var(--panel-border)]/50 w-full gap-2`,children:[(()=>{let e=h&&f?gn(n,d):null;return e?(0,i.jsxs)(`div`,{className:`flex items-center gap-1.5 pr-2 border-r border-[var(--panel-border)] border-dashed mr-auto`,children:[e.avatar?(0,i.jsx)(`img`,{src:e.avatar,className:`w-4 h-4 rounded-full shrink-0 object-cover`}):(0,i.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:e.name[0].toUpperCase()}),(0,i.jsx)(`span`,{className:`text-[10px] font-bold text-foreground/60 truncate max-w-[80px]`,children:e.name})]}):(0,i.jsx)(`div`,{className:`flex items-center gap-2 pr-2 border-r border-[var(--panel-border)] border-dashed mr-auto`})})(),(0,i.jsx)(`span`,{className:`text-[10px] text-foreground/40 font-bold text-right pt-0.5 shrink-0 max-w-[50%] truncate flex-1`,children:n.id.startsWith(`item_`)?new Date(parseInt(n.id.split(`_`)[1])).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}):`Recently Added`})]})]},n.id))}),D===e.id?(0,i.jsxs)(t.fr.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,i.jsx)(`div`,{className:`fixed inset-0 z-[-1]`,onClick:t=>{t.stopPropagation(),ae(e.id)}}),(0,i.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(),ae(e.id))},autoFocus:!0}),(0,i.jsx)(`div`,{className:`flex flex-col gap-2 mt-1 relative z-10 w-full`,children:N.map((t,n)=>(0,i.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,i.jsx)(`input`,{placeholder:x,style:{width:`${Math.max(3,t.key.length||x.length)}ch`},value:t.key,onChange:e=>ne(n,e.target.value,t.value),onKeyDown:t=>t.key===`Enter`&&ae(e.id),className:`no-glow bg-transparent outline-none text-[11px] text-foreground/50 font-bold placeholder:text-foreground/30 relative top-[1px]`}),(0,i.jsx)(`span`,{className:`text-[11px] text-foreground/50 font-bold mr-1.5 relative top-[1px]`,children:`:`}),(0,i.jsx)(`textarea`,{rows:1,placeholder:S,value:t.value,onChange:e=>ne(n,t.key,e.target.value),onInput:e=>{let t=e.target;t.style.height=`auto`,t.style.height=t.scrollHeight+`px`},onKeyDown:t=>{t.key===`Enter`&&!t.shiftKey&&(t.preventDefault(),ae(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,i.jsx)(`div`,{className:`flex items-center justify-end pt-1`,children:(0,i.jsx)(`div`,{className:`w-3 h-3 border-2 border-accent border-t-transparent rounded-full animate-spin`})})]}):(0,i.jsxs)(`button`,{onClick:()=>te(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,i.jsx)(t.Ur,{className:`w-4 h-4`}),` Add Item`]})]})]},e.id)}),(0,i.jsx)(`div`,{className:`w-[10px] shrink-0 pointer-events-none`})]})})]})]}),(0,i.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,i.jsx)(Ve,{isOpen:!!J,title:`Confirm Deletion`,message:(0,i.jsxs)(i.Fragment,{children:[`Are you sure you want to delete `,(0,i.jsx)(`strong`,{className:`text-foreground font-extrabold break-words mx-1`,children:J?.title}),` This action is permanent.`]}),onConfirm:de,onCancel:()=>Y(null),isProcessing:U,confirmText:`Yes, Delete`})]})}function yn(e){return Array.isArray?Array.isArray(e):kn(e)===`[object Array]`}function bn(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 xn(e){return e==null?``:bn(e)}function Sn(e){return typeof e==`string`}function Cn(e){return typeof e==`number`}function wn(e){return e===!0||e===!1||En(e)&&kn(e)==`[object Boolean]`}function Tn(e){return typeof e==`object`}function En(e){return Tn(e)&&e!==null}function Dn(e){return e!=null}function On(e){return!e.trim().length}function kn(e){return e==null?e===void 0?`[object Undefined]`:`[object Null]`:Object.prototype.toString.call(e)}var An=`Incorrect 'index' type`,jn=e=>`Invalid value for key ${e}`,Mn=e=>`Pattern length exceeds max of ${e}.`,Nn=e=>`Missing ${e} property in key`,Pn=e=>`Property 'weight' in key '${e}' must be a positive integer`,Fn=Object.prototype.hasOwnProperty,In=class{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(e=>{let n=Ln(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 Ln(e){let t=null,n=null,r=null,i=1,a=null;if(Sn(e)||yn(e))r=e,t=Rn(e),n=zn(e);else{if(!Fn.call(e,`name`))throw Error(Nn(`name`));let o=e.name;if(r=o,Fn.call(e,`weight`)&&(i=e.weight,i<=0))throw Error(Pn(o));t=Rn(o),n=zn(o),a=e.getFn}return{path:t,id:n,weight:i,src:r,getFn:a}}function Rn(e){return yn(e)?e:e.split(`.`)}function zn(e){return yn(e)?e.join(`.`):e}function Bn(e,t){let n=[],r=!1,i=(e,t,a,o)=>{if(Dn(e))if(!t[a])n.push(o===void 0?e:{v:e,i:o});else{let s=e[t[a]];if(!Dn(s))return;if(a===t.length-1&&(Sn(s)||Cn(s)||wn(s)||typeof s==`bigint`))n.push(o===void 0?xn(s):{v:xn(s),i:o});else if(yn(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,Sn(t)?t.split(`.`):t,0),r?n:n[0]}var Vn={includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},Hn={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},Un={location:0,threshold:.6,distance:100},Wn={useExtendedSearch:!1,useTokenSearch:!1,getFn:Bn,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1},$=Object.freeze({...Hn,...Vn,...Un,...Wn}),Gn=/[^ ]+/g;function Kn(e=1,t=3){let n=new Map,r=10**t;return{get(t){let i=t.match(Gn).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 qn=class{constructor({getFn:e=$.getFn,fieldNormWeight:t=$.fieldNormWeight}={}){this.norm=Kn(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,Sn(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();Sn(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(!Dn(e)||On(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(Dn(i)){if(yn(i)){let e=[];for(let t=0,n=i.length;t<n;t+=1){let n=i[t];if(Dn(n)){if(Sn(n)){if(!On(n)){let r={v:n,i:t,n:this.norm.get(n)};e.push(r)}}else if(Dn(n.v)){let t=Sn(n.v)?n.v:xn(n.v);if(!On(t)){let r={v:t,i:n.i,n:this.norm.get(t)};e.push(r)}}}}n.$[r]=e}else if(Sn(i)&&!On(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 Jn(e,t,{getFn:n=$.getFn,fieldNormWeight:r=$.fieldNormWeight}={}){let i=new qn({getFn:n,fieldNormWeight:r});return i.setKeys(e.map(Ln)),i.setSources(t),i.create(),i}function Yn(e,{getFn:t=$.getFn,fieldNormWeight:n=$.fieldNormWeight}={}){let{keys:r,records:i}=e,a=new qn({getFn:t,fieldNormWeight:n});return a.setKeys(r),a.setIndexRecords(i),a}function Xn(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 Zn=32;function Qn(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>Zn)throw Error(Mn(Zn));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=Xn(_,s);e.length?c&&(C.indices=e):C.isMatch=!1}return C}function $n(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 er(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 tr={ł:`l`,Ł:`L`,đ:`d`,Đ:`D`,ø:`o`,Ø:`O`,ħ:`h`,Ħ:`H`,ŧ:`t`,Ŧ:`T`,ı:`i`,ß:`ss`},nr=RegExp(`[`+Object.keys(tr).join(``)+`]`,`g`),rr=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(nr,e=>tr[e]):e=>e,ir=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?rr(e):e,this.pattern=e,this.chunks=[],!this.pattern.length)return;let u=(e,t)=>{this.chunks.push({pattern:e,alphabet:$n(e),startIndex:t})},d=this.pattern.length;if(d>Zn){let e=0,t=d%Zn,n=d-t;for(;e<n;)u(this.pattern.substr(e,Zn),e),e+=Zn;if(t){let e=d-Zn;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?rr(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}=Qn(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=er(u)),p}},ar=class{constructor(e){this.pattern=e}static isMultiMatch(e){return or(e,this.multiRegex)}static isSingleMatch(e){return or(e,this.singleRegex)}search(e){return{isMatch:!1,score:1}}};function or(e,t){let n=e.match(t);return n?n[1]:null}var sr=class extends ar{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]}}},cr=class extends ar{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]}}},lr=class extends ar{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]}}},ur=class extends ar{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]}}},dr=class extends ar{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]}}},fr=class extends ar{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]}}},pr=class extends ar{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 ir(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)}},mr=class extends ar{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}}},hr=[sr,mr,lr,ur,fr,dr,cr,pr],gr=hr.length,_r=`\0`,vr=`|`;function yr(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 br(e,t={}){return e.replace(/\\\|/g,_r).split(vr).map(e=>{let n=yr(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<gr;){let e=hr[o],n=e.isMultiMatch(i);n&&(r.push(new e(n,t)),a=!0)}if(!a)for(o=-1;++o<gr;){let e=hr[o],n=e.isSingleMatch(i);if(n){r.push(new e(n,t));break}}}return r})}var xr=new Set([pr.type,mr.type]),Sr=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?rr(e):e,this.pattern=e,this.query=br(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?rr(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&&(xr.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=er(o)),e}}return{isMatch:!1,score:1}}},Cr=[];function wr(...e){Cr.push(...e)}function Tr(e,t){for(let n=0,r=Cr.length;n<r;n+=1){let r=Cr[n];if(r.condition(e,t))return new r(e,t)}return new ir(e,t)}var Er={AND:`$and`,OR:`$or`},Dr={PATH:`$path`,PATTERN:`$val`},Or=e=>!!(e[Er.AND]||e[Er.OR]),kr=e=>!!e[Dr.PATH],Ar=e=>!yn(e)&&Tn(e)&&!Or(e),jr=e=>({[Er.AND]:Object.keys(e).map(t=>({[t]:e[t]}))});function Mr(e,t,{auto:n=!0}={}){let r=e=>{if(Sn(e)){let r={keyId:null,pattern:e};return n&&(r.searcher=Tr(e,t)),r}let i=Object.keys(e),a=kr(e);if(!a&&i.length>1&&!Or(e))return r(jr(e));if(Ar(e)){let r=a?e[Dr.PATH]:i[0],o=a?e[Dr.PATTERN]:e[r];if(!Sn(o))throw Error(jn(r));let s={keyId:zn(r),pattern:o};return n&&(s.searcher=Tr(o,t)),s}let o={children:[],operator:i[0]};return i.forEach(t=>{let n=e[t];yn(n)&&n.forEach(e=>{o.children.push(r(e))})}),o};return Or(e)||(e=jr(e)),r(e)}function Nr(e,{ignoreFieldNorm:t=$.ignoreFieldNorm}){let n=1;return e.forEach(({key:e,norm:r,score:i})=>{let a=e?e.weight:null;n*=(i===0&&a?2**-52:i)**+((a||1)*(t?1:r))}),n}function Pr(e,{ignoreFieldNorm:t=$.ignoreFieldNorm}){e.forEach(e=>{e.score=Nr(e.matches,{ignoreFieldNorm:t})})}var Fr=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 Ir(e,t){let n=e.matches;t.matches=[],Dn(n)&&n.forEach(e=>{if(!Dn(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 Lr(e,t){t.score=e.score}function Rr(e,t,{includeMatches:n=$.includeMatches,includeScore:r=$.includeScore}={}){let i=[];return n&&i.push(Ir),r&&i.push(Lr),e.map(e=>{let{idx:n}=e,r={item:t[n],refIndex:n};return i.length&&i.forEach(t=>{t(e,r)}),r})}var zr=/\b\w+\b/g;function Br({isCaseSensitive:e=!1,ignoreDiacritics:t=!1}={}){return{tokenize(n){return e||(n=n.toLowerCase()),t&&(n=rr(n)),n.match(zr)||[]}}}function Vr(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 Hr(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 Ur(e,t){for(let[n,r]of e.terms){let i=r.filter(e=>e.docIdx!==t),a=r.length-i.length;a>0&&(e.fieldCount-=a,e.df.set(n,(e.df.get(n)||0)-a),i.length===0?(e.terms.delete(n),e.df.delete(n)):e.terms.set(n,i))}}var Wr=class{constructor(e,t,n){this.options={...$,...t},this.options.useExtendedSearch,this.options.useTokenSearch,this._keyStore=new In(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=Tr(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 qn))throw Error(An);if(this._myIndex=t||Jn(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight}),this.options.useTokenSearch){let e=Br({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});this._invertedIndex=Vr(this._myIndex.records,this._myIndex.keys.length,e)}}add(e){if(Dn(e)&&(this._docs.push(e),this._myIndex.add(e),this._invertedIndex)){let e=this._myIndex.records[this._myIndex.records.length-1],t=Br({isCaseSensitive:this.options.isCaseSensitive,ignoreDiacritics:this.options.ignoreDiacritics});Hr(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)Ur(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&&Ur(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(Sn(e)&&!e.trim()){let e=this._docs.map((e,t)=>({item:e,refIndex:t}));return Cn(n)&&n>-1&&(e=e.slice(0,n)),e}let c=Cn(n)&&n>0&&Sn(e),l;if(c){let t=new Fr(n);Sn(this._docs[0])?this._searchStringList(e,{heap:t,ignoreFieldNorm:s}):this._searchObjectList(e,{heap:t,ignoreFieldNorm:s}),l=t.extractSorted(o)}else l=Sn(e)?Sn(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e),Pr(l,{ignoreFieldNorm:s}),a&&l.sort(o),Cn(n)&&n>-1&&(l=l.slice(0,n));return Rr(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(!Dn(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=Nr(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):a.push(r)}}),a}_searchLogical(e){let t=Mr(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===Er.AND)return[]}return o},r=this._myIndex.records,i=new Map,a=[];return r.forEach(({$:e,i:r})=>{if(Dn(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(!Dn(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=Nr(r.matches,{ignoreFieldNorm:n}),t.shouldInsert(r.score)&&t.insert(r)):o.push(r)}}),o}_findMatches({key:e,value:t,searcher:n}){if(!Dn(t))return[];let r=[];if(yn(t))t.forEach(({v:t,i,n:a})=>{if(!Dn(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}},Gr=class{static condition(e,t){return t.useTokenSearch}constructor(e,t){this.options=t,this.analyzer=Br({isCaseSensitive:t.isCaseSensitive,ignoreDiacritics:t.ignoreDiacritics});let n=this.analyzer.tokenize(e),{df:r,fieldCount:i}=t._invertedIndex;this.termSearchers=[],this.idfWeights=[];for(let e of n){this.termSearchers.push(new ir(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=er(t)),o}};Wr.version=`7.3.0`,Wr.createIndex=Jn,Wr.parseIndex=Yn,Wr.config=$,Wr.match=function(e,t,n){return Tr(e,{...$,...n}).searchIn(t)},Wr.parseQuery=Mr,wr(Sr),wr(Gr),Wr.use=function(...e){e.forEach(e=>wr(e))};var Kr=[{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 qr({title:e=`Table View`,subtitle:n=`/table`,backUrl:a=`/templates`,tableCollection:s=`pub_table_data`,config:c,customContent:l}){let{user:u}=t.na(),d=!!c,f=c?.isInternal||c?.isShared;c?.isPrivate&&c?.isAdmin;let p=c?.isAdmin||f,m=d?p||s.startsWith(`role_`):!0,h=(e,t)=>u?s.startsWith(`user_`)?{...e,uid:u.uid}:t?{uid:u.uid,...e}:e:e,g=!!l,_=c?.showButton!==!1&&!g,v=c?.buttonText||`+`,y=c?.buttonStyle||`secondary`,b=c?.showExportButton!==!1,[x,S]=(0,r.useState)([]),[C,w]=(0,r.useState)(`demo`),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(!1),[k,A]=(0,r.useState)(``),[j,M]=(0,r.useState)(!1),[N,P]=(0,r.useState)(null),[F,I]=(0,r.useState)(null),[L,R]=(0,r.useState)(``),[z,B]=(0,r.useState)(!1),[V,H]=(0,r.useState)(``),[U,W]=(0,r.useState)(null),[G,ee]=(0,r.useState)(null),[K,q]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=s.startsWith(`user_`);if(e&&!u)return;try{let e=localStorage.getItem(`fbos_tables_${s}`);e&&S(JSON.parse(e))}catch{}let n=(0,o.onSnapshot)(e&&u?(0,o.query)((0,o.collection)(t.Da,s),(0,o.where)(`uid`,`==`,u.uid)):(0,o.collection)(t.Da,s),n=>{let r=[];if(n.forEach(e=>{r.push({id:e.id,...e.data()})}),r.length===0){let n={name:`Unnamed Table`,columns:[`Column 1`,`Column 2`,`Column 3`,`Column 4`],...u?{uid:u.uid}:{},rows:[{id:`1`,"Column 1":``,"Column 2":``,"Column 3":``,"Column 4":``},{id:`2`,"Column 1":``,"Column 2":``,"Column 3":``,"Column 4":``}]};(0,o.setDoc)((0,o.doc)(t.Da,s,e&&u?`demo_${u.uid}`:`demo`),n)}else{let e=r.sort((e,t)=>(e.name||``).localeCompare(t.name||``));S(e),localStorage.setItem(`fbos_tables_${s}`,JSON.stringify(e))}});return()=>n()},[s,u]);let J=x.find(e=>e.id===C)||x[0]||{columns:[],rows:[]},Y=async e=>{J.id&&(u&&s.startsWith(`user_`)&&(e.uid=u.uid),await(0,o.setDoc)((0,o.doc)(t.Da,s,J.id),e,{merge:!0}))},te=()=>{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(`
|
|
4
4
|
`),n=new Blob([`${e}\n${t}`],{type:`text/csv`}),r=window.URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`export_${J.name||`table`}.csv`,i.click(),window.URL.revokeObjectURL(r)},ne=(e,t,n)=>{Y({...J,rows:J.rows.map(r=>r.id===e?{...r,[t]:n}:r)})},re=()=>{let e=hn(u),t={id:Date.now().toString(),...u?{_uid:u.uid,_creatorName:e.creatorName,_creatorAvatar:e.creatorAvatar}:{}};J.columns.forEach(e=>t[e]=``),Y({...J,rows:[...J.rows||[],t]})},X=e=>{Y({...J,rows:J.rows.filter(t=>t.id!==e)})},Z=()=>{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))},Q=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})},ie=async e=>{e.trim()&&J.id&&e!==J.name&&await(0,o.setDoc)((0,o.doc)(t.Da,s,J.id),{name:e},{merge:!0})},ae=async()=>{M(!0),E(!1);let e=`tbl_${Date.now()}`;await(0,o.setDoc)((0,o.doc)(t.Da,s,e),{name:`Unnamed Table`,columns:[`Column 1`,`Column 2`,`Column 3`],...u?{uid:u.uid}:{},rows:[]}),setTimeout(()=>{w(e),M(!1)},600)},oe=e=>{let t=V.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})}I(null)},se=e=>gn({uid:e._uid,creatorName:e._creatorName,creatorAvatar:e._creatorAvatar},u),ce=J.rows||[];return L.trim()!==``&&(ce=new Wr(ce.map(e=>({...e,_creatorMatch:se(e)?.name||``})),{keys:(J.columns||[]).concat([`_creatorMatch`]),threshold:.4,ignoreLocation:!0}).search(L).map(e=>{let{_creatorMatch:t,...n}=e.item;return n})),(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4 md:mb-6 flex items-center gap-3`,children:[!d&&a&&(0,i.jsx)(Wt,{to:a}),(0,i.jsxs)(`div`,{className:`min-w-0`,children:[(0,i.jsx)(Ce,{children:e}),n&&(0,i.jsxs)(`div`,{className:`max-sm:hidden sm:flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),n]})]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 min-h-0 pb-16`,children:[d&&(0,i.jsx)(Fe,{}),(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`glass-panel border border-[var(--panel-border)] rounded-3xl overflow-hidden shadow-2xl relative z-10 flex flex-col flex-1 min-h-[400px]`,children:[(0,i.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,i.jsxs)(`div`,{className:`p-4 md:px-6 border-b border-[var(--panel-border)]/50 flex items-center justify-between bg-foreground/[0.01] gap-3 sm:gap-4`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col min-w-0 relative`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2 relative`,children:[(0,i.jsxs)(`div`,{className:`relative flex items-center`,children:[D?(0,i.jsx)(`div`,{contentEditable:!0,suppressContentEditableWarning:!0,onBlur:e=>{O(!1),ie(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,i.jsx)(`h3`,{className:`font-bold text-[16px] text-foreground/90 cursor-pointer hover:text-accent transition-colors truncate max-w-[38vw] sm:max-w-[200px]`,onClick:()=>O(!0),title:`Click to rename table`,children:J.name||`Unnamed Table`}),(0,i.jsx)(t.pr,{children:T&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>E(!1)}),(0,i.jsxs)(t.fr.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,i.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,i.jsx)(`div`,{className:`max-h-[250px] overflow-y-auto styled-scrollbars z-50 relative`,children:x.map(e=>(0,i.jsx)(`button`,{onClick:()=>{w(e.id),E(!1)},className:`w-full px-4 py-2 text-[13px] font-bold text-left hover:bg-foreground/[0.03] transition-colors truncate ${C===e.id?`text-accent bg-accent/5`:`text-foreground/70`}`,children:e.name||`Unnamed Table`},e.id))}),(0,i.jsx)(`div`,{className:`w-full h-[1px] bg-[var(--panel-border)]/50 my-1`}),(0,i.jsxs)(`button`,{onClick:ae,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,i.jsx)(t.Ur,{className:`w-4 h-4`}),` Create New Table`]})]})]})})]}),(0,i.jsx)(`button`,{onClick:()=>E(!T),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,i.jsx)(t.Ri,{className:`w-4 h-4 transition-transform ${T?`rotate-180 text-accent`:``}`})})]}),(0,i.jsxs)(`span`,{className:`opacity-40 text-[11px] font-bold mt-1 uppercase tracking-wider`,children:[(J.rows||[]).length,` Records`]})]}),(0,i.jsx)(`div`,{className:`relative shrink-0 ${z?`flex-1 min-w-[130px] max-w-[300px]`:``}`,children:z?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.Lr,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-foreground/40`}),(0,i.jsx)(`input`,{autoFocus:!0,type:`text`,"aria-label":`Search records`,placeholder:`Search records...`,value:L,onChange:e=>R(e.target.value),onBlur:()=>{L.trim()||B(!1)},onKeyDown:e=>{e.key===`Escape`&&(R(``),B(!1))},className:`w-full bg-background border border-[var(--panel-border)] rounded-xl py-2.5 px-9 text-[13px] font-medium text-foreground focus:outline-none focus:border-accent transition-colors shadow-inner`})]}):(0,i.jsx)(`button`,{type:`button`,onClick:()=>B(!0),"aria-label":`Search records`,title:`Search records`,className:`w-10 h-10 flex items-center justify-center rounded-xl border border-[var(--panel-border)] text-foreground/50 hover:text-accent hover:bg-foreground/5 transition-colors`,children:(0,i.jsx)(t.Lr,{className:`w-4 h-4`})})}),(0,i.jsxs)(`div`,{className:`flex gap-2 shrink-0`,children:[b&&(0,i.jsx)(t.cr,{variant:`secondary`,onClick:te,className:`px-3 py-2.5 font-bold rounded-xl shadow-sm border border-[var(--panel-border)] flex items-center gap-2`,children:(0,i.jsx)(t.Si,{className:`w-4 h-4`})}),_&&(0,i.jsx)(t.cr,{variant:y===`primary`?void 0:`secondary`,onClick:re,className:`px-3 py-2.5 font-bold rounded-xl border border-[var(--panel-border)] shadow-sm flex items-center gap-2 whitespace-nowrap`,children:v===`+`?(0,i.jsx)(t.Ur,{className:`w-4 h-4`}):v})]})]}),(0,i.jsx)(`div`,{id:`table-scroll-container`,className:`overflow-auto w-full flex-1 min-h-[300px] relative styled-scrollbars`,children:l?(0,i.jsx)(`div`,{className:`fbos-content-slot p-4 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:(0,i.jsx)(l,{config:c,actions:{tables:x,activeTable:J,collection:s,user:u,saveTable:async(e,n)=>{let r=h(n,!x.some(t=>t.id===e));S(t=>t.find(t=>t.id===e)?t.map(t=>t.id===e?{...t,...r}:t):[...t,{id:e,...r}]),await(0,o.setDoc)((0,o.doc)(t.Da,s,e),r,{merge:!0})},deleteTable:async e=>{S(t=>t.filter(t=>t.id!==e)),await(0,o.deleteDoc)((0,o.doc)(t.Da,s,e))},updateCell:(e,t,n)=>ne(e,t,n),addRow:()=>re(),addColumn:()=>Z()}})}):(0,i.jsx)(t.pr,{mode:`wait`,children:j?(0,i.jsxs)(t.fr.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,i.jsx)(`div`,{className:`w-8 h-8 rounded-full border-2 border-accent border-r-transparent animate-spin mb-4`}),(0,i.jsx)(`p`,{className:`text-[11px] font-bold text-foreground/50 uppercase tracking-widest`,children:`Generating Table`})]},`loader`):(0,i.jsxs)(t.fr.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,i.jsx)(`thead`,{children:(0,i.jsxs)(`tr`,{className:`border-b border-[var(--panel-border)] transition-colors ${J.headerColor?Kr.find(e=>e.text===J.headerColor)?.bgAlt:`bg-foreground/[0.02]`}`,children:[(0,i.jsx)(`th`,{className:`py-4 px-6 text-[12px] font-bold uppercase tracking-wider whitespace-nowrap text-foreground/50 w-32 border-r border-[var(--panel-border)]/20 ${m?``:`hidden`}`,children:`Creator`}),(J.columns||[]).map((e,n)=>{let r=(J.colColors||{})[e],a=(J.colorTimestamps||{})[`col_${e}`]||0;J.headerColor;let o=(J.colorTimestamps||{}).header||0,s=`bg-transparent`,c=`text-foreground/50`;if(r&&r!==`none`&&a>=o){let e=Kr.find(e=>e.text===r);e&&(s=e.bgCard,c=e.text)}return(0,i.jsx)(`th`,{className:`py-3 px-6 text-[12px] font-bold uppercase tracking-wider relative group h-[53px] min-w-[120px] ${c} ${s} border-r border-[var(--panel-border)]/20 last:border-r-0 select-none align-middle`,children:(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-2 w-full h-full`,children:[F===e?(0,i.jsx)(`div`,{className:`flex-1 min-w-[50px]`,children:(0,i.jsx)(`span`,{contentEditable:!0,suppressContentEditableWarning:!0,onBlur:t=>{I(null),H(t.currentTarget.textContent||``),(t.currentTarget.textContent||``).trim()!==``&&oe(e)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},className:`bg-transparent outline-none border-b border-accent/40 font-bold text-[12px] uppercase tracking-wider p-0 m-0 ${c} block w-full whitespace-nowrap overflow-hidden cursor-text`,ref:e=>{e&&requestAnimationFrame(()=>{e.focus()})},children:V})}):(0,i.jsx)(`div`,{className:`flex items-center gap-2 flex-1 overflow-hidden`,onClick:()=>{I(e),H(e)},children:(0,i.jsx)(`span`,{className:`truncate cursor-text`,children:e})}),(0,i.jsxs)(`div`,{className:`relative shrink-0 flex items-center h-full gap-0.5`,children:[(0,i.jsx)(`button`,{onClick:()=>ee(G===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,i.jsx)(t.Jr,{className:`w-4 h-4`})}),(J.columns||[]).length>1&&(0,i.jsx)(`button`,{onClick:t=>{t.stopPropagation(),Q(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,i.jsx)(t.Dr,{className:`w-3.5 h-3.5`})}),G===e&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>ee(null)}),(0,i.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,i.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}),ee(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,i.jsx)(t._r,{className:`w-3 h-3`})}),(0,i.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Kr.map(t=>(0,i.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}),ee(null)},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50 shrink-0`},t.name))]})]})]})]})},`col_${n}_${e}`)}),(0,i.jsx)(`th`,{className:`py-4 px-4 w-14 border-l border-[var(--panel-border)]/30 relative`,children:(0,i.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 relative z-20`,children:[(0,i.jsx)(`button`,{onClick:()=>q(!K),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${J.headerColor?Kr.find(e=>e.text===J.headerColor)?.text:`text-foreground/30`}`,children:(0,i.jsx)(t.Jr,{className:`w-4 h-4`})}),K&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>q(!1)}),(0,i.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,i.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,i.jsx)(t._r,{className:`w-3 h-3`})}),(0,i.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Kr.map(e=>(0,i.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,i.jsx)(`button`,{onClick:Z,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,i.jsx)(t.Ur,{className:`w-4 h-4`})})]})})]})}),(0,i.jsxs)(`tbody`,{children:[ce.map((e,n)=>{let r=n%2==1,a=(J.rowColors||{})[e.id],o=a?r?Kr.find(e=>e.text===a)?.bgAlt:Kr.find(e=>e.text===a)?.bgCard:r?`bg-foreground/[0.02]`:`bg-transparent`;return(0,i.jsxs)(`tr`,{className:`border-b border-[var(--panel-border)]/30 hover:bg-foreground/[0.04] transition-colors group`,children:[(0,i.jsx)(`td`,{className:`py-4 px-6 whitespace-nowrap h-[53px] border-r border-[var(--panel-border)]/20 ${o} ${m?``:`hidden`}`,children:(0,i.jsx)(`div`,{className:`flex items-center gap-2`,children:d?(()=>{let t=se(e);return t?(0,i.jsxs)(i.Fragment,{children:[t.avatar?(0,i.jsx)(`img`,{src:t.avatar,className:`w-5 h-5 rounded-full shrink-0 object-cover`}):(0,i.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:t.name[0].toUpperCase()}),(0,i.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/80 tracking-tight shrink-0`,children:t.name})]}):(0,i.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/30`,children:`—`})})():(0,i.jsxs)(i.Fragment,{children:[(0,i.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,i.jsx)(`span`,{className:`text-[11px] font-bold text-foreground/80 tracking-tight shrink-0`,children:`Guest`})]})})}),(J.columns||[]).map(t=>{let a=N?.id===e.id&&N?.field===t,o=(J.colColors||{})[t],s=(J.colorTimestamps||{})[`col_${t}`]||0,c=(J.rowColors||{})[e.id],l=(J.colorTimestamps||{})[`row_${e.id}`]||0,u=``;u=l>s?c===`none`?``:c:s>l?o===`none`?``:o:c===`none`?``:c||o||``,u===`none`&&(u=``);let d=u?Kr.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,i.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:()=>!a&&P({id:e.id,field:t}),children:[a?(0,i.jsx)(`textarea`,{autoFocus:!0,value:e[t]||``,onChange:n=>ne(e.id,t,n.target.value),onBlur:()=>P(null),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&P(null)},className:`absolute inset-0 bg-transparent !border-0 !outline-none focus:!outline-none focus:!ring-0 !ring-0 !shadow-none focus:!shadow-none p-4 px-6 text-[14px] font-medium w-full h-full caret-accent ${p} z-20 resize-none styled-scrollbars`}):null,(0,i.jsx)(`span`,{className:`block w-full min-h-[20px] break-words transition-all ${a?`opacity-0`:`opacity-100`} ${p} ${t===`Status`&&e[t]===`Active`&&!u?`text-green-500`:``}`,children:e[t]||(0,i.jsx)(`span`,{className:`opacity-30 italic font-normal`,children:`empty`})})]},`cell_${e.id||n}_${t}`)}),(0,i.jsx)(`td`,{className:`py-4 px-4 whitespace-nowrap text-right h-[53px] ${o} relative z-10`,children:(0,i.jsxs)(`div`,{className:`flex items-center justify-end gap-1 opacity-100 md:opacity-20 md:group-hover:opacity-100 transition-opacity relative`,children:[(0,i.jsx)(`button`,{onClick:()=>W(U===e.id?null:e.id),className:`p-1.5 rounded-lg transition-colors hover:bg-foreground/10 ${a?Kr.find(e=>e.text===a)?.text:`text-foreground/40`}`,children:(0,i.jsx)(t.Jr,{className:`w-4 h-4`})}),U===e.id&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`div`,{className:`fixed inset-0 z-30`,onClick:()=>W(null)}),(0,i.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,i.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}),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 Row Color`,children:(0,i.jsx)(t._r,{className:`w-3 h-3`})}),(0,i.jsx)(`div`,{className:`h-4 w-px bg-[var(--panel-border)]/50 mx-0.5`}),Kr.map(t=>(0,i.jsx)(`button`,{onClick:()=>{let n={...J.colorTimestamps||{},[`row_${e.id}`]:Date.now()};Y({...J,rowColors:{...J.rowColors||{},[e.id]:t.text},colorTimestamps:n}),W(null)},className:`w-4 h-4 rounded-full ${t.bgCircle} hover:scale-125 transition-transform border border-[var(--panel-border)]/50`},t.name))]})]}),(0,i.jsx)(`button`,{onClick:()=>X(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,i.jsx)(t.Dr,{className:`w-4 h-4`})})]})})]},e.id||`row_${n}`)}),ce.length===0&&(0,i.jsx)(`tr`,{children:(0,i.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,i.jsx)(`tr`,{children:(0,i.jsx)(`td`,{colSpan:(J.columns||[]).length+2,className:`py-2 px-4 border-none bg-foreground/[0.01]`,children:(0,i.jsx)(`div`,{className:`flex items-center gap-4`,children:(0,i.jsx)(`button`,{onClick:re,className:`p-1.5 rounded-lg text-foreground/40 hover:text-accent hover:bg-accent/10 transition-colors flex items-center justify-center ml-2 border border-transparent hover:border-accent/20`,children:(0,i.jsx)(t.Ur,{className:`w-4 h-4`})})})})})]})]},`table`)})})]})]})]})}var Jr=[{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`}],Yr={dateStr:``,title:``,description:``,time:`12:00`,duration:`60`,color:``,guestEmail:``,customFields:{}};function Xr({title:e=`Calendar View`,subtitle:n=`/calendar`,backUrl:s=`/templates`,eventsCollection:l=`pub_events`,defaultTimeFormat:u=`12h`,config:d,customContent:f}){let p=!!(d?.isPrivate||d?.isAdmin||d?.isInternal||d?.isShared);d?.isAdmin,d?.isInternal||d?.isShared,d?.isPrivate;let m=d?.showButton!==!1,h=d?.buttonText||`+`,g=d?.buttonStyle||`primary`,_=d?.showViewsButton!==!1,v=d?.viewsButtonStyle||`secondary`,y=d?.defaultView||`calendar`,b=d?.customFields||[],x=l.startsWith(`user_`)?`user`:l.startsWith(`mem_`)||l.startsWith(`role_`)?`internal`:l.startsWith(`admin_`)?`admin_only`:`public`,[S,C]=(0,r.useState)(()=>{try{let e=localStorage.getItem(`cal_view_${l}`);if(e===`list`||e===`month`)return e}catch{}return y===`board`?`list`:`month`}),[w,T]=(0,r.useState)([]),[E,D]=(0,r.useState)(!1),[O,k]=(0,r.useState)(null),[A,j]=(0,r.useState)(!1),[M,N]=(0,r.useState)(!1),[P,F]=(0,r.useState)(null),[I,L]=(0,r.useState)(Yr),[R,z]=(0,r.useState)(new Date),[B,V]=(0,r.useState)(null),[H,U]=(0,r.useState)(null),[W,G]=(0,r.useState)(!1),ee=`cal_24h_${l}`,[K,q]=(0,r.useState)(()=>{try{let e=localStorage.getItem(ee);if(e!==null)return e===`true`}catch{}return u===`24h`}),J=()=>{let e=!K;q(e);try{localStorage.setItem(ee,String(e))}catch{}};(0,r.useEffect)(()=>{try{localStorage.setItem(`cal_view_${l}`,S)}catch{}},[S,l,x]);let Y=()=>{let e=S===`month`?`list`:`month`;C(e);try{localStorage.setItem(`cal_view_${l}`,e)}catch{}},te=()=>{try{return sessionStorage.getItem(`cal_guest_email`)||``}catch{return``}},ne=e=>{try{sessionStorage.setItem(`cal_guest_email`,e)}catch{}};(0,r.useEffect)(()=>(0,a.onAuthStateChanged)(t.Ea,async e=>{if(V(e),e&&x===`admin_only`)try{let n=await(0,o.getDoc)((0,o.doc)(t.Da,`user_profiles`,e.uid));n.exists()&&U(n.data())}catch{}G(!0)}),[x]),(0,r.useEffect)(()=>{if(!W)return;if(x!==`public`&&!B){T([]);return}try{let e=localStorage.getItem(`fbos_cal_${l}`);e&&T(JSON.parse(e))}catch{}let e=(0,o.onSnapshot)(x===`user`&&B?(0,o.query)((0,o.collection)(t.Da,l),(0,o.where)(`uid`,`==`,B.uid)):(0,o.collection)(t.Da,l),e=>{let t=[];e.forEach(e=>t.push({id:e.id,...e.data()})),T(t),localStorage.setItem(`fbos_cal_${l}`,JSON.stringify(t))},e=>console.error(`Calendar events:`,e));return()=>e()},[l,x,B?.uid,W]);let re=e=>!!B&&B.uid===e.uid,X=e=>x===`public`?!1:x===`user`?!!B:re(e),Z=(e,t)=>!B||x===`public`?e:x===`user`?{...e,uid:B.uid}:t?{uid:B.uid,creatorEmail:B.email||``,creatorName:B.displayName||``,creatorAvatar:B.photoURL||``,...e}:e,Q=e=>{if(!e)return``;if(K)return e;let[t,n]=e.split(`:`),r=parseInt(t,10),i=r>=12?`PM`:`AM`;return r=r%12||12,`${r}:${n} ${i}`},ie=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`},ae=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}},oe=(e,t,n)=>{let r=e%12;return n===`PM`&&(r+=12),`${r.toString().padStart(2,`0`)}:${t.toString().padStart(2,`0`)}`},se=e=>{let t=e.getTimezoneOffset()*6e4;return new Date(e.getTime()-t).toISOString().split(`T`)[0]},ce=()=>se(new Date),le=new Date(R.getFullYear(),R.getMonth(),1),ue=new Date(R.getFullYear(),R.getMonth()+1,0),de=le.getDay(),fe=ue.getDate(),pe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],me=Array.from({length:42},(e,t)=>{let n=t-de+1,r=new Date(R.getFullYear(),R.getMonth(),n);return{day:r.getDate(),dateStr:se(r),isCurrentMonth:n>0&&n<=fe}}),he=()=>z(S===`month`?new Date(R.getFullYear(),R.getMonth()-1,1):new Date(R.getFullYear(),R.getMonth(),R.getDate()-1)),ge=()=>z(S===`month`?new Date(R.getFullYear(),R.getMonth()+1,1):new Date(R.getFullYear(),R.getMonth(),R.getDate()+1)),_e=e=>{if(x!==`public`&&!B)return;let t=new Date;t.setDate(t.getDate()+1);let n=new Date().getHours().toString().padStart(2,`0`);L({...Yr,dateStr:e||se(t),time:`${n}:00`,guestEmail:x===`public`?te():``,customFields:{}}),D(!0)},ve=e=>{let t=e.time;if(t){let[e,n]=t.split(`:`);e&&n&&(t=`${e.padStart(2,`0`)}:${n}`)}L({id:e.id,uid:e.uid,dateStr:e.dateStr,title:e.title,description:e.description||``,time:t||`12:00`,duration:e.duration||`60`,color:e.color||``,guestEmail:e.creatorEmail||``,customFields:e.customFields||{}}),D(!0)},ye=async e=>{if(e.preventDefault(),I.title.trim()){j(!0);try{let e={dateStr:I.dateStr,title:I.title.trim(),description:I.description.trim(),time:I.time,duration:I.duration||`60`};if(I.color&&(e.color=I.color),b.length>0&&(e.customFields=I.customFields),!I.id)if(x===`public`){let t=I.guestEmail.trim();e.creatorEmail=t,ne(t)}else x===`user`||x===`internal`?(e.uid=B?.uid,e.creatorEmail=B?.email||``,e.creatorName=B?.displayName||``,e.creatorAvatar=B?.photoURL||``):x===`admin_only`&&(e.uid=B?.uid,e.creatorEmail=H?.email||B?.email||``,e.creatorName=H?.displayName||H?.name||``,e.creatorAvatar=H?.avatar||H?.avatarUrl||B?.photoURL||``);I.id?(await(0,o.setDoc)((0,o.doc)(t.Da,l,I.id),e,{merge:!0}),O?.id===I.id&&k({...O,...e})):await(0,o.setDoc)((0,o.doc)(t.Da,l,`ev_${Date.now()}`),e,{merge:!0}),D(!1)}catch(e){console.error(e)}j(!1)}},be=async()=>{if(P){N(!0);try{await(0,o.deleteDoc)((0,o.doc)(t.Da,l,P.id)),O?.id===P.id&&k(null),F(null),D(!1)}catch{}N(!1)}},xe=e=>{if(x===`user`||!e.creatorEmail&&!e.creatorName)return null;let t=(e.creatorName||e.creatorEmail||`?`).charAt(0).toUpperCase(),n=Jr.find(t=>t.text===e.color);return(0,i.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,i.jsx)(`img`,{src:e.creatorAvatar,alt:``,className:`w-8 h-8 rounded-full object-cover shrink-0`}):(0,i.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,i.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[e.creatorName&&(0,i.jsx)(`span`,{className:`text-[13px] font-bold text-foreground/90 truncate`,children:e.creatorName}),e.creatorEmail&&(0,i.jsx)(`span`,{className:`text-[12px] text-foreground/50 truncate`,children:e.creatorEmail})]})]})},Se=e=>{if(x===`user`||x===`public`||!e.creatorName&&!e.creatorEmail)return null;let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||``,n=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,i.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[e.creatorAvatar?(0,i.jsx)(`img`,{src:e.creatorAvatar,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,i.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,i.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,i.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),e.creatorEmail&&(0,i.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,e.creatorEmail]})]})]})};if(W&&x!==`public`&&!B)return(0,i.jsx)(`main`,{className:`flex-1 w-full flex items-center justify-center min-h-screen p-8`,children:(0,i.jsxs)(`div`,{className:`text-center glass-panel border border-[var(--panel-border)] rounded-3xl p-12 max-w-sm w-full`,children:[(0,i.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,i.jsx)(t.Zr,{className:`w-7 h-7 text-accent`})}),(0,i.jsx)(`h2`,{className:`text-2xl font-extrabold mb-2`,children:`Sign in required`}),(0,i.jsx)(`p`,{className:`text-foreground/50 text-[14px] mb-6`,children:`You need to be signed in to access this calendar.`}),(0,i.jsx)(c.Link,{to:`/login`,className:`inline-flex items-center justify-center gap-2 px-6 py-2.5 rounded-xl btn-primary font-bold text-[14px] w-full`,children:`Sign In`})]})});if(!W&&x!==`public`)return(0,i.jsx)(`main`,{className:`flex-1 w-full flex items-center justify-center min-h-screen`,children:(0,i.jsx)(t.ti,{className:`w-8 h-8 animate-spin text-accent`})});let we=!!f,Te=(x===`public`||!!B)&&m&&!we,Ee=()=>(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm:p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,i.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,i.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:d?.tabTitle||d?.tabName||e}),(0,i.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:[w.length,` `,w.length===1?`event`:`events`,` · `,S===`month`?`Month`:`Board`,` View`]})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,i.jsx)(t.fr.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:J,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:K?`24h`:`12h`}),_&&!we&&(0,i.jsx)(t.fr.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:Y,title:S===`month`?`Switch to Board`:`Switch to Calendar`,className:`w-10 h-10 flex items-center justify-center rounded-xl transition-all duration-300 cursor-pointer ${v===`primary`?`btn-primary`:`btn-secondary`}`,children:S===`month`?(0,i.jsx)(t.oi,{className:`w-4 h-4`}):(0,i.jsx)(t.Vi,{className:`w-4 h-4`})}),Te&&(0,i.jsx)(t.fr.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>_e(),title:`Add event`,"aria-label":`Add event`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${h===`+`?`w-10`:`px-5`} ${g===`primary`?`btn-primary`:`btn-secondary`}`,children:h===`+`?(0,i.jsx)(t.Ur,{className:`w-4 h-4`}):(0,i.jsx)(`span`,{className:`text-[13px] font-bold`,children:h})})]})]}),De=()=>(0,i.jsxs)(`div`,{className:`p-4 md:p-6 border-b border-[var(--panel-border)]/50 flex flex-wrap items-center justify-between gap-x-3 gap-y-2 bg-foreground/[0.01]`,children:[(0,i.jsx)(`h3`,{className:`text-lg md:text-xl font-extrabold tracking-tight ml-2 min-w-0`,children:S===`month`?R.toLocaleString(`default`,{month:`long`,year:`numeric`}):R.toLocaleString(`default`,{month:`long`,day:`numeric`,year:`numeric`})}),(0,i.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,i.jsx)(`button`,{onClick:()=>z(new Date),className:`px-3 md:px-4 py-2 text-[13px] font-bold border border-[var(--panel-border)] rounded-xl mr-1 md:mr-2 hover:bg-foreground/5 transition-colors`,children:`Today`}),(0,i.jsx)(`button`,{onClick:he,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,i.jsx)(t.Li,{className:`w-5 h-5`})}),(0,i.jsx)(`button`,{onClick:ge,className:`p-2 rounded-xl text-foreground/50 hover:text-foreground hover:bg-foreground/5 transition-colors border border-transparent hover:border-[var(--panel-border)]`,children:(0,i.jsx)(t.Ii,{className:`w-5 h-5`})})]})]}),Oe=()=>(0,i.jsxs)(i.Fragment,{children:[De(),f?(0,i.jsx)(`div`,{className:`fbos-content-slot p-4 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:(0,i.jsx)(f,{config:d,actions:{events:w,loading:!W,collection:l,currentUser:B,user:B,saveEvent:async e=>{let n=e.id||`ev_${Date.now()}`,r=Z(e,!w.some(e=>e.id===n));T(e=>e.find(e=>e.id===n)?e.map(e=>e.id===n?{...e,...r}:e):[...e,{id:n,...r}]),await(0,o.setDoc)((0,o.doc)(t.Da,l,n),r,{merge:!0})},deleteEvent:async e=>{T(t=>t.filter(t=>t.id!==e)),await(0,o.deleteDoc)((0,o.doc)(t.Da,l,e))},openAddModal:e=>_e(e),openEditModal:e=>ve(e),setViewingEvent:e=>k(e),currentDate:R,setCurrentDate:z,goToPrev:he,goToNext:ge,goToToday:()=>z(new Date)}})}):S===`month`?(0,i.jsx)(`div`,{className:`overflow-x-auto w-full flex-1`,children:(0,i.jsxs)(`div`,{className:`min-w-[800px] h-full flex flex-col`,children:[(0,i.jsx)(`div`,{className:`grid grid-cols-7 border-b border-[var(--panel-border)]/50 bg-foreground/[0.02]`,children:pe.map(e=>(0,i.jsx)(`div`,{className:`py-3 text-center text-[12px] font-bold uppercase tracking-wider text-foreground/40`,children:e},e))}),(0,i.jsx)(`div`,{className:`grid grid-cols-7 auto-rows-auto bg-[var(--panel-border)] gap-[1px] relative flex-1`,children:me.map((e,n)=>{let r=e.dateStr===ce(),a=w.filter(t=>t.dateStr===e.dateStr);return(0,i.jsxs)(`div`,{onClick:()=>e.isCurrentMonth&&Te&&_e(e.dateStr),className:`min-h-[140px] p-2 bg-[var(--panel-bg)] flex flex-col relative group
|
|
@@ -669,10 +669,10 @@ service firebase.storage {
|
|
|
669
669
|
}
|
|
670
670
|
}
|
|
671
671
|
}
|
|
672
|
-
`,ku=[{key:`VITE_FIREBASE_API_KEY`,label:`API Key`,shownAs:`apiKey`},{key:`VITE_FIREBASE_AUTH_DOMAIN`,label:`Auth Domain`,shownAs:`authDomain`},{key:`VITE_FIREBASE_PROJECT_ID`,label:`Project ID`,shownAs:`projectId`},{key:`VITE_FIREBASE_STORAGE_BUCKET`,label:`Storage Bucket`,shownAs:`storageBucket`},{key:`VITE_FIREBASE_MESSAGING_SENDER_ID`,label:`Messaging Sender ID`,shownAs:`messagingSenderId`},{key:`VITE_FIREBASE_APP_ID`,label:`App ID`,shownAs:`appId`}];function Au(e){let t;try{if(t={BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_ADMIN_EMAILS:void 0,VITE_FIREBASE_API_KEY:void 0,VITE_FIREBASE_APP_ID:void 0,VITE_FIREBASE_AUTH_DOMAIN:void 0,VITE_FIREBASE_MESSAGING_SENDER_ID:void 0,VITE_FIREBASE_PROJECT_ID:void 0,VITE_FIREBASE_STORAGE_BUCKET:void 0}?.[e],t&&typeof t==`string`&&t.trim()!==``)return t}catch{}try{if(t=(typeof window<`u`?window:globalThis)?.process?.env?.[e],t&&typeof t==`string`&&t.trim()!==``)return t}catch{}try{switch(e){case`VITE_FIREBASE_API_KEY`:t=void 0;break;case`VITE_FIREBASE_AUTH_DOMAIN`:t=void 0;break;case`VITE_FIREBASE_PROJECT_ID`:t=void 0;break;case`VITE_FIREBASE_STORAGE_BUCKET`:t=void 0;break;case`VITE_FIREBASE_MESSAGING_SENDER_ID`:t=void 0;break;case`VITE_FIREBASE_APP_ID`:t=void 0;break}if(t&&typeof t==`string`&&t.trim()!==``)return t}catch{}return``}function ju(e,t){let n=Au(e);if(n)return n;if(t?.firebaseConfig){let n={VITE_FIREBASE_API_KEY:`apiKey`,VITE_FIREBASE_AUTH_DOMAIN:`authDomain`,VITE_FIREBASE_PROJECT_ID:`projectId`,VITE_FIREBASE_STORAGE_BUCKET:`storageBucket`,VITE_FIREBASE_MESSAGING_SENDER_ID:`messagingSenderId`,VITE_FIREBASE_APP_ID:`appId`}[e];if(n&&t.firebaseConfig[n])return t.firebaseConfig[n]}return``}function Mu(e){let t=[],n=[],r=t=>ju(t,e);for(let{key:e,label:i}of ku){let a=r(e);a?a.trim()===``&&n.push(i):t.push(i)}let i=[...t,...n];return{allSet:i.length===0,missing:i,empty:n}}function Nu(){return Mu().allSet}var Pu=Ou;function Fu(e){let t=e.map(e=>e.trim().toLowerCase()).filter(Boolean).filter((e,t,n)=>n.indexOf(e)===t),n=t.length?t.map(e=>`'${e.replace(/'/g,``)}'`).join(`, `):`'your@email.com'`;return Du.replace(/(function adminEmails\(\) \{\s*return )\[[^\]]*\];/,`$1[${n}];`)}function Iu(e){return e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean)}var Lu=/^[^@\s]+@[^@\s]+\.[^@\s]+$/;function Ru({code:e,label:n,compact:a}){let[o,s]=r.default.useState(!1);return(0,i.jsxs)(t.fr.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>{navigator.clipboard?.writeText(e),s(!0),setTimeout(()=>s(!1),2e3)},className:`inline-flex items-center font-bold transition-all shrink-0 cursor-pointer ${a?`gap-1.5 h-9 px-3 rounded-xl text-[12px] self-start sm:self-auto`:`gap-2 px-4 py-2 mt-2 rounded-xl text-[13px] tracking-wide`} ${o?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary${a?``:` shadow-sm`}`}`,children:[o?(0,i.jsx)(t.zi,{className:a?`w-3.5 h-3.5`:`w-4 h-4`}):(0,i.jsx)(t.Ti,{className:a?`w-3.5 h-3.5`:`w-4 h-4`}),o?a?`Copied`:`Copied to Clipboard!`:n]})}function zu(e){let t=``;try{t=new URL(e).hostname}catch{t=``}let n=t===`localhost`||t===`127.0.0.1`||t.endsWith(`.local`);return{host:t,local:n}}function Bu(){let{host:e,local:t}=zu(typeof window>`u`?``:window.location.href);return e?(0,i.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl bg-background flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-3 px-4 py-3 mt-3`,children:[(0,i.jsxs)(`div`,{className:`min-w-0`,children:[(0,i.jsx)(`div`,{className:`text-[13.5px] font-bold text-foreground break-all sm:break-normal sm:truncate`,children:e}),(0,i.jsx)(`div`,{className:`text-[12.5px] text-foreground/50 font-medium`,children:t?`this machine — Firebase trusts it already, nothing to add`:`your app's address, read from this page`})]}),!t&&(0,i.jsx)(Ru,{compact:!0,code:e,label:`Copy the address`})]}):null}function Vu({name:e,shownAs:n,hint:a}){let[o,s]=r.default.useState(!1);return(0,i.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-3 px-4 py-3 border-b border-[var(--panel-border)]/40 last:border-0`,children:[(0,i.jsxs)(`div`,{className:`min-w-0`,children:[(0,i.jsx)(`div`,{className:`text-[13.5px] font-bold text-foreground break-all sm:break-normal sm:truncate`,children:e}),(0,i.jsx)(`div`,{className:`text-[12.5px] text-foreground/50 font-medium`,children:a??(0,i.jsxs)(i.Fragment,{children:[`the value Firebase labels `,n]})})]}),(0,i.jsxs)(`button`,{type:`button`,onClick:()=>{navigator.clipboard?.writeText(e),s(!0),setTimeout(()=>s(!1),2e3)},className:`inline-flex items-center gap-1.5 h-9 px-3 rounded-xl text-[12px] font-bold shrink-0 self-start sm:self-auto transition-all cursor-pointer active:scale-[0.98] ${o?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary`}`,children:[o?(0,i.jsx)(t.zi,{className:`w-3.5 h-3.5`}):(0,i.jsx)(t.Ti,{className:`w-3.5 h-3.5`}),o?`Copied`:`Copy name`]})]})}var Hu=ku.map(({key:e,shownAs:t})=>e===`VITE_FIREBASE_STORAGE_BUCKET`?{name:e,value:`leave empty`,empty:!0}:{name:e,value:`paste ${t}`});function Uu({name:e,value:n,empty:r}){return(0,i.jsxs)(`div`,{className:`px-3 sm:px-4 py-1.5 flex flex-col gap-1 sm:grid sm:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_2.25rem] sm:gap-3 sm:items-center`,children:[(0,i.jsx)(`div`,{title:e,className:`text-[12.5px] sm:text-[13px] font-semibold text-foreground/80 break-all sm:truncate`,children:e}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 sm:contents`,children:[(0,i.jsx)(`div`,{className:`flex-1 min-w-0 h-9 px-3 flex items-center rounded-xl border text-[12.5px] sm:text-[13px] font-medium ${r?`border-dashed border-accent/40 text-accent`:`border-[var(--panel-border)]/60 text-foreground/45`}`,children:(0,i.jsx)(`span`,{className:`truncate`,children:n})}),(0,i.jsx)(`span`,{"aria-hidden":`true`,className:`w-9 h-9 shrink-0 rounded-xl flex items-center justify-center bg-foreground/[0.05] text-foreground/35`,children:(0,i.jsx)(t.yi,{className:`w-4 h-4`})})]})]})}function Wu(){return(0,i.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl overflow-hidden bg-background`,children:[(0,i.jsx)(`div`,{className:`max-sm:hidden sm:grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_2.25rem] gap-3 px-4 pt-3.5 pb-1`,children:[`Name`,`Value`].map(e=>(0,i.jsx)(`span`,{className:`text-[12.5px] font-semibold text-foreground/45`,children:e},e))}),(0,i.jsx)(`div`,{className:`py-2 sm:py-1.5`,children:Hu.map(e=>(0,i.jsx)(Uu,{...e},e.name))}),(0,i.jsx)(`div`,{className:`flex justify-end px-3 sm:px-4 py-3 border-t border-[var(--panel-border)]/40`,children:(0,i.jsx)(`span`,{"aria-hidden":`true`,className:`btn-secondary inline-flex items-center h-9 px-4 rounded-xl text-[12.5px] font-bold select-none`,children:`Apply`})})]})}function Gu(){let[e,n]=(0,r.useState)(``),[a,o]=(0,r.useState)(``),[s,c]=(0,r.useState)([]),[l,u]=(0,r.useState)(``),d=e=>{n(e),a&&(o(``),c([])),l&&u(``)},f=()=>{let t=Iu(e);if(t.length===0){u(`Type an email address first — it is what the rules will name.`);return}let n=t.filter(e=>!Lu.test(e));if(n.length>0){u(`That does not look like an email address: ${n.join(`, `)}`);return}u(``),c(t.map(e=>e.trim().toLowerCase())),o(Fu(t))};return(0,i.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl p-5 mb-2 flex flex-col gap-4`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-3.5 min-w-0`,children:[(0,i.jsx)(`div`,{className:`w-10 h-10 rounded-2xl flex items-center justify-center shrink-0 border border-[var(--panel-border)]/50 bg-accent/10 text-accent`,children:(0,i.jsx)(t.Fr,{className:`w-5 h-5`})}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,i.jsx)(`h3`,{className:`text-[15px] font-bold text-foreground tracking-tight leading-tight truncate`,children:`Who runs this app?`}),(0,i.jsx)(`p`,{className:`text-[12px] text-foreground/50 font-normal leading-snug truncate`,children:`The email you sign in with becomes the owner — separate several with commas.`})]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center gap-2`,children:[(0,i.jsx)(`input`,{type:`text`,value:e,"aria-label":`The email address you will sign in with`,placeholder:`you@yourcompany.com`,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f())},className:`w-full h-10 px-3.5 rounded-[var(--input-radius,0.75rem)] border border-[var(--panel-border)] bg-[var(--panel-bg)] text-[13.5px] text-foreground outline-none transition-all duration-300 placeholder:text-foreground/35 hover:border-accent/40 focus:border-accent console-field ${l?`is-invalid border-red-500/60`:``}`}),(0,i.jsx)(`button`,{type:`button`,onClick:f,className:`btn-primary inline-flex items-center justify-center h-10 px-4 rounded-[var(--btn-radius,0.75rem)] text-[12.5px] font-bold text-white shrink-0 cursor-pointer active:scale-[0.98] transition-transform whitespace-nowrap`,children:`Generate the rules`})]}),l&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 leading-snug px-1`,children:l}),a&&(0,i.jsxs)(`div`,{className:`rounded-2xl border border-emerald-500/20 bg-emerald-500/[0.05] px-3.5 py-3 flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-3`,children:[(0,i.jsx)(`span`,{className:`w-7 h-7 rounded-full bg-emerald-500/10 border border-emerald-500/20 flex items-center justify-center shrink-0`,children:(0,i.jsx)(t.zi,{className:`w-3.5 h-3.5 text-emerald-500`})}),(0,i.jsxs)(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[(0,i.jsxs)(`p`,{"data-admin-emails":!0,className:`text-[13px] font-bold text-foreground leading-snug break-all`,children:[`Ready — they make `,s.join(`, `),` the owner.`]}),(0,i.jsx)(`p`,{className:`text-[12px] font-medium text-foreground/50 leading-snug`,children:`Paste them into Firebase, then sign in with that address — or reload, if you already are.`})]}),(0,i.jsx)(Ru,{compact:!0,code:a,label:`Copy the rules`})]})]})}var Ku=`text-accent underline underline-offset-2 font-semibold hover:text-accent-deep transition-colors`;function qu({text:e,label:t}){return(0,i.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl bg-background overflow-hidden`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3 border-b border-[var(--panel-border)]/40`,children:[(0,i.jsx)(`span`,{className:`text-[12px] font-extrabold tracking-tight text-gradient truncate max-sm:hidden`,children:`Paste this into your assistant`}),(0,i.jsx)(Ru,{compact:!0,code:e,label:t})]}),(0,i.jsx)(`pre`,{className:`px-4 py-3 max-h-64 overflow-auto text-[11.5px] leading-relaxed font-mono text-foreground/70 whitespace-pre-wrap [overflow-wrap:anywhere]`,children:e})]})}function Ju({number:e,title:t,aside:n,children:r}){return(0,i.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,i.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,i.jsx)(`span`,{className:`w-8 h-8 shrink-0 rounded-full bg-accent/10 border border-accent/20 text-accent flex items-center justify-center text-[14px] font-extrabold`,children:e}),(0,i.jsx)(`h3`,{className:`text-[17px] md:text-[19px] font-extrabold text-foreground tracking-tight flex-1 min-w-0`,children:t}),n]}),(0,i.jsx)(`div`,{className:`text-[14px] md:text-[15px] text-foreground/70 leading-relaxed space-y-4`,children:r})]})}function Yu({basename:e}){return(0,i.jsxs)(`div`,{className:`mt-6 sm:mt-8 relative z-10 flex flex-col sm:flex-row sm:items-center gap-4 sm:gap-6 p-5 sm:p-6 rounded-3xl border border-accent/20 bg-accent/[0.06]`,children:[(0,i.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,i.jsx)(`h3`,{className:`text-[16px] sm:text-[17px] font-extrabold text-foreground tracking-tight`,children:`Worked through every step?`}),(0,i.jsx)(`p`,{className:`text-[13px] sm:text-[13.5px] text-foreground/60 font-medium leading-relaxed mt-1`,children:`Your app will start again and take you to sign in. Use the email address you typed into the rules — that is the one this app knows as its owner.`})]}),(0,i.jsxs)(t.fr.button,{type:`button`,whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>{Eu();let t=String(e||``).replace(/\/+$/,``);window.location.assign(`${t}/login`)},className:`btn-primary inline-flex items-center justify-center gap-2 h-12 px-6 rounded-[var(--btn-radius,0.75rem)] text-[13.5px] font-bold text-white shrink-0 cursor-pointer whitespace-nowrap shadow-lg`,children:[`I've completed all the steps`,(0,i.jsx)(t.Xi,{className:`w-4 h-4`})]})]})}function Xu({standalone:e}){let n=t.Na(),[a,o]=Cu(),s=a===`local`,c={project:s?2:1,webApp:s?3:2,keys:s?4:3,signIn:s?5:4,database:s?6:5,storage:s?7:6},l=zu(typeof window>`u`?``:window.location.href).local,[u]=(0,r.useState)(()=>{let e=localStorage.getItem(`theme-mode`);return e===`light`?!1:e===`dark`?!0:window.matchMedia(`(prefers-color-scheme: dark)`).matches});return(0,r.useEffect)(()=>{e&&document.documentElement.setAttribute(`data-theme`,u?`dark`:`light`)},[u,e]),(0,r.useEffect)(()=>{if(e&&t.Pa.faviconUrl){let e=document.querySelector(`link[rel*='icon']`);e||(e=document.createElement(`link`),e.rel=`icon`,document.head.appendChild(e)),e.href=t.Pa.faviconUrl}},[e]),(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,i.jsxs)(`div`,{children:[(0,i.jsx)(Ce,{children:`Setup`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/setup`]})]})}),(0,i.jsx)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-6 md:p-10 shadow-2xl relative overflow-hidden bg-background flex flex-col`,children:[(0,i.jsx)(`div`,{className:`mb-6 pb-4 sm:mb-8 sm:pb-6 border-b border-[var(--panel-border)]/50 relative z-10`,children:(0,i.jsxs)(`div`,{className:`flex max-sm:flex-col max-sm:items-stretch items-center justify-between gap-3 sm:gap-4`,children:[(0,i.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,i.jsx)(`h2`,{className:`text-[17px] sm:text-xl font-extrabold text-foreground tracking-tight truncate`,children:`Connect your app to Firebase`}),(0,i.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1 sm:mt-1.5 leading-snug truncate`,children:[(0,i.jsx)(`span`,{className:`sm:hidden`,children:`Google's free data and sign-in service.`}),(0,i.jsx)(`span`,{className:`max-sm:hidden`,children:`Firebase is Google's free service that stores your data and signs people in — about ten minutes, once.`})]})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,i.jsx)(t.fr.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,i.jsx)(t.Zr,{className:`w-4 h-4`})}),(0,i.jsx)(t.fr.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,i.jsx)(bu,{className:`w-4 h-4 text-foreground/80`})})]})]})}),!1,(0,i.jsxs)(`div`,{className:`flex flex-col relative z-10 p-4 sm:p-6 md:p-8 bg-foreground/[0.015] rounded-3xl border border-[var(--panel-border)]/50`,children:[s&&(0,i.jsxs)(Ju,{number:1,title:`Set your project up`,children:[(0,i.jsx)(`p`,{className:`text-foreground/80`,children:`Your assistant does this part — none of it is yours to type. Copy the block below into Claude Code, Codex or Antigravity and let it finish before you carry on. If you are already looking at this page on your own machine, paste it anyway: it only fills in what is missing and changes nothing that is already right.`}),(0,i.jsx)(qu,{text:wu,label:`Copy the setup prompt`}),(0,i.jsxs)(`p`,{className:`text-foreground/80`,children:[`One of the lines it writes is `,(0,i.jsx)(`strong`,{children:`GEMINI_API_KEY`}),`, and it stays empty unless you later ask for something that uses AI — a chatbot, a writing helper. A free key comes from`,` `,(0,i.jsx)(`a`,{href:`https://aistudio.google.com/apikey`,target:`_blank`,rel:`noopener noreferrer`,className:Ku,children:`aistudio.google.com/apikey`}),` `,`when that day comes.`]})]}),(0,i.jsx)(Ju,{number:c.project,title:`Create a Firebase project`,children:(0,i.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,i.jsxs)(`li`,{children:[`Open`,` `,(0,i.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,i.jsx)(`strong`,{children:`Add project`}),`. Sign in with your Google account if it asks.`]}),(0,i.jsxs)(`li`,{children:[`Type any name you like and click `,(0,i.jsx)(`strong`,{children:`Continue`}),`.`]}),(0,i.jsxs)(`li`,{children:[`If it offers `,(0,i.jsx)(`strong`,{children:`Enable Gemini in Firebase`}),`, switch it off.`]}),(0,i.jsxs)(`li`,{children:[`Switch off `,(0,i.jsx)(`strong`,{children:`Enable Google Analytics for this project`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Create project`}),`, wait, then click `,(0,i.jsx)(`strong`,{children:`Continue`}),`.`]})]})}),(0,i.jsx)(Ju,{number:c.webApp,title:`Add a web app and copy the six values`,children:(0,i.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,i.jsxs)(`li`,{children:[`On that page click `,(0,i.jsx)(`strong`,{children:`+ Add app`}),` under your project's name, then pick the `,(0,i.jsx)(`strong`,{children:`</> Web`}),` icon.`]}),(0,i.jsxs)(`li`,{children:[`Give it any nickname (`,(0,i.jsx)(`span`,{className:`text-accent`,children:`MyApp`}),` is fine). Leave `,(0,i.jsx)(`strong`,{children:`Firebase Hosting`}),` unticked.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Register app`}),`.`]}),(0,i.jsx)(`li`,{children:`Firebase now shows six values on screen, each with a label beside it — apiKey, authDomain, projectId, storageBucket, messagingSenderId and appId. You will copy them one at a time in the next step, so keep this tab open.`})]})}),(0,i.jsx)(Ju,{number:c.keys,title:s?`Put the six values in your .env`:`Paste the values into the Gemini prompt`,children:s?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(`p`,{className:`text-foreground/80`,children:[`Step 1 made a `,(0,i.jsx)(`strong`,{children:`.env`}),` file, and every name below is already a line in it. Open it — or ask your assistant to open it for you — and put each value from your Firebase tab between that line's quotes. The names have to match letter for letter, so find them with the Copy name button rather than retyping.`]}),(0,i.jsxs)(`p`,{className:`text-foreground/80`,children:[`Six lines, and that is all of them. Fill five of them now and leave`,` `,(0,i.jsx)(`strong`,{children:`VITE_FIREBASE_STORAGE_BUCKET`}),` empty — step `,c.storage,` gives you its real value.`]}),(0,i.jsxs)(`p`,{className:`text-foreground/80`,children:[(0,i.jsx)(`strong`,{children:`Leave the app as it is for now.`}),` One value is still missing, and starting it again is the last thing you do on this whole page.`]}),(0,i.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl overflow-hidden bg-background`,children:ku.map(({key:e,shownAs:t})=>(0,i.jsx)(Vu,{name:e,shownAs:t,hint:e===`VITE_FIREBASE_STORAGE_BUCKET`?`leave this one empty — step ${c.storage} gives you the real address`:void 0},e))})]}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(`p`,{className:`text-foreground/80`,children:[`In the Gemini chat to the left, you will see a prompt to`,` `,(0,i.jsx)(`strong`,{children:`Enter your environment variables to continue`}),`, with a form like the one below. Paste each value from your Firebase tab into its row, then click `,(0,i.jsx)(`strong`,{children:`Apply`}),`.`]}),(0,i.jsxs)(`p`,{className:`text-foreground/80`,children:[`Leave `,(0,i.jsx)(`strong`,{children:`VITE_FIREBASE_STORAGE_BUCKET`}),` empty — step `,c.storage,` gives you its real value.`]}),(0,i.jsx)(Wu,{})]})}),(0,i.jsxs)(Ju,{number:c.signIn,title:`Turn on sign-in`,children:[(0,i.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,i.jsxs)(`li`,{children:[`In the Firebase menu on the left, open `,(0,i.jsx)(`strong`,{children:`Authentication`}),` and click `,(0,i.jsx)(`strong`,{children:`Get started`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Open the `,(0,i.jsx)(`strong`,{children:`Sign-in method`}),` tab.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Email/Password`}),`, switch on the first toggle and `,(0,i.jsx)(`strong`,{children:`Save`}),`. (Leave email link off.)`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Add provider`}),`, choose `,(0,i.jsx)(`strong`,{children:`Google`}),`, switch it on, pick your own address as the support email, and `,(0,i.jsx)(`strong`,{children:`Save`}),`. The app needs this for the `,(0,i.jsx)(`strong`,{children:`Sign in with Google`}),` button to work.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Add provider`}),`, choose `,(0,i.jsx)(`strong`,{children:`Anonymous`}),`, switch it on, and `,(0,i.jsx)(`strong`,{children:`Save`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Open the `,(0,i.jsx)(`strong`,{children:`Settings`}),` tab, then `,(0,i.jsx)(`strong`,{children:`Authorized domains`}),`. Your app has to be listed here or nobody can sign in.`]}),l?(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`strong`,{children:`Nothing to add here yet.`}),` This app is being served from your own machine, and Firebase trusts that address from the start. Come back and add the real one the day you put your app on the internet.`]}):(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`strong`,{children:`Your app's address is right here`}),` — copy it below, then in Firebase click `,(0,i.jsx)(`strong`,{children:`Add domain`}),`, paste it, and save. Nothing to hunt for: it is the address this very page is being served from.`]})]}),(0,i.jsx)(Bu,{})]}),(0,i.jsxs)(Ju,{number:c.database,title:`Create the database and publish its rules`,children:[(0,i.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80 mb-4`,children:[(0,i.jsxs)(`li`,{children:[`In the Firebase menu, open `,(0,i.jsx)(`strong`,{children:`Firestore Database`}),` and click `,(0,i.jsx)(`strong`,{children:`Create database`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Pick `,(0,i.jsx)(`strong`,{children:`Standard edition`}),` if asked, choose the location closest to your people, start in `,(0,i.jsx)(`strong`,{children:`Production mode`}),`, and click Continue.`]}),(0,i.jsxs)(`li`,{children:[`In the box below, type the email address you will sign in with and click `,(0,i.jsx)(`strong`,{children:`Generate the rules`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Copy the rules`}),`, then in Firebase open the `,(0,i.jsx)(`strong`,{children:`Rules`}),` tab, select everything that is there, paste over it, and click `,(0,i.jsx)(`strong`,{children:`Publish`}),`.`]})]}),(0,i.jsx)(Gu,{})]}),(0,i.jsxs)(Ju,{number:c.storage,title:s?`Create storage, publish its rules, and start it again`:`Create storage, publish its rules, and press Apply`,children:[(0,i.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80 mb-4`,children:[(0,i.jsxs)(`li`,{children:[`In the Firebase menu, open `,(0,i.jsx)(`strong`,{children:`Storage`}),`. Google asks you to upgrade the project first: click `,(0,i.jsx)(`strong`,{children:`Upgrade project`}),` and pick the pay-as-you-go`,` `,(0,i.jsx)(`strong`,{children:`Blaze plan`}),`. Profile photos and attachments cost about $0.03 per gigabyte a month, so this is cents. Set a budget you are comfortable with (say $20), link a billing account, and continue.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Get started`}),`, choose a no-cost location, start in `,(0,i.jsx)(`strong`,{children:`Production mode`}),`, and click `,(0,i.jsx)(`strong`,{children:`Create`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Open the `,(0,i.jsx)(`strong`,{children:`Rules`}),` tab, select everything that is there, paste these over it, and click `,(0,i.jsx)(`strong`,{children:`Publish`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Now Firebase shows the storage address at the top of the page — something like`,` `,`your-project.firebasestorage.app. `,(0,i.jsx)(`strong`,{children:`Copy that`}),`. This is the real one; the one Firebase showed you back in step `,c.webApp,` was a guess made before storage existed.`]}),s?(0,i.jsxs)(`li`,{children:[`Back in your `,(0,i.jsx)(`strong`,{children:`.env`}),` file, paste it into`,` `,(0,i.jsx)(`strong`,{children:`VITE_FIREBASE_STORAGE_BUCKET`}),` — the line you left empty.`]}):(0,i.jsxs)(`li`,{children:[`In Google AI Studio, click the `,(0,i.jsx)(`strong`,{children:`cog`}),` icon in the top right corner and scroll the menu along the top to `,(0,i.jsx)(`strong`,{children:`Secrets`}),`. Paste it as the value of `,(0,i.jsx)(`strong`,{children:`VITE_FIREBASE_STORAGE_BUCKET`}),` — the one you left empty. If it is not listed, click `,(0,i.jsx)(`strong`,{children:`+ Add secret`}),` and use that name.`]}),s?(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`strong`,{children:`Start the app again.`}),` Stop it and start it once more — or just ask your assistant to restart it. A value added while it is running is not read until then. That is the last thing to do: then reload this page and your app is connected.`]}):(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`strong`,{children:`Press Apply, then reload this page.`}),` Your app is connected.`]})]}),(0,i.jsx)(Ru,{code:Pu,label:`Copy the storage rules`})]})]}),(0,i.jsx)(Yu,{basename:n.basename})]})})]})}var Zu={email:{collection:`sys_configs`,doc:`email`},payments:{collection:`sys_payments`,doc:`_settings`}},Qu=e=>e?.enabled!==!1;function $u(e){let{collection:n,doc:i}=Zu[e],[a,s]=(0,r.useState)({loading:!0,on:!0});return(0,r.useEffect)(()=>(0,o.onSnapshot)((0,o.doc)(t.Da,n,i),e=>s({loading:!1,on:Qu(e.exists()?e.data():null)}),()=>s({loading:!1,on:!0})),[n,i]),{loading:a.loading,on:a.on,set:async r=>{let c=a.on;s({loading:!1,on:r});try{return await(0,o.setDoc)((0,o.doc)(t.Da,n,i),{enabled:r},{merge:!0}),e===`payments`&&J(),null}catch{return s({loading:!1,on:c}),`The switch could not be saved. Check that you are signed in as an admin.`}}}}var ed=`The server could not be reached.`;function td(e,t,n=0){let[i,a]=(0,r.useState)(null),[o,s]=(0,r.useState)(``),c=(0,r.useRef)(!0);(0,r.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]);let l=(0,r.useRef)(t);(0,r.useEffect)(()=>{l.current=t},[t]);let u=(0,r.useCallback)(async()=>{try{let t=await(await fetch(e)).json();if(!c.current)return;a(l.current(t)),s(``)}catch{c.current&&s(ed)}},[e]);return(0,r.useEffect)(()=>{if(u(),!n)return;let e=setInterval(u,n);return()=>clearInterval(e)},[u,n]),{status:i,error:o,reread:u}}var nd=e=>({configured:!!e?.configured,mode:e?.mode===`live`||e?.mode===`test`?e.mode:null,webhookConfigured:!!e?.webhookConfigured}),rd=e=>({configured:!!e?.configured,from:e?.from??null,adminCount:Number(e?.adminCount)||0}),id={email:`/api/email/status`,payments:`/api/payments/status`},ad=(e=0)=>td(id.payments,nd,e),od=(e=0)=>td(id.email,rd,e),sd=e=>!!e?.configured;function cd(e){let t=td(id[e],sd),n=$u(e);return{loading:t.status===null&&!t.error||n.loading,configured:t.status===!0,on:n.on}}var ld={collection:`sys_configs`,doc:`publish`},ud=[`published`,`connected`,`authorised`],dd={appName:``,domain:``,done:[]};function fd(e){let t=Array.isArray(e?.done)?e.done:[];return{appName:typeof e?.appName==`string`?e.appName:``,domain:typeof e?.domain==`string`?e.domain:``,done:ud.filter(e=>t.includes(e))}}function pd(e){let t=String(e??``).trim().toLowerCase();return t=t.replace(/^[a-z][a-z0-9+.-]*:\/\//,``),t=t.split(/[/?#]/)[0],t=t.replace(/\.ai\.studio$/,``),t.replace(/[\s_]+/g,`-`).replace(/[^a-z0-9-]/g,``).replace(/-{2,}/g,`-`).replace(/^-+|-+$/g,``)}var md=e=>{let t=pd(e);return t?`https://${t}.ai.studio/`:``};function hd(e){let t=String(e??``).trim().toLowerCase();return t=t.replace(/^[a-z][a-z0-9+.-]*:\/\//,``),t=t.replace(/^[^/@]*@/,``),t=t.split(/[/?#]/)[0],t=t.split(`:`)[0],t=t.replace(/^www\./,``),t=t.replace(/^\.+|\.+$/g,``),/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*\.[a-z]{2,}$/.test(t)?t:``}var gd=e=>{let t=hd(e);return t?`https://${t}/`:``},_d=e=>gd(e?.domain)||md(e?.appName);function vd(e,t=null){let n=t=>e.includes(t),r=ud.find(e=>!n(e))??null,i=r?ud.indexOf(r):ud.length-1;return ud.map((e,a)=>{let o=a<=i,s=t!==null&&t===e&&o;return{id:e,visible:o,done:n(e),open:s||t===null&&e===r}})}var yd=(e,t)=>ud.filter(n=>n===t||e.includes(n));function bd(e){return!e||!e.configured?!1:e.mode===`live`?!e.webhookConfigured:!0}function xd(){let[e,n]=(0,r.useState)({loading:!0,record:dd});return(0,r.useEffect)(()=>(0,o.onSnapshot)((0,o.doc)(t.Da,ld.collection,ld.doc),e=>n({loading:!1,record:fd(e.exists()?e.data():null)}),()=>n({loading:!1,record:dd})),[]),{loading:e.loading,record:e.record,save:async e=>{n(t=>({loading:!1,record:{...t.record,...e}}));try{return await(0,o.setDoc)((0,o.doc)(t.Da,ld.collection,ld.doc),e,{merge:!0}),null}catch(e){return console.error(`Could not save where you got to`,e),`That could not be saved. Only an admin can, and only while you are signed in.`}}}}function Sd(e,t){return!e&&t!==`live`?{state:`off`,label:`In test mode`}:t===`live`?{state:`saved`,label:`Live`}:{state:`saving`,label:`Waiting for the live key`}}var Cd=[`checkout.session.completed`,`checkout.session.async_payment_succeeded`],wd=`text-[12.5px] font-medium text-foreground/70 leading-relaxed`,Td=`mt-1.5 space-y-1 list-disc list-inside marker:text-foreground/30`,Ed=`my-2 glass-panel border border-[var(--panel-border)] rounded-2xl overflow-hidden bg-background`;function Dd(){let[e,n]=(0,r.useState)(null),[a,s]=(0,r.useState)([]),{status:l}=ad(5e3),u=l?.mode??null,d=l?.webhookConfigured??!1,[f]=Cu(),p=f===`local`,{record:m}=xd(),h=z(_d(m)),g=m.done.includes(`authorised`)&&!!h;(0,r.useEffect)(()=>(0,o.onSnapshot)((0,o.collection)(t.Da,ji),e=>{n(!!e.docs.find(e=>e.id===Mi)?.data()?.liveMode);let t=[];e.forEach(e=>{e.id!==`_settings`&&t.push(Ui(e.id,e.data()))}),t.sort((e,t)=>(e.createdAt||0)-(t.createdAt||0)),s(t)},()=>n(!1)),[]);let _=async e=>{n(e);try{await(0,o.setDoc)((0,o.doc)(t.Da,ji,Mi),{liveMode:e},{merge:!0})}catch(e){console.error(`Could not save the go-live switch`,e)}},v=!!e,y=Sd(v,u),b=a.filter(e=>qi(e,!1)),x=b.filter(e=>!qi(e,!0)),S=b.length>0&&x.length===0,C=b.some(e=>e.kind===`subscription`);return(0,i.jsx)(t.ut,{icon:t.zr,title:`Go live`,description:v?`Real cards, real money — the steps below finish the switch.`:`Practice is free — flip this only when a test payment has gone all the way through.`,chip:y,enabled:e===null?null:v,onChange:_,children:v&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(`ol`,{className:`space-y-3.5 list-decimal list-inside ${wd}`,children:[(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`strong`,{children:`Your live secret key.`}),` In Stripe, click your account name in the top left corner and choose your `,(0,i.jsx)(`strong`,{children:`live`}),` account — not the sandbox.`,(0,i.jsxs)(`ul`,{className:Td,children:[(0,i.jsxs)(`li`,{children:[`Open the dark strip along the bottom that says `,(0,i.jsx)(`strong`,{children:`Developers`}),`, and scroll down to the `,(0,i.jsx)(`strong`,{children:`API keys`}),` section.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Manage API keys`}),`. Under `,(0,i.jsx)(`strong`,{children:`Standard keys`}),`, click `,(0,i.jsx)(`strong`,{children:`+ Create secret key`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Where it asks `,(0,i.jsx)(`em`,{children:`How will you be using this key?`}),`, choose`,` `,(0,i.jsx)(`strong`,{children:`Powering an integration you built`}),`, then`,` `,(0,i.jsx)(`strong`,{children:`Create secret key`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Stripe asks you to confirm it is you: click `,(0,i.jsx)(`strong`,{children:`Send verification`}),` `,`and verify the request with the code it sends.`]}),(0,i.jsxs)(`li`,{children:[`Give the key a name — `,(0,i.jsx)(`span`,{className:`text-accent`,children:`my ai project app key`}),` `,`— and copy it. `,(0,i.jsx)(`strong`,{children:`Stripe will not show it to you again.`})]}),p?(0,i.jsxs)(`li`,{children:[`Open your `,(0,i.jsx)(`strong`,{children:`.env`}),` file and paste it over the sk_test_… value of `,(0,i.jsx)(`strong`,{children:`STRIPE_SECRET_KEY`}),` — replace it, do not add a second line. Start the app again, and the chip at the top of this card turns to `,(0,i.jsx)(`strong`,{children:`Live`}),` on its own.`]}):(0,i.jsxs)(`li`,{children:[`Click the `,(0,i.jsx)(`strong`,{children:`cog icon`}),` in the top right corner of your app in Google AI Studio and find the `,(0,i.jsx)(`strong`,{children:`Secrets`}),` tab. Paste the new key over the value of `,(0,i.jsx)(`strong`,{children:`STRIPE_SECRET_KEY`}),` — replace the sk_test_… one, do not add a second. Click `,(0,i.jsx)(`strong`,{children:`Apply`}),` and refresh this page: the chip at the top of this card turns to `,(0,i.jsx)(`strong`,{children:`Live`}),` on its own.`]})]})]}),C&&(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`strong`,{children:`Your live price ids.`}),` A subscription's prices are made fresh in live mode, so the ids under `,(0,i.jsx)(`strong`,{children:`What you sell`}),` change. Create each plan's price in your live Stripe account and paste its id there. Your test ids are kept and come straight back if you switch off again.`]}),(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`strong`,{children:`The webhook.`}),` `,g?`What keeps receipts and your sale alerts sending when a buyer pays and never comes back to your app.`:`Stripe has to be able to reach your app from the outside, so this one waits until your app is published.`,` `,(0,i.jsx)(`span`,{className:`inline-block align-middle ml-0.5`,children:(0,i.jsx)(t.lt,{state:d?`saved`:`off`,label:d?`Connected`:`Not yet`})}),g?(0,i.jsxs)(`ul`,{className:Td,children:[(0,i.jsxs)(`li`,{children:[`Still in your `,(0,i.jsx)(`strong`,{children:`live`}),` Stripe account, open the`,` `,(0,i.jsx)(`strong`,{children:`Developers`}),` strip at the bottom again and, in its top menu, click `,(0,i.jsx)(`strong`,{children:`Webhooks`}),`. Click `,(0,i.jsx)(`strong`,{children:`Add destination`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Leave every setting as it is. Under `,(0,i.jsx)(`strong`,{children:`Events`}),`, use the`,` `,(0,i.jsx)(`em`,{children:`Find event by name or description…`}),` search bar to find these two, and click the checkmark on each:`,(0,i.jsx)(`div`,{className:`mt-1.5 flex flex-col gap-1`,children:Cd.map(e=>(0,i.jsx)(Ru,{code:e,label:e,compact:!0},e))}),`The first is an ordinary card payment. The second is a bank transfer landing hours later, when nobody is watching — without it those sales send no email at all.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Continue`}),` and keep it as a`,` `,(0,i.jsx)(`strong`,{children:`Webhook endpoint`}),`. Give the destination a name —`,` `,(0,i.jsx)(`span`,{className:`text-accent`,children:`my ai project receipts`}),`.`]}),(0,i.jsxs)(`li`,{children:[`As the `,(0,i.jsx)(`strong`,{children:`Endpoint URL`}),`, paste exactly this — your published address with the webhook route on the end:`,(0,i.jsx)(`div`,{className:`my-2`,children:(0,i.jsx)(Ru,{code:h,label:`Copy your webhook address`,compact:!0})})]}),(0,i.jsxs)(`li`,{children:[`Create the destination. On the right, under Webhooks, you will find its`,` `,(0,i.jsx)(`strong`,{children:`signing secret`}),` — it starts with `,(0,i.jsx)(`strong`,{children:`whsec_`}),`. Copy it.`]}),(0,i.jsxs)(`li`,{children:[p?(0,i.jsxs)(i.Fragment,{children:[`Add the line below to your `,(0,i.jsx)(`strong`,{children:`.env`}),` file with the whsec_… secret as its value, and start the app again. You are all set — the chip beside this step turns green.`]}):(0,i.jsxs)(i.Fragment,{children:[`Click the `,(0,i.jsx)(`strong`,{children:`cog icon`}),` in the top right corner of your app in Google AI Studio, scroll the menu along the top to `,(0,i.jsx)(`strong`,{children:`Secrets`}),` `,`and click `,(0,i.jsx)(`strong`,{children:`+ Add secret`}),`. Copy the name below into`,` `,(0,i.jsx)(`strong`,{children:`Secret name`}),` and paste the whsec_… secret as its value. Click `,(0,i.jsx)(`strong`,{children:`Apply`}),` and refresh this page. You are all set — the chip beside this step turns green.`]}),(0,i.jsx)(`div`,{className:Ed,children:(0,i.jsx)(Vu,{name:`STRIPE_WEBHOOK_SECRET`,hint:`the whsec_… signing secret from the destination you just made`})})]})]}):(0,i.jsxs)(`div`,{className:`mt-2 flex flex-col gap-2.5`,children:[(0,i.jsxs)(t.st,{children:[`Your app has no public address yet, and the preview address in this browser is not one Stripe can reach — it changes every session.`,` `,m.done.length===0?`Publish your app first`:`Finish publishing your app first`,`: this step opens on its own once step 3 of Publish App,`,` `,(0,i.jsx)(`strong`,{children:`Add your domains and email sender`}),`, is ticked. Everything above works in the meantime.`]}),(0,i.jsxs)(c.Link,{to:`/publish`,className:`inline-flex items-center gap-1.5 w-fit h-9 px-4 rounded-[var(--btn-radius,0.75rem)] text-[12.5px] font-bold border border-accent/40 bg-accent/10 text-accent hover:bg-accent/15 transition-all active:scale-[0.98] cursor-pointer`,children:[`Take me to Publish App`,(0,i.jsx)(t.Xi,{className:`w-3.5 h-3.5`})]})]})]})]}),(0,i.jsxs)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:[`One more switch lives in Stripe, not here: switching plans (monthly ↔ yearly, Basic ↔ Pro) appears in Stripe’s customer portal — where your buyers manage their own subscriptions — only if you allow it:`,` `,(0,i.jsx)(`a`,{href:`https://dashboard.stripe.com/settings/billing/portal`,target:`_blank`,rel:`noopener noreferrer`,className:`text-accent font-bold hover:underline`,children:`Stripe Settings → Billing → Customer portal`}),` `,`→ let customers switch plans.`]}),b.length>0&&!S&&(0,i.jsxs)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:[`Your subscriptions under What you sell now ask for `,(0,i.jsx)(`strong`,{children:`live`}),` price ids — `,x.length===b.length?`each one`:`${x.length} of ${b.length}`,` is still waiting. Your test ids are kept and come back if you switch back. Once the live ids are in, the message for your assistant appears right here.`]}),S&&(0,i.jsx)(it,{title:`Tell your assistant about the switch`,prompt:ja(b)})]})})}var Od={configured:!1,mode:null,webhookConfigured:!1};function kd(e=5e3){let{status:t,error:n}=ad(e);return{...t??Od,checked:t!==null||!!n}}function Ad(e,t){if(!t.checked)return{state:`saving`,label:`Checking`};switch(e){case 1:case 2:return t.configured?{state:`saved`,label:`Done`}:{state:`off`,label:`Not yet`};case 3:return t.configured?{state:`saved`,label:t.mode===`live`?`Key found — live`:`Key found — test mode`}:{state:`off`,label:`No key yet`}}}var jd={configured:!1,from:null,adminCount:0};function Md(e=5e3){let{status:t,error:n}=od(e);return{...t??jd,checked:t!==null||!!n}}function Nd(e){return e.checked?e.configured?{state:`saved`,label:`Connected`}:{state:`off`,label:`Not yet`}:{state:`saving`,label:`Checking`}}function Pd(e){return e.checked?e.from&&!String(e.from).toLowerCase().endsWith(`@resend.dev`)?{state:`saved`,label:`Your own address`}:{state:`off`,label:`Practice address`}:{state:`saving`,label:`Checking`}}var Fd=`text-accent underline underline-offset-2 font-semibold hover:text-accent-deep transition-colors`;function Id({href:e,children:t}){return(0,i.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:Fd,children:t})}function Ld({number:e,title:t,aside:n,children:r}){return(0,i.jsxs)(`div`,{className:`flex flex-col gap-3 pb-5 mb-5 border-b border-[var(--panel-border)]/50 last:border-0 last:pb-0 last:mb-0`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,i.jsx)(`span`,{className:`w-7 h-7 shrink-0 rounded-full bg-accent/10 border border-accent/20 text-accent flex items-center justify-center text-[12.5px] font-extrabold`,children:e}),(0,i.jsx)(`h4`,{className:`text-[14px] font-bold text-foreground tracking-tight flex-1 min-w-0`,children:t}),n]}),(0,i.jsx)(`div`,{className:`text-[13px] text-foreground/70 leading-relaxed space-y-3 sm:pl-[2.375rem]`,children:r})]})}var Rd=`space-y-1.5 list-decimal list-inside text-foreground/75`,zd=`glass-panel border border-[var(--panel-border)] rounded-2xl overflow-hidden bg-background`;function Bd({onConfirm:e,hint:n}){let[r]=Cu();return(0,i.jsxs)(`div`,{className:`flex flex-col gap-2 pt-1`,children:[(0,i.jsx)(t.Q,{icon:t.zi,onClick:e,className:`self-start`,children:`I have added the variables`}),(0,i.jsx)(`p`,{className:t.$,children:n||(r===`local`?`Start the app again first — a value added to .env while it is running is not read until then. If the chips have not turned green a minute later, reload this page.`:`Press Apply in AI Studio’s Secrets tab first — the app can only read a secret once it has been applied. If the chips have not turned green a minute later, reload this page.`)})]})}function Vd({icon:e,title:n,description:r,stepsDescription:a,button:o,secret:s,open:c,onOpen:l,confirmed:u,steps:d,children:f}){let[p]=Cu();return(0,i.jsx)(t.at,{icon:e,title:n,description:c?a:r,collapsible:!1,children:c?d:(0,i.jsxs)(i.Fragment,{children:[f,u&&(0,i.jsxs)(t.st,{tone:`error`,children:[`The app cannot see the key yet.`,` `,p===`local`?(0,i.jsxs)(i.Fragment,{children:[`Make sure `,s,` has a value in your .env file, start the app again, then reload this page`]}):(0,i.jsxs)(i.Fragment,{children:[`In AI Studio’s Secrets tab make sure `,s,` is there and press Apply, then reload this page`]}),` `,`— or open the steps again to check them.`]}),(0,i.jsxs)(`button`,{type:`button`,onClick:l,className:`inline-flex items-center gap-1.5 w-fit h-9 px-4 rounded-[var(--btn-radius,0.75rem)] text-[12.5px] font-bold border border-accent/40 bg-accent/10 text-accent hover:bg-accent/15 transition-all active:scale-[0.98] cursor-pointer`,children:[o,(0,i.jsx)(t.Xi,{className:`w-3.5 h-3.5`})]})]})})}function Hd({onConfirm:e}){let n=kd(),[r]=Cu(),a=r===`local`;return(0,i.jsxs)(`div`,{className:`flex flex-col`,children:[(0,i.jsx)(Ld,{number:1,title:`Make a Stripe account`,aside:(0,i.jsx)(t.lt,{...Ad(1,n)}),children:(0,i.jsxs)(`ol`,{className:Rd,children:[(0,i.jsxs)(`li`,{children:[`Open `,(0,i.jsx)(Id,{href:`https://dashboard.stripe.com`,children:`dashboard.stripe.com`}),` and create an account. It asks about your business — answer what you can and skip what you can't; none of it blocks the next steps.`]}),(0,i.jsxs)(`li`,{children:[`Click your account name in the `,(0,i.jsx)(`strong`,{children:`top left`}),` corner, choose`,` `,(0,i.jsx)(`strong`,{children:`Switch to sandbox`}),`, and make a sandbox for testing. A sandbox is a practice copy of Stripe: every card in it is pretend and every payment is practice, so nothing you do here can cost anyone real money.`]})]})}),(0,i.jsx)(Ld,{number:2,title:`Copy the test secret key`,aside:(0,i.jsx)(t.lt,{...Ad(2,n)}),children:(0,i.jsxs)(`ol`,{className:Rd,children:[(0,i.jsxs)(`li`,{children:[`Along the very bottom of the Stripe page is a dark bar that says `,(0,i.jsx)(`strong`,{children:`Developers`}),`. Click the arrow on it to unfold the panel.`]}),(0,i.jsxs)(`li`,{children:[`On the right of that panel, under `,(0,i.jsx)(`strong`,{children:`Testing tools`}),`, is your`,` `,(0,i.jsx)(`strong`,{children:`secret key`}),` — it starts with `,(0,i.jsx)(`strong`,{children:`sk_test_`}),`. Copy it.`]})]})}),(0,i.jsxs)(Ld,{number:3,title:a?`Put it in your .env and start the app again`:`Paste it into Secrets and press Apply`,aside:(0,i.jsx)(t.lt,{...Ad(3,n)}),children:[a?(0,i.jsxs)(`p`,{children:[`Open your `,(0,i.jsx)(`strong`,{children:`.env`}),` file — or ask your assistant to. The line below is already in it: paste the sk_test_… key between its quotes. One line, and that is the whole step — then `,(0,i.jsx)(`strong`,{children:`start the app again`}),` so it is read.`]}):(0,i.jsxs)(`ol`,{className:Rd,children:[(0,i.jsxs)(`li`,{children:[`Click the `,(0,i.jsx)(`strong`,{children:`cog`}),` icon in the top right corner of your app in Google AI Studio.`]}),(0,i.jsxs)(`li`,{children:[`In the menu along the top, scroll across to `,(0,i.jsx)(`strong`,{children:`Secrets`}),`, then click`,` `,(0,i.jsx)(`strong`,{children:`+ Add secret`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Copy the name below into `,(0,i.jsx)(`strong`,{children:`Secret name`}),`, and paste the sk_test_… key you just copied as the value.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Apply`}),`, then refresh the page. You are all set.`]})]}),(0,i.jsx)(`div`,{className:zd,children:(0,i.jsx)(Vu,{name:`STRIPE_SECRET_KEY`,hint:`the sk_test_… key you copied in step 2`})}),(0,i.jsxs)(`p`,{children:[`Now you can test a payment with the pretend card `,(0,i.jsx)(`strong`,{children:`4242 4242 4242 4242`}),` and any other details you like, or by paying with Google Pay or Apple Pay. Nothing is ever charged — a sandbox is all practice.`]})]}),(0,i.jsx)(Bd,{onConfirm:e})]})}function Ud({onConfirm:e}){let n=Md(),[r]=Cu(),a=r===`local`;return(0,i.jsxs)(`div`,{className:`flex flex-col`,children:[(0,i.jsx)(Ld,{number:1,title:`Make a Resend account and a key`,aside:(0,i.jsx)(t.lt,{...Nd(n)}),children:(0,i.jsxs)(`ol`,{className:Rd,children:[(0,i.jsxs)(`li`,{children:[`Open `,(0,i.jsx)(Id,{href:`https://resend.com`,children:`resend.com`}),` and create a free account — it is the service that delivers email for you. Sign up with the address you want your app's mail to reach you at.`]}),(0,i.jsxs)(`li`,{children:[`In Resend, open `,(0,i.jsx)(`strong`,{children:`API Keys`}),` and click `,(0,i.jsx)(`strong`,{children:`Create API key`}),`. Copy the key it shows — it starts with `,(0,i.jsx)(`strong`,{children:`re_`}),` — and keep the tab open.`]})]})}),(0,i.jsxs)(Ld,{number:2,title:a?`Put two values in your .env and start the app again`:`Paste two secrets and press Apply`,aside:(0,i.jsx)(t.lt,{...Nd(n)}),children:[a?(0,i.jsxs)(`p`,{children:[`Open your `,(0,i.jsx)(`strong`,{children:`.env`}),` file. Both lines below are already in it — paste each value between its quotes, then `,(0,i.jsx)(`strong`,{children:`start the app again`}),` so they are read.`]}):(0,i.jsxs)(`ol`,{className:Rd,children:[(0,i.jsxs)(`li`,{children:[`Click the `,(0,i.jsx)(`strong`,{children:`cog`}),` icon in the top right corner of your app in Google AI Studio.`]}),(0,i.jsxs)(`li`,{children:[`In the menu along the top, scroll across to `,(0,i.jsx)(`strong`,{children:`Secrets`}),`.`]}),(0,i.jsxs)(`li`,{children:[`For each row below, click `,(0,i.jsx)(`strong`,{children:`+ Add secret`}),`, copy the name here into`,` `,(0,i.jsx)(`strong`,{children:`Secret name`}),`, and paste the value.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Apply`}),`, then refresh the page.`]})]}),(0,i.jsxs)(`div`,{className:zd,children:[(0,i.jsx)(Vu,{name:`RESEND_API_KEY`,hint:`the re_… key you just made in Resend`}),(0,i.jsx)(Vu,{name:`ADMIN_EMAILS`,hint:`your own email address — where sale, booking and form alerts are sent`})]})]}),(0,i.jsxs)(Ld,{number:3,title:`Verify your domain, or mail only reaches you`,aside:(0,i.jsx)(t.lt,{...Pd(n)}),children:[(0,i.jsxs)(`p`,{children:[(0,i.jsx)(`strong`,{children:`Until you verify a domain of your own, Resend delivers only to the email address you made your Resend account with.`}),` A test email to yourself works; a customer's confirmation, a buyer's receipt, a booking note to someone else does not arrive at all. Do this before anyone but you should get an email.`]}),(0,i.jsxs)(`ol`,{className:Rd,children:[(0,i.jsxs)(`li`,{children:[`In Resend open `,(0,i.jsx)(Id,{href:`https://resend.com/domains`,children:`Domains`}),`, click `,(0,i.jsx)(`strong`,{children:`Add domain`}),` `,`and type the domain you own — `,(0,i.jsx)(`strong`,{children:`yourbusiness.com`}),`, without www.`]}),(0,i.jsx)(`li`,{children:`Resend shows a few DNS records. Add each one where your domain is managed — the company you bought it from, or wherever its website is hosted — copying name and value exactly.`}),(0,i.jsxs)(`li`,{children:[`Back in Resend, click `,(0,i.jsx)(`strong`,{children:`Verify`}),`. It can take a few minutes to turn green; if it does not, one record was copied wrong.`]}),a?(0,i.jsxs)(`li`,{children:[`Fill in one more line in your `,(0,i.jsx)(`strong`,{children:`.env`}),` — an address at that domain, which is what your mail goes out as — and `,(0,i.jsx)(`strong`,{children:`start the app again`}),`.`]}):(0,i.jsxs)(`li`,{children:[`Add one more secret in AI Studio — an address at that domain, which is what your mail goes out as — and press `,(0,i.jsx)(`strong`,{children:`Apply`}),` again.`]})]}),(0,i.jsx)(`div`,{className:zd,children:(0,i.jsx)(Vu,{name:`EMAIL_FROM`,hint:`an address at your verified domain, like hello@yourbusiness.com`})})]}),(0,i.jsx)(Bd,{onConfirm:e})]})}function Wd(){return(0,i.jsx)(c.Navigate,{to:`/setup`,replace:!0})}function Gd(e){return e.kind===`subscription`?e.active?{label:`Subscription active`,tone:`good`}:{label:`Cancelled`,tone:`quiet`}:e.fullyRefunded?{label:`Refunded`,tone:`bad`}:(e.amountRefunded||0)>0?{label:`Partially refunded`,tone:`bad`}:e.paid?{label:`Paid`,tone:`good`}:{label:`Not paid`,tone:`quiet`}}function Kd(e,t){if(e==null)return`—`;try{return new Intl.NumberFormat(void 0,{style:`currency`,currency:(t||`usd`).toUpperCase()}).format(e)}catch{return`${e} ${(t||``).toUpperCase()}`.trim()}}var qd=e=>e?{description:`Every Pay button on your pages works. Switch it off to pause all of it at once.`,chip:{state:`saved`,label:`On`}}:{description:`No Pay button shows and nothing can be bought. Your pages keep their settings.`,chip:{state:`off`,label:`Off`}},Jd=e=>e?new Date(e*1e3).toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`}):``;function Yd({label:e,tone:t}){return(0,i.jsx)(`span`,{className:`inline-flex items-center h-6 px-2.5 rounded-full border text-[11px] font-bold whitespace-nowrap shrink-0 ${t===`good`?`text-emerald-500 bg-emerald-500/10 border-emerald-500/20`:t===`bad`?`text-red-500 bg-red-500/10 border-red-500/20`:`text-foreground/50 bg-foreground/[0.04] border-[var(--panel-border)]`}`,children:e})}function Xd(){let{user:e}=t.na(),{status:n,error:a,reread:o}=ad(),[s,c]=(0,r.useState)(!1),[l,u]=(0,r.useState)(!1),[d,f]=(0,r.useState)(null),[p,m]=(0,r.useState)(``),[h,g]=(0,r.useState)([]),[_,v]=(0,r.useState)([]),[y,b]=(0,r.useState)(!1),[x,S]=(0,r.useState)(``),[C,w]=(0,r.useState)(!1),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(``),k=$u(`payments`),[A,j]=(0,r.useState)(``),M=qd(k.on),N=(0,r.useCallback)(async t=>{let n=e?await e.getIdToken():``,r=await fetch(t,{headers:n?{Authorization:`Bearer ${n}`}:void 0}),i=await r.json().catch(()=>({}));if(!r.ok||i?.success===!1)throw Error(i?.error||`The server could not answer.`);return i},[e]),P=()=>{c(!1),o().then(()=>u(!0))},F=(0,r.useCallback)((e,t)=>{let n=e.charges||[],r=e.subscriptions||[];g(e=>t?[...e,...n]:n),v(e=>t?[...e,...r]:r),w(!!(e.chargesHasMore||e.subscriptionsHasMore))},[]);(0,r.useEffect)(()=>{if(!n?.configured||!e)return;let t=!1;return N(`/api/payments/products`).then(e=>{t||f(e.products||[])}).catch(e=>{t||m(e.message)}),N(`/api/payments/orders`).then(e=>{t||(F(e,!1),b(!0))}).catch(e=>{t||(S(e.message),b(!0))}),()=>{t=!0}},[n?.configured,e,N,F]);let I=async()=>{E(!0);try{let e=new URLSearchParams,t=h[h.length-1],n=_[_.length-1];t&&e.set(`starting_after`,t.id),n&&e.set(`subscriptions_after`,n.id),F(await N(`/api/payments/orders?${e}`),!0)}catch(e){S(e.message)}E(!1)},L=e=>{navigator.clipboard?.writeText(e),O(e),setTimeout(()=>O(``),2e3)},R=[...h,..._].sort((e,t)=>(t.created||0)-(e.created||0)),z=(d||[]).flatMap(e=>e.prices),B=n?.mode===`live`?`https://dashboard.stripe.com/products`:`https://dashboard.stripe.com/test/products`,V=!!(n&&!n.configured);return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,i.jsx)(Ce,{children:`Payments`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/payments`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-5 md:p-8 shadow-2xl relative bg-background flex flex-col min-h-[600px]`,children:!n&&!a?(0,i.jsx)(`div`,{className:`flex items-center justify-center flex-1 text-foreground/40 py-16`,children:(0,i.jsx)(t.ti,{className:`w-6 h-6 animate-spin text-accent`})}):V?(0,i.jsx)(Vd,{icon:t.wi,title:`Connect Stripe`,description:`This app is not taking payments yet.`,stepsDescription:`Three steps — about five minutes, with pretend money until you say otherwise.`,button:`Set up payments`,secret:`STRIPE_SECRET_KEY`,open:s,onOpen:()=>c(!0),confirmed:l,steps:(0,i.jsx)(Hd,{onConfirm:P}),children:(0,i.jsx)(t.st,{children:`Payments run through Stripe, and connecting it is one pasted key — no code, no terminal. Once it is in, this screen fills itself: what you sell, and every payment as it happens.`})}):(0,i.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[n?.mode===`live`&&(0,i.jsxs)(`div`,{className:`flex items-center gap-3 rounded-2xl border border-red-500/25 bg-red-500/[0.06] px-4 py-3`,children:[(0,i.jsx)(t.Er,{className:`w-4 h-4 text-red-500 shrink-0`}),(0,i.jsx)(`p`,{className:`text-[12.5px] font-semibold text-red-500 leading-snug`,children:`Live mode — real cards are being charged. Every payment on this screen is real money.`})]}),(0,i.jsx)(t.ut,{icon:t.Hr,title:`Take payments`,description:M.description,chip:M.chip,enabled:k.loading?null:k.on,onChange:async e=>j(await k.set(e)||``),children:A?(0,i.jsx)(t.st,{tone:`error`,children:A}):null}),(0,i.jsx)(t.at,{icon:t.Wr,title:`Connection`,description:`Which Stripe account this app is running on.`,defaultOpen:!n?.configured,actions:a?(0,i.jsx)(t.lt,{state:`error`,label:`Unreachable`}):(0,i.jsx)(t.lt,{state:`saved`,label:n?.mode===`live`?`Live mode connected`:`Test mode connected`}),children:a?(0,i.jsx)(t.st,{tone:`error`,children:a}):(0,i.jsx)(t.st,{children:n?.mode===`live`?`Connected with a live key. Payments made anywhere on your site are real money.`:`Test mode connected. Your Pay buttons work end to end, but only test cards are accepted and no real money moves. When you are ready for real payments, use Go live below.`})}),(0,i.jsx)(Dd,{}),(0,i.jsx)(fu,{}),(0,i.jsx)(t.at,{icon:t.Ar,title:`In your Stripe account`,description:`The products and prices Stripe has right now — where price ids come from.`,defaultOpen:!1,children:p?(0,i.jsx)(t.st,{tone:`error`,children:p}):d===null?(0,i.jsx)(`div`,{className:`flex items-center justify-center py-6 text-foreground/40`,children:(0,i.jsx)(t.ti,{className:`w-5 h-5 animate-spin text-accent`})}):z.length===0?(0,i.jsxs)(t.st,{children:[`Nothing needs to exist here for one-off payments — a Pay button can name its own amount. Only a subscription needs a price made in Stripe first:`,` `,(0,i.jsx)(`a`,{href:B,target:`_blank`,rel:`noreferrer`,className:`text-accent font-bold hover:underline`,children:`create one in your Stripe dashboard`}),` `,`and it appears here with its id ready to copy.`]}):(0,i.jsx)(`div`,{className:`flex flex-col gap-2.5`,children:z.map(e=>(0,i.jsxs)(`div`,{className:`flex items-center gap-3 px-3.5 py-2.5 ${t.X}`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-bold text-foreground truncate min-w-0 flex-1`,children:e.productName||`Unnamed product`}),(0,i.jsxs)(`span`,{className:`text-[12.5px] font-semibold text-foreground/60 whitespace-nowrap shrink-0`,children:[Kd(e.amount,e.currency),e.interval?` / ${e.interval}`:``]}),(0,i.jsx)(t.Q,{compact:!0,icon:D===e.id?t.zi:t.Ti,title:`Copy the price id for ${e.productName||`this price`}`,onClick:()=>L(e.id),children:D===e.id?`Copied`:`Copy price id`})]},e.id))})}),(0,i.jsx)(t.at,{icon:t.Vr,title:`Payments received`,description:`Every charge and subscription, straight from Stripe.`,defaultOpen:!1,children:x?(0,i.jsx)(t.st,{tone:`error`,children:x}):y?R.length===0?(0,i.jsx)(t.st,{children:`Nothing yet. When someone pays, it lands here on its own — and refunds you make in Stripe show up here too, with nothing to sync.`}):(0,i.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[R.map(e=>{let n=Gd(e);return(0,i.jsxs)(`div`,{className:`flex items-center gap-3 px-3.5 py-2.5 ${t.X}`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0 flex-1`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-bold text-foreground truncate`,children:e.name||e.email||`Someone`}),(0,i.jsxs)(`span`,{className:`text-[11px] text-foreground/45 font-medium truncate`,children:[e.productName||e.description||(e.kind===`subscription`?`Subscription`:`One-off payment`),e.page?` — sold on ${e.page}`:``]})]}),(0,i.jsx)(`span`,{className:`max-sm:hidden text-[11.5px] font-medium text-foreground/45 whitespace-nowrap shrink-0`,children:Jd(e.created)}),(0,i.jsxs)(`span`,{className:`text-[12.5px] font-semibold text-foreground/70 whitespace-nowrap shrink-0`,children:[Kd(e.amount,e.currency),e.kind===`subscription`&&e.interval?` / ${e.interval}`:``]}),(0,i.jsx)(Yd,{label:n.label,tone:n.tone})]},e.id)}),C&&(0,i.jsx)(t.Q,{busy:T,onClick:I,className:`self-center mt-1`,children:`Show older payments`})]}):(0,i.jsx)(`div`,{className:`flex items-center justify-center py-6 text-foreground/40`,children:(0,i.jsx)(t.ti,{className:`w-5 h-5 animate-spin text-accent`})})})]})})]})]})}var Zd=`w-[6.5rem] shrink-0`,Qd=`w-9 h-9 rounded-[var(--btn-radius,0.75rem)] border border-[var(--panel-border)] flex items-center justify-center shrink-0 text-foreground/45 hover:text-red-500 hover:border-red-500/40 hover:bg-red-500/[0.06] active:scale-[0.98] transition-all cursor-pointer`,$d=`date-field h-9 w-[10.5rem] shrink-0 px-3 text-[13px] font-semibold bg-transparent border border-[var(--panel-border)] text-foreground focus:outline-none focus:border-accent transition-colors`,ef={from:`09:00`,to:`13:00`};function tf(e,t){return{upcoming:e.filter(e=>e.date>=t),past:e.filter(e=>e.date<t)}}function nf({row:e,onChange:n,onRemove:r}){let a=e.windows.length===0,o=(t,r)=>n({...e,windows:e.windows.map((e,n)=>n===t?{...e,...r}:e)});return(0,i.jsxs)(`div`,{className:`flex flex-col gap-2 py-2.5`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,i.jsx)(`input`,{type:`date`,value:e.date,"aria-label":`The date`,onChange:t=>n({...e,date:t.target.value}),className:$d,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(`div`,{className:`w-[11rem] shrink-0`,children:(0,i.jsx)(t.sr,{ariaLabel:`${e.date} — how much of it`,value:a?`all`:`some`,options:[{value:`all`,label:`All day`},{value:`some`,label:`Only some hours`}],onChange:t=>n({...e,windows:t===`all`?[]:[ef]}),className:`console-select`,compact:!0,dense:!0,portal:!0,direction:`auto`})}),(0,i.jsx)(`button`,{type:`button`,title:`Remove ${e.date||`this date`}`,"aria-label":`Remove ${e.date||`this date`}`,onClick:r,className:`${Qd} ml-auto`,children:(0,i.jsx)(t._r,{className:`w-3.5 h-3.5`})})]}),!a&&(0,i.jsxs)(`div`,{className:`flex flex-col gap-2 sm:pl-[0.125rem]`,children:[e.windows.map((r,a)=>(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`div`,{className:Zd,children:(0,i.jsx)(t.sr,{ariaLabel:`${e.date} from${a?` (${a+1})`:``}`,value:r.from,options:t.Ot,onChange:e=>o(a,{from:e}),className:`console-select`,compact:!0,portal:!0,direction:`auto`})}),(0,i.jsx)(`span`,{className:`w-3 text-center text-foreground/40 text-[13px] shrink-0 select-none`,children:`–`}),(0,i.jsx)(`div`,{className:Zd,children:(0,i.jsx)(t.sr,{ariaLabel:`${e.date} to${a?` (${a+1})`:``}`,value:r.to,options:t.Tt,onChange:e=>o(a,{to:e}),className:`console-select`,compact:!0,portal:!0,direction:`auto`})}),e.windows.length>1&&(0,i.jsx)(`button`,{type:`button`,title:`Remove these hours on ${e.date}`,"aria-label":`Remove ${e.date} hours ${a+1}`,onClick:()=>n({...e,windows:e.windows.filter((e,t)=>t!==a)}),className:Qd,children:(0,i.jsx)(t._r,{className:`w-3.5 h-3.5`})})]},a)),e.windows.length<2&&(0,i.jsx)(`button`,{type:`button`,onClick:()=>n({...e,windows:[...e.windows,{from:`14:00`,to:`18:00`}]}),className:`self-start h-6 px-1 text-[11.5px] font-semibold text-foreground/45 hover:text-accent transition-colors cursor-pointer`,children:`+ Add a second stretch`})]})]})}function rf({blocked:e,onChange:n,now:a}){let o=t.qn(a?a():new Date),[s,c]=(0,r.useState)(!1),{upcoming:l,past:u}=tf(e,o),d=s?[...u,...l]:l,f=(t,r)=>n(e.map(e=>e===t?r:e));return(0,i.jsx)(t.Z,{label:`Days away`,hint:`Dates this week's hours do not apply to — a holiday, a flight, an afternoon out. Nobody can book them, on any link on these hours.`,children:(0,i.jsxs)(`div`,{className:`flex flex-col divide-y divide-[var(--panel-border)]/60 rounded-2xl border border-[var(--panel-border)]/60 px-4 py-1`,children:[d.length===0?(0,i.jsx)(`p`,{className:`${t.$} py-3`,children:`No days blocked out. Add one for a holiday or a day off.`}):d.map((t,r)=>(0,i.jsx)(nf,{row:t,onChange:e=>f(t,e),onRemove:()=>n(e.filter(e=>e!==t))},`${t.date}-${r}`)),(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 py-2.5`,children:[(0,i.jsx)(t.Q,{icon:t.Ur,compact:!0,title:`Add a day away`,onClick:()=>n([...e,{date:o,windows:[]}]),children:`Add a date`}),u.length>0&&(0,i.jsx)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`h-6 px-1 text-[11.5px] font-semibold text-foreground/45 hover:text-accent transition-colors cursor-pointer`,children:s?`Hide past dates`:`Show ${u.length} past date${u.length===1?``:`s`}`})]})]})})}var af=e=>t.xt.find(t=>t.value===e)?.label||`Short text`;function of({options:e,onChange:n}){return(0,i.jsx)(t.Z,{label:`Choices`,hint:`What people pick from.`,children:(0,i.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.length===0&&(0,i.jsx)(`span`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug px-1`,children:`No choices yet — add the first one.`}),e.map((r,a)=>(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`input`,{type:`text`,value:r,"aria-label":`Choice ${a+1}`,placeholder:`e.g. At my place`,onChange:t=>n(e.map((e,n)=>n===a?t.target.value:e)),className:t.et}),(0,i.jsx)(t.Q,{icon:t._r,tone:`danger`,compact:!0,title:`Remove choice ${a+1}`,onClick:()=>n(e.filter((e,t)=>t!==a)),children:`Remove`})]},a)),(0,i.jsx)(`div`,{children:(0,i.jsx)(t.Q,{icon:t.Ur,onClick:()=>n([...e,``]),children:`Add choice`})})]})})}function sf({question:e,index:n,count:a,siblings:o,fixed:s,onChange:c,onMove:l,onRemove:u}){let[d,f]=(0,r.useState)(!e.label.trim()),p=e.label.trim()||`A new question`;return(0,i.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)]`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2.5 pr-2.5 sm:pr-3.5`,children:[(0,i.jsxs)(`button`,{type:`button`,onClick:()=>f(e=>!e),"aria-expanded":d,className:`flex-1 min-w-0 flex items-center justify-between gap-3 px-4 py-3.5 text-left cursor-pointer`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground/75 truncate`,children:p}),(0,i.jsxs)(`span`,{className:`flex items-center gap-2.5 shrink-0`,children:[(0,i.jsx)(`span`,{className:`${t.$} max-sm:hidden`,children:s?`Always asked`:`${af(e.type)}${e.required?` · must be answered`:``}`}),(0,i.jsx)(t.Ri,{className:`w-3.5 h-3.5 text-foreground/40 shrink-0 transition-transform ${d?`rotate-180`:``}`})]})]}),!s&&(0,i.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-1.5 shrink-0`,children:[(0,i.jsx)(t.Q,{icon:t.Ji,compact:!0,disabled:n===0,title:`Move ${p} up`,onClick:()=>l(-1),children:`Up`}),(0,i.jsx)(t.Q,{icon:t.Qi,compact:!0,disabled:n===a-1,title:`Move ${p} down`,onClick:()=>l(1),children:`Down`}),(0,i.jsx)(`span`,{className:`max-sm:hidden w-px h-5 bg-[var(--panel-border)] mx-0.5`}),(0,i.jsx)(t.Q,{icon:t.Or,tone:`danger`,compact:!0,title:`Remove ${p}`,onClick:u,children:`Remove`})]})]}),d&&(0,i.jsxs)(`div`,{className:`px-4 pb-4 pt-4 border-t border-[var(--panel-border)]/60 flex flex-col gap-4`,children:[(0,i.jsx)(t.ft,{label:`What are you asking?`,hint:s?`The words above the box. Every booking asks this one — you can only change how it is put.`:`The words above the box, as the person booking reads them.`,value:e.label,placeholder:s?`e.g. Who is coming?`:`e.g. What is your phone number?`,onChange:n=>c({...e,label:n,name:s?e.name:t.tn(e,n,o)})}),!s&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.ct,{label:`Kind of answer`,hint:`Sets the box they type into. The example below follows what you pick.`,value:e.type,options:t.xt,allowEmpty:!1,onChange:n=>c({...e,type:n,options:n===`select`?e.options:[],placeholder:t.$t(e,n)})}),(0,i.jsx)(t.mt,{label:`Must be answered`,hint:`On means they cannot book until it is filled in.`,hintWideOnly:!0,enabled:e.required,onChange:t=>c({...e,required:t})})]}),e.type===`select`&&(0,i.jsx)(of,{options:e.options,onChange:t=>c({...e,options:t})}),t.en(e.type)&&(0,i.jsx)(t.ft,{label:`Example answer`,hint:e.type===`tel`?`Shown under the box — a phone box already starts with a dial code, so the example stands below it.`:`Faint grey words inside the empty box.`,value:e.placeholder,placeholder:t.bt[e.type]||`e.g. +1 555 0123`,onChange:t=>c({...e,placeholder:t})})]})]})}function cf({questions:e,onChange:n}){let r=e.filter(e=>t.vn(e.name)),a=e.filter(e=>!t.vn(e.name)),o=e=>n([...r,...e]);return(0,i.jsx)(t.Z,{label:`What does a booking ask for?`,children:(0,i.jsxs)(`div`,{className:`flex flex-col gap-3.5`,children:[r.map(t=>(0,i.jsx)(sf,{question:t,index:0,count:1,siblings:e,fixed:!0,onChange:r=>n(e.map(e=>e.name===t.name?r:e)),onMove:()=>{},onRemove:()=>{}},t.name)),a.map((t,n)=>(0,i.jsx)(sf,{question:t,index:n,count:a.length,siblings:e,onChange:e=>o(a.map((t,r)=>r===n?e:t)),onMove:e=>{let t=n+e;if(t<0||t>=a.length)return;let r=[...a];[r[n],r[t]]=[r[t],r[n]],o(r)},onRemove:()=>o(a.filter((e,t)=>t!==n))},n)),(0,i.jsxs)(`div`,{className:`flex flex-col items-start sm:flex-row sm:items-center gap-3 rounded-2xl border border-dashed border-[var(--panel-border)] px-4 py-3.5`,children:[(0,i.jsx)(t.Q,{icon:t.Ur,title:`Add a question`,onClick:()=>o([...a,t.Vt()]),children:`Add a question`}),a.length===0&&(0,i.jsx)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:`Nothing else is asked — just a name and an email.`})]})]})})}var lf=(e,t,n=72)=>e>=n&&e<=Math.max(n,t*.45);function uf(e,t=340){if(!e)return null;let n=()=>{let t=e.getBoundingClientRect?.(),n=typeof window<`u`&&window.innerHeight||0;t&&n&&lf(t.top,n)||e.scrollIntoView?.({behavior:`smooth`,block:`start`})};return typeof setTimeout==`function`?setTimeout(n,t):(n(),null)}var df=`__new_payment__`;function ff(){let[e,n]=(0,r.useState)([]);return(0,r.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.collection)(t.Da,ji),e=>{let t=[];e.forEach(e=>{e.id!==`_settings`&&t.push(Ui(e.id,e.data()))}),n(t.filter(e=>e.kind===`once`).sort((e,t)=>(e.createdAt||0)-(t.createdAt||0)))},()=>n([]));return()=>e()},[]),e}function pf({service:e,what:n,path:r,screen:a,children:o}){return e.loading?null:e.configured?e.on?(0,i.jsx)(i.Fragment,{children:o}):null:(0,i.jsxs)(`div`,{className:`rounded-2xl border border-accent/25 bg-accent/[0.05] px-4 py-3.5 flex flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[(0,i.jsxs)(`span`,{className:`text-[13px] font-medium text-foreground/70`,children:[`You do not have `,n,` set up yet.`]}),(0,i.jsxs)(c.Link,{to:r,className:`inline-flex items-center gap-1 text-[12px] font-bold text-accent hover:underline whitespace-nowrap`,children:[`Set it up on the `,a,` screen`,(0,i.jsx)(t.Xi,{className:`w-3 h-3`})]})]})}function mf({value:e,products:n,meetingName:a,canCreate:o,onChange:s,onCreate:c}){let[l,u]=(0,r.useState)(!1),[d,f]=(0,r.useState)(``),[p,m]=(0,r.useState)(``),[h,g]=(0,r.useState)(!1),_=[...n.map(e=>({value:e.id,label:`${Yi(e)} — ${Li(e).map(e=>e.amount).filter(Boolean).join(` + `)||`no price yet`}`})),...o?[{value:df,label:`+ A new one-time payment`}]:[]],v=n.find(t=>t.id===e),y=d.trim()&&Ri(d)===null?`Just a number, like 25.`:void 0;return(0,i.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,i.jsx)(t.ct,{label:`Payment for this meeting`,hint:v?`Taken on the booking page before the time is confirmed. Its price and its link are on the Payments screen.`:o?`Optional. A one-time payment taken on the booking page before the time is confirmed.`:n.length?`Optional. One of the payments your admin set up, taken on the booking page before the time is confirmed.`:`Your admin has not set up a payment to charge for a meeting yet.`,value:l?df:e,placeholder:`No payment`,options:_,onChange:e=>{if(e===`__new_payment__`){u(!0);return}u(!1),s(e)}}),l&&(0,i.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)]/60 px-4 py-3.5 flex flex-col gap-3`,children:[(0,i.jsx)(t.ft,{label:`The price`,hint:`Just the number — 25 charges 25 in your Stripe account's currency. The payment is called ${a} and appears on the Payments screen too.`,value:d,onChange:e=>{f(e),p&&m(``)},placeholder:`25`,error:p||y}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(t.Q,{icon:t.Ur,busy:h,onClick:async()=>{if(Ri(d)===null){m(`Just a number for the price, like 25.`);return}m(``),g(!0);let e=await c(a,d.trim());if(g(!1),e){m(e);return}u(!1),f(``)},children:`Create it`}),(0,i.jsx)(t.Q,{onClick:()=>{u(!1),m(``),f(``)},children:`Never mind`})]})]})]})}function hf({link:e,onChange:n}){return(0,i.jsx)(t.Z,{label:`Emails about bookings`,hint:`Sent the moment a time is taken. Every booking is in your Inbox and on the calendar regardless.`,children:(0,i.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-2xl border border-[var(--panel-border)]/60 px-4 py-3.5`,children:[(0,i.jsx)(t.mt,{label:`Email me when someone books`,hint:`A note at your address — the sale alert, when they paid.`,hintWideOnly:!0,enabled:e.notifyOwner,onChange:e=>n({notifyOwner:e})}),(0,i.jsx)(t.mt,{label:`Email them a confirmation`,hint:`Their receipt when they pay. For a free booking, a note that the time is theirs — to people who book signed in.`,hintWideOnly:!0,enabled:e.confirmBooker,onChange:e=>n({confirmBooker:e})})]})})}var gf=e=>{let n={...t.A(t.I(),e),createdAt:Date.now()};return{...n,name:t.Rt(n),description:t.Lt(n)}};function _f({link:e,schedules:n,products:r,services:a,isAdmin:o=!0,onChange:s,onCreatePayment:c}){let l=n.find(t=>t.id===e.scheduleId),u=t=>s({...e,...t}),d=t.N(e,l),f=l?t.j(e,l):null,p=n=>{let r={...e,...n};return{...n,...e.name.trim()===t.Rt(e)?{name:t.Rt(r)}:{},...e.description.trim()===t.Lt(e)?{description:t.Lt(r)}:{}}};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.ct,{label:`Which hours is it booked in?`,hint:`Change the hours and every meeting booked in them changes with it — one holiday, entered once, closes them all.`,value:e.scheduleId,options:n.map(e=>({value:e.id,label:t.pn(e)})),allowEmpty:!1,onChange:t=>{let r=n.find(e=>e.id===t);if(!r)return;let i=!l||e.memberName.trim()===l.memberName.trim();u(p({scheduleId:r.id,memberId:r.memberId,...i?{memberName:r.memberName}:{}}))}}),(0,i.jsx)(t.ft,{label:`What is it called?`,hint:`Visitors read this on the booking page. It starts named after its length — call it whatever you like. Left blank it goes back to ${t.Rt(e)}.`,value:e.name,onChange:e=>u({name:e}),placeholder:t.Rt(e)}),(0,i.jsx)(t.dt,{label:`A line or two about it`,hint:`Visitors read it under the name — what it is for, what to bring, what happens after. Emptied, the booking page simply shows none.`,value:e.description,onChange:e=>u({description:e}),placeholder:`A first conversation about what you need and how I can help.`}),(0,i.jsx)(t.ft,{label:`The name visitors see`,value:e.memberName,onChange:e=>u(p({memberName:e})),placeholder:`Anna`}),(0,i.jsx)(t.ct,{label:`How long is one booking?`,value:String(e.slotMinutes),options:t.Mt,allowEmpty:!1,onChange:e=>u(p({slotMinutes:Number(e)}))}),(0,i.jsx)(t.ct,{label:`How far ahead can people book?`,value:String(e.horizonDays),options:t.kt,allowEmpty:!1,onChange:e=>u({horizonDays:Number(e)})}),(0,i.jsx)(t.ct,{label:`How much notice do you need?`,value:String(e.noticeHours),options:t.At,allowEmpty:!1,onChange:e=>u({noticeHours:Number(e)})}),(0,i.jsx)(cf,{questions:e.questions,onChange:e=>u({questions:e})}),(0,i.jsx)(pf,{service:a.payments,what:`Stripe`,path:`/payments`,screen:`Payments`,children:(0,i.jsx)(mf,{value:e.paymentId,products:r,meetingName:t.F(e),canCreate:o,onChange:e=>u({paymentId:e}),onCreate:async(e,t)=>{let n=await c(e,t);return n&&n.startsWith(`p_`)?(u({paymentId:n}),null):n||`The payment could not be made — make sure you are signed in as an admin and try again.`}})}),(0,i.jsx)(pf,{service:a.email,what:`emails`,path:`/email`,screen:`Email`,children:(0,i.jsx)(hf,{link:e,onChange:u})}),(0,i.jsx)(t.Z,{label:`Booking link`,hint:f&&!d&&e.enabled?`Send it to anyone. They see the free times in their own time zone, pick one and book — and pay first, when a payment is attached.`:`The link opens once the meeting is complete and turned on.`,children:(0,i.jsx)(eu,{title:t.F(e),path:t.Qt(e.id)})}),(0,i.jsx)(`div`,{className:`pt-1`,children:d?e.enabled?(0,i.jsxs)(`span`,{className:`text-[11.5px] font-semibold text-amber-500`,children:[`Turned on, but not bookable yet — `,d]}):(0,i.jsx)(`span`,{className:t.$,children:d}):e.enabled?(0,i.jsx)(`span`,{className:`text-[11.5px] font-semibold text-emerald-500`,children:`Bookable — send the link, pick it on a page under Booking on this page, or add a Pick-a-time question to a form.`}):(0,i.jsx)(`span`,{className:t.$,children:`Complete — flip the switch at the top of the row to offer it.`})})]})}function vf({link:e,schedules:n,products:a,services:o,isAdmin:s=!0,open:c,fresh:l,error:u,onToggle:d,onChange:f,onRemove:p,onCreatePayment:m}){let h=n.find(t=>t.id===e.scheduleId),g=t.M(e,h),[_,v]=(0,r.useState)(!1),y=t.F(e),b=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!l)return;let e=uf(b.current);return()=>{e&&clearTimeout(e)}},[l]),(0,i.jsxs)(`div`,{ref:b,className:`scroll-mt-4 rounded-2xl border border-[var(--panel-border)]`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-2.5 pr-3`,children:[(0,i.jsxs)(`button`,{type:`button`,onClick:d,"aria-expanded":c,className:`flex-1 min-w-0 flex items-center justify-between gap-3 px-4 py-3 text-left cursor-pointer`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground/75 truncate`,children:t.P(e,h)}),(0,i.jsxs)(`span`,{className:`flex items-center gap-2.5 shrink-0`,children:[(0,i.jsx)(`span`,{className:`max-sm:hidden`,children:(0,i.jsx)(t.lt,{state:g.state,label:g.label})}),(0,i.jsx)(t.Ri,{className:`w-3.5 h-3.5 text-foreground/40 shrink-0 transition-transform ${c?`rotate-180`:``}`})]})]}),(0,i.jsx)(t.pt,{enabled:e.enabled,onChange:t=>f({...e,enabled:t}),label:`${y} — can be booked`}),(0,i.jsx)(t.Q,{icon:t.Or,tone:`danger`,compact:!0,title:`Remove ${y}`,onClick:()=>v(!0),children:`Remove`})]}),(0,i.jsx)(Ve,{isOpen:_,title:`Remove ${y}?`,message:`Its booking link stops working and it leaves every page and form it was picked on. The hours it was booked in stay, and so do the bookings already taken.`,confirmText:`Yes, remove`,cancelText:`Keep it`,onCancel:()=>v(!1),onConfirm:()=>{v(!1),p()}}),c&&(0,i.jsx)(`div`,{className:`px-4 pb-4 pt-4 border-t border-[var(--panel-border)]/60 flex flex-col gap-4`,children:(0,i.jsx)(_f,{link:e,schedules:n,products:a,services:o,isAdmin:s,onChange:f,onCreatePayment:m})}),u&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 px-4 pb-3`,children:u})]})}function yf({isAdmin:e=!0}={}){let{user:n}=t.na(),{loading:a,docs:s}=t.b(),c=ff(),l={payments:cd(`payments`),email:cd(`email`)},[u,d]=(0,r.useState)({}),[f,p]=(0,r.useState)([]),[m,h]=(0,r.useState)(null),[g,_]=(0,r.useState)(null),[v,y]=(0,r.useState)({}),b=(0,r.useRef)(new Map),x=n?.uid||``,S=(0,r.useMemo)(()=>[...e?s.schedules:s.schedules.filter(e=>e.memberId===x)].sort((e,t)=>Number(t.memberId===x)-Number(e.memberId===x)),[s.schedules,e,x]),C=(0,r.useMemo)(()=>{let t=new Map(s.links.map(e=>[e.id,e]));for(let e of Object.values(u))t.set(e.id,e);for(let e of f)t.delete(e);return[...t.values()].filter(t=>e||t.memberId===x).sort((e,t)=>Number(t.memberId===x)-Number(e.memberId===x)||(e.createdAt||0)-(t.createdAt||0)||e.id.localeCompare(t.id))},[s.links,u,f,e,x]),w=e=>{let n=b.current.get(e.id);n&&clearTimeout(n),b.current.set(e.id,setTimeout(async()=>{b.current.delete(e.id);let n=await t.d(e);y(t=>{let r={...t};return n?r[e.id]=n:delete r[e.id],r})},600))},T=e=>{d(t=>({...t,[e.id]:e})),w(e)},E=()=>{let e=S.find(e=>e.memberId===x)||S[0];if(!e)return;let t=gf(e);d(e=>({...e,[t.id]:t})),h(t.id),_(t.id),w(t)},D=async e=>{let n=b.current.get(e);n&&(clearTimeout(n),b.current.delete(e)),d(t=>{let n={...t};return delete n[e],n}),p(t=>[...t,e]),m===e&&h(null);let r=await t.l(e);r&&(p(t=>t.filter(t=>t!==e)),y(t=>({...t,[e]:r})))},O=async(e,n)=>{let r={...Ii(`p_${Date.now().toString(36)}`),kind:`once`,items:[{name:e,amount:n}]};try{let{id:e,...n}=r;return await(0,o.setDoc)((0,o.doc)(t.Da,ji,e),n),e}catch(e){return console.error(`Could not make the payment`,e),null}};return(0,i.jsx)(t.at,{icon:t.ii,title:`Booking links`,description:`One per kind of meeting — pick the hours it is booked in, say how long it lasts and what it asks, and send the link.`,actions:!a&&S.length>0?({open:e})=>(0,i.jsx)(t.Q,{icon:t.Ur,compact:!0,title:`Add a booking link`,onClick:()=>{e(),E()},children:`Add a booking link`}):void 0,children:(0,i.jsx)(`div`,{className:`flex flex-col gap-3`,children:a?(0,i.jsx)(`p`,{className:t.$,children:`Loading your booking links…`}):S.length===0?(0,i.jsx)(`p`,{className:`${t.$} px-1`,children:`Add a schedule above first — a booking link is a meeting booked in somebody's hours, so there have to be hours to put it on.`}):C.length===0?(0,i.jsxs)(`p`,{className:`${t.$} px-1`,children:[`No booking link yet — press Add a booking link. It is what turns `,t.mn(S[0]),` into something people can book.`]}):C.map(t=>(0,i.jsx)(vf,{link:t,schedules:S,products:c,services:l,isAdmin:e,open:m===t.id,fresh:g===t.id,error:v[t.id],onToggle:()=>h(m===t.id?null:t.id),onChange:T,onRemove:()=>D(t.id),onCreatePayment:O},t.id))})})}var bf=(e,n=`host`)=>e.heldOnly?`Held time`:n===`booker`?e.scheduleName.trim()||`A meeting`:t.cn(e),xf=(e,t=`host`)=>e.heldOnly?`Held with no booking behind it`:e.own?`Your own event`:t===`booker`?e.memberName.trim()?`With ${e.memberName.trim()}`:`Booked`:e.scheduleName||e.email||`Booked`,Sf=(e,n=`host`)=>n===`booker`&&!e.heldOnly?t.Yt(e):bf(e,n),Cf=e=>!e.pending||e.cancelled||e.own||e.heldOnly?``:e.partySize>1?`${e.partyAccepted} of ${e.partySize}`:`Pending`;function wf({value:e,onChange:n}){return(0,i.jsx)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:t.Et.map(r=>{let a=r.value===e;return(0,i.jsx)(`button`,{type:`button`,title:r.label,"aria-label":r.label,"aria-pressed":a,onClick:()=>n(r.value),className:`w-8 h-8 rounded-full transition-all cursor-pointer active:scale-95 flex items-center justify-center ${r.value?`border-2`:`border-2 border-dashed`} ${a?`scale-105`:`hover:scale-105`}`,style:{background:t.ln(r.value,a?55:30),borderColor:a?t.sn(r.value):t.ln(r.value,40)},children:a&&(0,i.jsx)(`span`,{className:`w-2 h-2 rounded-full`,style:{background:t.sn(r.value)}})},r.value||`theme`)})})}function Tf({className:e=``}){return(0,i.jsx)(`span`,{className:`inline-flex items-center h-[18px] px-1.5 rounded-md shrink-0 border border-red-500/25 bg-red-500/10 text-[10px] font-bold uppercase tracking-[0.08em] text-red-500/90 ${e}`,children:`Cancelled`})}function Ef({label:e=`Pending`,className:t=``}){return(0,i.jsx)(`span`,{title:`Waiting to be accepted`,className:`inline-flex items-center h-[18px] px-1.5 rounded-md shrink-0 border border-amber-500/25 bg-amber-500/10 text-[10px] font-bold uppercase tracking-[0.08em] text-amber-600 dark:text-amber-400 ${t}`,children:e})}function Df({className:e=``}){return(0,i.jsx)(`span`,{title:`Held with nothing booked`,className:`inline-flex items-center h-[18px] px-1.5 rounded-md shrink-0 border border-[var(--panel-border)] bg-foreground/[0.04] text-[10px] font-bold uppercase tracking-[0.08em] text-foreground/45 ${e}`,children:`Held`})}function Of({booking:e,zone:n,chip:r,withMember:a=!1,side:o=`host`,onOpen:s,now:c}){let l=e.end<(c?c():new Date).toISOString(),u=e.cancelled,d=Cf(e),f=e.color;return(0,i.jsxs)(`button`,{type:`button`,onClick:s,"aria-label":`${t.dn(new Date(e.start),n)} — ${bf(e,o)}${u?` (cancelled)`:``}`,className:`group relative w-full text-left rounded-2xl border overflow-hidden flex items-stretch gap-2.5 p-2.5 transition-all cursor-pointer active:scale-[0.99] ${l&&!u?`opacity-60`:``} ${u||e.heldOnly?`border-dashed border-[var(--panel-border)]/60 bg-foreground/[0.02]`:``}`,style:u||e.heldOnly?void 0:{background:t.ln(f,7),borderColor:t.ln(f,26)},children:[(0,i.jsx)(`span`,{"aria-hidden":!0,className:`w-1 rounded-full shrink-0 ${u||e.heldOnly?`bg-foreground/15`:``}`,style:u||e.heldOnly?void 0:{background:t.ln(f,85)}}),(0,i.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-0 bg-foreground/0 group-hover:bg-foreground/[0.04] transition-colors`}),(0,i.jsxs)(`span`,{className:`relative flex-1 min-w-0 flex flex-col gap-0.5 py-0.5`,children:[(0,i.jsxs)(`span`,{className:`flex items-baseline gap-2 min-w-0`,children:[(0,i.jsx)(`span`,{className:`text-[12.5px] font-bold tabular-nums shrink-0 ${u?`text-foreground/45 line-through`:`text-foreground`}`,children:t.dn(new Date(e.start),n)}),(0,i.jsx)(`span`,{className:`text-[12.5px] font-semibold truncate ${u?`text-foreground/45 line-through`:`text-foreground/80`}`,children:bf(e,o)})]}),(0,i.jsxs)(`span`,{className:`flex items-center justify-between gap-2 min-w-0`,children:[(0,i.jsx)(`span`,{className:`text-[11.5px] font-medium text-foreground/45 truncate`,children:a&&e.memberName?`${e.memberName} · ${xf(e,o)}`:xf(e,o)}),u?(0,i.jsx)(Tf,{}):e.heldOnly?(0,i.jsx)(Df,{}):d?(0,i.jsx)(Ef,{label:d}):r&&(0,i.jsx)(t.lt,{state:r.state,label:r.label})]})]})]})}var kf=e=>{let t=e.replace(/_/g,` `).trim();return t.charAt(0).toUpperCase()+t.slice(1)};function Af(e,t){let n=e.memberName.trim();if(e.partySize>1){let n=`${e.partyAccepted} of ${e.partySize} have accepted.`;return t?`${n} Yours is still to come.`:n}return t?`This is waiting for you to accept.`:n?`Waiting for ${n} to accept.`:`Waiting to be accepted.`}function jf(e){let t=e.memberName.trim();return e.partySize>1?e.partyAccepted>0?`${e.partyAccepted} of ${e.partySize} have confirmed so far. You will hear once they all have.`:`Waiting to be confirmed. You will hear as soon as it is.`:t?`Waiting for ${t} to confirm. You will hear as soon as they do.`:`Waiting to be confirmed. You will hear as soon as it is.`}function Mf({open:e,onClose:n,children:a}){return(0,r.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,n]),(0,i.jsx)(t.pr,{children:e&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:n,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(0,i.jsx)(t.fr.div,{role:`dialog`,"aria-modal":`true`,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-[420px] max-h-[85vh] overflow-y-auto styled-scrollbars-mini p-5 sm:p-6 rounded-3xl glass-popover border border-[var(--panel-border)] shadow-2xl relative z-10 text-left`,children:a})]})})}function Nf({color:e,title:n,line:r,cancelled:a,onClose:o}){return(0,i.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,i.jsx)(`span`,{"aria-hidden":!0,className:`w-1 self-stretch rounded-full shrink-0 ${a?`bg-foreground/15`:``}`,style:a?void 0:{background:t.ln(e,85)}}),(0,i.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,i.jsx)(`h3`,{className:`text-[17px] font-extrabold tracking-tight leading-tight break-words ${a?`text-foreground/50 line-through`:`text-foreground`}`,children:n}),a&&(0,i.jsx)(Tf,{})]}),(0,i.jsx)(`p`,{className:`text-[12.5px] font-medium text-foreground/50 leading-snug mt-0.5`,children:r})]}),(0,i.jsx)(`button`,{type:`button`,onClick:o,"aria-label":`Close`,className:t.R,children:(0,i.jsx)(t._r,{className:`w-4 h-4`})})]})}function Pf({label:e,children:t}){return(0,i.jsxs)(`div`,{className:`flex items-start justify-between gap-3 px-3.5 py-2.5`,children:[(0,i.jsx)(`span`,{className:`text-[12px] font-medium text-foreground/45 shrink-0`,children:e}),(0,i.jsx)(`span`,{className:`text-[12.5px] font-semibold text-foreground/80 text-right break-words min-w-0`,children:t})]})}function Ff({booking:e,zone:n,chip:a,me:o=``,side:s=`host`,onClose:c,onColor:l,onAccept:u,onCancel:d,onDelete:f,onRelease:p}){let[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(!1),[v,y]=(0,r.useState)(``),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(``),w=t.Hn(e,n),T=e.end<new Date().toISOString(),E=!e.own&&e.timeZone&&e.timeZone!==n?e.timeZone:``,D=Object.entries(e.answers).filter(([,e])=>e),O=s===`booker`,k=!e.heldOnly&&(D.length>0||!!E||!!a||!O&&!e.own&&(!!e.scheduleName||!!e.email||e.createdAt>0)),A=e.heldOnly,j=!A&&(e.own||e.cancelled||T),M=!O&&!!o&&e.memberId===o,N=Cf(e),P=!!N&&M&&!!u,F=A?`Free this held time`:e.own?`Delete this event`:e.cancelled?`Remove this cancelled booking`:T?`Remove this booking`:N&&M?`Decline this booking`:`Cancel this booking`,I=A?!!p:j&&!!f,L=!j&&!A,R=!!N&&M&&!j;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Mf,{open:!0,onClose:c,children:[(0,i.jsx)(Nf,{color:e.color,title:Sf(e,s),line:`${w.day} · ${w.time}`,cancelled:e.cancelled,onClose:c}),e.cancelled&&(0,i.jsxs)(`div`,{className:`mb-4 px-3.5 py-2.5 rounded-2xl border border-[var(--panel-border)] bg-foreground/[0.03] flex flex-col gap-1.5`,children:[(0,i.jsxs)(`p`,{className:`text-[12.5px] font-medium text-foreground/70 leading-snug`,children:[If(e),` The time is free again — it stays here so you have the record.`]}),!!e.cancelReason&&(0,i.jsxs)(`p`,{className:`text-[12.5px] font-semibold text-foreground/80 leading-snug border-l-2 border-[var(--panel-border)] pl-2.5`,children:[`“`,e.cancelReason,`”`]})]}),!!N&&(0,i.jsxs)(`div`,{className:`mb-4 px-3.5 py-3 rounded-2xl border border-amber-500/25 bg-amber-500/[0.07] flex flex-col gap-2.5`,children:[(0,i.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,i.jsx)(t.ki,{className:`w-4 h-4 shrink-0 mt-[1px] text-amber-600 dark:text-amber-400`,"aria-hidden":!0}),(0,i.jsx)(`p`,{className:`text-[12.5px] font-semibold text-foreground/75 leading-snug flex-1 min-w-0`,children:O?jf(e):Af(e,M)}),e.partySize>1&&(0,i.jsx)(Ef,{label:N})]}),P&&!g&&(0,i.jsxs)(t.cr,{onClick:async()=>{x(!0),C(``);let e=await u();x(!1),e&&C(e)},isLoading:b,className:`py-2 px-4 text-[13px] font-bold rounded-xl self-start`,children:[(0,i.jsx)(t.zi,{className:`w-3.5 h-3.5 shrink-0`,"aria-hidden":!0}),`Accept`]})]}),A&&(0,i.jsx)(`p`,{className:`mb-4 px-3.5 py-2.5 rounded-2xl border border-[var(--panel-border)] bg-foreground/[0.03] text-[12.5px] font-medium text-foreground/70 leading-snug`,children:`This hour is held with no booking behind it — a booking that was started and never finished. Nobody can take the time until it is freed, and there is nothing here to cancel.`}),k&&(0,i.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)]/60 bg-foreground/[0.015] divide-y divide-[var(--panel-border)]/40`,children:[!O&&!e.own&&e.scheduleName&&(0,i.jsx)(Pf,{label:`Meeting`,children:e.scheduleName}),!O&&e.email&&(0,i.jsx)(Pf,{label:`Email`,children:(0,i.jsx)(`a`,{href:`mailto:${e.email}`,className:`text-accent hover:underline break-all`,children:e.email})}),D.map(([e,n])=>(0,i.jsx)(Pf,{label:e===`note`?`Note`:kf(e),children:t.rr(n)?(0,i.jsx)(`span`,{className:`flex flex-col items-end gap-1 min-w-0`,children:t.nr(n).map(e=>(0,i.jsxs)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,title:t.tr(e),className:`inline-flex items-center gap-1.5 max-w-full min-w-0 text-accent hover:underline`,children:[(0,i.jsx)(t.qr,{className:`w-3.5 h-3.5 shrink-0`}),(0,i.jsx)(`span`,{className:`truncate min-w-0`,children:t.tr(e)})]},e))}):n},e)),E&&(0,i.jsxs)(Pf,{label:O?`The time you booked in`:`Their time`,children:[t.dn(new Date(e.start),E),` — `,t.Kn(E)]}),a&&(0,i.jsx)(Pf,{label:`Payment`,children:(0,i.jsx)(t.lt,{state:a.state,label:a.label})}),!O&&!e.own&&e.createdAt>0&&(0,i.jsx)(Pf,{label:`Booked`,children:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}).format(new Date(e.createdAt))})]}),!e.cancelled&&!A&&!!l&&(0,i.jsxs)(`div`,{className:`mt-4 flex flex-col gap-2`,children:[(0,i.jsx)(`span`,{className:`text-[12.5px] sm:text-[13px] font-medium text-foreground/50 select-none ml-1`,children:`Colour`}),(0,i.jsx)(wf,{value:e.color,onChange:async e=>{C(``);let t=await l(e);t&&C(t)}}),(0,i.jsx)(`p`,{className:`text-[11px] font-medium text-foreground/40 leading-snug ml-1 mt-0.5`,children:`Shown on the calendar and in the day beside it.`})]}),g&&(0,i.jsxs)(`div`,{className:`mt-4 flex flex-col gap-3 p-3.5 rounded-2xl border border-[var(--panel-border)] bg-foreground/[0.02]`,children:[(0,i.jsx)(t.dt,{label:R?`Why are you turning it down?`:O?`Why can you not make it?`:`Why are you cancelling?`,value:v,onChange:y,placeholder:O?`Something has come up — I would like to book another time.`:`Something has come up and I cannot make this time — do book another.`,hint:O?`${e.memberName.trim()||`Whoever you booked with`} will see this.`:`${e.name.trim()||`Whoever booked`} will see this on the meeting.`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,i.jsx)(t.cr,{variant:`secondary`,onClick:()=>{_(!1),C(``)},disabled:b,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:`Keep it`}),(0,i.jsx)(t.cr,{onClick:async()=>{x(!0),C(``);let e=await d(v.trim());if(x(!1),e){C(e);return}_(!1),c()},isLoading:b,disabled:!v.trim(),className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl bg-red-500 hover:bg-red-600 border-none text-white shadow-lg hover:shadow-red-500/20 disabled:opacity-40 disabled:hover:bg-red-500 disabled:hover:shadow-none`,children:R?`Decline it`:`Cancel it`})]})]}),!g&&!L&&!I&&!O&&!A&&(0,i.jsx)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug mt-4 ml-1`,children:`Nothing left to do here — only an admin can take a booking off the calendar for good.`}),!!S&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 mt-3 ml-1`,children:S}),!g&&(0,i.jsxs)(`div`,{className:`mt-5 flex items-center gap-3 ${I||L?`justify-between`:`justify-end`}`,children:[(I||L)&&(0,i.jsx)(t.Q,{icon:I?t.Or:t.Hi,tone:`danger`,title:F,onClick:()=>I?h(!0):_(!0),children:A?`Free the time`:e.own?`Delete`:I?`Remove`:R?`Decline`:`Cancel booking`}),(0,i.jsx)(t.cr,{variant:`secondary`,onClick:c,className:`py-2 px-4 text-[13px] font-bold rounded-xl`,children:`Close`})]})]}),(0,i.jsx)(Ve,{isOpen:m,title:`${F}?`,message:A?`The hour goes back on offer. There is no booking behind it, so nothing else is lost.`:e.own?`It leaves your calendar and the time can be booked again.`:`It goes from the calendar for good, with everything it holds — in every diary it was booked into. This cannot be undone.`,confirmText:A?`Yes, free it`:e.own?`Yes, delete`:`Yes, remove`,cancelText:`Keep it`,isProcessing:b,onCancel:()=>h(!1),onConfirm:async()=>{x(!0);let e=await(A?p?.()??null:f?.()??null);x(!1),h(!1),e?C(e):c()}})]})}function If(e){let t=e.cancelledAt>0?` on ${new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}).format(new Date(e.cancelledAt))}`:``,n=e.cancelledBy.trim();return e.cancelledSide===`booker`?`${n||`The person who booked`} cancelled this${t}.`:e.cancelledSide===`host`?`${n||`Your team`} cancelled this${t}.`:`This booking was cancelled${t}.`}var Lf=(e,n,r,i)=>({title:``,time:e===i?t.Tn(r,n):`09:00`,minutes:`60`,color:``,note:``});function Rf({dateKey:e,dayLabel:n,zone:a,today:o,now:s,onClose:c,onAdd:l}){let[u,d]=(0,r.useState)(()=>Lf(e,a,s?s():new Date,o)),[f,p]=(0,r.useState)(!1),[m,h]=(0,r.useState)(``),g=e=>d(t=>({...t,...e}));return(0,i.jsxs)(Mf,{open:!0,onClose:c,children:[(0,i.jsx)(Nf,{color:u.color,title:u.title.trim()||`Add an event`,line:`${n} · your time, ${t.Kn(a)}`,onClose:c}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-3.5`,children:[(0,i.jsx)(t.ft,{label:`What is it?`,value:u.title,onChange:e=>g({title:e}),placeholder:`Lunch with Sam`,hint:`Leave it empty and the time simply shows as busy.`}),(0,i.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,i.jsx)(t.ct,{label:`Starts at`,value:u.time,onChange:e=>g({time:e}),options:t.jt,allowEmpty:!1}),(0,i.jsx)(t.ct,{label:`Lasts`,value:u.minutes,onChange:e=>g({minutes:e}),options:t.Dt,allowEmpty:!1})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,i.jsx)(`span`,{className:`${t.nt} ml-1`,children:`Colour`}),(0,i.jsx)(wf,{value:u.color,onChange:e=>g({color:e})})]}),(0,i.jsx)(t.dt,{label:`Note`,value:u.note,onChange:e=>g({note:e}),placeholder:`Anything to remember`})]}),(0,i.jsx)(`p`,{className:`text-[11.5px] font-medium text-foreground/40 leading-snug mt-3 ml-1`,children:`Nobody can book this time once it is here.`}),!!m&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 mt-3 ml-1`,children:m}),(0,i.jsxs)(`div`,{className:`mt-5 flex items-center gap-3`,children:[(0,i.jsx)(t.cr,{variant:`secondary`,onClick:c,disabled:f,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:`Cancel`}),(0,i.jsx)(t.cr,{onClick:async()=>{p(!0),h(``);let n=t.Qn(e,u.time,a),r=new Date(n.getTime()+Number(u.minutes)*6e4),i=await l({title:u.title.trim(),start:n.toISOString(),end:r.toISOString(),color:u.color,note:u.note.trim()});p(!1),i?h(i):c()},isLoading:f,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:`Add it`})]})]})}var zf=(e,t)=>new Intl.DateTimeFormat(t,{timeZone:`UTC`,weekday:`short`,day:`numeric`,month:`long`}).format(new Date(`${e}T00:00:00Z`)),Bf=[`M`,`T`,`W`,`T`,`F`,`S`,`S`],Vf=e=>e.slice(0,7),Hf=(e,n,r)=>t.dn(e,n,r).replace(/[\s\u00a0\u202f]+/g,``).toLowerCase();function Uf(e,t=3){return e.length<=t?{shown:e,extra:0}:{shown:e.slice(0,t-1),extra:e.length-(t-1)}}var Wf=(e,t,n=`host`)=>n===`booker`?Sf(e,n):t&&e.memberName?`${bf(e)} · ${e.memberName}`:bf(e);function Gf(e,n){let r=new Map;for(let i of e){let e=t.Zn(new Date(i.start),n).dateKey,a=r.get(e)||[];a.push(i),r.set(e,a)}for(let e of r.values())e.sort((e,t)=>e.start.localeCompare(t.start));return r}function Kf(e,t,n=!0){return!n||!e.paymentId&&!e.paymentSession?null:e.paymentSession?t===void 0?{state:`saving`,label:`Checking payment`}:t?{state:`saved`,label:`Paid`}:{state:`off`,label:`Awaiting payment`}:{state:`off`,label:`Not paid`}}var qf=`h-8 px-3 rounded-xl border border-[var(--panel-border)]/60 inline-flex items-center gap-1.5 text-[12.5px] font-semibold text-foreground/60 hover:text-foreground hover:border-accent/40 hover:bg-foreground/5 active:scale-[0.98] transition-all cursor-pointer`;function Jf({bookings:e,zone:n,paid:a,openBookingId:o,onOpened:s,withMember:c=!1,me:l=``,side:u=`host`,onAccept:d,onCancel:f,onDelete:p,canDelete:m,onColor:h,onRelease:g,onAdd:_,now:v}){let y=t.Zn(v?v():new Date,n).dateKey,b=(0,r.useMemo)(()=>Gf(e,n),[e,n]),[x,S]=(0,r.useState)(Vf(y)),[C,w]=(0,r.useState)(y),[T,E]=(0,r.useState)(null),[D,O]=(0,r.useState)(!1),k=(0,r.useRef)(``);(0,r.useEffect)(()=>{if(!o){k.current=``;return}if(k.current===o)return;let r=e.find(e=>e.id===o);if(!r)return;k.current=o;let i=t.Zn(new Date(r.start),n).dateKey;S(Vf(i)),w(i),E(r.id),s?.()},[o,e,n,s]);let A=t.U(x),j=b.get(C)||[],M=(v?v():new Date).toISOString(),N=zf(C),P=T?e.find(e=>e.id===T):void 0,{ref:F,moreBelow:I}=t.W(j.length,C);return(0,i.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-3 md:gap-4 w-full md:items-stretch`,children:[(0,i.jsxs)(`div`,{className:`${t.B} w-full md:flex-1 min-w-0`,children:[(0,i.jsxs)(`div`,{className:t.V,children:[(0,i.jsx)(`h4`,{className:`text-[14px] font-bold text-foreground tracking-tight truncate`,children:t.wn(x)}),(0,i.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[(0,i.jsx)(`button`,{type:`button`,onClick:()=>{S(Vf(y)),w(y)},className:qf,children:`Today`}),(0,i.jsx)(`button`,{type:`button`,"aria-label":`Previous month`,onClick:()=>S(e=>t.Rn(e,-1)),className:t.R,children:(0,i.jsx)(t.Li,{className:`w-4 h-4`})}),(0,i.jsx)(`button`,{type:`button`,"aria-label":`Next month`,onClick:()=>S(e=>t.Rn(e,1)),className:t.R,children:(0,i.jsx)(t.Ii,{className:`w-4 h-4`})})]})]}),(0,i.jsx)(`div`,{className:`p-2 sm:p-3`,children:(0,i.jsxs)(`div`,{className:`grid grid-cols-7 gap-1`,role:`grid`,"aria-label":t.wn(x),children:[Bf.map((e,t)=>(0,i.jsx)(`div`,{className:`text-center text-[10.5px] font-bold uppercase tracking-wider text-foreground/35 pb-1`,children:e},t)),A.map((e,r)=>{if(!e)return(0,i.jsx)(`div`,{"aria-hidden":!0},`blank-${r}`);let a=b.get(e)||[],{shown:o,extra:s}=Uf(a),l=e===C,d=e===y;return(0,i.jsxs)(`button`,{type:`button`,role:`gridcell`,"aria-label":`${e}${a.length?`, ${a.length} booked`:``}`,"aria-selected":l,onClick:()=>w(e),className:`relative flex flex-col items-center sm:items-stretch justify-center sm:justify-start h-10 sm:h-[86px] rounded-xl sm:p-1 text-left transition-all cursor-pointer border ${l?`border-accent/70 bg-accent/[0.08] shadow-sm shadow-accent/10`:a.length?`border-transparent hover:bg-foreground/[0.05] hover:border-[var(--panel-border)]/60`:`border-transparent hover:bg-foreground/[0.03]`} ${d&&!l?`ring-1 ring-inset ring-accent/45`:``}`,children:[(0,i.jsx)(`span`,{className:`text-[13px] tabular-nums leading-none sm:px-1 sm:pt-0.5 sm:pb-1 ${l||d?`font-bold text-accent`:a.length?`font-bold text-foreground`:`font-semibold text-foreground/35`}`,children:Number(e.slice(8,10))}),(0,i.jsxs)(`span`,{"aria-hidden":!0,className:`max-sm:hidden sm:flex flex-col gap-[2px] w-full min-w-0`,children:[o.map(e=>(0,i.jsxs)(`span`,{className:`flex items-center gap-1 min-w-0 rounded-md pr-1 py-[2px] leading-[1.2] overflow-hidden ${e.end<M&&!e.cancelled?`opacity-50`:``} ${e.cancelled?`bg-foreground/[0.04] line-through`:``}`,style:e.cancelled?void 0:{background:t.ln(e.color,12)},children:[(0,i.jsx)(`span`,{className:`w-[3px] self-stretch rounded-full shrink-0 ${e.cancelled?`bg-foreground/15`:``}`,style:e.cancelled?void 0:{background:t.ln(e.color,85)}}),(0,i.jsx)(`span`,{className:`text-[9.5px] font-bold tabular-nums shrink-0 ${e.cancelled?`text-foreground/40`:`text-foreground/85`}`,children:Hf(new Date(e.start),n)}),(0,i.jsx)(`span`,{className:`text-[9.5px] font-medium truncate ${e.cancelled?`text-foreground/40`:`text-foreground/60`}`,children:Wf(e,c,u)})]},e.id)),s>0&&(0,i.jsxs)(`span`,{className:`px-1 text-[9.5px] font-bold text-foreground/45 leading-[1.2]`,children:[`+`,s,` more`]})]})]},e)})]})})]}),(0,i.jsx)(`div`,{className:`w-full md:w-[320px] shrink-0 md:relative md:min-h-[360px]`,children:(0,i.jsxs)(`div`,{className:`${t.B} flex flex-col md:absolute md:inset-0`,children:[(0,i.jsxs)(`div`,{className:t.V,children:[(0,i.jsx)(`p`,{className:`text-[13px] font-bold text-foreground tracking-tight truncate`,children:N}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[j.length>0&&(0,i.jsxs)(`span`,{className:`text-[11.5px] font-semibold text-foreground/40 tabular-nums max-sm:hidden`,children:[j.length,` `,j.length===1?`event`:`events`]}),_&&(0,i.jsxs)(`button`,{type:`button`,onClick:()=>O(!0),title:`Add an event on ${N}`,className:qf,children:[(0,i.jsx)(t.Ur,{className:`w-3.5 h-3.5 shrink-0`}),`Add`]})]})]}),(0,i.jsxs)(`div`,{className:`relative flex-1 min-h-0`,children:[(0,i.jsx)(`div`,{ref:F,className:`p-3 h-full overflow-y-auto styled-scrollbars-mini flex flex-col gap-2`,children:j.length===0?(0,i.jsxs)(`div`,{className:`flex flex-col items-center justify-center text-center gap-2 py-8 px-2`,children:[(0,i.jsx)(t.Ui,{className:`w-5 h-5 text-foreground/25`,"aria-hidden":!0}),(0,i.jsx)(`p`,{className:`text-[12.5px] font-medium text-foreground/45 leading-relaxed`,children:`Nothing on this day yet.`})]}):j.map(e=>(0,i.jsx)(Of,{booking:e,zone:n,now:v,chip:Kf(e,a?.[e.paymentSession],!!a),withMember:c,side:u,onOpen:()=>E(e.id)},e.id))}),I&&(0,i.jsx)(t.H,{})]})]})}),P&&(0,i.jsx)(Ff,{booking:P,zone:n,chip:Kf(P,a?.[P.paymentSession],!!a),onClose:()=>E(null),me:l,side:u,onColor:h?e=>h(P.id,e):void 0,onAccept:d?()=>d(P):void 0,onCancel:e=>f(P,e),onDelete:p&&(!m||m(P))?()=>p(P):void 0,onRelease:g?()=>g(P):void 0}),D&&_&&(0,i.jsx)(Rf,{dateKey:C,dayLabel:N,zone:n,today:y,now:v,onClose:()=>O(!1),onAdd:_})]})}var Yf=`team`,Xf=e=>`m:${e}`,Zf=`__nobody__`;function Qf(e,n,r){return[{value:`me`,label:`My calendar`},{value:Yf,label:`My team's calendar`},...e.filter(e=>e.id!==r).map(e=>({value:Xf(e.id),label:t.h(e)||e.email,disabled:!n.has(e.id)}))]}var $f=e=>e.startsWith(`m:`)?e.slice(2):``;function ep(e){let[t,n]=(0,r.useState)({});return(0,r.useEffect)(()=>{let r=e.filter(e=>e.paymentSession&&t[e.paymentSession]===void 0);if(!r.length)return;let i=!1;return Promise.all(r.map(async e=>[e.paymentSession,(await ee(e.paymentSession)).paid])).then(e=>{i||n(t=>({...t,...Object.fromEntries(e)}))}),()=>{i=!0}},[e,t]),t}function tp(e,n,r,i=``){if(!e.email)return Promise.resolve();let a=t.Hn(e,e.timeZone||r);return Xa(n,t.ht,e.id,{when:`${a.day}, ${a.time}`,memberName:e.memberName,scheduleName:e.scheduleName,reason:i.trim()}).then(()=>{}).catch(()=>{})}function np(e,t,n){let r=e=>[...new Set(e.map(e=>String(e||``).trim()))].filter(e=>e&&e!==n),i=r([e.memberId,...t.map(e=>e.memberId),...e.copyIds.map(e=>e.split(`__`)[0])]);return{members:i,bookers:r([e.uid,...t.map(e=>e.uid)]).filter(e=>e!==`guest`).filter(e=>!i.includes(e))}}async function rp(e,n,r,i){if(e.own||e.heldOnly)return;let a={title:`Meeting removed`,body:`${t.Yt(e)} · ${t.un(new Date(e.start),i)}`};await tp(e,`booking_cancelled`,i,`The meeting was removed from the calendar.`);let{members:o,bookers:s}=np(e,n,r);await T(o,{...a,link:`/schedule`}),await T(s,{...a,link:`/my-bookings`})}function ip({isAdmin:e}){let{user:n}=t.na(),a=n?.uid||``,o=t.an(),[s,l]=(0,c.useSearchParams)(),u=s.get(`open`)||s.get(`booking`)||``,{schedules:d}=t.S(),{members:f}=t.C(),p=(0,r.useMemo)(()=>new Set(d.map(e=>e.memberId)),[d]),m=(0,r.useMemo)(()=>Qf(f,p,a),[f,p,a]),[h,g]=(0,r.useState)(null);(0,r.useEffect)(()=>{u&&e&&g(e=>e??`team`)},[u,e]);let _=h??`me`,v=new Set(m.filter(e=>!e.disabled).map(e=>e.value)).has(_)?_:`me`,y=$f(v),{loading:b,bookings:x,error:S}=t.g({members:v===`team`?void 0:[y||a||Zf],includePast:!0}),C=ep(x),w=t.x((0,r.useMemo)(()=>(v===`team`?f.map(e=>e.id):[y||a]).filter(Boolean),[v,f,y,a]),(0,r.useMemo)(()=>{let e=new Date;return new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth()-1,1))},[])),[T,E]=(0,r.useState)(()=>Date.now());(0,r.useEffect)(()=>{let e=setInterval(()=>E(Date.now()),6e4);return()=>clearInterval(e)},[]);let D=(0,r.useMemo)(()=>t.O(x),[x]),O=(0,r.useMemo)(()=>{let e=x.map(e=>{let t=D.get(e.id);return t?{...e,...t}:e}),n=e=>{let n=f.find(t=>t.id===e);return d.find(t=>t.memberId===e)?.memberName||(n?t.h(n):``)},r=t.k(w,x,T).map(e=>t.D(e,n(e.memberId)));return r.length?[...e,...r]:e},[x,D,w,T,f,d]),k=y||a,A=f.find(e=>e.id===k),j=d.find(e=>e.memberId===k)?.memberName||(A?t.h(A):``)||(k===a?String(n?.displayName||``):``);return O.length===0?null:(0,i.jsx)(t.at,{icon:t.Ui,title:`Calendar`,description:v===`team`?`Every booking made with your team, and the events they put on their own days — in your time, ${t.Kn(o)}.`:y?`${j||`Their`} calendar, read as they read it — in your time, ${t.Kn(o)}.`:`Every booking made with you, under every schedule of yours — in your time, ${t.Kn(o)}.`,actions:e&&m.length>2?(0,i.jsx)(t.sr,{ariaLabel:`Whose calendar`,value:v,options:m,onChange:g,className:`console-select`,compact:!0,dense:!0,portal:!0,direction:`auto`}):void 0,children:b?(0,i.jsx)(`p`,{className:t.$,children:`Loading the calendar…`}):S?(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 px-1`,children:S}):(0,i.jsx)(Jf,{bookings:O,zone:o,paid:C,openBookingId:u||void 0,onOpened:u?()=>l(e=>(e.delete(`open`),e.delete(`booking`),e),{replace:!0}):void 0,withMember:v===Yf,me:a,onAccept:async e=>{let n=await t.n(e.id);return n||tp(e,`booking_confirmed`,o),n},onCancel:async(e,r)=>{let i=await t.i(e.id,{ids:e.copyIds,reason:r,side:`host`,by:e.memberId===a?j||String(n?.displayName||``):e.memberName,byUid:a});return i||tp(e,`booking_cancelled`,o,r),i},onDelete:async e=>(await rp(e,x,a,o),t.o(e.id,e.copyIds)),canDelete:t=>e||t.own&&t.memberId===a,onRelease:e=>t.s(e.memberId,e.start),onColor:t.p,onAdd:v===`team`?void 0:e=>t.r({...e,memberId:k,memberName:j,timeZone:o})})})}function ap(e,t){if(!e.enabled)return{state:`off`,label:`Off`};if(lo(e,t))return{state:`error`,label:`Unfinished`};let n=e.schedules.length;return{state:`saved`,label:n===1?`1 meeting`:`${n} meetings`}}var op=e=>{let t=e.schedules.length;return`${uo(e)} — ${t===0?`nothing on it yet`:t===1?`1 meeting`:`${t} meetings`}`};function sp({page:e,schedules:n,onChange:r}){return n.length?(0,i.jsx)(t.Z,{label:`Meetings on this page`,hint:`They appear in the order you tick them. A meeting switched off above is kept off the page too.`,children:(0,i.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:n.map(n=>{let a=e.schedules.includes(n.id);return(0,i.jsxs)(`button`,{type:`button`,role:`checkbox`,"aria-checked":a,onClick:()=>r(co(e,n.id)),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl border text-left transition-all cursor-pointer active:scale-[0.995] ${a?`border-accent/45 bg-accent/[0.07]`:`border-[var(--panel-border)]/70 hover:border-accent/30 hover:bg-foreground/[0.03]`}`,children:[(0,i.jsx)(`span`,{"aria-hidden":!0,className:`w-[18px] h-[18px] rounded-[5px] border flex items-center justify-center shrink-0 transition-all ${a?`border-accent bg-accent`:`border-foreground/25`}`,children:a&&(0,i.jsx)(`span`,{className:`w-[7px] h-[7px] rounded-[2px] bg-[var(--button-fg,#fff)]`})}),(0,i.jsx)(`span`,{className:`flex-1 min-w-0 text-[13px] font-semibold text-foreground/80 truncate`,children:t.Fn(n)})]},n.id)})})}):(0,i.jsx)(t.Z,{label:`Meetings on this page`,children:(0,i.jsx)(`p`,{className:`${t.$} px-1`,children:`Make a schedule above first — a page offers the meetings you have set up.`})})}function cp({page:e,taken:n,onRename:a}){let[o,s]=(0,r.useState)(e.id),c=to(o),l=!!c&&c!==e.id&&n.includes(c);return(0,i.jsx)(t.ft,{label:`Its address`,prefix:`/meet/`,value:o,onChange:s,onBlur:()=>{if(!c||l||c===e.id){s(e.id);return}a(c)},placeholder:`anna-bell`,error:l?`Another page already has that address.`:void 0,hint:`Change it and the old link stops working, so change it before you send it out.`})}function lp({page:e,schedules:n,taken:a,open:o,fresh:s,error:c,onToggle:l,onChange:u,onRename:d,onRemove:f}){let[p,m]=(0,r.useState)(!1),h=ap(e,n),g=uo(e),_=lo(e,n),v=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!s)return;let e=uf(v.current);return()=>{e&&clearTimeout(e)}},[s]),(0,i.jsxs)(`div`,{ref:v,className:`scroll-mt-4 rounded-2xl border border-[var(--panel-border)]`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-2.5 pr-3`,children:[(0,i.jsxs)(`button`,{type:`button`,onClick:l,"aria-expanded":o,className:`flex-1 min-w-0 flex items-center justify-between gap-3 px-4 py-3 text-left cursor-pointer`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground/75 truncate`,children:op(e)}),(0,i.jsxs)(`span`,{className:`flex items-center gap-2.5 shrink-0`,children:[(0,i.jsx)(`span`,{className:`max-sm:hidden`,children:(0,i.jsx)(t.lt,{state:h.state,label:h.label})}),(0,i.jsx)(t.Ri,{className:`w-3.5 h-3.5 text-foreground/40 shrink-0 transition-transform ${o?`rotate-180`:``}`})]})]}),(0,i.jsx)(t.pt,{enabled:e.enabled,onChange:t=>u({...e,enabled:t}),label:`${g} — page is live`}),(0,i.jsx)(t.Q,{icon:t.Or,tone:`danger`,compact:!0,title:`Remove ${g}`,onClick:()=>m(!0),children:`Remove`})]}),(0,i.jsx)(Ve,{isOpen:p,title:`Remove ${g}?`,message:`Its link stops working. The meetings on it are untouched and keep their own links, and bookings already taken are kept.`,confirmText:`Yes, remove`,cancelText:`Keep it`,onCancel:()=>m(!1),onConfirm:()=>{m(!1),f()}}),o&&(0,i.jsxs)(`div`,{className:`px-4 pb-4 pt-4 border-t border-[var(--panel-border)]/60 flex flex-col gap-4`,children:[(0,i.jsx)(t.ft,{label:`Name on the page`,value:e.title,onChange:t=>u({...e,title:t}),placeholder:`Anna Bell`,hint:`Usually the name of whoever the page is for.`}),(0,i.jsx)(st,{label:`Photo`,hint:`Shown at the top of the page. A square picture of the person works best.`,value:e.photo,onChange:t=>u({...e,photo:t})}),(0,i.jsx)(t.dt,{label:`About this page`,value:e.intro,onChange:t=>u({...e,intro:t}),rows:3,placeholder:`I help small studios get their bookkeeping straight. Pick a time below and tell me what you need.`}),(0,i.jsx)(sp,{page:e,schedules:n,onChange:u}),(0,i.jsx)(cp,{page:e,taken:a,onRename:d}),_?(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-amber-500 px-1`,children:_}):(0,i.jsx)(eu,{title:g,path:ro(e.id)})]}),c&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 px-4 pb-3`,children:c})]})}function up({schedules:e,myName:n,isAdmin:a=!0,meId:o=``}){let{loading:s,pages:c}=fo(),[l,u]=(0,r.useState)({}),[d,f]=(0,r.useState)([]),[p,m]=(0,r.useState)(null),[h,g]=(0,r.useState)(null),[_,v]=(0,r.useState)({}),y=(0,r.useRef)(new Map),b=new Map(c.map(e=>[e.id,e]));for(let e of Object.values(l))b.set(e.id,e);for(let e of d)b.delete(e);let x=[...b.values()].sort((e,t)=>(e.createdAt||0)-(t.createdAt||0)||e.id.localeCompare(t.id)),S=x.map(e=>e.id),C=ao(x,o,a),w=a?e:e.filter(e=>e.memberId===o),T=e=>{let t=y.current.get(e.id);t&&clearTimeout(t),y.current.set(e.id,setTimeout(async()=>{y.current.delete(e.id);let t=await po(e);v(n=>{let r={...n};return t?r[e.id]=t:delete r[e.id],r})},600))},E=e=>{u(t=>({...t,[e.id]:e})),T(e)},D=()=>{let e=eo(no(n||`my page`,S),n,o);u(t=>({...t,[e.id]:e})),f(t=>t.filter(t=>t!==e.id)),m(e.id),g(e.id),T(e)},O=async(e,t)=>{let n=y.current.get(e.id);n&&(clearTimeout(n),y.current.delete(e.id));let r={...e,id:t};u(n=>{let i={...n};return delete i[e.id],i[t]=r,i}),f(n=>[...n.filter(e=>e!==t),e.id]),p===e.id&&m(t);let i=await ho(e.id,r);i&&v(e=>({...e,[t]:i}))},k=async e=>{let t=y.current.get(e);t&&(clearTimeout(t),y.current.delete(e)),u(t=>{let n={...t};return delete n[e],n}),f(t=>[...t,e]),p===e&&m(null);let n=await mo(e);n&&(f(t=>t.filter(t=>t!==e)),v(t=>({...t,[e]:n})))};return(0,i.jsx)(t.at,{icon:t.ii,title:`Your booking pages`,description:`One link with a photo, a line about you and every meeting you offer.`,actions:({open:e})=>(0,i.jsx)(t.Q,{icon:t.Ur,compact:!0,title:`Create a page`,onClick:()=>{e(),D()},children:`Create a page`}),children:(0,i.jsx)(`div`,{className:`flex flex-col gap-3`,children:s?(0,i.jsx)(`p`,{className:`${t.$} px-1`,children:`Loading pages…`}):C.length===0?(0,i.jsx)(`p`,{className:`${t.$} px-1`,children:`No pages yet. Create one to hand out a single link — a visitor sees your photo, what you do and every meeting you offer, and picks the one they want.`}):C.map(e=>(0,i.jsx)(lp,{page:e,schedules:w,taken:S,open:p===e.id,fresh:h===e.id,error:_[e.id],onToggle:()=>m(t=>t===e.id?null:e.id),onChange:E,onRename:t=>O(e,t),onRemove:()=>k(e.id)},e.id))})})}var dp={from:`09:00`,to:`17:00`},fp=e=>t.gn(e)?{state:`saved`,label:`Ready`}:{state:`off`,label:`In progress`},pp=e=>({...t.Ht(t.L(),e.id,t.h(e),t.an()),name:`Working hours`,enabled:!0,createdAt:Date.now()}),mp=`w-[6.5rem] shrink-0`,hp=`w-9 h-9 rounded-[var(--btn-radius,0.75rem)] border border-[var(--panel-border)] flex items-center justify-center shrink-0 text-foreground/45 hover:text-red-500 hover:border-red-500/40 hover:bg-red-500/[0.06] active:scale-[0.98] transition-all cursor-pointer`;function gp({day:e,windows:n,onChange:r}){let a=n.length>0,o=(e,t)=>r(n.map((n,r)=>r===e?{...n,...t}:n));return(0,i.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-[8.5rem_minmax(0,1fr)] items-start gap-x-4 gap-y-2 py-2.5`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 h-9`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-medium ${a?`text-foreground/80`:`text-foreground/40`}`,children:t.wt[e]}),(0,i.jsx)(t.pt,{enabled:a,onChange:e=>r(e?[dp]:[]),label:`${t.wt[e]} — bookable`})]}),a&&(0,i.jsxs)(`div`,{className:`flex flex-col gap-2 min-w-0`,children:[n.map((a,s)=>(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`div`,{className:mp,children:(0,i.jsx)(t.sr,{ariaLabel:`${t.wt[e]} from${s?` (${s+1})`:``}`,value:a.from,options:t.Ot,onChange:e=>o(s,{from:e}),className:`console-select`,compact:!0,portal:!0,direction:`auto`})}),(0,i.jsx)(`span`,{className:`w-3 text-center text-foreground/40 text-[13px] shrink-0 select-none`,children:`–`}),(0,i.jsx)(`div`,{className:mp,children:(0,i.jsx)(t.sr,{ariaLabel:`${t.wt[e]} to${s?` (${s+1})`:``}`,value:a.to,options:t.Tt,onChange:e=>o(s,{to:e}),className:`console-select`,compact:!0,portal:!0,direction:`auto`})}),n.length>1&&(0,i.jsx)(`button`,{type:`button`,title:`Remove these hours on ${t.wt[e]}`,"aria-label":`Remove ${t.wt[e]} hours ${s+1}`,onClick:()=>r(n.filter((e,t)=>t!==s)),className:hp,children:(0,i.jsx)(t._r,{className:`w-3.5 h-3.5`})})]},s)),n.length<2&&(0,i.jsx)(`button`,{type:`button`,onClick:()=>r([...n,{from:`18:00`,to:`20:00`}]),className:`self-start h-6 px-1 text-[11.5px] font-semibold text-foreground/45 hover:text-accent transition-colors cursor-pointer`,children:`+ Add a second stretch`})]})]})}function _p({schedule:e,onChange:n}){let r=t=>n({...e,...t}),a=t.hn(e);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.ft,{label:`What are these hours called?`,hint:`Only you and your team read this — it is how a booking link names the hours it is booked in. Working hours, Evenings, Studio days.`,value:e.name,onChange:e=>r({name:e}),placeholder:`Working hours`}),(0,i.jsx)(t.Y,{value:e.timeZone,onChange:e=>r({timeZone:e})}),(0,i.jsx)(t.Z,{label:`When`,hint:`The hours on each day, in this person's own time zone. Add a second stretch for a break in the middle. A time booked in any of their hours is taken here too.`,children:(0,i.jsx)(`div`,{className:`flex flex-col divide-y divide-[var(--panel-border)]/60 rounded-2xl border border-[var(--panel-border)]/60 px-4 py-1`,children:t.Ct.map(t=>(0,i.jsx)(gp,{day:t,windows:e.days[t]||[],onChange:n=>r({days:{...e.days,[t]:n}})},t))})}),(0,i.jsx)(rf,{blocked:e.blocked,onChange:e=>r({blocked:e})}),(0,i.jsx)(`div`,{className:`pt-1`,children:a?(0,i.jsxs)(`span`,{className:`text-[11.5px] font-semibold text-amber-500`,children:[`Not usable yet — `,a]}):(0,i.jsx)(`span`,{className:`text-[11.5px] font-semibold text-emerald-500`,children:`Ready — add a booking link below to let people book these hours, or ask for a page built on them.`})})]})}function vp({schedule:e,open:n,stale:a,fresh:o,error:s,onToggle:c,onChange:l,onRemove:u}){let d=fp(e),[f,p]=(0,r.useState)(!1),m=t.mn(e),h=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!o)return;let e=uf(h.current);return()=>{e&&clearTimeout(e)}},[o]),(0,i.jsxs)(`div`,{ref:h,className:`scroll-mt-4 rounded-2xl border border-[var(--panel-border)] ${a?`opacity-60`:``}`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-2.5 pr-3`,children:[(0,i.jsxs)(`button`,{type:`button`,onClick:c,"aria-expanded":n,className:`flex-1 min-w-0 flex items-center justify-between gap-3 px-4 py-3 text-left cursor-pointer`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground/75 truncate`,children:t._n(e)}),(0,i.jsxs)(`span`,{className:`flex items-center gap-2.5 shrink-0`,children:[a?(0,i.jsx)(`span`,{className:`${t.$} max-sm:hidden`,children:`No longer on the team`}):(0,i.jsx)(`span`,{className:`max-sm:hidden`,children:(0,i.jsx)(t.lt,{state:d.state,label:d.label})}),(0,i.jsx)(t.Ri,{className:`w-3.5 h-3.5 text-foreground/40 shrink-0 transition-transform ${n?`rotate-180`:``}`})]})]}),(0,i.jsx)(t.Q,{icon:t.Or,tone:`danger`,compact:!0,title:`Remove ${m}`,onClick:()=>p(!0),children:`Remove`})]}),(0,i.jsx)(Ve,{isOpen:f,title:`Remove ${m}?`,message:a?`They are no longer on the team, so nobody can book them. Bookings already taken are kept.`:`Every booking link booked in these hours stops working, and they leave every page and form they were picked on. Bookings already taken are kept.`,confirmText:`Yes, remove`,cancelText:`Keep it`,onCancel:()=>p(!1),onConfirm:()=>{p(!1),u()}}),n&&(0,i.jsx)(`div`,{className:`px-4 pb-4 pt-4 border-t border-[var(--panel-border)]/60 flex flex-col gap-4`,children:(0,i.jsx)(_p,{schedule:e,onChange:l})}),s&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 px-4 pb-3`,children:s})]})}function yp({name:e,schedules:n,stale:a,open:o,onToggle:s,onAdd:c,openScheduleId:l,freshId:u,errors:d,onToggleSchedule:f,onChange:p,onRemove:m}){let h=a?`No longer on the team`:n.length===0?`No schedules yet`:`${n.length} schedule${n.length===1?``:`s`}`,g=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!o)return;let e=uf(g.current);return()=>{e&&clearTimeout(e)}},[o]),(0,i.jsxs)(`div`,{ref:g,className:`scroll-mt-4 rounded-2xl border border-[var(--panel-border)]`,children:[(0,i.jsxs)(`button`,{type:`button`,onClick:s,"aria-expanded":o,className:`w-full flex items-center justify-between gap-3 px-4 py-3 text-left cursor-pointer`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground/75 truncate`,children:e}),(0,i.jsxs)(`span`,{className:`flex items-center gap-2.5 shrink-0`,children:[(0,i.jsx)(`span`,{className:`${t.$} max-sm:hidden`,children:h}),(0,i.jsx)(t.Ri,{className:`w-3.5 h-3.5 text-foreground/40 shrink-0 transition-transform ${o?`rotate-180`:``}`})]})]}),o&&(0,i.jsxs)(`div`,{className:`px-4 pb-4 pt-4 border-t border-[var(--panel-border)]/60 flex flex-col gap-3`,children:[n.map(e=>(0,i.jsx)(vp,{schedule:e,stale:a,fresh:u===e.id,open:l===e.id,error:d[e.id],onToggle:()=>f(e.id),onChange:p,onRemove:()=>m(e.id)},e.id)),a?n.length===0&&(0,i.jsxs)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:[`No schedule yet for `,e,`.`]}):(0,i.jsxs)(`div`,{className:`flex flex-col items-start sm:flex-row sm:items-center gap-3 rounded-2xl border border-dashed border-[var(--panel-border)] px-4 py-3`,children:[(0,i.jsx)(t.Q,{icon:t.Ur,title:`Add a schedule for ${e}`,onClick:c,children:`Add a schedule`}),n.length===0&&(0,i.jsxs)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:[`No schedule yet for `,e,`.`]})]})]})]})}var bp=e=>({id:e.uid,name:String(e.displayName||``),email:String(e.email||``),role:`admin`});function xp({isAdmin:e=!0}={}){let{user:n}=t.na(),{loading:a,members:o}=t.C(),{loading:s,docs:l}=t.b(),u=l.schedules,[d,f]=(0,r.useState)({}),[p,m]=(0,r.useState)([]),[h,g]=(0,r.useState)(null),[_,v]=(0,r.useState)(null),[y,b]=(0,r.useState)(null),[x,S]=(0,r.useState)({}),C=(0,r.useRef)(new Map),w=(0,r.useMemo)(()=>{let e=new Map(u.map(e=>[e.id,e]));for(let t of Object.values(d))e.set(t.id,t);for(let t of p)e.delete(t);return[...e.values()].sort((e,t)=>(e.createdAt||0)-(t.createdAt||0)||e.id.localeCompare(t.id))},[u,d,p]),T=e=>{let n=C.current.get(e.id);n&&clearTimeout(n),C.current.set(e.id,setTimeout(async()=>{C.current.delete(e.id);let n=await t.f(e);S(t=>{let r={...t};return n?r[e.id]=n:delete r[e.id],r})},600))},E=e=>{f(t=>({...t,[e.id]:e})),T(e)},D=(0,r.useMemo)(()=>n?o.find(e=>e.id===n.uid)||bp(n):null,[n,o]),O=(0,r.useMemo)(()=>D&&!o.some(e=>e.id===D.id)?[D,...o]:o,[D,o]),k=(0,r.useRef)(!1),[A,j]=(0,r.useState)(``),M=(0,r.useMemo)(()=>l.schedules.filter(t=>l.legacyIds.includes(t.id)&&(e||t.memberId===D?.id)),[l.schedules,l.legacyIds,e,D]);(0,r.useEffect)(()=>{k.current||M.length===0||(k.current=!0,t.m(M).then(e=>{e&&j(e)}))},[M]);let N=e=>{let t=pp(e);f(e=>({...e,[t.id]:t})),g(t.id),v(t.id),D&&e.id!==D.id&&b(e.id),T(t)},P=()=>{D&&N(D)},F=async e=>{let n=C.current.get(e);n&&(clearTimeout(n),C.current.delete(e)),f(t=>{let n={...t};return delete n[e],n}),m(t=>[...t,e]),h===e&&g(null);let r=await t.u(e);r&&(m(t=>t.filter(t=>t!==e)),S(t=>({...t,[e]:r})))},I=a||s,L=new Set(O.map(e=>e.id)),R=D?w.filter(e=>e.memberId===D.id):[],z=(0,r.useMemo)(()=>{if(!D)return[];let e=new Map;for(let t of w){if(t.memberId===D.id)continue;let n=e.get(t.memberId);n?n.push(t):e.set(t.memberId,[t])}let n=[];for(let r of O)r.id!==D.id&&(n.push({id:r.id,name:t.h(r)||r.email,stale:!1,schedules:e.get(r.id)||[]}),e.delete(r.id));for(let[t,r]of e)n.push({id:t,name:r[0].memberName.trim()||`Someone no longer on the team`,stale:!0,schedules:r});return n},[w,O,D]);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.at,{icon:t.Wi,title:`Your schedules`,description:`When you are free — a name, a time zone, the week's hours and the days you are away. The base for anything booked on them.`,actions:I?void 0:({open:e})=>(0,i.jsx)(t.Q,{icon:t.Ur,compact:!0,title:`Add a schedule`,onClick:()=>{e(),P()},children:`Add a schedule`}),children:(0,i.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[I?(0,i.jsx)(`p`,{className:t.$,children:`Loading your schedules…`}):R.length===0?(0,i.jsx)(`p`,{className:`${t.$} px-1`,children:`No hours of your own yet — press Add a schedule. Everything booked in them shares one availability, so a time taken once is gone from all of it.`}):R.map(e=>(0,i.jsx)(vp,{schedule:e,stale:!L.has(e.memberId),fresh:_===e.id,open:h===e.id,error:x[e.id],onToggle:()=>g(h===e.id?null:e.id),onChange:E,onRemove:()=>F(e.id)},e.id)),!!A&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 px-1`,children:A})]})}),e&&(0,i.jsx)(t.at,{icon:t.xr,title:`Your team's schedules`,description:`When everyone else is free — one folded row per person; open a name to add their hours or see what they keep.`,children:(0,i.jsx)(`div`,{className:`flex flex-col gap-3`,children:I?(0,i.jsx)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:`Loading your team's schedules…`}):z.length===0?(0,i.jsxs)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug px-1`,children:[`Nobody else is marked Internal or Admin yet. Add them on the`,` `,(0,i.jsx)(c.Link,{to:`/users`,className:`text-accent font-bold hover:underline`,children:`Users screen`}),` and a folded row for them appears here.`]}):z.map(e=>(0,i.jsx)(yp,{name:e.name,schedules:e.schedules,stale:e.stale,open:y===e.id,onToggle:()=>{let t=y!==e.id;b(t?e.id:null),t&&e.schedules.length&&g(e.schedules[0].id)},onAdd:()=>{let t=O.find(t=>t.id===e.id);t&&N(t)},openScheduleId:h,freshId:_,errors:x,onToggleSchedule:e=>g(h===e?null:e),onChange:E,onRemove:F},e.id))})})]})}function Sp(){let{user:e,userRole:n}=t.na(),r=n===`admin`,{schedules:a}=t._(),o=e&&(e.displayName||e.email?.split(`@`)[0])||``;return t.fa(n)?(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,i.jsx)(Ce,{children:`Schedule`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/schedule`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-5 md:p-8 shadow-2xl relative bg-background flex flex-col min-h-[600px]`,children:(0,i.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,i.jsx)(`div`,{className:`flex flex-col gap-1.5 px-1`,children:(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/60 leading-relaxed`,children:r?`When you and your team are free, and everything built on it. A schedule is a week of hours in one person’s own time zone; a booking link turns those hours into a meeting people can book, with an address to send. The same hours are what a page you ask for is built on.`:`When you are free, and what people can book in it. Your schedule is your week of hours; a booking link turns it into a meeting, with an address of its own to send — they pick a free time and it lands on your calendar. A booking page gathers your meetings under one address to hand out.`})}),(0,i.jsx)(ip,{isAdmin:r}),(0,i.jsx)(xp,{isAdmin:r}),(0,i.jsx)(yf,{isAdmin:r}),(0,i.jsx)(up,{schedules:a,myName:o,isAdmin:r,meId:e?.uid||``})]})})]})]}):(0,i.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:(0,i.jsx)(Ci,{})})}function Cp(){let{user:e}=t.na(),n=t.an(),{loading:a,bookings:o,error:s}=t.v(e?.uid||``,e?.email||``),{docs:c}=t.b(),l=(0,r.useMemo)(()=>t.w(c),[c]),u=(0,r.useMemo)(()=>t.T(o,l),[o,l]);return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,i.jsx)(Ce,{children:`My bookings`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/my-bookings`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-5 md:p-8 shadow-2xl relative bg-background flex flex-col min-h-[600px]`,children:(0,i.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,i.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/60 leading-relaxed px-1`,children:[`Every meeting booked with your email address — including any you booked before you had an account. Shown in your time, `,t.Kn(n),`.`]}),a?(0,i.jsx)(`p`,{className:`${t.$} px-1`,children:`Loading your bookings…`}):s?(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 px-1`,children:s}):u.length===0?(0,i.jsx)(t.at,{icon:t.Wi,title:`Nothing booked yet`,description:`Meetings you book appear here.`,children:(0,i.jsxs)(`p`,{className:`${t.$} px-1`,children:[`When you book a time through one of `,e?.displayName?`their`:`our`,` booking links, it lands here — and stays here afterwards, so you always have the record.`]})}):(0,i.jsx)(t.at,{icon:t.Wi,title:`Your calendar`,description:`Press a day to see what is on it. Everything you have booked is here, including the meetings that have been and the ones called off.`,children:(0,i.jsx)(Jf,{bookings:u,zone:n,side:`booker`,onCancel:async(r,i)=>{let a=await t.i(r.id,{ids:r.copyIds,reason:i,side:`booker`,by:r.name.trim()||String(e?.displayName||``)});if(!a){let e=t.Hn(r,n);Ya(`heads_up`,{title:`Booking cancelled`,summary:`${r.name.trim()||`Someone`} cancelled ${t.Yt(r)} — ${e.day}, ${e.time}`,details:{Who:r.name.trim(),Email:r.email,When:`${e.day}, ${e.time}`,Reason:i}}).catch(()=>{})}return a}})}),!a&&!s&&u.length>0&&(0,i.jsxs)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug px-1 flex items-start gap-1.5`,children:[(0,i.jsx)(t.Cr,{className:`w-3.5 h-3.5 shrink-0 mt-[1px]`,"aria-hidden":!0}),(0,i.jsx)(`span`,{children:`Cancelling gives the time back straight away. To MOVE a meeting, cancel it and book another — or reply to its confirmation email.`})]})]})})]})]})}var wp=(0,r.lazy)(()=>Promise.resolve().then(()=>require(`./PhoneInputField-CkAv_5Lw.cjs`)).then(e=>e.n)),Tp=`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,Ep=`text-[12px] font-semibold text-red-500 mt-1 ml-1`,Dp=`flex w-full 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 resize-none`;function Op({children:e}){return(0,i.jsx)(`div`,{className:`flex flex-col w-full min-w-0`,children:e})}function kp({question:e,value:n,error:a,onChange:o}){let s=e.label.trim(),c=e.required?`${s} *`:s;return e.type===`textarea`?(0,i.jsxs)(Op,{children:[(0,i.jsx)(`label`,{className:Tp,htmlFor:`q_${e.name}`,children:c}),(0,i.jsx)(`textarea`,{id:`q_${e.name}`,rows:3,value:n,placeholder:e.placeholder,onChange:e=>o(e.target.value),className:`${Dp} rounded-xl min-h-[90px]`}),a&&(0,i.jsx)(`p`,{className:Ep,children:a})]}):e.type===`checkbox`?(0,i.jsxs)(Op,{children:[(0,i.jsxs)(`label`,{className:`flex items-center gap-3 w-full cursor-pointer group py-1.5`,children:[(0,i.jsxs)(`span`,{className:`relative flex items-center justify-center w-5 h-5 rounded border border-foreground/20 bg-background/50 group-hover:border-accent transition-colors shrink-0`,children:[(0,i.jsx)(`input`,{type:`checkbox`,checked:n===`Yes`,onChange:e=>o(e.target.checked?`Yes`:``),className:`absolute opacity-0 w-full h-full cursor-pointer`}),n===`Yes`&&(0,i.jsx)(`span`,{className:`w-2.5 h-2.5 bg-accent rounded-sm shrink-0`})]}),(0,i.jsx)(`span`,{className:`text-[14px] font-medium text-foreground/80 leading-snug group-hover:text-foreground transition-colors`,children:c})]}),a&&(0,i.jsx)(`p`,{className:Ep,children:a})]}):e.type===`select`?(0,i.jsxs)(Op,{children:[(0,i.jsx)(t.sr,{label:c,direction:`auto`,value:n,options:[{value:``,label:(0,i.jsx)(`span`,{className:`text-foreground/40`,children:e.placeholder||`Choose one…`})},...e.options.filter(Boolean).map(e=>({value:e,label:e}))],onChange:o}),a&&(0,i.jsx)(`p`,{className:Ep,children:a})]}):e.type===`tel`?(0,i.jsxs)(Op,{children:[(0,i.jsx)(r.Suspense,{fallback:(0,i.jsx)(`div`,{className:`h-12 w-full glass-panel animate-pulse rounded-xl`}),children:(0,i.jsx)(wp,{field:{label:c,required:!1,placeholder:e.placeholder},value:n,onChange:o})}),a&&(0,i.jsx)(`p`,{className:Ep,children:a})]}):e.type===`file`?(0,i.jsx)(Op,{children:(0,i.jsx)(t.$n,{field:{label:c,placeholder:e.placeholder},value:n,error:a,onChange:e=>o(e(n))})}):e.type===`date`?(0,i.jsxs)(Op,{children:[(0,i.jsx)(`label`,{className:Tp,htmlFor:`q_${e.name}`,children:c}),(0,i.jsxs)(`div`,{className:`relative flex items-center lift-focus`,children:[(0,i.jsx)(`input`,{id:`q_${e.name}`,type:`date`,value:n,onChange:e=>o(e.target.value),className:`date-field block h-12 w-full text-[15px] pl-4 pr-11 py-2 transition-all duration-300 focus:outline-none focus:border-accent glow-focus glass-panel ${n?`text-foreground`:`text-foreground/40`}`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(t.Vi,{className:`w-4 h-4 text-foreground/50 absolute right-4 pointer-events-none`,"aria-hidden":!0})]}),a&&(0,i.jsx)(`p`,{className:Ep,children:a})]}):(0,i.jsx)(Op,{children:(0,i.jsx)(t.lr,{label:c,type:e.type,value:n,error:a,placeholder:e.placeholder,onChange:e=>o(e.target.value)})})}function Ap({questions:e,answers:n,errors:r,onChange:a}){return(0,i.jsx)(i.Fragment,{children:t.It(e).map(e=>(0,i.jsx)(kp,{question:e,value:n[e.name]||``,error:r[e.name],onChange:t=>a(e.name,t)},e.name))})}var jp=/^[^\s@,;]+@[^\s@,;.]+(\.[^\s@,;.]+)*\.[a-z]{2,}$/i;function Mp(e){if(!e||e.kind!==`once`)return null;let t=Li(e),n=t.reduce((e,t)=>e+(Ri(t.amount)||0),0),r=e.name.trim()||t.map(e=>e.name.trim()).filter(Boolean).join(` and `)||Yi(e);return n>0?{amount:n,name:r}:null}var Np=(e,t=`usd`)=>{try{return new Intl.NumberFormat(void 0,{style:`currency`,currency:t.toUpperCase()}).format(e)}catch{return`${e} ${t.toUpperCase()}`}};function Pp(e){let[n,i]=(0,r.useState)({id:``,product:null});return(0,r.useEffect)(()=>{if(!e)return;let n=!1;return(0,o.getDoc)((0,o.doc)(t.Da,ji,e)).then(t=>{n||i({id:e,product:t.exists()?Ui(t.id,t.data()):null})}).catch(()=>{n||i({id:e,product:null})}),()=>{n=!0}},[e]),e?n.id===e?{loading:!1,product:n.product}:{loading:!0,product:null}:{loading:!1,product:null}}function Fp({icon:e,accent:t,children:n}){return(0,i.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 h-7 px-3 rounded-full border text-[12.5px] font-semibold whitespace-nowrap ${t?`border-accent/40 bg-accent/10 text-accent`:`border-[var(--panel-border)]/70 text-foreground/65`}`,children:[e&&(0,i.jsx)(e,{className:`w-3.5 h-3.5 text-accent shrink-0`,"aria-hidden":!0}),n]})}function Ip({children:e,wide:n,form:r}){return(0,i.jsx)(`main`,{className:`flex-1 w-full mx-auto px-4 py-8 md:py-12 z-10 flex flex-col justify-center transition-[max-width] duration-500 ease-out ${n?`max-w-4xl`:r?`max-w-2xl`:`max-w-xl`}`,children:(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.4},className:`w-full rounded-3xl glass-panel border border-[var(--panel-border)] p-5 sm:p-8 md:p-10 shadow-[0_8px_32px_rgba(0,0,0,0.08)]`,children:e})})}function Lp({children:e}){return(0,i.jsx)(`h1`,{ref:Se([e]),className:`text-2xl sm:text-3xl font-extrabold tracking-tight text-gradient leading-tight whitespace-nowrap data-[fold]:whitespace-normal data-[fold]:text-balance`,children:e})}function Rp({icon:e,title:n,children:r}){return(0,i.jsxs)(`div`,{className:`flex flex-col items-center text-center py-8 gap-4`,children:[(0,i.jsx)(`div`,{className:`w-14 h-14 ${t.K}`,children:(0,i.jsx)(e,{className:`w-6 h-6`})}),(0,i.jsx)(`h1`,{className:`text-2xl md:text-3xl font-extrabold text-foreground tracking-tight`,children:n}),r&&(0,i.jsx)(`div`,{className:`text-[14px] md:text-[15px] text-foreground/60 leading-relaxed max-w-md`,children:r}),(0,i.jsx)(c.Link,{to:`/`,className:`text-[13px] font-bold text-accent hover:underline mt-2`,children:`Back to the site`})]})}function zp({sessionId:e,schedule:n}){let[a,o]=(0,r.useState)(null);if((0,r.useEffect)(()=>{let t=!1;return ee(e).then(e=>{t||o(e)}),()=>{t=!0}},[e]),!a)return(0,i.jsx)(Rp,{icon:t.ti,title:`Confirming your payment…`,children:`One moment — checking with the payment provider.`});let s=a.metadata?.when||``;return a.paid?(0,i.jsx)(Rp,{icon:t.Gi,title:`Paid — your time is held`,children:(0,i.jsxs)(`p`,{children:[s?`${s} — `:``,t.In(n),`. Held for you while it is confirmed.`,a.customerEmail?` A receipt is on its way to ${a.customerEmail}.`:``]})}):(0,i.jsx)(Rp,{icon:t.Oi,title:`Not confirmed yet`,children:(0,i.jsx)(`p`,{children:a.error||`The payment provider has not confirmed this payment yet. Your time is held; if a receipt arrives by email, the booking is yours.`})})}function Bp(){let{id:e=``}=(0,c.useParams)(),[n]=(0,c.useSearchParams)(),{activeConfig:a}=t.ja(),{loading:o,schedule:s}=t.y(e),{loading:l,product:u}=Pp(s?.paymentId||``),d=Mp(u),f=Y(),[p,m]=(0,r.useState)(()=>t.an()),[h]=(0,r.useState)(()=>new Date),g=t.x(s?[s.memberId]:[],h),_=(0,r.useMemo)(()=>s&&t.Wt(s)?[s]:[],[s]),[v,y]=(0,r.useState)(null),[b,x]=(0,r.useState)(()=>t.Ea.currentUser?.displayName||``),[S,C]=(0,r.useState)(()=>t.Ea.currentUser?.email||``),[w,T]=(0,r.useState)({}),[E,D]=(0,r.useState)({}),[O,k]=(0,r.useState)(!1),[A,j]=(0,r.useState)(``),[M,N]=(0,r.useState)(``),[P,F]=(0,r.useState)(``),I=n.get(`session_id`)||``,R=n.get(`cancelled`)===`1`;if(o)return(0,i.jsx)(Ip,{children:(0,i.jsxs)(`div`,{className:`flex items-center justify-center gap-3 py-16 text-foreground/50`,children:[(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin text-accent`}),(0,i.jsx)(`span`,{className:`text-[13px] font-medium`,children:`Loading…`})]})});if(!s)return(0,i.jsx)(Ip,{children:(0,i.jsx)(Rp,{icon:t.Hi,title:`This booking link is no longer open`,children:`It may have been taken down. Ask whoever sent it for a new one.`})});if(I)return(0,i.jsx)(Ip,{children:(0,i.jsx)(zp,{sessionId:I,schedule:s})});if(M)return(0,i.jsx)(Ip,{children:(0,i.jsx)(Rp,{icon:t.Oi,title:`Your time is held`,children:(0,i.jsxs)(`p`,{children:[M,` — held for you while `,s.memberName.trim()||`the person you booked with`,` confirms it.`,P?` We have sent the details to ${P}, and will write again the moment it is confirmed.`:``]})})});if(!t.Wt(s))return(0,i.jsx)(Ip,{children:(0,i.jsx)(Rp,{icon:t.Hi,title:t.In(s),children:`This is not taking bookings at the moment.`})});let z=!!s.paymentId&&!l&&(!d||!f.loading&&!f.configured),B=async()=>{if(!v||O)return;let e={...t.qt(s.questions,w)};if(b.trim()||(e._name=`Your name, please.`),jp.test(S.trim())||(e._email=`That does not look like an email address — check for a typo, e.g. jane@example.com`),D(e),Object.keys(e).length)return;k(!0),j(``);let n=t.nn(v,s.memberName,p),r=await t.a(v);if(r){j(r),y(null),k(!1);return}let i=null;if(d){let e=await W({amount:d.amount,productName:`${t.In(s)} — ${n}`,metadata:{bookingId:t.zn(v.memberId,v.start),scheduleId:s.id,page:t.Qt(s.id),when:n,emailReceipt:s.confirmBooker?`yes`:`no`,notifyOwner:s.notifyOwner?`yes`:`no`},successPath:t.Qt(s.id),cancelPath:`${t.Qt(s.id)}?cancelled=1`});if(typeof e==`string`){await t.c(v),j(e),k(!1);return}i=e}let a=t.zn(v.memberId,v.start),o=await t.E(v,{memberName:s.memberName,scheduleId:s.id,scheduleName:t.Mn(s),paymentId:s.paymentId,paymentSession:i?.sessionId||``,timeZone:p,name:b.trim(),email:S.trim(),answers:t.Gt(s.questions,w),formId:t.gt,entryId:``});if(o){await t.c(v),j(o),k(!1);return}if(i){L.goTo(i.url);return}if(s.notifyOwner&&Ya(`heads_up`,{title:`New booking`,summary:`${b.trim()} booked ${t.In(s)} — ${n}`,details:{Name:b.trim(),Email:S.trim(),When:n,...t.Kt(s.questions,w)}}).catch(()=>{}),s.confirmBooker&&t.Ea.currentUser){let e=S.trim();Xa(`booking_requested`,`mem_bookings`,a,{when:n,memberName:s.memberName,scheduleName:t.In(s),details:{When:n,With:s.memberName,What:t.In(s)}}).then(t=>{t||F(e)}).catch(()=>{})}N(n),k(!1)},V=!z&&!v,H=!z&&!!v,U=t.Ft(s.questions,`name`),G=t.Ft(s.questions,`email`);return(0,i.jsxs)(Ip,{wide:V,form:H,children:[R&&(0,i.jsx)(`p`,{className:`mb-5 px-4 py-3 rounded-xl bg-amber-500/10 border border-amber-500/20 text-[13px] font-medium text-foreground/80`,children:`Nothing was charged. Pick a time again to book.`}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-4 mb-5 sm:mb-6`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-3.5 min-w-0`,children:[(0,i.jsx)(`div`,{className:`w-11 h-11 ${t.K}`,children:(0,i.jsx)(t.Wi,{className:`w-5 h-5`})}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0 flex-1`,children:[a?.appName&&(0,i.jsx)(`span`,{className:`text-[10.5px] font-bold uppercase tracking-[0.18em] text-foreground/40 truncate`,children:a.appName}),(0,i.jsx)(Lp,{children:t.In(s)})]})]}),(0,i.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[!s.memberName.trim()&&(0,i.jsx)(Fp,{icon:t.Cr,children:`with your host`}),(0,i.jsx)(Fp,{icon:t.Oi,children:t.Bn(s.slotMinutes)}),d&&(0,i.jsx)(Fp,{accent:!0,children:Np(d.amount)})]}),t.jn(s)&&(0,i.jsx)(`p`,{className:`text-[13.5px] sm:text-[14px] text-foreground/60 font-medium leading-relaxed max-w-2xl whitespace-pre-line`,children:t.jn(s)})]}),(0,i.jsx)(`div`,{className:`h-px bg-[var(--panel-border)]/60 mb-5 sm:mb-6`}),z?(0,i.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60`,children:`This booking cannot be paid for right now — please try again later.`}):v?(0,i.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,i.jsx)(t.G,{slot:v,timeZone:p,onChange:()=>y(null)}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,i.jsx)(t.lr,{label:U.label,value:b,onChange:e=>x(e.target.value),error:E._name,placeholder:U.placeholder}),(0,i.jsx)(t.lr,{label:G.label,type:`email`,value:S,onChange:e=>C(e.target.value),error:E._email,placeholder:G.placeholder}),(0,i.jsx)(Ap,{questions:s.questions,answers:w,errors:E,onChange:(e,t)=>{T(n=>({...n,[e]:t})),D(t=>t[e]?{...t,[e]:``}:t)}})]}),A&&(0,i.jsx)(`p`,{role:`alert`,className:`text-[13px] font-semibold text-red-500`,children:A}),(0,i.jsx)(`div`,{className:`h-px bg-[var(--panel-border)]/60`}),(0,i.jsx)(t.J,{timeZone:p,onTimeZone:m,action:(0,i.jsx)(t.cr,{variant:`primary`,onClick:B,disabled:O||l,className:`max-sm:w-full h-11 px-6 text-[13.5px] font-bold shrink-0`,children:O?d?`Opening checkout…`:`Booking…`:d?`Book and pay ${Np(d.amount)}`:`Confirm booking`})})]}):(0,i.jsxs)(i.Fragment,{children:[A&&(0,i.jsx)(`p`,{role:`alert`,className:`mb-3 text-[13px] font-semibold text-red-500`,children:A}),(0,i.jsx)(t.z,{members:_,value:v,onChange:y,taken:g,timeZone:p,onTimeZone:m})]})]})}var Vp=`rounded-2xl flex items-center justify-center shrink-0 border border-[var(--panel-border)]/50 bg-accent/10 text-accent`,Hp=`rounded-2xl border border-[var(--panel-border)]/60 bg-foreground/[0.015]`;function Up(e){let[n,i]=(0,r.useState)(new Map),a=e.join(`,`);return(0,r.useEffect)(()=>{let e=a?a.split(`,`):[];if(!e.length)return;let n=!1;return Promise.all(e.map(async e=>{try{let n=await(0,o.getDoc)((0,o.doc)(t.Da,ji,e));return n.exists()?Ui(e,n.data()):null}catch{return null}})).then(e=>{if(n)return;let t=new Map;e.forEach(e=>{e&&t.set(e.id,e)}),i(t)}),()=>{n=!0}},[a]),n}function Wp({children:e}){return(0,i.jsx)(`main`,{className:`flex-1 w-full max-w-2xl mx-auto px-4 py-8 md:py-12 z-10 flex flex-col justify-center`,children:(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.4},className:`w-full rounded-3xl glass-panel border border-[var(--panel-border)] p-5 sm:p-8 md:p-10 shadow-[0_8px_32px_rgba(0,0,0,0.08)]`,children:e})})}function Gp({icon:e,title:t,children:n}){return(0,i.jsxs)(`div`,{className:`flex flex-col items-center text-center py-8 gap-4`,children:[(0,i.jsx)(`div`,{className:`w-14 h-14 ${Vp}`,children:(0,i.jsx)(e,{className:`w-6 h-6`})}),(0,i.jsx)(`h1`,{className:`text-2xl md:text-3xl font-extrabold text-foreground tracking-tight`,children:t}),n&&(0,i.jsx)(`div`,{className:`text-[14px] md:text-[15px] text-foreground/60 leading-relaxed max-w-md`,children:n}),(0,i.jsx)(c.Link,{to:`/`,className:`text-[13px] font-bold text-accent hover:underline mt-2`,children:`Back to the site`})]})}function Kp({icon:e,accent:t,children:n}){return(0,i.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 h-6 px-2.5 rounded-full border text-[11.5px] font-semibold whitespace-nowrap ${t?`border-accent/40 bg-accent/10 text-accent`:`border-[var(--panel-border)]/70 text-foreground/60`}`,children:[e&&(0,i.jsx)(e,{className:`w-3 h-3 text-accent shrink-0`,"aria-hidden":!0}),n]})}function qp({schedule:e,price:n}){let r=t.jn(e),a=t.Vn(e.slotMinutes);return(0,i.jsxs)(c.Link,{to:t.Qt(e.id),className:`${Hp} group relative overflow-hidden flex items-center gap-3.5 sm:gap-4 p-3 sm:p-4 transition-all duration-300
|
|
672
|
+
`,ku=[{key:`VITE_FIREBASE_API_KEY`,label:`API Key`,shownAs:`apiKey`},{key:`VITE_FIREBASE_AUTH_DOMAIN`,label:`Auth Domain`,shownAs:`authDomain`},{key:`VITE_FIREBASE_PROJECT_ID`,label:`Project ID`,shownAs:`projectId`},{key:`VITE_FIREBASE_STORAGE_BUCKET`,label:`Storage Bucket`,shownAs:`storageBucket`},{key:`VITE_FIREBASE_MESSAGING_SENDER_ID`,label:`Messaging Sender ID`,shownAs:`messagingSenderId`},{key:`VITE_FIREBASE_APP_ID`,label:`App ID`,shownAs:`appId`}];function Au(e){let t;try{if(t={BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_ADMIN_EMAILS:void 0,VITE_FIREBASE_API_KEY:void 0,VITE_FIREBASE_APP_ID:void 0,VITE_FIREBASE_AUTH_DOMAIN:void 0,VITE_FIREBASE_MESSAGING_SENDER_ID:void 0,VITE_FIREBASE_PROJECT_ID:void 0,VITE_FIREBASE_STORAGE_BUCKET:void 0}?.[e],t&&typeof t==`string`&&t.trim()!==``)return t}catch{}try{if(t=(typeof window<`u`?window:globalThis)?.process?.env?.[e],t&&typeof t==`string`&&t.trim()!==``)return t}catch{}try{switch(e){case`VITE_FIREBASE_API_KEY`:t=void 0;break;case`VITE_FIREBASE_AUTH_DOMAIN`:t=void 0;break;case`VITE_FIREBASE_PROJECT_ID`:t=void 0;break;case`VITE_FIREBASE_STORAGE_BUCKET`:t=void 0;break;case`VITE_FIREBASE_MESSAGING_SENDER_ID`:t=void 0;break;case`VITE_FIREBASE_APP_ID`:t=void 0;break}if(t&&typeof t==`string`&&t.trim()!==``)return t}catch{}return``}function ju(e,t){let n=Au(e);if(n)return n;if(t?.firebaseConfig){let n={VITE_FIREBASE_API_KEY:`apiKey`,VITE_FIREBASE_AUTH_DOMAIN:`authDomain`,VITE_FIREBASE_PROJECT_ID:`projectId`,VITE_FIREBASE_STORAGE_BUCKET:`storageBucket`,VITE_FIREBASE_MESSAGING_SENDER_ID:`messagingSenderId`,VITE_FIREBASE_APP_ID:`appId`}[e];if(n&&t.firebaseConfig[n])return t.firebaseConfig[n]}return``}function Mu(e){let t=[],n=[],r=t=>ju(t,e);for(let{key:e,label:i}of ku){let a=r(e);a?a.trim()===``&&n.push(i):t.push(i)}let i=[...t,...n];return{allSet:i.length===0,missing:i,empty:n}}function Nu(){return Mu().allSet}var Pu=Ou;function Fu(e){let t=e.map(e=>e.trim().toLowerCase()).filter(Boolean).filter((e,t,n)=>n.indexOf(e)===t),n=t.length?t.map(e=>`'${e.replace(/'/g,``)}'`).join(`, `):`'your@email.com'`;return Du.replace(/(function adminEmails\(\) \{\s*return )\[[^\]]*\];/,`$1[${n}];`)}function Iu(e){return e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean)}var Lu=/^[^@\s]+@[^@\s]+\.[^@\s]+$/;function Ru({code:e,label:n,compact:a}){let[o,s]=r.default.useState(!1);return(0,i.jsxs)(t.fr.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>{navigator.clipboard?.writeText(e),s(!0),setTimeout(()=>s(!1),2e3)},className:`inline-flex items-center font-bold transition-all shrink-0 cursor-pointer ${a?`gap-1.5 h-9 px-3 rounded-xl text-[12px] self-start sm:self-auto`:`gap-2 px-4 py-2 mt-2 rounded-xl text-[13px] tracking-wide`} ${o?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary${a?``:` shadow-sm`}`}`,children:[o?(0,i.jsx)(t.zi,{className:a?`w-3.5 h-3.5`:`w-4 h-4`}):(0,i.jsx)(t.Ti,{className:a?`w-3.5 h-3.5`:`w-4 h-4`}),o?a?`Copied`:`Copied to Clipboard!`:n]})}function zu(e){let t=``;try{t=new URL(e).hostname}catch{t=``}let n=t===`localhost`||t===`127.0.0.1`||t.endsWith(`.local`);return{host:t,local:n}}function Bu(){let{host:e,local:t}=zu(typeof window>`u`?``:window.location.href);return e?(0,i.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl bg-background flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-3 px-4 py-3 mt-3`,children:[(0,i.jsxs)(`div`,{className:`min-w-0`,children:[(0,i.jsx)(`div`,{className:`text-[13.5px] font-bold text-foreground break-all sm:break-normal sm:truncate`,children:e}),(0,i.jsx)(`div`,{className:`text-[12.5px] text-foreground/50 font-medium`,children:t?`this machine — Firebase trusts it already, nothing to add`:`your app's address, read from this page`})]}),!t&&(0,i.jsx)(Ru,{compact:!0,code:e,label:`Copy the address`})]}):null}function Vu({name:e,shownAs:n,hint:a}){let[o,s]=r.default.useState(!1);return(0,i.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 sm:gap-3 px-4 py-3 border-b border-[var(--panel-border)]/40 last:border-0`,children:[(0,i.jsxs)(`div`,{className:`min-w-0`,children:[(0,i.jsx)(`div`,{className:`text-[13.5px] font-bold text-foreground break-all sm:break-normal sm:truncate`,children:e}),(0,i.jsx)(`div`,{className:`text-[12.5px] text-foreground/50 font-medium`,children:a??(0,i.jsxs)(i.Fragment,{children:[`the value Firebase labels `,n]})})]}),(0,i.jsxs)(`button`,{type:`button`,onClick:()=>{navigator.clipboard?.writeText(e),s(!0),setTimeout(()=>s(!1),2e3)},className:`inline-flex items-center gap-1.5 h-9 px-3 rounded-xl text-[12px] font-bold shrink-0 self-start sm:self-auto transition-all cursor-pointer active:scale-[0.98] ${o?`bg-emerald-500/10 text-emerald-500 border border-emerald-500/20`:`btn-secondary`}`,children:[o?(0,i.jsx)(t.zi,{className:`w-3.5 h-3.5`}):(0,i.jsx)(t.Ti,{className:`w-3.5 h-3.5`}),o?`Copied`:`Copy name`]})]})}var Hu={VITE_FIREBASE_API_KEY:`AIzaSyD3k9xQeL7vR2mN8pT4wY6…`,VITE_FIREBASE_AUTH_DOMAIN:`your-project.firebaseapp.com`,VITE_FIREBASE_PROJECT_ID:`your-project`,VITE_FIREBASE_MESSAGING_SENDER_ID:`482915736204`,VITE_FIREBASE_APP_ID:`1:482915736204:web:9c1e7a4b2d8f6e3a`},Uu=ku.map(({key:e})=>e===`VITE_FIREBASE_STORAGE_BUCKET`?{name:e,value:`leave empty`,empty:!0}:{name:e,value:Hu[e]});function Wu({name:e,value:n,empty:r}){return(0,i.jsxs)(`div`,{className:`px-3 sm:px-4 py-1.5 flex flex-col gap-1 sm:grid sm:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_2.25rem] sm:gap-3 sm:items-center`,children:[(0,i.jsx)(`div`,{title:e,className:`min-w-0 sm:h-9 sm:px-3 flex items-center sm:rounded-xl sm:bg-foreground/[0.05] text-[12.5px] sm:text-[13px] font-semibold text-foreground/80`,children:(0,i.jsx)(`span`,{className:`break-all sm:truncate`,children:e})}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 sm:contents`,children:[(0,i.jsx)(`div`,{className:`flex-1 min-w-0 h-9 px-3 flex items-center rounded-xl border text-[12.5px] sm:text-[13px] font-medium ${r?`border-dashed border-accent/40 text-accent`:`border-[var(--panel-border)]/60 text-foreground/45`}`,children:(0,i.jsx)(`span`,{className:`truncate`,children:n})}),(0,i.jsx)(`span`,{"aria-hidden":`true`,className:`w-9 h-9 shrink-0 rounded-xl flex items-center justify-center bg-foreground/[0.05] text-foreground/35`,children:(0,i.jsx)(t.yi,{className:`w-4 h-4`})})]})]})}function Gu(){return(0,i.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl overflow-hidden bg-background`,children:[(0,i.jsx)(`div`,{className:`max-sm:hidden sm:grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_2.25rem] gap-3 px-4 pt-3.5 pb-1`,children:[`Name`,`Value`].map(e=>(0,i.jsx)(`span`,{className:`px-3 text-[12.5px] font-semibold text-foreground/45`,children:e},e))}),(0,i.jsx)(`div`,{className:`py-2 sm:py-1.5`,children:Uu.map(e=>(0,i.jsx)(Wu,{...e},e.name))}),(0,i.jsx)(`div`,{className:`flex justify-end px-3 sm:px-4 py-3 border-t border-[var(--panel-border)]/40`,children:(0,i.jsx)(`span`,{"aria-hidden":`true`,className:`btn-secondary inline-flex items-center h-9 px-4 rounded-xl text-[12.5px] font-bold select-none`,children:`Apply`})})]})}function Ku(){let[e,n]=(0,r.useState)(``),[a,o]=(0,r.useState)(``),[s,c]=(0,r.useState)([]),[l,u]=(0,r.useState)(``),d=e=>{n(e),a&&(o(``),c([])),l&&u(``)},f=()=>{let t=Iu(e);if(t.length===0){u(`Type an email address first — it is what the rules will name.`);return}let n=t.filter(e=>!Lu.test(e));if(n.length>0){u(`That does not look like an email address: ${n.join(`, `)}`);return}u(``),c(t.map(e=>e.trim().toLowerCase())),o(Fu(t))};return(0,i.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl p-5 mb-2 flex flex-col gap-4`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-3.5 min-w-0`,children:[(0,i.jsx)(`div`,{className:`w-10 h-10 rounded-2xl flex items-center justify-center shrink-0 border border-[var(--panel-border)]/50 bg-accent/10 text-accent`,children:(0,i.jsx)(t.Fr,{className:`w-5 h-5`})}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,i.jsx)(`h3`,{className:`text-[15px] font-bold text-foreground tracking-tight leading-tight truncate`,children:`Who runs this app?`}),(0,i.jsx)(`p`,{className:`text-[12px] text-foreground/50 font-normal leading-snug truncate`,children:`The email you sign in with becomes the owner — separate several with commas.`})]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center gap-2`,children:[(0,i.jsx)(`input`,{type:`text`,value:e,"aria-label":`The email address you will sign in with`,placeholder:`you@yourcompany.com`,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f())},className:`w-full h-10 px-3.5 rounded-[var(--input-radius,0.75rem)] border border-[var(--panel-border)] bg-[var(--panel-bg)] text-[13.5px] text-foreground outline-none transition-all duration-300 placeholder:text-foreground/35 hover:border-accent/40 focus:border-accent console-field ${l?`is-invalid border-red-500/60`:``}`}),(0,i.jsx)(`button`,{type:`button`,onClick:f,className:`btn-primary inline-flex items-center justify-center h-10 px-4 rounded-[var(--btn-radius,0.75rem)] text-[12.5px] font-bold text-white shrink-0 cursor-pointer active:scale-[0.98] transition-transform whitespace-nowrap`,children:`Generate the rules`})]}),l&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 leading-snug px-1`,children:l}),a&&(0,i.jsxs)(`div`,{className:`rounded-2xl border border-emerald-500/20 bg-emerald-500/[0.05] px-3.5 py-3 flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-3`,children:[(0,i.jsx)(`span`,{className:`w-7 h-7 rounded-full bg-emerald-500/10 border border-emerald-500/20 flex items-center justify-center shrink-0`,children:(0,i.jsx)(t.zi,{className:`w-3.5 h-3.5 text-emerald-500`})}),(0,i.jsxs)(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[(0,i.jsxs)(`p`,{"data-admin-emails":!0,className:`text-[13px] font-bold text-foreground leading-snug break-all`,children:[`Ready — they make `,s.join(`, `),` the owner.`]}),(0,i.jsx)(`p`,{className:`text-[12px] font-medium text-foreground/50 leading-snug`,children:`Paste them into Firebase, then sign in with that address — or reload, if you already are.`})]}),(0,i.jsx)(Ru,{compact:!0,code:a,label:`Copy the rules`})]})]})}var qu=`text-accent underline underline-offset-2 font-semibold hover:text-accent-deep transition-colors`;function Ju({text:e,label:t}){return(0,i.jsxs)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl bg-background overflow-hidden`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3 border-b border-[var(--panel-border)]/40`,children:[(0,i.jsx)(`span`,{className:`text-[12px] font-extrabold tracking-tight text-gradient truncate max-sm:hidden`,children:`Paste this into your assistant`}),(0,i.jsx)(Ru,{compact:!0,code:e,label:t})]}),(0,i.jsx)(`pre`,{className:`px-4 py-3 max-h-64 overflow-auto text-[11.5px] leading-relaxed font-mono text-foreground/70 whitespace-pre-wrap [overflow-wrap:anywhere]`,children:e})]})}function Yu({number:e,title:t,aside:n,children:r}){return(0,i.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,i.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,i.jsx)(`span`,{className:`w-8 h-8 shrink-0 rounded-full bg-accent/10 border border-accent/20 text-accent flex items-center justify-center text-[14px] font-extrabold`,children:e}),(0,i.jsx)(`h3`,{className:`text-[17px] md:text-[19px] font-extrabold text-foreground tracking-tight flex-1 min-w-0`,children:t}),n]}),(0,i.jsx)(`div`,{className:`text-[14px] md:text-[15px] text-foreground/70 leading-relaxed space-y-4`,children:r})]})}function Xu({basename:e}){return(0,i.jsxs)(`div`,{className:`mt-6 sm:mt-8 relative z-10 flex flex-col sm:flex-row sm:items-center gap-4 sm:gap-6 p-5 sm:p-6 rounded-3xl border border-accent/20 bg-accent/[0.06]`,children:[(0,i.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,i.jsx)(`h3`,{className:`text-[16px] sm:text-[17px] font-extrabold text-foreground tracking-tight`,children:`Worked through every step?`}),(0,i.jsx)(`p`,{className:`text-[13px] sm:text-[13.5px] text-foreground/60 font-medium leading-relaxed mt-1`,children:`Your app will start again and take you to sign in. Use the email address you typed into the rules — that is the one this app knows as its owner.`})]}),(0,i.jsxs)(t.fr.button,{type:`button`,whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>{Eu();let t=String(e||``).replace(/\/+$/,``);window.location.assign(`${t}/login`)},className:`btn-primary inline-flex items-center justify-center gap-2 h-12 px-6 rounded-[var(--btn-radius,0.75rem)] text-[13.5px] font-bold text-white shrink-0 cursor-pointer whitespace-nowrap shadow-lg`,children:[`I've completed all the steps`,(0,i.jsx)(t.Xi,{className:`w-4 h-4`})]})]})}function Zu({standalone:e}){let n=t.Na(),[a,o]=Cu(),s=a===`local`,c={project:s?2:1,webApp:s?3:2,keys:s?4:3,signIn:s?5:4,database:s?6:5,storage:s?7:6},l=zu(typeof window>`u`?``:window.location.href).local,[u]=(0,r.useState)(()=>{let e=localStorage.getItem(`theme-mode`);return e===`light`?!1:e===`dark`?!0:window.matchMedia(`(prefers-color-scheme: dark)`).matches});return(0,r.useEffect)(()=>{e&&document.documentElement.setAttribute(`data-theme`,u?`dark`:`light`)},[u,e]),(0,r.useEffect)(()=>{if(e&&t.Pa.faviconUrl){let e=document.querySelector(`link[rel*='icon']`);e||(e=document.createElement(`link`),e.rel=`icon`,document.head.appendChild(e)),e.href=t.Pa.faviconUrl}},[e]),(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,i.jsxs)(`div`,{children:[(0,i.jsx)(Ce,{children:`Setup`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/setup`]})]})}),(0,i.jsx)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-6 md:p-10 shadow-2xl relative overflow-hidden bg-background flex flex-col`,children:[(0,i.jsx)(`div`,{className:`mb-6 pb-4 sm:mb-8 sm:pb-6 border-b border-[var(--panel-border)]/50 relative z-10`,children:(0,i.jsxs)(`div`,{className:`flex max-sm:flex-col max-sm:items-stretch items-center justify-between gap-3 sm:gap-4`,children:[(0,i.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,i.jsx)(`h2`,{className:`text-[17px] sm:text-xl font-extrabold text-foreground tracking-tight truncate`,children:`Connect your app to Firebase`}),(0,i.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1 sm:mt-1.5 leading-snug truncate`,children:[(0,i.jsx)(`span`,{className:`sm:hidden`,children:`Google's free data and sign-in service.`}),(0,i.jsx)(`span`,{className:`max-sm:hidden`,children:`Firebase is Google's free service that stores your data and signs people in — about ten minutes, once.`})]})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,i.jsx)(t.fr.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,i.jsx)(t.Zr,{className:`w-4 h-4`})}),(0,i.jsx)(t.fr.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,i.jsx)(bu,{className:`w-4 h-4 text-foreground/80`})})]})]})}),!1,(0,i.jsxs)(`div`,{className:`flex flex-col relative z-10 p-4 sm:p-6 md:p-8 bg-foreground/[0.015] rounded-3xl border border-[var(--panel-border)]/50`,children:[s&&(0,i.jsxs)(Yu,{number:1,title:`Set your project up`,children:[(0,i.jsx)(`p`,{className:`text-foreground/80`,children:`Your assistant does this part — none of it is yours to type. Copy the block below into Claude Code, Codex or Antigravity and let it finish before you carry on. If you are already looking at this page on your own machine, paste it anyway: it only fills in what is missing and changes nothing that is already right.`}),(0,i.jsx)(Ju,{text:wu,label:`Copy the setup prompt`}),(0,i.jsxs)(`p`,{className:`text-foreground/80`,children:[`One of the lines it writes is `,(0,i.jsx)(`strong`,{children:`GEMINI_API_KEY`}),`, and it stays empty unless you later ask for something that uses AI — a chatbot, a writing helper. A free key comes from`,` `,(0,i.jsx)(`a`,{href:`https://aistudio.google.com/apikey`,target:`_blank`,rel:`noopener noreferrer`,className:qu,children:`aistudio.google.com/apikey`}),` `,`when that day comes.`]})]}),(0,i.jsx)(Yu,{number:c.project,title:`Create a Firebase project`,children:(0,i.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,i.jsxs)(`li`,{children:[`Open`,` `,(0,i.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,i.jsx)(`strong`,{children:`Add project`}),`. Sign in with your Google account if it asks.`]}),(0,i.jsxs)(`li`,{children:[`Type any name you like and click `,(0,i.jsx)(`strong`,{children:`Continue`}),`.`]}),(0,i.jsxs)(`li`,{children:[`If it offers `,(0,i.jsx)(`strong`,{children:`Enable Gemini in Firebase`}),`, switch it off.`]}),(0,i.jsxs)(`li`,{children:[`Switch off `,(0,i.jsx)(`strong`,{children:`Enable Google Analytics for this project`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Create project`}),`, wait, then click `,(0,i.jsx)(`strong`,{children:`Continue`}),`.`]})]})}),(0,i.jsx)(Yu,{number:c.webApp,title:`Add a web app and copy the six values`,children:(0,i.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,i.jsxs)(`li`,{children:[`On that page click `,(0,i.jsx)(`strong`,{children:`+ Add app`}),` under your project's name, then pick the `,(0,i.jsx)(`strong`,{children:`</> Web`}),` icon.`]}),(0,i.jsxs)(`li`,{children:[`Give it any nickname (`,(0,i.jsx)(`span`,{className:`text-accent`,children:`MyApp`}),` is fine). Leave `,(0,i.jsx)(`strong`,{children:`Firebase Hosting`}),` unticked.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Register app`}),`.`]}),(0,i.jsx)(`li`,{children:`Firebase now shows six values on screen, each with a label beside it — apiKey, authDomain, projectId, storageBucket, messagingSenderId and appId. You will copy them one at a time in the next step, so keep this tab open.`})]})}),(0,i.jsx)(Yu,{number:c.keys,title:s?`Put the six values in your .env`:`Paste the values into the environment variables window`,children:s?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(`p`,{className:`text-foreground/80`,children:[`Step 1 made a `,(0,i.jsx)(`strong`,{children:`.env`}),` file, and every name below is already a line in it. Open it — or ask your assistant to open it for you — and put each value from your Firebase tab between that line's quotes. The names have to match letter for letter, so find them with the Copy name button rather than retyping.`]}),(0,i.jsxs)(`p`,{className:`text-foreground/80`,children:[`Six lines, and that is all of them. Fill five of them now and leave`,` `,(0,i.jsx)(`strong`,{children:`VITE_FIREBASE_STORAGE_BUCKET`}),` empty — step `,c.storage,` gives you its real value.`]}),(0,i.jsxs)(`p`,{className:`text-foreground/80`,children:[(0,i.jsx)(`strong`,{children:`Leave the app as it is for now.`}),` One value is still missing, and starting it again is the last thing you do on this whole page.`]}),(0,i.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-2xl overflow-hidden bg-background`,children:ku.map(({key:e,shownAs:t})=>(0,i.jsx)(Vu,{name:e,shownAs:t,hint:e===`VITE_FIREBASE_STORAGE_BUCKET`?`leave this one empty — step ${c.storage} gives you the real address`:void 0},e))})]}):(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(`p`,{className:`text-foreground/80`,children:[`AI Studio pops up a window that says`,` `,(0,i.jsx)(`strong`,{children:`Enter your environment variables to continue`}),`, with a form like the one below. Paste each value from your Firebase tab into its row — the values below are only examples of what each one looks like.`]}),(0,i.jsxs)(`p`,{className:`text-foreground/80`,children:[`Leave `,(0,i.jsx)(`strong`,{children:`VITE_FIREBASE_STORAGE_BUCKET`}),` empty and keep the window open — don't press `,(0,i.jsx)(`strong`,{children:`Apply`}),` yet. Step `,c.storage,` gives you the last value, and Apply comes after it.`]}),(0,i.jsx)(Gu,{})]})}),(0,i.jsxs)(Yu,{number:c.signIn,title:`Turn on sign-in`,children:[(0,i.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80`,children:[(0,i.jsxs)(`li`,{children:[`In the Firebase menu on the left, open `,(0,i.jsx)(`strong`,{children:`Authentication`}),` and click `,(0,i.jsx)(`strong`,{children:`Get started`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Open the `,(0,i.jsx)(`strong`,{children:`Sign-in method`}),` tab.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Email/Password`}),`, switch on the first toggle and `,(0,i.jsx)(`strong`,{children:`Save`}),`. (Leave email link off.)`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Add provider`}),`, choose `,(0,i.jsx)(`strong`,{children:`Google`}),`, switch it on, pick your own address as the support email, and `,(0,i.jsx)(`strong`,{children:`Save`}),`. The app needs this for the `,(0,i.jsx)(`strong`,{children:`Sign in with Google`}),` button to work.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Add provider`}),`, choose `,(0,i.jsx)(`strong`,{children:`Anonymous`}),`, switch it on, and `,(0,i.jsx)(`strong`,{children:`Save`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Open the `,(0,i.jsx)(`strong`,{children:`Settings`}),` tab, then `,(0,i.jsx)(`strong`,{children:`Authorized domains`}),`. Your app has to be listed here or nobody can sign in.`]}),l?(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`strong`,{children:`Nothing to add here yet.`}),` This app is being served from your own machine, and Firebase trusts that address from the start. Come back and add the real one the day you put your app on the internet.`]}):(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`strong`,{children:`Your app's address is right here`}),` — copy it below, then in Firebase click `,(0,i.jsx)(`strong`,{children:`Add domain`}),`, paste it, and save.`]})]}),(0,i.jsx)(Bu,{})]}),(0,i.jsxs)(Yu,{number:c.database,title:`Create the database and publish its rules`,children:[(0,i.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80 mb-4`,children:[(0,i.jsxs)(`li`,{children:[`In the Firebase menu, open `,(0,i.jsx)(`strong`,{children:`Firestore Database`}),` and click `,(0,i.jsx)(`strong`,{children:`Create database`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Pick `,(0,i.jsx)(`strong`,{children:`Standard edition`}),` if asked, choose the location closest to your people, start in `,(0,i.jsx)(`strong`,{children:`Production mode`}),`, and click Continue.`]}),(0,i.jsxs)(`li`,{children:[`In the box below, type the email address you will sign in with and click `,(0,i.jsx)(`strong`,{children:`Generate the rules`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Copy the rules`}),`, then in Firebase open the `,(0,i.jsx)(`strong`,{children:`Rules`}),` tab, select everything that is there, paste over it, and click `,(0,i.jsx)(`strong`,{children:`Publish`}),`.`]})]}),(0,i.jsx)(Ku,{})]}),(0,i.jsxs)(Yu,{number:c.storage,title:`Create storage and publish its rules`,children:[(0,i.jsxs)(`ol`,{className:`space-y-2 list-decimal list-inside text-foreground/80 mb-4`,children:[(0,i.jsxs)(`li`,{children:[`In the Firebase menu, open `,(0,i.jsx)(`strong`,{children:`Storage`}),`. Google asks you to upgrade the project first: click `,(0,i.jsx)(`strong`,{children:`Upgrade project`}),` and pick the pay-as-you-go`,` `,(0,i.jsx)(`strong`,{children:`Blaze plan`}),`. Profile photos and attachments cost about $0.03 per gigabyte a month, so this is cents. Set a budget you are comfortable with (say $20), link a billing account, and continue.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Get started`}),`, choose a no-cost location, start in `,(0,i.jsx)(`strong`,{children:`Production mode`}),`, and click `,(0,i.jsx)(`strong`,{children:`Create`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Open the `,(0,i.jsx)(`strong`,{children:`Rules`}),` tab, select everything that is there, paste these over it, and click `,(0,i.jsx)(`strong`,{children:`Publish`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Now Firebase shows the storage address at the top of the page — something like`,` `,`your-project.firebasestorage.app. `,(0,i.jsx)(`strong`,{children:`Copy that`}),`. This is the real one; the one Firebase showed you back in step `,c.webApp,` was a guess made before storage existed.`]}),s?(0,i.jsxs)(`li`,{children:[`Back in your `,(0,i.jsx)(`strong`,{children:`.env`}),` file, paste it into`,` `,(0,i.jsx)(`strong`,{children:`VITE_FIREBASE_STORAGE_BUCKET`}),` — the line you left empty.`]}):(0,i.jsxs)(`li`,{children:[`Back in the environment variables window from step `,c.keys,`, paste it into`,` `,(0,i.jsx)(`strong`,{children:`VITE_FIREBASE_STORAGE_BUCKET`}),` — the row you left empty.`]}),s?(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`strong`,{children:`Start the app again.`}),` Stop it and start it once more — or just ask your assistant to restart it. A value added while it is running is not read until then. That is the last thing to do: then reload this page and your app is connected.`]}):(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`strong`,{children:`Press Apply, then reload this page.`}),` Your app is connected.`]})]}),(0,i.jsx)(Ru,{code:Pu,label:`Copy the storage rules`})]})]}),(0,i.jsx)(Xu,{basename:n.basename})]})})]})}var Qu={email:{collection:`sys_configs`,doc:`email`},payments:{collection:`sys_payments`,doc:`_settings`}},$u=e=>e?.enabled!==!1;function ed(e){let{collection:n,doc:i}=Qu[e],[a,s]=(0,r.useState)({loading:!0,on:!0});return(0,r.useEffect)(()=>(0,o.onSnapshot)((0,o.doc)(t.Da,n,i),e=>s({loading:!1,on:$u(e.exists()?e.data():null)}),()=>s({loading:!1,on:!0})),[n,i]),{loading:a.loading,on:a.on,set:async r=>{let c=a.on;s({loading:!1,on:r});try{return await(0,o.setDoc)((0,o.doc)(t.Da,n,i),{enabled:r},{merge:!0}),e===`payments`&&J(),null}catch{return s({loading:!1,on:c}),`The switch could not be saved. Check that you are signed in as an admin.`}}}}var td=`The server could not be reached.`;function nd(e,t,n=0){let[i,a]=(0,r.useState)(null),[o,s]=(0,r.useState)(``),c=(0,r.useRef)(!0);(0,r.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]);let l=(0,r.useRef)(t);(0,r.useEffect)(()=>{l.current=t},[t]);let u=(0,r.useCallback)(async()=>{try{let t=await(await fetch(e)).json();if(!c.current)return;a(l.current(t)),s(``)}catch{c.current&&s(td)}},[e]);return(0,r.useEffect)(()=>{if(u(),!n)return;let e=setInterval(u,n);return()=>clearInterval(e)},[u,n]),{status:i,error:o,reread:u}}var rd=e=>({configured:!!e?.configured,mode:e?.mode===`live`||e?.mode===`test`?e.mode:null,webhookConfigured:!!e?.webhookConfigured}),id=e=>({configured:!!e?.configured,from:e?.from??null,adminCount:Number(e?.adminCount)||0}),ad={email:`/api/email/status`,payments:`/api/payments/status`},od=(e=0)=>nd(ad.payments,rd,e),sd=(e=0)=>nd(ad.email,id,e),cd=e=>!!e?.configured;function ld(e){let t=nd(ad[e],cd),n=ed(e);return{loading:t.status===null&&!t.error||n.loading,configured:t.status===!0,on:n.on}}var ud={collection:`sys_configs`,doc:`publish`},dd=[`published`,`connected`,`authorised`],fd={appName:``,domain:``,done:[]};function pd(e){let t=Array.isArray(e?.done)?e.done:[];return{appName:typeof e?.appName==`string`?e.appName:``,domain:typeof e?.domain==`string`?e.domain:``,done:dd.filter(e=>t.includes(e))}}function md(e){let t=String(e??``).trim().toLowerCase();return t=t.replace(/^[a-z][a-z0-9+.-]*:\/\//,``),t=t.split(/[/?#]/)[0],t=t.replace(/\.ai\.studio$/,``),t.replace(/[\s_]+/g,`-`).replace(/[^a-z0-9-]/g,``).replace(/-{2,}/g,`-`).replace(/^-+|-+$/g,``)}var hd=e=>{let t=md(e);return t?`https://${t}.ai.studio/`:``};function gd(e){let t=String(e??``).trim().toLowerCase();return t=t.replace(/^[a-z][a-z0-9+.-]*:\/\//,``),t=t.replace(/^[^/@]*@/,``),t=t.split(/[/?#]/)[0],t=t.split(`:`)[0],t=t.replace(/^www\./,``),t=t.replace(/^\.+|\.+$/g,``),/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)*\.[a-z]{2,}$/.test(t)?t:``}var _d=e=>{let t=gd(e);return t?`https://${t}/`:``},vd=e=>_d(e?.domain)||hd(e?.appName);function yd(e,t=null){let n=t=>e.includes(t),r=dd.find(e=>!n(e))??null,i=r?dd.indexOf(r):dd.length-1;return dd.map((e,a)=>{let o=a<=i,s=t!==null&&t===e&&o;return{id:e,visible:o,done:n(e),open:s||t===null&&e===r}})}var bd=(e,t)=>dd.filter(n=>n===t||e.includes(n));function xd(e){return!e||!e.configured?!1:e.mode===`live`?!e.webhookConfigured:!0}function Sd(){let[e,n]=(0,r.useState)({loading:!0,record:fd});return(0,r.useEffect)(()=>(0,o.onSnapshot)((0,o.doc)(t.Da,ud.collection,ud.doc),e=>n({loading:!1,record:pd(e.exists()?e.data():null)}),()=>n({loading:!1,record:fd})),[]),{loading:e.loading,record:e.record,save:async e=>{n(t=>({loading:!1,record:{...t.record,...e}}));try{return await(0,o.setDoc)((0,o.doc)(t.Da,ud.collection,ud.doc),e,{merge:!0}),null}catch(e){return console.error(`Could not save where you got to`,e),`That could not be saved. Only an admin can, and only while you are signed in.`}}}}function Cd(e,t){return!e&&t!==`live`?{state:`off`,label:`In test mode`}:t===`live`?{state:`saved`,label:`Live`}:{state:`saving`,label:`Waiting for the live key`}}var wd=[`checkout.session.completed`,`checkout.session.async_payment_succeeded`],Td=`text-[12.5px] font-medium text-foreground/70 leading-relaxed`,Ed=`mt-1.5 space-y-1 list-disc list-inside marker:text-foreground/30`,Dd=`my-2 glass-panel border border-[var(--panel-border)] rounded-2xl overflow-hidden bg-background`;function Od(){let[e,n]=(0,r.useState)(null),[a,s]=(0,r.useState)([]),{status:l}=od(5e3),u=l?.mode??null,d=l?.webhookConfigured??!1,[f]=Cu(),p=f===`local`,{record:m}=Sd(),h=z(vd(m)),g=m.done.includes(`authorised`)&&!!h;(0,r.useEffect)(()=>(0,o.onSnapshot)((0,o.collection)(t.Da,ji),e=>{n(!!e.docs.find(e=>e.id===Mi)?.data()?.liveMode);let t=[];e.forEach(e=>{e.id!==`_settings`&&t.push(Ui(e.id,e.data()))}),t.sort((e,t)=>(e.createdAt||0)-(t.createdAt||0)),s(t)},()=>n(!1)),[]);let _=async e=>{n(e);try{await(0,o.setDoc)((0,o.doc)(t.Da,ji,Mi),{liveMode:e},{merge:!0})}catch(e){console.error(`Could not save the go-live switch`,e)}},v=!!e,y=Cd(v,u),b=a.filter(e=>qi(e,!1)),x=b.filter(e=>!qi(e,!0)),S=b.length>0&&x.length===0,C=b.some(e=>e.kind===`subscription`);return(0,i.jsx)(t.ut,{icon:t.zr,title:`Go live`,description:v?`Real cards, real money — the steps below finish the switch.`:`Practice is free — flip this only when a test payment has gone all the way through.`,chip:y,enabled:e===null?null:v,onChange:_,children:v&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(`ol`,{className:`space-y-3.5 list-decimal list-inside ${Td}`,children:[(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`strong`,{children:`Your live secret key.`}),` In Stripe, click your account name in the top left corner and choose your `,(0,i.jsx)(`strong`,{children:`live`}),` account — not the sandbox.`,(0,i.jsxs)(`ul`,{className:Ed,children:[(0,i.jsxs)(`li`,{children:[`Open the dark strip along the bottom that says `,(0,i.jsx)(`strong`,{children:`Developers`}),`, and scroll down to the `,(0,i.jsx)(`strong`,{children:`API keys`}),` section.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Manage API keys`}),`. Under `,(0,i.jsx)(`strong`,{children:`Standard keys`}),`, click `,(0,i.jsx)(`strong`,{children:`+ Create secret key`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Where it asks `,(0,i.jsx)(`em`,{children:`How will you be using this key?`}),`, choose`,` `,(0,i.jsx)(`strong`,{children:`Powering an integration you built`}),`, then`,` `,(0,i.jsx)(`strong`,{children:`Create secret key`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Stripe asks you to confirm it is you: click `,(0,i.jsx)(`strong`,{children:`Send verification`}),` `,`and verify the request with the code it sends.`]}),(0,i.jsxs)(`li`,{children:[`Give the key a name — `,(0,i.jsx)(`span`,{className:`text-accent`,children:`my ai project app key`}),` `,`— and copy it. `,(0,i.jsx)(`strong`,{children:`Stripe will not show it to you again.`})]}),p?(0,i.jsxs)(`li`,{children:[`Open your `,(0,i.jsx)(`strong`,{children:`.env`}),` file and paste it over the sk_test_… value of `,(0,i.jsx)(`strong`,{children:`STRIPE_SECRET_KEY`}),` — replace it, do not add a second line. Start the app again, and the chip at the top of this card turns to `,(0,i.jsx)(`strong`,{children:`Live`}),` on its own.`]}):(0,i.jsxs)(`li`,{children:[`Click the `,(0,i.jsx)(`strong`,{children:`cog icon`}),` in the top right corner of your app in Google AI Studio and find the `,(0,i.jsx)(`strong`,{children:`Secrets`}),` tab. Paste the new key over the value of `,(0,i.jsx)(`strong`,{children:`STRIPE_SECRET_KEY`}),` — replace the sk_test_… one, do not add a second. Click `,(0,i.jsx)(`strong`,{children:`Apply`}),` and refresh this page: the chip at the top of this card turns to `,(0,i.jsx)(`strong`,{children:`Live`}),` on its own.`]})]})]}),C&&(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`strong`,{children:`Your live price ids.`}),` A subscription's prices are made fresh in live mode, so the ids under `,(0,i.jsx)(`strong`,{children:`What you sell`}),` change. Create each plan's price in your live Stripe account and paste its id there. Your test ids are kept and come straight back if you switch off again.`]}),(0,i.jsxs)(`li`,{children:[(0,i.jsx)(`strong`,{children:`The webhook.`}),` `,g?`What keeps receipts and your sale alerts sending when a buyer pays and never comes back to your app.`:`Stripe has to be able to reach your app from the outside, so this one waits until your app is published.`,` `,(0,i.jsx)(`span`,{className:`inline-block align-middle ml-0.5`,children:(0,i.jsx)(t.lt,{state:d?`saved`:`off`,label:d?`Connected`:`Not yet`})}),g?(0,i.jsxs)(`ul`,{className:Ed,children:[(0,i.jsxs)(`li`,{children:[`Still in your `,(0,i.jsx)(`strong`,{children:`live`}),` Stripe account, open the`,` `,(0,i.jsx)(`strong`,{children:`Developers`}),` strip at the bottom again and, in its top menu, click `,(0,i.jsx)(`strong`,{children:`Webhooks`}),`. Click `,(0,i.jsx)(`strong`,{children:`Add destination`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Leave every setting as it is. Under `,(0,i.jsx)(`strong`,{children:`Events`}),`, use the`,` `,(0,i.jsx)(`em`,{children:`Find event by name or description…`}),` search bar to find these two, and click the checkmark on each:`,(0,i.jsx)(`div`,{className:`mt-1.5 flex flex-col gap-1`,children:wd.map(e=>(0,i.jsx)(Ru,{code:e,label:e,compact:!0},e))}),`The first is an ordinary card payment. The second is a bank transfer landing hours later, when nobody is watching — without it those sales send no email at all.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Continue`}),` and keep it as a`,` `,(0,i.jsx)(`strong`,{children:`Webhook endpoint`}),`. Give the destination a name —`,` `,(0,i.jsx)(`span`,{className:`text-accent`,children:`my ai project receipts`}),`.`]}),(0,i.jsxs)(`li`,{children:[`As the `,(0,i.jsx)(`strong`,{children:`Endpoint URL`}),`, paste exactly this — your published address with the webhook route on the end:`,(0,i.jsx)(`div`,{className:`my-2`,children:(0,i.jsx)(Ru,{code:h,label:`Copy your webhook address`,compact:!0})})]}),(0,i.jsxs)(`li`,{children:[`Create the destination. On the right, under Webhooks, you will find its`,` `,(0,i.jsx)(`strong`,{children:`signing secret`}),` — it starts with `,(0,i.jsx)(`strong`,{children:`whsec_`}),`. Copy it.`]}),(0,i.jsxs)(`li`,{children:[p?(0,i.jsxs)(i.Fragment,{children:[`Add the line below to your `,(0,i.jsx)(`strong`,{children:`.env`}),` file with the whsec_… secret as its value, and start the app again. You are all set — the chip beside this step turns green.`]}):(0,i.jsxs)(i.Fragment,{children:[`Click the `,(0,i.jsx)(`strong`,{children:`cog icon`}),` in the top right corner of your app in Google AI Studio, scroll the menu along the top to `,(0,i.jsx)(`strong`,{children:`Secrets`}),` `,`and click `,(0,i.jsx)(`strong`,{children:`+ Add secret`}),`. Copy the name below into`,` `,(0,i.jsx)(`strong`,{children:`Secret name`}),` and paste the whsec_… secret as its value. Click `,(0,i.jsx)(`strong`,{children:`Apply`}),` and refresh this page. You are all set — the chip beside this step turns green.`]}),(0,i.jsx)(`div`,{className:Dd,children:(0,i.jsx)(Vu,{name:`STRIPE_WEBHOOK_SECRET`,hint:`the whsec_… signing secret from the destination you just made`})})]})]}):(0,i.jsxs)(`div`,{className:`mt-2 flex flex-col gap-2.5`,children:[(0,i.jsxs)(t.st,{children:[`Your app has no public address yet, and the preview address in this browser is not one Stripe can reach — it changes every session.`,` `,m.done.length===0?`Publish your app first`:`Finish publishing your app first`,`: this step opens on its own once step 3 of Publish App,`,` `,(0,i.jsx)(`strong`,{children:`Add your domains and email sender`}),`, is ticked. Everything above works in the meantime.`]}),(0,i.jsxs)(c.Link,{to:`/publish`,className:`inline-flex items-center gap-1.5 w-fit h-9 px-4 rounded-[var(--btn-radius,0.75rem)] text-[12.5px] font-bold border border-accent/40 bg-accent/10 text-accent hover:bg-accent/15 transition-all active:scale-[0.98] cursor-pointer`,children:[`Take me to Publish App`,(0,i.jsx)(t.Xi,{className:`w-3.5 h-3.5`})]})]})]})]}),(0,i.jsxs)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:[`One more switch lives in Stripe, not here: switching plans (monthly ↔ yearly, Basic ↔ Pro) appears in Stripe’s customer portal — where your buyers manage their own subscriptions — only if you allow it:`,` `,(0,i.jsx)(`a`,{href:`https://dashboard.stripe.com/settings/billing/portal`,target:`_blank`,rel:`noopener noreferrer`,className:`text-accent font-bold hover:underline`,children:`Stripe Settings → Billing → Customer portal`}),` `,`→ let customers switch plans.`]}),b.length>0&&!S&&(0,i.jsxs)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:[`Your subscriptions under What you sell now ask for `,(0,i.jsx)(`strong`,{children:`live`}),` price ids — `,x.length===b.length?`each one`:`${x.length} of ${b.length}`,` is still waiting. Your test ids are kept and come back if you switch back. Once the live ids are in, the message for your assistant appears right here.`]}),S&&(0,i.jsx)(it,{title:`Tell your assistant about the switch`,prompt:ja(b)})]})})}var kd={configured:!1,mode:null,webhookConfigured:!1};function Ad(e=5e3){let{status:t,error:n}=od(e);return{...t??kd,checked:t!==null||!!n}}function jd(e,t){if(!t.checked)return{state:`saving`,label:`Checking`};switch(e){case 1:case 2:return t.configured?{state:`saved`,label:`Done`}:{state:`off`,label:`Not yet`};case 3:return t.configured?{state:`saved`,label:t.mode===`live`?`Key found — live`:`Key found — test mode`}:{state:`off`,label:`No key yet`}}}var Md={configured:!1,from:null,adminCount:0};function Nd(e=5e3){let{status:t,error:n}=sd(e);return{...t??Md,checked:t!==null||!!n}}function Pd(e){return e.checked?e.configured?{state:`saved`,label:`Connected`}:{state:`off`,label:`Not yet`}:{state:`saving`,label:`Checking`}}function Fd(e){return e.checked?e.from&&!String(e.from).toLowerCase().endsWith(`@resend.dev`)?{state:`saved`,label:`Your own address`}:{state:`off`,label:`Practice address`}:{state:`saving`,label:`Checking`}}var Id=`text-accent underline underline-offset-2 font-semibold hover:text-accent-deep transition-colors`;function Ld({href:e,children:t}){return(0,i.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:Id,children:t})}function Rd({number:e,title:t,aside:n,children:r}){return(0,i.jsxs)(`div`,{className:`flex flex-col gap-3 pb-5 mb-5 border-b border-[var(--panel-border)]/50 last:border-0 last:pb-0 last:mb-0`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,i.jsx)(`span`,{className:`w-7 h-7 shrink-0 rounded-full bg-accent/10 border border-accent/20 text-accent flex items-center justify-center text-[12.5px] font-extrabold`,children:e}),(0,i.jsx)(`h4`,{className:`text-[14px] font-bold text-foreground tracking-tight flex-1 min-w-0`,children:t}),n]}),(0,i.jsx)(`div`,{className:`text-[13px] text-foreground/70 leading-relaxed space-y-3 sm:pl-[2.375rem]`,children:r})]})}var zd=`space-y-1.5 list-decimal list-inside text-foreground/75`,Bd=`glass-panel border border-[var(--panel-border)] rounded-2xl overflow-hidden bg-background`;function Vd({onConfirm:e,hint:n}){let[r]=Cu();return(0,i.jsxs)(`div`,{className:`flex flex-col gap-2 pt-1`,children:[(0,i.jsx)(t.Q,{icon:t.zi,onClick:e,className:`self-start`,children:`I have added the variables`}),(0,i.jsx)(`p`,{className:t.$,children:n||(r===`local`?`Start the app again first — a value added to .env while it is running is not read until then. If the chips have not turned green a minute later, reload this page.`:`Press Apply in AI Studio’s Secrets tab first — the app can only read a secret once it has been applied. If the chips have not turned green a minute later, reload this page.`)})]})}function Hd({icon:e,title:n,description:r,stepsDescription:a,button:o,secret:s,open:c,onOpen:l,confirmed:u,steps:d,children:f}){let[p]=Cu();return(0,i.jsx)(t.at,{icon:e,title:n,description:c?a:r,collapsible:!1,children:c?d:(0,i.jsxs)(i.Fragment,{children:[f,u&&(0,i.jsxs)(t.st,{tone:`error`,children:[`The app cannot see the key yet.`,` `,p===`local`?(0,i.jsxs)(i.Fragment,{children:[`Make sure `,s,` has a value in your .env file, start the app again, then reload this page`]}):(0,i.jsxs)(i.Fragment,{children:[`In AI Studio’s Secrets tab make sure `,s,` is there and press Apply, then reload this page`]}),` `,`— or open the steps again to check them.`]}),(0,i.jsxs)(`button`,{type:`button`,onClick:l,className:`inline-flex items-center gap-1.5 w-fit h-9 px-4 rounded-[var(--btn-radius,0.75rem)] text-[12.5px] font-bold border border-accent/40 bg-accent/10 text-accent hover:bg-accent/15 transition-all active:scale-[0.98] cursor-pointer`,children:[o,(0,i.jsx)(t.Xi,{className:`w-3.5 h-3.5`})]})]})})}function Ud({onConfirm:e}){let n=Ad(),[r]=Cu(),a=r===`local`;return(0,i.jsxs)(`div`,{className:`flex flex-col`,children:[(0,i.jsx)(Rd,{number:1,title:`Make a Stripe account`,aside:(0,i.jsx)(t.lt,{...jd(1,n)}),children:(0,i.jsxs)(`ol`,{className:zd,children:[(0,i.jsxs)(`li`,{children:[`Open `,(0,i.jsx)(Ld,{href:`https://dashboard.stripe.com`,children:`dashboard.stripe.com`}),` and create an account. It asks about your business — answer what you can and skip what you can't; none of it blocks the next steps.`]}),(0,i.jsxs)(`li`,{children:[`Click your account name in the `,(0,i.jsx)(`strong`,{children:`top left`}),` corner, choose`,` `,(0,i.jsx)(`strong`,{children:`Switch to sandbox`}),`, and make a sandbox for testing. A sandbox is a practice copy of Stripe: every card in it is pretend and every payment is practice, so nothing you do here can cost anyone real money.`]})]})}),(0,i.jsx)(Rd,{number:2,title:`Copy the test secret key`,aside:(0,i.jsx)(t.lt,{...jd(2,n)}),children:(0,i.jsxs)(`ol`,{className:zd,children:[(0,i.jsxs)(`li`,{children:[`Along the very bottom of the Stripe page is a dark bar that says `,(0,i.jsx)(`strong`,{children:`Developers`}),`. Click the arrow on it to unfold the panel.`]}),(0,i.jsxs)(`li`,{children:[`On the right of that panel, under `,(0,i.jsx)(`strong`,{children:`Testing tools`}),`, is your`,` `,(0,i.jsx)(`strong`,{children:`secret key`}),` — it starts with `,(0,i.jsx)(`strong`,{children:`sk_test_`}),`. Copy it.`]})]})}),(0,i.jsxs)(Rd,{number:3,title:a?`Put it in your .env and start the app again`:`Paste it into Secrets and press Apply`,aside:(0,i.jsx)(t.lt,{...jd(3,n)}),children:[a?(0,i.jsxs)(`p`,{children:[`Open your `,(0,i.jsx)(`strong`,{children:`.env`}),` file — or ask your assistant to. The line below is already in it: paste the sk_test_… key between its quotes. One line, and that is the whole step — then `,(0,i.jsx)(`strong`,{children:`start the app again`}),` so it is read.`]}):(0,i.jsxs)(`ol`,{className:zd,children:[(0,i.jsxs)(`li`,{children:[`Click the `,(0,i.jsx)(`strong`,{children:`cog`}),` icon in the top right corner of your app in Google AI Studio.`]}),(0,i.jsxs)(`li`,{children:[`In the menu along the top, scroll across to `,(0,i.jsx)(`strong`,{children:`Secrets`}),`, then click`,` `,(0,i.jsx)(`strong`,{children:`+ Add secret`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Copy the name below into `,(0,i.jsx)(`strong`,{children:`Secret name`}),`, and paste the sk_test_… key you just copied as the value.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Apply`}),`, then refresh the page. You are all set.`]})]}),(0,i.jsx)(`div`,{className:Bd,children:(0,i.jsx)(Vu,{name:`STRIPE_SECRET_KEY`,hint:`the sk_test_… key you copied in step 2`})}),(0,i.jsxs)(`p`,{children:[`Now you can test a payment with the pretend card `,(0,i.jsx)(`strong`,{children:`4242 4242 4242 4242`}),` and any other details you like, or by paying with Google Pay or Apple Pay. Nothing is ever charged — a sandbox is all practice.`]})]}),(0,i.jsx)(Vd,{onConfirm:e})]})}function Wd({onConfirm:e}){let n=Nd(),[r]=Cu(),a=r===`local`;return(0,i.jsxs)(`div`,{className:`flex flex-col`,children:[(0,i.jsx)(Rd,{number:1,title:`Make a Resend account and a key`,aside:(0,i.jsx)(t.lt,{...Pd(n)}),children:(0,i.jsxs)(`ol`,{className:zd,children:[(0,i.jsxs)(`li`,{children:[`Open `,(0,i.jsx)(Ld,{href:`https://resend.com`,children:`resend.com`}),` and create a free account — it is the service that delivers email for you. Sign up with the address you want your app's mail to reach you at.`]}),(0,i.jsxs)(`li`,{children:[`In Resend, open `,(0,i.jsx)(`strong`,{children:`API Keys`}),` and click `,(0,i.jsx)(`strong`,{children:`Create API key`}),`. Copy the key it shows — it starts with `,(0,i.jsx)(`strong`,{children:`re_`}),` — and keep the tab open.`]})]})}),(0,i.jsxs)(Rd,{number:2,title:a?`Put two values in your .env and start the app again`:`Paste two secrets and press Apply`,aside:(0,i.jsx)(t.lt,{...Pd(n)}),children:[a?(0,i.jsxs)(`p`,{children:[`Open your `,(0,i.jsx)(`strong`,{children:`.env`}),` file. Both lines below are already in it — paste each value between its quotes, then `,(0,i.jsx)(`strong`,{children:`start the app again`}),` so they are read.`]}):(0,i.jsxs)(`ol`,{className:zd,children:[(0,i.jsxs)(`li`,{children:[`Click the `,(0,i.jsx)(`strong`,{children:`cog`}),` icon in the top right corner of your app in Google AI Studio.`]}),(0,i.jsxs)(`li`,{children:[`In the menu along the top, scroll across to `,(0,i.jsx)(`strong`,{children:`Secrets`}),`.`]}),(0,i.jsxs)(`li`,{children:[`For each row below, click `,(0,i.jsx)(`strong`,{children:`+ Add secret`}),`, copy the name here into`,` `,(0,i.jsx)(`strong`,{children:`Secret name`}),`, and paste the value.`]}),(0,i.jsxs)(`li`,{children:[`Click `,(0,i.jsx)(`strong`,{children:`Apply`}),`, then refresh the page.`]})]}),(0,i.jsxs)(`div`,{className:Bd,children:[(0,i.jsx)(Vu,{name:`RESEND_API_KEY`,hint:`the re_… key you just made in Resend`}),(0,i.jsx)(Vu,{name:`ADMIN_EMAILS`,hint:`your own email address — where sale, booking and form alerts are sent`})]})]}),(0,i.jsxs)(Rd,{number:3,title:`Verify your domain, or mail only reaches you`,aside:(0,i.jsx)(t.lt,{...Fd(n)}),children:[(0,i.jsxs)(`p`,{children:[(0,i.jsx)(`strong`,{children:`Until you verify a domain of your own, Resend delivers only to the email address you made your Resend account with.`}),` A test email to yourself works; a customer's confirmation, a buyer's receipt, a booking note to someone else does not arrive at all. Do this before anyone but you should get an email.`]}),(0,i.jsxs)(`ol`,{className:zd,children:[(0,i.jsxs)(`li`,{children:[`In Resend open `,(0,i.jsx)(Ld,{href:`https://resend.com/domains`,children:`Domains`}),`, click `,(0,i.jsx)(`strong`,{children:`Add domain`}),` `,`and type the domain you own — `,(0,i.jsx)(`strong`,{children:`yourbusiness.com`}),`, without www.`]}),(0,i.jsx)(`li`,{children:`Resend shows a few DNS records. Add each one where your domain is managed — the company you bought it from, or wherever its website is hosted — copying name and value exactly.`}),(0,i.jsxs)(`li`,{children:[`Back in Resend, click `,(0,i.jsx)(`strong`,{children:`Verify`}),`. It can take a few minutes to turn green; if it does not, one record was copied wrong.`]}),a?(0,i.jsxs)(`li`,{children:[`Fill in one more line in your `,(0,i.jsx)(`strong`,{children:`.env`}),` — an address at that domain, which is what your mail goes out as — and `,(0,i.jsx)(`strong`,{children:`start the app again`}),`.`]}):(0,i.jsxs)(`li`,{children:[`Add one more secret in AI Studio — an address at that domain, which is what your mail goes out as — and press `,(0,i.jsx)(`strong`,{children:`Apply`}),` again.`]})]}),(0,i.jsx)(`div`,{className:Bd,children:(0,i.jsx)(Vu,{name:`EMAIL_FROM`,hint:`an address at your verified domain, like hello@yourbusiness.com`})})]}),(0,i.jsx)(Vd,{onConfirm:e})]})}function Gd(){return(0,i.jsx)(c.Navigate,{to:`/setup`,replace:!0})}function Kd(e){return e.kind===`subscription`?e.active?{label:`Subscription active`,tone:`good`}:{label:`Cancelled`,tone:`quiet`}:e.fullyRefunded?{label:`Refunded`,tone:`bad`}:(e.amountRefunded||0)>0?{label:`Partially refunded`,tone:`bad`}:e.paid?{label:`Paid`,tone:`good`}:{label:`Not paid`,tone:`quiet`}}function qd(e,t){if(e==null)return`—`;try{return new Intl.NumberFormat(void 0,{style:`currency`,currency:(t||`usd`).toUpperCase()}).format(e)}catch{return`${e} ${(t||``).toUpperCase()}`.trim()}}var Jd=e=>e?{description:`Every Pay button on your pages works. Switch it off to pause all of it at once.`,chip:{state:`saved`,label:`On`}}:{description:`No Pay button shows and nothing can be bought. Your pages keep their settings.`,chip:{state:`off`,label:`Off`}},Yd=e=>e?new Date(e*1e3).toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`}):``;function Xd({label:e,tone:t}){return(0,i.jsx)(`span`,{className:`inline-flex items-center h-6 px-2.5 rounded-full border text-[11px] font-bold whitespace-nowrap shrink-0 ${t===`good`?`text-emerald-500 bg-emerald-500/10 border-emerald-500/20`:t===`bad`?`text-red-500 bg-red-500/10 border-red-500/20`:`text-foreground/50 bg-foreground/[0.04] border-[var(--panel-border)]`}`,children:e})}function Zd(){let{user:e}=t.na(),{status:n,error:a,reread:o}=od(),[s,c]=(0,r.useState)(!1),[l,u]=(0,r.useState)(!1),[d,f]=(0,r.useState)(null),[p,m]=(0,r.useState)(``),[h,g]=(0,r.useState)([]),[_,v]=(0,r.useState)([]),[y,b]=(0,r.useState)(!1),[x,S]=(0,r.useState)(``),[C,w]=(0,r.useState)(!1),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(``),k=ed(`payments`),[A,j]=(0,r.useState)(``),M=Jd(k.on),N=(0,r.useCallback)(async t=>{let n=e?await e.getIdToken():``,r=await fetch(t,{headers:n?{Authorization:`Bearer ${n}`}:void 0}),i=await r.json().catch(()=>({}));if(!r.ok||i?.success===!1)throw Error(i?.error||`The server could not answer.`);return i},[e]),P=()=>{c(!1),o().then(()=>u(!0))},F=(0,r.useCallback)((e,t)=>{let n=e.charges||[],r=e.subscriptions||[];g(e=>t?[...e,...n]:n),v(e=>t?[...e,...r]:r),w(!!(e.chargesHasMore||e.subscriptionsHasMore))},[]);(0,r.useEffect)(()=>{if(!n?.configured||!e)return;let t=!1;return N(`/api/payments/products`).then(e=>{t||f(e.products||[])}).catch(e=>{t||m(e.message)}),N(`/api/payments/orders`).then(e=>{t||(F(e,!1),b(!0))}).catch(e=>{t||(S(e.message),b(!0))}),()=>{t=!0}},[n?.configured,e,N,F]);let I=async()=>{E(!0);try{let e=new URLSearchParams,t=h[h.length-1],n=_[_.length-1];t&&e.set(`starting_after`,t.id),n&&e.set(`subscriptions_after`,n.id),F(await N(`/api/payments/orders?${e}`),!0)}catch(e){S(e.message)}E(!1)},L=e=>{navigator.clipboard?.writeText(e),O(e),setTimeout(()=>O(``),2e3)},R=[...h,..._].sort((e,t)=>(t.created||0)-(e.created||0)),z=(d||[]).flatMap(e=>e.prices),B=n?.mode===`live`?`https://dashboard.stripe.com/products`:`https://dashboard.stripe.com/test/products`,V=!!(n&&!n.configured);return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,i.jsx)(Ce,{children:`Payments`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/payments`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-5 md:p-8 shadow-2xl relative bg-background flex flex-col min-h-[600px]`,children:!n&&!a?(0,i.jsx)(`div`,{className:`flex items-center justify-center flex-1 text-foreground/40 py-16`,children:(0,i.jsx)(t.ti,{className:`w-6 h-6 animate-spin text-accent`})}):V?(0,i.jsx)(Hd,{icon:t.wi,title:`Connect Stripe`,description:`This app is not taking payments yet.`,stepsDescription:`Three steps — about five minutes, with pretend money until you say otherwise.`,button:`Set up payments`,secret:`STRIPE_SECRET_KEY`,open:s,onOpen:()=>c(!0),confirmed:l,steps:(0,i.jsx)(Ud,{onConfirm:P}),children:(0,i.jsx)(t.st,{children:`Payments run through Stripe, and connecting it is one pasted key — no code, no terminal. Once it is in, this screen fills itself: what you sell, and every payment as it happens.`})}):(0,i.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[n?.mode===`live`&&(0,i.jsxs)(`div`,{className:`flex items-center gap-3 rounded-2xl border border-red-500/25 bg-red-500/[0.06] px-4 py-3`,children:[(0,i.jsx)(t.Er,{className:`w-4 h-4 text-red-500 shrink-0`}),(0,i.jsx)(`p`,{className:`text-[12.5px] font-semibold text-red-500 leading-snug`,children:`Live mode — real cards are being charged. Every payment on this screen is real money.`})]}),(0,i.jsx)(t.ut,{icon:t.Hr,title:`Take payments`,description:M.description,chip:M.chip,enabled:k.loading?null:k.on,onChange:async e=>j(await k.set(e)||``),children:A?(0,i.jsx)(t.st,{tone:`error`,children:A}):null}),(0,i.jsx)(t.at,{icon:t.Wr,title:`Connection`,description:`Which Stripe account this app is running on.`,defaultOpen:!n?.configured,actions:a?(0,i.jsx)(t.lt,{state:`error`,label:`Unreachable`}):(0,i.jsx)(t.lt,{state:`saved`,label:n?.mode===`live`?`Live mode connected`:`Test mode connected`}),children:a?(0,i.jsx)(t.st,{tone:`error`,children:a}):(0,i.jsx)(t.st,{children:n?.mode===`live`?`Connected with a live key. Payments made anywhere on your site are real money.`:`Test mode connected. Your Pay buttons work end to end, but only test cards are accepted and no real money moves. When you are ready for real payments, use Go live below.`})}),(0,i.jsx)(Od,{}),(0,i.jsx)(fu,{}),(0,i.jsx)(t.at,{icon:t.Ar,title:`In your Stripe account`,description:`The products and prices Stripe has right now — where price ids come from.`,defaultOpen:!1,children:p?(0,i.jsx)(t.st,{tone:`error`,children:p}):d===null?(0,i.jsx)(`div`,{className:`flex items-center justify-center py-6 text-foreground/40`,children:(0,i.jsx)(t.ti,{className:`w-5 h-5 animate-spin text-accent`})}):z.length===0?(0,i.jsxs)(t.st,{children:[`Nothing needs to exist here for one-off payments — a Pay button can name its own amount. Only a subscription needs a price made in Stripe first:`,` `,(0,i.jsx)(`a`,{href:B,target:`_blank`,rel:`noreferrer`,className:`text-accent font-bold hover:underline`,children:`create one in your Stripe dashboard`}),` `,`and it appears here with its id ready to copy.`]}):(0,i.jsx)(`div`,{className:`flex flex-col gap-2.5`,children:z.map(e=>(0,i.jsxs)(`div`,{className:`flex items-center gap-3 px-3.5 py-2.5 ${t.X}`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-bold text-foreground truncate min-w-0 flex-1`,children:e.productName||`Unnamed product`}),(0,i.jsxs)(`span`,{className:`text-[12.5px] font-semibold text-foreground/60 whitespace-nowrap shrink-0`,children:[qd(e.amount,e.currency),e.interval?` / ${e.interval}`:``]}),(0,i.jsx)(t.Q,{compact:!0,icon:D===e.id?t.zi:t.Ti,title:`Copy the price id for ${e.productName||`this price`}`,onClick:()=>L(e.id),children:D===e.id?`Copied`:`Copy price id`})]},e.id))})}),(0,i.jsx)(t.at,{icon:t.Vr,title:`Payments received`,description:`Every charge and subscription, straight from Stripe.`,defaultOpen:!1,children:x?(0,i.jsx)(t.st,{tone:`error`,children:x}):y?R.length===0?(0,i.jsx)(t.st,{children:`Nothing yet. When someone pays, it lands here on its own — and refunds you make in Stripe show up here too, with nothing to sync.`}):(0,i.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[R.map(e=>{let n=Kd(e);return(0,i.jsxs)(`div`,{className:`flex items-center gap-3 px-3.5 py-2.5 ${t.X}`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0 flex-1`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-bold text-foreground truncate`,children:e.name||e.email||`Someone`}),(0,i.jsxs)(`span`,{className:`text-[11px] text-foreground/45 font-medium truncate`,children:[e.productName||e.description||(e.kind===`subscription`?`Subscription`:`One-off payment`),e.page?` — sold on ${e.page}`:``]})]}),(0,i.jsx)(`span`,{className:`max-sm:hidden text-[11.5px] font-medium text-foreground/45 whitespace-nowrap shrink-0`,children:Yd(e.created)}),(0,i.jsxs)(`span`,{className:`text-[12.5px] font-semibold text-foreground/70 whitespace-nowrap shrink-0`,children:[qd(e.amount,e.currency),e.kind===`subscription`&&e.interval?` / ${e.interval}`:``]}),(0,i.jsx)(Xd,{label:n.label,tone:n.tone})]},e.id)}),C&&(0,i.jsx)(t.Q,{busy:T,onClick:I,className:`self-center mt-1`,children:`Show older payments`})]}):(0,i.jsx)(`div`,{className:`flex items-center justify-center py-6 text-foreground/40`,children:(0,i.jsx)(t.ti,{className:`w-5 h-5 animate-spin text-accent`})})})]})})]})]})}var Qd=`w-[6.5rem] shrink-0`,$d=`w-9 h-9 rounded-[var(--btn-radius,0.75rem)] border border-[var(--panel-border)] flex items-center justify-center shrink-0 text-foreground/45 hover:text-red-500 hover:border-red-500/40 hover:bg-red-500/[0.06] active:scale-[0.98] transition-all cursor-pointer`,ef=`date-field h-9 w-[10.5rem] shrink-0 px-3 text-[13px] font-semibold bg-transparent border border-[var(--panel-border)] text-foreground focus:outline-none focus:border-accent transition-colors`,tf={from:`09:00`,to:`13:00`};function nf(e,t){return{upcoming:e.filter(e=>e.date>=t),past:e.filter(e=>e.date<t)}}function rf({row:e,onChange:n,onRemove:r}){let a=e.windows.length===0,o=(t,r)=>n({...e,windows:e.windows.map((e,n)=>n===t?{...e,...r}:e)});return(0,i.jsxs)(`div`,{className:`flex flex-col gap-2 py-2.5`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,i.jsx)(`input`,{type:`date`,value:e.date,"aria-label":`The date`,onChange:t=>n({...e,date:t.target.value}),className:ef,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(`div`,{className:`w-[11rem] shrink-0`,children:(0,i.jsx)(t.sr,{ariaLabel:`${e.date} — how much of it`,value:a?`all`:`some`,options:[{value:`all`,label:`All day`},{value:`some`,label:`Only some hours`}],onChange:t=>n({...e,windows:t===`all`?[]:[tf]}),className:`console-select`,compact:!0,dense:!0,portal:!0,direction:`auto`})}),(0,i.jsx)(`button`,{type:`button`,title:`Remove ${e.date||`this date`}`,"aria-label":`Remove ${e.date||`this date`}`,onClick:r,className:`${$d} ml-auto`,children:(0,i.jsx)(t._r,{className:`w-3.5 h-3.5`})})]}),!a&&(0,i.jsxs)(`div`,{className:`flex flex-col gap-2 sm:pl-[0.125rem]`,children:[e.windows.map((r,a)=>(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`div`,{className:Qd,children:(0,i.jsx)(t.sr,{ariaLabel:`${e.date} from${a?` (${a+1})`:``}`,value:r.from,options:t.Ot,onChange:e=>o(a,{from:e}),className:`console-select`,compact:!0,portal:!0,direction:`auto`})}),(0,i.jsx)(`span`,{className:`w-3 text-center text-foreground/40 text-[13px] shrink-0 select-none`,children:`–`}),(0,i.jsx)(`div`,{className:Qd,children:(0,i.jsx)(t.sr,{ariaLabel:`${e.date} to${a?` (${a+1})`:``}`,value:r.to,options:t.Tt,onChange:e=>o(a,{to:e}),className:`console-select`,compact:!0,portal:!0,direction:`auto`})}),e.windows.length>1&&(0,i.jsx)(`button`,{type:`button`,title:`Remove these hours on ${e.date}`,"aria-label":`Remove ${e.date} hours ${a+1}`,onClick:()=>n({...e,windows:e.windows.filter((e,t)=>t!==a)}),className:$d,children:(0,i.jsx)(t._r,{className:`w-3.5 h-3.5`})})]},a)),e.windows.length<2&&(0,i.jsx)(`button`,{type:`button`,onClick:()=>n({...e,windows:[...e.windows,{from:`14:00`,to:`18:00`}]}),className:`self-start h-6 px-1 text-[11.5px] font-semibold text-foreground/45 hover:text-accent transition-colors cursor-pointer`,children:`+ Add a second stretch`})]})]})}function af({blocked:e,onChange:n,now:a}){let o=t.qn(a?a():new Date),[s,c]=(0,r.useState)(!1),{upcoming:l,past:u}=nf(e,o),d=s?[...u,...l]:l,f=(t,r)=>n(e.map(e=>e===t?r:e));return(0,i.jsx)(t.Z,{label:`Days away`,hint:`Dates this week's hours do not apply to — a holiday, a flight, an afternoon out. Nobody can book them, on any link on these hours.`,children:(0,i.jsxs)(`div`,{className:`flex flex-col divide-y divide-[var(--panel-border)]/60 rounded-2xl border border-[var(--panel-border)]/60 px-4 py-1`,children:[d.length===0?(0,i.jsx)(`p`,{className:`${t.$} py-3`,children:`No days blocked out. Add one for a holiday or a day off.`}):d.map((t,r)=>(0,i.jsx)(rf,{row:t,onChange:e=>f(t,e),onRemove:()=>n(e.filter(e=>e!==t))},`${t.date}-${r}`)),(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 py-2.5`,children:[(0,i.jsx)(t.Q,{icon:t.Ur,compact:!0,title:`Add a day away`,onClick:()=>n([...e,{date:o,windows:[]}]),children:`Add a date`}),u.length>0&&(0,i.jsx)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`h-6 px-1 text-[11.5px] font-semibold text-foreground/45 hover:text-accent transition-colors cursor-pointer`,children:s?`Hide past dates`:`Show ${u.length} past date${u.length===1?``:`s`}`})]})]})})}var of=e=>t.xt.find(t=>t.value===e)?.label||`Short text`;function sf({options:e,onChange:n}){return(0,i.jsx)(t.Z,{label:`Choices`,hint:`What people pick from.`,children:(0,i.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.length===0&&(0,i.jsx)(`span`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug px-1`,children:`No choices yet — add the first one.`}),e.map((r,a)=>(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`input`,{type:`text`,value:r,"aria-label":`Choice ${a+1}`,placeholder:`e.g. At my place`,onChange:t=>n(e.map((e,n)=>n===a?t.target.value:e)),className:t.et}),(0,i.jsx)(t.Q,{icon:t._r,tone:`danger`,compact:!0,title:`Remove choice ${a+1}`,onClick:()=>n(e.filter((e,t)=>t!==a)),children:`Remove`})]},a)),(0,i.jsx)(`div`,{children:(0,i.jsx)(t.Q,{icon:t.Ur,onClick:()=>n([...e,``]),children:`Add choice`})})]})})}function cf({question:e,index:n,count:a,siblings:o,fixed:s,onChange:c,onMove:l,onRemove:u}){let[d,f]=(0,r.useState)(!e.label.trim()),p=e.label.trim()||`A new question`;return(0,i.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)]`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2.5 pr-2.5 sm:pr-3.5`,children:[(0,i.jsxs)(`button`,{type:`button`,onClick:()=>f(e=>!e),"aria-expanded":d,className:`flex-1 min-w-0 flex items-center justify-between gap-3 px-4 py-3.5 text-left cursor-pointer`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground/75 truncate`,children:p}),(0,i.jsxs)(`span`,{className:`flex items-center gap-2.5 shrink-0`,children:[(0,i.jsx)(`span`,{className:`${t.$} max-sm:hidden`,children:s?`Always asked`:`${of(e.type)}${e.required?` · must be answered`:``}`}),(0,i.jsx)(t.Ri,{className:`w-3.5 h-3.5 text-foreground/40 shrink-0 transition-transform ${d?`rotate-180`:``}`})]})]}),!s&&(0,i.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-1.5 shrink-0`,children:[(0,i.jsx)(t.Q,{icon:t.Ji,compact:!0,disabled:n===0,title:`Move ${p} up`,onClick:()=>l(-1),children:`Up`}),(0,i.jsx)(t.Q,{icon:t.Qi,compact:!0,disabled:n===a-1,title:`Move ${p} down`,onClick:()=>l(1),children:`Down`}),(0,i.jsx)(`span`,{className:`max-sm:hidden w-px h-5 bg-[var(--panel-border)] mx-0.5`}),(0,i.jsx)(t.Q,{icon:t.Or,tone:`danger`,compact:!0,title:`Remove ${p}`,onClick:u,children:`Remove`})]})]}),d&&(0,i.jsxs)(`div`,{className:`px-4 pb-4 pt-4 border-t border-[var(--panel-border)]/60 flex flex-col gap-4`,children:[(0,i.jsx)(t.ft,{label:`What are you asking?`,hint:s?`The words above the box. Every booking asks this one — you can only change how it is put.`:`The words above the box, as the person booking reads them.`,value:e.label,placeholder:s?`e.g. Who is coming?`:`e.g. What is your phone number?`,onChange:n=>c({...e,label:n,name:s?e.name:t.tn(e,n,o)})}),!s&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.ct,{label:`Kind of answer`,hint:`Sets the box they type into. The example below follows what you pick.`,value:e.type,options:t.xt,allowEmpty:!1,onChange:n=>c({...e,type:n,options:n===`select`?e.options:[],placeholder:t.$t(e,n)})}),(0,i.jsx)(t.mt,{label:`Must be answered`,hint:`On means they cannot book until it is filled in.`,hintWideOnly:!0,enabled:e.required,onChange:t=>c({...e,required:t})})]}),e.type===`select`&&(0,i.jsx)(sf,{options:e.options,onChange:t=>c({...e,options:t})}),t.en(e.type)&&(0,i.jsx)(t.ft,{label:`Example answer`,hint:e.type===`tel`?`Shown under the box — a phone box already starts with a dial code, so the example stands below it.`:`Faint grey words inside the empty box.`,value:e.placeholder,placeholder:t.bt[e.type]||`e.g. +1 555 0123`,onChange:t=>c({...e,placeholder:t})})]})]})}function lf({questions:e,onChange:n}){let r=e.filter(e=>t.vn(e.name)),a=e.filter(e=>!t.vn(e.name)),o=e=>n([...r,...e]);return(0,i.jsx)(t.Z,{label:`What does a booking ask for?`,children:(0,i.jsxs)(`div`,{className:`flex flex-col gap-3.5`,children:[r.map(t=>(0,i.jsx)(cf,{question:t,index:0,count:1,siblings:e,fixed:!0,onChange:r=>n(e.map(e=>e.name===t.name?r:e)),onMove:()=>{},onRemove:()=>{}},t.name)),a.map((t,n)=>(0,i.jsx)(cf,{question:t,index:n,count:a.length,siblings:e,onChange:e=>o(a.map((t,r)=>r===n?e:t)),onMove:e=>{let t=n+e;if(t<0||t>=a.length)return;let r=[...a];[r[n],r[t]]=[r[t],r[n]],o(r)},onRemove:()=>o(a.filter((e,t)=>t!==n))},n)),(0,i.jsxs)(`div`,{className:`flex flex-col items-start sm:flex-row sm:items-center gap-3 rounded-2xl border border-dashed border-[var(--panel-border)] px-4 py-3.5`,children:[(0,i.jsx)(t.Q,{icon:t.Ur,title:`Add a question`,onClick:()=>o([...a,t.Vt()]),children:`Add a question`}),a.length===0&&(0,i.jsx)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:`Nothing else is asked — just a name and an email.`})]})]})})}var uf=(e,t,n=72)=>e>=n&&e<=Math.max(n,t*.45);function df(e,t=340){if(!e)return null;let n=()=>{let t=e.getBoundingClientRect?.(),n=typeof window<`u`&&window.innerHeight||0;t&&n&&uf(t.top,n)||e.scrollIntoView?.({behavior:`smooth`,block:`start`})};return typeof setTimeout==`function`?setTimeout(n,t):(n(),null)}var ff=`__new_payment__`;function pf(){let[e,n]=(0,r.useState)([]);return(0,r.useEffect)(()=>{let e=(0,o.onSnapshot)((0,o.collection)(t.Da,ji),e=>{let t=[];e.forEach(e=>{e.id!==`_settings`&&t.push(Ui(e.id,e.data()))}),n(t.filter(e=>e.kind===`once`).sort((e,t)=>(e.createdAt||0)-(t.createdAt||0)))},()=>n([]));return()=>e()},[]),e}function mf({service:e,what:n,path:r,screen:a,children:o}){return e.loading?null:e.configured?e.on?(0,i.jsx)(i.Fragment,{children:o}):null:(0,i.jsxs)(`div`,{className:`rounded-2xl border border-accent/25 bg-accent/[0.05] px-4 py-3.5 flex flex-wrap items-center justify-between gap-x-4 gap-y-2`,children:[(0,i.jsxs)(`span`,{className:`text-[13px] font-medium text-foreground/70`,children:[`You do not have `,n,` set up yet.`]}),(0,i.jsxs)(c.Link,{to:r,className:`inline-flex items-center gap-1 text-[12px] font-bold text-accent hover:underline whitespace-nowrap`,children:[`Set it up on the `,a,` screen`,(0,i.jsx)(t.Xi,{className:`w-3 h-3`})]})]})}function hf({value:e,products:n,meetingName:a,canCreate:o,onChange:s,onCreate:c}){let[l,u]=(0,r.useState)(!1),[d,f]=(0,r.useState)(``),[p,m]=(0,r.useState)(``),[h,g]=(0,r.useState)(!1),_=[...n.map(e=>({value:e.id,label:`${Yi(e)} — ${Li(e).map(e=>e.amount).filter(Boolean).join(` + `)||`no price yet`}`})),...o?[{value:ff,label:`+ A new one-time payment`}]:[]],v=n.find(t=>t.id===e),y=d.trim()&&Ri(d)===null?`Just a number, like 25.`:void 0;return(0,i.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,i.jsx)(t.ct,{label:`Payment for this meeting`,hint:v?`Taken on the booking page before the time is confirmed. Its price and its link are on the Payments screen.`:o?`Optional. A one-time payment taken on the booking page before the time is confirmed.`:n.length?`Optional. One of the payments your admin set up, taken on the booking page before the time is confirmed.`:`Your admin has not set up a payment to charge for a meeting yet.`,value:l?ff:e,placeholder:`No payment`,options:_,onChange:e=>{if(e===`__new_payment__`){u(!0);return}u(!1),s(e)}}),l&&(0,i.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)]/60 px-4 py-3.5 flex flex-col gap-3`,children:[(0,i.jsx)(t.ft,{label:`The price`,hint:`Just the number — 25 charges 25 in your Stripe account's currency. The payment is called ${a} and appears on the Payments screen too.`,value:d,onChange:e=>{f(e),p&&m(``)},placeholder:`25`,error:p||y}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(t.Q,{icon:t.Ur,busy:h,onClick:async()=>{if(Ri(d)===null){m(`Just a number for the price, like 25.`);return}m(``),g(!0);let e=await c(a,d.trim());if(g(!1),e){m(e);return}u(!1),f(``)},children:`Create it`}),(0,i.jsx)(t.Q,{onClick:()=>{u(!1),m(``),f(``)},children:`Never mind`})]})]})]})}function gf({link:e,onChange:n}){return(0,i.jsx)(t.Z,{label:`Emails about bookings`,hint:`Sent the moment a time is taken. Every booking is in your Inbox and on the calendar regardless.`,children:(0,i.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-2xl border border-[var(--panel-border)]/60 px-4 py-3.5`,children:[(0,i.jsx)(t.mt,{label:`Email me when someone books`,hint:`A note at your address — the sale alert, when they paid.`,hintWideOnly:!0,enabled:e.notifyOwner,onChange:e=>n({notifyOwner:e})}),(0,i.jsx)(t.mt,{label:`Email them a confirmation`,hint:`Their receipt when they pay. For a free booking, a note that the time is theirs — to people who book signed in.`,hintWideOnly:!0,enabled:e.confirmBooker,onChange:e=>n({confirmBooker:e})})]})})}var _f=e=>{let n={...t.A(t.I(),e),createdAt:Date.now()};return{...n,name:t.Rt(n),description:t.Lt(n)}};function vf({link:e,schedules:n,products:r,services:a,isAdmin:o=!0,onChange:s,onCreatePayment:c}){let l=n.find(t=>t.id===e.scheduleId),u=t=>s({...e,...t}),d=t.N(e,l),f=l?t.j(e,l):null,p=n=>{let r={...e,...n};return{...n,...e.name.trim()===t.Rt(e)?{name:t.Rt(r)}:{},...e.description.trim()===t.Lt(e)?{description:t.Lt(r)}:{}}};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.ct,{label:`Which hours is it booked in?`,hint:`Change the hours and every meeting booked in them changes with it — one holiday, entered once, closes them all.`,value:e.scheduleId,options:n.map(e=>({value:e.id,label:t.pn(e)})),allowEmpty:!1,onChange:t=>{let r=n.find(e=>e.id===t);if(!r)return;let i=!l||e.memberName.trim()===l.memberName.trim();u(p({scheduleId:r.id,memberId:r.memberId,...i?{memberName:r.memberName}:{}}))}}),(0,i.jsx)(t.ft,{label:`What is it called?`,hint:`Visitors read this on the booking page. It starts named after its length — call it whatever you like. Left blank it goes back to ${t.Rt(e)}.`,value:e.name,onChange:e=>u({name:e}),placeholder:t.Rt(e)}),(0,i.jsx)(t.dt,{label:`A line or two about it`,hint:`Visitors read it under the name — what it is for, what to bring, what happens after. Emptied, the booking page simply shows none.`,value:e.description,onChange:e=>u({description:e}),placeholder:`A first conversation about what you need and how I can help.`}),(0,i.jsx)(t.ft,{label:`The name visitors see`,value:e.memberName,onChange:e=>u(p({memberName:e})),placeholder:`Anna`}),(0,i.jsx)(t.ct,{label:`How long is one booking?`,value:String(e.slotMinutes),options:t.Mt,allowEmpty:!1,onChange:e=>u(p({slotMinutes:Number(e)}))}),(0,i.jsx)(t.ct,{label:`How far ahead can people book?`,value:String(e.horizonDays),options:t.kt,allowEmpty:!1,onChange:e=>u({horizonDays:Number(e)})}),(0,i.jsx)(t.ct,{label:`How much notice do you need?`,value:String(e.noticeHours),options:t.At,allowEmpty:!1,onChange:e=>u({noticeHours:Number(e)})}),(0,i.jsx)(lf,{questions:e.questions,onChange:e=>u({questions:e})}),(0,i.jsx)(mf,{service:a.payments,what:`Stripe`,path:`/payments`,screen:`Payments`,children:(0,i.jsx)(hf,{value:e.paymentId,products:r,meetingName:t.F(e),canCreate:o,onChange:e=>u({paymentId:e}),onCreate:async(e,t)=>{let n=await c(e,t);return n&&n.startsWith(`p_`)?(u({paymentId:n}),null):n||`The payment could not be made — make sure you are signed in as an admin and try again.`}})}),(0,i.jsx)(mf,{service:a.email,what:`emails`,path:`/email`,screen:`Email`,children:(0,i.jsx)(gf,{link:e,onChange:u})}),(0,i.jsx)(t.Z,{label:`Booking link`,hint:f&&!d&&e.enabled?`Send it to anyone. They see the free times in their own time zone, pick one and book — and pay first, when a payment is attached.`:`The link opens once the meeting is complete and turned on.`,children:(0,i.jsx)(eu,{title:t.F(e),path:t.Qt(e.id)})}),(0,i.jsx)(`div`,{className:`pt-1`,children:d?e.enabled?(0,i.jsxs)(`span`,{className:`text-[11.5px] font-semibold text-amber-500`,children:[`Turned on, but not bookable yet — `,d]}):(0,i.jsx)(`span`,{className:t.$,children:d}):e.enabled?(0,i.jsx)(`span`,{className:`text-[11.5px] font-semibold text-emerald-500`,children:`Bookable — send the link, pick it on a page under Booking on this page, or add a Pick-a-time question to a form.`}):(0,i.jsx)(`span`,{className:t.$,children:`Complete — flip the switch at the top of the row to offer it.`})})]})}function yf({link:e,schedules:n,products:a,services:o,isAdmin:s=!0,open:c,fresh:l,error:u,onToggle:d,onChange:f,onRemove:p,onCreatePayment:m}){let h=n.find(t=>t.id===e.scheduleId),g=t.M(e,h),[_,v]=(0,r.useState)(!1),y=t.F(e),b=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!l)return;let e=df(b.current);return()=>{e&&clearTimeout(e)}},[l]),(0,i.jsxs)(`div`,{ref:b,className:`scroll-mt-4 rounded-2xl border border-[var(--panel-border)]`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-2.5 pr-3`,children:[(0,i.jsxs)(`button`,{type:`button`,onClick:d,"aria-expanded":c,className:`flex-1 min-w-0 flex items-center justify-between gap-3 px-4 py-3 text-left cursor-pointer`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground/75 truncate`,children:t.P(e,h)}),(0,i.jsxs)(`span`,{className:`flex items-center gap-2.5 shrink-0`,children:[(0,i.jsx)(`span`,{className:`max-sm:hidden`,children:(0,i.jsx)(t.lt,{state:g.state,label:g.label})}),(0,i.jsx)(t.Ri,{className:`w-3.5 h-3.5 text-foreground/40 shrink-0 transition-transform ${c?`rotate-180`:``}`})]})]}),(0,i.jsx)(t.pt,{enabled:e.enabled,onChange:t=>f({...e,enabled:t}),label:`${y} — can be booked`}),(0,i.jsx)(t.Q,{icon:t.Or,tone:`danger`,compact:!0,title:`Remove ${y}`,onClick:()=>v(!0),children:`Remove`})]}),(0,i.jsx)(Ve,{isOpen:_,title:`Remove ${y}?`,message:`Its booking link stops working and it leaves every page and form it was picked on. The hours it was booked in stay, and so do the bookings already taken.`,confirmText:`Yes, remove`,cancelText:`Keep it`,onCancel:()=>v(!1),onConfirm:()=>{v(!1),p()}}),c&&(0,i.jsx)(`div`,{className:`px-4 pb-4 pt-4 border-t border-[var(--panel-border)]/60 flex flex-col gap-4`,children:(0,i.jsx)(vf,{link:e,schedules:n,products:a,services:o,isAdmin:s,onChange:f,onCreatePayment:m})}),u&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 px-4 pb-3`,children:u})]})}function bf({isAdmin:e=!0}={}){let{user:n}=t.na(),{loading:a,docs:s}=t.b(),c=pf(),l={payments:ld(`payments`),email:ld(`email`)},[u,d]=(0,r.useState)({}),[f,p]=(0,r.useState)([]),[m,h]=(0,r.useState)(null),[g,_]=(0,r.useState)(null),[v,y]=(0,r.useState)({}),b=(0,r.useRef)(new Map),x=n?.uid||``,S=(0,r.useMemo)(()=>[...e?s.schedules:s.schedules.filter(e=>e.memberId===x)].sort((e,t)=>Number(t.memberId===x)-Number(e.memberId===x)),[s.schedules,e,x]),C=(0,r.useMemo)(()=>{let t=new Map(s.links.map(e=>[e.id,e]));for(let e of Object.values(u))t.set(e.id,e);for(let e of f)t.delete(e);return[...t.values()].filter(t=>e||t.memberId===x).sort((e,t)=>Number(t.memberId===x)-Number(e.memberId===x)||(e.createdAt||0)-(t.createdAt||0)||e.id.localeCompare(t.id))},[s.links,u,f,e,x]),w=e=>{let n=b.current.get(e.id);n&&clearTimeout(n),b.current.set(e.id,setTimeout(async()=>{b.current.delete(e.id);let n=await t.d(e);y(t=>{let r={...t};return n?r[e.id]=n:delete r[e.id],r})},600))},T=e=>{d(t=>({...t,[e.id]:e})),w(e)},E=()=>{let e=S.find(e=>e.memberId===x)||S[0];if(!e)return;let t=_f(e);d(e=>({...e,[t.id]:t})),h(t.id),_(t.id),w(t)},D=async e=>{let n=b.current.get(e);n&&(clearTimeout(n),b.current.delete(e)),d(t=>{let n={...t};return delete n[e],n}),p(t=>[...t,e]),m===e&&h(null);let r=await t.l(e);r&&(p(t=>t.filter(t=>t!==e)),y(t=>({...t,[e]:r})))},O=async(e,n)=>{let r={...Ii(`p_${Date.now().toString(36)}`),kind:`once`,items:[{name:e,amount:n}]};try{let{id:e,...n}=r;return await(0,o.setDoc)((0,o.doc)(t.Da,ji,e),n),e}catch(e){return console.error(`Could not make the payment`,e),null}};return(0,i.jsx)(t.at,{icon:t.ii,title:`Booking links`,description:`One per kind of meeting — pick the hours it is booked in, say how long it lasts and what it asks, and send the link.`,actions:!a&&S.length>0?({open:e})=>(0,i.jsx)(t.Q,{icon:t.Ur,compact:!0,title:`Add a booking link`,onClick:()=>{e(),E()},children:`Add a booking link`}):void 0,children:(0,i.jsx)(`div`,{className:`flex flex-col gap-3`,children:a?(0,i.jsx)(`p`,{className:t.$,children:`Loading your booking links…`}):S.length===0?(0,i.jsx)(`p`,{className:`${t.$} px-1`,children:`Add a schedule above first — a booking link is a meeting booked in somebody's hours, so there have to be hours to put it on.`}):C.length===0?(0,i.jsxs)(`p`,{className:`${t.$} px-1`,children:[`No booking link yet — press Add a booking link. It is what turns `,t.mn(S[0]),` into something people can book.`]}):C.map(t=>(0,i.jsx)(yf,{link:t,schedules:S,products:c,services:l,isAdmin:e,open:m===t.id,fresh:g===t.id,error:v[t.id],onToggle:()=>h(m===t.id?null:t.id),onChange:T,onRemove:()=>D(t.id),onCreatePayment:O},t.id))})})}var xf=(e,n=`host`)=>e.heldOnly?`Held time`:n===`booker`?e.scheduleName.trim()||`A meeting`:t.cn(e),Sf=(e,t=`host`)=>e.heldOnly?`Held with no booking behind it`:e.own?`Your own event`:t===`booker`?e.memberName.trim()?`With ${e.memberName.trim()}`:`Booked`:e.scheduleName||e.email||`Booked`,Cf=(e,n=`host`)=>n===`booker`&&!e.heldOnly?t.Yt(e):xf(e,n),wf=e=>!e.pending||e.cancelled||e.own||e.heldOnly?``:e.partySize>1?`${e.partyAccepted} of ${e.partySize}`:`Pending`;function Tf({value:e,onChange:n}){return(0,i.jsx)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:t.Et.map(r=>{let a=r.value===e;return(0,i.jsx)(`button`,{type:`button`,title:r.label,"aria-label":r.label,"aria-pressed":a,onClick:()=>n(r.value),className:`w-8 h-8 rounded-full transition-all cursor-pointer active:scale-95 flex items-center justify-center ${r.value?`border-2`:`border-2 border-dashed`} ${a?`scale-105`:`hover:scale-105`}`,style:{background:t.ln(r.value,a?55:30),borderColor:a?t.sn(r.value):t.ln(r.value,40)},children:a&&(0,i.jsx)(`span`,{className:`w-2 h-2 rounded-full`,style:{background:t.sn(r.value)}})},r.value||`theme`)})})}function Ef({className:e=``}){return(0,i.jsx)(`span`,{className:`inline-flex items-center h-[18px] px-1.5 rounded-md shrink-0 border border-red-500/25 bg-red-500/10 text-[10px] font-bold uppercase tracking-[0.08em] text-red-500/90 ${e}`,children:`Cancelled`})}function Df({label:e=`Pending`,className:t=``}){return(0,i.jsx)(`span`,{title:`Waiting to be accepted`,className:`inline-flex items-center h-[18px] px-1.5 rounded-md shrink-0 border border-amber-500/25 bg-amber-500/10 text-[10px] font-bold uppercase tracking-[0.08em] text-amber-600 dark:text-amber-400 ${t}`,children:e})}function Of({className:e=``}){return(0,i.jsx)(`span`,{title:`Held with nothing booked`,className:`inline-flex items-center h-[18px] px-1.5 rounded-md shrink-0 border border-[var(--panel-border)] bg-foreground/[0.04] text-[10px] font-bold uppercase tracking-[0.08em] text-foreground/45 ${e}`,children:`Held`})}function kf({booking:e,zone:n,chip:r,withMember:a=!1,side:o=`host`,onOpen:s,now:c}){let l=e.end<(c?c():new Date).toISOString(),u=e.cancelled,d=wf(e),f=e.color;return(0,i.jsxs)(`button`,{type:`button`,onClick:s,"aria-label":`${t.dn(new Date(e.start),n)} — ${xf(e,o)}${u?` (cancelled)`:``}`,className:`group relative w-full text-left rounded-2xl border overflow-hidden flex items-stretch gap-2.5 p-2.5 transition-all cursor-pointer active:scale-[0.99] ${l&&!u?`opacity-60`:``} ${u||e.heldOnly?`border-dashed border-[var(--panel-border)]/60 bg-foreground/[0.02]`:``}`,style:u||e.heldOnly?void 0:{background:t.ln(f,7),borderColor:t.ln(f,26)},children:[(0,i.jsx)(`span`,{"aria-hidden":!0,className:`w-1 rounded-full shrink-0 ${u||e.heldOnly?`bg-foreground/15`:``}`,style:u||e.heldOnly?void 0:{background:t.ln(f,85)}}),(0,i.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-0 bg-foreground/0 group-hover:bg-foreground/[0.04] transition-colors`}),(0,i.jsxs)(`span`,{className:`relative flex-1 min-w-0 flex flex-col gap-0.5 py-0.5`,children:[(0,i.jsxs)(`span`,{className:`flex items-baseline gap-2 min-w-0`,children:[(0,i.jsx)(`span`,{className:`text-[12.5px] font-bold tabular-nums shrink-0 ${u?`text-foreground/45 line-through`:`text-foreground`}`,children:t.dn(new Date(e.start),n)}),(0,i.jsx)(`span`,{className:`text-[12.5px] font-semibold truncate ${u?`text-foreground/45 line-through`:`text-foreground/80`}`,children:xf(e,o)})]}),(0,i.jsxs)(`span`,{className:`flex items-center justify-between gap-2 min-w-0`,children:[(0,i.jsx)(`span`,{className:`text-[11.5px] font-medium text-foreground/45 truncate`,children:a&&e.memberName?`${e.memberName} · ${Sf(e,o)}`:Sf(e,o)}),u?(0,i.jsx)(Ef,{}):e.heldOnly?(0,i.jsx)(Of,{}):d?(0,i.jsx)(Df,{label:d}):r&&(0,i.jsx)(t.lt,{state:r.state,label:r.label})]})]})]})}var Af=e=>{let t=e.replace(/_/g,` `).trim();return t.charAt(0).toUpperCase()+t.slice(1)};function jf(e,t){let n=e.memberName.trim();if(e.partySize>1){let n=`${e.partyAccepted} of ${e.partySize} have accepted.`;return t?`${n} Yours is still to come.`:n}return t?`This is waiting for you to accept.`:n?`Waiting for ${n} to accept.`:`Waiting to be accepted.`}function Mf(e){let t=e.memberName.trim();return e.partySize>1?e.partyAccepted>0?`${e.partyAccepted} of ${e.partySize} have confirmed so far. You will hear once they all have.`:`Waiting to be confirmed. You will hear as soon as it is.`:t?`Waiting for ${t} to confirm. You will hear as soon as they do.`:`Waiting to be confirmed. You will hear as soon as it is.`}function Nf({open:e,onClose:n,children:a}){return(0,r.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,n]),(0,i.jsx)(t.pr,{children:e&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:n,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/80 backdrop-blur-xl cursor-pointer`}),(0,i.jsx)(t.fr.div,{role:`dialog`,"aria-modal":`true`,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-[420px] max-h-[85vh] overflow-y-auto styled-scrollbars-mini p-5 sm:p-6 rounded-3xl glass-popover border border-[var(--panel-border)] shadow-2xl relative z-10 text-left`,children:a})]})})}function Pf({color:e,title:n,line:r,cancelled:a,onClose:o}){return(0,i.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,i.jsx)(`span`,{"aria-hidden":!0,className:`w-1 self-stretch rounded-full shrink-0 ${a?`bg-foreground/15`:``}`,style:a?void 0:{background:t.ln(e,85)}}),(0,i.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,i.jsx)(`h3`,{className:`text-[17px] font-extrabold tracking-tight leading-tight break-words ${a?`text-foreground/50 line-through`:`text-foreground`}`,children:n}),a&&(0,i.jsx)(Ef,{})]}),(0,i.jsx)(`p`,{className:`text-[12.5px] font-medium text-foreground/50 leading-snug mt-0.5`,children:r})]}),(0,i.jsx)(`button`,{type:`button`,onClick:o,"aria-label":`Close`,className:t.R,children:(0,i.jsx)(t._r,{className:`w-4 h-4`})})]})}function Ff({label:e,children:t}){return(0,i.jsxs)(`div`,{className:`flex items-start justify-between gap-3 px-3.5 py-2.5`,children:[(0,i.jsx)(`span`,{className:`text-[12px] font-medium text-foreground/45 shrink-0`,children:e}),(0,i.jsx)(`span`,{className:`text-[12.5px] font-semibold text-foreground/80 text-right break-words min-w-0`,children:t})]})}function If({booking:e,zone:n,chip:a,me:o=``,side:s=`host`,onClose:c,onColor:l,onAccept:u,onCancel:d,onDelete:f,onRelease:p}){let[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(!1),[v,y]=(0,r.useState)(``),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(``),w=t.Hn(e,n),T=e.end<new Date().toISOString(),E=!e.own&&e.timeZone&&e.timeZone!==n?e.timeZone:``,D=Object.entries(e.answers).filter(([,e])=>e),O=s===`booker`,k=!e.heldOnly&&(D.length>0||!!E||!!a||!O&&!e.own&&(!!e.scheduleName||!!e.email||e.createdAt>0)),A=e.heldOnly,j=!A&&(e.own||e.cancelled||T),M=!O&&!!o&&e.memberId===o,N=wf(e),P=!!N&&M&&!!u,F=A?`Free this held time`:e.own?`Delete this event`:e.cancelled?`Remove this cancelled booking`:T?`Remove this booking`:N&&M?`Decline this booking`:`Cancel this booking`,I=A?!!p:j&&!!f,L=!j&&!A,R=!!N&&M&&!j;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(Nf,{open:!0,onClose:c,children:[(0,i.jsx)(Pf,{color:e.color,title:Cf(e,s),line:`${w.day} · ${w.time}`,cancelled:e.cancelled,onClose:c}),e.cancelled&&(0,i.jsxs)(`div`,{className:`mb-4 px-3.5 py-2.5 rounded-2xl border border-[var(--panel-border)] bg-foreground/[0.03] flex flex-col gap-1.5`,children:[(0,i.jsxs)(`p`,{className:`text-[12.5px] font-medium text-foreground/70 leading-snug`,children:[Lf(e),` The time is free again — it stays here so you have the record.`]}),!!e.cancelReason&&(0,i.jsxs)(`p`,{className:`text-[12.5px] font-semibold text-foreground/80 leading-snug border-l-2 border-[var(--panel-border)] pl-2.5`,children:[`“`,e.cancelReason,`”`]})]}),!!N&&(0,i.jsxs)(`div`,{className:`mb-4 px-3.5 py-3 rounded-2xl border border-amber-500/25 bg-amber-500/[0.07] flex flex-col gap-2.5`,children:[(0,i.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,i.jsx)(t.ki,{className:`w-4 h-4 shrink-0 mt-[1px] text-amber-600 dark:text-amber-400`,"aria-hidden":!0}),(0,i.jsx)(`p`,{className:`text-[12.5px] font-semibold text-foreground/75 leading-snug flex-1 min-w-0`,children:O?Mf(e):jf(e,M)}),e.partySize>1&&(0,i.jsx)(Df,{label:N})]}),P&&!g&&(0,i.jsxs)(t.cr,{onClick:async()=>{x(!0),C(``);let e=await u();x(!1),e&&C(e)},isLoading:b,className:`py-2 px-4 text-[13px] font-bold rounded-xl self-start`,children:[(0,i.jsx)(t.zi,{className:`w-3.5 h-3.5 shrink-0`,"aria-hidden":!0}),`Accept`]})]}),A&&(0,i.jsx)(`p`,{className:`mb-4 px-3.5 py-2.5 rounded-2xl border border-[var(--panel-border)] bg-foreground/[0.03] text-[12.5px] font-medium text-foreground/70 leading-snug`,children:`This hour is held with no booking behind it — a booking that was started and never finished. Nobody can take the time until it is freed, and there is nothing here to cancel.`}),k&&(0,i.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)]/60 bg-foreground/[0.015] divide-y divide-[var(--panel-border)]/40`,children:[!O&&!e.own&&e.scheduleName&&(0,i.jsx)(Ff,{label:`Meeting`,children:e.scheduleName}),!O&&e.email&&(0,i.jsx)(Ff,{label:`Email`,children:(0,i.jsx)(`a`,{href:`mailto:${e.email}`,className:`text-accent hover:underline break-all`,children:e.email})}),D.map(([e,n])=>(0,i.jsx)(Ff,{label:e===`note`?`Note`:Af(e),children:t.rr(n)?(0,i.jsx)(`span`,{className:`flex flex-col items-end gap-1 min-w-0`,children:t.nr(n).map(e=>(0,i.jsxs)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,title:t.tr(e),className:`inline-flex items-center gap-1.5 max-w-full min-w-0 text-accent hover:underline`,children:[(0,i.jsx)(t.qr,{className:`w-3.5 h-3.5 shrink-0`}),(0,i.jsx)(`span`,{className:`truncate min-w-0`,children:t.tr(e)})]},e))}):n},e)),E&&(0,i.jsxs)(Ff,{label:O?`The time you booked in`:`Their time`,children:[t.dn(new Date(e.start),E),` — `,t.Kn(E)]}),a&&(0,i.jsx)(Ff,{label:`Payment`,children:(0,i.jsx)(t.lt,{state:a.state,label:a.label})}),!O&&!e.own&&e.createdAt>0&&(0,i.jsx)(Ff,{label:`Booked`,children:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}).format(new Date(e.createdAt))})]}),!e.cancelled&&!A&&!!l&&(0,i.jsxs)(`div`,{className:`mt-4 flex flex-col gap-2`,children:[(0,i.jsx)(`span`,{className:`text-[12.5px] sm:text-[13px] font-medium text-foreground/50 select-none ml-1`,children:`Colour`}),(0,i.jsx)(Tf,{value:e.color,onChange:async e=>{C(``);let t=await l(e);t&&C(t)}}),(0,i.jsx)(`p`,{className:`text-[11px] font-medium text-foreground/40 leading-snug ml-1 mt-0.5`,children:`Shown on the calendar and in the day beside it.`})]}),g&&(0,i.jsxs)(`div`,{className:`mt-4 flex flex-col gap-3 p-3.5 rounded-2xl border border-[var(--panel-border)] bg-foreground/[0.02]`,children:[(0,i.jsx)(t.dt,{label:R?`Why are you turning it down?`:O?`Why can you not make it?`:`Why are you cancelling?`,value:v,onChange:y,placeholder:O?`Something has come up — I would like to book another time.`:`Something has come up and I cannot make this time — do book another.`,hint:O?`${e.memberName.trim()||`Whoever you booked with`} will see this.`:`${e.name.trim()||`Whoever booked`} will see this on the meeting.`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,i.jsx)(t.cr,{variant:`secondary`,onClick:()=>{_(!1),C(``)},disabled:b,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:`Keep it`}),(0,i.jsx)(t.cr,{onClick:async()=>{x(!0),C(``);let e=await d(v.trim());if(x(!1),e){C(e);return}_(!1),c()},isLoading:b,disabled:!v.trim(),className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl bg-red-500 hover:bg-red-600 border-none text-white shadow-lg hover:shadow-red-500/20 disabled:opacity-40 disabled:hover:bg-red-500 disabled:hover:shadow-none`,children:R?`Decline it`:`Cancel it`})]})]}),!g&&!L&&!I&&!O&&!A&&(0,i.jsx)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug mt-4 ml-1`,children:`Nothing left to do here — only an admin can take a booking off the calendar for good.`}),!!S&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 mt-3 ml-1`,children:S}),!g&&(0,i.jsxs)(`div`,{className:`mt-5 flex items-center gap-3 ${I||L?`justify-between`:`justify-end`}`,children:[(I||L)&&(0,i.jsx)(t.Q,{icon:I?t.Or:t.Hi,tone:`danger`,title:F,onClick:()=>I?h(!0):_(!0),children:A?`Free the time`:e.own?`Delete`:I?`Remove`:R?`Decline`:`Cancel booking`}),(0,i.jsx)(t.cr,{variant:`secondary`,onClick:c,className:`py-2 px-4 text-[13px] font-bold rounded-xl`,children:`Close`})]})]}),(0,i.jsx)(Ve,{isOpen:m,title:`${F}?`,message:A?`The hour goes back on offer. There is no booking behind it, so nothing else is lost.`:e.own?`It leaves your calendar and the time can be booked again.`:`It goes from the calendar for good, with everything it holds — in every diary it was booked into. This cannot be undone.`,confirmText:A?`Yes, free it`:e.own?`Yes, delete`:`Yes, remove`,cancelText:`Keep it`,isProcessing:b,onCancel:()=>h(!1),onConfirm:async()=>{x(!0);let e=await(A?p?.()??null:f?.()??null);x(!1),h(!1),e?C(e):c()}})]})}function Lf(e){let t=e.cancelledAt>0?` on ${new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}).format(new Date(e.cancelledAt))}`:``,n=e.cancelledBy.trim();return e.cancelledSide===`booker`?`${n||`The person who booked`} cancelled this${t}.`:e.cancelledSide===`host`?`${n||`Your team`} cancelled this${t}.`:`This booking was cancelled${t}.`}var Rf=(e,n,r,i)=>({title:``,time:e===i?t.Tn(r,n):`09:00`,minutes:`60`,color:``,note:``});function zf({dateKey:e,dayLabel:n,zone:a,today:o,now:s,onClose:c,onAdd:l}){let[u,d]=(0,r.useState)(()=>Rf(e,a,s?s():new Date,o)),[f,p]=(0,r.useState)(!1),[m,h]=(0,r.useState)(``),g=e=>d(t=>({...t,...e}));return(0,i.jsxs)(Nf,{open:!0,onClose:c,children:[(0,i.jsx)(Pf,{color:u.color,title:u.title.trim()||`Add an event`,line:`${n} · your time, ${t.Kn(a)}`,onClose:c}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-3.5`,children:[(0,i.jsx)(t.ft,{label:`What is it?`,value:u.title,onChange:e=>g({title:e}),placeholder:`Lunch with Sam`,hint:`Leave it empty and the time simply shows as busy.`}),(0,i.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,i.jsx)(t.ct,{label:`Starts at`,value:u.time,onChange:e=>g({time:e}),options:t.jt,allowEmpty:!1}),(0,i.jsx)(t.ct,{label:`Lasts`,value:u.minutes,onChange:e=>g({minutes:e}),options:t.Dt,allowEmpty:!1})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,i.jsx)(`span`,{className:`${t.nt} ml-1`,children:`Colour`}),(0,i.jsx)(Tf,{value:u.color,onChange:e=>g({color:e})})]}),(0,i.jsx)(t.dt,{label:`Note`,value:u.note,onChange:e=>g({note:e}),placeholder:`Anything to remember`})]}),(0,i.jsx)(`p`,{className:`text-[11.5px] font-medium text-foreground/40 leading-snug mt-3 ml-1`,children:`Nobody can book this time once it is here.`}),!!m&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 mt-3 ml-1`,children:m}),(0,i.jsxs)(`div`,{className:`mt-5 flex items-center gap-3`,children:[(0,i.jsx)(t.cr,{variant:`secondary`,onClick:c,disabled:f,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:`Cancel`}),(0,i.jsx)(t.cr,{onClick:async()=>{p(!0),h(``);let n=t.Qn(e,u.time,a),r=new Date(n.getTime()+Number(u.minutes)*6e4),i=await l({title:u.title.trim(),start:n.toISOString(),end:r.toISOString(),color:u.color,note:u.note.trim()});p(!1),i?h(i):c()},isLoading:f,className:`flex-1 py-2.5 text-[13px] font-bold rounded-xl`,children:`Add it`})]})]})}var Bf=(e,t)=>new Intl.DateTimeFormat(t,{timeZone:`UTC`,weekday:`short`,day:`numeric`,month:`long`}).format(new Date(`${e}T00:00:00Z`)),Vf=[`M`,`T`,`W`,`T`,`F`,`S`,`S`],Hf=e=>e.slice(0,7),Uf=(e,n,r)=>t.dn(e,n,r).replace(/[\s\u00a0\u202f]+/g,``).toLowerCase();function Wf(e,t=3){return e.length<=t?{shown:e,extra:0}:{shown:e.slice(0,t-1),extra:e.length-(t-1)}}var Gf=(e,t,n=`host`)=>n===`booker`?Cf(e,n):t&&e.memberName?`${xf(e)} · ${e.memberName}`:xf(e);function Kf(e,n){let r=new Map;for(let i of e){let e=t.Zn(new Date(i.start),n).dateKey,a=r.get(e)||[];a.push(i),r.set(e,a)}for(let e of r.values())e.sort((e,t)=>e.start.localeCompare(t.start));return r}function qf(e,t,n=!0){return!n||!e.paymentId&&!e.paymentSession?null:e.paymentSession?t===void 0?{state:`saving`,label:`Checking payment`}:t?{state:`saved`,label:`Paid`}:{state:`off`,label:`Awaiting payment`}:{state:`off`,label:`Not paid`}}var Jf=`h-8 px-3 rounded-xl border border-[var(--panel-border)]/60 inline-flex items-center gap-1.5 text-[12.5px] font-semibold text-foreground/60 hover:text-foreground hover:border-accent/40 hover:bg-foreground/5 active:scale-[0.98] transition-all cursor-pointer`;function Yf({bookings:e,zone:n,paid:a,openBookingId:o,onOpened:s,withMember:c=!1,me:l=``,side:u=`host`,onAccept:d,onCancel:f,onDelete:p,canDelete:m,onColor:h,onRelease:g,onAdd:_,now:v}){let y=t.Zn(v?v():new Date,n).dateKey,b=(0,r.useMemo)(()=>Kf(e,n),[e,n]),[x,S]=(0,r.useState)(Hf(y)),[C,w]=(0,r.useState)(y),[T,E]=(0,r.useState)(null),[D,O]=(0,r.useState)(!1),k=(0,r.useRef)(``);(0,r.useEffect)(()=>{if(!o){k.current=``;return}if(k.current===o)return;let r=e.find(e=>e.id===o);if(!r)return;k.current=o;let i=t.Zn(new Date(r.start),n).dateKey;S(Hf(i)),w(i),E(r.id),s?.()},[o,e,n,s]);let A=t.U(x),j=b.get(C)||[],M=(v?v():new Date).toISOString(),N=Bf(C),P=T?e.find(e=>e.id===T):void 0,{ref:F,moreBelow:I}=t.W(j.length,C);return(0,i.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-3 md:gap-4 w-full md:items-stretch`,children:[(0,i.jsxs)(`div`,{className:`${t.B} w-full md:flex-1 min-w-0`,children:[(0,i.jsxs)(`div`,{className:t.V,children:[(0,i.jsx)(`h4`,{className:`text-[14px] font-bold text-foreground tracking-tight truncate`,children:t.wn(x)}),(0,i.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[(0,i.jsx)(`button`,{type:`button`,onClick:()=>{S(Hf(y)),w(y)},className:Jf,children:`Today`}),(0,i.jsx)(`button`,{type:`button`,"aria-label":`Previous month`,onClick:()=>S(e=>t.Rn(e,-1)),className:t.R,children:(0,i.jsx)(t.Li,{className:`w-4 h-4`})}),(0,i.jsx)(`button`,{type:`button`,"aria-label":`Next month`,onClick:()=>S(e=>t.Rn(e,1)),className:t.R,children:(0,i.jsx)(t.Ii,{className:`w-4 h-4`})})]})]}),(0,i.jsx)(`div`,{className:`p-2 sm:p-3`,children:(0,i.jsxs)(`div`,{className:`grid grid-cols-7 gap-1`,role:`grid`,"aria-label":t.wn(x),children:[Vf.map((e,t)=>(0,i.jsx)(`div`,{className:`text-center text-[10.5px] font-bold uppercase tracking-wider text-foreground/35 pb-1`,children:e},t)),A.map((e,r)=>{if(!e)return(0,i.jsx)(`div`,{"aria-hidden":!0},`blank-${r}`);let a=b.get(e)||[],{shown:o,extra:s}=Wf(a),l=e===C,d=e===y;return(0,i.jsxs)(`button`,{type:`button`,role:`gridcell`,"aria-label":`${e}${a.length?`, ${a.length} booked`:``}`,"aria-selected":l,onClick:()=>w(e),className:`relative flex flex-col items-center sm:items-stretch justify-center sm:justify-start h-10 sm:h-[86px] rounded-xl sm:p-1 text-left transition-all cursor-pointer border ${l?`border-accent/70 bg-accent/[0.08] shadow-sm shadow-accent/10`:a.length?`border-transparent hover:bg-foreground/[0.05] hover:border-[var(--panel-border)]/60`:`border-transparent hover:bg-foreground/[0.03]`} ${d&&!l?`ring-1 ring-inset ring-accent/45`:``}`,children:[(0,i.jsx)(`span`,{className:`text-[13px] tabular-nums leading-none sm:px-1 sm:pt-0.5 sm:pb-1 ${l||d?`font-bold text-accent`:a.length?`font-bold text-foreground`:`font-semibold text-foreground/35`}`,children:Number(e.slice(8,10))}),(0,i.jsxs)(`span`,{"aria-hidden":!0,className:`max-sm:hidden sm:flex flex-col gap-[2px] w-full min-w-0`,children:[o.map(e=>(0,i.jsxs)(`span`,{className:`flex items-center gap-1 min-w-0 rounded-md pr-1 py-[2px] leading-[1.2] overflow-hidden ${e.end<M&&!e.cancelled?`opacity-50`:``} ${e.cancelled?`bg-foreground/[0.04] line-through`:``}`,style:e.cancelled?void 0:{background:t.ln(e.color,12)},children:[(0,i.jsx)(`span`,{className:`w-[3px] self-stretch rounded-full shrink-0 ${e.cancelled?`bg-foreground/15`:``}`,style:e.cancelled?void 0:{background:t.ln(e.color,85)}}),(0,i.jsx)(`span`,{className:`text-[9.5px] font-bold tabular-nums shrink-0 ${e.cancelled?`text-foreground/40`:`text-foreground/85`}`,children:Uf(new Date(e.start),n)}),(0,i.jsx)(`span`,{className:`text-[9.5px] font-medium truncate ${e.cancelled?`text-foreground/40`:`text-foreground/60`}`,children:Gf(e,c,u)})]},e.id)),s>0&&(0,i.jsxs)(`span`,{className:`px-1 text-[9.5px] font-bold text-foreground/45 leading-[1.2]`,children:[`+`,s,` more`]})]})]},e)})]})})]}),(0,i.jsx)(`div`,{className:`w-full md:w-[320px] shrink-0 md:relative md:min-h-[360px]`,children:(0,i.jsxs)(`div`,{className:`${t.B} flex flex-col md:absolute md:inset-0`,children:[(0,i.jsxs)(`div`,{className:t.V,children:[(0,i.jsx)(`p`,{className:`text-[13px] font-bold text-foreground tracking-tight truncate`,children:N}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[j.length>0&&(0,i.jsxs)(`span`,{className:`text-[11.5px] font-semibold text-foreground/40 tabular-nums max-sm:hidden`,children:[j.length,` `,j.length===1?`event`:`events`]}),_&&(0,i.jsxs)(`button`,{type:`button`,onClick:()=>O(!0),title:`Add an event on ${N}`,className:Jf,children:[(0,i.jsx)(t.Ur,{className:`w-3.5 h-3.5 shrink-0`}),`Add`]})]})]}),(0,i.jsxs)(`div`,{className:`relative flex-1 min-h-0`,children:[(0,i.jsx)(`div`,{ref:F,className:`p-3 h-full overflow-y-auto styled-scrollbars-mini flex flex-col gap-2`,children:j.length===0?(0,i.jsxs)(`div`,{className:`flex flex-col items-center justify-center text-center gap-2 py-8 px-2`,children:[(0,i.jsx)(t.Ui,{className:`w-5 h-5 text-foreground/25`,"aria-hidden":!0}),(0,i.jsx)(`p`,{className:`text-[12.5px] font-medium text-foreground/45 leading-relaxed`,children:`Nothing on this day yet.`})]}):j.map(e=>(0,i.jsx)(kf,{booking:e,zone:n,now:v,chip:qf(e,a?.[e.paymentSession],!!a),withMember:c,side:u,onOpen:()=>E(e.id)},e.id))}),I&&(0,i.jsx)(t.H,{})]})]})}),P&&(0,i.jsx)(If,{booking:P,zone:n,chip:qf(P,a?.[P.paymentSession],!!a),onClose:()=>E(null),me:l,side:u,onColor:h?e=>h(P.id,e):void 0,onAccept:d?()=>d(P):void 0,onCancel:e=>f(P,e),onDelete:p&&(!m||m(P))?()=>p(P):void 0,onRelease:g?()=>g(P):void 0}),D&&_&&(0,i.jsx)(zf,{dateKey:C,dayLabel:N,zone:n,today:y,now:v,onClose:()=>O(!1),onAdd:_})]})}var Xf=`team`,Zf=e=>`m:${e}`,Qf=`__nobody__`;function $f(e,n,r){return[{value:`me`,label:`My calendar`},{value:Xf,label:`My team's calendar`},...e.filter(e=>e.id!==r).map(e=>({value:Zf(e.id),label:t.h(e)||e.email,disabled:!n.has(e.id)}))]}var ep=e=>e.startsWith(`m:`)?e.slice(2):``;function tp(e){let[t,n]=(0,r.useState)({});return(0,r.useEffect)(()=>{let r=e.filter(e=>e.paymentSession&&t[e.paymentSession]===void 0);if(!r.length)return;let i=!1;return Promise.all(r.map(async e=>[e.paymentSession,(await ee(e.paymentSession)).paid])).then(e=>{i||n(t=>({...t,...Object.fromEntries(e)}))}),()=>{i=!0}},[e,t]),t}function np(e,n,r,i=``){if(!e.email)return Promise.resolve();let a=t.Hn(e,e.timeZone||r);return Xa(n,t.ht,e.id,{when:`${a.day}, ${a.time}`,memberName:e.memberName,scheduleName:e.scheduleName,reason:i.trim()}).then(()=>{}).catch(()=>{})}function rp(e,t,n){let r=e=>[...new Set(e.map(e=>String(e||``).trim()))].filter(e=>e&&e!==n),i=r([e.memberId,...t.map(e=>e.memberId),...e.copyIds.map(e=>e.split(`__`)[0])]);return{members:i,bookers:r([e.uid,...t.map(e=>e.uid)]).filter(e=>e!==`guest`).filter(e=>!i.includes(e))}}async function ip(e,n,r,i){if(e.own||e.heldOnly)return;let a={title:`Meeting removed`,body:`${t.Yt(e)} · ${t.un(new Date(e.start),i)}`};await np(e,`booking_cancelled`,i,`The meeting was removed from the calendar.`);let{members:o,bookers:s}=rp(e,n,r);await T(o,{...a,link:`/schedule`}),await T(s,{...a,link:`/my-bookings`})}function ap({isAdmin:e}){let{user:n}=t.na(),a=n?.uid||``,o=t.an(),[s,l]=(0,c.useSearchParams)(),u=s.get(`open`)||s.get(`booking`)||``,{schedules:d}=t.S(),{members:f}=t.C(),p=(0,r.useMemo)(()=>new Set(d.map(e=>e.memberId)),[d]),m=(0,r.useMemo)(()=>$f(f,p,a),[f,p,a]),[h,g]=(0,r.useState)(null);(0,r.useEffect)(()=>{u&&e&&g(e=>e??`team`)},[u,e]);let _=h??`me`,v=new Set(m.filter(e=>!e.disabled).map(e=>e.value)).has(_)?_:`me`,y=ep(v),{loading:b,bookings:x,error:S}=t.g({members:v===`team`?void 0:[y||a||Qf],includePast:!0}),C=tp(x),w=t.x((0,r.useMemo)(()=>(v===`team`?f.map(e=>e.id):[y||a]).filter(Boolean),[v,f,y,a]),(0,r.useMemo)(()=>{let e=new Date;return new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth()-1,1))},[])),[T,E]=(0,r.useState)(()=>Date.now());(0,r.useEffect)(()=>{let e=setInterval(()=>E(Date.now()),6e4);return()=>clearInterval(e)},[]);let D=(0,r.useMemo)(()=>t.O(x),[x]),O=(0,r.useMemo)(()=>{let e=x.map(e=>{let t=D.get(e.id);return t?{...e,...t}:e}),n=e=>{let n=f.find(t=>t.id===e);return d.find(t=>t.memberId===e)?.memberName||(n?t.h(n):``)},r=t.k(w,x,T).map(e=>t.D(e,n(e.memberId)));return r.length?[...e,...r]:e},[x,D,w,T,f,d]),k=y||a,A=f.find(e=>e.id===k),j=d.find(e=>e.memberId===k)?.memberName||(A?t.h(A):``)||(k===a?String(n?.displayName||``):``);return O.length===0?null:(0,i.jsx)(t.at,{icon:t.Ui,title:`Calendar`,description:v===`team`?`Every booking made with your team, and the events they put on their own days — in your time, ${t.Kn(o)}.`:y?`${j||`Their`} calendar, read as they read it — in your time, ${t.Kn(o)}.`:`Every booking made with you, under every schedule of yours — in your time, ${t.Kn(o)}.`,actions:e&&m.length>2?(0,i.jsx)(t.sr,{ariaLabel:`Whose calendar`,value:v,options:m,onChange:g,className:`console-select`,compact:!0,dense:!0,portal:!0,direction:`auto`}):void 0,children:b?(0,i.jsx)(`p`,{className:t.$,children:`Loading the calendar…`}):S?(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 px-1`,children:S}):(0,i.jsx)(Yf,{bookings:O,zone:o,paid:C,openBookingId:u||void 0,onOpened:u?()=>l(e=>(e.delete(`open`),e.delete(`booking`),e),{replace:!0}):void 0,withMember:v===Xf,me:a,onAccept:async e=>{let n=await t.n(e.id);return n||np(e,`booking_confirmed`,o),n},onCancel:async(e,r)=>{let i=await t.i(e.id,{ids:e.copyIds,reason:r,side:`host`,by:e.memberId===a?j||String(n?.displayName||``):e.memberName,byUid:a});return i||np(e,`booking_cancelled`,o,r),i},onDelete:async e=>(await ip(e,x,a,o),t.o(e.id,e.copyIds)),canDelete:t=>e||t.own&&t.memberId===a,onRelease:e=>t.s(e.memberId,e.start),onColor:t.p,onAdd:v===`team`?void 0:e=>t.r({...e,memberId:k,memberName:j,timeZone:o})})})}function op(e,t){if(!e.enabled)return{state:`off`,label:`Off`};if(lo(e,t))return{state:`error`,label:`Unfinished`};let n=e.schedules.length;return{state:`saved`,label:n===1?`1 meeting`:`${n} meetings`}}var sp=e=>{let t=e.schedules.length;return`${uo(e)} — ${t===0?`nothing on it yet`:t===1?`1 meeting`:`${t} meetings`}`};function cp({page:e,schedules:n,onChange:r}){return n.length?(0,i.jsx)(t.Z,{label:`Meetings on this page`,hint:`They appear in the order you tick them. A meeting switched off above is kept off the page too.`,children:(0,i.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:n.map(n=>{let a=e.schedules.includes(n.id);return(0,i.jsxs)(`button`,{type:`button`,role:`checkbox`,"aria-checked":a,onClick:()=>r(co(e,n.id)),className:`flex items-center gap-3 px-3 py-2.5 rounded-xl border text-left transition-all cursor-pointer active:scale-[0.995] ${a?`border-accent/45 bg-accent/[0.07]`:`border-[var(--panel-border)]/70 hover:border-accent/30 hover:bg-foreground/[0.03]`}`,children:[(0,i.jsx)(`span`,{"aria-hidden":!0,className:`w-[18px] h-[18px] rounded-[5px] border flex items-center justify-center shrink-0 transition-all ${a?`border-accent bg-accent`:`border-foreground/25`}`,children:a&&(0,i.jsx)(`span`,{className:`w-[7px] h-[7px] rounded-[2px] bg-[var(--button-fg,#fff)]`})}),(0,i.jsx)(`span`,{className:`flex-1 min-w-0 text-[13px] font-semibold text-foreground/80 truncate`,children:t.Fn(n)})]},n.id)})})}):(0,i.jsx)(t.Z,{label:`Meetings on this page`,children:(0,i.jsx)(`p`,{className:`${t.$} px-1`,children:`Make a schedule above first — a page offers the meetings you have set up.`})})}function lp({page:e,taken:n,onRename:a}){let[o,s]=(0,r.useState)(e.id),c=to(o),l=!!c&&c!==e.id&&n.includes(c);return(0,i.jsx)(t.ft,{label:`Its address`,prefix:`/meet/`,value:o,onChange:s,onBlur:()=>{if(!c||l||c===e.id){s(e.id);return}a(c)},placeholder:`anna-bell`,error:l?`Another page already has that address.`:void 0,hint:`Change it and the old link stops working, so change it before you send it out.`})}function up({page:e,schedules:n,taken:a,open:o,fresh:s,error:c,onToggle:l,onChange:u,onRename:d,onRemove:f}){let[p,m]=(0,r.useState)(!1),h=op(e,n),g=uo(e),_=lo(e,n),v=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!s)return;let e=df(v.current);return()=>{e&&clearTimeout(e)}},[s]),(0,i.jsxs)(`div`,{ref:v,className:`scroll-mt-4 rounded-2xl border border-[var(--panel-border)]`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-2.5 pr-3`,children:[(0,i.jsxs)(`button`,{type:`button`,onClick:l,"aria-expanded":o,className:`flex-1 min-w-0 flex items-center justify-between gap-3 px-4 py-3 text-left cursor-pointer`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground/75 truncate`,children:sp(e)}),(0,i.jsxs)(`span`,{className:`flex items-center gap-2.5 shrink-0`,children:[(0,i.jsx)(`span`,{className:`max-sm:hidden`,children:(0,i.jsx)(t.lt,{state:h.state,label:h.label})}),(0,i.jsx)(t.Ri,{className:`w-3.5 h-3.5 text-foreground/40 shrink-0 transition-transform ${o?`rotate-180`:``}`})]})]}),(0,i.jsx)(t.pt,{enabled:e.enabled,onChange:t=>u({...e,enabled:t}),label:`${g} — page is live`}),(0,i.jsx)(t.Q,{icon:t.Or,tone:`danger`,compact:!0,title:`Remove ${g}`,onClick:()=>m(!0),children:`Remove`})]}),(0,i.jsx)(Ve,{isOpen:p,title:`Remove ${g}?`,message:`Its link stops working. The meetings on it are untouched and keep their own links, and bookings already taken are kept.`,confirmText:`Yes, remove`,cancelText:`Keep it`,onCancel:()=>m(!1),onConfirm:()=>{m(!1),f()}}),o&&(0,i.jsxs)(`div`,{className:`px-4 pb-4 pt-4 border-t border-[var(--panel-border)]/60 flex flex-col gap-4`,children:[(0,i.jsx)(t.ft,{label:`Name on the page`,value:e.title,onChange:t=>u({...e,title:t}),placeholder:`Anna Bell`,hint:`Usually the name of whoever the page is for.`}),(0,i.jsx)(st,{label:`Photo`,hint:`Shown at the top of the page. A square picture of the person works best.`,value:e.photo,onChange:t=>u({...e,photo:t})}),(0,i.jsx)(t.dt,{label:`About this page`,value:e.intro,onChange:t=>u({...e,intro:t}),rows:3,placeholder:`I help small studios get their bookkeeping straight. Pick a time below and tell me what you need.`}),(0,i.jsx)(cp,{page:e,schedules:n,onChange:u}),(0,i.jsx)(lp,{page:e,taken:a,onRename:d}),_?(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-amber-500 px-1`,children:_}):(0,i.jsx)(eu,{title:g,path:ro(e.id)})]}),c&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 px-4 pb-3`,children:c})]})}function dp({schedules:e,myName:n,isAdmin:a=!0,meId:o=``}){let{loading:s,pages:c}=fo(),[l,u]=(0,r.useState)({}),[d,f]=(0,r.useState)([]),[p,m]=(0,r.useState)(null),[h,g]=(0,r.useState)(null),[_,v]=(0,r.useState)({}),y=(0,r.useRef)(new Map),b=new Map(c.map(e=>[e.id,e]));for(let e of Object.values(l))b.set(e.id,e);for(let e of d)b.delete(e);let x=[...b.values()].sort((e,t)=>(e.createdAt||0)-(t.createdAt||0)||e.id.localeCompare(t.id)),S=x.map(e=>e.id),C=ao(x,o,a),w=a?e:e.filter(e=>e.memberId===o),T=e=>{let t=y.current.get(e.id);t&&clearTimeout(t),y.current.set(e.id,setTimeout(async()=>{y.current.delete(e.id);let t=await po(e);v(n=>{let r={...n};return t?r[e.id]=t:delete r[e.id],r})},600))},E=e=>{u(t=>({...t,[e.id]:e})),T(e)},D=()=>{let e=eo(no(n||`my page`,S),n,o);u(t=>({...t,[e.id]:e})),f(t=>t.filter(t=>t!==e.id)),m(e.id),g(e.id),T(e)},O=async(e,t)=>{let n=y.current.get(e.id);n&&(clearTimeout(n),y.current.delete(e.id));let r={...e,id:t};u(n=>{let i={...n};return delete i[e.id],i[t]=r,i}),f(n=>[...n.filter(e=>e!==t),e.id]),p===e.id&&m(t);let i=await ho(e.id,r);i&&v(e=>({...e,[t]:i}))},k=async e=>{let t=y.current.get(e);t&&(clearTimeout(t),y.current.delete(e)),u(t=>{let n={...t};return delete n[e],n}),f(t=>[...t,e]),p===e&&m(null);let n=await mo(e);n&&(f(t=>t.filter(t=>t!==e)),v(t=>({...t,[e]:n})))};return(0,i.jsx)(t.at,{icon:t.ii,title:`Your booking pages`,description:`One link with a photo, a line about you and every meeting you offer.`,actions:({open:e})=>(0,i.jsx)(t.Q,{icon:t.Ur,compact:!0,title:`Create a page`,onClick:()=>{e(),D()},children:`Create a page`}),children:(0,i.jsx)(`div`,{className:`flex flex-col gap-3`,children:s?(0,i.jsx)(`p`,{className:`${t.$} px-1`,children:`Loading pages…`}):C.length===0?(0,i.jsx)(`p`,{className:`${t.$} px-1`,children:`No pages yet. Create one to hand out a single link — a visitor sees your photo, what you do and every meeting you offer, and picks the one they want.`}):C.map(e=>(0,i.jsx)(up,{page:e,schedules:w,taken:S,open:p===e.id,fresh:h===e.id,error:_[e.id],onToggle:()=>m(t=>t===e.id?null:e.id),onChange:E,onRename:t=>O(e,t),onRemove:()=>k(e.id)},e.id))})})}var fp={from:`09:00`,to:`17:00`},pp=e=>t.gn(e)?{state:`saved`,label:`Ready`}:{state:`off`,label:`In progress`},mp=e=>({...t.Ht(t.L(),e.id,t.h(e),t.an()),name:`Working hours`,enabled:!0,createdAt:Date.now()}),hp=`w-[6.5rem] shrink-0`,gp=`w-9 h-9 rounded-[var(--btn-radius,0.75rem)] border border-[var(--panel-border)] flex items-center justify-center shrink-0 text-foreground/45 hover:text-red-500 hover:border-red-500/40 hover:bg-red-500/[0.06] active:scale-[0.98] transition-all cursor-pointer`;function _p({day:e,windows:n,onChange:r}){let a=n.length>0,o=(e,t)=>r(n.map((n,r)=>r===e?{...n,...t}:n));return(0,i.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-[8.5rem_minmax(0,1fr)] items-start gap-x-4 gap-y-2 py-2.5`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 h-9`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-medium ${a?`text-foreground/80`:`text-foreground/40`}`,children:t.wt[e]}),(0,i.jsx)(t.pt,{enabled:a,onChange:e=>r(e?[fp]:[]),label:`${t.wt[e]} — bookable`})]}),a&&(0,i.jsxs)(`div`,{className:`flex flex-col gap-2 min-w-0`,children:[n.map((a,s)=>(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`div`,{className:hp,children:(0,i.jsx)(t.sr,{ariaLabel:`${t.wt[e]} from${s?` (${s+1})`:``}`,value:a.from,options:t.Ot,onChange:e=>o(s,{from:e}),className:`console-select`,compact:!0,portal:!0,direction:`auto`})}),(0,i.jsx)(`span`,{className:`w-3 text-center text-foreground/40 text-[13px] shrink-0 select-none`,children:`–`}),(0,i.jsx)(`div`,{className:hp,children:(0,i.jsx)(t.sr,{ariaLabel:`${t.wt[e]} to${s?` (${s+1})`:``}`,value:a.to,options:t.Tt,onChange:e=>o(s,{to:e}),className:`console-select`,compact:!0,portal:!0,direction:`auto`})}),n.length>1&&(0,i.jsx)(`button`,{type:`button`,title:`Remove these hours on ${t.wt[e]}`,"aria-label":`Remove ${t.wt[e]} hours ${s+1}`,onClick:()=>r(n.filter((e,t)=>t!==s)),className:gp,children:(0,i.jsx)(t._r,{className:`w-3.5 h-3.5`})})]},s)),n.length<2&&(0,i.jsx)(`button`,{type:`button`,onClick:()=>r([...n,{from:`18:00`,to:`20:00`}]),className:`self-start h-6 px-1 text-[11.5px] font-semibold text-foreground/45 hover:text-accent transition-colors cursor-pointer`,children:`+ Add a second stretch`})]})]})}function vp({schedule:e,onChange:n}){let r=t=>n({...e,...t}),a=t.hn(e);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.ft,{label:`What are these hours called?`,hint:`Only you and your team read this — it is how a booking link names the hours it is booked in. Working hours, Evenings, Studio days.`,value:e.name,onChange:e=>r({name:e}),placeholder:`Working hours`}),(0,i.jsx)(t.Y,{value:e.timeZone,onChange:e=>r({timeZone:e})}),(0,i.jsx)(t.Z,{label:`When`,hint:`The hours on each day, in this person's own time zone. Add a second stretch for a break in the middle. A time booked in any of their hours is taken here too.`,children:(0,i.jsx)(`div`,{className:`flex flex-col divide-y divide-[var(--panel-border)]/60 rounded-2xl border border-[var(--panel-border)]/60 px-4 py-1`,children:t.Ct.map(t=>(0,i.jsx)(_p,{day:t,windows:e.days[t]||[],onChange:n=>r({days:{...e.days,[t]:n}})},t))})}),(0,i.jsx)(af,{blocked:e.blocked,onChange:e=>r({blocked:e})}),(0,i.jsx)(`div`,{className:`pt-1`,children:a?(0,i.jsxs)(`span`,{className:`text-[11.5px] font-semibold text-amber-500`,children:[`Not usable yet — `,a]}):(0,i.jsx)(`span`,{className:`text-[11.5px] font-semibold text-emerald-500`,children:`Ready — add a booking link below to let people book these hours, or ask for a page built on them.`})})]})}function yp({schedule:e,open:n,stale:a,fresh:o,error:s,onToggle:c,onChange:l,onRemove:u}){let d=pp(e),[f,p]=(0,r.useState)(!1),m=t.mn(e),h=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!o)return;let e=df(h.current);return()=>{e&&clearTimeout(e)}},[o]),(0,i.jsxs)(`div`,{ref:h,className:`scroll-mt-4 rounded-2xl border border-[var(--panel-border)] ${a?`opacity-60`:``}`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2 sm:gap-2.5 pr-3`,children:[(0,i.jsxs)(`button`,{type:`button`,onClick:c,"aria-expanded":n,className:`flex-1 min-w-0 flex items-center justify-between gap-3 px-4 py-3 text-left cursor-pointer`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground/75 truncate`,children:t._n(e)}),(0,i.jsxs)(`span`,{className:`flex items-center gap-2.5 shrink-0`,children:[a?(0,i.jsx)(`span`,{className:`${t.$} max-sm:hidden`,children:`No longer on the team`}):(0,i.jsx)(`span`,{className:`max-sm:hidden`,children:(0,i.jsx)(t.lt,{state:d.state,label:d.label})}),(0,i.jsx)(t.Ri,{className:`w-3.5 h-3.5 text-foreground/40 shrink-0 transition-transform ${n?`rotate-180`:``}`})]})]}),(0,i.jsx)(t.Q,{icon:t.Or,tone:`danger`,compact:!0,title:`Remove ${m}`,onClick:()=>p(!0),children:`Remove`})]}),(0,i.jsx)(Ve,{isOpen:f,title:`Remove ${m}?`,message:a?`They are no longer on the team, so nobody can book them. Bookings already taken are kept.`:`Every booking link booked in these hours stops working, and they leave every page and form they were picked on. Bookings already taken are kept.`,confirmText:`Yes, remove`,cancelText:`Keep it`,onCancel:()=>p(!1),onConfirm:()=>{p(!1),u()}}),n&&(0,i.jsx)(`div`,{className:`px-4 pb-4 pt-4 border-t border-[var(--panel-border)]/60 flex flex-col gap-4`,children:(0,i.jsx)(vp,{schedule:e,onChange:l})}),s&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 px-4 pb-3`,children:s})]})}function bp({name:e,schedules:n,stale:a,open:o,onToggle:s,onAdd:c,openScheduleId:l,freshId:u,errors:d,onToggleSchedule:f,onChange:p,onRemove:m}){let h=a?`No longer on the team`:n.length===0?`No schedules yet`:`${n.length} schedule${n.length===1?``:`s`}`,g=(0,r.useRef)(null);return(0,r.useEffect)(()=>{if(!o)return;let e=df(g.current);return()=>{e&&clearTimeout(e)}},[o]),(0,i.jsxs)(`div`,{ref:g,className:`scroll-mt-4 rounded-2xl border border-[var(--panel-border)]`,children:[(0,i.jsxs)(`button`,{type:`button`,onClick:s,"aria-expanded":o,className:`w-full flex items-center justify-between gap-3 px-4 py-3 text-left cursor-pointer`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-semibold text-foreground/75 truncate`,children:e}),(0,i.jsxs)(`span`,{className:`flex items-center gap-2.5 shrink-0`,children:[(0,i.jsx)(`span`,{className:`${t.$} max-sm:hidden`,children:h}),(0,i.jsx)(t.Ri,{className:`w-3.5 h-3.5 text-foreground/40 shrink-0 transition-transform ${o?`rotate-180`:``}`})]})]}),o&&(0,i.jsxs)(`div`,{className:`px-4 pb-4 pt-4 border-t border-[var(--panel-border)]/60 flex flex-col gap-3`,children:[n.map(e=>(0,i.jsx)(yp,{schedule:e,stale:a,fresh:u===e.id,open:l===e.id,error:d[e.id],onToggle:()=>f(e.id),onChange:p,onRemove:()=>m(e.id)},e.id)),a?n.length===0&&(0,i.jsxs)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:[`No schedule yet for `,e,`.`]}):(0,i.jsxs)(`div`,{className:`flex flex-col items-start sm:flex-row sm:items-center gap-3 rounded-2xl border border-dashed border-[var(--panel-border)] px-4 py-3`,children:[(0,i.jsx)(t.Q,{icon:t.Ur,title:`Add a schedule for ${e}`,onClick:c,children:`Add a schedule`}),n.length===0&&(0,i.jsxs)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:[`No schedule yet for `,e,`.`]})]})]})]})}var xp=e=>({id:e.uid,name:String(e.displayName||``),email:String(e.email||``),role:`admin`});function Sp({isAdmin:e=!0}={}){let{user:n}=t.na(),{loading:a,members:o}=t.C(),{loading:s,docs:l}=t.b(),u=l.schedules,[d,f]=(0,r.useState)({}),[p,m]=(0,r.useState)([]),[h,g]=(0,r.useState)(null),[_,v]=(0,r.useState)(null),[y,b]=(0,r.useState)(null),[x,S]=(0,r.useState)({}),C=(0,r.useRef)(new Map),w=(0,r.useMemo)(()=>{let e=new Map(u.map(e=>[e.id,e]));for(let t of Object.values(d))e.set(t.id,t);for(let t of p)e.delete(t);return[...e.values()].sort((e,t)=>(e.createdAt||0)-(t.createdAt||0)||e.id.localeCompare(t.id))},[u,d,p]),T=e=>{let n=C.current.get(e.id);n&&clearTimeout(n),C.current.set(e.id,setTimeout(async()=>{C.current.delete(e.id);let n=await t.f(e);S(t=>{let r={...t};return n?r[e.id]=n:delete r[e.id],r})},600))},E=e=>{f(t=>({...t,[e.id]:e})),T(e)},D=(0,r.useMemo)(()=>n?o.find(e=>e.id===n.uid)||xp(n):null,[n,o]),O=(0,r.useMemo)(()=>D&&!o.some(e=>e.id===D.id)?[D,...o]:o,[D,o]),k=(0,r.useRef)(!1),[A,j]=(0,r.useState)(``),M=(0,r.useMemo)(()=>l.schedules.filter(t=>l.legacyIds.includes(t.id)&&(e||t.memberId===D?.id)),[l.schedules,l.legacyIds,e,D]);(0,r.useEffect)(()=>{k.current||M.length===0||(k.current=!0,t.m(M).then(e=>{e&&j(e)}))},[M]);let N=e=>{let t=mp(e);f(e=>({...e,[t.id]:t})),g(t.id),v(t.id),D&&e.id!==D.id&&b(e.id),T(t)},P=()=>{D&&N(D)},F=async e=>{let n=C.current.get(e);n&&(clearTimeout(n),C.current.delete(e)),f(t=>{let n={...t};return delete n[e],n}),m(t=>[...t,e]),h===e&&g(null);let r=await t.u(e);r&&(m(t=>t.filter(t=>t!==e)),S(t=>({...t,[e]:r})))},I=a||s,L=new Set(O.map(e=>e.id)),R=D?w.filter(e=>e.memberId===D.id):[],z=(0,r.useMemo)(()=>{if(!D)return[];let e=new Map;for(let t of w){if(t.memberId===D.id)continue;let n=e.get(t.memberId);n?n.push(t):e.set(t.memberId,[t])}let n=[];for(let r of O)r.id!==D.id&&(n.push({id:r.id,name:t.h(r)||r.email,stale:!1,schedules:e.get(r.id)||[]}),e.delete(r.id));for(let[t,r]of e)n.push({id:t,name:r[0].memberName.trim()||`Someone no longer on the team`,stale:!0,schedules:r});return n},[w,O,D]);return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(t.at,{icon:t.Wi,title:`Your schedules`,description:`When you are free — a name, a time zone, the week's hours and the days you are away. The base for anything booked on them.`,actions:I?void 0:({open:e})=>(0,i.jsx)(t.Q,{icon:t.Ur,compact:!0,title:`Add a schedule`,onClick:()=>{e(),P()},children:`Add a schedule`}),children:(0,i.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[I?(0,i.jsx)(`p`,{className:t.$,children:`Loading your schedules…`}):R.length===0?(0,i.jsx)(`p`,{className:`${t.$} px-1`,children:`No hours of your own yet — press Add a schedule. Everything booked in them shares one availability, so a time taken once is gone from all of it.`}):R.map(e=>(0,i.jsx)(yp,{schedule:e,stale:!L.has(e.memberId),fresh:_===e.id,open:h===e.id,error:x[e.id],onToggle:()=>g(h===e.id?null:e.id),onChange:E,onRemove:()=>F(e.id)},e.id)),!!A&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 px-1`,children:A})]})}),e&&(0,i.jsx)(t.at,{icon:t.xr,title:`Your team's schedules`,description:`When everyone else is free — one folded row per person; open a name to add their hours or see what they keep.`,children:(0,i.jsx)(`div`,{className:`flex flex-col gap-3`,children:I?(0,i.jsx)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:`Loading your team's schedules…`}):z.length===0?(0,i.jsxs)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug px-1`,children:[`Nobody else is marked Internal or Admin yet. Add them on the`,` `,(0,i.jsx)(c.Link,{to:`/users`,className:`text-accent font-bold hover:underline`,children:`Users screen`}),` and a folded row for them appears here.`]}):z.map(e=>(0,i.jsx)(bp,{name:e.name,schedules:e.schedules,stale:e.stale,open:y===e.id,onToggle:()=>{let t=y!==e.id;b(t?e.id:null),t&&e.schedules.length&&g(e.schedules[0].id)},onAdd:()=>{let t=O.find(t=>t.id===e.id);t&&N(t)},openScheduleId:h,freshId:_,errors:x,onToggleSchedule:e=>g(h===e?null:e),onChange:E,onRemove:F},e.id))})})]})}function Cp(){let{user:e,userRole:n}=t.na(),r=n===`admin`,{schedules:a}=t._(),o=e&&(e.displayName||e.email?.split(`@`)[0])||``;return t.fa(n)?(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,i.jsx)(Ce,{children:`Schedule`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/schedule`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-5 md:p-8 shadow-2xl relative bg-background flex flex-col min-h-[600px]`,children:(0,i.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,i.jsx)(`div`,{className:`flex flex-col gap-1.5 px-1`,children:(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/60 leading-relaxed`,children:r?`When you and your team are free, and everything built on it. A schedule is a week of hours in one person’s own time zone; a booking link turns those hours into a meeting people can book, with an address to send. The same hours are what a page you ask for is built on.`:`When you are free, and what people can book in it. Your schedule is your week of hours; a booking link turns it into a meeting, with an address of its own to send — they pick a free time and it lands on your calendar. A booking page gathers your meetings under one address to hand out.`})}),(0,i.jsx)(ap,{isAdmin:r}),(0,i.jsx)(Sp,{isAdmin:r}),(0,i.jsx)(bf,{isAdmin:r}),(0,i.jsx)(dp,{schedules:a,myName:o,isAdmin:r,meId:e?.uid||``})]})})]})]}):(0,i.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:(0,i.jsx)(Ci,{})})}function wp(){let{user:e}=t.na(),n=t.an(),{loading:a,bookings:o,error:s}=t.v(e?.uid||``,e?.email||``),{docs:c}=t.b(),l=(0,r.useMemo)(()=>t.w(c),[c]),u=(0,r.useMemo)(()=>t.T(o,l),[o,l]);return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,i.jsx)(Ce,{children:`My bookings`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/my-bookings`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-5 md:p-8 shadow-2xl relative bg-background flex flex-col min-h-[600px]`,children:(0,i.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,i.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/60 leading-relaxed px-1`,children:[`Every meeting booked with your email address — including any you booked before you had an account. Shown in your time, `,t.Kn(n),`.`]}),a?(0,i.jsx)(`p`,{className:`${t.$} px-1`,children:`Loading your bookings…`}):s?(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-red-500 px-1`,children:s}):u.length===0?(0,i.jsx)(t.at,{icon:t.Wi,title:`Nothing booked yet`,description:`Meetings you book appear here.`,children:(0,i.jsxs)(`p`,{className:`${t.$} px-1`,children:[`When you book a time through one of `,e?.displayName?`their`:`our`,` booking links, it lands here — and stays here afterwards, so you always have the record.`]})}):(0,i.jsx)(t.at,{icon:t.Wi,title:`Your calendar`,description:`Press a day to see what is on it. Everything you have booked is here, including the meetings that have been and the ones called off.`,children:(0,i.jsx)(Yf,{bookings:u,zone:n,side:`booker`,onCancel:async(r,i)=>{let a=await t.i(r.id,{ids:r.copyIds,reason:i,side:`booker`,by:r.name.trim()||String(e?.displayName||``)});if(!a){let e=t.Hn(r,n);Ya(`heads_up`,{title:`Booking cancelled`,summary:`${r.name.trim()||`Someone`} cancelled ${t.Yt(r)} — ${e.day}, ${e.time}`,details:{Who:r.name.trim(),Email:r.email,When:`${e.day}, ${e.time}`,Reason:i}}).catch(()=>{})}return a}})}),!a&&!s&&u.length>0&&(0,i.jsxs)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug px-1 flex items-start gap-1.5`,children:[(0,i.jsx)(t.Cr,{className:`w-3.5 h-3.5 shrink-0 mt-[1px]`,"aria-hidden":!0}),(0,i.jsx)(`span`,{children:`Cancelling gives the time back straight away. To MOVE a meeting, cancel it and book another — or reply to its confirmation email.`})]})]})})]})]})}var Tp=(0,r.lazy)(()=>Promise.resolve().then(()=>require(`./PhoneInputField-CkAv_5Lw.cjs`)).then(e=>e.n)),Ep=`text-[13px] font-medium text-foreground/50 select-none mb-1.5 ml-1`,Dp=`text-[12px] font-semibold text-red-500 mt-1 ml-1`,Op=`flex w-full 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 resize-none`;function kp({children:e}){return(0,i.jsx)(`div`,{className:`flex flex-col w-full min-w-0`,children:e})}function Ap({question:e,value:n,error:a,onChange:o}){let s=e.label.trim(),c=e.required?`${s} *`:s;return e.type===`textarea`?(0,i.jsxs)(kp,{children:[(0,i.jsx)(`label`,{className:Ep,htmlFor:`q_${e.name}`,children:c}),(0,i.jsx)(`textarea`,{id:`q_${e.name}`,rows:3,value:n,placeholder:e.placeholder,onChange:e=>o(e.target.value),className:`${Op} rounded-xl min-h-[90px]`}),a&&(0,i.jsx)(`p`,{className:Dp,children:a})]}):e.type===`checkbox`?(0,i.jsxs)(kp,{children:[(0,i.jsxs)(`label`,{className:`flex items-center gap-3 w-full cursor-pointer group py-1.5`,children:[(0,i.jsxs)(`span`,{className:`relative flex items-center justify-center w-5 h-5 rounded border border-foreground/20 bg-background/50 group-hover:border-accent transition-colors shrink-0`,children:[(0,i.jsx)(`input`,{type:`checkbox`,checked:n===`Yes`,onChange:e=>o(e.target.checked?`Yes`:``),className:`absolute opacity-0 w-full h-full cursor-pointer`}),n===`Yes`&&(0,i.jsx)(`span`,{className:`w-2.5 h-2.5 bg-accent rounded-sm shrink-0`})]}),(0,i.jsx)(`span`,{className:`text-[14px] font-medium text-foreground/80 leading-snug group-hover:text-foreground transition-colors`,children:c})]}),a&&(0,i.jsx)(`p`,{className:Dp,children:a})]}):e.type===`select`?(0,i.jsxs)(kp,{children:[(0,i.jsx)(t.sr,{label:c,direction:`auto`,value:n,options:[{value:``,label:(0,i.jsx)(`span`,{className:`text-foreground/40`,children:e.placeholder||`Choose one…`})},...e.options.filter(Boolean).map(e=>({value:e,label:e}))],onChange:o}),a&&(0,i.jsx)(`p`,{className:Dp,children:a})]}):e.type===`tel`?(0,i.jsxs)(kp,{children:[(0,i.jsx)(r.Suspense,{fallback:(0,i.jsx)(`div`,{className:`h-12 w-full glass-panel animate-pulse rounded-xl`}),children:(0,i.jsx)(Tp,{field:{label:c,required:!1,placeholder:e.placeholder},value:n,onChange:o})}),a&&(0,i.jsx)(`p`,{className:Dp,children:a})]}):e.type===`file`?(0,i.jsx)(kp,{children:(0,i.jsx)(t.$n,{field:{label:c,placeholder:e.placeholder},value:n,error:a,onChange:e=>o(e(n))})}):e.type===`date`?(0,i.jsxs)(kp,{children:[(0,i.jsx)(`label`,{className:Ep,htmlFor:`q_${e.name}`,children:c}),(0,i.jsxs)(`div`,{className:`relative flex items-center lift-focus`,children:[(0,i.jsx)(`input`,{id:`q_${e.name}`,type:`date`,value:n,onChange:e=>o(e.target.value),className:`date-field block h-12 w-full text-[15px] pl-4 pr-11 py-2 transition-all duration-300 focus:outline-none focus:border-accent glow-focus glass-panel ${n?`text-foreground`:`text-foreground/40`}`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(t.Vi,{className:`w-4 h-4 text-foreground/50 absolute right-4 pointer-events-none`,"aria-hidden":!0})]}),a&&(0,i.jsx)(`p`,{className:Dp,children:a})]}):(0,i.jsx)(kp,{children:(0,i.jsx)(t.lr,{label:c,type:e.type,value:n,error:a,placeholder:e.placeholder,onChange:e=>o(e.target.value)})})}function jp({questions:e,answers:n,errors:r,onChange:a}){return(0,i.jsx)(i.Fragment,{children:t.It(e).map(e=>(0,i.jsx)(Ap,{question:e,value:n[e.name]||``,error:r[e.name],onChange:t=>a(e.name,t)},e.name))})}var Mp=/^[^\s@,;]+@[^\s@,;.]+(\.[^\s@,;.]+)*\.[a-z]{2,}$/i;function Np(e){if(!e||e.kind!==`once`)return null;let t=Li(e),n=t.reduce((e,t)=>e+(Ri(t.amount)||0),0),r=e.name.trim()||t.map(e=>e.name.trim()).filter(Boolean).join(` and `)||Yi(e);return n>0?{amount:n,name:r}:null}var Pp=(e,t=`usd`)=>{try{return new Intl.NumberFormat(void 0,{style:`currency`,currency:t.toUpperCase()}).format(e)}catch{return`${e} ${t.toUpperCase()}`}};function Fp(e){let[n,i]=(0,r.useState)({id:``,product:null});return(0,r.useEffect)(()=>{if(!e)return;let n=!1;return(0,o.getDoc)((0,o.doc)(t.Da,ji,e)).then(t=>{n||i({id:e,product:t.exists()?Ui(t.id,t.data()):null})}).catch(()=>{n||i({id:e,product:null})}),()=>{n=!0}},[e]),e?n.id===e?{loading:!1,product:n.product}:{loading:!0,product:null}:{loading:!1,product:null}}function Ip({icon:e,accent:t,children:n}){return(0,i.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 h-7 px-3 rounded-full border text-[12.5px] font-semibold whitespace-nowrap ${t?`border-accent/40 bg-accent/10 text-accent`:`border-[var(--panel-border)]/70 text-foreground/65`}`,children:[e&&(0,i.jsx)(e,{className:`w-3.5 h-3.5 text-accent shrink-0`,"aria-hidden":!0}),n]})}function Lp({children:e,wide:n,form:r}){return(0,i.jsx)(`main`,{className:`flex-1 w-full mx-auto px-4 py-8 md:py-12 z-10 flex flex-col justify-center transition-[max-width] duration-500 ease-out ${n?`max-w-4xl`:r?`max-w-2xl`:`max-w-xl`}`,children:(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.4},className:`w-full rounded-3xl glass-panel border border-[var(--panel-border)] p-5 sm:p-8 md:p-10 shadow-[0_8px_32px_rgba(0,0,0,0.08)]`,children:e})})}function Rp({children:e}){return(0,i.jsx)(`h1`,{ref:Se([e]),className:`text-2xl sm:text-3xl font-extrabold tracking-tight text-gradient leading-tight whitespace-nowrap data-[fold]:whitespace-normal data-[fold]:text-balance`,children:e})}function zp({icon:e,title:n,children:r}){return(0,i.jsxs)(`div`,{className:`flex flex-col items-center text-center py-8 gap-4`,children:[(0,i.jsx)(`div`,{className:`w-14 h-14 ${t.K}`,children:(0,i.jsx)(e,{className:`w-6 h-6`})}),(0,i.jsx)(`h1`,{className:`text-2xl md:text-3xl font-extrabold text-foreground tracking-tight`,children:n}),r&&(0,i.jsx)(`div`,{className:`text-[14px] md:text-[15px] text-foreground/60 leading-relaxed max-w-md`,children:r}),(0,i.jsx)(c.Link,{to:`/`,className:`text-[13px] font-bold text-accent hover:underline mt-2`,children:`Back to the site`})]})}function Bp({sessionId:e,schedule:n}){let[a,o]=(0,r.useState)(null);if((0,r.useEffect)(()=>{let t=!1;return ee(e).then(e=>{t||o(e)}),()=>{t=!0}},[e]),!a)return(0,i.jsx)(zp,{icon:t.ti,title:`Confirming your payment…`,children:`One moment — checking with the payment provider.`});let s=a.metadata?.when||``;return a.paid?(0,i.jsx)(zp,{icon:t.Gi,title:`Paid — your time is held`,children:(0,i.jsxs)(`p`,{children:[s?`${s} — `:``,t.In(n),`. Held for you while it is confirmed.`,a.customerEmail?` A receipt is on its way to ${a.customerEmail}.`:``]})}):(0,i.jsx)(zp,{icon:t.Oi,title:`Not confirmed yet`,children:(0,i.jsx)(`p`,{children:a.error||`The payment provider has not confirmed this payment yet. Your time is held; if a receipt arrives by email, the booking is yours.`})})}function Vp(){let{id:e=``}=(0,c.useParams)(),[n]=(0,c.useSearchParams)(),{activeConfig:a}=t.ja(),{loading:o,schedule:s}=t.y(e),{loading:l,product:u}=Fp(s?.paymentId||``),d=Np(u),f=Y(),[p,m]=(0,r.useState)(()=>t.an()),[h]=(0,r.useState)(()=>new Date),g=t.x(s?[s.memberId]:[],h),_=(0,r.useMemo)(()=>s&&t.Wt(s)?[s]:[],[s]),[v,y]=(0,r.useState)(null),[b,x]=(0,r.useState)(()=>t.Ea.currentUser?.displayName||``),[S,C]=(0,r.useState)(()=>t.Ea.currentUser?.email||``),[w,T]=(0,r.useState)({}),[E,D]=(0,r.useState)({}),[O,k]=(0,r.useState)(!1),[A,j]=(0,r.useState)(``),[M,N]=(0,r.useState)(``),[P,F]=(0,r.useState)(``),I=n.get(`session_id`)||``,R=n.get(`cancelled`)===`1`;if(o)return(0,i.jsx)(Lp,{children:(0,i.jsxs)(`div`,{className:`flex items-center justify-center gap-3 py-16 text-foreground/50`,children:[(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin text-accent`}),(0,i.jsx)(`span`,{className:`text-[13px] font-medium`,children:`Loading…`})]})});if(!s)return(0,i.jsx)(Lp,{children:(0,i.jsx)(zp,{icon:t.Hi,title:`This booking link is no longer open`,children:`It may have been taken down. Ask whoever sent it for a new one.`})});if(I)return(0,i.jsx)(Lp,{children:(0,i.jsx)(Bp,{sessionId:I,schedule:s})});if(M)return(0,i.jsx)(Lp,{children:(0,i.jsx)(zp,{icon:t.Oi,title:`Your time is held`,children:(0,i.jsxs)(`p`,{children:[M,` — held for you while `,s.memberName.trim()||`the person you booked with`,` confirms it.`,P?` We have sent the details to ${P}, and will write again the moment it is confirmed.`:``]})})});if(!t.Wt(s))return(0,i.jsx)(Lp,{children:(0,i.jsx)(zp,{icon:t.Hi,title:t.In(s),children:`This is not taking bookings at the moment.`})});let z=!!s.paymentId&&!l&&(!d||!f.loading&&!f.configured),B=async()=>{if(!v||O)return;let e={...t.qt(s.questions,w)};if(b.trim()||(e._name=`Your name, please.`),Mp.test(S.trim())||(e._email=`That does not look like an email address — check for a typo, e.g. jane@example.com`),D(e),Object.keys(e).length)return;k(!0),j(``);let n=t.nn(v,s.memberName,p),r=await t.a(v);if(r){j(r),y(null),k(!1);return}let i=null;if(d){let e=await W({amount:d.amount,productName:`${t.In(s)} — ${n}`,metadata:{bookingId:t.zn(v.memberId,v.start),scheduleId:s.id,page:t.Qt(s.id),when:n,emailReceipt:s.confirmBooker?`yes`:`no`,notifyOwner:s.notifyOwner?`yes`:`no`},successPath:t.Qt(s.id),cancelPath:`${t.Qt(s.id)}?cancelled=1`});if(typeof e==`string`){await t.c(v),j(e),k(!1);return}i=e}let a=t.zn(v.memberId,v.start),o=await t.E(v,{memberName:s.memberName,scheduleId:s.id,scheduleName:t.Mn(s),paymentId:s.paymentId,paymentSession:i?.sessionId||``,timeZone:p,name:b.trim(),email:S.trim(),answers:t.Gt(s.questions,w),formId:t.gt,entryId:``});if(o){await t.c(v),j(o),k(!1);return}if(i){L.goTo(i.url);return}if(s.notifyOwner&&Ya(`heads_up`,{title:`New booking`,summary:`${b.trim()} booked ${t.In(s)} — ${n}`,details:{Name:b.trim(),Email:S.trim(),When:n,...t.Kt(s.questions,w)}}).catch(()=>{}),s.confirmBooker&&t.Ea.currentUser){let e=S.trim();Xa(`booking_requested`,`mem_bookings`,a,{when:n,memberName:s.memberName,scheduleName:t.In(s),details:{When:n,With:s.memberName,What:t.In(s)}}).then(t=>{t||F(e)}).catch(()=>{})}N(n),k(!1)},V=!z&&!v,H=!z&&!!v,U=t.Ft(s.questions,`name`),G=t.Ft(s.questions,`email`);return(0,i.jsxs)(Lp,{wide:V,form:H,children:[R&&(0,i.jsx)(`p`,{className:`mb-5 px-4 py-3 rounded-xl bg-amber-500/10 border border-amber-500/20 text-[13px] font-medium text-foreground/80`,children:`Nothing was charged. Pick a time again to book.`}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-4 mb-5 sm:mb-6`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-3.5 min-w-0`,children:[(0,i.jsx)(`div`,{className:`w-11 h-11 ${t.K}`,children:(0,i.jsx)(t.Wi,{className:`w-5 h-5`})}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0 flex-1`,children:[a?.appName&&(0,i.jsx)(`span`,{className:`text-[10.5px] font-bold uppercase tracking-[0.18em] text-foreground/40 truncate`,children:a.appName}),(0,i.jsx)(Rp,{children:t.In(s)})]})]}),(0,i.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[!s.memberName.trim()&&(0,i.jsx)(Ip,{icon:t.Cr,children:`with your host`}),(0,i.jsx)(Ip,{icon:t.Oi,children:t.Bn(s.slotMinutes)}),d&&(0,i.jsx)(Ip,{accent:!0,children:Pp(d.amount)})]}),t.jn(s)&&(0,i.jsx)(`p`,{className:`text-[13.5px] sm:text-[14px] text-foreground/60 font-medium leading-relaxed max-w-2xl whitespace-pre-line`,children:t.jn(s)})]}),(0,i.jsx)(`div`,{className:`h-px bg-[var(--panel-border)]/60 mb-5 sm:mb-6`}),z?(0,i.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60`,children:`This booking cannot be paid for right now — please try again later.`}):v?(0,i.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,i.jsx)(t.G,{slot:v,timeZone:p,onChange:()=>y(null)}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,i.jsx)(t.lr,{label:U.label,value:b,onChange:e=>x(e.target.value),error:E._name,placeholder:U.placeholder}),(0,i.jsx)(t.lr,{label:G.label,type:`email`,value:S,onChange:e=>C(e.target.value),error:E._email,placeholder:G.placeholder}),(0,i.jsx)(jp,{questions:s.questions,answers:w,errors:E,onChange:(e,t)=>{T(n=>({...n,[e]:t})),D(t=>t[e]?{...t,[e]:``}:t)}})]}),A&&(0,i.jsx)(`p`,{role:`alert`,className:`text-[13px] font-semibold text-red-500`,children:A}),(0,i.jsx)(`div`,{className:`h-px bg-[var(--panel-border)]/60`}),(0,i.jsx)(t.J,{timeZone:p,onTimeZone:m,action:(0,i.jsx)(t.cr,{variant:`primary`,onClick:B,disabled:O||l,className:`max-sm:w-full h-11 px-6 text-[13.5px] font-bold shrink-0`,children:O?d?`Opening checkout…`:`Booking…`:d?`Book and pay ${Pp(d.amount)}`:`Confirm booking`})})]}):(0,i.jsxs)(i.Fragment,{children:[A&&(0,i.jsx)(`p`,{role:`alert`,className:`mb-3 text-[13px] font-semibold text-red-500`,children:A}),(0,i.jsx)(t.z,{members:_,value:v,onChange:y,taken:g,timeZone:p,onTimeZone:m})]})]})}var Hp=`rounded-2xl flex items-center justify-center shrink-0 border border-[var(--panel-border)]/50 bg-accent/10 text-accent`,Up=`rounded-2xl border border-[var(--panel-border)]/60 bg-foreground/[0.015]`;function Wp(e){let[n,i]=(0,r.useState)(new Map),a=e.join(`,`);return(0,r.useEffect)(()=>{let e=a?a.split(`,`):[];if(!e.length)return;let n=!1;return Promise.all(e.map(async e=>{try{let n=await(0,o.getDoc)((0,o.doc)(t.Da,ji,e));return n.exists()?Ui(e,n.data()):null}catch{return null}})).then(e=>{if(n)return;let t=new Map;e.forEach(e=>{e&&t.set(e.id,e)}),i(t)}),()=>{n=!0}},[a]),n}function Gp({children:e}){return(0,i.jsx)(`main`,{className:`flex-1 w-full max-w-2xl mx-auto px-4 py-8 md:py-12 z-10 flex flex-col justify-center`,children:(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.4},className:`w-full rounded-3xl glass-panel border border-[var(--panel-border)] p-5 sm:p-8 md:p-10 shadow-[0_8px_32px_rgba(0,0,0,0.08)]`,children:e})})}function Kp({icon:e,title:t,children:n}){return(0,i.jsxs)(`div`,{className:`flex flex-col items-center text-center py-8 gap-4`,children:[(0,i.jsx)(`div`,{className:`w-14 h-14 ${Hp}`,children:(0,i.jsx)(e,{className:`w-6 h-6`})}),(0,i.jsx)(`h1`,{className:`text-2xl md:text-3xl font-extrabold text-foreground tracking-tight`,children:t}),n&&(0,i.jsx)(`div`,{className:`text-[14px] md:text-[15px] text-foreground/60 leading-relaxed max-w-md`,children:n}),(0,i.jsx)(c.Link,{to:`/`,className:`text-[13px] font-bold text-accent hover:underline mt-2`,children:`Back to the site`})]})}function qp({icon:e,accent:t,children:n}){return(0,i.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 h-6 px-2.5 rounded-full border text-[11.5px] font-semibold whitespace-nowrap ${t?`border-accent/40 bg-accent/10 text-accent`:`border-[var(--panel-border)]/70 text-foreground/60`}`,children:[e&&(0,i.jsx)(e,{className:`w-3 h-3 text-accent shrink-0`,"aria-hidden":!0}),n]})}function Jp({schedule:e,price:n}){let r=t.jn(e),a=t.Vn(e.slotMinutes);return(0,i.jsxs)(c.Link,{to:t.Qt(e.id),className:`${Up} group relative overflow-hidden flex items-center gap-3.5 sm:gap-4 p-3 sm:p-4 transition-all duration-300
|
|
673
673
|
hover:border-accent/50 hover:shadow-[0_10px_30px_-12px_rgba(0,0,0,0.28)] hover:-translate-y-[2px] active:translate-y-0 active:scale-[0.995]`,children:[(0,i.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-0 opacity-0 group-hover:opacity-100 transition-opacity duration-300 bg-gradient-to-r from-accent/[0.09] via-accent/[0.03] to-transparent`}),(0,i.jsx)(`span`,{"aria-hidden":!0,className:`absolute left-0 top-0 bottom-0 w-[3px] bg-accent origin-center scale-y-0 group-hover:scale-y-100 transition-transform duration-300`}),(0,i.jsxs)(`span`,{"aria-hidden":!0,className:`relative shrink-0 w-[52px] h-[52px] rounded-2xl border border-[var(--panel-border)]/60 bg-accent/[0.07] text-accent
|
|
674
|
-
flex flex-col items-center justify-center leading-none gap-0.5 transition-colors duration-300 group-hover:bg-accent/[0.13] group-hover:border-accent/30`,children:[(0,i.jsx)(`span`,{className:`text-[17px] font-extrabold tracking-tight tabular-nums`,children:a.value}),(0,i.jsx)(`span`,{className:`text-[9.5px] font-bold uppercase tracking-[0.08em] opacity-70`,children:a.unit})]}),(0,i.jsxs)(`span`,{className:`relative flex-1 min-w-0 flex flex-col gap-1`,children:[(0,i.jsx)(`span`,{className:`text-[14.5px] sm:text-[15px] font-bold text-foreground tracking-tight leading-snug break-words`,children:t.In(e)}),(0,i.jsxs)(`span`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,i.jsx)(
|
|
675
|
-
text-foreground/35 transition-all duration-300 group-hover:border-accent/50 group-hover:bg-accent group-hover:text-[var(--button-fg,#fff)]`,children:(0,i.jsx)(t.Xi,{className:`w-4 h-4 transition-transform duration-300 group-hover:translate-x-[1px]`})})]})}function Jp({page:e}){let n=`w-24 h-24 sm:w-28 sm:h-28`;return(0,i.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,i.jsx)(`span`,{"aria-hidden":!0,className:`absolute -inset-3 rounded-[2rem] bg-accent/15 blur-2xl`}),e.photo?(0,i.jsx)(`img`,{src:e.photo,alt:``,className:`relative ${n} rounded-2xl object-cover border border-[var(--panel-border)] shadow-[0_10px_30px_rgba(0,0,0,0.12)]`}):(0,i.jsx)(`div`,{className:`relative ${n} ${Vp}`,children:(0,i.jsx)(t.Cr,{className:`w-9 h-9`})})]})}function Yp(){let{id:e=``}=(0,c.useParams)(),{activeConfig:n}=t.ja(),{loading:a,pages:o}=fo(),{loading:s,schedules:l}=t._(),u=o.find(t=>t.id===e)||null,d=(0,r.useMemo)(()=>u?so(u,l):[],[u,l]),f=Up((0,r.useMemo)(()=>[...new Set(d.map(e=>e.paymentId).filter(Boolean))],[d]));if(a||s)return(0,i.jsx)(Wp,{children:(0,i.jsxs)(`div`,{className:`flex items-center justify-center gap-3 py-16 text-foreground/50`,children:[(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin text-accent`}),(0,i.jsx)(`span`,{className:`text-[13px] font-medium`,children:`Loading…`})]})});if(!u||!u.enabled)return(0,i.jsx)(Wp,{children:(0,i.jsx)(Gp,{icon:t.Hi,title:`This page is no longer open`,children:`It may have been taken down. Ask whoever sent it for a new link.`})});if(!d.length){let e=oo(u,l).length;return(0,i.jsx)(Wp,{children:(0,i.jsx)(Gp,{icon:t.Hi,title:uo(u),children:e?`Nothing here is taking bookings at the moment. Please check back later.`:`There is nothing to book here at the moment. Please check back later.`})})}let p=u.intro.trim();return(0,i.jsxs)(Wp,{children:[(0,i.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-4`,children:[(0,i.jsx)(Jp,{page:u}),(0,i.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 w-full min-w-0`,children:[n?.appName&&(0,i.jsx)(`span`,{className:`text-[10.5px] font-bold uppercase tracking-[0.18em] text-foreground/40 truncate max-w-full`,children:n.appName}),(0,i.jsx)(`h1`,{className:`text-[26px] sm:text-4xl font-extrabold tracking-tight text-gradient leading-[1.1] break-words`,children:uo(u)}),p&&(0,i.jsx)(`p`,{className:`mt-1.5 max-w-md text-[13.5px] sm:text-[14.5px] text-foreground/60 font-medium leading-relaxed whitespace-pre-line`,children:p})]})]}),(0,i.jsx)(`div`,{className:`h-px bg-[var(--panel-border)]/60 my-5 sm:my-7`}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-1`,children:[(0,i.jsx)(`p`,{className:`text-[11px] font-bold uppercase tracking-[0.16em] text-foreground/40`,children:d.length===1?`Book a time`:`Pick what to book`}),d.length>1&&(0,i.jsxs)(`span`,{className:`text-[11px] font-semibold text-foreground/35 tabular-nums`,children:[d.length,` meetings`]})]}),d.map(e=>(0,i.jsx)(qp,{schedule:e,price:Mp(f.get(e.paymentId)||null)},e.id))]})]})}function Xp({children:e,className:n,variant:a=`primary`,pendingLabel:o=`Opening checkout…`,...s}){let{loading:c,configured:l}=Y(),{userRole:u}=t.na(),[d,f]=(0,r.useState)(!1),[p,m]=(0,r.useState)(null);return c?null:l?(0,i.jsxs)(`span`,{className:`inline-flex flex-col items-stretch gap-2`,children:[(0,i.jsx)(t.cr,{variant:a,className:n,onClick:async()=>{if(d)return;f(!0),m(null);let e=await U(s);e&&(m(e),f(!1))},disabled:d,children:d?o:e??`Pay`}),p&&(0,i.jsx)(`span`,{role:`alert`,className:`text-[13px] font-semibold text-red-400 leading-snug`,children:p})]}):t.pa(u)?(0,i.jsx)(`span`,{className:`text-[12.5px] font-medium text-foreground/50 leading-snug`,children:`Only admins see this: payments are not on yet, so this button is hidden. Connect Stripe and switch payments on at /payments and it appears here.`}):null}function Zp(){let{id:e=``}=(0,c.useParams)(),{activeConfig:n}=t.ja(),a=Y(),[s,l]=(0,r.useState)({loading:!0,product:null});(0,r.useEffect)(()=>{let n=!1;return(0,o.getDoc)((0,o.doc)(t.Da,ji,e)).then(e=>{n||l({loading:!1,product:e.exists()?Ui(e.id,e.data()):null})}).catch(()=>{n||l({loading:!1,product:null})}),()=>{n=!0}},[e]);let u=s.product,d=u?.customPath.trim()||``;if(d)return(0,i.jsx)(c.Navigate,{to:d.startsWith(`/`)?d:`/${d}`,replace:!0});let f=u?Li(u).filter(e=>Ri(e.amount)):[],p=u?.name.trim()||f[0]?.name.trim()||`Pay`;return(0,i.jsx)(`main`,{className:`flex-1 w-full max-w-3xl mx-auto px-4 pt-2 pb-16 md:pt-4 z-10 flex flex-col`,children:(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.4},className:`w-full rounded-3xl glass-panel border border-[var(--panel-border)] p-5 sm:p-8 md:p-10 shadow-[0_8px_32px_rgba(0,0,0,0.08)]`,children:s.loading?(0,i.jsxs)(`div`,{className:`flex items-center justify-center gap-3 py-16 text-foreground/50`,children:[(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin text-accent`}),(0,i.jsx)(`span`,{className:`text-[13px] font-medium`,children:`Loading…`})]}):!u||u.kind!==`once`||!f.length?(0,i.jsxs)(`div`,{className:`flex flex-col items-center text-center py-8 gap-4`,children:[(0,i.jsx)(`div`,{className:`w-14 h-14 rounded-2xl glass-panel border border-[var(--panel-border)] flex items-center justify-center shadow-xl`,children:(0,i.jsx)(t.Pr,{className:`w-7 h-7 text-accent`})}),(0,i.jsx)(`h1`,{className:`text-2xl md:text-3xl font-extrabold text-foreground tracking-tight`,children:`This payment link is no longer open`}),(0,i.jsx)(`p`,{className:`text-[14px] text-foreground/60 max-w-md`,children:`Ask whoever sent it for a new one.`}),(0,i.jsx)(c.Link,{to:`/`,className:`text-[13px] font-bold text-accent hover:underline mt-2`,children:`Back to the site`})]}):(0,i.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[n?.appName&&(0,i.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-[0.2em] text-foreground/40`,children:n.appName}),(0,i.jsx)(`h1`,{className:`text-2xl sm:text-3xl md:text-4xl font-extrabold text-foreground tracking-tight`,children:p}),u.description.trim()&&(0,i.jsx)(`p`,{className:`text-[14px] md:text-[15px] text-foreground/60 leading-relaxed mt-1 max-w-2xl whitespace-pre-line`,children:u.description.trim()})]}),!a.loading&&!a.configured&&(0,i.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60`,children:`Payments are not open right now — please try again later.`}),(0,i.jsx)(`div`,{className:`flex flex-col divide-y divide-[var(--panel-border)]/60 rounded-2xl border border-[var(--panel-border)]/60`,children:f.map((e,n)=>(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3.5`,children:[(0,i.jsxs)(`div`,{className:`min-w-0 flex flex-col`,children:[(0,i.jsx)(`span`,{className:`text-[15px] font-semibold text-foreground truncate`,children:e.name.trim()||p}),(0,i.jsx)(`span`,{className:`text-[13px] font-medium text-foreground/50`,children:Np(Ri(e.amount)||0)})]}),(0,i.jsxs)(Xp,{amount:Ri(e.amount)||0,productName:e.name.trim()||p,metadata:{productId:u.id,page:t.kn(u.id),emailReceipt:u.emailReceipt?`yes`:`no`,notifyOwner:u.notifyOwner?`yes`:`no`},successPath:`/payment-complete`,cancelPath:t.kn(u.id),className:`px-5 py-2.5 text-[14px] font-bold`,children:[`Pay `,Np(Ri(e.amount)||0)]})]},n))})]})})})}function Qp({trailing:e,onSent:n}){let[a,o]=(0,r.useState)(`idle`),[s,c]=(0,r.useState)(``);return(0,i.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2.5 flex-wrap`,children:[(0,i.jsx)(t.Q,{compact:!0,icon:t.qi,busy:a===`sending`,onClick:async()=>{o(`sending`),c(``);try{let e=await fetch(`/api/_selftest/email`),t=await e.json().catch(()=>({}));e.ok&&t?.ok?(o(`sent`),n?.(typeof t.from==`string`&&t.from.trim()?t.from:null)):(o(`failed`),c(String(t?.error||t?.message||`The server answered ${e.status}.`)))}catch{o(`failed`),c(`The server could not be reached.`)}},title:`Sends the test email to your own admin address`,children:`Send yourself a test email`}),e]}),a===`sent`&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-emerald-500 px-1`,children:`Sent. If you do not receive it within a minute, check your spam.`}),a===`failed`&&(0,i.jsxs)(`p`,{className:`text-[12px] font-medium text-red-500 px-1 leading-relaxed`,children:[`It did not send: `,s,` If the sending address uses your own domain, that domain must be verified under `,(0,i.jsx)(`strong`,{children:`Domains`}),` in your Resend account — an unverified domain makes every send fail.`]})]})}var{collection:$p,doc:em}=Zu.email,tm=(e,t)=>{let n=String(e||``).trim().toLowerCase(),r=String(t||``).trim().toLowerCase();return!!n&&n===r};function nm(){let[e,n]=(0,r.useState)({loading:!0,testedFrom:null});return(0,r.useEffect)(()=>(0,o.onSnapshot)((0,o.doc)(t.Da,$p,em),e=>{let t=e.exists()?e.data()?.testedFrom:null;n({loading:!1,testedFrom:typeof t==`string`&&t.trim()?t:null})},()=>n({loading:!1,testedFrom:null})),[]),{loading:e.loading,testedFrom:e.testedFrom,mark:async e=>{if(e.trim()){n({loading:!1,testedFrom:e});try{await(0,o.setDoc)((0,o.doc)(t.Da,$p,em),{testedFrom:e},{merge:!0})}catch(e){console.error(`Could not remember the test send`,e)}}}}}var rm=e=>[{title:`Hear about what happens`,body:`A booking, a form entry, a new member — at your address the moment it happens.`,icon:t.Ki,where:{path:`/pages`,label:`Pages screen`}},{title:`Confirm to the people who write in`,body:`Whoever books or writes gets a note that it arrived, in your words.`,icon:t.Qr,where:{path:`/pages`,label:`Pages screen`}},{title:`Receipts and sale alerts`,body:`Every payment emails the buyer a receipt and tells you something sold.`,icon:t.Vr,where:{path:`/payments`,label:`Payments screen`}},{title:`Write to anyone from your app`,body:`A page for your team can write to any address, from ${e}.`,icon:t.Ir,where:{path:`/pages`,label:`Pages screen`}}],im=e=>String(e||``).toLowerCase().endsWith(`@resend.dev`),am=e=>String(e||``).split(`@`)[1]||``,om=e=>e?{description:`Every page you told to send email does. Switch it off to stop all of it at once.`,chip:{state:`saved`,label:`On`}}:{description:`Nothing sends. Your pages keep their settings and wait for this to come back on.`,chip:{state:`off`,label:`Off`}};function sm({from:e}){return(0,i.jsx)(`div`,{className:`flex flex-col divide-y divide-[var(--panel-border)]/60 rounded-2xl border border-[var(--panel-border)]/60`,children:rm(e).map(e=>{let n=e.icon;return(0,i.jsxs)(`div`,{className:`grid grid-cols-[auto_minmax(0,1fr)] sm:grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-3 sm:gap-x-3.5 gap-y-0.5 px-4 py-3`,children:[(0,i.jsx)(`div`,{className:`row-start-1 row-span-2 col-start-1 self-center w-9 h-9 rounded-xl flex items-center justify-center shrink-0 border border-[var(--panel-border)]/50 bg-accent/10 text-accent`,children:(0,i.jsx)(n,{className:`w-4 h-4`})}),(0,i.jsx)(`span`,{className:`row-start-1 col-start-2 min-w-0 text-[13px] font-bold text-foreground leading-tight self-end`,children:e.title}),(0,i.jsx)(`span`,{className:`row-start-2 col-start-2 min-w-0 text-[12px] text-foreground/50 font-normal leading-snug self-start`,children:e.body}),(0,i.jsxs)(c.Link,{to:e.where.path,className:`max-sm:hidden sm:inline-flex row-start-1 row-span-2 col-start-3 self-center justify-self-end items-center gap-1.5 text-[11.5px] font-semibold text-foreground/45 hover:text-accent whitespace-nowrap transition-colors`,children:[e.where.label,(0,i.jsx)(t.Xi,{className:`w-3 h-3`})]})]},e.title)})})}function cm({adminCount:e,onSetUp:n}){return(0,i.jsxs)(`div`,{className:`flex items-center gap-2.5 px-1 flex-wrap`,children:[(0,i.jsx)(t.lt,{state:e?`saved`:`off`,label:e?`Your mail reaches ${e} address${e===1?``:`es`}`:`No address for your mail`}),!e&&(0,i.jsxs)(`span`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:[`Sale, booking and form alerts have nowhere to go —`,` `,(0,i.jsx)(t.rt,{onClick:n,children:`add ADMIN_EMAILS`}),`.`]})]})}function lm(){let{status:e,error:n,reread:a}=od(),o=$u(`email`),[s,c]=(0,r.useState)(``),l=nm(),[u,d]=(0,r.useState)(!1),[f,p]=(0,r.useState)(!1),m=()=>{d(!1),a().then(()=>p(!0))},h=!!(e&&!e.configured),g=im(e?.from),_=om(o.on),v=!l.loading&&tm(l.testedFrom,e?.from);return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,i.jsx)(Ce,{children:`Email`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/email`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-5 md:p-8 shadow-2xl relative bg-background flex flex-col min-h-[600px]`,children:!e&&!n?(0,i.jsx)(`div`,{className:`flex items-center justify-center flex-1 text-foreground/40 py-16`,children:(0,i.jsx)(t.ti,{className:`w-6 h-6 animate-spin text-accent`})}):h?(0,i.jsx)(Vd,{icon:t.Zr,title:`Connect email`,description:`This app is not sending email yet.`,stepsDescription:`Three steps — a key, two secrets, and the domain your mail goes out as.`,button:`Set up email`,secret:`RESEND_API_KEY`,open:u,onOpen:()=>d(!0),confirmed:f,steps:(0,i.jsx)(Ud,{onConfirm:m}),children:(0,i.jsx)(t.st,{children:`Email runs through Resend, and connecting it is two pasted rows — a key, and your own address for the mail that is meant for you. Once they are in, this screen fills itself: what your app can do with email, and where it goes.`})}):(0,i.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,i.jsx)(t.ut,{icon:t.Hr,title:`Send email`,description:_.description,chip:_.chip,enabled:o.loading?null:o.on,onChange:async e=>c(await o.set(e)||``),children:s?(0,i.jsx)(t.st,{tone:`error`,children:s}):null}),(0,i.jsx)(t.at,{icon:t.Qr,title:`Connection`,description:v&&!n?`Mail goes out as ${e?.from}.`:`Whether this app can send email right now.`,defaultOpen:!v||!e?.adminCount,actions:n?(0,i.jsx)(t.lt,{state:`error`,label:`Unreachable`}):(0,i.jsx)(t.lt,{state:`saved`,label:`Connected`}),children:n?(0,i.jsx)(t.st,{tone:`error`,children:n}):(0,i.jsxs)(i.Fragment,{children:[!v&&(0,i.jsxs)(t.st,{children:[`Mail goes out as `,(0,i.jsx)(`span`,{className:`font-bold text-foreground/70`,children:e?.from}),`.`,g?` That is Resend’s shared practice address: it delivers only to the address you made your Resend account with, so a test to yourself works and a customer’s email does not arrive. Before anyone else should get one, verify your own domain in Resend and add EMAIL_FROM — `:` That only works if ${am(e?.from)} is verified under Domains in your Resend account — an unverified domain makes every send fail. Every send also appears in your Resend dashboard, with nothing to sync.`,g&&(0,i.jsx)(t.rt,{onClick:()=>d(!0),children:`show me how`}),g&&`.`]}),(0,i.jsx)(cm,{adminCount:e?.adminCount||0,onSetUp:()=>d(!0)}),u&&(0,i.jsx)(`div`,{className:`px-1 pt-1`,children:(0,i.jsx)(Ud,{onConfirm:m})}),!v&&(0,i.jsx)(`div`,{className:`px-1`,children:(0,i.jsx)(Qp,{onSent:t=>l.mark(t||e?.from||``),trailing:(0,i.jsxs)(`a`,{href:`https://resend.com/emails`,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1.5 text-[12px] font-bold text-accent hover:underline`,children:[`See everything sent, in Resend`,(0,i.jsx)(t.bi,{className:`w-3 h-3`})]})})})]})}),(0,i.jsx)(t.at,{icon:t.Nr,title:`What you can do with email`,description:`Each is switched on where it happens — a page on the Pages screen, a payment on the Payments screen.`,children:(0,i.jsx)(sm,{from:e?.from||``})})]})})]})]})}var um=`src/your-ai-workflow-firebase-os`;function dm(){let e=new Set;for(let[t,n]of b()){let r=n?.config?.route,i=typeof r==`string`&&r.trim()?r.startsWith(`/`)?r:`/`+r:`/`+t.toLowerCase();e.add(i)}return[...e].sort()}var fm=e=>(e||``).split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``);function pm(e){let t=e?.contentKey||e?.tabName||e?.pageName||e?.pageId||`Page`;return`${um}/microcomponents/${fm(String(t))||`Page`}Content.tsx`}function mm(e,t){let n=t.replace(/^.*\//,``).replace(/\.tsx$/,``),r=n.replace(/Content$/,``).replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase();return[`My app has a page at ${e} and it is still empty after you said it was done. The ONLY thing that fills this page is one file: ${t}, with a default export, registered in ${um}/microcomponents/registry.ts.`,`Check these in order and fix whatever is wrong, without asking me questions:`,`1. The file exists at exactly that path and name — not another folder, not another spelling. If you put it somewhere else, move it there.`,`2. It has a default export. A named-only export is silently ignored.`,`3. ${um}/microcomponents/registry.ts contains these two lines: import ${n} from './${n}'; and registerMicrocomponent('${r}', ${n}); — registerMicrocomponent is imported there from 'your-ai-workflow-firebase-os'. Add them if they are missing, and never remove another page's lines.`,`4. You created nothing else for this page — no config file, no route, no page, and no edit to src/App.tsx or src/main.tsx. Undo any of those you made.`,`Then tell me, in one sentence, which of these was wrong.`].join(`
|
|
676
|
-
`)}function
|
|
677
|
-
`)}function gm({config:e,customContent:n}){let{config:a}=t.ja(),{userRole:o}=t.na();return(0,r.useEffect)(()=>{document.title=e.pageName||e.pageTitle||a.appName||`Your AI Firebase`},[e.pageName,e.pageTitle,a.appName]),(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col relative min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4 md:mb-6 flex items-center gap-3`,children:[(0,i.jsx)(Wt,{}),(0,i.jsxs)(`div`,{className:`min-w-0`,children:[(0,i.jsx)(Ce,{children:e.pageTitle||e.pageName||`New Page`}),e.route&&(0,i.jsxs)(`div`,{className:`max-sm:hidden sm:flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})]}),(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl shadow-2xl relative flex flex-col flex-1 bg-background/50 h-full min-h-[400px]`,children:n?(0,i.jsx)(`div`,{className:`fbos-content-slot flex-1 p-4 md:p-8`,children:(0,i.jsx)(n,{config:e})}):e.form?(0,i.jsx)(`div`,{className:`fbos-content-slot flex-1 flex flex-col items-center justify-start p-4 md:p-8`,children:(0,i.jsx)(t.t,{isInline:!0,formId:e.form})}):(0,i.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center m-4 md:m-8 gap-6`,children:[(0,i.jsxs)(`div`,{className:`w-full glass-panel border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-16 text-center opacity-70`,children:[(0,i.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/70`,children:`This page is empty`}),(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 max-w-sm leading-relaxed mx-auto`,children:`Open the Pages screen, say what you would like on it, and copy the sentence there into your assistant's chat.`})]}),t.pa(o)&&(0,i.jsx)(`div`,{className:`w-full max-w-lg`,children:(0,i.jsx)(it,{compact:!0,title:`Already asked, and it is still empty? Paste this`,prompt:mm(e.route||`/`,pm(e))})})]})})]})}function _m({config:e,customContent:n}){let{user:a}=t.na(),{config:c}=t.ja(),[u,d]=(0,r.useState)([]),[f,p]=(0,r.useState)(!0),[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(``),[v,y]=(0,r.useState)(``),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(null),w=(0,r.useRef)(null),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(null),[k,A]=(0,r.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;P(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[N,P]=(0,r.useState)(!0),[F,I]=(0,r.useState)(!1),[L,R]=(0,r.useState)(null),[z,B]=(0,r.useState)(``),[V,H]=(0,r.useState)(``),[U,W]=(0,r.useState)([]),G=(0,r.useRef)(null),ee=(e.tabName||e.pageId||`user_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),K=t.va({...e,pageType:`user`}),q=`${K}${ee}_records`,J=K.startsWith(`role_`);(0,r.useEffect)(()=>{document.title=e.tabTitle||e.tabName||c.appName||`Your AI Firebase`},[e.tabTitle,e.tabName,c.appName]),(0,r.useEffect)(()=>{if(!a)return;try{let e=Wa(q,a.uid);e?(d(e),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}}),n=(0,o.onSnapshot)(J?(0,o.query)((0,o.collection)(t.Da,q),(0,o.limit)(150)):(0,o.query)((0,o.collection)(t.Da,q),(0,o.where)(`uid`,`==`,a.uid),(0,o.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),d(n),p(!1),Ga(q,a.uid,n)},e=>{console.warn(`${q}: this account cannot read its records here (${e?.code||`permission-denied`}). Signed-in pages need a verified email address; the records themselves are only ever the signer's own.`),d(e=>e.length?[]:e),p(!1)});return()=>n()},[a,q,J]),(0,r.useEffect)(()=>{!f&&a&&Ga(q,a.uid,u)},[u,f,q,a]);let Y=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=await(0,o.addDoc)((0,o.collection)(t.Da,q),{name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,createdAt:(0,o.serverTimestamp)()});d(t=>[{id:e.id,name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,createdAt:Date.now()},...t]),_(``),y(``),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)}},te=async e=>{let n=e.target.files?.[0];if(!n||!a)return;let r=await t.or(n);E(!0);try{let e=`user_files/${`${Date.now()}_${r.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,n=(0,s.ref)(t.ka,e);await(0,s.uploadBytes)(n,r,{customMetadata:{ownerId:a.uid}});let i=await(0,s.getDownloadURL)(n);if(w.current)w.current(r,i,{uid:a.uid,storagePath:e});else{let e=await(0,o.addDoc)((0,o.collection)(t.Da,q),{name:r.name,note:`${r.type||`File`} · ${ge(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type||`unknown`,fileSize:r.size,downloadURL:i,createdAt:(0,o.serverTimestamp)()});d(t=>[{id:e.id,name:r.name,note:`${r.type||`File`} · ${ge(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type,fileSize:r.size,downloadURL:i,createdAt:Date.now()},...t])}}catch(e){console.error(`Error uploading file:`,e)}E(!1),G.current&&(G.current.value=``)},ne=async()=>{if(D){I(!0);try{let e=u.find(e=>e.id===D);if(await(0,o.deleteDoc)((0,o.doc)(t.Da,q,D)),e?.recordType===`file`&&e.downloadURL)try{let n=e.downloadURL.split(`user_files%2F`)[1]?.split(`?`)[0];n&&await(0,s.deleteObject)((0,s.ref)(t.ka,`user_files/${decodeURIComponent(n)}`)).catch(()=>{})}catch(e){console.error(`Error cleaning up user file:`,e)}d(e=>e.filter(e=>e.id!==D)),O(null)}catch(e){console.error(`Error deleting record:`,e)}I(!1)}},[re,X]=(0,r.useState)(null),[Z,Q]=(0,r.useState)(``),[ie,ae]=(0,r.useState)(!1),[oe,se]=(0,r.useState)(null),ce=(0,r.useRef)([]),le=e=>{if(e.recordType===`file`){X(e.id),Q(e.name);return}R(e.id),B(e.name),H(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??``)}));W(n),ce.current=n.map(e=>e.key)},ue=async()=>{if(!re||!Z.trim()){X(null);return}let e=u.find(e=>e.id===re);if(e&&e.name===Z.trim()){X(null);return}ae(!0);try{await(0,o.updateDoc)((0,o.doc)(t.Da,q,re),{name:Z.trim()}),d(e=>e.map(e=>e.id===re?{...e,name:Z.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}ae(!1),X(null)},de=async()=>{await fe(),R(null)},fe=async()=>{if(!L||!z.trim())return;x(!0);let e={};U.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=U.map(e=>e.key.trim()).filter(Boolean),r=ce.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(t.Da,q,L),{name:z.trim(),note:V.trim(),...e}),d(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]}),U.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),ce.current=n}catch(e){console.error(`Error saving record:`,e)}x(!1)},pe=(e,n)=>e?e.startsWith(`image/`)?n?(0,i.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${n})`}}):(0,i.jsx)(t.fi,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,i.jsx)(t.br,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,i.jsx)(t.gi,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,i.jsx)(t.ea,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,i.jsx)(t.Ei,{className:`w-4 h-4`}):(0,i.jsx)(t.hi,{className:`w-4 h-4`}):(0,i.jsx)(t.gi,{className:`w-4 h-4`}),me=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-accent/10 text-accent`:e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?`bg-blue-500/10 text-blue-500`:e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?`bg-yellow-500/10 text-yellow-500`:e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?`bg-emerald-500/10 text-emerald-500`:`bg-foreground/5 text-foreground/40`:`bg-foreground/5 text-foreground/40`,he=e=>{if(!e)return`FILE`;let t={"application/pdf":`PDF`,"application/zip":`ZIP`,"application/x-zip-compressed":`ZIP`,"application/x-rar-compressed":`RAR`,"application/x-7z-compressed":`7Z`,"application/json":`JSON`,"application/xml":`XML`,"application/javascript":`JS`,"application/typescript":`TS`,"application/msword":`DOC`,"application/vnd.openxmlformats-officedocument.wordprocessingml.document":`DOCX`,"application/vnd.ms-excel":`XLS`,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":`XLSX`,"application/vnd.ms-powerpoint":`PPT`,"application/vnd.openxmlformats-officedocument.presentationml.presentation":`PPTX`,"application/rtf":`RTF`,"application/x-tar":`TAR`,"application/gzip":`GZ`,"text/plain":`TXT`,"text/html":`HTML`,"text/css":`CSS`,"text/csv":`CSV`,"text/markdown":`MD`},n=e.toLowerCase();if(t[n])return t[n];let r=n.split(`/`);return r[r.length-1].replace(/^x-/,``).replace(/^vnd\..*\./,``).toUpperCase().slice(0,10)},ge=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},_e=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},ve=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.mr[r]?t.mr[r]:t.mr[n]?t.mr[n]:t.wr||t.Ur})(),ye=e.buttonStyle!==`secondary`,be=e.buttonStorageStyle===`primary`;return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,i.jsxs)(`div`,{children:[(0,i.jsx)(Ce,{children:e.tabTitle||e.tabName||`User Page`}),e.route&&(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsxs)(t.fr.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,i.jsx)(`input`,{type:`file`,ref:G,onChange:te,className:`hidden`}),!n&&(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm:p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,i.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,i.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${u.length} ${u.length===1?`item`:`items`}`})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.storage!==!1&&(0,i.jsx)(i.Fragment,{children:(0,i.jsxs)(t.fr.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>G.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${be?`btn-primary`:`btn-secondary`}`,children:[T?(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin`}):(0,i.jsx)(ve,{className:`w-4 h-4`}),e.buttonStorageText&&(0,i.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})}),e.showButton!==!1&&(0,i.jsx)(t.fr.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>h(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${ye?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,i.jsx)(t.Ur,{className:`w-4 h-4`}):(0,i.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,i.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,i.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,i.jsx)(t.ti,{className:`w-8 h-8 text-accent animate-spin`})}),n?(0,i.jsx)(`div`,{className:`fbos-content-slot`,children:(0,i.jsx)(n,{config:e,actions:{records:u,loading:f,collection:q,user:a,saveRecord:async e=>{let n=(0,o.doc)((0,o.collection)(t.Da,q)),r={id:n.id,uid:a.uid,recordType:`record`,createdAt:Date.now(),...e};d(e=>[r,...e]),await(0,o.setDoc)(n,{uid:a.uid,recordType:`record`,createdAt:(0,o.serverTimestamp)(),...e})},updateRecord:async(e,n)=>{d(t=>t.map(t=>t.id===e?{...t,...n}:t)),await(0,o.updateDoc)((0,o.doc)(t.Da,q,e),n)},deleteRecord:async e=>{await(0,o.deleteDoc)((0,o.doc)(t.Da,q,e))},startEdit:e=>le(e),confirmDelete:e=>O(e),uploadFile:()=>G.current?.click(),openAddForm:()=>h(!0),setAddForm:e=>C(()=>e),setFileHandler:e=>{w.current=e}}})}):(0,i.jsxs)(i.Fragment,{children:[!f&&u.length===0&&(0,i.jsxs)(t.fr.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,i.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,i.jsx)(t.Ur,{className:`w-6 h-6 text-accent/40`})}),(0,i.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files to get started`})]}),!f&&u.length>0&&(0,i.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,i.jsx)(t.pr,{children:u.map((e,n)=>{let r=L===e.id;return(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},transition:{delay:n*.03,duration:.25},onClick:()=>le(e),className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative cursor-pointer ${r?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,i.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),se(e.id),setTimeout(()=>se(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,i.jsx)(t.zi,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,i.jsx)(t.ri,{className:`w-3.5 h-3.5`})}),(0,i.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,i.jsx)(t.Si,{className:`w-3.5 h-3.5`})})]}),(0,i.jsx)(`button`,{onClick:t=>{t.stopPropagation(),le(e)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,i.jsx)(t.Kr,{className:`w-3.5 h-3.5`})}),(0,i.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,i.jsx)(t.Or,{className:`w-3.5 h-3.5`})})]}),(0,i.jsxs)(`div`,{className:`flex items-start gap-3 mb-3`,children:[(0,i.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 ${me(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?pe(e.fileType,e.downloadURL):(0,i.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,i.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[re===e.id?(0,i.jsx)(`input`,{autoFocus:!0,type:`text`,value:Z,onChange:e=>Q(e.target.value),onBlur:()=>ue(),onKeyDown:e=>{e.key===`Enter`&&ue(),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,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,i.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>j(e)}),(0,i.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:_e(e.createdAt)})]})]}),e.note&&(0,i.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,i.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,i.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,i.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e))]},e.id)})})})]})]})]})]}),(0,i.jsx)(t.pr,{children:m&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>!b&&h(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,i.jsx)(t.fr.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:S?r.default.createElement(S,{onSave:async e=>{x(!0);try{await(0,o.addDoc)((0,o.collection)(t.Da,q),{uid:a.uid,recordType:`record`,createdAt:(0,o.serverTimestamp)(),...e}),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)},onClose:()=>!b&&h(!1),saving:b}):(0,i.jsxs)(`form`,{onSubmit:Y,className:`p-5 flex flex-col gap-3`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>!b&&h(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,i.jsx)(t._r,{className:`w-4 h-4`})})]}),(0,i.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:g,onChange:e=>_(e.target.value),placeholder:`Name *`,disabled:b,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),placeholder:`Note (optional)`,disabled:b,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,i.jsx)(t.cr,{type:`submit`,isLoading:b,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:b?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,l.createPortal)((0,i.jsx)(t.pr,{children:M&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,i.jsx)(t.fr.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,i.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,i.jsx)(t._r,{className:`w-5 h-5`})}),(0,i.jsxs)(t.fr.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,i.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,i.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,i.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:M.fileName||M.name}),(0,i.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[he(M.fileType),` • `,ge(M.fileSize||0)]})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,i.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.downloadURL),se(`preview`),setTimeout(()=>se(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,i.jsx)(t.zi,{className:`w-4 h-4 text-emerald-500`}):(0,i.jsx)(t.ri,{className:`w-4 h-4`})}),(0,i.jsx)(`button`,{onClick:()=>{j(null),X(M.id),Q(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,i.jsx)(t.Kr,{className:`w-4 h-4`})}),(0,i.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,i.jsx)(t.Or,{className:`w-4 h-4`})}),(0,i.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,i.jsx)(t.Si,{className:`w-4 h-4`})})]})]}),(0,i.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>j(null),children:(0,i.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,i.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,i.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,i.jsx)(t.ti,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,i.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,i.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,i.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,i.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,i.jsx)(t.gi,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,i.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,i.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,i.jsx)(t.pr,{children:L&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>de(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,i.jsx)(t.fr.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,i.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),b&&(0,i.jsx)(t.ti,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>de(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,i.jsx)(t._r,{className:`w-4 h-4`})})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.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,i.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>B(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>fe(),placeholder:`Name *`,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50`}),(0,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.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,i.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{H(e.target.value),e.target.style.height=`auto`,e.target.style.height=e.target.scrollHeight+`px`},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),e.target.blur())},onBlur:()=>fe(),placeholder:`Add a note...`,rows:1,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50 resize-none overflow-hidden`}),(0,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),U.map((e,n)=>(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let t=[...U];t[n].key=e.target.value,W(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>fe(),className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none placeholder:text-foreground/15 pt-3 pb-0.5 caret-foreground/40`}),(0,i.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let t=[...U];t[n].value=e.target.value,W(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>fe(),className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pt-1.5 pb-1 caret-foreground/50`}),(0,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>W(U.filter((e,t)=>t!==n)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,i.jsx)(t._r,{className:`w-3 h-3`})})]},n)),(0,i.jsxs)(`button`,{type:`button`,onClick:()=>W([...U,{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,i.jsx)(t.Ur,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,i.jsx)(Ve,{isOpen:!!D,onCancel:()=>O(null),onConfirm:ne,title:`Delete Record`,message:(0,i.jsxs)(i.Fragment,{children:[`Are you sure you want to delete `,(0,i.jsx)(`strong`,{className:`text-foreground font-extrabold break-words mx-1`,children:u.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:F})]})}function vm({config:e,customContent:n}){let{user:a}=t.na(),{config:c}=t.ja(),[u,d]=(0,r.useState)([]),[f,p]=(0,r.useState)(!0),[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(``),[v,y]=(0,r.useState)(``),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(null),w=(0,r.useRef)(null),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(null),[k,A]=(0,r.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;P(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[N,P]=(0,r.useState)(!0),[F,I]=(0,r.useState)(!1),[L,R]=(0,r.useState)(null),[z,B]=(0,r.useState)(``),[V,H]=(0,r.useState)(``),[U,W]=(0,r.useState)([]),G=(0,r.useRef)(null),[ee,K]=(0,r.useState)(null),q=(0,r.useRef)([]),J=`admin_${(e.tabName||e.pageId||`admin_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`)}_records`;(0,r.useEffect)(()=>{document.title=e.tabTitle||e.tabName||c.appName||`Your AI Firebase`},[e.tabTitle,e.tabName,c.appName]);let Y=()=>({name:a.displayName||a.email?.split(`@`)[0]||`Admin`,email:a.email||``,avatar:a.photoURL||``});(0,r.useEffect)(()=>{if(!a)return;try{let e=Wa(J,a.uid);e?(d(e),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}}),n=(0,o.onSnapshot)((0,o.query)((0,o.collection)(t.Da,J),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(150)),t=>{let n=e(t.docs);d(n),p(!1),Ga(J,a.uid,n)},n=>{console.error(`Error listening to admin records:`,n);let r=(0,o.onSnapshot)((0,o.query)((0,o.collection)(t.Da,J),(0,o.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),d(n),p(!1),Ga(J,a.uid,n)});return()=>r()});return()=>n()},[a,J]);let te=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=Y();await(0,o.addDoc)((0,o.collection)(t.Da,J),{name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()}),_(``),y(``),h(!1)}catch(e){console.error(`Error saving admin record:`,e)}x(!1)}},ne=async e=>{let n=e.target.files?.[0];if(!n||!a)return;let r=await t.or(n);E(!0);try{let e=`admin_files/${`${Date.now()}_${r.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,n=(0,s.ref)(t.ka,e);await(0,s.uploadBytes)(n,r,{customMetadata:{ownerId:a.uid}});let i=await(0,s.getDownloadURL)(n);if(w.current)w.current(r,i,{uid:a.uid,storagePath:e});else{let e=Y();await(0,o.addDoc)((0,o.collection)(t.Da,J),{name:r.name,note:`${r.type||`File`} · ${me(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type||`unknown`,fileSize:r.size,downloadURL:i,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()})}}catch(e){console.error(`Error uploading admin file:`,e)}E(!1),G.current&&(G.current.value=``)},re=async()=>{if(D){I(!0);try{let e=u.find(e=>e.id===D);if(await(0,o.deleteDoc)((0,o.doc)(t.Da,J,D)),e?.recordType===`file`&&e.downloadURL)try{let n=e.downloadURL.split(`admin_files%2F`)[1]?.split(`?`)[0];n&&await(0,s.deleteObject)((0,s.ref)(t.ka,`admin_files/${decodeURIComponent(n)}`)).catch(()=>{})}catch(e){console.error(`Error cleaning up admin file:`,e)}O(null)}catch(e){console.error(`Error deleting admin record:`,e)}I(!1)}},[X,Z]=(0,r.useState)(null),[Q,ie]=(0,r.useState)(``),[ae,oe]=(0,r.useState)(!1),se=e=>{if(e.recordType===`file`){Z(e.id),ie(e.name);return}R(e.id),B(e.name),H(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??``)}));W(n),q.current=n.map(e=>e.key)},ce=async()=>{if(!X||!Q.trim()){Z(null);return}let e=u.find(e=>e.id===X);if(e&&e.name===Q.trim()){Z(null);return}oe(!0);try{await(0,o.updateDoc)((0,o.doc)(t.Da,J,X),{name:Q.trim()}),d(e=>e.map(e=>e.id===X?{...e,name:Q.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}oe(!1),Z(null)},le=async()=>{if(!L||!z.trim()){R(null);return}x(!0);let e={};U.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=U.map(e=>e.key.trim()).filter(Boolean),r=q.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(t.Da,J,L),{name:z.trim(),note:V.trim(),...e}),d(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]}),U.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),q.current=n}catch(e){console.error(`Error updating record:`,e)}x(!1),R(null)},ue=async()=>{if(!L||!z.trim())return;let e={};U.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=U.map(e=>e.key.trim()).filter(Boolean),r=q.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(t.Da,J,L),{name:z.trim(),note:V.trim(),...e}),d(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]}),U.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),q.current=n}catch(e){console.error(`Error silently saving record:`,e)}},de=(e,n)=>e?e.startsWith(`image/`)?n?(0,i.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${n})`}}):(0,i.jsx)(t.fi,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,i.jsx)(t.br,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,i.jsx)(t.gi,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,i.jsx)(t.ea,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,i.jsx)(t.Ei,{className:`w-4 h-4`}):(0,i.jsx)(t.hi,{className:`w-4 h-4`}):(0,i.jsx)(t.gi,{className:`w-4 h-4`}),fe=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-accent/10 text-accent`: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`,pe=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)},me=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]},he=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},ge=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.mr[r]?t.mr[r]:t.mr[n]?t.mr[n]:t.wr||t.Ur})(),_e=e.buttonStyle!==`secondary`,ve=e.buttonStorageStyle===`primary`,ye=e=>e.uid===a?.uid,be=({record:e})=>{let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||`Admin`,n=e.creatorEmail||``,r=e.creatorAvatar||``,a=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,i.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,i.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,i.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:a}),(0,i.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,i.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,i.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,i.jsxs)(`div`,{children:[(0,i.jsx)(Ce,{children:e.tabTitle||e.tabName||`Admin Page`}),e.route&&(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsxs)(t.fr.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,i.jsx)(`input`,{type:`file`,ref:G,onChange:ne,className:`hidden`}),!n&&(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm:p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,i.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,i.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${u.length} ${u.length===1?`item`:`items`}`})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.storage!==!1&&(0,i.jsx)(i.Fragment,{children:(0,i.jsxs)(t.fr.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>G.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`} ${ve?`btn-primary`:`btn-secondary`}`,children:[T?(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin`}):(0,i.jsx)(ge,{className:`w-4 h-4`}),e.buttonStorageText&&(0,i.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})}),e.showButton!==!1&&(0,i.jsx)(t.fr.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>h(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${_e?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,i.jsx)(t.Ur,{className:`w-4 h-4`}):(0,i.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,i.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,i.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,i.jsx)(t.ti,{className:`w-8 h-8 text-accent animate-spin`})}),n?(0,i.jsx)(`div`,{className:`fbos-content-slot`,children:(0,i.jsx)(n,{config:e,actions:{records:u,loading:f,collection:J,user:a,saveRecord:async e=>{let n=(0,o.doc)((0,o.collection)(t.Da,J)),r=Y(),i={id:n.id,uid:a.uid,recordType:`record`,creatorName:r.name,creatorEmail:r.email,creatorAvatar:r.avatar,createdAt:Date.now(),...e};d(e=>[i,...e]),await(0,o.setDoc)(n,{uid:a.uid,recordType:`record`,creatorName:r.name,creatorEmail:r.email,creatorAvatar:r.avatar,createdAt:(0,o.serverTimestamp)(),...e})},updateRecord:async(e,n)=>{d(t=>t.map(t=>t.id===e?{...t,...n}:t)),await(0,o.updateDoc)((0,o.doc)(t.Da,J,e),n)},deleteRecord:async e=>{await(0,o.deleteDoc)((0,o.doc)(t.Da,J,e))},startEdit:e=>se(e),confirmDelete:e=>O(e),uploadFile:()=>G.current?.click(),openAddForm:()=>h(!0),setAddForm:e=>C(()=>e),setFileHandler:e=>{w.current=e}}})}):(0,i.jsxs)(i.Fragment,{children:[!f&&u.length===0&&(0,i.jsxs)(t.fr.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,i.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,i.jsx)(t.Ur,{className:`w-6 h-6 text-accent/40`})}),(0,i.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All admins can view and contribute.`})]}),!f&&u.length>0&&(0,i.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,i.jsx)(t.pr,{children:u.map((e,n)=>{let r=L===e.id,a=ye(e);return(0,i.jsxs)(t.fr.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>se(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,i.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,i.jsxs)(i.Fragment,{children:[(0,i.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:ee===e.id?(0,i.jsx)(t.zi,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,i.jsx)(t.ri,{className:`w-3.5 h-3.5`})}),(0,i.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,i.jsx)(t.Si,{className:`w-3.5 h-3.5`})})]}),a&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`button`,{onClick:t=>{t.stopPropagation(),se(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,i.jsx)(t.Kr,{className:`w-3.5 h-3.5`})}),(0,i.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,i.jsx)(t.Or,{className:`w-3.5 h-3.5`})})]})]}),(0,i.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,i.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 ${fe(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?de(e.fileType,e.downloadURL):(0,i.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,i.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[X===e.id?(0,i.jsx)(`input`,{autoFocus:!0,type:`text`,value:Q,onChange:e=>ie(e.target.value),onBlur:()=>ce(),onKeyDown:e=>{e.key===`Enter`&&ce(),e.key===`Escape`&&Z(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,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,i.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>j(e)}),(0,i.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:he(e.createdAt)})]})]}),e.note&&(0,i.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,i.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,i.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,i.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,i.jsx)(be,{record:e})]},e.id)})})})]})]})]})]}),(0,i.jsx)(t.pr,{children:m&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>!b&&h(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,i.jsx)(t.fr.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:S?r.default.createElement(S,{onSave:async e=>{x(!0);try{let n=Y();await(0,o.addDoc)((0,o.collection)(t.Da,J),{uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:(0,o.serverTimestamp)(),...e}),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)},onClose:()=>!b&&h(!1),saving:b}):(0,i.jsxs)(`form`,{onSubmit:te,className:`p-5 flex flex-col gap-3`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>!b&&h(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,i.jsx)(t._r,{className:`w-4 h-4`})})]}),(0,i.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:g,onChange:e=>_(e.target.value),placeholder:`Name *`,disabled:b,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),placeholder:`Note (optional)`,disabled:b,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,i.jsx)(t.cr,{type:`submit`,isLoading:b,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:b?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,l.createPortal)((0,i.jsx)(t.pr,{children:M&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,i.jsx)(t.fr.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,i.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,i.jsx)(t._r,{className:`w-5 h-5`})}),(0,i.jsxs)(t.fr.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,i.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,i.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,i.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:M.fileName||M.name}),(0,i.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[pe(M.fileType),` • `,me(M.fileSize||0)]})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,i.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:ee===`preview`?(0,i.jsx)(t.zi,{className:`w-4 h-4 text-emerald-500`}):(0,i.jsx)(t.ri,{className:`w-4 h-4`})}),(0,i.jsx)(`button`,{onClick:()=>{j(null),Z(M.id),ie(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,i.jsx)(t.Kr,{className:`w-4 h-4`})}),(0,i.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,i.jsx)(t.Or,{className:`w-4 h-4`})}),(0,i.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,i.jsx)(t.Si,{className:`w-4 h-4`})})]})]}),(0,i.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>j(null),children:(0,i.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,i.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,i.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,i.jsx)(t.ti,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,i.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,i.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,i.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,i.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,i.jsx)(t.gi,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,i.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,i.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,i.jsx)(t.pr,{children:L&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>le(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,i.jsx)(t.fr.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,i.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),b&&(0,i.jsx)(t.ti,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>le(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,i.jsx)(t._r,{className:`w-4 h-4`})})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.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,i.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:()=>ue(),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,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.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,i.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{H(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:()=>ue(),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,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),U.map((e,n)=>(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let t=[...U];t[n].key=e.target.value,W(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>ue(),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,i.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let t=[...U];t[n].value=e.target.value,W(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>ue(),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,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>W(U.filter((e,t)=>t!==n)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,i.jsx)(t._r,{className:`w-3 h-3`})})]},n)),(0,i.jsxs)(`button`,{type:`button`,onClick:()=>W([...U,{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,i.jsx)(t.Ur,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,i.jsx)(Ve,{isOpen:!!D,onCancel:()=>O(null),onConfirm:re,title:`Delete Record`,message:(0,i.jsxs)(i.Fragment,{children:[`Are you sure you want to delete `,(0,i.jsx)(`strong`,{className:`text-foreground font-extrabold break-words mx-1`,children:u.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:F})]})}function ym({config:e,customContent:n}){let{user:a}=t.na(),{config:c}=t.ja(),[u,d]=(0,r.useState)([]),[f,p]=(0,r.useState)(!0),[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(``),[v,y]=(0,r.useState)(``),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(null),w=(0,r.useRef)(null),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(null),[k,A]=(0,r.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;P(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[N,P]=(0,r.useState)(!0),[F,I]=(0,r.useState)(!1),[L,R]=(0,r.useState)(null),[z,B]=(0,r.useState)(``),[V,H]=(0,r.useState)(``),[U,W]=(0,r.useState)([]),G=(0,r.useRef)(null),[ee,K]=(0,r.useState)(null),q=(0,r.useRef)([]),J=`mem_${(e.tabName||e.pageId||`internal_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`)}_records`;(0,r.useEffect)(()=>{document.title=e.tabTitle||e.tabName||c.appName||`Your AI Firebase`},[e.tabTitle,e.tabName,c.appName]),(0,r.useEffect)(()=>{if(!a)return;try{let e=Wa(J,a.uid);e?(d(e),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}}),n=(0,o.onSnapshot)((0,o.query)((0,o.collection)(t.Da,J),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(150)),t=>{let n=e(t.docs);d(n),p(!1),Ga(J,a.uid,n)},n=>{console.error(`Error listening to shared records:`,n);let r=(0,o.onSnapshot)((0,o.query)((0,o.collection)(t.Da,J),(0,o.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),d(n),p(!1),Ga(J,a.uid,n)});return()=>r()});return()=>n()},[a,J]);let Y=()=>({name:a.displayName||a.email?.split(`@`)[0]||`Member`,email:a.email||``,avatar:a.photoURL||``}),te=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=Y();await(0,o.addDoc)((0,o.collection)(t.Da,J),{name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()}),_(``),y(``),h(!1)}catch(e){console.error(`Error saving shared record:`,e)}x(!1)}},ne=async e=>{let n=e.target.files?.[0];if(!n||!a)return;let r=await t.or(n);E(!0);try{let e=`mem_files/${`${Date.now()}_${r.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,n=(0,s.ref)(t.ka,e);await(0,s.uploadBytes)(n,r,{customMetadata:{ownerId:a.uid}});let i=await(0,s.getDownloadURL)(n);if(w.current)w.current(r,i,{uid:a.uid,storagePath:e});else{let e=Y();await(0,o.addDoc)((0,o.collection)(t.Da,J),{name:r.name,note:`${r.type||`File`} · ${me(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type||`unknown`,fileSize:r.size,downloadURL:i,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()})}}catch(e){console.error(`Error uploading shared file:`,e)}E(!1),G.current&&(G.current.value=``)},re=async()=>{if(D){I(!0);try{let e=u.find(e=>e.id===D);if(await(0,o.deleteDoc)((0,o.doc)(t.Da,J,D)),e?.recordType===`file`&&e.downloadURL)try{let n=e.downloadURL.split(`mem_files%2F`)[1]?.split(`?`)[0];n&&await(0,s.deleteObject)((0,s.ref)(t.ka,`mem_files/${decodeURIComponent(n)}`)).catch(()=>{})}catch(e){console.error(`Error cleaning up shared file:`,e)}O(null)}catch(e){console.error(`Error deleting shared record:`,e)}I(!1)}},[X,Z]=(0,r.useState)(null),[Q,ie]=(0,r.useState)(``),[ae,oe]=(0,r.useState)(!1),se=e=>{if(e.recordType===`file`){Z(e.id),ie(e.name);return}R(e.id),B(e.name),H(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??``)}));W(n),q.current=n.map(e=>e.key)},ce=async()=>{if(!X||!Q.trim()){Z(null);return}let e=u.find(e=>e.id===X);if(e&&e.name===Q.trim()){Z(null);return}oe(!0);try{await(0,o.updateDoc)((0,o.doc)(t.Da,J,X),{name:Q.trim()}),d(e=>e.map(e=>e.id===X?{...e,name:Q.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}oe(!1),Z(null)},le=async()=>{await ue(),R(null)},ue=async()=>{if(!L||!z.trim())return;x(!0);let e={};U.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=U.map(e=>e.key.trim()).filter(Boolean),r=q.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(t.Da,J,L),{name:z.trim(),note:V.trim(),...e}),d(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]}),U.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),q.current=n}catch(e){console.error(`Error saving record:`,e)}x(!1)},de=(e,n)=>e?e.startsWith(`image/`)?n?(0,i.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${n})`}}):(0,i.jsx)(t.fi,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,i.jsx)(t.br,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,i.jsx)(t.gi,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,i.jsx)(t.ea,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,i.jsx)(t.Ei,{className:`w-4 h-4`}):(0,i.jsx)(t.hi,{className:`w-4 h-4`}):(0,i.jsx)(t.gi,{className:`w-4 h-4`}),fe=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-accent/10 text-accent`: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`,pe=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)},me=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]},he=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},ge=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.mr[r]?t.mr[r]:t.mr[n]?t.mr[n]:t.wr||t.Ur})(),_e=e.buttonStyle!==`secondary`,ve=e.buttonStorageStyle===`primary`,ye=e=>e.uid===a?.uid,be=({record:e})=>{let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||`Member`,n=e.creatorEmail||``,r=e.creatorAvatar||``,a=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,i.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,i.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,i.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:a}),(0,i.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,i.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,i.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,i.jsxs)(`div`,{children:[(0,i.jsx)(Ce,{children:e.tabTitle||e.tabName||`Internal Page`}),e.route&&(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsxs)(t.fr.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,i.jsx)(`input`,{type:`file`,ref:G,onChange:ne,className:`hidden`}),!n&&(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm:p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,i.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,i.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${u.length} ${u.length===1?`item`:`items`} · Internal`})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.storage!==!1&&(0,i.jsx)(i.Fragment,{children:(0,i.jsxs)(t.fr.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>G.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`} ${ve?`btn-primary`:`btn-secondary`}`,children:[T?(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin`}):(0,i.jsx)(ge,{className:`w-4 h-4`}),e.buttonStorageText&&(0,i.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})}),e.showButton!==!1&&(0,i.jsx)(t.fr.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>h(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${_e?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,i.jsx)(t.Ur,{className:`w-4 h-4`}):(0,i.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,i.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,i.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,i.jsx)(t.ti,{className:`w-8 h-8 text-accent animate-spin`})}),n?(0,i.jsx)(`div`,{className:`fbos-content-slot`,children:(0,i.jsx)(n,{config:e,actions:{records:u,loading:f,collection:J,user:a,saveRecord:async e=>{let n=(0,o.doc)((0,o.collection)(t.Da,J)),r=Y(),i={id:n.id,uid:a.uid,recordType:`record`,creatorName:r.name,creatorEmail:r.email,creatorAvatar:r.avatar,createdAt:Date.now(),...e};d(e=>[i,...e]),await(0,o.setDoc)(n,{uid:a.uid,recordType:`record`,creatorName:r.name,creatorEmail:r.email,creatorAvatar:r.avatar,createdAt:(0,o.serverTimestamp)(),...e})},updateRecord:async(e,n)=>{d(t=>t.map(t=>t.id===e?{...t,...n}:t)),await(0,o.updateDoc)((0,o.doc)(t.Da,J,e),n)},deleteRecord:async e=>{await(0,o.deleteDoc)((0,o.doc)(t.Da,J,e))},startEdit:e=>se(e),confirmDelete:e=>O(e),uploadFile:()=>G.current?.click(),openAddForm:()=>h(!0),setAddForm:e=>C(()=>e),setFileHandler:e=>{w.current=e}}})}):(0,i.jsxs)(i.Fragment,{children:[!f&&u.length===0&&(0,i.jsxs)(t.fr.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,i.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,i.jsx)(t.Ur,{className:`w-6 h-6 text-accent/40`})}),(0,i.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All team members can view and contribute.`})]}),!f&&u.length>0&&(0,i.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,i.jsx)(t.pr,{children:u.map(e=>{let n=L===e.id,r=ye(e);return(0,i.jsxs)(t.fr.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>r?se(e):null,className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative ${r?`cursor-pointer`:``} ${n?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,i.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,i.jsxs)(i.Fragment,{children:[(0,i.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:ee===e.id?(0,i.jsx)(t.zi,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,i.jsx)(t.ri,{className:`w-3.5 h-3.5`})}),(0,i.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,i.jsx)(t.Si,{className:`w-3.5 h-3.5`})})]}),r&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`button`,{onClick:t=>{t.stopPropagation(),se(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,i.jsx)(t.Kr,{className:`w-3.5 h-3.5`})}),(0,i.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,i.jsx)(t.Or,{className:`w-3.5 h-3.5`})})]})]}),(0,i.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,i.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 ${fe(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?de(e.fileType,e.downloadURL):(0,i.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,i.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[X===e.id?(0,i.jsx)(`input`,{autoFocus:!0,type:`text`,value:Q,onChange:e=>ie(e.target.value),onBlur:()=>ce(),onKeyDown:e=>{e.key===`Enter`&&ce(),e.key===`Escape`&&Z(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,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,i.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>j(e)}),(0,i.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:he(e.createdAt)})]})]}),e.note&&(0,i.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,i.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,i.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,i.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,i.jsx)(be,{record:e})]},e.id)})})})]})]})]})]}),(0,i.jsx)(t.pr,{children:m&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>!b&&h(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,i.jsx)(t.fr.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:S?r.default.createElement(S,{onSave:async e=>{x(!0);try{let n=Y();await(0,o.addDoc)((0,o.collection)(t.Da,J),{uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:(0,o.serverTimestamp)(),...e}),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)},onClose:()=>!b&&h(!1),saving:b}):(0,i.jsxs)(`form`,{onSubmit:te,className:`p-5 flex flex-col gap-3`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>!b&&h(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,i.jsx)(t._r,{className:`w-4 h-4`})})]}),(0,i.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:g,onChange:e=>_(e.target.value),placeholder:`Name *`,disabled:b,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),placeholder:`Note (optional)`,disabled:b,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,i.jsx)(t.cr,{type:`submit`,isLoading:b,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:b?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,l.createPortal)((0,i.jsx)(t.pr,{children:M&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,i.jsx)(t.fr.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,i.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,i.jsx)(t._r,{className:`w-5 h-5`})}),(0,i.jsxs)(t.fr.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,i.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,i.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,i.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:M.fileName||M.name}),(0,i.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[pe(M.fileType),` • `,me(M.fileSize||0)]})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,i.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:ee===`preview`?(0,i.jsx)(t.zi,{className:`w-4 h-4 text-emerald-500`}):(0,i.jsx)(t.ri,{className:`w-4 h-4`})}),(0,i.jsx)(`button`,{onClick:()=>{j(null),Z(M.id),ie(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,i.jsx)(t.Kr,{className:`w-4 h-4`})}),(0,i.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,i.jsx)(t.Or,{className:`w-4 h-4`})}),(0,i.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,i.jsx)(t.Si,{className:`w-4 h-4`})})]})]}),(0,i.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>j(null),children:(0,i.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,i.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,i.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,i.jsx)(t.ti,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,i.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,i.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,i.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,i.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,i.jsx)(t.gi,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,i.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,i.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,i.jsx)(t.pr,{children:L&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>le(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,i.jsx)(t.fr.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,i.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),b&&(0,i.jsx)(t.ti,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>le(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,i.jsx)(t._r,{className:`w-4 h-4`})})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.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,i.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:()=>ue(),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,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.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,i.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{H(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:()=>ue(),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,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),U.map((e,n)=>(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let t=[...U];t[n].key=e.target.value,W(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>ue(),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,i.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let t=[...U];t[n].value=e.target.value,W(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>ue(),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,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>W(U.filter((e,t)=>t!==n)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,i.jsx)(t._r,{className:`w-3 h-3`})})]},n)),(0,i.jsxs)(`button`,{type:`button`,onClick:()=>W([...U,{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,i.jsx)(t.Ur,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,i.jsx)(Ve,{isOpen:!!D,onCancel:()=>O(null),onConfirm:re,title:`Delete Record`,message:(0,i.jsxs)(i.Fragment,{children:[`Are you sure you want to delete `,(0,i.jsx)(`strong`,{className:`text-foreground font-extrabold break-words mx-1`,children:u.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:F})]})}var bm=[`board`,`table`,`calendar`,`drive`],xm=[`inline_form`,`popup_form`],Sm=e=>typeof e!=`string`||e===``||e===`none`||e===`custom`||![...bm,...xm].includes(e),Cm=(e,t)=>Sm(e)||t&&!wm(e),wm=e=>typeof e==`string`&&bm.includes(e),Tm=`/src/your-ai-workflow-firebase-os/microcomponents`,Em=e=>(e||``).split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``),Dm=e=>{let t=e.replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase();return[t,t.replace(/_/g,``)]},Om=e=>{let t=[e?.contentKey,e?.tabName,e?.pageId,e?.pageName].filter(e=>typeof e==`string`&&e.trim()).map(e=>Em(e)).filter(Boolean);return[...new Set(t)].map(e=>`${e}Content.tsx`)},km=e=>{if(typeof window>`u`)return!1;let t=window.__FBOS_MICROCOMPONENTS__;if(!t)return!1;let n=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_|_$/g,``);return[e?.contentKey,e?.tabName,e?.pageId,e?.pageName].filter(e=>typeof e==`string`&&e.trim()).some(e=>t[n(e)])},Am=new Map,jm=e=>{let t=Am.get(e);return t||(t=import(`${Tm}/${e}`).then(e=>typeof e?.default==`function`||typeof e?.default==`object`?e.default:null).catch(()=>null),Am.set(e,t)),t};async function Mm(e){if(typeof window>`u`||km(e))return null;for(let t of Om(e)){let e=await jm(t);if(!e)continue;let[n,r]=Dm(t.replace(/Content\.tsx$/,``)),i=window.__FBOS_MICROCOMPONENTS__||{};return window.__FBOS_MICROCOMPONENTS__={[n]:e,[r]:e,...i},e}return null}var Nm=(e,n)=>{let r=n?t._a(e.pageType):`public`;return{...e,pageType:r,isPrivate:n,isAdmin:r===`admin`,isInternal:r===`internal`,isShared:r===`internal`}};function Pm(){let e=(0,c.useLocation)(),{user:n,userRole:a,loading:s,roleResolved:l,userInactive:u,signOut:d}=t.na(),f=t.Na(),p=e=>{if(typeof window<`u`){let t=localStorage.getItem(`fbos_route_${e}`);if(t)try{let e=JSON.parse(t);if(e.form&&!e.formConfigOverride){let t=localStorage.getItem(`fbos_form_${e.form}`);t&&(e.formConfigOverride=JSON.parse(t))}return Nm(e,e.isPrivate===!0)}catch{}}let n=(typeof window<`u`?window.__FBOS_PAGES__:null)||{},r=e.replace(/^\//,``);for(let[t,i]of Object.entries(n)){let n=i.config,a=i.isPublic,o=n.route||`/`+t;if(o===e||t===r)return Nm({...n,route:o,contentKey:n.pageId||t,pageId:t},!a)}return e===`/contact`?{route:`/contact`,template:`popup_form`,form:`contact`,pageId:`contact`,contentKey:`contact`,pageName:`Contact`,formConfigOverride:f.defaultConfigs?.contactForm||t.La}:e===`/support`?{route:`/support`,template:`popup_form`,form:`support`,pageId:`support`,contentKey:`support`,pageName:`Support`,formConfigOverride:f.defaultConfigs?.supportForm||t.Fa}:null},[m,h]=(0,r.useState)(()=>p(e.pathname)),[g,_]=(0,r.useState)(()=>!p(e.pathname));(0,r.useEffect)(()=>{let n=!0,r=p(e.pathname);if(r){h(r),_(!1);let e=r.pageName||r.tabName||r.title;e&&(document.title=e)}return(async()=>{try{let r=e.pathname;r.startsWith(`/`)&&(r=r.substring(1));let[i,a,s,c,l,u]=await Promise.allSettled([(0,o.getDoc)((0,o.doc)(t.Da,`sys_pages`,r)),(0,o.getDoc)((0,o.doc)(t.Da,`sys_tabs`,r)),(0,o.getDocs)((0,o.query)((0,o.collection)(t.Da,`sys_pages`),(0,o.where)(`route`,`==`,e.pathname),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(t.Da,`sys_pages`),(0,o.where)(`route`,`==`,r),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(t.Da,`sys_tabs`),(0,o.where)(`route`,`==`,e.pathname),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(t.Da,`sys_tabs`),(0,o.where)(`route`,`==`,r),(0,o.limit)(1)))]),d=null,p=null,m=(e,t)=>{d||e.status===`fulfilled`&&(e.value.exists&&e.value.exists()?(d=Nm(e.value.data(),t),p=e.value.id):e.value.docs&&e.value.docs.length>0&&(d=Nm(e.value.docs[0].data(),t),p=e.value.docs[0].id))};if(m(i,!1),m(s,!1),m(c,!1),m(a,!0),m(l,!0),m(u,!0),!d){let t=(typeof window<`u`?window.__FBOS_PAGES__:null)||{};for(let[n,i]of Object.entries(t)){let t=i.config,a=i.isPublic,o=t.route||`/`+n;if(o===e.pathname||n===r){d=Nm({...t,route:o,contentKey:t.pageId||n,pageId:n},!a),p=n;break}}}if(d||(e.pathname===`/contact`?(d={route:`/contact`,template:`popup_form`,form:`contact`,pageName:`Contact`},p=`contact`):e.pathname===`/support`&&(d={route:`/support`,template:`popup_form`,form:`support`,pageName:`Support`},p=`support`)),!n)return;if(d){if((p===`contact`||p===`support`)&&!d.form&&(d.form=p),d.contentKey||=d.pageId||p,d.pageId=p,localStorage.setItem(`fbos_route_${e.pathname}`,JSON.stringify(d)),d.form){let e=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},r=n=>f.defaultConfigs?.[n]||f.defaultConfigs?.[`${n}Form`]||e[n]||(n===`contact`?t.La:n===`support`?t.Fa:null);if(localStorage.getItem(`fbos_custom_form_${d.form}`)){try{let e=localStorage.getItem(`fbos_form_${d.form}`);e&&(d.formConfigOverride=JSON.parse(e))}catch{}(0,o.getDoc)((0,o.doc)(t.Da,`sys_forms`,d.form)).then(async e=>{if(n)if(e.exists()){let t={...e.data(),id:e.id};h(e=>({...e,formConfigOverride:t})),localStorage.setItem(`fbos_form_${d.form}`,JSON.stringify(t))}else{let e=r(d.form);e&&(h(t=>({...t,formConfigOverride:e})),localStorage.setItem(`fbos_form_${d.form}`,JSON.stringify(e)),localStorage.removeItem(`fbos_custom_form_${d.form}`))}})}else{let e=r(d.form);e&&(d.formConfigOverride=e)}}let r=d.pageName||d.tabName||d.title;r&&(document.title=r),h(d),_(!1)}else h(`not-found`),_(!1),localStorage.removeItem(`fbos_route_${e.pathname}`)}catch{n&&g&&(h(`not-found`),_(!1))}})(),()=>{n=!1}},[e.pathname]);let[v,y]=(0,r.useState)(!1),[b,x]=(0,r.useState)(null),[S,C]=(0,r.useState)(!1),w=m&&m!==`not-found`&&typeof m==`object`?[m.contentKey,m.tabName,m.pageId,m.pageName].filter(Boolean).join(`|`):``;if((0,r.useEffect)(()=>{if(x(null),!w||km(m)){C(!1);return}let e=!1;C(!0),Mm(m).then(t=>{e||(t&&x(()=>t),C(!1))});let t=setTimeout(()=>{e||C(!1)},4e3);return()=>{e=!0,clearTimeout(t)}},[w]),(0,r.useEffect)(()=>{let e;return g||s||!l||S?e=setTimeout(()=>y(!0),150):y(!1),()=>clearTimeout(e)},[g,s,l,S]),g||s||!l||S)return v?n?(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(`div`,{className:`mb-6`,children:[(0,i.jsx)(`div`,{className:`h-10 w-56 rounded-xl bg-foreground/5 animate-pulse mt-1`}),(0,i.jsx)(`div`,{className:`h-3 w-24 rounded bg-foreground/5 animate-pulse mt-3`})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.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,i.jsx)(t.ti,{className:`w-6 h-6 animate-spin text-accent`})})]})]}):(0,i.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[40vh] z-10`,children:(0,i.jsxs)(`div`,{className:`p-4 rounded-2xl glass-panel border border-[var(--panel-border)]/40 bg-background/80 shadow-md flex items-center gap-3`,children:[(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin text-accent`}),(0,i.jsx)(`span`,{className:`text-[12px] font-medium text-foreground/60 tracking-wide`,children:`Loading page...`})]})}):null;if(m===`not-found`)return(0,i.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:(0,i.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1 text-center`,children:[(0,i.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,i.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,i.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,i.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,i.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]})}),(0,i.jsx)(`h2`,{className:`text-2xl sm:text-3xl font-bold mb-3 text-foreground`,children:`Page Not Found`}),(0,i.jsx)(`p`,{className:`text-foreground/60 max-w-md`,children:`The route you are looking for does not exist or has been removed.`}),t.pa(a)&&(()=>{let t=dm();return(0,i.jsxs)(`div`,{className:`mt-8 w-full max-w-lg text-left flex flex-col gap-4`,children:[(0,i.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)] px-5 py-4`,children:[(0,i.jsx)(`p`,{className:`text-[12px] font-extrabold tracking-tight text-gradient mb-1.5`,children:`Pages the app can see`}),(0,i.jsx)(`p`,{className:`text-[13px] text-foreground/70 font-medium leading-relaxed`,children:t.length?t.join(` · `):`None yet. If your assistant says it created a page, the app has not picked its file up.`})]}),(0,i.jsx)(it,{title:`If your assistant just made this page, paste this`,prompt:hm(e.pathname)})]})})()]})});if((m.pageId===`support`||m.isPrivate)&&!n)return(0,i.jsx)(c.Navigate,{to:`/login?from=${encodeURIComponent(e.pathname)}`,replace:!0});if((m.pageId===`support`||m.isPrivate)&&n&&u)return(0,i.jsx)(yi,{tone:`red`,title:`Access Denied`,message:`You don't have access to this app. Please contact the administrator.`,action:(0,i.jsx)(`button`,{onClick:()=>d(),className:bi,children:`Sign Out`})});if((m.pageId===`support`||m.isPrivate)&&n&&!n.emailVerified)return(0,i.jsx)(c.Navigate,{to:`/verify`,replace:!0});if(m.isPrivate&&!t.ua(a,m))return(0,i.jsx)(Ci,{});let T=f.customRoutes?.[e.pathname]||(m&&m.route?f.customRoutes?.[m.route]:null),E=m.pageName?.toLowerCase().replace(/\s+/g,`_`)||m.pageId||`custom_page`,D=`pub_${E}`,O=m.isPrivate?`${t.va(m)}${m.pageId||E}`:D,k=f.microcomponents||(typeof window<`u`?window.__FBOS_MICROCOMPONENTS__:void 0),A=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_|_$/g,``),j=[m.contentKey,m.tabName,m.pageId,m.pageName,m.pageName?.replace(/\s+/g,`_`)].filter(Boolean).map(e=>A(e)).reduce((e,t)=>e||k?.[t],void 0),M=T||j||b||void 0,N=m.route||m.pageId||`custom`;return Cm(m.template,!!M)?m.isAdmin?(0,i.jsx)(vm,{config:m,customContent:M},N):m.isInternal?(0,i.jsx)(ym,{config:m,customContent:M},N):m.isPrivate?(0,i.jsx)(_m,{config:m,customContent:M},N):(0,i.jsx)(gm,{config:m,customContent:M},N):m.template===`board`?(0,i.jsx)(f.components?.TemplateBoard||vn,{title:m.tabTitle||m.tabName||m.title||m.pageName||`Board`,subtitle:m.route,tasksCollection:`${O}_tasks`,categoriesCollection:`${O}_categories`,config:m,customContent:M},N):m.template===`table`?(0,i.jsx)(f.components?.TemplateTable||qr,{title:m.tabTitle||m.tabName||m.title||m.pageName||`Table`,subtitle:m.route,tableCollection:`${O}_table`,config:m,customContent:M},N):m.template===`calendar`?(0,i.jsx)(f.components?.TemplateCalendar||Xr,{title:m.tabTitle||m.tabName||m.title||m.pageName||`Calendar`,subtitle:m.route,eventsCollection:`${O}_events`,defaultTimeFormat:m.defaultTimeFormat||m.defaulttimeformat||`12h`,config:m,customContent:M},N):m.template===`drive`?(0,i.jsx)(f.components?.TemplateDrive||Kt,{title:m.tabTitle||m.tabName||m.title||m.pageName||`Drive`,subtitle:m.route,filesCollection:`${O}_files`,config:m,customContent:M},N):m.template===`inline_form`?(0,i.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-start mt-8 relative z-10 w-full min-h-[60vh]`,children:(0,i.jsx)(t.t,{isInline:!0,formId:m.form,formConfig:m.formConfigOverride})}):(0,i.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 w-full min-h-[60vh]`,children:(0,i.jsx)(t.t,{formId:m.form,formConfig:m.formConfigOverride,onClose:()=>window.history.back()})})}var Fm=e=>e.error?`error`:e.paid?`paid`:`unpaid`,Im={checking:{icon:t.Oi,tint:`text-accent`,title:`Checking your payment…`},paid:{icon:t.Ni,tint:`text-emerald-400`,title:`Thank you — payment received`},unpaid:{icon:t.Oi,tint:`text-amber-400`,title:`Not confirmed yet`},error:{icon:t.Pi,tint:`text-red-400`,title:`We could not confirm this payment`},cancelled:{icon:t.Ai,tint:`text-foreground/50`,title:`Payment cancelled`}};function Lm({cancelled:e=!1}){let[n]=(0,c.useSearchParams)(),a=n.get(`session_id`)||``,[o,s]=(0,r.useState)(`checking`),[l,u]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(e)return;let t=!1;return ee(a).then(e=>{t||(u(e),s(Fm(e)))}),()=>{t=!0}},[e,a]);let d=async()=>{s(`checking`);let e=await ee(a);u(e),s(Fm(e))},f=Im[e?`cancelled`:o],p=f.icon;return(0,i.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mb-16`,children:(0,i.jsxs)(t.fr.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,i.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,i.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 shadow-xl`,children:(0,i.jsx)(p,{className:`w-7 h-7 md:w-8 md:h-8 ${f.tint} ${!e&&o===`checking`?`animate-pulse`:``}`})}),(0,i.jsx)(`h1`,{className:`text-2xl md:text-3xl font-extrabold mb-3 text-foreground tracking-tight`,children:f.title}),(0,i.jsxs)(`div`,{className:`text-[14px] md:text-[15px] text-foreground/60 mb-6 md:mb-8 leading-[1.6] tracking-wide`,children:[e&&(0,i.jsx)(`p`,{children:`Nothing was charged. You can try again whenever you like.`}),!e&&o===`checking`&&(0,i.jsx)(`p`,{children:`One moment — confirming with the payment provider.`}),!e&&o===`paid`&&(0,i.jsxs)(`p`,{children:[l?.amountTotal!=null&&l?.currency?`Your payment of ${l.amountTotal} ${l.currency.toUpperCase()} went through.`:`Your payment went through.`,l?.customerEmail?` A receipt is on its way to ${l.customerEmail}.`:``]}),!e&&o===`unpaid`&&(0,i.jsx)(`p`,{children:`The payment provider has not confirmed this payment yet. Some payment methods take a minute — check again shortly, and look for a receipt in your email.`}),!e&&o===`error`&&(0,i.jsxs)(`p`,{children:[l?.error,` If you completed the payment, check your email for a receipt — if one arrived, your payment went through and you can safely close this page.`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-3 max-w-[360px] mx-auto`,children:[!e&&(o===`unpaid`||o===`error`)&&(0,i.jsx)(t.cr,{variant:`primary`,onClick:d,className:`w-full py-2.5 md:py-3 text-[14px] font-bold tracking-wide rounded-xl`,children:`Check again`}),(0,i.jsx)(c.Link,{to:`/`,className:`w-full block py-2.5 md:py-3 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors`,children:`Back to the site`})]})]})})}function Rm({children:e,className:n,variant:a=`secondary`}){let{loading:o,configured:s}=Y(),[c,l]=(0,r.useState)(!1),[u,d]=(0,r.useState)(null);return o||!s?null:(0,i.jsxs)(`span`,{className:`inline-flex flex-col items-stretch gap-2`,children:[(0,i.jsx)(t.cr,{variant:a,className:n,onClick:async()=>{if(c)return;l(!0),d(null);let e=await G();e&&(d(e),l(!1))},disabled:c,children:c?`Opening…`:e??`Manage plan`}),u&&(0,i.jsx)(`span`,{role:`alert`,className:`text-[13px] font-semibold text-red-400 leading-snug`,children:u})]})}function zm(e){return e.status===`past_due`?{label:`Past due`,tone:`bad`}:e.active?{label:`Active`,tone:`good`}:{label:`Cancelled`,tone:`quiet`}}function Bm(e){if(!e.currentPeriodEnd||!e.active)return``;let t=new Date(e.currentPeriodEnd*1e3).toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`});return e.cancelAtPeriodEnd?`Ends on ${t}`:`Renews on ${t}`}function Vm({payment:e}){let n=Gd({kind:`charge`,email:null,name:null,...e});return(0,i.jsxs)(`div`,{className:`flex items-center gap-3 px-3.5 py-2.5 ${t.X}`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0 flex-1`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-bold text-foreground truncate`,children:e.description||`One-off payment`}),(0,i.jsx)(`span`,{className:`text-[11px] text-foreground/45 font-medium truncate`,children:Jd(e.created)})]}),(0,i.jsx)(`span`,{className:`text-[12.5px] font-semibold text-foreground/70 whitespace-nowrap shrink-0`,children:Kd(e.amount,e.currency)}),(0,i.jsx)(Yd,{label:n.label,tone:n.tone})]})}function Hm({sub:e}){let n=zm(e),r=Bm(e);return(0,i.jsxs)(`div`,{className:`flex flex-col gap-3 px-3.5 py-3 ${t.X}`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0 flex-1`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-bold text-foreground truncate`,children:e.productName||`Subscription`}),(0,i.jsxs)(`span`,{className:`text-[11px] text-foreground/45 font-medium truncate`,children:[Kd(e.amount,e.currency),e.interval?` / ${e.interval}`:``,r?` — ${r}`:``]})]}),(0,i.jsx)(Yd,{label:n.label,tone:n.tone})]}),(0,i.jsx)(Rm,{className:`self-start`})]})}function Um(){let{user:e}=t.na(),{loading:n,subscriptions:r,payments:a,error:o}=te(),s=!n&&!o&&r.length===0&&a.length===0;return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,i.jsx)(Ce,{children:`Billing`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/billing`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-5 md:p-8 shadow-2xl relative bg-background flex flex-col min-h-[400px]`,children:n?(0,i.jsx)(`div`,{className:`flex items-center justify-center flex-1 text-foreground/40 py-16`,children:(0,i.jsx)(t.ti,{className:`w-6 h-6 animate-spin text-accent`})}):o?(0,i.jsx)(`p`,{className:`text-[12.5px] font-medium leading-relaxed px-1 text-red-500`,children:o}):s?(0,i.jsx)(t.at,{icon:t.Vr,title:`Nothing here yet`,description:`No payments have been made on this account.`,collapsible:!1,children:(0,i.jsxs)(`p`,{className:`text-[12.5px] font-medium leading-relaxed px-1 text-foreground/50`,children:[`Nothing has been bought on this account’s email`,e?.email?(0,i.jsxs)(i.Fragment,{children:[` (`,(0,i.jsx)(`strong`,{children:e.email}),`)`]}):null,`. A payment made with a different email address at checkout lives with that email — sign in with the address you paid with to see it here.`]})}):(0,i.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[r.length>0&&(0,i.jsx)(t.at,{icon:t.wi,title:r.length===1?`Your subscription`:`Your subscriptions`,description:`Manage plan opens Stripe's own portal — cancel, switch, card, invoices.`,collapsible:!1,children:(0,i.jsx)(`div`,{className:`flex flex-col gap-2.5`,children:r.map(e=>(0,i.jsx)(Hm,{sub:e},e.id))})}),a.length>0&&(0,i.jsx)(t.at,{icon:t.Vr,title:`Your payments`,description:`Every payment on this account, straight from Stripe.`,collapsible:!1,children:(0,i.jsx)(`div`,{className:`flex flex-col gap-2.5`,children:a.map(e=>(0,i.jsx)(Vm,{payment:e},e.id))})})]})})]})]})}var Wm=`text-accent underline underline-offset-2 font-semibold hover:text-accent-deep transition-colors`,Gm=`space-y-2 list-decimal list-inside text-foreground/75 marker:font-bold marker:text-foreground/40`;function Km({href:e,children:t}){return(0,i.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:Wm,children:t})}function qm({children:e}){return(0,i.jsx)(`h4`,{className:`text-[12px] font-extrabold uppercase tracking-[0.14em] text-foreground/40 pt-1`,children:e})}function Jm({number:e,title:n,done:r,open:a,onToggle:o,children:s}){let c=(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`span`,{className:`w-8 h-8 shrink-0 rounded-full flex items-center justify-center text-[13.5px] font-extrabold border ${r?`bg-emerald-500/10 border-emerald-500/20 text-emerald-500`:`bg-accent/10 border-accent/20 text-accent`}`,children:r?(0,i.jsx)(t.zi,{className:`w-4 h-4`}):e}),(0,i.jsx)(`span`,{className:`flex-1 min-w-0 text-[14.5px] sm:text-[15px] font-bold text-foreground tracking-tight truncate`,children:n}),o&&(0,i.jsx)(t.Ri,{className:`w-4 h-4 shrink-0 text-foreground/40 transition-transform duration-200 ${a?`rotate-180`:``}`})]});return(0,i.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)]/60 bg-foreground/[0.015] overflow-hidden transition-all`,children:[o?(0,i.jsx)(`button`,{type:`button`,onClick:o,"aria-expanded":a,className:`w-full px-4 sm:px-5 py-4 flex items-center gap-3 sm:gap-3.5 text-left cursor-pointer hover:bg-foreground/[0.02] transition-colors`,children:c}):(0,i.jsx)(`div`,{className:`w-full px-4 sm:px-5 py-4 flex items-center gap-3 sm:gap-3.5`,children:c}),(0,i.jsx)(t.pr,{initial:!1,children:a&&(0,i.jsx)(t.fr.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden`,children:(0,i.jsx)(`div`,{className:`border-t border-[var(--panel-border)]/40 p-4 sm:p-5 flex flex-col gap-4 bg-background/30 text-[13.5px] sm:text-[14px] text-foreground/70 leading-relaxed`,children:s})})})]})}function Ym({label:e,onDone:n,waitingFor:r}){return(0,i.jsxs)(`div`,{className:`flex flex-col gap-2 pt-1`,children:[(0,i.jsxs)(t.fr.button,{type:`button`,whileHover:r?void 0:{scale:1.01},whileTap:r?void 0:{scale:.99},onClick:n,disabled:!!r,className:`btn-primary inline-flex items-center justify-center gap-2 h-11 px-5 rounded-[var(--btn-radius,0.75rem)] text-[13px] font-bold text-white self-start max-sm:self-stretch shadow-lg ${r?`opacity-40 cursor-not-allowed`:`cursor-pointer`}`,children:[(0,i.jsx)(t.zi,{className:`w-4 h-4`}),e]}),r&&(0,i.jsx)(`span`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:r})]})}function Xm({label:e,hint:n,placeholder:a,invalid:o,value:s,clean:c,preview:l,onSave:u}){let[d,f]=(0,r.useState)(s),[p,m]=(0,r.useState)(!1),[h,g]=(0,r.useState)(``),_=c(d),v=d.trim().length>0,y=_!==s;return(0,i.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,i.jsx)(t.ft,{label:e,hint:n,value:d,onChange:e=>{f(e),g(``)},placeholder:a,error:h,action:(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s&&!y&&(0,i.jsx)(t.lt,{state:`saved`,label:`Saved`}),(0,i.jsx)(t.Q,{icon:t.zi,onClick:async()=>{if(!_){g(o);return}m(!0);let e=await u(_);m(!1),g(e||``),e||f(_)},busy:p,disabled:!v||!y&&!!s,children:`Save`})]})}),_&&!h&&(0,i.jsx)(`div`,{className:`px-3.5 py-2.5 rounded-xl border border-[var(--panel-border)]/60 bg-background`,children:(0,i.jsx)(`span`,{className:`text-[12.5px] font-mono text-foreground/60 truncate block`,children:l(_)})})]})}function Zm({label:e,url:t}){return(0,i.jsxs)(`div`,{className:`flex max-sm:flex-col sm:items-center justify-between gap-2 sm:gap-3 px-3.5 py-3 rounded-xl border border-[var(--panel-border)]/60 bg-background`,children:[(0,i.jsxs)(`div`,{className:`min-w-0 flex flex-col gap-0.5`,children:[(0,i.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-[0.14em] text-foreground/40`,children:e}),(0,i.jsx)(`span`,{className:`text-[12.5px] font-mono text-foreground/70 truncate`,children:t})]}),(0,i.jsx)(Ru,{compact:!0,code:t,label:`Copy`})]})}var Qm=[`216.239.32.21`,`216.239.34.21`,`216.239.36.21`,`216.239.38.21`];function $m(){let{loading:e,record:n,save:a}=xd(),[o,s]=(0,r.useState)(null),{status:l}=ad(),u=vd(n.done,o),d=e=>u[ud.indexOf(e)],f=md(n.appName),p=gd(n.domain),m=n.done.length===ud.length,h=m&&bd(l),g=e=>{s(null),a({done:yd(n.done,e)})},_=e=>e.open?e.done?()=>s(null):void 0:()=>s(e.done?e.id:null),v=e=>{let t=d(e);return{done:t.done,open:t.open,onToggle:_(t)}};return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,i.jsx)(Ce,{children:`Publish App`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/publish`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-6 md:p-8 shadow-2xl relative bg-background flex flex-col`,children:[(0,i.jsx)(`div`,{className:`mb-6 pb-4 sm:mb-8 sm:pb-6 border-b border-[var(--panel-border)]/50`,children:(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4`,children:[(0,i.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,i.jsx)(`h2`,{className:`text-[17px] sm:text-xl font-extrabold text-foreground tracking-tight truncate`,children:`Putting your app in front of people`}),(0,i.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1 sm:mt-1.5 leading-snug truncate`,children:[(0,i.jsx)(`span`,{className:`sm:hidden`,children:`One step at a time. Stuck? Message me.`}),(0,i.jsx)(`span`,{className:`max-sm:hidden`,children:`One step at a time — the next one appears as you tick each off. Stuck anywhere? Message me.`})]})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,i.jsx)(t.fr.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,i.jsx)(t.Zr,{className:`w-4 h-4`})}),(0,i.jsx)(t.fr.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,i.jsx)(bu,{className:`w-4 h-4 text-foreground/80`})})]})]})}),!e&&(0,i.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,i.jsxs)(Jm,{number:1,title:`Publish in AI Studio`,...v(`published`),children:[(0,i.jsxs)(`ol`,{className:Gm,children:[(0,i.jsxs)(`li`,{children:[`In `,(0,i.jsx)(Km,{href:`https://aistudio.google.com`,children:`Google AI Studio`}),`, click`,` `,(0,i.jsx)(`strong`,{children:`Publish`}),` in the top left corner, then `,(0,i.jsx)(`strong`,{children:`Get started`}),`.`]}),(0,i.jsxs)(`li`,{children:[`It asks for an app URL. Type a name for your app —`,` `,(0,i.jsx)(`span`,{className:`text-accent`,children:`my-ai-project`}),` — and copy it, you need it again at the bottom of this step.`]}),(0,i.jsxs)(`li`,{children:[`Follow the rest of AI Studio's instructions, then click `,(0,i.jsx)(`strong`,{children:`Publish your app`}),`.`]})]}),(0,i.jsxs)(`p`,{children:[`If it says `,(0,i.jsx)(`strong`,{children:`Failed to publish app`}),`, reload the page, unpublish, and publish again. It usually goes through the second time.`]}),(0,i.jsx)(Xm,{label:`Your app name`,hint:`The name you just typed into AI Studio. Saving only keeps it for step 3 — nothing changes in AI Studio, it just says Saved. Pasting the whole address is fine; only the name is kept.`,placeholder:`my-ai-project`,invalid:`That does not look like an app name — letters, numbers and dashes.`,value:n.appName,clean:pd,preview:md,onSave:e=>a({appName:e})}),(0,i.jsx)(Ym,{label:`My app is published`,onDone:()=>g(`published`),waitingFor:n.appName?void 0:`Save your app name first — step 3 asks for this address.`})]}),d(`connected`).visible&&(0,i.jsxs)(Jm,{number:2,title:`Connect your website domain`,...v(`connected`),children:[(0,i.jsxs)(`p`,{children:[`Your app is live at `,(0,i.jsx)(`span`,{className:`font-mono text-foreground/80`,children:f||`your AI Studio address`}),` `,`already. This step puts it on a domain of your own.`]}),(0,i.jsx)(qm,{children:`Start the mapping`}),(0,i.jsxs)(`ol`,{className:Gm,children:[(0,i.jsxs)(`li`,{children:[`Back where you published, click `,(0,i.jsx)(`strong`,{children:`Advanced settings`}),`. It takes you to Google Cloud Run.`]}),(0,i.jsxs)(`li`,{children:[`In the menu on the left, open `,(0,i.jsx)(`strong`,{children:`Domain mappings`}),`, then`,` `,(0,i.jsx)(`strong`,{children:`Add mapping`}),` at the top.`]}),(0,i.jsxs)(`li`,{children:[`Choose your service, then under `,(0,i.jsx)(`strong`,{children:`Select a verified domain`}),` click`,` `,(0,i.jsx)(`strong`,{children:`Verify new domain`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Type your domain — `,(0,i.jsx)(`span`,{className:`text-accent`,children:`myaiproject.com`}),` — and click`,` `,(0,i.jsx)(`strong`,{children:`Continue`}),`, then `,(0,i.jsx)(`strong`,{children:`Verify in Search Console`}),`.`]})]}),(0,i.jsx)(qm,{children:`Prove the domain is yours`}),(0,i.jsxs)(`ol`,{className:Gm,children:[(0,i.jsxs)(`li`,{children:[`Google Search Console opens. Click `,(0,i.jsx)(`strong`,{children:`Add a website`}),`, type the same domain, and click `,(0,i.jsx)(`strong`,{children:`Continue`}),`.`]}),(0,i.jsxs)(`li`,{children:[`On the next screen, under `,(0,i.jsxs)(`em`,{children:[`Copy the TXT record below into the DNS configuration for `,hd(n.domain)||`myaiproject.com`]}),`, copy the`,` `,(0,i.jsx)(`strong`,{children:`TXT record`}),` — a long line starting`,` `,(0,i.jsx)(`span`,{className:`font-mono text-foreground/80`,children:`google-site-verification=`})]}),(0,i.jsxs)(`li`,{children:[`Open your domain registrar in another tab — GoDaddy, Namecheap, whoever you bought the domain from — go to its `,(0,i.jsx)(`strong`,{children:`DNS settings`}),`, and click`,` `,(0,i.jsx)(`strong`,{children:`Add record`}),`. Choose `,(0,i.jsx)(`strong`,{children:`TXT`}),`, paste the line into`,` `,(0,i.jsx)(`strong`,{children:`Value`}),`, and put `,(0,i.jsx)(`span`,{className:`font-mono text-foreground/80`,children:`@`}),` `,`in `,(0,i.jsx)(`strong`,{children:`Host`}),` or `,(0,i.jsx)(`strong`,{children:`Name`}),`. Save it.`]}),(0,i.jsxs)(`li`,{children:[`Back in Search Console, click `,(0,i.jsx)(`strong`,{children:`Verify`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Once it is verified you are done with Search Console — close that tab. Go back to the Google Cloud Run tab (`,(0,i.jsx)(`span`,{className:`font-mono text-foreground/80`,children:`console.cloud.google.com`}),`) where you clicked to verify, and press its `,(0,i.jsx)(`strong`,{children:`refresh`}),` button. It should say `,(0,i.jsxs)(`em`,{children:[`Your ownership of `,hd(n.domain)||`myaiproject.com`,` has been successfully verified. You can now map this domain to your Cloud Run services.`]})]})]}),(0,i.jsx)(qm,{children:`Point the domain at your app`}),(0,i.jsxs)(`ol`,{className:Gm,children:[(0,i.jsxs)(`li`,{children:[`Add a subdomain if you want one, then click `,(0,i.jsx)(`strong`,{children:`Continue`}),`. Cloud Run now shows you the records to add.`]}),(0,i.jsxs)(`li`,{children:[`Back at your registrar, add each one as an `,(0,i.jsx)(`strong`,{children:`A record`}),`, the same way you added the TXT. It is normally these four:`]})]}),(0,i.jsxs)(`div`,{className:`rounded-xl border border-[var(--panel-border)]/60 bg-background overflow-hidden`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3.5 py-2.5 border-b border-[var(--panel-border)]/40`,children:[(0,i.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-[0.14em] text-foreground/40`,children:`A records`}),(0,i.jsx)(Ru,{compact:!0,code:Qm.join(`
|
|
678
|
-
`),label:`Copy all four`})]}),(0,i.jsx)(`div`,{className:`px-3.5 py-2.5 flex flex-col gap-1`,children:Qm.map(e=>(0,i.jsx)(`span`,{className:`text-[12.5px] font-mono text-foreground/70`,children:e},e))})]}),(0,i.jsx)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:`Use whatever your own Cloud Run screen shows if it differs from these — that screen is always right.`}),(0,i.jsxs)(`p`,{children:[`Once they are all in, press `,(0,i.jsx)(`strong`,{children:`Done`}),` in Cloud Run and wait — this can take an hour or more. Check every few minutes by typing your domain into any browser, like `,(0,i.jsx)(`span`,{className:`text-accent`,children:`myaiproject.com`}),`: when your published app comes up, it is connected.`]}),(0,i.jsx)(Xm,{label:`Your domain`,hint:`However you have it — with or without https:// and www. Only the domain itself is kept, for step 3.`,placeholder:`myaiproject.com`,invalid:`That does not look like a domain — something like myaiproject.com.`,value:n.domain,clean:hd,preview:gd,onSave:e=>a({domain:e})}),(0,i.jsx)(Ym,{label:`My domain is verified and my app is connected`,onDone:()=>g(`connected`),waitingFor:n.domain?void 0:`Save your domain first — step 3 asks for this address.`})]}),d(`authorised`).visible&&(0,i.jsxs)(Jm,{number:3,title:`Add your domains and email sender`,...v(`authorised`),children:[(0,i.jsxs)(`p`,{children:[`Once your domain answers, head back to the`,` `,(0,i.jsx)(Km,{href:`https://console.firebase.google.com`,children:`Firebase console`}),`. Two jobs, both under `,(0,i.jsx)(`strong`,{children:`Security → Authentication`}),`.`]}),(0,i.jsx)(qm,{children:`Authorise both addresses`}),(0,i.jsxs)(`p`,{children:[`Nobody can sign in from an address Firebase does not know. Open`,` `,(0,i.jsx)(`strong`,{children:`Security → Authentication → Settings → Authorised domains`}),`, click`,` `,(0,i.jsx)(`strong`,{children:`Add domain`}),`, and paste these in one at a time — both need to be there.`]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,i.jsx)(Zm,{label:`Your AI Studio address`,url:f?`${pd(n.appName)}.ai.studio`:`—`}),(0,i.jsx)(Zm,{label:`Your own domain`,url:hd(n.domain)||`—`})]}),(0,i.jsx)(qm,{children:`Send email from your own domain`}),(0,i.jsxs)(`ol`,{className:Gm,children:[(0,i.jsxs)(`li`,{children:[`On the same Authentication page, open the `,(0,i.jsx)(`strong`,{children:`Templates`}),` tab. Every email Firebase sends for you lives here — password changes, email verification. You can reword them, but the one thing worth doing is the sender.`]}),(0,i.jsxs)(`li`,{children:[`Click the pencil beside `,(0,i.jsx)(`strong`,{children:`From`}),`. It will be something like`,` `,(0,i.jsx)(`span`,{className:`font-mono text-foreground/80`,children:`noreply@your-project.firebaseapp.com`})]}),(0,i.jsxs)(`li`,{children:[`On the right, click `,(0,i.jsx)(`strong`,{children:`Customise domain`}),`, enter your own domain, and follow the steps it gives you — more records at your registrar, same as before.`]})]}),(0,i.jsx)(`p`,{children:`This is what keeps your emails out of people's spam folders, and it is why they arrive looking like they came from you.`}),(0,i.jsx)(Ym,{label:`I've added my domains and verified my email domain`,onDone:()=>g(`authorised`)})]}),h&&(0,i.jsxs)(Jm,{number:4,title:`Finalise your Stripe live setup`,done:!1,open:!0,children:[(0,i.jsx)(`p`,{children:`Your payments are not live yet — still on practice cards, or live without the webhook that sends receipts. Finish Go live on the Payments screen and your setup is complete.`}),(0,i.jsxs)(`p`,{children:[`Switch `,(0,i.jsx)(`strong`,{children:`Go live`}),` on and follow its steps. Its webhook step was waiting for your published address, and it is open now that step 3 is ticked.`]}),(0,i.jsxs)(c.Link,{to:`/payments`,className:`btn-primary inline-flex items-center justify-center gap-2 h-11 px-5 rounded-[var(--btn-radius,0.75rem)] text-[13px] font-bold text-white self-start max-sm:self-stretch shadow-lg cursor-pointer`,children:[(0,i.jsx)(t.wi,{className:`w-4 h-4`}),`Take me to Go live`]})]}),m&&!h&&(0,i.jsxs)(`div`,{className:`mt-3 flex max-sm:flex-col sm:items-center gap-4 sm:gap-6 p-5 sm:p-6 rounded-2xl border border-emerald-500/20 bg-emerald-500/[0.06]`,children:[(0,i.jsx)(`div`,{className:`w-10 h-10 shrink-0 rounded-2xl flex items-center justify-center border border-emerald-500/20 bg-emerald-500/10 text-emerald-500`,children:(0,i.jsx)(t.zr,{className:`w-5 h-5`})}),(0,i.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,i.jsx)(`h3`,{className:`text-[15px] font-extrabold text-foreground tracking-tight`,children:`Your app is live`}),(0,i.jsxs)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed mt-1`,children:[p?(0,i.jsxs)(i.Fragment,{children:[`Anyone can open `,(0,i.jsx)(Km,{href:p,children:hd(n.domain)}),` and sign up.`]}):(0,i.jsx)(i.Fragment,{children:`Anyone can open your app and sign up.`}),` `,`Any step above opens again if you need to check what you typed.`]})]})]})]})]})]})]})}var eh={contentKey:`dashboard`};function th(){let{user:e}=t.na(),n=t.Na(),[a,o]=(0,r.useState)(null),[s,c]=(0,r.useState)(()=>typeof window<`u`&&!km(eh));(0,r.useEffect)(()=>{if(km(eh))return;let e=!1;Mm(eh).then(t=>{e||(t&&o(()=>t),c(!1))});let t=setTimeout(()=>{e||c(!1)},4e3);return()=>{e=!0,clearTimeout(t)}},[]);let l=n.microcomponents?.dashboard||(typeof window<`u`?window.__FBOS_MICROCOMPONENTS__?.dashboard:void 0)||a||void 0,u=(e?.displayName||e?.email?.split(`@`)[0]||`there`).split(` `)[0],d=u.charAt(0).toUpperCase()+u.slice(1);return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,i.jsxs)(Ce,{children:[`Welcome back, `,d,`.`]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/dashboard`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-4 flex-1 min-h-[500px]`,children:[(0,i.jsx)(`div`,{className:`flex justify-start`,children:(0,i.jsx)(Fe,{})}),(0,i.jsxs)(`div`,{className:`w-full flex-1 glass-panel rounded-3xl relative overflow-hidden border border-[var(--panel-border)] shadow-2xl bg-[var(--panel-bg)] ${l?`p-6 md:p-8`:`p-8 md:p-12 flex items-center justify-center`}`,children:[(0,i.jsx)(`div`,{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-64 h-64 bg-accent/10 blur-[100px] rounded-full pointer-events-none`}),l?(0,i.jsx)(`div`,{className:`fbos-content-slot relative z-10`,children:(0,i.jsx)(l,{})}):s?(0,i.jsx)(t.ti,{className:`w-6 h-6 text-accent animate-spin relative z-10`}):(0,i.jsx)(t.pr,{mode:`wait`,children:(0,i.jsxs)(t.fr.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,i.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,i.jsx)(t.Ci,{className:`w-6 h-6`})}),(0,i.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground mb-2`,children:`No data added here yet`}),(0,i.jsx)(`p`,{className:`text-foreground/40 font-medium`,children:`Keep moving forward, your data will appear here.`})]})})]})]})]})}var nh=()=>(0,i.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,i.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,i.jsx)(t.Ci,{className:`w-6 h-6 text-accent animate-pulse`})}),(0,i.jsxs)(`div`,{className:`flex items-center gap-3 glass-panel px-5 py-2.5 rounded-full border border-[var(--panel-border)]`,children:[(0,i.jsx)(`div`,{className:`w-4 h-4 border-2 border-accent border-t-transparent rounded-full animate-spin`}),(0,i.jsx)(`span`,{className:`text-[13px] font-bold tracking-widest uppercase text-foreground/70`,children:`Connecting`})]})]});function rh({level:e,children:n}){let{user:r,userRole:a,loading:o,userInactive:s,signOut:l,roleResolved:u}=t.na(),d=(0,c.useLocation)();return o||!u?(0,i.jsx)(nh,{}):r?s?(0,i.jsx)(yi,{tone:`red`,title:`Access Denied`,message:`You don't have access to this app. Please contact the administrator.`,action:(0,i.jsx)(`button`,{onClick:()=>l(),className:bi,children:`Sign Out`})}):r.emailVerified?e===`admin`&&!t.pa(a)?(0,i.jsx)(Ti,{}):e===`internal`&&!t.fa(a)?(0,i.jsx)(wi,{}):(0,i.jsx)(i.Fragment,{children:n}):(0,i.jsx)(c.Navigate,{to:`/verify`}):(0,i.jsx)(c.Navigate,{to:`/login?from=${encodeURIComponent(d.pathname)}`,replace:!0})}var ih=({children:e})=>(0,i.jsx)(rh,{level:`signed-in`,children:e}),ah=({children:e})=>(0,i.jsx)(rh,{level:`admin`,children:e}),oh=({children:e})=>(0,i.jsx)(rh,{level:`internal`,children:e});function sh({children:e}){let{user:n,loading:r,roleResolved:a}=t.na(),[o]=(0,c.useSearchParams)();return r||!a?(0,i.jsx)(nh,{}):n&&n.emailVerified?(0,i.jsx)(c.Navigate,{to:o.get(`from`)||`/dashboard`,replace:!0}):(0,i.jsx)(i.Fragment,{children:e})}function ch({children:e}){let{user:n,loading:r,roleResolved:a}=t.na();return r||!a?(0,i.jsx)(nh,{}):n?n.emailVerified?(0,i.jsx)(c.Navigate,{to:`/dashboard`}):(0,i.jsx)(i.Fragment,{children:e}):(0,i.jsx)(c.Navigate,{to:`/`})}function lh({to:e}){return(0,i.jsx)(c.Navigate,{to:`${e}${(0,c.useLocation)().search}`,replace:!0})}function uh(){return(0,i.jsxs)(`div`,{className:`fixed top-0 left-0 w-full h-full pointer-events-none -z-0 overflow-hidden`,children:[(0,i.jsx)(t.fr.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,i.jsx)(t.fr.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 dh(){let e=t.Na().components?.Home||se,n=(0,c.useNavigate)();return(0,i.jsx)(t.ta,{onSignedOut:()=>n(`/`,{replace:!0}),children:(0,i.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,i.jsx)(oe,{}),(0,i.jsxs)(c.Routes,{children:[(0,i.jsx)(c.Route,{path:`/`,element:(0,i.jsx)(sh,{children:(0,i.jsx)(`div`,{className:`fbos-home-slot contents`,children:(0,i.jsx)(e,{})})})}),(0,i.jsx)(c.Route,{path:`/register`,element:(0,i.jsx)(sh,{children:(0,i.jsx)(ve,{})})}),(0,i.jsx)(c.Route,{path:`/login`,element:(0,i.jsx)(sh,{children:(0,i.jsx)(ye,{})})}),(0,i.jsx)(c.Route,{path:`/reset-password`,element:(0,i.jsx)(sh,{children:(0,i.jsx)(Le,{})})}),(0,i.jsx)(c.Route,{path:`/verify`,element:(0,i.jsx)(ch,{children:(0,i.jsx)(be,{})})}),(0,i.jsx)(c.Route,{path:`/book/:id`,element:(0,i.jsx)(Bp,{})}),(0,i.jsx)(c.Route,{path:`/meet/:id`,element:(0,i.jsx)(Yp,{})}),(0,i.jsx)(c.Route,{path:`/pay/:id`,element:(0,i.jsx)(Zp,{})}),(0,i.jsx)(c.Route,{path:`/payment-complete`,element:(0,i.jsx)(Lm,{})}),(0,i.jsx)(c.Route,{path:`/payment-cancelled`,element:(0,i.jsx)(Lm,{cancelled:!0})}),(0,i.jsx)(c.Route,{path:`/guide`,element:(0,i.jsx)(fn,{})}),(0,i.jsx)(c.Route,{path:`/templates`,element:(0,i.jsx)(Zt,{})}),(0,i.jsx)(c.Route,{path:`/board`,element:(0,i.jsx)(vn,{})}),(0,i.jsx)(c.Route,{path:`/table`,element:(0,i.jsx)(qr,{})}),(0,i.jsx)(c.Route,{path:`/calendar`,element:(0,i.jsx)(Xr,{})}),(0,i.jsx)(c.Route,{path:`/drive`,element:(0,i.jsx)(Kt,{})}),(0,i.jsx)(c.Route,{path:`/inline_form`,element:(0,i.jsx)(pn,{})}),(0,i.jsx)(c.Route,{path:`/popup_form`,element:(0,i.jsx)(mn,{})}),(0,i.jsx)(c.Route,{path:`/users`,element:(0,i.jsx)(ah,{children:(0,i.jsx)(Dt,{})})}),(0,i.jsx)(c.Route,{path:`/users/:id`,element:(0,i.jsx)(ah,{children:(0,i.jsx)(Dt,{})})}),(0,i.jsx)(c.Route,{path:`/inbox`,element:(0,i.jsx)(ah,{children:(0,i.jsx)(Ht,{})})}),(0,i.jsx)(c.Route,{path:`/payments`,element:(0,i.jsx)(ah,{children:(0,i.jsx)(Xd,{})})}),(0,i.jsx)(c.Route,{path:`/schedule`,element:(0,i.jsx)(oh,{children:(0,i.jsx)(Sp,{})})}),(0,i.jsx)(c.Route,{path:`/my-calendar`,element:(0,i.jsx)(lh,{to:`/schedule`})}),(0,i.jsx)(c.Route,{path:`/my-bookings`,element:(0,i.jsx)(ih,{children:(0,i.jsx)(Cp,{})})}),(0,i.jsx)(c.Route,{path:`/email`,element:(0,i.jsx)(ah,{children:(0,i.jsx)(lm,{})})}),(0,i.jsx)(c.Route,{path:`/submissions`,element:(0,i.jsx)(c.Navigate,{to:`/inbox`,replace:!0})}),(0,i.jsx)(c.Route,{path:`/requests`,element:(0,i.jsx)(c.Navigate,{to:`/inbox`,replace:!0})}),(0,i.jsx)(c.Route,{path:`/assets`,element:(0,i.jsx)(ah,{children:(0,i.jsx)(Xt,{})})}),(0,i.jsx)(c.Route,{path:`/drive/:rest`,element:(0,i.jsx)(c.Navigate,{to:`/assets`,replace:!0})}),(0,i.jsx)(c.Route,{path:`/theme`,element:(0,i.jsx)(ah,{children:(0,i.jsx)(vi,{})})}),(0,i.jsx)(c.Route,{path:`/pages/*`,element:(0,i.jsx)(ah,{children:(0,i.jsx)(Ml,{})})}),(0,i.jsx)(c.Route,{path:`/forms/*`,element:(0,i.jsx)(ah,{children:(0,i.jsx)(ql,{})})}),(0,i.jsx)(c.Route,{path:`/settings`,element:(0,i.jsx)(c.Navigate,{to:`/pages`,replace:!0})}),(0,i.jsx)(c.Route,{path:`/profile`,element:(0,i.jsx)(ih,{children:(0,i.jsx)(Ie,{})})}),(0,i.jsx)(c.Route,{path:`/billing`,element:(0,i.jsx)(ih,{children:(0,i.jsx)(Um,{})})}),(0,i.jsx)(c.Route,{path:`/dashboard`,element:(0,i.jsx)(ih,{children:(0,i.jsx)(th,{})})}),(0,i.jsx)(c.Route,{path:`/publish`,element:(0,i.jsx)(ah,{children:(0,i.jsx)($m,{})})}),(0,i.jsx)(c.Route,{path:`/setup`,element:(0,i.jsx)(Xu,{})}),(0,i.jsx)(c.Route,{path:`/setup/payments`,element:(0,i.jsx)(Wd,{})}),(0,i.jsx)(c.Route,{path:`*`,element:(0,i.jsx)(Pm,{})})]}),(0,i.jsx)(uh,{})]})})}function fh(){return(0,i.jsx)(c.BrowserRouter,{children:(0,i.jsx)(ph,{})})}function ph(){let e=t.Na();return e.firebaseConfig&&e.firebaseConfig.apiKey&&e.firebaseConfig.apiKey.trim()!==``&&e.firebaseConfig.projectId&&e.firebaseConfig.projectId.trim()!==``||Nu()?(0,i.jsx)(dh,{}):(0,i.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,i.jsx)(oe,{standalone:!0}),(0,i.jsx)(Xu,{standalone:!0}),(0,i.jsx)(uh,{})]})}function mh(e){v();let n=e.firebaseConfig;return n&&n.apiKey&&n.apiKey.trim()!==``&&n.projectId&&n.projectId.trim()!==``&&t.Oa(n),(0,i.jsx)(t.Ma,{config:{firebaseConfig:e.firebaseConfig,basename:e.basename,onAuthChange:e.onAuthChange,themeConfig:e.themeConfig,components:e.components,customRoutes:e.customRoutes,microcomponents:e.microcomponents,defaultConfigs:e.defaultConfigs},children:(0,i.jsx)(t.Aa,{children:(0,i.jsx)(`div`,{className:`firebase-os flex-1 flex flex-col min-h-screen`,style:{background:`var(--bg-gradient)`,color:`var(--fg-color)`},children:(0,i.jsx)(fh,{})})})})}var hh=Object.assign({}),gh={};for(let e in hh){let t=hh[e];if(!t?.default)continue;let n=e.replace(`./`,``).replace(`.tsx`,``);if(n===`registry`)continue;let r=n.replace(/Content$/,``).replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase();gh[r]=t.default,gh[r.replace(/_/g,``)]=t.default}if(typeof window<`u`){let e=window.__FBOS_MICROCOMPONENTS__||{};window.__FBOS_MICROCOMPONENTS__={...gh,...e}}var _h=(e,t)=>{let n=e.toLowerCase().replace(/[^a-z0-9]+/g,`_`),r=n.replace(/_/g,``);if(gh[n]=t,gh[r]=t,typeof window<`u`){let e=window.__FBOS_MICROCOMPONENTS__||{};window.__FBOS_MICROCOMPONENTS__={...e,[n]:t,[r]:t}}},vh=({title:e,className:n,children:r,...a})=>(0,i.jsxs)(`div`,{className:t.ur(`border border-[var(--panel-border)] bg-[var(--panel-bg)] px-5 py-4`,n),style:{borderRadius:`var(--card-radius, 1rem)`},...a,children:[e?(0,i.jsx)(`p`,{className:`text-[12px] font-extrabold tracking-tight text-gradient mb-1.5`,children:e}):null,r]});vh.displayName=`Card`;var yh=({sub:e,className:n,children:r,...a})=>(0,i.jsxs)(`div`,{className:t.ur(`mb-4`,n),children:[(0,i.jsx)(`h2`,{className:`text-xl md:text-2xl font-extrabold tracking-tight text-foreground`,...a,children:r}),e?(0,i.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed mt-1`,children:e}):null]});yh.displayName=`SectionHeading`,exports.AdminNotifications=O,exports.Button=t.cr,exports.Card=vh,exports.ConfirmModal=Ve,exports.ContactPopup=t.t,exports.CustomSelect=t.sr,exports.DashboardNav=Fe,exports.EventCard=Of,exports.FirebaseOS=mh,exports.Input=t.lr,exports.ManagePlanButton=Rm,exports.Navbar=oe,exports.PayButton=Xp,exports.PhoneInputField=n.t,exports.SectionHeading=yh,exports.TimeChips=t.q,exports.acceptBooking=t.n,Object.defineProperty(exports,`auth`,{enumerable:!0,get:function(){return t.Ea}}),exports.availableSlots=t.zt,exports.availableSlotsFor=t.Bt,exports.blockedWindows=t.Ut,exports.bookingPath=t.Qt,exports.cancelBooking=t.i,exports.confirmPayment=ee,exports.dayBlocked=t.rn,exports.daysLine=t.in,Object.defineProperty(exports,`db`,{enumerable:!0,get:function(){return t.Da}}),exports.emailAnyone=Za,exports.emailOwner=Ya,exports.emailPerson=Xa,exports.emailStatus=Qa,exports.eventName=t.cn,exports.hoursSummary=t._n,exports.meetPath=ro,exports.notify=S,exports.oneEach=t.En,exports.openBillingPortal=G,exports.partySlots=t.On,exports.payPath=t.kn,exports.registerMicrocomponent=_h,exports.scheduleName=t.Mn,exports.scheduleTitle=t.In,exports.slotsFor=t.Un,exports.startCheckout=U,Object.defineProperty(exports,`storage`,{enumerable:!0,get:function(){return t.ka}}),exports.timeZoneLabel=t.Kn,exports.togetherSlots=t.Xn,exports.useAuth=t.na,exports.useBookings=t.g,exports.useConfig=t.Na,exports.useMemberSchedules=t._,exports.useMyPayments=te,exports.usePaymentsEnabled=Y,exports.useSales=ne,exports.useTakenSlots=t.x,exports.useTeamHours=t.S,exports.useTheme=t.ja;
|
|
674
|
+
flex flex-col items-center justify-center leading-none gap-0.5 transition-colors duration-300 group-hover:bg-accent/[0.13] group-hover:border-accent/30`,children:[(0,i.jsx)(`span`,{className:`text-[17px] font-extrabold tracking-tight tabular-nums`,children:a.value}),(0,i.jsx)(`span`,{className:`text-[9.5px] font-bold uppercase tracking-[0.08em] opacity-70`,children:a.unit})]}),(0,i.jsxs)(`span`,{className:`relative flex-1 min-w-0 flex flex-col gap-1`,children:[(0,i.jsx)(`span`,{className:`text-[14.5px] sm:text-[15px] font-bold text-foreground tracking-tight leading-snug break-words`,children:t.In(e)}),(0,i.jsxs)(`span`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,i.jsx)(qp,{icon:t.Oi,children:t.Bn(e.slotMinutes)}),n&&(0,i.jsx)(qp,{accent:!0,children:Pp(n.amount)})]}),r&&(0,i.jsx)(`span`,{className:`text-[12.5px] font-medium text-foreground/55 leading-relaxed line-clamp-2 mt-0.5`,children:r})]}),(0,i.jsx)(`span`,{"aria-hidden":!0,className:`relative shrink-0 w-8 h-8 rounded-full border border-[var(--panel-border)]/70 flex items-center justify-center
|
|
675
|
+
text-foreground/35 transition-all duration-300 group-hover:border-accent/50 group-hover:bg-accent group-hover:text-[var(--button-fg,#fff)]`,children:(0,i.jsx)(t.Xi,{className:`w-4 h-4 transition-transform duration-300 group-hover:translate-x-[1px]`})})]})}function Yp({page:e}){let n=`w-24 h-24 sm:w-28 sm:h-28`;return(0,i.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,i.jsx)(`span`,{"aria-hidden":!0,className:`absolute -inset-3 rounded-[2rem] bg-accent/15 blur-2xl`}),e.photo?(0,i.jsx)(`img`,{src:e.photo,alt:``,className:`relative ${n} rounded-2xl object-cover border border-[var(--panel-border)] shadow-[0_10px_30px_rgba(0,0,0,0.12)]`}):(0,i.jsx)(`div`,{className:`relative ${n} ${Hp}`,children:(0,i.jsx)(t.Cr,{className:`w-9 h-9`})})]})}function Xp(){let{id:e=``}=(0,c.useParams)(),{activeConfig:n}=t.ja(),{loading:a,pages:o}=fo(),{loading:s,schedules:l}=t._(),u=o.find(t=>t.id===e)||null,d=(0,r.useMemo)(()=>u?so(u,l):[],[u,l]),f=Wp((0,r.useMemo)(()=>[...new Set(d.map(e=>e.paymentId).filter(Boolean))],[d]));if(a||s)return(0,i.jsx)(Gp,{children:(0,i.jsxs)(`div`,{className:`flex items-center justify-center gap-3 py-16 text-foreground/50`,children:[(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin text-accent`}),(0,i.jsx)(`span`,{className:`text-[13px] font-medium`,children:`Loading…`})]})});if(!u||!u.enabled)return(0,i.jsx)(Gp,{children:(0,i.jsx)(Kp,{icon:t.Hi,title:`This page is no longer open`,children:`It may have been taken down. Ask whoever sent it for a new link.`})});if(!d.length){let e=oo(u,l).length;return(0,i.jsx)(Gp,{children:(0,i.jsx)(Kp,{icon:t.Hi,title:uo(u),children:e?`Nothing here is taking bookings at the moment. Please check back later.`:`There is nothing to book here at the moment. Please check back later.`})})}let p=u.intro.trim();return(0,i.jsxs)(Gp,{children:[(0,i.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-4`,children:[(0,i.jsx)(Yp,{page:u}),(0,i.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 w-full min-w-0`,children:[n?.appName&&(0,i.jsx)(`span`,{className:`text-[10.5px] font-bold uppercase tracking-[0.18em] text-foreground/40 truncate max-w-full`,children:n.appName}),(0,i.jsx)(`h1`,{className:`text-[26px] sm:text-4xl font-extrabold tracking-tight text-gradient leading-[1.1] break-words`,children:uo(u)}),p&&(0,i.jsx)(`p`,{className:`mt-1.5 max-w-md text-[13.5px] sm:text-[14.5px] text-foreground/60 font-medium leading-relaxed whitespace-pre-line`,children:p})]})]}),(0,i.jsx)(`div`,{className:`h-px bg-[var(--panel-border)]/60 my-5 sm:my-7`}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-1`,children:[(0,i.jsx)(`p`,{className:`text-[11px] font-bold uppercase tracking-[0.16em] text-foreground/40`,children:d.length===1?`Book a time`:`Pick what to book`}),d.length>1&&(0,i.jsxs)(`span`,{className:`text-[11px] font-semibold text-foreground/35 tabular-nums`,children:[d.length,` meetings`]})]}),d.map(e=>(0,i.jsx)(Jp,{schedule:e,price:Np(f.get(e.paymentId)||null)},e.id))]})]})}function Zp({children:e,className:n,variant:a=`primary`,pendingLabel:o=`Opening checkout…`,...s}){let{loading:c,configured:l}=Y(),{userRole:u}=t.na(),[d,f]=(0,r.useState)(!1),[p,m]=(0,r.useState)(null);return c?null:l?(0,i.jsxs)(`span`,{className:`inline-flex flex-col items-stretch gap-2`,children:[(0,i.jsx)(t.cr,{variant:a,className:n,onClick:async()=>{if(d)return;f(!0),m(null);let e=await U(s);e&&(m(e),f(!1))},disabled:d,children:d?o:e??`Pay`}),p&&(0,i.jsx)(`span`,{role:`alert`,className:`text-[13px] font-semibold text-red-400 leading-snug`,children:p})]}):t.pa(u)?(0,i.jsx)(`span`,{className:`text-[12.5px] font-medium text-foreground/50 leading-snug`,children:`Only admins see this: payments are not on yet, so this button is hidden. Connect Stripe and switch payments on at /payments and it appears here.`}):null}function Qp(){let{id:e=``}=(0,c.useParams)(),{activeConfig:n}=t.ja(),a=Y(),[s,l]=(0,r.useState)({loading:!0,product:null});(0,r.useEffect)(()=>{let n=!1;return(0,o.getDoc)((0,o.doc)(t.Da,ji,e)).then(e=>{n||l({loading:!1,product:e.exists()?Ui(e.id,e.data()):null})}).catch(()=>{n||l({loading:!1,product:null})}),()=>{n=!0}},[e]);let u=s.product,d=u?.customPath.trim()||``;if(d)return(0,i.jsx)(c.Navigate,{to:d.startsWith(`/`)?d:`/${d}`,replace:!0});let f=u?Li(u).filter(e=>Ri(e.amount)):[],p=u?.name.trim()||f[0]?.name.trim()||`Pay`;return(0,i.jsx)(`main`,{className:`flex-1 w-full max-w-3xl mx-auto px-4 pt-2 pb-16 md:pt-4 z-10 flex flex-col`,children:(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.4},className:`w-full rounded-3xl glass-panel border border-[var(--panel-border)] p-5 sm:p-8 md:p-10 shadow-[0_8px_32px_rgba(0,0,0,0.08)]`,children:s.loading?(0,i.jsxs)(`div`,{className:`flex items-center justify-center gap-3 py-16 text-foreground/50`,children:[(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin text-accent`}),(0,i.jsx)(`span`,{className:`text-[13px] font-medium`,children:`Loading…`})]}):!u||u.kind!==`once`||!f.length?(0,i.jsxs)(`div`,{className:`flex flex-col items-center text-center py-8 gap-4`,children:[(0,i.jsx)(`div`,{className:`w-14 h-14 rounded-2xl glass-panel border border-[var(--panel-border)] flex items-center justify-center shadow-xl`,children:(0,i.jsx)(t.Pr,{className:`w-7 h-7 text-accent`})}),(0,i.jsx)(`h1`,{className:`text-2xl md:text-3xl font-extrabold text-foreground tracking-tight`,children:`This payment link is no longer open`}),(0,i.jsx)(`p`,{className:`text-[14px] text-foreground/60 max-w-md`,children:`Ask whoever sent it for a new one.`}),(0,i.jsx)(c.Link,{to:`/`,className:`text-[13px] font-bold text-accent hover:underline mt-2`,children:`Back to the site`})]}):(0,i.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[n?.appName&&(0,i.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-[0.2em] text-foreground/40`,children:n.appName}),(0,i.jsx)(`h1`,{className:`text-2xl sm:text-3xl md:text-4xl font-extrabold text-foreground tracking-tight`,children:p}),u.description.trim()&&(0,i.jsx)(`p`,{className:`text-[14px] md:text-[15px] text-foreground/60 leading-relaxed mt-1 max-w-2xl whitespace-pre-line`,children:u.description.trim()})]}),!a.loading&&!a.configured&&(0,i.jsx)(`p`,{className:`text-[14px] font-medium text-foreground/60`,children:`Payments are not open right now — please try again later.`}),(0,i.jsx)(`div`,{className:`flex flex-col divide-y divide-[var(--panel-border)]/60 rounded-2xl border border-[var(--panel-border)]/60`,children:f.map((e,n)=>(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3.5`,children:[(0,i.jsxs)(`div`,{className:`min-w-0 flex flex-col`,children:[(0,i.jsx)(`span`,{className:`text-[15px] font-semibold text-foreground truncate`,children:e.name.trim()||p}),(0,i.jsx)(`span`,{className:`text-[13px] font-medium text-foreground/50`,children:Pp(Ri(e.amount)||0)})]}),(0,i.jsxs)(Zp,{amount:Ri(e.amount)||0,productName:e.name.trim()||p,metadata:{productId:u.id,page:t.kn(u.id),emailReceipt:u.emailReceipt?`yes`:`no`,notifyOwner:u.notifyOwner?`yes`:`no`},successPath:`/payment-complete`,cancelPath:t.kn(u.id),className:`px-5 py-2.5 text-[14px] font-bold`,children:[`Pay `,Pp(Ri(e.amount)||0)]})]},n))})]})})})}function $p({trailing:e,onSent:n}){let[a,o]=(0,r.useState)(`idle`),[s,c]=(0,r.useState)(``);return(0,i.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2.5 flex-wrap`,children:[(0,i.jsx)(t.Q,{compact:!0,icon:t.qi,busy:a===`sending`,onClick:async()=>{o(`sending`),c(``);try{let e=await fetch(`/api/_selftest/email`),t=await e.json().catch(()=>({}));e.ok&&t?.ok?(o(`sent`),n?.(typeof t.from==`string`&&t.from.trim()?t.from:null)):(o(`failed`),c(String(t?.error||t?.message||`The server answered ${e.status}.`)))}catch{o(`failed`),c(`The server could not be reached.`)}},title:`Sends the test email to your own admin address`,children:`Send yourself a test email`}),e]}),a===`sent`&&(0,i.jsx)(`p`,{className:`text-[12px] font-semibold text-emerald-500 px-1`,children:`Sent. If you do not receive it within a minute, check your spam.`}),a===`failed`&&(0,i.jsxs)(`p`,{className:`text-[12px] font-medium text-red-500 px-1 leading-relaxed`,children:[`It did not send: `,s,` If the sending address uses your own domain, that domain must be verified under `,(0,i.jsx)(`strong`,{children:`Domains`}),` in your Resend account — an unverified domain makes every send fail.`]})]})}var{collection:em,doc:tm}=Qu.email,nm=(e,t)=>{let n=String(e||``).trim().toLowerCase(),r=String(t||``).trim().toLowerCase();return!!n&&n===r};function rm(){let[e,n]=(0,r.useState)({loading:!0,testedFrom:null});return(0,r.useEffect)(()=>(0,o.onSnapshot)((0,o.doc)(t.Da,em,tm),e=>{let t=e.exists()?e.data()?.testedFrom:null;n({loading:!1,testedFrom:typeof t==`string`&&t.trim()?t:null})},()=>n({loading:!1,testedFrom:null})),[]),{loading:e.loading,testedFrom:e.testedFrom,mark:async e=>{if(e.trim()){n({loading:!1,testedFrom:e});try{await(0,o.setDoc)((0,o.doc)(t.Da,em,tm),{testedFrom:e},{merge:!0})}catch(e){console.error(`Could not remember the test send`,e)}}}}}var im=e=>[{title:`Hear about what happens`,body:`A booking, a form entry, a new member — at your address the moment it happens.`,icon:t.Ki,where:{path:`/pages`,label:`Pages screen`}},{title:`Confirm to the people who write in`,body:`Whoever books or writes gets a note that it arrived, in your words.`,icon:t.Qr,where:{path:`/pages`,label:`Pages screen`}},{title:`Receipts and sale alerts`,body:`Every payment emails the buyer a receipt and tells you something sold.`,icon:t.Vr,where:{path:`/payments`,label:`Payments screen`}},{title:`Write to anyone from your app`,body:`A page for your team can write to any address, from ${e}.`,icon:t.Ir,where:{path:`/pages`,label:`Pages screen`}}],am=e=>String(e||``).toLowerCase().endsWith(`@resend.dev`),om=e=>String(e||``).split(`@`)[1]||``,sm=e=>e?{description:`Every page you told to send email does. Switch it off to stop all of it at once.`,chip:{state:`saved`,label:`On`}}:{description:`Nothing sends. Your pages keep their settings and wait for this to come back on.`,chip:{state:`off`,label:`Off`}};function cm({from:e}){return(0,i.jsx)(`div`,{className:`flex flex-col divide-y divide-[var(--panel-border)]/60 rounded-2xl border border-[var(--panel-border)]/60`,children:im(e).map(e=>{let n=e.icon;return(0,i.jsxs)(`div`,{className:`grid grid-cols-[auto_minmax(0,1fr)] sm:grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-3 sm:gap-x-3.5 gap-y-0.5 px-4 py-3`,children:[(0,i.jsx)(`div`,{className:`row-start-1 row-span-2 col-start-1 self-center w-9 h-9 rounded-xl flex items-center justify-center shrink-0 border border-[var(--panel-border)]/50 bg-accent/10 text-accent`,children:(0,i.jsx)(n,{className:`w-4 h-4`})}),(0,i.jsx)(`span`,{className:`row-start-1 col-start-2 min-w-0 text-[13px] font-bold text-foreground leading-tight self-end`,children:e.title}),(0,i.jsx)(`span`,{className:`row-start-2 col-start-2 min-w-0 text-[12px] text-foreground/50 font-normal leading-snug self-start`,children:e.body}),(0,i.jsxs)(c.Link,{to:e.where.path,className:`max-sm:hidden sm:inline-flex row-start-1 row-span-2 col-start-3 self-center justify-self-end items-center gap-1.5 text-[11.5px] font-semibold text-foreground/45 hover:text-accent whitespace-nowrap transition-colors`,children:[e.where.label,(0,i.jsx)(t.Xi,{className:`w-3 h-3`})]})]},e.title)})})}function lm({adminCount:e,onSetUp:n}){return(0,i.jsxs)(`div`,{className:`flex items-center gap-2.5 px-1 flex-wrap`,children:[(0,i.jsx)(t.lt,{state:e?`saved`:`off`,label:e?`Your mail reaches ${e} address${e===1?``:`es`}`:`No address for your mail`}),!e&&(0,i.jsxs)(`span`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:[`Sale, booking and form alerts have nowhere to go —`,` `,(0,i.jsx)(t.rt,{onClick:n,children:`add ADMIN_EMAILS`}),`.`]})]})}function um(){let{status:e,error:n,reread:a}=sd(),o=ed(`email`),[s,c]=(0,r.useState)(``),l=rm(),[u,d]=(0,r.useState)(!1),[f,p]=(0,r.useState)(!1),m=()=>{d(!1),a().then(()=>p(!0))},h=!!(e&&!e.configured),g=am(e?.from),_=sm(o.on),v=!l.loading&&nm(l.testedFrom,e?.from);return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,i.jsx)(Ce,{children:`Email`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/email`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-5 md:p-8 shadow-2xl relative bg-background flex flex-col min-h-[600px]`,children:!e&&!n?(0,i.jsx)(`div`,{className:`flex items-center justify-center flex-1 text-foreground/40 py-16`,children:(0,i.jsx)(t.ti,{className:`w-6 h-6 animate-spin text-accent`})}):h?(0,i.jsx)(Hd,{icon:t.Zr,title:`Connect email`,description:`This app is not sending email yet.`,stepsDescription:`Three steps — a key, two secrets, and the domain your mail goes out as.`,button:`Set up email`,secret:`RESEND_API_KEY`,open:u,onOpen:()=>d(!0),confirmed:f,steps:(0,i.jsx)(Wd,{onConfirm:m}),children:(0,i.jsx)(t.st,{children:`Email runs through Resend, and connecting it is two pasted rows — a key, and your own address for the mail that is meant for you. Once they are in, this screen fills itself: what your app can do with email, and where it goes.`})}):(0,i.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,i.jsx)(t.ut,{icon:t.Hr,title:`Send email`,description:_.description,chip:_.chip,enabled:o.loading?null:o.on,onChange:async e=>c(await o.set(e)||``),children:s?(0,i.jsx)(t.st,{tone:`error`,children:s}):null}),(0,i.jsx)(t.at,{icon:t.Qr,title:`Connection`,description:v&&!n?`Mail goes out as ${e?.from}.`:`Whether this app can send email right now.`,defaultOpen:!v||!e?.adminCount,actions:n?(0,i.jsx)(t.lt,{state:`error`,label:`Unreachable`}):(0,i.jsx)(t.lt,{state:`saved`,label:`Connected`}),children:n?(0,i.jsx)(t.st,{tone:`error`,children:n}):(0,i.jsxs)(i.Fragment,{children:[!v&&(0,i.jsxs)(t.st,{children:[`Mail goes out as `,(0,i.jsx)(`span`,{className:`font-bold text-foreground/70`,children:e?.from}),`.`,g?` That is Resend’s shared practice address: it delivers only to the address you made your Resend account with, so a test to yourself works and a customer’s email does not arrive. Before anyone else should get one, verify your own domain in Resend and add EMAIL_FROM — `:` That only works if ${om(e?.from)} is verified under Domains in your Resend account — an unverified domain makes every send fail. Every send also appears in your Resend dashboard, with nothing to sync.`,g&&(0,i.jsx)(t.rt,{onClick:()=>d(!0),children:`show me how`}),g&&`.`]}),(0,i.jsx)(lm,{adminCount:e?.adminCount||0,onSetUp:()=>d(!0)}),u&&(0,i.jsx)(`div`,{className:`px-1 pt-1`,children:(0,i.jsx)(Wd,{onConfirm:m})}),!v&&(0,i.jsx)(`div`,{className:`px-1`,children:(0,i.jsx)($p,{onSent:t=>l.mark(t||e?.from||``),trailing:(0,i.jsxs)(`a`,{href:`https://resend.com/emails`,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1.5 text-[12px] font-bold text-accent hover:underline`,children:[`See everything sent, in Resend`,(0,i.jsx)(t.bi,{className:`w-3 h-3`})]})})})]})}),(0,i.jsx)(t.at,{icon:t.Nr,title:`What you can do with email`,description:`Each is switched on where it happens — a page on the Pages screen, a payment on the Payments screen.`,children:(0,i.jsx)(cm,{from:e?.from||``})})]})})]})]})}var dm=`src/your-ai-workflow-firebase-os`;function fm(){let e=new Set;for(let[t,n]of b()){let r=n?.config?.route,i=typeof r==`string`&&r.trim()?r.startsWith(`/`)?r:`/`+r:`/`+t.toLowerCase();e.add(i)}return[...e].sort()}var pm=e=>(e||``).split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``);function mm(e){let t=e?.contentKey||e?.tabName||e?.pageName||e?.pageId||`Page`;return`${dm}/microcomponents/${pm(String(t))||`Page`}Content.tsx`}function hm(e,t){let n=t.replace(/^.*\//,``).replace(/\.tsx$/,``),r=n.replace(/Content$/,``).replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase();return[`My app has a page at ${e} and it is still empty after you said it was done. The ONLY thing that fills this page is one file: ${t}, with a default export, registered in ${dm}/microcomponents/registry.ts.`,`Check these in order and fix whatever is wrong, without asking me questions:`,`1. The file exists at exactly that path and name — not another folder, not another spelling. If you put it somewhere else, move it there.`,`2. It has a default export. A named-only export is silently ignored.`,`3. ${dm}/microcomponents/registry.ts contains these two lines: import ${n} from './${n}'; and registerMicrocomponent('${r}', ${n}); — registerMicrocomponent is imported there from 'your-ai-workflow-firebase-os'. Add them if they are missing, and never remove another page's lines.`,`4. You created nothing else for this page — no config file, no route, no page, and no edit to src/App.tsx or src/main.tsx. Undo any of those you made.`,`Then tell me, in one sentence, which of these was wrong.`].join(`
|
|
676
|
+
`)}function gm(e){return[`The page at ${e} shows "Page Not Found". The app only finds a page when its config file is picked up, so check these in order and fix whatever is wrong, without asking me questions.`,`1. The page's config file sits directly in ${dm}/configs/ and its name ends with Tab.config.ts (a page for signed-in users, my team or admins) or Page.config.ts (a page for anyone). Not in a subfolder, not any other name.`,`2. It exports one const whose name ends with Config, and its route is the single string '${e}'. A page has exactly one web address — remove any other addresses you registered for it.`,`3. ${dm}/configs/pagesRegistry.ts exists and src/main.tsx contains the line import './your-ai-workflow-firebase-os/configs/pagesRegistry'. If either is missing, run npm install so the package's postinstall script restores them.`,`4. Put src/App.tsx back to the version the package wrote: it only mounts <FirebaseOS />. Never add routes, a router or the customRoutes prop.`,`5. If the page is for my team, its config says pageType: 'internal'. Any form on it is a *Form.config.ts file shown through <ContactPopup formId="..." />, never a form you wrote by hand.`,`Then rebuild and tell me, in one sentence, which of these was wrong.`].join(`
|
|
677
|
+
`)}function _m({config:e,customContent:n}){let{config:a}=t.ja(),{userRole:o}=t.na();return(0,r.useEffect)(()=>{document.title=e.pageName||e.pageTitle||a.appName||`Your AI Firebase`},[e.pageName,e.pageTitle,a.appName]),(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col relative min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-4 md:mb-6 flex items-center gap-3`,children:[(0,i.jsx)(Wt,{}),(0,i.jsxs)(`div`,{className:`min-w-0`,children:[(0,i.jsx)(Ce,{children:e.pageTitle||e.pageName||`New Page`}),e.route&&(0,i.jsxs)(`div`,{className:`max-sm:hidden sm:flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})]}),(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`glass-panel border border-[var(--panel-border)] rounded-3xl shadow-2xl relative flex flex-col flex-1 bg-background/50 h-full min-h-[400px]`,children:n?(0,i.jsx)(`div`,{className:`fbos-content-slot flex-1 p-4 md:p-8`,children:(0,i.jsx)(n,{config:e})}):e.form?(0,i.jsx)(`div`,{className:`fbos-content-slot flex-1 flex flex-col items-center justify-start p-4 md:p-8`,children:(0,i.jsx)(t.t,{isInline:!0,formId:e.form})}):(0,i.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center m-4 md:m-8 gap-6`,children:[(0,i.jsxs)(`div`,{className:`w-full glass-panel border border-[var(--panel-border)]/50 border-dashed rounded-2xl p-8 py-16 text-center opacity-70`,children:[(0,i.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/70`,children:`This page is empty`}),(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 max-w-sm leading-relaxed mx-auto`,children:`Open the Pages screen, say what you would like on it, and copy the sentence there into your assistant's chat.`})]}),t.pa(o)&&(0,i.jsx)(`div`,{className:`w-full max-w-lg`,children:(0,i.jsx)(it,{compact:!0,title:`Already asked, and it is still empty? Paste this`,prompt:hm(e.route||`/`,mm(e))})})]})})]})}function vm({config:e,customContent:n}){let{user:a}=t.na(),{config:c}=t.ja(),[u,d]=(0,r.useState)([]),[f,p]=(0,r.useState)(!0),[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(``),[v,y]=(0,r.useState)(``),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(null),w=(0,r.useRef)(null),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(null),[k,A]=(0,r.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;P(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[N,P]=(0,r.useState)(!0),[F,I]=(0,r.useState)(!1),[L,R]=(0,r.useState)(null),[z,B]=(0,r.useState)(``),[V,H]=(0,r.useState)(``),[U,W]=(0,r.useState)([]),G=(0,r.useRef)(null),ee=(e.tabName||e.pageId||`user_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`),K=t.va({...e,pageType:`user`}),q=`${K}${ee}_records`,J=K.startsWith(`role_`);(0,r.useEffect)(()=>{document.title=e.tabTitle||e.tabName||c.appName||`Your AI Firebase`},[e.tabTitle,e.tabName,c.appName]),(0,r.useEffect)(()=>{if(!a)return;try{let e=Wa(q,a.uid);e?(d(e),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}}),n=(0,o.onSnapshot)(J?(0,o.query)((0,o.collection)(t.Da,q),(0,o.limit)(150)):(0,o.query)((0,o.collection)(t.Da,q),(0,o.where)(`uid`,`==`,a.uid),(0,o.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),d(n),p(!1),Ga(q,a.uid,n)},e=>{console.warn(`${q}: this account cannot read its records here (${e?.code||`permission-denied`}). Signed-in pages need a verified email address; the records themselves are only ever the signer's own.`),d(e=>e.length?[]:e),p(!1)});return()=>n()},[a,q,J]),(0,r.useEffect)(()=>{!f&&a&&Ga(q,a.uid,u)},[u,f,q,a]);let Y=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=await(0,o.addDoc)((0,o.collection)(t.Da,q),{name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,createdAt:(0,o.serverTimestamp)()});d(t=>[{id:e.id,name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,createdAt:Date.now()},...t]),_(``),y(``),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)}},te=async e=>{let n=e.target.files?.[0];if(!n||!a)return;let r=await t.or(n);E(!0);try{let e=`user_files/${`${Date.now()}_${r.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,n=(0,s.ref)(t.ka,e);await(0,s.uploadBytes)(n,r,{customMetadata:{ownerId:a.uid}});let i=await(0,s.getDownloadURL)(n);if(w.current)w.current(r,i,{uid:a.uid,storagePath:e});else{let e=await(0,o.addDoc)((0,o.collection)(t.Da,q),{name:r.name,note:`${r.type||`File`} · ${ge(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type||`unknown`,fileSize:r.size,downloadURL:i,createdAt:(0,o.serverTimestamp)()});d(t=>[{id:e.id,name:r.name,note:`${r.type||`File`} · ${ge(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type,fileSize:r.size,downloadURL:i,createdAt:Date.now()},...t])}}catch(e){console.error(`Error uploading file:`,e)}E(!1),G.current&&(G.current.value=``)},ne=async()=>{if(D){I(!0);try{let e=u.find(e=>e.id===D);if(await(0,o.deleteDoc)((0,o.doc)(t.Da,q,D)),e?.recordType===`file`&&e.downloadURL)try{let n=e.downloadURL.split(`user_files%2F`)[1]?.split(`?`)[0];n&&await(0,s.deleteObject)((0,s.ref)(t.ka,`user_files/${decodeURIComponent(n)}`)).catch(()=>{})}catch(e){console.error(`Error cleaning up user file:`,e)}d(e=>e.filter(e=>e.id!==D)),O(null)}catch(e){console.error(`Error deleting record:`,e)}I(!1)}},[re,X]=(0,r.useState)(null),[Z,Q]=(0,r.useState)(``),[ie,ae]=(0,r.useState)(!1),[oe,se]=(0,r.useState)(null),ce=(0,r.useRef)([]),le=e=>{if(e.recordType===`file`){X(e.id),Q(e.name);return}R(e.id),B(e.name),H(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??``)}));W(n),ce.current=n.map(e=>e.key)},ue=async()=>{if(!re||!Z.trim()){X(null);return}let e=u.find(e=>e.id===re);if(e&&e.name===Z.trim()){X(null);return}ae(!0);try{await(0,o.updateDoc)((0,o.doc)(t.Da,q,re),{name:Z.trim()}),d(e=>e.map(e=>e.id===re?{...e,name:Z.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}ae(!1),X(null)},de=async()=>{await fe(),R(null)},fe=async()=>{if(!L||!z.trim())return;x(!0);let e={};U.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=U.map(e=>e.key.trim()).filter(Boolean),r=ce.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(t.Da,q,L),{name:z.trim(),note:V.trim(),...e}),d(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]}),U.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),ce.current=n}catch(e){console.error(`Error saving record:`,e)}x(!1)},pe=(e,n)=>e?e.startsWith(`image/`)?n?(0,i.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${n})`}}):(0,i.jsx)(t.fi,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,i.jsx)(t.br,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,i.jsx)(t.gi,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,i.jsx)(t.ea,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,i.jsx)(t.Ei,{className:`w-4 h-4`}):(0,i.jsx)(t.hi,{className:`w-4 h-4`}):(0,i.jsx)(t.gi,{className:`w-4 h-4`}),me=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-accent/10 text-accent`:e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?`bg-blue-500/10 text-blue-500`:e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?`bg-yellow-500/10 text-yellow-500`:e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?`bg-emerald-500/10 text-emerald-500`:`bg-foreground/5 text-foreground/40`:`bg-foreground/5 text-foreground/40`,he=e=>{if(!e)return`FILE`;let t={"application/pdf":`PDF`,"application/zip":`ZIP`,"application/x-zip-compressed":`ZIP`,"application/x-rar-compressed":`RAR`,"application/x-7z-compressed":`7Z`,"application/json":`JSON`,"application/xml":`XML`,"application/javascript":`JS`,"application/typescript":`TS`,"application/msword":`DOC`,"application/vnd.openxmlformats-officedocument.wordprocessingml.document":`DOCX`,"application/vnd.ms-excel":`XLS`,"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":`XLSX`,"application/vnd.ms-powerpoint":`PPT`,"application/vnd.openxmlformats-officedocument.presentationml.presentation":`PPTX`,"application/rtf":`RTF`,"application/x-tar":`TAR`,"application/gzip":`GZ`,"text/plain":`TXT`,"text/html":`HTML`,"text/css":`CSS`,"text/csv":`CSV`,"text/markdown":`MD`},n=e.toLowerCase();if(t[n])return t[n];let r=n.split(`/`);return r[r.length-1].replace(/^x-/,``).replace(/^vnd\..*\./,``).toUpperCase().slice(0,10)},ge=e=>{if(!e)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**+r).toFixed(2))+` `+n[r]},_e=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},ve=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.mr[r]?t.mr[r]:t.mr[n]?t.mr[n]:t.wr||t.Ur})(),ye=e.buttonStyle!==`secondary`,be=e.buttonStorageStyle===`primary`;return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,i.jsxs)(`div`,{children:[(0,i.jsx)(Ce,{children:e.tabTitle||e.tabName||`User Page`}),e.route&&(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsxs)(t.fr.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,i.jsx)(`input`,{type:`file`,ref:G,onChange:te,className:`hidden`}),!n&&(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm:p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,i.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,i.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${u.length} ${u.length===1?`item`:`items`}`})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.storage!==!1&&(0,i.jsx)(i.Fragment,{children:(0,i.jsxs)(t.fr.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>G.current?.click(),disabled:T,title:e.buttonStorageText||`Upload File`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed ${e.buttonStorageText?`px-4`:`w-10`} ${be?`btn-primary`:`btn-secondary`}`,children:[T?(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin`}):(0,i.jsx)(ve,{className:`w-4 h-4`}),e.buttonStorageText&&(0,i.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})}),e.showButton!==!1&&(0,i.jsx)(t.fr.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>h(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${ye?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,i.jsx)(t.Ur,{className:`w-4 h-4`}):(0,i.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,i.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,i.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,i.jsx)(t.ti,{className:`w-8 h-8 text-accent animate-spin`})}),n?(0,i.jsx)(`div`,{className:`fbos-content-slot`,children:(0,i.jsx)(n,{config:e,actions:{records:u,loading:f,collection:q,user:a,saveRecord:async e=>{let n=(0,o.doc)((0,o.collection)(t.Da,q)),r={id:n.id,uid:a.uid,recordType:`record`,createdAt:Date.now(),...e};d(e=>[r,...e]),await(0,o.setDoc)(n,{uid:a.uid,recordType:`record`,createdAt:(0,o.serverTimestamp)(),...e})},updateRecord:async(e,n)=>{d(t=>t.map(t=>t.id===e?{...t,...n}:t)),await(0,o.updateDoc)((0,o.doc)(t.Da,q,e),n)},deleteRecord:async e=>{await(0,o.deleteDoc)((0,o.doc)(t.Da,q,e))},startEdit:e=>le(e),confirmDelete:e=>O(e),uploadFile:()=>G.current?.click(),openAddForm:()=>h(!0),setAddForm:e=>C(()=>e),setFileHandler:e=>{w.current=e}}})}):(0,i.jsxs)(i.Fragment,{children:[!f&&u.length===0&&(0,i.jsxs)(t.fr.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,i.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,i.jsx)(t.Ur,{className:`w-6 h-6 text-accent/40`})}),(0,i.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files to get started`})]}),!f&&u.length>0&&(0,i.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,i.jsx)(t.pr,{children:u.map((e,n)=>{let r=L===e.id;return(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},transition:{delay:n*.03,duration:.25},onClick:()=>le(e),className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative cursor-pointer ${r?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,i.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`button`,{onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e.downloadURL),se(e.id),setTimeout(()=>se(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,i.jsx)(t.zi,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,i.jsx)(t.ri,{className:`w-3.5 h-3.5`})}),(0,i.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,i.jsx)(t.Si,{className:`w-3.5 h-3.5`})})]}),(0,i.jsx)(`button`,{onClick:t=>{t.stopPropagation(),le(e)},className:`p-1.5 rounded-lg text-foreground/25 hover:text-accent hover:bg-accent/10 transition-all cursor-pointer`,title:`Edit`,children:(0,i.jsx)(t.Kr,{className:`w-3.5 h-3.5`})}),(0,i.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,i.jsx)(t.Or,{className:`w-3.5 h-3.5`})})]}),(0,i.jsxs)(`div`,{className:`flex items-start gap-3 mb-3`,children:[(0,i.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 ${me(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?pe(e.fileType,e.downloadURL):(0,i.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,i.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[re===e.id?(0,i.jsx)(`input`,{autoFocus:!0,type:`text`,value:Z,onChange:e=>Q(e.target.value),onBlur:()=>ue(),onKeyDown:e=>{e.key===`Enter`&&ue(),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,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,i.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>j(e)}),(0,i.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:_e(e.createdAt)})]})]}),e.note&&(0,i.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,i.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,i.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,i.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e))]},e.id)})})})]})]})]})]}),(0,i.jsx)(t.pr,{children:m&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>!b&&h(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,i.jsx)(t.fr.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:S?r.default.createElement(S,{onSave:async e=>{x(!0);try{await(0,o.addDoc)((0,o.collection)(t.Da,q),{uid:a.uid,recordType:`record`,createdAt:(0,o.serverTimestamp)(),...e}),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)},onClose:()=>!b&&h(!1),saving:b}):(0,i.jsxs)(`form`,{onSubmit:Y,className:`p-5 flex flex-col gap-3`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>!b&&h(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,i.jsx)(t._r,{className:`w-4 h-4`})})]}),(0,i.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:g,onChange:e=>_(e.target.value),placeholder:`Name *`,disabled:b,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),placeholder:`Note (optional)`,disabled:b,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,i.jsx)(t.cr,{type:`submit`,isLoading:b,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:b?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,l.createPortal)((0,i.jsx)(t.pr,{children:M&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,i.jsx)(t.fr.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,i.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,i.jsx)(t._r,{className:`w-5 h-5`})}),(0,i.jsxs)(t.fr.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,i.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,i.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,i.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:M.fileName||M.name}),(0,i.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[he(M.fileType),` • `,ge(M.fileSize||0)]})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,i.jsx)(`button`,{onClick:()=>{navigator.clipboard.writeText(M.downloadURL),se(`preview`),setTimeout(()=>se(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,i.jsx)(t.zi,{className:`w-4 h-4 text-emerald-500`}):(0,i.jsx)(t.ri,{className:`w-4 h-4`})}),(0,i.jsx)(`button`,{onClick:()=>{j(null),X(M.id),Q(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,i.jsx)(t.Kr,{className:`w-4 h-4`})}),(0,i.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,i.jsx)(t.Or,{className:`w-4 h-4`})}),(0,i.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,i.jsx)(t.Si,{className:`w-4 h-4`})})]})]}),(0,i.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>j(null),children:(0,i.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,i.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,i.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,i.jsx)(t.ti,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,i.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,i.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,i.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,i.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,i.jsx)(t.gi,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,i.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,i.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,i.jsx)(t.pr,{children:L&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>de(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,i.jsx)(t.fr.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,i.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),b&&(0,i.jsx)(t.ti,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>de(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,i.jsx)(t._r,{className:`w-4 h-4`})})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.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,i.jsx)(`input`,{autoFocus:!0,required:!0,value:z,onChange:e=>B(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>fe(),placeholder:`Name *`,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50`}),(0,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.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,i.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{H(e.target.value),e.target.style.height=`auto`,e.target.style.height=e.target.scrollHeight+`px`},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),e.target.blur())},onBlur:()=>fe(),placeholder:`Add a note...`,rows:1,className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pb-1 caret-foreground/50 resize-none overflow-hidden`}),(0,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),U.map((e,n)=>(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let t=[...U];t[n].key=e.target.value,W(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>fe(),className:`no-glow bg-transparent text-[10px] font-bold text-foreground/30 uppercase tracking-[0.15em] outline-none placeholder:text-foreground/15 pt-3 pb-0.5 caret-foreground/40`}),(0,i.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let t=[...U];t[n].value=e.target.value,W(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>fe(),className:`no-glow bg-transparent text-[13px] font-medium text-foreground outline-none placeholder:text-foreground/15 pt-1.5 pb-1 caret-foreground/50`}),(0,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>W(U.filter((e,t)=>t!==n)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,i.jsx)(t._r,{className:`w-3 h-3`})})]},n)),(0,i.jsxs)(`button`,{type:`button`,onClick:()=>W([...U,{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,i.jsx)(t.Ur,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,i.jsx)(Ve,{isOpen:!!D,onCancel:()=>O(null),onConfirm:ne,title:`Delete Record`,message:(0,i.jsxs)(i.Fragment,{children:[`Are you sure you want to delete `,(0,i.jsx)(`strong`,{className:`text-foreground font-extrabold break-words mx-1`,children:u.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:F})]})}function ym({config:e,customContent:n}){let{user:a}=t.na(),{config:c}=t.ja(),[u,d]=(0,r.useState)([]),[f,p]=(0,r.useState)(!0),[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(``),[v,y]=(0,r.useState)(``),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(null),w=(0,r.useRef)(null),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(null),[k,A]=(0,r.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;P(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[N,P]=(0,r.useState)(!0),[F,I]=(0,r.useState)(!1),[L,R]=(0,r.useState)(null),[z,B]=(0,r.useState)(``),[V,H]=(0,r.useState)(``),[U,W]=(0,r.useState)([]),G=(0,r.useRef)(null),[ee,K]=(0,r.useState)(null),q=(0,r.useRef)([]),J=`admin_${(e.tabName||e.pageId||`admin_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`)}_records`;(0,r.useEffect)(()=>{document.title=e.tabTitle||e.tabName||c.appName||`Your AI Firebase`},[e.tabTitle,e.tabName,c.appName]);let Y=()=>({name:a.displayName||a.email?.split(`@`)[0]||`Admin`,email:a.email||``,avatar:a.photoURL||``});(0,r.useEffect)(()=>{if(!a)return;try{let e=Wa(J,a.uid);e?(d(e),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}}),n=(0,o.onSnapshot)((0,o.query)((0,o.collection)(t.Da,J),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(150)),t=>{let n=e(t.docs);d(n),p(!1),Ga(J,a.uid,n)},n=>{console.error(`Error listening to admin records:`,n);let r=(0,o.onSnapshot)((0,o.query)((0,o.collection)(t.Da,J),(0,o.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),d(n),p(!1),Ga(J,a.uid,n)});return()=>r()});return()=>n()},[a,J]);let te=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=Y();await(0,o.addDoc)((0,o.collection)(t.Da,J),{name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()}),_(``),y(``),h(!1)}catch(e){console.error(`Error saving admin record:`,e)}x(!1)}},ne=async e=>{let n=e.target.files?.[0];if(!n||!a)return;let r=await t.or(n);E(!0);try{let e=`admin_files/${`${Date.now()}_${r.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,n=(0,s.ref)(t.ka,e);await(0,s.uploadBytes)(n,r,{customMetadata:{ownerId:a.uid}});let i=await(0,s.getDownloadURL)(n);if(w.current)w.current(r,i,{uid:a.uid,storagePath:e});else{let e=Y();await(0,o.addDoc)((0,o.collection)(t.Da,J),{name:r.name,note:`${r.type||`File`} · ${me(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type||`unknown`,fileSize:r.size,downloadURL:i,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()})}}catch(e){console.error(`Error uploading admin file:`,e)}E(!1),G.current&&(G.current.value=``)},re=async()=>{if(D){I(!0);try{let e=u.find(e=>e.id===D);if(await(0,o.deleteDoc)((0,o.doc)(t.Da,J,D)),e?.recordType===`file`&&e.downloadURL)try{let n=e.downloadURL.split(`admin_files%2F`)[1]?.split(`?`)[0];n&&await(0,s.deleteObject)((0,s.ref)(t.ka,`admin_files/${decodeURIComponent(n)}`)).catch(()=>{})}catch(e){console.error(`Error cleaning up admin file:`,e)}O(null)}catch(e){console.error(`Error deleting admin record:`,e)}I(!1)}},[X,Z]=(0,r.useState)(null),[Q,ie]=(0,r.useState)(``),[ae,oe]=(0,r.useState)(!1),se=e=>{if(e.recordType===`file`){Z(e.id),ie(e.name);return}R(e.id),B(e.name),H(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??``)}));W(n),q.current=n.map(e=>e.key)},ce=async()=>{if(!X||!Q.trim()){Z(null);return}let e=u.find(e=>e.id===X);if(e&&e.name===Q.trim()){Z(null);return}oe(!0);try{await(0,o.updateDoc)((0,o.doc)(t.Da,J,X),{name:Q.trim()}),d(e=>e.map(e=>e.id===X?{...e,name:Q.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}oe(!1),Z(null)},le=async()=>{if(!L||!z.trim()){R(null);return}x(!0);let e={};U.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=U.map(e=>e.key.trim()).filter(Boolean),r=q.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(t.Da,J,L),{name:z.trim(),note:V.trim(),...e}),d(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]}),U.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),q.current=n}catch(e){console.error(`Error updating record:`,e)}x(!1),R(null)},ue=async()=>{if(!L||!z.trim())return;let e={};U.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=U.map(e=>e.key.trim()).filter(Boolean),r=q.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(t.Da,J,L),{name:z.trim(),note:V.trim(),...e}),d(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]}),U.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),q.current=n}catch(e){console.error(`Error silently saving record:`,e)}},de=(e,n)=>e?e.startsWith(`image/`)?n?(0,i.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${n})`}}):(0,i.jsx)(t.fi,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,i.jsx)(t.br,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,i.jsx)(t.gi,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,i.jsx)(t.ea,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,i.jsx)(t.Ei,{className:`w-4 h-4`}):(0,i.jsx)(t.hi,{className:`w-4 h-4`}):(0,i.jsx)(t.gi,{className:`w-4 h-4`}),fe=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-accent/10 text-accent`: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`,pe=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)},me=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]},he=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},ge=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.mr[r]?t.mr[r]:t.mr[n]?t.mr[n]:t.wr||t.Ur})(),_e=e.buttonStyle!==`secondary`,ve=e.buttonStorageStyle===`primary`,ye=e=>e.uid===a?.uid,be=({record:e})=>{let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||`Admin`,n=e.creatorEmail||``,r=e.creatorAvatar||``,a=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,i.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,i.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,i.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:a}),(0,i.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,i.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,i.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,i.jsxs)(`div`,{children:[(0,i.jsx)(Ce,{children:e.tabTitle||e.tabName||`Admin Page`}),e.route&&(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsxs)(t.fr.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,i.jsx)(`input`,{type:`file`,ref:G,onChange:ne,className:`hidden`}),!n&&(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm:p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,i.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,i.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${u.length} ${u.length===1?`item`:`items`}`})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.storage!==!1&&(0,i.jsx)(i.Fragment,{children:(0,i.jsxs)(t.fr.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>G.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`} ${ve?`btn-primary`:`btn-secondary`}`,children:[T?(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin`}):(0,i.jsx)(ge,{className:`w-4 h-4`}),e.buttonStorageText&&(0,i.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})}),e.showButton!==!1&&(0,i.jsx)(t.fr.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>h(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${_e?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,i.jsx)(t.Ur,{className:`w-4 h-4`}):(0,i.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,i.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,i.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,i.jsx)(t.ti,{className:`w-8 h-8 text-accent animate-spin`})}),n?(0,i.jsx)(`div`,{className:`fbos-content-slot`,children:(0,i.jsx)(n,{config:e,actions:{records:u,loading:f,collection:J,user:a,saveRecord:async e=>{let n=(0,o.doc)((0,o.collection)(t.Da,J)),r=Y(),i={id:n.id,uid:a.uid,recordType:`record`,creatorName:r.name,creatorEmail:r.email,creatorAvatar:r.avatar,createdAt:Date.now(),...e};d(e=>[i,...e]),await(0,o.setDoc)(n,{uid:a.uid,recordType:`record`,creatorName:r.name,creatorEmail:r.email,creatorAvatar:r.avatar,createdAt:(0,o.serverTimestamp)(),...e})},updateRecord:async(e,n)=>{d(t=>t.map(t=>t.id===e?{...t,...n}:t)),await(0,o.updateDoc)((0,o.doc)(t.Da,J,e),n)},deleteRecord:async e=>{await(0,o.deleteDoc)((0,o.doc)(t.Da,J,e))},startEdit:e=>se(e),confirmDelete:e=>O(e),uploadFile:()=>G.current?.click(),openAddForm:()=>h(!0),setAddForm:e=>C(()=>e),setFileHandler:e=>{w.current=e}}})}):(0,i.jsxs)(i.Fragment,{children:[!f&&u.length===0&&(0,i.jsxs)(t.fr.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,i.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,i.jsx)(t.Ur,{className:`w-6 h-6 text-accent/40`})}),(0,i.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All admins can view and contribute.`})]}),!f&&u.length>0&&(0,i.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,i.jsx)(t.pr,{children:u.map((e,n)=>{let r=L===e.id,a=ye(e);return(0,i.jsxs)(t.fr.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>se(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,i.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,i.jsxs)(i.Fragment,{children:[(0,i.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:ee===e.id?(0,i.jsx)(t.zi,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,i.jsx)(t.ri,{className:`w-3.5 h-3.5`})}),(0,i.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,i.jsx)(t.Si,{className:`w-3.5 h-3.5`})})]}),a&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`button`,{onClick:t=>{t.stopPropagation(),se(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,i.jsx)(t.Kr,{className:`w-3.5 h-3.5`})}),(0,i.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,i.jsx)(t.Or,{className:`w-3.5 h-3.5`})})]})]}),(0,i.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,i.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 ${fe(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?de(e.fileType,e.downloadURL):(0,i.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,i.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[X===e.id?(0,i.jsx)(`input`,{autoFocus:!0,type:`text`,value:Q,onChange:e=>ie(e.target.value),onBlur:()=>ce(),onKeyDown:e=>{e.key===`Enter`&&ce(),e.key===`Escape`&&Z(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,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,i.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>j(e)}),(0,i.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:he(e.createdAt)})]})]}),e.note&&(0,i.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,i.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,i.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,i.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,i.jsx)(be,{record:e})]},e.id)})})})]})]})]})]}),(0,i.jsx)(t.pr,{children:m&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>!b&&h(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,i.jsx)(t.fr.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:S?r.default.createElement(S,{onSave:async e=>{x(!0);try{let n=Y();await(0,o.addDoc)((0,o.collection)(t.Da,J),{uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:(0,o.serverTimestamp)(),...e}),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)},onClose:()=>!b&&h(!1),saving:b}):(0,i.jsxs)(`form`,{onSubmit:te,className:`p-5 flex flex-col gap-3`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>!b&&h(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,i.jsx)(t._r,{className:`w-4 h-4`})})]}),(0,i.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:g,onChange:e=>_(e.target.value),placeholder:`Name *`,disabled:b,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),placeholder:`Note (optional)`,disabled:b,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,i.jsx)(t.cr,{type:`submit`,isLoading:b,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:b?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,l.createPortal)((0,i.jsx)(t.pr,{children:M&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,i.jsx)(t.fr.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,i.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,i.jsx)(t._r,{className:`w-5 h-5`})}),(0,i.jsxs)(t.fr.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,i.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,i.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,i.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:M.fileName||M.name}),(0,i.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[pe(M.fileType),` • `,me(M.fileSize||0)]})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,i.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:ee===`preview`?(0,i.jsx)(t.zi,{className:`w-4 h-4 text-emerald-500`}):(0,i.jsx)(t.ri,{className:`w-4 h-4`})}),(0,i.jsx)(`button`,{onClick:()=>{j(null),Z(M.id),ie(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,i.jsx)(t.Kr,{className:`w-4 h-4`})}),(0,i.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,i.jsx)(t.Or,{className:`w-4 h-4`})}),(0,i.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,i.jsx)(t.Si,{className:`w-4 h-4`})})]})]}),(0,i.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>j(null),children:(0,i.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,i.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,i.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,i.jsx)(t.ti,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,i.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,i.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,i.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,i.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,i.jsx)(t.gi,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,i.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,i.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,i.jsx)(t.pr,{children:L&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>le(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,i.jsx)(t.fr.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,i.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),b&&(0,i.jsx)(t.ti,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>le(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,i.jsx)(t._r,{className:`w-4 h-4`})})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.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,i.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:()=>ue(),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,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.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,i.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{H(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:()=>ue(),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,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),U.map((e,n)=>(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let t=[...U];t[n].key=e.target.value,W(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>ue(),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,i.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let t=[...U];t[n].value=e.target.value,W(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>ue(),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,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>W(U.filter((e,t)=>t!==n)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,i.jsx)(t._r,{className:`w-3 h-3`})})]},n)),(0,i.jsxs)(`button`,{type:`button`,onClick:()=>W([...U,{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,i.jsx)(t.Ur,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,i.jsx)(Ve,{isOpen:!!D,onCancel:()=>O(null),onConfirm:re,title:`Delete Record`,message:(0,i.jsxs)(i.Fragment,{children:[`Are you sure you want to delete `,(0,i.jsx)(`strong`,{className:`text-foreground font-extrabold break-words mx-1`,children:u.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:F})]})}function bm({config:e,customContent:n}){let{user:a}=t.na(),{config:c}=t.ja(),[u,d]=(0,r.useState)([]),[f,p]=(0,r.useState)(!0),[m,h]=(0,r.useState)(!1),[g,_]=(0,r.useState)(``),[v,y]=(0,r.useState)(``),[b,x]=(0,r.useState)(!1),[S,C]=(0,r.useState)(null),w=(0,r.useRef)(null),[T,E]=(0,r.useState)(!1),[D,O]=(0,r.useState)(null),[k,A]=(0,r.useState)(null),j=e=>{if(A(e),e){let t=e.fileType||``;P(t.startsWith(`image/`)||t.startsWith(`video/`)||t===`application/pdf`)}},M=k,[N,P]=(0,r.useState)(!0),[F,I]=(0,r.useState)(!1),[L,R]=(0,r.useState)(null),[z,B]=(0,r.useState)(``),[V,H]=(0,r.useState)(``),[U,W]=(0,r.useState)([]),G=(0,r.useRef)(null),[ee,K]=(0,r.useState)(null),q=(0,r.useRef)([]),J=`mem_${(e.tabName||e.pageId||`internal_page`).toLowerCase().replace(/[^a-z0-9]+/g,`_`)}_records`;(0,r.useEffect)(()=>{document.title=e.tabTitle||e.tabName||c.appName||`Your AI Firebase`},[e.tabTitle,e.tabName,c.appName]),(0,r.useEffect)(()=>{if(!a)return;try{let e=Wa(J,a.uid);e?(d(e),p(!1)):p(!0)}catch{}let e=e=>e.map(e=>{let t=e.data();return{id:e.id,...t,createdAt:t.createdAt?.toMillis?t.createdAt.toMillis():t.createdAt}}),n=(0,o.onSnapshot)((0,o.query)((0,o.collection)(t.Da,J),(0,o.orderBy)(`createdAt`,`desc`),(0,o.limit)(150)),t=>{let n=e(t.docs);d(n),p(!1),Ga(J,a.uid,n)},n=>{console.error(`Error listening to shared records:`,n);let r=(0,o.onSnapshot)((0,o.query)((0,o.collection)(t.Da,J),(0,o.limit)(150)),t=>{let n=e(t.docs);n.sort((e,t)=>(t.createdAt||0)-(e.createdAt||0)),d(n),p(!1),Ga(J,a.uid,n)});return()=>r()});return()=>n()},[a,J]);let Y=()=>({name:a.displayName||a.email?.split(`@`)[0]||`Member`,email:a.email||``,avatar:a.photoURL||``}),te=async e=>{if(e.preventDefault(),!(!a||!g.trim())){x(!0);try{let e=Y();await(0,o.addDoc)((0,o.collection)(t.Da,J),{name:g.trim(),note:v.trim(),uid:a.uid,recordType:`record`,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()}),_(``),y(``),h(!1)}catch(e){console.error(`Error saving shared record:`,e)}x(!1)}},ne=async e=>{let n=e.target.files?.[0];if(!n||!a)return;let r=await t.or(n);E(!0);try{let e=`mem_files/${`${Date.now()}_${r.name.replace(/[^a-zA-Z0-9.-]/g,`_`)}`}`,n=(0,s.ref)(t.ka,e);await(0,s.uploadBytes)(n,r,{customMetadata:{ownerId:a.uid}});let i=await(0,s.getDownloadURL)(n);if(w.current)w.current(r,i,{uid:a.uid,storagePath:e});else{let e=Y();await(0,o.addDoc)((0,o.collection)(t.Da,J),{name:r.name,note:`${r.type||`File`} · ${me(r.size)}`,uid:a.uid,recordType:`file`,fileName:r.name,fileType:r.type||`unknown`,fileSize:r.size,downloadURL:i,creatorName:e.name,creatorEmail:e.email,creatorAvatar:e.avatar,createdAt:(0,o.serverTimestamp)()})}}catch(e){console.error(`Error uploading shared file:`,e)}E(!1),G.current&&(G.current.value=``)},re=async()=>{if(D){I(!0);try{let e=u.find(e=>e.id===D);if(await(0,o.deleteDoc)((0,o.doc)(t.Da,J,D)),e?.recordType===`file`&&e.downloadURL)try{let n=e.downloadURL.split(`mem_files%2F`)[1]?.split(`?`)[0];n&&await(0,s.deleteObject)((0,s.ref)(t.ka,`mem_files/${decodeURIComponent(n)}`)).catch(()=>{})}catch(e){console.error(`Error cleaning up shared file:`,e)}O(null)}catch(e){console.error(`Error deleting shared record:`,e)}I(!1)}},[X,Z]=(0,r.useState)(null),[Q,ie]=(0,r.useState)(``),[ae,oe]=(0,r.useState)(!1),se=e=>{if(e.recordType===`file`){Z(e.id),ie(e.name);return}R(e.id),B(e.name),H(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??``)}));W(n),q.current=n.map(e=>e.key)},ce=async()=>{if(!X||!Q.trim()){Z(null);return}let e=u.find(e=>e.id===X);if(e&&e.name===Q.trim()){Z(null);return}oe(!0);try{await(0,o.updateDoc)((0,o.doc)(t.Da,J,X),{name:Q.trim()}),d(e=>e.map(e=>e.id===X?{...e,name:Q.trim()}:e))}catch(e){console.error(`Error renaming file:`,e)}oe(!1),Z(null)},le=async()=>{await ue(),R(null)},ue=async()=>{if(!L||!z.trim())return;x(!0);let e={};U.forEach(({key:t,value:n})=>{t.trim()&&(e[t.trim()]=n)});let n=U.map(e=>e.key.trim()).filter(Boolean),r=q.current.filter(e=>!n.includes(e));r.forEach(t=>{e[t]=(0,o.deleteField)()});try{await(0,o.updateDoc)((0,o.doc)(t.Da,J,L),{name:z.trim(),note:V.trim(),...e}),d(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]}),U.forEach(({key:e,value:n})=>{e.trim()&&(t[e.trim()]=n)}),t})),q.current=n}catch(e){console.error(`Error saving record:`,e)}x(!1)},de=(e,n)=>e?e.startsWith(`image/`)?n?(0,i.jsx)(`div`,{className:`w-9 h-9 rounded-xl bg-cover bg-center shrink-0`,style:{backgroundImage:`url(${n})`}}):(0,i.jsx)(t.fi,{className:`w-4 h-4`}):e.startsWith(`video/`)||e.startsWith(`audio/`)?(0,i.jsx)(t.br,{className:`w-4 h-4`}):e.includes(`pdf`)||e.includes(`word`)||e.includes(`text`)?(0,i.jsx)(t.gi,{className:`w-4 h-4`}):e.includes(`zip`)||e.includes(`rar`)||e.includes(`archive`)?(0,i.jsx)(t.ea,{className:`w-4 h-4`}):e.includes(`html`)||e.includes(`csv`)||e.includes(`json`)?(0,i.jsx)(t.Ei,{className:`w-4 h-4`}):(0,i.jsx)(t.hi,{className:`w-4 h-4`}):(0,i.jsx)(t.gi,{className:`w-4 h-4`}),fe=e=>e?e.startsWith(`image/`)?`bg-emerald-500/10 text-emerald-500`:e.startsWith(`video/`)||e.startsWith(`audio/`)?`bg-accent/10 text-accent`: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`,pe=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)},me=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]},he=e=>{if(!e)return``;let t=e.toMillis?e.toMillis():e;return new Date(t).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,year:`numeric`})},ge=(()=>{let n=(e.buttonStorageIcon||`upload`).trim(),r=n.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``);return t.mr[r]?t.mr[r]:t.mr[n]?t.mr[n]:t.wr||t.Ur})(),_e=e.buttonStyle!==`secondary`,ve=e.buttonStorageStyle===`primary`,ye=e=>e.uid===a?.uid,be=({record:e})=>{let t=e.creatorName||e.creatorEmail?.split(`@`)[0]||`Member`,n=e.creatorEmail||``,r=e.creatorAvatar||``,a=t.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2);return(0,i.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 pt-2 border-t border-[var(--panel-border)]/30`,children:[r?(0,i.jsx)(`img`,{src:r,alt:``,className:`w-5 h-5 rounded-full object-cover shrink-0`}):(0,i.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:a}),(0,i.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0 flex-1`,children:[(0,i.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/40 truncate`,children:t}),n&&(0,i.jsxs)(`span`,{className:`text-[10px] text-foreground/25 truncate`,children:[`· `,n]})]})]})};return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsx)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6 flex items-center justify-between`,children:(0,i.jsxs)(`div`,{children:[(0,i.jsx)(Ce,{children:e.tabTitle||e.tabName||`Internal Page`}),e.route&&(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),e.route]})]})}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsxs)(t.fr.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,i.jsx)(`input`,{type:`file`,ref:G,onChange:ne,className:`hidden`}),!n&&(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4 p-4 sm:p-6 md:px-8 md:py-6 border-b border-[var(--panel-border)]/50 bg-background/50 shrink-0`,children:[(0,i.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,i.jsx)(`h2`,{className:`text-xl font-extrabold text-foreground tracking-tight truncate`,children:e.tabTitle||e.tabName||`Dashboard`}),(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1`,children:f?`Loading…`:`${u.length} ${u.length===1?`item`:`items`} · Internal`})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.storage!==!1&&(0,i.jsx)(i.Fragment,{children:(0,i.jsxs)(t.fr.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>G.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`} ${ve?`btn-primary`:`btn-secondary`}`,children:[T?(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin`}):(0,i.jsx)(ge,{className:`w-4 h-4`}),e.buttonStorageText&&(0,i.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonStorageText})]})}),e.showButton!==!1&&(0,i.jsx)(t.fr.button,{whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>h(!0),title:`Add New`,className:`h-10 flex items-center justify-center gap-2 rounded-xl transition-all duration-300 cursor-pointer ${e.buttonText&&e.buttonText!==`+`?`px-5`:`w-10`} ${_e?`btn-primary`:`btn-secondary`}`,children:e.buttonText===`+`||!e.buttonText?(0,i.jsx)(t.Ur,{className:`w-4 h-4`}):(0,i.jsx)(`span`,{className:`text-[13px] font-bold`,children:e.buttonText})})]})]}),(0,i.jsxs)(`div`,{className:`p-6 md:p-8 flex-1 overflow-y-auto relative min-h-[400px]`,children:[f&&(0,i.jsx)(`div`,{className:`absolute inset-0 z-10 flex items-center justify-center bg-background/50 backdrop-blur-sm`,children:(0,i.jsx)(t.ti,{className:`w-8 h-8 text-accent animate-spin`})}),n?(0,i.jsx)(`div`,{className:`fbos-content-slot`,children:(0,i.jsx)(n,{config:e,actions:{records:u,loading:f,collection:J,user:a,saveRecord:async e=>{let n=(0,o.doc)((0,o.collection)(t.Da,J)),r=Y(),i={id:n.id,uid:a.uid,recordType:`record`,creatorName:r.name,creatorEmail:r.email,creatorAvatar:r.avatar,createdAt:Date.now(),...e};d(e=>[i,...e]),await(0,o.setDoc)(n,{uid:a.uid,recordType:`record`,creatorName:r.name,creatorEmail:r.email,creatorAvatar:r.avatar,createdAt:(0,o.serverTimestamp)(),...e})},updateRecord:async(e,n)=>{d(t=>t.map(t=>t.id===e?{...t,...n}:t)),await(0,o.updateDoc)((0,o.doc)(t.Da,J,e),n)},deleteRecord:async e=>{await(0,o.deleteDoc)((0,o.doc)(t.Da,J,e))},startEdit:e=>se(e),confirmDelete:e=>O(e),uploadFile:()=>G.current?.click(),openAddForm:()=>h(!0),setAddForm:e=>C(()=>e),setFileHandler:e=>{w.current=e}}})}):(0,i.jsxs)(i.Fragment,{children:[!f&&u.length===0&&(0,i.jsxs)(t.fr.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,i.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,i.jsx)(t.Ur,{className:`w-6 h-6 text-accent/40`})}),(0,i.jsx)(`p`,{className:`text-[15px] font-bold mb-1.5 text-foreground/50`,children:`No items yet`}),(0,i.jsx)(`p`,{className:`text-[13px] font-medium text-foreground/35 max-w-xs leading-relaxed`,children:`Use the buttons above to add records or upload files. All team members can view and contribute.`})]}),!f&&u.length>0&&(0,i.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:(0,i.jsx)(t.pr,{children:u.map(e=>{let n=L===e.id,r=ye(e);return(0,i.jsxs)(t.fr.div,{initial:!1,animate:{opacity:1,y:0},exit:{opacity:0,scale:.95},onClick:()=>r?se(e):null,className:`group flex flex-col bg-background border rounded-2xl p-5 transition-all relative ${r?`cursor-pointer`:``} ${n?`border-accent/40 shadow-lg ring-1 ring-accent/20`:`border-[var(--panel-border)] hover:border-accent/30 hover:shadow-lg`}`,children:[(0,i.jsxs)(`div`,{className:`absolute top-3 right-3 flex items-center gap-0.5 opacity-100 md:opacity-0 md:group-hover:opacity-100 transition-all z-10`,children:[e.recordType===`file`&&e.downloadURL&&(0,i.jsxs)(i.Fragment,{children:[(0,i.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:ee===e.id?(0,i.jsx)(t.zi,{className:`w-3.5 h-3.5 text-emerald-500`}):(0,i.jsx)(t.ri,{className:`w-3.5 h-3.5`})}),(0,i.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,i.jsx)(t.Si,{className:`w-3.5 h-3.5`})})]}),r&&(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`button`,{onClick:t=>{t.stopPropagation(),se(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,i.jsx)(t.Kr,{className:`w-3.5 h-3.5`})}),(0,i.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,i.jsx)(t.Or,{className:`w-3.5 h-3.5`})})]})]}),(0,i.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,i.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 ${fe(e.fileType)}`:`bg-accent/10 text-accent`}`,children:e.recordType===`file`?de(e.fileType,e.downloadURL):(0,i.jsx)(`div`,{className:`w-2 h-2 rounded-full bg-current`})}),(0,i.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1 relative`,children:[X===e.id?(0,i.jsx)(`input`,{autoFocus:!0,type:`text`,value:Q,onChange:e=>ie(e.target.value),onBlur:()=>ce(),onKeyDown:e=>{e.key===`Enter`&&ce(),e.key===`Escape`&&Z(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,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground truncate pr-12`,children:e.name}),e.recordType===`file`&&(0,i.jsx)(`div`,{className:`absolute inset-0 z-0 cursor-pointer`,onClick:()=>j(e)}),(0,i.jsx)(`span`,{className:`text-[11px] text-foreground/35 font-bold uppercase tracking-wider mt-0.5`,children:he(e.createdAt)})]})]}),e.note&&(0,i.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,i.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-1`,children:[(0,i.jsxs)(`span`,{className:`text-[10px] font-bold text-foreground/30 uppercase tracking-wider shrink-0`,children:[e,`:`]}),(0,i.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground/60 truncate`,children:String(t)})]},e)),(0,i.jsx)(be,{record:e})]},e.id)})})})]})]})]})]}),(0,i.jsx)(t.pr,{children:m&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>!b&&h(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,i.jsx)(t.fr.div,{initial:{opacity:0,scale:.97,y:6},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.97,y:6},transition:{duration:.2},className:`w-full max-w-[360px] border-[var(--panel-border)] border rounded-2xl relative z-10 glass-panel shadow-2xl bg-background overflow-hidden`,children:S?r.default.createElement(S,{onSave:async e=>{x(!0);try{let n=Y();await(0,o.addDoc)((0,o.collection)(t.Da,J),{uid:a.uid,recordType:`record`,creatorName:n.name,creatorEmail:n.email,creatorAvatar:n.avatar,createdAt:(0,o.serverTimestamp)(),...e}),h(!1)}catch(e){console.error(`Error saving record:`,e)}x(!1)},onClose:()=>!b&&h(!1),saving:b}):(0,i.jsxs)(`form`,{onSubmit:te,className:`p-5 flex flex-col gap-3`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`New Record`}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>!b&&h(!1),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer p-0.5`,children:(0,i.jsx)(t._r,{className:`w-4 h-4`})})]}),(0,i.jsx)(`input`,{autoFocus:!0,type:`text`,required:!0,value:g,onChange:e=>_(e.target.value),placeholder:`Name *`,disabled:b,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-semibold text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),placeholder:`Note (optional)`,disabled:b,rows:2,className:`w-full bg-foreground/[0.03] border border-[var(--panel-border)] px-3.5 py-2.5 text-[13px] font-medium text-foreground outline-none focus:border-accent transition-colors placeholder:text-foreground/30 resize-none`,style:{borderRadius:`var(--input-radius, 0.75rem)`}}),(0,i.jsx)(`div`,{className:`flex justify-end pt-1`,children:(0,i.jsx)(t.cr,{type:`submit`,isLoading:b,className:`px-5 py-2 text-[12px] font-bold shadow-md`,children:b?`Saving…`:`Save`})})]})})]})}),typeof window<`u`&&(0,l.createPortal)((0,i.jsx)(t.pr,{children:M&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[9999] flex items-center justify-center p-4 md:p-12`,children:[(0,i.jsx)(t.fr.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,i.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,i.jsx)(t._r,{className:`w-5 h-5`})}),(0,i.jsxs)(t.fr.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,i.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,i.jsxs)(`div`,{className:`flex flex-col min-w-0 pr-4`,children:[(0,i.jsx)(`span`,{className:`text-xl font-extrabold text-foreground truncate`,children:M.fileName||M.name}),(0,i.jsxs)(`span`,{className:`text-[12px] text-foreground/70 font-bold uppercase tracking-wider mt-1`,children:[pe(M.fileType),` • `,me(M.fileSize||0)]})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,i.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:ee===`preview`?(0,i.jsx)(t.zi,{className:`w-4 h-4 text-emerald-500`}):(0,i.jsx)(t.ri,{className:`w-4 h-4`})}),(0,i.jsx)(`button`,{onClick:()=>{j(null),Z(M.id),ie(M.name)},className:`p-2.5 bg-foreground/5 hover:bg-foreground/10 text-foreground/70 hover:text-accent transition-colors rounded-xl shadow-sm cursor-pointer`,title:`Rename`,children:(0,i.jsx)(t.Kr,{className:`w-4 h-4`})}),(0,i.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,i.jsx)(t.Or,{className:`w-4 h-4`})}),(0,i.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,i.jsx)(t.Si,{className:`w-4 h-4`})})]})]}),(0,i.jsx)(`div`,{className:`flex-1 w-full relative bg-foreground/[0.02] min-h-[50vh] md:min-h-[600px]`,onClick:()=>j(null),children:(0,i.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,i.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center rounded-lg z-50 pointer-events-none`,children:(0,i.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,i.jsx)(t.ti,{className:`w-5 h-5 text-accent animate-spin`})})}),M.fileType?.startsWith(`image/`)?(0,i.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,i.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,i.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,i.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,i.jsx)(t.gi,{className:`w-24 h-24 mb-6 opacity-40 drop-shadow-sm`}),(0,i.jsx)(`span`,{className:`text-[20px] font-extrabold text-foreground`,children:`Preview Unavailable`}),(0,i.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,i.jsx)(t.pr,{children:L&&(0,i.jsxs)(`div`,{className:`fixed inset-0 z-[120] flex items-center justify-center p-4`,children:[(0,i.jsx)(t.fr.div,{onClick:()=>le(),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`absolute inset-0 bg-background/60 backdrop-blur-sm cursor-pointer`}),(0,i.jsx)(t.fr.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,i.jsxs)(`div`,{className:`p-5 flex flex-col gap-3 max-h-[80vh] overflow-y-auto`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between mb-2 mt-2 px-1`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,i.jsx)(`span`,{className:`text-[14px] font-bold text-foreground`,children:`Edit Record`}),b&&(0,i.jsx)(t.ti,{className:`w-3 h-3 animate-spin text-foreground/40`})]}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>le(),className:`text-foreground/30 hover:text-foreground/60 transition-colors cursor-pointer`,children:(0,i.jsx)(t._r,{className:`w-4 h-4`})})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-0 max-h-[70vh] overflow-y-auto no-scrollbar px-1`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.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,i.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:()=>ue(),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,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.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,i.jsx)(`textarea`,{ref:e=>{e&&(e.style.height=`auto`,e.style.height=e.scrollHeight+`px`)},value:V,onChange:e=>{H(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:()=>ue(),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,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`})]}),U.map((e,n)=>(0,i.jsxs)(`div`,{className:`flex flex-col relative group/field`,children:[(0,i.jsx)(`input`,{placeholder:`FIELD NAME`,value:e.key,onChange:e=>{let t=[...U];t[n].key=e.target.value,W(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>ue(),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,i.jsx)(`input`,{placeholder:`Field value...`,value:e.value,onChange:e=>{let t=[...U];t[n].value=e.target.value,W(t)},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur())},onBlur:()=>ue(),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,i.jsx)(`div`,{className:`border-b border-dashed border-[var(--panel-border)]/60`}),(0,i.jsx)(`button`,{type:`button`,onClick:()=>W(U.filter((e,t)=>t!==n)),className:`absolute top-3 right-0 p-1 text-foreground/0 group-hover/field:text-foreground/20 hover:!text-red-400 transition-colors cursor-pointer`,children:(0,i.jsx)(t._r,{className:`w-3 h-3`})})]},n)),(0,i.jsxs)(`button`,{type:`button`,onClick:()=>W([...U,{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,i.jsx)(t.Ur,{className:`w-3 h-3`}),` Add Field`]})]})]})})]})}),(0,i.jsx)(Ve,{isOpen:!!D,onCancel:()=>O(null),onConfirm:re,title:`Delete Record`,message:(0,i.jsxs)(i.Fragment,{children:[`Are you sure you want to delete `,(0,i.jsx)(`strong`,{className:`text-foreground font-extrabold break-words mx-1`,children:u.find(e=>e.id===D)?.name}),` This action cannot be undone.`]}),confirmText:`Delete`,isProcessing:F})]})}var xm=[`board`,`table`,`calendar`,`drive`],Sm=[`inline_form`,`popup_form`],Cm=e=>typeof e!=`string`||e===``||e===`none`||e===`custom`||![...xm,...Sm].includes(e),wm=(e,t)=>Cm(e)||t&&!Tm(e),Tm=e=>typeof e==`string`&&xm.includes(e),Em=`/src/your-ai-workflow-firebase-os/microcomponents`,Dm=e=>(e||``).split(/[^a-zA-Z0-9]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(``),Om=e=>{let t=e.replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase();return[t,t.replace(/_/g,``)]},km=e=>{let t=[e?.contentKey,e?.tabName,e?.pageId,e?.pageName].filter(e=>typeof e==`string`&&e.trim()).map(e=>Dm(e)).filter(Boolean);return[...new Set(t)].map(e=>`${e}Content.tsx`)},Am=e=>{if(typeof window>`u`)return!1;let t=window.__FBOS_MICROCOMPONENTS__;if(!t)return!1;let n=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_|_$/g,``);return[e?.contentKey,e?.tabName,e?.pageId,e?.pageName].filter(e=>typeof e==`string`&&e.trim()).some(e=>t[n(e)])},jm=new Map,Mm=e=>{let t=jm.get(e);return t||(t=import(`${Em}/${e}`).then(e=>typeof e?.default==`function`||typeof e?.default==`object`?e.default:null).catch(()=>null),jm.set(e,t)),t};async function Nm(e){if(typeof window>`u`||Am(e))return null;for(let t of km(e)){let e=await Mm(t);if(!e)continue;let[n,r]=Om(t.replace(/Content\.tsx$/,``)),i=window.__FBOS_MICROCOMPONENTS__||{};return window.__FBOS_MICROCOMPONENTS__={[n]:e,[r]:e,...i},e}return null}var Pm=(e,n)=>{let r=n?t._a(e.pageType):`public`;return{...e,pageType:r,isPrivate:n,isAdmin:r===`admin`,isInternal:r===`internal`,isShared:r===`internal`}};function Fm(){let e=(0,c.useLocation)(),{user:n,userRole:a,loading:s,roleResolved:l,userInactive:u,signOut:d}=t.na(),f=t.Na(),p=e=>{if(typeof window<`u`){let t=localStorage.getItem(`fbos_route_${e}`);if(t)try{let e=JSON.parse(t);if(e.form&&!e.formConfigOverride){let t=localStorage.getItem(`fbos_form_${e.form}`);t&&(e.formConfigOverride=JSON.parse(t))}return Pm(e,e.isPrivate===!0)}catch{}}let n=(typeof window<`u`?window.__FBOS_PAGES__:null)||{},r=e.replace(/^\//,``);for(let[t,i]of Object.entries(n)){let n=i.config,a=i.isPublic,o=n.route||`/`+t;if(o===e||t===r)return Pm({...n,route:o,contentKey:n.pageId||t,pageId:t},!a)}return e===`/contact`?{route:`/contact`,template:`popup_form`,form:`contact`,pageId:`contact`,contentKey:`contact`,pageName:`Contact`,formConfigOverride:f.defaultConfigs?.contactForm||t.La}:e===`/support`?{route:`/support`,template:`popup_form`,form:`support`,pageId:`support`,contentKey:`support`,pageName:`Support`,formConfigOverride:f.defaultConfigs?.supportForm||t.Fa}:null},[m,h]=(0,r.useState)(()=>p(e.pathname)),[g,_]=(0,r.useState)(()=>!p(e.pathname));(0,r.useEffect)(()=>{let n=!0,r=p(e.pathname);if(r){h(r),_(!1);let e=r.pageName||r.tabName||r.title;e&&(document.title=e)}return(async()=>{try{let r=e.pathname;r.startsWith(`/`)&&(r=r.substring(1));let[i,a,s,c,l,u]=await Promise.allSettled([(0,o.getDoc)((0,o.doc)(t.Da,`sys_pages`,r)),(0,o.getDoc)((0,o.doc)(t.Da,`sys_tabs`,r)),(0,o.getDocs)((0,o.query)((0,o.collection)(t.Da,`sys_pages`),(0,o.where)(`route`,`==`,e.pathname),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(t.Da,`sys_pages`),(0,o.where)(`route`,`==`,r),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(t.Da,`sys_tabs`),(0,o.where)(`route`,`==`,e.pathname),(0,o.limit)(1))),(0,o.getDocs)((0,o.query)((0,o.collection)(t.Da,`sys_tabs`),(0,o.where)(`route`,`==`,r),(0,o.limit)(1)))]),d=null,p=null,m=(e,t)=>{d||e.status===`fulfilled`&&(e.value.exists&&e.value.exists()?(d=Pm(e.value.data(),t),p=e.value.id):e.value.docs&&e.value.docs.length>0&&(d=Pm(e.value.docs[0].data(),t),p=e.value.docs[0].id))};if(m(i,!1),m(s,!1),m(c,!1),m(a,!0),m(l,!0),m(u,!0),!d){let t=(typeof window<`u`?window.__FBOS_PAGES__:null)||{};for(let[n,i]of Object.entries(t)){let t=i.config,a=i.isPublic,o=t.route||`/`+n;if(o===e.pathname||n===r){d=Pm({...t,route:o,contentKey:t.pageId||n,pageId:n},!a),p=n;break}}}if(d||(e.pathname===`/contact`?(d={route:`/contact`,template:`popup_form`,form:`contact`,pageName:`Contact`},p=`contact`):e.pathname===`/support`&&(d={route:`/support`,template:`popup_form`,form:`support`,pageName:`Support`},p=`support`)),!n)return;if(d){if((p===`contact`||p===`support`)&&!d.form&&(d.form=p),d.contentKey||=d.pageId||p,d.pageId=p,localStorage.setItem(`fbos_route_${e.pathname}`,JSON.stringify(d)),d.form){let e=(typeof window<`u`?window.__FBOS_FORMS__:null)||{},r=n=>f.defaultConfigs?.[n]||f.defaultConfigs?.[`${n}Form`]||e[n]||(n===`contact`?t.La:n===`support`?t.Fa:null);if(localStorage.getItem(`fbos_custom_form_${d.form}`)){try{let e=localStorage.getItem(`fbos_form_${d.form}`);e&&(d.formConfigOverride=JSON.parse(e))}catch{}(0,o.getDoc)((0,o.doc)(t.Da,`sys_forms`,d.form)).then(async e=>{if(n)if(e.exists()){let t={...e.data(),id:e.id};h(e=>({...e,formConfigOverride:t})),localStorage.setItem(`fbos_form_${d.form}`,JSON.stringify(t))}else{let e=r(d.form);e&&(h(t=>({...t,formConfigOverride:e})),localStorage.setItem(`fbos_form_${d.form}`,JSON.stringify(e)),localStorage.removeItem(`fbos_custom_form_${d.form}`))}})}else{let e=r(d.form);e&&(d.formConfigOverride=e)}}let r=d.pageName||d.tabName||d.title;r&&(document.title=r),h(d),_(!1)}else h(`not-found`),_(!1),localStorage.removeItem(`fbos_route_${e.pathname}`)}catch{n&&g&&(h(`not-found`),_(!1))}})(),()=>{n=!1}},[e.pathname]);let[v,y]=(0,r.useState)(!1),[b,x]=(0,r.useState)(null),[S,C]=(0,r.useState)(!1),w=m&&m!==`not-found`&&typeof m==`object`?[m.contentKey,m.tabName,m.pageId,m.pageName].filter(Boolean).join(`|`):``;if((0,r.useEffect)(()=>{if(x(null),!w||Am(m)){C(!1);return}let e=!1;C(!0),Nm(m).then(t=>{e||(t&&x(()=>t),C(!1))});let t=setTimeout(()=>{e||C(!1)},4e3);return()=>{e=!0,clearTimeout(t)}},[w]),(0,r.useEffect)(()=>{let e;return g||s||!l||S?e=setTimeout(()=>y(!0),150):y(!1),()=>clearTimeout(e)},[g,s,l,S]),g||s||!l||S)return v?n?(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(`div`,{className:`mb-6`,children:[(0,i.jsx)(`div`,{className:`h-10 w-56 rounded-xl bg-foreground/5 animate-pulse mt-1`}),(0,i.jsx)(`div`,{className:`h-3 w-24 rounded bg-foreground/5 animate-pulse mt-3`})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.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,i.jsx)(t.ti,{className:`w-6 h-6 animate-spin text-accent`})})]})]}):(0,i.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-[40vh] z-10`,children:(0,i.jsxs)(`div`,{className:`p-4 rounded-2xl glass-panel border border-[var(--panel-border)]/40 bg-background/80 shadow-md flex items-center gap-3`,children:[(0,i.jsx)(t.ti,{className:`w-4 h-4 animate-spin text-accent`}),(0,i.jsx)(`span`,{className:`text-[12px] font-medium text-foreground/60 tracking-wide`,children:`Loading page...`})]})}):null;if(m===`not-found`)return(0,i.jsx)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:(0,i.jsxs)(`div`,{className:`flex flex-col items-center justify-center flex-1 text-center`,children:[(0,i.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,i.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,i.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,i.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,i.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]})}),(0,i.jsx)(`h2`,{className:`text-2xl sm:text-3xl font-bold mb-3 text-foreground`,children:`Page Not Found`}),(0,i.jsx)(`p`,{className:`text-foreground/60 max-w-md`,children:`The route you are looking for does not exist or has been removed.`}),t.pa(a)&&(()=>{let t=fm();return(0,i.jsxs)(`div`,{className:`mt-8 w-full max-w-lg text-left flex flex-col gap-4`,children:[(0,i.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)] bg-[var(--panel-bg)] px-5 py-4`,children:[(0,i.jsx)(`p`,{className:`text-[12px] font-extrabold tracking-tight text-gradient mb-1.5`,children:`Pages the app can see`}),(0,i.jsx)(`p`,{className:`text-[13px] text-foreground/70 font-medium leading-relaxed`,children:t.length?t.join(` · `):`None yet. If your assistant says it created a page, the app has not picked its file up.`})]}),(0,i.jsx)(it,{title:`If your assistant just made this page, paste this`,prompt:gm(e.pathname)})]})})()]})});if((m.pageId===`support`||m.isPrivate)&&!n)return(0,i.jsx)(c.Navigate,{to:`/login?from=${encodeURIComponent(e.pathname)}`,replace:!0});if((m.pageId===`support`||m.isPrivate)&&n&&u)return(0,i.jsx)(yi,{tone:`red`,title:`Access Denied`,message:`You don't have access to this app. Please contact the administrator.`,action:(0,i.jsx)(`button`,{onClick:()=>d(),className:bi,children:`Sign Out`})});if((m.pageId===`support`||m.isPrivate)&&n&&!n.emailVerified)return(0,i.jsx)(c.Navigate,{to:`/verify`,replace:!0});if(m.isPrivate&&!t.ua(a,m))return(0,i.jsx)(Ci,{});let T=f.customRoutes?.[e.pathname]||(m&&m.route?f.customRoutes?.[m.route]:null),E=m.pageName?.toLowerCase().replace(/\s+/g,`_`)||m.pageId||`custom_page`,D=`pub_${E}`,O=m.isPrivate?`${t.va(m)}${m.pageId||E}`:D,k=f.microcomponents||(typeof window<`u`?window.__FBOS_MICROCOMPONENTS__:void 0),A=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_|_$/g,``),j=[m.contentKey,m.tabName,m.pageId,m.pageName,m.pageName?.replace(/\s+/g,`_`)].filter(Boolean).map(e=>A(e)).reduce((e,t)=>e||k?.[t],void 0),M=T||j||b||void 0,N=m.route||m.pageId||`custom`;return wm(m.template,!!M)?m.isAdmin?(0,i.jsx)(ym,{config:m,customContent:M},N):m.isInternal?(0,i.jsx)(bm,{config:m,customContent:M},N):m.isPrivate?(0,i.jsx)(vm,{config:m,customContent:M},N):(0,i.jsx)(_m,{config:m,customContent:M},N):m.template===`board`?(0,i.jsx)(f.components?.TemplateBoard||vn,{title:m.tabTitle||m.tabName||m.title||m.pageName||`Board`,subtitle:m.route,tasksCollection:`${O}_tasks`,categoriesCollection:`${O}_categories`,config:m,customContent:M},N):m.template===`table`?(0,i.jsx)(f.components?.TemplateTable||qr,{title:m.tabTitle||m.tabName||m.title||m.pageName||`Table`,subtitle:m.route,tableCollection:`${O}_table`,config:m,customContent:M},N):m.template===`calendar`?(0,i.jsx)(f.components?.TemplateCalendar||Xr,{title:m.tabTitle||m.tabName||m.title||m.pageName||`Calendar`,subtitle:m.route,eventsCollection:`${O}_events`,defaultTimeFormat:m.defaultTimeFormat||m.defaulttimeformat||`12h`,config:m,customContent:M},N):m.template===`drive`?(0,i.jsx)(f.components?.TemplateDrive||Kt,{title:m.tabTitle||m.tabName||m.title||m.pageName||`Drive`,subtitle:m.route,filesCollection:`${O}_files`,config:m,customContent:M},N):m.template===`inline_form`?(0,i.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-start mt-8 relative z-10 w-full min-h-[60vh]`,children:(0,i.jsx)(t.t,{isInline:!0,formId:m.form,formConfig:m.formConfigOverride})}):(0,i.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center relative z-10 w-full min-h-[60vh]`,children:(0,i.jsx)(t.t,{formId:m.form,formConfig:m.formConfigOverride,onClose:()=>window.history.back()})})}var Im=e=>e.error?`error`:e.paid?`paid`:`unpaid`,Lm={checking:{icon:t.Oi,tint:`text-accent`,title:`Checking your payment…`},paid:{icon:t.Ni,tint:`text-emerald-400`,title:`Thank you — payment received`},unpaid:{icon:t.Oi,tint:`text-amber-400`,title:`Not confirmed yet`},error:{icon:t.Pi,tint:`text-red-400`,title:`We could not confirm this payment`},cancelled:{icon:t.Ai,tint:`text-foreground/50`,title:`Payment cancelled`}};function Rm({cancelled:e=!1}){let[n]=(0,c.useSearchParams)(),a=n.get(`session_id`)||``,[o,s]=(0,r.useState)(`checking`),[l,u]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(e)return;let t=!1;return ee(a).then(e=>{t||(u(e),s(Im(e)))}),()=>{t=!0}},[e,a]);let d=async()=>{s(`checking`);let e=await ee(a);u(e),s(Im(e))},f=Lm[e?`cancelled`:o],p=f.icon;return(0,i.jsx)(`div`,{className:`flex-1 flex items-center justify-center w-full z-10 px-4 mb-16`,children:(0,i.jsxs)(t.fr.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,i.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,i.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 shadow-xl`,children:(0,i.jsx)(p,{className:`w-7 h-7 md:w-8 md:h-8 ${f.tint} ${!e&&o===`checking`?`animate-pulse`:``}`})}),(0,i.jsx)(`h1`,{className:`text-2xl md:text-3xl font-extrabold mb-3 text-foreground tracking-tight`,children:f.title}),(0,i.jsxs)(`div`,{className:`text-[14px] md:text-[15px] text-foreground/60 mb-6 md:mb-8 leading-[1.6] tracking-wide`,children:[e&&(0,i.jsx)(`p`,{children:`Nothing was charged. You can try again whenever you like.`}),!e&&o===`checking`&&(0,i.jsx)(`p`,{children:`One moment — confirming with the payment provider.`}),!e&&o===`paid`&&(0,i.jsxs)(`p`,{children:[l?.amountTotal!=null&&l?.currency?`Your payment of ${l.amountTotal} ${l.currency.toUpperCase()} went through.`:`Your payment went through.`,l?.customerEmail?` A receipt is on its way to ${l.customerEmail}.`:``]}),!e&&o===`unpaid`&&(0,i.jsx)(`p`,{children:`The payment provider has not confirmed this payment yet. Some payment methods take a minute — check again shortly, and look for a receipt in your email.`}),!e&&o===`error`&&(0,i.jsxs)(`p`,{children:[l?.error,` If you completed the payment, check your email for a receipt — if one arrived, your payment went through and you can safely close this page.`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-3 max-w-[360px] mx-auto`,children:[!e&&(o===`unpaid`||o===`error`)&&(0,i.jsx)(t.cr,{variant:`primary`,onClick:d,className:`w-full py-2.5 md:py-3 text-[14px] font-bold tracking-wide rounded-xl`,children:`Check again`}),(0,i.jsx)(c.Link,{to:`/`,className:`w-full block py-2.5 md:py-3 bg-foreground/5 hover:bg-foreground/10 text-foreground text-[14px] font-bold rounded-xl transition-colors`,children:`Back to the site`})]})]})})}function zm({children:e,className:n,variant:a=`secondary`}){let{loading:o,configured:s}=Y(),[c,l]=(0,r.useState)(!1),[u,d]=(0,r.useState)(null);return o||!s?null:(0,i.jsxs)(`span`,{className:`inline-flex flex-col items-stretch gap-2`,children:[(0,i.jsx)(t.cr,{variant:a,className:n,onClick:async()=>{if(c)return;l(!0),d(null);let e=await G();e&&(d(e),l(!1))},disabled:c,children:c?`Opening…`:e??`Manage plan`}),u&&(0,i.jsx)(`span`,{role:`alert`,className:`text-[13px] font-semibold text-red-400 leading-snug`,children:u})]})}function Bm(e){return e.status===`past_due`?{label:`Past due`,tone:`bad`}:e.active?{label:`Active`,tone:`good`}:{label:`Cancelled`,tone:`quiet`}}function Vm(e){if(!e.currentPeriodEnd||!e.active)return``;let t=new Date(e.currentPeriodEnd*1e3).toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`});return e.cancelAtPeriodEnd?`Ends on ${t}`:`Renews on ${t}`}function Hm({payment:e}){let n=Kd({kind:`charge`,email:null,name:null,...e});return(0,i.jsxs)(`div`,{className:`flex items-center gap-3 px-3.5 py-2.5 ${t.X}`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0 flex-1`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-bold text-foreground truncate`,children:e.description||`One-off payment`}),(0,i.jsx)(`span`,{className:`text-[11px] text-foreground/45 font-medium truncate`,children:Yd(e.created)})]}),(0,i.jsx)(`span`,{className:`text-[12.5px] font-semibold text-foreground/70 whitespace-nowrap shrink-0`,children:qd(e.amount,e.currency)}),(0,i.jsx)(Xd,{label:n.label,tone:n.tone})]})}function Um({sub:e}){let n=Bm(e),r=Vm(e);return(0,i.jsxs)(`div`,{className:`flex flex-col gap-3 px-3.5 py-3 ${t.X}`,children:[(0,i.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,i.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0 flex-1`,children:[(0,i.jsx)(`span`,{className:`text-[13px] font-bold text-foreground truncate`,children:e.productName||`Subscription`}),(0,i.jsxs)(`span`,{className:`text-[11px] text-foreground/45 font-medium truncate`,children:[qd(e.amount,e.currency),e.interval?` / ${e.interval}`:``,r?` — ${r}`:``]})]}),(0,i.jsx)(Xd,{label:n.label,tone:n.tone})]}),(0,i.jsx)(zm,{className:`self-start`})]})}function Wm(){let{user:e}=t.na(),{loading:n,subscriptions:r,payments:a,error:o}=te(),s=!n&&!o&&r.length===0&&a.length===0;return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,i.jsx)(Ce,{children:`Billing`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/billing`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsx)(`div`,{className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-5 md:p-8 shadow-2xl relative bg-background flex flex-col min-h-[400px]`,children:n?(0,i.jsx)(`div`,{className:`flex items-center justify-center flex-1 text-foreground/40 py-16`,children:(0,i.jsx)(t.ti,{className:`w-6 h-6 animate-spin text-accent`})}):o?(0,i.jsx)(`p`,{className:`text-[12.5px] font-medium leading-relaxed px-1 text-red-500`,children:o}):s?(0,i.jsx)(t.at,{icon:t.Vr,title:`Nothing here yet`,description:`No payments have been made on this account.`,collapsible:!1,children:(0,i.jsxs)(`p`,{className:`text-[12.5px] font-medium leading-relaxed px-1 text-foreground/50`,children:[`Nothing has been bought on this account’s email`,e?.email?(0,i.jsxs)(i.Fragment,{children:[` (`,(0,i.jsx)(`strong`,{children:e.email}),`)`]}):null,`. A payment made with a different email address at checkout lives with that email — sign in with the address you paid with to see it here.`]})}):(0,i.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[r.length>0&&(0,i.jsx)(t.at,{icon:t.wi,title:r.length===1?`Your subscription`:`Your subscriptions`,description:`Manage plan opens Stripe's own portal — cancel, switch, card, invoices.`,collapsible:!1,children:(0,i.jsx)(`div`,{className:`flex flex-col gap-2.5`,children:r.map(e=>(0,i.jsx)(Um,{sub:e},e.id))})}),a.length>0&&(0,i.jsx)(t.at,{icon:t.Vr,title:`Your payments`,description:`Every payment on this account, straight from Stripe.`,collapsible:!1,children:(0,i.jsx)(`div`,{className:`flex flex-col gap-2.5`,children:a.map(e=>(0,i.jsx)(Hm,{payment:e},e.id))})})]})})]})]})}var Gm=`text-accent underline underline-offset-2 font-semibold hover:text-accent-deep transition-colors`,Km=`space-y-2 list-decimal list-inside text-foreground/75 marker:font-bold marker:text-foreground/40`;function qm({href:e,children:t}){return(0,i.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:Gm,children:t})}function Jm({children:e}){return(0,i.jsx)(`h4`,{className:`text-[12px] font-extrabold uppercase tracking-[0.14em] text-foreground/40 pt-1`,children:e})}function Ym({number:e,title:n,done:r,open:a,onToggle:o,children:s}){let c=(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`span`,{className:`w-8 h-8 shrink-0 rounded-full flex items-center justify-center text-[13.5px] font-extrabold border ${r?`bg-emerald-500/10 border-emerald-500/20 text-emerald-500`:`bg-accent/10 border-accent/20 text-accent`}`,children:r?(0,i.jsx)(t.zi,{className:`w-4 h-4`}):e}),(0,i.jsx)(`span`,{className:`flex-1 min-w-0 text-[14.5px] sm:text-[15px] font-bold text-foreground tracking-tight truncate`,children:n}),o&&(0,i.jsx)(t.Ri,{className:`w-4 h-4 shrink-0 text-foreground/40 transition-transform duration-200 ${a?`rotate-180`:``}`})]});return(0,i.jsxs)(`div`,{className:`rounded-2xl border border-[var(--panel-border)]/60 bg-foreground/[0.015] overflow-hidden transition-all`,children:[o?(0,i.jsx)(`button`,{type:`button`,onClick:o,"aria-expanded":a,className:`w-full px-4 sm:px-5 py-4 flex items-center gap-3 sm:gap-3.5 text-left cursor-pointer hover:bg-foreground/[0.02] transition-colors`,children:c}):(0,i.jsx)(`div`,{className:`w-full px-4 sm:px-5 py-4 flex items-center gap-3 sm:gap-3.5`,children:c}),(0,i.jsx)(t.pr,{initial:!1,children:a&&(0,i.jsx)(t.fr.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},className:`overflow-hidden`,children:(0,i.jsx)(`div`,{className:`border-t border-[var(--panel-border)]/40 p-4 sm:p-5 flex flex-col gap-4 bg-background/30 text-[13.5px] sm:text-[14px] text-foreground/70 leading-relaxed`,children:s})})})]})}function Xm({label:e,onDone:n,waitingFor:r}){return(0,i.jsxs)(`div`,{className:`flex flex-col gap-2 pt-1`,children:[(0,i.jsxs)(t.fr.button,{type:`button`,whileHover:r?void 0:{scale:1.01},whileTap:r?void 0:{scale:.99},onClick:n,disabled:!!r,className:`btn-primary inline-flex items-center justify-center gap-2 h-11 px-5 rounded-[var(--btn-radius,0.75rem)] text-[13px] font-bold text-white self-start max-sm:self-stretch shadow-lg ${r?`opacity-40 cursor-not-allowed`:`cursor-pointer`}`,children:[(0,i.jsx)(t.zi,{className:`w-4 h-4`}),e]}),r&&(0,i.jsx)(`span`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:r})]})}function Zm({label:e,hint:n,placeholder:a,invalid:o,value:s,clean:c,preview:l,onSave:u}){let[d,f]=(0,r.useState)(s),[p,m]=(0,r.useState)(!1),[h,g]=(0,r.useState)(``),_=c(d),v=d.trim().length>0,y=_!==s;return(0,i.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,i.jsx)(t.ft,{label:e,hint:n,value:d,onChange:e=>{f(e),g(``)},placeholder:a,error:h,action:(0,i.jsxs)(`div`,{className:`flex items-center gap-2`,children:[s&&!y&&(0,i.jsx)(t.lt,{state:`saved`,label:`Saved`}),(0,i.jsx)(t.Q,{icon:t.zi,onClick:async()=>{if(!_){g(o);return}m(!0);let e=await u(_);m(!1),g(e||``),e||f(_)},busy:p,disabled:!v||!y&&!!s,children:`Save`})]})}),_&&!h&&(0,i.jsx)(`div`,{className:`px-3.5 py-2.5 rounded-xl border border-[var(--panel-border)]/60 bg-background`,children:(0,i.jsx)(`span`,{className:`text-[12.5px] font-mono text-foreground/60 truncate block`,children:l(_)})})]})}function Qm({label:e,url:t}){return(0,i.jsxs)(`div`,{className:`flex max-sm:flex-col sm:items-center justify-between gap-2 sm:gap-3 px-3.5 py-3 rounded-xl border border-[var(--panel-border)]/60 bg-background`,children:[(0,i.jsxs)(`div`,{className:`min-w-0 flex flex-col gap-0.5`,children:[(0,i.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-[0.14em] text-foreground/40`,children:e}),(0,i.jsx)(`span`,{className:`text-[12.5px] font-mono text-foreground/70 truncate`,children:t})]}),(0,i.jsx)(Ru,{compact:!0,code:t,label:`Copy`})]})}var $m=[`216.239.32.21`,`216.239.34.21`,`216.239.36.21`,`216.239.38.21`];function eh(){let{loading:e,record:n,save:a}=Sd(),[o,s]=(0,r.useState)(null),{status:l}=od(),u=yd(n.done,o),d=e=>u[dd.indexOf(e)],f=hd(n.appName),p=_d(n.domain),m=n.done.length===dd.length,h=m&&xd(l),g=e=>{s(null),a({done:bd(n.done,e)})},_=e=>e.open?e.done?()=>s(null):void 0:()=>s(e.done?e.id:null),v=e=>{let t=d(e);return{done:t.done,open:t.open,onToggle:_(t)}};return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-6`,children:[(0,i.jsx)(Ce,{children:`Publish App`}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/publish`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-6 flex-1 pb-16`,children:[(0,i.jsx)(Fe,{}),(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.1},className:`glass-panel border border-[var(--panel-border)] rounded-3xl p-4 sm:p-6 md:p-8 shadow-2xl relative bg-background flex flex-col`,children:[(0,i.jsx)(`div`,{className:`mb-6 pb-4 sm:mb-8 sm:pb-6 border-b border-[var(--panel-border)]/50`,children:(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 sm:gap-4`,children:[(0,i.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,i.jsx)(`h2`,{className:`text-[17px] sm:text-xl font-extrabold text-foreground tracking-tight truncate`,children:`Putting your app in front of people`}),(0,i.jsxs)(`p`,{className:`text-[13px] font-medium text-foreground/50 mt-1 sm:mt-1.5 leading-snug truncate`,children:[(0,i.jsx)(`span`,{className:`sm:hidden`,children:`One step at a time. Stuck? Message me.`}),(0,i.jsx)(`span`,{className:`max-sm:hidden`,children:`One step at a time — the next one appears as you tick each off. Stuck anywhere? Message me.`})]})]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,i.jsx)(t.fr.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,i.jsx)(t.Zr,{className:`w-4 h-4`})}),(0,i.jsx)(t.fr.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,i.jsx)(bu,{className:`w-4 h-4 text-foreground/80`})})]})]})}),!e&&(0,i.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,i.jsxs)(Ym,{number:1,title:`Publish in AI Studio`,...v(`published`),children:[(0,i.jsxs)(`ol`,{className:Km,children:[(0,i.jsxs)(`li`,{children:[`In `,(0,i.jsx)(qm,{href:`https://aistudio.google.com`,children:`Google AI Studio`}),`, click`,` `,(0,i.jsx)(`strong`,{children:`Publish`}),` in the top left corner, then `,(0,i.jsx)(`strong`,{children:`Get started`}),`.`]}),(0,i.jsxs)(`li`,{children:[`It asks for an app URL. Type a name for your app —`,` `,(0,i.jsx)(`span`,{className:`text-accent`,children:`my-ai-project`}),` — and copy it, you need it again at the bottom of this step.`]}),(0,i.jsxs)(`li`,{children:[`Follow the rest of AI Studio's instructions, then click `,(0,i.jsx)(`strong`,{children:`Publish your app`}),`.`]})]}),(0,i.jsxs)(`p`,{children:[`If it says `,(0,i.jsx)(`strong`,{children:`Failed to publish app`}),`, reload the page, unpublish, and publish again. It usually goes through the second time.`]}),(0,i.jsx)(Zm,{label:`Your app name`,hint:`The name you just typed into AI Studio. Saving only keeps it for step 3 — nothing changes in AI Studio, it just says Saved. Pasting the whole address is fine; only the name is kept.`,placeholder:`my-ai-project`,invalid:`That does not look like an app name — letters, numbers and dashes.`,value:n.appName,clean:md,preview:hd,onSave:e=>a({appName:e})}),(0,i.jsx)(Xm,{label:`My app is published`,onDone:()=>g(`published`),waitingFor:n.appName?void 0:`Save your app name first — step 3 asks for this address.`})]}),d(`connected`).visible&&(0,i.jsxs)(Ym,{number:2,title:`Connect your website domain`,...v(`connected`),children:[(0,i.jsxs)(`p`,{children:[`Your app is live at `,(0,i.jsx)(`span`,{className:`font-mono text-foreground/80`,children:f||`your AI Studio address`}),` `,`already. This step puts it on a domain of your own.`]}),(0,i.jsx)(Jm,{children:`Start the mapping`}),(0,i.jsxs)(`ol`,{className:Km,children:[(0,i.jsxs)(`li`,{children:[`Back where you published, click `,(0,i.jsx)(`strong`,{children:`Advanced settings`}),`. It takes you to Google Cloud Run.`]}),(0,i.jsxs)(`li`,{children:[`In the menu on the left, open `,(0,i.jsx)(`strong`,{children:`Domain mappings`}),`, then`,` `,(0,i.jsx)(`strong`,{children:`Add mapping`}),` at the top.`]}),(0,i.jsxs)(`li`,{children:[`Choose your service, then under `,(0,i.jsx)(`strong`,{children:`Select a verified domain`}),` click`,` `,(0,i.jsx)(`strong`,{children:`Verify new domain`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Type your domain — `,(0,i.jsx)(`span`,{className:`text-accent`,children:`myaiproject.com`}),` — and click`,` `,(0,i.jsx)(`strong`,{children:`Continue`}),`, then `,(0,i.jsx)(`strong`,{children:`Verify in Search Console`}),`.`]})]}),(0,i.jsx)(Jm,{children:`Prove the domain is yours`}),(0,i.jsxs)(`ol`,{className:Km,children:[(0,i.jsxs)(`li`,{children:[`Google Search Console opens. Click `,(0,i.jsx)(`strong`,{children:`Add a website`}),`, type the same domain, and click `,(0,i.jsx)(`strong`,{children:`Continue`}),`.`]}),(0,i.jsxs)(`li`,{children:[`On the next screen, under `,(0,i.jsxs)(`em`,{children:[`Copy the TXT record below into the DNS configuration for `,gd(n.domain)||`myaiproject.com`]}),`, copy the`,` `,(0,i.jsx)(`strong`,{children:`TXT record`}),` — a long line starting`,` `,(0,i.jsx)(`span`,{className:`font-mono text-foreground/80`,children:`google-site-verification=`})]}),(0,i.jsxs)(`li`,{children:[`Open your domain registrar in another tab — GoDaddy, Namecheap, whoever you bought the domain from — go to its `,(0,i.jsx)(`strong`,{children:`DNS settings`}),`, and click`,` `,(0,i.jsx)(`strong`,{children:`Add record`}),`. Choose `,(0,i.jsx)(`strong`,{children:`TXT`}),`, paste the line into`,` `,(0,i.jsx)(`strong`,{children:`Value`}),`, and put `,(0,i.jsx)(`span`,{className:`font-mono text-foreground/80`,children:`@`}),` `,`in `,(0,i.jsx)(`strong`,{children:`Host`}),` or `,(0,i.jsx)(`strong`,{children:`Name`}),`. Save it.`]}),(0,i.jsxs)(`li`,{children:[`Back in Search Console, click `,(0,i.jsx)(`strong`,{children:`Verify`}),`.`]}),(0,i.jsxs)(`li`,{children:[`Once it is verified you are done with Search Console — close that tab. Go back to the Google Cloud Run tab (`,(0,i.jsx)(`span`,{className:`font-mono text-foreground/80`,children:`console.cloud.google.com`}),`) where you clicked to verify, and press its `,(0,i.jsx)(`strong`,{children:`refresh`}),` button. It should say `,(0,i.jsxs)(`em`,{children:[`Your ownership of `,gd(n.domain)||`myaiproject.com`,` has been successfully verified. You can now map this domain to your Cloud Run services.`]})]})]}),(0,i.jsx)(Jm,{children:`Point the domain at your app`}),(0,i.jsxs)(`ol`,{className:Km,children:[(0,i.jsxs)(`li`,{children:[`Add a subdomain if you want one, then click `,(0,i.jsx)(`strong`,{children:`Continue`}),`. Cloud Run now shows you the records to add.`]}),(0,i.jsxs)(`li`,{children:[`Back at your registrar, add each one as an `,(0,i.jsx)(`strong`,{children:`A record`}),`, the same way you added the TXT. It is normally these four:`]})]}),(0,i.jsxs)(`div`,{className:`rounded-xl border border-[var(--panel-border)]/60 bg-background overflow-hidden`,children:[(0,i.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3.5 py-2.5 border-b border-[var(--panel-border)]/40`,children:[(0,i.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-[0.14em] text-foreground/40`,children:`A records`}),(0,i.jsx)(Ru,{compact:!0,code:$m.join(`
|
|
678
|
+
`),label:`Copy all four`})]}),(0,i.jsx)(`div`,{className:`px-3.5 py-2.5 flex flex-col gap-1`,children:$m.map(e=>(0,i.jsx)(`span`,{className:`text-[12.5px] font-mono text-foreground/70`,children:e},e))})]}),(0,i.jsx)(`p`,{className:`text-[11px] sm:text-[11.5px] text-foreground/40 font-medium leading-snug`,children:`Use whatever your own Cloud Run screen shows if it differs from these — that screen is always right.`}),(0,i.jsxs)(`p`,{children:[`Once they are all in, press `,(0,i.jsx)(`strong`,{children:`Done`}),` in Cloud Run and wait — this can take an hour or more. Check every few minutes by typing your domain into any browser, like `,(0,i.jsx)(`span`,{className:`text-accent`,children:`myaiproject.com`}),`: when your published app comes up, it is connected.`]}),(0,i.jsx)(Zm,{label:`Your domain`,hint:`However you have it — with or without https:// and www. Only the domain itself is kept, for step 3.`,placeholder:`myaiproject.com`,invalid:`That does not look like a domain — something like myaiproject.com.`,value:n.domain,clean:gd,preview:_d,onSave:e=>a({domain:e})}),(0,i.jsx)(Xm,{label:`My domain is verified and my app is connected`,onDone:()=>g(`connected`),waitingFor:n.domain?void 0:`Save your domain first — step 3 asks for this address.`})]}),d(`authorised`).visible&&(0,i.jsxs)(Ym,{number:3,title:`Add your domains and email sender`,...v(`authorised`),children:[(0,i.jsxs)(`p`,{children:[`Once your domain answers, head back to the`,` `,(0,i.jsx)(qm,{href:`https://console.firebase.google.com`,children:`Firebase console`}),`. Two jobs, both under `,(0,i.jsx)(`strong`,{children:`Security → Authentication`}),`.`]}),(0,i.jsx)(Jm,{children:`Authorise both addresses`}),(0,i.jsxs)(`p`,{children:[`Nobody can sign in from an address Firebase does not know. Open`,` `,(0,i.jsx)(`strong`,{children:`Security → Authentication → Settings → Authorised domains`}),`, click`,` `,(0,i.jsx)(`strong`,{children:`Add domain`}),`, and paste these in one at a time — both need to be there.`]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,i.jsx)(Qm,{label:`Your AI Studio address`,url:f?`${md(n.appName)}.ai.studio`:`—`}),(0,i.jsx)(Qm,{label:`Your own domain`,url:gd(n.domain)||`—`})]}),(0,i.jsx)(Jm,{children:`Send email from your own domain`}),(0,i.jsxs)(`ol`,{className:Km,children:[(0,i.jsxs)(`li`,{children:[`On the same Authentication page, open the `,(0,i.jsx)(`strong`,{children:`Templates`}),` tab. Every email Firebase sends for you lives here — password changes, email verification. You can reword them, but the one thing worth doing is the sender.`]}),(0,i.jsxs)(`li`,{children:[`Click the pencil beside `,(0,i.jsx)(`strong`,{children:`From`}),`. It will be something like`,` `,(0,i.jsx)(`span`,{className:`font-mono text-foreground/80`,children:`noreply@your-project.firebaseapp.com`})]}),(0,i.jsxs)(`li`,{children:[`On the right, click `,(0,i.jsx)(`strong`,{children:`Customise domain`}),`, enter your own domain, and follow the steps it gives you — more records at your registrar, same as before.`]})]}),(0,i.jsx)(`p`,{children:`This is what keeps your emails out of people's spam folders, and it is why they arrive looking like they came from you.`}),(0,i.jsx)(Xm,{label:`I've added my domains and verified my email domain`,onDone:()=>g(`authorised`)})]}),h&&(0,i.jsxs)(Ym,{number:4,title:`Finalise your Stripe live setup`,done:!1,open:!0,children:[(0,i.jsx)(`p`,{children:`Your payments are not live yet — still on practice cards, or live without the webhook that sends receipts. Finish Go live on the Payments screen and your setup is complete.`}),(0,i.jsxs)(`p`,{children:[`Switch `,(0,i.jsx)(`strong`,{children:`Go live`}),` on and follow its steps. Its webhook step was waiting for your published address, and it is open now that step 3 is ticked.`]}),(0,i.jsxs)(c.Link,{to:`/payments`,className:`btn-primary inline-flex items-center justify-center gap-2 h-11 px-5 rounded-[var(--btn-radius,0.75rem)] text-[13px] font-bold text-white self-start max-sm:self-stretch shadow-lg cursor-pointer`,children:[(0,i.jsx)(t.wi,{className:`w-4 h-4`}),`Take me to Go live`]})]}),m&&!h&&(0,i.jsxs)(`div`,{className:`mt-3 flex max-sm:flex-col sm:items-center gap-4 sm:gap-6 p-5 sm:p-6 rounded-2xl border border-emerald-500/20 bg-emerald-500/[0.06]`,children:[(0,i.jsx)(`div`,{className:`w-10 h-10 shrink-0 rounded-2xl flex items-center justify-center border border-emerald-500/20 bg-emerald-500/10 text-emerald-500`,children:(0,i.jsx)(t.zr,{className:`w-5 h-5`})}),(0,i.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,i.jsx)(`h3`,{className:`text-[15px] font-extrabold text-foreground tracking-tight`,children:`Your app is live`}),(0,i.jsxs)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed mt-1`,children:[p?(0,i.jsxs)(i.Fragment,{children:[`Anyone can open `,(0,i.jsx)(qm,{href:p,children:gd(n.domain)}),` and sign up.`]}):(0,i.jsx)(i.Fragment,{children:`Anyone can open your app and sign up.`}),` `,`Any step above opens again if you need to check what you typed.`]})]})]})]})]})]})]})}var th={contentKey:`dashboard`};function nh(){let{user:e}=t.na(),n=t.Na(),[a,o]=(0,r.useState)(null),[s,c]=(0,r.useState)(()=>typeof window<`u`&&!Am(th));(0,r.useEffect)(()=>{if(Am(th))return;let e=!1;Nm(th).then(t=>{e||(t&&o(()=>t),c(!1))});let t=setTimeout(()=>{e||c(!1)},4e3);return()=>{e=!0,clearTimeout(t)}},[]);let l=n.microcomponents?.dashboard||(typeof window<`u`?window.__FBOS_MICROCOMPONENTS__?.dashboard:void 0)||a||void 0,u=(e?.displayName||e?.email?.split(`@`)[0]||`there`).split(` `)[0],d=u.charAt(0).toUpperCase()+u.slice(1);return(0,i.jsxs)(`main`,{className:`flex-1 w-full max-w-7xl mx-auto p-4 pt-2 md:p-8 md:pt-4 z-10 flex flex-col min-h-screen`,children:[(0,i.jsxs)(t.fr.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:`mb-8`,children:[(0,i.jsxs)(Ce,{children:[`Welcome back, `,d,`.`]}),(0,i.jsxs)(`div`,{className:`flex items-center gap-2 text-foreground/40 font-bold uppercase tracking-[0.2em] text-[11px]`,children:[(0,i.jsx)(`span`,{className:`w-8 h-[1px] bg-foreground/10`}),`/dashboard`]})]}),(0,i.jsxs)(`div`,{className:`flex flex-col gap-4 flex-1 min-h-[500px]`,children:[(0,i.jsx)(`div`,{className:`flex justify-start`,children:(0,i.jsx)(Fe,{})}),(0,i.jsxs)(`div`,{className:`w-full flex-1 glass-panel rounded-3xl relative overflow-hidden border border-[var(--panel-border)] shadow-2xl bg-[var(--panel-bg)] ${l?`p-6 md:p-8`:`p-8 md:p-12 flex items-center justify-center`}`,children:[(0,i.jsx)(`div`,{className:`absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-64 h-64 bg-accent/10 blur-[100px] rounded-full pointer-events-none`}),l?(0,i.jsx)(`div`,{className:`fbos-content-slot relative z-10`,children:(0,i.jsx)(l,{})}):s?(0,i.jsx)(t.ti,{className:`w-6 h-6 text-accent animate-spin relative z-10`}):(0,i.jsx)(t.pr,{mode:`wait`,children:(0,i.jsxs)(t.fr.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,i.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,i.jsx)(t.Ci,{className:`w-6 h-6`})}),(0,i.jsx)(`h2`,{className:`text-2xl font-extrabold text-foreground mb-2`,children:`No data added here yet`}),(0,i.jsx)(`p`,{className:`text-foreground/40 font-medium`,children:`Keep moving forward, your data will appear here.`})]})})]})]})]})}var rh=()=>(0,i.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,i.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,i.jsx)(t.Ci,{className:`w-6 h-6 text-accent animate-pulse`})}),(0,i.jsxs)(`div`,{className:`flex items-center gap-3 glass-panel px-5 py-2.5 rounded-full border border-[var(--panel-border)]`,children:[(0,i.jsx)(`div`,{className:`w-4 h-4 border-2 border-accent border-t-transparent rounded-full animate-spin`}),(0,i.jsx)(`span`,{className:`text-[13px] font-bold tracking-widest uppercase text-foreground/70`,children:`Connecting`})]})]});function ih({level:e,children:n}){let{user:r,userRole:a,loading:o,userInactive:s,signOut:l,roleResolved:u}=t.na(),d=(0,c.useLocation)();return o||!u?(0,i.jsx)(rh,{}):r?s?(0,i.jsx)(yi,{tone:`red`,title:`Access Denied`,message:`You don't have access to this app. Please contact the administrator.`,action:(0,i.jsx)(`button`,{onClick:()=>l(),className:bi,children:`Sign Out`})}):r.emailVerified?e===`admin`&&!t.pa(a)?(0,i.jsx)(Ti,{}):e===`internal`&&!t.fa(a)?(0,i.jsx)(wi,{}):(0,i.jsx)(i.Fragment,{children:n}):(0,i.jsx)(c.Navigate,{to:`/verify`}):(0,i.jsx)(c.Navigate,{to:`/login?from=${encodeURIComponent(d.pathname)}`,replace:!0})}var ah=({children:e})=>(0,i.jsx)(ih,{level:`signed-in`,children:e}),oh=({children:e})=>(0,i.jsx)(ih,{level:`admin`,children:e}),sh=({children:e})=>(0,i.jsx)(ih,{level:`internal`,children:e});function ch({children:e}){let{user:n,loading:r,roleResolved:a}=t.na(),[o]=(0,c.useSearchParams)();return r||!a?(0,i.jsx)(rh,{}):n&&n.emailVerified?(0,i.jsx)(c.Navigate,{to:o.get(`from`)||`/dashboard`,replace:!0}):(0,i.jsx)(i.Fragment,{children:e})}function lh({children:e}){let{user:n,loading:r,roleResolved:a}=t.na();return r||!a?(0,i.jsx)(rh,{}):n?n.emailVerified?(0,i.jsx)(c.Navigate,{to:`/dashboard`}):(0,i.jsx)(i.Fragment,{children:e}):(0,i.jsx)(c.Navigate,{to:`/`})}function uh({to:e}){return(0,i.jsx)(c.Navigate,{to:`${e}${(0,c.useLocation)().search}`,replace:!0})}function dh(){return(0,i.jsxs)(`div`,{className:`fixed top-0 left-0 w-full h-full pointer-events-none -z-0 overflow-hidden`,children:[(0,i.jsx)(t.fr.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,i.jsx)(t.fr.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 fh(){let e=t.Na().components?.Home||se,n=(0,c.useNavigate)();return(0,i.jsx)(t.ta,{onSignedOut:()=>n(`/`,{replace:!0}),children:(0,i.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,i.jsx)(oe,{}),(0,i.jsxs)(c.Routes,{children:[(0,i.jsx)(c.Route,{path:`/`,element:(0,i.jsx)(ch,{children:(0,i.jsx)(`div`,{className:`fbos-home-slot contents`,children:(0,i.jsx)(e,{})})})}),(0,i.jsx)(c.Route,{path:`/register`,element:(0,i.jsx)(ch,{children:(0,i.jsx)(ve,{})})}),(0,i.jsx)(c.Route,{path:`/login`,element:(0,i.jsx)(ch,{children:(0,i.jsx)(ye,{})})}),(0,i.jsx)(c.Route,{path:`/reset-password`,element:(0,i.jsx)(ch,{children:(0,i.jsx)(Le,{})})}),(0,i.jsx)(c.Route,{path:`/verify`,element:(0,i.jsx)(lh,{children:(0,i.jsx)(be,{})})}),(0,i.jsx)(c.Route,{path:`/book/:id`,element:(0,i.jsx)(Vp,{})}),(0,i.jsx)(c.Route,{path:`/meet/:id`,element:(0,i.jsx)(Xp,{})}),(0,i.jsx)(c.Route,{path:`/pay/:id`,element:(0,i.jsx)(Qp,{})}),(0,i.jsx)(c.Route,{path:`/payment-complete`,element:(0,i.jsx)(Rm,{})}),(0,i.jsx)(c.Route,{path:`/payment-cancelled`,element:(0,i.jsx)(Rm,{cancelled:!0})}),(0,i.jsx)(c.Route,{path:`/guide`,element:(0,i.jsx)(fn,{})}),(0,i.jsx)(c.Route,{path:`/templates`,element:(0,i.jsx)(Zt,{})}),(0,i.jsx)(c.Route,{path:`/board`,element:(0,i.jsx)(vn,{})}),(0,i.jsx)(c.Route,{path:`/table`,element:(0,i.jsx)(qr,{})}),(0,i.jsx)(c.Route,{path:`/calendar`,element:(0,i.jsx)(Xr,{})}),(0,i.jsx)(c.Route,{path:`/drive`,element:(0,i.jsx)(Kt,{})}),(0,i.jsx)(c.Route,{path:`/inline_form`,element:(0,i.jsx)(pn,{})}),(0,i.jsx)(c.Route,{path:`/popup_form`,element:(0,i.jsx)(mn,{})}),(0,i.jsx)(c.Route,{path:`/users`,element:(0,i.jsx)(oh,{children:(0,i.jsx)(Dt,{})})}),(0,i.jsx)(c.Route,{path:`/users/:id`,element:(0,i.jsx)(oh,{children:(0,i.jsx)(Dt,{})})}),(0,i.jsx)(c.Route,{path:`/inbox`,element:(0,i.jsx)(oh,{children:(0,i.jsx)(Ht,{})})}),(0,i.jsx)(c.Route,{path:`/payments`,element:(0,i.jsx)(oh,{children:(0,i.jsx)(Zd,{})})}),(0,i.jsx)(c.Route,{path:`/schedule`,element:(0,i.jsx)(sh,{children:(0,i.jsx)(Cp,{})})}),(0,i.jsx)(c.Route,{path:`/my-calendar`,element:(0,i.jsx)(uh,{to:`/schedule`})}),(0,i.jsx)(c.Route,{path:`/my-bookings`,element:(0,i.jsx)(ah,{children:(0,i.jsx)(wp,{})})}),(0,i.jsx)(c.Route,{path:`/email`,element:(0,i.jsx)(oh,{children:(0,i.jsx)(um,{})})}),(0,i.jsx)(c.Route,{path:`/submissions`,element:(0,i.jsx)(c.Navigate,{to:`/inbox`,replace:!0})}),(0,i.jsx)(c.Route,{path:`/requests`,element:(0,i.jsx)(c.Navigate,{to:`/inbox`,replace:!0})}),(0,i.jsx)(c.Route,{path:`/assets`,element:(0,i.jsx)(oh,{children:(0,i.jsx)(Xt,{})})}),(0,i.jsx)(c.Route,{path:`/drive/:rest`,element:(0,i.jsx)(c.Navigate,{to:`/assets`,replace:!0})}),(0,i.jsx)(c.Route,{path:`/theme`,element:(0,i.jsx)(oh,{children:(0,i.jsx)(vi,{})})}),(0,i.jsx)(c.Route,{path:`/pages/*`,element:(0,i.jsx)(oh,{children:(0,i.jsx)(Ml,{})})}),(0,i.jsx)(c.Route,{path:`/forms/*`,element:(0,i.jsx)(oh,{children:(0,i.jsx)(ql,{})})}),(0,i.jsx)(c.Route,{path:`/settings`,element:(0,i.jsx)(c.Navigate,{to:`/pages`,replace:!0})}),(0,i.jsx)(c.Route,{path:`/profile`,element:(0,i.jsx)(ah,{children:(0,i.jsx)(Ie,{})})}),(0,i.jsx)(c.Route,{path:`/billing`,element:(0,i.jsx)(ah,{children:(0,i.jsx)(Wm,{})})}),(0,i.jsx)(c.Route,{path:`/dashboard`,element:(0,i.jsx)(ah,{children:(0,i.jsx)(nh,{})})}),(0,i.jsx)(c.Route,{path:`/publish`,element:(0,i.jsx)(oh,{children:(0,i.jsx)(eh,{})})}),(0,i.jsx)(c.Route,{path:`/setup`,element:(0,i.jsx)(Zu,{})}),(0,i.jsx)(c.Route,{path:`/setup/payments`,element:(0,i.jsx)(Gd,{})}),(0,i.jsx)(c.Route,{path:`*`,element:(0,i.jsx)(Fm,{})})]}),(0,i.jsx)(dh,{})]})})}function ph(){return(0,i.jsx)(c.BrowserRouter,{children:(0,i.jsx)(mh,{})})}function mh(){let e=t.Na();return e.firebaseConfig&&e.firebaseConfig.apiKey&&e.firebaseConfig.apiKey.trim()!==``&&e.firebaseConfig.projectId&&e.firebaseConfig.projectId.trim()!==``||Nu()?(0,i.jsx)(fh,{}):(0,i.jsxs)(`div`,{className:`min-h-screen relative flex flex-col overflow-x-hidden`,children:[(0,i.jsx)(oe,{standalone:!0}),(0,i.jsx)(Zu,{standalone:!0}),(0,i.jsx)(dh,{})]})}function hh(e){v();let n=e.firebaseConfig;return n&&n.apiKey&&n.apiKey.trim()!==``&&n.projectId&&n.projectId.trim()!==``&&t.Oa(n),(0,i.jsx)(t.Ma,{config:{firebaseConfig:e.firebaseConfig,basename:e.basename,onAuthChange:e.onAuthChange,themeConfig:e.themeConfig,components:e.components,customRoutes:e.customRoutes,microcomponents:e.microcomponents,defaultConfigs:e.defaultConfigs},children:(0,i.jsx)(t.Aa,{children:(0,i.jsx)(`div`,{className:`firebase-os flex-1 flex flex-col min-h-screen`,style:{background:`var(--bg-gradient)`,color:`var(--fg-color)`},children:(0,i.jsx)(ph,{})})})})}var gh=Object.assign({}),_h={};for(let e in gh){let t=gh[e];if(!t?.default)continue;let n=e.replace(`./`,``).replace(`.tsx`,``);if(n===`registry`)continue;let r=n.replace(/Content$/,``).replace(/([a-z0-9])([A-Z])/g,`$1_$2`).toLowerCase();_h[r]=t.default,_h[r.replace(/_/g,``)]=t.default}if(typeof window<`u`){let e=window.__FBOS_MICROCOMPONENTS__||{};window.__FBOS_MICROCOMPONENTS__={..._h,...e}}var vh=(e,t)=>{let n=e.toLowerCase().replace(/[^a-z0-9]+/g,`_`),r=n.replace(/_/g,``);if(_h[n]=t,_h[r]=t,typeof window<`u`){let e=window.__FBOS_MICROCOMPONENTS__||{};window.__FBOS_MICROCOMPONENTS__={...e,[n]:t,[r]:t}}},yh=({title:e,className:n,children:r,...a})=>(0,i.jsxs)(`div`,{className:t.ur(`border border-[var(--panel-border)] bg-[var(--panel-bg)] px-5 py-4`,n),style:{borderRadius:`var(--card-radius, 1rem)`},...a,children:[e?(0,i.jsx)(`p`,{className:`text-[12px] font-extrabold tracking-tight text-gradient mb-1.5`,children:e}):null,r]});yh.displayName=`Card`;var bh=({sub:e,className:n,children:r,...a})=>(0,i.jsxs)(`div`,{className:t.ur(`mb-4`,n),children:[(0,i.jsx)(`h2`,{className:`text-xl md:text-2xl font-extrabold tracking-tight text-foreground`,...a,children:r}),e?(0,i.jsx)(`p`,{className:`text-[13px] text-foreground/60 font-medium leading-relaxed mt-1`,children:e}):null]});bh.displayName=`SectionHeading`,exports.AdminNotifications=O,exports.Button=t.cr,exports.Card=yh,exports.ConfirmModal=Ve,exports.ContactPopup=t.t,exports.CustomSelect=t.sr,exports.DashboardNav=Fe,exports.EventCard=kf,exports.FirebaseOS=hh,exports.Input=t.lr,exports.ManagePlanButton=zm,exports.Navbar=oe,exports.PayButton=Zp,exports.PhoneInputField=n.t,exports.SectionHeading=bh,exports.TimeChips=t.q,exports.acceptBooking=t.n,Object.defineProperty(exports,`auth`,{enumerable:!0,get:function(){return t.Ea}}),exports.availableSlots=t.zt,exports.availableSlotsFor=t.Bt,exports.blockedWindows=t.Ut,exports.bookingPath=t.Qt,exports.cancelBooking=t.i,exports.confirmPayment=ee,exports.dayBlocked=t.rn,exports.daysLine=t.in,Object.defineProperty(exports,`db`,{enumerable:!0,get:function(){return t.Da}}),exports.emailAnyone=Za,exports.emailOwner=Ya,exports.emailPerson=Xa,exports.emailStatus=Qa,exports.eventName=t.cn,exports.hoursSummary=t._n,exports.meetPath=ro,exports.notify=S,exports.oneEach=t.En,exports.openBillingPortal=G,exports.partySlots=t.On,exports.payPath=t.kn,exports.registerMicrocomponent=vh,exports.scheduleName=t.Mn,exports.scheduleTitle=t.In,exports.slotsFor=t.Un,exports.startCheckout=U,Object.defineProperty(exports,`storage`,{enumerable:!0,get:function(){return t.ka}}),exports.timeZoneLabel=t.Kn,exports.togetherSlots=t.Xn,exports.useAuth=t.na,exports.useBookings=t.g,exports.useConfig=t.Na,exports.useMemberSchedules=t._,exports.useMyPayments=te,exports.usePaymentsEnabled=Y,exports.useSales=ne,exports.useTakenSlots=t.x,exports.useTeamHours=t.S,exports.useTheme=t.ja;
|