import{r as a,c as _,E as C,b as e,a as D}from"./app-DTeOhhdM.js";import{A as F,a as x}from"./AuthenticatedLayout-DNj-hWy1.js";import{T as k}from"./toast.esm-CLj0hUIX.js";import{C as h}from"./calendar.esm-DqUk2xOX.js";import"./html2canvas.esm-CBrSDip1.js";import{a as E}from"./helper-Gzy5oJm-.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";function q({auth:i}){const{permission:r,warehouseList:b,supplierList:f}=a.useContext(_),[l,g]=a.useState(),[n,w]=a.useState(),[j,L]=a.useState([]),[d,N]=a.useState([]),v=a.useRef(null);new C;const[c,m]=a.useState([]),[o,u]=a.useState(!1);a.useEffect(()=>{r.includes("report_super_admin_access")||m(i.user.shop_id)},[]);const y=async()=>{u(!0);let s=new FormData;return s.append("start",l),s.append("end",n),s.append("location_id",c),s.append("supplier",d),(await D.post("purchase-report-search",s)).data},S=async()=>{const s=await y(),p=await window.generatePDFView(s,window.reportModes.purchaseSummary,!1,"Purchase Summary",l,n);E(p,"purchaseSummary.pdf"),u(!1)},t={};return j.forEach(s=>{t[s.date]?(t[s.date].invoice+=Number(s.invoice_count),t[s.date].details=t[s.date].details.concat(s.purchase_detalis),t[s.date].total+=Number(s.total)):t[s.date]={invoice:Number(s.invoice_count),details:s.purchase_detalis,total:Number(s.total)}}),e.jsxs(F,{user:i.user,header:e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-skin-header font-medium ",children:"Purchase Summary"})," ",e.jsxs("p",{className:"text-skin-sub-header font-semibold text-xs",children:[" ","Home - PurchaseSummary"]})]}),headerButton:e.jsx(e.Fragment,{}),children:[e.jsx(k,{ref:v}),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 md:col-span-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-600 mb-2",children:"Starting Date"}),e.jsx(h,{value:l,onChange:s=>g(s.value),className:"w-full h-[41px] text-[14px] rounded-lg shadow-sm"})]}),e.jsxs("div",{className:"col-span-12 md:col-span-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-600 mb-2",children:"End Date"}),e.jsx(h,{value:n,onChange:s=>w(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:"Supplier"}),e.jsx(x,{value:d,options:f,optionLabel:"name",optionValue:"id",placeholder:"Select a Supplier",showClear:!0,onChange:s=>N(s.value??null),className:"w-full rounded-lg shadow-sm",inputClassName:"h-11 px-4 text-sm"})]}),r.includes("report_super_admin_access")&&e.jsxs("div",{className:"col-span-12 md:col-span-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-600 mb-2",children:"Warehouse/Shop"}),e.jsx(x,{value:c,options:b,optionLabel:"name",optionValue:"id",placeholder:"Select a Warehouse",showClear:!0,disabled:!r.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:S,disabled:o,className:`px-6 py-3 rounded-xl font-semibold text-sm min-w-[160px] flex items-center justify-center gap-2 transition duration-200
                    ${o?"bg-blue-400 cursor-not-allowed":"bg-blue-600 hover:bg-blue-700"}
                    text-white shadow-md`,children:o?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{q as default};
