import{r as t,c as k,b as e,a as F}from"./app-DTeOhhdM.js";import{A as E,a as b}from"./AuthenticatedLayout-DNj-hWy1.js";import{T as L}from"./toast.esm-CLj0hUIX.js";import{C as g}from"./calendar.esm-DqUk2xOX.js";import{a as V}from"./helper-Gzy5oJm-.js";import{S as I}from"./ProductDropdown-CIH7Yk36.js";import"./createLucideIcon-0QtVMxKe.js";import"./defualtLogo-C0dU5cUD.js";import"./index.esm-xhUioO7y.js";import"./index.esm-DydXoyuW.js";import"./index.esm-BlFJNgmX.js";import"./inputtext.esm-DvYkLvTo.js";import"./asyncToGenerator-BfWTt6ZC.js";import"./autocomplete.esm-wKYwH1zm.js";function oe({auth:p}){const{permission:n,warehouseList:j,supplierList:w}=t.useContext(k),[R,T]=t.useState("All"),[i,v]=t.useState(),[c,N]=t.useState(),[S,A]=t.useState([]),[W,M]=t.useState([]);t.useRef();const _=t.useRef(null),[u,m]=t.useState([]),[h,D]=t.useState([]),[B,G]=t.useState([]),[d,x]=t.useState(!1),[y,f]=t.useState(),[H,U]=t.useState({product:""}),C=async()=>{x(!0);let s=new FormData;return s.append("start",i),s.append("end",c),s.append("location_id",u),s.append("productId",y),s.append("supplier",h),(await F.post("purchase-details-search",s)).data};t.useEffect(()=>{n.includes("report_super_admin_access")||m(p.user.shop_id)},[]);const P=async()=>{const s=await C(),r=await window.generatePDFView(s.purchase,window.reportModes.purchaseDetails,!1,"Purchase Details",i,c,s.discountSum);V(r,"purchaseDetails.pdf"),x(!1)},o={};return S.forEach(s=>{const r=s.purchase_detalis.map(a=>({...a,invoice_no:s.invoice_no,supplier:s.supplier})),l={};r.forEach(a=>{l[a.invoice_no]?l[a.invoice_no].list.push(a):l[a.invoice_no]={list:[a]}}),o[s.invoice_no]?(o[s.invoice_no].details=o[s.invoice_no].details.concat(r),o[s.invoice_no].total+=s.total,o[s.invoice_no].more=l):o[s.invoice_no]={details:r,total:s.total,more:l,date:s.date}}),e.jsxs(E,{user:p.user,header:e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-skin-header font-medium ",children:"Purchase Details"})," ",e.jsxs("p",{className:"text-skin-sub-header font-semibold text-xs",children:[" ","Home - PurchaseDetails"]})]}),headerButton:e.jsx(e.Fragment,{}),children:[e.jsx(L,{ref:_}),e.jsx("div",{className:"card min-h-screen",children:e.jsx("div",{className:"bg-gray-100  flex items-center justify-center py-12 px-2 sm:px-6 lg:px-8",children:e.jsxs("div",{className:"w-full max-w-5xl bg-white rounded-2xl shadow-lg border border-gray-200 p-4 sm:p-8 md:p-10",children:[e.jsx("h2",{className:"text-2xl md:text-3xl font-bold text-center text-gray-800 mb-8 md:mb-10 tracking-tight",children:"Filter Report Criteria"}),e.jsxs("div",{className:"grid grid-cols-12 gap-6",children:[e.jsxs("div",{className:"col-span-12 sm:col-span-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-600 mb-2",children:"Starting Date"}),e.jsx(g,{value:i,onChange:s=>v(s.value),className:"w-full h-[41px] text-[14px] rounded-lg shadow-sm"})]}),e.jsxs("div",{className:"col-span-12 sm:col-span-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-600 mb-2",children:"End Date"}),e.jsx(g,{value:c,onChange:s=>N(s.value),className:"w-full h-[41px] text-[14px] rounded-lg shadow-sm"})]}),e.jsxs("div",{className:"col-span-12 sm:col-span-4",children:[e.jsx("label",{htmlFor:"type",className:"block text-sm font-medium text-gray-600 mb-2",children:"Search Product"}),e.jsx(I,{reportMode:!0,selectedItem:s=>{s!=null&&s.id?f(s.id):f(null)}})]}),e.jsxs("div",{className:"col-span-12 sm:col-span-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-600 mb-2",children:"Supplier"}),e.jsx(b,{value:h,options:w,optionLabel:"name",optionValue:"id",placeholder:"Select a Supplier",showClear:!0,onChange:s=>D(s.value??null),className:"w-full rounded-lg shadow-sm",inputClassName:"h-11 px-4 text-sm"})]}),n.includes("report_super_admin_access")&&e.jsxs("div",{className:"col-span-12 sm:col-span-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-600 mb-2",children:"Warehouse/Shop"}),e.jsx(b,{value:u,options:j,optionLabel:"name",optionValue:"id",placeholder:"Select a Warehouse",showClear:!0,disabled:!n.includes("report_super_admin_access"),onChange:s=>m(s.target.value??null),className:"w-full rounded-lg shadow-sm",inputClassName:"h-11 px-4 text-sm"})]})]}),e.jsx("div",{className:"mt-10 flex justify-center",children:e.jsx("button",{type:"button",onClick:P,disabled:d,className:`px-6 py-3 rounded-xl font-semibold text-sm min-w-[160px] flex items-center justify-center gap-2 transition duration-200
                    ${d?"bg-blue-400 cursor-not-allowed":"bg-blue-600 hover:bg-blue-700"}
                    text-white shadow-md`,children:d?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-5 h-5 border-2 border-white border-t-transparent rounded-full animate-spin","aria-hidden":"true"}),e.jsx("span",{className:"text-xs font-medium",children:"Generating..."})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{role:"img","aria-label":"View Report",children:"🔍"}),"View Report"]})})})]})})})]})}export{oe as default};
