import{r as t,c as L,E as _,a as l,b as e}from"./app-DTeOhhdM.js";import{A as k}from"./AuthenticatedLayout-DNj-hWy1.js";import{T as F}from"./toast.esm-CLj0hUIX.js";import{C as p}from"./calendar.esm-DqUk2xOX.js";import{a as T}from"./helper-Gzy5oJm-.js";import{A}from"./autocomplete.esm-wKYwH1zm.js";import{W as E}from"./WarehouseDropdown-CN8BA3Aw.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 se({auth:m}){const{permission:x,warehouseList:I}=t.useContext(L),[V,P]=t.useState("All"),[a,h]=t.useState(),[o,g]=t.useState(),[c,i]=t.useState([]),[f,b]=t.useState([]),[W,$]=t.useState([]),[M,j]=t.useState([]);t.useRef();const[w,d]=t.useState(null),[n,u]=t.useState(!1),N=t.useRef(null),[v,C]=t.useState({customer:""});new _,t.useEffect(()=>{l.get(route("sales.report.shop")).then(s=>{j(s.data.shop)}),x.includes("report_super_admin_access")||i(m.user.shop_id)},[]);const y=async()=>{u(!0);let s=new FormData;return s.append("start",a),s.append("end",o),s.append("customer_id",w),s.append("location",c),(await l.post("customer-ledger-report-search",s)).data},S=async()=>{const s=await y(),r=await window.generatePDFView(s==null?void 0:s.customerLedger,window.reportModes.customerLedger,s==null?void 0:s.customer,"Customer Ledger Report",a,o);T(r,"Customer-ledger-report.pdf"),u(!1)},D=s=>{setTimeout(()=>{l.post(route("customer-search"),{data:s.query}).then(r=>{b(r.data.customer)})},250)},R=s=>e.jsx("div",{className:"country-item",children:e.jsxs("div",{children:[s.name," (",s.code,") (",s.user_type,")"]})});return e.jsxs(k,{user:m.user,header:e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-skin-header font-medium ",children:"Customer Ledger Report"})," ",e.jsxs("p",{className:"text-skin-sub-header font-semibold text-xs",children:[" ","Home - Report - Customer Ledger Report"]})]}),headerButton:e.jsx(e.Fragment,{}),children:[e.jsx(F,{ref:N}),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(p,{value:a,onChange:s=>h(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(p,{value:o,onChange:s=>g(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:"Search Customer/Retailer"}),e.jsx(A,{value:v.customer,suggestions:f,completeMethod:D,"aria-label":"customer_id",dropdown:!0,itemTemplate:R,onChange:s=>{s.value.name?d(s.value.id):d(null),C(r=>({...r,customer:s.value.name?`${s.value.name} (${s.value.code})`:s.value}))},dropdownAriaLabel:"Select Customer",className:"w-full h-10 rounded-lg"})]}),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:"Search Customer/Retailer"}),e.jsx(E,{setPermission:"report_super_admin_access",warehouse:c,setWarehouse:s=>{i(s)}})]})]}),e.jsx("div",{className:"mt-10 flex justify-center",children:e.jsx("button",{type:"button",onClick:S,disabled:n,className:`px-6 py-3 rounded-xl font-semibold text-sm min-w-[160px] flex items-center justify-center gap-2 transition duration-200
                    ${n?"bg-blue-400 cursor-not-allowed":"bg-blue-600 hover:bg-blue-700"}
                    text-white shadow-md`,children:n?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{se as default};
