import{j as t,M as m,S as g}from"./vendor-mui-CBBEb17G.js";import{a as s}from"./vendor-react-BBazpZul.js";import{e as v,v as q,b0 as B,w as y,ao as S,fG as H,dP as K,b3 as M,fH as z}from"./index-IP_FWtso.js";import"./vendor-utils-BveVE6Uf.js";import{W as F}from"./workPlaceItem-_ruxAKJn.js";const Z=({onClose:h,defaultValue:l,onAdd:b,onDelete:I})=>{var j;const{centerInfo:p}=v(e=>e.data),{clinicId:D,officeId:C}=v(e=>e.doctorData),{GetDepartmentsReq:N}=z(),[u,n]=s.useState(!1),[a,w]=s.useState(),[i,k]=s.useState(null),[c,P]=s.useState(null),[x,W]=s.useState([]),O=async()=>{!c||!i||await b(+c.value)},E=async e=>{try{n(!0),await I(e)}finally{n(!1)}},A=async()=>{try{n(!0);const{data:e}=await N({ClinicId:D??void 0,OfficeId:C??void 0});e&&p&&w([{centerId:p.id,centerName:p.name,departments:e.map(o=>({id:o.id,title:o.title})),uuid:M()}])}finally{n(!1)}},G=async()=>{try{if(n(!0),!l||!a)return;const e=a.filter(r=>r.departments.some(d=>l.some(f=>f.departmentId===d.id))),o=[];for(let r of l){const d=e.flat().find(f=>f.departments.some(U=>U.id===r.departmentId));d&&o.push({id:r.id,centerUuid:d.uuid,centerName:d.centerName,departmentId:r.departmentId,departmentName:r.departmentName})}W(o)}finally{n(!1)}};s.useEffect(()=>{A()},[]),s.useEffect(()=>{G()},[l,a]);const L=(a==null?void 0:a.map(e=>({label:e.centerName,value:e.uuid})))||[],R=((j=a==null?void 0:a.find(e=>e.uuid==(i==null?void 0:i.value)))==null?void 0:j.departments.map(e=>({label:e.title,value:e.id.toString()})))||[];return t.jsxs(q,{title:"انتخاب محل کار",onClose:h,maxWidth:"md",children:[t.jsxs(B,{className:"!p-4 !m-2 border border-gray-400 rounded-xl !h-[430px] !overflow-hidden",children:[t.jsxs(m,{container:!0,spacing:1,children:[t.jsx(m,{item:!0,xs:12,sm:4,children:t.jsx(y,{label:"مرکز",selectOption:L,value:i,onChange:e=>k(e),loading:u})}),t.jsx(m,{item:!0,xs:12,sm:4,children:t.jsx(y,{label:"بخش",selectOption:R,value:c,onChange:e=>P(e),loading:u})}),t.jsx(m,{item:!0,xs:12,sm:4,children:t.jsx(S,{fullWidth:!0,disabled:!c,onClick:O,children:"افزودن به لیست"})})]}),t.jsx(H,{className:"!mt-4 !mb-4"}),t.jsxs(g,{spacing:1,className:"!h-[200px] !overflow-y-auto",children:[u&&t.jsx(K,{}),!x.length&&t.jsx("h4",{className:"w-full text-center !p-4 border border-blue-400 rounded-xl",children:"محل کاری مشخص نشده است"}),x.map(e=>t.jsx(F,{info:e,onDelete:()=>E(e.id)},e.departmentId))]})]}),t.jsx(g,{direction:"row",justifyContent:"center",alignItems:"center",p:1,children:t.jsx(S,{color:"primary",onClick:()=>h(),children:"بستن"})})]})};export{Z as S};
