import{r as d,a4 as m,y as U,z as u,j as e,f as H,L as ue,c as me,q as pe,s as J}from"./index-9FS9bw8D.js";import{F as ge}from"./MagnifyingGlassIcon-DIIDUrHz.js";import{F as he}from"./ArrowUpIcon-cULW2MO5.js";import{F as ye}from"./ExclamationTriangleIcon-BZPGBcaI.js";function fe({title:j,titleId:v,...T},A){return d.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:A,"aria-labelledby":v},T),j?d.createElement("title",{id:v},j):null,d.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z"}))}const be=d.forwardRef(fe),Se=()=>{const[j,v]=d.useState([]),[T,A]=d.useState([]),[M,W]=d.useState([]),[X,E]=d.useState(!0),[N,K]=d.useState(""),[h,Q]=d.useState("all"),[w,Y]=d.useState("all"),[R,ee]=d.useState("all"),[o,y]=d.useState(null),[L,F]=d.useState(!1),[z,B]=d.useState(!1),[$,D]=d.useState(!1),[V,O]=d.useState(!1),[f,G]=d.useState({rates:[],spreaderSettings:[]}),[te,S]=d.useState(!1),[p,g]=d.useState({equipmentId:"",spreaderBrand:"",spreaderModel:"",settingValue:"",rateDescription:"",notes:""}),[a,x]=d.useState({name:"",brand:"",categoryId:"",productType:"granular",activeIngredients:"",description:"",seedBlend:[],rates:[{applicationType:"granular",rateAmount:"",rateUnit:"lbs/1000 sq ft",notes:""}]});d.useEffect(()=>{b()},[N,h,w]);const b=async()=>{try{E(!0);const[t,n,s]=await Promise.all([m.getProducts({search:N,category:h!=="all"?h:"",type:w!=="all"?w:""}),m.getAllUserProducts({search:N,category:h!=="all"?h:""}),U.getCategories()]);v(t.data.data.products||[]),A(n.data.data.userProducts||[]),W(s.data.data.categories||[])}catch(t){console.error("Failed to fetch products:",t),u.error("Failed to load products")}finally{E(!1)}},se=async t=>{t.preventDefault();try{await m.createProduct(a),u.success("Product created successfully"),F(!1),I(),b()}catch(n){console.error("Failed to create product:",n),u.error("Failed to create product")}},ae=async t=>{t.preventDefault();try{await m.updateProduct(o.id,a),u.success("Product updated successfully"),B(!1),I(),b()}catch(n){console.error("Failed to update product:",n),u.error("Failed to update product")}},re=async()=>{var t,n,s,r;try{if(o.isShared)await m.deleteProduct(o.id);else try{await U.deleteUserProduct(o.id)}catch(l){if((((n=(t=l==null?void 0:l.response)==null?void 0:t.data)==null?void 0:n.message)||"").includes("used in applications"))await U.archiveUserProduct(o.id),u("Product archived instead of deleted (in use)");else throw l}u.success("Product deleted successfully"),D(!1),y(null),b()}catch(l){console.error("Failed to delete product:",l),u.error(((r=(s=l==null?void 0:l.response)==null?void 0:s.data)==null?void 0:r.message)||"Failed to delete product")}},le=async t=>{try{await m.promoteUserProduct(t.id),u.success(`"${t.customName}" promoted to shared product`),b()}catch(n){console.error("Failed to promote product:",n),u.error("Failed to promote product to shared")}},q=async t=>{try{y(t);let n=[],s=[];t.isShared?n=(await m.getProductRates(t.id)).data.data.rates||[]:s=(await m.getUserProductSpreaderSettings(t.id)).data.data.spreaderSettings||[],G({rates:n,spreaderSettings:s}),O(!0)}catch(n){console.error("Failed to fetch product details:",n),u.error("Failed to load product details")}},ne=async t=>{t.preventDefault();try{await m.addUserProductSpreaderSetting(o.id,p),u.success("Spreader setting added successfully"),S(!1),g({equipmentId:"",spreaderBrand:"",spreaderModel:"",settingValue:"",rateDescription:"",notes:""}),q(o)}catch(n){console.error("Failed to add spreader setting:",n),u.error("Failed to add spreader setting")}},de=async t=>{try{await m.deleteUserProductSpreaderSetting(t),u.success("Spreader setting deleted successfully"),q(o)}catch(n){console.error("Failed to delete spreader setting:",n),u.error("Failed to delete spreader setting")}},I=()=>{x({name:"",brand:"",categoryId:"",productType:"granular",activeIngredients:"",description:"",seedBlend:[],rates:[{applicationType:"granular",rateAmount:"",rateUnit:"lbs/1000 sq ft",notes:""}]}),y(null)},ie=async t=>{var l,c,P;y(t);const n=t.productType||t.customProductType||"granular";let s=t.seedBlend||[],r=t.rates&&t.rates.length>0?t.rates:[];if(t.isShared&&t.id&&m.getProductRates)try{r=((c=(l=(await m.getProductRates(t.id)).data)==null?void 0:l.data)==null?void 0:c.rates)||r}catch(i){console.warn("Admin fetch rates failed",((P=i==null?void 0:i.response)==null?void 0:P.data)||i.message)}if(!t.isShared&&n==="seed"&&t.activeIngredients)try{const i=typeof t.activeIngredients=="string"?JSON.parse(t.activeIngredients):t.activeIngredients;if(Array.isArray(i==null?void 0:i.seedBlend)&&(s=i.seedBlend),i!=null&&i.seedRates){const _=i.seedRates.unit||t.rateUnit||"lbs/1000 sq ft",k=[];i.seedRates.new&&k.push({applicationType:"New Lawn",rateAmount:i.seedRates.new,rateUnit:_,notes:""}),i.seedRates.overseed&&k.push({applicationType:"Overseeding",rateAmount:i.seedRates.overseed,rateUnit:_,notes:""}),k.length&&(r=k)}}catch{}x({name:t.name||t.customName||"",brand:t.brand||t.customBrand||"",categoryId:t.categoryId||"",productType:n,activeIngredients:t.activeIngredients||t.customActiveIngredients||"",description:t.description||t.customDescription||"",seedBlend:s,rates:r.length>0?r:[{applicationType:n,rateAmount:t.rateAmount||"",rateUnit:t.rateUnit||"lbs/1000 sq ft",notes:""}]}),B(!0)},oe=()=>{x(t=>({...t,rates:[...t.rates,{applicationType:t.productType,rateAmount:"",rateUnit:t.productType==="granular"?"lbs/1000 sq ft":"oz/1000 sq ft",notes:""}]}))},ce=t=>{x(n=>({...n,rates:n.rates.filter((s,r)=>r!==t)}))},C=(t,n,s)=>{x(r=>({...r,rates:r.rates.map((l,c)=>c===t?{...l,[n]:s}:l)}))},xe=[...R==="custom"?[]:j.map(t=>({...t,isShared:!0})),...R==="shared"?[]:T.map(t=>({...t,isShared:!1}))],Z=(t,n)=>e.jsxs("form",{onSubmit:t,className:"space-y-4",children:[e.jsxs("div",{className:"border rounded-lg p-4 bg-white shadow-sm",children:[e.jsxs("div",{className:"flex justify-between items-start mb-2",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-gray-900",children:a.name||"Untitled Product"}),a.brand&&e.jsx("p",{className:"text-sm text-gray-600",children:a.brand})]}),e.jsx("span",{className:`px-2 py-1 text-xs font-medium rounded-full ${a.productType==="liquid"?"bg-blue-100 text-blue-800":a.productType==="granular"?"bg-green-100 text-green-800":a.productType==="seed"?"bg-yellow-100 text-yellow-800":"bg-gray-100 text-gray-800"}`,children:a.productType||"—"})]}),a.productType==="seed"?e.jsxs("div",{className:"mt-2",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:"Seed Blend:"}),(a.seedBlend||[]).length===0?e.jsx("p",{className:"text-sm text-gray-600",children:"No blend details"}):e.jsx("div",{className:"mt-1 flex flex-wrap gap-2",children:a.seedBlend.map((s,r)=>e.jsxs("span",{className:"px-2 py-1 bg-gray-100 rounded text-xs text-gray-800",children:[s.cultivar," — ",parseFloat(s.percent||0).toFixed(1),"%"]},r))}),e.jsxs("div",{className:"bg-gray-50 rounded mt-3 p-3",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900 mb-1",children:"Application Rates"}),(()=>{const s=(a.rates||[]).find(l=>(l.applicationType||"").toLowerCase().includes("new")),r=(a.rates||[]).find(l=>(l.applicationType||"").toLowerCase().includes("over"));return e.jsxs(e.Fragment,{children:[s&&e.jsxs("div",{className:"text-sm text-gray-700",children:["New Lawn: ",s.rateAmount," ",s.rateUnit]}),r&&e.jsxs("div",{className:"text-sm text-gray-700",children:["Overseeding: ",r.rateAmount," ",r.rateUnit]}),!s&&!r&&(a.rates||[]).slice(0,2).map((l,c)=>e.jsxs("div",{className:"text-sm text-gray-700",children:[l.applicationType,": ",l.rateAmount," ",l.rateUnit]},c))]})})()]})]}):a.activeIngredients&&e.jsxs("p",{className:"text-sm text-gray-700 mt-2",children:[e.jsx("strong",{children:"Active Ingredients:"})," ",a.activeIngredients]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Product Name *"}),e.jsx("input",{type:"text",required:!0,value:a.name,onChange:s=>x({...a,name:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Brand"}),e.jsx("input",{type:"text",value:a.brand,onChange:s=>x({...a,brand:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Category"}),e.jsxs("select",{value:a.categoryId,onChange:s=>x({...a,categoryId:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"",children:"Select Category"}),M.map(s=>e.jsx("option",{value:s.id,children:s.name},s.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Product Type *"}),e.jsxs("select",{required:!0,value:a.productType,onChange:s=>x({...a,productType:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"granular",children:"Granular"}),e.jsx("option",{value:"liquid",children:"Liquid"}),e.jsx("option",{value:"seed",children:"Seed"}),e.jsx("option",{value:"powder",children:"Powder"})]})]})]}),a.productType!=="seed"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Active Ingredients"}),e.jsx("textarea",{value:a.activeIngredients,onChange:s=>x({...a,activeIngredients:s.target.value}),rows:"3",className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Description"}),e.jsx("textarea",{value:a.description,onChange:s=>x({...a,description:s.target.value}),rows:"3",className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"})]}),a.productType==="seed"&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Seed Blend (Cultivars + %)"}),e.jsx("button",{type:"button",onClick:()=>x({...a,seedBlend:[...a.seedBlend||[],{cultivar:"",percent:""}]}),className:"text-sm text-blue-600 hover:text-blue-800",children:"+ Add Cultivar"})]}),a.seedBlend&&a.seedBlend.length>0?e.jsxs("div",{className:"space-y-2",children:[a.seedBlend.map((s,r)=>e.jsxs("div",{className:"grid grid-cols-6 gap-2 items-center",children:[e.jsx("input",{className:"col-span-4 px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Cultivar name",value:s.cultivar,onChange:l=>{const c=[...a.seedBlend];c[r]={...c[r],cultivar:l.target.value},x({...a,seedBlend:c})}}),e.jsx("input",{type:"number",step:"0.1",className:"col-span-1 px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"%",value:s.percent,onChange:l=>{const c=[...a.seedBlend];c[r]={...c[r],percent:l.target.value},x({...a,seedBlend:c})}}),e.jsx("button",{type:"button",className:"text-red-600",onClick:()=>{const l=(a.seedBlend||[]).filter((c,P)=>P!==r);x({...a,seedBlend:l})},children:"Remove"})]},r)),e.jsxs("div",{className:"text-xs text-gray-600",children:["Total: ",(a.seedBlend||[]).reduce((s,r)=>s+(parseFloat(r.percent)||0),0).toFixed(1),"%"]})]}):e.jsx("div",{className:"text-sm text-gray-500",children:"No cultivars added yet."})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Application Rates"}),e.jsx("button",{type:"button",onClick:oe,className:"text-sm text-blue-600 hover:text-blue-800",children:"+ Add Rate"})]}),a.rates.map((s,r)=>e.jsxs("div",{className:"border border-gray-200 rounded-md p-3 mb-2",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-2 mb-2",children:[e.jsx("input",{type:"text",placeholder:a.productType==="seed"?"New Lawn / Overseeding":"Application Type",value:s.applicationType||"",onChange:l=>C(r,"applicationType",l.target.value),className:"px-2 py-1 border border-gray-300 rounded text-sm focus:outline-none focus:ring-1 focus:ring-blue-500"}),e.jsx("input",{type:"number",placeholder:"Rate Amount",value:s.rateAmount,onChange:l=>C(r,"rateAmount",l.target.value),className:"px-2 py-1 border border-gray-300 rounded text-sm focus:outline-none focus:ring-1 focus:ring-blue-500"}),e.jsxs("select",{value:s.rateUnit,onChange:l=>C(r,"rateUnit",l.target.value),className:"px-2 py-1 border border-gray-300 rounded text-sm focus:outline-none focus:ring-1 focus:ring-blue-500",children:[e.jsx("option",{value:"lbs/1000 sq ft",children:"lbs/1000 sq ft"}),e.jsx("option",{value:"oz/1000 sq ft",children:"oz/1000 sq ft"}),e.jsx("option",{value:"lbs/acre",children:"lbs/acre"}),e.jsx("option",{value:"oz/acre",children:"oz/acre"})]}),a.rates.length>1&&e.jsx("button",{type:"button",onClick:()=>ce(r),className:"text-red-600 hover:text-red-800 text-sm",children:"Remove"})]}),e.jsx("input",{type:"text",placeholder:"Notes (optional)",value:s.notes,onChange:l=>C(r,"notes",l.target.value),className:"w-full px-2 py-1 border border-gray-300 rounded text-sm focus:outline-none focus:ring-1 focus:ring-blue-500"})]},r))]}),e.jsxs("div",{className:"flex justify-end space-x-3 pt-4",children:[e.jsx("button",{type:"button",onClick:()=>{F(!1),B(!1),I()},className:"px-4 py-2 text-sm text-gray-700 bg-gray-200 rounded hover:bg-gray-300",children:"Cancel"}),e.jsx("button",{type:"submit",className:"px-4 py-2 text-sm text-white bg-blue-600 rounded hover:bg-blue-700",children:n})]})]});return e.jsxs("div",{className:"p-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Manage Products"}),e.jsx("p",{className:"text-gray-600",children:"Add, edit, and manage all lawn care products"})]}),e.jsxs("button",{onClick:()=>F(!0),className:"btn-primary flex items-center",children:[e.jsx(H,{className:"h-5 w-5 mr-2"}),"Add Product"]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mb-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ge,{className:"h-5 w-5 absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"text",placeholder:"Search products...",value:N,onChange:t=>K(t.target.value),className:"pl-10 pr-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 w-full"})]}),e.jsxs("select",{value:h,onChange:t=>Q(t.target.value),className:"px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"all",children:"All Categories"}),M.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]}),e.jsxs("select",{value:w,onChange:t=>Y(t.target.value),className:"px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"all",children:"All Types"}),e.jsx("option",{value:"granular",children:"Granular"}),e.jsx("option",{value:"liquid",children:"Liquid"}),e.jsx("option",{value:"seed",children:"Seed"}),e.jsx("option",{value:"powder",children:"Powder"})]}),e.jsxs("select",{value:R,onChange:t=>ee(t.target.value),className:"px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",children:[e.jsx("option",{value:"all",children:"All Products"}),e.jsx("option",{value:"shared",children:"Shared Only"}),e.jsx("option",{value:"custom",children:"Custom Only"})]})]})]}),X&&!L&&!z&&!V&&!$?e.jsx("div",{className:"flex justify-center items-center h-64",children:e.jsx(ue,{size:"lg"})}):e.jsx("div",{className:"card overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Product"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Type"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Category"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Source"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Owner"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Usage"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Actions"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200",children:xe.map(t=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"h-10 w-10 rounded-full bg-green-100 flex items-center justify-center",children:e.jsx(me,{className:"h-6 w-6 text-green-600"})}),e.jsxs("div",{className:"ml-4",children:[e.jsx("div",{className:"text-sm font-medium text-gray-900",children:t.name||t.customName}),e.jsx("div",{className:"text-sm text-gray-500",children:t.brand||t.customBrand})]})]})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:`px-2 py-1 text-xs font-medium rounded-full ${t.productType==="granular"?"bg-green-100 text-green-800":t.productType==="liquid"?"bg-blue-100 text-blue-800":t.productType==="seed"?"bg-yellow-100 text-yellow-800":t.productType==="powder"?"bg-purple-100 text-purple-800":"bg-gray-100 text-gray-800"}`,children:t.productType})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900",children:t.categoryName||"Uncategorized"}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap",children:e.jsx("span",{className:`px-2 py-1 text-xs font-medium rounded-full ${t.isShared?"bg-purple-100 text-purple-800":"bg-orange-100 text-orange-800"}`,children:t.isShared?"Shared":"Custom"})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900",children:t.isShared?e.jsx("span",{className:"text-gray-500",children:"System"}):e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:t.userName}),e.jsx("div",{className:"text-xs text-gray-500",children:t.userEmail})]})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900",children:t.isShared?e.jsxs("div",{children:[e.jsxs("div",{children:[t.rateCount||0," rates"]}),e.jsxs("div",{className:"text-xs text-gray-500",children:[t.usageCount||0," users"]})]}):e.jsxs("div",{children:[e.jsxs("div",{children:[t.spreaderSettingsCount||0," spreader settings"]}),e.jsxs("div",{className:"text-xs text-gray-500",children:[t.usageCount||0," applications"]})]})}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("button",{onClick:()=>q(t),className:"text-blue-600 hover:text-blue-900",title:"View Rates & Settings",children:e.jsx(be,{className:"h-4 w-4"})}),!t.isShared&&e.jsx("button",{onClick:()=>le(t),className:"text-green-600 hover:text-green-900",title:"Promote to Shared Product",children:e.jsx(he,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>ie(t),className:"text-indigo-600 hover:text-indigo-900",title:"Edit Product",children:e.jsx(pe,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>{y(t),D(!0)},className:"text-red-600 hover:text-red-900",title:"Delete Product",children:e.jsx(J,{className:"h-4 w-4"})})]})})]},`${t.isShared?"shared":"custom"}-${t.id}`))})]})})}),L&&e.jsx("div",{className:"fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50",children:e.jsx("div",{className:"relative top-10 mx-auto p-5 border w-full max-w-2xl shadow-lg rounded-md bg-white",children:e.jsxs("div",{className:"mt-3",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-4",children:"Create New Product"}),Z(se,"Create Product")]})})}),z&&e.jsx("div",{className:"fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50",children:e.jsx("div",{className:"relative top-10 mx-auto p-5 border w-full max-w-2xl shadow-lg rounded-md bg-white",children:e.jsxs("div",{className:"mt-3",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-4",children:"Edit Product"}),Z(ae,"Update Product")]})})}),$&&o&&e.jsx("div",{className:"fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50",children:e.jsx("div",{className:"relative top-20 mx-auto p-5 border w-96 shadow-lg rounded-md bg-white",children:e.jsxs("div",{className:"mt-3",children:[e.jsxs("div",{className:"flex items-center mb-4",children:[e.jsx(ye,{className:"h-6 w-6 text-red-600 mr-2"}),e.jsx("h3",{className:"text-lg font-medium text-gray-900",children:"Delete Product"})]}),e.jsxs("p",{className:"text-sm text-gray-600 mb-6",children:['Are you sure you want to delete "',o.name||o.customName,'"? This action cannot be undone.']}),e.jsxs("div",{className:"flex justify-end space-x-3",children:[e.jsx("button",{onClick:()=>D(!1),className:"px-4 py-2 text-sm text-gray-700 bg-gray-200 rounded hover:bg-gray-300",children:"Cancel"}),e.jsx("button",{onClick:re,className:"px-4 py-2 text-sm text-white bg-red-600 rounded hover:bg-red-700",children:"Delete Product"})]})]})})}),V&&o&&e.jsx("div",{className:"fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full z-50",children:e.jsx("div",{className:"relative top-10 mx-auto p-5 border w-full max-w-4xl shadow-lg rounded-md bg-white",children:e.jsxs("div",{className:"mt-3",children:[e.jsxs("h3",{className:"text-lg font-medium text-gray-900 mb-4",children:[o.isShared?"Application Rates":"Spreader Settings"," - ",o.name||o.customName]}),o.isShared?e.jsxs("div",{children:[e.jsxs("h4",{className:"text-md font-semibold text-gray-800 mb-3",children:["Application Rates (",f.rates.length,")"]}),f.rates.length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Type"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Rate"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Unit"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Notes"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200",children:f.rates.map((t,n)=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900",children:t.applicationType}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900",children:t.rateAmount}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900",children:t.rateUnit}),e.jsx("td",{className:"px-6 py-4 text-sm text-gray-900",children:t.notes||"No notes"})]},n))})]})}):e.jsx("p",{className:"text-gray-500 text-center py-8",children:"No application rates defined for this product."})]}):e.jsxs("div",{children:[e.jsxs("h4",{className:"text-md font-semibold text-gray-800 mb-3",children:["Spreader Settings (",f.spreaderSettings.length,")"]}),f.spreaderSettings.length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200",children:[e.jsx("thead",{className:"bg-gray-50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Equipment"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Spreader"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Setting Value"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Rate Description"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Notes"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:"Actions"})]})}),e.jsx("tbody",{className:"bg-white divide-y divide-gray-200",children:f.spreaderSettings.map((t,n)=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900",children:t.equipmentName||"Generic Equipment"}),e.jsxs("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900",children:[t.spreaderBrand," ",t.spreaderModel]}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900",children:t.settingValue||"N/A"}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900",children:t.rateDescription||"Not specified"}),e.jsx("td",{className:"px-6 py-4 text-sm text-gray-900",children:t.notes||"No notes"}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium",children:e.jsx("button",{onClick:()=>de(t.id),className:"text-red-600 hover:text-red-900",title:"Delete Setting",children:e.jsx(J,{className:"h-4 w-4"})})})]},n))})]})}):e.jsx("p",{className:"text-gray-500 text-center py-8",children:"No spreader settings configured for this product."}),e.jsx("div",{className:"mt-4",children:te?e.jsxs("div",{className:"border rounded-lg p-4 bg-gray-50",children:[e.jsx("h5",{className:"text-sm font-semibold text-gray-800 mb-3",children:"Add New Spreader Setting"}),e.jsxs("form",{onSubmit:ne,className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-700 mb-1",children:"Spreader Brand"}),e.jsx("input",{type:"text",required:!0,value:p.spreaderBrand,onChange:t=>g({...p,spreaderBrand:t.target.value}),className:"w-full px-2 py-1 text-sm border border-gray-300 rounded focus:outline-none focus:ring-1 focus:ring-blue-500",placeholder:"e.g. Scotts, TruGreen"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-700 mb-1",children:"Spreader Model"}),e.jsx("input",{type:"text",value:p.spreaderModel,onChange:t=>g({...p,spreaderModel:t.target.value}),className:"w-full px-2 py-1 text-sm border border-gray-300 rounded focus:outline-none focus:ring-1 focus:ring-blue-500",placeholder:"e.g. EdgeGuard, DLX"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-700 mb-1",children:"Setting Value"}),e.jsx("input",{type:"text",value:p.settingValue,onChange:t=>g({...p,settingValue:t.target.value}),className:"w-full px-2 py-1 text-sm border border-gray-300 rounded focus:outline-none focus:ring-1 focus:ring-blue-500",placeholder:"e.g. 3.5, M, Large"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-700 mb-1",children:"Rate Description"}),e.jsx("input",{type:"text",value:p.rateDescription,onChange:t=>g({...p,rateDescription:t.target.value}),className:"w-full px-2 py-1 text-sm border border-gray-300 rounded focus:outline-none focus:ring-1 focus:ring-blue-500",placeholder:"e.g. 2.5 lbs/1000 sq ft"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-gray-700 mb-1",children:"Notes"}),e.jsx("textarea",{value:p.notes,onChange:t=>g({...p,notes:t.target.value}),className:"w-full px-2 py-1 text-sm border border-gray-300 rounded focus:outline-none focus:ring-1 focus:ring-blue-500",rows:"2",placeholder:"Additional notes or instructions"})]}),e.jsxs("div",{className:"flex justify-end space-x-2",children:[e.jsx("button",{type:"button",onClick:()=>{S(!1),g({equipmentId:"",spreaderBrand:"",spreaderModel:"",settingValue:"",rateDescription:"",notes:""})},className:"px-3 py-1 text-xs text-gray-700 bg-gray-200 rounded hover:bg-gray-300",children:"Cancel"}),e.jsx("button",{type:"submit",className:"px-3 py-1 text-xs text-white bg-blue-600 rounded hover:bg-blue-700",children:"Add Setting"})]})]})]}):e.jsxs("button",{onClick:()=>S(!0),className:"btn-primary flex items-center text-sm",children:[e.jsx(H,{className:"h-4 w-4 mr-1"}),"Add Spreader Setting"]})})]}),e.jsx("div",{className:"flex justify-end mt-6",children:e.jsx("button",{onClick:()=>{O(!1),y(null),G({rates:[],spreaderSettings:[]}),S(!1),g({equipmentId:"",spreaderBrand:"",spreaderModel:"",settingValue:"",rateDescription:"",notes:""})},className:"px-4 py-2 text-sm text-gray-700 bg-gray-200 rounded hover:bg-gray-300",children:"Close"})})]})})})]})};export{Se as default};