1import{r,j as e,m as ge,aw as D,C as He,a1 as V,ax as ce,H as Y,J as he,A as mt,ay as ke,az as Re,ac as _e,F as xt,f as qe,ab as ut,p as gt,aA as ht,K as ft,O as pt,aB as Pe,W as De,U as Be,i as bt,aC as Ve,$ as We,a4 as oe,aD as wt,L as yt,aE as jt,M as vt,Q as Je}from"./index-DFsRoN7L.js";import{s as u}from"./customer-utils-Cvoil6QM.js";import{a as Nt,ax as _t,ay as kt,az as St}from"./main-1ZtydJwB.js";import{F as Ge,a as Ct}from"./UserPlusIcon-D9O17vEw.js";import{F as Et}from"./CheckCircleIcon-D9GLD7np.js";import"./customer-vendor-CDEsLGFF.js";function Ot({title:d,titleId:x,...m},b){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:b,"aria-labelledby":x},m),d?r.createElement("title",{id:x},d):null,r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5A2.25 2.25 0 0 1 21 11.25v7.5"}))}const At=r.forwardRef(Ot);function Ft({title:d,titleId:x,...m},b){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:b,"aria-labelledby":x},m),d?r.createElement("title",{id:x},d):null,r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8.25 7.5V6.108c0-1.135.845-2.098 1.976-2.192.373-.03.748-.057 1.123-.08M15.75 18H18a2.25 2.25 0 0 0 2.25-2.25V6.108c0-1.135-.845-2.098-1.976-2.192a48.424 48.424 0 0 0-1.123-.08M15.75 18.75v-1.875a3.375 3.375 0 0 0-3.375-3.375h-1.5a1.125 1.125 0 0 1-1.125-1.125v-1.5A3.375 3.375 0 0 0 6.375 7.5H5.25m11.9-3.664A2.251 2.251 0 0 0 15 2.25h-1.5a2.251 2.251 0 0 0-2.15 1.586m5.8 0c.065.21.1.433.1.664v.75h-6V4.5c0-.231.035-.454.1-.664M6.75 7.5H4.875c-.621 0-1.125.504-1.125 1.125v12c0 .621.504 1.125 1.125 1.125h9.75c.621 0 1.125-.504 1.125-1.125V16.5a9 9 0 0 0-9-9Z"}))}const $t=r.forwardRef(Ft);function Mt({title:d,titleId:x,...m},b){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:b,"aria-labelledby":x},m),d?r.createElement("title",{id:x},d):null,r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"}))}const Tt=r.forwardRef(Mt);function zt({title:d,titleId:x,...m},b){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:b,"aria-labelledby":x},m),d?r.createElement("title",{id:x},d):null,r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13.19 8.688a4.5 4.5 0 0 1 1.242 7.244l-4.5 4.5a4.5 4.5 0 0 1-6.364-6.364l1.757-1.757m13.35-.622 1.757-1.757a4.5 4.5 0 0 0-6.364-6.364l-4.5 4.5a4.5 4.5 0 0 0 1.242 7.244"}))}const Lt=r.forwardRef(zt);function Ut({title:d,titleId:x,...m},b){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:b,"aria-labelledby":x},m),d?r.createElement("title",{id:x},d):null,r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 12 3.269 3.125A59.769 59.769 0 0 1 21.485 12 59.768 59.768 0 0 1 3.27 20.875L5.999 12Zm0 0h7.5"}))}const It=r.forwardRef(Ut);function Ht({title:d,titleId:x,...m},b){return r.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:b,"aria-labelledby":x},m),d?r.createElement("title",{id:x},d):null,r.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18 18 6M6 6l12 12"}))}const Rt=r.forwardRef(Ht),qt=({isOpen:d,onClose:x,onInviteSent:m})=>{var G;const[b,H]=r.useState({email:"",role:"member"}),[Z,O]=r.useState(!1),[X,$]=r.useState(null),[Q,L]=r.useState(!1),[W,ee]=r.useState(null),[w,y]=r.useState(null),de=[{value:"member",label:"Member",description:"Access to orders, uploads, and basic features",color:"text-green-600"},{value:"manager",label:"Manager",description:"Manage orders, uploads, and team members",color:"text-blue-600"},{value:"admin",label:"Admin",description:"Manage team members, settings, and most features",color:"text-red-600"}],te=()=>window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"?"http://localhost:3001":"https://api.sortaflow.com",fe=async h=>{h.preventDefault(),O(!0),$(null);try{const{data:{session:N},error:v}=await u.auth.getSession();if(v||!N){$("Authentication required");return}const{data:k}=await u.from("users").select("current_organization_id").eq("id",N.user.id).single();if(!(k!=null&&k.current_organization_id)){$("No organization found");return}const _=te(),C=await fetch(`${_}/api/team/invite`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${N.access_token}`},body:JSON.stringify({email:b.email.trim().toLowerCase(),role:b.role})}),M=await C.text();if(!C.ok){let R=`Server error: ${C.status}`;try{R=JSON.parse(M).error||R}catch{R=M.substring(0,200)||C.statusText||R}throw new Error(R)}let A;try{A=JSON.parse(M)}catch{throw new Error(`Invalid JSON response: ${M.substring(0,100)}`)}A.success||A.invitation?(L(!0),y(A.invitation),A.invite_url&&ee(A.invite_url),m&&m(A.invitation)):$(A.error||"Failed to send invitation")}catch(N){$(N.message||"Failed to send invitation. Please try again.")}finally{O(!1)}},j=()=>{H({email:"",role:"member"}),$(null),L(!1),O(!1),ee(null),y(null),x()},J=h=>{const{name:N,value:v}=h.target;H(k=>({...k,[N]:v})),X&&$(null)},U=h=>{if(!h)return"Not available";const N=new Date(h);return isNaN(N.getTime())?"Invalid date":N.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})},pe=h=>
1{if(!h)return"Unknown";const N=new Date,v=new Date(h);if(isNaN(v.getTime()))return"Unknown";const k=v-N,_=Math.floor(k/(1e3*60*60)),C=Math.floor(_/24);return C>0?`${C} day${C===1?"":"s"}`:_>0?`${_} hour${_===1?"":"s"}`:k>0?"Less than 1 hour":"Expired"},be=async h=>{try{await navigator.clipboard.writeText(h),alert("Copied to clipboard!")}catch{const v=document.createElement("textarea");v.value=h,document.body.appendChild(v),v.focus(),v.select();try{document.execCommand("copy"),alert("Copied to clipboard!")}catch{alert(`Copy failed. Text: ${h}`)}document.body.removeChild(v)}};return d?e.jsx("div",{className:"fixed inset-0 flex items-center justify-center z-50 p-4",style:{backgroundColor:"rgba(0, 0, 0, 0.2)"},children:e.jsxs(ge.div,{className:"bg-white rounded-xl shadow-xl max-w-4xl w-full max-h-[90vh] overflow-y-auto",initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx(Ge,{className:"h-6 w-6 text-blue-600"}),e.jsx("h2",{className:"text-xl font-semibold text-gray-900",children:"Invite Team Member"})]}),e.jsx("button",{onClick:j,className:"text-gray-400 hover:text-gray-600 transition-colors",children:e.jsx(Rt,{className:"h-6 w-6"})})]}),e.jsx("div",{className:"p-6",children:Q?e.jsxs(ge.div,{className:"py-6",initial:{opacity:0,y:20},animate:{opacity:1,y:0},children:[e.jsxs("div",{className:"text-center mb-6",children:[e.jsx(Et,{className:"h-16 w-16 text-green-500 mx-auto mb-4"}),e.jsx("h3",{className:"text-xl font-semibold text-gray-900 mb-2",children:"Invitation Sent Successfully!"}),e.jsxs("p",{className:"text-gray-600",children:["An invitation has been sent to"," ",e.jsx("span",{className:"font-medium",children:b.email})]})]}),w&&e.jsxs("div",{className:"bg-gray-50 rounded-lg p-4 mb-6 space-y-3",children:[e.jsx("h4",{className:"font-medium text-gray-900 text-sm mb-3",children:"Invitation Details"}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-gray-600",children:[e.jsx(At,{className:"w-4 h-4"}),e.jsxs("span",{children:["Sent: ",U(w==null?void 0:w.created_at)]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-gray-600",children:[e.jsx(Tt,{className:"w-4 h-4"}),e.jsxs("span",{children:["Expires: ",U(w==null?void 0:w.expires_at),(w==null?void 0:w.expires_at)&&e.jsxs("span",{className:"text-orange-600 ml-1",children:["(",pe(w.expires_at)," ","remaining)"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-gray-600",children:[e.jsx(Ge,{className:"w-4 h-4"}),e.jsxs("span",{children:["Role:"," ",e.jsx("span",{className:"font-medium",children:(G=de.find(h=>h.value===b.role))==null?void 0:G.label})]})]})]})]}),W&&e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Lt,{className:"w-4 h-4 text-blue-600"}),e.jsx("span",{className:"font-medium text-blue-900 text-sm",children:"Invitation Link"})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("input",{type:"text",value:W,readOnly:!0,className:"flex-1 px-3 py-2 text-sm border border-blue-300 rounded-md bg-white font-mono"}),e.jsxs("button",{onClick:()=>be(W),className:"flex items-center gap-1 px-3 py-2 text-sm bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors",children:[e.jsx($t,{className:"w-3 h-3"}),"Copy"]})]}),e.jsx("p",{className:"text-xs text-blue-700",children:"ð¡ Send this link to the invitee to join your team immediately"})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>{L(!1),H({email:"",role:"member"}),y(null),ee(null)},className:"flex-1 px-4 py-2 bg-gradient-to-r from-blue-500 to-cyan-500 text-white rounded-lg hover:from-blue-600 hover:to-cyan-600 transition-all font-medium",children:"Send Another Invite"}),e.jsx("button",{onClick:j,className:"px-4 py-2 bg-gray-200 text-gray-800 rounded-lg hover:bg-gray-300 transition-colors font-medium",children:"Done"})]})]}):e.jsxs("form",{onSubmit:fe,className:"space-y-6",children:[X&&e.jsxs(ge.div,{className:"bg-red-50 border border-red-200 rounded-lg p-4 flex items-center space-x-3",initial:{opacity:0,y:-10}
1,animate:{opacity:1,y:0},children:[e.jsx(Ct,{className:"h-5 w-5 text-red-500 flex-shrink-0"}),e.jsx("span",{className:"text-red-700 text-sm",children:X})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium text-gray-700 mb-2",children:"Email Address"}),e.jsx("input",{type:"email",id:"email",name:"email",required:!0,value:b.email,onChange:J,className:"w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors",placeholder:"[email protected]"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"role",className:"block text-sm font-medium text-gray-700 mb-2",children:"Role"}),e.jsx("div",{className:"space-y-3",children:de.map(h=>e.jsxs("label",{className:`flex items-start space-x-3 p-4 border rounded-lg cursor-pointer transition-colors ${b.role===h.value?"border-blue-500 bg-blue-50":"border-gray-200 hover:border-gray-300"}`,children:[e.jsx("input",{type:"radio",name:"role",value:h.value,checked:b.role===h.value,onChange:J,className:"mt-1 text-blue-600 focus:ring-blue-500"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx("span",{className:`font-medium ${h.color}`,children:h.label})}),e.jsx("p",{className:"text-sm text-gray-600 mt-1",children:h.description})]})]},h.value))})]})]}),e.jsx("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx("div",{className:"text-blue-600 mt-0.5",children:e.jsx("svg",{className:"h-5 w-5",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"text-sm text-blue-800",children:[e.jsx("p",{className:"font-medium mb-1",children:"About Invitations"}),e.jsxs("ul",{className:"space-y-1 text-blue-700",children:[e.jsx("li",{children:"⢠Invitations expire after 7 days"}),e.jsx("li",{children:"⢠The invitee must create a SortaFlow account via invite"}),e.jsx("li",{children:"⢠You can cancel pending invitations anytime"})]})]})]})}),e.jsxs("div",{className:"flex justify-end space-x-3 pt-4 border-t border-gray-200",children:[e.jsx("button",{type:"button",onClick:j,className:"px-6 py-3 border border-gray-300 rounded-lg text-gray-700 font-medium hover:bg-gray-50 transition-colors",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:Z||!b.email.trim(),className:"px-6 py-3 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center justify-center space-x-2",children:Z?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"animate-spin rounded-full h-5 w-5 border-2 border-white border-t-transparent"}),e.jsx("span",{children:"Sending..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(It,{className:"h-5 w-5"}),e.jsx("span",{children:"Send Invitation"})]})})]})]})})]})}):null},B={owner:{name:"Owner",color:"bg-gradient-to-r from-[#FF719A] to-[#FFA99F] text-white",description:"Full access to everything",icon:ke},admin:{name:"Admin",color:"bg-gradient-to-r from-red-500 to-orange-500 text-white",description:"Manage team and settings",icon:he},manager:{name:"Manager",color:"bg-gradient-to-r from-blue-500 to-cyan-500 text-white",description:"Manage orders and workflows",icon:ce},member:{name:"Member",color:"bg-gradient-to-r from-green-500 to-emerald-500 text-white",description:"Handle assigned orders",icon:V}},Pt=()=>{try{const d=new(window.AudioContext||window.webkitAudioContext),x=d.createOscillator(),m=d.createGain();x.connect(m),m.connect(d.destination),x.frequency.setValueAtTime(1046.5,d.currentTime),x.frequency.setValueAtTime(1318.5,d.currentTime+.1),x.type="sine",m.gain.setValueAtTime(0,d.currentTime),m.gain.linearRampToValueAtTime(.15,d.currentTime+.05),m.gain.linearRampToValueAtTime(.1,d.currentTime+.1),m.gain.linearRampToValueAtTime(0,d.currentTime+.25),x.start(d.currentTime),x.stop(d.currentTime+.25)}catch{}};function Yt(){const d=Nt(),x=()=>window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"?"http://localhost:3001":"https://api.sortaflow.com",[m,b]=r.useState([]),[H,Z]=r.useState([]),[O,X]=r.useState([]),[$,Q]=r.useState(!1),[L,W]=r.useState(!1),[ee,w]=r.useState(!1),[y,de]=r.useState(null),[te,fe]=r.useState(null),[j,J]=r.useState(null),[U,pe]=r.useState(null),[be,G]=r.useState(!1),[h,N]=r.useState(""),[v,k]=r.useState(""),[_,C]=r.useState(null),[M,A]=r.useState([]),[R,I]=r.useState(!0),[Dt,Se]=r.useState(!1),[Ce,Ee]=r.useState(null),[Ke,we]=r.useState(!1),[se,ae]=r.useState(null),[Oe,re]=r.useState(null),[Ae,Fe]=r.useState(!1),[ye,ne]=r.useState(null),[ie,$e]=r.useState(!0),[Ye,Me]=r.useState(!0),[Te,ze]=r.useState(!0),[le,Ze]=r.useState("members"),F=_t(te,y==null?void 0:y.id),{info:je}=kt(),me=r.useRef(new Set);r.useEffect(()=>{if(me.current.size===0&&F.size>
10){me.current=new Set(F);return}if(m.length===0)return;const t=me.current,s=F,a=Array.from(s).filter(l=>!t.has(l)&&l!==(y==null?void 0:y.id)),n=Array.from(t).filter(l=>!s.has(l)&&l!==(y==null?void 0:y.id));a.forEach(l=>{var o,g;const i=m.find(p=>{var f;return((f=p.users)==null?void 0:f.id)===l});if(i){const p=((o=i.users)==null?void 0:o.display_name)||((g=i.users)==null?void 0:g.email)||"Team member";je(`${p} is now online ð¢`,{autoClose:3e3}),Pt()}}),n.forEach(l=>{var o,g;const i=m.find(p=>{var f;return((f=p.users)==null?void 0:f.id)===l});if(i){const p=((o=i.users)==null?void 0:o.display_name)||((g=i.users)==null?void 0:g.email)||"Team member";je(`${p} went offline`,{autoClose:3e3})}}),me.current=new Set(s)},[F,m,y==null?void 0:y.id,je]),r.useEffect(()=>{Xe(),K(),Qe(),et()},[]);const Xe=async()=>{ze(!0);try{const{data:{user:t}}=await u.auth.getUser();if(de(t),t){const{data:s}=await u.from("users").select("current_organization_id").eq("id",t.id).single();if(s!=null&&s.current_organization_id){const{data:a}=await u.from("team_members").select("role").eq("organization_id",s.current_organization_id).eq("user_id",t.id).single();pe(a==null?void 0:a.role),fe(s.current_organization_id)}}}finally{ze(!1)}},Qe=async()=>{Me(!0);try{const{data:{user:t}}=await u.auth.getUser();if(!t)return;const{data:s}=await u.from("users").select("current_organization_id").eq("id",t.id).single();if(!(s!=null&&s.current_organization_id))return;const{data:a}=await u.from("organizations").select("*").eq("id",s.current_organization_id).single();a&&(J(a),N(a.name),k(a.name));const{data:n}=await u.from("shops").select("id, shop_name, icon_url_fullxfull, platform").eq("organization_id",s.current_organization_id);n&&A(n)}finally{Me(!1)}},et=async()=>{I(!0);const{data:{user:t}}=await u.auth.getUser();if(!t){I(!1);return}const{data:s}=await u.from("users").select("current_organization_id").eq("id",t.id).single();if(!(s!=null&&s.current_organization_id)){I(!1);return}const{data:a,error:n}=await u.from("shops").select("shop_name, icon_url_fullxfull").eq("organization_id",s.current_organization_id).single();a?(C(a),a.icon_url_fullxfull!==Ce&&(Se(!1),Ee(a.icon_url_fullxfull||null)),a.icon_url_fullxfull,I(!1)):(C(null),I(!1))};r.useEffect(()=>{_&&_.icon_url_fullxfull!==Ce&&(Se(!1),Ee(_.icon_url_fullxfull||null))},[_]);const Le=async()=>{if(!(!j||!v.trim())){w(!0);try{const{error:t}=await u.from("organizations").update({name:v.trim()}).eq("id",j.id);if(t)throw t;N(v),G(!1),J({...j,name:v}),window.dispatchEvent(new CustomEvent("org-profile-updated",{detail:{name:v.trim()}}))}catch{alert("Failed to update organization name")}finally{w(!1)}}},tt=()=>{k(h),G(!1)},st=async()=>{if(j!=null&&j.id){Fe(!0);try{let t=ye;if(se){const a=se.name.split(".").pop(),n=`org-logos/${j.id}.${a}`,{error:l}=await u.storage.from("shop-images").upload(n,se,{upsert:!0,contentType:se.type});if(l)throw l;const{data:i}=u.storage.from("shop-images").getPublicUrl(n);t=i.publicUrl}if(!t)return;const{error:s}=await u.from("organizations").update({logo_url:t}).eq("id",j.id);if(s)throw s;J({...j,logo_url:t}),we(!1),ae(null),re(null),ne(null),window.dispatchEvent(new CustomEvent("org-profile-updated",{detail:{logo_url:t}}))}catch{alert("Failed to save image")}finally{Fe(!1)}}},K=async()=>{$e(!0);try{const{data:{user:t}}=await u.auth.getUser();if(!t)return;const{data:s}=await u.from("users").select("current_organization_id").eq("id",t.id).single();if(!(s!=null&&s.current_organization_id))return;const{data:a,error:n}=await u.rpc("get_team_members_with_users",{org_id:s.current_organization_id});if(n&&n.code==="42883"){const{data:o,error:g}=await u.from("team_members").select(` 2 id, 3 role, 4 status, 5 joined_at, 6 user_id 7 `).eq("organization_id",s.current_organization_id).eq("status","active");let p=[];if(o&&o.length>0){const S=o.map(E=>E.user_id),{data:c,error:T}=await u.from("users").select("id, first_name, last_name, display_name, email, avatar_url").in("id",S);p=o.map(E=>{const z=c==null?void 0:c.find(ue=>ue.id===E.user_id);return{...E,users:z?{id:E.user_id,email:z.email||"[email protected]",first_name:z.first_name,last_name:z.last_name,display_name:z.display_name,avatar_url:z.avatar_url||null}:{id:E.user_id,email:"[email protected]",first_name:"Unknown",last_name:"User",dis
7play_name:"Unknown User"}}})}const{data:f,error:P}=await u.from("organizations").select("id, name, owner_id").eq("id",s.current_organization_id).single();if(f!=null&&f.owner_id)if(p.some(c=>c.user_id===f.owner_id))p=p.map(c=>c.user_id===f.owner_id?{...c,role:"owner"}:c);else{const{data:c}=await u.from("users").select("id, first_name, last_name, display_name, email, avatar_url").eq("id",f.owner_id).single();p=[{id:`owner-${f.owner_id}`,role:"owner",status:"active",joined_at:null,user_id:f.owner_id,users:c?{id:f.owner_id,email:c.email||"[email protected]",first_name:c.first_name||"Owner",last_name:c.last_name||"",display_name:c.display_name||"Organization Owner",avatar_url:c.avatar_url||null}:{id:f.owner_id,email:"[email protected]",first_name:"Owner",last_name:"",display_name:"Organization Owner"}},...p]}p=p.map(S=>{var E;const c=(E=S.users)==null?void 0:E.avatar_url;if(!c)return S;const{data:T}=u.storage.from("avatars").getPublicUrl(c);return{...S,users:{...S.users,avatar_public_url:T!=null&&T.publicUrl?`${T.publicUrl}?t=${Date.now()}`:null}}}),b(p)}else if(a){let o=a.map(g=>{var P;const p=(P=g.users)==null?void 0:P.avatar_url;if(!p)return g;const{data:f}=u.storage.from("avatars").getPublicUrl(p);return{...g,users:{...g.users,avatar_public_url:f!=null&&f.publicUrl?`${f.publicUrl}?t=${Date.now()}`:null}}});b(o)}else b([]);try{const{data:{session:o},error:g}=await u.auth.getSession();if(g||!o)throw new Error("Authentication required");const p=x(),f=await fetch(`${p}/api/team/members?status=deactivated`,{method:"GET",headers:{Authorization:`Bearer ${o.access_token}`,"Content-Type":"application/json"}});if(!f.ok)throw new Error(`Failed to fetch deactivated members: ${f.status}`);const S=(await f.json()||[]).map(c=>{const T=c.avatar_url,E=T?(()=>{var ue;const z=(ue=u.storage.from("avatars").getPublicUrl(T).data)==null?void 0:ue.publicUrl;return z?`${z}?t=${Date.now()}`:null})():null;return{id:c.team_member_id||c.id,role:c.role,status:c.status,joined_at:c.joined_at||null,user_id:c.user_id||c.id,users:{id:c.user_id||c.id,email:c.email||"",first_name:c.first_name||"",last_name:c.last_name||"",display_name:c.display_name||"Unknown User",avatar_url:c.avatar_url||null,avatar_public_url:E}}});Z(S)}catch{Z([])}const{data:l,error:i}=await u.from("team_invitations").select(` 8 id, 9 email, 10 role, 11 token, 12 created_at, 13 expires_at, 14 users!team_invitations_invited_by_fkey ( 15 first_name, 16 last_name, 17 display_name 18 ) 19 `).eq("organization_id",s.current_organization_id).eq("status","pending").gt("expires_at",new Date().toISOString());X(l||[])}finally{$e(!1)}},q=()=>["owner","admin"].includes(U),ve=t=>U==="owner"?t!=="owner":U==="admin"?!["owner","admin"].includes(t):!1,Ne=()=>["owner","admin"].includes(U),at=t=>{K()},rt=async t=>{if(q()){w(!0);try{const{data:{session:s},error:a}=await u.auth.getSession();if(a||!s)throw new Error("Authentication required");const n=x(),l=await fetch(`${n}/api/team/invite/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s.access_token}`}});if(!l.ok){let i=`Error: ${l.status}`;try{i=(await l.json()).error||i}catch{i=l.statusText||i}throw new Error(i)}K()}catch(s){alert("Failed to cancel invitation: "+s.message)}finally{w(!1)}}},nt=async(t,s)=>{if(ve(s)&&s!=="owner"&&!(typeof t=="string"&&t.startsWith("owner-"))&&confirm("Are you sure you want to remove this team member?")){w(!0);try{const{data:{session:a},error:n}=await u.auth.getSession();if(n||!a)throw new Error("Authentication required");const l=x(),i=await fetch(`${l}/api/team/member/${t}/status`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a.access_token}`},body:JSON.stringify({status:"removed"})});if(!i.ok){let o=`Error: ${i.status}`;try{const g=await i.json();o=g.error||g.details||o}catch{o=i.statusText||o}throw new Error(o)}K()}catch(a){alert(`Failed to remove member: ${a.message||"Unknown error"}`)}finally{w(!1)}}},it=async(t,s)=>{if(ve(s)&&s!=="owner"&&!(typeof t=="string"&&t.startsWith("owner-"))){w(!0);try{const{data:{session:a},error:n}=await u.auth.getSession();if(n||!a)throw new Error("Authentication required");const l=x(),i=await fetch(`${l}/api/team/member/${t}/status`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a.access_token}`},body:JSON.stringify({status:"inactive"})});if(!i.ok){let o=`Error: ${i.status}`;try{const g=await i.json();o=g.error||g.details||o}catch{o=i.statusText||o}throw new Error(o)}K()}catch(a){alert(`Failed to deactivate member: ${a.message||"Unknown error"}`)}finally{w(!1)}}},lt=async t=>{if(q()){w(!0);try{const{data:{session:s},error:a}=await u.auth.getSession();if(a||!s)throw new Error("Authentication required");const n=x(),l=await fetch(`${n}/api/team/member/${t}/status`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s.access_token}`},body:JSON.stringify({status:"active"})});if(!l.ok){let i=`Error: ${l.status}`;try{const o=await l.json();i=o.error||o.details||i}catch{i=l.statusText||i}throw new Error(i)}K()}catch(s){alert(`Failed to reactivate member: ${s.message||"Unknown error"}`)}finally{w(!1)}}},Ue=t=>{var l,i,o;const s=(l=t.users)==null?void 0:l.display_name,a=(i=t.users)==null?void 0:i.first_name,n=(o=t.users)==null?void 0:o.last_name;if(s){const g=s.trim().split(" ");return g.length>=2?`${g[0].charAt(0)}${g[1].charAt(0)}`.toUpperCase():s.charAt(0).toUpperCase()}return`${(a==null?void 0:a.charAt(0))||""}${(n==null?void 0:n.charAt(0))||""}`.toUpperCase()},xe=t=>{var s,a,n;return((s=t.users)==null?void 0:s.display_name)||`${((a=t.users)==null?void 0:a.first_name)||""} ${((n=t.users)==null?void 0:n.last_name)||""}`.trim()},ot=t=>new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}),ct=t=>{const s=new Date,n=new Date(t)-s,l=Math.floor(n/(1e3*60*60)),i=Math.floor(l/24);return i>0?`${i} day${i===1?"":"s"}`:l>0?`${l} hour${l===1?"":"s"}`:"Less than 1 hour"},Ie=(t,s)=>{const a=window.location.hostname==="localhost"?"http://localhost:5173":window.location.origin;return s&&s!=="undefined"?`${a}/invite/${s}`:`${a}/invite/id/${t}`},dt=async t=>{const s=t.token,a=t.id;if(!s&&!a){alert("No invitation information available. The invitation may be corrupted.");return}const n=Ie(a,s);try{await navigator.clipboard.writeText(n),alert("Invitation link copied to clipboard!")}catch{const i=document.createElement("textarea");i.value=n,document.body.appendChild(i),i.focus(),i.select();try{document.execCommand("copy"),alert("Invitation link copied to clipboard!")}catch{alert(`Copy failed. Link: ${n}`)}document.body.removeChild(i)}};return e.jsxs("div",{className:"min-h-screen bg-gradient-to-tr from-[#FFE29F] via-[#FFA99F] to-[#FF719A] flex flex-col",children:[e.jsx("div",{className:"bg-white border-b border-gray-200 shadow-sm sticky top-0 z-30",children:e.jsxs("div",{className:"px-4 md:px-6 h-14 md:h-16 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-9 h-9 rounded-xl bg-gradient-to-br from-[#FFA99F] to-[#FF719A] flex items-center justify-center flex-shrink-0",children:e.jsx(D,{className:"w-5 h-5 text-white"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-base font-bold text-gray-900 leading-none",children:"Team Management"}),e.jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:ie?"Loadingâ¦":`${m.length} member${m.length!==1?"s":""}`})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>W(!L),className:`px-3 md:px-4 py-2 rounded-lg text-sm font-medium flex items-center gap-2 border transition-colors ${L?"bg-[#111] text-white border-[#111]":"border-gray-200 text-gray-700 hover:bg-gray-50"}`,children:[e.jsx(He,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:L?"Hide Chat":"Team Chat"})]}),!Te&&q()&&e.jsxs("button",{onClick:()=>Q(!0),className:"px-3 md:px-4 py-2 bg-[#111] hover:bg-[#333] text-white text-sm font-medium rounded-lg flex items-center gap-2 transition-colors",children:[e.jsx(V,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Invite Member"})]})]})]})}),e.jsx("div",{className:"flex-1 p-3 md:p-6",children:e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:gap-6 items-start",children:[e.jsxs("div",{className:"w-full flex flex-col gap-3 lg:w-56 lg:flex-shrink-0 lg:sticky lg:top-[5.5rem]",children:[e.jsxs("div",{className:"hidden lg:flex bg-white rounded-xl shadow-sm border border-[#e8e8e8] p-4 flex-col items-center gap-2 text-center",children:[e.jsx("div",{className:"w-14 h-14 roun
19ded-xl overflow-hidden bg-gradient-to-br from-[#FFE29F] via-[#FFA99F] to-[#FF719A] flex items-center justify-center flex-shrink-0",children:(()=>{var a;const t=(a=M.find(n=>(n.platform==="etsy"||!n.platform)&&n.icon_url_fullxfull))==null?void 0:a.icon_url_fullxfull,s=(j==null?void 0:j.logo_url)||t;return s?e.jsx("img",{src:s,alt:h||"Org",className:"w-full h-full object-cover",draggable:!1}):e.jsx(D,{className:"w-7 h-7 text-white"})})()}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900 leading-tight",children:h||"Your Organization"}),(_==null?void 0:_.shop_name)&&e.jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:_.shop_name})]})]}),e.jsx("div",{className:"bg-white rounded-xl shadow-sm border border-[#e8e8e8] p-1.5 lg:p-2 flex lg:block gap-1 overflow-x-auto",children:[{id:"members",label:"Members",icon:ce,badge:F.size>0?F.size:null},{id:"invitations",label:"Invitations",icon:Y,badge:O.length>0?O.length:null},{id:"roles",label:"Roles",icon:he,badge:null},{id:"organization",label:"Organization",icon:D,badge:null}].map(t=>{const s=t.icon,a=le===t.id;return e.jsxs("button",{onClick:()=>Ze(t.id),className:`flex-1 lg:flex-none lg:w-full flex flex-col lg:flex-row items-center justify-center lg:justify-start gap-1 lg:gap-2.5 px-2 lg:px-3 py-2 lg:py-2.5 rounded-lg text-xs lg:text-sm transition-colors lg:mb-0.5 min-w-[4rem] ${a?"bg-[#f0f0f0] text-[#111] font-semibold":"text-gray-500 font-medium hover:bg-[#f7f7f7]"}`,children:[e.jsx(s,{className:`w-4 h-4 flex-shrink-0 ${a?"text-[#111]":"text-gray-400"}`}),e.jsx("span",{className:"text-center lg:text-left lg:flex-1 leading-tight",children:t.label}),t.badge&&e.jsx("span",{className:`${t.id==="members"?"bg-green-500":"bg-orange-500"} text-white text-[10px] font-bold rounded-full px-1.5 py-0.5 leading-none`,children:t.badge})]},t.id)})})]}),e.jsxs("div",{className:"flex-1 bg-white rounded-xl shadow-sm border border-[#e8e8e8] overflow-hidden min-w-0",children:[le==="members"&&e.jsxs("div",{className:"p-4 lg:p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-[#0a0a0a] flex items-center justify-center flex-shrink-0",children:e.jsx(ce,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900",children:"Team Members"}),e.jsxs("p",{className:"text-sm text-gray-600",children:[m.length," member",m.length!==1?"s":""," in your organization",F.size>0&&e.jsxs("span",{className:"text-green-600 font-medium",children:[" ","⢠",F.size," online"]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[ie?e.jsx(e.Fragment,{children:[...Array(3)].map((t,s)=>e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl border border-[#e8e8e8] animate-pulse",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-12 h-12 bg-gray-200 rounded-xl"}),e.jsx("div",{className:"absolute -bottom-1 -right-1 w-5 h-5 bg-gray-200 rounded-full"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"h-4 bg-gray-200 rounded w-32 mb-2"}),e.jsx("div",{className:"h-3 bg-gray-200 rounded w-48"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-6 bg-gray-200 rounded-full w-20"}),e.jsx("div",{className:"w-8 h-8 bg-gray-200 rounded-lg"})]})]},`skeleton-${s}`))}):e.jsx(mt,{children:m.map((t,s)=>{var n,l,i,o,g,p,f,P;const a=((n=B[t.role])==null?void 0:n.icon)||V;return e.jsxs(ge.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},transition:{delay:s*.05},className:"flex items-center justify-between p-3 md:p-4 bg-gray-50 rounded-xl border border-[#e8e8e8] hover:shadow-md transition-all group",children:[e.jsxs("div",{className:"flex items-center gap-3 md:gap-4 min-w-0",children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[(l=t.users)!=null&&l.avatar_public_url?e.jsx("img",{src:t.users.avatar_public_url,alt:xe(t),className:"w-12 h-12 rounded-xl object-cover",onError:S=>{S.currentTarget.style.display="none",S.currentTarget.nextSibling.style.display="flex"}}):null,e.jsx("div",{className:"w-12 h-12 bg-gradient-to-br from-[#FFE29F] via-[#FFA99F] to-[#FF719A] rounded-xl items-center justify-center text-white font-semibold text-sm",style:{display:(i=t.users)!=null&&i.avatar_public_url?"none":"flex"},children:Ue(t)}),F.has((o=t.users)==null?void 0:o.id)&&e.jsx("div",{className:"absolute -top-1 -right-1 w-3.5 h-3.5 bg-green-500 rounded-full border-2 border-white shadow-sm"}),e.jsx("div",{className:"absolute -bottom-1 -right-1 w-5 h-5 bg-[#111] rounded-full flex items-center justify-center",children:e.jsx(a,{className:"w-3 h-3 text-white"})})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-semibold text-gray-900 truncate",children:xe(t)}),e.jsx("p",{className:"text-sm text-gray-600 truncate",children:(g=t.users)==null?void 0:g.email})]})]}),e.jsxs("div",{className:"flex items-center gap-2 md:gap-3 flex-shrink-0",children:[e.jsxs("span",{className:`hidden sm:inline-flex items-center gap-1 px-3 py-1 text-xs font-medium rounded-full ${(p=B[t.role])==null?void 0:p.color}`,children:[e.jsx(a,{className:"w-3 h-3"}),(f=B[t.role])==null?void 0:f.name]}),ve(t.role)&&(t.user_id||((P=t.users)==null?void 0:P.id))!==(y==null?void 0:y.id)&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>it(t.id,t.role),className:"text-amber-500 hover:text-amber-700 p-2 hover:bg-amber-50 rounded-lg transition-all",title:"Deactivate member",children:e.jsx(Re,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>nt(t.id,t.role),className:"text-red-500 hover:text-red-700 p-2 hover:bg-red-50 rounded-lg transition-all",title:"Remove member",children:e.jsx(_e,{className:"w-4 h-4"})})]})]})]},t.id)})}),!ie&&m.length===0&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"w-16 h-16 bg-[#0a0a0a] rounded-2xl flex items-center justify-center mx-auto mb-4",children:e.jsx(V,{className:"w-8 h-8 text-white"})}),e.jsx("h4",{className:"text-lg font-medium text-gray-900 mb-2",children:"No team members yet"}),e.jsx("p",{className:"text-gray-600",children:q()?"Send your first invitation to get started!":"Ask an admin to invite you to the team."})]}),!ie&&H.length>0&&e.jsxs("div",{className:"mt-6 pt-6 border-t border-gray-100",children:[e.jsxs("p",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wider mb-3",children:["Deactivated (",H.length,")"]}),e.jsx("div",{className:"space-y-2",children:H.map(t=>{var a,n,l,i,o;const s=((a=B[t.role])==null?void 0:a.icon)||V;return e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50/60 rounded-xl border border-dashed border-gray-200 opacity-70",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"relative",children:[(n=t.users)!=null&&n.avatar_public_url?e.jsx("img",{src:t.users.avatar_public_url,alt:xe(t),className:"w-12 h-12 rounded-xl object-cover grayscale",onError:g=>{g.currentTarget.style.display="none",g.currentTarget.nextSibling.style.display="flex"}}):null,e.jsx("div",{className:"w-12 h-12 bg-gray-200 rounded-xl items-center justify-center text-gray-400 font-semibold text-sm",style:{display:(l=t.users)!=null&&l.avatar_public_url?"none":"flex"},children:Ue(t)}),e.jsx("div",{className:"absolute -bottom-1 -right-1 w-5 h-5 bg-gray-400 rounded-full flex items-center justify-center",children:e.jsx(Re,{className:"w-3 h-3 text-white"})})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-gray-500",children:xe(t)}),e.jsx("p",{className:"text-sm text-gray-400",children:(i=t.users)==null?void 0:i.email})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 px-3 py-1 text-xs font-medium rounded-full bg-gray-100 text-gray-400",children:[e.jsx(s,{className:"w-3 h-3"}),(o=B[t.role])==null?void 0:o.name]}),q()&&e.jsx("button",{onClick:()=>
19lt(t.id),className:"text-green-600 hover:text-green-800 p-2 hover:bg-green-50 rounded-lg transition-all",title:"Reactivate member",children:e.jsx(xt,{className:"w-4 h-4"})})]})]},t.id)})})]})]})]}),le==="invitations"&&e.jsxs("div",{className:"p-4 lg:p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-[#0a0a0a] flex items-center justify-center flex-shrink-0",children:e.jsx(Y,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900",children:"Pending Invitations"}),e.jsxs("p",{className:"text-sm text-gray-600",children:[O.length," invitation",O.length!==1?"s":""," awaiting acceptance"]})]})]}),q()?ie?e.jsx("div",{className:"space-y-4",children:[...Array(2)].map((t,s)=>e.jsxs("div",{className:"bg-gray-50 rounded-xl border border-[#e8e8e8] p-4 space-y-3 animate-pulse",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"h-4 bg-gray-200 rounded w-40 mb-2"}),e.jsx("div",{className:"h-5 bg-gray-200 rounded-full w-16"})]}),e.jsx("div",{className:"w-6 h-6 bg-gray-200 rounded"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-3 bg-gray-200 rounded w-32"}),e.jsx("div",{className:"h-3 bg-gray-200 rounded w-28"})]})]},`skeleton-inv-${s}`))}):O.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"w-16 h-16 bg-[#0a0a0a] rounded-2xl flex items-center justify-center mx-auto mb-4",children:e.jsx(Y,{className:"w-8 h-8 text-white"})}),e.jsx("h4",{className:"text-lg font-medium text-gray-900 mb-2",children:"No pending invitations"}),e.jsx("p",{className:"text-gray-600",children:"All invitations have been accepted or have expired."}),e.jsxs("button",{onClick:()=>Q(!0),className:"mt-4 px-4 py-2 bg-[#111] hover:bg-[#333] text-white text-sm font-medium rounded-lg inline-flex items-center gap-2 transition-colors",children:[e.jsx(V,{className:"w-4 h-4"}),"Send Invitation"]})]}):e.jsx("div",{className:"space-y-4",children:O.map(t=>{var s,a;return e.jsxs("div",{className:"bg-gray-50 rounded-xl border border-[#e8e8e8] p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-900 text-sm",children:t.email}),e.jsx("span",{className:`inline-flex items-center gap-1 px-2 py-1 text-xs font-medium rounded-full ${((s=B[t.role])==null?void 0:s.color)||"bg-gray-100 text-gray-800"}`,children:((a=B[t.role])==null?void 0:a.name)||t.role})]}),e.jsx("button",{onClick:()=>rt(t.id),className:"text-red-500 hover:text-red-700 p-1.5 hover:bg-red-50 rounded-lg transition-colors",title:"Cancel invitation",children:e.jsx(qe,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"space-y-1.5 text-xs text-gray-600",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ut,{className:"w-3 h-3"}),e.jsxs("span",{children:["Sent: ",ot(t.created_at)]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(gt,{className:"w-3 h-3"}),e.jsxs("span",{children:["Expires in:"," ",ct(t.expires_at)]})]}),t.users&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{className:"w-3 h-3"}),e.jsxs("span",{children:["Sent by:"," ",t.users.display_name||`${t.users.first_name||""} ${t.users.last_name||""}`.trim()]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2 border-t border-[#e8e8e8]",children:[e.jsxs("button",{onClick:()=>dt(t),className:"flex-1 flex items-center justify-center gap-2 px-3 py-2 bg-[#111] hover:bg-[#333] text-white text-xs font-medium rounded-lg transition-colors",children:[e.jsx(ht,{className:"w-3 h-3"}),"Copy Invite Link"]}),e.jsx("button",{onClick:()=>{const n=Ie(t.id,t.token);window.open(n,"_blank")},className:"flex items-center justify-center px-3 py-2 border border-[#e8e8e8] text-gray-700 text-xs font-medium rounded-lg hover:bg-gray-50 transition-colors",title:"Open invite link",children:e.jsx(ft,{className:"w-3 h-3"})})]})]},t.id)})}):e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"w-16 h-16 bg-[#0a0a0a] rounded-2xl flex items-center justify-center mx-auto mb-4",children:e.jsx(Y,{className:"w-8 h-8 text-white"})}),e.jsx("h4",{className:"text-lg font-medium text-gray-900 mb-2",children:"No access"}),e.jsx("p",{className:"text-gray-600",children:"Only admins and owners can view pending invitations."})]})]}),le==="roles"&&e.jsxs("div",{className:"p-4 lg:p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-[#0a0a0a] flex items-center justify-center flex-shrink-0",children:e.jsx(he,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900",children:"Role Permissions"}),e.jsx("p",{className:"text-sm text-gray-600",children:"What each role can access in Sortaflow"})]}),["owner","admin"].includes(U)&&e.jsxs("button",{onClick:()=>d("/dashboard/team/permissions"),className:"ml-auto flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-[#e8e8e8] bg-white text-xs font-semibold text-gray-700 hover:bg-gray-50 transition-colors",children:[e.jsx(pt,{className:"w-3.5 h-3.5"}),"Edit Permissions"]})]}),e.jsxs("div",{className:"mb-5 px-4 py-3 bg-gray-50 rounded-xl border border-[#e8e8e8] text-xs text-gray-500 flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4 text-gray-400 flex-shrink-0"}),e.jsxs("span",{children:["Each role inherits all permissions from the roles below it."," ",e.jsx("span",{className:"font-medium text-gray-700",children:"Member â Manager â Admin â Owner"})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-[#e8e8e8] overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-gradient-to-r from-green-500 to-emerald-500",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-white/20 flex items-center justify-center",children:e.jsx(V,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-white text-sm",children:"Member"}),e.jsx("p",{className:"text-white/80 text-xs",children:"Handle assigned orders"})]})]}),e.jsx("div",{className:"px-4 py-3 bg-gray-50 grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-2",children:[{icon:De,label:"Kanban board & order management"},{icon:Be,label:"Pack Mode scanning"},{icon:He,label:"Team messaging"},{icon:bt,label:"UploadFlow (customer files)"},{icon:Ve,label:"SpreadFlow"},{icon:We,label:"Account settings"}].map(({icon:t,label:s})=>e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-700",children:[e.jsx(oe,{className:"w-3.5 h-3.5 text-green-500 flex-shrink-0"}),e.jsx(t,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}),e.jsx("span",{children:s})]},s))})]}),e.jsxs("div",{className:"rounded-xl border border-[#e8e8e8] overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-gradient-to-r from-blue-500 to-cyan-500",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-white/20 flex items-center justify-center",children:e.jsx(ce,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-white text-sm",children:"Manager"}),e.jsx("p",{className:"text-white/80 text-xs",children:"Manage orders and workflows + everything Members can do"})]})]}),e.jsx("div",{className:"px-4 py-3 bg-gray-50 grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-2",children:[{icon:Be,label:"Bulk Editor (profiles, images, videos)"},{icon:De,label:"Manage workflows"},{icon:wt,label:"Seller Tools & Profit Estimator"},{icon:yt,label:"Listing image & video editor"},{icon:Ve,label:"Content templates & taxonomy"},{icon:jt,label:"Export CSV"}].map(({icon:t,label:s})=>e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-700",children:[e.jsx(oe,{className:"w-3.5 h-3.5 text-blue-500 flex-shrink-0"}),e.jsx(t,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}),e.jsx("span",{children:s})]},s))})]}),e.jsxs("div",{className:"rounded-xl border border-[#e8e8e8] overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-gradient-to-r from-red-500 to-orange-500",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-white/20 flex items-center justify-center",children:e.jsx(he,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-white text-sm",children:"Admin"}),e.jsx("p",{className:"text-white/80 text-xs",children:"Manage team and settings + everything Managers can do"})]})]}),e.jsx("div",{className:"px-4 py-3 bg-gray-50 grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-2",children:[{icon:ce,label:"Invite & remove members"},{icon:vt,label:"Automation rules"},{icon:We,label:"Billing & integrations settings"},{icon:D,label:"Rename organization"},{icon:Y,label:"Manage pending invitations"},{icon:_e,label:"Remove managers & members"}].map(({icon:t,label:s})=>e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-700",children:[e.jsx(oe,{className:"w-3.5 h-3.5 text-red-500 flex-shrink-0"}),e.jsx(t,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}),e.jsx("span",{children:s})]},s))})]}),e.jsxs("div",{className:"rounded-xl border border-[#e8e8e8] overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 bg-gradient-to-r from-[#FF719A] to-[#FFA99F]",children:[e.jsx("div",{className:"w-7 h-7 rounded-lg bg-white/20 flex items-center justify-center",children:e.jsx(ke,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-white text-sm",children:"Owner"}),e.jsx("p",{className:"text-white/80 text-xs",children:"Full access â cannot be removed"})]})]}),e.jsx("div",{className:"px-4 py-3 bg-gray-50 grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-2",children:[{icon:Pe,label:"Everything Admins can do"},{icon:_e,label:"Remove admins"},{icon:D,label:"Delete or transfer organization"},{icon:ke,label:"Only one per organization"}].map(({icon:t,label:s})=>e.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-700",children:[e.jsx(oe,{className:"w-3.5 h-3.5 text-[#FF719A] flex-shrink-0"}),e.jsx(t,{className:"w-3.5 h-3.5 text-gray-400 flex-shrink-0"}),e.jsx("span",{children:s})]},s))})]})]})]}),le==="organization"&&e.jsxs("div",{className:"p-4 lg:p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-[#0a0a0a] flex items-center justify-center flex-shrink-0",children:e.jsx(D,{className:"w-4 h-4 text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900",children:"Organization"}),e.jsx("p",{className:"text-sm text-gray-600",children:"Manage your organization settings"})]})]}),Ye||Te?e.jsx("div",{className:"animate-pulse space-y-4",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-16 h-16 bg-gray-200 rounded-xl"}),e.jsxs("div",{children:[e.jsx("div",{className:"h-6 bg-gray-200 rounded w-48 mb-2"}),e.jsx("div",{className:"h-4 bg-gray-200 rounded w-32"})]})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-4 p-4 bg-gray-50 rounded-xl border border-[#e8e8e8]",children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx("div",{className:"w-16 h-16 bg-gradient-to-br from-[#FFE29F] via-[#FFA99F] to-[#FF719A] rounded-xl flex items-center justify-center shadow-md overflow-hidden",children:(()=>{var a;const t=(a=M.find(n=>(n.platform==="etsy"||!n.platform)&&n.icon_url_fullxfull))==null?void 0:a.icon_url_fullxfull,s=(j==null?void 0:j.logo_url)||t;return s?e.jsx("img",{src:s,alt:h||"Org",className:"w-full h-full object-cover rounded-xl",draggable:!1}):e.jsx(D,{className:"w-8 h-8 text-white"})})()}),Ne()&&e.jsx("button",{onClick:()=>{we(t=>!t),ae(null),re(null),ne(null)},className:"absolute -bottom-1 -right-1 w-5 h-5 bg-white border border-gray-300 rounded-full flex items-center justify-center shadow text-gray-600 hover:bg-gray-100 transition",title:"Change organization image",children:e.jsx(Je,{className:"w-3 h-3"})})]}),e.jsxs("div",{className:"flex-1",children:[be?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:v,onCh
19ange:t=>k(t.target.value),className:"text-xl font-bold bg-transparent border-b-2 border-[#111] focus:outline-none focus:border-[#333] transition-colors text-gray-900",autoFocus:!0,onKeyDown:t=>t.key==="Enter"&&Le()}),e.jsx("button",{onClick:Le,disabled:ee,className:"p-1.5 text-green-600 hover:bg-green-50 rounded-lg transition-colors",children:e.jsx(oe,{className:"w-4 h-4"})}),e.jsx("button",{onClick:tt,className:"p-1.5 text-gray-400 hover:bg-gray-50 rounded-lg transition-colors",children:e.jsx(qe,{className:"w-4 h-4"})})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-xl font-bold text-gray-900",children:h||"Your Organization"}),Ne()&&e.jsx("button",{onClick:()=>G(!0),className:"p-1.5 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded-lg transition-colors",children:e.jsx(Je,{className:"w-4 h-4"})})]}),e.jsxs("p",{className:"text-sm text-gray-600 mt-0.5",children:[m.length," member",m.length!==1?"s":""]})]}),q()&&e.jsx("div",{className:"bg-green-50 px-3 py-1.5 rounded-lg border border-green-200 flex-shrink-0",children:e.jsx("span",{className:"text-sm font-medium text-green-700",children:"Admin"})})]}),Ke&&Ne()&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-gray-200 space-y-4",children:[M.filter(t=>t.icon_url_fullxfull).length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 mb-2",children:"Use a shop icon"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:M.filter(t=>t.icon_url_fullxfull).map(t=>e.jsx("button",{onClick:()=>{ne(t.icon_url_fullxfull),ae(null),re(null)},className:`w-12 h-12 rounded-xl overflow-hidden border-2 transition ${ye===t.icon_url_fullxfull?"border-[#111] ring-2 ring-gray-300":"border-transparent hover:border-gray-300"}`,title:t.shop_name,children:e.jsx("img",{src:t.icon_url_fullxfull,alt:t.shop_name,className:"w-full h-full object-cover"})},t.id))})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-gray-700 mb-2",children:"Upload a custom image"}),e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer w-fit",children:[e.jsx("div",{className:"px-3 py-1.5 rounded-lg border border-gray-300 bg-white text-sm text-gray-700 hover:bg-gray-50 transition font-medium",children:"Choose file"}),Oe?e.jsx("img",{src:Oe,alt:"Preview",className:"w-10 h-10 rounded-lg object-cover border border-gray-200"}):e.jsx("span",{className:"text-xs text-gray-400",children:"No file chosen"}),e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:t=>{var n;const s=(n=t.target.files)==null?void 0:n[0];if(!s)return;ae(s),ne(null);const a=new FileReader;a.onload=l=>re(l.target.result),a.readAsDataURL(s)}})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:st,disabled:Ae||!se&&!ye,className:"px-4 py-1.5 rounded-lg bg-[#111] text-white text-sm font-medium hover:bg-[#333] transition disabled:opacity-50 disabled:cursor-not-allowed",children:Ae?"Savingâ¦":"Save"}),e.jsx("button",{onClick:()=>{we(!1),ae(null),re(null),ne(null)},className:"px-4 py-1.5 rounded-lg border border-gray-300 text-gray-700 text-sm font-medium hover:bg-gray-50 transition",children:"Cancel"})]})]})]})]})]})]})}),y&&te&&e.jsx(St,{currentUser:y,organizationId:te,isOpen:L,onClose:()=>W(!1),onlineUserIds:F}),e.jsx(qt,{isOpen:$,onClose:()=>Q(!1),onInviteSent:at})]})}export{Yt as default}; 20//# sourceMappingURL=TeamManagement-CGHcsZBl.js.map
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.