import{o as e,r as t,t as n}from"./jsx-runtime-BbTa8W_M-1776590214964.js";import{t as r}from"./useTranslation-D1etqd9u-1776590214964.js";import{t as i}from"./circle-alert-BavsmUGI-1776590214964.js";import{t as a}from"./image-plus-BQraWO0s-1776590214964.js";import{t as o}from"./x-CrKussrs-1776590214964.js";import{a as s,n as c,o as l,r as u,t as d}from"./card-Cby8flFO-1776590214964.js";import{t as f}from"./input-BlYvaS0F-1776590214964.js";var p=e(t(),1),m=n(),h=({data:e,setData:t,existingImages:n=[]})=>{let{t:h}=r(),[g,_]=(0,p.useState)([]),v=n.filter(t=>e.existing_images?.includes(t.id)),y=v.length+e.images.length,b=n=>{let r=Array.from(n.target.files);if(y+r.length>10){alert(h(`Maximum 10 images allowed in total.`));return}t(`images`,[...e.images,...r]);let i=r.map(e=>URL.createObjectURL(e));_([...g,...i])},x=n=>{t(`existing_images`,e.existing_images.filter(e=>e!==n))},S=n=>{let r=e.images.filter((e,t)=>t!==n),i=g.filter((e,t)=>t!==n);t(`images`,r),_(i)};return(0,m.jsxs)(d,{className:`shadow-sm`,children:[(0,m.jsxs)(s,{children:[(0,m.jsxs)(l,{children:[h(`Product Images`),` (`,y,`/10)`]}),(0,m.jsx)(u,{children:h(`Upload up to 10 images. The first image will be the cover.`)})]}),(0,m.jsxs)(c,{children:[(0,m.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-5 gap-4 mb-4`,children:[v.map((e,t)=>(0,m.jsxs)(`div`,{className:`relative group aspect-square border border-primary/20 rounded-lg overflow-hidden bg-white`,children:[(0,m.jsx)(`img`,{src:`/storage/${e.path}`,className:`w-full h-full object-contain p-1`,alt:``}),(0,m.jsx)(`button`,{type:`button`,onClick:()=>x(e.id),className:`absolute top-1 right-1 bg-red-500 text-white rounded-full p-1 opacity-0 group-hover:opacity-100 transition-opacity z-10`,children:(0,m.jsx)(o,{className:`w-3 h-3`})}),t===0&&(0,m.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 bg-primary text-[10px] text-white text-center py-0.5`,children:h(`Main Cover`)})]},`existing-${e.id}`)),g.map((e,t)=>{let n=v.length===0&&t===0;return(0,m.jsxs)(`div`,{className:`relative group aspect-square border border-dashed border-primary/50 rounded-lg overflow-hidden bg-muted`,children:[(0,m.jsx)(`img`,{src:e,className:`w-full h-full object-contain p-1`,alt:``}),(0,m.jsx)(`button`,{type:`button`,onClick:()=>S(t),className:`absolute top-1 right-1 bg-red-500 text-white rounded-full p-1 opacity-0 group-hover:opacity-100 transition-opacity z-10`,children:(0,m.jsx)(o,{className:`w-3 h-3`})}),n&&(0,m.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 bg-primary/80 text-[10px] text-white text-center py-0.5`,children:h(`New Cover`)})]},`new-${t}`)}),y<10&&(0,m.jsxs)(`label`,{className:`flex flex-col items-center justify-center aspect-square border-2 border-dashed rounded-lg cursor-pointer hover:bg-muted/50 transition-colors bg-card`,children:[(0,m.jsx)(a,{className:`w-6 h-6 text-muted-foreground`}),(0,m.jsx)(`span`,{className:`text-[10px] mt-2 font-bold text-muted-foreground`,children:h(`Add Photo`)}),(0,m.jsx)(f,{type:`file`,multiple:!0,accept:`image/*`,className:`hidden`,onChange:b})]})]}),y===0&&(0,m.jsxs)(`div`,{className:`flex items-center gap-2 p-3 text-sm rounded-md bg-amber-500/10 text-amber-600 border border-amber-500/20 mt-4`,children:[(0,m.jsx)(i,{className:`w-4 h-4`}),h(`At least one product image is required to publish.`)]})]})]})};export{h as t};