"use strict";exports.id=84261,exports.ids=[84261],exports.modules={19673:(a,b,c)=>{c.d(b,{R:()=>n});var d=c(48249),e=c(67484),f=c.n(e),g=c(52099),h=c(7154),i=c(62828),j=c(41090),k=c(20524),l=c(3430);let m=i.Ikc({title:i.YjP().max(255,"Title must be less than 255 characters").optional().or(i.euz(""))}),n=f().memo(({galleryItem:a,onSubmit:b,onCancel:c,isLoading:f=!1})=>{let[i,n]=(0,e.useState)([]),[o,p]=(0,e.useState)([]),[q,r]=(0,e.useState)(!1),s=f||q,{register:t,handleSubmit:u,formState:{errors:v}}=(0,g.mN)({resolver:(0,h.u)(m),defaultValues:{title:a?.title||""},mode:"onBlur"}),w=(0,e.useCallback)(a=>{let b=Array.from(a.target.files||[]);if(0===b.length)return;let c=[],d=[];b.forEach(a=>{let b=a.size/1048576;!a.type.startsWith("image/")||b>10||(c.push(a),d.push(URL.createObjectURL(a)))}),n(c),p(d)},[]),x=(0,e.useCallback)(async c=>{let d=c.title?.trim()||"",e=d!==(a?.title||""),f=i.length>0;if(!a&&!f)return void alert("Please upload at least one image.");if(a&&!f&&!e)return void alert("Please upload new image(s) or update the title.");r(!0);try{await b({title:d||void 0,mediaType:"IMAGE",files:f?i:void 0})}finally{r(!1)}},[i,b,a]),y=(0,e.useMemo)(()=>!!a,[a]);return(0,d.jsxs)("form",{onSubmit:u(x),className:"space-y-6",children:[(0,d.jsxs)(j.Z,{padding:"lg",children:[(0,d.jsx)("h2",{className:"text-2xl font-bold mb-6 text-[var(--foreground)]",children:y?"Update Gallery Item":"Create Gallery Items"}),(0,d.jsxs)("div",{className:"space-y-4",children:[(0,d.jsx)(l.p,{label:"Title (optional)",...t("title"),error:v.title?.message,placeholder:"Enter gallery item title (optional)"}),(0,d.jsxs)("div",{children:[(0,d.jsxs)("label",{className:"block text-sm font-medium text-[var(--foreground)] mb-2",children:["Image Files ",y?"(optional)":"*"]}),(0,d.jsx)("input",{type:"file",accept:"image/*",multiple:!0,onChange:w,className:"block w-full text-sm text-[var(--foreground)] file:mr-4 file:py-2 file:px-4 file:rounded-none file:border-0 file:text-sm file:font-semibold file:bg-[var(--primary-100)] file:text-[var(--primary-700)] hover:file:bg-[var(--primary-200)]"}),(0,d.jsx)("p",{className:"mt-1 text-xs text-[var(--muted-foreground)]",children:"Upload one or many images (max 10MB each). Title applies to all uploads (optional)."}),i.length>0&&(0,d.jsxs)("div",{className:"mt-4",children:[(0,d.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,d.jsxs)("p",{className:"text-sm text-[var(--muted-foreground)]",children:[i.length," file",i.length>1?"s":""," selected"]}),(0,d.jsx)("button",{type:"button",className:"text-sm text-red-600 hover:underline",onClick:()=>{n([]),p([])},children:"Remove all"})]}),(0,d.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3",children:o.map((a,b)=>(0,d.jsx)("div",{className:"relative aspect-square rounded-none overflow-hidden border border-[var(--border)]",children:(0,d.jsx)("img",{src:a,alt:`Preview ${b+1}`,className:"w-full h-full object-cover"})},a+b))})]})]})]})]}),(0,d.jsxs)("div",{className:"flex justify-between items-center pt-6 border-t border-[var(--border)]",children:[c&&(0,d.jsx)(k.$,{type:"button",variant:"ghost",onClick:c,children:"Cancel"}),(0,d.jsx)(k.$,{type:"submit",variant:"primary",disabled:s,children:s?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4 inline",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[(0,d.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,d.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Uploading..."]}):y?"Update Gallery Item":"Create Gallery Items"})]})]})})},84261:(a,b,c)=>{c.r(b),c.d(b,{default:()=>i});var d=c(48249);c(67484);var e=c(19099),f=c(19673),g=c(70815),h=c(91115);function i(){let a=(0,e.useRouter)(),b=async b=>{try{console.log("Creating gallery item with data:",{title:b.title,fileCount:b.files?.length||0}),await g.og(b),(0,h.Te)("Gallery items created successfully!"),a.push("/admin/gallery")}catch(b){console.error("Error creating gallery item:",b);let a="Failed to create gallery item";a=b?.message?.includes("timeout")||b?.message?.includes("timed out")?"Upload timed out. Please try again with a smaller file or check your internet connection.":b?.response?.status===408?b?.response?.data?.message||"Upload timed out. Please try again with a smaller file.":b?.message||b?.response?.data?.message||a,(0,h.Qg)(a)}};return(0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{className:"mb-8",children:[(0,d.jsx)("h1",{className:"text-3xl font-bold text-[var(--foreground)]",children:"Create New Gallery Item"}),(0,d.jsx)("p",{className:"text-[var(--muted-foreground)] mt-2",children:"Add one or many images to the gallery"})]}),(0,d.jsx)(f.R,{onSubmit:b,onCancel:()=>{a.push("/admin/gallery")}})]})}}};