1import{j as e,h as b,a5 as A}from"./index-C3hYg7Vm.js";import{e as _,r as n,L as S}from"./react-DaZfdddc.js";import{C as N,B as h,P as E,A as k,E as F,F as v,T as w,S as C}from"./ui-Bc_efa8_.js";import{F as L}from"./dashIcons-B03TTgmr.js";import{I}from"./InstallPanel-DjYndMsA.js";import{u as P}from"./useAsync-D_8S-tHt.js";function U({project:l,onDone:t}){return e.jsxs(N,{className:"overflow-hidden",children:[e.jsxs("div",{className:"border-b border-slate-100 bg-gradient-to-br from-brand-50 to-white px-6 py-6",children:[e.jsx("span",{className:"inline-flex items-center rounded-full bg-emerald-100 px-2.5 py-1 text-xs font-medium text-emerald-700",children:"Project created"}),e.jsxs("h2",{className:"mt-2 font-display text-xl font-bold text-slate-900",children:["Get ",l.name," live"]}),e.jsx("p",{className:"mt-1 max-w-xl text-sm text-slate-600",children:"Choose one way to install the widget. We confirm the moment your site checks in."})]}),e.jsx("div",{className:"px-6 py-5",children:e.jsx(I,{project:l})}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 border-t border-slate-100 px-6 py-4",children:[e.jsx("p",{className:"text-xs text-slate-500",children:"You can always find your snippet and key on the project's settings page."}),e.jsx(h,{onClick:t,children:"Go to project"})]})]})}function D(l){return l.split(/[\n,]/).map(t=>t.trim()).filter(t=>t.length>0)}function O(){return e.jsxs(N,{className:"h-full p-5",children:[e.jsx(C,{className:"h-5 w-2/3"}),e.jsx(C,{className:"mt-3 h-4 w-1/2"}),e.jsx(C,{className:"mt-6 h-3 w-1/3"})]})}function $(){var f;const l=_(),{data:t,loading:m,error:p,reload:g}=P(()=>b.listProjects(),[]),{data:s}=P(()=>b.getSubscription(),[]),[c,x]=n.useState(!1),[o,u]=n.useState(null),d=(s==null?void 0:s.plan.limits.max_projects)??0,j=(t==null?void 0:t.length)??((f=s==null?void 0:s.usage)==null?void 0:f.projects)??0,i=d>0&&j>=d;return e.jsxs("div",{className:"space-y-6",children:[e.jsx(E,{eyebrow:"Workspace",title:"Projects",description:"Each project gets its own widget and ingest key.",actions:e.jsx(h,{onClick:()=>x(a=>!a),disabled:i&&!c,children:c?"Close":"New project"})}),s?e.jsxs("p",{className:"-mt-2 text-xs text-slate-400",children:[e.jsxs("span",{className:i?"font-medium text-amber-600":"",children:[j," / ",d>0?d:"Unlimited"," projects"]})," ","on the ",s.plan.name," plan"]}):null,i&&!c?e.jsxs(k,{tone:"info",children:["You have reached the ",d,"-project limit on the ",s==null?void 0:s.plan.name," plan."," ",e.jsx(S,{to:"/billing",className:"font-medium underline",children:"Upgrade your plan"})," ","to add more projects."]}):null,c?e.jsx(W,{onCancel:()=>x(!1),onCreated:a=>{x(!1),u(a)}}):null,o?e.jsx(U,{project:o,onDone:()=>l(`/projects/${o.id}`)}):null,m&&!o?e.jsx("div",{className:"grid gap-4 sm:grid-cols-2",children:Array.from({length:4}).map((a,r)=>e.jsx(O,{},r))}):null,p?e.jsx(k,{children:p}):null,!m&&!p&&t&&t.length===0?e.jsx(F,{icon:e.jsx(L,{className:"h-6 w-6"}),title:"No projects yet",description:"Create your first project to get a widget snippet and ingest key. Your AI agent gets full context from every note.",action:e.jsx(h,{onClick:()=>x(!0),children:"New project"})}):null,!m&&t&&t.length>0&&!o?e.jsx("div",{className:"grid gap-4 sm:grid-cols-2",children:t.map(a=>e.jsx(S,{to:`/projects/${a.id}`,children:e.jsxs(N,{hover:!0,className:"h-full p-5",children:[e.jsx("h2",{className:"text-lg font-semibold text-slate-900",children:a.name}),e.jsx("p",{className:"mt-1 truncate text-sm text-slate-500",children:a.website_url??"No website set"}),e.jsxs("p",{className:"mt-4 text-xs text-slate-400",children:["Created ",new Date(a.created_at).toLocaleDateString()]})]})},a.id))}):null,p?e.jsx(h,{variant:"secondary",onClick:()=>g(),children:"Retry"}):null]})}function W({onCreated:l,onCancel:t}){const[m,p]=n.useState(""),[g,s]=n.useState(""),[c,x]=n.useState(""),[o,u]=n.useState(null),[d,j]=n.useState(!1),[i,f]=n.useState(!1);n.useEffect(()=>{b.trackActivation("project_form_viewed")},[]);async function a(r){if(r.preventDefault(),!i){u("Please confirm you have permission to capture from this website or application.");return}u(null),j(!0);try{const y=await b.createProject({name:m.trim(),website_url:g.trim()||void 0,allowed_origins:D(c),accept_permission:i});l(y)}catch(y){u(y instanceof A?y.message:"Could not create the project.")}finally{j(!1)}}return e.jsx(N,{className:"p-5",children:e.jsxs("form",{onSubmit:a,className:"space-y-4",children:[o?e.jsx(k,{children:o}):null,e.jsx(v,{label:"Project name",htmlFor:"project-name",children:e.jsx(w,{id:"project-name",required:!0,placeholder:"Marketing site",value:m,onChange:r=>p(r.target.value)})}),e.jsx(v,{label:"Website URL",htmlFor:"project-url",hint:"Optional, but helps you recognise it.",children:e.jsx(w,{id:"project-url",type:"url",placeholder:"https://example.com",value:g,onChange:r=>s(r.target.value)})}),e.jsx(v,{label:"Allowed origins",htmlFor:"project-origins",hint:"One per line or comma-separated. Leave empty to allow any origin during development.",children:e.jsx(w,{id:"project-origins",placeholder:"https://example.com",value:c,onChange:r=>x(r.target.value)})}),e.jsxs("label",{className:"flex items-start gap-2.5 rounded-lg border border-slate-200 bg-slate-50 p-3 text-sm text-slate-600",children:[e.jsx("input",{type:"checkbox",required:!0,checked:i,onChange:r=>f(r.target.checked),className:"mt-0.5 h-4 w-4 shrink-0 rounded border-slate-300 text-brand-600 focus:ring-brand-500"}),e.jsx("span",{children:"I confirm that I have permission to capture, store, and share information from this website or application."})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(h,{type:"submit",busy:d,disabled:!i,children:"Create project"}),e.jsx(h,{type:"button",variant:"secondary",onClick:t,children:"Cancel"})]})]})})}export{$ as ProjectsPage};
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.