import{r as a,c as A,b as e,a as l}from"./app-DTeOhhdM.js";import{A as E,a as V}from"./AuthenticatedLayout-DNj-hWy1.js";import{T as M}from"./toast.esm-CLj0hUIX.js";import{A as b}from"./autocomplete.esm-wKYwH1zm.js";import{C as f}from"./calendar.esm-DqUk2xOX.js";import{a as q}from"./helper-Gzy5oJm-.js";import"./createLucideIcon-0QtVMxKe.js";import"./defualtLogo-C0dU5cUD.js";import"./index.esm-xhUioO7y.js";import"./inputtext.esm-DvYkLvTo.js";import"./index.esm-DydXoyuW.js";import"./index.esm-BlFJNgmX.js";import"./asyncToGenerator-BfWTt6ZC.js";function Z({auth:i}){const{permission:c,warehouseList:j}=a.useContext(A),[n,v]=a.useState(),[r,w]=a.useState(),[y,N]=a.useState([]),[C,m]=a.useState(null),S=a.useRef(null),[D,_]=a.useState([]),[k,d]=a.useState(null),[o,u]=a.useState(!1),[p,x]=a.useState({customer:"",company:""}),[h,g]=a.useState([]),R=async()=>{u(!0);let s=new FormData;return s.append("start",n),s.append("end",r),s.append("customer",k),s.append("company",C),s.append("location_id",h),(await l.post("customer-opening-search-report",s)).data};a.useEffect(()=>{c.includes("report_super_admin_access")||g(i.user.shop_id)},[]);const T=s=>{setTimeout(()=>{l.post(route("customer-search"),{data:s.query}).then(t=>{_(t.data.customer)})},250)},F=s=>e.jsx("div",{className:"country-item",children:e.jsxs("div",{children:[s.name," (",s.code,") (",s.user_type,")"]})}),I=s=>{setTimeout(()=>{l.post(route("company-search"),{data:s.query}).then(t=>{N(t.data.suppliers)})},250)},L=s=>e.jsx("div",{className:"country-item",children:e.jsxs("div",{children:[s.name," (",s.number,")"]})}),O=async()=>{const s=await R(),t=await window.generatePDFView(s,window.reportModes.clientOpening,!1,"Customer/Retailer Account Opening",n,r);q(t,"ClientOpening.pdf"),u(!1)};return e.jsxs(E,{user:i.user,header:e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-skin-header font-medium ",children:"Customer/Retailer Opening"})," ",e.jsxs("p",{className:"text-skin-sub-header font-semibold text-xs",children:[" ","Home - Customer/Retailer Opening"]})]}),headerButton:e.jsx(e.Fragment,{}),children:[e.jsx(M,{ref:S}),e.jsx("div",{className:"card p-5",children:e.jsx("div",{className:"min-h-screen  bg-gray-100  py-12 px-4 sm:px-6 lg:px-8",children:e.jsxs("div",{className:"max-w-5xl mx-auto bg-white rounded-2xl shadow-lg p-10 border border-gray-200",children:[e.jsx("h2",{className:"text-3xl font-bold text-center text-gray-800 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(f,{value:n,onChange:s=>{v(s.value)},className:"w-full rounded-lg shadow-sm focus:ring-2 focus:ring-blue-300"})]}),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(f,{value:r,onChange:s=>{w(s.value)},className:"w-full rounded-lg shadow-sm focus:ring-2 focus:ring-blue-300"})]}),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:"Search Company"}),e.jsx(b,{value:p.company,suggestions:y,completeMethod:I,"aria-label":"customer_id",dropdown:!0,itemTemplate:L,onChange:s=>{s.value.name?m(s.value.id):m(null),x(t=>({...t,company:s.value.name?s.value.name+" ("+s.value.number+")":s.value}))},className:"w-full  rounded-lg "})]}),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:"Search Customer/Retailer"}),e.jsx(b,{value:p.customer,suggestions:D,completeMethod:T,"aria-label":"customer_id",dropdown:!0,itemTemplate:F,onChange:s=>{s.value.name?d(s.value.id):d(null),x(t=>({...t,customer:s.value.name?s.value.name+" ("+s.value.code+")":s.value}))},dropdownAriaLabel:"Select Coustomer",className:"w-full rounded-lg"})]}),e.jsx("div",{className:"col-span-12 md:col-span-4",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:"Warehouse/Shop"}),e.jsx(V,{value:h,options:j,optionLabel:"name",optionValue:"id",placeholder:"Select a Warehouse",showClear:!0,disabled:!c.includes("report_super_admin_access"),onChange:s=>g(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:O,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{Z as default};
