@dipusevilla/componentes-iu 1.1.22 → 1.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -88,14 +88,14 @@ attempted value: ${i}
88
88
  self.postMessage({ success: false, error: err.toString() });
89
89
  }
90
90
  };
91
- `,d=new Blob([u],{type:"application/javascript"}),m=URL.createObjectURL(d),f=new Worker(m),h=setTimeout(()=>{f.terminate(),URL.revokeObjectURL(m),c(new Error("Timeout: La validación tardó demasiado."))},o);f.onmessage=p=>{clearTimeout(h),f.terminate(),URL.revokeObjectURL(m),p.data.success?i(p.data.result):(console.warn("Validation Script Error:",p.data.error),i("Error en script de validación"))},f.onerror=p=>{clearTimeout(h),f.terminate(),URL.revokeObjectURL(m),c(p)},f.postMessage({code:e,context:t,translations:l})})}const RM={fileUploader:{browse:"Document",dragDrop:"Drag your files here or click to browse",view:"View",remove:"Remove"},form:{fieldRequired:"Required field",invalidEmail:"Invalid email",submit:"Submit",sending:"Sending…",saveSuccess:"Saved successfully!",saveError:"There are errors in the form"},editor:{inspector:{field:"Field Inspector",tab:"Tab Inspector",section:"Section Inspector"},actions:{move:"Move",moveLeft:"Move left",moveRight:"Move right",add:"Add",addTab:"Tab to the right",addSection:"Add section",addRow:"Add row",addColumn:"Add column",delete:"Delete",deleteTab:"Delete tab",deleteColumn:"Remove last column",duplicate:"Duplicate",cancel:"Cancel"},confirmations:{deleteField:{title:"Delete field",message:"Are you sure you want to delete this field?"},deleteColumn:{title:"Delete column",message:"Are you sure you want to delete the last column? Fields it contains will be lost."},deleteRow:{title:"Delete row",message:"Are you sure you want to delete this row? All fields it contains will be lost."},deleteSection:{title:"Delete section",message:"Are you sure you want to delete this section? All fields it contains will be lost."}},title:"Form Schema Editor",context:"Context:",modes:{design:"Designer",preview:"Preview",code:"Code"},codeViewer:{copy:"Copy code",copied:"Copied",lines:"lines",format:"Format"},toolbar:{export:"Export",import:"Import JSON",shortcuts:"Shortcuts",showRelations:"Show relations",hideRelations:"Hide relations",toggleSidePanel:{open:"Open side panel",close:"Close side panel"}},importModal:{trigger:"Generate from object",triggerTitle:"Generate form from JSON or TypeScript",title:"Generate from JSON or TypeScript",labels:{formTitle:"Form Title",formId:"Form ID",layout:"Layout (cols)",input:"Input (paste JSON or TypeScript interface/type)"},placeholders:{layout:{auto:"Auto",col1:"1 column",col2:"2 columns",col3:"3 columns",col4:"4 columns"}},actions:{cancel:"Cancel",generate:"Generate Form",generating:"Generating..."},messages:{success:"Form generated successfully.",error:"Could not generate form."}}},fields:{defaults:{text:{label:"Text",placeholder:"Type…"},number:{label:"Number",placeholder:"0"},email:{label:"Email",placeholder:"user@domain.com"},password:{label:"Password",placeholder:"••••••••"},tel:{label:"Phone",placeholder:"600 000 000"},url:{label:"URL",placeholder:"https://example.com"},textarea:{label:"Comment",placeholder:"Write your comment…"},select:{label:"Select",placeholder:"Select an option"},checkbox:{label:"Checkbox"},date:{label:"Date"},file:{label:"File"},search:{label:"Search",placeholder:"Search..."}},validation:{required:"Required field",invalidEmail:"Invalid email",invalidUrl:"Invalid URL",invalidPhone:"Invalid phone",invalidID:"Invalid identity document",invalidIBAN:"Invalid IBAN",minLength:"Minimum {{count}} characters",maxLength:"Maximum {{count}} characters",pattern:"Invalid format",numberMin:"Must be greater than or equal to {{min}}",numberMax:"Must be less than or equal to {{max}}",step:"Must be a multiple of {{step}}",integerOnly:"Must be an integer",positiveOnly:"Must be a positive number",selectMin:"Select at least {{count}} options",selectMax:"Select at most {{count}} options",dateMin:"Date must be after {{date}}",dateMax:"Date must be before {{date}}",disallowPast:"Past dates are not allowed",disallowFuture:"Future dates are not allowed",number:"Must be a number",date:"Invalid date",invalidOption:"Invalid option",mustCheck:"You must check this box",invalidFile:"Invalid file",invalidFileType:"File type not allowed",fileMaxCount:"Max. {{count}} file(s)",fileMaxSize:"File must not exceed {{size}}MB",minItems:"Minimum {{count}} items",maxItems:"Maximum {{count}} items"}}},CM={ds:RM},SM={fileUploader:{browse:"Documento",dragDrop:"Arrastra tus archivos aquí o haz clic para buscarlos",view:"Ver",remove:"Eliminar"},form:{fieldRequired:"Campo obligatorio",invalidEmail:"Email inválido",submit:"Enviar",sending:"Enviando…",saveSuccess:"¡Guardado con éxito!",saveError:"Hay errores en el formulario"},editor:{inspector:{field:"Inspector de campo",tab:"Inspector de pestaña",section:"Inspector de sección"},actions:{move:"Mover",moveLeft:"Mover a la izquierda",moveRight:"Mover a la derecha",add:"Añadir",addTab:"Pestaña a la derecha",addSection:"Añadir sección",addRow:"Añadir fila",addColumn:"Añadir columna",delete:"Eliminar",deleteTab:"Eliminar pestaña",deleteColumn:"Quitar última columna",duplicate:"Duplicar",cancel:"Cancelar"},confirmations:{deleteField:{title:"Eliminar campo",message:"¿Estás seguro de que quieres eliminar este campo?"},deleteColumn:{title:"Eliminar columna",message:"¿Estás seguro de que quieres eliminar la última columna? Se perderán los campos que contiene."},deleteRow:{title:"Eliminar fila",message:"¿Estás seguro de que quieres eliminar esta fila? Se perderán todos los campos que contiene."},deleteSection:{title:"Eliminar sección",message:"¿Estás seguro de que quieres eliminar esta sección? Se perderán todos los campos que contiene."}},title:"Editor de Esquema de Formulario",context:"Contexto:",modes:{design:"Diseñar",preview:"Vista Previa",code:"Código"},codeViewer:{copy:"Copiar código",copied:"Copiado",lines:"líneas",format:"Formato"},toolbar:{export:"Exportar",import:"Importar JSON",shortcuts:"Configurar atajos",showRelations:"Mostrar relaciones",hideRelations:"Ocultar relaciones",toggleSidePanel:{open:"Abrir panel lateral",close:"Cerrar panel lateral"}},importModal:{trigger:"Generar desde objeto",triggerTitle:"Generar formulario desde JSON o TypeScript",title:"Generar desde JSON o TypeScript",labels:{formTitle:"Título del formulario",formId:"ID del formulario",layout:"Distribución (cols)",input:"Entrada (pega JSON o una interface/type de TypeScript)"},placeholders:{layout:{auto:"Auto",col1:"1 columna",col2:"2 columnas",col3:"3 columnas",col4:"4 columnas"}},actions:{cancel:"Cancelar",generate:"Generar formulario",generating:"Generando..."},messages:{success:"Formulario generado correctamente.",error:"No se pudo generar el formulario."}}},fields:{defaults:{text:{label:"Texto",placeholder:"Escribe…"},number:{label:"Número",placeholder:"0"},email:{label:"Email",placeholder:"usuario@dominio.com"},password:{label:"Contraseña",placeholder:"••••••••"},tel:{label:"Teléfono",placeholder:"600 000 000"},url:{label:"URL",placeholder:"https://ejemplo.com"},textarea:{label:"Comentario",placeholder:"Escribe tu comentario…"},select:{label:"Seleccionar",placeholder:"Seleccione una opción"},checkbox:{label:"Casilla"},date:{label:"Fecha"},file:{label:"Archivo"},search:{label:"Búsqueda",placeholder:"Buscar..."}},validation:{required:"Campo obligatorio",invalidEmail:"Email inválido",invalidUrl:"URL inválida",invalidPhone:"Teléfono inválido",invalidID:"Documento de identidad inválido",invalidIBAN:"IBAN inválido",minLength:"Mínimo {{count}} caracteres",maxLength:"Máximo {{count}} caracteres",pattern:"Formato inválido",numberMin:"Debe ser mayor o igual a {{min}}",numberMax:"Debe ser menor o igual a {{max}}",step:"Debe ser múltiplo de {{step}}",integerOnly:"Debe ser un número entero",positiveOnly:"Debe ser un número positivo",selectMin:"Selecciona al menos {{count}} opciones",selectMax:"Selecciona como máximo {{count}} opciones",dateMin:"La fecha debe ser posterior a {{date}}",dateMax:"La fecha debe ser anterior a {{date}}",disallowPast:"No se permiten fechas pasadas",disallowFuture:"No se permiten fechas futuras",number:"Debe ser un número",date:"Fecha inválida",invalidOption:"Opción inválida",mustCheck:"Debes marcar esta casilla",invalidFile:"Archivo inválido",invalidFileType:"Tipo de archivo no permitido",fileMaxCount:"Máx. {{count}} fichero(s)",fileMaxSize:"El archivo no debe superar {{size}}MB",minItems:"Mínimo {{count}} elementos",maxItems:"Máximo {{count}} elementos"}}},NM={ds:SM};We.use(RA).init({resources:{en:{translation:CM},es:{translation:NM}},lng:"es",fallbackLng:"es",interpolation:{escapeValue:!1}});const AM=e=>{We.changeLanguage(e)},W5="TRWAGMYFPDXBNJZSQVHLCKE",MM=["X","Y","Z"];function OM(e){if(!/^\d{8}[A-Z]$/.test(e))return!1;const t=parseInt(e.substring(0,8),10),r=e.charAt(8),n=W5.charAt(t%23);return r===n}function LM(e){if(!/^[XYZ]\d{7}[A-Z]$/.test(e))return!1;const t=e.charAt(0),n=MM.indexOf(t).toString()+e.substring(1),o=parseInt(n.substring(0,8),10),l=e.charAt(8),i=W5.charAt(o%23);return l===i}function $M(e){if(!/^[A-Z]\d{7}[A-Z0-9]$/.test(e))return!1;const t=e.charAt(0),r=e.substring(1,8),n=e.charAt(8);let o=0;for(let m=0;m<7;m++){const f=parseInt(r.charAt(m),10);if(m%2===0){const h=f*2;o+=Math.floor(h/10)+h%10}else o+=f}const l=o%10,i=l===0?0:10-l,c="JABCDEFGHI".charAt(i);return["A","B","E","H"].includes(t)?n===i.toString():n===c||n===i.toString()}function IM(e){if(!e||e.length<9)return!1;const t=e.toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"");return/^\d{8}[A-Z]$/.test(t)?OM(t):/^[XYZ]\d{7}[A-Z]$/.test(t)?LM(t):/^[A-Z]\d{7}[A-Z0-9]$/.test(t)?$M(t):!1}const FM=/^\s*(?:\+?\d{1,4}[\s-]*)?(?:\(?\d{2,4}\)?[\s-]*)?\d{3,4}[\s-]?\d{3,4}\s*$/;function U5(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"")}function _M(e){const t=U5(e);if(t.length<15||t.length>34||!/^[A-Z]{2}\d{2}[A-Z0-9]+$/.test(t))return!1;const r=t.slice(4)+t.slice(0,4);let n=0;for(const o of r){const l=o.charCodeAt(0);if(l>=65&&l<=90){const i=String(l-55);for(let c=0;c<i.length;c++)n=(n*10+(i.charCodeAt(c)-48))%97}else n=(n*10+(o.charCodeAt(0)-48))%97}return n===1}function TM(e){return e.validation??{}}function BM(e){return!!e.multiple}function ZM(e){const t=e.maxFiles;return typeof t=="number"?t:void 0}function VM(e){const t=e.options;return Array.isArray(t)?t.map(r=>r==null?void 0:r.value).filter(r=>r!==void 0):[]}function DM(e){if(!e)return{exts:[],mimes:[]};const t=e.split(",").map(o=>o.trim().toLowerCase()).filter(Boolean),r=[],n=[];for(const o of t)o.startsWith(".")?r.push(o):o.includes("/")&&n.push(o);return{exts:r,mimes:n}}function ct(e,t){const r=typeof e=="string"?e:t;return We.isInitialized&&(r.startsWith("forms.")||r.startsWith("ds."))?We.t(r):r}function Pt(e,t){let r=e;return t.required&&(r=r.required(ct(t.requiredMessage||(typeof t.required=="string"?t.required:void 0),"ds.fields.validation.required"))),t.customFn&&(r=r.test({name:"custom-script-validation",message:"${path} no es válido",test:async function(n,o){if(n==null||n==="")return!0;const l=o.parent;let i={};try{if(We.isInitialized){const c=We.getResourceBundle(We.language,"translation")||{},u=(d,m="")=>{for(const f of Object.keys(d)){const h=m?`${m}.${f}`:f,p=d[f];typeof p=="string"?i[h]=p:typeof p=="object"&&p!==null&&u(p,h)}};u(c)}}catch(c){console.warn("Error extracting translations for validation:",c)}try{const c=await H5(t.customFn,{value:n,form:l,customMessages:t.customMessages||{}},{translations:i});if(c===!0)return!0;if(typeof c=="string"){const u=We.isInitialized&&c.startsWith("forms.")?We.t(c):c;return this.createError({message:u})}return!1}catch(c){return console.error("Custom Validation Error",c),this.createError({message:"Error ejecutando validación: "+String(c)})}}})),r}function Pr(e,t){var n,o,l;let r=e;return((n=t.minLength)==null?void 0:n.value)!=null&&(r=r.min(t.minLength.value,ct(t.minLength.message,"ds.fields.validation.minLength"))),((o=t.maxLength)==null?void 0:o.value)!=null&&(r=r.max(t.maxLength.value,ct(t.maxLength.message,"ds.fields.validation.maxLength"))),((l=t.pattern)==null?void 0:l.value)instanceof RegExp&&(r=r.matches(t.pattern.value,ct(t.pattern.message,"ds.fields.validation.pattern"))),r}function PM(e,t){var n,o,l,i;let r=e;if(((n=t.numberMin)==null?void 0:n.value)!=null&&(r=r.min(t.numberMin.value,ct(t.numberMin.message,"ds.fields.validation.numberMin"))),((o=t.numberMax)==null?void 0:o.value)!=null&&(r=r.max(t.numberMax.value,ct(t.numberMax.message,"ds.fields.validation.numberMax"))),t.positiveOnly&&(r=r.moreThan(0,ct(t.positiveOnly,"ds.fields.validation.positiveOnly"))),t.integerOnly&&(r=r.integer(ct(t.integerOnly,"ds.fields.validation.integerOnly"))),((l=t.step)==null?void 0:l.value)!=null){const c=Number(t.step.value),u=t.step.message||"ds.fields.validation.step";r=r.test("step",u,d=>{if(d==null||Number.isNaN(d)||c===0)return!0;const m=d/c;return Math.abs(m-Math.round(m))<1e-9})}return((i=t.pattern)==null?void 0:i.value)instanceof RegExp&&(r=r.test("pattern-number",t.pattern.message||"ds.fields.validation.pattern",c=>c==null||t.pattern.value.test(String(c)))),r}function zM(e,t){var n,o;let r=e;return(n=t.dateMin)!=null&&n.value&&(r=r.min(new Date(t.dateMin.value),ct(t.dateMin.message,"ds.fields.validation.dateMin"))),(o=t.dateMax)!=null&&o.value&&(r=r.max(new Date(t.dateMax.value),ct(t.dateMax.message,"ds.fields.validation.dateMax"))),t.disallowPast&&(r=r.min(new Date,ct(t.disallowPast,"ds.fields.validation.disallowPast"))),t.disallowFuture&&(r=r.max(new Date,ct(t.disallowFuture,"ds.fields.validation.disallowFuture"))),r}function HM(e){var r,n,o,l;const t=TM(e);switch(e.type){case"text":case"password":case"textarea":case"search":{let i=Cr().trim();return i=Pr(i,t),Pt(i,t)}case"dni":{let i=Cr().trim();return i=Pr(i,t),i=i.test("dni-valid",ct("ds.fields.validation.invalidID","Documento de identidad inválido"),c=>c==null||c===""?!0:IM(c)),Pt(i,t)}case"email":{let i=Cr().trim().email(ct(t.emailMessage,"ds.fields.validation.invalidEmail"));return i=Pr(i,t),Pt(i,t)}case"url":{let i=Cr().trim().url(ct(t.urlMessage,"ds.fields.validation.invalidUrl"));return i=Pr(i,t),Pt(i,t)}case"tel":{let i=Cr().trim();return i=Pr(i,t),(r=t.pattern)!=null&&r.value||(i=i.matches(FM,ct(t.phoneMessage,"ds.fields.validation.invalidPhone"))),Pt(i,t)}case"iban":{let i=Cr().transform((c,u)=>u===""||u===null||u===void 0?"":typeof u=="string"?U5(u):c);return i=Pr(i,t),i=i.test("iban-valid",ct("ds.fields.validation.invalidIBAN","IBAN inválido"),c=>c==null||c===""?!0:_M(String(c))),Pt(i,t)}case"number":{let i=T5().transform((c,u)=>{if(u===""||u===null||u===void 0)return;const d=typeof u=="string"?Number(u.replace(",",".")):c;return Number.isNaN(d)?NaN:d}).typeError(ct(t.typeError,"ds.fields.validation.number"));return i=PM(i,t),Pt(i,t)}case"date":{let i=yi().nullable().typeError(ct(t.typeError,"ds.fields.validation.date")).transform((c,u)=>u?new Date(u):null);return i=zM(i,t),Pt(i,t)}case"select":case"optionGroup":{const i=BM(e),c=VM(e);if(i){let u=Cl().of(c.length?Jn().oneOf(c,"ds.fields.validation.invalidOption"):Jn());return t.required&&(u=u.min(1,t.requiredMessage||(typeof t.required=="string"?t.required:"ds.fields.validation.required"))),u}else{let u=Cr().trim();return u=Pr(u,t),c.length&&(u=u.oneOf(c,"ds.fields.validation.invalidOption")),Pt(u,t)}}case"checkbox":{let i=I5();return t.required&&(i=i.oneOf([!0],t.requiredMessage||"ds.fields.validation.mustCheck")),i}case"file":{const i=e,{exts:c,mimes:u}=DM(i.accept),d=ZM(e);let m=Jn().test("file-shape","ds.fields.validation.invalidFile",f=>(f==null,!0));if((n=t.fileMaxSizeMB)!=null&&n.value){const f=Number(t.fileMaxSizeMB.value)*1024*1024,h=t.fileMaxSizeMB.message||"ds.fields.validation.fileMaxSize";m=m.test("file-max-size",h,p=>p?(Array.isArray(p)?p:typeof FileList<"u"&&p instanceof FileList?Array.from(p):[p].filter(Boolean)).every(v=>typeof(v==null?void 0:v.size)!="number"||v.size<=f):!0)}return(c.length||u.length)&&(m=m.test("file-accept","ds.fields.validation.invalidFileType",f=>f?(Array.isArray(f)?f:typeof FileList<"u"&&f instanceof FileList?Array.from(f):[f].filter(Boolean)).every(b=>{var y,E,j,R;const v=((E=(y=b==null?void 0:b.name)==null?void 0:y.toLowerCase)==null?void 0:E.call(y))||"",g=((R=(j=b==null?void 0:b.type)==null?void 0:j.toLowerCase)==null?void 0:R.call(j))||"",x=c.length===0||c.some(A=>v.endsWith(A)),w=u.length===0||u.includes(g);return x&&w}):!0)),typeof d=="number"&&(m=m.test("file-max-files","ds.fields.validation.fileMaxCount",f=>f?(Array.isArray(f)?f:typeof FileList<"u"&&f instanceof FileList?Array.from(f):[f].filter(Boolean)).length<=d:!0)),m=Pt(m,t),m}case"array":{const i=e,c=i.items||[],u=q5(c);let d=Cl().of(ji(u));t.required&&(d=d.min(1,t.requiredMessage||(typeof t.required=="string"?t.required:"ds.fields.validation.required")));const m=i.validation;return(o=m==null?void 0:m.min)!=null&&o.value&&(d=d.min(m.min.value,m.min.message||"ds.fields.validation.minItems")),(l=m==null?void 0:m.max)!=null&&l.value&&(d=d.max(m.max.value,m.max.message||"ds.fields.validation.maxItems")),d}default:{const i=Jn();return Pt(i,t)}}}function q5(e){const t={};for(const r of e){const n=r;n!=null&&n.name&&(t[n.name]=HM(n))}return t}function ki(e){const t=q5(e.fields);return ji(t)}const Yc=e=>{let t;const r=new Set,n=(d,m)=>{const f=typeof d=="function"?d(t):d;if(!Object.is(f,t)){const h=t;t=m??(typeof f!="object"||f===null)?f:Object.assign({},t,f),r.forEach(p=>p(t,h))}},o=()=>t,c={setState:n,getState:o,getInitialState:()=>u,subscribe:d=>(r.add(d),()=>r.delete(d))},u=t=e(n,o,c);return c},WM=(e=>e?Yc(e):Yc),UM=e=>e;function qM(e,t=UM){const r=k.useSyncExternalStore(e.subscribe,k.useCallback(()=>t(e.getState()),[e,t]),k.useCallback(()=>t(e.getInitialState()),[e,t]));return k.useDebugValue(r),r}const Xc=e=>{const t=WM(e),r=n=>qM(t,n);return Object.assign(r,t),r},G5=(e=>e?Xc(e):Xc),Jr=G5(e=>({isActive:!1,formValues:{},systemContext:{},setRuntimeState:t=>e(r=>({...r,...t})),reset:()=>e({isActive:!1,formValues:{},systemContext:{}})}));function Sl(e,t){return e?typeof e!="string"?String(e):e.replace(/\{\{([^}]+)\}\}/g,(r,n)=>{let l=n.trim().split(".").reduce((i,c)=>{if(!i)return;if(i[c]!==void 0)return i[c];const u=c.toLowerCase(),d=Object.keys(i).find(m=>m.toLowerCase()===u);return d?i[d]:void 0},t);return l!=null?String(l):r}):""}function xr({options:e,value:t,onChange:r,children:n,className:o,contentClassName:l}){const i=k.useRef(null),[c,u]=k.useState({left:0,width:0}),[d,m]=k.useState(!1),[f,h]=k.useState(!1),p=()=>{if(i.current){const{scrollLeft:v,scrollWidth:g,clientWidth:x}=i.current;m(v>0),h(v<g-x-1)}};k.useLayoutEffect(()=>{const v=i.current;if(!v)return;const g=()=>{const x=v.querySelector(`[data-value="${t}"]`);x&&u({left:x.offsetLeft,width:x.offsetWidth})};return g(),p(),window.addEventListener("resize",g),window.addEventListener("resize",p),()=>{window.removeEventListener("resize",g),window.removeEventListener("resize",p)}},[t,e]);const b=v=>{i.current&&i.current.scrollBy({left:v==="left"?-200:200,behavior:"smooth"})};return s.jsxs("div",{className:o,children:[s.jsxs("div",{className:"relative border-b border-[var(--color-ds-border-default-50)] group",children:[d&&s.jsx("div",{className:"absolute left-0 top-0 bottom-0 z-20 flex items-center bg-gradient-to-r from-[var(--color-ds-background-page)] to-transparent pr-4 pl-1 opacity-0 group-hover:opacity-100 transition-opacity duration-200",children:s.jsx("button",{type:"button",onClick:()=>b("left"),className:"p-1 rounded-full bg-[var(--color-ds-background-surface)] shadow-sm border border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-button-hover-bg)] hover:text-white transition-colors",children:s.jsx(Od,{className:"w-4 h-4"})})}),s.jsx("div",{ref:i,onScroll:p,className:"overflow-x-auto scrollbar-hidden flex items-center w-full relative",style:{scrollBehavior:"smooth"},children:s.jsxs("div",{className:"relative flex min-w-full px-1",children:[e.map(v=>{const g=v.value===t;return s.jsxs("button",{"data-value":v.value,role:"tab","aria-selected":g,onClick:()=>!v.disabled&&r(v.value),type:"button",className:ge("relative z-10 whitespace-nowrap px-4 py-2 transition-colors duration-150 ease-in-out font-medium text-sm focus:outline-none",g?"text-[var(--color-ds-background-accent)]":"text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)]",v.disabled&&"opacity-50 cursor-not-allowed"),disabled:v.disabled,children:[v.icon&&s.jsx("span",{className:"mr-2 -ml-1 inline-block align-text-bottom",children:v.icon}),v.label]},v.value)}),s.jsx("span",{className:"absolute bottom-0 h-0.5 bg-[var(--color-ds-background-accent)] transition-all duration-200 ease-in-out z-20",style:{left:c.left,width:c.width}})]})}),f&&s.jsx("div",{className:"absolute right-0 top-0 bottom-0 z-20 flex items-center bg-gradient-to-l from-[var(--color-ds-background-page)] to-transparent pl-4 pr-1 opacity-0 group-hover:opacity-100 transition-opacity duration-200",children:s.jsx("button",{type:"button",onClick:()=>b("right"),className:"p-1 rounded-full bg-[var(--color-ds-background-surface)] shadow-sm border border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-button-hover-bg)] hover:text-white transition-colors",children:s.jsx(Ho,{className:"w-4 h-4"})})})]}),s.jsx("div",{className:ge("mt-4",l),children:n[t]})]})}const cn={sm:"text-ds-sm",md:"text-ds-md",lg:"text-ds-lg"},qa={sm:"h-5",md:"h-10",lg:"h-12"},Ga={sm:"px-2",md:"px-2.5",lg:"px-3"},Ka={sm:"1.5rem",md:"2.5rem",lg:"3rem"},Ja={sm:"pr-9",md:"pr-11",lg:"pr-12"},GM={sm:"h-6 w-6",md:"h-8 w-8",lg:"h-10 w-10"};function Ya({id:e,size:t,disabled:r,error:n,reserveErrorSpace:o,className:l,suffixButton:i,children:c,showDropdownIndicator:u}){var d;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:ge("relative w-full",l),children:[c,u&&!i&&s.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-2 flex items-center",children:s.jsx(Kt,{className:"h-4 w-4 text-[var(--color-ds-text-secondary)]"})}),i&&s.jsx("div",{className:"pointer-events-none absolute flex items-center",style:{top:2,bottom:2,right:4},children:s.jsx("div",{className:"pointer-events-auto",children:k.isValidElement(i)?k.cloneElement(i,{className:ge(GM[t],(d=i.props)==null?void 0:d.className)}):i})})]}),o?s.jsx("div",{className:"h-[1em]",children:n!=null&&n.message?s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:n.message}):s.jsx("span",{"aria-hidden":"true",children:" "})}):n!=null&&n.message?s.jsx("div",{className:"pt-1",children:s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:n.message})}):null]})}function Qc(e,t){k.useEffect(()=>{const r=n=>{e.current&&(e.current.contains(n.target)||t())};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[t,e])}function Ge(e){const{control:t,name:r,rules:n,defaultValue:o,options:l=[],loadOptions:i,reloadDeps:c=[],value:u,onChange:d,size:m="sm",width:f="100%",label:h,labelHidden:p=!1,info:b,infoHeader:v,hasError:g=!1,errorMessage:x="",reserveErrorSpace:w,disableErrorPlaceholder:y,disabled:E=!1,className:j,suffixButton:R,loading:A=!1,coerceFirstValid:S=!0,mode:O="menu",renderTrigger:_,renderOption:V,popupWidth:$,triggerClassName:D,onBlur:M,searchable:z=!1,searchPlaceholder:te="Buscar...",noOptionsText:Q="No se encontraron resultados"}=e,ne=k.useId(),ae=r||ne,[K,N]=k.useState(l),[I,re]=k.useState(!!i);k.useEffect(()=>{if(!i){N(l);return}re(!0),i().then(ve=>N(ve)).finally(()=>re(!1))},[i,...c]),k.useEffect(()=>{i||N(l)},[l,i]);const G=ve=>ve.find(ue=>ue.value!==""&&ue.value!==void 0)??ve[0],X=(ve,ue)=>{const xe=ue.trim().toLowerCase();return xe?ve.filter(C=>String(C.label).toLowerCase().includes(xe)||String(C.value).toLowerCase().includes(xe)):ve},fe=typeof w=="boolean"?w:!!t,le=f&&(f.includes(" ")||f.startsWith("w-")||f.startsWith("max-w-")||f.startsWith("min-w-")),he=le?{maxWidth:"100%"}:{width:f,maxWidth:"100%"},ce=ge("flex flex-col",le&&f,j);if(t&&r){const{field:ve,fieldState:ue}=d5({name:r,control:t,rules:n,defaultValue:o});k.useEffect(()=>{if(!I&&K.length>0&&S){const C=ve.value,q=K.some(ee=>String(ee.value)===String(C));(C===void 0||!q)&&ve.onChange(G(K).value)}},[K,I,ve,S]);const xe=h&&!p&&s.jsx(Gt,{id:ae,text:h,size:m,info:b,infoHeader:v});if((O??"native")==="menu"){const[C,q]=k.useState(!1),[ee,W]=k.useState(""),H=k.useRef(null);Qc(H,()=>{q(!1),W("")});const Y=K.find(Z=>String(Z.value)===String(ve.value)),L=z?X(K,ee):K;return s.jsxs("div",{className:ce,style:he,children:[xe,A||I?s.jsx(pr,{width:"100%",height:Ka[m],variant:"rect",className:"rounded-lg"}):s.jsx(Ya,{id:ae,size:m,disabled:E,error:ue.error,reserveErrorSpace:typeof y=="boolean"?!y:fe,className:j,suffixButton:R,showDropdownIndicator:!0,children:s.jsxs("div",{className:"relative w-full",ref:H,children:[s.jsx("button",{type:"button",onClick:()=>{E||q(Z=>{const F=!Z;return F||W(""),F})},onBlur:()=>{ve.onBlur(),M==null||M()},className:ge("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none text-left flex items-center",cn[m],qa[m],Ga[m],R&&Ja[m],ue.error?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)] hover:border-[var(--color-ds-border-default-hover)]",D),"aria-haspopup":"listbox","aria-expanded":C,children:_?_(Y):(Y==null?void 0:Y.label)??"—"}),C&&s.jsxs("div",{role:"listbox",className:"custom-scroll absolute z-50 mt-1 rounded-xl border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-page)] shadow-xl p-1 max-h-72 overflow-auto",style:{width:$??"100%"},children:[z&&s.jsx("div",{className:"sticky top-0 z-10 bg-[var(--color-ds-background-page)] p-1",children:s.jsx("input",{type:"text",value:ee,onChange:Z=>W(Z.target.value),onClick:Z=>Z.stopPropagation(),placeholder:te,className:"w-full rounded-lg border border-[var(--color-ds-border-default)] bg-[var(--color-ds-background-page)] px-2 py-2 text-sm outline-none"})}),L.length>0?L.map(Z=>{const F=String(Z.value)===String(ve.value);return s.jsx("button",{role:"option","aria-selected":F,type:"button",onClick:()=>{ve.onChange(Z.value),q(!1),W("")},className:ge("w-full rounded-lg px-2 py-1.5 text-left transition-all duration-200",cn[m],F?"bg-[var(--color-ds-background-neutral)] font-medium text-[var(--color-ds-text-primary)]":"text-[var(--color-ds-text-secondary)] hover:bg-[var(--color-ds-background-neutral-hover)] hover:text-[var(--color-ds-text-primary)] hover:pl-3"),children:V?V(Z,F):Z.label},Z.value)}):s.jsx("div",{className:"px-2 py-2 text-sm text-[var(--color-ds-text-secondary)]",children:Q})]})]})})]})}return s.jsxs("div",{className:ce,style:he,children:[xe,A||I?s.jsx(pr,{width:"100%",height:Ka[m],variant:"rect",className:"rounded-lg"}):s.jsx(Ya,{id:ae,size:m,disabled:E,error:ue.error,reserveErrorSpace:typeof y=="boolean"?!y:fe,className:j,suffixButton:R,showDropdownIndicator:!0,children:s.jsx("select",{id:ae,value:ve.value,onChange:C=>ve.onChange(C.target.value),onBlur:()=>{ve.onBlur(),M==null||M()},disabled:E,className:ge("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none leading-none",cn[m],qa[m],Ga[m],R&&Ja[m],ue.error?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)]",D),children:K.map(C=>s.jsx("option",{value:C.value,className:"bg-[var(--color-ds-background-page)] text-[var(--color-ds-text-primary)]",children:C.label},C.value))})})]})}k.useEffect(()=>{if(!t&&K.length>0&&S){const ve=K.some(xe=>String(xe.value)===String(u));(u===void 0||u===""||!ve)&&d&&d(G(K).value)}},[K,u,d,t,S]);const ie=h&&!p&&s.jsx(Gt,{id:ae,text:h,size:m,info:b,infoHeader:v});if((O??"native")==="menu"){const[ve,ue]=k.useState(!1),[xe,C]=k.useState(""),q=k.useRef(null);Qc(q,()=>{ue(!1),C("")});const ee=K.find(H=>String(H.value)===String(u)),W=z?X(K,xe):K;return s.jsxs("div",{className:ce,style:he,children:[ie,A||I?s.jsx(pr,{width:"100%",height:Ka[m],variant:"rect",className:"rounded-lg"}):s.jsx(Ya,{id:ae,size:m,disabled:E,error:g?{message:x}:void 0,reserveErrorSpace:typeof y=="boolean"?!y:!!(w??!1),className:j,suffixButton:R,showDropdownIndicator:!0,children:s.jsxs("div",{className:"relative w-full",ref:q,children:[s.jsx("button",{type:"button",onClick:()=>{E||ue(H=>{const Y=!H;return Y||C(""),Y})},onBlur:M,className:ge("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none text-left flex items-center",cn[m],qa[m],Ga[m],R&&Ja[m],g?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)] hover:border-[var(--color-ds-border-default-hover)]",D),"aria-haspopup":"listbox","aria-expanded":ve,children:_?_(ee):(ee==null?void 0:ee.label)??"—"}),ve&&s.jsxs("div",{role:"listbox",className:"custom-scroll absolute z-50 mt-1 rounded-xl border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-page)] shadow-xl p-1 max-h-72 overflow-auto",style:{width:$??"100%"},children:[z&&s.jsx("div",{className:"sticky top-0 z-10 bg-[var(--color-ds-background-page)] p-1",children:s.jsx("input",{type:"text",value:xe,onChange:H=>C(H.target.value),onClick:H=>H.stopPropagation(),placeholder:te,className:"w-full rounded-lg border border-[var(--color-ds-border-default)] bg-[var(--color-ds-background-page)] px-2 py-2 text-sm outline-none"})}),W.length>0?W.map(H=>{const Y=String(H.value)===String(u);return s.jsx("button",{role:"option","aria-selected":Y,type:"button",onClick:()=>{d==null||d(H.value),ue(!1),C("")},className:ge("w-full rounded-lg px-2 py-1.5 text-left transition-all duration-200",cn[m],Y?"bg-[var(--color-ds-background-neutral)] font-medium text-[var(--color-ds-text-primary)]":"text-[var(--color-ds-text-secondary)] hover:bg-[var(--color-ds-background-neutral-hover)] hover:text-[var(--color-ds-text-primary)] hover:pl-3"),children:V?V(H,Y):H.label},H.value)}):s.jsx("div",{className:"px-2 py-2 text-sm text-[var(--color-ds-text-secondary)]",children:Q})]})]})})]})}return s.jsxs("div",{className:ce,style:he,children:[ie,A||I?s.jsx(pr,{width:"100%",height:Ka[m],variant:"rect",className:"rounded-lg"}):s.jsx(Ya,{id:ae,size:m,disabled:E,error:g?{message:x}:void 0,reserveErrorSpace:typeof y=="boolean"?!y:!!(w??!1),className:j,suffixButton:R,showDropdownIndicator:!0,children:s.jsx("select",{id:ae,value:u,onChange:ve=>d==null?void 0:d(ve.target.value),onBlur:M,disabled:E,className:ge("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none leading-none",cn[m],qa[m],Ga[m],R&&Ja[m],g?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)]"),children:K.map(ve=>s.jsx("option",{value:ve.value,className:"bg-[var(--color-ds-background-page)] text-[var(--color-ds-text-primary)]",children:ve.label},ve.value))})})]})}const e0={sm:"text-ds-sm",md:"text-ds-md",lg:"text-ds-lg"};function t0(e){var t;e.preventDefault(),e.stopPropagation(),(t=e.nativeEvent)!=null&&t.stopImmediatePropagation&&e.nativeEvent.stopImmediatePropagation()}function Ei({groupLabel:e,inputs:t=[],separator:r=s.jsx("span",{className:"px-1 select-none",children:"/"}),useSeparator:n=!1,className:o,showVisibleLabel:l=!1,size:i="sm",width:c,respectChildWidths:u=!1}){const d=t.length,m=c&&(c.includes(" ")||c.startsWith("w-")||c.startsWith("max-w-")||c.startsWith("min-w-")),f=m?void 0:c?{width:c}:void 0;return s.jsxs("div",{"data-input-group-root":!0,role:"group",className:ge("flex flex-col w-full",m&&c,o),style:f,onDoubleClick:t0,onDoubleClickCapture:t0,onClickCapture:h=>{var v;const p=h.target;!!((v=p==null?void 0:p.closest)!=null&&v.call(p,'input,select,textarea,button,[data-interactive="true"]'))||h.stopPropagation()},children:[s.jsx("label",{className:ge("sr-only pb-2",e0[i]),children:e}),l&&s.jsx("label",{className:ge("pb-2",e0[i]),children:e}),s.jsx("div",{className:"flex items-stretch flex-nowrap w-full min-w-0",children:t.map((h,p)=>{const{width:b,className:v,options:g,loadOptions:x,info:w,infoHeader:y,...E}=h,j=Array.isArray(g)||typeof x=="function";let R="rounded-lg";!n&&d>1&&(p===0?R="rounded-l-lg rounded-r-none":p===d-1?R="rounded-r-lg rounded-l-none !rounded-l-none":R="rounded-none !rounded-l-none !rounded-r-none");const A=u?b:void 0,S=typeof A=="string"&&A.split(/\s+/).some($=>$.startsWith("w-")||$.includes(":w-")),O=ge("inline-flex items-stretch",A?"flex-shrink-0":"flex-1 min-w-0",typeof A=="string"&&S?A:void 0,!n&&d>1&&p>0?"-ml-px focus-within:z-10 relative":void 0),_=A?typeof A=="string"&&S?void 0:{width:A}:void 0,V=ge(v,"w-full",R);return s.jsxs(k.Fragment,{children:[s.jsx("div",{className:O,style:_,children:j?s.jsx(Ge,{...E,size:i,className:v,triggerClassName:ge("w-full",R),options:g,loadOptions:x,"data-interactive":"true",info:w,infoHeader:y,mode:"menu",searchable:!0,searchPlaceholder:$c("common.search"),noOptionsText:$c("common.noMatches")}):s.jsx(ke,{...E,size:i,className:V,"data-interactive":"true",info:w,infoHeader:y})}),n&&p<d-1&&s.jsx("div",{className:"flex items-center flex-shrink-0 px-1 select-none",children:r})]},p)})})]})}const KM={sm:"w-4 h-4",md:"w-5 h-5",lg:"w-6 h-6"},JM={sm:"w-3 h-3",md:"w-3.5 h-3.5",lg:"w-4 h-4"};function es({groupLabel:e,options:t,control:r,name:n,rules:o,defaultValue:l,multiple:i=!0,size:c="sm",vertical:u=!0,className:d,showVisibleLabel:m=!0,disabled:f=!1,hasError:h=!1,errorMessage:p}){return s.jsx(mt,{name:n,control:r,rules:o,defaultValue:l,render:({field:b,fieldState:v})=>{const{value:g,onChange:x}=b,w=v.error,y=A=>{var S;return i?Array.isArray(g)&&((S=g==null?void 0:g.includes)==null?void 0:S.call(g,A)):g===A},E=A=>{if(!f)if(i){const S=Array.isArray(g)?[...g]:[],O=S.indexOf(A);O>=0?S.splice(O,1):S.push(A),x(S)}else x(A)},j=h||!!w,R=(w==null?void 0:w.message)||p;return s.jsxs("fieldset",{className:ge("w-full flex flex-col gap-1",d),"aria-invalid":j||void 0,disabled:f,children:[e&&s.jsx("legend",{className:ge("mb-1 text-ds-sm text-[var(--color-ds-text-primary)]",!m&&"sr-only"),children:e}),s.jsx("div",{className:ge(u?"flex flex-col gap-2":"flex flex-wrap gap-2"),children:t.map(A=>{const S=y(A.value),O=f||!!(A!=null&&A.disabled),_=ge("inline-flex items-center justify-center border transition-all duration-150",i?"rounded-[6px]":"rounded-full",KM[c],"bg-[var(--color-ds-background-page)]","border-[var(--color-ds-border-default-50)]","shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-default)20%,transparent)]","peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-[var(--color-ds-border-default)]","hover:border-[var(--color-ds-border-default)]",i&&S&&"bg-[var(--color-ds-button-primary-bg)] border-[var(--color-ds-button-primary-bg)]",!i&&S&&"border-[var(--color-ds-button-primary-bg)]",j&&"border-[var(--color-ds-border-error)] shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-error)30%,transparent)]",O&&"opacity-60 cursor-not-allowed"),V=ge("text-ds-sm text-[var(--color-ds-text-primary)]",O&&"text-[var(--color-ds-text-secondary)]"),$=ge(JM[c],"text-[var(--color-ds-button-primary-text)] transition-all duration-150",S?"opacity-100 scale-100":"opacity-0 scale-75"),D=ge(c==="sm"?"w-2 h-2":c==="md"?"w-2.5 h-2.5":"w-3 h-3","rounded-full bg-[var(--color-ds-button-primary-bg)] transition-all duration-150",S?"opacity-100 scale-100":"opacity-0 scale-0");return s.jsxs("label",{className:ge("inline-flex items-center gap-2 cursor-pointer select-none rounded-md px-1 py-1","hover:bg-[color-mix(in_srgb,var(--color-ds-border-default)6%,transparent)]",O&&"cursor-not-allowed hover:bg-transparent"),children:[s.jsxs("span",{className:"relative inline-flex items-center justify-center",children:[s.jsx("input",{type:i?"checkbox":"radio",name:n,value:A.value,checked:S,onChange:()=>E(A.value),disabled:O,className:"peer sr-only"}),s.jsx("span",{"aria-hidden":!0,className:_,children:i?s.jsx(vi,{className:$}):s.jsx("span",{className:D})})]}),s.jsx("span",{className:V,children:A.label})]},String(A.value))})}),j&&!!R&&s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] mt-1",children:R})]})}})}function YM(e){function t(i){var c,u;for(const d of Object.keys(i)){if((c=i[d])!=null&&c.types||(u=i[d])!=null&&u.message)return d;if(typeof i[d]=="object"){const m=t(i[d]);if(m)return`${d}.${m}`}}return null}const r=t(e);if(!r)return;const n=`[name="${r}"]`,o=`[name^="${r}["], [name^="${r}."]`,l=document.querySelector(n)??document.querySelector(o);l&&(l.scrollIntoView({behavior:"smooth",block:"center"}),l.focus({preventScroll:!0}))}const XM={success:"bg-green-100 border-green-500 text-green-800",error:"bg-red-100 border-red-500 text-red-800",info:"bg-blue-100 border-blue-500 text-blue-800",warning:"bg-yellow-100 border-yellow-500 text-yellow-800"},K5=({id:e,message:t,variant:r="info",duration:n=5e3,onClose:o})=>(k.useEffect(()=>{const l=setTimeout(()=>o(e),n);return()=>clearTimeout(l)},[e,n,o]),s.jsxs("div",{className:ge("w-80 max-w-full border-l-4 rounded shadow-md p-4 mb-2 flex justify-between items-start",XM[r]),role:"alert","aria-live":"assertive",children:[s.jsx("span",{className:"flex-1",children:t}),s.jsx("button",{onClick:()=>o(e),className:"ml-4 text-xl font-bold leading-none focus:outline-none",children:"×"})]})),ft=[];for(let e=0;e<256;++e)ft.push((e+256).toString(16).slice(1));function QM(e,t=0){return(ft[e[t+0]]+ft[e[t+1]]+ft[e[t+2]]+ft[e[t+3]]+"-"+ft[e[t+4]]+ft[e[t+5]]+"-"+ft[e[t+6]]+ft[e[t+7]]+"-"+ft[e[t+8]]+ft[e[t+9]]+"-"+ft[e[t+10]]+ft[e[t+11]]+ft[e[t+12]]+ft[e[t+13]]+ft[e[t+14]]+ft[e[t+15]]).toLowerCase()}let Ls;const eO=new Uint8Array(16);function tO(){if(!Ls){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ls=crypto.getRandomValues.bind(crypto)}return Ls(eO)}const rO=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),r0={randomUUID:rO};function nO(e,t,r){var o;e=e||{};const n=e.random??((o=e.rng)==null?void 0:o.call(e))??tO();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,QM(n)}function aO(e,t,r){return r0.randomUUID&&!e?r0.randomUUID():nO(e)}const J5=k.createContext(null),Vr=()=>{const e=k.useContext(J5);if(!e)throw new Error("useToast debe usarse dentro de <ToastProvider>");return e},oO=({children:e})=>{const[t,r]=k.useState([]),n=(l,i="info",c=5e3)=>{const u=aO();r(d=>[...d,{id:u,message:l,variant:i,duration:c}])},o=l=>{r(i=>i.filter(c=>c.id!==l))};return s.jsxs(J5.Provider,{value:{show:n},children:[e,s.jsx("div",{className:"fixed top-4 right-4 z-50 flex flex-col items-end",children:t.map(l=>s.jsx(K5,{id:l.id,message:l.message,variant:l.variant,duration:l.duration,onClose:o},l.id))})]})},sO=e=>e.type==="inputGroup",lO=e=>e.type==="button",iO=e=>!sO(e)&&!lO(e);function Y5(e){const t=Array.isArray(e)?e:[];return k.useMemo(()=>{const r={};for(const n of t)iO(n)&&n.name&&(r[n.name]=n);return r},[t])}const X5=k.createContext(null);function Q5({children:e,value:t}){return s.jsx(X5.Provider,{value:t,children:e})}function At(){const e=k.useContext(X5);if(!e)throw new Error("useAdapters debe usarse dentro de <AdaptersProvider />");return e}const cO=e=>!!e&&typeof e.then=="function";function dO(e){return Array.isArray(e)?e.length>0&&typeof e[0]=="object"&&e[0]!==null?e.map(t=>{var o;if("label"in t&&"value"in t)return t;const n=(o=Object.entries(t)[0])==null?void 0:o[1];return{label:String(n??JSON.stringify(t)),value:String(n??"")}}):e.map(t=>({label:String(t),value:t})):[]}function e1(e){const{services:t}=At(),[r,n]=k.useState({}),[o,l]=k.useState(0),i=k.useRef(!0);k.useEffect(()=>(i.current=!0,()=>{i.current=!1}),[]);const c=k.useMemo(()=>e.filter(u=>u.type==="select"&&!u.options&&typeof u.optionSource=="string"&&u.name),[e]);return k.useEffect(()=>{if(c.length===0)return;let u=!1;return(async()=>{l(d=>d+1);try{const d=await Promise.all(c.map(async m=>{var g;const f=m.name,h=m.optionSource,p=(g=t==null?void 0:t.registry)==null?void 0:g[h];if(!p)return[f,[]];const b=cO(p)?await p:await p(),v=dO(b);return[f,v]}));if(u||!i.current)return;n(m=>{const f={...m};for(const[h,p]of d)f[h]=[...p];return f})}finally{!u&&i.current&&l(d=>Math.max(0,d-1))}})(),()=>{u=!0}},[c,t==null?void 0:t.registry]),{optionsMap:r,loadingCount:o}}const uO=e=>e.type==="inputGroup",fO=e=>e.type==="button",mO=e=>!uO(e)&&!fO(e);function hO(e){return typeof e=="object"&&e!==null}const pO=e=>{const t=e.disabledWhen;if(!hO(t))return!1;const r="watchField"in t,n="rule"in t;return r&&!n};function t1(e,t){const r=Array.isArray(e)?e:[],n=k.useMemo(()=>r.filter(mO).filter(pO),[r]),o=k.useMemo(()=>n.map(u=>u.disabledWhen.watchField),[n]),l=mi({control:t,name:o,compute:u=>u}),i=Array.isArray(l)?l:[],c={};return n.forEach((u,d)=>{const m=i[d];c[u.name??`__unnamed_${d}`]=m===u.disabledWhen.watchValue}),c}const gO={sm:"text-ds-sm",md:"text-ds-sm",lg:"text-ds-sm"},vO={sm:"px-2 py-1.5",md:"px-3 py-2",lg:"px-4 py-3"};function or({control:e,name:t,rules:r,defaultValue:n,size:o="sm",width:l="100%",label:i,labelHidden:c=!1,hasError:u=!1,errorMessage:d="",maxLength:m,showCounter:f=!1,className:h,suffixButton:p,labelPrefixIcon:b,labelSuffixIcon:v,info:g,infoHeader:x,infoAriaLabel:w,prefixIcon:y,suffixIcon:E,reserveErrorSpace:j,disableErrorPlaceholder:R,id:A,...S}){const O=k.useId(),_=A||O,[V,$]=k.useState(String(n??S.value??"")),D=typeof j=="boolean"?j:typeof R=="boolean"?!R:!!e,M=ge("box-border bg-[var(--color-ds-background-page)] w-full rounded-lg border outline-none transition","placeholder-[var(--color-ds-text-secondary)] text-[var(--color-ds-text-primary)]",gO[o],vO[o],u?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",S.disabled&&"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-secondary)] cursor-not-allowed"),z=y?"pl-9":"",te=E?"pr-9":"",Q=N=>{var I;typeof m=="number"&&N.target.value.length>m||($(N.target.value),(I=S.onChange)==null||I.call(S,N))},ne=l&&(l.includes(" ")||l.startsWith("w-")||l.startsWith("max-w-")||l.startsWith("min-w-")),ae=ne?void 0:{width:l},K=ge("flex flex-col",ne&&l,h);return k.useEffect(()=>{n!==void 0&&$(String(n??""))},[n]),e&&t?s.jsx(mt,{name:t,control:e,rules:r,defaultValue:n??"",render:({field:N,fieldState:I})=>{var re;return s.jsxs("div",{className:K,style:ae,children:[!c&&i&&s.jsx(Gt,{id:_,text:i,size:o,prefixIcon:b,suffixIcon:v,info:g,infoHeader:x,infoAriaLabel:w}),s.jsxs("div",{className:"flex items-stretch gap-2",children:[s.jsxs("div",{className:"relative w-full",children:[y&&s.jsx("span",{className:"absolute left-2 top-2.5",children:s.jsx(yt,{component:y,size:o,className:"text-[var(--color-ds-text-secondary)]"})}),s.jsx("textarea",{id:_,"aria-invalid":!!I.error,className:ge(M,z,te),maxLength:m,...N,placeholder:S.disabled?"":S.placeholder,onChange:G=>{N.onChange(G),f&&$(G.target.value)}}),E&&s.jsx("span",{className:"absolute right-2 top-2.5",children:s.jsx(yt,{component:E,size:o,className:"text-[var(--color-ds-text-secondary)]"})})]}),p?s.jsx("div",{className:"shrink-0",children:p}):null]}),s.jsxs("div",{className:"flex justify-between pt-1 h-[1em]",children:[D?I.error?s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:I.error.message}):s.jsx("span",{"aria-hidden":"true",children:" "}):I.error?s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:I.error.message}):s.jsx("span",{"aria-hidden":"true",children:" "}),f&&typeof m=="number"&&s.jsxs("span",{className:"text-xs text-[var(--color-ds-text-secondary)]",children:[((re=N.value)==null?void 0:re.length)??0,"/",m]})]})]})}}):s.jsxs("div",{className:K,style:ae,children:[!c&&i&&s.jsx(Gt,{id:_,text:i,size:o,prefixIcon:b,suffixIcon:v,info:g,infoHeader:x,infoAriaLabel:w}),s.jsxs("div",{className:"flex items-stretch gap-2",children:[s.jsxs("div",{className:"relative w-full",children:[y&&s.jsx("span",{className:"absolute left-2 top-2.5",children:s.jsx(yt,{component:y,size:o,className:"text-[var(--color-ds-text-secondary)]"})}),s.jsx("textarea",{id:_,className:ge(M,z,te),value:V,onChange:Q,maxLength:m,...S,placeholder:S.disabled?"":S.placeholder}),E&&s.jsx("span",{className:"absolute right-2 top-2.5",children:s.jsx(yt,{component:E,size:o,className:"text-[var(--color-ds-text-secondary)]"})})]}),p?s.jsx("div",{className:"shrink-0",children:p}):null]}),s.jsxs("div",{className:"flex justify-between pt-1 h-[1em]",children:[D?u&&d?s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:d}):s.jsx("span",{"aria-hidden":"true",children:" "}):u&&d?s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:d}):s.jsx("span",{"aria-hidden":"true",children:" "}),f&&typeof m=="number"&&s.jsxs("span",{className:"text-xs text-[var(--color-ds-text-secondary)]",children:[V.length,"/",m]})]})]})}const bO={sm:"w-4 h-4",md:"w-5 h-5",lg:"w-6 h-6"},xO={sm:"w-3 h-3",md:"w-3.5 h-3.5",lg:"w-4 h-4"};function tt({control:e=null,name:t,rules:r,defaultValue:n=!1,label:o,labelHidden:l=!1,disabled:i=!1,size:c="sm",className:u,hasError:d=!1,errorMessage:m="",reserveErrorSpace:f,disableErrorPlaceholder:h,checked:p,indeterminate:b,onChange:v}){const g=ge("text-[var(--color-ds-text-primary)] text-ds-sm",i&&"text-[var(--color-ds-text-secondary)]",l&&"sr-only"),x=typeof f=="boolean"?f:typeof h=="boolean"?!h:!!e,w=(y,E,j)=>{const R=d||!!j,A=(j==null?void 0:j.message)||m,S=ge("inline-flex items-center justify-center rounded-[6px] border transition-all duration-150",bO[c],"bg-[var(--color-ds-background-page)]","border-[var(--color-ds-border-default-50)]","shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-default)20%,transparent)]","peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-[var(--color-ds-border-default)]","hover:border-[var(--color-ds-border-default)]",(y||b)&&"bg-[var(--color-ds-button-primary-bg)] border-[var(--color-ds-button-primary-bg)]",R&&"border-[var(--color-ds-border-error)] shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-error)30%,transparent)]",i&&"opacity-60 cursor-not-allowed"),O=ge(xO[c],"text-[var(--color-ds-button-primary-text)]","transition-all duration-150",y||b?"opacity-100 scale-100":"opacity-0 scale-75");return s.jsxs("div",{className:ge("flex flex-col gap-1",u),children:[k.createElement(typeof o=="string"?"label":"div",{className:ge("inline-flex items-center gap-2 cursor-pointer select-none",i&&"cursor-not-allowed")},s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"relative inline-flex items-center justify-center",children:[s.jsx("input",{id:t,type:"checkbox",className:"peer sr-only",checked:y,ref:_=>{_&&(_.indeterminate=!!b)},onChange:_=>E(_.target.checked),disabled:i}),s.jsx("span",{"aria-hidden":!0,className:S,children:b?s.jsx("div",{className:"bg-white h-0.5 w-[60%] rounded-full"}):s.jsx(vi,{className:O})})]}),o&&s.jsx("span",{className:g,children:o})]})),x?s.jsx("div",{className:"h-[1em]",children:R&&A?s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:A}):s.jsx("span",{"aria-hidden":"true",children:" "})}):R&&A?s.jsx("div",{className:"pt-1",children:s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:A})}):null]})};return e?s.jsx(mt,{name:t||"",control:e,rules:r,defaultValue:n,render:({field:y,fieldState:E})=>{const j=E.error;return w(!!y.value,R=>y.onChange(R),j)}}):w(!!p,y=>v==null?void 0:v(y))}function Ri({name:e,control:t,searchFn:r,resolveByValue:n,label:o,size:l="sm",width:i="100%",disabled:c=!1,searchMode:u="button",minChars:d=3,debounceMs:m=600,labelPrefixIcon:f,labelSuffixIcon:h,prefixIcon:p,suffixIcon:b,reserveErrorSpace:v,disableErrorPlaceholder:g}){const x=Tr(),{watch:w,getValues:y,setValue:E}=x,j=mi({control:t,name:e}),[R,A]=k.useState([]),[S,O]=k.useState(!1),[_,V]=k.useState(!1),[$,D]=k.useState(""),M=k.useRef(null),z=k.useRef(null),te=k.useRef(!1),Q=k.useRef(!1),ne=k.useRef(!0),ae=k.useMemo(()=>{const ce=new Map;for(const ie of R)ce.set(String(ie.value).trim(),ie.label??"");return ce},[R]),K=async ce=>{const ie=(ce??"").trim();if(!ie){A([]),V(!1);return}O(!0);try{const ve=await r(ie,{watch:w,getValues:y});A(ve??[]),V(!0)}finally{O(!1)}};k.useEffect(()=>{function ce(ie){M.current&&!M.current.contains(ie.target)&&V(!1)}if(_)return document.addEventListener("mousedown",ce),()=>document.removeEventListener("mousedown",ce)},[_]);const[N,I]=k.useState({});k.useEffect(()=>{if(te.current)return;const ie=(j?String(j):"").trim();if(!ie){$!==""&&D(""),V(!1);return}const ve=ae.get(ie);if(ve){$!==ve&&(D(ve),ne.current=!0);return}const ue=N[ie];if(ue){$!==ue&&(D(ue),ne.current=!0);return}let xe=!1;return n?($!==ie&&D(ie),(async()=>{try{const C=await n(ie,{watch:w,getValues:y});if(xe)return;if(C){const q=C.label??String(C.value);I(ee=>{const W={...ee,[ie]:q};return D(q),ne.current=!0,W})}else $!==ie&&(D(ie),ne.current=!0)}catch{!xe&&$!==ie&&(D(ie),ne.current=!0)}})()):$!==ie&&(D(ie),ne.current=!0),()=>{xe=!0}},[j,ae,N,n,w,y]),k.useEffect(()=>{if(u!=="debounced"||c)return;if(ne.current){ne.current=!1;return}if(!Q.current)return;z.current&&(window.clearTimeout(z.current),z.current=null);const ce=($||"").trim();return ce.length>=d?z.current=window.setTimeout(()=>{K(ce)},m):(A([]),V(!1)),()=>{z.current&&(window.clearTimeout(z.current),z.current=null)}},[$,u,d,m,c]);const re=l==="sm"?"text-ds-sm":l==="md"?"text-ds-md":"text-ds-lg",G=l==="sm"?"h-6":l==="md"?"h-10":"h-12",X=ce=>{if(c)return;const ie=($||"").trim();ce.key==="Enter"&&(ce.preventDefault(),u==="debounced"?ie.length>=d&&K(ie):K(ie)),ce.key==="Escape"&&V(!1)},fe=i&&(i.includes(" ")||i.startsWith("w-")||i.startsWith("max-w-")||i.startsWith("min-w-")),le=fe?void 0:{width:i},he=`relative flex flex-col ${fe?i:""}`;return s.jsx(mt,{name:e,control:t,render:({field:ce,fieldState:ie})=>{var ve;return s.jsxs("div",{ref:M,className:he,style:le,children:[o&&s.jsx(Gt,{id:e,text:o,size:l,prefixIcon:f,suffixIcon:h}),s.jsx(ke,{className:u==="button"?"rounded-r-none":void 0,type:"text",size:l,width:"100%",value:$,prefixIcon:p,suffixIcon:b,onChange:ue=>{const xe=ue.target.value;te.current=!0,Q.current=!0,D(xe),(j?String(j):"").trim()&&E(e,"",{shouldDirty:!0})},onKeyDown:X,onBlur:()=>{te.current=!1},disabled:c,hasError:ie.invalid,errorMessage:(ve=ie.error)==null?void 0:ve.message,reserveErrorSpace:v,disableErrorPlaceholder:g,onFocus:()=>{if(te.current=!0,u==="button"&&Q.current){const ue=($||"").trim();ue&&K(ue)}},suffixButton:u==="button"?s.jsx(me,{type:"button",className:"!rounded-l-none",size:l,variant:"primary",onClick:()=>K(($||"").trim()),disabled:c,children:"Buscar"}):void 0}),S&&s.jsx("div",{className:"absolute top-14 left-0 right-0 z-10",children:s.jsx(pr,{width:"100%",height:l==="sm"?"1.5rem":l==="md"?"2.5rem":"3rem",variant:"rect",className:"rounded-lg"})}),_&&!S&&R.length>0&&s.jsx("ul",{className:`
91
+ `,d=new Blob([u],{type:"application/javascript"}),m=URL.createObjectURL(d),f=new Worker(m),h=setTimeout(()=>{f.terminate(),URL.revokeObjectURL(m),c(new Error("Timeout: La validación tardó demasiado."))},o);f.onmessage=p=>{clearTimeout(h),f.terminate(),URL.revokeObjectURL(m),p.data.success?i(p.data.result):(console.warn("Validation Script Error:",p.data.error),i("Error en script de validación"))},f.onerror=p=>{clearTimeout(h),f.terminate(),URL.revokeObjectURL(m),c(p)},f.postMessage({code:e,context:t,translations:l})})}const RM={fileUploader:{browse:"Document",dragDrop:"Drag your files here or click to browse",view:"View",remove:"Remove"},form:{fieldRequired:"Required field",invalidEmail:"Invalid email",submit:"Submit",sending:"Sending…",saveSuccess:"Saved successfully!",saveError:"There are errors in the form"},editor:{inspector:{field:"Field Inspector",tab:"Tab Inspector",section:"Section Inspector"},actions:{move:"Move",moveLeft:"Move left",moveRight:"Move right",add:"Add",addTab:"Tab to the right",addSection:"Add section",addRow:"Add row",addColumn:"Add column",delete:"Delete",deleteTab:"Delete tab",deleteColumn:"Remove last column",duplicate:"Duplicate",cancel:"Cancel"},confirmations:{deleteField:{title:"Delete field",message:"Are you sure you want to delete this field?"},deleteColumn:{title:"Delete column",message:"Are you sure you want to delete the last column? Fields it contains will be lost."},deleteRow:{title:"Delete row",message:"Are you sure you want to delete this row? All fields it contains will be lost."},deleteSection:{title:"Delete section",message:"Are you sure you want to delete this section? All fields it contains will be lost."}},title:"Form Schema Editor",context:"Context:",modes:{design:"Designer",preview:"Preview",code:"Code"},codeViewer:{copy:"Copy code",copied:"Copied",lines:"lines",format:"Format"},toolbar:{export:"Export",import:"Import JSON",shortcuts:"Shortcuts",showRelations:"Show relations",hideRelations:"Hide relations",toggleSidePanel:{open:"Open side panel",close:"Close side panel"}},importModal:{trigger:"Generate from object",triggerTitle:"Generate form from JSON or TypeScript",title:"Generate from JSON or TypeScript",labels:{formTitle:"Form Title",formId:"Form ID",layout:"Layout (cols)",input:"Input (paste JSON or TypeScript interface/type)"},placeholders:{layout:{auto:"Auto",col1:"1 column",col2:"2 columns",col3:"3 columns",col4:"4 columns"}},actions:{cancel:"Cancel",generate:"Generate Form",generating:"Generating..."},messages:{success:"Form generated successfully.",error:"Could not generate form."}}},fields:{defaults:{text:{label:"Text",placeholder:"Type…"},number:{label:"Number",placeholder:"0"},email:{label:"Email",placeholder:"user@domain.com"},password:{label:"Password",placeholder:"••••••••"},tel:{label:"Phone",placeholder:"600 000 000"},url:{label:"URL",placeholder:"https://example.com"},textarea:{label:"Comment",placeholder:"Write your comment…"},select:{label:"Select",placeholder:"Select an option"},checkbox:{label:"Checkbox"},date:{label:"Date"},file:{label:"File"},search:{label:"Search",placeholder:"Search...",noMatches:"No matches found"}},validation:{required:"Required field",invalidEmail:"Invalid email",invalidUrl:"Invalid URL",invalidPhone:"Invalid phone",invalidID:"Invalid identity document",invalidIBAN:"Invalid IBAN",minLength:"Minimum {{count}} characters",maxLength:"Maximum {{count}} characters",pattern:"Invalid format",numberMin:"Must be greater than or equal to {{min}}",numberMax:"Must be less than or equal to {{max}}",step:"Must be a multiple of {{step}}",integerOnly:"Must be an integer",positiveOnly:"Must be a positive number",selectMin:"Select at least {{count}} options",selectMax:"Select at most {{count}} options",dateMin:"Date must be after {{date}}",dateMax:"Date must be before {{date}}",disallowPast:"Past dates are not allowed",disallowFuture:"Future dates are not allowed",number:"Must be a number",date:"Invalid date",invalidOption:"Invalid option",mustCheck:"You must check this box",invalidFile:"Invalid file",invalidFileType:"File type not allowed",fileMaxCount:"Max. {{count}} file(s)",fileMaxSize:"File must not exceed {{size}}MB",minItems:"Minimum {{count}} items",maxItems:"Maximum {{count}} items"}}},CM={ds:RM},SM={fileUploader:{browse:"Documento",dragDrop:"Arrastra tus archivos aquí o haz clic para buscarlos",view:"Ver",remove:"Eliminar"},form:{fieldRequired:"Campo obligatorio",invalidEmail:"Email inválido",submit:"Enviar",sending:"Enviando…",saveSuccess:"¡Guardado con éxito!",saveError:"Hay errores en el formulario"},editor:{inspector:{field:"Inspector de campo",tab:"Inspector de pestaña",section:"Inspector de sección"},actions:{move:"Mover",moveLeft:"Mover a la izquierda",moveRight:"Mover a la derecha",add:"Añadir",addTab:"Pestaña a la derecha",addSection:"Añadir sección",addRow:"Añadir fila",addColumn:"Añadir columna",delete:"Eliminar",deleteTab:"Eliminar pestaña",deleteColumn:"Quitar última columna",duplicate:"Duplicar",cancel:"Cancelar"},confirmations:{deleteField:{title:"Eliminar campo",message:"¿Estás seguro de que quieres eliminar este campo?"},deleteColumn:{title:"Eliminar columna",message:"¿Estás seguro de que quieres eliminar la última columna? Se perderán los campos que contiene."},deleteRow:{title:"Eliminar fila",message:"¿Estás seguro de que quieres eliminar esta fila? Se perderán todos los campos que contiene."},deleteSection:{title:"Eliminar sección",message:"¿Estás seguro de que quieres eliminar esta sección? Se perderán todos los campos que contiene."}},title:"Editor de Esquema de Formulario",context:"Contexto:",modes:{design:"Diseñar",preview:"Vista Previa",code:"Código"},codeViewer:{copy:"Copiar código",copied:"Copiado",lines:"líneas",format:"Formato"},toolbar:{export:"Exportar",import:"Importar JSON",shortcuts:"Configurar atajos",showRelations:"Mostrar relaciones",hideRelations:"Ocultar relaciones",toggleSidePanel:{open:"Abrir panel lateral",close:"Cerrar panel lateral"}},importModal:{trigger:"Generar desde objeto",triggerTitle:"Generar formulario desde JSON o TypeScript",title:"Generar desde JSON o TypeScript",labels:{formTitle:"Título del formulario",formId:"ID del formulario",layout:"Distribución (cols)",input:"Entrada (pega JSON o una interface/type de TypeScript)"},placeholders:{layout:{auto:"Auto",col1:"1 columna",col2:"2 columnas",col3:"3 columnas",col4:"4 columnas"}},actions:{cancel:"Cancelar",generate:"Generar formulario",generating:"Generando..."},messages:{success:"Formulario generado correctamente.",error:"No se pudo generar el formulario."}}},fields:{defaults:{text:{label:"Texto",placeholder:"Escribe…"},number:{label:"Número",placeholder:"0"},email:{label:"Email",placeholder:"usuario@dominio.com"},password:{label:"Contraseña",placeholder:"••••••••"},tel:{label:"Teléfono",placeholder:"600 000 000"},url:{label:"URL",placeholder:"https://ejemplo.com"},textarea:{label:"Comentario",placeholder:"Escribe tu comentario…"},select:{label:"Seleccionar",placeholder:"Seleccione una opción"},checkbox:{label:"Casilla"},date:{label:"Fecha"},file:{label:"Archivo"},search:{label:"Búsqueda",placeholder:"Buscar...",noMatches:"No hay coincidencias"}},validation:{required:"Campo obligatorio",invalidEmail:"Email inválido",invalidUrl:"URL inválida",invalidPhone:"Teléfono inválido",invalidID:"Documento de identidad inválido",invalidIBAN:"IBAN inválido",minLength:"Mínimo {{count}} caracteres",maxLength:"Máximo {{count}} caracteres",pattern:"Formato inválido",numberMin:"Debe ser mayor o igual a {{min}}",numberMax:"Debe ser menor o igual a {{max}}",step:"Debe ser múltiplo de {{step}}",integerOnly:"Debe ser un número entero",positiveOnly:"Debe ser un número positivo",selectMin:"Selecciona al menos {{count}} opciones",selectMax:"Selecciona como máximo {{count}} opciones",dateMin:"La fecha debe ser posterior a {{date}}",dateMax:"La fecha debe ser anterior a {{date}}",disallowPast:"No se permiten fechas pasadas",disallowFuture:"No se permiten fechas futuras",number:"Debe ser un número",date:"Fecha inválida",invalidOption:"Opción inválida",mustCheck:"Debes marcar esta casilla",invalidFile:"Archivo inválido",invalidFileType:"Tipo de archivo no permitido",fileMaxCount:"Máx. {{count}} fichero(s)",fileMaxSize:"El archivo no debe superar {{size}}MB",minItems:"Mínimo {{count}} elementos",maxItems:"Máximo {{count}} elementos"}}},NM={ds:SM};We.use(RA).init({resources:{en:{translation:CM},es:{translation:NM}},lng:"es",fallbackLng:"es",interpolation:{escapeValue:!1}});const AM=e=>{We.changeLanguage(e)},W5="TRWAGMYFPDXBNJZSQVHLCKE",MM=["X","Y","Z"];function OM(e){if(!/^\d{8}[A-Z]$/.test(e))return!1;const t=parseInt(e.substring(0,8),10),r=e.charAt(8),n=W5.charAt(t%23);return r===n}function LM(e){if(!/^[XYZ]\d{7}[A-Z]$/.test(e))return!1;const t=e.charAt(0),n=MM.indexOf(t).toString()+e.substring(1),o=parseInt(n.substring(0,8),10),l=e.charAt(8),i=W5.charAt(o%23);return l===i}function $M(e){if(!/^[A-Z]\d{7}[A-Z0-9]$/.test(e))return!1;const t=e.charAt(0),r=e.substring(1,8),n=e.charAt(8);let o=0;for(let m=0;m<7;m++){const f=parseInt(r.charAt(m),10);if(m%2===0){const h=f*2;o+=Math.floor(h/10)+h%10}else o+=f}const l=o%10,i=l===0?0:10-l,c="JABCDEFGHI".charAt(i);return["A","B","E","H"].includes(t)?n===i.toString():n===c||n===i.toString()}function IM(e){if(!e||e.length<9)return!1;const t=e.toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"");return/^\d{8}[A-Z]$/.test(t)?OM(t):/^[XYZ]\d{7}[A-Z]$/.test(t)?LM(t):/^[A-Z]\d{7}[A-Z0-9]$/.test(t)?$M(t):!1}const FM=/^\s*(?:\+?\d{1,4}[\s-]*)?(?:\(?\d{2,4}\)?[\s-]*)?\d{3,4}[\s-]?\d{3,4}\s*$/;function U5(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"")}function _M(e){const t=U5(e);if(t.length<15||t.length>34||!/^[A-Z]{2}\d{2}[A-Z0-9]+$/.test(t))return!1;const r=t.slice(4)+t.slice(0,4);let n=0;for(const o of r){const l=o.charCodeAt(0);if(l>=65&&l<=90){const i=String(l-55);for(let c=0;c<i.length;c++)n=(n*10+(i.charCodeAt(c)-48))%97}else n=(n*10+(o.charCodeAt(0)-48))%97}return n===1}function TM(e){return e.validation??{}}function BM(e){return!!e.multiple}function ZM(e){const t=e.maxFiles;return typeof t=="number"?t:void 0}function VM(e){const t=e.options;return Array.isArray(t)?t.map(r=>r==null?void 0:r.value).filter(r=>r!==void 0):[]}function DM(e){if(!e)return{exts:[],mimes:[]};const t=e.split(",").map(o=>o.trim().toLowerCase()).filter(Boolean),r=[],n=[];for(const o of t)o.startsWith(".")?r.push(o):o.includes("/")&&n.push(o);return{exts:r,mimes:n}}function ct(e,t){const r=typeof e=="string"?e:t;return We.isInitialized&&(r.startsWith("forms.")||r.startsWith("ds."))?We.t(r):r}function Pt(e,t){let r=e;return t.required&&(r=r.required(ct(t.requiredMessage||(typeof t.required=="string"?t.required:void 0),"ds.fields.validation.required"))),t.customFn&&(r=r.test({name:"custom-script-validation",message:"${path} no es válido",test:async function(n,o){if(n==null||n==="")return!0;const l=o.parent;let i={};try{if(We.isInitialized){const c=We.getResourceBundle(We.language,"translation")||{},u=(d,m="")=>{for(const f of Object.keys(d)){const h=m?`${m}.${f}`:f,p=d[f];typeof p=="string"?i[h]=p:typeof p=="object"&&p!==null&&u(p,h)}};u(c)}}catch(c){console.warn("Error extracting translations for validation:",c)}try{const c=await H5(t.customFn,{value:n,form:l,customMessages:t.customMessages||{}},{translations:i});if(c===!0)return!0;if(typeof c=="string"){const u=We.isInitialized&&c.startsWith("forms.")?We.t(c):c;return this.createError({message:u})}return!1}catch(c){return console.error("Custom Validation Error",c),this.createError({message:"Error ejecutando validación: "+String(c)})}}})),r}function Pr(e,t){var n,o,l;let r=e;return((n=t.minLength)==null?void 0:n.value)!=null&&(r=r.min(t.minLength.value,ct(t.minLength.message,"ds.fields.validation.minLength"))),((o=t.maxLength)==null?void 0:o.value)!=null&&(r=r.max(t.maxLength.value,ct(t.maxLength.message,"ds.fields.validation.maxLength"))),((l=t.pattern)==null?void 0:l.value)instanceof RegExp&&(r=r.matches(t.pattern.value,ct(t.pattern.message,"ds.fields.validation.pattern"))),r}function PM(e,t){var n,o,l,i;let r=e;if(((n=t.numberMin)==null?void 0:n.value)!=null&&(r=r.min(t.numberMin.value,ct(t.numberMin.message,"ds.fields.validation.numberMin"))),((o=t.numberMax)==null?void 0:o.value)!=null&&(r=r.max(t.numberMax.value,ct(t.numberMax.message,"ds.fields.validation.numberMax"))),t.positiveOnly&&(r=r.moreThan(0,ct(t.positiveOnly,"ds.fields.validation.positiveOnly"))),t.integerOnly&&(r=r.integer(ct(t.integerOnly,"ds.fields.validation.integerOnly"))),((l=t.step)==null?void 0:l.value)!=null){const c=Number(t.step.value),u=t.step.message||"ds.fields.validation.step";r=r.test("step",u,d=>{if(d==null||Number.isNaN(d)||c===0)return!0;const m=d/c;return Math.abs(m-Math.round(m))<1e-9})}return((i=t.pattern)==null?void 0:i.value)instanceof RegExp&&(r=r.test("pattern-number",t.pattern.message||"ds.fields.validation.pattern",c=>c==null||t.pattern.value.test(String(c)))),r}function zM(e,t){var n,o;let r=e;return(n=t.dateMin)!=null&&n.value&&(r=r.min(new Date(t.dateMin.value),ct(t.dateMin.message,"ds.fields.validation.dateMin"))),(o=t.dateMax)!=null&&o.value&&(r=r.max(new Date(t.dateMax.value),ct(t.dateMax.message,"ds.fields.validation.dateMax"))),t.disallowPast&&(r=r.min(new Date,ct(t.disallowPast,"ds.fields.validation.disallowPast"))),t.disallowFuture&&(r=r.max(new Date,ct(t.disallowFuture,"ds.fields.validation.disallowFuture"))),r}function HM(e){var r,n,o,l;const t=TM(e);switch(e.type){case"text":case"password":case"textarea":case"search":{let i=Cr().trim();return i=Pr(i,t),Pt(i,t)}case"dni":{let i=Cr().trim();return i=Pr(i,t),i=i.test("dni-valid",ct("ds.fields.validation.invalidID","Documento de identidad inválido"),c=>c==null||c===""?!0:IM(c)),Pt(i,t)}case"email":{let i=Cr().trim().email(ct(t.emailMessage,"ds.fields.validation.invalidEmail"));return i=Pr(i,t),Pt(i,t)}case"url":{let i=Cr().trim().url(ct(t.urlMessage,"ds.fields.validation.invalidUrl"));return i=Pr(i,t),Pt(i,t)}case"tel":{let i=Cr().trim();return i=Pr(i,t),(r=t.pattern)!=null&&r.value||(i=i.matches(FM,ct(t.phoneMessage,"ds.fields.validation.invalidPhone"))),Pt(i,t)}case"iban":{let i=Cr().transform((c,u)=>u===""||u===null||u===void 0?"":typeof u=="string"?U5(u):c);return i=Pr(i,t),i=i.test("iban-valid",ct("ds.fields.validation.invalidIBAN","IBAN inválido"),c=>c==null||c===""?!0:_M(String(c))),Pt(i,t)}case"number":{let i=T5().transform((c,u)=>{if(u===""||u===null||u===void 0)return;const d=typeof u=="string"?Number(u.replace(",",".")):c;return Number.isNaN(d)?NaN:d}).typeError(ct(t.typeError,"ds.fields.validation.number"));return i=PM(i,t),Pt(i,t)}case"date":{let i=yi().nullable().typeError(ct(t.typeError,"ds.fields.validation.date")).transform((c,u)=>u?new Date(u):null);return i=zM(i,t),Pt(i,t)}case"select":case"optionGroup":{const i=BM(e),c=VM(e);if(i){let u=Cl().of(c.length?Jn().oneOf(c,"ds.fields.validation.invalidOption"):Jn());return t.required&&(u=u.min(1,t.requiredMessage||(typeof t.required=="string"?t.required:"ds.fields.validation.required"))),u}else{let u=Cr().trim();return u=Pr(u,t),c.length&&(u=u.oneOf(c,"ds.fields.validation.invalidOption")),Pt(u,t)}}case"checkbox":{let i=I5();return t.required&&(i=i.oneOf([!0],t.requiredMessage||"ds.fields.validation.mustCheck")),i}case"file":{const i=e,{exts:c,mimes:u}=DM(i.accept),d=ZM(e);let m=Jn().test("file-shape","ds.fields.validation.invalidFile",f=>(f==null,!0));if((n=t.fileMaxSizeMB)!=null&&n.value){const f=Number(t.fileMaxSizeMB.value)*1024*1024,h=t.fileMaxSizeMB.message||"ds.fields.validation.fileMaxSize";m=m.test("file-max-size",h,p=>p?(Array.isArray(p)?p:typeof FileList<"u"&&p instanceof FileList?Array.from(p):[p].filter(Boolean)).every(v=>typeof(v==null?void 0:v.size)!="number"||v.size<=f):!0)}return(c.length||u.length)&&(m=m.test("file-accept","ds.fields.validation.invalidFileType",f=>f?(Array.isArray(f)?f:typeof FileList<"u"&&f instanceof FileList?Array.from(f):[f].filter(Boolean)).every(b=>{var y,E,j,R;const v=((E=(y=b==null?void 0:b.name)==null?void 0:y.toLowerCase)==null?void 0:E.call(y))||"",g=((R=(j=b==null?void 0:b.type)==null?void 0:j.toLowerCase)==null?void 0:R.call(j))||"",x=c.length===0||c.some(A=>v.endsWith(A)),w=u.length===0||u.includes(g);return x&&w}):!0)),typeof d=="number"&&(m=m.test("file-max-files","ds.fields.validation.fileMaxCount",f=>f?(Array.isArray(f)?f:typeof FileList<"u"&&f instanceof FileList?Array.from(f):[f].filter(Boolean)).length<=d:!0)),m=Pt(m,t),m}case"array":{const i=e,c=i.items||[],u=q5(c);let d=Cl().of(ji(u));t.required&&(d=d.min(1,t.requiredMessage||(typeof t.required=="string"?t.required:"ds.fields.validation.required")));const m=i.validation;return(o=m==null?void 0:m.min)!=null&&o.value&&(d=d.min(m.min.value,m.min.message||"ds.fields.validation.minItems")),(l=m==null?void 0:m.max)!=null&&l.value&&(d=d.max(m.max.value,m.max.message||"ds.fields.validation.maxItems")),d}default:{const i=Jn();return Pt(i,t)}}}function q5(e){const t={};for(const r of e){const n=r;n!=null&&n.name&&(t[n.name]=HM(n))}return t}function ki(e){const t=q5(e.fields);return ji(t)}const Yc=e=>{let t;const r=new Set,n=(d,m)=>{const f=typeof d=="function"?d(t):d;if(!Object.is(f,t)){const h=t;t=m??(typeof f!="object"||f===null)?f:Object.assign({},t,f),r.forEach(p=>p(t,h))}},o=()=>t,c={setState:n,getState:o,getInitialState:()=>u,subscribe:d=>(r.add(d),()=>r.delete(d))},u=t=e(n,o,c);return c},WM=(e=>e?Yc(e):Yc),UM=e=>e;function qM(e,t=UM){const r=k.useSyncExternalStore(e.subscribe,k.useCallback(()=>t(e.getState()),[e,t]),k.useCallback(()=>t(e.getInitialState()),[e,t]));return k.useDebugValue(r),r}const Xc=e=>{const t=WM(e),r=n=>qM(t,n);return Object.assign(r,t),r},G5=(e=>e?Xc(e):Xc),Jr=G5(e=>({isActive:!1,formValues:{},systemContext:{},setRuntimeState:t=>e(r=>({...r,...t})),reset:()=>e({isActive:!1,formValues:{},systemContext:{}})}));function Sl(e,t){return e?typeof e!="string"?String(e):e.replace(/\{\{([^}]+)\}\}/g,(r,n)=>{let l=n.trim().split(".").reduce((i,c)=>{if(!i)return;if(i[c]!==void 0)return i[c];const u=c.toLowerCase(),d=Object.keys(i).find(m=>m.toLowerCase()===u);return d?i[d]:void 0},t);return l!=null?String(l):r}):""}function xr({options:e,value:t,onChange:r,children:n,className:o,contentClassName:l}){const i=k.useRef(null),[c,u]=k.useState({left:0,width:0}),[d,m]=k.useState(!1),[f,h]=k.useState(!1),p=()=>{if(i.current){const{scrollLeft:v,scrollWidth:g,clientWidth:x}=i.current;m(v>0),h(v<g-x-1)}};k.useLayoutEffect(()=>{const v=i.current;if(!v)return;const g=()=>{const x=v.querySelector(`[data-value="${t}"]`);x&&u({left:x.offsetLeft,width:x.offsetWidth})};return g(),p(),window.addEventListener("resize",g),window.addEventListener("resize",p),()=>{window.removeEventListener("resize",g),window.removeEventListener("resize",p)}},[t,e]);const b=v=>{i.current&&i.current.scrollBy({left:v==="left"?-200:200,behavior:"smooth"})};return s.jsxs("div",{className:o,children:[s.jsxs("div",{className:"relative border-b border-[var(--color-ds-border-default-50)] group",children:[d&&s.jsx("div",{className:"absolute left-0 top-0 bottom-0 z-20 flex items-center bg-gradient-to-r from-[var(--color-ds-background-page)] to-transparent pr-4 pl-1 opacity-0 group-hover:opacity-100 transition-opacity duration-200",children:s.jsx("button",{type:"button",onClick:()=>b("left"),className:"p-1 rounded-full bg-[var(--color-ds-background-surface)] shadow-sm border border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-button-hover-bg)] hover:text-white transition-colors",children:s.jsx(Od,{className:"w-4 h-4"})})}),s.jsx("div",{ref:i,onScroll:p,className:"overflow-x-auto scrollbar-hidden flex items-center w-full relative",style:{scrollBehavior:"smooth"},children:s.jsxs("div",{className:"relative flex min-w-full px-1",children:[e.map(v=>{const g=v.value===t;return s.jsxs("button",{"data-value":v.value,role:"tab","aria-selected":g,onClick:()=>!v.disabled&&r(v.value),type:"button",className:ge("relative z-10 whitespace-nowrap px-4 py-2 transition-colors duration-150 ease-in-out font-medium text-sm focus:outline-none",g?"text-[var(--color-ds-background-accent)]":"text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)]",v.disabled&&"opacity-50 cursor-not-allowed"),disabled:v.disabled,children:[v.icon&&s.jsx("span",{className:"mr-2 -ml-1 inline-block align-text-bottom",children:v.icon}),v.label]},v.value)}),s.jsx("span",{className:"absolute bottom-0 h-0.5 bg-[var(--color-ds-background-accent)] transition-all duration-200 ease-in-out z-20",style:{left:c.left,width:c.width}})]})}),f&&s.jsx("div",{className:"absolute right-0 top-0 bottom-0 z-20 flex items-center bg-gradient-to-l from-[var(--color-ds-background-page)] to-transparent pl-4 pr-1 opacity-0 group-hover:opacity-100 transition-opacity duration-200",children:s.jsx("button",{type:"button",onClick:()=>b("right"),className:"p-1 rounded-full bg-[var(--color-ds-background-surface)] shadow-sm border border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-button-hover-bg)] hover:text-white transition-colors",children:s.jsx(Ho,{className:"w-4 h-4"})})})]}),s.jsx("div",{className:ge("mt-4",l),children:n[t]})]})}const cn={sm:"text-ds-sm",md:"text-ds-md",lg:"text-ds-lg"},qa={sm:"h-5",md:"h-10",lg:"h-12"},Ga={sm:"px-2",md:"px-2.5",lg:"px-3"},Ka={sm:"1.5rem",md:"2.5rem",lg:"3rem"},Ja={sm:"pr-9",md:"pr-11",lg:"pr-12"},GM={sm:"h-6 w-6",md:"h-8 w-8",lg:"h-10 w-10"};function Ya({id:e,size:t,disabled:r,error:n,reserveErrorSpace:o,className:l,suffixButton:i,children:c,showDropdownIndicator:u}){var d;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:ge("relative w-full",l),children:[c,u&&!i&&s.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-2 flex items-center",children:s.jsx(Kt,{className:"h-4 w-4 text-[var(--color-ds-text-secondary)]"})}),i&&s.jsx("div",{className:"pointer-events-none absolute flex items-center",style:{top:2,bottom:2,right:4},children:s.jsx("div",{className:"pointer-events-auto",children:k.isValidElement(i)?k.cloneElement(i,{className:ge(GM[t],(d=i.props)==null?void 0:d.className)}):i})})]}),o?s.jsx("div",{className:"h-[1em]",children:n!=null&&n.message?s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:n.message}):s.jsx("span",{"aria-hidden":"true",children:" "})}):n!=null&&n.message?s.jsx("div",{className:"pt-1",children:s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:n.message})}):null]})}function Qc(e,t){k.useEffect(()=>{const r=n=>{e.current&&(e.current.contains(n.target)||t())};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[t,e])}function Ge(e){const{control:t,name:r,rules:n,defaultValue:o,options:l=[],loadOptions:i,reloadDeps:c=[],value:u,onChange:d,size:m="sm",width:f="100%",label:h,labelHidden:p=!1,info:b,infoHeader:v,hasError:g=!1,errorMessage:x="",reserveErrorSpace:w,disableErrorPlaceholder:y,disabled:E=!1,className:j,suffixButton:R,loading:A=!1,coerceFirstValid:S=!0,mode:O="menu",renderTrigger:_,renderOption:V,popupWidth:$,triggerClassName:D,onBlur:M,searchable:z=!1,searchPlaceholder:te="Buscar...",noOptionsText:Q="No se encontraron resultados"}=e,ne=k.useId(),ae=r||ne,[K,N]=k.useState(l),[I,re]=k.useState(!!i);k.useEffect(()=>{if(!i){N(l);return}re(!0),i().then(ve=>N(ve)).finally(()=>re(!1))},[i,...c]),k.useEffect(()=>{i||N(l)},[l,i]);const G=ve=>ve.find(ue=>ue.value!==""&&ue.value!==void 0)??ve[0],X=(ve,ue)=>{const xe=ue.trim().toLowerCase();return xe?ve.filter(C=>String(C.label).toLowerCase().includes(xe)||String(C.value).toLowerCase().includes(xe)):ve},fe=typeof w=="boolean"?w:!!t,le=f&&(f.includes(" ")||f.startsWith("w-")||f.startsWith("max-w-")||f.startsWith("min-w-")),he=le?{maxWidth:"100%"}:{width:f,maxWidth:"100%"},ce=ge("flex flex-col",le&&f,j);if(t&&r){const{field:ve,fieldState:ue}=d5({name:r,control:t,rules:n,defaultValue:o});k.useEffect(()=>{if(!I&&K.length>0&&S){const C=ve.value,q=K.some(ee=>String(ee.value)===String(C));(C===void 0||!q)&&ve.onChange(G(K).value)}},[K,I,ve,S]);const xe=h&&!p&&s.jsx(Gt,{id:ae,text:h,size:m,info:b,infoHeader:v});if((O??"native")==="menu"){const[C,q]=k.useState(!1),[ee,W]=k.useState(""),H=k.useRef(null);Qc(H,()=>{q(!1),W("")});const Y=K.find(Z=>String(Z.value)===String(ve.value)),L=z?X(K,ee):K;return s.jsxs("div",{className:ce,style:he,children:[xe,A||I?s.jsx(pr,{width:"100%",height:Ka[m],variant:"rect",className:"rounded-lg"}):s.jsx(Ya,{id:ae,size:m,disabled:E,error:ue.error,reserveErrorSpace:typeof y=="boolean"?!y:fe,className:j,suffixButton:R,showDropdownIndicator:!0,children:s.jsxs("div",{className:"relative w-full",ref:H,children:[s.jsx("button",{type:"button",onClick:()=>{E||q(Z=>{const F=!Z;return F||W(""),F})},onBlur:()=>{ve.onBlur(),M==null||M()},className:ge("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none text-left flex items-center",cn[m],qa[m],Ga[m],R&&Ja[m],ue.error?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)] hover:border-[var(--color-ds-border-default-hover)]",D),"aria-haspopup":"listbox","aria-expanded":C,children:_?_(Y):(Y==null?void 0:Y.label)??"—"}),C&&s.jsxs("div",{role:"listbox",className:"custom-scroll absolute z-50 mt-1 rounded-xl border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-page)] shadow-xl p-1 max-h-72 overflow-auto",style:{width:$??"100%"},children:[z&&s.jsx("div",{className:"sticky top-0 z-10 bg-[var(--color-ds-background-page)] p-1",children:s.jsx("input",{type:"text",value:ee,onChange:Z=>W(Z.target.value),onClick:Z=>Z.stopPropagation(),placeholder:te,className:"w-full rounded-lg border border-[var(--color-ds-border-default)] bg-[var(--color-ds-background-page)] px-2 py-2 text-sm outline-none"})}),L.length>0?L.map(Z=>{const F=String(Z.value)===String(ve.value);return s.jsx("button",{role:"option","aria-selected":F,type:"button",onClick:()=>{ve.onChange(Z.value),q(!1),W("")},className:ge("w-full rounded-lg px-2 py-1.5 text-left transition-all duration-200",cn[m],F?"bg-[var(--color-ds-background-neutral)] font-medium text-[var(--color-ds-text-primary)]":"text-[var(--color-ds-text-secondary)] hover:bg-[var(--color-ds-background-neutral-hover)] hover:text-[var(--color-ds-text-primary)] hover:pl-3"),children:V?V(Z,F):Z.label},Z.value)}):s.jsx("div",{className:"px-2 py-2 text-sm text-[var(--color-ds-text-secondary)]",children:Q})]})]})})]})}return s.jsxs("div",{className:ce,style:he,children:[xe,A||I?s.jsx(pr,{width:"100%",height:Ka[m],variant:"rect",className:"rounded-lg"}):s.jsx(Ya,{id:ae,size:m,disabled:E,error:ue.error,reserveErrorSpace:typeof y=="boolean"?!y:fe,className:j,suffixButton:R,showDropdownIndicator:!0,children:s.jsx("select",{id:ae,value:ve.value,onChange:C=>ve.onChange(C.target.value),onBlur:()=>{ve.onBlur(),M==null||M()},disabled:E,className:ge("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none leading-none",cn[m],qa[m],Ga[m],R&&Ja[m],ue.error?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)]",D),children:K.map(C=>s.jsx("option",{value:C.value,className:"bg-[var(--color-ds-background-page)] text-[var(--color-ds-text-primary)]",children:C.label},C.value))})})]})}k.useEffect(()=>{if(!t&&K.length>0&&S){const ve=K.some(xe=>String(xe.value)===String(u));(u===void 0||u===""||!ve)&&d&&d(G(K).value)}},[K,u,d,t,S]);const ie=h&&!p&&s.jsx(Gt,{id:ae,text:h,size:m,info:b,infoHeader:v});if((O??"native")==="menu"){const[ve,ue]=k.useState(!1),[xe,C]=k.useState(""),q=k.useRef(null);Qc(q,()=>{ue(!1),C("")});const ee=K.find(H=>String(H.value)===String(u)),W=z?X(K,xe):K;return s.jsxs("div",{className:ce,style:he,children:[ie,A||I?s.jsx(pr,{width:"100%",height:Ka[m],variant:"rect",className:"rounded-lg"}):s.jsx(Ya,{id:ae,size:m,disabled:E,error:g?{message:x}:void 0,reserveErrorSpace:typeof y=="boolean"?!y:!!(w??!1),className:j,suffixButton:R,showDropdownIndicator:!0,children:s.jsxs("div",{className:"relative w-full",ref:q,children:[s.jsx("button",{type:"button",onClick:()=>{E||ue(H=>{const Y=!H;return Y||C(""),Y})},onBlur:M,className:ge("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none text-left flex items-center",cn[m],qa[m],Ga[m],R&&Ja[m],g?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)] hover:border-[var(--color-ds-border-default-hover)]",D),"aria-haspopup":"listbox","aria-expanded":ve,children:_?_(ee):(ee==null?void 0:ee.label)??"—"}),ve&&s.jsxs("div",{role:"listbox",className:"custom-scroll absolute z-50 mt-1 rounded-xl border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-page)] shadow-xl p-1 max-h-72 overflow-auto",style:{width:$??"100%"},children:[z&&s.jsx("div",{className:"sticky top-0 z-10 bg-[var(--color-ds-background-page)] p-1",children:s.jsx("input",{type:"text",value:xe,onChange:H=>C(H.target.value),onClick:H=>H.stopPropagation(),placeholder:te,className:"w-full rounded-lg border border-[var(--color-ds-border-default)] bg-[var(--color-ds-background-page)] px-2 py-2 text-sm outline-none"})}),W.length>0?W.map(H=>{const Y=String(H.value)===String(u);return s.jsx("button",{role:"option","aria-selected":Y,type:"button",onClick:()=>{d==null||d(H.value),ue(!1),C("")},className:ge("w-full rounded-lg px-2 py-1.5 text-left transition-all duration-200",cn[m],Y?"bg-[var(--color-ds-background-neutral)] font-medium text-[var(--color-ds-text-primary)]":"text-[var(--color-ds-text-secondary)] hover:bg-[var(--color-ds-background-neutral-hover)] hover:text-[var(--color-ds-text-primary)] hover:pl-3"),children:V?V(H,Y):H.label},H.value)}):s.jsx("div",{className:"px-2 py-2 text-sm text-[var(--color-ds-text-secondary)]",children:Q})]})]})})]})}return s.jsxs("div",{className:ce,style:he,children:[ie,A||I?s.jsx(pr,{width:"100%",height:Ka[m],variant:"rect",className:"rounded-lg"}):s.jsx(Ya,{id:ae,size:m,disabled:E,error:g?{message:x}:void 0,reserveErrorSpace:typeof y=="boolean"?!y:!!(w??!1),className:j,suffixButton:R,showDropdownIndicator:!0,children:s.jsx("select",{id:ae,value:u,onChange:ve=>d==null?void 0:d(ve.target.value),onBlur:M,disabled:E,className:ge("box-border w-full rounded-lg border bg-[var(--color-ds-background-page)] outline-none transition appearance-none leading-none",cn[m],qa[m],Ga[m],R&&Ja[m],g?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",E?"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-primary)] cursor-not-allowed":"text-[var(--color-ds-text-primary)]"),children:K.map(ve=>s.jsx("option",{value:ve.value,className:"bg-[var(--color-ds-background-page)] text-[var(--color-ds-text-primary)]",children:ve.label},ve.value))})})]})}const e0={sm:"text-ds-sm",md:"text-ds-md",lg:"text-ds-lg"};function t0(e){var t;e.preventDefault(),e.stopPropagation(),(t=e.nativeEvent)!=null&&t.stopImmediatePropagation&&e.nativeEvent.stopImmediatePropagation()}function Ei({groupLabel:e,inputs:t=[],separator:r=s.jsx("span",{className:"px-1 select-none",children:"/"}),useSeparator:n=!1,className:o,showVisibleLabel:l=!1,size:i="sm",width:c,respectChildWidths:u=!1}){const d=t.length,m=c&&(c.includes(" ")||c.startsWith("w-")||c.startsWith("max-w-")||c.startsWith("min-w-")),f=m?void 0:c?{width:c}:void 0;return s.jsxs("div",{"data-input-group-root":!0,role:"group",className:ge("flex flex-col w-full",m&&c,o),style:f,onDoubleClick:t0,onDoubleClickCapture:t0,onClickCapture:h=>{var v;const p=h.target;!!((v=p==null?void 0:p.closest)!=null&&v.call(p,'input,select,textarea,button,[data-interactive="true"]'))||h.stopPropagation()},children:[s.jsx("label",{className:ge("sr-only pb-2",e0[i]),children:e}),l&&s.jsx("label",{className:ge("pb-2",e0[i]),children:e}),s.jsx("div",{className:"flex items-stretch flex-nowrap w-full min-w-0",children:t.map((h,p)=>{const{width:b,className:v,options:g,loadOptions:x,info:w,infoHeader:y,...E}=h,j=Array.isArray(g)||typeof x=="function";let R="rounded-lg";!n&&d>1&&(p===0?R="rounded-l-lg rounded-r-none":p===d-1?R="rounded-r-lg rounded-l-none !rounded-l-none":R="rounded-none !rounded-l-none !rounded-r-none");const A=u?b:void 0,S=typeof A=="string"&&A.split(/\s+/).some($=>$.startsWith("w-")||$.includes(":w-")),O=ge("inline-flex items-stretch",A?"flex-shrink-0":"flex-1 min-w-0",typeof A=="string"&&S?A:void 0,!n&&d>1&&p>0?"-ml-px focus-within:z-10 relative":void 0),_=A?typeof A=="string"&&S?void 0:{width:A}:void 0,V=ge(v,"w-full",R);return s.jsxs(k.Fragment,{children:[s.jsx("div",{className:O,style:_,children:j?s.jsx(Ge,{...E,size:i,className:v,triggerClassName:ge("w-full",R),options:g,loadOptions:x,"data-interactive":"true",info:w,infoHeader:y,mode:"menu",searchable:!0,searchPlaceholder:$c("ds.fields.defaults.search.placeholder"),noOptionsText:$c("ds.fields.defaults.search.noMatches")}):s.jsx(ke,{...E,size:i,className:V,"data-interactive":"true",info:w,infoHeader:y})}),n&&p<d-1&&s.jsx("div",{className:"flex items-center flex-shrink-0 px-1 select-none",children:r})]},p)})})]})}const KM={sm:"w-4 h-4",md:"w-5 h-5",lg:"w-6 h-6"},JM={sm:"w-3 h-3",md:"w-3.5 h-3.5",lg:"w-4 h-4"};function es({groupLabel:e,options:t,control:r,name:n,rules:o,defaultValue:l,multiple:i=!0,size:c="sm",vertical:u=!0,className:d,showVisibleLabel:m=!0,disabled:f=!1,hasError:h=!1,errorMessage:p}){return s.jsx(mt,{name:n,control:r,rules:o,defaultValue:l,render:({field:b,fieldState:v})=>{const{value:g,onChange:x}=b,w=v.error,y=A=>{var S;return i?Array.isArray(g)&&((S=g==null?void 0:g.includes)==null?void 0:S.call(g,A)):g===A},E=A=>{if(!f)if(i){const S=Array.isArray(g)?[...g]:[],O=S.indexOf(A);O>=0?S.splice(O,1):S.push(A),x(S)}else x(A)},j=h||!!w,R=(w==null?void 0:w.message)||p;return s.jsxs("fieldset",{className:ge("w-full flex flex-col gap-1",d),"aria-invalid":j||void 0,disabled:f,children:[e&&s.jsx("legend",{className:ge("mb-1 text-ds-sm text-[var(--color-ds-text-primary)]",!m&&"sr-only"),children:e}),s.jsx("div",{className:ge(u?"flex flex-col gap-2":"flex flex-wrap gap-2"),children:t.map(A=>{const S=y(A.value),O=f||!!(A!=null&&A.disabled),_=ge("inline-flex items-center justify-center border transition-all duration-150",i?"rounded-[6px]":"rounded-full",KM[c],"bg-[var(--color-ds-background-page)]","border-[var(--color-ds-border-default-50)]","shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-default)20%,transparent)]","peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-[var(--color-ds-border-default)]","hover:border-[var(--color-ds-border-default)]",i&&S&&"bg-[var(--color-ds-button-primary-bg)] border-[var(--color-ds-button-primary-bg)]",!i&&S&&"border-[var(--color-ds-button-primary-bg)]",j&&"border-[var(--color-ds-border-error)] shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-error)30%,transparent)]",O&&"opacity-60 cursor-not-allowed"),V=ge("text-ds-sm text-[var(--color-ds-text-primary)]",O&&"text-[var(--color-ds-text-secondary)]"),$=ge(JM[c],"text-[var(--color-ds-button-primary-text)] transition-all duration-150",S?"opacity-100 scale-100":"opacity-0 scale-75"),D=ge(c==="sm"?"w-2 h-2":c==="md"?"w-2.5 h-2.5":"w-3 h-3","rounded-full bg-[var(--color-ds-button-primary-bg)] transition-all duration-150",S?"opacity-100 scale-100":"opacity-0 scale-0");return s.jsxs("label",{className:ge("inline-flex items-center gap-2 cursor-pointer select-none rounded-md px-1 py-1","hover:bg-[color-mix(in_srgb,var(--color-ds-border-default)6%,transparent)]",O&&"cursor-not-allowed hover:bg-transparent"),children:[s.jsxs("span",{className:"relative inline-flex items-center justify-center",children:[s.jsx("input",{type:i?"checkbox":"radio",name:n,value:A.value,checked:S,onChange:()=>E(A.value),disabled:O,className:"peer sr-only"}),s.jsx("span",{"aria-hidden":!0,className:_,children:i?s.jsx(vi,{className:$}):s.jsx("span",{className:D})})]}),s.jsx("span",{className:V,children:A.label})]},String(A.value))})}),j&&!!R&&s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] mt-1",children:R})]})}})}function YM(e){function t(i){var c,u;for(const d of Object.keys(i)){if((c=i[d])!=null&&c.types||(u=i[d])!=null&&u.message)return d;if(typeof i[d]=="object"){const m=t(i[d]);if(m)return`${d}.${m}`}}return null}const r=t(e);if(!r)return;const n=`[name="${r}"]`,o=`[name^="${r}["], [name^="${r}."]`,l=document.querySelector(n)??document.querySelector(o);l&&(l.scrollIntoView({behavior:"smooth",block:"center"}),l.focus({preventScroll:!0}))}const XM={success:"bg-green-100 border-green-500 text-green-800",error:"bg-red-100 border-red-500 text-red-800",info:"bg-blue-100 border-blue-500 text-blue-800",warning:"bg-yellow-100 border-yellow-500 text-yellow-800"},K5=({id:e,message:t,variant:r="info",duration:n=5e3,onClose:o})=>(k.useEffect(()=>{const l=setTimeout(()=>o(e),n);return()=>clearTimeout(l)},[e,n,o]),s.jsxs("div",{className:ge("w-80 max-w-full border-l-4 rounded shadow-md p-4 mb-2 flex justify-between items-start",XM[r]),role:"alert","aria-live":"assertive",children:[s.jsx("span",{className:"flex-1",children:t}),s.jsx("button",{onClick:()=>o(e),className:"ml-4 text-xl font-bold leading-none focus:outline-none",children:"×"})]})),ft=[];for(let e=0;e<256;++e)ft.push((e+256).toString(16).slice(1));function QM(e,t=0){return(ft[e[t+0]]+ft[e[t+1]]+ft[e[t+2]]+ft[e[t+3]]+"-"+ft[e[t+4]]+ft[e[t+5]]+"-"+ft[e[t+6]]+ft[e[t+7]]+"-"+ft[e[t+8]]+ft[e[t+9]]+"-"+ft[e[t+10]]+ft[e[t+11]]+ft[e[t+12]]+ft[e[t+13]]+ft[e[t+14]]+ft[e[t+15]]).toLowerCase()}let Ls;const eO=new Uint8Array(16);function tO(){if(!Ls){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ls=crypto.getRandomValues.bind(crypto)}return Ls(eO)}const rO=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),r0={randomUUID:rO};function nO(e,t,r){var o;e=e||{};const n=e.random??((o=e.rng)==null?void 0:o.call(e))??tO();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,QM(n)}function aO(e,t,r){return r0.randomUUID&&!e?r0.randomUUID():nO(e)}const J5=k.createContext(null),Vr=()=>{const e=k.useContext(J5);if(!e)throw new Error("useToast debe usarse dentro de <ToastProvider>");return e},oO=({children:e})=>{const[t,r]=k.useState([]),n=(l,i="info",c=5e3)=>{const u=aO();r(d=>[...d,{id:u,message:l,variant:i,duration:c}])},o=l=>{r(i=>i.filter(c=>c.id!==l))};return s.jsxs(J5.Provider,{value:{show:n},children:[e,s.jsx("div",{className:"fixed top-4 right-4 z-50 flex flex-col items-end",children:t.map(l=>s.jsx(K5,{id:l.id,message:l.message,variant:l.variant,duration:l.duration,onClose:o},l.id))})]})},sO=e=>e.type==="inputGroup",lO=e=>e.type==="button",iO=e=>!sO(e)&&!lO(e);function Y5(e){const t=Array.isArray(e)?e:[];return k.useMemo(()=>{const r={};for(const n of t)iO(n)&&n.name&&(r[n.name]=n);return r},[t])}const X5=k.createContext(null);function Q5({children:e,value:t}){return s.jsx(X5.Provider,{value:t,children:e})}function At(){const e=k.useContext(X5);if(!e)throw new Error("useAdapters debe usarse dentro de <AdaptersProvider />");return e}const cO=e=>!!e&&typeof e.then=="function";function dO(e){return Array.isArray(e)?e.length>0&&typeof e[0]=="object"&&e[0]!==null?e.map(t=>{var o;if("label"in t&&"value"in t)return t;const n=(o=Object.entries(t)[0])==null?void 0:o[1];return{label:String(n??JSON.stringify(t)),value:String(n??"")}}):e.map(t=>({label:String(t),value:t})):[]}function e1(e){const{services:t}=At(),[r,n]=k.useState({}),[o,l]=k.useState(0),i=k.useRef(!0);k.useEffect(()=>(i.current=!0,()=>{i.current=!1}),[]);const c=k.useMemo(()=>e.filter(u=>u.type==="select"&&!u.options&&typeof u.optionSource=="string"&&u.name),[e]);return k.useEffect(()=>{if(c.length===0)return;let u=!1;return(async()=>{l(d=>d+1);try{const d=await Promise.all(c.map(async m=>{var g;const f=m.name,h=m.optionSource,p=(g=t==null?void 0:t.registry)==null?void 0:g[h];if(!p)return[f,[]];const b=cO(p)?await p:await p(),v=dO(b);return[f,v]}));if(u||!i.current)return;n(m=>{const f={...m};for(const[h,p]of d)f[h]=[...p];return f})}finally{!u&&i.current&&l(d=>Math.max(0,d-1))}})(),()=>{u=!0}},[c,t==null?void 0:t.registry]),{optionsMap:r,loadingCount:o}}const uO=e=>e.type==="inputGroup",fO=e=>e.type==="button",mO=e=>!uO(e)&&!fO(e);function hO(e){return typeof e=="object"&&e!==null}const pO=e=>{const t=e.disabledWhen;if(!hO(t))return!1;const r="watchField"in t,n="rule"in t;return r&&!n};function t1(e,t){const r=Array.isArray(e)?e:[],n=k.useMemo(()=>r.filter(mO).filter(pO),[r]),o=k.useMemo(()=>n.map(u=>u.disabledWhen.watchField),[n]),l=mi({control:t,name:o,compute:u=>u}),i=Array.isArray(l)?l:[],c={};return n.forEach((u,d)=>{const m=i[d];c[u.name??`__unnamed_${d}`]=m===u.disabledWhen.watchValue}),c}const gO={sm:"text-ds-sm",md:"text-ds-sm",lg:"text-ds-sm"},vO={sm:"px-2 py-1.5",md:"px-3 py-2",lg:"px-4 py-3"};function or({control:e,name:t,rules:r,defaultValue:n,size:o="sm",width:l="100%",label:i,labelHidden:c=!1,hasError:u=!1,errorMessage:d="",maxLength:m,showCounter:f=!1,className:h,suffixButton:p,labelPrefixIcon:b,labelSuffixIcon:v,info:g,infoHeader:x,infoAriaLabel:w,prefixIcon:y,suffixIcon:E,reserveErrorSpace:j,disableErrorPlaceholder:R,id:A,...S}){const O=k.useId(),_=A||O,[V,$]=k.useState(String(n??S.value??"")),D=typeof j=="boolean"?j:typeof R=="boolean"?!R:!!e,M=ge("box-border bg-[var(--color-ds-background-page)] w-full rounded-lg border outline-none transition","placeholder-[var(--color-ds-text-secondary)] text-[var(--color-ds-text-primary)]",gO[o],vO[o],u?"border-[var(--color-ds-border-error)]":"border-[var(--color-ds-border-default)]",S.disabled&&"bg-[var(--color-ds-background-disabled)] border-[var(--color-ds-border-muted)] text-[var(--color-ds-text-secondary)] cursor-not-allowed"),z=y?"pl-9":"",te=E?"pr-9":"",Q=N=>{var I;typeof m=="number"&&N.target.value.length>m||($(N.target.value),(I=S.onChange)==null||I.call(S,N))},ne=l&&(l.includes(" ")||l.startsWith("w-")||l.startsWith("max-w-")||l.startsWith("min-w-")),ae=ne?void 0:{width:l},K=ge("flex flex-col",ne&&l,h);return k.useEffect(()=>{n!==void 0&&$(String(n??""))},[n]),e&&t?s.jsx(mt,{name:t,control:e,rules:r,defaultValue:n??"",render:({field:N,fieldState:I})=>{var re;return s.jsxs("div",{className:K,style:ae,children:[!c&&i&&s.jsx(Gt,{id:_,text:i,size:o,prefixIcon:b,suffixIcon:v,info:g,infoHeader:x,infoAriaLabel:w}),s.jsxs("div",{className:"flex items-stretch gap-2",children:[s.jsxs("div",{className:"relative w-full",children:[y&&s.jsx("span",{className:"absolute left-2 top-2.5",children:s.jsx(yt,{component:y,size:o,className:"text-[var(--color-ds-text-secondary)]"})}),s.jsx("textarea",{id:_,"aria-invalid":!!I.error,className:ge(M,z,te),maxLength:m,...N,placeholder:S.disabled?"":S.placeholder,onChange:G=>{N.onChange(G),f&&$(G.target.value)}}),E&&s.jsx("span",{className:"absolute right-2 top-2.5",children:s.jsx(yt,{component:E,size:o,className:"text-[var(--color-ds-text-secondary)]"})})]}),p?s.jsx("div",{className:"shrink-0",children:p}):null]}),s.jsxs("div",{className:"flex justify-between pt-1 h-[1em]",children:[D?I.error?s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:I.error.message}):s.jsx("span",{"aria-hidden":"true",children:" "}):I.error?s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:I.error.message}):s.jsx("span",{"aria-hidden":"true",children:" "}),f&&typeof m=="number"&&s.jsxs("span",{className:"text-xs text-[var(--color-ds-text-secondary)]",children:[((re=N.value)==null?void 0:re.length)??0,"/",m]})]})]})}}):s.jsxs("div",{className:K,style:ae,children:[!c&&i&&s.jsx(Gt,{id:_,text:i,size:o,prefixIcon:b,suffixIcon:v,info:g,infoHeader:x,infoAriaLabel:w}),s.jsxs("div",{className:"flex items-stretch gap-2",children:[s.jsxs("div",{className:"relative w-full",children:[y&&s.jsx("span",{className:"absolute left-2 top-2.5",children:s.jsx(yt,{component:y,size:o,className:"text-[var(--color-ds-text-secondary)]"})}),s.jsx("textarea",{id:_,className:ge(M,z,te),value:V,onChange:Q,maxLength:m,...S,placeholder:S.disabled?"":S.placeholder}),E&&s.jsx("span",{className:"absolute right-2 top-2.5",children:s.jsx(yt,{component:E,size:o,className:"text-[var(--color-ds-text-secondary)]"})})]}),p?s.jsx("div",{className:"shrink-0",children:p}):null]}),s.jsxs("div",{className:"flex justify-between pt-1 h-[1em]",children:[D?u&&d?s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:d}):s.jsx("span",{"aria-hidden":"true",children:" "}):u&&d?s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)]",children:d}):s.jsx("span",{"aria-hidden":"true",children:" "}),f&&typeof m=="number"&&s.jsxs("span",{className:"text-xs text-[var(--color-ds-text-secondary)]",children:[V.length,"/",m]})]})]})}const bO={sm:"w-4 h-4",md:"w-5 h-5",lg:"w-6 h-6"},xO={sm:"w-3 h-3",md:"w-3.5 h-3.5",lg:"w-4 h-4"};function tt({control:e=null,name:t,rules:r,defaultValue:n=!1,label:o,labelHidden:l=!1,disabled:i=!1,size:c="sm",className:u,hasError:d=!1,errorMessage:m="",reserveErrorSpace:f,disableErrorPlaceholder:h,checked:p,indeterminate:b,onChange:v}){const g=ge("text-[var(--color-ds-text-primary)] text-ds-sm",i&&"text-[var(--color-ds-text-secondary)]",l&&"sr-only"),x=typeof f=="boolean"?f:typeof h=="boolean"?!h:!!e,w=(y,E,j)=>{const R=d||!!j,A=(j==null?void 0:j.message)||m,S=ge("inline-flex items-center justify-center rounded-[6px] border transition-all duration-150",bO[c],"bg-[var(--color-ds-background-page)]","border-[var(--color-ds-border-default-50)]","shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-default)20%,transparent)]","peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-[var(--color-ds-border-default)]","hover:border-[var(--color-ds-border-default)]",(y||b)&&"bg-[var(--color-ds-button-primary-bg)] border-[var(--color-ds-button-primary-bg)]",R&&"border-[var(--color-ds-border-error)] shadow-[0_0_0_1px_color-mix(in_srgb,var(--color-ds-border-error)30%,transparent)]",i&&"opacity-60 cursor-not-allowed"),O=ge(xO[c],"text-[var(--color-ds-button-primary-text)]","transition-all duration-150",y||b?"opacity-100 scale-100":"opacity-0 scale-75");return s.jsxs("div",{className:ge("flex flex-col gap-1",u),children:[k.createElement(typeof o=="string"?"label":"div",{className:ge("inline-flex items-center gap-2 cursor-pointer select-none",i&&"cursor-not-allowed")},s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"relative inline-flex items-center justify-center",children:[s.jsx("input",{id:t,type:"checkbox",className:"peer sr-only",checked:y,ref:_=>{_&&(_.indeterminate=!!b)},onChange:_=>E(_.target.checked),disabled:i}),s.jsx("span",{"aria-hidden":!0,className:S,children:b?s.jsx("div",{className:"bg-white h-0.5 w-[60%] rounded-full"}):s.jsx(vi,{className:O})})]}),o&&s.jsx("span",{className:g,children:o})]})),x?s.jsx("div",{className:"h-[1em]",children:R&&A?s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:A}):s.jsx("span",{"aria-hidden":"true",children:" "})}):R&&A?s.jsx("div",{className:"pt-1",children:s.jsx("span",{className:"text-xs text-[var(--color-ds-text-error)] h-[1em]",children:A})}):null]})};return e?s.jsx(mt,{name:t||"",control:e,rules:r,defaultValue:n,render:({field:y,fieldState:E})=>{const j=E.error;return w(!!y.value,R=>y.onChange(R),j)}}):w(!!p,y=>v==null?void 0:v(y))}function Ri({name:e,control:t,searchFn:r,resolveByValue:n,label:o,size:l="sm",width:i="100%",disabled:c=!1,searchMode:u="button",minChars:d=3,debounceMs:m=600,labelPrefixIcon:f,labelSuffixIcon:h,prefixIcon:p,suffixIcon:b,reserveErrorSpace:v,disableErrorPlaceholder:g}){const x=Tr(),{watch:w,getValues:y,setValue:E}=x,j=mi({control:t,name:e}),[R,A]=k.useState([]),[S,O]=k.useState(!1),[_,V]=k.useState(!1),[$,D]=k.useState(""),M=k.useRef(null),z=k.useRef(null),te=k.useRef(!1),Q=k.useRef(!1),ne=k.useRef(!0),ae=k.useMemo(()=>{const ce=new Map;for(const ie of R)ce.set(String(ie.value).trim(),ie.label??"");return ce},[R]),K=async ce=>{const ie=(ce??"").trim();if(!ie){A([]),V(!1);return}O(!0);try{const ve=await r(ie,{watch:w,getValues:y});A(ve??[]),V(!0)}finally{O(!1)}};k.useEffect(()=>{function ce(ie){M.current&&!M.current.contains(ie.target)&&V(!1)}if(_)return document.addEventListener("mousedown",ce),()=>document.removeEventListener("mousedown",ce)},[_]);const[N,I]=k.useState({});k.useEffect(()=>{if(te.current)return;const ie=(j?String(j):"").trim();if(!ie){$!==""&&D(""),V(!1);return}const ve=ae.get(ie);if(ve){$!==ve&&(D(ve),ne.current=!0);return}const ue=N[ie];if(ue){$!==ue&&(D(ue),ne.current=!0);return}let xe=!1;return n?($!==ie&&D(ie),(async()=>{try{const C=await n(ie,{watch:w,getValues:y});if(xe)return;if(C){const q=C.label??String(C.value);I(ee=>{const W={...ee,[ie]:q};return D(q),ne.current=!0,W})}else $!==ie&&(D(ie),ne.current=!0)}catch{!xe&&$!==ie&&(D(ie),ne.current=!0)}})()):$!==ie&&(D(ie),ne.current=!0),()=>{xe=!0}},[j,ae,N,n,w,y]),k.useEffect(()=>{if(u!=="debounced"||c)return;if(ne.current){ne.current=!1;return}if(!Q.current)return;z.current&&(window.clearTimeout(z.current),z.current=null);const ce=($||"").trim();return ce.length>=d?z.current=window.setTimeout(()=>{K(ce)},m):(A([]),V(!1)),()=>{z.current&&(window.clearTimeout(z.current),z.current=null)}},[$,u,d,m,c]);const re=l==="sm"?"text-ds-sm":l==="md"?"text-ds-md":"text-ds-lg",G=l==="sm"?"h-6":l==="md"?"h-10":"h-12",X=ce=>{if(c)return;const ie=($||"").trim();ce.key==="Enter"&&(ce.preventDefault(),u==="debounced"?ie.length>=d&&K(ie):K(ie)),ce.key==="Escape"&&V(!1)},fe=i&&(i.includes(" ")||i.startsWith("w-")||i.startsWith("max-w-")||i.startsWith("min-w-")),le=fe?void 0:{width:i},he=`relative flex flex-col ${fe?i:""}`;return s.jsx(mt,{name:e,control:t,render:({field:ce,fieldState:ie})=>{var ve;return s.jsxs("div",{ref:M,className:he,style:le,children:[o&&s.jsx(Gt,{id:e,text:o,size:l,prefixIcon:f,suffixIcon:h}),s.jsx(ke,{className:u==="button"?"rounded-r-none":void 0,type:"text",size:l,width:"100%",value:$,prefixIcon:p,suffixIcon:b,onChange:ue=>{const xe=ue.target.value;te.current=!0,Q.current=!0,D(xe),(j?String(j):"").trim()&&E(e,"",{shouldDirty:!0})},onKeyDown:X,onBlur:()=>{te.current=!1},disabled:c,hasError:ie.invalid,errorMessage:(ve=ie.error)==null?void 0:ve.message,reserveErrorSpace:v,disableErrorPlaceholder:g,onFocus:()=>{if(te.current=!0,u==="button"&&Q.current){const ue=($||"").trim();ue&&K(ue)}},suffixButton:u==="button"?s.jsx(me,{type:"button",className:"!rounded-l-none",size:l,variant:"primary",onClick:()=>K(($||"").trim()),disabled:c,children:"Buscar"}):void 0}),S&&s.jsx("div",{className:"absolute top-14 left-0 right-0 z-10",children:s.jsx(pr,{width:"100%",height:l==="sm"?"1.5rem":l==="md"?"2.5rem":"3rem",variant:"rect",className:"rounded-lg"})}),_&&!S&&R.length>0&&s.jsx("ul",{className:`
92
92
  absolute top-14 left-0 right-0
93
93
  border-[var(--color-ds-border-default)]
94
94
  rounded-lg bg-[var(--color-ds-background-page)]
95
95
  shadow-lg ${re} max-h-48 overflow-auto z-10
96
96
  `,children:R.map(ue=>s.jsx("li",{className:`px-2 ${G} flex items-center cursor-pointer
97
97
  text-[var(--color-ds-text-primary)]
98
- hover:bg-[var(--color-ds-background-surface)]`,onClick:()=>{const xe=String(ue.value).trim();E(e,xe,{shouldDirty:!0,shouldValidate:!0}),D(ue.label??xe),te.current=!1,Q.current=!1,V(!1)},children:ue.label},String(ue.value)))})]})}})}const qn=(e,t)=>e[t],n0=e=>e instanceof Date?e.getTime():e;function wO(e,t,r){const n=n0(e),o=n0(t);return typeof n=="number"&&typeof o=="number"||typeof n=="string"&&typeof o=="string"?r==="gt"?n>o:r==="gte"?n>=o:r==="lt"?n<o:n<=o:!1}function Ao(e,t){if(!e)return!1;switch(e.op){case"eq":return qn(t,e.field)===e.value;case"neq":return qn(t,e.field)!==e.value;case"in":return e.values.includes(qn(t,e.field));case"notIn":return!e.values.includes(qn(t,e.field));case"gt":case"gte":case"lt":case"lte":return wO(qn(t,e.field),e.value,e.op);case"and":return e.rules.every(r=>Ao(r,t));case"or":return e.rules.some(r=>Ao(r,t));case"always":return!!e.value;default:return!1}}function Ci(e){return!!e&&(typeof e=="function"||typeof e=="object")}function An(e,t){const r=t==="outline"?Cn:Sn,n=r==null?void 0:r[e];return Ci(n)?n:null}const yO=Object.entries(Cn).filter(([e,t])=>e.endsWith("Icon")&&Ci(t)).map(([e,t])=>({name:e,Icon:t,style:"outline"})),jO=Object.entries(Sn).filter(([e,t])=>e.endsWith("Icon")&&Ci(t)).map(([e,t])=>({name:e,Icon:t,style:"solid"})),kO=oi||ai||(e=>s.jsx("svg",{...e})),Wr=({value:e,onChange:t,buttonLabel:r,disabled:n,className:o})=>{const[l,i]=k.useState(!1),[c,u]=k.useState(""),[d,m]=k.useState((e==null?void 0:e.style)??"outline"),f=e&&An(e.name,e.style)||kO,h=k.useCallback((b,v)=>{const g=An(b,v);t==null||t({name:b,style:v},g),i(!1)},[t]),p=k.useCallback(()=>{t==null||t(void 0,void 0),i(!1)},[t]);return s.jsxs(s.Fragment,{children:[s.jsx(me,{size:"sm",variant:"outline",shape:"circle",className:`rounded-full p-0 w-8 h-8 inline-flex items-center justify-center ${o??""}`,disabled:n,onClick:()=>i(!0),ariaLabel:"Elegir icono",title:r||"Elegir icono",children:s.jsx(f,{className:"h-4 w-4"})}),s.jsx(St,{isOpen:l,onClose:()=>i(!1),title:"Seleccionar icono",children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(ke,{labelHidden:!0,placeholder:"Buscar icono (p. ej. 'user', 'arrow', 'calendar'...)",value:c,onChange:b=>u(b.target.value)}),s.jsx(xr,{options:[{label:"Outline",value:"outline"},{label:"Solid",value:"solid"}],value:d,onChange:b=>m(b),children:{outline:s.jsx(a0,{items:yO,query:c,onPick:b=>h(b,"outline"),onClear:p}),solid:s.jsx(a0,{items:jO,query:c,onPick:b=>h(b,"solid"),onClear:p})}})]})})]})},a0=({items:e,query:t,onPick:r,onClear:n})=>{const o=k.useMemo(()=>{if(!t.trim())return e;const i=t.trim().toLowerCase().replace(/\s+/g,"");return e.filter(c=>c.name.toLowerCase().includes(i))},[e,t]),l=et;return s.jsx("div",{className:"custom-scroll max-h-[60vh] overflow-y-auto",children:s.jsxs("div",{className:"grid gap-2 grid-cols-3 sm:grid-cols-4 md:grid-cols-6",children:[s.jsxs("button",{type:"button",onClick:n,className:"group w-full aspect-square border border-[var(--color-ds-border-default-50)] rounded-lg p-1 bg-[var(--color-ds-background-page)] hover:bg-[var(--color-ds-background-accent)]/5 hover:border-[var(--color-ds-border-default)] transition focus:outline-none",title:"Ninguno","aria-label":"Quitar icono",children:[s.jsx("div",{className:"h-full w-full flex items-center justify-center",children:l?s.jsx(l,{className:"w-6 h-6"}):s.jsx("span",{className:"text-ds-lg",children:"×"})}),s.jsx("div",{className:"mt-1 text-center",children:s.jsx("span",{className:"block text-[11px] leading-tight text-[var(--color-ds-text-secondary)] truncate",children:"Ninguno"})})]}),(o.length===0?e:o).map(({name:i,Icon:c})=>s.jsxs("button",{type:"button",onClick:()=>r(i),className:"group w-full aspect-square border border-[var(--color-ds-border-default-50)] rounded-lg p-1 bg-[var(--color-ds-background-page)] hover:bg-[var(--color-ds-background-accent)]/5 hover:border-[var(--color-ds-border-default)] transition focus:outline-none",title:i,"aria-label":`Elegir ${i}`,children:[s.jsx("div",{className:"h-full w-full flex items-center justify-center",children:s.jsx(c,{className:"w-6 h-6 text-[var(--color-ds-text-primary)]"})}),s.jsx("div",{className:"mt-1 text-center",children:s.jsx("span",{className:"block text-[11px] leading-tight text-[var(--color-ds-text-secondary)] truncate",children:i.replace(/Icon$/,"")})})]},i))]})})};function st(e,t,r=""){if(!t)return r;if(typeof t=="object"&&t!==null){if(t.type==="complex"){const o=[];return t.header&&o.push(`<strong>${t.header}</strong>`),t.template&&o.push(t.template),o.join("<br/>")||r}return r}return e(t,{defaultValue:t})}const EO=({schema:e,renderField:t})=>{var v,g,x;const{control:r}=Tr(),{fields:n,append:o,remove:l}=Zx({control:r,name:e.name}),{label:i,addLabel:c="Añadir",items:u,disabled:d,validation:m,className:f}=e,{formState:{errors:h}}=Tr(),p=((g=(v=h[e.name])==null?void 0:v.root)==null?void 0:g.message)||((x=h[e.name])==null?void 0:x.message),b=typeof p=="string"?p:void 0;return s.jsxs("div",{className:ge("space-y-3",f),children:[i&&s.jsx("div",{className:"flex items-center justify-between",children:s.jsx("label",{className:"block text-ds-sm font-medium text-[var(--color-ds-text-primary)]",children:i})}),s.jsx("div",{className:"space-y-4",children:n.map((w,y)=>{const E=`${e.name}.${y}`;return s.jsxs("div",{className:"relative rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)] p-4 group",children:[!d&&s.jsx("div",{className:"absolute top-2 right-2",children:s.jsx(me,{size:"xs",variant:"ghost",className:"text-[var(--color-ds-text-error)] hover:bg-[var(--color-ds-background-error-hover)]",onClick:()=>l(y),title:"Eliminar fila",ariaLabel:"Eliminar fila",children:s.jsx(pt,{className:"w-4 h-4"})})}),s.jsx("div",{className:"grid grid-cols-1 gap-4",children:u.map((j,R)=>s.jsx(k.Fragment,{children:t(j,E)},R))})]},w.id)})}),n.length===0&&s.jsx("div",{className:"text-ds-sm text-[var(--color-ds-text-secondary)] italic p-2 border border-dashed border-[var(--color-ds-border-default-50)] rounded bg-[var(--color-ds-background-subtle)]",children:"No hay elementos."}),b&&s.jsx("p",{className:"text-xs text-[var(--color-ds-text-error)]",children:b}),!d&&s.jsxs(me,{type:"button",variant:"outline",size:"sm",onClick:()=>{o({})},children:[s.jsx(Jt,{className:"w-4 h-4 mr-1"}),c]})]})};function o0(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,24)}function RO(e){return e.replace(/(.{4})/g,"$1 ").trim()}function ts({label:e,labelHidden:t,placeholder:r="ES00 0000 0000 0000 0000 0000",size:n="sm",value:o,onChange:l,onBlur:i,disabled:c,required:u,reserveErrorSpace:d=!0,error:m,errorMessage:f,hasError:h,id:p,name:b,className:v,"aria-label":g}){const x=k.useMemo(()=>o0(o),[o]),w=k.useMemo(()=>RO(x),[x]),y=E=>{const j=o0(E.target.value);l(j)};return s.jsx(ke,{id:p,name:b,label:e,labelHidden:t,placeholder:r,size:n,value:w,onChange:y,onBlur:i,disabled:c,required:u,hasError:h||!!m||!!f,errorMessage:f||m,reserveErrorSpace:d,prefixIcon:Wl,className:v,"aria-label":g,inputMode:"text",autoComplete:"off",spellCheck:!1})}function s0(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,9)}function Si({label:e,labelHidden:t,placeholder:r="12345678A",size:n="sm",value:o,onChange:l,onBlur:i,disabled:c,required:u,reserveErrorSpace:d=!0,error:m,errorMessage:f,hasError:h,id:p,name:b,className:v,"aria-label":g}){const{t:x}=gt(),w=k.useMemo(()=>s0(o),[o]),y=k.useMemo(()=>w,[w]),E=j=>{const R=s0(j.target.value);l(R)};return s.jsx(ke,{id:p,name:b,label:e,labelHidden:t,placeholder:r,size:n,value:y,onChange:E,onBlur:i,disabled:c,required:u,hasError:h||!!m||!!f,errorMessage:f||m,prefixIcon:Ql,className:v,"aria-label":g,inputMode:"text",autoComplete:"off",spellCheck:!1,reserveErrorSpace:d})}function l0(e){if(e){if(typeof e=="string")try{return JSON.parse(e)}catch{return}if(typeof e=="object")return e}}function CO(e,t){var r;return Array.isArray(e)?e.length&&typeof e[0]=="object"&&"value"in e[0]?t?e.map(n=>n.value):((r=e[0])==null?void 0:r.value)??"":t?e:e[0]??"":e&&typeof e=="object"&&"value"in e?e.value:e??(t?[]:"")}const SO=e=>e.type!=="inputGroup"&&e.type!=="button";function NO(){try{return At()??void 0}catch{return}}function Mt(e){if(!e||typeof e!="object")return;const t=e.name,r=e.style;if(!(!t||!r))return An(t,r)||void 0}function r1({schema:e,resolver:t,serviceRegistry:r,activeVariantId:n}){var Y;const{layout:o,fields:l=[],onSubmit:i,successMessage:c,errorMessage:u,footerButtons:d,defaultValues:m,loadDefaultValues:f,validationSchema:h}=e,{show:p}=Vr(),{t:b}=gt(),v=NO(),g=r??((Y=v==null?void 0:v.services)==null?void 0:Y.registry)??void 0,x=k.useMemo(()=>{if(t)return t;try{const L=h??ki(e);return wi(L)}catch{return}},[t,e,h]),w=gi({resolver:x,mode:"onBlur",reValidateMode:"onChange",defaultValues:m??{}}),y=Jr(L=>L.setRuntimeState),E=Jr(L=>L.systemContext),j=Jr(L=>L.formValues);k.useEffect(()=>{y({isActive:!0});let L=!1;return(async()=>{const Z=e.defaultSource,F=e.onloadEndpoint;let T={};if(e.variables&&Array.isArray(e.variables)&&(e.variables.forEach(P=>{P.type==="constant"&&(T[P.key]=P.value)}),e.variables.forEach(P=>{if(P.type==="computed"&&P.value)try{const U=new Function("ctx",`return (${P.value});`);T[P.key]=U(T)}catch(U){console.warn(`[FormRenderer] Error evaluating computed variable "${P.key}":`,U),T[P.key]=null}})),Z)try{const P=g==null?void 0:g[Z];if(P){const U=typeof P=="function"?await P():P;U&&typeof U=="object"&&(T={...T,...U})}}catch{}y({systemContext:{...T}});const B=[];if(F&&B.push(F),e.onloadEndpoints&&Array.isArray(e.onloadEndpoints)&&B.push(...e.onloadEndpoints),B.length>0){const P=async J=>{if(!J)return{};try{const oe=g==null?void 0:g[J.key];if(!oe)return console.warn("[FormRenderer] Provider not found for key:",J.key),{};const de=Ar(J.parameters,(()=>({})),{...T,ACTIVE_VARIANT:e.activeVariantId});console.log(`[FormRenderer] Calling ${J.key} with params:`,de);const pe=await Promise.resolve(oe(de,{getValues:(()=>({})),watch:(()=>{}),params:de,...T}));let be=pe;if(typeof pe=="string")try{be=JSON.parse(pe)}catch(je){console.warn("[FormRenderer] Failed to parse onload response string",je)}return be&&typeof be=="object"?be:(console.warn("[FormRenderer] OnLoad response is not an object:",be),{})}catch(oe){return console.error("Error in onloadEndpoint",oe),{}}};(await Promise.all(B.map(P))).forEach(J=>{J&&typeof J=="object"&&(T={...T,...J})}),L||y({systemContext:{...T}})}if(!L&&Object.keys(T).length>0){const P={...e.defaultValues??{}};Object.assign(P,T);const U=e.fields.map(J=>J.name);Object.keys(T).forEach(J=>{const oe=J.toLowerCase(),de=U.find(pe=>pe.toLowerCase()===oe);de&&(P[de]===void 0||P[de]==="")&&(P[de]=T[J])}),w.reset(P)}})(),()=>{L=!0,y({isActive:!1,systemContext:{},formValues:{}})}},[e,g,w.reset]);const{control:R,reset:A,handleSubmit:S,formState:{errors:O,isSubmitting:_}}=w,[V,$]=k.useState(!1);k.useEffect(()=>{f&&($(!0),f().then(L=>A(L)).finally(()=>$(!1)))},[f,A]);const D=k.useMemo(()=>(l??[]).filter(SO),[l]),{loadingCount:M,optionsMap:z}=e1(D),[te,Q]=k.useState({}),[ne,ae]=k.useState(0);k.useEffect(()=>{let L;const Z=w.watch(()=>{clearTimeout(L),L=setTimeout(()=>{ae(F=>F+1)},500)});return()=>{Z.unsubscribe(),clearTimeout(L)}},[w.watch]);const K=k.useRef(g);k.useEffect(()=>{K.current=g},[g]);const N=k.useRef({});k.useEffect(()=>{let L=!0;return(async()=>{const F=await Promise.all(D.filter(B=>B.type==="select"&&(B.optionSource||B.endpointConfig)).map(async B=>{var be;const P=B.name,U=Co(B.optionSource,B.endpointConfig);if(!U)return[P,[]];const J=B.endpointConfig?Ar(B.endpointConfig.parameters,w.getValues,E):{...E,...w.getValues()},oe=l0(B.adapterCtx??B.optionAdapterCtx),de=JSON.stringify({key:U,resolvedParams:J,ctx:oe});N.current[P],N.current[P]=de;const pe=(be=K.current)==null?void 0:be[U];if(typeof pe!="function")return[P,[]];try{const je=await Promise.resolve(pe(J,{getValues:w.getValues,watch:w.watch,ctx:oe,params:J,...E})),ye=Array.isArray(je)?je:[];return[P,ye]}catch{return[P,[]]}}));if(!L)return;const T={};for(const[B,P]of F)T[B]=P;Q(B=>Object.entries(T).some(([U,J])=>{const oe=B[U];return!oe||oe.length!==J.length?!0:JSON.stringify(oe)!==JSON.stringify(J)})?T:B)})(),()=>{L=!1}},[ne,JSON.stringify(D.map(L=>({n:L.name,os:L.optionSource??null,ec:L.endpointConfig??null,ctx:L.adapterCtx??L.optionAdapterCtx??null}))),E]),k.useEffect(()=>{let L=!0;return(async()=>{for(const F of D){if(F.type!=="select")continue;const T=F.name,B=F.defaultSource;if(!B)continue;const P=w.getValues(T);if(!(P==null||(Array.isArray(P)?P.length===0:P==="")))continue;const J=g==null?void 0:g[B];if(typeof J=="function")try{const oe=l0(F.adapterCtx??F.optionAdapterCtx),de=await Promise.resolve(J("",{getValues:w.getValues,watch:w.watch,ctx:oe}));if(!L)return;const pe=CO(de,!!F.multiple);w.setValue(T,pe,{shouldDirty:!0,shouldTouch:!0})}catch{}}})(),()=>{L=!1}},[g,w.getValues,w.setValue,JSON.stringify(D.map(L=>({n:L.name,ds:L.defaultSource??null,mult:!!L.multiple})))]);const I=Y5(l),re=t1(l,R),G=k.useMemo(()=>{const L={};return o.forEach((Z,F)=>{Z.type==="tabs"&&(L[F]=Z.tabs[0].key)}),L},[o]),[X,fe]=k.useState(G),[le,he]=k.useState({}),[ce,ie]=k.useState({}),ve=k.useRef({}),ue=k.useCallback(async()=>{const L={},Z=l.filter(T=>{var P,U,J;const B=T;return((P=B.visibleWhen)==null?void 0:P.endpoint)||((U=B.disabledWhen)==null?void 0:U.endpoint)||((J=B.clearWhen)==null?void 0:J.endpoint)});if(Z.length===0)return;(await Promise.all(Z.map(async T=>{const B=T,P=B.name,U={};for(const J of["visibleWhen","disabledWhen","clearWhen"]){const oe=B[J];if(oe!=null&&oe.enabled&&oe.endpoint){const de=oe.endpoint.key,pe=g==null?void 0:g[de];if(typeof pe=="function")try{const be=Ar(oe.endpoint.parameters,w.getValues,E),je=await Promise.resolve(pe(be,{getValues:w.getValues,watch:w.watch,params:be,...E}));U[J]=typeof je=="object"&&je!==null?!!je.ok:!!je}catch(be){console.error(`Error evaluando regla backend para ${P}.${J}:`,be),U[J]=!1}}}return{fieldName:P,res:U}}))).forEach(({fieldName:T,res:B})=>{Object.keys(B).length>0&&(L[T]=B)}),he(L)},[l,g,w,E]),xe=k.useCallback(async L=>{var U;const Z=L,F=Z.name,T=Z.asyncValidation.endpoint,B=T.key,P=g==null?void 0:g[B];if(typeof P=="function"){ie(J=>({...J,[F]:{...J[F],loading:!0}}));try{const J=Ar(T.parameters,w.getValues,E),oe=await Promise.resolve(P(J,{getValues:w.getValues,watch:w.watch,params:J,...E})),de=typeof oe=="object"&&oe!==null?!!oe.ok:!!oe,pe=typeof oe=="object"&&oe!==null?oe.message:void 0;ie(be=>({...be,[F]:{ok:de,message:pe,loading:!1}})),de?((U=w.formState.errors[F])==null?void 0:U.type)==="manual"&&w.clearErrors(F):w.setError(F,{type:"manual",message:pe||"Validación externa fallida"})}catch{ie(oe=>({...oe,[F]:{ok:!1,message:"Error de conexión",loading:!1}}))}}},[g,w,E]),C=k.useCallback(async(L,Z,F)=>{const T=l.filter(B=>{var oe,de;const P=B,U=(oe=P.asyncValidation)==null?void 0:oe.endpoint;if(!U)return!1;const J=U.trigger||P.asyncValidation.trigger||"onBlur";if(F&&J!==F&&!(J==="auto"&&F==="onChange"))return!1;if(Z&&F!=="onSubmit"){const pe=P.name===Z,be=Object.values(U.parameters||{}).some(ye=>ye.fieldRef===Z),je=(de=U.triggerFields)==null?void 0:de.includes(Z);if(!pe&&!be&&!je)return!1}return!0});for(const B of T){const P=B,U=P.name,J=P.asyncValidation.endpoint;if(F==="onChange"&&J.trigger==="debounced"){ve.current[U]&&clearTimeout(ve.current[U]),ve.current[U]=setTimeout(()=>xe(B),J.debounceMs||300);continue}await xe(B)}},[l,xe]);k.useEffect(()=>{ue();const L=w.watch((Z,{name:F})=>{ue(),F&&C(Z,F,"onChange")});return()=>{L.unsubscribe(),Object.values(ve.current).forEach(Z=>Z&&clearTimeout(Z))}},[ue,C,w]);const q=k.useCallback((L,Z,F,T)=>{var P;if(!(L!=null&&L.enabled))return Z;let B=!0;if(L.rule)try{const U={...w.getValues(),...E,ACTIVE_VARIANT:n};B=!!Ao(L.rule,U)}catch{B=Z}if(B&&F&&T&&L.endpoint){const U=(P=le[F])==null?void 0:P[T];if(U===void 0)return!1;B=U}return B},[w,le,n]),ee=k.useMemo(()=>l.map(L=>L).filter(L=>{var Z;return((Z=L.clearWhen)==null?void 0:Z.enabled)&&(L.clearWhen.rule||L.clearWhen.endpoint)}).map(L=>({name:L.name,container:L.clearWhen})),[l]);k.useEffect(()=>{if(!ee.length)return;const L=F=>{ee.forEach(({name:T,container:B})=>{try{if(q(B,!1,T,"clearWhen")){const U=B.clearTo??"";F[T]!==U&&w.setValue(T,U,{shouldDirty:!0,shouldValidate:!0})}}catch{}})};L(w.getValues());const Z=w.watch(()=>L(w.getValues()));return()=>{var F;return(F=Z==null?void 0:Z.unsubscribe)==null?void 0:F.call(Z)}},[w,ee,q]);const W=k.useCallback(L=>{const Z=st(b,L);if(!Z)return"";const F={...E,...j,sys:E,form:j};return Sl(Z,F)},[b,E,j]),H=k.useCallback((L,Z)=>{var Oe,_e,ze,nt;let F;if(typeof L=="string"){if(F=I[L],!F){const Se=(l??[]).find(Ne=>(Ne==null?void 0:Ne.name)===L);if(Se)F=Se;else return null}}else F=L;const T=F.name,B=T?Z?`${Z}.${T}`:T:void 0,P=F.visibleWhen;if(!q(P,!0,T,"visibleWhen"))return null;let J=!!F.disabled;const oe=F.disabledWhen,de=q(oe,!1,T,"disabledWhen");if(oe!=null&&oe.enabled&&(J=de),!(oe!=null&&oe.enabled)&&T&&re[T]&&(J=!0),F.type==="search"){const Se=typeof F.searchFn=="function",Ne=Co(F.searchSource,F.endpointConfig),Me=async vt=>{if(Se)return F.searchFn(vt,{getValues:w.getValues,watch:w.watch});if(Ne){const Ze=F.endpointConfig?Ar(F.endpointConfig.parameters,w.getValues,E):{...E,...w.getValues()},qe=g==null?void 0:g[Ne];if(typeof qe=="function")return await qe(vt,{getValues:w.getValues,watch:w.watch,params:Ze,...E});if(Array.isArray(qe))return qe}return[]},Ae={};F.searchMode&&(Ae.searchMode=F.searchMode),F.minChars&&(Ae.minChars=F.minChars),F.debounceMs&&(Ae.debounceMs=F.debounceMs),F.resolveByValue&&(Ae.resolveByValue=F.resolveByValue);const Ie=Mt(F.labelIconLeft??F.labelPrefixIcon),Be=Mt(F.labelIconRight??F.labelSuffixIcon),Ve=Mt(F.prefixIcon),De=Mt(F.suffixIcon);return s.jsx(Ri,{name:B,control:R,searchFn:Me,label:W(F.label),size:F.size,width:F.width,disabled:J||_,labelPrefixIcon:Ie,labelSuffixIcon:Be,prefixIcon:Ve,suffixIcon:De,...Ae},B)}if(F.type==="inputGroup"){const Se=F,Ne=(Se.inputs??[]).map(Me=>{var wr,Dt;const Ae=typeof Me=="string"?I[Me]??(l??[]).find(lr=>(lr==null?void 0:lr.name)===Me):Me;if(!Ae)return null;const Ie=Ae.name,Be=Z?`${Z}.${Ie}`:Ie,Ve=Ae.disabledWhen;let De=!!Ae.disabled;const vt=q(Ve,!1,Ie,"disabledWhen");Ve!=null&&Ve.enabled&&(De=vt),!(Ve!=null&&Ve.enabled)&&re[Ie]&&(De=!0);const Ze=Mt(Ae.labelIconLeft??Ae.labelPrefixIcon),qe=Mt(Ae.labelIconRight??Ae.labelSuffixIcon),He=Mt(Ae.prefixIcon),at=Mt(Ae.suffixIcon),Qt={name:Be,control:R,label:W(Ae.label),size:Ae.size,width:Ae.width,placeholder:W(Ae.placeholder),hasError:!!(O[Be]||Z&&((wr=O[Z])!=null&&wr[Ie])),errorMessage:st(b,(Dt=O[Be])==null?void 0:Dt.message),loading:V,disabled:De||_,suffixButton:Ae.suffixButton,reserveErrorSpace:!0,labelPrefixIcon:Ze,labelSuffixIcon:qe,prefixIcon:He,suffixIcon:at};return Ae.type==="select"?{...Qt,options:Ae.options??te[Ie]??z[Ie]??[],loadOptions:Ae.options||Ae.optionSource?void 0:Ae.loadOptions}:{...Qt,type:Ae.type}}).filter(Boolean);return s.jsx(Ei,{groupLabel:st(b,Se.groupLabel),inputs:Ne,separator:Se.separator,useSeparator:Se.useSeparator,className:Se.className,showVisibleLabel:Se.showVisibleLabel,size:Se.size},`inputGroup_${B??Se.groupLabel??"group"}`)}if(F.type==="button"){const Se=F,Ne=Se.icon,Me=Ne&&typeof Ne=="object"&&Ne.name&&Ne.style?Mt(Ne):void 0;return s.jsx("div",{className:"self-center",children:s.jsx(me,{type:"button",variant:Se.variant,size:Se.size,width:Se.width,icon:Me,iconPosition:Se.iconPosition,ariaLabel:W(Se.ariaLabel),onClick:Se.onClick,disabled:J||_,children:W(Se.label)})},B??Se.label)}if(F.type==="array"){const Se=F;return s.jsx(EO,{schema:{...Se,name:B},renderField:H},B)}const pe=F.suffixButton,be=typeof pe=="string"?H(pe):pe,je=Mt(F.labelIconLeft??F.labelPrefixIcon),ye=Mt(F.labelIconRight??F.labelSuffixIcon),Fe=Mt(F.prefixIcon),$e=Mt(F.suffixIcon),Ee={name:B,control:R,disabled:J||_,label:W(F.label),size:F.size,width:F.width,placeholder:W(F.placeholder),info:st(b,F.info),suffixButton:be,labelPrefixIcon:je,labelSuffixIcon:ye,prefixIcon:Fe,suffixIcon:$e,onBlur:()=>{C(w.getValues(),T,"onBlur"),l.filter(Ne=>{const Me=Ne;return["visibleWhen","disabledWhen","clearWhen"].some(Ae=>{var Be;const Ie=(Be=Me[Ae])==null?void 0:Be.endpoint;return(Ie==null?void 0:Ie.trigger)==="onBlur"&&Object.values(Ie.parameters||{}).some(Ve=>Ve.fieldRef===T)})}).length>0&&ue()}};switch(F.type){case"select":{const Se=F.options??te[T]??z[T]??[],Ne=Array.isArray(Se)&&Se.length?`${Se.length}:${Se.map(Ae=>String((Ae==null?void 0:Ae.value)??"")).join("|")}`:"0",Me=!F.options&&!F.optionSource&&F.loadOptions;return s.jsx(mt,{name:B,control:R,render:({field:Ae})=>{var Ie;return s.jsx(Ge,{...Ee,value:Ae.value,onChange:Ae.onChange,options:Se,loadOptions:Me||void 0,hasError:!!O[B],errorMessage:st(b,(Ie=O[B])==null?void 0:Ie.message),suffixButton:be,mode:"menu",searchable:!0,searchPlaceholder:b("common.search"),noOptionsText:b("common.noMatches")})}},`${B}:${Ne}`)}case"textarea":return s.jsx(mt,{name:B,control:R,render:({field:Se,fieldState:Ne})=>{var Me;return s.jsx(or,{...Ee,value:Se.value,onChange:Se.onChange,maxLength:F.maxLength,showCounter:!!F.showCounter,hasError:!!Ne.error,errorMessage:st(b,(Me=Ne.error)==null?void 0:Me.message)})}},B);case"file":return s.jsx(xi,{...Ee,defaultValue:[],maxFiles:F.maxFiles,accept:F.accept,hideDropZone:F.hideDropZone,hasError:!!O[B],errorMessage:st(b,(Oe=O[B])==null?void 0:Oe.message)},B);case"checkbox":return s.jsx(tt,{...Ee,defaultValue:!1,hasError:!!O[B],errorMessage:st(b,(_e=O[B])==null?void 0:_e.message),name:B},B);case"date":return s.jsx(Nn,{...Ee,defaultValue:"",showTime:!!F.showTime,hasError:!!O[B],errorMessage:st(b,(ze=O[B])==null?void 0:ze.message)},B);case"optionGroup":return s.jsx(es,{...Ee,options:F.options||[],multiple:F.multiple,vertical:F.vertical,groupLabel:F.groupLabel,defaultValue:F.defaultValue,className:F.width?void 0:"w-full",name:B},B);case"iban":return s.jsx(mt,{name:B,control:R,render:({field:Se,fieldState:Ne})=>{var Me;return s.jsx(ts,{label:W(F.label),placeholder:W(F.placeholder),size:F.size,disabled:J||_,value:Se.value??"",onChange:Se.onChange,onBlur:Se.onBlur,hasError:!!Ne.error,errorMessage:st(b,(Me=Ne.error)==null?void 0:Me.message),name:B})}},B);case"dni":return s.jsx(mt,{name:B,control:R,render:({field:Se,fieldState:Ne})=>{var Me;return s.jsx(Si,{label:W(F.label),placeholder:W(F.placeholder),size:F.size,disabled:J||_,value:Se.value??"",onChange:Se.onChange,onBlur:Se.onBlur,hasError:!!Ne.error,errorMessage:st(b,(Me=Ne.error)==null?void 0:Me.message),name:B})}},B);default:return s.jsx(Xo,{...Ee,type:F.type,loadingDefaults:V,hasError:!!O[B],errorMessage:st(b,(nt=O[B])==null?void 0:nt.message),suffixButton:be,name:B},B)}},[l,I,R,O,_,V,z,te,q,re,w.getValues,w.watch,g,b]);return s.jsx(fi,{...w,children:s.jsxs("form",{noValidate:!0,onSubmit:S(async L=>{await C(L,void 0,"onSubmit"),!(Object.keys(w.formState.errors).length>0)&&(await i(L),p(c??b("ds.form.saveSuccess"),"success"))},L=>{YM(L),p(u??b("ds.form.saveError"),"error")}),className:"space-y-6",children:[o.map((L,Z)=>L.type==="rows"?s.jsx(k.Fragment,{children:L.sections.map((F,T)=>s.jsx("div",{children:s.jsx(rt,{title:W(F.sectionTitle),defaultOpen:F.defaultOpen,children:F.rows.map((B,P)=>s.jsxs("div",{children:[B.title&&s.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:W(B.title)}),s.jsx("div",{className:"flex flex-wrap -mx-2",children:B.columns.map((U,J)=>{var oe;return s.jsx("div",{className:`${U.width} px-2 flex flex-col`,children:s.jsx("div",{className:"",children:U.fields?U.fields.map(de=>H(de)):(oe=U.rows)==null?void 0:oe.map((de,pe)=>s.jsx("div",{className:"mb-1",children:s.jsx("div",{className:"flex flex-wrap -mx-2",children:de.columns.map((be,je)=>{var ye;return s.jsx("div",{className:`${be.width} px-2`,children:(ye=be.fields)==null?void 0:ye.map(Fe=>H(Fe))},je)})})},pe))})},J)})})]},P))})},T))},Z):s.jsx(xr,{options:L.tabs.map(F=>{const T=F.icon?An(F.icon.name,F.icon.style):null;return{label:W(F.label),value:F.key,disabled:F.disabled,icon:T?s.jsx(T,{className:"w-4 h-4"}):null}}),value:X[Z],onChange:F=>fe(T=>({...T,[Z]:F})),children:Object.fromEntries(L.tabs.map(F=>[F.key,s.jsx("div",{className:"space-y-6",children:F.sections.map((T,B)=>s.jsx("div",{className:"mb-6",children:s.jsx(rt,{title:W(T.sectionTitle),defaultOpen:T.defaultOpen,children:T.rows.map((P,U)=>s.jsx("div",{children:s.jsx("div",{className:"flex flex-wrap -mx-2",children:P.columns.map((J,oe)=>{var de;return s.jsx("div",{className:`${J.width??"flex-1"} px-2 flex flex-col`,children:s.jsx("div",{className:"space-y-4",children:(de=J.fields)==null?void 0:de.map((pe,be)=>s.jsx(k.Fragment,{children:H(pe)},be))})},oe)})})},U))})},B))},F.key)]))},Z)),s.jsx("footer",{className:"py-4 w-full flex justify-center space-x-4",children:d??s.jsx(me,{type:"submit",variant:"primary",icon:Gr,size:"sm",disabled:_||V||M>0,children:b(_?"ds.form.sending":"ds.form.submit")})})]})})}function n1({dark:e,onToggle:t}){return s.jsx("button",{type:"button","aria-pressed":e,"aria-label":e?"Cambiar a modo claro":"Cambiar a modo oscuro",onClick:t,className:ge("relative inline-flex items-center transition-colors focus:outline-none duration-200 ease-in-out","bg-[var(--color-ds-background-accent)]","h-6 w-12 rounded-full"),children:s.jsxs("div",{className:ge("absolute bg-[var(--color-ds-background-page)] flex items-center justify-center rounded-full transition-transform duration-200 ease-in-out","h-5 w-5",e?"translate-x-6":"translate-x-1"),children:[s.jsx(yt,{component:si,size:"sm",className:ge("absolute transition-opacity duration-200 ease-in-out",e?"opacity-0":"opacity-100 text-[var(--color-ds-background-accent)]")}),s.jsx(yt,{component:ti,size:"sm",className:ge("absolute transition-opacity duration-200 ease-in-out",e?"opacity-100 text-[var(--color-ds-background-accent)]":"opacity-0")})]})})}const i0="licytal:ui:theme",a1=k.createContext({theme:"light",dark:!1,toggle:()=>{}});function AO({children:e}){const[t,r]=k.useState(!1),[n,o]=k.useState("light");k.useEffect(()=>{if(typeof window>"u")return;const i=localStorage.getItem(i0);i==="light"||i==="dark"?o(i):window.matchMedia("(prefers-color-scheme: dark)").matches&&o("dark"),r(!0)},[]),k.useEffect(()=>{t&&(document.documentElement.classList.toggle("dark",n==="dark"),localStorage.setItem(i0,n))},[n,t]);const l=()=>o(i=>i==="light"?"dark":"light");return t?s.jsx(a1.Provider,{value:{theme:n,dark:n==="dark",toggle:l},children:e}):null}const Ni=()=>k.useContext(a1),Gn={locale:"licytal:ui:locale",theme:"licytal:ui:theme"},o1=({pinnedPages:e,onRemovePinned:t,onBack:r,dark:n,locale:o,languageOptions:l,onChangeLocale:i,profile:c="",profileOptions:u=[],onChangeProfile:d,logoSrc:m,logoAlt:f="Logo aplicación"})=>{e.slice(0,3);const{toggle:h}=Ni(),p=v=>{try{localStorage.setItem(Gn.locale,v)}catch{}i==null||i(v)},b=()=>{const v=!n;try{localStorage.setItem(Gn.theme,v?"dark":"light")}catch{}h()};return k.useEffect(()=>{try{const v=localStorage.getItem(Gn.locale);v&&v!==o&&(i==null||i(v))}catch{}},[]),k.useEffect(()=>{if(o)try{localStorage.setItem(Gn.locale,o)}catch{}},[o]),k.useEffect(()=>{try{const v=localStorage.getItem(Gn.theme);if(!v)return;v==="dark"!==n&&h()}catch{}},[]),s.jsxs("header",{className:"flex items-center justify-between bg-[var(--color-ds-background-page)] py-2 px-4 min-h-[88px]",children:[s.jsx("div",{className:"flex items-center",children:m&&s.jsx("img",{src:m,alt:f,className:"h-24 w-auto object-contain"})}),s.jsxs("div",{className:"flex items-center space-x-2",children:[s.jsx(Ge,{size:"sm",width:"auto",options:l,value:o,onChange:p,disableErrorPlaceholder:!0,label:"Idioma",labelHidden:!0}),!!u.length&&s.jsx(Ge,{size:"sm",width:"auto",options:u,value:c,onChange:v=>d==null?void 0:d(v),disableErrorPlaceholder:!0,label:"Perfil",labelHidden:!0}),s.jsx(n1,{dark:n,onToggle:b})]})]})},MO={sm:"h-8 w-8",md:"h-10 w-10",lg:"h-12 w-12"};function _t({icon:e,size:t="md",ariaLabel:r,disabled:n=!1,onClick:o,className:l,...i}){return s.jsx("button",{type:"button","aria-label":r,disabled:n,onClick:o,className:ge("inline-flex items-center justify-center","rounded-full","bg-transparent","text-[var(--color-ds-text-primary)]","transition-transform","focus:outline-none",MO[t],n?"opacity-50 cursor-not-allowed":["hover:scale-110","hover:animate-pulse","hover:bg-[var(--color-ds-background-neutral-hover)]"],l),...i,children:s.jsx(e,{className:ge(t==="sm"?"h-4 w-4":t==="md"?"h-5 w-5":"h-6 w-6")})})}const OO=({loading:e=!1,ariaLabel:t="Cargando..."})=>e?s.jsxs("div",{className:`\r
98
+ hover:bg-[var(--color-ds-background-surface)]`,onClick:()=>{const xe=String(ue.value).trim();E(e,xe,{shouldDirty:!0,shouldValidate:!0}),D(ue.label??xe),te.current=!1,Q.current=!1,V(!1)},children:ue.label},String(ue.value)))})]})}})}const qn=(e,t)=>e[t],n0=e=>e instanceof Date?e.getTime():e;function wO(e,t,r){const n=n0(e),o=n0(t);return typeof n=="number"&&typeof o=="number"||typeof n=="string"&&typeof o=="string"?r==="gt"?n>o:r==="gte"?n>=o:r==="lt"?n<o:n<=o:!1}function Ao(e,t){if(!e)return!1;switch(e.op){case"eq":return qn(t,e.field)===e.value;case"neq":return qn(t,e.field)!==e.value;case"in":return e.values.includes(qn(t,e.field));case"notIn":return!e.values.includes(qn(t,e.field));case"gt":case"gte":case"lt":case"lte":return wO(qn(t,e.field),e.value,e.op);case"and":return e.rules.every(r=>Ao(r,t));case"or":return e.rules.some(r=>Ao(r,t));case"always":return!!e.value;default:return!1}}function Ci(e){return!!e&&(typeof e=="function"||typeof e=="object")}function An(e,t){const r=t==="outline"?Cn:Sn,n=r==null?void 0:r[e];return Ci(n)?n:null}const yO=Object.entries(Cn).filter(([e,t])=>e.endsWith("Icon")&&Ci(t)).map(([e,t])=>({name:e,Icon:t,style:"outline"})),jO=Object.entries(Sn).filter(([e,t])=>e.endsWith("Icon")&&Ci(t)).map(([e,t])=>({name:e,Icon:t,style:"solid"})),kO=oi||ai||(e=>s.jsx("svg",{...e})),Wr=({value:e,onChange:t,buttonLabel:r,disabled:n,className:o})=>{const[l,i]=k.useState(!1),[c,u]=k.useState(""),[d,m]=k.useState((e==null?void 0:e.style)??"outline"),f=e&&An(e.name,e.style)||kO,h=k.useCallback((b,v)=>{const g=An(b,v);t==null||t({name:b,style:v},g),i(!1)},[t]),p=k.useCallback(()=>{t==null||t(void 0,void 0),i(!1)},[t]);return s.jsxs(s.Fragment,{children:[s.jsx(me,{size:"sm",variant:"outline",shape:"circle",className:`rounded-full p-0 w-8 h-8 inline-flex items-center justify-center ${o??""}`,disabled:n,onClick:()=>i(!0),ariaLabel:"Elegir icono",title:r||"Elegir icono",children:s.jsx(f,{className:"h-4 w-4"})}),s.jsx(St,{isOpen:l,onClose:()=>i(!1),title:"Seleccionar icono",children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(ke,{labelHidden:!0,placeholder:"Buscar icono (p. ej. 'user', 'arrow', 'calendar'...)",value:c,onChange:b=>u(b.target.value)}),s.jsx(xr,{options:[{label:"Outline",value:"outline"},{label:"Solid",value:"solid"}],value:d,onChange:b=>m(b),children:{outline:s.jsx(a0,{items:yO,query:c,onPick:b=>h(b,"outline"),onClear:p}),solid:s.jsx(a0,{items:jO,query:c,onPick:b=>h(b,"solid"),onClear:p})}})]})})]})},a0=({items:e,query:t,onPick:r,onClear:n})=>{const o=k.useMemo(()=>{if(!t.trim())return e;const i=t.trim().toLowerCase().replace(/\s+/g,"");return e.filter(c=>c.name.toLowerCase().includes(i))},[e,t]),l=et;return s.jsx("div",{className:"custom-scroll max-h-[60vh] overflow-y-auto",children:s.jsxs("div",{className:"grid gap-2 grid-cols-3 sm:grid-cols-4 md:grid-cols-6",children:[s.jsxs("button",{type:"button",onClick:n,className:"group w-full aspect-square border border-[var(--color-ds-border-default-50)] rounded-lg p-1 bg-[var(--color-ds-background-page)] hover:bg-[var(--color-ds-background-accent)]/5 hover:border-[var(--color-ds-border-default)] transition focus:outline-none",title:"Ninguno","aria-label":"Quitar icono",children:[s.jsx("div",{className:"h-full w-full flex items-center justify-center",children:l?s.jsx(l,{className:"w-6 h-6"}):s.jsx("span",{className:"text-ds-lg",children:"×"})}),s.jsx("div",{className:"mt-1 text-center",children:s.jsx("span",{className:"block text-[11px] leading-tight text-[var(--color-ds-text-secondary)] truncate",children:"Ninguno"})})]}),(o.length===0?e:o).map(({name:i,Icon:c})=>s.jsxs("button",{type:"button",onClick:()=>r(i),className:"group w-full aspect-square border border-[var(--color-ds-border-default-50)] rounded-lg p-1 bg-[var(--color-ds-background-page)] hover:bg-[var(--color-ds-background-accent)]/5 hover:border-[var(--color-ds-border-default)] transition focus:outline-none",title:i,"aria-label":`Elegir ${i}`,children:[s.jsx("div",{className:"h-full w-full flex items-center justify-center",children:s.jsx(c,{className:"w-6 h-6 text-[var(--color-ds-text-primary)]"})}),s.jsx("div",{className:"mt-1 text-center",children:s.jsx("span",{className:"block text-[11px] leading-tight text-[var(--color-ds-text-secondary)] truncate",children:i.replace(/Icon$/,"")})})]},i))]})})};function st(e,t,r=""){if(!t)return r;if(typeof t=="object"&&t!==null){if(t.type==="complex"){const o=[];return t.header&&o.push(`<strong>${t.header}</strong>`),t.template&&o.push(t.template),o.join("<br/>")||r}return r}return e(t,{defaultValue:t})}const EO=({schema:e,renderField:t})=>{var v,g,x;const{control:r}=Tr(),{fields:n,append:o,remove:l}=Zx({control:r,name:e.name}),{label:i,addLabel:c="Añadir",items:u,disabled:d,validation:m,className:f}=e,{formState:{errors:h}}=Tr(),p=((g=(v=h[e.name])==null?void 0:v.root)==null?void 0:g.message)||((x=h[e.name])==null?void 0:x.message),b=typeof p=="string"?p:void 0;return s.jsxs("div",{className:ge("space-y-3",f),children:[i&&s.jsx("div",{className:"flex items-center justify-between",children:s.jsx("label",{className:"block text-ds-sm font-medium text-[var(--color-ds-text-primary)]",children:i})}),s.jsx("div",{className:"space-y-4",children:n.map((w,y)=>{const E=`${e.name}.${y}`;return s.jsxs("div",{className:"relative rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)] p-4 group",children:[!d&&s.jsx("div",{className:"absolute top-2 right-2",children:s.jsx(me,{size:"xs",variant:"ghost",className:"text-[var(--color-ds-text-error)] hover:bg-[var(--color-ds-background-error-hover)]",onClick:()=>l(y),title:"Eliminar fila",ariaLabel:"Eliminar fila",children:s.jsx(pt,{className:"w-4 h-4"})})}),s.jsx("div",{className:"grid grid-cols-1 gap-4",children:u.map((j,R)=>s.jsx(k.Fragment,{children:t(j,E)},R))})]},w.id)})}),n.length===0&&s.jsx("div",{className:"text-ds-sm text-[var(--color-ds-text-secondary)] italic p-2 border border-dashed border-[var(--color-ds-border-default-50)] rounded bg-[var(--color-ds-background-subtle)]",children:"No hay elementos."}),b&&s.jsx("p",{className:"text-xs text-[var(--color-ds-text-error)]",children:b}),!d&&s.jsxs(me,{type:"button",variant:"outline",size:"sm",onClick:()=>{o({})},children:[s.jsx(Jt,{className:"w-4 h-4 mr-1"}),c]})]})};function o0(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,24)}function RO(e){return e.replace(/(.{4})/g,"$1 ").trim()}function ts({label:e,labelHidden:t,placeholder:r="ES00 0000 0000 0000 0000 0000",size:n="sm",value:o,onChange:l,onBlur:i,disabled:c,required:u,reserveErrorSpace:d=!0,error:m,errorMessage:f,hasError:h,id:p,name:b,className:v,"aria-label":g}){const x=k.useMemo(()=>o0(o),[o]),w=k.useMemo(()=>RO(x),[x]),y=E=>{const j=o0(E.target.value);l(j)};return s.jsx(ke,{id:p,name:b,label:e,labelHidden:t,placeholder:r,size:n,value:w,onChange:y,onBlur:i,disabled:c,required:u,hasError:h||!!m||!!f,errorMessage:f||m,reserveErrorSpace:d,prefixIcon:Wl,className:v,"aria-label":g,inputMode:"text",autoComplete:"off",spellCheck:!1})}function s0(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,9)}function Si({label:e,labelHidden:t,placeholder:r="12345678A",size:n="sm",value:o,onChange:l,onBlur:i,disabled:c,required:u,reserveErrorSpace:d=!0,error:m,errorMessage:f,hasError:h,id:p,name:b,className:v,"aria-label":g}){const{t:x}=gt(),w=k.useMemo(()=>s0(o),[o]),y=k.useMemo(()=>w,[w]),E=j=>{const R=s0(j.target.value);l(R)};return s.jsx(ke,{id:p,name:b,label:e,labelHidden:t,placeholder:r,size:n,value:y,onChange:E,onBlur:i,disabled:c,required:u,hasError:h||!!m||!!f,errorMessage:f||m,prefixIcon:Ql,className:v,"aria-label":g,inputMode:"text",autoComplete:"off",spellCheck:!1,reserveErrorSpace:d})}function l0(e){if(e){if(typeof e=="string")try{return JSON.parse(e)}catch{return}if(typeof e=="object")return e}}function CO(e,t){var r;return Array.isArray(e)?e.length&&typeof e[0]=="object"&&"value"in e[0]?t?e.map(n=>n.value):((r=e[0])==null?void 0:r.value)??"":t?e:e[0]??"":e&&typeof e=="object"&&"value"in e?e.value:e??(t?[]:"")}const SO=e=>e.type!=="inputGroup"&&e.type!=="button";function NO(){try{return At()??void 0}catch{return}}function Mt(e){if(!e||typeof e!="object")return;const t=e.name,r=e.style;if(!(!t||!r))return An(t,r)||void 0}function r1({schema:e,resolver:t,serviceRegistry:r,activeVariantId:n}){var Y;const{layout:o,fields:l=[],onSubmit:i,successMessage:c,errorMessage:u,footerButtons:d,defaultValues:m,loadDefaultValues:f,validationSchema:h}=e,{show:p}=Vr(),{t:b}=gt(),v=NO(),g=r??((Y=v==null?void 0:v.services)==null?void 0:Y.registry)??void 0,x=k.useMemo(()=>{if(t)return t;try{const L=h??ki(e);return wi(L)}catch{return}},[t,e,h]),w=gi({resolver:x,mode:"onBlur",reValidateMode:"onChange",defaultValues:m??{}}),y=Jr(L=>L.setRuntimeState),E=Jr(L=>L.systemContext),j=Jr(L=>L.formValues);k.useEffect(()=>{y({isActive:!0});let L=!1;return(async()=>{const Z=e.defaultSource,F=e.onloadEndpoint;let T={};if(e.variables&&Array.isArray(e.variables)&&(e.variables.forEach(P=>{P.type==="constant"&&(T[P.key]=P.value)}),e.variables.forEach(P=>{if(P.type==="computed"&&P.value)try{const U=new Function("ctx",`return (${P.value});`);T[P.key]=U(T)}catch(U){console.warn(`[FormRenderer] Error evaluating computed variable "${P.key}":`,U),T[P.key]=null}})),Z)try{const P=g==null?void 0:g[Z];if(P){const U=typeof P=="function"?await P():P;U&&typeof U=="object"&&(T={...T,...U})}}catch{}y({systemContext:{...T}});const B=[];if(F&&B.push(F),e.onloadEndpoints&&Array.isArray(e.onloadEndpoints)&&B.push(...e.onloadEndpoints),B.length>0){const P=async J=>{if(!J)return{};try{const oe=g==null?void 0:g[J.key];if(!oe)return console.warn("[FormRenderer] Provider not found for key:",J.key),{};const de=Ar(J.parameters,(()=>({})),{...T,ACTIVE_VARIANT:e.activeVariantId});console.log(`[FormRenderer] Calling ${J.key} with params:`,de);const pe=await Promise.resolve(oe(de,{getValues:(()=>({})),watch:(()=>{}),params:de,...T}));let be=pe;if(typeof pe=="string")try{be=JSON.parse(pe)}catch(je){console.warn("[FormRenderer] Failed to parse onload response string",je)}return be&&typeof be=="object"?be:(console.warn("[FormRenderer] OnLoad response is not an object:",be),{})}catch(oe){return console.error("Error in onloadEndpoint",oe),{}}};(await Promise.all(B.map(P))).forEach(J=>{J&&typeof J=="object"&&(T={...T,...J})}),L||y({systemContext:{...T}})}if(!L&&Object.keys(T).length>0){const P={...e.defaultValues??{}};Object.assign(P,T);const U=e.fields.map(J=>J.name);Object.keys(T).forEach(J=>{const oe=J.toLowerCase(),de=U.find(pe=>pe.toLowerCase()===oe);de&&(P[de]===void 0||P[de]==="")&&(P[de]=T[J])}),w.reset(P)}})(),()=>{L=!0,y({isActive:!1,systemContext:{},formValues:{}})}},[e,g,w.reset]);const{control:R,reset:A,handleSubmit:S,formState:{errors:O,isSubmitting:_}}=w,[V,$]=k.useState(!1);k.useEffect(()=>{f&&($(!0),f().then(L=>A(L)).finally(()=>$(!1)))},[f,A]);const D=k.useMemo(()=>(l??[]).filter(SO),[l]),{loadingCount:M,optionsMap:z}=e1(D),[te,Q]=k.useState({}),[ne,ae]=k.useState(0);k.useEffect(()=>{let L;const Z=w.watch(()=>{clearTimeout(L),L=setTimeout(()=>{ae(F=>F+1)},500)});return()=>{Z.unsubscribe(),clearTimeout(L)}},[w.watch]);const K=k.useRef(g);k.useEffect(()=>{K.current=g},[g]);const N=k.useRef({});k.useEffect(()=>{let L=!0;return(async()=>{const F=await Promise.all(D.filter(B=>B.type==="select"&&(B.optionSource||B.endpointConfig)).map(async B=>{var be;const P=B.name,U=Co(B.optionSource,B.endpointConfig);if(!U)return[P,[]];const J=B.endpointConfig?Ar(B.endpointConfig.parameters,w.getValues,E):{...E,...w.getValues()},oe=l0(B.adapterCtx??B.optionAdapterCtx),de=JSON.stringify({key:U,resolvedParams:J,ctx:oe});N.current[P],N.current[P]=de;const pe=(be=K.current)==null?void 0:be[U];if(typeof pe!="function")return[P,[]];try{const je=await Promise.resolve(pe(J,{getValues:w.getValues,watch:w.watch,ctx:oe,params:J,...E})),ye=Array.isArray(je)?je:[];return[P,ye]}catch{return[P,[]]}}));if(!L)return;const T={};for(const[B,P]of F)T[B]=P;Q(B=>Object.entries(T).some(([U,J])=>{const oe=B[U];return!oe||oe.length!==J.length?!0:JSON.stringify(oe)!==JSON.stringify(J)})?T:B)})(),()=>{L=!1}},[ne,JSON.stringify(D.map(L=>({n:L.name,os:L.optionSource??null,ec:L.endpointConfig??null,ctx:L.adapterCtx??L.optionAdapterCtx??null}))),E]),k.useEffect(()=>{let L=!0;return(async()=>{for(const F of D){if(F.type!=="select")continue;const T=F.name,B=F.defaultSource;if(!B)continue;const P=w.getValues(T);if(!(P==null||(Array.isArray(P)?P.length===0:P==="")))continue;const J=g==null?void 0:g[B];if(typeof J=="function")try{const oe=l0(F.adapterCtx??F.optionAdapterCtx),de=await Promise.resolve(J("",{getValues:w.getValues,watch:w.watch,ctx:oe}));if(!L)return;const pe=CO(de,!!F.multiple);w.setValue(T,pe,{shouldDirty:!0,shouldTouch:!0})}catch{}}})(),()=>{L=!1}},[g,w.getValues,w.setValue,JSON.stringify(D.map(L=>({n:L.name,ds:L.defaultSource??null,mult:!!L.multiple})))]);const I=Y5(l),re=t1(l,R),G=k.useMemo(()=>{const L={};return o.forEach((Z,F)=>{Z.type==="tabs"&&(L[F]=Z.tabs[0].key)}),L},[o]),[X,fe]=k.useState(G),[le,he]=k.useState({}),[ce,ie]=k.useState({}),ve=k.useRef({}),ue=k.useCallback(async()=>{const L={},Z=l.filter(T=>{var P,U,J;const B=T;return((P=B.visibleWhen)==null?void 0:P.endpoint)||((U=B.disabledWhen)==null?void 0:U.endpoint)||((J=B.clearWhen)==null?void 0:J.endpoint)});if(Z.length===0)return;(await Promise.all(Z.map(async T=>{const B=T,P=B.name,U={};for(const J of["visibleWhen","disabledWhen","clearWhen"]){const oe=B[J];if(oe!=null&&oe.enabled&&oe.endpoint){const de=oe.endpoint.key,pe=g==null?void 0:g[de];if(typeof pe=="function")try{const be=Ar(oe.endpoint.parameters,w.getValues,E),je=await Promise.resolve(pe(be,{getValues:w.getValues,watch:w.watch,params:be,...E}));U[J]=typeof je=="object"&&je!==null?!!je.ok:!!je}catch(be){console.error(`Error evaluando regla backend para ${P}.${J}:`,be),U[J]=!1}}}return{fieldName:P,res:U}}))).forEach(({fieldName:T,res:B})=>{Object.keys(B).length>0&&(L[T]=B)}),he(L)},[l,g,w,E]),xe=k.useCallback(async L=>{var U;const Z=L,F=Z.name,T=Z.asyncValidation.endpoint,B=T.key,P=g==null?void 0:g[B];if(typeof P=="function"){ie(J=>({...J,[F]:{...J[F],loading:!0}}));try{const J=Ar(T.parameters,w.getValues,E),oe=await Promise.resolve(P(J,{getValues:w.getValues,watch:w.watch,params:J,...E})),de=typeof oe=="object"&&oe!==null?!!oe.ok:!!oe,pe=typeof oe=="object"&&oe!==null?oe.message:void 0;ie(be=>({...be,[F]:{ok:de,message:pe,loading:!1}})),de?((U=w.formState.errors[F])==null?void 0:U.type)==="manual"&&w.clearErrors(F):w.setError(F,{type:"manual",message:pe||"Validación externa fallida"})}catch{ie(oe=>({...oe,[F]:{ok:!1,message:"Error de conexión",loading:!1}}))}}},[g,w,E]),C=k.useCallback(async(L,Z,F)=>{const T=l.filter(B=>{var oe,de;const P=B,U=(oe=P.asyncValidation)==null?void 0:oe.endpoint;if(!U)return!1;const J=U.trigger||P.asyncValidation.trigger||"onBlur";if(F&&J!==F&&!(J==="auto"&&F==="onChange"))return!1;if(Z&&F!=="onSubmit"){const pe=P.name===Z,be=Object.values(U.parameters||{}).some(ye=>ye.fieldRef===Z),je=(de=U.triggerFields)==null?void 0:de.includes(Z);if(!pe&&!be&&!je)return!1}return!0});for(const B of T){const P=B,U=P.name,J=P.asyncValidation.endpoint;if(F==="onChange"&&J.trigger==="debounced"){ve.current[U]&&clearTimeout(ve.current[U]),ve.current[U]=setTimeout(()=>xe(B),J.debounceMs||300);continue}await xe(B)}},[l,xe]);k.useEffect(()=>{ue();const L=w.watch((Z,{name:F})=>{ue(),F&&C(Z,F,"onChange")});return()=>{L.unsubscribe(),Object.values(ve.current).forEach(Z=>Z&&clearTimeout(Z))}},[ue,C,w]);const q=k.useCallback((L,Z,F,T)=>{var P;if(!(L!=null&&L.enabled))return Z;let B=!0;if(L.rule)try{const U={...w.getValues(),...E,ACTIVE_VARIANT:n};B=!!Ao(L.rule,U)}catch{B=Z}if(B&&F&&T&&L.endpoint){const U=(P=le[F])==null?void 0:P[T];if(U===void 0)return!1;B=U}return B},[w,le,n]),ee=k.useMemo(()=>l.map(L=>L).filter(L=>{var Z;return((Z=L.clearWhen)==null?void 0:Z.enabled)&&(L.clearWhen.rule||L.clearWhen.endpoint)}).map(L=>({name:L.name,container:L.clearWhen})),[l]);k.useEffect(()=>{if(!ee.length)return;const L=F=>{ee.forEach(({name:T,container:B})=>{try{if(q(B,!1,T,"clearWhen")){const U=B.clearTo??"";F[T]!==U&&w.setValue(T,U,{shouldDirty:!0,shouldValidate:!0})}}catch{}})};L(w.getValues());const Z=w.watch(()=>L(w.getValues()));return()=>{var F;return(F=Z==null?void 0:Z.unsubscribe)==null?void 0:F.call(Z)}},[w,ee,q]);const W=k.useCallback(L=>{const Z=st(b,L);if(!Z)return"";const F={...E,...j,sys:E,form:j};return Sl(Z,F)},[b,E,j]),H=k.useCallback((L,Z)=>{var Oe,_e,ze,nt;let F;if(typeof L=="string"){if(F=I[L],!F){const Se=(l??[]).find(Ne=>(Ne==null?void 0:Ne.name)===L);if(Se)F=Se;else return null}}else F=L;const T=F.name,B=T?Z?`${Z}.${T}`:T:void 0,P=F.visibleWhen;if(!q(P,!0,T,"visibleWhen"))return null;let J=!!F.disabled;const oe=F.disabledWhen,de=q(oe,!1,T,"disabledWhen");if(oe!=null&&oe.enabled&&(J=de),!(oe!=null&&oe.enabled)&&T&&re[T]&&(J=!0),F.type==="search"){const Se=typeof F.searchFn=="function",Ne=Co(F.searchSource,F.endpointConfig),Me=async vt=>{if(Se)return F.searchFn(vt,{getValues:w.getValues,watch:w.watch});if(Ne){const Ze=F.endpointConfig?Ar(F.endpointConfig.parameters,w.getValues,E):{...E,...w.getValues()},qe=g==null?void 0:g[Ne];if(typeof qe=="function")return await qe(vt,{getValues:w.getValues,watch:w.watch,params:Ze,...E});if(Array.isArray(qe))return qe}return[]},Ae={};F.searchMode&&(Ae.searchMode=F.searchMode),F.minChars&&(Ae.minChars=F.minChars),F.debounceMs&&(Ae.debounceMs=F.debounceMs),F.resolveByValue&&(Ae.resolveByValue=F.resolveByValue);const Ie=Mt(F.labelIconLeft??F.labelPrefixIcon),Be=Mt(F.labelIconRight??F.labelSuffixIcon),Ve=Mt(F.prefixIcon),De=Mt(F.suffixIcon);return s.jsx(Ri,{name:B,control:R,searchFn:Me,label:W(F.label),size:F.size,width:F.width,disabled:J||_,labelPrefixIcon:Ie,labelSuffixIcon:Be,prefixIcon:Ve,suffixIcon:De,...Ae},B)}if(F.type==="inputGroup"){const Se=F,Ne=(Se.inputs??[]).map(Me=>{var wr,Dt;const Ae=typeof Me=="string"?I[Me]??(l??[]).find(lr=>(lr==null?void 0:lr.name)===Me):Me;if(!Ae)return null;const Ie=Ae.name,Be=Z?`${Z}.${Ie}`:Ie,Ve=Ae.disabledWhen;let De=!!Ae.disabled;const vt=q(Ve,!1,Ie,"disabledWhen");Ve!=null&&Ve.enabled&&(De=vt),!(Ve!=null&&Ve.enabled)&&re[Ie]&&(De=!0);const Ze=Mt(Ae.labelIconLeft??Ae.labelPrefixIcon),qe=Mt(Ae.labelIconRight??Ae.labelSuffixIcon),He=Mt(Ae.prefixIcon),at=Mt(Ae.suffixIcon),Qt={name:Be,control:R,label:W(Ae.label),size:Ae.size,width:Ae.width,placeholder:W(Ae.placeholder),hasError:!!(O[Be]||Z&&((wr=O[Z])!=null&&wr[Ie])),errorMessage:st(b,(Dt=O[Be])==null?void 0:Dt.message),loading:V,disabled:De||_,suffixButton:Ae.suffixButton,reserveErrorSpace:!0,labelPrefixIcon:Ze,labelSuffixIcon:qe,prefixIcon:He,suffixIcon:at};return Ae.type==="select"?{...Qt,options:Ae.options??te[Ie]??z[Ie]??[],loadOptions:Ae.options||Ae.optionSource?void 0:Ae.loadOptions}:{...Qt,type:Ae.type}}).filter(Boolean);return s.jsx(Ei,{groupLabel:st(b,Se.groupLabel),inputs:Ne,separator:Se.separator,useSeparator:Se.useSeparator,className:Se.className,showVisibleLabel:Se.showVisibleLabel,size:Se.size},`inputGroup_${B??Se.groupLabel??"group"}`)}if(F.type==="button"){const Se=F,Ne=Se.icon,Me=Ne&&typeof Ne=="object"&&Ne.name&&Ne.style?Mt(Ne):void 0;return s.jsx("div",{className:"self-center",children:s.jsx(me,{type:"button",variant:Se.variant,size:Se.size,width:Se.width,icon:Me,iconPosition:Se.iconPosition,ariaLabel:W(Se.ariaLabel),onClick:Se.onClick,disabled:J||_,children:W(Se.label)})},B??Se.label)}if(F.type==="array"){const Se=F;return s.jsx(EO,{schema:{...Se,name:B},renderField:H},B)}const pe=F.suffixButton,be=typeof pe=="string"?H(pe):pe,je=Mt(F.labelIconLeft??F.labelPrefixIcon),ye=Mt(F.labelIconRight??F.labelSuffixIcon),Fe=Mt(F.prefixIcon),$e=Mt(F.suffixIcon),Ee={name:B,control:R,disabled:J||_,label:W(F.label),size:F.size,width:F.width,placeholder:W(F.placeholder),info:st(b,F.info),suffixButton:be,labelPrefixIcon:je,labelSuffixIcon:ye,prefixIcon:Fe,suffixIcon:$e,onBlur:()=>{C(w.getValues(),T,"onBlur"),l.filter(Ne=>{const Me=Ne;return["visibleWhen","disabledWhen","clearWhen"].some(Ae=>{var Be;const Ie=(Be=Me[Ae])==null?void 0:Be.endpoint;return(Ie==null?void 0:Ie.trigger)==="onBlur"&&Object.values(Ie.parameters||{}).some(Ve=>Ve.fieldRef===T)})}).length>0&&ue()}};switch(F.type){case"select":{const Se=F.options??te[T]??z[T]??[],Ne=Array.isArray(Se)&&Se.length?`${Se.length}:${Se.map(Ae=>String((Ae==null?void 0:Ae.value)??"")).join("|")}`:"0",Me=!F.options&&!F.optionSource&&F.loadOptions;return s.jsx(mt,{name:B,control:R,render:({field:Ae})=>{var Ie;return s.jsx(Ge,{...Ee,value:Ae.value,onChange:Ae.onChange,options:Se,loadOptions:Me||void 0,hasError:!!O[B],errorMessage:st(b,(Ie=O[B])==null?void 0:Ie.message),suffixButton:be,mode:"menu",searchable:!0,searchPlaceholder:b("ds.fields.defaults.search.placeholder"),noOptionsText:b("ds.fields.defaults.search.noMatches")})}},`${B}:${Ne}`)}case"textarea":return s.jsx(mt,{name:B,control:R,render:({field:Se,fieldState:Ne})=>{var Me;return s.jsx(or,{...Ee,value:Se.value,onChange:Se.onChange,maxLength:F.maxLength,showCounter:!!F.showCounter,hasError:!!Ne.error,errorMessage:st(b,(Me=Ne.error)==null?void 0:Me.message)})}},B);case"file":return s.jsx(xi,{...Ee,defaultValue:[],maxFiles:F.maxFiles,accept:F.accept,hideDropZone:F.hideDropZone,hasError:!!O[B],errorMessage:st(b,(Oe=O[B])==null?void 0:Oe.message)},B);case"checkbox":return s.jsx(tt,{...Ee,defaultValue:!1,hasError:!!O[B],errorMessage:st(b,(_e=O[B])==null?void 0:_e.message),name:B},B);case"date":return s.jsx(Nn,{...Ee,defaultValue:"",showTime:!!F.showTime,hasError:!!O[B],errorMessage:st(b,(ze=O[B])==null?void 0:ze.message)},B);case"optionGroup":return s.jsx(es,{...Ee,options:F.options||[],multiple:F.multiple,vertical:F.vertical,groupLabel:F.groupLabel,defaultValue:F.defaultValue,className:F.width?void 0:"w-full",name:B},B);case"iban":return s.jsx(mt,{name:B,control:R,render:({field:Se,fieldState:Ne})=>{var Me;return s.jsx(ts,{label:W(F.label),placeholder:W(F.placeholder),size:F.size,disabled:J||_,value:Se.value??"",onChange:Se.onChange,onBlur:Se.onBlur,hasError:!!Ne.error,errorMessage:st(b,(Me=Ne.error)==null?void 0:Me.message),name:B})}},B);case"dni":return s.jsx(mt,{name:B,control:R,render:({field:Se,fieldState:Ne})=>{var Me;return s.jsx(Si,{label:W(F.label),placeholder:W(F.placeholder),size:F.size,disabled:J||_,value:Se.value??"",onChange:Se.onChange,onBlur:Se.onBlur,hasError:!!Ne.error,errorMessage:st(b,(Me=Ne.error)==null?void 0:Me.message),name:B})}},B);default:return s.jsx(Xo,{...Ee,type:F.type,loadingDefaults:V,hasError:!!O[B],errorMessage:st(b,(nt=O[B])==null?void 0:nt.message),suffixButton:be,name:B},B)}},[l,I,R,O,_,V,z,te,q,re,w.getValues,w.watch,g,b]);return s.jsx(fi,{...w,children:s.jsxs("form",{noValidate:!0,onSubmit:S(async L=>{await C(L,void 0,"onSubmit"),!(Object.keys(w.formState.errors).length>0)&&(await i(L),p(c??b("ds.form.saveSuccess"),"success"))},L=>{YM(L),p(u??b("ds.form.saveError"),"error")}),className:"space-y-6",children:[o.map((L,Z)=>L.type==="rows"?s.jsx(k.Fragment,{children:L.sections.map((F,T)=>s.jsx("div",{children:s.jsx(rt,{title:W(F.sectionTitle),defaultOpen:F.defaultOpen,children:F.rows.map((B,P)=>s.jsxs("div",{children:[B.title&&s.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:W(B.title)}),s.jsx("div",{className:"flex flex-wrap -mx-2",children:B.columns.map((U,J)=>{var oe;return s.jsx("div",{className:`${U.width} px-2 flex flex-col`,children:s.jsx("div",{className:"",children:U.fields?U.fields.map(de=>H(de)):(oe=U.rows)==null?void 0:oe.map((de,pe)=>s.jsx("div",{className:"mb-1",children:s.jsx("div",{className:"flex flex-wrap -mx-2",children:de.columns.map((be,je)=>{var ye;return s.jsx("div",{className:`${be.width} px-2`,children:(ye=be.fields)==null?void 0:ye.map(Fe=>H(Fe))},je)})})},pe))})},J)})})]},P))})},T))},Z):s.jsx(xr,{options:L.tabs.map(F=>{const T=F.icon?An(F.icon.name,F.icon.style):null;return{label:W(F.label),value:F.key,disabled:F.disabled,icon:T?s.jsx(T,{className:"w-4 h-4"}):null}}),value:X[Z],onChange:F=>fe(T=>({...T,[Z]:F})),children:Object.fromEntries(L.tabs.map(F=>[F.key,s.jsx("div",{className:"space-y-6",children:F.sections.map((T,B)=>s.jsx("div",{className:"mb-6",children:s.jsx(rt,{title:W(T.sectionTitle),defaultOpen:T.defaultOpen,children:T.rows.map((P,U)=>s.jsx("div",{children:s.jsx("div",{className:"flex flex-wrap -mx-2",children:P.columns.map((J,oe)=>{var de;return s.jsx("div",{className:`${J.width??"flex-1"} px-2 flex flex-col`,children:s.jsx("div",{className:"space-y-4",children:(de=J.fields)==null?void 0:de.map((pe,be)=>s.jsx(k.Fragment,{children:H(pe)},be))})},oe)})})},U))})},B))},F.key)]))},Z)),s.jsx("footer",{className:"py-4 w-full flex justify-center space-x-4",children:d??s.jsx(me,{type:"submit",variant:"primary",icon:Gr,size:"sm",disabled:_||V||M>0,children:b(_?"ds.form.sending":"ds.form.submit")})})]})})}function n1({dark:e,onToggle:t}){return s.jsx("button",{type:"button","aria-pressed":e,"aria-label":e?"Cambiar a modo claro":"Cambiar a modo oscuro",onClick:t,className:ge("relative inline-flex items-center transition-colors focus:outline-none duration-200 ease-in-out","bg-[var(--color-ds-background-accent)]","h-6 w-12 rounded-full"),children:s.jsxs("div",{className:ge("absolute bg-[var(--color-ds-background-page)] flex items-center justify-center rounded-full transition-transform duration-200 ease-in-out","h-5 w-5",e?"translate-x-6":"translate-x-1"),children:[s.jsx(yt,{component:si,size:"sm",className:ge("absolute transition-opacity duration-200 ease-in-out",e?"opacity-0":"opacity-100 text-[var(--color-ds-background-accent)]")}),s.jsx(yt,{component:ti,size:"sm",className:ge("absolute transition-opacity duration-200 ease-in-out",e?"opacity-100 text-[var(--color-ds-background-accent)]":"opacity-0")})]})})}const i0="licytal:ui:theme",a1=k.createContext({theme:"light",dark:!1,toggle:()=>{}});function AO({children:e}){const[t,r]=k.useState(!1),[n,o]=k.useState("light");k.useEffect(()=>{if(typeof window>"u")return;const i=localStorage.getItem(i0);i==="light"||i==="dark"?o(i):window.matchMedia("(prefers-color-scheme: dark)").matches&&o("dark"),r(!0)},[]),k.useEffect(()=>{t&&(document.documentElement.classList.toggle("dark",n==="dark"),localStorage.setItem(i0,n))},[n,t]);const l=()=>o(i=>i==="light"?"dark":"light");return t?s.jsx(a1.Provider,{value:{theme:n,dark:n==="dark",toggle:l},children:e}):null}const Ni=()=>k.useContext(a1),Gn={locale:"licytal:ui:locale",theme:"licytal:ui:theme"},o1=({pinnedPages:e,onRemovePinned:t,onBack:r,dark:n,locale:o,languageOptions:l,onChangeLocale:i,profile:c="",profileOptions:u=[],onChangeProfile:d,logoSrc:m,logoAlt:f="Logo aplicación"})=>{e.slice(0,3);const{toggle:h}=Ni(),p=v=>{try{localStorage.setItem(Gn.locale,v)}catch{}i==null||i(v)},b=()=>{const v=!n;try{localStorage.setItem(Gn.theme,v?"dark":"light")}catch{}h()};return k.useEffect(()=>{try{const v=localStorage.getItem(Gn.locale);v&&v!==o&&(i==null||i(v))}catch{}},[]),k.useEffect(()=>{if(o)try{localStorage.setItem(Gn.locale,o)}catch{}},[o]),k.useEffect(()=>{try{const v=localStorage.getItem(Gn.theme);if(!v)return;v==="dark"!==n&&h()}catch{}},[]),s.jsxs("header",{className:"flex items-center justify-between bg-[var(--color-ds-background-page)] py-2 px-4 min-h-[88px]",children:[s.jsx("div",{className:"flex items-center",children:m&&s.jsx("img",{src:m,alt:f,className:"h-24 w-auto object-contain"})}),s.jsxs("div",{className:"flex items-center space-x-2",children:[s.jsx(Ge,{size:"sm",width:"auto",options:l,value:o,onChange:p,disableErrorPlaceholder:!0,label:"Idioma",labelHidden:!0}),!!u.length&&s.jsx(Ge,{size:"sm",width:"auto",options:u,value:c,onChange:v=>d==null?void 0:d(v),disableErrorPlaceholder:!0,label:"Perfil",labelHidden:!0}),s.jsx(n1,{dark:n,onToggle:b})]})]})},MO={sm:"h-8 w-8",md:"h-10 w-10",lg:"h-12 w-12"};function _t({icon:e,size:t="md",ariaLabel:r,disabled:n=!1,onClick:o,className:l,...i}){return s.jsx("button",{type:"button","aria-label":r,disabled:n,onClick:o,className:ge("inline-flex items-center justify-center","rounded-full","bg-transparent","text-[var(--color-ds-text-primary)]","transition-transform","focus:outline-none",MO[t],n?"opacity-50 cursor-not-allowed":["hover:scale-110","hover:animate-pulse","hover:bg-[var(--color-ds-background-neutral-hover)]"],l),...i,children:s.jsx(e,{className:ge(t==="sm"?"h-4 w-4":t==="md"?"h-5 w-5":"h-6 w-6")})})}const OO=({loading:e=!1,ariaLabel:t="Cargando..."})=>e?s.jsxs("div",{className:`\r
99
99
  fixed inset-0\r
100
100
  flex items-center justify-center\r
101
101
  bg-[var(--color-ds-background-surface)]/90\r
@@ -408,7 +408,7 @@ ${A.join(`
408
408
  `)}`,"error");return}n(c),p("Configuración de shortcuts guardada","success")},x=()=>{if(window.confirm("¿Restaurar shortcuts a valores por defecto?")){const R=ZT();u(R),p("Shortcuts restaurados a valores por defecto","info")}},w=R=>{u(A=>({...A,[R]:{...A[R],enabled:!A[R].enabled}}))},y=R=>{m(R),h(!0)},E=R=>{if(!f||!d||(R.preventDefault(),R.stopPropagation(),["Control","Shift","Alt","Meta"].includes(R.key)))return;const A={...c[d],key:R.key,ctrl:R.ctrlKey||R.metaKey,shift:R.shiftKey,alt:R.altKey};u(S=>({...S,[d]:A})),h(!1),m(null)};if(k.useEffect(()=>{u(r)},[r]),k.useEffect(()=>{if(f)return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[f,d,c]),k.useEffect(()=>{e||(h(!1),m(null),u(r),i("general"))},[e,r]),!e)return null;const j=[{id:"general",label:o("ds.editor.settings.general","General"),icon:Yr},{id:"appearance",label:o("ds.editor.settings.appearance","Apariencia"),icon:zd},{id:"shortcuts",label:o("ds.editor.settings.shortcuts","Atajos"),icon:bn}];return s.jsxs(St,{isOpen:e,onClose:t,title:o("ds.editor.settings.title","Configuración del Editor"),maxWidth:"max-w-4xl",children:[s.jsxs("div",{className:"flex h-[60vh] gap-6",children:[s.jsx("div",{className:"w-48 flex-shrink-0 flex flex-col gap-1 border-r border-[var(--color-ds-border-default-50)] pr-4",children:j.map(R=>s.jsxs("button",{onClick:()=>i(R.id),className:ge("flex items-center gap-2 px-3 py-2 text-sm font-medium rounded-lg transition-colors text-left",l===R.id?"bg-[var(--color-ds-button-primary-bg)] text-[var(--color-ds-button-primary-text)]":"text-[var(--color-ds-text-secondary)] hover:bg-[var(--color-ds-background-neutral-hover)] hover:text-[var(--color-ds-text-primary)]"),children:[s.jsx(R.icon,{className:"w-4 h-4"}),R.label]},R.id))}),s.jsxs("div",{className:"flex-1 overflow-y-auto pr-2",children:[l==="general"&&s.jsx("div",{className:"space-y-6",children:s.jsxs("div",{className:"space-y-4",children:[s.jsx("h4",{className:"text-sm font-semibold text-[var(--color-ds-text-primary)] border-b border-[var(--color-ds-border-default-50)] pb-2",children:"Comportamiento"}),s.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)]",children:[s.jsx(tt,{checked:b.confirmDelete,onChange:R=>v({confirmDelete:R}),size:"md",disableErrorPlaceholder:!0}),s.jsxs("div",{children:[s.jsx("div",{className:"text-sm font-medium text-[var(--color-ds-text-primary)]",children:"Confirmar eliminación"}),s.jsx("div",{className:"text-xs text-[var(--color-ds-text-secondary)]",children:"Solicitar confirmación antes de eliminar campos o secciones."})]})]}),s.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)]",children:[s.jsx(tt,{checked:b.showGrid,onChange:R=>v({showGrid:R}),size:"md",disableErrorPlaceholder:!0}),s.jsxs("div",{children:[s.jsx("div",{className:"text-sm font-medium text-[var(--color-ds-text-primary)]",children:"Mostrar rejilla de diseño"}),s.jsx("div",{className:"text-xs text-[var(--color-ds-text-secondary)]",children:"Visualizar guías de columnas y filas en el editor."})]})]})]})}),l==="appearance"&&s.jsx("div",{className:"space-y-6",children:s.jsxs("div",{className:"space-y-4",children:[s.jsx("h4",{className:"text-sm font-semibold text-[var(--color-ds-text-primary)] border-b border-[var(--color-ds-border-default-50)] pb-2",children:"Tema del Editor"}),s.jsxs("div",{className:"p-4 rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)] flex items-center justify-between",children:[s.jsxs("div",{children:[s.jsx("div",{className:"text-sm font-medium text-[var(--color-ds-text-primary)] mb-1",children:"Preferencia de color"}),s.jsx("div",{className:"text-xs text-[var(--color-ds-text-secondary)]",children:"Elige entre modo claro, oscuro o sincronizar con el sistema."})]}),s.jsx(Aa,{value:b.theme,onChange:R=>v({theme:R}),size:"lg",variant:"rounded",items:[{id:"light",label:"Claro",icon:si},{id:"system",label:"Sistema",icon:Gl},{id:"dark",label:"Oscuro",icon:ti}]})]})]})}),l==="shortcuts"&&s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex justify-between items-center mb-2",children:[s.jsx("div",{className:"text-sm text-[var(--color-ds-text-secondary)]",children:"Personaliza los atajos de teclado para mejorar tu productividad."}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(me,{variant:"ghost",size:"xs",onClick:x,children:"Restaurar"}),s.jsx(me,{variant:"primary",size:"xs",onClick:g,children:"Guardar Atajos"})]})]}),s.jsx("div",{className:"space-y-2",children:Object.entries(c).map(([R,A])=>s.jsxs("div",{className:ge("flex items-center justify-between p-3 rounded-xl transition-colors border","border-[var(--color-ds-border-muted)] hover:border-[var(--color-ds-border-default)]","bg-[var(--color-ds-background-surface)] hover:bg-[var(--color-ds-background-surface-hover)]"),children:[s.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[s.jsx(tt,{checked:A.enabled,onChange:()=>w(R),size:"sm",disableErrorPlaceholder:!0}),s.jsx("div",{className:"cursor-pointer",onClick:()=>w(R),children:s.jsx("div",{className:ge("font-medium text-sm",!A.enabled&&"opacity-50 line-through"),children:A.description})})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:ge("px-2 py-1 rounded border font-mono text-[10px] min-w-[60px] text-center",f&&d===R?"bg-blue-100 text-blue-700 border-blue-300 animate-pulse":"bg-[var(--color-ds-background-page)] border-[var(--color-ds-border-muted)]",!A.enabled&&"opacity-40"),children:f&&d===R?"...":Xn(A)}),s.jsx(me,{size:"xs",variant:"ghost",onClick:S=>{S.stopPropagation(),y(R)},disabled:!A.enabled||f,children:s.jsx(Uo,{className:"w-3 h-3"})})]})]},R))})]})]})]}),s.jsx("div",{className:"flex justify-end pt-4 border-t border-[var(--color-ds-border-default)] mt-2",children:s.jsx(me,{variant:"outline",onClick:t,children:"Cerrar"})})]})},HT=zT;function tl(e,t){const r=new Blob([t],{type:"text/plain;charset=utf-8"}),n=URL.createObjectURL(r),o=document.createElement("a");o.href=n,o.download=e,o.click(),URL.revokeObjectURL(n)}const rl=e=>e.toLowerCase().endsWith(".json")?e:`${e}.json`,Q0=(e,t)=>`${e.replace(/\/+$/,"")}/${t.replace(/^\/+/,"")}`,ed=()=>s.jsx("div",{className:"w-px h-6 bg-[var(--color-ds-border-default-50)] mx-2"});function WT(){var Y;const{t:e,i18n:t}=gt(),r=se(L=>L.schema),n=se(L=>L.undo),o=se(L=>L.redo),l=se(L=>L.setSchema),i=se(L=>L.resetHistory),c=se(L=>L.past.length),u=se(L=>L.future.length),d=se(L=>L.selection),m=se(L=>L.removeField),f=se(L=>L.duplicateField),h=se(L=>L.editorSettings),p=se(L=>L.showRelations??!1),b=se(L=>L.toggleRelations),v=se(L=>L.setShowRelations),g=se(L=>L.mode),x=se(L=>L.setMode),[w,y]=k.useState(!1),[E,j]=k.useState(!1),[R,A]=k.useState(!1),[S,O]=k.useState(!1),[_,V]=k.useState(!1),[$,D]=k.useState(!1),M=()=>{typeof b=="function"?b():typeof v=="function"&&v(!p)},z=k.useRef(null),te=k.useRef(null),{show:Q}=Vr(),{fs:ne,baseDir:ae,translations:K,services:N,setServices:I}=At(),re=((Y=r.title)==null?void 0:Y.toString().trim().replace(/\s+/g,"-").toLowerCase())||"form-schema",G=()=>{tl(`${re}.json`,JSON.stringify(r,null,2)),Q("Esquema exportado como JSON.","success")},X=()=>{try{const L=Yi(r,"validationSchema");tl(`${re}.validation.ts`,L),Q("Yup exportado como TypeScript.","success")}catch(L){console.error(L),Q("No se pudo generar el Yup.","error")}},fe=()=>{try{const L=Xi(r,K,t),Z=`${re}.translations.json`;tl(Z,JSON.stringify(L,null,2)),Q("Traducciones exportadas como JSON.","success")}catch(L){console.error(L),Q("No se pudo generar el JSON de traducciones.","error")}},le=async()=>{try{await navigator.clipboard.writeText(JSON.stringify(r,null,2)),Q("JSON copiado al portapapeles.","success")}catch{Q("No se pudo copiar al portapapeles.","error")}},he=()=>{var L;return(L=z.current)==null?void 0:L.click()},ce=()=>{var L;return(L=te.current)==null?void 0:L.click()},ie=L=>{var B;const Z=(B=L.target.files)==null?void 0:B[0];if(!Z)return;if(!window.confirm("Vas a reemplazar el esquema actual. ¿Continuar?")){L.currentTarget.value="";return}const T=new FileReader;T.onload=()=>{try{const P=JSON.parse(String(T.result));if(!Array.isArray(P.layout)||!Array.isArray(P.fields)){Q("JSON inválido: faltan layout/fields.","error");return}l(P),i(),Q("Esquema importado correctamente.","success")}catch{Q("No se pudo parsear el JSON.","error")}},T.readAsText(Z),L.currentTarget.value=""},ve=async L=>{var B;const Z=L.target,F=(B=Z.files)==null?void 0:B[0];if(!F)return;if(!window.confirm("Al importar un proyecto ZIP se reemplazará el esquema actual, los servicios y las traducciones. ¿Continuar?")){Z.value="";return}try{await AT({file:F,setSchema:P=>{l(P),i()},setServices:I,translationAdapter:K}),Q("Proyecto importado correctamente.","success")}catch(P){console.error(P),Q(P.message||"Error al importar ZIP","error")}Z.value=""},ue=()=>{window.confirm("Crear un esquema nuevo vacío (perderás cambios no guardados). ¿Continuar?")&&(l(Z=>{Z.layout=[{type:"rows",sections:[{sectionTitle:"Sección 1",defaultOpen:!0,rows:[{title:"",columns:[{width:"w-full",fields:[]}]}]}]}],Z.fields=[],Z.successMessage="Guardado",Z.errorMessage="Error",Z.onSubmit=async()=>{}}),i(),Q("Esquema nuevo creado.","info"))},xe=async()=>{try{const L=Q0(ae,rl(`${re}.json`));await ne.write(L,JSON.stringify(r,null,2)),Q(`Guardado rápido en ${L}`,"success")}catch(L){console.error(L),Q("Guardado rápido fallido.","error")}},C=async()=>{try{const L=rl(`${re}.json`),Z=window.prompt("Guardar como (archivo en baseDir):",L);if(!Z)return;const F=Q0(ae,rl(Z));await ne.write(F,JSON.stringify(r,null,2)),Q(`Guardado en ${F}`,"success")}catch(L){console.error(L),Q("No se pudo guardar el archivo.","error")}},{config:q,updateConfig:ee}=PT({undo:()=>{c>0&&n()},redo:()=>{u>0&&o()},save:()=>{xe()},saveAs:()=>{C()},toggleRelations:()=>{M()},togglePreview:()=>{x(g==="design"?"preview":g==="preview"?"code":"design")},deleteField:()=>{d.kind==="field"&&(!h.confirmDelete||window.confirm(`¿Eliminar el campo "${d.name}"?`))&&(m(d.name),Q("Campo eliminado","success"))},duplicateField:()=>{d.kind==="field"&&(f(d.name),Q("Campo duplicado","success"))},copy:()=>{le()},newSchema:()=>{ue()},importSchema:()=>{he()},exportSchema:()=>{G()}}),W=[{label:"Nuevo esquema",icon:Bd,onSelect:ue},{label:"Importar JSON...",icon:Vd,onSelect:he},{label:"Importar Proyecto (ZIP)...",icon:gd,onSelect:ce},{label:"Generar desde DTO...",icon:bn,onSelect:()=>j(!0)},{label:"Gestionar Servicios...",icon:bn,onSelect:()=>O(!0)},{label:"Generar desde BD...",icon:ua,onSelect:()=>A(!0)},{label:"Guardar",icon:sl,onSelect:xe},{label:"Guardar como...",icon:sl,onSelect:C}],H=[{label:"Exportar JSON",icon:Fn,onSelect:G},{label:"Exportar Yup (.ts)",icon:Bt,onSelect:X},{label:"Exportar Traducciones",icon:Wo,onSelect:fe},{label:"Copiar JSON",icon:fa,onSelect:le},{label:"Exportar Proyecto (ZIP)",icon:il,onSelect:()=>{const L=(N==null?void 0:N.registry)||{};console.log("Services Registry for Export:",L),TT({schema:r,translationsAdapter:K,i18n:t,servicesRegistry:L,baseName:re}),Q("Proyecto exportado correctamente","success")}}];return s.jsxs("div",{className:"pb-1 bg-[var(--color-ds-background-page)]",children:[s.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-page)] shadow-sm px-3 py-2",children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(_t,{icon:Ed,size:"sm",onClick:n,disabled:c===0,ariaLabel:`Deshacer (${Xn(q.undo)})`,title:`Deshacer (${Xn(q.undo)})`}),s.jsx(_t,{icon:Rd,size:"sm",onClick:o,disabled:u===0,ariaLabel:`Rehacer (${Xn(q.redo)})`,title:`Rehacer (${Xn(q.redo)})`}),s.jsx(ed,{}),s.jsx(wT,{}),s.jsx(ed,{}),s.jsx(pa,{trigger:s.jsxs("span",{className:"flex items-center gap-1 px-2 py-1.5 text-sm font-medium text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-background-neutral-hover)] rounded-md transition-colors",children:["Archivo",s.jsx(Kt,{className:"w-3 h-3 opacity-50"})]}),items:W}),s.jsx(pa,{trigger:s.jsxs("span",{className:"flex items-center gap-1 px-2 py-1.5 text-sm font-medium text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-background-neutral-hover)] rounded-md transition-colors",children:[e("ds.editor.toolbar.export"),s.jsx(Kt,{className:"w-3 h-3 opacity-50"})]}),items:H}),s.jsx(me,{variant:"subtle",size:"sm",onClick:()=>O(!0),icon:il,ariaLabel:"Importar/Gestionar Servicios OpenAPI",className:"ml-1 text-[var(--color-ds-primary-700)] bg-[var(--color-ds-primary-50)] hover:bg-[var(--color-ds-primary-100)] ring-[var(--color-ds-primary-200)]",children:"Servicios"}),s.jsx(me,{variant:"subtle",size:"sm",onClick:()=>V(!0),icon:ua,ariaLabel:"Configurar carga inicial de datos",className:"ml-1 text-[var(--color-ds-primary-700)] bg-[var(--color-ds-primary-50)] hover:bg-[var(--color-ds-primary-100)] ring-[var(--color-ds-primary-200)]",children:"Pre-carga"}),s.jsx(me,{variant:"ghost",size:"sm",onClick:()=>D(!0),icon:bn,ariaLabel:"Ver variables de sistema",title:"Variables de sistema",className:"ml-1 text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)]"}),s.jsx("input",{ref:z,type:"file",accept:"application/json",className:"hidden",onChange:ie,"aria-label":e("ds.editor.toolbar.import")}),s.jsx("input",{ref:te,type:"file",accept:".zip,application/zip,application/x-zip-compressed",className:"hidden",onChange:ve,"aria-label":"Importar Proyecto ZIP"})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(_t,{icon:p?Yl:Xr,size:"sm",onClick:M,ariaLabel:e(p?"ds.editor.toolbar.hideRelations":"ds.editor.toolbar.showRelations"),title:e(p?"ds.editor.toolbar.hideRelations":"ds.editor.toolbar.showRelations"),className:"text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)]"}),s.jsx(_t,{icon:Yr,size:"sm",onClick:()=>y(!0),ariaLabel:e("ds.editor.toolbar.shortcuts"),title:e("ds.editor.toolbar.shortcuts")}),s.jsx("div",{className:"w-px h-6 bg-[var(--color-ds-border-default-50)] mx-1"}),s.jsx(Aa,{value:g,onChange:L=>x(L),size:"sm",variant:"square",items:[{id:"design",label:e("ds.editor.modes.design"),icon:En},{id:"preview",label:e("ds.editor.modes.preview"),icon:Xr},{id:"code",label:e("ds.editor.modes.code"),icon:Bt}]})]})]}),s.jsx(HT,{isOpen:w,onClose:()=>y(!1),config:q,onSaveShortcuts:ee}),s.jsx(G_,{open:E,onClose:()=>j(!1)}),s.jsx(Q_,{open:R,onClose:()=>A(!1)}),s.jsx(mT,{isOpen:S,onClose:()=>O(!1)}),_&&s.jsx(hT,{isOpen:!0,onClose:()=>V(!1)}),s.jsx(xT,{isOpen:$,onClose:()=>D(!1)})]})}const oo="application/x-ds-field-template",td="application/x-ds-layout-kind";function nl(e){return e.layout.find(t=>(t==null?void 0:t.type)==="rows")}function UT({className:e,children:t}){var w;const r=se(y=>y.schema),n=se(y=>y.addFieldAndPlace),o=se(y=>y.addRowsBlockAt),l=se(y=>y.addSection),i=se(y=>y.addRowToSection),c=se(y=>y.setRowColumns),u=se(y=>y.moveField),[d,m]=k.useState(!1),f=k.useMemo(()=>{var j;const y=nl(r);if(!y)return[];const E=[];return(j=y.sections)==null||j.forEach((R,A)=>{var S;(S=R.rows)==null||S.forEach((O,_)=>{(O.columns??[]).forEach((V,$)=>{var z;const D=((z=V.fields)==null?void 0:z.length)??0,M=Math.max(1,D+1);for(let te=0;te<M;te++)E.push({kind:"field-slot",sectionIdx:A,rowIdx:_,colIdx:$,insertIdx:te,key:`s${A}-r${_}-c${$}-i${te}`})})})}),E},[r]),h=k.useCallback(()=>{var R,A;const y=r.layout.findIndex(S=>(S==null?void 0:S.type)==="rows"),E=r.layout[y];return E?(R=E.sections)!=null&&R.length?(A=E.sections[0].rows)!=null&&A.length?((E.sections[0].rows[0].columns??[]).length||c==null||c(y,0,0,1),{s:0,r:0,c:0}):(i==null||i(y,0),{s:0,r:0,c:0}):(l==null||l("Sección 1"),{s:0,r:0,c:0}):(o==null||o(r.layout.length??0,"Sección 1"),{s:0,r:0,c:0})},[r,o,l,i,c]),p=k.useCallback(y=>{var j;const E=((j=y.dataTransfer)==null?void 0:j.types)||[];(E.includes(oo)||E.includes(td))&&(y.preventDefault(),y.dataTransfer.dropEffect="copy",m(E.includes(oo)?"field":"layout"))},[]),b=k.useCallback(()=>m(!1),[]),v=k.useCallback(y=>{var A;const E=y.dataTransfer.getData(td);if(!E)return!1;const{kind:j}=JSON.parse(E),R=((A=r==null?void 0:r.layout)==null?void 0:A.length)??0;return j==="section-layout"&&(o==null||o(R,"Nueva sección")),!0},[(w=r==null?void 0:r.layout)==null?void 0:w.length,o]),g=k.useCallback((y,E)=>{const j=E.dataTransfer.getData(oo);if(!j)return!1;const{fieldTemplate:R}=JSON.parse(j);return n(R,y.sectionIdx,y.rowIdx,y.colIdx),queueMicrotask(()=>{var V;const A=se.getState().schema,_=(((V=nl(A).sections[y.sectionIdx].rows[y.rowIdx].columns[y.colIdx].fields)==null?void 0:V.length)??1)-1;y.insertIdx>=0&&y.insertIdx<_&&u({s:y.sectionIdx,r:y.rowIdx,c:y.colIdx,idx:_},{s:y.sectionIdx,r:y.rowIdx,c:y.colIdx,idx:y.insertIdx})}),!0},[n,u]),x=k.useCallback(y=>{if(y.preventDefault(),y.stopPropagation(),v(y)){m(!1);return}const E=y.dataTransfer.getData(oo);if(E){const{fieldTemplate:j}=JSON.parse(E),R=h();n(j,R.s,R.r,R.c)}m(!1)},[v,h,n]);return s.jsxs("div",{className:["relative",e].filter(Boolean).join(" "),onDragOver:p,onDragLeave:b,onDrop:x,children:[t,d&&s.jsxs("div",{className:"absolute inset-0 z-40",children:[s.jsx("div",{className:"absolute inset-0 bg-black/5 pointer-events-none"}),s.jsx("div",{className:"absolute inset-0 px-4 py-4 overflow-auto space-y-4",children:(()=>{var j;const y=nl(r);if(!y||!((j=y.sections)!=null&&j.length)){const R=h(),A={kind:"field-slot",sectionIdx:R.s,rowIdx:R.r,colIdx:R.c,insertIdx:0,key:"init"};return s.jsx("div",{className:"min-h-[220px] border-2 border-dashed rounded-2xl bg-white/70 flex items-center justify-center text-ds-sm",onDragOver:S=>S.preventDefault(),onDrop:S=>{S.preventDefault(),S.stopPropagation(),g(A,S),m(!1)},children:"Suelta aquí para empezar"})}const E=[];return y.sections.forEach((R,A)=>{var S;(S=R.rows)==null||S.forEach((O,_)=>{const V=[];(O.columns??[]).forEach(($,D)=>{const M=f.filter(z=>z.sectionIdx===A&&z.rowIdx===_&&z.colIdx===D);V.push(M)}),E.push({key:`s${A}-r${_}`,cols:V})})}),E.map(R=>s.jsx("div",{className:"grid gap-3 pointer-events-none",style:{gridTemplateColumns:`repeat(${R.cols.length||1}, minmax(0,1fr))`},children:R.cols.map((A,S)=>{const O=A.length===1;return s.jsx("div",{className:"pointer-events-auto",children:s.jsx("div",{className:["rounded-xl border-2 border-dashed bg-white/60",O?"min-h-[160px]":"py-2"].join(" "),children:s.jsx("div",{className:"flex flex-col gap-2",children:A.map(_=>s.jsx("div",{className:"h-7 rounded-md border border-transparent hover:border-[var(--color-ds-border-default)] hover:bg-white/80 flex items-center justify-center text-ds-sm text-[var(--color-ds-text-secondary)]",onDragOver:V=>V.preventDefault(),onDrop:V=>{V.preventDefault(),V.stopPropagation(),g(_,V),m(!1)},title:`Insertar en Col ${_.colIdx+1}, posición ${_.insertIdx+1}`,children:O?"Soltar aquí":_.insertIdx===A.length-1?"Añadir al final":"Insertar aquí"},_.key))})})},`${R.key}-c${S}`)})},R.key))})()})]})]})}function qT({nodeIdx:e,insertAt:t}){const r={scope:"rows-section",nodeIdx:e,insertAt:t},{setNodeRef:n,isOver:o}=sr({id:`rows-section:drop:${e}:${t}`,data:r});return s.jsx("div",{ref:n,className:["h-2 my-1 w-full rounded-sm transition relative mx-1 px-1",o?"bg-[var(--color-ds-border-default)]/30 ring-1 ring-[var(--color-ds-border-default)]":"bg-transparent"].join(" "),"aria-label":`Insertar sección en posición ${t+1}`})}function GT({nodeIdx:e,sIdx:t}){const r=`rows-section:drag:${e}:${t}`,n={kind:"rows-section",nodeIdx:e,sIdx:t},{attributes:o,listeners:l,setNodeRef:i,isDragging:c}=nn({id:r,data:n});return s.jsx("div",{ref:i,...o,...l,role:"button",title:"Arrastrar sección","aria-grabbed":c,className:"shrink-0 w-6 h-6 grid place-items-center cursor-grab active:cursor-grabbing rounded text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-background-muted)]",children:"⇅"})}function rd(e){const r={...e.scope==="rows-column"?{scope:"rows-column",s:e.s,r:e.r,c:e.c,rowsNodeIdx:e.rowsNodeIdx}:{scope:"tabs-column",tabKey:e.tabKey,s:e.s,r:e.r,c:e.c},insertAt:Number.MAX_SAFE_INTEGER},{setNodeRef:n,isOver:o}=sr({id:JSON.stringify(r),data:r});return s.jsx("div",{ref:n,className:o?"ring-5 ring-[var(--color-ds-border-default)] rounded-md":"","aria-dropeffect":o?"copy":void 0,"data-drop-scope":e.scope,children:e.children})}function KT(e,t=44){if(!e)return t;const r=e.previousElementSibling,n=e.nextElementSibling,o=c=>{var u;return((u=c==null?void 0:c.querySelector)==null?void 0:u.call(c,"[data-sortable-item]"))||c},l=o(r)??o(n)??null,i=(l==null?void 0:l.getBoundingClientRect().height)??0;return Math.max(32,Math.min(96,Math.round(i||t)))}function JT(e){var f,h,p,b,v,g,x,w;if(!e)return null;const t=e.kind??e.scope??e.type,r=e.s??((f=e.path)==null?void 0:f.s),n=e.r??((h=e.path)==null?void 0:h.r),o=e.c??((p=e.path)==null?void 0:p.c),l=e.idx??((b=e.path)==null?void 0:b.idx),i=e.index,c=e.rowsNodeIdx??e.nodeIdx??((v=e.path)==null?void 0:v.rowsNodeIdx),u=e.tabKey??((g=e.path)==null?void 0:g.tabKey),d=e.groupName??((x=e.path)==null?void 0:x.groupName),m=e.arrayName??((w=e.path)==null?void 0:w.arrayName);return{kind:t,s:r,r:n,c:o,idx:l,index:i,rowsNodeIdx:c,tabKey:u,groupName:d,arrayName:m}}function YT(e,t){if(!t)return!1;const r=n=>typeof n=="number"&&(e.insertAt===n||e.insertAt===n+1);if(e.scope==="rows-column"){if((t.kind==="field-in-rows"||t.kind==="rows-column")&&t.rowsNodeIdx===e.rowsNodeIdx&&t.s===e.s&&t.r===e.r&&t.c===e.c&&r(t.idx))return!0}else if(e.scope==="tabs-column"){if((t.kind==="field-in-tabs"||t.kind==="tabs-column")&&t.tabKey===e.tabKey&&t.s===e.s&&t.r===e.r&&t.c===e.c&&r(t.idx))return!0}else if(e.scope==="input-group"){if((t.kind==="field-in-inputgroup"||t.kind==="input-group")&&t.groupName===e.groupName&&r(t.idx))return!0}else if(e.scope==="array-items"&&(t.kind==="field-in-array"||t.kind==="array-items")&&t.arrayName===e.arrayName&&r(t.index))return!0;return!1}function rr(e){let t;e.scope==="rows-column"?t={scope:"rows-column",rowsNodeIdx:e.rowsNodeIdx,s:e.s,r:e.r,c:e.c,insertAt:e.insertAt}:e.scope==="tabs-column"?t={scope:"tabs-column",tabKey:e.tabKey,s:e.s,r:e.r,c:e.c,insertAt:e.insertAt}:e.scope==="input-group"?t={scope:"input-group",groupName:e.groupName,insertAt:e.insertAt}:t={scope:"array-items",arrayName:e.arrayName,insertAt:e.insertAt};const r=k.useRef(null),{setNodeRef:n,isOver:o}=sr({id:JSON.stringify(t),data:t}),[l,i]=k.useState(44),c=e.scope==="input-group"?6:8,[u,d]=k.useState(null);Ia({onDragStart:v=>{var g,x;return d(((x=(g=v.active)==null?void 0:g.data)==null?void 0:x.current)??null)},onDragCancel:()=>d(null),onDragEnd:()=>d(null)});const m=YT(e,JT(u)),f=!!e.suppressAll||m;if(k.useEffect(()=>{if(!o||f)return;const v=KT(r.current,e.scope==="input-group"?36:44);i(v)},[o,e.scope,f]),f)return s.jsx("div",{ref:v=>{r.current=v,n(v)},style:{position:"absolute",inset:0,pointerEvents:"none"},role:"button","aria-dropeffect":o?"copy":void 0,"aria-label":`Soltar aquí (posición ${e.insertAt+1})`,"data-drop-scope":e.scope,"data-insert-at":e.insertAt});const h=e.insertAt===0,p={height:o?l:0,margin:o?`${c}px 0`:"0px",transition:"height 120ms ease, margin 120ms ease, opacity 80ms ease",opacity:o?1:0},b=e.scope==="input-group"?"w-full inline-flex":"w-full block";return s.jsx("div",{ref:v=>{r.current=v,n(v)},role:"button","aria-dropeffect":o?"copy":void 0,"aria-label":`Soltar aquí (posición ${e.insertAt+1})`,"data-drop-scope":e.scope,"data-insert-at":e.insertAt,className:b,style:p,children:o&&s.jsx("div",{"aria-hidden":!0,className:["w-full","rounded-md","border","border-dashed","border-[var(--color-ds-border-default-50)]",e.scope==="input-group"?"bg-[var(--color-ds-background-surface)]/70":"bg-[var(--color-ds-background)]/60","relative"].join(" "),style:{height:l,boxShadow:"inset 0 0 0 1px color-mix(in srgb, var(--color-ds-border-default-50) 30%, transparent)"},children:!e.suppressHint&&s.jsxs("div",{className:"absolute -top-2 left-3 px-1.5 py-0.5 rounded text-[11px] leading-none",style:{background:"var(--color-ds-background-elevated)",color:"var(--color-ds-text-secondary)",border:"1px solid var(--color-ds-border-default-50)"},children:["Soltar aquí",""]})})})}function Sr(e){const t=e.kind==="field-in-tabs"?`${e.kind}:${e.tabKey}:${e.name}:${e.path.s}-${e.path.r}-${e.path.c}-${e.path.idx}`:e.kind==="field-in-rows"?`${e.kind}:${e.rowsNodeIdx}:${e.name}:${e.path.s}-${e.path.r}-${e.path.c}-${e.path.idx}`:e.kind==="field-in-inputgroup"?`${e.kind}:${e.groupName}:${e.name}:${e.path.idx}`:`${e.kind}:${e.arrayName}:${e.name}:${e.index}`,r=e.kind==="field-in-rows"?{kind:e.kind,name:e.name,path:e.path,rowsNodeIdx:e.rowsNodeIdx}:e.kind==="field-in-tabs"?{kind:e.kind,name:e.name,path:e.path,tabKey:e.tabKey}:e.kind==="field-in-inputgroup"?{kind:e.kind,name:e.name,path:e.path,groupName:e.groupName}:{kind:e.kind,name:e.name,arrayName:e.arrayName,index:e.index},{attributes:n,listeners:o,setNodeRef:l,isDragging:i}=nn({id:t,data:r}),c=e.disableSelect?s.jsxs("span",{className:"text-[var(--color-ds-text-primary)] text-ds-sm text-left truncate inline-flex items-center gap-1",children:[e.icon?s.jsx("span",{"aria-hidden":!0,className:"shrink-0 text-[var(--color-ds-text-secondary)]",children:e.icon}):null,s.jsx("span",{className:"truncate",children:e.name})]}):s.jsxs("button",{type:"button",className:"text-[var(--color-ds-text-primary)] text-ds-sm hover:underline text-left truncate inline-flex items-center gap-1",onClick:u=>{u.stopPropagation(),e.onSelect()},children:[e.icon?s.jsx("span",{"aria-hidden":!0,className:"shrink-0 text-[var(--color-ds-text-secondary)]",children:e.icon}):null,s.jsx("span",{className:"truncate",children:e.name})]});return s.jsxs("div",{ref:l,className:["text-[var(--color-ds-text-primary)] group flex items-center justify-between rounded-md py-1 w-full","overflow-visible",i?"opacity-50":"opacity-100"].join(" "),"data-field-name":e.name,children:[c,s.jsx("div",{...o,...n,role:"button","aria-grabbed":i,"aria-label":`Arrastrar campo ${e.name}`,className:["text-[var(--color-ds-text-primary)] text-[11px] select-none cursor-grab active:cursor-grabbing","px-1 py-0.5 rounded-sm","hover:bg-[var(--color-ds-background-muted)]","focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)]"].join(" "),title:"Arrastra para reordenar",children:"⇅"})]})}function Hu(e){return se(k.useCallback(t=>{if(e)return t.schema.fields.find(r=>r.name===e)},[e]))}const XT=k.memo(({fieldOrName:e,groupName:t,index:r,onRemove:n,setSelection:o,confirmDelete:l})=>{const i=typeof e=="string"?e:e.name,u=Hu(i)||(typeof e=="object"?e:void 0),d=u==null?void 0:u.name,m=(u==null?void 0:u.type)??"text";let f;u&&("label"in u?f=u.label:"groupLabel"in u&&(f=u.groupLabel));const h=gr(m),p=Ht(m);return s.jsxs("div",{className:"flex items-center justify-between w-full gap-2 rounded-md border bg-[var(--color-ds-background-page)] px-2 py-1",style:{borderColor:"var(--color-ds-border-default-50)",borderLeft:`4px solid ${h}`,boxShadow:`inset 0 0 0 1px color-mix(in srgb, ${h} 18%, transparent)`},children:[d?s.jsx(Sr,{kind:"field-in-inputgroup",groupName:t,name:d,path:{idx:r},onSelect:()=>o({kind:"field",name:d}),icon:p}):s.jsx("div",{className:"text-ds-sm opacity-80",children:f??"(inline sin nombre)"}),d?s.jsx(me,{size:"xs",variant:"danger",onClick:()=>l("Eliminar campo","¿Estás seguro de que quieres eliminar este campo del grupo?",n),title:"Quitar del grupo",shape:"circle",icon:et}):null]})}),QT=k.memo(function({field:t,index:r,nodeIdx:n,sIdx:o,rIdx:l,cIdx:i,parentType:c,tabKey:u,onDelete:d,confirmDelete:m}){const f=typeof t=="string"?t:t==null?void 0:t.name,p=Hu(f)||(typeof t=="object"?t:void 0),b=se(z=>z.setSelection),v=se(z=>z.removeFieldFromInputGroup),g=se(z=>z.removeFieldFromArray),x=(p==null?void 0:p.name)??f,w=(p==null?void 0:p.type)??"text",y=Ht(w),E=gr(w),j=()=>c==="rows"?s.jsx(Sr,{kind:"field-in-rows",rowsNodeIdx:n,name:x,path:{s:o,r:l,c:i,idx:r},onSelect:()=>b({kind:"field",name:x}),icon:y}):s.jsx(Sr,{kind:"field-in-tabs",tabKey:u,name:x,path:{s:o,r:l,c:i,idx:r},onSelect:()=>b({kind:"field",name:x}),icon:y}),R=(z,te)=>c==="rows"?s.jsx(rr,{scope:"rows-column",rowsNodeIdx:n,s:o,r:l,c:i,insertAt:z,suppressAll:te}):s.jsx(rr,{scope:"tabs-column",tabKey:u,s:o,r:l,c:i,insertAt:z,suppressAll:te}),A=se(z=>z.activeVariantId),S=se(z=>z.schema.variants),O=k.useMemo(()=>S==null?void 0:S.find(z=>z.key===A),[S,A]),_=k.useMemo(()=>{var z;return(z=O==null?void 0:O.overrides)==null?void 0:z[x]},[O,x]),V=_==null?void 0:_.hidden,$=_==null?void 0:_.disabled,D=V?{opacity:.4,filter:"grayscale(100%)"}:{},M=()=>V||$?s.jsxs("div",{className:"flex gap-1 absolute top-0 right-8 -mt-2",children:[V&&s.jsx("span",{className:"bg-gray-500 text-white text-[9px] px-1 rounded shadow-sm",children:"Hidden"}),$&&s.jsx("span",{className:"bg-amber-500 text-white text-[9px] px-1 rounded shadow-sm",children:"Disabled"})]}):null;if(w==="inputGroup"){const z=p,te=(z==null?void 0:z.type)==="inputGroup"&&Array.isArray(z==null?void 0:z.inputs)?z.inputs:[],Q=(z==null?void 0:z.type)!=="inputGroup"&&Array.isArray(z==null?void 0:z.inputs)?z.inputs:[],ne=te.length>0,ae=!ne&&Q.length>0;return s.jsxs(k.Fragment,{children:[s.jsxs("div",{"data-field-name":x,className:"rounded-md border bg-[var(--color-ds-background-page)] relative",style:{borderColor:"var(--color-ds-border-default-50)",boxShadow:`inset 0 0 0 1px color-mix(in srgb, ${gr("inputGroup")} 18%, transparent)`,...D},children:[s.jsx(M,{}),s.jsxs("div",{className:"flex items-center justify-between gap-2 px-2 py-1 bg-[var(--color-ds-background-surface)] border-b border-[var(--color-ds-border-default-50)]",children:[c==="rows"?s.jsx(Sr,{kind:"field-in-rows",rowsNodeIdx:n,name:x,path:{s:o,r:l,c:i,idx:r},onSelect:()=>b({kind:"field",name:x}),icon:Ht("inputGroup"),disableSelect:!0}):s.jsx(Sr,{kind:"field-in-tabs",tabKey:u,name:x,path:{s:o,r:l,c:i,idx:r},onSelect:()=>b({kind:"field",name:x}),icon:Ht("inputGroup"),disableSelect:!0}),s.jsx(me,{size:"xs",variant:"danger",onClick:d,title:"Quitar grupo del layout",shape:"circle",icon:et})]}),s.jsx("div",{className:"p-2",children:s.jsxs("div",{className:"flex flex-row gap-2 flex-wrap relative",children:[s.jsx(rr,{scope:"input-group",groupName:x,insertAt:0,suppressAll:!ne}),ne&&te.map((K,N)=>{const I=typeof K=="string"?K:K.name??N;return s.jsxs(k.Fragment,{children:[s.jsx(XT,{fieldOrName:K,groupName:x,index:N,onRemove:()=>v(x,N),setSelection:b,confirmDelete:m}),s.jsx(rr,{scope:"input-group",groupName:x,insertAt:N+1,suppressAll:!ne})]},`${x}-child-${I}`)}),!ne&&ae&&Q.map((K,N)=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-dashed bg-[var(--color-ds-background-surface)] px-2 py-1 opacity-80",title:"Definido en FieldSchema.inputs (vista previa).",children:[s.jsx("span",{className:"text-[11px] px-1.5 py-0.5 rounded-full border",children:(K==null?void 0:K.label)??(K==null?void 0:K.name)??"Input"}),s.jsx("span",{className:"text-[var(--color-ds-text-secondary)] text-ds-sm",children:"(solo vista)"})]},`${x}-ui-${(K==null?void 0:K.name)??N}`)),!ne&&!ae&&s.jsx("div",{className:"text-center text-[12px] text-[var(--color-ds-text-secondary)] border border-dashed border-[var(--color-ds-border-default-50)] rounded-md py-3 w-full",children:"Suelta inputs dentro del grupo"})]})})]}),R(r+1,!1)]})}if(w==="array"){const z=p,te=Array.isArray(z==null?void 0:z.items)?z.items:[];return s.jsxs(k.Fragment,{children:[s.jsxs("div",{"data-field-name":x,className:"rounded-md border bg-[var(--color-ds-background-page)] relative",style:{borderColor:"var(--color-ds-border-default-50)",boxShadow:`inset 0 0 0 1px color-mix(in srgb, ${gr("array")} 18%, transparent)`,...D},children:[s.jsx(M,{}),s.jsxs("div",{className:"flex items-center justify-between gap-2 px-2 py-1 bg-[var(--color-ds-background-surface)] border-b border-[var(--color-ds-border-default-50)]",children:[c==="rows"?s.jsx(Sr,{kind:"field-in-rows",rowsNodeIdx:n,name:x,path:{s:o,r:l,c:i,idx:r},onSelect:()=>b({kind:"field",name:x}),icon:Ht("array"),disableSelect:!0}):s.jsx(Sr,{kind:"field-in-tabs",tabKey:u,name:x,path:{s:o,r:l,c:i,idx:r},onSelect:()=>b({kind:"field",name:x}),icon:Ht("array"),disableSelect:!0}),s.jsx(me,{size:"xs",variant:"danger",onClick:d,title:"Quitar repeater",shape:"circle",icon:et})]}),s.jsxs("div",{className:"p-3 bg-[var(--color-ds-background-subtle)] rounded-b-md",children:[s.jsx("div",{className:"text-[10px] uppercase font-bold tracking-wider text-[var(--color-ds-text-tertiary)] mb-2 pl-1 select-none",children:"Plantilla de Item"}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(rr,{scope:"array-items",arrayName:x,insertAt:0,suppressAll:te.length===0}),te.length===0&&s.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 text-center text-[12px] text-[var(--color-ds-text-secondary)] border-2 border-dashed border-[var(--color-ds-border-default-50)] rounded-lg py-6 bg-[var(--color-ds-background-page)] transition-colors hover:border-[var(--color-ds-border-default)] hover:bg-[var(--color-ds-background-surface)]",children:[s.jsx("div",{className:"p-2 rounded-full bg-[var(--color-ds-background-subtle)]",children:s.jsx(Jt,{className:"w-5 h-5 opacity-50"})}),s.jsx("span",{className:"font-medium",children:"Arrastra campos aquí"}),s.jsx("span",{className:"text-[11px] opacity-70 max-w-[180px]",children:"Define qué campos tendrá cada elemento de la lista"})]}),te.map((Q,ne)=>{const ae=Q.name,K=Q.type,N=Ht(K),I=gr(K);return s.jsxs(k.Fragment,{children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded border bg-[var(--color-ds-background-page)] px-2 py-1",style:{borderLeft:`3px solid ${I}`},children:[s.jsx(Sr,{kind:"field-in-array",arrayName:x,name:ae,index:ne,path:{idx:ne},onSelect:()=>b({kind:"field",name:ae}),icon:N}),s.jsx(me,{size:"xs",variant:"danger",onClick:()=>g(x,ne),title:"Eliminar campo del template",shape:"circle",icon:et})]}),s.jsx(rr,{scope:"array-items",arrayName:x,insertAt:ne+1,suppressAll:te.length===0})]},`${x}-item-${ne}`)})]})]})]}),R(r+1,!1)]})}return s.jsxs(k.Fragment,{children:[s.jsxs("div",{"data-field-name":x,className:"flex items-center justify-between gap-2 w-full rounded-md border bg-[var(--color-ds-background-page)] px-2 py-1 relative",style:{borderColor:"var(--color-ds-border-default-50)",borderLeft:`4px solid ${E}`,boxShadow:`inset 0 0 0 1px color-mix(in srgb, ${E} 18%, transparent)`,...D},children:[s.jsx(M,{}),j(),s.jsx(me,{size:"xs",variant:"danger",onClick:d,title:"Quitar del layout",shape:"circle",icon:et})]}),R(r+1,!1)]})}),eB=k.memo(function({col:t,widthClass:r,nodeIdx:n,sIdx:o,rIdx:l,cIdx:i,parentType:c,tabKey:u,confirmDelete:d}){const m=se(j=>j.removeColumn),f=se(j=>j.removeTabColumn),h=se(j=>j.placeFieldInColumn),p=se(j=>j.placeFieldInTabColumn),b=se(j=>j.removeFieldFromLayout),v=se(j=>j.removeFieldFromTabLayout),g=t.fields??[],x=se(k.useCallback(j=>{const R=j.schema.fields;for(let A=R.length-1;A>=0;A--){const S=R[A];if(S.type!=="inputGroup"&&S.type!=="button")return S.name}},[])),w=()=>{d("Eliminar columna","¿Estás seguro de que quieres eliminar esta columna? Se perderán los campos que contiene.",()=>{c==="rows"?m(n,o,l,i):f(u,o,l,i)})},y=()=>{x&&(c==="rows"?h(x,n,o,l,i):p(x,u,o,l,i))},E=()=>s.jsxs("div",{className:"bg-[var(--color-ds-background-page)] overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-[var(--color-ds-background-surface)]",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:"inline-flex items-center justify-center text-[11px] leading-none px-1.5 py-0.5 rounded-full border text-[var(--color-ds-text-primary)] border-[var(--color-ds-border-default-50)]",children:["Col ",i+1]}),s.jsx("span",{className:"text-[11px] leading-none text-[var(--color-ds-text-secondary)]",children:t.width||r||"flex-1"})]}),s.jsx("div",{className:"flex items-center gap-1",children:s.jsx(me,{size:"xs",variant:"danger",onClick:w,title:"Eliminar columna",shape:"circle",icon:et})})]}),s.jsxs("div",{className:"p-2 relative",children:[s.jsxs("div",{className:"space-y-2",children:[c==="rows"?s.jsx(rr,{scope:"rows-column",rowsNodeIdx:n,s:o,r:l,c:i,insertAt:0,suppressAll:g.length===0}):s.jsx(rr,{scope:"tabs-column",tabKey:u,s:o,r:l,c:i,insertAt:0,suppressAll:g.length===0}),g.length===0&&s.jsx("div",{className:"text-center text-[12px] text-[var(--color-ds-text-secondary)] border border-dashed border-[var(--color-ds-border-default-50)] rounded-md py-4",children:"Suelta campos aquí"}),g.map((j,R)=>s.jsx(QT,{field:j,index:R,nodeIdx:n,sIdx:o,rIdx:l,cIdx:i,parentType:c,tabKey:u,onDelete:()=>{d("Eliminar campo","¿Estás seguro de que quieres eliminar este campo?",()=>{c==="rows"?b({nodeIdx:n,s:o,r:l,c:i,idx:R}):v({tabKey:u,s:o,r:l,c:i,idx:R})})},confirmDelete:d},`${typeof j=="string"?j:j.name}-${R}`))]}),s.jsx("div",{className:"mt-2 text-center",children:s.jsx(me,{size:"xs",variant:"outline",onClick:y,title:"Colocar el último campo creado en esta columna",children:"Colocar último campo"})})]})]});return c==="rows"?s.jsx(rd,{scope:"rows-column",rowsNodeIdx:n,s:o,r:l,c:i,children:E()}):s.jsx(rd,{scope:"tabs-column",tabKey:u,s:o,r:l,c:i,children:E()})}),ec=({value:e,onChange:t,placeholder:r="Click to edit",className:n,inputClassName:o,autoFocus:l=!1})=>{const[i,c]=k.useState(l),[u,d]=k.useState(e),m=k.useRef(null);k.useEffect(()=>{d(e)},[e]),k.useEffect(()=>{i&&m.current&&(m.current.focus(),m.current.select())},[i]);const f=()=>{c(!1),u.trim()!==e&&t(u)},h=p=>{p.key==="Enter"?(p.preventDefault(),f()):p.key==="Escape"&&(d(e),c(!1))};return i?s.jsx("input",{ref:m,value:u,onChange:p=>d(p.target.value),onBlur:f,onKeyDown:h,placeholder:r,className:ge("bg-transparent border border-transparent focus:border-gray-400 dark:focus:border-gray-500 rounded px-0.5 -ml-0.5 outline-none w-full min-w-[20px] leading-inherit font-inherit text-inherit","focus:ring-2 focus:ring-gray-200 dark:focus:ring-gray-700",o,n),onClick:p=>p.stopPropagation(),onPointerDown:p=>p.stopPropagation(),onMouseDown:p=>p.stopPropagation()}):s.jsxs("span",{onDoubleClick:p=>{p.preventDefault(),p.stopPropagation(),c(!0)},onClick:p=>{p.preventDefault()},className:ge("group cursor-text hover:bg-gray-100 dark:hover:bg-white/5 rounded px-0.5 -mx-0.5 border border-transparent hover:border-dashed hover:border-gray-400 truncate min-w-[20px] inline-flex items-center gap-1",!e&&"text-gray-400 italic",n),title:"Double click to edit",children:[s.jsx("span",{className:"truncate",children:e||r}),s.jsx("span",{role:"button",onClick:p=>{p.stopPropagation(),p.preventDefault(),c(!0)},className:"opacity-0 group-hover:opacity-100 transition-opacity text-gray-400 hover:text-blue-500 cursor-pointer",title:"Edit",children:s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"w-3 h-3",children:[s.jsx("path",{d:"M5.433 13.917l1.262-3.155A4 4 0 017.58 9.42l6.92-6.918a2.121 2.121 0 013 3l-6.92 6.918c-.383.383-.84.685-1.343.886l-3.154 1.262a.5.5 0 01-.65-.65z"}),s.jsx("path",{d:"M3.5 5.75c0-.69.56-1.25 1.25-1.25H10A.75.75 0 0010 3H4.75A2.75 2.75 0 002 5.75v9.5A2.75 2.75 0 004.75 18h9.5A2.75 2.75 0 0017 15.25V10a.75.75 0 00-1.5 0v5.25c0 .69-.56 1.25-1.25 1.25h-9.5c-.69 0-1.25-.56-1.25-1.25v-9.5z"})]})})]})},tB=e=>e<=1?["w-full"]:e===2?["w-1/2","w-1/2"]:e===3?["w-1/3","w-1/3","w-1/3"]:Array.from({length:e},()=>"flex-1"),rB=[1,2,3,4],nB=k.memo(function({row:t,nodeIdx:r,sIdx:n,rIdx:o,parentType:l,tabKey:i,confirmDelete:c}){const u=se(O=>O.setRowColumns),d=se(O=>O.removeRowFromSection),m=se(O=>O.addRowToSectionAt),f=se(O=>O.setRowTitle),h=se(O=>O.setTabRowColumns),p=se(O=>O.removeTabRow),b=se(O=>O.addRowToTabSectionAt),v=se(O=>O.setTabRowTitle),[g,x]=k.useState(!!t.title),w=t.columns??[],y=w.length===0,E=tB(w.length),j=O=>{l==="rows"?u(r,n,o,O):h(i,n,o,O)},R=()=>{c("Eliminar fila","¿Estás seguro de que quieres eliminar esta fila? Se perderán todos los campos que contiene.",()=>{l==="rows"?d(r,n,o):p(i,n,o)})},A=O=>{l==="rows"?f(r,n,o,O):v(i,n,o,O),O.trim()||x(!1)},S=()=>{x(!0)};return s.jsxs("div",{className:"space-y-0",children:[(g||t.title)&&s.jsx("div",{className:"px-3 py-2 bg-[var(--color-ds-background-elevated)] border-b border-[var(--color-ds-border-default-50)]",children:s.jsx(ec,{value:t.title||"",onChange:A,placeholder:"Título de la fila (opcional)",className:"text-sm font-medium text-[var(--color-ds-text-primary)]"})}),s.jsxs("div",{className:"px-3 py-2 flex items-center gap-1 bg-[var(--color-ds-background)] border-b border-[var(--color-ds-border-default-50)]",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap flex-1 min-w-0",children:[s.jsxs("span",{className:"text-[11px] leading-none uppercase tracking-wide text-[var(--color-ds-text-secondary)]",children:["Fila ",o+1]}),!g&&!t.title&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"h-3 w-px bg-[var(--color-ds-border-default-50)]"}),s.jsx(me,{size:"xs",variant:"ghost",onClick:S,title:"Añadir título a la fila",icon:Uo,className:"text-[10px] text-[var(--color-ds-text-secondary)]",children:"Título"})]}),s.jsx("div",{className:"h-3 w-px bg-[var(--color-ds-border-default-50)]"}),s.jsx("div",{className:"flex gap-1 flex-wrap",children:rB.map(O=>s.jsx(me,{size:"xs",variant:"outline",className:"rounded-full px-2 py-0.5",onClick:()=>j(O),title:`${O} columna(s)`,children:O},O))})]}),s.jsx(me,{size:"xs",variant:"danger",onClick:R,title:"Eliminar fila",shape:"circle",icon:et})]}),y?s.jsx("div",{className:"rounded-md border border-dashed p-6 text-center border-[var(--color-ds-border-default-50)] text-[var(--color-ds-text-secondary)]",children:'No hay columnas. Usa "+ columna".'}):s.jsx("div",{children:w.map((O,_)=>s.jsx(eB,{col:O,widthClass:E[_],nodeIdx:r,sIdx:n,rIdx:o,cIdx:_,parentType:l,tabKey:i,confirmDelete:c},`${l==="rows"?"col":"tcol"}-${r}-${n}-${o}-${_}`))}),s.jsx("div",{className:"flex justify-center p-1 bg-[var(--color-ds-background-surface)] border-t border-[var(--color-ds-border-default-50)]",children:s.jsx(me,{size:"xs",variant:"ghost",className:"w-full justify-center text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)]",onClick:()=>{l==="rows"?m(r,n,o+1):b(i,n,o+1)},title:"Añadir fila debajo",children:"+ Añadir fila debajo"})})]})});function aB({nodeIdx:e,tabKey:t,insertAt:r}){const n={scope:"tab-section",nodeIdx:e,tabKey:t,insertAt:r},{setNodeRef:o,isOver:l}=sr({id:`tab-section:${e}:${t}:${r}`,data:n});return s.jsx("div",{ref:o,className:["h-2 my-1 w-full rounded-sm transition relative -mx-1 px-1",l?"bg-[var(--color-ds-border-default)]/30 ring-1 ring-[var(--color-ds-border-default)]":"bg-transparent"].join(" "),"aria-label":`Insertar sección de pestaña en posición ${r+1}`})}function oB({nodeIdx:e,tabKey:t,sIdx:r}){const n=`tab-section:${e}:${t}:${r}`,o={kind:"tab-section",nodeIdx:e,tabKey:t,sIdx:r},{attributes:l,listeners:i,setNodeRef:c,isDragging:u}=nn({id:n,data:o});return s.jsx("div",{ref:c,...l,...i,title:"Arrastrar sección de pestaña","aria-grabbed":u,className:"shrink-0 w-6 h-6 grid place-items-center cursor-grab active:cursor-grabbing rounded text-[var(--color-ds-text-primary)] hover:bg-[var(--color-ds-background-muted)]",children:"⇅"})}function Wu({expanded:e,onClick:t,labelExpanded:r,labelCollapsed:n,titleExpanded:o,titleCollapsed:l,className:i=""}){return s.jsx(me,{size:"xs",variant:"ghost","aria-expanded":e,"aria-label":e?r:n,onClick:t,title:e?o??"Colapsar":l??"Expandir",className:`shrink-0 w-8 h-8 p-0 grid place-items-center ${i}`,children:s.jsx(Kt,{className:`w-4 h-4 text-[var(--color-ds-text-primary)] transition-transform duration-150 ${e?"rotate-180":""}`})})}function sB({section:e,onChange:t,formId:r,parentType:n,sectionIndex:o,tabKey:l}){const{translations:i}=At(),{t:c}=gt(),[u,d]=k.useState("");k.useEffect(()=>{const h=e.sectionTitle,p=h&&(h.startsWith("forms.")||h.startsWith("ds."));if(i&&p){const b=i.getTranslation(h);d(b!==h?b:h)}else d(st(c,h))},[e.sectionTitle,i,c]);const m=async()=>{const h=e.sectionTitle||"";if(u===(i&&h.startsWith("forms.")?i.getTranslation(h):st(c,h)))return;if(!i){t(u);return}if((h.startsWith("forms.")||h.startsWith("ds."))&&!h.startsWith("ds."))await i.updateTranslation(h,u);else{const b=r||"defaultForm",v=Date.now().toString(36);let g="";n==="tabs"&&l?g=`forms.${b}.tabs.${l}.sections.s_${v}.title`:g=`forms.${b}.sections.s_${v}.title`,console.log("Generating section key",g,u),await i.updateTranslation(g,u),t(g)}},f=h=>{h.key==="Enter"&&h.currentTarget.blur()};return s.jsx("input",{type:"text",value:u,onChange:h=>d(h.target.value),onBlur:m,onKeyDown:f,className:"bg-transparent font-medium text-[var(--color-ds-text-primary)] placeholder-[var(--color-ds-text-tertiary)] outline-none border-b border-transparent focus:border-[var(--color-ds-border-accent)] transition-colors w-full",placeholder:"Sección sin título"})}const Uu=k.memo(function({section:t,nodeIdx:r,sIdx:n,parentType:o,tabKey:l,confirmDelete:i}){const{t:c}=gt(),[u,d]=k.useState(!1),m=se(x=>{var w,y;return((w=x.schema)==null?void 0:w.formId)||((y=x.schema)==null?void 0:y.id)}),f=se(x=>x.renameSectionAt),h=se(x=>x.removeSectionAt),p=se(x=>x.removeTabSection),b=se(x=>x.renameTabSection),v=x=>{o==="rows"?f(r,n,x):b(l,n,x)},g=()=>{i("Eliminar sección","¿Estás seguro de que quieres eliminar esta sección? Se perderán todos los campos que contiene.",()=>{o==="tabs"&&l?p(l,n):h(r,n)})};return s.jsxs("div",{className:"rounded-lg border border-[var(--color-ds-border-default-50)] overflow-hidden",children:[s.jsx("div",{className:"pr-3 bg-[var(--color-ds-background-surface)] border-b border-[var(--color-ds-border-default-50)]",children:s.jsxs("div",{className:"flex items-center gap-2 min-h-9 py-1",children:[s.jsx(Wu,{expanded:!u,onClick:()=>d(!u),labelExpanded:"Colapsar sección",labelCollapsed:"Expandir sección",className:o==="tabs"?"ml-2":""}),s.jsx("div",{className:"flex-1 min-w-0 px-2 font-medium text-[var(--color-ds-text-primary)]",children:s.jsx(sB,{section:t,onChange:v,formId:m,parentType:o,sectionIndex:n,tabKey:l})}),o==="rows"?s.jsx(GT,{nodeIdx:r,sIdx:n}):s.jsx(oB,{nodeIdx:r,tabKey:l,sIdx:n}),s.jsx("div",{className:"flex flex-wrap gap-1 ml-auto",children:s.jsx(me,{size:"xs",variant:"danger",onClick:g,title:"Eliminar sección",shape:"circle",icon:et})})]})}),!u&&s.jsx("div",{className:"bg-[var(--color-ds-background-page)]",children:t.rows.map((x,w)=>s.jsx(nB,{row:x,nodeIdx:r,sIdx:n,rIdx:w,parentType:o,tabKey:l,confirmDelete:i},`${o==="rows"?"row":"trow"}-${o==="tabs"?l:r}-${w}`))})]})});function nd({nodeIdx:e,insertAt:t}){const r={scope:"tabs-tab",nodeIdx:e,insertAt:t},{setNodeRef:n,isOver:o}=sr({id:`tabs-tab:${e}:${t}`,data:r});return s.jsx("div",{ref:n,className:["w-1 h-5 rounded-md transition",o?"bg-[var(--color-ds-border-default)]/30 ring-1 ring-[var(--color-ds-border-default)]":"bg-transparent"].join(" "),title:`Insertar pestaña en posición ${t+1}`})}function lB({className:e=""}){return s.jsx("svg",{width:"10",height:"10",viewBox:"0 0 10 10","aria-hidden":"true",className:e,fill:"currentColor",children:[1,5].map(t=>[1,4,7].map((r,n)=>s.jsx("circle",{cx:t,cy:r,r:"1"},`${t}-${r}-${n}`)))})}function iB({nodeIdx:e,index:t,tabKey:r,label:n,onRename:o}){const l=`tabs-tab:${e}:${t}:${r}`,i={kind:"tabs-tab",nodeIdx:e,index:t,tabKey:r},{attributes:c,listeners:u,setNodeRef:d,isDragging:m}=nn({id:l,data:i});return s.jsxs("div",{ref:d,...c,...u,tabIndex:0,"aria-grabbed":m,"aria-label":`Arrastrar pestaña "${n}"`,title:`Arrastrar pestaña "${n}"`,className:["inline-flex items-center gap-1 select-none","h-6 px-1.5 rounded-full","text-[11px] leading-none","border border-[var(--color-ds-border-default-50)]","bg-[var(--color-ds-background-surface)]","text-[var(--color-ds-text-primary)]","cursor-grab active:cursor-grabbing","hover:bg-[color-mix(in_srgb,var(--color-ds-background-surface)_85%,black_15%)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-ds-border-default)]",m?"opacity-60":"opacity-100","transition-colors"].join(" "),children:[s.jsx(lB,{className:"text-[var(--color-ds-text-primary)]"}),o?s.jsx(ec,{value:n,onChange:o,className:"max-w-[10rem]",inputClassName:"w-20 text-[11px]"}):s.jsx("span",{className:"truncate max-w-[10rem]",children:n})]})}function cB({tab:e,onChange:t,formId:r}){const{translations:n}=At(),{t:o}=gt(),[l,i]=k.useState("");k.useEffect(()=>{const d=e.label,m=d&&(d.startsWith("forms.")||d.startsWith("ds."));if(n&&m){const f=n.getTranslation(d);i(f!==d?f:d)}else i(st(o,d))},[e.label,n,o]);const c=async()=>{const d=e.label||"";if(l===(n&&d.startsWith("forms.")?n.getTranslation(d):st(o,d)))return;if(!n){t(l);return}if((d.startsWith("forms.")||d.startsWith("ds."))&&!d.startsWith("ds."))await n.updateTranslation(d,l);else{const h=`forms.${r||"defaultForm"}.tabs.${e.key}.label`;await n.updateTranslation(h,l),t(h)}},u=d=>{d.key==="Enter"&&d.currentTarget.blur()};return s.jsx("input",{type:"text",value:l,onChange:d=>i(d.target.value),onBlur:c,onKeyDown:u,className:"bg-transparent text-lg font-bold text-[var(--color-ds-text-primary)] placeholder-[var(--color-ds-text-tertiary)] outline-none border-b border-transparent focus:border-[var(--color-ds-border-accent)] transition-colors flex-1 w-auto min-w-[60px]",placeholder:"Pestaña sin título"})}const dB=k.memo(function({node:t,nodeIdx:r,draggedTabSection:n,confirmDelete:o}){var w;const{t:l}=gt(),[i,c]=k.useState(!1),[u,d]=k.useState(((w=t.tabs[0])==null?void 0:w.key)??""),m=se(y=>y.removeLayoutNode),f=se(y=>y.renameTab),h=se(y=>y.updateTab),p=se(y=>y.addTabAfter),b=se(y=>y.removeTab),v=se(y=>y.addSectionToTab);se(y=>y.renameTabSection);const g=se(y=>{var E,j;return((E=y.schema)==null?void 0:E.formId)||((j=y.schema)==null?void 0:j.id)}),x=t.tabs.map(y=>{const E=y.icon?An(y.icon.name,y.icon.style):null;return{label:st(l,y.label),value:y.key,disabled:!1,icon:E?s.jsx(E,{className:"w-4 h-4"}):null}});return k.useEffect(()=>{u===""&&t.tabs.length>0&&d(t.tabs[0].key)},[t.tabs,u]),s.jsx("div",{className:"space-y-2",children:s.jsxs("div",{className:"rounded-lg border border-[var(--color-ds-border-default-50)] overflow-hidden",children:[s.jsx("div",{className:"bg-[var(--color-ds-background-surface)] border-b border-[var(--color-ds-border-default-50)]",children:s.jsxs("div",{className:"flex items-center gap-2 min-h-9 py-1 pr-2",children:[s.jsx(Wu,{expanded:!i,onClick:()=>c(!i),labelExpanded:"Colapsar pestañas",labelCollapsed:"Expandir pestañas"}),s.jsx("span",{className:"text-[11px] leading-none uppercase tracking-wide text-[var(--color-ds-text-secondary)]",children:"Pestañas"}),s.jsx("div",{className:"ml-auto",children:s.jsx(me,{size:"xs",variant:"danger",onClick:()=>o("Eliminar bloque de pestañas","¿Estás seguro de que quieres eliminar este bloque de pestañas? Se perderá todo su contenido.",()=>m(r)),title:"Eliminar bloque",shape:"circle",icon:et})})]})}),!i&&s.jsxs("div",{className:"bg-[var(--color-ds-background)]",children:[s.jsx("div",{className:"px-3 py-2 border-b border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface-soft)]",children:s.jsxs("span",{className:"text-[10px] uppercase tracking-wider font-medium text-[var(--color-ds-text-tertiary)] flex items-center gap-2",children:["Reordenar pestañas ",s.jsx("span",{className:"text-[var(--color-ds-text-tertiary)]/50 text-[9px] font-normal normal-case",children:"(Arrastrar para ordenar)"})]})}),s.jsx("div",{className:"custom-scroll scrollbar-hidden overflow-x-auto overflow-y-hidden bg-[var(--color-ds-background-surface-soft)]/30 border-b border-[var(--color-ds-border-default-50)]",children:s.jsxs("div",{className:"px-2 py-2 inline-flex items-center gap-1 whitespace-nowrap min-h-[2rem]",role:"list","aria-label":"Reordenar pestañas",children:[s.jsx(nd,{nodeIdx:r,insertAt:0}),t.tabs.map((y,E)=>s.jsxs(k.Fragment,{children:[s.jsx(iB,{nodeIdx:r,index:E,tabKey:y.key,label:y.label,onRename:j=>f==null?void 0:f(y.key,j)}),s.jsx(nd,{nodeIdx:r,insertAt:E+1})]},`tabchip-${r}-${y.key}`))]})}),s.jsx("div",{children:s.jsx(xr,{options:x,value:u,onChange:y=>d(y),children:t.tabs.reduce((y,E)=>(y[E.key]=s.jsxs("div",{className:"space-y-3",children:[u===E.key&&s.jsxs("div",{className:"flex flex-wrap items-center justify-between px-3 pt-3 pb-1 mb-1 gap-y-2",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-[150px]",children:[s.jsx("div",{className:"flex-shrink-0",children:s.jsx(Wr,{value:E.icon,onChange:j=>h==null?void 0:h(E.key,{icon:j})})}),s.jsx(cB,{tab:E,onChange:j=>h==null?void 0:h(E.key,{label:j}),formId:g})]}),s.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0 ml-auto",children:[s.jsxs("button",{onClick:()=>h==null?void 0:h(E.key,{disabled:!E.disabled}),className:`
409
409
  flex items-center gap-1.5 px-2 py-1 rounded-full text-[10px] font-medium transition-colors border
410
410
  ${E.disabled?"bg-red-50 text-red-700 border-red-200 hover:bg-red-100":"bg-[var(--color-ds-background-surface)] text-[var(--color-ds-text-tertiary)] border-[var(--color-ds-border-default-50)] hover:text-[var(--color-ds-text-primary)] hover:border-[var(--color-ds-border-default)]"}
411
- `,title:E.disabled?"Click para habilitar":"Click para deshabilitar",children:[E.disabled?s.jsx(Ca,{className:"w-3 h-3"}):s.jsx(Pd,{className:"w-3 h-3"}),s.jsx("span",{className:E.disabled?"inline":"hidden sm:inline",children:E.disabled?"Deshabilitada":"Habilitada"})]}),s.jsx("div",{className:"h-4 w-px bg-[var(--color-ds-border-default-50)]"}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(me,{icon:_n,size:"sm",variant:"primary",shape:"circle",onClick:()=>v==null?void 0:v(E.key,"Nueva sección"),title:"Añadir nueva sección",className:"shadow-sm"}),s.jsx(pa,{align:"right",trigger:s.jsx("div",{className:"p-1.5 rounded-md hover:bg-[var(--color-ds-background-surface-soft)] text-[var(--color-ds-text-secondary)] transition-colors cursor-pointer",children:s.jsx(Zd,{className:"w-5 h-5"})}),items:[{label:"Añadir Pestaña",icon:ai,onSelect:()=>p==null?void 0:p(E.key)},{separator:!0},{label:"Eliminar Pestaña",icon:pt,variant:"danger",disabled:t.tabs.length<=1,onSelect:()=>o("Eliminar pestaña","¿Estás seguro de que quieres eliminar esta pestaña? Se perderá todo su contenido.",()=>b==null?void 0:b(E.key))}]})]})]})]}),Array.from({length:E.sections.length+1}).map((j,R)=>{const A=R,S=E.sections[A],O=(n==null?void 0:n.nodeIdx)===r&&(n==null?void 0:n.tabKey)===E.key&&R===n.sIdx+1;return s.jsxs(k.Fragment,{children:[s.jsx("div",{className:"px-2",children:!O&&s.jsx(aB,{nodeIdx:r,tabKey:E.key,insertAt:R})}),A<E.sections.length&&s.jsx(Uu,{section:S,nodeIdx:r,sIdx:A,parentType:"tabs",tabKey:E.key,confirmDelete:o})]},`tsec-${E.key}-${R}`)})]}),y),{})})})]})]})})});function uB(){const e=se(f=>f.schema.layout),t=se(f=>f.editorSettings),[r,n]=k.useState(null),[o,l]=k.useState(null),[i,c]=k.useState({isOpen:!1,title:"",message:null,onConfirm:()=>{}});Ia({onDragStart:f=>{const{active:h}=f,p=h.data.current;p&&p.kind==="rows-section"&&n(p.sIdx),p&&p.kind==="tab-section"&&l({nodeIdx:p.nodeIdx,tabKey:p.tabKey,sIdx:p.sIdx})},onDragEnd:()=>{n(null),l(null)},onDragCancel:()=>{n(null),l(null)}});const u=k.useCallback((f,h,p)=>{if(!t.confirmDelete){p();return}c({isOpen:!0,title:f,message:h,onConfirm:p})},[t.confirmDelete]),d=()=>{i.onConfirm(),c(f=>({...f,isOpen:!1}))},m=()=>{c(f=>({...f,isOpen:!1}))};return s.jsxs("div",{id:"designer-canvas-root",className:"space-y-3 relative",children:[e.map((f,h)=>{if(f.type==="rows"){const p=f.sections;return s.jsx("div",{className:"space-y-3",children:Array.from({length:p.length+1}).map((b,v)=>{const g=v,x=p[g];return s.jsxs(k.Fragment,{children:[!(r!==null&&v===r+1)&&s.jsx(qT,{nodeIdx:h,insertAt:v}),g<p.length&&s.jsx(Uu,{section:x,nodeIdx:h,sIdx:g,parentType:"rows",confirmDelete:u})]},`rows-slot-sec-${h}-${v}`)})},`rows-${h}`)}return f.type==="tabs"?s.jsx(dB,{node:f,nodeIdx:h,draggedTabSection:o,confirmDelete:u},`tabs-${h}`):null}),s.jsx(St,{isOpen:i.isOpen,onClose:m,title:i.title,footer:s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(me,{variant:"outline",onClick:m,children:"Cancelar"}),s.jsx(me,{variant:"danger",onClick:d,children:"Eliminar"})]}),children:s.jsx("p",{className:"text-sm text-[var(--color-ds-text-secondary)]",children:i.message})})]})}const qu=(e,t,r)=>Math.max(t,Math.min(r,e));function ad(e){const t=[`li:${e.li}`];return e.tabIdx!=null&&t.push(`t:${e.tabIdx}`),t.push(`s:${e.sectionIdx}`,`r:${e.rowIdx}`,`c:${e.colIdx}`,`f:${e.fieldIdx}`),t.join("|")}function Qn(e){const t=Object.fromEntries(e.split("|").map(r=>r.split(":")));return{li:Number(t.li),tabIdx:t.t!=null?Number(t.t):void 0,sectionIdx:Number(t.s),rowIdx:Number(t.r),colIdx:Number(t.c),fieldIdx:Number(t.f)}}function od(e,t){var n,o,l,i,c,u,d;const r=e[t.li];if(!r)return null;if(r.type==="rows"){const m=(n=r.sections)==null?void 0:n[t.sectionIdx],f=(o=m==null?void 0:m.rows)==null?void 0:o[t.rowIdx];return((l=f==null?void 0:f.columns)==null?void 0:l[t.colIdx])??null}if(r.type==="tabs"){const m=(i=r.tabs)==null?void 0:i[t.tabIdx??0],f=(c=m==null?void 0:m.sections)==null?void 0:c[t.sectionIdx],h=(u=f==null?void 0:f.rows)==null?void 0:u[t.rowIdx];return((d=h==null?void 0:h.columns)==null?void 0:d[t.colIdx])??null}return null}function fB(e,t,r){if(t.li===r.li&&(t.tabIdx??-1)===(r.tabIdx??-1)&&t.sectionIdx===r.sectionIdx&&t.rowIdx===r.rowIdx&&t.colIdx===r.colIdx&&t.fieldIdx===r.fieldIdx)return e;const n=JSON.parse(JSON.stringify(e.layout)),o=od(n,{li:t.li,tabIdx:t.tabIdx,sectionIdx:t.sectionIdx,rowIdx:t.rowIdx,colIdx:t.colIdx}),l=od(n,{li:r.li,tabIdx:r.tabIdx,sectionIdx:r.sectionIdx,rowIdx:r.rowIdx,colIdx:r.colIdx});if(!o||!Array.isArray(o.fields)||!l||!Array.isArray(l.fields))return e;const i=[...o.fields];if(t.fieldIdx<0||t.fieldIdx>=i.length)return e;const[c]=i.splice(t.fieldIdx,1);o.fields=i;const u=[...l.fields],d=qu(r.fieldIdx??u.length,0,u.length);return u.splice(d,0,c),l.fields=u,{...e,layout:n}}function mB(e,t){const r=JSON.parse(JSON.stringify(e.layout)),o=(u=>{var m,f,h,p,b,v,g,x,w,y,E,j;const d=r[u.li];return d?d.type==="rows"?((b=(p=(h=(f=(m=d.sections)==null?void 0:m[u.sectionIdx])==null?void 0:f.rows)==null?void 0:h[u.rowIdx])==null?void 0:p.columns)==null?void 0:b[u.colIdx])??null:d.type==="tabs"?((j=(E=(y=(w=(x=(g=(v=d.tabs)==null?void 0:v[u.tabIdx??0])==null?void 0:g.sections)==null?void 0:x[u.sectionIdx])==null?void 0:w.rows)==null?void 0:y[u.rowIdx])==null?void 0:E.columns)==null?void 0:j[u.colIdx])??null:null:null})({li:t.li,tabIdx:t.tabIdx,sectionIdx:t.sectionIdx,rowIdx:t.rowIdx,colIdx:t.colIdx});if(!o||!Array.isArray(o.fields))return e;const l=[...o.fields];if(t.fieldIdx<0||t.fieldIdx>=l.length)return e;const[i]=l.splice(t.fieldIdx,1);o.fields=l;const c=[...e.fields||[]];if(i){let u=0;const d=m=>{Array.isArray(m)&&m.includes(i)&&u++};if(r.forEach(m=>{var f,h;m.type==="rows"?(f=m.sections)==null||f.forEach(p=>{var b;return(b=p.rows)==null?void 0:b.forEach(v=>{var g;return(g=v.columns)==null?void 0:g.forEach(x=>d(x.fields))})}):m.type==="tabs"&&((h=m.tabs)==null||h.forEach(p=>{var b;return(b=p.sections)==null?void 0:b.forEach(v=>{var g;return(g=v.rows)==null?void 0:g.forEach(x=>{var w;return(w=x.columns)==null?void 0:w.forEach(y=>d(y.fields))})})}))}),u===0){const m=c.findIndex(f=>f.name===i);m!==-1&&c.splice(m,1)}}return{...e,layout:r,fields:c}}function hB(e,t){const r=new Set(e.map(l=>l.name));let n=1,o=`${t}_${n}`;for(;r.has(o);)n++,o=`${t}_${n}`;return o}function pB(e,t,r){const n=hB(e.fields||[],t.type||"field"),o={...t,name:n},l=[...e.fields||[],o],i=JSON.parse(JSON.stringify(e.layout)),u=(m=>{var h,p,b,v,g,x,w,y,E,j,R,A;const f=i[m.li];return f?f.type==="rows"?((g=(v=(b=(p=(h=f.sections)==null?void 0:h[m.sectionIdx])==null?void 0:p.rows)==null?void 0:b[m.rowIdx])==null?void 0:v.columns)==null?void 0:g[m.colIdx])??null:f.type==="tabs"?((A=(R=(j=(E=(y=(w=(x=f.tabs)==null?void 0:x[m.tabIdx??0])==null?void 0:w.sections)==null?void 0:y[m.sectionIdx])==null?void 0:E.rows)==null?void 0:j[m.rowIdx])==null?void 0:R.columns)==null?void 0:A[m.colIdx])??null:null:null})({li:r.li,tabIdx:r.tabIdx,sectionIdx:r.sectionIdx,rowIdx:r.rowIdx,colIdx:r.colIdx});if(!u)return{...e,fields:l};Array.isArray(u.fields)||(u.fields=[]);const d=qu(r.fieldIdx??u.fields.length,0,u.fields.length);return u.fields.splice(d,0,n),{...e,fields:l,layout:i}}const Gu=k.createContext(null),Ku=()=>{const e=k.useContext(Gu);if(!e)throw new Error("useRelations must be used inside <RelationsProvider>");return e},gB=e=>{const{registerFieldEl:t}=Ku();return k.useCallback(r=>{e&&t(e,r)},[e,t])},vB=({children:e})=>{const[t,r]=k.useState(!1),[n,o]=k.useState(null),[l,i]=k.useState({}),c=k.useRef({}),u=p=>r(b=>typeof p=="boolean"?p:!b),d=k.useCallback((p,b)=>{c.current[p]=b},[]);k.useEffect(()=>{let p=!0,b;const g=(async()=>{try{const{useEditorStore:x}=await Promise.resolve().then(()=>nL),y=x.getState().showRelations??!1;return b=y,p&&r(y),x.subscribe(j=>{const R=j.showRelations??!1;p&&R!==b&&(b=R,r(R))})}catch(x){return console.error("Failed to sync with store:",x),()=>{}}})();return()=>{p=!1,g.then(x=>x())}},[]);const m=k.useRef(null),f=k.useRef({});k.useEffect(()=>{if(!t)return;const p=()=>{const w=m.current;if(!w)return;const y=w.getBoundingClientRect(),E={};for(const[S,O]of Object.entries(c.current)){if(!O)continue;const _=O.getBoundingClientRect();E[S]={x:Math.round(_.left-y.left+_.width/2),y:Math.round(_.top-y.top+_.height/2),w:Math.round(_.width),h:Math.round(_.height)}}const j=f.current;let R=!1;const A=new Set([...Object.keys(E),...Object.keys(j)]);for(const S of A){const O=E[S],_=j[S];if(!O||!_||O.x!==_.x||O.y!==_.y||O.w!==_.w||O.h!==_.h){R=!0;break}}R&&(f.current=E,i(E))},b=()=>requestAnimationFrame(p),v=new ResizeObserver(b);m.current&&v.observe(m.current);const g=new MutationObserver(b);m.current&&g.observe(m.current,{childList:!0,subtree:!0}),window.addEventListener("resize",b,{passive:!0}),document.addEventListener("scroll",b,{passive:!0,capture:!0});const x=new ResizeObserver(b);return Object.values(c.current).forEach(w=>w&&x.observe(w)),b(),()=>{v.disconnect(),g.disconnect(),x.disconnect(),window.removeEventListener("resize",b),document.removeEventListener("scroll",b,{capture:!0})}},[t]);const h=k.useMemo(()=>({enabled:t,toggle:u,registerFieldEl:d,anchors:l,schema:n,setSchema:o}),[t,d,l,n]);return s.jsx(Gu.Provider,{value:h,children:s.jsx("div",{ref:m,className:"relative",children:e})})};function vo(e){return e?e.op==="and"||e.op==="or"?(e.rules??[]).flatMap(vo):e.op==="always"?[]:[e.field]:[]}function al(e){return e!=null&&e.parameters?Object.values(e.parameters).filter(t=>t.type==="field"&&t.fieldRef).map(t=>t.fieldRef):[]}function bB(e){var o,l,i,c,u,d;const t=[];for(const m of e.fields){const f=m.name;if(!f)continue;const h=(o=m.visibleWhen)==null?void 0:o.rule,p=(l=m.disabledWhen)==null?void 0:l.rule,b=(i=m.clearWhen)==null?void 0:i.rule;for(const w of vo(h))t.push({from:w,to:f,kind:"visibleWhen"});for(const w of vo(p))t.push({from:w,to:f,kind:"disabledWhen"});for(const w of vo(b))t.push({from:w,to:f,kind:"clearWhen"});const v=(c=m.visibleWhen)==null?void 0:c.endpoint,g=(u=m.disabledWhen)==null?void 0:u.endpoint,x=(d=m.clearWhen)==null?void 0:d.endpoint;for(const w of al(v))t.push({from:w,to:f,kind:"visibleWhen"});for(const w of al(g))t.push({from:w,to:f,kind:"disabledWhen"});for(const w of al(x))t.push({from:w,to:f,kind:"clearWhen"})}const r=m=>`${m.from}->${m.to}:${m.kind}`,n=new Set;return t.filter(m=>n.has(r(m))?!1:(n.add(r(m)),!0))}const ol={visibleWhen:"var(--color-success-500, #22c55e)",disabledWhen:"var(--color-warning-500, #f59e0b)",clearWhen:"var(--color-info-500, #0ea5e9)"};function sd(e){return{left:e.x-e.w/2,right:e.x+e.w/2,top:e.y-e.h/2,bottom:e.y+e.h/2,cx:e.x,cy:e.y,w:e.w,h:e.h}}function ld(e,t,r=20,n=0){const o=sd(e),l=sd(t),i=1,c=1,u=l.cx-o.cx,d=l.cy-o.cy,f=Math.min(o.bottom,l.bottom)-Math.max(o.top,l.top)>0||Math.abs(u)>Math.abs(d);let h,p,b=[];if(f)if(u>0?(h={x:o.right+i,y:o.cy},p={x:l.left-c,y:l.cy}):(h={x:o.left-i,y:o.cy},p={x:l.right+c,y:l.cy}),Math.abs(h.y-p.y)<5)b=[h,p];else{const x=(h.x+p.x)/2;if(u>0&&h.x>p.x||u<0&&h.x<p.x){const w=Math.max(o.bottom,l.bottom)+r;b=[h,{x:h.x+(u>0?10:-10),y:h.y},{x:h.x+(u>0?10:-10),y:w},{x:p.x-(u>0?10:-10),y:w},{x:p.x-(u>0?10:-10),y:p.y},p]}else b=[h,{x,y:h.y},{x,y:p.y},p]}else if(d>0?(h={x:o.cx,y:o.bottom+i},p={x:l.cx,y:l.top-c}):(h={x:o.right+i,y:o.cy},p={x:l.right+c,y:l.cy}),d>0&&Math.abs(h.x-p.x)<5)b=[h,p];else if(d>0){const x=(h.y+p.y)/2;b=[h,{x:h.x,y:x},{x:p.x,y:x},p]}else{const x=Math.max(o.right,l.right)+r;b=[h,{x,y:h.y},{x,y:p.y},p]}n!==0&&(b=b.map(x=>f?{x:x.x,y:x.y+n}:{x:x.x+n,y:x.y}));let v=`M ${b[0].x},${b[0].y}`;for(let x=1;x<b.length;x++)v+=` L ${b[x].x},${b[x].y}`;let g={x:0,y:0};if(b.length===2)g={x:(b[0].x+b[1].x)/2,y:(b[0].y+b[1].y)/2};else{const x=Math.floor((b.length-1)/2),w=b[x],y=b[x+1];g={x:(w.x+y.x)/2,y:(w.y+y.y)/2}}return{d:v,label:g}}const xB=({enabled:e=!0,anchors:t,schema:r})=>{const n=k.useMemo(()=>r?bB(r):[],[r]),[o,l]=k.useState(null),i=se(m=>m.setSelection),c=se(m=>m.selection),u=(c==null?void 0:c.kind)==="field"?c.name:null,d=k.useMemo(()=>{const m=new Map;return n.forEach(f=>{const h=`${f.from}->${f.to}`;m.has(h)||m.set(h,[]),m.get(h).push(f)}),Array.from(m.entries())},[n]);return!e||!r||n.length===0?null:s.jsxs("svg",{className:"pointer-events-none absolute inset-0 z-50",width:"100%",height:"100%",children:[s.jsxs("defs",{children:[s.jsx("marker",{id:"arrow-head-visibleWhen",viewBox:"0 0 10 10",refX:8,refY:5,markerWidth:4,markerHeight:4,orient:"auto",children:s.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--color-success-500, #22c55e)"})}),s.jsx("marker",{id:"arrow-head-disabledWhen",viewBox:"0 0 10 10",refX:8,refY:5,markerWidth:4,markerHeight:4,orient:"auto",children:s.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--color-warning-500, #f59e0b)"})}),s.jsx("marker",{id:"arrow-head-clearWhen",viewBox:"0 0 10 10",refX:8,refY:5,markerWidth:4,markerHeight:4,orient:"auto",children:s.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--color-info-500, #0ea5e9)"})}),s.jsx("marker",{id:"circle-start-visibleWhen",viewBox:"0 0 10 10",refX:5,refY:5,markerWidth:3,markerHeight:3,children:s.jsx("circle",{cx:5,cy:5,r:3,fill:"var(--color-success-500, #22c55e)"})}),s.jsx("marker",{id:"circle-start-disabledWhen",viewBox:"0 0 10 10",refX:5,refY:5,markerWidth:3,markerHeight:3,children:s.jsx("circle",{cx:5,cy:5,r:3,fill:"var(--color-warning-500, #f59e0b)"})}),s.jsx("marker",{id:"circle-start-clearWhen",viewBox:"0 0 10 10",refX:5,refY:5,markerWidth:3,markerHeight:3,children:s.jsx("circle",{cx:5,cy:5,r:3,fill:"var(--color-info-500, #0ea5e9)"})})]}),d.map(([m,f])=>{const h=f[0],p=t[h.from],b=t[h.to];if(!p||!b)return null;const v=`${m}`,g=o===v,x=!!u&&f.some(D=>D.from===u||D.to===u),w=f[0].kind,y=ol[w];let E=1;g?E=1:o?E=x?.4:.15:u&&(E=x?1:.2);const j=ld(p,b),{label:R}=j,A=f.length>1?f.map(D=>{const M=D.kind.replace("When","");return M.charAt(0).toUpperCase()+M.slice(1)}).join(" + "):h.kind,S=Math.max(80,A.length*6+20),O=()=>{i({kind:"field",name:h.to})},_=f.length,V=3,$=f.map((D,M)=>(M-(_-1)/2)*V);return s.jsxs("g",{style:{opacity:E,transition:"opacity 0.2s"},onMouseEnter:()=>l(v),onMouseLeave:()=>l(null),onClick:O,className:"pointer-events-auto cursor-pointer",children:[f.map((D,M)=>{const z=ol[D.kind],{d:te}=ld(p,b,20,$[M]),Q=!!u&&(D.from===u||D.to===u),ne=g||Q?1.75:1,ae=`url(#arrow-head-${D.kind})`,K=`url(#circle-start-${D.kind})`;return s.jsxs("g",{children:[s.jsx("path",{d:te,stroke:"transparent",strokeWidth:18,fill:"none"}),s.jsx("path",{d:te,stroke:z,strokeWidth:ne,fill:"none",markerEnd:ae,markerStart:K,strokeLinejoin:"round",strokeDasharray:D.kind==="disabledWhen"?"5 5":void 0})]},`${v}-${D.kind}-${M}`)}),s.jsxs("g",{transform:`translate(${R.x}, ${R.y})`,children:[s.jsx("rect",{x:-S/2,y:-10,width:S,height:20,rx:4,ry:4,fill:"var(--color-ds-background-page, #f8fafc)",stroke:y,strokeWidth:1,className:"shadow-sm"}),s.jsx("text",{x:0,y:4,textAnchor:"middle",fontSize:10,fontWeight:600,fill:"var(--color-ds-text-primary, #0f172a)",style:{pointerEvents:"none"},children:A}),f.length>1&&s.jsx("g",{transform:"translate(0, 15)",children:f.map((D,M)=>{const z=ol[D.kind],te=(M-(f.length-1)/2)*20;return s.jsx("circle",{cx:te,cy:0,r:3,fill:z,stroke:"white",strokeWidth:1},M)})})]})]},v)})]})};function id(e,t){if(!e||!t)return;const r=t==="outline"?Cn:Sn;let n=r==null?void 0:r[e];return!n&&(r!=null&&r.default)&&(n=r.default[e]),n||console.warn(`[IconResolver] Icon "${e}" (${t}) no encontrado en @heroicons/react/24/${t}. Revisa tu versión o el nombre. Exports disponibles (outline):`,Object.keys(t==="outline"?Cn:Sn)),console.log(n),n||void 0}function ur(e){if(!(!e||typeof e!="object"))return console.log(id(e.name,e.style)),id(e.name,e.style)}function wB(e){const{fields:t,fieldsByName:r,control:n,errors:o,isSubmitting:l,loadingDefaults:i,asyncOptionsMap:c,adapterOptionsMap:u,evalContainer:d,disabledMap:m,registry:f,methods:h,translateFn:p,onUpdateField:b,isDesignMode:v,systemContext:g={}}=e,x=()=>se.getState().fieldPick,w=E=>se.getState().completeFieldPick(E),y=(E,j)=>{if(!j)return E;const R=x(),A=R.armed,S=A&&R.forField===j,O=A&&!S,_=D=>{A&&(D.preventDefault(),D.stopPropagation(),!S&&w(j))},V=D=>{A&&O&&(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),D.stopPropagation(),w(j))},$=A?S?"opacity-40 cursor-not-allowed":"cursor-pointer transition-all rounded border border-[color-mix(in_srgb,var(--color-ds-border-default)_40%,transparent)] hover:border-[color-mix(in_srgb,var(--color-ds-border-default)_70%,transparent)] hover:bg-[color-mix(in_srgb,var(--color-ds-background-accent)_5%,transparent)]":"";return s.jsx("div",{onClick:_,onKeyDown:V,tabIndex:O?0:-1,className:$,role:O?"button":void 0,"aria-label":O?`Seleccionar campo ${j}`:void 0,children:E})};return function E(j){var te,Q,ne,ae,K;let R;if(typeof j=="string"){if(R=r[j],R||(R=(t??[]).find(N=>(N==null?void 0:N.name)===j)),!R)return null}else R=j;R.visibleWhen;let A=!!R.disabled;const S=R.disabledWhen,O=d(S,!1);S!=null&&S.enabled&&(A=O),!(S!=null&&S.enabled)&&"name"in R&&R.name&&m[R.name]&&(A=!0);const _=R==null?void 0:R.name;if(R.type==="search"){const N=typeof R.searchFn=="function",I=Co(R.searchSource,R.endpointConfig),re=async fe=>{if(N)return R.searchFn(fe,{getValues:h.getValues,watch:h.watch});if(I){const le=R.endpointConfig?Ar(R.endpointConfig.parameters,h.getValues,g):{},he=f==null?void 0:f[I];if(typeof he=="function")return await he(fe,{getValues:h.getValues,watch:h.watch,params:le,...g});if(Array.isArray(he))return he}return[]},G={};R.searchMode&&(G.searchMode=R.searchMode),R.minChars&&(G.minChars=R.minChars),R.debounceMs&&(G.debounceMs=R.debounceMs),R.resolveByValue&&(G.resolveByValue=R.resolveByValue);const X=s.jsx(Ri,{name:R.name,control:n,searchFn:re,label:p(R.label),size:R.size,width:R.width,disabled:A||l,...G},R.name);return y(X,_)}if(R.type==="inputGroup"){const N=R,I=(N.inputs??[]).map(G=>{var ie;const X=typeof G=="string"?r[G]??(t??[]).find(ve=>(ve==null?void 0:ve.name)===G):G;if(!X)return null;const fe=X.disabledWhen;let le=!!X.disabled;const he=d(fe,!1);fe!=null&&fe.enabled&&(le=he),!(fe!=null&&fe.enabled)&&m[X.name]&&(le=!0);const ce={name:X.name,control:n,label:p(X.label),size:X.size,width:X.width,placeholder:p(X.placeholder),hasError:!!o[X.name],errorMessage:p((ie=o[X.name])==null?void 0:ie.message),loading:!1,disabled:le||l,suffixButton:X.suffixButton,reserveErrorSpace:!0,labelPrefixIcon:ur(X.labelPrefixIcon),labelSuffixIcon:ur(X.labelSuffixIcon),prefixIcon:ur(X.prefixIcon),suffixIcon:ur(X.suffixIcon)};return X.type==="select"?{...ce,options:X.options??u[X.name]??c[X.name]??[],loadOptions:X.options||X.optionSource||X.endpointConfig?void 0:X.loadOptions}:{...ce,type:X.type}}).filter(Boolean),re=s.jsx(Ei,{groupLabel:p(N.groupLabel),inputs:I,separator:N.separator,useSeparator:N.useSeparator,className:N.className,showVisibleLabel:N.showVisibleLabel,size:N.size},`inputGroup_${N.name??N.groupLabel??"group"}`);return y(re,N.name)}if(R.type==="button"){const N=R,I=N.icon,re=I&&typeof I=="object"&&I.name&&I.style?ur(I):void 0,G=s.jsx("div",{className:"self-center",children:s.jsx(me,{type:"button",variant:N.variant,size:N.size,width:N.width,icon:re,iconPosition:N.iconPosition,ariaLabel:p(N.ariaLabel),onClick:N.onClick,disabled:A||l,children:p(N.label)})},N.name);return y(G,_)}const V=R.suffixButton,$=typeof V=="string"?E(V):V,D=p(R.label),M=v&&b&&R.name?s.jsx(ec,{value:D,onChange:N=>{const I=se.getState().schema.formId||"defaultForm",re=R.name,G=`forms.${I}.fields.${re}.label`;na.updateTranslation(G,N),b(re,{label:G})},placeholder:"Sin etiqueta",className:"font-medium"}):D,z={name:R.name,control:n,disabled:A||l,label:M,size:R.size,width:R.width,placeholder:p(R.placeholder),info:(()=>{const N=R.info;return N&&typeof N=="object"&&(N.type==="complex"||"header"in N||"template"in N)?N.template?p(N.template):"":p(N)})(),infoHeader:(()=>{const N=R.info;if(N&&typeof N=="object"&&(N.type==="complex"||"header"in N||"template"in N))return N.header||void 0})(),suffixButton:$,labelPrefixIcon:ur(R.labelPrefixIcon),labelSuffixIcon:ur(R.labelSuffixIcon),prefixIcon:ur(R.prefixIcon),suffixIcon:ur(R.suffixIcon)};switch(R.type){case"select":{const N=R.name,I=R.options??u[N]??c[N]??[],re=!R.options&&!R.optionSource&&!R.endpointConfig&&R.loadOptions,G=s.jsx(mt,{name:N,control:n,render:({field:X})=>{var fe;return s.jsx(Ge,{...z,value:X.value,onChange:X.onChange,options:I,onBlur:X.onBlur,loadOptions:re||void 0,hasError:!!o[N],errorMessage:p((fe=o[N])==null?void 0:fe.message),suffixButton:$,mode:"menu",searchable:!0,searchPlaceholder:p("common.search"),noOptionsText:p("common.noMatches")})}},`${N}`);return y(G,_)}case"iban":{const N=R.name;return y(s.jsx(mt,{name:N,control:n,render:({field:re,fieldState:G})=>{var X;return s.jsx(ts,{...z,value:re.value??"",onChange:re.onChange,onBlur:re.onBlur,hasError:!!o[N],error:p((X=o[N])==null?void 0:X.message),reserveErrorSpace:!0})}},N),_)}case"dni":{const N=R.name;return y(s.jsx(mt,{name:N,control:n,render:({field:re,fieldState:G})=>{var X;return s.jsx(Si,{...z,value:re.value??"",onChange:re.onChange,onBlur:re.onBlur,hasError:!!o[N],error:p((X=o[N])==null?void 0:X.message),reserveErrorSpace:!0})}},N),_)}case"textarea":{const N=s.jsx(mt,{name:R.name,control:n,render:({field:I,fieldState:re})=>{var G;return s.jsx(or,{...z,value:I.value,onChange:I.onChange,onBlur:I.onBlur,maxLength:R.maxLength,showCounter:!!R.showCounter,hasError:!!o[R.name],errorMessage:p((G=o[R.name])==null?void 0:G.message)})}},R.name);return y(N,_)}case"file":{const N=s.jsx(xi,{...z,defaultValue:[],maxFiles:R.maxFiles,accept:R.accept,hideDropZone:R.hideDropZone,hasError:!!o[R.name],errorMessage:p((te=o[R.name])==null?void 0:te.message)},R.name);return y(N,_)}case"checkbox":{const N=s.jsx(tt,{...z,defaultValue:!1,hasError:!!o[R.name],errorMessage:p((Q=o[R.name])==null?void 0:Q.message),name:R.name},R.name);return y(N,_)}case"date":{const N=s.jsx(Nn,{...z,defaultValue:"",showTime:!!R.showTime,hasError:!!o[R.name],errorMessage:p((ne=o[R.name])==null?void 0:ne.message)},R.name);return y(N,_)}case"optionGroup":{const N=s.jsx(es,{...z,options:R.options||[],multiple:R.multiple,vertical:R.vertical,groupLabel:R.groupLabel,defaultValue:R.defaultValue,className:R.width?void 0:"w-full",name:R.name},R.name);return y(N,_)}case"toggle":{const N=s.jsx(Mi,{...z,checked:R.defaultValue??!1,errorMessage:p((ae=o[R.name])==null?void 0:ae.message),name:R.name},R.name);return y(N,_)}case"table":{const N=R.columns??[],I=R.endpointConfig;let re;I&&(re=async()=>{const X=I.key;if(!X)return[];const fe=Ar(I.parameters,h.getValues,g),le=f==null?void 0:f[X];return typeof le=="function"?await le(fe):(console.warn(`Provider factory for key "${X}" not found in registry.`),[])});const G=s.jsx(l1,{columns:N,loadData:re,idAccessor:R.idAccessor||"id",className:R.className},R.name);return y(G,_)}default:{const N=s.jsx(Xo,{...z,type:R.type,loadingDefaults:i,hasError:!!o[R.name],errorMessage:p((K=o[R.name])==null?void 0:K.message),suffixButton:$,name:R.name},R.name);return y(N,_)}}}}function yB(e){var r;return e?!!((r=e.closest)!=null&&r.call(e,'button,[role="button"],a[href],input,select,textarea,[contenteditable="true"],[data-interactive="true"]')):!1}function jB(e){var r;return e?!!((r=e.closest)!=null&&r.call(e,'[data-input-group-root],[data-input-group],[data-role="input-group"],.input-group,.InputGroup')):!1}function Kn(e){var t;e.preventDefault(),e.stopPropagation(),(t=e.nativeEvent)!=null&&t.stopImmediatePropagation&&e.nativeEvent.stopImmediatePropagation()}function kB({id:e,children:t,onDelete:r,fieldName:n,chromeDisabled:o=!1}){const{attributes:l,listeners:i,setNodeRef:c,transform:u,transition:d,isDragging:m}=ku({id:e,disabled:o}),f=se(g=>g.setSelection),h={transform:br.Transform.toString(u),transition:d},p="opacity-0 scale-95 group-hover:opacity-100 group-hover:scale-100 group-focus-within:opacity-100 group-focus-within:scale-100",b=g=>{const x=g.target;yB(x)||jB(x)||n&&(g.stopPropagation(),f({kind:"field",name:n}))},v=g=>{Kn(g)};return s.jsxs("div",{ref:c,style:h,className:["relative",o?"":"group",m?"z-30":"z-0"].filter(Boolean).join(" "),onClickCapture:b,onDoubleClick:v,onDoubleClickCapture:v,children:[!o&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:["pointer-events-none absolute -inset-0.5 rounded-lg","bg-[var(--color-ds-background-surface)]/80","border border-dashed border-[var(--color-ds-border-default-50)]","transition-all duration-150 ease-out",p,m?"opacity-100 scale-100":""].join(" ")}),s.jsxs("div",{className:["pointer-events-none absolute -top-3 right-2 flex gap-1 z-40","transition-all duration-150 ease-out",p,m?"opacity-100 scale-100":""].join(" "),children:[r&&s.jsx("button",{type:"button","aria-label":"Eliminar campo",className:["pointer-events-auto inline-flex items-center justify-center","w-7 h-7 rounded-full","bg-[var(--color-ds-background-surface)]","border border-[var(--color-ds-border-default-50)]","text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-danger)]","focus:outline-none focus:ring-2 focus:ring-[var(--color-ds-border-default-50)]","transition-colors"].join(" "),onClick:g=>{g.preventDefault(),g.stopPropagation(),r==null||r(e)},onDoubleClick:Kn,onDoubleClickCapture:Kn,children:s.jsx(pt,{className:"w-4 h-4"})}),s.jsx("button",{type:"button","aria-label":"Mover campo","data-drag-handle":!0,className:["pointer-events-auto inline-flex items-center justify-center","w-8 h-8 rounded-full cursor-grab active:cursor-grabbing touch-none","bg-[var(--color-ds-background-surface)]","border border-[var(--color-ds-border-default-50)]","text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)]","focus:outline-none focus:ring-2 focus:ring-[var(--color-ds-border-default-50)]","transition-colors"].join(" "),...l,...i,onDoubleClick:Kn,onDoubleClickCapture:Kn,children:s.jsx(Hl,{className:"w-4 h-4"})})]})]}),s.jsx("div",{className:"relative z-10",children:t})]})}function EB(e,t){if(!t||t.kind!=="row-in-section"&&t.kind!=="row-in-tab-section")return!1;const r=n=>e.insertAt===n||e.insertAt===n+1;if(e.scope==="row-slot"){if(t.kind==="row-in-section"&&t.li===e.li&&t.sIdx===e.sIdx&&r(t.rIdx))return!0}else if(e.scope==="tab-row-slot"&&t.kind==="row-in-tab-section"&&t.li===e.li&&t.tabKey===e.tabKey&&t.sIdx===e.sIdx&&r(t.rIdx))return!0;return!1}function so(e){const t=e.scope==="row-slot"?{scope:"row-slot",li:e.li,sIdx:e.sIdx,insertAt:e.insertAt}:{scope:"tab-row-slot",li:e.li,tabKey:e.tabKey,sIdx:e.sIdx,insertAt:e.insertAt},r=e.scope==="row-slot"?`row-slot|li:${e.li}|s:${e.sIdx}|i:${e.insertAt}`:`tab-row-slot|li:${e.li}|t:${e.tabKey}|s:${e.sIdx}|i:${e.insertAt}`,{setNodeRef:n,isOver:o}=sr({id:r,data:t}),[l,i]=k.useState(void 0);return Ia({onDragStart:d=>{i(d.active.data.current)},onDragEnd:()=>i(void 0),onDragCancel:()=>i(void 0)}),EB(e,l)?s.jsx("div",{ref:n,style:{display:"none"}}):s.jsx("div",{className:"w-full relative transition-all duration-200 ease-in-out",style:{height:o?60:0,pointerEvents:"none",zIndex:o?10:0},children:s.jsx("div",{ref:n,className:"absolute left-0 right-0",style:{top:o?0:-12,height:o?"100%":24,zIndex:o?10:2,pointerEvents:"auto"},children:o&&s.jsx("div",{className:"w-full h-full rounded-md border border-dashed border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background)]/60 relative",style:{boxShadow:"inset 0 0 0 1px color-mix(in srgb, var(--color-ds-border-default-50) 30%, transparent)"},children:s.jsx("div",{className:"absolute -top-2 left-3 px-1.5 py-0.5 rounded text-[11px] leading-none",style:{background:"var(--color-ds-background-elevated)",color:"var(--color-ds-text-secondary)",border:"1px solid var(--color-ds-border-default-50)"},children:"Soltar fila aquí"})})})})}function cd(e){const t=e.kind==="row-in-section"?{kind:"row-in-section",li:e.li,sIdx:e.sIdx,rIdx:e.rIdx}:{kind:"row-in-tab-section",li:e.li,tabKey:e.tabKey,sIdx:e.sIdx,rIdx:e.rIdx},r=e.kind==="row-in-section"?`row|li:${e.li}|s:${e.sIdx}|r:${e.rIdx}`:`tab-row|li:${e.li}|t:${e.tabKey}|s:${e.sIdx}|r:${e.rIdx}`,{attributes:n,listeners:o,setNodeRef:l,isDragging:i}=nn({id:r,data:t});return s.jsx("div",{ref:l,"aria-label":"Handle de arrastre de fila",style:{position:"absolute",left:"50%",top:-14,transform:"translateX(-50%)",zIndex:2147483647,pointerEvents:e.visible?"auto":"none",opacity:e.visible?1:0,transition:"opacity .12s ease"},...o,...n,children:s.jsx("div",{className:"flex items-center justify-center bg-[var(--color-ds-background-elevated)]/85 backdrop-blur-sm px-1 py-0.5 rounded-lg border border-[var(--color-ds-border-default-50)] shadow-sm",children:s.jsx("div",{title:"Mover fila (arrastrar)",className:"flex items-center justify-center rounded hover:bg-[var(--color-ds-background-muted)] transition-colors",style:{cursor:i?"grabbing":"grab",touchAction:"none",padding:"2px 6px"},children:s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",className:"w-4 h-4 text-[var(--color-ds-text-secondary)]",children:s.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3.75 9h16.5m-16.5 6.75h16.5"})})})})})}function RB(e){const r={text:()=>({label:"ds.fields.defaults.text.label",type:"text",width:"w-full",placeholder:"ds.fields.defaults.text.placeholder",size:"sm"}),number:()=>({label:"ds.fields.defaults.number.label",type:"number",width:"w-full",placeholder:"ds.fields.defaults.number.placeholder",size:"sm",validation:{required:!1}}),email:()=>({label:"ds.fields.defaults.email.label",type:"email",width:"w-full",placeholder:"ds.fields.defaults.email.placeholder",size:"sm"}),password:()=>({label:"ds.fields.defaults.password.label",type:"password",width:"w-full",placeholder:"ds.fields.defaults.password.placeholder",size:"sm",validation:{minLength:8}}),tel:()=>({label:"ds.fields.defaults.tel.label",type:"tel",width:"w-full",placeholder:"ds.fields.defaults.tel.placeholder",size:"sm"}),url:()=>({label:"ds.fields.defaults.url.label",type:"url",width:"w-full",placeholder:"ds.fields.defaults.url.placeholder",size:"sm"}),select:()=>({label:"ds.fields.defaults.select.label",type:"select",width:"w-full",size:"sm",options:[{label:"Opción A",value:"A"},{label:"Opción B",value:"B"}]}),checkbox:()=>({label:"ds.fields.defaults.checkbox.label",type:"checkbox",width:"w-full",size:"sm",defaultValue:!1}),textarea:()=>({label:"ds.fields.defaults.textarea.label",type:"textarea",width:"w-full",size:"sm",maxLength:300,showCounter:!0,placeholder:"ds.fields.defaults.textarea.placeholder"}),date:()=>({label:"ds.fields.defaults.date.label",type:"date",width:"w-full",size:"sm",showTime:!1}),file:()=>({label:"ds.fields.defaults.file.label",type:"file",width:"w-full",maxFiles:1,accept:".pdf,.doc,.docx"}),inputGroup:()=>({label:"Grupo",type:"inputGroup",width:"w-full",fields:[]}),search:()=>({label:"ds.fields.defaults.search.label",type:"search",width:"w-full",placeholder:"ds.fields.defaults.search.placeholder",size:"sm",searchMode:"button"}),optionGroup:()=>({label:"Selecciona opciones",type:"optionGroup",width:"w-full",size:"sm",multiple:!0,vertical:!0,options:[{label:"Opción 1",value:"opt1"},{label:"Opción 2",value:"opt2"},{label:"Opción 3",value:"opt3"}]}),array:()=>({label:"Lista repetible",type:"array",width:"w-full",items:[]}),button:()=>({label:"Botón",type:"button",width:"w-auto",variant:"primary",size:"sm"}),iban:()=>({label:"ds.fields.defaults.iban.label",type:"iban",width:"w-full",placeholder:"ds.fields.defaults.iban.placeholder",size:"sm",validation:{required:!1}}),table:()=>({label:"Tabla de Datos",type:"table",width:"w-full",size:"sm",columns:[{header:"ID",accessor:"id",width:"w-16"},{header:"Nombre",accessor:"name",width:"w-auto"}]})}[e];return r?r():{type:e}}function CB(e){return typeof e=="function"}function ea(e,t){if(!e||!t)return null;const r=t==="outline"?Cn:Sn,n=r==null?void 0:r[e];return CB(n)?n:null}function Pl(e){var c,u,d,m,f,h,p,b;if(!e||typeof e!="object")return e;if(e.type==="inputGroup"){const v=e,g={...v};return Array.isArray(v.inputs)&&(g.inputs=v.inputs.map(x=>typeof x=="string"?x:Pl(x))),g}const t=e,r={...t},n=ea((c=t.labelPrefixIcon)==null?void 0:c.name,(u=t.labelPrefixIcon)==null?void 0:u.style),o=ea((d=t.labelSuffixIcon)==null?void 0:d.name,(m=t.labelSuffixIcon)==null?void 0:m.style),l=ea((f=t.prefixIcon)==null?void 0:f.name,(h=t.prefixIcon)==null?void 0:h.style),i=ea((p=t.suffixIcon)==null?void 0:p.name,(b=t.suffixIcon)==null?void 0:b.style);return n&&(r.labelPrefixIcon=n),o&&(r.labelSuffixIcon=o),l&&(r.prefixIcon=l),i&&(r.suffixIcon=i),r}function SB({name:e,children:t}){const r=gB(e);return s.jsx("div",{ref:r,"data-field":e,style:{position:"relative"},children:t})}function dd(e){return e.startsWith("row|")?Object.fromEntries(e.slice(4).split(";").map(r=>r.split(":"))):{}}function NB(e,t){const r=dd(e),n=dd(t);return r.ctx===n.ctx&&r.li===n.li&&r.s===n.s&&(r.t??"")===(n.t??"")}function ud(e,t){if(!e.startsWith("col|"))return Qn(e);const r=Object.fromEntries(e.slice(4).split(";").map(i=>i.split(":"))),n=r.ctx==="rows"?`rows|li:${r.li}|s:${r.s}|r:${r.r}|c:${r.c}`:`tabs|li:${r.li}|t:${r.t}|s:${r.s}|r:${r.r}|c:${r.c}`,o=(t[n]??[]).length,l=Object.prototype.hasOwnProperty.call(r,"insertAt");return{li:Number(r.li),tabIdx:r.t?Number(r.t):void 0,sectionIdx:Number(r.s),rowIdx:Number(r.r),colIdx:Number(r.c),fieldIdx:l?Number(r.insertAt):o}}function AB(e,t){const r=Array.from(e.querySelectorAll("[data-sortable-item]"));if(!r.length)return{insertAt:0,yAbs:e.getBoundingClientRect().top+8};let n=r.length,o=r[r.length-1].getBoundingClientRect().bottom;for(let l=0;l<r.length;l++){const i=r[l].getBoundingClientRect(),c=(i.top+i.bottom)/2;if(t<c){n=l,o=i.top;break}}return{insertAt:n,yAbs:o}}function MB(e){k.useEffect(()=>{if(!e)return;let t=0;const r=()=>{const n=document.getElementById("form-renderer-root");if(!n){t=requestAnimationFrame(r);return}const o=n.getBoundingClientRect(),l=window.__lastPointerY,i=80,c=14;typeof l=="number"&&(l<o.top+i?window.scrollBy({top:-c}):l>o.bottom-i&&window.scrollBy({top:c})),t=requestAnimationFrame(r)};return t=requestAnimationFrame(r),()=>cancelAnimationFrame(t)},[e])}function OB(e){const t=e.replaceAll("|",";");return t.startsWith("rows;")?`col|ctx:rows;${t.slice(5)}`:t.startsWith("tabs;")?`col|ctx:tabs;${t.slice(5)}`:`col|${t}`}function LB({droppableId:e,children:t,className:r,scope:n,li:o,tabIdx:l,sectionIdx:i,rowIdx:c,colIdx:u}){const d=n?{scope:n,...n==="rows-column"?{rowsNodeIdx:o}:{tabKey:`tab-${l}`},s:i,r:c,c:u,insertAt:0}:void 0,{isOver:m,setNodeRef:f}=sr({id:e,data:d});return s.jsx("div",{ref:f,className:["relative min-h-[28px] h-full overflow-visible transition-[box-shadow,border-color] duration-100",m?"ring-1 ring-[var(--color-ds-border-default-50)] rounded":"",r??""].join(" "),style:{isolation:"isolate"},"data-droppable-col":!0,children:t})}function $B(e,t){var n,o,l,i,c,u,d,m,f;const r=e.layout[t.li];if(r)return r.type==="rows"?(i=(l=(o=(n=r.sections[t.sectionIdx])==null?void 0:n.rows[t.rowIdx])==null?void 0:o.columns[t.colIdx])==null?void 0:l.fields)==null?void 0:i[t.fieldIdx]:(f=(m=(d=(u=(c=r.tabs[t.tabIdx])==null?void 0:c.sections[t.sectionIdx])==null?void 0:u.rows[t.rowIdx])==null?void 0:d.columns[t.colIdx])==null?void 0:m.fields)==null?void 0:f[t.fieldIdx]}function fd({ctx:e,visible:t}){const{t:r}=gt(),n=se(j=>j.addColumnToRow),o=se(j=>j.setRowColumns),l=se(j=>j.removeLastColumn),i=se(j=>j.addRowToSectionAt),c=se(j=>j.addColumnToTabRow),u=se(j=>j.setTabRowColumns),d=se(j=>j.removeLastTabColumn),m=se(j=>j.addRowToTabSectionAt),f=()=>e.kind==="rows"?n==null?void 0:n(e.sectionIdx,e.rowIdx):c==null?void 0:c(e.tabKey,e.sectionIdx,e.rowIdx),h=()=>e.kind==="rows"?l==null?void 0:l(e.sectionIdx,e.rowIdx):d==null?void 0:d(e.tabKey,e.sectionIdx,e.rowIdx),p=j=>e.kind==="rows"?o==null?void 0:o(e.sectionIdx,e.rowIdx,j):u==null?void 0:u(e.tabKey,e.sectionIdx,e.rowIdx,j),b=()=>e.kind==="rows"?i==null?void 0:i(e.sectionIdx,e.rowIdx):m==null?void 0:m(e.tabKey,e.sectionIdx,e.rowIdx),v=()=>e.kind==="rows"?i==null?void 0:i(e.sectionIdx,e.rowIdx+1):m==null?void 0:m(e.tabKey,e.sectionIdx,e.rowIdx+1),[g,x]=k.useState({isOpen:!1,title:"",message:null,onConfirm:()=>{}}),w=(j,R,A)=>{x({isOpen:!0,title:j,message:R,onConfirm:A})},y=()=>{g.onConfirm(),x(j=>({...j,isOpen:!1}))},E=()=>{x(j=>({...j,isOpen:!1}))};return s.jsxs("div",{"aria-label":"Acciones de fila",style:{position:"absolute",insetInlineEnd:6,insetBlockStart:-25,zIndex:2147483646,pointerEvents:t?"auto":"none",opacity:t?1:0,transition:"opacity .12s ease"},className:"flex items-center gap-1",children:[s.jsxs("div",{className:"flex items-center gap-1 bg-[var(--color-ds-background-elevated)]/85 backdrop-blur-sm px-1.5 py-1 rounded-lg border border-[var(--color-ds-border-default-50)] shadow-sm",children:[s.jsx(me,{size:"xs",variant:"ghost",title:r("ds.editor.actions.addRow"),onClick:b,children:"↑"}),s.jsx(me,{size:"xs",variant:"ghost",title:r("ds.editor.actions.addRow"),onClick:v,children:"↓"}),s.jsx("span",{className:"w-px h-4 bg-[var(--color-ds-border-default-50)] mx-1","aria-hidden":!0}),s.jsx(me,{size:"xs",variant:"ghost",title:r("ds.editor.actions.addColumn"),onClick:f,children:"+"}),s.jsx(me,{size:"xs",variant:"ghost",title:r("ds.editor.actions.deleteColumn"),onClick:()=>w(r("ds.editor.confirmations.deleteColumn.title"),r("ds.editor.confirmations.deleteColumn.message"),h),children:"−"}),s.jsx("span",{className:"w-px h-4 bg-[var(--color-ds-border-default-50)] mx-1","aria-hidden":!0}),[1,2,3,4].map(j=>s.jsx(me,{size:"xs",variant:"ghost",title:`Distribuir en ${j} columna(s)`,onClick:()=>p(j),children:j},j))]}),s.jsx(St,{isOpen:g.isOpen,onClose:E,title:g.title,footer:s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(me,{variant:"outline",onClick:E,children:r("ds.editor.actions.cancel")}),s.jsx(me,{variant:"danger",onClick:y,children:r("ds.editor.actions.delete")})]}),children:s.jsx("p",{className:"text-sm text-[var(--color-ds-text-secondary)]",children:g.message})})]})}function IB({schema:e,onSchemaChange:t,deps:r,layoutEditMode:n=!1}){const{t:o}=gt(),l=se(U=>U.updateField),i=se(U=>U.mode),c=Jr(U=>U.setRuntimeState),u=Jr(U=>U.systemContext);k.useEffect(()=>{if(!e.variables)return;const U={};e.variables.forEach(J=>{J.type==="constant"&&(U[J.key]=J.value)}),e.variables.forEach(J=>{if(J.type==="computed"&&J.value)try{const oe=new Function("ctx",`return (${J.value});`);U[J.key]=oe(U)}catch(oe){console.warn(`[FormRendererDnd] Error evaluating computed variable "${J.key}":`,oe),U[J.key]=null}}),Object.keys(U).length>0&&c({systemContext:U})},[e.variables,c]);const d=k.useMemo(()=>({...r,translateFn:(U,J)=>{const oe=st(o,U,J);return oe?Sl(oe,u):""},onUpdateField:(U,J)=>{l(U,oe=>{Object.assign(oe,J)})},isDesignMode:i==="design"}),[r,o,l,i,u]),m=k.useCallback((U,J)=>{const oe=st(o,U,J);return oe?Sl(oe,u):""},[o,u]),f=k.useMemo(()=>wB(d),[d]),h=se(U=>U.selection),p=(h==null?void 0:h.kind)==="field"?h.name:void 0,v=se(U=>U.fieldPick).armed,{enabled:g,anchors:x,setSchema:w}=Ku();k.useEffect(()=>{w(e)},[e,w]);const[y,E]=k.useState(null),[j,R]=k.useState(null),A=k.useRef({}),S=k.useCallback(U=>J=>{A.current[U]=J},[]),O=k.useRef(null),_=k.useRef(null),V=k.useRef(null),$=U=>{_.current==null&&(_.current=requestAnimationFrame(()=>{_.current=null;const J=V.current;JSON.stringify(J)!==JSON.stringify(U)&&(V.current=U,R(U))}))},D=k.useMemo(()=>{const U={};return e.layout.forEach((J,oe)=>{J.type==="tabs"&&(U[oe]=J.tabs[0].key)}),U},[e.layout]),[M,z]=k.useState(D),[te,Q]=k.useState({isOpen:!1,title:"",message:null,onConfirm:()=>{}}),ne=(U,J,oe)=>{Q({isOpen:!0,title:U,message:J,onConfirm:oe})},ae=()=>{te.onConfirm(),Q(U=>({...U,isOpen:!1}))},K=()=>{Q(U=>({...U,isOpen:!1}))},N=k.useMemo(()=>{const U={};return e.layout.forEach((J,oe)=>{J.type==="rows"?J.sections.forEach((de,pe)=>{de.rows.forEach((be,je)=>{be.columns.forEach((ye,Fe)=>{const $e=`rows|li:${oe}|s:${pe}|r:${je}|c:${Fe}`;U[$e]=(ye.fields??[]).map((Ee,Oe)=>ad({li:oe,sectionIdx:pe,rowIdx:je,colIdx:Fe,fieldIdx:Oe}))})})}):J.type==="tabs"&&J.tabs.forEach((de,pe)=>{de.sections.forEach((be,je)=>{be.rows.forEach((ye,Fe)=>{ye.columns.forEach(($e,Ee)=>{const Oe=`tabs|li:${oe}|t:${pe}|s:${je}|r:${Fe}|c:${Ee}`;U[Oe]=($e.fields??[]).map((_e,ze)=>ad({li:oe,tabIdx:pe,sectionIdx:je,rowIdx:Fe,colIdx:Ee,fieldIdx:ze}))})})})})}),U},[e]),I=k.useMemo(()=>{const U={};return Object.entries(N).forEach(([J,oe])=>oe.forEach(de=>U[de]=J)),U},[N]),re=Fi(On(_a,{activationConstraint:{distance:6}}),On(Fa,{coordinateGetter:Eu})),G="__phantom__",[X,fe]=k.useState(!1),[le,he]=k.useState(null),[ce,ie]=k.useState(null),[ve,ue]=k.useState(40),[xe,C]=k.useState(null),[q,ee]=k.useState(null),W=k.useCallback(U=>{if(!U)return!1;if(typeof U=="string"){const J=r.fieldsByName[U];return!!J&&J.type==="inputGroup"}return(U==null?void 0:U.type)==="inputGroup"},[r.fieldsByName]),H=U=>{var je;const J=String(((je=U.active)==null?void 0:je.id)??""),oe=Bi(U),de=oe[0],pe=de?String(de.id):null;if(pe&&I[pe]&&I[J]&&I[pe]===I[J])return oe;const be=jL(U);if(J.startsWith("row|")||J.startsWith("tab-row|")){const ye=be.filter(Fe=>String(Fe.id).startsWith("row-slot|")||String(Fe.id).startsWith("tab-row-slot|"));if(ye.length)return ye}else{const ye=be.filter(Fe=>String(Fe.id).startsWith("col|"));if(ye.length)return ye}return oe};Ia({onDragStart:U=>{var de,pe,be,je,ye,Fe;fe(!0);const J=String(U.active.id??"");he(J),ie(I[J]??null),O.current=J.startsWith("row|")?"row":"field";const oe=((pe=(de=U.active.rect.current)==null?void 0:de.translated)==null?void 0:pe.height)??((je=(be=U.active.rect.current)==null?void 0:be.initial)==null?void 0:je.height)??40;if(ue(Math.max(24,Math.floor(oe))),O.current==="field"&&!J.startsWith("col|")&&!J.startsWith("palette:"))try{const $e=Qn(J),Ee=(ye=e.layout)==null?void 0:ye[$e.li],_e=(Fe=((Ee==null?void 0:Ee.type)==="rows"?Ee.sections[$e.sectionIdx].rows[$e.rowIdx].columns[$e.colIdx]:Ee.tabs[$e.tabIdx].sections[$e.sectionIdx].rows[$e.rowIdx].columns[$e.colIdx]).fields)==null?void 0:Fe[$e.fieldIdx??0],ze=_e&&Pl(_e);C(ze?f(ze):null)}catch{C(null)}else C(null)},onDragOver:U=>{var Fe,$e;const J=String(((Fe=U.over)==null?void 0:Fe.id)??""),oe=String((($e=U.active)==null?void 0:$e.id)??""),de=U.activatorEvent;if(de&&typeof de.clientY=="number"&&(window.__lastPointerY=de.clientY),O.current==="row"){if(J.startsWith("row|")&&oe.startsWith("row|"))if(NB(oe,J)&&oe!==J){const Ee=A.current[J],Oe=(de==null?void 0:de.clientY)??0;if(Ee&&Oe){const _e=Ee.getBoundingClientRect(),ze=Oe<_e.top+_e.height/2?"before":"after";$({rid:J,pos:ze})}else $(null)}else $(null);else $(null);ee(null);return}if(!J.startsWith("col|")){ee(null);return}const pe=Object.fromEntries(J.slice(4).split(";").map(Ee=>Ee.split(":"))),be=pe.ctx==="rows"?`rows|li:${pe.li}|s:${pe.s}|r:${pe.r}|c:${pe.c}`:`tabs|li:${pe.li}|t:${pe.t}|s:${pe.s}|r:${pe.r}|c:${pe.c}`,je=document.querySelector(`[data-col-key="${be}"]`),ye=(de==null?void 0:de.clientY)??0;if(je&&ye){const{insertAt:Ee,yAbs:Oe}=AB(je,ye),_e=je.getBoundingClientRect().top;ee({overId:J,keyId:be,insertAt:Ee,yRel:Oe-_e})}else ee(null)},onDragCancel:U=>{fe(!1),he(null),ie(null),ue(40),C(null),ee(null),R(null),O.current=null,_.current&&(cancelAnimationFrame(_.current),_.current=null),V.current=null},onDragEnd:()=>{fe(!1),he(null),ie(null),ue(40),C(null),R(null),O.current=null,_.current&&(cancelAnimationFrame(_.current),_.current=null),V.current=null}}),MB(X);const Y=k.useCallback(U=>{const{active:J,over:oe}=U;if(!(J!=null&&J.id)||!(oe!=null&&oe.id)){ee(null),R(null);return}const de=J.data.current,pe=oe.data.current;if(((de==null?void 0:de.kind)==="row-in-section"||(de==null?void 0:de.kind)==="row-in-tab-section")&&((pe==null?void 0:pe.scope)==="row-slot"||(pe==null?void 0:pe.scope)==="tab-row-slot")){const Ee=de.li,Oe=de.sIdx,_e=de.rIdx,ze=pe.li,nt=pe.sIdx,Se=pe.insertAt,Ne={...e,layout:[...e.layout]},Me={...Ne.layout[Ee]};Ne.layout[Ee]=Me;let Ae=null,Ie=null,Be=null;if(de.kind==="row-in-section"&&Me.type==="rows")Me.sections=[...Me.sections],Ie={...Me.sections[Oe]},Me.sections[Oe]=Ie,Ie.rows=[...Ie.rows],Ae=Ie.rows;else if(de.kind==="row-in-tab-section"&&Me.type==="tabs"){Me.tabs=[...Me.tabs];const qe=Me.tabs.findIndex(He=>He.key===de.tabKey);qe>=0&&(Be={...Me.tabs[qe]},Me.tabs[qe]=Be,Be.sections=[...Be.sections],Ie={...Be.sections[Oe]},Be.sections[Oe]=Ie,Ie.rows=[...Ie.rows],Ae=Ie.rows)}if(!Ae)return;let Ve=null,De=null;if(Ee===ze?De=Me:(De={...Ne.layout[ze]},Ne.layout[ze]=De),pe.scope==="row-slot"&&De.type==="rows")if(De.sections===Me.sections||(De.sections=[...De.sections]),Ee===ze&&Oe===nt&&de.kind==="row-in-section")Ve=Ae;else{const qe={...De.sections[nt]};De.sections[nt]=qe,qe.rows=[...qe.rows],Ve=qe.rows}else if(pe.scope==="tab-row-slot"&&De.type==="tabs"){De.tabs===Me.tabs||(De.tabs=[...De.tabs]);const qe=De.tabs.findIndex(He=>He.key===pe.tabKey);if(qe>=0){let He=De.tabs[qe];if(Ee===ze&&de.kind==="row-in-tab-section"&&de.tabKey===pe.tabKey?He=Be:(He={...He},De.tabs[qe]=He),He.sections===(Be==null?void 0:Be.sections)||(He.sections=[...He.sections]),Ee===ze&&Oe===nt&&de.kind==="row-in-tab-section"&&de.tabKey===pe.tabKey)Ve=Ae;else{const at={...He.sections[nt]};He.sections[nt]=at,at.rows=[...at.rows],Ve=at.rows}}}if(!Ve)return;const[vt]=Ae.splice(_e,1);let Ze=Se;Ae===Ve&&_e<Se&&(Ze-=1),Ve.splice(Ze,0,vt),t(Ne),ee(null),R(null);return}if((de==null?void 0:de.kind)==="palette-field"){const Ee=String(oe.id);if(!Ee.startsWith("col|")){ee(null),R(null);return}const Oe=Object.fromEntries(Ee.slice(4).split(";").map(Me=>Me.split(":"))),_e=q&&q.overId===Ee?q.insertAt:Oe.insertAt?Number(Oe.insertAt):0,ze={li:Number(Oe.li),tabIdx:Oe.t!=null?Number(Oe.t):void 0,sectionIdx:Number(Oe.s),rowIdx:Number(Oe.r),colIdx:Number(Oe.c),fieldIdx:_e},nt=de.factoryKind,Se=RB(nt),Ne=pB(e,Se,ze);ee(null),R(null),t(Ne);return}const be=String(J.id),je=String(oe.id);if(be.startsWith("row|")&&je.startsWith("row|"),be.startsWith("palette:")){ee(null),R(null);return}const ye=Qn(be);let Fe;if(je.startsWith("col|")&&q&&q.overId===je){const Ee=Object.fromEntries(je.slice(4).split(";").map(_e=>_e.split(":"))),Oe=`col|${Object.entries(Ee).filter(([_e])=>_e!=="insertAt").map(([_e,ze])=>`${_e}:${ze}`).join(";")};insertAt:${q.insertAt}`;Fe=ud(Oe,N)}else Fe=ud(je,N);const $e=fB(e,ye,Fe);ee(null),R(null),t($e)},[e,t,N,q]);function L(U,J){let oe=U;if(le&&ce&&ce!==J&&(oe=oe.filter(de=>de!==le)),X&&q&&q.keyId===J){const de=Math.max(0,Math.min(q.insertAt,oe.length)),pe=oe.slice();return pe.splice(de,0,G),pe}return oe}const Z=({keyId:U,ids:J,className:oe,tabKey:de})=>{const pe=OB(U),be=L(J,U),je=Object.fromEntries(U.split("|").map(Se=>Se.split(":"))),ye=U.startsWith("rows|"),Fe=ye?"rows-column":"tabs-column",$e=Number(je.li),Ee=je.t!=null?Number(je.t):void 0,Oe=Number(je.s),_e=Number(je.r),ze=Number(je.c),nt=J.length;return s.jsx(LB,{droppableId:pe,className:oe,scope:Fe,li:$e,tabIdx:Ee,sectionIdx:Oe,rowIdx:_e,colIdx:ze,children:s.jsxs("div",{"data-col-key":U,className:"relative",children:[ye?s.jsx(rr,{scope:"rows-column",rowsNodeIdx:$e,s:Oe,r:_e,c:ze,insertAt:0,suppressAll:nt===0}):de?s.jsx(rr,{scope:"tabs-column",tabKey:de,s:Oe,r:_e,c:ze,insertAt:0,suppressAll:nt===0}):null,X&&q&&q.overId===pe?s.jsx("div",{"aria-hidden":!0,style:{position:"absolute",left:0,right:0,top:Math.max(0,q.yRel-1),height:2,background:"var(--color-ds-border-default)",borderRadius:2}}):null,s.jsx(yu,{items:be,strategy:bu,children:s.jsx("div",{children:be.map((Se,Ne)=>{if(Se===G)return s.jsx("div",{"data-sortable-item":!0,"aria-hidden":!0,style:{height:ve,border:"1px dashed var(--color-ds-border-default-50)",borderRadius:8,background:"color-mix(in srgb, var(--color-ds-border-default-50) 8%, transparent)"}},`${U}-ph-${Ne}`);const Me=Qn(String(Se)),Ae=$B(e,Me);if(!Ae)return s.jsx("div",{"data-sortable-item":!0,"aria-hidden":!0},`${U}-miss-${Ne}`);const Ie=Pl(Ae),Be=typeof Ie=="string"?Ie:(Ie==null?void 0:Ie.name)??"",Ve=!!p&&!!Be&&p===Be,De=f(Ie),vt=W(Ie),Ze=He=>{var at;He.preventDefault(),He.stopPropagation(),(at=He.nativeEvent)!=null&&at.stopImmediatePropagation&&He.nativeEvent.stopImmediatePropagation()},qe=vt?{onDoubleClick:Ze,onDoubleClickCapture:Ze,onClick:Ze,onClickCapture:Ze,onMouseDown:Ze,onMouseDownCapture:Ze,onMouseUp:Ze,onMouseUpCapture:Ze,onPointerDown:Ze,onPointerDownCapture:Ze,onPointerUp:Ze,onPointerUpCapture:Ze,onContextMenu:Ze}:{};return s.jsx("div",{"data-sortable-item":!0,children:s.jsx(kB,{id:String(Se),fieldName:Be,onDelete:He=>{const at=Qn(He);ne("Eliminar campo","¿Estás seguro de que quieres eliminar este campo?",()=>{const Qt=mB(e,at);t(Qt)})},chromeDisabled:v,children:s.jsx(SB,{name:Be,children:s.jsx("div",{className:Ve?"selected-field":void 0,"data-field-name":Be,"aria-selected":Ve||void 0,...qe,children:De})})})},String(Se))})})})]})})},F=X&&O.current==="row",T=(U,J)=>s.jsx(s.Fragment,{children:U.sections.map((oe,de)=>s.jsx("div",{className:"mb-6",children:s.jsx(rt,{title:m(oe.sectionTitle),defaultOpen:oe.defaultOpen,forceOpen:F,children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx(so,{scope:"row-slot",li:J,sIdx:de,insertAt:0}),oe.rows.map((pe,be)=>{const je=`row|li:${J}|s:${de}|r:${be}`,ye=n&&y===je,Fe=le===je;return s.jsxs(k.Fragment,{children:[s.jsxs("div",{ref:S(je),className:`relative transition-all duration-200 ${Fe?"opacity-40 ring-1 ring-dashed ring-[var(--color-ds-border-default)] bg-[var(--color-ds-background-muted)]":n&&ye?"ring-1 ring-[var(--color-ds-border-default-50)]":""}`,onMouseEnter:()=>E(je),onMouseLeave:()=>E($e=>$e===je?null:$e),style:{borderRadius:8},children:[n&&s.jsxs(s.Fragment,{children:[s.jsx(fd,{ctx:{kind:"rows",li:J,sectionIdx:de,rowIdx:be},visible:!!ye&&!v}),s.jsx(cd,{kind:"row-in-section",li:J,sIdx:de,rIdx:be,visible:!!ye&&!v})]}),pe.title&&s.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:m(pe.title)}),s.jsx("div",{className:"flex flex-wrap -mx-2 items-stretch",children:pe.columns.map(($e,Ee)=>{const Oe=`rows|li:${J}|s:${de}|r:${be}|c:${Ee}`,_e=N[Oe]??[];return s.jsx("div",{className:`${$e.width} px-2 flex flex-col`,children:s.jsx(Z,{keyId:Oe,ids:_e})},`col-${J}-${de}-${be}-${Ee}`)})})]}),s.jsx(so,{scope:"row-slot",li:J,sIdx:de,insertAt:be+1})]},`rowwrap-${je}`)})]})})},`sec-${J}-${de}`))}),B=(U,J)=>{var de;const oe=M[J]??((de=U.tabs[0])==null?void 0:de.key);return s.jsx(xr,{options:U.tabs.map(pe=>{const be=pe.icon?ea(pe.icon.name,pe.icon.style):null;return{label:m(pe.label),value:pe.key,disabled:pe.disabled,icon:be?s.jsx(be,{className:"w-4 h-4"}):null}}),value:oe,onChange:pe=>z(be=>({...be,[J]:pe})),children:Object.fromEntries(U.tabs.map((pe,be)=>[pe.key,s.jsx("div",{className:"space-y-6",children:pe.sections.map((je,ye)=>s.jsx("div",{className:"mb-6",children:s.jsx(rt,{title:m(je.sectionTitle),defaultOpen:je.defaultOpen,forceOpen:F,children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx(so,{scope:"tab-row-slot",li:J,tabKey:pe.key,sIdx:ye,insertAt:0}),je.rows.map((Fe,$e)=>{const Ee=`tab-row|li:${J}|t:${pe.key}|s:${ye}|r:${$e}`,Oe=n&&y===Ee,_e=le===Ee;return s.jsxs(k.Fragment,{children:[s.jsxs("div",{ref:S(Ee),className:`relative transition-all duration-200 ${_e?"opacity-40 ring-1 ring-dashed ring-[var(--color-ds-border-default)] bg-[var(--color-ds-background-muted)]":n&&Oe?"ring-1 ring-[var(--color-ds-border-default-50)]":""}`,onMouseEnter:()=>E(Ee),onMouseLeave:()=>E(ze=>ze===Ee?null:ze),style:{borderRadius:8},children:[n&&s.jsxs(s.Fragment,{children:[s.jsx(fd,{ctx:{kind:"tabs",li:J,tabKey:pe.key,tabIdx:be,sectionIdx:ye,rowIdx:$e},visible:!!Oe&&!v}),s.jsx(cd,{kind:"row-in-tab-section",li:J,tabKey:pe.key,sIdx:ye,rIdx:$e,visible:!!Oe&&!v})]}),Fe.title&&s.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:m(Fe.title)}),s.jsx("div",{className:"flex flex-wrap -mx-2 items-stretch",children:Fe.columns.map((ze,nt)=>{const Se=`tabs|li:${J}|t:${be}|s:${ye}|r:${$e}|c:${nt}`,Ne=N[Se]??[];return s.jsx("div",{className:`${ze.width??"flex-1"} px-2 flex flex-col`,children:s.jsx(Z,{keyId:Se,ids:Ne,tabKey:pe.key})},`col-${J}-${be}-${ye}-${$e}-${nt}`)})})]}),s.jsx(so,{scope:"tab-row-slot",li:J,tabKey:pe.key,sIdx:ye,insertAt:$e+1})]},`rowwrap-${Ee}`)})]})})},`sec-${J}-${be}-${ye}`))},`tabpanel-${J}-${be}`)]))},`tabs-${J}`)},P=se(U=>U.setSelection);return s.jsxs(fi,{...r.methods,children:[s.jsxs(Pi,{sensors:re,collisionDetection:H,onDragEnd:Y,children:[s.jsxs("div",{id:"form-renderer-root",className:"relative overflow-visible",onDoubleClick:U=>{P({kind:"none"})},children:[s.jsx("div",{className:"space-y-6 ",children:e.layout.map((U,J)=>U.type==="rows"?s.jsx(k.Fragment,{children:T(U,J)},`rows-${J}`):s.jsx(k.Fragment,{children:B(U,J)},`tabs-${J}`))}),s.jsx(xB,{schema:e,anchors:x,enabled:g})]}),s.jsx(Z1,{dropAnimation:null,children:xe?s.jsx("div",{style:{pointerEvents:"none",opacity:.9},children:xe}):null})]}),s.jsx(St,{isOpen:te.isOpen,onClose:K,title:te.title,footer:s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(me,{variant:"outline",onClick:K,children:"Cancelar"}),s.jsx(me,{variant:"danger",onClick:ae,children:"Eliminar"})]}),children:s.jsx("p",{className:"text-sm text-[var(--color-ds-text-secondary)]",children:te.message})})]})}function FB(e,t,r,n){var j;const{fields:o=[],layout:l,validationSchema:i}=e,c=_B(),u=((j=c==null?void 0:c.services)==null?void 0:j.registry)??void 0,d=Jr(R=>R.systemContext),m=k.useMemo(()=>{if(t)return t;try{const R=i??ki(e);return wi(R)}catch{return}},[t,e,i]),f=gi({resolver:m,mode:"onBlur",reValidateMode:"onChange",defaultValues:e.defaultValues??{}}),h=k.useMemo(()=>(o??[]).filter(R=>R.type!=="inputGroup"&&R.type!=="button"),[o]),{optionsMap:p}=e1(h),b=Y5(o),v=t1(o,f.control),[g,x]=k.useState({}),[w,y]=k.useState(0);k.useEffect(()=>{let R;const A=f.watch(()=>{clearTimeout(R),R=setTimeout(()=>{y(S=>S+1)},500)});return()=>{A.unsubscribe(),clearTimeout(R)}},[f.watch]),k.useEffect(()=>{let R=!0;return(async()=>{const S=await Promise.all(h.filter(_=>_.type==="select"&&(_.optionSource||_.endpointConfig)).map(async _=>{const V=_.name,$=Co(_.optionSource,_.endpointConfig);if(!$)return[V,[]];const D=_.endpointConfig?Ar(_.endpointConfig.parameters,f.getValues,{...d,ACTIVE_VARIANT:n}):{},M=u==null?void 0:u[$];if(typeof M!="function")return[V,[]];try{const z=await Promise.resolve(M("",{getValues:f.getValues,watch:f.watch,params:D,...d})),te=Array.isArray(z)?z:[];return[V,te]}catch{return[V,[]]}}));if(!R)return;const O={};for(const[_,V]of S)O[_]=V;x(O)})(),()=>{R=!1}},[u,f.getValues,f.watch,JSON.stringify(h.map(R=>({n:R.name,os:R.optionSource??null,ec:R.endpointConfig??null}))),n,w]);const E=k.useCallback((R,A)=>{if(!(R!=null&&R.enabled)||!R.rule)return A;try{const S={...f.getValues(),ACTIVE_VARIANT:n};return!!Ao(R.rule,S)}catch{return A}},[f,n]);return{methods:f,control:f.control,formState:f.formState,fields:o,fieldsByName:b,asyncOptionsMap:p,adapterOptionsMap:g,disabledMap:v,evalContainer:E,registry:u,layout:l,systemContext:d}}function _B(){try{return At()??void 0}catch{return}}function TB(e,t,r){const n={...e};return t.top+e.y<=r.top?n.y=r.top-t.top:t.bottom+e.y>=r.top+r.height&&(n.y=r.top+r.height-t.bottom),t.left+e.x<=r.left?n.x=r.left-t.left:t.right+e.x>=r.left+r.width&&(n.x=r.left+r.width-t.right),n}const BB=e=>{let{transform:t,draggingNodeRect:r,windowRect:n}=e;return!r||!n?t:TB(t,r,n)};function un(e){const r={text:()=>({label:"ds.fields.defaults.text.label",type:"text",width:"w-full",placeholder:"ds.fields.defaults.text.placeholder",size:"sm"}),number:()=>({label:"ds.fields.defaults.number.label",type:"number",width:"w-full",placeholder:"ds.fields.defaults.number.placeholder",size:"sm",validation:{required:!1}}),email:()=>({label:"ds.fields.defaults.email.label",type:"email",width:"w-full",placeholder:"ds.fields.defaults.email.placeholder",size:"sm"}),password:()=>({label:"ds.fields.defaults.password.label",type:"password",width:"w-full",placeholder:"ds.fields.defaults.password.placeholder",size:"sm",validation:{minLength:8}}),tel:()=>({label:"ds.fields.defaults.tel.label",type:"tel",width:"w-full",placeholder:"ds.fields.defaults.tel.placeholder",size:"sm"}),url:()=>({label:"ds.fields.defaults.url.label",type:"url",width:"w-full",placeholder:"ds.fields.defaults.url.placeholder",size:"sm"}),select:()=>({label:"ds.fields.defaults.select.label",type:"select",width:"w-full",size:"sm",options:[{label:"Opción A",value:"A"},{label:"Opción B",value:"B"}]}),checkbox:()=>({label:"ds.fields.defaults.checkbox.label",type:"checkbox",width:"w-full",size:"sm",defaultValue:!1}),textarea:()=>({label:"ds.fields.defaults.textarea.label",type:"textarea",width:"w-full",size:"sm",maxLength:300,showCounter:!0,placeholder:"ds.fields.defaults.textarea.placeholder"}),date:()=>({label:"ds.fields.defaults.date.label",type:"date",width:"w-full",size:"sm",showTime:!1}),file:()=>({label:"ds.fields.defaults.file.label",type:"file",width:"w-full",maxFiles:1,accept:".pdf,.doc,.docx"}),inputGroup:()=>({label:"Grupo",type:"inputGroup",width:"w-full",fields:[]}),search:()=>({label:"ds.fields.defaults.search.label",type:"search",width:"w-full",placeholder:"ds.fields.defaults.search.placeholder",size:"sm",searchMode:"button"}),optionGroup:()=>({label:"Selecciona opciones",type:"optionGroup",width:"w-full",size:"sm",multiple:!0,vertical:!0,options:[{label:"Opción 1",value:"opt1"},{label:"Opción 2",value:"opt2"},{label:"Opción 3",value:"opt3"}]}),array:()=>({label:"Lista repetible",type:"array",width:"w-full",items:[]})}[e];return r?r():{type:e}}function ZB(e){if(!e)return null;const t=e.data;if(t.kind==="palette-field"){const r=t.factoryKind,n=X$[r];if(n)return s.jsx("div",{className:"pointer-events-none opacity-95",children:s.jsx("div",{className:`\r
411
+ `,title:E.disabled?"Click para habilitar":"Click para deshabilitar",children:[E.disabled?s.jsx(Ca,{className:"w-3 h-3"}):s.jsx(Pd,{className:"w-3 h-3"}),s.jsx("span",{className:E.disabled?"inline":"hidden sm:inline",children:E.disabled?"Deshabilitada":"Habilitada"})]}),s.jsx("div",{className:"h-4 w-px bg-[var(--color-ds-border-default-50)]"}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(me,{icon:_n,size:"sm",variant:"primary",shape:"circle",onClick:()=>v==null?void 0:v(E.key,"Nueva sección"),title:"Añadir nueva sección",className:"shadow-sm"}),s.jsx(pa,{align:"right",trigger:s.jsx("div",{className:"p-1.5 rounded-md hover:bg-[var(--color-ds-background-surface-soft)] text-[var(--color-ds-text-secondary)] transition-colors cursor-pointer",children:s.jsx(Zd,{className:"w-5 h-5"})}),items:[{label:"Añadir Pestaña",icon:ai,onSelect:()=>p==null?void 0:p(E.key)},{separator:!0},{label:"Eliminar Pestaña",icon:pt,variant:"danger",disabled:t.tabs.length<=1,onSelect:()=>o("Eliminar pestaña","¿Estás seguro de que quieres eliminar esta pestaña? Se perderá todo su contenido.",()=>b==null?void 0:b(E.key))}]})]})]})]}),Array.from({length:E.sections.length+1}).map((j,R)=>{const A=R,S=E.sections[A],O=(n==null?void 0:n.nodeIdx)===r&&(n==null?void 0:n.tabKey)===E.key&&R===n.sIdx+1;return s.jsxs(k.Fragment,{children:[s.jsx("div",{className:"px-2",children:!O&&s.jsx(aB,{nodeIdx:r,tabKey:E.key,insertAt:R})}),A<E.sections.length&&s.jsx(Uu,{section:S,nodeIdx:r,sIdx:A,parentType:"tabs",tabKey:E.key,confirmDelete:o})]},`tsec-${E.key}-${R}`)})]}),y),{})})})]})]})})});function uB(){const e=se(f=>f.schema.layout),t=se(f=>f.editorSettings),[r,n]=k.useState(null),[o,l]=k.useState(null),[i,c]=k.useState({isOpen:!1,title:"",message:null,onConfirm:()=>{}});Ia({onDragStart:f=>{const{active:h}=f,p=h.data.current;p&&p.kind==="rows-section"&&n(p.sIdx),p&&p.kind==="tab-section"&&l({nodeIdx:p.nodeIdx,tabKey:p.tabKey,sIdx:p.sIdx})},onDragEnd:()=>{n(null),l(null)},onDragCancel:()=>{n(null),l(null)}});const u=k.useCallback((f,h,p)=>{if(!t.confirmDelete){p();return}c({isOpen:!0,title:f,message:h,onConfirm:p})},[t.confirmDelete]),d=()=>{i.onConfirm(),c(f=>({...f,isOpen:!1}))},m=()=>{c(f=>({...f,isOpen:!1}))};return s.jsxs("div",{id:"designer-canvas-root",className:"space-y-3 relative",children:[e.map((f,h)=>{if(f.type==="rows"){const p=f.sections;return s.jsx("div",{className:"space-y-3",children:Array.from({length:p.length+1}).map((b,v)=>{const g=v,x=p[g];return s.jsxs(k.Fragment,{children:[!(r!==null&&v===r+1)&&s.jsx(qT,{nodeIdx:h,insertAt:v}),g<p.length&&s.jsx(Uu,{section:x,nodeIdx:h,sIdx:g,parentType:"rows",confirmDelete:u})]},`rows-slot-sec-${h}-${v}`)})},`rows-${h}`)}return f.type==="tabs"?s.jsx(dB,{node:f,nodeIdx:h,draggedTabSection:o,confirmDelete:u},`tabs-${h}`):null}),s.jsx(St,{isOpen:i.isOpen,onClose:m,title:i.title,footer:s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(me,{variant:"outline",onClick:m,children:"Cancelar"}),s.jsx(me,{variant:"danger",onClick:d,children:"Eliminar"})]}),children:s.jsx("p",{className:"text-sm text-[var(--color-ds-text-secondary)]",children:i.message})})]})}const qu=(e,t,r)=>Math.max(t,Math.min(r,e));function ad(e){const t=[`li:${e.li}`];return e.tabIdx!=null&&t.push(`t:${e.tabIdx}`),t.push(`s:${e.sectionIdx}`,`r:${e.rowIdx}`,`c:${e.colIdx}`,`f:${e.fieldIdx}`),t.join("|")}function Qn(e){const t=Object.fromEntries(e.split("|").map(r=>r.split(":")));return{li:Number(t.li),tabIdx:t.t!=null?Number(t.t):void 0,sectionIdx:Number(t.s),rowIdx:Number(t.r),colIdx:Number(t.c),fieldIdx:Number(t.f)}}function od(e,t){var n,o,l,i,c,u,d;const r=e[t.li];if(!r)return null;if(r.type==="rows"){const m=(n=r.sections)==null?void 0:n[t.sectionIdx],f=(o=m==null?void 0:m.rows)==null?void 0:o[t.rowIdx];return((l=f==null?void 0:f.columns)==null?void 0:l[t.colIdx])??null}if(r.type==="tabs"){const m=(i=r.tabs)==null?void 0:i[t.tabIdx??0],f=(c=m==null?void 0:m.sections)==null?void 0:c[t.sectionIdx],h=(u=f==null?void 0:f.rows)==null?void 0:u[t.rowIdx];return((d=h==null?void 0:h.columns)==null?void 0:d[t.colIdx])??null}return null}function fB(e,t,r){if(t.li===r.li&&(t.tabIdx??-1)===(r.tabIdx??-1)&&t.sectionIdx===r.sectionIdx&&t.rowIdx===r.rowIdx&&t.colIdx===r.colIdx&&t.fieldIdx===r.fieldIdx)return e;const n=JSON.parse(JSON.stringify(e.layout)),o=od(n,{li:t.li,tabIdx:t.tabIdx,sectionIdx:t.sectionIdx,rowIdx:t.rowIdx,colIdx:t.colIdx}),l=od(n,{li:r.li,tabIdx:r.tabIdx,sectionIdx:r.sectionIdx,rowIdx:r.rowIdx,colIdx:r.colIdx});if(!o||!Array.isArray(o.fields)||!l||!Array.isArray(l.fields))return e;const i=[...o.fields];if(t.fieldIdx<0||t.fieldIdx>=i.length)return e;const[c]=i.splice(t.fieldIdx,1);o.fields=i;const u=[...l.fields],d=qu(r.fieldIdx??u.length,0,u.length);return u.splice(d,0,c),l.fields=u,{...e,layout:n}}function mB(e,t){const r=JSON.parse(JSON.stringify(e.layout)),o=(u=>{var m,f,h,p,b,v,g,x,w,y,E,j;const d=r[u.li];return d?d.type==="rows"?((b=(p=(h=(f=(m=d.sections)==null?void 0:m[u.sectionIdx])==null?void 0:f.rows)==null?void 0:h[u.rowIdx])==null?void 0:p.columns)==null?void 0:b[u.colIdx])??null:d.type==="tabs"?((j=(E=(y=(w=(x=(g=(v=d.tabs)==null?void 0:v[u.tabIdx??0])==null?void 0:g.sections)==null?void 0:x[u.sectionIdx])==null?void 0:w.rows)==null?void 0:y[u.rowIdx])==null?void 0:E.columns)==null?void 0:j[u.colIdx])??null:null:null})({li:t.li,tabIdx:t.tabIdx,sectionIdx:t.sectionIdx,rowIdx:t.rowIdx,colIdx:t.colIdx});if(!o||!Array.isArray(o.fields))return e;const l=[...o.fields];if(t.fieldIdx<0||t.fieldIdx>=l.length)return e;const[i]=l.splice(t.fieldIdx,1);o.fields=l;const c=[...e.fields||[]];if(i){let u=0;const d=m=>{Array.isArray(m)&&m.includes(i)&&u++};if(r.forEach(m=>{var f,h;m.type==="rows"?(f=m.sections)==null||f.forEach(p=>{var b;return(b=p.rows)==null?void 0:b.forEach(v=>{var g;return(g=v.columns)==null?void 0:g.forEach(x=>d(x.fields))})}):m.type==="tabs"&&((h=m.tabs)==null||h.forEach(p=>{var b;return(b=p.sections)==null?void 0:b.forEach(v=>{var g;return(g=v.rows)==null?void 0:g.forEach(x=>{var w;return(w=x.columns)==null?void 0:w.forEach(y=>d(y.fields))})})}))}),u===0){const m=c.findIndex(f=>f.name===i);m!==-1&&c.splice(m,1)}}return{...e,layout:r,fields:c}}function hB(e,t){const r=new Set(e.map(l=>l.name));let n=1,o=`${t}_${n}`;for(;r.has(o);)n++,o=`${t}_${n}`;return o}function pB(e,t,r){const n=hB(e.fields||[],t.type||"field"),o={...t,name:n},l=[...e.fields||[],o],i=JSON.parse(JSON.stringify(e.layout)),u=(m=>{var h,p,b,v,g,x,w,y,E,j,R,A;const f=i[m.li];return f?f.type==="rows"?((g=(v=(b=(p=(h=f.sections)==null?void 0:h[m.sectionIdx])==null?void 0:p.rows)==null?void 0:b[m.rowIdx])==null?void 0:v.columns)==null?void 0:g[m.colIdx])??null:f.type==="tabs"?((A=(R=(j=(E=(y=(w=(x=f.tabs)==null?void 0:x[m.tabIdx??0])==null?void 0:w.sections)==null?void 0:y[m.sectionIdx])==null?void 0:E.rows)==null?void 0:j[m.rowIdx])==null?void 0:R.columns)==null?void 0:A[m.colIdx])??null:null:null})({li:r.li,tabIdx:r.tabIdx,sectionIdx:r.sectionIdx,rowIdx:r.rowIdx,colIdx:r.colIdx});if(!u)return{...e,fields:l};Array.isArray(u.fields)||(u.fields=[]);const d=qu(r.fieldIdx??u.fields.length,0,u.fields.length);return u.fields.splice(d,0,n),{...e,fields:l,layout:i}}const Gu=k.createContext(null),Ku=()=>{const e=k.useContext(Gu);if(!e)throw new Error("useRelations must be used inside <RelationsProvider>");return e},gB=e=>{const{registerFieldEl:t}=Ku();return k.useCallback(r=>{e&&t(e,r)},[e,t])},vB=({children:e})=>{const[t,r]=k.useState(!1),[n,o]=k.useState(null),[l,i]=k.useState({}),c=k.useRef({}),u=p=>r(b=>typeof p=="boolean"?p:!b),d=k.useCallback((p,b)=>{c.current[p]=b},[]);k.useEffect(()=>{let p=!0,b;const g=(async()=>{try{const{useEditorStore:x}=await Promise.resolve().then(()=>nL),y=x.getState().showRelations??!1;return b=y,p&&r(y),x.subscribe(j=>{const R=j.showRelations??!1;p&&R!==b&&(b=R,r(R))})}catch(x){return console.error("Failed to sync with store:",x),()=>{}}})();return()=>{p=!1,g.then(x=>x())}},[]);const m=k.useRef(null),f=k.useRef({});k.useEffect(()=>{if(!t)return;const p=()=>{const w=m.current;if(!w)return;const y=w.getBoundingClientRect(),E={};for(const[S,O]of Object.entries(c.current)){if(!O)continue;const _=O.getBoundingClientRect();E[S]={x:Math.round(_.left-y.left+_.width/2),y:Math.round(_.top-y.top+_.height/2),w:Math.round(_.width),h:Math.round(_.height)}}const j=f.current;let R=!1;const A=new Set([...Object.keys(E),...Object.keys(j)]);for(const S of A){const O=E[S],_=j[S];if(!O||!_||O.x!==_.x||O.y!==_.y||O.w!==_.w||O.h!==_.h){R=!0;break}}R&&(f.current=E,i(E))},b=()=>requestAnimationFrame(p),v=new ResizeObserver(b);m.current&&v.observe(m.current);const g=new MutationObserver(b);m.current&&g.observe(m.current,{childList:!0,subtree:!0}),window.addEventListener("resize",b,{passive:!0}),document.addEventListener("scroll",b,{passive:!0,capture:!0});const x=new ResizeObserver(b);return Object.values(c.current).forEach(w=>w&&x.observe(w)),b(),()=>{v.disconnect(),g.disconnect(),x.disconnect(),window.removeEventListener("resize",b),document.removeEventListener("scroll",b,{capture:!0})}},[t]);const h=k.useMemo(()=>({enabled:t,toggle:u,registerFieldEl:d,anchors:l,schema:n,setSchema:o}),[t,d,l,n]);return s.jsx(Gu.Provider,{value:h,children:s.jsx("div",{ref:m,className:"relative",children:e})})};function vo(e){return e?e.op==="and"||e.op==="or"?(e.rules??[]).flatMap(vo):e.op==="always"?[]:[e.field]:[]}function al(e){return e!=null&&e.parameters?Object.values(e.parameters).filter(t=>t.type==="field"&&t.fieldRef).map(t=>t.fieldRef):[]}function bB(e){var o,l,i,c,u,d;const t=[];for(const m of e.fields){const f=m.name;if(!f)continue;const h=(o=m.visibleWhen)==null?void 0:o.rule,p=(l=m.disabledWhen)==null?void 0:l.rule,b=(i=m.clearWhen)==null?void 0:i.rule;for(const w of vo(h))t.push({from:w,to:f,kind:"visibleWhen"});for(const w of vo(p))t.push({from:w,to:f,kind:"disabledWhen"});for(const w of vo(b))t.push({from:w,to:f,kind:"clearWhen"});const v=(c=m.visibleWhen)==null?void 0:c.endpoint,g=(u=m.disabledWhen)==null?void 0:u.endpoint,x=(d=m.clearWhen)==null?void 0:d.endpoint;for(const w of al(v))t.push({from:w,to:f,kind:"visibleWhen"});for(const w of al(g))t.push({from:w,to:f,kind:"disabledWhen"});for(const w of al(x))t.push({from:w,to:f,kind:"clearWhen"})}const r=m=>`${m.from}->${m.to}:${m.kind}`,n=new Set;return t.filter(m=>n.has(r(m))?!1:(n.add(r(m)),!0))}const ol={visibleWhen:"var(--color-success-500, #22c55e)",disabledWhen:"var(--color-warning-500, #f59e0b)",clearWhen:"var(--color-info-500, #0ea5e9)"};function sd(e){return{left:e.x-e.w/2,right:e.x+e.w/2,top:e.y-e.h/2,bottom:e.y+e.h/2,cx:e.x,cy:e.y,w:e.w,h:e.h}}function ld(e,t,r=20,n=0){const o=sd(e),l=sd(t),i=1,c=1,u=l.cx-o.cx,d=l.cy-o.cy,f=Math.min(o.bottom,l.bottom)-Math.max(o.top,l.top)>0||Math.abs(u)>Math.abs(d);let h,p,b=[];if(f)if(u>0?(h={x:o.right+i,y:o.cy},p={x:l.left-c,y:l.cy}):(h={x:o.left-i,y:o.cy},p={x:l.right+c,y:l.cy}),Math.abs(h.y-p.y)<5)b=[h,p];else{const x=(h.x+p.x)/2;if(u>0&&h.x>p.x||u<0&&h.x<p.x){const w=Math.max(o.bottom,l.bottom)+r;b=[h,{x:h.x+(u>0?10:-10),y:h.y},{x:h.x+(u>0?10:-10),y:w},{x:p.x-(u>0?10:-10),y:w},{x:p.x-(u>0?10:-10),y:p.y},p]}else b=[h,{x,y:h.y},{x,y:p.y},p]}else if(d>0?(h={x:o.cx,y:o.bottom+i},p={x:l.cx,y:l.top-c}):(h={x:o.right+i,y:o.cy},p={x:l.right+c,y:l.cy}),d>0&&Math.abs(h.x-p.x)<5)b=[h,p];else if(d>0){const x=(h.y+p.y)/2;b=[h,{x:h.x,y:x},{x:p.x,y:x},p]}else{const x=Math.max(o.right,l.right)+r;b=[h,{x,y:h.y},{x,y:p.y},p]}n!==0&&(b=b.map(x=>f?{x:x.x,y:x.y+n}:{x:x.x+n,y:x.y}));let v=`M ${b[0].x},${b[0].y}`;for(let x=1;x<b.length;x++)v+=` L ${b[x].x},${b[x].y}`;let g={x:0,y:0};if(b.length===2)g={x:(b[0].x+b[1].x)/2,y:(b[0].y+b[1].y)/2};else{const x=Math.floor((b.length-1)/2),w=b[x],y=b[x+1];g={x:(w.x+y.x)/2,y:(w.y+y.y)/2}}return{d:v,label:g}}const xB=({enabled:e=!0,anchors:t,schema:r})=>{const n=k.useMemo(()=>r?bB(r):[],[r]),[o,l]=k.useState(null),i=se(m=>m.setSelection),c=se(m=>m.selection),u=(c==null?void 0:c.kind)==="field"?c.name:null,d=k.useMemo(()=>{const m=new Map;return n.forEach(f=>{const h=`${f.from}->${f.to}`;m.has(h)||m.set(h,[]),m.get(h).push(f)}),Array.from(m.entries())},[n]);return!e||!r||n.length===0?null:s.jsxs("svg",{className:"pointer-events-none absolute inset-0 z-50",width:"100%",height:"100%",children:[s.jsxs("defs",{children:[s.jsx("marker",{id:"arrow-head-visibleWhen",viewBox:"0 0 10 10",refX:8,refY:5,markerWidth:4,markerHeight:4,orient:"auto",children:s.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--color-success-500, #22c55e)"})}),s.jsx("marker",{id:"arrow-head-disabledWhen",viewBox:"0 0 10 10",refX:8,refY:5,markerWidth:4,markerHeight:4,orient:"auto",children:s.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--color-warning-500, #f59e0b)"})}),s.jsx("marker",{id:"arrow-head-clearWhen",viewBox:"0 0 10 10",refX:8,refY:5,markerWidth:4,markerHeight:4,orient:"auto",children:s.jsx("path",{d:"M 0 0 L 10 5 L 0 10 z",fill:"var(--color-info-500, #0ea5e9)"})}),s.jsx("marker",{id:"circle-start-visibleWhen",viewBox:"0 0 10 10",refX:5,refY:5,markerWidth:3,markerHeight:3,children:s.jsx("circle",{cx:5,cy:5,r:3,fill:"var(--color-success-500, #22c55e)"})}),s.jsx("marker",{id:"circle-start-disabledWhen",viewBox:"0 0 10 10",refX:5,refY:5,markerWidth:3,markerHeight:3,children:s.jsx("circle",{cx:5,cy:5,r:3,fill:"var(--color-warning-500, #f59e0b)"})}),s.jsx("marker",{id:"circle-start-clearWhen",viewBox:"0 0 10 10",refX:5,refY:5,markerWidth:3,markerHeight:3,children:s.jsx("circle",{cx:5,cy:5,r:3,fill:"var(--color-info-500, #0ea5e9)"})})]}),d.map(([m,f])=>{const h=f[0],p=t[h.from],b=t[h.to];if(!p||!b)return null;const v=`${m}`,g=o===v,x=!!u&&f.some(D=>D.from===u||D.to===u),w=f[0].kind,y=ol[w];let E=1;g?E=1:o?E=x?.4:.15:u&&(E=x?1:.2);const j=ld(p,b),{label:R}=j,A=f.length>1?f.map(D=>{const M=D.kind.replace("When","");return M.charAt(0).toUpperCase()+M.slice(1)}).join(" + "):h.kind,S=Math.max(80,A.length*6+20),O=()=>{i({kind:"field",name:h.to})},_=f.length,V=3,$=f.map((D,M)=>(M-(_-1)/2)*V);return s.jsxs("g",{style:{opacity:E,transition:"opacity 0.2s"},onMouseEnter:()=>l(v),onMouseLeave:()=>l(null),onClick:O,className:"pointer-events-auto cursor-pointer",children:[f.map((D,M)=>{const z=ol[D.kind],{d:te}=ld(p,b,20,$[M]),Q=!!u&&(D.from===u||D.to===u),ne=g||Q?1.75:1,ae=`url(#arrow-head-${D.kind})`,K=`url(#circle-start-${D.kind})`;return s.jsxs("g",{children:[s.jsx("path",{d:te,stroke:"transparent",strokeWidth:18,fill:"none"}),s.jsx("path",{d:te,stroke:z,strokeWidth:ne,fill:"none",markerEnd:ae,markerStart:K,strokeLinejoin:"round",strokeDasharray:D.kind==="disabledWhen"?"5 5":void 0})]},`${v}-${D.kind}-${M}`)}),s.jsxs("g",{transform:`translate(${R.x}, ${R.y})`,children:[s.jsx("rect",{x:-S/2,y:-10,width:S,height:20,rx:4,ry:4,fill:"var(--color-ds-background-page, #f8fafc)",stroke:y,strokeWidth:1,className:"shadow-sm"}),s.jsx("text",{x:0,y:4,textAnchor:"middle",fontSize:10,fontWeight:600,fill:"var(--color-ds-text-primary, #0f172a)",style:{pointerEvents:"none"},children:A}),f.length>1&&s.jsx("g",{transform:"translate(0, 15)",children:f.map((D,M)=>{const z=ol[D.kind],te=(M-(f.length-1)/2)*20;return s.jsx("circle",{cx:te,cy:0,r:3,fill:z,stroke:"white",strokeWidth:1},M)})})]})]},v)})]})};function id(e,t){if(!e||!t)return;const r=t==="outline"?Cn:Sn;let n=r==null?void 0:r[e];return!n&&(r!=null&&r.default)&&(n=r.default[e]),n||console.warn(`[IconResolver] Icon "${e}" (${t}) no encontrado en @heroicons/react/24/${t}. Revisa tu versión o el nombre. Exports disponibles (outline):`,Object.keys(t==="outline"?Cn:Sn)),console.log(n),n||void 0}function ur(e){if(!(!e||typeof e!="object"))return console.log(id(e.name,e.style)),id(e.name,e.style)}function wB(e){const{fields:t,fieldsByName:r,control:n,errors:o,isSubmitting:l,loadingDefaults:i,asyncOptionsMap:c,adapterOptionsMap:u,evalContainer:d,disabledMap:m,registry:f,methods:h,translateFn:p,onUpdateField:b,isDesignMode:v,systemContext:g={}}=e,x=()=>se.getState().fieldPick,w=E=>se.getState().completeFieldPick(E),y=(E,j)=>{if(!j)return E;const R=x(),A=R.armed,S=A&&R.forField===j,O=A&&!S,_=D=>{A&&(D.preventDefault(),D.stopPropagation(),!S&&w(j))},V=D=>{A&&O&&(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),D.stopPropagation(),w(j))},$=A?S?"opacity-40 cursor-not-allowed":"cursor-pointer transition-all rounded border border-[color-mix(in_srgb,var(--color-ds-border-default)_40%,transparent)] hover:border-[color-mix(in_srgb,var(--color-ds-border-default)_70%,transparent)] hover:bg-[color-mix(in_srgb,var(--color-ds-background-accent)_5%,transparent)]":"";return s.jsx("div",{onClick:_,onKeyDown:V,tabIndex:O?0:-1,className:$,role:O?"button":void 0,"aria-label":O?`Seleccionar campo ${j}`:void 0,children:E})};return function E(j){var te,Q,ne,ae,K;let R;if(typeof j=="string"){if(R=r[j],R||(R=(t??[]).find(N=>(N==null?void 0:N.name)===j)),!R)return null}else R=j;R.visibleWhen;let A=!!R.disabled;const S=R.disabledWhen,O=d(S,!1);S!=null&&S.enabled&&(A=O),!(S!=null&&S.enabled)&&"name"in R&&R.name&&m[R.name]&&(A=!0);const _=R==null?void 0:R.name;if(R.type==="search"){const N=typeof R.searchFn=="function",I=Co(R.searchSource,R.endpointConfig),re=async fe=>{if(N)return R.searchFn(fe,{getValues:h.getValues,watch:h.watch});if(I){const le=R.endpointConfig?Ar(R.endpointConfig.parameters,h.getValues,g):{},he=f==null?void 0:f[I];if(typeof he=="function")return await he(fe,{getValues:h.getValues,watch:h.watch,params:le,...g});if(Array.isArray(he))return he}return[]},G={};R.searchMode&&(G.searchMode=R.searchMode),R.minChars&&(G.minChars=R.minChars),R.debounceMs&&(G.debounceMs=R.debounceMs),R.resolveByValue&&(G.resolveByValue=R.resolveByValue);const X=s.jsx(Ri,{name:R.name,control:n,searchFn:re,label:p(R.label),size:R.size,width:R.width,disabled:A||l,...G},R.name);return y(X,_)}if(R.type==="inputGroup"){const N=R,I=(N.inputs??[]).map(G=>{var ie;const X=typeof G=="string"?r[G]??(t??[]).find(ve=>(ve==null?void 0:ve.name)===G):G;if(!X)return null;const fe=X.disabledWhen;let le=!!X.disabled;const he=d(fe,!1);fe!=null&&fe.enabled&&(le=he),!(fe!=null&&fe.enabled)&&m[X.name]&&(le=!0);const ce={name:X.name,control:n,label:p(X.label),size:X.size,width:X.width,placeholder:p(X.placeholder),hasError:!!o[X.name],errorMessage:p((ie=o[X.name])==null?void 0:ie.message),loading:!1,disabled:le||l,suffixButton:X.suffixButton,reserveErrorSpace:!0,labelPrefixIcon:ur(X.labelPrefixIcon),labelSuffixIcon:ur(X.labelSuffixIcon),prefixIcon:ur(X.prefixIcon),suffixIcon:ur(X.suffixIcon)};return X.type==="select"?{...ce,options:X.options??u[X.name]??c[X.name]??[],loadOptions:X.options||X.optionSource||X.endpointConfig?void 0:X.loadOptions}:{...ce,type:X.type}}).filter(Boolean),re=s.jsx(Ei,{groupLabel:p(N.groupLabel),inputs:I,separator:N.separator,useSeparator:N.useSeparator,className:N.className,showVisibleLabel:N.showVisibleLabel,size:N.size},`inputGroup_${N.name??N.groupLabel??"group"}`);return y(re,N.name)}if(R.type==="button"){const N=R,I=N.icon,re=I&&typeof I=="object"&&I.name&&I.style?ur(I):void 0,G=s.jsx("div",{className:"self-center",children:s.jsx(me,{type:"button",variant:N.variant,size:N.size,width:N.width,icon:re,iconPosition:N.iconPosition,ariaLabel:p(N.ariaLabel),onClick:N.onClick,disabled:A||l,children:p(N.label)})},N.name);return y(G,_)}const V=R.suffixButton,$=typeof V=="string"?E(V):V,D=p(R.label),M=v&&b&&R.name?s.jsx(ec,{value:D,onChange:N=>{const I=se.getState().schema.formId||"defaultForm",re=R.name,G=`forms.${I}.fields.${re}.label`;na.updateTranslation(G,N),b(re,{label:G})},placeholder:"Sin etiqueta",className:"font-medium"}):D,z={name:R.name,control:n,disabled:A||l,label:M,size:R.size,width:R.width,placeholder:p(R.placeholder),info:(()=>{const N=R.info;return N&&typeof N=="object"&&(N.type==="complex"||"header"in N||"template"in N)?N.template?p(N.template):"":p(N)})(),infoHeader:(()=>{const N=R.info;if(N&&typeof N=="object"&&(N.type==="complex"||"header"in N||"template"in N))return N.header||void 0})(),suffixButton:$,labelPrefixIcon:ur(R.labelPrefixIcon),labelSuffixIcon:ur(R.labelSuffixIcon),prefixIcon:ur(R.prefixIcon),suffixIcon:ur(R.suffixIcon)};switch(R.type){case"select":{const N=R.name,I=R.options??u[N]??c[N]??[],re=!R.options&&!R.optionSource&&!R.endpointConfig&&R.loadOptions,G=s.jsx(mt,{name:N,control:n,render:({field:X})=>{var fe;return s.jsx(Ge,{...z,value:X.value,onChange:X.onChange,options:I,onBlur:X.onBlur,loadOptions:re||void 0,hasError:!!o[N],errorMessage:p((fe=o[N])==null?void 0:fe.message),suffixButton:$,mode:"menu",searchable:!0,searchPlaceholder:p("ds.fields.defaults.search.placeholder"),noOptionsText:p("ds.fields.defaults.search.noMatches")})}},`${N}`);return y(G,_)}case"iban":{const N=R.name;return y(s.jsx(mt,{name:N,control:n,render:({field:re,fieldState:G})=>{var X;return s.jsx(ts,{...z,value:re.value??"",onChange:re.onChange,onBlur:re.onBlur,hasError:!!o[N],error:p((X=o[N])==null?void 0:X.message),reserveErrorSpace:!0})}},N),_)}case"dni":{const N=R.name;return y(s.jsx(mt,{name:N,control:n,render:({field:re,fieldState:G})=>{var X;return s.jsx(Si,{...z,value:re.value??"",onChange:re.onChange,onBlur:re.onBlur,hasError:!!o[N],error:p((X=o[N])==null?void 0:X.message),reserveErrorSpace:!0})}},N),_)}case"textarea":{const N=s.jsx(mt,{name:R.name,control:n,render:({field:I,fieldState:re})=>{var G;return s.jsx(or,{...z,value:I.value,onChange:I.onChange,onBlur:I.onBlur,maxLength:R.maxLength,showCounter:!!R.showCounter,hasError:!!o[R.name],errorMessage:p((G=o[R.name])==null?void 0:G.message)})}},R.name);return y(N,_)}case"file":{const N=s.jsx(xi,{...z,defaultValue:[],maxFiles:R.maxFiles,accept:R.accept,hideDropZone:R.hideDropZone,hasError:!!o[R.name],errorMessage:p((te=o[R.name])==null?void 0:te.message)},R.name);return y(N,_)}case"checkbox":{const N=s.jsx(tt,{...z,defaultValue:!1,hasError:!!o[R.name],errorMessage:p((Q=o[R.name])==null?void 0:Q.message),name:R.name},R.name);return y(N,_)}case"date":{const N=s.jsx(Nn,{...z,defaultValue:"",showTime:!!R.showTime,hasError:!!o[R.name],errorMessage:p((ne=o[R.name])==null?void 0:ne.message)},R.name);return y(N,_)}case"optionGroup":{const N=s.jsx(es,{...z,options:R.options||[],multiple:R.multiple,vertical:R.vertical,groupLabel:R.groupLabel,defaultValue:R.defaultValue,className:R.width?void 0:"w-full",name:R.name},R.name);return y(N,_)}case"toggle":{const N=s.jsx(Mi,{...z,checked:R.defaultValue??!1,errorMessage:p((ae=o[R.name])==null?void 0:ae.message),name:R.name},R.name);return y(N,_)}case"table":{const N=R.columns??[],I=R.endpointConfig;let re;I&&(re=async()=>{const X=I.key;if(!X)return[];const fe=Ar(I.parameters,h.getValues,g),le=f==null?void 0:f[X];return typeof le=="function"?await le(fe):(console.warn(`Provider factory for key "${X}" not found in registry.`),[])});const G=s.jsx(l1,{columns:N,loadData:re,idAccessor:R.idAccessor||"id",className:R.className},R.name);return y(G,_)}default:{const N=s.jsx(Xo,{...z,type:R.type,loadingDefaults:i,hasError:!!o[R.name],errorMessage:p((K=o[R.name])==null?void 0:K.message),suffixButton:$,name:R.name},R.name);return y(N,_)}}}}function yB(e){var r;return e?!!((r=e.closest)!=null&&r.call(e,'button,[role="button"],a[href],input,select,textarea,[contenteditable="true"],[data-interactive="true"]')):!1}function jB(e){var r;return e?!!((r=e.closest)!=null&&r.call(e,'[data-input-group-root],[data-input-group],[data-role="input-group"],.input-group,.InputGroup')):!1}function Kn(e){var t;e.preventDefault(),e.stopPropagation(),(t=e.nativeEvent)!=null&&t.stopImmediatePropagation&&e.nativeEvent.stopImmediatePropagation()}function kB({id:e,children:t,onDelete:r,fieldName:n,chromeDisabled:o=!1}){const{attributes:l,listeners:i,setNodeRef:c,transform:u,transition:d,isDragging:m}=ku({id:e,disabled:o}),f=se(g=>g.setSelection),h={transform:br.Transform.toString(u),transition:d},p="opacity-0 scale-95 group-hover:opacity-100 group-hover:scale-100 group-focus-within:opacity-100 group-focus-within:scale-100",b=g=>{const x=g.target;yB(x)||jB(x)||n&&(g.stopPropagation(),f({kind:"field",name:n}))},v=g=>{Kn(g)};return s.jsxs("div",{ref:c,style:h,className:["relative",o?"":"group",m?"z-30":"z-0"].filter(Boolean).join(" "),onClickCapture:b,onDoubleClick:v,onDoubleClickCapture:v,children:[!o&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:["pointer-events-none absolute -inset-0.5 rounded-lg","bg-[var(--color-ds-background-surface)]/80","border border-dashed border-[var(--color-ds-border-default-50)]","transition-all duration-150 ease-out",p,m?"opacity-100 scale-100":""].join(" ")}),s.jsxs("div",{className:["pointer-events-none absolute -top-3 right-2 flex gap-1 z-40","transition-all duration-150 ease-out",p,m?"opacity-100 scale-100":""].join(" "),children:[r&&s.jsx("button",{type:"button","aria-label":"Eliminar campo",className:["pointer-events-auto inline-flex items-center justify-center","w-7 h-7 rounded-full","bg-[var(--color-ds-background-surface)]","border border-[var(--color-ds-border-default-50)]","text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-danger)]","focus:outline-none focus:ring-2 focus:ring-[var(--color-ds-border-default-50)]","transition-colors"].join(" "),onClick:g=>{g.preventDefault(),g.stopPropagation(),r==null||r(e)},onDoubleClick:Kn,onDoubleClickCapture:Kn,children:s.jsx(pt,{className:"w-4 h-4"})}),s.jsx("button",{type:"button","aria-label":"Mover campo","data-drag-handle":!0,className:["pointer-events-auto inline-flex items-center justify-center","w-8 h-8 rounded-full cursor-grab active:cursor-grabbing touch-none","bg-[var(--color-ds-background-surface)]","border border-[var(--color-ds-border-default-50)]","text-[var(--color-ds-text-secondary)] hover:text-[var(--color-ds-text-primary)]","focus:outline-none focus:ring-2 focus:ring-[var(--color-ds-border-default-50)]","transition-colors"].join(" "),...l,...i,onDoubleClick:Kn,onDoubleClickCapture:Kn,children:s.jsx(Hl,{className:"w-4 h-4"})})]})]}),s.jsx("div",{className:"relative z-10",children:t})]})}function EB(e,t){if(!t||t.kind!=="row-in-section"&&t.kind!=="row-in-tab-section")return!1;const r=n=>e.insertAt===n||e.insertAt===n+1;if(e.scope==="row-slot"){if(t.kind==="row-in-section"&&t.li===e.li&&t.sIdx===e.sIdx&&r(t.rIdx))return!0}else if(e.scope==="tab-row-slot"&&t.kind==="row-in-tab-section"&&t.li===e.li&&t.tabKey===e.tabKey&&t.sIdx===e.sIdx&&r(t.rIdx))return!0;return!1}function so(e){const t=e.scope==="row-slot"?{scope:"row-slot",li:e.li,sIdx:e.sIdx,insertAt:e.insertAt}:{scope:"tab-row-slot",li:e.li,tabKey:e.tabKey,sIdx:e.sIdx,insertAt:e.insertAt},r=e.scope==="row-slot"?`row-slot|li:${e.li}|s:${e.sIdx}|i:${e.insertAt}`:`tab-row-slot|li:${e.li}|t:${e.tabKey}|s:${e.sIdx}|i:${e.insertAt}`,{setNodeRef:n,isOver:o}=sr({id:r,data:t}),[l,i]=k.useState(void 0);return Ia({onDragStart:d=>{i(d.active.data.current)},onDragEnd:()=>i(void 0),onDragCancel:()=>i(void 0)}),EB(e,l)?s.jsx("div",{ref:n,style:{display:"none"}}):s.jsx("div",{className:"w-full relative transition-all duration-200 ease-in-out",style:{height:o?60:0,pointerEvents:"none",zIndex:o?10:0},children:s.jsx("div",{ref:n,className:"absolute left-0 right-0",style:{top:o?0:-12,height:o?"100%":24,zIndex:o?10:2,pointerEvents:"auto"},children:o&&s.jsx("div",{className:"w-full h-full rounded-md border border-dashed border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background)]/60 relative",style:{boxShadow:"inset 0 0 0 1px color-mix(in srgb, var(--color-ds-border-default-50) 30%, transparent)"},children:s.jsx("div",{className:"absolute -top-2 left-3 px-1.5 py-0.5 rounded text-[11px] leading-none",style:{background:"var(--color-ds-background-elevated)",color:"var(--color-ds-text-secondary)",border:"1px solid var(--color-ds-border-default-50)"},children:"Soltar fila aquí"})})})})}function cd(e){const t=e.kind==="row-in-section"?{kind:"row-in-section",li:e.li,sIdx:e.sIdx,rIdx:e.rIdx}:{kind:"row-in-tab-section",li:e.li,tabKey:e.tabKey,sIdx:e.sIdx,rIdx:e.rIdx},r=e.kind==="row-in-section"?`row|li:${e.li}|s:${e.sIdx}|r:${e.rIdx}`:`tab-row|li:${e.li}|t:${e.tabKey}|s:${e.sIdx}|r:${e.rIdx}`,{attributes:n,listeners:o,setNodeRef:l,isDragging:i}=nn({id:r,data:t});return s.jsx("div",{ref:l,"aria-label":"Handle de arrastre de fila",style:{position:"absolute",left:"50%",top:-14,transform:"translateX(-50%)",zIndex:2147483647,pointerEvents:e.visible?"auto":"none",opacity:e.visible?1:0,transition:"opacity .12s ease"},...o,...n,children:s.jsx("div",{className:"flex items-center justify-center bg-[var(--color-ds-background-elevated)]/85 backdrop-blur-sm px-1 py-0.5 rounded-lg border border-[var(--color-ds-border-default-50)] shadow-sm",children:s.jsx("div",{title:"Mover fila (arrastrar)",className:"flex items-center justify-center rounded hover:bg-[var(--color-ds-background-muted)] transition-colors",style:{cursor:i?"grabbing":"grab",touchAction:"none",padding:"2px 6px"},children:s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",className:"w-4 h-4 text-[var(--color-ds-text-secondary)]",children:s.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M3.75 9h16.5m-16.5 6.75h16.5"})})})})})}function RB(e){const r={text:()=>({label:"ds.fields.defaults.text.label",type:"text",width:"w-full",placeholder:"ds.fields.defaults.text.placeholder",size:"sm"}),number:()=>({label:"ds.fields.defaults.number.label",type:"number",width:"w-full",placeholder:"ds.fields.defaults.number.placeholder",size:"sm",validation:{required:!1}}),email:()=>({label:"ds.fields.defaults.email.label",type:"email",width:"w-full",placeholder:"ds.fields.defaults.email.placeholder",size:"sm"}),password:()=>({label:"ds.fields.defaults.password.label",type:"password",width:"w-full",placeholder:"ds.fields.defaults.password.placeholder",size:"sm",validation:{minLength:8}}),tel:()=>({label:"ds.fields.defaults.tel.label",type:"tel",width:"w-full",placeholder:"ds.fields.defaults.tel.placeholder",size:"sm"}),url:()=>({label:"ds.fields.defaults.url.label",type:"url",width:"w-full",placeholder:"ds.fields.defaults.url.placeholder",size:"sm"}),select:()=>({label:"ds.fields.defaults.select.label",type:"select",width:"w-full",size:"sm",options:[{label:"Opción A",value:"A"},{label:"Opción B",value:"B"}]}),checkbox:()=>({label:"ds.fields.defaults.checkbox.label",type:"checkbox",width:"w-full",size:"sm",defaultValue:!1}),textarea:()=>({label:"ds.fields.defaults.textarea.label",type:"textarea",width:"w-full",size:"sm",maxLength:300,showCounter:!0,placeholder:"ds.fields.defaults.textarea.placeholder"}),date:()=>({label:"ds.fields.defaults.date.label",type:"date",width:"w-full",size:"sm",showTime:!1}),file:()=>({label:"ds.fields.defaults.file.label",type:"file",width:"w-full",maxFiles:1,accept:".pdf,.doc,.docx"}),inputGroup:()=>({label:"Grupo",type:"inputGroup",width:"w-full",fields:[]}),search:()=>({label:"ds.fields.defaults.search.label",type:"search",width:"w-full",placeholder:"ds.fields.defaults.search.placeholder",size:"sm",searchMode:"button"}),optionGroup:()=>({label:"Selecciona opciones",type:"optionGroup",width:"w-full",size:"sm",multiple:!0,vertical:!0,options:[{label:"Opción 1",value:"opt1"},{label:"Opción 2",value:"opt2"},{label:"Opción 3",value:"opt3"}]}),array:()=>({label:"Lista repetible",type:"array",width:"w-full",items:[]}),button:()=>({label:"Botón",type:"button",width:"w-auto",variant:"primary",size:"sm"}),iban:()=>({label:"ds.fields.defaults.iban.label",type:"iban",width:"w-full",placeholder:"ds.fields.defaults.iban.placeholder",size:"sm",validation:{required:!1}}),table:()=>({label:"Tabla de Datos",type:"table",width:"w-full",size:"sm",columns:[{header:"ID",accessor:"id",width:"w-16"},{header:"Nombre",accessor:"name",width:"w-auto"}]})}[e];return r?r():{type:e}}function CB(e){return typeof e=="function"}function ea(e,t){if(!e||!t)return null;const r=t==="outline"?Cn:Sn,n=r==null?void 0:r[e];return CB(n)?n:null}function Pl(e){var c,u,d,m,f,h,p,b;if(!e||typeof e!="object")return e;if(e.type==="inputGroup"){const v=e,g={...v};return Array.isArray(v.inputs)&&(g.inputs=v.inputs.map(x=>typeof x=="string"?x:Pl(x))),g}const t=e,r={...t},n=ea((c=t.labelPrefixIcon)==null?void 0:c.name,(u=t.labelPrefixIcon)==null?void 0:u.style),o=ea((d=t.labelSuffixIcon)==null?void 0:d.name,(m=t.labelSuffixIcon)==null?void 0:m.style),l=ea((f=t.prefixIcon)==null?void 0:f.name,(h=t.prefixIcon)==null?void 0:h.style),i=ea((p=t.suffixIcon)==null?void 0:p.name,(b=t.suffixIcon)==null?void 0:b.style);return n&&(r.labelPrefixIcon=n),o&&(r.labelSuffixIcon=o),l&&(r.prefixIcon=l),i&&(r.suffixIcon=i),r}function SB({name:e,children:t}){const r=gB(e);return s.jsx("div",{ref:r,"data-field":e,style:{position:"relative"},children:t})}function dd(e){return e.startsWith("row|")?Object.fromEntries(e.slice(4).split(";").map(r=>r.split(":"))):{}}function NB(e,t){const r=dd(e),n=dd(t);return r.ctx===n.ctx&&r.li===n.li&&r.s===n.s&&(r.t??"")===(n.t??"")}function ud(e,t){if(!e.startsWith("col|"))return Qn(e);const r=Object.fromEntries(e.slice(4).split(";").map(i=>i.split(":"))),n=r.ctx==="rows"?`rows|li:${r.li}|s:${r.s}|r:${r.r}|c:${r.c}`:`tabs|li:${r.li}|t:${r.t}|s:${r.s}|r:${r.r}|c:${r.c}`,o=(t[n]??[]).length,l=Object.prototype.hasOwnProperty.call(r,"insertAt");return{li:Number(r.li),tabIdx:r.t?Number(r.t):void 0,sectionIdx:Number(r.s),rowIdx:Number(r.r),colIdx:Number(r.c),fieldIdx:l?Number(r.insertAt):o}}function AB(e,t){const r=Array.from(e.querySelectorAll("[data-sortable-item]"));if(!r.length)return{insertAt:0,yAbs:e.getBoundingClientRect().top+8};let n=r.length,o=r[r.length-1].getBoundingClientRect().bottom;for(let l=0;l<r.length;l++){const i=r[l].getBoundingClientRect(),c=(i.top+i.bottom)/2;if(t<c){n=l,o=i.top;break}}return{insertAt:n,yAbs:o}}function MB(e){k.useEffect(()=>{if(!e)return;let t=0;const r=()=>{const n=document.getElementById("form-renderer-root");if(!n){t=requestAnimationFrame(r);return}const o=n.getBoundingClientRect(),l=window.__lastPointerY,i=80,c=14;typeof l=="number"&&(l<o.top+i?window.scrollBy({top:-c}):l>o.bottom-i&&window.scrollBy({top:c})),t=requestAnimationFrame(r)};return t=requestAnimationFrame(r),()=>cancelAnimationFrame(t)},[e])}function OB(e){const t=e.replaceAll("|",";");return t.startsWith("rows;")?`col|ctx:rows;${t.slice(5)}`:t.startsWith("tabs;")?`col|ctx:tabs;${t.slice(5)}`:`col|${t}`}function LB({droppableId:e,children:t,className:r,scope:n,li:o,tabIdx:l,sectionIdx:i,rowIdx:c,colIdx:u}){const d=n?{scope:n,...n==="rows-column"?{rowsNodeIdx:o}:{tabKey:`tab-${l}`},s:i,r:c,c:u,insertAt:0}:void 0,{isOver:m,setNodeRef:f}=sr({id:e,data:d});return s.jsx("div",{ref:f,className:["relative min-h-[28px] h-full overflow-visible transition-[box-shadow,border-color] duration-100",m?"ring-1 ring-[var(--color-ds-border-default-50)] rounded":"",r??""].join(" "),style:{isolation:"isolate"},"data-droppable-col":!0,children:t})}function $B(e,t){var n,o,l,i,c,u,d,m,f;const r=e.layout[t.li];if(r)return r.type==="rows"?(i=(l=(o=(n=r.sections[t.sectionIdx])==null?void 0:n.rows[t.rowIdx])==null?void 0:o.columns[t.colIdx])==null?void 0:l.fields)==null?void 0:i[t.fieldIdx]:(f=(m=(d=(u=(c=r.tabs[t.tabIdx])==null?void 0:c.sections[t.sectionIdx])==null?void 0:u.rows[t.rowIdx])==null?void 0:d.columns[t.colIdx])==null?void 0:m.fields)==null?void 0:f[t.fieldIdx]}function fd({ctx:e,visible:t}){const{t:r}=gt(),n=se(j=>j.addColumnToRow),o=se(j=>j.setRowColumns),l=se(j=>j.removeLastColumn),i=se(j=>j.addRowToSectionAt),c=se(j=>j.addColumnToTabRow),u=se(j=>j.setTabRowColumns),d=se(j=>j.removeLastTabColumn),m=se(j=>j.addRowToTabSectionAt),f=()=>e.kind==="rows"?n==null?void 0:n(e.sectionIdx,e.rowIdx):c==null?void 0:c(e.tabKey,e.sectionIdx,e.rowIdx),h=()=>e.kind==="rows"?l==null?void 0:l(e.sectionIdx,e.rowIdx):d==null?void 0:d(e.tabKey,e.sectionIdx,e.rowIdx),p=j=>e.kind==="rows"?o==null?void 0:o(e.sectionIdx,e.rowIdx,j):u==null?void 0:u(e.tabKey,e.sectionIdx,e.rowIdx,j),b=()=>e.kind==="rows"?i==null?void 0:i(e.sectionIdx,e.rowIdx):m==null?void 0:m(e.tabKey,e.sectionIdx,e.rowIdx),v=()=>e.kind==="rows"?i==null?void 0:i(e.sectionIdx,e.rowIdx+1):m==null?void 0:m(e.tabKey,e.sectionIdx,e.rowIdx+1),[g,x]=k.useState({isOpen:!1,title:"",message:null,onConfirm:()=>{}}),w=(j,R,A)=>{x({isOpen:!0,title:j,message:R,onConfirm:A})},y=()=>{g.onConfirm(),x(j=>({...j,isOpen:!1}))},E=()=>{x(j=>({...j,isOpen:!1}))};return s.jsxs("div",{"aria-label":"Acciones de fila",style:{position:"absolute",insetInlineEnd:6,insetBlockStart:-25,zIndex:2147483646,pointerEvents:t?"auto":"none",opacity:t?1:0,transition:"opacity .12s ease"},className:"flex items-center gap-1",children:[s.jsxs("div",{className:"flex items-center gap-1 bg-[var(--color-ds-background-elevated)]/85 backdrop-blur-sm px-1.5 py-1 rounded-lg border border-[var(--color-ds-border-default-50)] shadow-sm",children:[s.jsx(me,{size:"xs",variant:"ghost",title:r("ds.editor.actions.addRow"),onClick:b,children:"↑"}),s.jsx(me,{size:"xs",variant:"ghost",title:r("ds.editor.actions.addRow"),onClick:v,children:"↓"}),s.jsx("span",{className:"w-px h-4 bg-[var(--color-ds-border-default-50)] mx-1","aria-hidden":!0}),s.jsx(me,{size:"xs",variant:"ghost",title:r("ds.editor.actions.addColumn"),onClick:f,children:"+"}),s.jsx(me,{size:"xs",variant:"ghost",title:r("ds.editor.actions.deleteColumn"),onClick:()=>w(r("ds.editor.confirmations.deleteColumn.title"),r("ds.editor.confirmations.deleteColumn.message"),h),children:"−"}),s.jsx("span",{className:"w-px h-4 bg-[var(--color-ds-border-default-50)] mx-1","aria-hidden":!0}),[1,2,3,4].map(j=>s.jsx(me,{size:"xs",variant:"ghost",title:`Distribuir en ${j} columna(s)`,onClick:()=>p(j),children:j},j))]}),s.jsx(St,{isOpen:g.isOpen,onClose:E,title:g.title,footer:s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(me,{variant:"outline",onClick:E,children:r("ds.editor.actions.cancel")}),s.jsx(me,{variant:"danger",onClick:y,children:r("ds.editor.actions.delete")})]}),children:s.jsx("p",{className:"text-sm text-[var(--color-ds-text-secondary)]",children:g.message})})]})}function IB({schema:e,onSchemaChange:t,deps:r,layoutEditMode:n=!1}){const{t:o}=gt(),l=se(U=>U.updateField),i=se(U=>U.mode),c=Jr(U=>U.setRuntimeState),u=Jr(U=>U.systemContext);k.useEffect(()=>{if(!e.variables)return;const U={};e.variables.forEach(J=>{J.type==="constant"&&(U[J.key]=J.value)}),e.variables.forEach(J=>{if(J.type==="computed"&&J.value)try{const oe=new Function("ctx",`return (${J.value});`);U[J.key]=oe(U)}catch(oe){console.warn(`[FormRendererDnd] Error evaluating computed variable "${J.key}":`,oe),U[J.key]=null}}),Object.keys(U).length>0&&c({systemContext:U})},[e.variables,c]);const d=k.useMemo(()=>({...r,translateFn:(U,J)=>{const oe=st(o,U,J);return oe?Sl(oe,u):""},onUpdateField:(U,J)=>{l(U,oe=>{Object.assign(oe,J)})},isDesignMode:i==="design"}),[r,o,l,i,u]),m=k.useCallback((U,J)=>{const oe=st(o,U,J);return oe?Sl(oe,u):""},[o,u]),f=k.useMemo(()=>wB(d),[d]),h=se(U=>U.selection),p=(h==null?void 0:h.kind)==="field"?h.name:void 0,v=se(U=>U.fieldPick).armed,{enabled:g,anchors:x,setSchema:w}=Ku();k.useEffect(()=>{w(e)},[e,w]);const[y,E]=k.useState(null),[j,R]=k.useState(null),A=k.useRef({}),S=k.useCallback(U=>J=>{A.current[U]=J},[]),O=k.useRef(null),_=k.useRef(null),V=k.useRef(null),$=U=>{_.current==null&&(_.current=requestAnimationFrame(()=>{_.current=null;const J=V.current;JSON.stringify(J)!==JSON.stringify(U)&&(V.current=U,R(U))}))},D=k.useMemo(()=>{const U={};return e.layout.forEach((J,oe)=>{J.type==="tabs"&&(U[oe]=J.tabs[0].key)}),U},[e.layout]),[M,z]=k.useState(D),[te,Q]=k.useState({isOpen:!1,title:"",message:null,onConfirm:()=>{}}),ne=(U,J,oe)=>{Q({isOpen:!0,title:U,message:J,onConfirm:oe})},ae=()=>{te.onConfirm(),Q(U=>({...U,isOpen:!1}))},K=()=>{Q(U=>({...U,isOpen:!1}))},N=k.useMemo(()=>{const U={};return e.layout.forEach((J,oe)=>{J.type==="rows"?J.sections.forEach((de,pe)=>{de.rows.forEach((be,je)=>{be.columns.forEach((ye,Fe)=>{const $e=`rows|li:${oe}|s:${pe}|r:${je}|c:${Fe}`;U[$e]=(ye.fields??[]).map((Ee,Oe)=>ad({li:oe,sectionIdx:pe,rowIdx:je,colIdx:Fe,fieldIdx:Oe}))})})}):J.type==="tabs"&&J.tabs.forEach((de,pe)=>{de.sections.forEach((be,je)=>{be.rows.forEach((ye,Fe)=>{ye.columns.forEach(($e,Ee)=>{const Oe=`tabs|li:${oe}|t:${pe}|s:${je}|r:${Fe}|c:${Ee}`;U[Oe]=($e.fields??[]).map((_e,ze)=>ad({li:oe,tabIdx:pe,sectionIdx:je,rowIdx:Fe,colIdx:Ee,fieldIdx:ze}))})})})})}),U},[e]),I=k.useMemo(()=>{const U={};return Object.entries(N).forEach(([J,oe])=>oe.forEach(de=>U[de]=J)),U},[N]),re=Fi(On(_a,{activationConstraint:{distance:6}}),On(Fa,{coordinateGetter:Eu})),G="__phantom__",[X,fe]=k.useState(!1),[le,he]=k.useState(null),[ce,ie]=k.useState(null),[ve,ue]=k.useState(40),[xe,C]=k.useState(null),[q,ee]=k.useState(null),W=k.useCallback(U=>{if(!U)return!1;if(typeof U=="string"){const J=r.fieldsByName[U];return!!J&&J.type==="inputGroup"}return(U==null?void 0:U.type)==="inputGroup"},[r.fieldsByName]),H=U=>{var je;const J=String(((je=U.active)==null?void 0:je.id)??""),oe=Bi(U),de=oe[0],pe=de?String(de.id):null;if(pe&&I[pe]&&I[J]&&I[pe]===I[J])return oe;const be=jL(U);if(J.startsWith("row|")||J.startsWith("tab-row|")){const ye=be.filter(Fe=>String(Fe.id).startsWith("row-slot|")||String(Fe.id).startsWith("tab-row-slot|"));if(ye.length)return ye}else{const ye=be.filter(Fe=>String(Fe.id).startsWith("col|"));if(ye.length)return ye}return oe};Ia({onDragStart:U=>{var de,pe,be,je,ye,Fe;fe(!0);const J=String(U.active.id??"");he(J),ie(I[J]??null),O.current=J.startsWith("row|")?"row":"field";const oe=((pe=(de=U.active.rect.current)==null?void 0:de.translated)==null?void 0:pe.height)??((je=(be=U.active.rect.current)==null?void 0:be.initial)==null?void 0:je.height)??40;if(ue(Math.max(24,Math.floor(oe))),O.current==="field"&&!J.startsWith("col|")&&!J.startsWith("palette:"))try{const $e=Qn(J),Ee=(ye=e.layout)==null?void 0:ye[$e.li],_e=(Fe=((Ee==null?void 0:Ee.type)==="rows"?Ee.sections[$e.sectionIdx].rows[$e.rowIdx].columns[$e.colIdx]:Ee.tabs[$e.tabIdx].sections[$e.sectionIdx].rows[$e.rowIdx].columns[$e.colIdx]).fields)==null?void 0:Fe[$e.fieldIdx??0],ze=_e&&Pl(_e);C(ze?f(ze):null)}catch{C(null)}else C(null)},onDragOver:U=>{var Fe,$e;const J=String(((Fe=U.over)==null?void 0:Fe.id)??""),oe=String((($e=U.active)==null?void 0:$e.id)??""),de=U.activatorEvent;if(de&&typeof de.clientY=="number"&&(window.__lastPointerY=de.clientY),O.current==="row"){if(J.startsWith("row|")&&oe.startsWith("row|"))if(NB(oe,J)&&oe!==J){const Ee=A.current[J],Oe=(de==null?void 0:de.clientY)??0;if(Ee&&Oe){const _e=Ee.getBoundingClientRect(),ze=Oe<_e.top+_e.height/2?"before":"after";$({rid:J,pos:ze})}else $(null)}else $(null);else $(null);ee(null);return}if(!J.startsWith("col|")){ee(null);return}const pe=Object.fromEntries(J.slice(4).split(";").map(Ee=>Ee.split(":"))),be=pe.ctx==="rows"?`rows|li:${pe.li}|s:${pe.s}|r:${pe.r}|c:${pe.c}`:`tabs|li:${pe.li}|t:${pe.t}|s:${pe.s}|r:${pe.r}|c:${pe.c}`,je=document.querySelector(`[data-col-key="${be}"]`),ye=(de==null?void 0:de.clientY)??0;if(je&&ye){const{insertAt:Ee,yAbs:Oe}=AB(je,ye),_e=je.getBoundingClientRect().top;ee({overId:J,keyId:be,insertAt:Ee,yRel:Oe-_e})}else ee(null)},onDragCancel:U=>{fe(!1),he(null),ie(null),ue(40),C(null),ee(null),R(null),O.current=null,_.current&&(cancelAnimationFrame(_.current),_.current=null),V.current=null},onDragEnd:()=>{fe(!1),he(null),ie(null),ue(40),C(null),R(null),O.current=null,_.current&&(cancelAnimationFrame(_.current),_.current=null),V.current=null}}),MB(X);const Y=k.useCallback(U=>{const{active:J,over:oe}=U;if(!(J!=null&&J.id)||!(oe!=null&&oe.id)){ee(null),R(null);return}const de=J.data.current,pe=oe.data.current;if(((de==null?void 0:de.kind)==="row-in-section"||(de==null?void 0:de.kind)==="row-in-tab-section")&&((pe==null?void 0:pe.scope)==="row-slot"||(pe==null?void 0:pe.scope)==="tab-row-slot")){const Ee=de.li,Oe=de.sIdx,_e=de.rIdx,ze=pe.li,nt=pe.sIdx,Se=pe.insertAt,Ne={...e,layout:[...e.layout]},Me={...Ne.layout[Ee]};Ne.layout[Ee]=Me;let Ae=null,Ie=null,Be=null;if(de.kind==="row-in-section"&&Me.type==="rows")Me.sections=[...Me.sections],Ie={...Me.sections[Oe]},Me.sections[Oe]=Ie,Ie.rows=[...Ie.rows],Ae=Ie.rows;else if(de.kind==="row-in-tab-section"&&Me.type==="tabs"){Me.tabs=[...Me.tabs];const qe=Me.tabs.findIndex(He=>He.key===de.tabKey);qe>=0&&(Be={...Me.tabs[qe]},Me.tabs[qe]=Be,Be.sections=[...Be.sections],Ie={...Be.sections[Oe]},Be.sections[Oe]=Ie,Ie.rows=[...Ie.rows],Ae=Ie.rows)}if(!Ae)return;let Ve=null,De=null;if(Ee===ze?De=Me:(De={...Ne.layout[ze]},Ne.layout[ze]=De),pe.scope==="row-slot"&&De.type==="rows")if(De.sections===Me.sections||(De.sections=[...De.sections]),Ee===ze&&Oe===nt&&de.kind==="row-in-section")Ve=Ae;else{const qe={...De.sections[nt]};De.sections[nt]=qe,qe.rows=[...qe.rows],Ve=qe.rows}else if(pe.scope==="tab-row-slot"&&De.type==="tabs"){De.tabs===Me.tabs||(De.tabs=[...De.tabs]);const qe=De.tabs.findIndex(He=>He.key===pe.tabKey);if(qe>=0){let He=De.tabs[qe];if(Ee===ze&&de.kind==="row-in-tab-section"&&de.tabKey===pe.tabKey?He=Be:(He={...He},De.tabs[qe]=He),He.sections===(Be==null?void 0:Be.sections)||(He.sections=[...He.sections]),Ee===ze&&Oe===nt&&de.kind==="row-in-tab-section"&&de.tabKey===pe.tabKey)Ve=Ae;else{const at={...He.sections[nt]};He.sections[nt]=at,at.rows=[...at.rows],Ve=at.rows}}}if(!Ve)return;const[vt]=Ae.splice(_e,1);let Ze=Se;Ae===Ve&&_e<Se&&(Ze-=1),Ve.splice(Ze,0,vt),t(Ne),ee(null),R(null);return}if((de==null?void 0:de.kind)==="palette-field"){const Ee=String(oe.id);if(!Ee.startsWith("col|")){ee(null),R(null);return}const Oe=Object.fromEntries(Ee.slice(4).split(";").map(Me=>Me.split(":"))),_e=q&&q.overId===Ee?q.insertAt:Oe.insertAt?Number(Oe.insertAt):0,ze={li:Number(Oe.li),tabIdx:Oe.t!=null?Number(Oe.t):void 0,sectionIdx:Number(Oe.s),rowIdx:Number(Oe.r),colIdx:Number(Oe.c),fieldIdx:_e},nt=de.factoryKind,Se=RB(nt),Ne=pB(e,Se,ze);ee(null),R(null),t(Ne);return}const be=String(J.id),je=String(oe.id);if(be.startsWith("row|")&&je.startsWith("row|"),be.startsWith("palette:")){ee(null),R(null);return}const ye=Qn(be);let Fe;if(je.startsWith("col|")&&q&&q.overId===je){const Ee=Object.fromEntries(je.slice(4).split(";").map(_e=>_e.split(":"))),Oe=`col|${Object.entries(Ee).filter(([_e])=>_e!=="insertAt").map(([_e,ze])=>`${_e}:${ze}`).join(";")};insertAt:${q.insertAt}`;Fe=ud(Oe,N)}else Fe=ud(je,N);const $e=fB(e,ye,Fe);ee(null),R(null),t($e)},[e,t,N,q]);function L(U,J){let oe=U;if(le&&ce&&ce!==J&&(oe=oe.filter(de=>de!==le)),X&&q&&q.keyId===J){const de=Math.max(0,Math.min(q.insertAt,oe.length)),pe=oe.slice();return pe.splice(de,0,G),pe}return oe}const Z=({keyId:U,ids:J,className:oe,tabKey:de})=>{const pe=OB(U),be=L(J,U),je=Object.fromEntries(U.split("|").map(Se=>Se.split(":"))),ye=U.startsWith("rows|"),Fe=ye?"rows-column":"tabs-column",$e=Number(je.li),Ee=je.t!=null?Number(je.t):void 0,Oe=Number(je.s),_e=Number(je.r),ze=Number(je.c),nt=J.length;return s.jsx(LB,{droppableId:pe,className:oe,scope:Fe,li:$e,tabIdx:Ee,sectionIdx:Oe,rowIdx:_e,colIdx:ze,children:s.jsxs("div",{"data-col-key":U,className:"relative",children:[ye?s.jsx(rr,{scope:"rows-column",rowsNodeIdx:$e,s:Oe,r:_e,c:ze,insertAt:0,suppressAll:nt===0}):de?s.jsx(rr,{scope:"tabs-column",tabKey:de,s:Oe,r:_e,c:ze,insertAt:0,suppressAll:nt===0}):null,X&&q&&q.overId===pe?s.jsx("div",{"aria-hidden":!0,style:{position:"absolute",left:0,right:0,top:Math.max(0,q.yRel-1),height:2,background:"var(--color-ds-border-default)",borderRadius:2}}):null,s.jsx(yu,{items:be,strategy:bu,children:s.jsx("div",{children:be.map((Se,Ne)=>{if(Se===G)return s.jsx("div",{"data-sortable-item":!0,"aria-hidden":!0,style:{height:ve,border:"1px dashed var(--color-ds-border-default-50)",borderRadius:8,background:"color-mix(in srgb, var(--color-ds-border-default-50) 8%, transparent)"}},`${U}-ph-${Ne}`);const Me=Qn(String(Se)),Ae=$B(e,Me);if(!Ae)return s.jsx("div",{"data-sortable-item":!0,"aria-hidden":!0},`${U}-miss-${Ne}`);const Ie=Pl(Ae),Be=typeof Ie=="string"?Ie:(Ie==null?void 0:Ie.name)??"",Ve=!!p&&!!Be&&p===Be,De=f(Ie),vt=W(Ie),Ze=He=>{var at;He.preventDefault(),He.stopPropagation(),(at=He.nativeEvent)!=null&&at.stopImmediatePropagation&&He.nativeEvent.stopImmediatePropagation()},qe=vt?{onDoubleClick:Ze,onDoubleClickCapture:Ze,onClick:Ze,onClickCapture:Ze,onMouseDown:Ze,onMouseDownCapture:Ze,onMouseUp:Ze,onMouseUpCapture:Ze,onPointerDown:Ze,onPointerDownCapture:Ze,onPointerUp:Ze,onPointerUpCapture:Ze,onContextMenu:Ze}:{};return s.jsx("div",{"data-sortable-item":!0,children:s.jsx(kB,{id:String(Se),fieldName:Be,onDelete:He=>{const at=Qn(He);ne("Eliminar campo","¿Estás seguro de que quieres eliminar este campo?",()=>{const Qt=mB(e,at);t(Qt)})},chromeDisabled:v,children:s.jsx(SB,{name:Be,children:s.jsx("div",{className:Ve?"selected-field":void 0,"data-field-name":Be,"aria-selected":Ve||void 0,...qe,children:De})})})},String(Se))})})})]})})},F=X&&O.current==="row",T=(U,J)=>s.jsx(s.Fragment,{children:U.sections.map((oe,de)=>s.jsx("div",{className:"mb-6",children:s.jsx(rt,{title:m(oe.sectionTitle),defaultOpen:oe.defaultOpen,forceOpen:F,children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx(so,{scope:"row-slot",li:J,sIdx:de,insertAt:0}),oe.rows.map((pe,be)=>{const je=`row|li:${J}|s:${de}|r:${be}`,ye=n&&y===je,Fe=le===je;return s.jsxs(k.Fragment,{children:[s.jsxs("div",{ref:S(je),className:`relative transition-all duration-200 ${Fe?"opacity-40 ring-1 ring-dashed ring-[var(--color-ds-border-default)] bg-[var(--color-ds-background-muted)]":n&&ye?"ring-1 ring-[var(--color-ds-border-default-50)]":""}`,onMouseEnter:()=>E(je),onMouseLeave:()=>E($e=>$e===je?null:$e),style:{borderRadius:8},children:[n&&s.jsxs(s.Fragment,{children:[s.jsx(fd,{ctx:{kind:"rows",li:J,sectionIdx:de,rowIdx:be},visible:!!ye&&!v}),s.jsx(cd,{kind:"row-in-section",li:J,sIdx:de,rIdx:be,visible:!!ye&&!v})]}),pe.title&&s.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:m(pe.title)}),s.jsx("div",{className:"flex flex-wrap -mx-2 items-stretch",children:pe.columns.map(($e,Ee)=>{const Oe=`rows|li:${J}|s:${de}|r:${be}|c:${Ee}`,_e=N[Oe]??[];return s.jsx("div",{className:`${$e.width} px-2 flex flex-col`,children:s.jsx(Z,{keyId:Oe,ids:_e})},`col-${J}-${de}-${be}-${Ee}`)})})]}),s.jsx(so,{scope:"row-slot",li:J,sIdx:de,insertAt:be+1})]},`rowwrap-${je}`)})]})})},`sec-${J}-${de}`))}),B=(U,J)=>{var de;const oe=M[J]??((de=U.tabs[0])==null?void 0:de.key);return s.jsx(xr,{options:U.tabs.map(pe=>{const be=pe.icon?ea(pe.icon.name,pe.icon.style):null;return{label:m(pe.label),value:pe.key,disabled:pe.disabled,icon:be?s.jsx(be,{className:"w-4 h-4"}):null}}),value:oe,onChange:pe=>z(be=>({...be,[J]:pe})),children:Object.fromEntries(U.tabs.map((pe,be)=>[pe.key,s.jsx("div",{className:"space-y-6",children:pe.sections.map((je,ye)=>s.jsx("div",{className:"mb-6",children:s.jsx(rt,{title:m(je.sectionTitle),defaultOpen:je.defaultOpen,forceOpen:F,children:s.jsxs("div",{className:"flex flex-col",children:[s.jsx(so,{scope:"tab-row-slot",li:J,tabKey:pe.key,sIdx:ye,insertAt:0}),je.rows.map((Fe,$e)=>{const Ee=`tab-row|li:${J}|t:${pe.key}|s:${ye}|r:${$e}`,Oe=n&&y===Ee,_e=le===Ee;return s.jsxs(k.Fragment,{children:[s.jsxs("div",{ref:S(Ee),className:`relative transition-all duration-200 ${_e?"opacity-40 ring-1 ring-dashed ring-[var(--color-ds-border-default)] bg-[var(--color-ds-background-muted)]":n&&Oe?"ring-1 ring-[var(--color-ds-border-default-50)]":""}`,onMouseEnter:()=>E(Ee),onMouseLeave:()=>E(ze=>ze===Ee?null:ze),style:{borderRadius:8},children:[n&&s.jsxs(s.Fragment,{children:[s.jsx(fd,{ctx:{kind:"tabs",li:J,tabKey:pe.key,tabIdx:be,sectionIdx:ye,rowIdx:$e},visible:!!Oe&&!v}),s.jsx(cd,{kind:"row-in-tab-section",li:J,tabKey:pe.key,sIdx:ye,rIdx:$e,visible:!!Oe&&!v})]}),Fe.title&&s.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:m(Fe.title)}),s.jsx("div",{className:"flex flex-wrap -mx-2 items-stretch",children:Fe.columns.map((ze,nt)=>{const Se=`tabs|li:${J}|t:${be}|s:${ye}|r:${$e}|c:${nt}`,Ne=N[Se]??[];return s.jsx("div",{className:`${ze.width??"flex-1"} px-2 flex flex-col`,children:s.jsx(Z,{keyId:Se,ids:Ne,tabKey:pe.key})},`col-${J}-${be}-${ye}-${$e}-${nt}`)})})]}),s.jsx(so,{scope:"tab-row-slot",li:J,tabKey:pe.key,sIdx:ye,insertAt:$e+1})]},`rowwrap-${Ee}`)})]})})},`sec-${J}-${be}-${ye}`))},`tabpanel-${J}-${be}`)]))},`tabs-${J}`)},P=se(U=>U.setSelection);return s.jsxs(fi,{...r.methods,children:[s.jsxs(Pi,{sensors:re,collisionDetection:H,onDragEnd:Y,children:[s.jsxs("div",{id:"form-renderer-root",className:"relative overflow-visible",onDoubleClick:U=>{P({kind:"none"})},children:[s.jsx("div",{className:"space-y-6 ",children:e.layout.map((U,J)=>U.type==="rows"?s.jsx(k.Fragment,{children:T(U,J)},`rows-${J}`):s.jsx(k.Fragment,{children:B(U,J)},`tabs-${J}`))}),s.jsx(xB,{schema:e,anchors:x,enabled:g})]}),s.jsx(Z1,{dropAnimation:null,children:xe?s.jsx("div",{style:{pointerEvents:"none",opacity:.9},children:xe}):null})]}),s.jsx(St,{isOpen:te.isOpen,onClose:K,title:te.title,footer:s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(me,{variant:"outline",onClick:K,children:"Cancelar"}),s.jsx(me,{variant:"danger",onClick:ae,children:"Eliminar"})]}),children:s.jsx("p",{className:"text-sm text-[var(--color-ds-text-secondary)]",children:te.message})})]})}function FB(e,t,r,n){var j;const{fields:o=[],layout:l,validationSchema:i}=e,c=_B(),u=((j=c==null?void 0:c.services)==null?void 0:j.registry)??void 0,d=Jr(R=>R.systemContext),m=k.useMemo(()=>{if(t)return t;try{const R=i??ki(e);return wi(R)}catch{return}},[t,e,i]),f=gi({resolver:m,mode:"onBlur",reValidateMode:"onChange",defaultValues:e.defaultValues??{}}),h=k.useMemo(()=>(o??[]).filter(R=>R.type!=="inputGroup"&&R.type!=="button"),[o]),{optionsMap:p}=e1(h),b=Y5(o),v=t1(o,f.control),[g,x]=k.useState({}),[w,y]=k.useState(0);k.useEffect(()=>{let R;const A=f.watch(()=>{clearTimeout(R),R=setTimeout(()=>{y(S=>S+1)},500)});return()=>{A.unsubscribe(),clearTimeout(R)}},[f.watch]),k.useEffect(()=>{let R=!0;return(async()=>{const S=await Promise.all(h.filter(_=>_.type==="select"&&(_.optionSource||_.endpointConfig)).map(async _=>{const V=_.name,$=Co(_.optionSource,_.endpointConfig);if(!$)return[V,[]];const D=_.endpointConfig?Ar(_.endpointConfig.parameters,f.getValues,{...d,ACTIVE_VARIANT:n}):{},M=u==null?void 0:u[$];if(typeof M!="function")return[V,[]];try{const z=await Promise.resolve(M("",{getValues:f.getValues,watch:f.watch,params:D,...d})),te=Array.isArray(z)?z:[];return[V,te]}catch{return[V,[]]}}));if(!R)return;const O={};for(const[_,V]of S)O[_]=V;x(O)})(),()=>{R=!1}},[u,f.getValues,f.watch,JSON.stringify(h.map(R=>({n:R.name,os:R.optionSource??null,ec:R.endpointConfig??null}))),n,w]);const E=k.useCallback((R,A)=>{if(!(R!=null&&R.enabled)||!R.rule)return A;try{const S={...f.getValues(),ACTIVE_VARIANT:n};return!!Ao(R.rule,S)}catch{return A}},[f,n]);return{methods:f,control:f.control,formState:f.formState,fields:o,fieldsByName:b,asyncOptionsMap:p,adapterOptionsMap:g,disabledMap:v,evalContainer:E,registry:u,layout:l,systemContext:d}}function _B(){try{return At()??void 0}catch{return}}function TB(e,t,r){const n={...e};return t.top+e.y<=r.top?n.y=r.top-t.top:t.bottom+e.y>=r.top+r.height&&(n.y=r.top+r.height-t.bottom),t.left+e.x<=r.left?n.x=r.left-t.left:t.right+e.x>=r.left+r.width&&(n.x=r.left+r.width-t.right),n}const BB=e=>{let{transform:t,draggingNodeRect:r,windowRect:n}=e;return!r||!n?t:TB(t,r,n)};function un(e){const r={text:()=>({label:"ds.fields.defaults.text.label",type:"text",width:"w-full",placeholder:"ds.fields.defaults.text.placeholder",size:"sm"}),number:()=>({label:"ds.fields.defaults.number.label",type:"number",width:"w-full",placeholder:"ds.fields.defaults.number.placeholder",size:"sm",validation:{required:!1}}),email:()=>({label:"ds.fields.defaults.email.label",type:"email",width:"w-full",placeholder:"ds.fields.defaults.email.placeholder",size:"sm"}),password:()=>({label:"ds.fields.defaults.password.label",type:"password",width:"w-full",placeholder:"ds.fields.defaults.password.placeholder",size:"sm",validation:{minLength:8}}),tel:()=>({label:"ds.fields.defaults.tel.label",type:"tel",width:"w-full",placeholder:"ds.fields.defaults.tel.placeholder",size:"sm"}),url:()=>({label:"ds.fields.defaults.url.label",type:"url",width:"w-full",placeholder:"ds.fields.defaults.url.placeholder",size:"sm"}),select:()=>({label:"ds.fields.defaults.select.label",type:"select",width:"w-full",size:"sm",options:[{label:"Opción A",value:"A"},{label:"Opción B",value:"B"}]}),checkbox:()=>({label:"ds.fields.defaults.checkbox.label",type:"checkbox",width:"w-full",size:"sm",defaultValue:!1}),textarea:()=>({label:"ds.fields.defaults.textarea.label",type:"textarea",width:"w-full",size:"sm",maxLength:300,showCounter:!0,placeholder:"ds.fields.defaults.textarea.placeholder"}),date:()=>({label:"ds.fields.defaults.date.label",type:"date",width:"w-full",size:"sm",showTime:!1}),file:()=>({label:"ds.fields.defaults.file.label",type:"file",width:"w-full",maxFiles:1,accept:".pdf,.doc,.docx"}),inputGroup:()=>({label:"Grupo",type:"inputGroup",width:"w-full",fields:[]}),search:()=>({label:"ds.fields.defaults.search.label",type:"search",width:"w-full",placeholder:"ds.fields.defaults.search.placeholder",size:"sm",searchMode:"button"}),optionGroup:()=>({label:"Selecciona opciones",type:"optionGroup",width:"w-full",size:"sm",multiple:!0,vertical:!0,options:[{label:"Opción 1",value:"opt1"},{label:"Opción 2",value:"opt2"},{label:"Opción 3",value:"opt3"}]}),array:()=>({label:"Lista repetible",type:"array",width:"w-full",items:[]})}[e];return r?r():{type:e}}function ZB(e){if(!e)return null;const t=e.data;if(t.kind==="palette-field"){const r=t.factoryKind,n=X$[r];if(n)return s.jsx("div",{className:"pointer-events-none opacity-95",children:s.jsx("div",{className:`\r
412
412
  w-[320px]\r
413
413
  max-w-[80vw]\r
414
414
  rounded-xl \r