1import{bz as $,r as a,j as t,bA as O,B as m,a$ as B,g as U,s as n,v as o}from"./index-BNrdOJig.js";import{I as N}from"./input-CwAqzCK4.js";import{P as q}from"./plus-BewcIKll.js";import{T as G}from"./trash-2-DqSHrMYS.js";const I=["producer","writer","engineer","label","manager","feature"];function H(){const i=$(),[s,w]=a.useState([]),[y,u]=a.useState(!0),[S,x]=a.useState(!1),[d,p]=a.useState(""),[g,f]=a.useState(""),[v,k]=a.useState("producer"),[h,b]=a.useState(!1),l=async()=>{u(!0);const{data:e}=await n.from("greenlist_members").select("*").order("created_at",{ascending:!1});w(e??[]),u(!1)};a.useEffect(()=>{i?.id&&l()},[i?.id]);const _=async()=>{if(!d.trim()||!i?.id){o.error("Name is required");return}b(!0);const{error:e}=await n.from("greenlist_members").insert({owner_id:i.id,name:d.trim(),contact_email:g.trim()||null,role:v});if(b(!1),e){o.error(e.message);return}o.success(`${d} added to your greenlist`),p(""),f(""),x(!1),l()},R=async e=>{await n.from("greenlist_members").update({verified:!e.verified,status:e.verified?"pending":"approved"}).eq("id",e.id),l()},C=async e=>{await n.from("greenlist_members").delete().eq("id",e.id),o.success(`${e.name} removed`),l()},L=()=>{const e=`Name,Role,Verified,Status,Projects,Added 2`,P=s.map(r=>[r.name,r.role,r.verified?"yes":"no",r.status,r.projects,new Date(r.created_at).toISOString().slice(0,10)].map(V=>`"${String(V).replace(/"/g,'""')}"`).join(",")).join(` 3`),j=URL.createObjectURL(new Blob([e+P],{type:"text/csv"})),c=document.createElement("a");c.href=j,c.download="greenlist.csv",c.click(),URL.revokeObjectURL(j)},E=s.filter(e=>e.verified).length,A=s.filter(e=>!e.verified).length,D=s[0]?new Date(s[0].created_at).toLocaleDateString():"â";return t.jsx(O,{profile:i,title:"Greenlist",subtitle:"Approved collaborators and partners",children:t.jsxs("div",{className:"space-y-6",children:[t.jsx("p",{className:"text-sm text-muted-foreground max-w-3xl",children:"Your trusted list of producers, writers, engineers and labels. Verified names here can be attached to splits and credits without a second approval step."}),t.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[{label:"Approved",value:s.length},{label:"Verified",value:E},{label:"Pending invite",value:A},{label:"Last added",value:D}].map(e=>t.jsxs("div",{className:"rounded-2xl border border-white/5 p-5",style:{background:"var(--backoffice-card)"},children:[t.jsx("div",{className:"text-[10px] font-bold uppercase tracking-[0.18em] text-muted-foreground",children:e.label}),t.jsx("div",{className:"font-display text-3xl mt-2",children:e.value})]},e.label))}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs(m,{onClick:()=>x(e=>!e),className:"bg-primary text-primary-foreground hover:opacity-90",children:[t.jsx(q,{className:"w-4 h-4 mr-1.5"})," Add to greenlist"]}),t.jsxs(m,{variant:"outline",onClick:L,disabled:s.length===0,children:[t.jsx(B,{className:"w-4 h-4 mr-1.5"})," Export"]})]}),S&&t.jsxs("div",{className:"rounded-2xl border border-white/5 p-5 grid md:grid-cols-4 gap-3",style:{background:"var(--backoffice-card)"},children:[t.jsx(N,{placeholder:"Name",value:d,onChange:e=>p(e.target.value)}),t.jsx(N,{placeholder:"Email (optional)",value:g,onChange:e=>f(e.target.value)}),t.jsx("select",{value:v,onChange:e=>k(e.target.value),className:"h-10 rounded-md border border-input bg-[var(--dropdown,#000)] px-3 text-sm",children:I.map(e=>t.jsx("option",{value:e,children:e},e))}),t.jsx(m,{onClick:_,disabled:h,children:h?"Savingâ¦":"Save collaborator"})]}),t.jsxs("div",{className:"rounded-2xl border border-white/5 overflow-hidden",style:{background:"var(--backoffice-card)"},children:[t.jsxs("div",{className:"grid grid-cols-5 px-5 py-3 border-b border-white/5 text-[10px] font-bold uppercase tracking-[0.18em] text-muted-foreground",children:[t.jsx("div",{children:"Name"}),t.jsx("div",{children:"Role"}),t.jsx("div",{children:"Verified"}),t.jsx("div",{children:"Projects"}),t.jsx("div",{className:"text-right",children:"Added"})]}),y?t.jsx("div",{className:"p-10 text-center text-sm text-muted-foreground",children:"Loadingâ¦"}):s.length===0?t.jsxs("div",{className:"p-10 text-center",children:[t.jsx("div",{className:"font-display text-lg mb-1",children:"Greenlist is empty"}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"Add a collaborator to fast-track splits, credits and approvals."})]}):s.map(e=>t.jsxs("div",{className:"grid grid-cols-5 px-5 py-4 border-b border-white/5 text-sm items-center",children:[t.jsxs("div",{className:"font-semibold truncate",children:[e.name,e.contact_email&&t.jsx("div",{className:"text-xs text-muted-foreground truncate",children:e.contact_email})]}),t.jsx("div",{className:"capitalize text-muted-foreground",children:e.role}),t.jsx("div",{children:t.jsxs("button",{onClick:()=>R(e),className:`inline-flex items-center gap-1 text-xs font-bold uppercase tracking-wider ${e.verified?"text-primary":"text-muted-foreground"}`,children:[t.jsx(U,{className:"w-4 h-4"})," ",e.verified?"Verified":"Verify"]})}),t.jsx("div",{className:"text-muted-foreground",children:e.projects}),t.jsxs("div",{className:"text-right text-muted-foreground flex items-center justify-end gap-3",children:[new Date(e.created_at).toLocaleDateString(),t.jsx("button",{onClick:()=>C(e),"aria-label":`Remove ${e.name}`,className:"text-muted-foreground hover:text-destructive",children:t.jsx(G,{className:"w-4 h-4"})})]})]},e.id))]})]})})}export{H 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.