1import{f as ee,b as L,s as u,P as se,r as b,j as e,C as P,K as te,N as ae,bJ as ie,c as U,w as B,B as g,L as K,U as I,J as d,X as re,I as w}from"./index-PtGACUVf.js";import{u as O}from"./useMutation-B6B2ZZTv.js";import{a as Q}from"./purge-cache-EWkfeBR6.js";import{u as le}from"./BusinessContext-BOK9Au9O.js";import{S as oe}from"./switch-CWE3Of9x.js";import{L as j}from"./label-BGYTmHnu.js";import{T as ne}from"./textarea-B113Ozlu.js";import{D as ce,a as me,b as de,c as ue,e as he,f as pe}from"./dialog-1knjOMG6.js";import{A as xe,a as fe,b as ge,c as je,d as ye,e as be,f as ve,g as Ne}from"./alert-dialog-Cl4FfIMl.js";import{P as J}from"./plus-Dy1doKva.js";import{P as we}from"./pencil-42xSffWH.js";import{T as _e}from"./trash-2-BGrma1vw.js";import{U as Ce}from"./upload-CQnoTNQE.js";import"./index-DU2LHGu_.js";function De(l){var N;const{user:h}=ee(),{data:o,isLoading:i}=L({queryKey:["platform-settings-team"],queryFn:async()=>{const{data:f,error:n}=await u.from("platform_settings").select("key, value").in("key",["team_limit_default","team_limit_elite"]);if(n)throw n;return f.reduce((D,t)=>(D[t.key]=t.value,D),{})}}),{data:_,isLoading:T}=L({queryKey:["user-subscription-tier",h==null?void 0:h.id],queryFn:async()=>{const{data:f,error:n}=await u.from("subscriptions").select("level, status").eq("user_id",h.id).eq("status","active").order("created_at",{ascending:!1}).limit(1).maybeSingle();if(n)throw n;return f},enabled:!!(h!=null&&h.id)}),{data:q,isLoading:C}=L({queryKey:["team-member-count",l],queryFn:async()=>{const{count:f,error:n}=await u.from("business_team_members").select("*",{count:"exact",head:!0}).eq("business_id",l);if(n)throw n;return f||0},enabled:!!l}),S=i||T||C,A=((N=_==null?void 0:_.level)==null?void 0:N.toLowerCase())==="elite",F=(o==null?void 0:o.team_limit_elite)||"unlimited",k=parseInt((o==null?void 0:o.team_limit_default)||"20",10),p=A&&F==="unlimited",r=p?1/0:k,v=q||0,x=p||v<r;return{limit:r,unlimited:p,currentCount:v,canAddMore:x,isLoading:S}}function Oe(){const{business:l,refetch:h}=le(),o=se(),i=(l==null?void 0:l.id)||"",{limit:_,unlimited:T,currentCount:q,canAddMore:C,isLoading:S}=De(i),[A,F]=b.useState((l==null?void 0:l.show_team)??!0),[k,p]=b.useState(!1),[r,v]=b.useState(null),[x,N]=b.useState(null),[f,n]=b.useState(!1),D=b.useRef(null),[t,c]=b.useState({name:"",title:"",bio:"",specialties:"",email:"",phone:"",ph
1oto_url:""}),{data:M=[],isLoading:Y}=L({queryKey:["team-members",i],queryFn:async()=>{const{data:s,error:a}=await u.from("business_team_members").select("*").eq("business_id",i).order("sort_order",{ascending:!0});if(a)throw a;return s},enabled:!!i}),V=O({mutationFn:async s=>{const{error:a}=await u.from("businesses").update({show_team:s}).eq("id",i);if(a)throw a;Q(i,["team"])},onSuccess:()=>{d.success("Team settings saved"),h()},onError:()=>{d.error("Failed to save settings")}}),E=O({mutationFn:async s=>{const a=s.specialties.split(",").map(m=>m.trim()).filter(Boolean),y={business_id:i,name:s.name,title:s.title,bio:s.bio||null,specialties:a.length>0?a:null,email:s.email||null,phone:s.phone||null,photo_url:s.photo_url||null,sort_order:(r==null?void 0:r.sort_order)??M.length};if(r){const{error:m}=await u.from("business_team_members").update(y).eq("id",r.id);if(m)throw m}else{const{error:m}=await u.from("business_team_members").insert(y);if(m)throw m}Q(i,["team"])},onSuccess:()=>{d.success(r?"Team member updated":"Team member added"),o.invalidateQueries({queryKey:["team-members",i]}),o.invalidateQueries({queryKey:["team-member-count",i]}),$()},onError:()=>{d.error("Failed to save team member")}}),X=O({mutationFn:async s=>{const{error:a}=await u.from("business_team_members").delete().eq("id",s);if(a)throw a;Q(i,["team"])},onSuccess:()=>{d.success("Team member deleted"),o.invalidateQueries({queryKey:["team-members",i]}),o.invalidateQueries({queryKey:["team-member-count",i]}),N(null)},onError:()=>{d.error("Failed to delete team member")}}),R=()=>{v(null),c({name:"",title:"",bio:"",specialties:"",email:"",phone:"",ph
1oto_url:""}),p(!0)},G=s=>{var a;v(s),c({name:s.name,title:s.title,bio:s.bio||"",specialties:((a=s.specialties)==null?void 0:a.join(", "))||"",email:s.email||"",phone:s.phone||"",photo_url:s.photo_url||""}),p(!0)},$=()=>{p(!1),v(null)},W=s=>{if(s.preventDefault(),!t.name.trim()||!t.title.trim()){d.error("Name and title are required");return}E.mutate(t)};return l?e.jsxs("div",{className:"space-y-6",children:[e.jsxs(P,{children:[e.jsxs(te,{children:[e.jsx(ae,{children:"Team Settings"}),e.jsx(ie,{children:"Configure how your team is displayed"})]}),e.jsx(U,{className:"space-y-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(j,{htmlFor:"show-team",children:"Show Team on Listing"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Display your team members publicly on your listing page"})]}),e.jsx(oe,{id:"show-team",checked:A,onCheckedChange:s=>{F(s),V.mutate(s)}})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Team Members"}),e.jsx(B,{variant:"secondary",children:T?`${q} members - Unlimited`:`${q} of ${_} members`})]}),e.jsxs(g,{onClick:R,disabled:!C||S,children:[e.jsx(J,{className:"h-4 w-4 mr-2"}),"Add Team Member"]})]}),!C&&!T&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"You've reached your team member limit. Upgrade to Elite for unlimited team members."}),Y?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(K,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):M.length===0?e.jsx(P,{children:e.jsxs(U,{className:"py-12 text-center",children:[e.jsx(I,{className:"h-12 w-12 mx-auto text-muted-foreground mb-4"}),e.jsx("h3",{className:"font-medium text-lg mb-2",children:"No team members yet"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Add your team members to showcase them on your listing"}),e.jsxs(g,{onClick:R,disabled:!C,children:[e.jsx(J,{className:"h-4 w-4 mr-2"}),"Add Your First Team Member"]})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:M.map(s=>e.jsx(P,{className:"group relative",children:e.jsxs(U,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"h-16 w-16 rounded-full bg-muted flex items-center justify-center overflow-hidden flex-shrink-0",children:s.photo_url?e.jsx("img",{src:s.photo_url,alt:s.name,className:"h-full w-full object-cover"}):e.jsx(I,{className:"h-8 w-8 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-semibold truncate",children:s.name}),e.jsx("p",{className:"text-sm text-muted-foreground italic truncate",children:s.title}),s.specialties&&s.specialties.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[s.specialties.slice(0,2).map((a,y)=>e.jsx(B,{variant:"outline",className:"text-xs",children:a},y)),s.specialties.length>2&&e.jsxs(B,{variant:"outline",className:"text-xs",children:["+",s.specialties.length-2]})]})]})]}),e.jsxs("div",{className:"absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity flex gap-1",children:[e.jsx(g,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>G(s),children:e.jsx(we,{className:"h-4 w-4"})}),e.jsx(g,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive",onClick:()=>N(s),children:e.jsx(_e,{className:"h-4 w-4"})})]})]})},s.id))})]}),e.jsx(ce,{open:k,onOpenChange:p,children:e.jsxs(me,{className:"max-w-md max-h-[85vh] overflow-hidden flex flex-col p-0",children:[e.jsxs(de,{className:"px-6 pt-6 pb-2 flex-shrink-0",children:[e.jsx(ue,{children:r?"Edit Team Member":"Add Team Member"}),e.jsx(he,{children:r?"Update the team member's information":"Add a new team member to your listing"})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6",children:e.jsxs("form",{id:"team-member-form",onSubmit:W,className:"space-y-4 pb-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{children:"Photo"}),e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"h-20 w-20 rounded-full bg-muted flex items-center justify-center overflow-hidden flex-shrink-0 border-2 border-dashed border-border",children:t.photo_url?e.jsx("img",{src:t.photo_url,alt:"Preview",className:"h-full w-full object-cover"}):e.jsx(I,{className:"h-8 w-8 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("input",{ref:D,type:"file",accept:"image/*",className:"hidden",onChange:async s=>{var y;const a=(y=s.target.files)==null?void 0:y[0];if(a){if(a.size>5*1024*1024){d.error("Image must be less than 5MB");return}n(!0);try{const m=a.name.split(".").pop(),z=`${i}/${Date.now()}.${m}`,{error:H}=await u.storage.from("business_assets").upload(z,a);if(H)throw H;const{data:Z}=u.storage.from("business_assets").getPublicUrl(z);c({...t,photo_url:Z.publicUrl}),d.success("Photo uploaded")}catch(m){console.error(m),d.error("Failed to upload photo")}finally{n(!1)}}}}),e.jsxs(g,{type:"button",variant:"outline",size:"sm",onClick:()=>{var s;return(s=D.current)==null?void 0:s.click()},disabled:f,children:[f?e.jsx(K,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Ce,{className:"h-4 w-4 mr-2"}),"Upload Photo"]}),t.photo_url&&e.jsxs(g,{type:"button",variant:"ghost",size:"sm",onClick:()=>c({...t,photo_url:""}),children:[e.jsx(re,{className:"h-4 w-4 mr-2"}),"Remove"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Or paste an image URL below"}),e.jsx(w,{value:t.photo_url,onChange:s=>c({...t,photo_url:s.target.value}),placeholder:"https://example.com/photo.jpg",className:"text-sm"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"name",children:"Name *"}),e.jsx(w,{id:"name",value:t.name,onChange:s=>c({...t,name:s.target.value}),placeholder:"John Smith",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"title",children:"Title/Role *"}),e.jsx(w,{id:"title",value:t.title,onChange:s=>c({...t,title:s.target.value}),placeholder:"Head Chef, Lead Stylist, Owner...",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"bio",children:"Bio"}),e.jsx(ne,{id:"bio",value:t.bio,onChange:s=>c({...t,bio:s.target.value}),placeholder:"2-3 sentence description...",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"specialties",children:"Specialties"}),e.jsx(w,{id:"specialties",value:t.specialties,onChange:s=>c({...t,specialties:s.target.value}),placeholder:"Hair Color, Balayage, Extensions..."}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Separate with commas"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"email",children:"Email"}),e.jsx(w,{id:"email",type:"email",value:t.email,onChange:s=>c({...t,email:s.target.value}),placeholder:"[email protected]"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(j,{htmlFor:"phone",children:"Phone"}),e.jsx(w,{id:"phone",value:t.phone,onChange:s=>c({...t,phone:s.target.value}),placeholder:"(555) 123-4567"})]})]})]})}),e.jsxs(pe,{className:"px-6 py-4 border-t flex-shrink-0",children:[e.jsx(g,{type:"button",variant:"outline",onClick:$,children:"Cancel"}),e.jsxs(g,{type:"submit",form:"team-member-form",disabled:E.isPending,children:[E.isPending?e.jsx(K,{className:"h-4 w-4 animate-spin mr-2"}):null,r?"Save Changes":"Add Member"]})]})]})}),e.jsx(xe,{open:!!x,onOpenChange:()=>N(null),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:"Delete Team Member"}),e.jsxs(ye,{children:["Are you sure you want to delete ",x==null?void 0:x.name,"? This action cannot be undone."]})]}),e.jsxs(be,{children:[e.jsx(ve,{children:"Cancel"}),e.jsx(Ne,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>x&&X.mutate(x.id),children:"Delete"})]})]})})]}):null}export{Oe 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.