import{ek as I,E as A,b as L,a as w,hl as G,r as m,ht as T,hm as h,j as s,B as M,_ as N,P as R,J as U,eV as V,hr as $,hV as _}from"./index-d2b25495.js";import{G as F}from"./GoBack-f6710d2c.js";import{T as J}from"./index-75fca24c.js";import{C as Z}from"./Checkbox-d1c5682c.js";import{C as q}from"./CardContent-be810fe0.js";import"./Divider-29971892.js";import"./dividerClasses-02a44d89.js";import"./LoadingButton-c8e88148.js";import"./index-38f860bc.js";import"./useMediaQuery-b1fbc166.js";import"./useControlled-8d737f13.js";import"./composeClasses-b42b2e69.js";import"./TableContainer-dd7cf0ce.js";import"./TableRow-74f9cf3b.js";import"./Skeleton-1012c2e6.js";import"./index-1249dfe4.js";import"./TableHead-fac214d3.js";import"./createSvgIcon-e39ae511.js";import"./TablePagination-2c2a1682.js";import"./Select-ef36a2b2.js";import"./Menu-337a466b.js";import"./Grow-8719411b.js";import"./List-863f013e.js";import"./OutlinedInput-86f3ec98.js";import"./useFormControl-2b068664.js";import"./MenuItem-2bdddad4.js";import"./listItemTextClasses-cadd4b00.js";import"./KeyboardArrowRight-7e978a8a.js";import"./SwitchBase-8b4bccce.js";const ve=()=>{var x,C,k,j;const{tenderId:u,documentId:c,tab:P}=I();A();const o=L(),{document:{documentList:D,pageParams:r,selectedData:v,checkedList:i},mini:{miniDocuments:e},system:{userAccessList:H}}=w(t=>G(t)),y=()=>{i.length===0?V.fire({title:'<p style="font-size:20px">Zero Documents Selected</p>',text:"Atleast select one document",icon:"info",confirmButtonText:"Close",confirmButtonColor:"#3085d6"}):o($({id:c||"",data:{tender_id:u,document_ids:i},params:r,clearData:()=>{}}))},b=(t,a,n)=>{if(n)o(_([...i,t]));else{const p=i.filter(d=>d!=t);o(_(p))}};m.useEffect(()=>{o(T({id:c}))},[]),m.useEffect(()=>{o(h({page:1,page_size:10,search:""}))},[]);const B=[{title:"S.No",width:100},{title:"Document",width:100},{title:"Is Checked",width:100}];function g(t,a,n){return{index:t,document:a,yesCheck:n}}const f=m.useMemo(()=>{var t;return(t=e==null?void 0:e.list)==null?void 0:t.map((a,n)=>{const p=(r.page-1)*r.page_size+(n+1),d=a==null?void 0:a.name,E=s.jsx(Z,{checked:!!i.find(l=>l==a.id),onChange:l=>b(a.id,"yes",l.target.checked)});return g(p,d,E)})},[e,v,g]),z=(t,a)=>{o(h({...r,search:"",page:a+1}))},S=t=>{o(h({...r,search:"",page:1,page_size:parseInt(t.target.value)}))};return s.jsx("div",{children:s.jsx(M,{children:s.jsxs(F,{is_goback:!0,title:"Documents Update",go_back_url:`/tenders/view/${u}/${P}/documents/`,showSaveButton:!1,loading:!1,children:[s.jsx(N,{children:s.jsxs(q,{children:[s.jsx(J,{count:e==null?void 0:e.count,columns:B,rows:f||[],loading:e==null?void 0:e.loading,page:(x=e==null?void 0:e.miniParams)!=null&&x.page?(C=e==null?void 0:e.miniParams)==null?void 0:C.page:1,pageSize:(k=e==null?void 0:e.miniParams)!=null&&k.page_size?(j=e==null?void 0:e.miniParams)==null?void 0:j.page_size:10,handleChangePage:z,handleChangeRowsPerPage:S}),s.jsx(R,{container:!0,justifyContent:"flex-end",mt:3.4,children:s.jsx(U,{variant:"contained",onClick:t=>{t.preventDefault(),y()},type:"submit",color:"primary",autoFocus:!0,children:"Save"})})]})})," "]})})})};export{ve as default};
