import{j as n,_ as u}from"./wp-i18n-shim-DUX0OV_V.js";function h(o,s,a){return o?(Array.isArray(o)?o:Object.values(o)).filter(r=>{if(!r||!r.is_active||!(Array.isArray(r.applies_to)&&r.applies_to.length>0?r.applies_to:["service"]).includes(s))return!1;const l=s==="service"?"services":s==="meeting_type"?"meeting_types":"events",e=Array.isArray(r[l])?r[l]:[];return e.length===0?!0:e.map(String).includes(String(a))}):[]}function y(o,s){const a={};return o.forEach(i=>{if(!i.required)return;const r=s==null?void 0:s[i.id];(r==null||String(r).trim()==="")&&(a[i.id]=u("This field is required.","radius-booking"))}),a}function b(o,s){return o.filter(a=>{const i=s==null?void 0:s[a.id];return i!=null&&String(i).trim()!==""}).map(a=>({field_id:a.id,label:a.label,type:a.type,value:s[a.id]}))}function j({fields:o=[],values:s={},onChange:a,errors:i={}}){if(!o.length)return null;const r=e=>s[e]===void 0||s[e]===null?"":s[e],c=(e,t)=>a(e,t),l=e=>`
        w-full px-4 py-3 text-sm border rounded-xl bg-white transition-colors
        focus:outline-none focus:ring-2 focus:ring-[var(--primary)]/20 focus:border-[var(--primary)]
        ${i[e]?"border-red-300":"border-gray-200"}
    `;return n.jsx("div",{className:"space-y-4",children:o.map(e=>n.jsxs("div",{children:[n.jsxs("label",{className:"block text-[11px] font-semibold text-gray-400 uppercase tracking-wider mb-2",children:[e.label," ",e.required&&n.jsx("span",{className:"text-red-500",children:"*"})]}),(e.type==="text"||e.type==="email"||e.type==="number")&&n.jsx("input",{type:e.type,value:r(e.id),onChange:t=>c(e.id,t.target.value),placeholder:e.placeholder||"",className:l(e.id)}),e.type==="textarea"&&n.jsx("textarea",{value:r(e.id),onChange:t=>c(e.id,t.target.value),rows:3,placeholder:e.placeholder||"",className:`${l(e.id)} resize-none`}),e.type==="select"&&n.jsxs("select",{value:r(e.id),onChange:t=>c(e.id,t.target.value),className:l(e.id),children:[n.jsx("option",{value:"",children:e.placeholder||u("Select...","radius-booking")}),(e.options||[]).map(t=>n.jsx("option",{value:t,children:t},t))]}),e.type==="checkbox"&&n.jsx("div",{className:"flex flex-wrap gap-3",children:(e.options||[]).map(t=>{const p=r(e.id)?String(r(e.id)).split("||"):[];return n.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-700 cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:p.includes(t),onChange:d=>{const m=d.target.checked?[...p,t]:p.filter(x=>x!==t);c(e.id,m.join("||"))},className:"w-4 h-4 rounded border-gray-300"}),t]},t)})}),e.type==="date"&&n.jsx("input",{type:"date",value:r(e.id),onChange:t=>c(e.id,t.target.value),className:l(e.id)}),i[e.id]&&n.jsx("p",{className:"mt-1 text-xs text-red-500",children:i[e.id]})]},e.id))})}export{j as C,b,h as f,y as v};
//# sourceMappingURL=CustomFieldsBlock-DnshtruT.js.map
