import{al as q,aX as J,at as Q,e9 as X,dD as f,I as m,J as k,aP as U,v as at,bL as it,x as ot}from"./index-IP_FWtso.js";import{p as Y,j as t,S as Z,W as C,c as rt,a2 as ct}from"./vendor-mui-CBBEb17G.js";import{a as s}from"./vendor-react-BBazpZul.js";import{i as $,p as W}from"./index-DWGens_O.js";const ft=q(Y)`
    position: absolute;
    right: 0;
    top: 0;
    z-index:1500;
    display: flex;
    justify-content: start;
    align-items: center;
    width: 50px;
    height: 100%;
    padding-right:10px;
    
    background: transparent;

    & .right-arrow {
        width: 10px;
    height: 10px;
    border: 2px solid blue;
    border-width: 2px 2px 0 0;
    rotate: 45deg;
    }

    .navigate-btn{
        padding: 20px !important;
        transition: all 0.3s ease;
        opacity:0.7 !important;
         background: rgba(0, 4, 15, 0.23) !important;
        &:hover {
            background: rgba(0, 4, 15, 0.5) !important;
        }
    }

    &:hover > .navigate-btn{
        opacity:1;
    }


`,vt=q(Y)`
    position: absolute;
    left: 0;
    top: 0;
    z-index:1500;
    display: flex;
    justify-content: end;
    align-items: center;
    width: 50px;
    height: 100%;
    padding-left:10px;
    background: transparent;
    }

    & .left-arrow {
        width: 10px;
        height: 10px;
        border: 2px solid blue;
        border-width: 0 0 2px 2px;
        rotate: 45deg;
    }
    .navigate-btn{
        padding: 20px !important;
        transition: all 0.3s ease;
        background: rgba(0, 4, 15, 0.23) !important;
       
     opacity:0.7;
        &:hover {
            background: rgba(0, 4, 15, 0.5) !important;
        }
        
    }

    &:hover > .navigate-btn{
        opacity:1;
    }

`;var v=(n=>(n[n.Add=1]="Add",n[n.Edit=2]="Edit",n[n.AddToFavorite=3]="AddToFavorite",n))(v||{});const tt=s.createContext(void 0),bt=({children:n})=>{const{getPatientInterestsAsync:e}=W(),{getInterestAsync:o}=$(),[c,d]=s.useState(),[x,l]=s.useState(),[I,b]=s.useState([]),[S,j]=s.useState(),[h,i]=s.useState(!1),[A,y]=s.useState(1),[p,g]=s.useState(),[w,a]=s.useState([]),[D,P]=s.useState(),[R,V]=s.useState(v.Add),[_,M]=s.useState(!1),[E,L]=s.useState(""),[z,B]=s.useState(!1),[H,F]=s.useState(!1),O={patientId:c,setPatientId:d,patientFavoritesData:x,setPatientFavoritesData:l,patientFavoritesSelected:S,setPatientFavoritesSelected:j,getPatientInterests:async()=>{if(i(!0),c)try{const{data:u}=await e(c);i(!1),l(u),b(u)}catch(u){console.log(u),i(!1)}},loading:h,setLoading:i,dialogState:A,setDialogState:y,interestList:p,getInterestList:async()=>{i(!0);try{const{data:u}=await o(null);i(!1),g(u),a(u)}catch(u){console.log(u),i(!1)}},interestSelected:D,setInterestSelected:P,dialogModeI:R,setDialogModeI:V,openEditIn:_,setopenEditIn:M,setTextValueIn:L,textValueIn:E,patientFavoritesList:I,interestListC:w,setInterestList:g,showAddInput:z,setShowAddInput:B,addFavorite:H,setAddFavorite:F};return t.jsx(tt.Provider,{value:O,children:n})},N=()=>s.useContext(tt),lt=[{title:"عنوان علاقه",dataIndex:"interestName",key:"interestName",width:30},{title:"توضیحات",dataIndex:"description",key:"description",width:50}],dt=()=>{const{patientId:n,patientFavoritesData:e,setPatientFavoritesSelected:o,getPatientInterests:c,loading:d}=N();s.useEffect(()=>{c()},[n]);const x=l=>{o(l)};return t.jsx(J,{loading:d,rowKey:"id",columns:lt||[],data:e||[],onClick:l=>x(l)})},xt=({onClose:n,patientId:e})=>{const{deletePatientInterestAsync:o}=W(),{setPatientId:c,patientFavoritesSelected:d,getPatientInterests:x,setDialogState:l,patientFavoritesList:I,setPatientFavoritesData:b,setPatientFavoritesSelected:S}=N(),j=Q();s.useEffect(()=>{c(e)},[]);const h=y=>{const p=I.filter(g=>g.interestName.includes(y.title));b(p)},i=()=>{d&&j({content:"آیا از حذف این علاقه از لیست مطمئن هستید؟"}).then(async()=>{const{message:y}=await o(d.id);k.success(y),x(),S(void 0)}).catch(()=>{})},A=()=>l(2);return t.jsx(t.Fragment,{children:t.jsxs(X,{onClose:n,title:"علایق بیمار",onSearch:h,fetchData:x,maxWidth:"md",searchLabel:"جستجو",children:[t.jsxs(Z,{direction:"row",justifyContent:"start",alignItems:"center",gap:1,className:"!mr-5",children:[t.jsx(f,{onClick:A,children:t.jsx(m.AddIcon,{fontSize:"large",color:"success"})}),t.jsx(f,{onClick:i,children:t.jsx(m.DeleteIcon,{fontSize:"large",color:d?"error":"disabled"})})]}),t.jsx(dt,{})]})})},ht=()=>{const{getInterestList:n,loading:e,interestList:o,setInterestSelected:c,setTextValueIn:d,setDialogModeI:x,setopenEditIn:l,setAddFavorite:I,setShowAddInput:b}=N();s.useEffect(()=>{n()},[]);const S=async i=>{c(i)},j=()=>{x(v.AddToFavorite),d(""),l(!0)},h=[{title:"عنوان",dataIndex:"title",key:"title",width:30},{key:"action",dataIndex:"action",title:"عملیات",width:50,render:()=>t.jsx("button",{type:"button",onClick:()=>{b(!0),I(!1)},children:t.jsx(C,{title:t.jsx("h1",{className:"text-sm",children:"افزودن توضیحات"}),placement:"left",children:t.jsx(m.Description,{color:"action",className:"!w-6 !h-6"})})})}];return t.jsx(J,{loading:e,rowKey:"id",columns:h||[],data:o||[],onClick:i=>S(i),onDoubleClick:j})},ut=s.forwardRef(function(e,o){return t.jsx(ct,{direction:"right",ref:o,...e})}),pt=({patientId:n})=>{const[e,o]=s.useState(!1),[c,d]=s.useState(""),[x,l]=s.useState(""),{addInterestAsync:I,updateInterest:b,deleteInterestAsync:S}=$(),{addPatientInterestAsync:j}=W(),{getInterestList:h,setDialogState:i,openEditIn:A,setopenEditIn:y,dialogModeI:p,textValueIn:g,setTextValueIn:w,interestSelected:a,setInterestSelected:D,getPatientInterests:P,interestListC:R,setInterestList:V,addFavorite:_,showAddInput:M,setShowAddInput:E,setAddFavorite:L}=N(),z=Q();s.useEffect(()=>{D(void 0)},[]);const B=()=>{i(1)},H=r=>{const st=R.filter(nt=>nt.title.includes(r.title));V(st)},F=()=>{y(!1)},K=async()=>{w(""),F()},G=async()=>{try{if(o(!0),p===v.Add&&(await I({title:g}),F(),h()),p===v.Edit&&(a!=null&&a.id&&await b({id:a==null?void 0:a.id,title:g}),F(),h()),p===v.AddToFavorite){const r={patientId:n,interestsId:a==null?void 0:a.id,description:g};await j(r),F(),P(),w(""),i(1)}}finally{o(!1)}},O=async()=>{try{if(!c)return k.warn("عنوان الزامیست");const{message:r}=await I({title:c});k.success(r),h(),T()}catch(r){console.log("ERROR_IN_ADDING_FAVORITE",r)}},u=async()=>{try{if(!a)return;const{message:r}=await j({patientId:n,description:x,interestsId:a.id});k.success(r),P(),T()}catch(r){console.log("ERROR_IN_ADDING_PATIENT_FAVORITE",r)}},et=()=>{a&&z({content:"آیا از حذف این علاقه مطمئنید؟"}).then(async()=>{const{message:r}=await S(a.id);return k.success(r),D(void 0),h()})},T=()=>{d(""),l(""),E(!1),L(!1)};return t.jsxs(t.Fragment,{children:[t.jsxs(X,{onClose:B,title:"علایق بیماران",onSearch:H,fetchData:h,maxWidth:"md",searchLabel:"جستجو",dialogProps:{TransitionComponent:ut},children:[t.jsx("div",{className:"mr-5",children:M?t.jsx("div",{className:"flex  gap-3 w-full max-w-xs",children:_?t.jsxs(t.Fragment,{children:[t.jsx(U,{disabled:e,autoFocus:!0,label:"عنوان",required:!0,value:c,onChange:d}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(f,{type:"button",color:e?"inherit":"success",onClick:O,children:t.jsx(C,{title:t.jsx("h1",{className:"text-sm",children:"ثبت"}),children:t.jsx(m.Check,{color:e?"inherit":"success"})})}),t.jsx(f,{disabled:e,type:"button",color:e?"inherit":"error",onClick:()=>T(),children:t.jsx(C,{title:t.jsx("h1",{className:"text-sm",children:"لغو"}),children:t.jsx(m.CloseIcon,{color:e?"inherit":"error"})})})]})]}):t.jsxs(t.Fragment,{children:[t.jsx(U,{value:x,onChange:l,autoFocus:!0,disabled:e,label:"توضیحات"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(f,{disabled:e,type:"button",color:e?"inherit":"success",onClick:u,children:t.jsx(C,{title:t.jsx("h1",{className:"text-sm",children:"ثبت"}),children:t.jsx(m.Check,{color:e?"inherit":"success"})})}),t.jsx(f,{disabled:e,type:"button",color:e?"inherit":"error",onClick:()=>T(),children:t.jsx(C,{title:t.jsx("h1",{className:"text-sm",children:"لغو"}),children:t.jsx(m.CloseIcon,{color:e?"inherit":"error"})})})]})]})}):t.jsxs("div",{className:"flex gap-2",children:[t.jsx(f,{color:"success",className:"!min-h-[32px]",onClick:()=>{E(!0),L(!0)},children:t.jsx(C,{title:t.jsx("h1",{className:"text-sm",children:"افزودن"}),children:t.jsx(m.AddIcon,{color:"success"})})}),t.jsx(f,{disabled:!a,color:"error",className:"!min-h-[32px]",onClick:et,children:t.jsx(C,{title:t.jsx("h1",{className:"text-sm",children:"حذف"}),children:t.jsx(m.DeleteIcon,{color:a?"error":"inherit"})})})]})}),t.jsx(ht,{})]}),A&&t.jsx(at,{onClose:F,maxWidth:"xs",title:p===v.Add?"افزودن علاقه":p===v.Edit?"ویرایش":"توضیحات",children:t.jsxs(rt,{children:[t.jsx(Z,{padding:1,alignItems:"center",children:t.jsx(it,{label:"متن",size:"small",value:g,onChange:r=>w(r)})}),t.jsx(ot,{onSubmit:G,onClose:K,loading:e})]})})]})},St=({onClose:n,patientId:e})=>{const{dialogState:o}=N();return t.jsxs(t.Fragment,{children:[o===1&&t.jsx(xt,{onClose:n,patientId:e}),o===2&&t.jsx(pt,{patientId:e})]})};export{bt as F,St as S,ft as a,vt as b};
