import{r as t,c as T,b as e,a as h}from"./app-DTeOhhdM.js";import{A as B,a as E}from"./AuthenticatedLayout-DNj-hWy1.js";import{T as L}from"./toast.esm-CLj0hUIX.js";import{C as g}from"./calendar.esm-DqUk2xOX.js";import"./html2canvas.esm-CBrSDip1.js";import{A as M}from"./autocomplete.esm-wKYwH1zm.js";import{a as A}from"./helper-Gzy5oJm-.js";import{M as q}from"./multiselect.esm-BZr7lFMm.js";import{S as W}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";function me({auth:d,warehouseList:b}){const{permission:n,category:f}=t.useContext(T),[$,G]=t.useState([]),[j,H]=t.useState(null),[w,c]=t.useState(null),[N,i]=t.useState(null),[J,U]=t.useState([]),[r,y]=t.useState(),[o,S]=t.useState(),[v,z]=t.useState([]),[l,m]=t.useState(!1),C=t.useRef(null),[u,p]=t.useState([]),[k,_]=t.useState({product:"",company:"",brand:""}),[x,D]=t.useState([]),[I,F]=t.useState([]);t.useEffect(()=>{n.includes("report_super_admin_access")||p(d.user.shop_id)},[]);const V=async()=>{m(!0);let s=new FormData;return s.append("start",r),s.append("end",o),s.append("company_id",j),s.append("product_id",w),s.append("brand_id",N),s.append("warehouse_id",u),s.append("category",JSON.stringify(x)),(await h.post("opening-product-search",s)).data},O=async()=>{const s=await V(),a=await window.generatePDFView(s,window.reportModes.openingStock,!1,"Opening Stock Report",r,o);A(a,"openingStock.pdf"),m(!1)},P=s=>{setTimeout(()=>{h.post(route("brand.search"),{data:s.query}).then(a=>{F(a.data)})},250)},R=s=>e.jsx("div",{className:"country-item",children:e.jsx("div",{children:s.name})});return v.reduce((s,a)=>s+Number(a.quantity)-Number(a.damage?a.damage.qty:0),0),e.jsxs(B,{user:d.user,header:e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-skin-header font-medium ",children:"Current Opening Stock"})," ",e.jsxs("p",{className:"text-skin-sub-header font-semibold text-xs",children:[" ","Home - currentOpeningStock"]})]}),headerButton:e.jsx(e.Fragment,{}),children:[e.jsx(L,{ref:C}),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:r,onChange:s=>y(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:o,onChange:s=>S(s.value),className:"w-full h-[41px] text-[14px] rounded-lg shadow-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:"Select Warehouse/Shop"}),e.jsx(E,{optionLabel:"name",optionValue:"id",value:u,options:b,onChange:s=>p(s.target.value??null),disabled:!n.includes("report_super_admin_access"),showClear:!0,placeholder:"Select a Warehouse",className:"w-full rounded-lg shadow-sm",inputClassName:"h-11 px-4 text-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 Product"}),e.jsx(W,{reportMode:!0,selectedItem:s=>{s!=null&&s.id?c(s.id):c(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:"Search Brand"}),e.jsx(M,{value:k.brand,suggestions:I,completeMethod:P,"aria-label":"brand_id",itemTemplate:R,dropdown:!0,onChange:s=>{s.value.name?i(s.value.id):i(null),_(a=>({...a,brand:s.value.name?`${s.value.name}`:s.value}))},className:"w-full rounded-lg shadow-sm",inputClassName:"px-4 text-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:"Select Category"}),e.jsx(q,{value:x,options:f,optionLabel:"name",optionValue:"id",placeholder:"Select Category",onChange:s=>D(s.value),className:"w-full rounded-lg shadow-sm focus:ring-2 focus:ring-blue-300"})]})]}),e.jsx("div",{className:"mt-10 flex justify-center",children:e.jsx("button",{type:"button",onClick:O,disabled:l,className:`px-6 py-3 rounded-xl font-semibold text-sm min-w-[160px] flex items-center justify-center gap-2 transition duration-200
                    ${l?"bg-blue-400 cursor-not-allowed":"bg-blue-600 hover:bg-blue-700"}
                    text-white shadow-md`,children:l?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{me as default};
