1import{r as l,c as L,j as t,dC as R,S as v,ej as V,cQ as N,B as W,cP as Y,dF as w,dJ as x,e2 as g,L as Z,dj as k,dN as X,dK as ee,ef as te,eg as ae,dG as se,dm as le,dk as ne,dM as ie,cZ as oe,U as re,dI as _,az as ce}from"./index-Dp6uzjnE.js";import{a as me,A as de}from"./arionCharts-D6TxoLcV.js";import{u as pe}from"./useArionWorkforce-D6Tu5PR3.js";const D={full_name:"",email:"",position_title:"",department_name:"",employment_type:"full_time",status:"active",start_date:"",public_employment:!1},T={full_time:"Full time",part_time:"Part time",contract:"Contract",intern:"Intern"};function he(){const{orgId:m,isManager:d,loading:M}=pe(),[n,C]=l.useState([]),[j,I]=l.useState([]),[B,A]=l.useState(!0),[S,E]=l.useState(!1),[U,y]=l.useState(!1),[u,P]=l.useState(null),[s,o]=l.useState(D),[p,$]=l.useState(""),[r,q]=l.useState(""),[c,G]=l.useState("");l.useEffect(()=>{document.title="Arion â Team â Medarion"},[]);const h=l.useCallback(async()=>{if(m){A(!0);try{const[e,a]=await Promise.all([L(`/api/v1/workforce/employees?org_profile_id=${m}`),L(`/api/v1/workforce/departments?org_profile_id=${m}`).catch(()=>({results:[]}))]);C(e.results||[]),I(a.results||[])}catch{C([])}finally{A(!1)}}},[m]);l.useEffect(()=>{h()},[h]);function f(){o(D),P(null),y(!1)}function O(e){P(e.id),y(!0),o({full_name:e.full_name,email:e.email||"",position_title:e.position_title||"",department_name:e.department_name||"",employment_type:e.employment_type||"full_time",status:e.status==="active"?"active":"inactive",start_date:e.start_date?e.start_date.slice(0,10):"",public_employment:!1})}async function Q(e){if(e.preventDefault(),!m||!s.full_name.trim()||!s.email.trim())return;E(!0);const a={full_name:s.full_name.trim(),email:s.email.trim(),position_title:s.position_title.trim()||null,department_name:s.department_name.trim()||null,employment_type:s.employment_type,status:s.status==="active"?"active":"inactive",start_date:s.start_date||null,link_account:!0,public_employment:s.public_employment};try{u?await oe(`/api/v1/workforce/employees/${u}`,a):await re("/api/v1/workforce/employees",{org_profile_id:m,...a}),f(),await h(),_(u?"Employee updated":"Employee added")}catch{_("Could not save employee","error")}finally{E(!1)}}async function z(e){if(confirm("Deactivate this employee? They will be marked inactive."))try{await ce(`/api/v1/workforce/employees/${e}`),await h(),_("Employee deactivated")}catch{_("Could not remove employee","error")}}const F=l.useMemo(()=>{const e=p.trim().toLowerCase();return n.filter(a=>r&&(a.department_name||"")!==r||c&&a.status!==c?!1:e?a.full_name.toLowerCase().includes(e)||(a.email||"").toLowerCase().includes(e)||(a.position_title||"").toLowerCase().includes(e)||(a.department_name||"").toLowerCase().includes(e):!0)},[n,p,r,c]),b=n.filter(e=>e.status==="active").length,H=n.length-b,J=l.useMemo(()=>{const e=new Map;for(const a of n){if(a.status!=="active")continue;const i=a.department_name||"Unassigned";e.set(i,(e.get(i)||0)+1)}return Array.from(e.entries()).map(([a,i])=>({name:a,value:i})).sort((a,i)=>i.value-a.value)},[n]),K=l.useMemo(()=>{const e=new Map;for(const a of n){if(a.status!=="active")continue;const i=T[a.employment_type]||a.employment_type||"Other";e.set(i,(e.get(i)||0)+1)}return Array.from(e.entries()).map(([a,i])=>({name:a,value:i}))},[n]);return t.jsxs(R,{title:"Team Directory",lead:"Employees, roles, departments, and org structure.",badge:"People",icon:N,loading:M&&!n.length,stats:[{icon:V,label:"Active",value:b,color:v.emerald},{icon:N,label:"Inactive",value:H,color:v.slate},{icon:W,label:"Departments",value:j.length,color:v.indigo},{icon:Y,label:"Full-time",value:n.filter(e=>e.status==="active"&&e.employment_type==="full_time").length,color:v.violet}],actions:d?t.jsxs("button",{type:"button",onClick:()=>{f(),y(!0)},className:"medarion-btn-primary text-xs inline-flex items-center gap-1.5",children:[t.jsx(k,{className:"w-3.5 h-3.5"})," Add employee"]}):void 0,children:[n.length>0&&t.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[t.jsx(w,{title:"Headcount by department",lead:"Active employees per team",children:t.jsx(me,{data:J,centerValue:b,centerLabel:"Active",valueSuffix:"",emptyMessage:"No active employees"})}),t.jsx(w,{title:"Employment type",lead:"Active workforce composition",children:t.jsx(de,{data:K,emptyMessage:"No active employees"})})]}),d&&U&&t.jsx(w,{title:u?"Edit team member":"Add team member",lead:"Link their Medarion login email for employee self-service.",actions:t.jsx("button",{type:"button",onClick:f,className:"text-xs text-ink-500 hover:text-ink-950",children:"Cancel"}),children:t.jsxs("form",{onSubmit:Q,className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[t.jsx("input",{required:!0,className:x,placeholder:"Full name",value:s.full_name,onChange:e=>o(a=>({...a,full_name:e.target.value}))}),t.jsx("input",{required:!0,type:"email",className:x,placeholder:"Email",value:s.email,onChange:e=>o(a=>({...a,email:e.target.value}))}),t.jsx("input",{className:x,placeholder:"Position / title",value:s.position_title,onChange:e=>o(a=>({...a,position_title:e.target.value}))}),t.jsx("input",{className:x,list:"arion-dept-list",placeholder:"Department",value:s.department_name,onChange:e=>o(a=>({...a,department_name:e.target.value}))}),t.jsx("datalist",{id:"arion-dept-list",children:j.map(e=>t.jsx("option",{value:e.name},e.id))}
1),t.jsxs("select",{className:g,value:s.employment_type,onChange:e=>o(a=>({...a,employment_type:e.target.value})),children:[t.jsx("option",{value:"full_time",children:"Full time"}),t.jsx("option",{value:"part_time",children:"Part time"}),t.jsx("option",{value:"contract",children:"Contract"}),t.jsx("option",{value:"intern",children:"Intern"})]}),t.jsxs("select",{className:g,value:s.status,onChange:e=>o(a=>({...a,status:e.target.value})),children:[t.jsx("option",{value:"active",children:"Active"}),t.jsx("option",{value:"inactive",children:"Inactive"})]}),t.jsxs("label",{className:"text-xs text-ink-500 sm:col-span-2",children:["Start date",t.jsx("input",{type:"date",className:x,value:s.start_date,onChange:e=>o(a=>({...a,start_date:e.target.value}))})]}),t.jsxs("label",{className:"flex items-center gap-2 text-xs text-ink-700 sm:col-span-2",children:[t.jsx("input",{type:"checkbox",checked:s.public_employment,onChange:e=>o(a=>({...a,public_employment:e.target.checked}))}),"Show on public company profile when a matching Medarion account is linked"]}),t.jsxs("button",{type:"submit",disabled:S,className:"sm:col-span-2 medarion-btn-primary inline-flex items-center justify-center gap-2 disabled:opacity-50",children:[S?t.jsx(Z,{className:"w-4 h-4 animate-spin"}):t.jsx(k,{className:"w-4 h-4"}),u?"Update employee":"Add employee"]})]})}),t.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[t.jsx(X,{value:p,onChange:$,placeholder:"Search name, email, roleâ¦"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsxs("select",{className:`${g} w-auto`,value:r,onChange:e=>q(e.target.value),children:[t.jsx("option",{value:"",children:"All departments"}),j.map(e=>t.jsx("option",{value:e.name,children:e.name},e.id))]}),t.jsxs("select",{className:`${g} w-auto`,value:c,onChange:e=>G(e.target.value),children:[t.jsx("option",{value:"",children:"All statuses"}),t.jsx("option",{value:"active",children:"Active"}),t.jsx("option",{value:"inactive",children:"Inactive"})]})]})]}),t.jsx(ee,{columns:["Name","Position","Department","Type","Start","Status",...d?[""]:[]],loading:B&&!n.length,children:F.length?F.map(e=>t.jsxs("tr",{className:"hover:bg-surface-muted/40",children:[t.jsx("td",{className:"px-3 py-2.5",children:t.jsxs("div",{className:"flex items-center gap-2.5",children:[t.jsx(te,{name:e.full_name}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"font-medium text-ink-950 truncate",children:e.full_name}),t.jsx("p",{className:"text-xs text-ink-500 truncate",children:e.email||"â"})]})]})}),t.jsx("td",{className:"px-3 py-2.5 text-ink-600",children:e.position_title||"â"}),t.jsx("td",{className:"px-3 py-2.5 text-ink-600",children:e.department_name||"â"}),t.jsx("td",{className:"px-3 py-2.5 text-xs text-ink-600",children:T[e.employment_type]||"â"}),t.jsx("td",{className:"px-3 py-2.5 text-xs text-ink-500",children:ae(e.start_date)}),t.jsx("td",{className:"px-3 py-2.5",children:t.jsx(se,{status:e.status})}),d&&t.jsx("td",{className:"px-3 py-2.5",children:t.jsxs("div",{className:"flex gap-1 justify-end",children:[t.jsx("button",{type:"button",onClick:()=>O(e),className:"p-2 rounded-lg hover:bg-surface-muted text-ink-600",title:"Edit",children:t.jsx(le,{className:"w-3.5 h-3.5"})}),t.jsx("button",{type:"button",onClick:()=>{z(e.id)},className:"p-2 rounded-lg hover:bg-red-50 text-red-600",title:"Deactivate",children:t.jsx(ne,{className:"w-3.5 h-3.5"})})]})})]},e.id)):t.jsx(ie,{icon:N,title:p||r||c?"No matching employees":"No employees yet",description:p||r||c?"Try clearing filters or search terms.":d?"Add your team members or run workforce seed data.":"Employee records will appear here once added.",action:d&&!p&&!r&&!c?t.jsxs("button",{type:"button",onClick:()=>{f(),y(!0)},className:"medarion-btn-primary text-xs inline-flex items-center gap-1.5",children:[t.jsx(k,{className:"w-3.5 h-3.5"})," Add employee"]}):void 0})})]})}export{he as ArionTeamPage};
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.