import{An as e,D as t,Et as n,F as r,Ht as i,L as a,Lt as o,Mn as s,N as c,Nn as l,On as u,Pn as d,Tn as f,Yt as p,Zt as m,_n as h,_t as g,an as _,en as v,g as y,nn as b,on as x,rn as ee,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-3`},te={class:`col-span-6 sm:col-span-3`},R={class:`col-span-full`},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=u(null),q=u(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,category_id:G.current?.category_id,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=>{d.delete(o(`categories.photo.destroy`,{id:e.id}),{preserveScroll:!0,onSuccess:()=>{q.value=null,$()}})},Q=()=>{K.value.click()},$=()=>{K.value?.value&&(K.value.value=null)};function ne(){K.value&&(J.photo=K.value.files[0]),J.post(G.current?.id?o(`categories.update`,G.current.id):o(`categories.store`),{onSuccess:()=>{J.reset(),W(`done`),W(`close`)}})}return(i,o)=>(h(),ee(`form`,{onSubmit:m(ne,[`prevent`])},[v(`div`,T,[v(`div`,E,[v(`div`,D,[v(`h1`,O,l(H.current?.id?i.$t(`Edit {x}`,{x:i.$t(`Category`)}):i.$t(`Add {x}`,{x:i.$t(`Category`)})),1),v(`p`,k,l(i.$t(`Please fill the form below to {action} {record}.`,{record:i.$t(`category`),action:H.current?.id?i.$t(`edit`):i.$t(`add`)})),1)])])]),v(`div`,A,[v(`div`,j,[v(`input`,{id:`photo`,ref_key:`photoInput`,ref:K,type:`file`,class:`hidden`,onChange:o[0]||=()=>X()},null,544),x(e(g),{for:`photo`,value:i.$t(`Photo`)},null,8,[`value`]),f(v(`div`,M,[v(`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),[[p,!q.value&&H.current?.photo]]),f(v(`div`,P,[v(`span`,{class:`block h-full max-h-40 min-h-24 w-full max-w-64 rounded-md bg-contain bg-no-repeat`,style:s(`background-image: url('`+q.value+`');`)},null,4)],512),[[p,q.value]]),x(e(w),{class:`me-2 mt-2`,type:`button`,onClick:o[1]||=m(()=>Q(),[`prevent`])},{default:C(()=>[_(l(i.$t(`Select A New Photo`)),1)]),_:1}),H.current?.photo?(h(),S(e(w),{key:0,type:`button`,onClick:o[2]||=m(()=>Z(),[`prevent`]),class:`mt-2 flex items-center justify-center rounded-md bg-gray-50 p-1`},{default:C(()=>[_(l(i.$t(`Remove Photo`)),1)]),_:1})):b(``,!0),x(e(n),{message:e(J).errors.photo,class:`mt-2`},null,8,[`message`])]),v(`div`,F,[x(e(t),{id:`name`,label:i.$t(`Name`),modelValue:e(J).name,"onUpdate:modelValue":o[3]||=t=>e(J).name=t,error:e(J).errors.name},null,8,[`label`,`modelValue`,`error`])]),v(`div`,I,[x(e(t),{id:`slug`,label:i.$t(`Slug`),modelValue:e(J).slug,"onUpdate:modelValue":o[4]||=t=>e(J).slug=t,error:e(J).errors.slug},null,8,[`label`,`modelValue`,`error`])]),v(`div`,L,[x(e(t),{type:`number`,id:`order`,label:i.$t(`Order`),modelValue:e(J).order,"onUpdate:modelValue":o[5]||=t=>e(J).order=t,error:e(J).errors.order},null,8,[`label`,`modelValue`,`error`])]),v(`div`,te,[x(e(a),{json:!0,id:`category_id`,searchable:!1,suggestions:H.parents,modelValue:e(J).category_id,"onUpdate:modelValue":o[6]||=t=>e(J).category_id=t,label:i.$t(`Parent Category`),error:e(J).errors.category_id},null,8,[`suggestions`,`modelValue`,`label`,`error`])]),v(`div`,R,[x(e(t),{id:`title`,max:`50`,label:i.$t(`Title`),modelValue:e(J).title,"onUpdate:modelValue":o[7]||=t=>e(J).title=t,error:e(J).errors.title},null,8,[`label`,`modelValue`,`error`])]),v(`div`,z,[x(e(y),{max:`160`,id:`description`,label:i.$t(`Description`),modelValue:e(J).description,"onUpdate:modelValue":o[8]||=t=>e(J).description=t,error:e(J).errors.description},null,8,[`label`,`modelValue`,`error`])]),v(`div`,B,[x(e(c),{id:`active`,error:e(J).errors.active,checked:e(J).active,"onUpdate:checked":o[9]||=t=>e(J).active=t,label:i.$t(`Active`)},null,8,[`error`,`checked`,`label`])])]),v(`div`,V,[x(e(w),{onClick:Y},{default:C(()=>[_(l(i.$t(`Cancel`)),1)]),_:1}),x(e(r),{class:`ms-3`,loading:e(J).processing},{default:C(()=>[_(l(i.$t(`Save`)),1)]),_:1},8,[`loading`])])],32))}};export{H as default};