import{r as n,a as N,b as e,A as x}from"./app-DTeOhhdM.js";import{A as S,B as r}from"./AuthenticatedLayout-DNj-hWy1.js";import{D as w,C as i}from"./column.esm-CqBIx_TJ.js";import{T as q}from"./toast.esm-CLj0hUIX.js";import{A as C}from"./ApprovalActionModal-PtHx0E0N.js";import"./helper-Gzy5oJm-.js";import"./asyncToGenerator-BfWTt6ZC.js";import"./createLucideIcon-0QtVMxKe.js";import"./defualtLogo-C0dU5cUD.js";import"./inputtext.esm-DvYkLvTo.js";import"./index.esm-xhUioO7y.js";import"./index.esm-BlFJNgmX.js";import"./index.esm-CVWS0Xy2.js";import"./inputtextarea.esm-Dd-bVwF0.js";import"./checkbox.esm-BR_P7NMp.js";function K({auth:f}){const[h,b]=n.useState([]),[l,p]=n.useState(!1),[s,d]=n.useState(null),[y,c]=n.useState(!1),u=n.useRef(null);n.useEffect(()=>{o()},[]);const o=async()=>{var t;p(!0);try{const a=await N.get(route("approvals.pending"));a.data.success&&b(a.data.data)}catch(a){console.error("Error fetching pending approvals:",a),(t=u.current)==null||t.show({severity:"error",summary:"Error",detail:"Failed to fetch pending approvals"})}finally{p(!1)}},v=t=>{d(t),c(!0)},g=t=>{const a=t.approvable_type||"";if(a.includes("RequisitionMaster")){x.visit(`/shop-requisition/${t.approvable_id}`);return}if(a.includes("productQuotationMaster")){x.visit(`/product-quotation/${t.approvable_id}`);return}},_=t=>{const a=t.is_final||!1,m=t.assignment_status||"pending",A=m==="approved";return e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[a&&e.jsx("span",{className:"px-2 py-1 bg-purple-100 text-purple-800 text-xs font-semibold rounded",children:"Final"}),A&&!a&&e.jsx("span",{className:"px-2 py-1 bg-blue-100 text-blue-800 text-xs font-semibold rounded",children:"Approved"}),m==="pending"&&!a&&e.jsx("span",{className:"px-2 py-1 bg-yellow-100 text-yellow-800 text-xs font-semibold rounded",children:"Pending"})]})},j=t=>e.jsxs("div",{className:"flex items-center gap-1 justify-center",children:[e.jsx(r,{icon:"pi pi-eye",className:"p-button-rounded p-button-help w-10 h-10 font-medium",tooltip:"Preview",onClick:()=>g(t)}),e.jsx(r,{icon:"pi pi-cog",className:"p-button-rounded p-button-secondary w-10 h-10 font-medium",tooltip:"Take Action",onClick:()=>v(t)})]});return e.jsxs(S,{user:f.user,header:e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-skin-header font-medium",children:"Approval Inbox"}),e.jsx("p",{className:"text-skin-sub-header font-semibold text-xs",children:"Home - Approval Inbox"})]}),headerButton:e.jsx(r,{label:"Refresh",icon:"pi pi-refresh",onClick:o,className:"p-button-sm",loading:l}),children:[e.jsx(q,{ref:u}),e.jsx("div",{className:"card",children:e.jsxs(w,{className:"defulattable",value:h,loading:l,emptyMessage:"No pending approvals",paginator:!0,rows:10,rowsPerPageOptions:[10,20,50],showGridlines:!0,dataKey:"id",children:[e.jsx(i,{field:"module_name",header:"Module",sortable:!0,style:{minWidth:"120px"}}),e.jsx(i,{field:"reference_id",header:"Reference ID",sortable:!0,style:{minWidth:"150px"}}),e.jsx(i,{field:"requested_by",header:"Requested By",sortable:!0,style:{minWidth:"150px"}}),e.jsx(i,{field:"submitted_date",header:"Submitted Date",sortable:!0,style:{minWidth:"180px"}}),e.jsx(i,{field:"sequence",header:"Sequence",sortable:!0,style:{minWidth:"100px"}}),e.jsx(i,{body:_,header:"Status",bodyClassName:"text-center",style:{minWidth:"140px"}}),e.jsx(i,{body:j,header:"Action",bodyClassName:"text-center",style:{width:"auto",minWidth:"120px"},exportable:!1})]})}),e.jsx(C,{visible:y,onHide:()=>{c(!1),d(null)},approvalData:s?{approval_id:s.id,assignment_id:s.assignment_id,module_name:s.module_name,reference_id:s.reference_id,assignment_status:s.assignment_status,is_final:s.is_final,has_final_approver:s.has_final_approver,can_reassign:s.can_reassign,note:s.note,history:s.history}:null,onSuccess:()=>{o()}})]})}export{K as default};
