import{aJ as w,r as a,u as k,j as e,f as g}from"./index-7c7a558c.js";import{B as _}from"./Breadcrumb-21e99ae5.js";import{P as v}from"./PageLoader-31c46f94.js";const U=()=>{const[N,o,S]=w(),[b,l]=a.useState(!1),[C,c]=a.useState(!1),[d,x]=a.useState(null),[E,h]=a.useState(!0),i=k(),[r,u]=a.useState({name:"",category_id:""}),[n,m]=a.useState({}),y=()=>{const t={};return r.name||(t.name="Sub Category Name is required"),r.category_id||(t.category_id="Category Id is required"),t},j=async t=>{t.preventDefault();const s=y();if(Object.keys(s).length===0)try{const p=await g.post(`https://www.bdskilltech.com/backend/public/api/admin/subcategory/${i.upscatid}`,r,{headers:{Authorization:"Bearer "+o}});m({}),l(!0),t.target.reset()}catch(p){c(p.response.data.error)}else m(s)};if(a.useEffect(()=>{o&&(async()=>{try{const s=await g.get(`https://www.bdskilltech.com/backend/public/api/admin/subcategory/${i.upscatid}`,{headers:{Authorization:"Bearer "+o}});x(s.data.data)}catch(s){console.error("Error fetching data:",s)}})(),setTimeout(()=>{c(""),l(!1)},5e3),setTimeout(()=>{h(!1)},500)},[o]),!d)return e.jsx(v,{title:"Update SubCategory"});const{title:z,subcategory:f}=d;return e.jsxs(e.Fragment,{children:[e.jsx(_,{title:"Update SubCategory"}),e.jsx("div",{className:"my-12 h-screen",children:e.jsx("div",{className:"relative overflow-x-auto p-2 bg-gradient-to-r from-main to-second shadow-md border-dashed border rounded-tr-xl rounded-bl-xl",children:e.jsxs("form",{className:"p-5",onSubmit:j,children:[e.jsx("div",{className:"grid md:grid-cols-2 md:gap-6",children:b?e.jsx("h4",{className:"text-green-500 font-bold pb-8",children:"Sub Category Update Successfully."}):""}),e.jsxs("div",{className:"grid md:grid-cols-2 md:gap-6",children:[e.jsxs("div",{className:"relative z-0 w-full mb-12 group",children:[e.jsx("input",{type:"text",onChange:t=>u({...r,name:t.target.value}),defaultValue:r.name?r.name:f.name,name:"floating_first_name",id:"floating_first_name",className:"block py-2.5 px-0 w-full text-sm text-gray-900 bg-transparent border-0 border-b-2 border-gray-300 appearance-none dark:text-white dark:border-gray-600 dark:focus:border-blue-500 focus:outline-none focus:ring-0 focus:border-blue-600",placeholder:" ",required:!0}),e.jsx("label",{htmlFor:"floating_first_name",className:"peer-focus:font-medium absolute text-sm text-gray-500 dark:text-gray-400 duration-300 transform -translate-y-6 scale-75 top-3 -z-10 origin-[0] peer-focus:left-0 peer-focus:text-blue-600 peer-focus:dark:text-blue-500 peer-placeholder-shown:scale-100 peer-placeholder-shown:translate-y-0 peer-focus:scale-75 peer-focus:-translate-y-6",children:"Sub Category Name"}),n.title&&e.jsx("span",{className:"text-red-500",children:n.name})]}),e.jsxs("div",{className:"relative z-0 w-full mb-12 group",children:[e.jsx("input",{type:"text",onChange:t=>u({...r,category_id:t.target.value}),defaultValue:r.category_id?r.category_id:f.category_id,name:"floating_first_name",id:"floating_first_name",className:"block py-2.5 px-0 w-full text-sm text-gray-900 bg-transparent border-0 border-b-2 border-gray-300 appearance-none dark:text-white dark:border-gray-600 dark:focus:border-blue-500 focus:outline-none focus:ring-0 focus:border-blue-600",placeholder:" ",required:!0}),e.jsx("label",{htmlFor:"floating_first_name",className:"peer-focus:font-medium absolute text-sm text-gray-500 dark:text-gray-400 duration-300 transform -translate-y-6 scale-75 top-3 -z-10 origin-[0] peer-focus:left-0 peer-focus:text-blue-600 peer-focus:dark:text-blue-500 peer-placeholder-shown:scale-100 peer-placeholder-shown:translate-y-0 peer-focus:scale-75 peer-focus:-translate-y-6",children:"Category Id"}),n.title&&e.jsx("span",{className:"text-red-500",children:n.name})]})]}),e.jsx("button",{type:"submit",className:"text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800",children:"Update Category"}),e.jsx("br",{}),e.jsx("br",{})]})})})]})};export{U as default};
