1import{r as o,j as e}from"./index-BAXqC3uG.js";import{A as Y,a as $,b as R,c as q,d as H,e as O}from"./adaptive-dialog-DI7HP9ob.js";import{Capacitor as re}from"./index-DzAmrokj.js";import{A as ye}from"./AppBackLink-JcRGhY0r.js";import{u as ve}from"./useProjects-6SpnplBS.js";import{c as Ne,j as me,s as b,B as c,Q as N,g as be,cH as ae,bp as Ce,P as Pe,l as U,I as we,D as ne,cI as _e}from"./App-DZ8XJ0eL.js";import{T as ke}from"./textarea-B-W4bMR8.js";import{C as ie,a as oe,b as Ee,c as Se}from"./card-hkK_ih52.js";import{C as Ae}from"./checkbox-BWUnr1wL.js";import{B as le}from"./building-2-CL38oP3e.js";import{F as ce}from"./folder-tree-CFyjZzDS.js";import{T as Fe}from"./trash-2-4Z_Ns9i3.js";import{L as De}from"./layers-D7yj2FZF.js";import"./chevron-left-fs4Ok3UP.js";import"./index-W8QR2Uvi.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const de=Ne("FolderPlus",[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);function Te({project:r,open:p,onClose:h,onSaved:G}){const{user:_}=me(),[k,K]=o.useState([]),[E,f]=o.useState(new Set),[S,C]=o.useState(!1),[x,g]=o.useState(!1);o.useEffect(()=>{!p||!_||!r||(C(!0),b.from("experiences").select("id, name, is_published, project_id").eq("owner_id",_.id).order("updated_at",{ascending:!1}).then(({data:t})=>{const m=t??[];K(m),f(new Set(m.filter(n=>n.project_id===r.id).map(n=>n.id))),C(!1)}))},[p,_,r]);const L=t=>{f(m=>{const n=new Set(m);return n.has(t)?n.delete(t):n.add(t),n})},A=async()=>{if(!r)return;g(!0);const t=new Set(k.filter(l=>l.project_id===r.id).map(l=>l.id)),m=[...E].filter(l=>!t.has(l)),n=[...t].filter(l=>!E.has(l));if(m.length===0&&n.length===0){g(!1),h();return}const u=[];if(m.length>0){const{error:l}=await b.from("experiences").update({project_id:r.id}).in("id",m);l&&u.push(l)}if(n.length>0){const{error:l}=await b.from("experiences").update({project_id:null}).in("id",n);l&&u.push(l)}if(g(!1),u.length>0){N.error("Some changes couldn't be saved");return}N.success("Project updated",{duration:1500}),G(),h()};if(!r)return null;const F=r.accent_color??"#5C6F2D";return e.jsx(Y,{open:p,onOpenChange:t=>!t&&h(),children:e.jsxs($,{className:"max-w-lg",children:[e.jsxs(R,{children:[e.jsxs(q,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{backgroundColor:F}}),r.name]}),e.jsx(H,{children:"Choose which Experiences belong to this Project. Experiences already in another Project will be moved when checked here."})]}),e.jsx("div",{className:"max-h-[50vh] overflow-y-auto -mx-2 px-2",children:S?e.jsx("div",{className:"text-sm text-muted-foreground py-4",children:"Loadingâ¦"}):k.length===0?e.jsx("div",{className:"text-sm text-muted-foreground py-4",children:"You don't have any Experiences yet."}):e.jsx("ul",{className:"space-y-1",children:k.map(t=>{const m=t.project_id===r.id,n=t.project_id&&!m,u=E.has(t.id);return e.jsx("li",{children:e.jsxs("label",{htmlFor:`exp-${t.id}`,className:"flex items-center gap-3 rounded-md border border-transparent px-2 py-2 hover:bg-muted/40 cursor-pointer",children:[e.jsx(Ae,{id:`exp-${t.id}`,checked:u,onCheckedChange:()=>L(t.id)}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-foreground truncate",children:t.name||"Untitled"}),t.is_published?e.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded shrink-0",style:{backgroundColor:"#5C6F2D",color:"#FAF8F5"},children:"Live"}):e.jsx("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded shrink-0",style:{backgroundColor:"#FEF5E6",color:"#FFA32D"},children:"Draft"})]}),n&&!u&&e.jsx("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:"In another Project"}),n&&u&&e.jsx("p",{className:"text-[11px] text-primary mt-0.5",children:"Will move to this Project"})]})]})},t.id)})})}),e.jsxs(O,{children:[e.jsx(c,{variant:"outline",onClick:h,disabled:x,children:"Cancel"}),e.jsx(c,{onClick:A,disabled:S||x,children:x?"Savingâ¦":"Save changes"})]})]})})}const Q={2:"enterprise_2prop_monthly",3:"enterprise_3prop_monthly",4:"enterprise_4prop_monthly",5:"enterprise_5prop_monthly"},z=["#5C6F2D","#47614C","#CD412B","#FFA32D","#4A7FA8","#94E2D7","#2B2723"],I={name:"",description:"",accent_color:z[0]};function Qe(){be("Projects");const r=re.isNativePlatform(),{user:p}=me(),{projects:h,loading:G,createProject:_,updateProject:k,deleteProject:K,refresh:E}
6=ve(),[f,S]=o.useState(null),[C,x]=o.useState(!1),[g,L]=o.useState(!1),[A,F]=o.useState(null),[t,m]=o.useState({}),[n,u]=o.useState(null),[l,P]=o.useState(!1),[j,M]=o.useState(null),[V,Z]=o.useState(null),[d,y]=o.useState(I),[J,X]=o.useState(!1),pe=async()=>{if(!p)return;const{data:s}=await b.from("experiences").select("project_id").eq("owner_id",p.id).not("project_id","is",null),a={};(s??[]).forEach(i=>{i.project_id&&(a[i.project_id]=(a[i.project_id]??0)+1)}),m(a)};o.useEffect(()=>{p&&b.from("experiences").select("project_id").eq("owner_id",p.id).not("project_id","is",null).then(({data:s})=>{const a={};(s??[]).forEach(i=>{i.project_id&&(a[i.project_id]=(a[i.project_id]??0)+1)}),m(a)})},[p,h.length]),o.useEffect(()=>{p&&b.from("profiles").select("plan, property_limit").eq("id",p.id).maybeSingle().then(({data:s})=>{s&&S({plan:s.plan,property_limit:s.property_limit??999})})},[p]);const v=(f==null?void 0:f.plan)==="enterprise",w=(f==null?void 0:f.property_limit)??999,he=v&&h.length>=w,B=w+1,D=r&&!!Q[B];o.useEffect(()=>{if(!C||!D){F(null);return}const s=Q[B];ae().then(a=>{const i=a==null?void 0:a.availablePackages.find(T=>T.identifier===s);F((i==null?void 0:i.product.priceString)??null)}).catch(()=>F(null))},[C,D,B]);const ee=()=>{if(he){x(!0);return}y(I),P(!0)},ue=async()=>{const s=w+1;L(!0);try{if(r){const i=Q[s];if(!i)return;const T=await ae(),te=T==null?void 0:T.availablePackages.find(ge=>ge.identifier===i);if(!te){N.error("This isn't available for purchase right now. Please try again shortly.");return}const W=await _e(te);W.status==="purchased"?(N("Property added",{duration:1500}),x(!1),y(I),P(!0),window.location.reload()):W.status==="error"&&N.error(W.message||"Could not add a property");return}const{error:a}=await b.functions.invoke("create-checkout",{body:{mode:"add_properties",properties:s}});if(a)throw a;S(i=>i&&{...i,property_limit:i.property_limit+1}),x(!1),N("Property added",{duration:1500}),y(I),P(!0)}catch(a){N.error(a instanceof Error?a.message:"Could not add a property")}finally{L(!1)}},xe=s=>{y({name:s.name,description:s.description??"",accent_color:s.accent_color??z[0]}),u(s)},je=async()=>{d.name.trim()&&(X(!0),n?(await k(n.id,{name:d.name.trim(),description:d.description.trim()||null,accent_color:d.accent_color}),u(null)):(await _({name:d.name.trim(),description:d.description.trim()||null,accent_color:d.accent_color}),P(!1)),X(!1))},fe=async()=>{j&&(await K(j.id),M(null),E())},se=o.useMemo(()=>Object.values(t).reduce((s,a)=>s+a,0),[t]);return e.jsxs("div",{className:"space-y-6 max-w-5xl",children:[re.isNativePlatform()&&e.jsx("div",{className:"-mb-4",children:e.jsx(ye,{to:"/account",label:"Account"})}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between sm:gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-semibold text-foreground",children:"Projects"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Group related Experiences so they share variables and roll up together in Stats & Audience."}),v&&e.jsxs("p",{className:"mt-2 inline-flex items-center gap-1.5 text-xs font-medium text-muted-foreground",children:[e.jsx(le,{className:"h-3.5 w-3.5 text-primary"}),h.length," of ",w," ",w===1?"property":"properties"," used"]})]}),e.jsxs("div",{className:`grid ${v?"grid-cols-2":"grid-cols-1"} gap-2 sm:flex sm:items-center shrink-0`,children:[v&&e.jsxs(c,{variant:"outline",onClick:()=>x(!0),className:"w-full sm:w-auto",children:[e.jsx(le,{className:"mr-2 h-4 w-4"}),"Add a Property"]}),e.jsxs(c,{onClick:ee,className:"w-full sm:w-auto",children:[e.jsx(de,{className:"mr-2 h-4 w-4"}),"New Project"]})]})]}),e.jsx("div",{className:"rounded-lg border p-4",style:{backgroundColor:"hsl(var(--cotton))",borderColor:"hsl(var(--cloud))"},children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"h-9 w-9 rounded-sm flex items-center justify-center shrink-0",style:{backgroundColor:"hsl(var(--ivy-tint))"},children:e.jsx(ce,{className:"h-4 w-4",style:{color:"hsl(var(--ivy))"}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",style:{color:"hsl(var(--charcoal))"},children:v?"Each Project is a property":"What a Project does"}),e.jsxs("ul",{className:"mt-1.5 space-y-1 text-xs leading-relaxed",style:{color:"hsl(var(--umber))"},children:[e.jsx("li",{children:"· Group related Experiences â a location, campaign, or season â so they belong together."}),e.jsx("li",{children:"· Shared answers let those Experiences recognize the same visitor across ta
6ps."}),e.jsxs("li",{children:["· Stats and Audience roll up per Project, so you can compare ",v?"properties":"groups"," at a glance."]})]}),v?e.jsxs("p",{className:"mt-2 text-xs leading-relaxed",style:{color:"hsl(var(--umber))"},children:["On Enterprise, each Project is a ",e.jsx("strong",{children:"property"})," â its own Experiences, branded Markers, and analytics under one bill.",r?" Need another location? You can add one right here in the app â you'll see the price before you confirm.":" Need another location? Additional properties are $99/mo each."]}):e.jsx("p",{className:"mt-2 text-xs leading-relaxed",style:{color:"hsl(var(--umber))"},children:"Projects are unlimited on your plan, at no extra cost. Per-location billing (each Project as its own âpropertyâ) is an Enterprise feature."})]})]})}),G?e.jsx(Ce,{rows:4}):h.length===0?e.jsx(ie,{children:e.jsxs(oe,{className:"flex flex-col items-center justify-center gap-3 py-16 text-center",children:[e.jsx(ce,{className:"h-10 w-10 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-foreground",children:"No Projects yet"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Create a Project to group Experiences and unlock shared variables."})]}),e.jsxs(c,{onClick:ee,className:"mt-2",children:[e.jsx(de,{className:"mr-2 h-4 w-4"}),"Create your first Project"]})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-xs text-muted-foreground",children:[h.length," Project",h.length===1?"":"s"," · ",se," Experience",se===1?"":"s"," assigned"]}),e.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:h.map(s=>{const a=t[s.id]??0,i=s.accent_color??z[0];return e.jsxs(ie,{className:"overflow-hidden",children:[e.jsx("div",{className:"h-1.5 w-full",style:{backgroundColor:i}}),e.jsx(Ee,{className:"pb-2",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(Se,{className:"truncate text-lg",children:s.name}),s.description&&e.jsx("p",{className:"mt-1 line-clamp-2 text-sm text-muted-foreground",children:s.description})]}),e.jsxs("div",{className:"flex shrink-0 gap-1",children:[e.jsx(c,{size:"icon",variant:"ghost",onClick:()=>xe(s),"aria-label":"Edit",children:e.jsx(Pe,{className:"h-4 w-4"})}),e.jsx(c,{size:"icon",variant:"ghost",onClick:()=>M(s),"aria-label":"Delete",className:"text-destructive hover:text-destructive",children:e.jsx(Fe,{className:"h-4 w-4"})})]})]})}),e.jsx(oe,{className:"pt-0",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:a})," Experience",a===1?"":"s"]}),e.jsxs(c,{size:"sm",variant:"outline",onClick:()=>Z(s),children:[e.jsx(De,{className:"mr-2 h-3.5 w-3.5"}),"Manage Experiences"]})]})})]},s.id)})})]}),e.jsx(Y,{open:l||!!n,onOpenChange:s=>{s||(P(!1),u(null))},children:e.jsxs($,{onOpenAutoFocus:r?s=>s.preventDefault():void 0,children:[e.jsxs(R,{children:[e.jsx(q,{children:n?"Edit Project":"New Project"}),e.jsx(H,{children:"Projects group Experiences so they can share variables and rollup stats."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(U,{htmlFor:"project-name",children:"Name"}),e.jsx(we,{id:"project-name",value:d.name,onChange:s=>y({...d,name:s.target.value}),placeholder:"Summer Tour 2026",autoFocus:!r})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(U,{htmlFor:"project-desc",children:"Description (optional)"}),e.jsx(ke,{id:"project-desc",value:d.description,onChange:s=>y({...d,description:s.target.value}),placeholder:"What this group of Experiences is for",rows:3})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(U,{children:"Accent color"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:z.map(s=>e.jsx("button",{type:"button",onClick:()=>y({...d,accent_color:s}),className:"h-8 w-8 rounded border-2 transition",style:{backgroundColor:s,borderColor:d.accent_color===s?"hsl(var(--foreground))":"transparent"},"aria-label":`Select color ${s}`},s))})]})]}),e.jsxs(O,{children:[e.jsx(c,{variant:"outline",onClick:()=>{P(!1),u(null)},children:"Cancel"}),e.jsx(c,{onClick:je,disabled:!d.name.trim()||J,children:J?"Savingâ¦":n?"Save changes":"Create Project"})]})]})}),e.jsx(Y,{open:!!j,onOpenChange:s=>!s&&M(null),children:e.jsxs($,{children:[e.jsxs(R,{children:[e.jsxs(q,{children:['Delete "',j==null?void 0:j.name,'"?']}
6),e.jsx(H,{children:j&&(t[j.id]??0)>0?e.jsxs(e.Fragment,{children:["This Project has ",e.jsx("strong",{children:t[j.id]})," Experience",t[j.id]===1?"":"s"," assigned. They will be unassigned but not deleted. Project-scoped variables on those Experiences will lose their grouping."]}):"This Project has no Experiences assigned. It will be permanently removed."})]}),e.jsxs(O,{children:[e.jsx(c,{variant:"outline",onClick:()=>M(null),children:"Cancel"}),e.jsx(c,{variant:"destructive",onClick:fe,children:"Delete Project"})]})]})}),e.jsx(Y,{open:C,onOpenChange:s=>!s&&!g&&x(!1),children:e.jsxs($,{className:"max-w-sm",children:[e.jsxs(R,{children:[e.jsx(q,{children:r&&!D?"Property limit reached":"Add a property"}),e.jsx(H,{children:r&&!D?"You've reached the maximum properties available for in-app purchase. Email [email protected] and we'll set up additional properties for you.":"Each additional property gives that location its own Experiences, branded Markers, and analytics â all under your one Enterprise account and one bill."})]}),r&&!D?e.jsx(O,{children:e.jsx(c,{onClick:()=>x(!1),children:"Got it"})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-md border border-border bg-card p-3 text-sm text-muted-foreground",children:["You'll go from ",e.jsx("strong",{className:"text-foreground",children:w})," to"," ",e.jsx("strong",{className:"text-foreground",children:B}
6)," properties."," ",r?"Billed monthly through your Apple ID.":"The add-on is prorated and added to your current subscription."]}),e.jsxs(O,{children:[e.jsx(c,{variant:"outline",onClick:()=>x(!1),disabled:g,children:"Cancel"}),e.jsx(c,{onClick:ue,disabled:g||r&&!A,children:g?e.jsx(ne,{className:"h-4 w-4 animate-spin"}):r?A?`Upgrade to ${A}/mo`:e.jsx(ne,{className:"h-4 w-4 animate-spin"}):"Add for $99/mo"})]})]})]})}),e.jsx(Te,{project:V,open:!!V,onClose:()=>Z(null),onSaved:pe})]})}export{Qe as default};
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.