import{W as N,a as f,j as e}from"./BulkImageUpload-DGPbX05r.js";import{S as h}from"./sweetalert2.all-CGGHY7K6.js";import{I as x}from"./Input-CR3dcIBA.js";import"./bootstrap.esm-e_F80uXB.js";const k=({typ:l,edit:a,mymodel:j})=>{const{data:o,setData:c,post:t,put:v,processing:n,errors:r,clearErrors:m,reset:d}=N({name:"",icon:"",description:""});f.useEffect(()=>{a!=""&&c({name:a.name,description:a.description,_method:"PUT"})},[a]);const p=s=>{c(s.target.name,s.target.type==="checkbox"?s.target.checked:s.target.value),m(s.target.name)},u=s=>{c("icon",s.target.files[0]),m(s.target.name)},g=s=>{s.preventDefault(),l=="add"?t(route("category.store"),{onSuccess:()=>{d(),h.fire("Saved Successfully!","","success")},preserveState:i=>Object.keys(i.props.errors).length}):t(route("category.update",a.id),{onSuccess:()=>{j.hide(),d(),h.fire("Saved Successfully!","","success")},preserveScroll:!0,preserveState:i=>Object.keys(i.props.errors).length})};return e.jsxs("form",{className:"p-4",onSubmit:g,children:[e.jsxs("div",{className:"form-group  row",children:[e.jsxs("div",{className:"col-sm-4",children:[e.jsx("label",{htmlFor:"",children:"Category Name"}),e.jsx("span",{className:"form-indicat",children:":"})]}),e.jsxs("div",{className:"col-sm-8 sticky",children:[e.jsx(x,{type:"text",value:o.name,className:r.name&&"inerror",name:"name",placeholder:"Enter Category Name",handleChange:p}),r.name&&e.jsx("div",{className:"smart-valid",children:r.name})]})]}),e.jsxs("div",{className:"form-group  row",children:[e.jsxs("div",{className:"col-sm-4",children:[e.jsx("label",{htmlFor:"",children:"Category Icon"}),e.jsx("span",{className:"form-indicat",children:":"})]}),e.jsxs("div",{className:"col-sm-8 sticky",children:[e.jsx(x,{type:"file",className:r.icon&&"inerror",name:"icon",handleChange:u}),r.icon&&e.jsx("div",{className:"smart-valid",children:r.icon})]})]}),e.jsxs("div",{className:"form-group  row",children:[e.jsxs("div",{className:"col-sm-4",children:[e.jsx("label",{htmlFor:"",children:"Description"}),e.jsx("span",{className:"form-indicat",children:":"})]}),e.jsxs("div",{className:"col-sm-8 sticky",children:[e.jsx("textarea",{value:o.description,className:`form-control ${r.description&&"inerror"}`,name:"description",placeholder:"Enter Category Description",onChange:p}),r.description&&e.jsx("div",{className:"smart-valid",children:r.description})]})]}),e.jsxs("div",{className:"form-group  row",children:[e.jsx("div",{className:"col-sm-4"}),e.jsx("div",{className:"col-sm-8 sticky",children:l=="edit"?e.jsx("button",{disabled:n,className:"btn btn-primary",children:"Update Category"}):e.jsx("button",{disabled:n,className:"btn btn-primary",children:"Add Category"})})]})]})};export{k as default};
