1import{j as e}from"./vendor-tiptap-CRdka2py.js";import{u as ce,b as r}from"./vendor-i18n-Do9jGewF.js";import{C as le}from"./HelpButton-Dht5BAjR.js";import{aN as oe,s as de,r as pe}from"./index-Dm1QE6j5.js";import"./vendor-firebase-B7FTlnjY.js";import{M as xe,C as ue}from"./MediaPicker-D0nI0pq3.js";import{A as V,R as X}from"./RichTextEditor-BxRaERzG.js";import{s as me}from"./RichTextContent-CjBbBA82.js";import"./purify.es-5AjVNlXF.js";const we=({products:N,onAdd:J,onUpdate:Q,onDelete:Y})=>{const{t:a}=ce(),{addToast:z}=oe(),[B,m]=r.useState(!1),[A,D]=r.useState(!1),[s,g]=r.useState(null),[b,w]=r.useState(null),[H,y]=r.useState(null),[Z,ee]=r.useState(!1),[S,te]=r.useState(!1),[K,ae]=r.useState([]);r.useEffect(()=>{de().then(t=>{t?.enabled&&t?.publicKey&&ee(!0)}).catch(()=>{}),pe().then(t=>{t&&(te(t.vatEnabled??!1),ae(t.vatRates??[]))}).catch(()=>{})},[]);const[x,v]=r.useState(""),[h,f]=r.useState(""),[U,C]=r.useState(0),[_,M]=r.useState(void 0),[F,P]=r.useState(""),[L,j]=r.useState(""),[l,E]=r.useState("Utrustning"),[G,T]=r.useState(""),[W,I]=r.useState(""),[$,R]=r.useState(""),[u,k]=r.useState({}),[q,O]=r.useState(0),re=r.useMemo(()=>{const t=["Utrustning","Kläder","Märken","Annat"],n=N.map(c=>c.category);return Array.from(new Set([...t,...n])).sort()},[N]);r.useEffect(()=>{s?(v(s.name||""),f(s.nameEn||""),C(s.price||0),M(s.vatRate),P(s.description||""),j(s.descriptionEn||""),E(s.category||"Utrustning"),T(s.paymentLink||""),I(s.stripePriceId||""),y(s.image||null),R(s.sizes?.join(", ")||""),k(s.inventory||{}),O(s.stock||0)):(v(""),f(""),C(0),M(void 0),P(""),j(""),E("Utrustning"),T(""),I(""),y(null),R(""),k({}),O(0))},[s,B]);const se=t=>{const n=t.target.value;R(n);const c=n.split(",").map(d=>d.trim()).filter(Boolean),p={};c.forEach(d=>{p[d]=u[d]!==void 0?u[d]:0}),k(p)},ne=(t,n)=>{k(c=>({...c,[t]:n}))},ie=async t=>{t.preventDefault(),D(!0);try{const n=$.split(",").map(d=>d.trim()).filter(Boolean),c=l==="Kläder",p={name:x,nameEn:h||void 0,description:F||"",descriptionEn:L||void 0,price:Number(U)||0,vatRate:S?_:void 0,category:l,paymentLink:G||void 0,stripePriceId:W||void 0,sizes:c?n:[],inventory:c?u:{},stock:c?0:q,image:H||""};s?(await Q({...s,...p}),z(a("productManager.toastUpdated"),"success")):(await J(p),z(a("productManager.toastCreated"),"success")),m(!1),g(null)}catch(n){console.error("Save error:",n),z(a("productManager.toastSaveError"),"error")}finally{D(!1)}},i="block text-[10px] font-black text-zinc-400 uppercase tracking-widest mb-2 ml-1",o="w-full p-4 rounded-xl bg-zinc-50 dark:bg-zinc-800 border border-zinc-200 dark:border-zinc-700 font-bold text-zinc-900 dark:text-white outline-none focus:ring-2 focus:ring-primary transition-all placeholder-zinc-400";return e.jsxs("div",{className:"bg-white dark:bg-dark-surface p-8 rounded-[2.5rem] shadow-soft border border-zinc-200 dark:border-zinc-800",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-center border-b border-zinc-100 dark:border-zinc-800 pb-6 mb-8 gap-4",children:[e.jsx("h3",{className:"text-3xl font-black text-zinc-900 dark:text-white uppercase tracking-tighter font-display",children:a("productManager.pageTitle")}),e.jsx("button",{onClick:()=>{g(null),m(!0)},className:"bg-green-600 hover:bg-green-700 text-white font-black py-3 px-8 rounded-xl transition-all uppercase tracking-widest text-xs shadow-lg shadow-green-900/20 active:scale-95",children:a("productManager.createButton")})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:N.map(t=>{const c=t.category==="Kläder"?Object.values(t.inventory||{}).reduce((p,d)=>p+d,0):t.stock||0;return e.jsxs("div",{className:"p-6 bg-zinc-50 dark:bg-[#090909] rounded-[2rem] border border-zinc-100 dark:border-zinc-800 flex flex-col group hover:border-primary/30 transition-all",children:[e.jsxs("div",{className:"flex gap-4 mb-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-zinc-200 dark:bg-zinc-800 overflow-hidden flex-shrink-0 shadow-inner border border-zinc-100 dark:border-zinc-800",children:t.image?e.jsx("img",{src:t.image,className:"w-full h-full object-cover",alt:t.name}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-zinc-400",children:e.jsx("svg",{className:"w-6 h-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})})})}),e.jsxs("div",{className:"min-w-0 flex-grow",children:[e.jsx("h4",{className:"font-bold text-zinc-900 dark:text-white truncate text-lg uppercase tracking-tight",children:t.name}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("p",{className:"text-sm font-black text-primary uppercase tracking-widest",children:[t.price," kr"]}),e.jsx("span",{className:"text-[10px] font-black text-zinc-400 uppercase bg-zinc-100 dark:bg-zinc-800 px-1.5 py-0.5 rounded border border-zinc-200 dark:border-zinc-700",children:t.category})]})]})]}),e.jsxs("div",{className:"mb-6 flex-grow",children:[e.jsxs("p",{className:"text-xs text-zinc-500 line-clamp-2 italic",children:['"',me(t.de
1scription),'"']}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx("div",{className:`w-2 h-2 rounded-full ${c>0?"bg-green-500":"bg-red-500"}`}),e.jsx("span",{className:"text-[10px] font-black text-zinc-400 uppercase tracking-widest",children:a("productManager.inStockCount",{count:c})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 pt-4 border-t border-zinc-100 dark:border-zinc-800/50",children:[e.jsx("button",{onClick:()=>{g(t),m(!0)},className:"bg-zinc-900 dark:bg-white text-white dark:text-black font-black py-2.5 rounded-xl text-[10px] uppercase tracking-widest transition-all active:scale-95",children:a("productManager.editButton")}),e.jsx("button",{onClick:()=>w(t),className:"bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 font-black py-2.5 rounded-xl text-[10px] uppercase tracking-widest border border-red-100 dark:border-red-900/50 transition-all active:scale-95",children:a("common.remove")})]})]},t.id)})}),B&&e.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[110] p-4 backdrop-blur-sm",children:e.jsx("div",{className:"bg-white dark:bg-dark-surface rounded-[2.5rem] shadow-2xl w-full max-w-2xl max-h-[90vh] flex flex-col border border-zinc-200 dark:border-zinc-800 overflow-hidden animate-in zoom-in-95 duration-200",children:e.jsxs("form",{onSubmit:ie,className:"flex flex-col h-full overflow-hidden font-sans",children:[e.jsxs("div",{className:"p-8 border-b border-zinc-100 dark:border-zinc-800 flex justify-between items-center",children:[e.jsx("h3",{className:"text-3xl font-black text-zinc-900 dark:text-white uppercase tracking-tighter font-display",children:a(s?"productManager.editProductTitle":"productManager.newProductTitle")}),e.jsx("button",{type:"button",onClick:()=>{m(!1),g(null)},className:"text-zinc-400 hover:text-zinc-600 transition-colors",children:e.jsx("svg",{className:"w-8 h-8",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2.5",d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"p-8 overflow-y-auto flex-grow space-y-8 custom-scrollbar",children:[e.jsx(xe,{value:H||"",onChange:t=>y(t||null),compressOptions:ue.product,label:a("productManager.productImageLabel"),previewSize:"md",tags:["product"],hint:a("productManager.productImageHint")}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:i,children:a("productManager.nameLabelSv")}),e.jsx(V,{variant:"standalone",contentType:"general",context:{category:l},existingText:x,fieldLabel:"Produktnamn",onTextGenerated:v})]}),e.jsx("input",{value:x,onChange:t=>v(t.target.value),placeholder:a("productManager.namePlaceholder"),className:o,required:!0})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:i,children:a("productManager.nameLabelEn")}),e.jsx(V,{variant:"standalone",contentType:"general",context:{category:l},existingText:h,fieldLabel:"Product name",onTextGenerated:f,language:"en"})]}),e.jsx("input",{value:h,onChange:t=>f(t.target.value),placeholder:a("productManager.namePlaceholder"),className:o})]})]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-6",children:e.jsxs("div",{children:[e.jsx("label",{className:i,children:a("productManager.categoryLabel")}),e.jsx("select",{value:l,onChange:t=>E(t.target.value),className:o,children:re.map(t=>e.jsx("option",{value:t,children:t},t))})]})}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsxs("label",{className:i,children:[a("productManager.priceLabel"),S?a("productManager.priceInclVatSuffix"):""]}),e.jsx("input",{type:"number",value:U||"",onChange:t=>C(parseInt(t.target.value)),className:o,required:!0})]}),S&&K.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:i,children:a("productManager.vatRateLabel")}),e.jsxs("select",{value:_??"",onChange:t=>M(t.target.value?parseFloat(t.target.value):void 0),className:o,children:[e.jsx("option",{value:"",children:a("productManager.noVatOption")}),K.map(t=>e.jsxs("option",{value:t.rate,children:[t.rate,"% â ",t.label]},t.id))]})]}),e.jsx("div",{children:Z?e.jsxs(e.Fragment,{children:[e.jsx("label",{className:i,children:a("productManager.stripePriceIdLabel")}),e.jsx("input",{type:"text",value:W,onChange:t=>I(t.target.value),placeholder:"price_...",className:`${o} font-mono text-xs`}),e.jsx("p",{className:"text-[9px] text-zinc-500 mt-2 ml-1 italic leading-relaxed",children:a("productManager.stripePriceIdHint")})]}):e.jsxs(e.Fragment,{children:[e.jsx("label",{className:i,children:a("productManager.directPaymentLinkLabel")}),e.jsx("input",{type:"url",value:G,onChange:t=>T(t.target.value),placeholder:"https://buy.stripe.com/...",className:`${o} font-mono text-xs`})]})})]}),e.jsxs("div",{children:[e.jsx("label",{className:i,children:a("productManager.descriptionLabelSv")}),e.jsx(X,{content:F,onChange:P,placeholder:a("productManager.descriptionPlaceholder"),minHeight:"120px",toolbarVariant:"compact",aiContentType:"product_description",aiContext:{title:x,category:l}})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("label",{className:i.replace("mb-2",""),children:a("productManager.descriptionLabelEn")}),e.jsx(V,{variant:"standalone",contentType:"product_description",context:{title:h||x,category:l},existingText:L,fieldLabel:"Product description",onTextGenerated:j,language:"en"})]}),e.jsx(X,{content:L,onChange:j,placeholder:a("productManager.descriptionPlaceholderEn"),minHeight:"120px",toolbarVariant:"compact",aiContentType:"product_description",aiContext:{title:h||x,category:l,language:"en"}})]}),l==="Kläder"?e.jsxs("div",{className:"space-y-6 pt-6 border-t border-zinc-100 dark:border-zinc-800",children:[e.jsxs("div",{children:[e.jsx("label",{className:i,children:a("productManager.sizesLabel")}),e.jsx("input",{value:$,onChange:se,placeholder:"S, M, L, XL",className:o})]}),Object.keys(u).length>0&&e.jsxs("div",{children:[e.jsx("label",{className:i,children:a("productManager.stockPerSizeLabel")}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:Object.keys(u).map(t=>e.jsxs("div",{className:"p-3 bg-zinc-50 dark:bg-zinc-900 rounded-xl border border-zinc-200 dark:border-zinc-700",children:[e.jsx("span",{className:"block text-[9px] font-black text-zinc-400 uppercase tracking-widest mb-1 text-center",children:t}),e.jsx("input",{type:"number",value:u[t],onChange:n=>ne(t,parseInt(n.target.value)||0),className:"w-full bg-transparent text-center font-black text-zinc-900 dark:text-white outline-none"})]},t))})]})]}):e.jsxs("div",{className:"pt-6 border-t border-zinc-100 dark:border-zinc-800",children:[e.jsx("label",{className:i,children:a("productManager.totalStockLabel")}),e.jsx("input",{type:"number",value:q||"",onChange:t=>O(parseInt(t.target.value)||0),className:o})]})]}),e.jsxs("div",{className:"p-8 bg-zinc-50 dark:bg-[#090909] border-t border-zinc-100 dark:border-zinc-800 flex justify-between items-center gap-6",children:[e.jsx("button",{type:"button",onClick:()=>{m(!1),g(null)},className:"px-6 py-4 font-black text-[11px] uppercase tracking-widest text-zinc-400 hover:text-zinc-800 dark:hover:text-white transition-colors",children:a("common.cancel")}),e.jsx("button",{type:"submit",disabled:A,className:"bg-primary hover:bg-primary-hover text-white font-black py-4 px-12 rounded-[1.25rem] text-[11px] uppercase tracking-widest shadow-glow active:scale-95 disabled:opacity-50",children:a(A?"common.saving":"productManager.saveButton")})]})]})})}),b&&e.jsx(le,{isOpen:!!b,onClose:()=>w(null),onConfirm:async()=>{await Y(b.id),w(null)},title:a("productManager.deleteProductTitle"),message:a("productManager.deleteProductMessage",{name:b.name}),confirmText:a("common.remove")})]})};export{we as ProductManager};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.