import{r as l,j as e,_ as a}from"./wp-i18n-shim-DUX0OV_V.js";import{S as C,a as w,b as k,c as v,f as S}from"./select-BFNitOb0.js";import{a as y,s as f,u as D}from"./store-rDqSxbzb.js";import{D as _,a as E,b as B,c as I}from"./dialog-EtKUcLIM.js";import"./label-CwRAQd0m.js";import{I as A}from"./input-Dw-69aYW.js";import{B as M}from"./Button-BveKhP38.js";import{P as H}from"./plus-WPVVS3Qe.js";function P({isOpen:r,onOpenChange:c,categoryToEdit:n,onCategorySaved:u}){const[o,x]=l.useState(""),[d,t]=l.useState(!1),[p,i]=l.useState(null),s=!!n,h=y(f);l.useEffect(()=>{r&&(x(s?n.name:""),i(null))},[r,s,n]);const j=async g=>{try{return await h.saveCategory(g)}catch(b){console.error("Error saving category:",b)}},N=async g=>{if(g.preventDefault(),t(!0),i(null),!o.trim()){i(a("Category name cannot be empty.","radius-booking")),t(!1);return}const b={name:o.trim()};try{if(s){const m=await j({...n,...b});u({...n,...m})}else{const m=await j({...b});u({...m,services:[]})}c(!1)}catch(m){i(m.message)}finally{t(!1)}};return e.jsx(_,{open:r,onOpenChange:c,children:e.jsxs(E,{className:"rtrb-terms-add sm:max-w-md p-0 border-none overflow-hidden",children:[e.jsx(B,{className:"bg-light-bg px-[30px] h-[60px] flex justify-center flex-col",children:e.jsx(I,{className:"text-base font-semibold text-title",children:s?a("Edit Category","radius-booking"):a("Add Category","radius-booking")})}),e.jsxs("form",{onSubmit:N,className:"grid gap-4 px-[30px] pb-[30px] dialog-close-btn:bg-red-900",children:[e.jsx("p",{className:"text-title2 text-[14px]",children:s?a("Update the details for this category.","radius-booking"):a("Enter the name for your  category.","radius-booking")}),p&&e.jsx("p",{className:"text-red-500 text-sm",children:p}),e.jsx("div",{className:"flex items-center gap-4",children:e.jsx(A,{placeholder:a("Name","radius-booking"),id:"category-name",value:o,onChange:g=>x(g.target.value),className:"w-full h-[45px] rtrb-input",required:!0})}),e.jsx("div",{className:"",children:e.jsx(M,{type:"submit",className:"h-[45px] px-[40px] shadow-[0px_2px_6px_#9BB1EB;]",disabled:d,children:d?s?a("Saving...","radius-booking"):a("Creating...","radius-booking"):s?a("Save Changes","radius-booking"):a("Create Category","radius-booking")})})]})]})})}const G=({value:r,onChange:c,placeholder:n="Select a category",errors:u})=>{const o=y(f),[x,d]=l.useState(!1);l.useEffect(()=>{o.getAllCategory()},[o]);const t=D(s=>s(f).getAllCategories(),[]),p=s=>{s==="create_new"?d(!0):c(s)},i=s=>{o.getAllCategory(),s!=null&&s.id&&c(s.id.toString())};return e.jsxs(e.Fragment,{children:[e.jsxs(C,{value:r==null?void 0:r.toString(),onValueChange:p,children:[e.jsx(w,{className:`rtrb-input h-11 text-base border-border focus:border-gray-900 focus:ring-1 focus:ring-gray-900 rounded-lg ${u?"border-red-500":"border-border"}`,children:e.jsx(k,{placeholder:n})}),e.jsxs(v,{className:"rounded-lg border shadow-lg",children:[e.jsx(S,{value:"create_new",className:"text-blue-600 font-medium cursor-pointer",children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(H,{className:"w-4 h-4"}),"Create New Category"]})}),(t==null?void 0:t.length)>0&&e.jsx("div",{className:"h-px bg-gray-200 my-1"}),t==null?void 0:t.map(s=>{var h;return e.jsx(S,{value:(h=s.value)==null?void 0:h.toString(),children:s.label},s.value)})]})]}),e.jsx(P,{isOpen:x,onOpenChange:d,categoryToEdit:null,onCategorySaved:i})]})};export{G as C,P as a};
//# sourceMappingURL=CategorySelect-LE4jZ1Fs.js.map
