1import{u as D,r as c,s as o,j as e}from"./index-BpVKUgHF.js";import{c as u,L as v}from"./loader-circle-CKHymYzG.js";const E=[["path",{d:"M12 15V3",key:"m9g1x1"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["path",{d:"m7 10 5 5 5-5",key:"brsn70"}]],O=u("download",E);const A=[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]],w=u("log-out",A);const R=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],V=u("trash-2",R);function U(){const l=D(),[k,h]=c.useState(!0),[_,p]=c.useState(!1),[r,g]=c.useState([]),[S,f]=c.useState(!1),[j,b]=c.useState(null);c.useEffect(()=>{let t=!0;async function s(){const{data:a}=await o.auth.getSession();if(!a.session){l({to:"/login"});return}const n=a.session.user.id,{data:i,error:m}=await o.from("user_roles").select("role").eq("user_id",n);if(t){if(m||!i||!i.some(x=>x.role==="admin")){h(!1),p(!1);return}p(!0),h(!1),L()}}s();const{data:d}=o.auth.onAuthStateChange((a,n)=>{n||l({to:"/login"})});return()=>{t=!1,d.subscription.unsubscribe()}},[]);async function L(){f(!0),b(null);const{data:t,error:s}=await o.from("leads").select("*").order("created_at",{ascending:!1});s?b(s.message):g(t),f(!1)}async function y(){await o.auth.signOut(),l({to:"/login"})}async function C(t){if(!confirm("Delete this lead?"))return;const{error:s}=await o.from("leads").delete().eq("id",t);if(s){alert(s.message);return}g(d=>d.filter(a=>a.id!==t))}function M(){const t=["created_at","first_name","last_name","email","age","gender","weight_lb","height_in","activity","goal","calories","protein","carbs","fats","bmr","tdee"],s=r.map(m=>t.map(x=>{const N=m[x];return`"${(N==null?"":String(N)).replace(/"/g,'""')}"`}).join(",")),d=[t.join(","),...s].join(` 2`),a=new Blob([d],{type:"text/csv"}),n=URL.createObjectURL(a),i=document.createElement("a");i.href=n,i.download=`leads-${new Date().toISOString().slice(0,10)}.csv`,i.click(),URL.revokeObjectURL(n)}return k?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsx(v,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):_?e.jsxs("main",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"border-b border-border bg-card",children:e.jsxs("div",{className:"mx-auto max-w-6xl px-6 py-4 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold",children:"Leads"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[r.length," submission",r.length===1?"":"s"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:M,disabled:!r.length,className:"inline-flex items-center gap-2 rounded-md border border-border bg-background px-3 py-2 text-sm font-medium hover:bg-accent transition disabled:opacity-50",children:[e.jsx(O,{className:"h-4 w-4"})," CSV"]}),e.jsxs("button",{onClick:y,className:"inline-flex items-center gap-2 rounded-md bg-primary px-3 py-2 text-sm font-medium text-primary-foreground hover:opacity-90 transition",children:[e.jsx(w,{className:"h-4 w-4"})," Sign out"]})]})]})}),e.jsx("div",{className:"mx-auto max-w-6xl px-6 py-8",children:S?e.jsx("div",{className:"flex items-center justify-center py-20 text-muted-foreground",children:e.jsx(v,{className:"h-5 w-5 animate-spin"})}):j?e.jsx("div",{className:"text-center py-20 text-destructive",children:j}):r.length===0?e.jsx("div",{className:"text-center py-20 text-muted-foreground",children:"No leads yet."}):e.jsx("div",{className:"overflow-x-auto rounded-xl border border-border bg-card",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/40 text-left text-xs uppercase tracking-wider text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3",children:"Date"}),e.jsx("th",{className:"px-4 py-3",children:"Name"}),e.jsx("th",{className:"px-4 py-3",children:"Email"}),e.jsx("th",{className:"px-4 py-3",children:"Goal"}),e.jsx("th",{className:"px-4 py-3 text-right",children:"Calories"}),e.jsx("th",{className:"px-4 py-3 text-right",children:"P/C/F"}),e.jsx("th",{className:"px-4 py-3"})]})}),e.jsx("tbody",{children:r.map(t=>e.jsxs("tr",{className:"border-t border-border hover:bg-muted/20",children:[e.jsx("td",{className:"px-4 py-3 text-muted-foreground whitespace-nowrap",children:new Date(t.created_at).toLocaleStr
2ing()}),e.jsxs("td",{className:"px-4 py-3 font-medium",children:[t.first_name," ",t.last_name]}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("a",{href:`mailto:${t.email}`,className:"text-primary hover:underline",children:t.email})}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground",children:t.goal??"â"}),e.jsx("td",{className:"px-4 py-3 text-right font-semibold",children:t.calories??"â"}),e.jsxs("td",{className:"px-4 py-3 text-right text-muted-foreground",children:[t.protein??"â","/",t.carbs??"â","/",t.fats??"â"]}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsx("button",{onClick:()=>C(t.id),className:"text-muted-foreground hover:text-destructive transition","aria-label":"Delete",children:e.jsx(V,{className:"h-4 w-4"})})})]},t.id))})]})})})]}):e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background px-4",children:e.jsxs("div",{className:"max-w-md text-center",children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Access denied"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Your account is signed in but doesn't have admin access."}),e.jsxs("button",{onClick:y,className:"mt-6 inline-flex items-center gap-2 rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground",children:[e.jsx(w,{className:"h-4 w-4"})," Sign out"]})]})})}export{U as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.