import{r as e,t}from"./jsx-runtime-BbTa8W_M-1776590214964.js";import{t as n}from"./app-CXDQ5oEH-1776590214964.js";import{t as r}from"./useTranslation-D1etqd9u-1776590214964.js";import{t as i}from"./circle-plus-cg9Cid_6-1776590214964.js";import{t as a}from"./circle-question-mark-DOaYfAof-1776590214964.js";import{t as o}from"./image-plus-BQraWO0s-1776590214964.js";import{t as s}from"./trash-2-DaYZOh6f-1776590214964.js";import{t as c}from"./button-WiAFyHfP-1776590214964.js";import{t as l}from"./label-DwYxovYB-1776590214964.js";import{i as u,n as d,r as f,t as p}from"./tooltip-DTL_sKN1-1776590214964.js";import{a as m,n as h,o as g,r as _,t as v}from"./card-Cby8flFO-1776590214964.js";import{t as y}from"./input-BlYvaS0F-1776590214964.js";e();var b=t(),x=({data:e,setData:t,currencies:x})=>{let{t:S}=r(),C=e.variations||[],w=x?.find(t=>t.code===e.currency_code)||{symbol:`$`},T=()=>{t(`variations`,[...C,{name:``,options:[{value:``,additional_price:``,image:null,preview:null,existing_image:null}]}])},E=e=>{t(`variations`,C.filter((t,n)=>n!==e))},D=(e,n)=>{let r=[...C];r[e].name=n,t(`variations`,r)},O=e=>{let n=[...C];n[e].options.push({value:``,additional_price:``,image:null,preview:null,existing_image:null}),t(`variations`,n)},k=(e,n)=>{let r=[...C];r[e].options=r[e].options.filter((e,t)=>t!==n),t(`variations`,r)},A=(e,n,r,i)=>{let a=[...C];a[e].options[n][r]=i,t(`variations`,a)},j=(e,r,i)=>{let a=e.target.files[0];if(!a)return;if(a.size>100*1024){n.error(S(`Image must be less than 100KB for variations.`)),e.target.value=``;return}let o=[...C];o[r].options[i].image=a,o[r].options[i].preview=URL.createObjectURL(a),t(`variations`,o)};return(0,b.jsxs)(v,{className:`shadow-sm border-primary/20`,children:[(0,b.jsxs)(m,{className:`flex flex-row items-center justify-between pb-2`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(g,{className:`flex items-center gap-2`,children:[S(`Product Variations`),(0,b.jsx)(f,{children:(0,b.jsxs)(p,{children:[(0,b.jsx)(u,{type:`button`,children:(0,b.jsx)(a,{className:`w-4 h-4 text-muted-foreground`})}),(0,b.jsx)(d,{children:(0,b.jsx)(`p`,{children:S(`Create selectable options like Color, Size, or Material. Add extra cost or specific thumbnails per option.`)})})]})})]}),(0,b.jsx)(_,{children:S(`e.g., Color (Red, Blue) or Storage (64GB, 128GB)`)})]}),(0,b.jsxs)(c,{type:`button`,variant:`outline`,size:`sm`,onClick:T,children:[(0,b.jsx)(i,{className:`w-4 h-4 mr-2`}),` `,S(`Add Variation Type`)]})]}),(0,b.jsxs)(h,{className:`space-y-6`,children:[C.map((e,t)=>(0,b.jsxs)(`div`,{className:`p-4 border rounded-xl bg-muted/10`,children:[(0,b.jsxs)(`div`,{className:`flex items-center justify-between gap-4 mb-4`,children:[(0,b.jsxs)(`div`,{className:`flex-1`,children:[(0,b.jsx)(l,{className:`text-xs font-bold text-muted-foreground uppercase`,children:S(`Variation Name`)}),(0,b.jsx)(y,{placeholder:S(`e.g. Color, Size`),value:e.name,onChange:e=>D(t,e.target.value),className:`bg-background font-bold mt-1`})]}),(0,b.jsx)(c,{type:`button`,variant:`ghost`,onClick:()=>E(t),className:`text-destructive hover:bg-destructive/10 mt-5`,children:(0,b.jsx)(s,{className:`w-4 h-4`})})]}),(0,b.jsxs)(`div`,{className:`space-y-3`,children:[e.options.map((e,n)=>(0,b.jsxs)(`div`,{className:`flex flex-wrap sm:flex-nowrap items-center gap-3 p-2 border rounded-lg bg-background shadow-sm`,children:[(0,b.jsxs)(`label`,{className:`cursor-pointer shrink-0`,children:[(0,b.jsx)(`div`,{className:`w-10 h-10 border border-dashed rounded-md flex items-center justify-center bg-muted overflow-hidden relative group hover:border-primary`,children:e.preview||e.image_path?(0,b.jsx)(`img`,{src:e.preview||`/storage/${e.image_path}`,className:`w-full h-full object-cover`,alt:`Variation`}):(0,b.jsx)(o,{className:`w-4 h-4 text-muted-foreground group-hover:text-primary transition-colors`})}),(0,b.jsx)(`input`,{type:`file`,accept:`image/*`,className:`hidden`,onChange:e=>j(e,t,n)})]}),(0,b.jsx)(y,{placeholder:S(`Option (e.g. Red, XL)`),value:e.value,onChange:e=>A(t,n,`value`,e.target.value),className:`flex-1`}),(0,b.jsxs)(`div`,{className:`relative w-full sm:w-32 shrink-0`,children:[(0,b.jsx)(`span`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground text-xs`,children:w.symbol}),(0,b.jsx)(y,{type:`number`,min:`0`,step:`0.01`,placeholder:`+0.00`,value:e.additional_price,onChange:e=>A(t,n,`additional_price`,e.target.value),className:`pl-6`,title:S(`Additional cost for this option`)})]}),(0,b.jsx)(c,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>k(t,n),className:`text-destructive shrink-0`,children:(0,b.jsx)(s,{className:`w-4 h-4`})})]},n)),(0,b.jsxs)(c,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>O(t),className:`mt-2 w-full sm:w-auto text-xs`,children:[(0,b.jsx)(i,{className:`w-3 h-3 mr-2`}),` `,S(`Add Option`)]})]})]},t)),C.length===0&&(0,b.jsx)(`p`,{className:`text-sm text-center text-muted-foreground italic py-4`,children:S(`No variations added. Product is a single standard item.`)})]})]})};export{x as t};