1import{u as k,a5 as q,a as D,t as T,r as M,v as C,w as F,X as O,I as $,j as i,W as Q,P as L,V as W,B as E}from"./index-BrGYhmyP.js";import{M as z}from"./workflow-service-Du3HdXiV.js";import{M as R}from"./order-service-BZpFWy5A.js";import{A as _}from"./Accordion-y1a6osN7.js";import{A as J}from"./AccordionItem-BhQ8G56S.js";import{M as K}from"./MedicalCollegesNonJordanianAQAOrder-C4QjOY3D.js";function P(p){const{t,i18n:b}=k(["MedicalCollegesNonJordanianAQA","Shared"]),m=q(),f=D(),{showToast:y}=T(),[h,g]=M.useState([]),[A,v]=M.useState(!1),I=e=>e.role==="committeeSecretary"?t("committeeSecretary"):e.committeeMemberRoleId===1?b.language?.startsWith("ar")?"Ø±Ø¦ÙØ³":"President":e.committeeMemberRoleId===2?b.language?.startsWith("ar")?"عضÙ":"Member":t("committeeMember"),{data:o,isLoading:S,error:x}=C({queryKey:["openTask",p],queryFn:async()=>{if(!p)throw new Error("SerialGID is required");const e=await O.openTask(p);if(e.hasError||!e.data?.orderId)throw new Error("Failed to open task or orderId not found");return e.data},enabled:!!p}),{data:d,isLoading:l}=C({queryKey:["mcnjaqaCommittee",o?.orderId],queryFn:async()=>{if(!o?.orderId)return null;const e=await R.getCommittee(o.orderId);return!e.hasError&&e.data?e.data:null},enabled:!!o?.orderId});M.useEffect(()=>{if(!d)return;const e=[];d.committeeSecretaryUser&&e.push({id:0,memberEmail:d.committeeSecretaryUser.email||"",memberArabicName:d.committeeSecretaryUser.arabicName||"",memberEnglishName:d.committeeSecretaryUser.englishName||"",role:"committeeSecretary",isApprovedByInstitution:d.isSecretaryApprovedByInstitution??null,institutionNotes:d.secretaryInstitutionNotes||"",committeeMemberRoleId:null,memberOrganization:null}),d.orderCommitteeMembers&&d.orderCommitteeMembers.forEach(n=>{const u=n.orderCommitteeMemberDetails?.find(s=>s.locale==="ar"),a=n.orderCommitteeMemberDetails?.find(s=>s.locale==="en");e.push({id:n.id,memberEmail:n.memberEmail||"",memberArabicName:u?.name||"",memberEnglishName:a?.name||"",role:"committeeMember",isApprovedByInstitution:n.isApprovedByInstitution??null,institutionNotes:n.institutionNotes||"",committeeMemberRoleId:n.committeeMemberRoleId??null,memberOrganization:n.memberOrganization||""})}),g(e)},[d]);const r=(e,n,u)=>{g(a=>a.map(s=>s.id===e&&s.role===n?{...s,isApprovedByInstitution:u}:s))},c=(e,n,u)=>{g(a=>a.map(s=>s.id===e&&s.role===n?{...s,institutionNotes:u}:s))},N=F({mutationFn:async()=>{if(!o?.orderId)throw new Error("Order ID not found");const e=h.find(a=>a.role==="committeeSecretary"),n=h.filter(a=>a.role==="committeeMember").map(a=>({id:a.id,isApprovedByInstitution:a.isApprovedByInstitution,institutionNotes:a.institutionNotes||null})),u=await R.setCommitteeEvaluation(o.orderId,{isSecretaryApprovedByInstitution:e?.isApprovedByInstitution??null,secretaryInstitutionNotes:e?.institutionNotes||null,membersEvaluations:n});if(u.hasError)throw new Error(u.description||t("Shared:actionFailed"))},onSuccess:async()=>
1{await m.invalidateQueries({queryKey:["mcnjaqaCommittee",o?.orderId]})}});return{memberEvaluations:h,isSubmitting:A,taskData:o,isLoadingTask:S,isLoadingCommittee:l,error:x,handleEvaluationChange:r,handleNotesChange:c,handleSubmit:async()=>{if(!o?.orderId||!p)return;const e=h.filter(a=>a.role==="committeeMember");if(e.filter(a=>a.isApprovedByInstitution===null).length>0){y({type:"warning",title:t("pleaseEvaluateAllMembers")});return}if(e.filter(a=>a.isApprovedByInstitution===!1&&!a.institutionNotes?.trim()).length>0){y({type:"warning",title:t("pleaseEnterNotesForRejectedMembers")});return}v(!0);try{await N.mutateAsync();const s=e.some(B=>B.isApprovedByInstitution===!1)?"RejectCommittee":"ApproveCommittee",w=await z.workflowAction(o.orderId,{actionName:s,serialGuid:p,activityGuid:o.activityGuid,notes:void 0});if(w.hasError)throw new Error(w.description||t("Shared:actionFailed"));y({type:"success",title:t("Shared:success"),message:t(s==="ApproveCommittee"?"ApproveCommitteeSuccess":"RejectCommitteeSuccess")}),f("/app/orders/my-orders")}catch(a){y({type:"error",title:t("Shared:error"),message:a?.message||t("Shared:actionFailed")})}finally{v(!1)}},handleSaveAsDraft:async()=>{v(!0);try{await N.mutateAsync(),y({type:"success",title:t("Shared:success"),message:t("savedAsDraftSuccess")})}catch(e){y({type:"error",title:t("Shared:error"),message:e?.message||t("Shared:actionFailed")})}finally{v(!1)}},getMemberName:e=>b.language?.startsWith("ar")?e.memberArabicName||e.memberEnglishName||e.memberEmail:e.memberEnglishName||e.memberArabicName||e.memberEmail,getRoleName:I}}function te(){const{SerialGID:p}=$(),{t}=k(["MedicalCollegesNonJordanianAQA","Shared"]),{memberEvaluations:b,isSubmitting:m,taskData:f,isLoadingTask:y,isLoadingCommittee:h,error:g,handleEvaluationChange:A,handleNotesChange:v,handleSubmit:I,handleSaveAsDraft:o,getMemberName:S,getRoleName:x}=P(p);if(y||h)return i.jsx(Q,{});if(g)return i.jsx("div",{className:"p-4",children:i.jsxs("div",{className:"text-red-600",children:[t("Shared:error"),": ",g.message]})});const d=[{key:"rowNumber",title:t("rowNumber"),render:(l,r,c)=>c+1,width:"80px"},{key:"memberName",title:t("memberName"),dataIndex:"memberArabicName",render:(l,r)=>S(r)},{key:"role",title:t("role"),dataIndex:"role",render:(l,r)=>x(r)},{key:"memberOrganization",title:t("memberOrganization"),dataIndex:"memberOrganization",render:l=>l||"-"},{key:"isApprovedByInstitution",title:t("institutionResponse"),dataIndex:"isApprovedByInstitution",render:(l,r)=>i.jsxs("div",{className:"flex gap-4",children:[i.jsxs("label",{className:"flex items-center gap-1 cursor-pointer",children:[i.jsx("input",{type:"radio",name:`evaluation-${r.role}-${r.id}`,checked:r.isApprovedByInstitution===!0,onChange:()=>A(r.id,r.role,!0),disabled:m}),i.jsx("span",{children:t("approveMember")})]}),i.jsxs("label",{className:"flex items-center gap-1 cursor-pointer",children:[i.jsx("input",{type:"radio",name:`evaluation-${r.role}-${r.id}`,checked:r.isApprovedByInstitution===!1,onChange:()=>A(r.id,r.role,!1),disabled:m}),i.jsx("span",{children:t("rejectMember")})]})]}),width:"220px"},{key:"institutionNotes",title:t("institutionNotes"),dataIndex:"institutionNotes",render:(l,r)=>{const c=r.isApprovedByInstitution===!1,N=!r.institutionNotes?.trim();return i.jsxs("div",{className:"w-full",children:[i.jsx("input",{type:"text",id:`notes-${r.role}-${r.id}`,placeholder:t(c?"notesRequired":"enterNotes"),value:r.institutionNotes,onChange:j=>v(r.id,r.role,j.target.value),required:c,"aria-required":c,disabled:m,className:`w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary ${c&&N?"border-red-500":"border-gray-300"}`}),c&&N&&i.jsx("p",{className:"text-red-500 text-sm mt-1",children:t("notesRequired")})]})}}];return i.jsxs(i.Fragment,{children:[i.jsx(L,{title:t("committeeReviewStepTitle",{orderId:f?.orderId||""}),description:t("committeeReviewDescription"),className:"mb-4"}),f?.orderId!=null&&i.jsx(_,{children:i.jsx(J,{elementId:"order-details",title:t("orderDetails"),children:i.jsx(K,{orderId:f.orderId,sections:["granting-step1","payment-info","last-action"]})})}),i.jsxs("div",{className:"mt-5",children:[i.jsx(W,{columns:d,data:b.filter(l=>l.role==="committeeMember"),rowKey:l=>`${l.role}-${l.id}`,bordered:!0,striped:!0}),i.jsxs("div",{className:"flex justify-end gap-3 mt-6",children:[i.jsx(E,{variant:"secondary",onClick:o,disabled:m,loading:m,children:t("saveAsDraft")}),i.jsx(E,{variant:"primary",onClick:I,disabled:m,loading:m,children:t("send")})]})]})]})}export{te 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.