import{An as e,D as t,Et as n,F as r,Ht as i,Lt as a,Mn as o,N as s,Nn as c,On as l,Pn as u,Tn as d,Yt as f,Zt as p,_n as m,_t as h,an as g,en as _,g as v,nn as y,on as b,rn as x,tn as S,wn as C,wt as w}from"./app-4kCgdoJR.js";var T={class:`border-b border-gray-200 px-6 py-4 dark:border-gray-700`},E={class:`sm:flex sm:items-baseline sm:justify-between`},D={class:`sm:w-0 sm:flex-1`},O={class:`text-focus text-base font-semibold`},k={class:`text-mute mt-1 truncate text-sm`},A={class:`grid grid-cols-6 gap-6 p-6`},j={class:`col-span-full`},M={class:`mt-2 rounded-md p-1`},N=[`alt`,`src`],P={class:`mt-2 rounded-md p-1`},F={class:`col-span-6 sm:col-span-3`},I={class:`col-span-6 sm:col-span-3`},L={class:`col-span-6 sm:col-span-2`},R={class:`col-span-6 sm:col-span-4`},z={class:`col-span-full`},B={class:`col-span-full`},V={class:`flex flex-row justify-end bg-gray-100 px-6 py-4 text-end dark:bg-gray-950`},H={__name:`Form`,props:[`current`,`parents`],emits:[`close`,`done`],setup(H,{emit:U}){let W=U,G=H,K=l(null),q=l(null),J=i({_method:G.current?.id?`put`:`post`,photo:null,name:G.current?.name,slug:G.current?.slug,order:G.current?.order,title:G.current?.title,description:G.current?.description,active:G.current?.id?G.current?.active==1:!0}),Y=()=>{J.reset(),q.value=null,$(),W(`close`)},X=()=>{let e=K.value.files[0];if(!e)return;let t=new FileReader;t.onload=e=>{q.value=e.target.result},t.readAsDataURL(e)},Z=e=>{u.delete(a(`brands.photo.destroy`,{id:e.id}),{preserveScroll:!0,onSuccess:()=>{q.value=null,$()}})},Q=()=>{K.value.click()},$=()=>{K.value?.value&&(K.value.value=null)};function ee(){K.value&&(J.photo=K.value.files[0]),J.post(G.current?.id?a(`brands.update`,G.current.id):a(`brands.store`),{onSuccess:()=>{J.reset(),W(`done`),W(`close`)}})}return(i,a)=>(m(),x(`form`,{onSubmit:p(ee,[`prevent`])},[_(`div`,T,[_(`div`,E,[_(`div`,D,[_(`h1`,O,c(H.current?.id?i.$t(`Edit {x}`,{x:i.$t(`Brand`)}):i.$t(`Add {x}`,{x:i.$t(`Brand`)})),1),_(`p`,k,c(i.$t(`Please fill the form below to {action} {record}.`,{record:i.$t(`brand`),action:H.current?.id?i.$t(`edit`):i.$t(`add`)})),1)])])]),_(`div`,A,[_(`div`,j,[_(`input`,{id:`photo`,ref_key:`photoInput`,ref:K,type:`file`,class:`hidden`,onChange:a[0]||=()=>X()},null,544),b(e(h),{for:`photo`,value:i.$t(`Photo`)},null,8,[`value`]),d(_(`div`,M,[_(`img`,{alt:i.$t(`Photo`),src:H.current?.photo,class:`h-full max-h-40 min-h-20 w-full max-w-64 rounded-md object-contain`},null,8,N)],512),[[f,!q.value&&H.current?.photo]]),d(_(`div`,P,[_(`span`,{class:`block h-full max-h-40 min-h-24 w-full max-w-64 rounded-md bg-contain bg-no-repeat`,style:o(`background-image: url('`+q.value+`');`)},null,4)],512),[[f,q.value]]),b(e(w),{class:`me-2 mt-2`,type:`button`,onClick:a[1]||=p(()=>Q(),[`prevent`])},{default:C(()=>[g(c(i.$t(`Select A New Photo`)),1)]),_:1}),H.current?.photo?(m(),S(e(w),{key:0,type:`button`,onClick:a[2]||=p(()=>Z(),[`prevent`]),class:`mt-2 flex items-center justify-center rounded-md bg-gray-50 p-1`},{default:C(()=>[g(c(i.$t(`Remove Photo`)),1)]),_:1})):y(``,!0),b(e(n),{message:e(J).errors.photo,class:`mt-2`},null,8,[`message`])]),_(`div`,F,[b(e(t),{id:`name`,label:i.$t(`Name`),modelValue:e(J).name,"onUpdate:modelValue":a[3]||=t=>e(J).name=t,error:e(J).errors.name},null,8,[`label`,`modelValue`,`error`])]),_(`div`,I,[b(e(t),{id:`slug`,label:i.$t(`Slug`),modelValue:e(J).slug,"onUpdate:modelValue":a[4]||=t=>e(J).slug=t,error:e(J).errors.slug},null,8,[`label`,`modelValue`,`error`])]),_(`div`,L,[b(e(t),{type:`number`,id:`order`,label:i.$t(`Order`),modelValue:e(J).order,"onUpdate:modelValue":a[5]||=t=>e(J).order=t,error:e(J).errors.order},null,8,[`label`,`modelValue`,`error`])]),_(`div`,R,[b(e(t),{id:`title`,max:`50`,label:i.$t(`Title`),modelValue:e(J).title,"onUpdate:modelValue":a[6]||=t=>e(J).title=t,error:e(J).errors.title},null,8,[`label`,`modelValue`,`error`])]),_(`div`,z,[b(e(v),{max:`160`,id:`description`,label:i.$t(`Description`),modelValue:e(J).description,"onUpdate:modelValue":a[7]||=t=>e(J).description=t,error:e(J).errors.description},null,8,[`label`,`modelValue`,`error`])]),_(`div`,B,[b(e(s),{id:`active`,error:e(J).errors.active,checked:e(J).active,"onUpdate:checked":a[8]||=t=>e(J).active=t,label:i.$t(`Active`)},null,8,[`error`,`checked`,`label`])])]),_(`div`,V,[b(e(w),{onClick:Y},{default:C(()=>[g(c(i.$t(`Cancel`)),1)]),_:1}),b(e(r),{class:`ms-3`,loading:e(J).processing},{default:C(()=>[g(c(i.$t(`Save`)),1)]),_:1},8,[`loading`])])],32))}};export{H as default};