@dipusevilla/componentes-iu 1.1.29 → 1.1.30
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 +1 -1
- package/dist/index.es.js +1 -0
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -95,7 +95,7 @@ attempted value: ${i}
|
|
|
95
95
|
shadow-lg ${ne} max-h-48 overflow-auto z-10
|
|
96
96
|
`,children:E.map(fe=>s.jsx("li",{className:`px-2 ${q} flex items-center cursor-pointer
|
|
97
97
|
text-[var(--color-ds-text-primary)]
|
|
98
|
-
hover:bg-[var(--color-ds-background-surface)]`,onClick:()=>{const we=String(fe.value).trim();R(e,we,{shouldDirty:!0,shouldValidate:!0}),V(fe.label??we),re.current=!1,ee.current=!1,Z(!1)},children:fe.label},String(fe.value)))})]})}})}const Gn=(e,t)=>e[t],o0=e=>e instanceof Date?e.getTime():e;function NO(e,t,r){const n=o0(e),o=o0(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 Lo(e,t){if(!e)return!1;switch(e.op){case"eq":return Gn(t,e.field)===e.value;case"neq":return Gn(t,e.field)!==e.value;case"in":return e.values.includes(Gn(t,e.field));case"notIn":return!e.values.includes(Gn(t,e.field));case"gt":case"gte":case"lt":case"lte":return NO(Gn(t,e.field),e.value,e.op);case"and":return e.rules.every(r=>Lo(r,t));case"or":return e.rules.some(r=>Lo(r,t));case"always":return!!e.value;default:return!1}}function Ci(e){return!!e&&(typeof e=="function"||typeof e=="object")}function Mn(e,t){const r=t==="outline"?Sn:Nn,n=r==null?void 0:r[e];return Ci(n)?n:null}const AO=Object.entries(Sn).filter(([e,t])=>e.endsWith("Icon")&&Ci(t)).map(([e,t])=>({name:e,Icon:t,style:"outline"})),MO=Object.entries(Nn).filter(([e,t])=>e.endsWith("Icon")&&Ci(t)).map(([e,t])=>({name:e,Icon:t,style:"solid"})),OO=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&&Mn(e.name,e.style)||OO,h=k.useCallback((b,v)=>{const g=Mn(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(he,{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(Ee,{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(s0,{items:AO,query:c,onPick:b=>h(b,"outline"),onClear:p}),solid:s.jsx(s0,{items:MO,query:c,onPick:b=>h(b,"solid"),onClear:p})}})]})})]})},s0=({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 lt(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 LO=({schema:e,renderField:t})=>{var v,g,x;const{control:r}=_r(),{fields:n,append:o,remove:l}=Hx({control:r,name:e.name}),{label:i,addLabel:c="Añadir",items:u,disabled:d,validation:m,className:f}=e,{formState:{errors:h}}=_r(),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:be("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 R=`${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(he,{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(gt,{className:"w-4 h-4"})})}),s.jsx("div",{className:"grid grid-cols-1 gap-4",children:u.map((j,E)=>s.jsx(k.Fragment,{children:t(j,R)},E))})]},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(he,{type:"button",variant:"outline",size:"sm",onClick:()=>{o({})},children:[s.jsx(Jt,{className:"w-4 h-4 mr-1"}),c]})]})};function l0(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,24)}function $O(e){return e.replace(/(.{4})/g,"$1 ").trim()}function as({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(()=>l0(o),[o]),w=k.useMemo(()=>$O(x),[x]),y=R=>{const j=l0(R.target.value);l(j)};return s.jsx(Ee,{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:Ul,className:v,"aria-label":g,inputMode:"text",autoComplete:"off",spellCheck:!1})}function i0(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}=vt(),w=k.useMemo(()=>i0(o),[o]),y=k.useMemo(()=>w,[w]),R=j=>{const E=i0(j.target.value);l(E)};return s.jsx(Ee,{id:p,name:b,label:e,labelHidden:t,placeholder:r,size:n,value:y,onChange:R,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 c0(e){if(e){if(typeof e=="string")try{return JSON.parse(e)}catch{return}if(typeof e=="object")return e}}function IO(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 FO=e=>e.type!=="inputGroup"&&e.type!=="button";function _O(){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 Mn(t,r)||void 0}function l1({schema:e,resolver:t,serviceRegistry:r,activeVariantId:n}){var U;const{layout:o,fields:l=[],onSubmit:i,successMessage:c,errorMessage:u,footerButtons:d,defaultValues:m,loadDefaultValues:f,validationSchema:h}=e,{show:p}=Zr(),{t:b}=vt(),v=_O(),g=r??((U=v==null?void 0:v.services)==null?void 0:U.registry)??void 0,x=k.useMemo(()=>{if(t)return t;try{const B=h??ki(e);return wi(B)}catch{return}},[t,e,h]),w=gi({resolver:x,mode:"onBlur",reValidateMode:"onChange",defaultValues:m??{}}),y=Jr(B=>B.setRuntimeState),R=Jr(B=>B.systemContext),j=Jr(B=>B.formValues);k.useEffect(()=>{y({isActive:!0});let B=!1;return(async()=>{const T=e.defaultSource,F=e.onloadEndpoint;let D={};if(e.variables&&Array.isArray(e.variables)&&(e.variables.forEach(K=>{K.type==="constant"&&(D[K.key]=K.value)}),e.variables.forEach(K=>{if(K.type==="computed"&&K.value)try{const Q=new Function("ctx",`return (${K.value});`);D[K.key]=Q(D)}catch(Q){console.warn(`[FormRenderer] Error evaluating computed variable "${K.key}":`,Q),D[K.key]=null}})),T)try{const K=g==null?void 0:g[T];if(K){const Q=typeof K=="function"?await K():K;Q&&typeof Q=="object"&&(D={...D,...Q})}}catch{}y({systemContext:{...D}});const P=[];if(F&&P.push(F),e.onloadEndpoints&&Array.isArray(e.onloadEndpoints)&&P.push(...e.onloadEndpoints),P.length>0){const K=async ae=>{if(!ae)return{};try{const ce=g==null?void 0:g[ae.key];if(!ce)return console.warn("[FormRenderer] Provider not found for key:",ae.key),{};const ge=mr(ae.parameters,(()=>({})),{...D,ACTIVE_VARIANT:e.activeVariantId});console.log(`[FormRenderer] Calling ${ae.key} with params:`,ge);const ye=await Promise.resolve(ce(ge,{getValues:(()=>({})),watch:(()=>{}),params:ge,...D}));let ve=ye;if(typeof ye=="string")try{ve=JSON.parse(ye)}catch(Re){console.warn("[FormRenderer] Failed to parse onload response string",Re)}return ve&&typeof ve=="object"?ve:(console.warn("[FormRenderer] OnLoad response is not an object:",ve),{})}catch(ce){return console.error("Error in onloadEndpoint",ce),{}}};(await Promise.all(P.map(K))).forEach(ae=>{ae&&typeof ae=="object"&&(D={...D,...ae})}),B||y({systemContext:{...D}})}if(!B&&Object.keys(D).length>0){const K={...e.defaultValues??{}};Object.assign(K,D);const Q=e.fields.map(ae=>ae.name);Object.keys(D).forEach(ae=>{const ce=ae.toLowerCase(),ge=Q.find(ye=>ye.toLowerCase()===ce);ge&&(K[ge]===void 0||K[ge]==="")&&(K[ge]=D[ae])}),w.reset(K)}})(),()=>{B=!0,y({isActive:!1,systemContext:{},formValues:{}})}},[e,g,w.reset]);const{control:E,reset:N,handleSubmit:S,formState:{errors:O,isSubmitting:I}}=w,[Z,L]=k.useState(!1);k.useEffect(()=>{f&&(L(!0),f().then(B=>N(B)).finally(()=>L(!1)))},[f,N]);const V=k.useMemo(()=>(l??[]).filter(FO),[l]),{loadingCount:M,optionsMap:z}=o1(V),[re,ee]=k.useState({}),[oe,se]=k.useState(0);k.useEffect(()=>{let B;const T=w.watch(()=>{clearTimeout(B),B=setTimeout(()=>{se(F=>F+1)},500)});return()=>{T.unsubscribe(),clearTimeout(B)}},[w.watch]);const Y=k.useRef(g);k.useEffect(()=>{Y.current=g},[g]);const A=k.useRef({});k.useEffect(()=>{let B=!0;return(async()=>{const F=await Promise.all(V.filter(P=>P.type==="select"&&(P.optionSource||P.endpointConfig)).map(async P=>{var ve;const K=P.name,Q=Ao(P.optionSource,P.endpointConfig);if(!Q)return[K,[]];const ae=P.endpointConfig?mr(P.endpointConfig.parameters,w.getValues,R):{...R,...w.getValues()},ce=c0(P.adapterCtx??P.optionAdapterCtx),ge=JSON.stringify({key:Q,resolvedParams:ae,ctx:ce});A.current[K],A.current[K]=ge;const ye=(ve=Y.current)==null?void 0:ve[Q];if(typeof ye!="function")return[K,[]];try{const Re=await Promise.resolve(ye(ae,{getValues:w.getValues,watch:w.watch,ctx:ce,params:ae,...R})),Me=Array.isArray(Re)?Re:[];return[K,Me]}catch{return[K,[]]}}));if(!B)return;const D={};for(const[P,K]of F)D[P]=K;ee(P=>Object.entries(D).some(([Q,ae])=>{const ce=P[Q];return!ce||ce.length!==ae.length?!0:JSON.stringify(ce)!==JSON.stringify(ae)})?D:P)})(),()=>{B=!1}},[oe,JSON.stringify(V.map(B=>({n:B.name,os:B.optionSource??null,ec:B.endpointConfig??null,ctx:B.adapterCtx??B.optionAdapterCtx??null}))),R]),k.useEffect(()=>{let B=!0;return(async()=>{for(const F of V){if(F.type!=="select")continue;const D=F.name,P=F.defaultSource;if(!P)continue;const K=w.getValues(D);if(!(K==null||(Array.isArray(K)?K.length===0:K==="")))continue;const ae=g==null?void 0:g[P];if(typeof ae=="function")try{const ce=c0(F.adapterCtx??F.optionAdapterCtx),ge=await Promise.resolve(ae("",{getValues:w.getValues,watch:w.watch,ctx:ce}));if(!B)return;const ye=IO(ge,!!F.multiple);w.setValue(D,ye,{shouldDirty:!0,shouldTouch:!0})}catch{}}})(),()=>{B=!1}},[g,w.getValues,w.setValue,JSON.stringify(V.map(B=>({n:B.name,ds:B.defaultSource??null,mult:!!B.multiple})))]);const $=r1(l),ne=s1(l,E),q=k.useMemo(()=>{const B={};return o.forEach((T,F)=>{T.type==="tabs"&&(B[F]=T.tabs[0].key)}),B},[o]),[X,me]=k.useState(q),[ie,pe]=k.useState({}),[ue,de]=k.useState({}),xe=k.useRef({}),fe=k.useRef({}),we=k.useMemo(()=>Array.isArray(e.reactiveCalculations)?e.reactiveCalculations:[],[e]);k.useEffect(()=>{if(!we.length)return;const B=Q=>{if(Q==null||Q==="")return 0;if(typeof Q=="number")return Number.isFinite(Q)?Q:0;let ae=String(Q).trim().replace(/€/g,"").replace(/%/g,"").replace(/\s/g,"");if(!ae)return 0;const ce=ae.includes(","),ge=ae.includes(".");if(ce&&ge){const ve=ae.lastIndexOf(","),Re=ae.lastIndexOf(".");ve>Re?ae=ae.replace(/\./g,"").replace(",","."):ae=ae.replace(/,/g,"")}else ce&&(ae=ae.replace(/\./g,"").replace(",","."));const ye=Number(ae);return Number.isFinite(ye)?ye:0},T=Q=>Math.round((Q+Number.EPSILON)*100)/100,F=Q=>{var Me,Ce;const ae=Q.type??Q.formula??Q.operation??Q.calculation,ce=Q.parameters??{};if(ae!=="importeConImpuestos")return;const ge=((Me=ce.importeSin)==null?void 0:Me.fieldRef)??Q.importeSinField??"nImpSinImpuesto",ye=((Ce=ce.impuestos)==null?void 0:Ce.fieldRef)??Q.impuestosField??"N_IMPUESTO",ve=B(w.getValues(ge)),Re=B(w.getValues(ye));return!ve&&!Re?"":T(ve+ve*Re/100)},D=(Q,ae)=>{if(Q!=null)return typeof Q!="object"?Q:Q[ae]??Q.value??Q.total??Q.importeTotal??Q.importeCon??Q.iImporteCon},P=async Q=>{const ae=Q.targetField??Q.target;if(ae)try{let ce=F(Q);if(ce===void 0){const ye=Q.endpoint??Q.endpointConfig,ve=(ye==null?void 0:ye.key)??Q.endpointKey??Q.key;if(!ve)return;const Re=g==null?void 0:g[ve];if(typeof Re!="function"){console.warn("[FormRenderer] Reactive calculation provider not found:",ve);return}const Me=ye!=null&&ye.parameters?mr(ye.parameters,w.getValues,R):w.getValues(),Ce=await Promise.resolve(Re(Me,{getValues:w.getValues,watch:w.watch,params:Me,...R}));ce=D(Ce,ae)}if(ce===void 0)return;const ge=w.getValues(ae);if(String(ge??"")===String(ce??""))return;w.setValue(ae,ce,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}catch(ce){console.error("[FormRenderer] Error executing reactive calculation:",ce)}},K=w.watch((Q,{name:ae})=>{ae&&we.forEach((ce,ge)=>{const ye=ce.targetField??ce.target,ve=ce.triggerFields??ce.fields??[];if(ae===ye||Array.isArray(ve)&&ve.length>0&&!ve.includes(ae))return;const Re=`${ye??"target"}_${ge}`;fe.current[Re]&&clearTimeout(fe.current[Re]),fe.current[Re]=setTimeout(()=>P(ce),ce.debounceMs??250)})});return()=>{K.unsubscribe(),Object.values(fe.current).forEach(Q=>Q&&clearTimeout(Q)),fe.current={}}},[w,g,R,we]);const C=k.useCallback(async()=>{const B={},T=l.filter(D=>{var K,Q,ae;const P=D;return((K=P.visibleWhen)==null?void 0:K.endpoint)||((Q=P.disabledWhen)==null?void 0:Q.endpoint)||((ae=P.clearWhen)==null?void 0:ae.endpoint)});if(T.length===0)return;(await Promise.all(T.map(async D=>{const P=D,K=P.name,Q={};for(const ae of["visibleWhen","disabledWhen","clearWhen"]){const ce=P[ae];if(ce!=null&&ce.enabled&&ce.endpoint){const ge=ce.endpoint.key,ye=g==null?void 0:g[ge];if(typeof ye=="function")try{const ve=mr(ce.endpoint.parameters,w.getValues,R),Re=await Promise.resolve(ye(ve,{getValues:w.getValues,watch:w.watch,params:ve,...R}));Q[ae]=typeof Re=="object"&&Re!==null?!!Re.ok:!!Re}catch(ve){console.error(`Error evaluando regla backend para ${K}.${ae}:`,ve),Q[ae]=!1}}}return{fieldName:K,res:Q}}))).forEach(({fieldName:D,res:P})=>{Object.keys(P).length>0&&(B[D]=P)}),pe(B)},[l,g,w,R]),G=k.useCallback(async B=>{var Q;const T=B,F=T.name,D=T.asyncValidation.endpoint,P=D.key,K=g==null?void 0:g[P];if(typeof K=="function"){de(ae=>({...ae,[F]:{...ae[F],loading:!0}}));try{const ae=mr(D.parameters,w.getValues,R),ce=await Promise.resolve(K(ae,{getValues:w.getValues,watch:w.watch,params:ae,...R})),ge=typeof ce=="object"&&ce!==null?!!ce.ok:!!ce,ye=typeof ce=="object"&&ce!==null?ce.message:void 0;de(ve=>({...ve,[F]:{ok:ge,message:ye,loading:!1}})),ge?((Q=w.formState.errors[F])==null?void 0:Q.type)==="manual"&&w.clearErrors(F):w.setError(F,{type:"manual",message:ye||"Validación externa fallida"})}catch{de(ce=>({...ce,[F]:{ok:!1,message:"Error de conexión",loading:!1}}))}}},[g,w,R]),te=k.useCallback(async(B,T,F)=>{const D=l.filter(P=>{var ce,ge;const K=P,Q=(ce=K.asyncValidation)==null?void 0:ce.endpoint;if(!Q)return!1;const ae=Q.trigger||K.asyncValidation.trigger||"onBlur";if(F&&ae!==F&&!(ae==="auto"&&F==="onChange"))return!1;if(T&&F!=="onSubmit"){const ye=K.name===T,ve=Object.values(Q.parameters||{}).some(Me=>Me.fieldRef===T),Re=(ge=Q.triggerFields)==null?void 0:ge.includes(T);if(!ye&&!ve&&!Re)return!1}return!0});for(const P of D){const K=P,Q=K.name,ae=K.asyncValidation.endpoint;if(F==="onChange"&&ae.trigger==="debounced"){xe.current[Q]&&clearTimeout(xe.current[Q]),xe.current[Q]=setTimeout(()=>G(P),ae.debounceMs||300);continue}await G(P)}},[l,G]);k.useEffect(()=>{C();const B=w.watch((T,{name:F})=>{C(),F&&te(T,F,"onChange")});return()=>{B.unsubscribe(),Object.values(xe.current).forEach(T=>T&&clearTimeout(T))}},[C,te,w]);const W=k.useCallback((B,T,F,D)=>{var K;if(!(B!=null&&B.enabled))return T;let P=!0;if(B.rule)try{const Q={...w.getValues(),...R,ACTIVE_VARIANT:n};P=!!Lo(B.rule,Q)}catch{P=T}if(P&&F&&D&&B.endpoint){const Q=(K=ie[F])==null?void 0:K[D];if(Q===void 0)return!1;P=Q}return P},[w,ie,n]),H=k.useMemo(()=>l.map(B=>B).filter(B=>{var T;return((T=B.clearWhen)==null?void 0:T.enabled)&&(B.clearWhen.rule||B.clearWhen.endpoint)}).map(B=>({name:B.name,container:B.clearWhen})),[l]);k.useEffect(()=>{if(!H.length)return;const B=F=>{H.forEach(({name:D,container:P})=>{try{if(W(P,!1,D,"clearWhen")){const Q=P.clearTo??"";F[D]!==Q&&w.setValue(D,Q,{shouldDirty:!0,shouldValidate:!0})}}catch{}})};B(w.getValues());const T=w.watch(()=>B(w.getValues()));return()=>{var F;return(F=T==null?void 0:T.unsubscribe)==null?void 0:F.call(T)}},[w,H,W]);const J=k.useCallback(B=>{const T=lt(b,B);if(!T)return"";const F={...R,...j,sys:R,form:j};return Nl(T,F)},[b,R,j]),_=k.useCallback((B,T)=>{var ze,ot,rt,Ze;let F;if(typeof B=="string"){if(F=$[B],!F){const ke=(l??[]).find(Oe=>(Oe==null?void 0:Oe.name)===B);if(ke)F=ke;else return null}}else F=B;const D=F.name,P=D?T?`${T}.${D}`:D:void 0,K=F.visibleWhen;if(!W(K,!0,D,"visibleWhen"))return null;let ae=!!F.disabled;const ce=F.disabledWhen,ge=W(ce,!1,D,"disabledWhen");if(ce!=null&&ce.enabled&&(ae=ge),!(ce!=null&&ce.enabled)&&D&&ne[D]&&(ae=!0),F.type==="search"){const ke=typeof F.searchFn=="function",Oe=Ao(F.searchSource,F.endpointConfig),Le=async qe=>{if(ke)return F.searchFn(qe,{getValues:w.getValues,watch:w.watch});if(Oe){const De=F.endpointConfig?mr(F.endpointConfig.parameters,w.getValues,R):{...R,...w.getValues()},Ke=g==null?void 0:g[Oe];if(typeof Ke=="function")return await Ke({q:qe,...De},{getValues:w.getValues,watch:w.watch,params:De,...R});if(Array.isArray(Ke))return Ke}return[]},Se={};F.searchMode&&(Se.searchMode=F.searchMode),F.minChars&&(Se.minChars=F.minChars),F.debounceMs&&(Se.debounceMs=F.debounceMs),F.resolveByValue&&(Se.resolveByValue=F.resolveByValue);const _e=Mt(F.labelIconLeft??F.labelPrefixIcon),Ve=Mt(F.labelIconRight??F.labelSuffixIcon),nt=Mt(F.prefixIcon),Te=Mt(F.suffixIcon);return s.jsx(Ri,{name:P,control:E,searchFn:Le,label:J(F.label),size:F.size,width:F.width,disabled:ae||I,labelPrefixIcon:_e,labelSuffixIcon:Ve,prefixIcon:nt,suffixIcon:Te,...Se},P)}if(F.type==="inputGroup"){const ke=F,Oe=(ke.inputs??[]).map(Le=>{var wr,an;const Se=typeof Le=="string"?$[Le]??(l??[]).find(ps=>(ps==null?void 0:ps.name)===Le):Le;if(!Se)return null;const _e=Se.name,Ve=T?`${T}.${_e}`:_e,nt=Se.disabledWhen;let Te=!!Se.disabled;const qe=W(nt,!1,_e,"disabledWhen");nt!=null&&nt.enabled&&(Te=qe),!(nt!=null&&nt.enabled)&&ne[_e]&&(Te=!0);const De=Mt(Se.labelIconLeft??Se.labelPrefixIcon),Ke=Mt(Se.labelIconRight??Se.labelSuffixIcon),sr=Mt(Se.prefixIcon),Vr=Mt(Se.suffixIcon),Dt={name:Ve,control:E,label:J(Se.label),size:Se.size,width:Se.width,placeholder:J(Se.placeholder),hasError:!!(O[Ve]||T&&((wr=O[T])!=null&&wr[_e])),errorMessage:lt(b,(an=O[Ve])==null?void 0:an.message),loading:Z,disabled:Te||I,suffixButton:Se.suffixButton,reserveErrorSpace:!0,labelPrefixIcon:De,labelSuffixIcon:Ke,prefixIcon:sr,suffixIcon:Vr};return Se.type==="select"?{...Dt,options:Se.options??re[_e]??z[_e]??[],loadOptions:Se.options||Se.optionSource?void 0:Se.loadOptions}:{...Dt,type:Se.type}}).filter(Boolean);return s.jsx(Ei,{groupLabel:lt(b,ke.groupLabel),inputs:Oe,separator:ke.separator,useSeparator:ke.useSeparator,className:ke.className,showVisibleLabel:ke.showVisibleLabel,size:ke.size},`inputGroup_${P??ke.groupLabel??"group"}`)}if(F.type==="button"){const ke=F,Oe=ke.icon,Le=Oe&&typeof Oe=="object"&&Oe.name&&Oe.style?Mt(Oe):void 0;return s.jsx("div",{className:"self-center",children:s.jsx(he,{type:"button",variant:ke.variant,size:ke.size,width:ke.width,icon:Le,iconPosition:ke.iconPosition,ariaLabel:J(ke.ariaLabel),onClick:ke.onClick,disabled:ae||I,children:J(ke.label)})},P??ke.label)}if(F.type==="array"){const ke=F;return s.jsx(LO,{schema:{...ke,name:P},renderField:_},P)}const ye=F.suffixButton,ve=typeof ye=="string"?_(ye):ye,Re=Mt(F.labelIconLeft??F.labelPrefixIcon),Me=Mt(F.labelIconRight??F.labelSuffixIcon),Ce=Mt(F.prefixIcon),$e=Mt(F.suffixIcon),Fe={name:P,control:E,disabled:ae||I,label:J(F.label),size:F.size,width:F.width,placeholder:J(F.placeholder),info:lt(b,F.info),suffixButton:ve,labelPrefixIcon:Re,labelSuffixIcon:Me,prefixIcon:Ce,suffixIcon:$e,onBlur:()=>{te(w.getValues(),D,"onBlur"),l.filter(Oe=>{const Le=Oe;return["visibleWhen","disabledWhen","clearWhen"].some(Se=>{var Ve;const _e=(Ve=Le[Se])==null?void 0:Ve.endpoint;return(_e==null?void 0:_e.trigger)==="onBlur"&&Object.values(_e.parameters||{}).some(nt=>nt.fieldRef===D)})}).length>0&&C()}};switch(F.type){case"select":{const ke=F.options??re[D]??z[D]??[],Oe=Array.isArray(ke)&&ke.length?`${ke.length}:${ke.map(Se=>String((Se==null?void 0:Se.value)??"")).join("|")}`:"0",Le=!F.options&&!F.optionSource&&F.loadOptions;return s.jsx(ht,{name:P,control:E,render:({field:Se})=>{var _e;return s.jsx(Ue,{...Fe,value:Se.value,onChange:Se.onChange,options:ke,loadOptions:Le||void 0,hasError:!!O[P],errorMessage:lt(b,(_e=O[P])==null?void 0:_e.message),suffixButton:ve,mode:"menu",searchable:!0,searchPlaceholder:b("ds.fields.defaults.search.placeholder"),noOptionsText:b("ds.fields.defaults.search.noMatches")})}},`${P}:${Oe}`)}case"textarea":return s.jsx(ht,{name:P,control:E,render:({field:ke,fieldState:Oe})=>{var Le;return s.jsx(ar,{...Fe,value:ke.value,onChange:ke.onChange,maxLength:F.maxLength,showCounter:!!F.showCounter,hasError:!!Oe.error,errorMessage:lt(b,(Le=Oe.error)==null?void 0:Le.message)})}},P);case"file":return s.jsx(xi,{...Fe,defaultValue:[],maxFiles:F.maxFiles,accept:F.accept,hideDropZone:F.hideDropZone,existingFiles:F.existingFiles,hasError:!!O[P],errorMessage:lt(b,(ze=O[P])==null?void 0:ze.message)},P);case"checkbox":return s.jsx(tt,{...Fe,defaultValue:!1,hasError:!!O[P],errorMessage:lt(b,(ot=O[P])==null?void 0:ot.message),name:P},P);case"date":return s.jsx(An,{...Fe,defaultValue:"",showTime:!!F.showTime,hasError:!!O[P],errorMessage:lt(b,(rt=O[P])==null?void 0:rt.message)},P);case"optionGroup":return s.jsx(ns,{...Fe,options:F.options||[],multiple:F.multiple,vertical:F.vertical,groupLabel:F.groupLabel,defaultValue:F.defaultValue,className:F.width?void 0:"w-full",name:P},P);case"iban":return s.jsx(ht,{name:P,control:E,render:({field:ke,fieldState:Oe})=>{var Le;return s.jsx(as,{label:J(F.label),placeholder:J(F.placeholder),size:F.size,disabled:ae||I,value:ke.value??"",onChange:ke.onChange,onBlur:ke.onBlur,hasError:!!Oe.error,errorMessage:lt(b,(Le=Oe.error)==null?void 0:Le.message),name:P})}},P);case"dni":return s.jsx(ht,{name:P,control:E,render:({field:ke,fieldState:Oe})=>{var Le;return s.jsx(Si,{label:J(F.label),placeholder:J(F.placeholder),size:F.size,disabled:ae||I,value:ke.value??"",onChange:ke.onChange,onBlur:ke.onBlur,hasError:!!Oe.error,errorMessage:lt(b,(Le=Oe.error)==null?void 0:Le.message),name:P})}},P);default:return s.jsx(ts,{...Fe,type:F.type,loadingDefaults:Z,hasError:!!O[P],errorMessage:lt(b,(Ze=O[P])==null?void 0:Ze.message),suffixButton:ve,name:P},P)}},[l,$,E,O,I,Z,z,re,W,ne,w.getValues,w.watch,g,b]);return s.jsx(fi,{...w,children:s.jsxs("form",{noValidate:!0,onSubmit:S(async B=>{await te(B,void 0,"onSubmit"),!(Object.keys(w.formState.errors).length>0)&&(await i(B),p(c??b("ds.form.saveSuccess"),"success"))},B=>{oO(B),p(u??b("ds.form.saveError"),"error")}),className:"space-y-6",children:[o.map((B,T)=>B.type==="rows"?s.jsx(k.Fragment,{children:B.sections.map((F,D)=>s.jsx("div",{children:s.jsx(at,{title:J(F.sectionTitle),defaultOpen:F.defaultOpen,children:F.rows.map((P,K)=>s.jsxs("div",{children:[P.title&&s.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:J(P.title)}),s.jsx("div",{className:"flex flex-wrap -mx-2",children:P.columns.map((Q,ae)=>{var ce;return s.jsx("div",{className:`${Q.width} px-2 flex flex-col`,children:s.jsx("div",{className:"",children:Q.fields?Q.fields.map(ge=>_(ge)):(ce=Q.rows)==null?void 0:ce.map((ge,ye)=>s.jsx("div",{className:"mb-1",children:s.jsx("div",{className:"flex flex-wrap -mx-2",children:ge.columns.map((ve,Re)=>{var Me;return s.jsx("div",{className:`${ve.width} px-2`,children:(Me=ve.fields)==null?void 0:Me.map(Ce=>_(Ce))},Re)})})},ye))})},ae)})})]},K))})},D))},T):s.jsx(xr,{options:B.tabs.map(F=>{const D=F.icon?Mn(F.icon.name,F.icon.style):null;return{label:J(F.label),value:F.key,disabled:F.disabled,icon:D?s.jsx(D,{className:"w-4 h-4"}):null}}),value:X[T],onChange:F=>me(D=>({...D,[T]:F})),children:Object.fromEntries(B.tabs.map(F=>[F.key,s.jsx("div",{className:"space-y-6",children:F.sections.map((D,P)=>s.jsx("div",{className:"mb-6",children:s.jsx(at,{title:J(D.sectionTitle),defaultOpen:D.defaultOpen,children:D.rows.map((K,Q)=>s.jsx("div",{children:s.jsx("div",{className:"flex flex-wrap -mx-2",children:K.columns.map((ae,ce)=>{var ge;return s.jsx("div",{className:`${ae.width??"flex-1"} px-2 flex flex-col`,children:s.jsx("div",{className:"space-y-4",children:(ge=ae.fields)==null?void 0:ge.map((ye,ve)=>s.jsx(k.Fragment,{children:_(ye)},ve))})},ce)})})},Q))})},P))},F.key)]))},T)),s.jsx("footer",{className:"py-4 w-full flex justify-center space-x-4",children:d??s.jsx(he,{type:"submit",variant:"primary",icon:Gr,size:"sm",disabled:I||Z||M>0,children:b(I?"ds.form.sending":"ds.form.submit")})})]})})}function i1({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:be("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:be("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:be("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:be("absolute transition-opacity duration-200 ease-in-out",e?"opacity-100 text-[var(--color-ds-background-accent)]":"opacity-0")})]})})}const d0="licytal:ui:theme",c1=k.createContext({theme:"light",dark:!1,toggle:()=>{}});function TO({children:e}){const[t,r]=k.useState(!1),[n,o]=k.useState("light");k.useEffect(()=>{if(typeof window>"u")return;const i=localStorage.getItem(d0);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(d0,n))},[n,t]);const l=()=>o(i=>i==="light"?"dark":"light");return t?s.jsx(c1.Provider,{value:{theme:n,dark:n==="dark",toggle:l},children:e}):null}const Ni=()=>k.useContext(c1),Kn={locale:"licytal:ui:locale",theme:"licytal:ui:theme"},d1=({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(Kn.locale,v)}catch{}i==null||i(v)},b=()=>{const v=!n;try{localStorage.setItem(Kn.theme,v?"dark":"light")}catch{}h()};return k.useEffect(()=>{try{const v=localStorage.getItem(Kn.locale);v&&v!==o&&(i==null||i(v))}catch{}},[]),k.useEffect(()=>{if(o)try{localStorage.setItem(Kn.locale,o)}catch{}},[o]),k.useEffect(()=>{try{const v=localStorage.getItem(Kn.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(Ue,{size:"sm",width:"auto",options:l,value:o,onChange:p,disableErrorPlaceholder:!0,label:"Idioma",labelHidden:!0}),!!u.length&&s.jsx(Ue,{size:"sm",width:"auto",options:u,value:c,onChange:v=>d==null?void 0:d(v),disableErrorPlaceholder:!0,label:"Perfil",labelHidden:!0}),s.jsx(i1,{dark:n,onToggle:b})]})]})},BO={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:be("inline-flex items-center justify-center","rounded-full","bg-transparent","text-[var(--color-ds-text-primary)]","transition-transform","focus:outline-none",BO[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:be(t==="sm"?"h-4 w-4":t==="md"?"h-5 w-5":"h-6 w-6")})})}const ZO=({loading:e=!1,ariaLabel:t="Cargando..."})=>e?s.jsxs("div",{className:`\r
|
|
98
|
+
hover:bg-[var(--color-ds-background-surface)]`,onClick:()=>{const we=String(fe.value).trim();R(e,we,{shouldDirty:!0,shouldValidate:!0}),V(fe.label??we),re.current=!1,ee.current=!1,Z(!1)},children:fe.label},String(fe.value)))})]})}})}const Gn=(e,t)=>e[t],o0=e=>e instanceof Date?e.getTime():e;function NO(e,t,r){const n=o0(e),o=o0(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 Lo(e,t){if(!e)return!1;switch(e.op){case"eq":return Gn(t,e.field)===e.value;case"neq":return Gn(t,e.field)!==e.value;case"in":return e.values.includes(Gn(t,e.field));case"notIn":return!e.values.includes(Gn(t,e.field));case"gt":case"gte":case"lt":case"lte":return NO(Gn(t,e.field),e.value,e.op);case"and":return e.rules.every(r=>Lo(r,t));case"or":return e.rules.some(r=>Lo(r,t));case"always":return!!e.value;default:return!1}}function Ci(e){return!!e&&(typeof e=="function"||typeof e=="object")}function Mn(e,t){const r=t==="outline"?Sn:Nn,n=r==null?void 0:r[e];return Ci(n)?n:null}const AO=Object.entries(Sn).filter(([e,t])=>e.endsWith("Icon")&&Ci(t)).map(([e,t])=>({name:e,Icon:t,style:"outline"})),MO=Object.entries(Nn).filter(([e,t])=>e.endsWith("Icon")&&Ci(t)).map(([e,t])=>({name:e,Icon:t,style:"solid"})),OO=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&&Mn(e.name,e.style)||OO,h=k.useCallback((b,v)=>{const g=Mn(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(he,{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(Ee,{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(s0,{items:AO,query:c,onPick:b=>h(b,"outline"),onClear:p}),solid:s.jsx(s0,{items:MO,query:c,onPick:b=>h(b,"solid"),onClear:p})}})]})})]})},s0=({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 lt(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 LO=({schema:e,renderField:t})=>{var v,g,x;const{control:r}=_r(),{fields:n,append:o,remove:l}=Hx({control:r,name:e.name}),{label:i,addLabel:c="Añadir",items:u,disabled:d,validation:m,className:f}=e,{formState:{errors:h}}=_r(),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:be("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 R=`${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(he,{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(gt,{className:"w-4 h-4"})})}),s.jsx("div",{className:"grid grid-cols-1 gap-4",children:u.map((j,E)=>s.jsx(k.Fragment,{children:t(j,R)},E))})]},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(he,{type:"button",variant:"outline",size:"sm",onClick:()=>{o({})},children:[s.jsx(Jt,{className:"w-4 h-4 mr-1"}),c]})]})};function l0(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,24)}function $O(e){return e.replace(/(.{4})/g,"$1 ").trim()}function as({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(()=>l0(o),[o]),w=k.useMemo(()=>$O(x),[x]),y=R=>{const j=l0(R.target.value);l(j)};return s.jsx(Ee,{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:Ul,className:v,"aria-label":g,inputMode:"text",autoComplete:"off",spellCheck:!1})}function i0(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}=vt(),w=k.useMemo(()=>i0(o),[o]),y=k.useMemo(()=>w,[w]),R=j=>{const E=i0(j.target.value);l(E)};return s.jsx(Ee,{id:p,name:b,label:e,labelHidden:t,placeholder:r,size:n,value:y,onChange:R,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 c0(e){if(e){if(typeof e=="string")try{return JSON.parse(e)}catch{return}if(typeof e=="object")return e}}function IO(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 FO=e=>e.type!=="inputGroup"&&e.type!=="button";function _O(){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 Mn(t,r)||void 0}function l1({schema:e,resolver:t,serviceRegistry:r,activeVariantId:n}){var U;const{layout:o,fields:l=[],onSubmit:i,successMessage:c,errorMessage:u,footerButtons:d,defaultValues:m,loadDefaultValues:f,validationSchema:h}=e,{show:p}=Zr(),{t:b}=vt(),v=_O(),g=r??((U=v==null?void 0:v.services)==null?void 0:U.registry)??void 0,x=k.useMemo(()=>{if(t)return t;try{const B=h??ki(e);return wi(B)}catch{return}},[t,e,h]),w=gi({resolver:x,mode:"onBlur",reValidateMode:"onChange",defaultValues:m??{}}),y=Jr(B=>B.setRuntimeState),R=Jr(B=>B.systemContext),j=Jr(B=>B.formValues);k.useEffect(()=>{y({isActive:!0});let B=!1;return(async()=>{const T=e.defaultSource,F=e.onloadEndpoint;let D={};if(e.variables&&Array.isArray(e.variables)&&(e.variables.forEach(K=>{K.type==="constant"&&(D[K.key]=K.value)}),e.variables.forEach(K=>{if(K.type==="computed"&&K.value)try{const Q=new Function("ctx",`return (${K.value});`);D[K.key]=Q(D)}catch(Q){console.warn(`[FormRenderer] Error evaluating computed variable "${K.key}":`,Q),D[K.key]=null}})),T)try{const K=g==null?void 0:g[T];if(K){const Q=typeof K=="function"?await K():K;Q&&typeof Q=="object"&&(D={...D,...Q})}}catch{}y({systemContext:{...D}});const P=[];if(F&&P.push(F),e.onloadEndpoints&&Array.isArray(e.onloadEndpoints)&&P.push(...e.onloadEndpoints),P.length>0){const K=async ae=>{if(!ae)return{};try{const ce=g==null?void 0:g[ae.key];if(!ce)return console.warn("[FormRenderer] Provider not found for key:",ae.key),{};const ge=mr(ae.parameters,(()=>({})),{...D,ACTIVE_VARIANT:e.activeVariantId});console.log(`[FormRenderer] Calling ${ae.key} with params:`,ge);const ye=await Promise.resolve(ce(ge,{getValues:(()=>({})),watch:(()=>{}),params:ge,...D}));let ve=ye;if(typeof ye=="string")try{ve=JSON.parse(ye)}catch(Re){console.warn("[FormRenderer] Failed to parse onload response string",Re)}return ve&&typeof ve=="object"?ve:(console.warn("[FormRenderer] OnLoad response is not an object:",ve),{})}catch(ce){return console.error("Error in onloadEndpoint",ce),{}}};(await Promise.all(P.map(K))).forEach(ae=>{ae&&typeof ae=="object"&&(D={...D,...ae})}),B||y({systemContext:{...D}})}if(!B&&Object.keys(D).length>0){const K={...e.defaultValues??{}};Object.assign(K,D);const Q=e.fields.map(ae=>ae.name);Object.keys(D).forEach(ae=>{const ce=ae.toLowerCase(),ge=Q.find(ye=>ye.toLowerCase()===ce);ge&&(K[ge]===void 0||K[ge]==="")&&(K[ge]=D[ae])}),w.reset(K)}})(),()=>{B=!0,y({isActive:!1,systemContext:{},formValues:{}})}},[e,g,w.reset]);const{control:E,reset:N,handleSubmit:S,formState:{errors:O,isSubmitting:I}}=w,[Z,L]=k.useState(!1);k.useEffect(()=>{f&&(L(!0),f().then(B=>N(B)).finally(()=>L(!1)))},[f,N]);const V=k.useMemo(()=>(l??[]).filter(FO),[l]),{loadingCount:M,optionsMap:z}=o1(V),[re,ee]=k.useState({}),[oe,se]=k.useState(0);k.useEffect(()=>{let B;const T=w.watch(()=>{clearTimeout(B),B=setTimeout(()=>{se(F=>F+1)},500)});return()=>{T.unsubscribe(),clearTimeout(B)}},[w.watch]);const Y=k.useRef(g);k.useEffect(()=>{Y.current=g},[g]);const A=k.useRef({});k.useEffect(()=>{let B=!0;return(async()=>{const F=await Promise.all(V.filter(P=>P.type==="select"&&(P.optionSource||P.endpointConfig)).map(async P=>{var ve;const K=P.name,Q=Ao(P.optionSource,P.endpointConfig);if(!Q)return[K,[]];const ae=P.endpointConfig?mr(P.endpointConfig.parameters,w.getValues,R):{...R,...w.getValues()},ce=c0(P.adapterCtx??P.optionAdapterCtx),ge=JSON.stringify({key:Q,resolvedParams:ae,ctx:ce});A.current[K],A.current[K]=ge;const ye=(ve=Y.current)==null?void 0:ve[Q];if(typeof ye!="function")return[K,[]];try{const Re=await Promise.resolve(ye(ae,{getValues:w.getValues,watch:w.watch,ctx:ce,params:ae,...R})),Me=Array.isArray(Re)?Re:[];return[K,Me]}catch{return[K,[]]}}));if(!B)return;const D={};for(const[P,K]of F)D[P]=K;ee(P=>Object.entries(D).some(([Q,ae])=>{const ce=P[Q];return!ce||ce.length!==ae.length?!0:JSON.stringify(ce)!==JSON.stringify(ae)})?D:P)})(),()=>{B=!1}},[oe,JSON.stringify(V.map(B=>({n:B.name,os:B.optionSource??null,ec:B.endpointConfig??null,ctx:B.adapterCtx??B.optionAdapterCtx??null}))),R]),k.useEffect(()=>{let B=!0;return(async()=>{for(const F of V){if(F.type!=="select")continue;const D=F.name,P=F.defaultSource;if(!P)continue;const K=w.getValues(D);if(!(K==null||(Array.isArray(K)?K.length===0:K==="")))continue;const ae=g==null?void 0:g[P];if(typeof ae=="function")try{const ce=c0(F.adapterCtx??F.optionAdapterCtx),ge=await Promise.resolve(ae("",{getValues:w.getValues,watch:w.watch,ctx:ce}));if(!B)return;const ye=IO(ge,!!F.multiple);w.setValue(D,ye,{shouldDirty:!0,shouldTouch:!0})}catch{}}})(),()=>{B=!1}},[g,w.getValues,w.setValue,JSON.stringify(V.map(B=>({n:B.name,ds:B.defaultSource??null,mult:!!B.multiple})))]);const $=r1(l),ne=s1(l,E),q=k.useMemo(()=>{const B={};return o.forEach((T,F)=>{T.type==="tabs"&&(B[F]=T.tabs[0].key)}),B},[o]),[X,me]=k.useState(q),[ie,pe]=k.useState({}),[ue,de]=k.useState({}),xe=k.useRef({}),fe=k.useRef({}),we=k.useMemo(()=>Array.isArray(e.reactiveCalculations)?e.reactiveCalculations:[],[e]);k.useEffect(()=>{if(!we.length)return;const B=Q=>{if(Q==null||Q==="")return 0;if(typeof Q=="number")return Number.isFinite(Q)?Q:0;let ae=String(Q).trim().replace(/€/g,"").replace(/%/g,"").replace(/\s/g,"");if(!ae)return 0;const ce=ae.includes(","),ge=ae.includes(".");if(ce&&ge){const ve=ae.lastIndexOf(","),Re=ae.lastIndexOf(".");ve>Re?ae=ae.replace(/\./g,"").replace(",","."):ae=ae.replace(/,/g,"")}else ce&&(ae=ae.replace(/\./g,"").replace(",","."));const ye=Number(ae);return Number.isFinite(ye)?ye:0},T=Q=>Math.round((Q+Number.EPSILON)*100)/100,F=Q=>{var Me,Ce;const ae=Q.type??Q.formula??Q.operation??Q.calculation,ce=Q.parameters??{};if(ae!=="importeConImpuestos")return;const ge=((Me=ce.importeSin)==null?void 0:Me.fieldRef)??Q.importeSinField??"nImpSinImpuesto",ye=((Ce=ce.impuestos)==null?void 0:Ce.fieldRef)??Q.impuestosField??"N_IMPUESTO",ve=B(w.getValues(ge)),Re=B(w.getValues(ye));return!ve&&!Re?"":T(ve+ve*Re/100)},D=(Q,ae)=>{if(Q!=null)return typeof Q!="object"?Q:Q[ae]??Q.value??Q.total??Q.importeTotal??Q.importeCon??Q.iImporteCon},P=async Q=>{const ae=Q.targetField??Q.target;if(ae)try{let ce=F(Q);if(ce===void 0){const ye=Q.endpoint??Q.endpointConfig,ve=(ye==null?void 0:ye.key)??Q.endpointKey??Q.key;if(!ve)return;const Re=g==null?void 0:g[ve];if(typeof Re!="function"){console.warn("[FormRenderer] Reactive calculation provider not found:",ve);return}const Me=ye!=null&&ye.parameters?mr(ye.parameters,w.getValues,R):w.getValues(),Ce=await Promise.resolve(Re(Me,{getValues:w.getValues,watch:w.watch,params:Me,...R}));ce=D(Ce,ae)}if(ce===void 0)return;const ge=w.getValues(ae);if(String(ge??"")===String(ce??""))return;w.setValue(ae,ce,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}catch(ce){console.error("[FormRenderer] Error executing reactive calculation:",ce)}},K=w.watch((Q,{name:ae})=>{ae&&we.forEach((ce,ge)=>{const ye=ce.targetField??ce.target,ve=ce.triggerFields??ce.fields??[];if(ae===ye||Array.isArray(ve)&&ve.length>0&&!ve.includes(ae))return;const Re=`${ye??"target"}_${ge}`;fe.current[Re]&&clearTimeout(fe.current[Re]),fe.current[Re]=setTimeout(()=>P(ce),ce.debounceMs??250)})});return()=>{K.unsubscribe(),Object.values(fe.current).forEach(Q=>Q&&clearTimeout(Q)),fe.current={}}},[w,g,R,we]);const C=k.useCallback(async()=>{const B={},T=l.filter(D=>{var K,Q,ae;const P=D;return((K=P.visibleWhen)==null?void 0:K.endpoint)||((Q=P.disabledWhen)==null?void 0:Q.endpoint)||((ae=P.clearWhen)==null?void 0:ae.endpoint)});if(T.length===0)return;(await Promise.all(T.map(async D=>{const P=D,K=P.name,Q={};for(const ae of["visibleWhen","disabledWhen","clearWhen"]){const ce=P[ae];if(ce!=null&&ce.enabled&&ce.endpoint){const ge=ce.endpoint.key,ye=g==null?void 0:g[ge];if(typeof ye=="function")try{const ve=mr(ce.endpoint.parameters,w.getValues,R),Re=await Promise.resolve(ye(ve,{getValues:w.getValues,watch:w.watch,params:ve,...R}));Q[ae]=typeof Re=="object"&&Re!==null?!!Re.ok:!!Re}catch(ve){console.error(`Error evaluando regla backend para ${K}.${ae}:`,ve),Q[ae]=!1}}}return{fieldName:K,res:Q}}))).forEach(({fieldName:D,res:P})=>{Object.keys(P).length>0&&(B[D]=P)}),pe(B)},[l,g,w,R]),G=k.useCallback(async B=>{var Q;const T=B,F=T.name,D=T.asyncValidation.endpoint,P=D.key,K=g==null?void 0:g[P];if(typeof K=="function"){de(ae=>({...ae,[F]:{...ae[F],loading:!0}}));try{const ae=mr(D.parameters,w.getValues,R),ce=await Promise.resolve(K(ae,{getValues:w.getValues,watch:w.watch,params:ae,...R})),ge=typeof ce=="object"&&ce!==null?!!ce.ok:!!ce,ye=typeof ce=="object"&&ce!==null?ce.message:void 0;de(ve=>({...ve,[F]:{ok:ge,message:ye,loading:!1}})),ge?((Q=w.formState.errors[F])==null?void 0:Q.type)==="manual"&&w.clearErrors(F):w.setError(F,{type:"manual",message:ye||"Validación externa fallida"})}catch{de(ce=>({...ce,[F]:{ok:!1,message:"Error de conexión",loading:!1}}))}}},[g,w,R]),te=k.useCallback(async(B,T,F)=>{const D=l.filter(P=>{var ce,ge;const K=P,Q=(ce=K.asyncValidation)==null?void 0:ce.endpoint;if(!Q)return!1;const ae=Q.trigger||K.asyncValidation.trigger||"onBlur";if(F&&ae!==F&&!(ae==="auto"&&F==="onChange"))return!1;if(T&&F!=="onSubmit"){const ye=K.name===T,ve=Object.values(Q.parameters||{}).some(Me=>Me.fieldRef===T),Re=(ge=Q.triggerFields)==null?void 0:ge.includes(T);if(!ye&&!ve&&!Re)return!1}return!0});for(const P of D){const K=P,Q=K.name,ae=K.asyncValidation.endpoint;if(F==="onChange"&&ae.trigger==="debounced"){xe.current[Q]&&clearTimeout(xe.current[Q]),xe.current[Q]=setTimeout(()=>G(P),ae.debounceMs||300);continue}await G(P)}},[l,G]);k.useEffect(()=>{C();const B=w.watch((T,{name:F})=>{C(),F&&te(T,F,"onChange")});return()=>{B.unsubscribe(),Object.values(xe.current).forEach(T=>T&&clearTimeout(T))}},[C,te,w]);const W=k.useCallback((B,T,F,D)=>{var K;if(!(B!=null&&B.enabled))return T;let P=!0;if(B.rule)try{const Q={...w.getValues(),...R,ACTIVE_VARIANT:n};P=!!Lo(B.rule,Q)}catch{P=T}if(P&&F&&D&&B.endpoint){const Q=(K=ie[F])==null?void 0:K[D];if(Q===void 0)return!1;P=Q}return P},[w,ie,n]),H=k.useMemo(()=>l.map(B=>B).filter(B=>{var T;return((T=B.clearWhen)==null?void 0:T.enabled)&&(B.clearWhen.rule||B.clearWhen.endpoint)}).map(B=>({name:B.name,container:B.clearWhen})),[l]);k.useEffect(()=>{if(!H.length)return;const B=F=>{H.forEach(({name:D,container:P})=>{try{if(W(P,!1,D,"clearWhen")){const Q=P.clearTo??"";F[D]!==Q&&w.setValue(D,Q,{shouldDirty:!0,shouldValidate:!0})}}catch{}})};B(w.getValues());const T=w.watch(()=>B(w.getValues()));return()=>{var F;return(F=T==null?void 0:T.unsubscribe)==null?void 0:F.call(T)}},[w,H,W]);const J=k.useCallback(B=>{const T=lt(b,B);if(!T)return"";const F={...R,...j,sys:R,form:j};return Nl(T,F)},[b,R,j]),_=k.useCallback((B,T)=>{var ze,ot,rt,Ze;let F;if(typeof B=="string"){if(F=$[B],!F){const ke=(l??[]).find(Oe=>(Oe==null?void 0:Oe.name)===B);if(ke)F=ke;else return null}}else F=B;const D=F.name,P=D?T?`${T}.${D}`:D:void 0,K=F.visibleWhen;if(!W(K,!0,D,"visibleWhen"))return null;let ae=!!F.disabled;const ce=F.disabledWhen,ge=W(ce,!1,D,"disabledWhen");if(ce!=null&&ce.enabled&&(ae=ge),!(ce!=null&&ce.enabled)&&D&&ne[D]&&(ae=!0),F.type==="search"){const ke=typeof F.searchFn=="function",Oe=Ao(F.searchSource,F.endpointConfig),Le=async qe=>{if(ke)return F.searchFn(qe,{getValues:w.getValues,watch:w.watch});if(Oe){const De=F.endpointConfig?mr(F.endpointConfig.parameters,w.getValues,R):{...R,...w.getValues()},Ke=g==null?void 0:g[Oe];if(typeof Ke=="function")return await Ke({q:qe,...De},{getValues:w.getValues,watch:w.watch,params:De,...R});if(Array.isArray(Ke))return Ke}return[]},Se={};F.searchMode&&(Se.searchMode=F.searchMode),F.minChars&&(Se.minChars=F.minChars),F.debounceMs&&(Se.debounceMs=F.debounceMs),F.resolveByValue&&(Se.resolveByValue=F.resolveByValue);const _e=Mt(F.labelIconLeft??F.labelPrefixIcon),Ve=Mt(F.labelIconRight??F.labelSuffixIcon),nt=Mt(F.prefixIcon),Te=Mt(F.suffixIcon);return s.jsx(Ri,{name:P,control:E,searchFn:Le,label:J(F.label),size:F.size,width:F.width,disabled:ae||I,labelPrefixIcon:_e,labelSuffixIcon:Ve,prefixIcon:nt,suffixIcon:Te,...Se},P)}if(F.type==="inputGroup"){const ke=F,Oe=(ke.inputs??[]).map(Le=>{var wr,an;const Se=typeof Le=="string"?$[Le]??(l??[]).find(ps=>(ps==null?void 0:ps.name)===Le):Le;if(!Se)return null;const _e=Se.name,Ve=T?`${T}.${_e}`:_e,nt=Se.disabledWhen;let Te=!!Se.disabled;const qe=W(nt,!1,_e,"disabledWhen");nt!=null&&nt.enabled&&(Te=qe),!(nt!=null&&nt.enabled)&&ne[_e]&&(Te=!0);const De=Mt(Se.labelIconLeft??Se.labelPrefixIcon),Ke=Mt(Se.labelIconRight??Se.labelSuffixIcon),sr=Mt(Se.prefixIcon),Vr=Mt(Se.suffixIcon),Dt={name:Ve,control:E,label:J(Se.label),size:Se.size,width:Se.width,placeholder:J(Se.placeholder),hasError:!!(O[Ve]||T&&((wr=O[T])!=null&&wr[_e])),errorMessage:lt(b,(an=O[Ve])==null?void 0:an.message),loading:Z,disabled:Te||I,suffixButton:Se.suffixButton,reserveErrorSpace:!0,labelPrefixIcon:De,labelSuffixIcon:Ke,prefixIcon:sr,suffixIcon:Vr};return Se.type==="select"?{...Dt,options:Se.options??re[_e]??z[_e]??[],loadOptions:Se.options||Se.optionSource?void 0:Se.loadOptions}:{...Dt,type:Se.type}}).filter(Boolean);return s.jsx(Ei,{groupLabel:lt(b,ke.groupLabel),inputs:Oe,separator:ke.separator,useSeparator:ke.useSeparator,className:ke.className,showVisibleLabel:ke.showVisibleLabel,size:ke.size},`inputGroup_${P??ke.groupLabel??"group"}`)}if(F.type==="button"){const ke=F,Oe=ke.icon,Le=Oe&&typeof Oe=="object"&&Oe.name&&Oe.style?Mt(Oe):void 0;return s.jsx("div",{className:"self-center",children:s.jsx(he,{type:"button",variant:ke.variant,size:ke.size,width:ke.width,icon:Le,iconPosition:ke.iconPosition,ariaLabel:J(ke.ariaLabel),onClick:ke.onClick,disabled:ae||I,children:J(ke.label)})},P??ke.label)}if(F.type==="array"){const ke=F;return s.jsx(LO,{schema:{...ke,name:P},renderField:_},P)}const ye=F.suffixButton,ve=typeof ye=="string"?_(ye):ye,Re=Mt(F.labelIconLeft??F.labelPrefixIcon),Me=Mt(F.labelIconRight??F.labelSuffixIcon),Ce=Mt(F.prefixIcon),$e=Mt(F.suffixIcon),Fe={name:P,control:E,disabled:ae||I,readOnly:F.readOnly===!0,label:J(F.label),size:F.size,width:F.width,placeholder:J(F.placeholder),info:lt(b,F.info),suffixButton:ve,labelPrefixIcon:Re,labelSuffixIcon:Me,prefixIcon:Ce,suffixIcon:$e,onBlur:()=>{te(w.getValues(),D,"onBlur"),l.filter(Oe=>{const Le=Oe;return["visibleWhen","disabledWhen","clearWhen"].some(Se=>{var Ve;const _e=(Ve=Le[Se])==null?void 0:Ve.endpoint;return(_e==null?void 0:_e.trigger)==="onBlur"&&Object.values(_e.parameters||{}).some(nt=>nt.fieldRef===D)})}).length>0&&C()}};switch(F.type){case"select":{const ke=F.options??re[D]??z[D]??[],Oe=Array.isArray(ke)&&ke.length?`${ke.length}:${ke.map(Se=>String((Se==null?void 0:Se.value)??"")).join("|")}`:"0",Le=!F.options&&!F.optionSource&&F.loadOptions;return s.jsx(ht,{name:P,control:E,render:({field:Se})=>{var _e;return s.jsx(Ue,{...Fe,value:Se.value,onChange:Se.onChange,options:ke,loadOptions:Le||void 0,hasError:!!O[P],errorMessage:lt(b,(_e=O[P])==null?void 0:_e.message),suffixButton:ve,mode:"menu",searchable:!0,searchPlaceholder:b("ds.fields.defaults.search.placeholder"),noOptionsText:b("ds.fields.defaults.search.noMatches")})}},`${P}:${Oe}`)}case"textarea":return s.jsx(ht,{name:P,control:E,render:({field:ke,fieldState:Oe})=>{var Le;return s.jsx(ar,{...Fe,value:ke.value,onChange:ke.onChange,maxLength:F.maxLength,showCounter:!!F.showCounter,hasError:!!Oe.error,errorMessage:lt(b,(Le=Oe.error)==null?void 0:Le.message)})}},P);case"file":return s.jsx(xi,{...Fe,defaultValue:[],maxFiles:F.maxFiles,accept:F.accept,hideDropZone:F.hideDropZone,existingFiles:F.existingFiles,hasError:!!O[P],errorMessage:lt(b,(ze=O[P])==null?void 0:ze.message)},P);case"checkbox":return s.jsx(tt,{...Fe,defaultValue:!1,hasError:!!O[P],errorMessage:lt(b,(ot=O[P])==null?void 0:ot.message),name:P},P);case"date":return s.jsx(An,{...Fe,defaultValue:"",showTime:!!F.showTime,hasError:!!O[P],errorMessage:lt(b,(rt=O[P])==null?void 0:rt.message)},P);case"optionGroup":return s.jsx(ns,{...Fe,options:F.options||[],multiple:F.multiple,vertical:F.vertical,groupLabel:F.groupLabel,defaultValue:F.defaultValue,className:F.width?void 0:"w-full",name:P},P);case"iban":return s.jsx(ht,{name:P,control:E,render:({field:ke,fieldState:Oe})=>{var Le;return s.jsx(as,{label:J(F.label),placeholder:J(F.placeholder),size:F.size,disabled:ae||I,value:ke.value??"",onChange:ke.onChange,onBlur:ke.onBlur,hasError:!!Oe.error,errorMessage:lt(b,(Le=Oe.error)==null?void 0:Le.message),name:P})}},P);case"dni":return s.jsx(ht,{name:P,control:E,render:({field:ke,fieldState:Oe})=>{var Le;return s.jsx(Si,{label:J(F.label),placeholder:J(F.placeholder),size:F.size,disabled:ae||I,value:ke.value??"",onChange:ke.onChange,onBlur:ke.onBlur,hasError:!!Oe.error,errorMessage:lt(b,(Le=Oe.error)==null?void 0:Le.message),name:P})}},P);default:return s.jsx(ts,{...Fe,type:F.type,loadingDefaults:Z,hasError:!!O[P],errorMessage:lt(b,(Ze=O[P])==null?void 0:Ze.message),suffixButton:ve,name:P},P)}},[l,$,E,O,I,Z,z,re,W,ne,w.getValues,w.watch,g,b]);return s.jsx(fi,{...w,children:s.jsxs("form",{noValidate:!0,onSubmit:S(async B=>{await te(B,void 0,"onSubmit"),!(Object.keys(w.formState.errors).length>0)&&(await i(B),p(c??b("ds.form.saveSuccess"),"success"))},B=>{oO(B),p(u??b("ds.form.saveError"),"error")}),className:"space-y-6",children:[o.map((B,T)=>B.type==="rows"?s.jsx(k.Fragment,{children:B.sections.map((F,D)=>s.jsx("div",{children:s.jsx(at,{title:J(F.sectionTitle),defaultOpen:F.defaultOpen,children:F.rows.map((P,K)=>s.jsxs("div",{children:[P.title&&s.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:J(P.title)}),s.jsx("div",{className:"flex flex-wrap -mx-2",children:P.columns.map((Q,ae)=>{var ce;return s.jsx("div",{className:`${Q.width} px-2 flex flex-col`,children:s.jsx("div",{className:"",children:Q.fields?Q.fields.map(ge=>_(ge)):(ce=Q.rows)==null?void 0:ce.map((ge,ye)=>s.jsx("div",{className:"mb-1",children:s.jsx("div",{className:"flex flex-wrap -mx-2",children:ge.columns.map((ve,Re)=>{var Me;return s.jsx("div",{className:`${ve.width} px-2`,children:(Me=ve.fields)==null?void 0:Me.map(Ce=>_(Ce))},Re)})})},ye))})},ae)})})]},K))})},D))},T):s.jsx(xr,{options:B.tabs.map(F=>{const D=F.icon?Mn(F.icon.name,F.icon.style):null;return{label:J(F.label),value:F.key,disabled:F.disabled,icon:D?s.jsx(D,{className:"w-4 h-4"}):null}}),value:X[T],onChange:F=>me(D=>({...D,[T]:F})),children:Object.fromEntries(B.tabs.map(F=>[F.key,s.jsx("div",{className:"space-y-6",children:F.sections.map((D,P)=>s.jsx("div",{className:"mb-6",children:s.jsx(at,{title:J(D.sectionTitle),defaultOpen:D.defaultOpen,children:D.rows.map((K,Q)=>s.jsx("div",{children:s.jsx("div",{className:"flex flex-wrap -mx-2",children:K.columns.map((ae,ce)=>{var ge;return s.jsx("div",{className:`${ae.width??"flex-1"} px-2 flex flex-col`,children:s.jsx("div",{className:"space-y-4",children:(ge=ae.fields)==null?void 0:ge.map((ye,ve)=>s.jsx(k.Fragment,{children:_(ye)},ve))})},ce)})})},Q))})},P))},F.key)]))},T)),s.jsx("footer",{className:"py-4 w-full flex justify-center space-x-4",children:d??s.jsx(he,{type:"submit",variant:"primary",icon:Gr,size:"sm",disabled:I||Z||M>0,children:b(I?"ds.form.sending":"ds.form.submit")})})]})})}function i1({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:be("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:be("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:be("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:be("absolute transition-opacity duration-200 ease-in-out",e?"opacity-100 text-[var(--color-ds-background-accent)]":"opacity-0")})]})})}const d0="licytal:ui:theme",c1=k.createContext({theme:"light",dark:!1,toggle:()=>{}});function TO({children:e}){const[t,r]=k.useState(!1),[n,o]=k.useState("light");k.useEffect(()=>{if(typeof window>"u")return;const i=localStorage.getItem(d0);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(d0,n))},[n,t]);const l=()=>o(i=>i==="light"?"dark":"light");return t?s.jsx(c1.Provider,{value:{theme:n,dark:n==="dark",toggle:l},children:e}):null}const Ni=()=>k.useContext(c1),Kn={locale:"licytal:ui:locale",theme:"licytal:ui:theme"},d1=({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(Kn.locale,v)}catch{}i==null||i(v)},b=()=>{const v=!n;try{localStorage.setItem(Kn.theme,v?"dark":"light")}catch{}h()};return k.useEffect(()=>{try{const v=localStorage.getItem(Kn.locale);v&&v!==o&&(i==null||i(v))}catch{}},[]),k.useEffect(()=>{if(o)try{localStorage.setItem(Kn.locale,o)}catch{}},[o]),k.useEffect(()=>{try{const v=localStorage.getItem(Kn.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(Ue,{size:"sm",width:"auto",options:l,value:o,onChange:p,disableErrorPlaceholder:!0,label:"Idioma",labelHidden:!0}),!!u.length&&s.jsx(Ue,{size:"sm",width:"auto",options:u,value:c,onChange:v=>d==null?void 0:d(v),disableErrorPlaceholder:!0,label:"Perfil",labelHidden:!0}),s.jsx(i1,{dark:n,onToggle:b})]})]})},BO={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:be("inline-flex items-center justify-center","rounded-full","bg-transparent","text-[var(--color-ds-text-primary)]","transition-transform","focus:outline-none",BO[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:be(t==="sm"?"h-4 w-4":t==="md"?"h-5 w-5":"h-6 w-6")})})}const ZO=({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
|
package/dist/index.es.js
CHANGED
|
@@ -27877,6 +27877,7 @@ function zO({
|
|
|
27877
27877
|
name: D,
|
|
27878
27878
|
control: k,
|
|
27879
27879
|
disabled: ne || L,
|
|
27880
|
+
readOnly: I.readOnly === !0,
|
|
27880
27881
|
label: K(I.label),
|
|
27881
27882
|
size: I.size,
|
|
27882
27883
|
width: I.width,
|
package/dist/index.umd.js
CHANGED
|
@@ -96,7 +96,7 @@ attempted value: ${i}
|
|
|
96
96
|
shadow-lg ${ae} max-h-48 overflow-auto z-10
|
|
97
97
|
`,children:j.map(he=>l.jsx("li",{className:`px-2 ${G} flex items-center cursor-pointer
|
|
98
98
|
text-[var(--color-ds-text-primary)]
|
|
99
|
-
hover:bg-[var(--color-ds-background-surface)]`,onClick:()=>{const ye=String(he.value).trim();E(e,ye,{shouldDirty:!0,shouldValidate:!0}),I(he.label??ye),ee.current=!1,X.current=!1,B(!1)},children:he.label},String(he.value)))})]})}})}const Fo=(e,t)=>e[t],G2=e=>e instanceof Date?e.getTime():e;function DI(e,t,r){const n=G2(e),a=G2(t);return typeof n=="number"&&typeof a=="number"||typeof n=="string"&&typeof a=="string"?r==="gt"?n>a:r==="gte"?n>=a:r==="lt"?n<a:n<=a:!1}function Di(e,t){if(!e)return!1;switch(e.op){case"eq":return Fo(t,e.field)===e.value;case"neq":return Fo(t,e.field)!==e.value;case"in":return e.values.includes(Fo(t,e.field));case"notIn":return!e.values.includes(Fo(t,e.field));case"gt":case"gte":case"lt":case"lte":return DI(Fo(t,e.field),e.value,e.op);case"and":return e.rules.every(r=>Di(r,t));case"or":return e.rules.some(r=>Di(r,t));case"always":return!!e.value;default:return!1}}function hd(e){return!!e&&(typeof e=="function"||typeof e=="object")}function Ma(e,t){const r=t==="outline"?ba:Da,n=r==null?void 0:r[e];return hd(n)?n:null}const SI=Object.entries(ba).filter(([e,t])=>e.endsWith("Icon")&&hd(t)).map(([e,t])=>({name:e,Icon:t,style:"outline"})),AI=Object.entries(Da).filter(([e,t])=>e.endsWith("Icon")&&hd(t)).map(([e,t])=>({name:e,Icon:t,style:"solid"})),NI=dc||cc||(e=>l.jsx("svg",{...e})),Wn=({value:e,onChange:t,buttonLabel:r,disabled:n,className:a})=>{const[o,i]=C.useState(!1),[c,d]=C.useState(""),[u,f]=C.useState((e==null?void 0:e.style)??"outline"),h=e&&Ma(e.name,e.style)||NI,p=C.useCallback((v,g)=>{const b=Ma(v,g);t==null||t({name:v,style:g},b),i(!1)},[t]),m=C.useCallback(()=>{t==null||t(void 0,void 0),i(!1)},[t]);return l.jsxs(l.Fragment,{children:[l.jsx(me,{size:"sm",variant:"outline",shape:"circle",className:`rounded-full p-0 w-8 h-8 inline-flex items-center justify-center ${a??""}`,disabled:n,onClick:()=>i(!0),ariaLabel:"Elegir icono",title:r||"Elegir icono",children:l.jsx(h,{className:"h-4 w-4"})}),l.jsx(Bt,{isOpen:o,onClose:()=>i(!1),title:"Seleccionar icono",children:l.jsxs("div",{className:"space-y-3",children:[l.jsx(De,{labelHidden:!0,placeholder:"Buscar icono (p. ej. 'user', 'arrow', 'calendar'...)",value:c,onChange:v=>d(v.target.value)}),l.jsx(zr,{options:[{label:"Outline",value:"outline"},{label:"Solid",value:"solid"}],value:u,onChange:v=>f(v),children:{outline:l.jsx(K2,{items:SI,query:c,onPick:v=>p(v,"outline"),onClear:m}),solid:l.jsx(K2,{items:AI,query:c,onPick:v=>p(v,"solid"),onClear:m})}})]})})]})},K2=({items:e,query:t,onPick:r,onClear:n})=>{const a=C.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]),o=st;return l.jsx("div",{className:"custom-scroll max-h-[60vh] overflow-y-auto",children:l.jsxs("div",{className:"grid gap-2 grid-cols-3 sm:grid-cols-4 md:grid-cols-6",children:[l.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:[l.jsx("div",{className:"h-full w-full flex items-center justify-center",children:o?l.jsx(o,{className:"w-6 h-6"}):l.jsx("span",{className:"text-ds-lg",children:"×"})}),l.jsx("div",{className:"mt-1 text-center",children:l.jsx("span",{className:"block text-[11px] leading-tight text-[var(--color-ds-text-secondary)] truncate",children:"Ninguno"})})]}),(a.length===0?e:a).map(({name:i,Icon:c})=>l.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:[l.jsx("div",{className:"h-full w-full flex items-center justify-center",children:l.jsx(c,{className:"w-6 h-6 text-[var(--color-ds-text-primary)]"})}),l.jsx("div",{className:"mt-1 text-center",children:l.jsx("span",{className:"block text-[11px] leading-tight text-[var(--color-ds-text-secondary)] truncate",children:i.replace(/Icon$/,"")})})]},i))]})})};function gt(e,t,r=""){if(!t)return r;if(typeof t=="object"&&t!==null){if(t.type==="complex"){const a=[];return t.header&&a.push(`<strong>${t.header}</strong>`),t.template&&a.push(t.template),a.join("<br/>")||r}return r}return e(t,{defaultValue:t})}const FI=({schema:e,renderField:t})=>{var g,b,x;const{control:r}=gn(),{fields:n,append:a,remove:o}=KE({control:r,name:e.name}),{label:i,addLabel:c="Añadir",items:d,disabled:u,validation:f,className:h}=e,{formState:{errors:p}}=gn(),m=((b=(g=p[e.name])==null?void 0:g.root)==null?void 0:b.message)||((x=p[e.name])==null?void 0:x.message),v=typeof m=="string"?m:void 0;return l.jsxs("div",{className:we("space-y-3",h),children:[i&&l.jsx("div",{className:"flex items-center justify-between",children:l.jsx("label",{className:"block text-ds-sm font-medium text-[var(--color-ds-text-primary)]",children:i})}),l.jsx("div",{className:"space-y-4",children:n.map((w,y)=>{const E=`${e.name}.${y}`;return l.jsxs("div",{className:"relative rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)] p-4 group",children:[!u&&l.jsx("div",{className:"absolute top-2 right-2",children:l.jsx(me,{size:"xs",variant:"ghost",className:"text-[var(--color-ds-text-error)] hover:bg-[var(--color-ds-background-error-hover)]",onClick:()=>o(y),title:"Eliminar fila",ariaLabel:"Eliminar fila",children:l.jsx(St,{className:"w-4 h-4"})})}),l.jsx("div",{className:"grid grid-cols-1 gap-4",children:d.map((k,j)=>l.jsx(C.Fragment,{children:t(k,E)},j))})]},w.id)})}),n.length===0&&l.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."}),v&&l.jsx("p",{className:"text-xs text-[var(--color-ds-text-error)]",children:v}),!u&&l.jsxs(me,{type:"button",variant:"outline",size:"sm",onClick:()=>{a({})},children:[l.jsx(hr,{className:"w-4 h-4 mr-1"}),c]})]})};function J2(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,24)}function _I(e){return e.replace(/(.{4})/g,"$1 ").trim()}function Si({label:e,labelHidden:t,placeholder:r="ES00 0000 0000 0000 0000 0000",size:n="sm",value:a,onChange:o,onBlur:i,disabled:c,required:d,reserveErrorSpace:u=!0,error:f,errorMessage:h,hasError:p,id:m,name:v,className:g,"aria-label":b}){const x=C.useMemo(()=>J2(a),[a]),w=C.useMemo(()=>_I(x),[x]),y=E=>{const k=J2(E.target.value);o(k)};return l.jsx(De,{id:m,name:v,label:e,labelHidden:t,placeholder:r,size:n,value:w,onChange:y,onBlur:i,disabled:c,required:d,hasError:p||!!f||!!h,errorMessage:h||f,reserveErrorSpace:u,prefixIcon:ql,className:g,"aria-label":b,inputMode:"text",autoComplete:"off",spellCheck:!1})}function Y2(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,9)}function _ee(e){return e}function pd({label:e,labelHidden:t,placeholder:r="12345678A",size:n="sm",value:a,onChange:o,onBlur:i,disabled:c,required:d,reserveErrorSpace:u=!0,error:f,errorMessage:h,hasError:p,id:m,name:v,className:g,"aria-label":b}){const{t:x}=Nt(),w=C.useMemo(()=>Y2(a),[a]),y=C.useMemo(()=>w,[w]),E=k=>{const j=Y2(k.target.value);o(j)};return l.jsx(De,{id:m,name:v,label:e,labelHidden:t,placeholder:r,size:n,value:y,onChange:E,onBlur:i,disabled:c,required:d,hasError:p||!!f||!!h,errorMessage:h||f,prefixIcon:nc,className:g,"aria-label":b,inputMode:"text",autoComplete:"off",spellCheck:!1,reserveErrorSpace:u})}function X2(e){if(e){if(typeof e=="string")try{return JSON.parse(e)}catch{return}if(typeof e=="object")return e}}function MI(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 RI=e=>e.type!=="inputGroup"&&e.type!=="button";function OI(){try{return Zt()??void 0}catch{return}}function Kt(e){if(!e||typeof e!="object")return;const t=e.name,r=e.style;if(!(!t||!r))return Ma(t,r)||void 0}function Q2({schema:e,resolver:t,serviceRegistry:r,activeVariantId:n}){var U;const{layout:a,fields:o=[],onSubmit:i,successMessage:c,errorMessage:d,footerButtons:u,defaultValues:f,loadDefaultValues:h,validationSchema:p}=e,{show:m}=xn(),{t:v}=Nt(),g=OI(),b=r??((U=g==null?void 0:g.services)==null?void 0:U.registry)??void 0,x=C.useMemo(()=>{if(t)return t;try{const P=p??ld(e);return Xc(P)}catch{return}},[t,e,p]),w=Ic({resolver:x,mode:"onBlur",reValidateMode:"onChange",defaultValues:f??{}}),y=Hn(P=>P.setRuntimeState),E=Hn(P=>P.systemContext),k=Hn(P=>P.formValues);C.useEffect(()=>{y({isActive:!0});let P=!1;return(async()=>{const $=e.defaultSource,L=e.onloadEndpoint;let Z={};if(e.variables&&Array.isArray(e.variables)&&(e.variables.forEach(J=>{J.type==="constant"&&(Z[J.key]=J.value)}),e.variables.forEach(J=>{if(J.type==="computed"&&J.value)try{const te=new Function("ctx",`return (${J.value});`);Z[J.key]=te(Z)}catch(te){console.warn(`[FormRenderer] Error evaluating computed variable "${J.key}":`,te),Z[J.key]=null}})),$)try{const J=b==null?void 0:b[$];if(J){const te=typeof J=="function"?await J():J;te&&typeof te=="object"&&(Z={...Z,...te})}}catch{}y({systemContext:{...Z}});const z=[];if(L&&z.push(L),e.onloadEndpoints&&Array.isArray(e.onloadEndpoints)&&z.push(...e.onloadEndpoints),z.length>0){const J=async oe=>{if(!oe)return{};try{const ce=b==null?void 0:b[oe.key];if(!ce)return console.warn("[FormRenderer] Provider not found for key:",oe.key),{};const ve=Pr(oe.parameters,(()=>({})),{...Z,ACTIVE_VARIANT:e.activeVariantId});console.log(`[FormRenderer] Calling ${oe.key} with params:`,ve);const ke=await Promise.resolve(ce(ve,{getValues:(()=>({})),watch:(()=>{}),params:ve,...Z}));let be=ke;if(typeof ke=="string")try{be=JSON.parse(ke)}catch(Se){console.warn("[FormRenderer] Failed to parse onload response string",Se)}return be&&typeof be=="object"?be:(console.warn("[FormRenderer] OnLoad response is not an object:",be),{})}catch(ce){return console.error("Error in onloadEndpoint",ce),{}}};(await Promise.all(z.map(J))).forEach(oe=>{oe&&typeof oe=="object"&&(Z={...Z,...oe})}),P||y({systemContext:{...Z}})}if(!P&&Object.keys(Z).length>0){const J={...e.defaultValues??{}};Object.assign(J,Z);const te=e.fields.map(oe=>oe.name);Object.keys(Z).forEach(oe=>{const ce=oe.toLowerCase(),ve=te.find(ke=>ke.toLowerCase()===ce);ve&&(J[ve]===void 0||J[ve]==="")&&(J[ve]=Z[oe])}),w.reset(J)}})(),()=>{P=!0,y({isActive:!1,systemContext:{},formValues:{}})}},[e,b,w.reset]);const{control:j,reset:A,handleSubmit:S,formState:{errors:_,isSubmitting:M}}=w,[B,R]=C.useState(!1);C.useEffect(()=>{h&&(R(!0),h().then(P=>A(P)).finally(()=>R(!1)))},[h,A]);const I=C.useMemo(()=>(o??[]).filter(RI),[o]),{loadingCount:F,optionsMap:V}=U2(I),[ee,X]=C.useState({}),[ne,se]=C.useState(0);C.useEffect(()=>{let P;const $=w.watch(()=>{clearTimeout(P),P=setTimeout(()=>{se(L=>L+1)},500)});return()=>{$.unsubscribe(),clearTimeout(P)}},[w.watch]);const q=C.useRef(b);C.useEffect(()=>{q.current=b},[b]);const N=C.useRef({});C.useEffect(()=>{let P=!0;return(async()=>{const L=await Promise.all(I.filter(z=>z.type==="select"&&(z.optionSource||z.endpointConfig)).map(async z=>{var be;const J=z.name,te=ui(z.optionSource,z.endpointConfig);if(!te)return[J,[]];const oe=z.endpointConfig?Pr(z.endpointConfig.parameters,w.getValues,E):{...E,...w.getValues()},ce=X2(z.adapterCtx??z.optionAdapterCtx),ve=JSON.stringify({key:te,resolvedParams:oe,ctx:ce});N.current[J],N.current[J]=ve;const ke=(be=q.current)==null?void 0:be[te];if(typeof ke!="function")return[J,[]];try{const Se=await Promise.resolve(ke(oe,{getValues:w.getValues,watch:w.watch,ctx:ce,params:oe,...E})),Me=Array.isArray(Se)?Se:[];return[J,Me]}catch{return[J,[]]}}));if(!P)return;const Z={};for(const[z,J]of L)Z[z]=J;X(z=>Object.entries(Z).some(([te,oe])=>{const ce=z[te];return!ce||ce.length!==oe.length?!0:JSON.stringify(ce)!==JSON.stringify(oe)})?Z:z)})(),()=>{P=!1}},[ne,JSON.stringify(I.map(P=>({n:P.name,os:P.optionSource??null,ec:P.endpointConfig??null,ctx:P.adapterCtx??P.optionAdapterCtx??null}))),E]),C.useEffect(()=>{let P=!0;return(async()=>{for(const L of I){if(L.type!=="select")continue;const Z=L.name,z=L.defaultSource;if(!z)continue;const J=w.getValues(Z);if(!(J==null||(Array.isArray(J)?J.length===0:J==="")))continue;const oe=b==null?void 0:b[z];if(typeof oe=="function")try{const ce=X2(L.adapterCtx??L.optionAdapterCtx),ve=await Promise.resolve(oe("",{getValues:w.getValues,watch:w.watch,ctx:ce}));if(!P)return;const ke=MI(ve,!!L.multiple);w.setValue(Z,ke,{shouldDirty:!0,shouldTouch:!0})}catch{}}})(),()=>{P=!1}},[b,w.getValues,w.setValue,JSON.stringify(I.map(P=>({n:P.name,ds:P.defaultSource??null,mult:!!P.multiple})))]);const O=z2(o),ae=q2(o,j),G=C.useMemo(()=>{const P={};return a.forEach(($,L)=>{$.type==="tabs"&&(P[L]=$.tabs[0].key)}),P},[a]),[Q,pe]=C.useState(G),[le,ge]=C.useState({}),[ue,de]=C.useState({}),xe=C.useRef({}),he=C.useRef({}),ye=C.useMemo(()=>Array.isArray(e.reactiveCalculations)?e.reactiveCalculations:[],[e]);C.useEffect(()=>{if(!ye.length)return;const P=te=>{if(te==null||te==="")return 0;if(typeof te=="number")return Number.isFinite(te)?te:0;let oe=String(te).trim().replace(/€/g,"").replace(/%/g,"").replace(/\s/g,"");if(!oe)return 0;const ce=oe.includes(","),ve=oe.includes(".");if(ce&&ve){const be=oe.lastIndexOf(","),Se=oe.lastIndexOf(".");be>Se?oe=oe.replace(/\./g,"").replace(",","."):oe=oe.replace(/,/g,"")}else ce&&(oe=oe.replace(/\./g,"").replace(",","."));const ke=Number(oe);return Number.isFinite(ke)?ke:0},$=te=>Math.round((te+Number.EPSILON)*100)/100,L=te=>{var Me,Ae;const oe=te.type??te.formula??te.operation??te.calculation,ce=te.parameters??{};if(oe!=="importeConImpuestos")return;const ve=((Me=ce.importeSin)==null?void 0:Me.fieldRef)??te.importeSinField??"nImpSinImpuesto",ke=((Ae=ce.impuestos)==null?void 0:Ae.fieldRef)??te.impuestosField??"N_IMPUESTO",be=P(w.getValues(ve)),Se=P(w.getValues(ke));return!be&&!Se?"":$(be+be*Se/100)},Z=(te,oe)=>{if(te!=null)return typeof te!="object"?te:te[oe]??te.value??te.total??te.importeTotal??te.importeCon??te.iImporteCon},z=async te=>{const oe=te.targetField??te.target;if(oe)try{let ce=L(te);if(ce===void 0){const ke=te.endpoint??te.endpointConfig,be=(ke==null?void 0:ke.key)??te.endpointKey??te.key;if(!be)return;const Se=b==null?void 0:b[be];if(typeof Se!="function"){console.warn("[FormRenderer] Reactive calculation provider not found:",be);return}const Me=ke!=null&&ke.parameters?Pr(ke.parameters,w.getValues,E):w.getValues(),Ae=await Promise.resolve(Se(Me,{getValues:w.getValues,watch:w.watch,params:Me,...E}));ce=Z(Ae,oe)}if(ce===void 0)return;const ve=w.getValues(oe);if(String(ve??"")===String(ce??""))return;w.setValue(oe,ce,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}catch(ce){console.error("[FormRenderer] Error executing reactive calculation:",ce)}},J=w.watch((te,{name:oe})=>{oe&&ye.forEach((ce,ve)=>{const ke=ce.targetField??ce.target,be=ce.triggerFields??ce.fields??[];if(oe===ke||Array.isArray(be)&&be.length>0&&!be.includes(oe))return;const Se=`${ke??"target"}_${ve}`;he.current[Se]&&clearTimeout(he.current[Se]),he.current[Se]=setTimeout(()=>z(ce),ce.debounceMs??250)})});return()=>{J.unsubscribe(),Object.values(he.current).forEach(te=>te&&clearTimeout(te)),he.current={}}},[w,b,E,ye]);const D=C.useCallback(async()=>{const P={},$=o.filter(Z=>{var J,te,oe;const z=Z;return((J=z.visibleWhen)==null?void 0:J.endpoint)||((te=z.disabledWhen)==null?void 0:te.endpoint)||((oe=z.clearWhen)==null?void 0:oe.endpoint)});if($.length===0)return;(await Promise.all($.map(async Z=>{const z=Z,J=z.name,te={};for(const oe of["visibleWhen","disabledWhen","clearWhen"]){const ce=z[oe];if(ce!=null&&ce.enabled&&ce.endpoint){const ve=ce.endpoint.key,ke=b==null?void 0:b[ve];if(typeof ke=="function")try{const be=Pr(ce.endpoint.parameters,w.getValues,E),Se=await Promise.resolve(ke(be,{getValues:w.getValues,watch:w.watch,params:be,...E}));te[oe]=typeof Se=="object"&&Se!==null?!!Se.ok:!!Se}catch(be){console.error(`Error evaluando regla backend para ${J}.${oe}:`,be),te[oe]=!1}}}return{fieldName:J,res:te}}))).forEach(({fieldName:Z,res:z})=>{Object.keys(z).length>0&&(P[Z]=z)}),ge(P)},[o,b,w,E]),K=C.useCallback(async P=>{var te;const $=P,L=$.name,Z=$.asyncValidation.endpoint,z=Z.key,J=b==null?void 0:b[z];if(typeof J=="function"){de(oe=>({...oe,[L]:{...oe[L],loading:!0}}));try{const oe=Pr(Z.parameters,w.getValues,E),ce=await Promise.resolve(J(oe,{getValues:w.getValues,watch:w.watch,params:oe,...E})),ve=typeof ce=="object"&&ce!==null?!!ce.ok:!!ce,ke=typeof ce=="object"&&ce!==null?ce.message:void 0;de(be=>({...be,[L]:{ok:ve,message:ke,loading:!1}})),ve?((te=w.formState.errors[L])==null?void 0:te.type)==="manual"&&w.clearErrors(L):w.setError(L,{type:"manual",message:ke||"Validación externa fallida"})}catch{de(ce=>({...ce,[L]:{ok:!1,message:"Error de conexión",loading:!1}}))}}},[b,w,E]),re=C.useCallback(async(P,$,L)=>{const Z=o.filter(z=>{var ce,ve;const J=z,te=(ce=J.asyncValidation)==null?void 0:ce.endpoint;if(!te)return!1;const oe=te.trigger||J.asyncValidation.trigger||"onBlur";if(L&&oe!==L&&!(oe==="auto"&&L==="onChange"))return!1;if($&&L!=="onSubmit"){const ke=J.name===$,be=Object.values(te.parameters||{}).some(Me=>Me.fieldRef===$),Se=(ve=te.triggerFields)==null?void 0:ve.includes($);if(!ke&&!be&&!Se)return!1}return!0});for(const z of Z){const J=z,te=J.name,oe=J.asyncValidation.endpoint;if(L==="onChange"&&oe.trigger==="debounced"){xe.current[te]&&clearTimeout(xe.current[te]),xe.current[te]=setTimeout(()=>K(z),oe.debounceMs||300);continue}await K(z)}},[o,K]);C.useEffect(()=>{D();const P=w.watch(($,{name:L})=>{D(),L&&re($,L,"onChange")});return()=>{P.unsubscribe(),Object.values(xe.current).forEach($=>$&&clearTimeout($))}},[D,re,w]);const W=C.useCallback((P,$,L,Z)=>{var J;if(!(P!=null&&P.enabled))return $;let z=!0;if(P.rule)try{const te={...w.getValues(),...E,ACTIVE_VARIANT:n};z=!!Di(P.rule,te)}catch{z=$}if(z&&L&&Z&&P.endpoint){const te=(J=le[L])==null?void 0:J[Z];if(te===void 0)return!1;z=te}return z},[w,le,n]),H=C.useMemo(()=>o.map(P=>P).filter(P=>{var $;return(($=P.clearWhen)==null?void 0:$.enabled)&&(P.clearWhen.rule||P.clearWhen.endpoint)}).map(P=>({name:P.name,container:P.clearWhen})),[o]);C.useEffect(()=>{if(!H.length)return;const P=L=>{H.forEach(({name:Z,container:z})=>{try{if(W(z,!1,Z,"clearWhen")){const te=z.clearTo??"";L[Z]!==te&&w.setValue(Z,te,{shouldDirty:!0,shouldValidate:!0})}}catch{}})};P(w.getValues());const $=w.watch(()=>P(w.getValues()));return()=>{var L;return(L=$==null?void 0:$.unsubscribe)==null?void 0:L.call($)}},[w,H,W]);const Y=C.useCallback(P=>{const $=gt(v,P);if(!$)return"";const L={...E,...k,sys:E,form:k};return cd($,L)},[v,E,k]),T=C.useCallback((P,$)=>{var Ge,pt,dt,ze;let L;if(typeof P=="string"){if(L=O[P],!L){const Ce=(o??[]).find(Re=>(Re==null?void 0:Re.name)===P);if(Ce)L=Ce;else return null}}else L=P;const Z=L.name,z=Z?$?`${$}.${Z}`:Z:void 0,J=L.visibleWhen;if(!W(J,!0,Z,"visibleWhen"))return null;let oe=!!L.disabled;const ce=L.disabledWhen,ve=W(ce,!1,Z,"disabledWhen");if(ce!=null&&ce.enabled&&(oe=ve),!(ce!=null&&ce.enabled)&&Z&&ae[Z]&&(oe=!0),L.type==="search"){const Ce=typeof L.searchFn=="function",Re=ui(L.searchSource,L.endpointConfig),Oe=async Ye=>{if(Ce)return L.searchFn(Ye,{getValues:w.getValues,watch:w.watch});if(Re){const We=L.endpointConfig?Pr(L.endpointConfig.parameters,w.getValues,E):{...E,...w.getValues()},nt=b==null?void 0:b[Re];if(typeof nt=="function")return await nt({q:Ye,...We},{getValues:w.getValues,watch:w.watch,params:We,...E});if(Array.isArray(nt))return nt}return[]},Ne={};L.searchMode&&(Ne.searchMode=L.searchMode),L.minChars&&(Ne.minChars=L.minChars),L.debounceMs&&(Ne.debounceMs=L.debounceMs),L.resolveByValue&&(Ne.resolveByValue=L.resolveByValue);const Be=Kt(L.labelIconLeft??L.labelPrefixIcon),He=Kt(L.labelIconRight??L.labelSuffixIcon),ut=Kt(L.prefixIcon),Ve=Kt(L.suffixIcon);return l.jsx(fd,{name:z,control:j,searchFn:Oe,label:Y(L.label),size:L.size,width:L.width,disabled:oe||M,labelPrefixIcon:Be,labelSuffixIcon:He,prefixIcon:ut,suffixIcon:Ve,...Ne},z)}if(L.type==="inputGroup"){const Ce=L,Re=(Ce.inputs??[]).map(Oe=>{var On,uo;const Ne=typeof Oe=="string"?O[Oe]??(o??[]).find(G0=>(G0==null?void 0:G0.name)===Oe):Oe;if(!Ne)return null;const Be=Ne.name,He=$?`${$}.${Be}`:Be,ut=Ne.disabledWhen;let Ve=!!Ne.disabled;const Ye=W(ut,!1,Be,"disabledWhen");ut!=null&&ut.enabled&&(Ve=Ye),!(ut!=null&&ut.enabled)&&ae[Be]&&(Ve=!0);const We=Kt(Ne.labelIconLeft??Ne.labelPrefixIcon),nt=Kt(Ne.labelIconRight??Ne.labelSuffixIcon),cn=Kt(Ne.prefixIcon),da=Kt(Ne.suffixIcon),Er={name:He,control:j,label:Y(Ne.label),size:Ne.size,width:Ne.width,placeholder:Y(Ne.placeholder),hasError:!!(_[He]||$&&((On=_[$])!=null&&On[Be])),errorMessage:gt(v,(uo=_[He])==null?void 0:uo.message),loading:B,disabled:Ve||M,suffixButton:Ne.suffixButton,reserveErrorSpace:!0,labelPrefixIcon:We,labelSuffixIcon:nt,prefixIcon:cn,suffixIcon:da};return Ne.type==="select"?{...Er,options:Ne.options??ee[Be]??V[Be]??[],loadOptions:Ne.options||Ne.optionSource?void 0:Ne.loadOptions}:{...Er,type:Ne.type}}).filter(Boolean);return l.jsx(dd,{groupLabel:gt(v,Ce.groupLabel),inputs:Re,separator:Ce.separator,useSeparator:Ce.useSeparator,className:Ce.className,showVisibleLabel:Ce.showVisibleLabel,size:Ce.size},`inputGroup_${z??Ce.groupLabel??"group"}`)}if(L.type==="button"){const Ce=L,Re=Ce.icon,Oe=Re&&typeof Re=="object"&&Re.name&&Re.style?Kt(Re):void 0;return l.jsx("div",{className:"self-center",children:l.jsx(me,{type:"button",variant:Ce.variant,size:Ce.size,width:Ce.width,icon:Oe,iconPosition:Ce.iconPosition,ariaLabel:Y(Ce.ariaLabel),onClick:Ce.onClick,disabled:oe||M,children:Y(Ce.label)})},z??Ce.label)}if(L.type==="array"){const Ce=L;return l.jsx(FI,{schema:{...Ce,name:z},renderField:T},z)}const ke=L.suffixButton,be=typeof ke=="string"?T(ke):ke,Se=Kt(L.labelIconLeft??L.labelPrefixIcon),Me=Kt(L.labelIconRight??L.labelSuffixIcon),Ae=Kt(L.prefixIcon),Le=Kt(L.suffixIcon),$e={name:z,control:j,disabled:oe||M,label:Y(L.label),size:L.size,width:L.width,placeholder:Y(L.placeholder),info:gt(v,L.info),suffixButton:be,labelPrefixIcon:Se,labelSuffixIcon:Me,prefixIcon:Ae,suffixIcon:Le,onBlur:()=>{re(w.getValues(),Z,"onBlur"),o.filter(Re=>{const Oe=Re;return["visibleWhen","disabledWhen","clearWhen"].some(Ne=>{var He;const Be=(He=Oe[Ne])==null?void 0:He.endpoint;return(Be==null?void 0:Be.trigger)==="onBlur"&&Object.values(Be.parameters||{}).some(ut=>ut.fieldRef===Z)})}).length>0&&D()}};switch(L.type){case"select":{const Ce=L.options??ee[Z]??V[Z]??[],Re=Array.isArray(Ce)&&Ce.length?`${Ce.length}:${Ce.map(Ne=>String((Ne==null?void 0:Ne.value)??"")).join("|")}`:"0",Oe=!L.options&&!L.optionSource&&L.loadOptions;return l.jsx(Ct,{name:z,control:j,render:({field:Ne})=>{var Be;return l.jsx(Je,{...$e,value:Ne.value,onChange:Ne.onChange,options:Ce,loadOptions:Oe||void 0,hasError:!!_[z],errorMessage:gt(v,(Be=_[z])==null?void 0:Be.message),suffixButton:be,mode:"menu",searchable:!0,searchPlaceholder:v("ds.fields.defaults.search.placeholder"),noOptionsText:v("ds.fields.defaults.search.noMatches")})}},`${z}:${Re}`)}case"textarea":return l.jsx(Ct,{name:z,control:j,render:({field:Ce,fieldState:Re})=>{var Oe;return l.jsx(Dr,{...$e,value:Ce.value,onChange:Ce.onChange,maxLength:L.maxLength,showCounter:!!L.showCounter,hasError:!!Re.error,errorMessage:gt(v,(Oe=Re.error)==null?void 0:Oe.message)})}},z);case"file":return l.jsx(Yc,{...$e,defaultValue:[],maxFiles:L.maxFiles,accept:L.accept,hideDropZone:L.hideDropZone,existingFiles:L.existingFiles,hasError:!!_[z],errorMessage:gt(v,(Ge=_[z])==null?void 0:Ge.message)},z);case"checkbox":return l.jsx(it,{...$e,defaultValue:!1,hasError:!!_[z],errorMessage:gt(v,(pt=_[z])==null?void 0:pt.message),name:z},z);case"date":return l.jsx(Sa,{...$e,defaultValue:"",showTime:!!L.showTime,hasError:!!_[z],errorMessage:gt(v,(dt=_[z])==null?void 0:dt.message)},z);case"optionGroup":return l.jsx(ji,{...$e,options:L.options||[],multiple:L.multiple,vertical:L.vertical,groupLabel:L.groupLabel,defaultValue:L.defaultValue,className:L.width?void 0:"w-full",name:z},z);case"iban":return l.jsx(Ct,{name:z,control:j,render:({field:Ce,fieldState:Re})=>{var Oe;return l.jsx(Si,{label:Y(L.label),placeholder:Y(L.placeholder),size:L.size,disabled:oe||M,value:Ce.value??"",onChange:Ce.onChange,onBlur:Ce.onBlur,hasError:!!Re.error,errorMessage:gt(v,(Oe=Re.error)==null?void 0:Oe.message),name:z})}},z);case"dni":return l.jsx(Ct,{name:z,control:j,render:({field:Ce,fieldState:Re})=>{var Oe;return l.jsx(pd,{label:Y(L.label),placeholder:Y(L.placeholder),size:L.size,disabled:oe||M,value:Ce.value??"",onChange:Ce.onChange,onBlur:Ce.onBlur,hasError:!!Re.error,errorMessage:gt(v,(Oe=Re.error)==null?void 0:Oe.message),name:z})}},z);default:return l.jsx(di,{...$e,type:L.type,loadingDefaults:B,hasError:!!_[z],errorMessage:gt(v,(ze=_[z])==null?void 0:ze.message),suffixButton:be,name:z},z)}},[o,O,j,_,M,B,V,ee,W,ae,w.getValues,w.watch,b,v]);return l.jsx(xc,{...w,children:l.jsxs("form",{noValidate:!0,onSubmit:S(async P=>{await re(P,void 0,"onSubmit"),!(Object.keys(w.formState.errors).length>0)&&(await i(P),m(c??v("ds.form.saveSuccess"),"success"))},P=>{aI(P),m(d??v("ds.form.saveError"),"error")}),className:"space-y-6",children:[a.map((P,$)=>P.type==="rows"?l.jsx(C.Fragment,{children:P.sections.map((L,Z)=>l.jsx("div",{children:l.jsx(lt,{title:Y(L.sectionTitle),defaultOpen:L.defaultOpen,children:L.rows.map((z,J)=>l.jsxs("div",{children:[z.title&&l.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:Y(z.title)}),l.jsx("div",{className:"flex flex-wrap -mx-2",children:z.columns.map((te,oe)=>{var ce;return l.jsx("div",{className:`${te.width} px-2 flex flex-col`,children:l.jsx("div",{className:"",children:te.fields?te.fields.map(ve=>T(ve)):(ce=te.rows)==null?void 0:ce.map((ve,ke)=>l.jsx("div",{className:"mb-1",children:l.jsx("div",{className:"flex flex-wrap -mx-2",children:ve.columns.map((be,Se)=>{var Me;return l.jsx("div",{className:`${be.width} px-2`,children:(Me=be.fields)==null?void 0:Me.map(Ae=>T(Ae))},Se)})})},ke))})},oe)})})]},J))})},Z))},$):l.jsx(zr,{options:P.tabs.map(L=>{const Z=L.icon?Ma(L.icon.name,L.icon.style):null;return{label:Y(L.label),value:L.key,disabled:L.disabled,icon:Z?l.jsx(Z,{className:"w-4 h-4"}):null}}),value:Q[$],onChange:L=>pe(Z=>({...Z,[$]:L})),children:Object.fromEntries(P.tabs.map(L=>[L.key,l.jsx("div",{className:"space-y-6",children:L.sections.map((Z,z)=>l.jsx("div",{className:"mb-6",children:l.jsx(lt,{title:Y(Z.sectionTitle),defaultOpen:Z.defaultOpen,children:Z.rows.map((J,te)=>l.jsx("div",{children:l.jsx("div",{className:"flex flex-wrap -mx-2",children:J.columns.map((oe,ce)=>{var ve;return l.jsx("div",{className:`${oe.width??"flex-1"} px-2 flex flex-col`,children:l.jsx("div",{className:"space-y-4",children:(ve=oe.fields)==null?void 0:ve.map((ke,be)=>l.jsx(C.Fragment,{children:T(ke)},be))})},ce)})})},te))})},z))},L.key)]))},$)),l.jsx("footer",{className:"py-4 w-full flex justify-center space-x-4",children:u??l.jsx(me,{type:"submit",variant:"primary",icon:Ln,size:"sm",disabled:M||B||F>0,children:v(M?"ds.form.sending":"ds.form.submit")})})]})})}function ef({dark:e,onToggle:t}){return l.jsx("button",{type:"button","aria-pressed":e,"aria-label":e?"Cambiar a modo claro":"Cambiar a modo oscuro",onClick:t,className:we("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:l.jsxs("div",{className:we("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:[l.jsx(_t,{component:uc,size:"sm",className:we("absolute transition-opacity duration-200 ease-in-out",e?"opacity-0":"opacity-100 text-[var(--color-ds-background-accent)]")}),l.jsx(_t,{component:oc,size:"sm",className:we("absolute transition-opacity duration-200 ease-in-out",e?"opacity-100 text-[var(--color-ds-background-accent)]":"opacity-0")})]})})}const tf="licytal:ui:theme",rf=C.createContext({theme:"light",dark:!1,toggle:()=>{}});function LI({children:e}){const[t,r]=C.useState(!1),[n,a]=C.useState("light");C.useEffect(()=>{if(typeof window>"u")return;const i=localStorage.getItem(tf);i==="light"||i==="dark"?a(i):window.matchMedia("(prefers-color-scheme: dark)").matches&&a("dark"),r(!0)},[]),C.useEffect(()=>{t&&(document.documentElement.classList.toggle("dark",n==="dark"),localStorage.setItem(tf,n))},[n,t]);const o=()=>a(i=>i==="light"?"dark":"light");return t?l.jsx(rf.Provider,{value:{theme:n,dark:n==="dark",toggle:o},children:e}):null}const md=()=>C.useContext(rf),_o={locale:"licytal:ui:locale",theme:"licytal:ui:theme"},nf=({pinnedPages:e,onRemovePinned:t,onBack:r,dark:n,locale:a,languageOptions:o,onChangeLocale:i,profile:c="",profileOptions:d=[],onChangeProfile:u,logoSrc:f,logoAlt:h="Logo aplicación"})=>{e.slice(0,3);const{toggle:p}=md(),m=g=>{try{localStorage.setItem(_o.locale,g)}catch{}i==null||i(g)},v=()=>{const g=!n;try{localStorage.setItem(_o.theme,g?"dark":"light")}catch{}p()};return C.useEffect(()=>{try{const g=localStorage.getItem(_o.locale);g&&g!==a&&(i==null||i(g))}catch{}},[]),C.useEffect(()=>{if(a)try{localStorage.setItem(_o.locale,a)}catch{}},[a]),C.useEffect(()=>{try{const g=localStorage.getItem(_o.theme);if(!g)return;g==="dark"!==n&&p()}catch{}},[]),l.jsxs("header",{className:"flex items-center justify-between bg-[var(--color-ds-background-page)] py-2 px-4 min-h-[88px]",children:[l.jsx("div",{className:"flex items-center",children:f&&l.jsx("img",{src:f,alt:h,className:"h-24 w-auto object-contain"})}),l.jsxs("div",{className:"flex items-center space-x-2",children:[l.jsx(Je,{size:"sm",width:"auto",options:o,value:a,onChange:m,disableErrorPlaceholder:!0,label:"Idioma",labelHidden:!0}),!!d.length&&l.jsx(Je,{size:"sm",width:"auto",options:d,value:c,onChange:g=>u==null?void 0:u(g),disableErrorPlaceholder:!0,label:"Perfil",labelHidden:!0}),l.jsx(ef,{dark:n,onToggle:v})]})]})},TI={sm:"h-8 w-8",md:"h-10 w-10",lg:"h-12 w-12"};function Jt({icon:e,size:t="md",ariaLabel:r,disabled:n=!1,onClick:a,className:o,...i}){return l.jsx("button",{type:"button","aria-label":r,disabled:n,onClick:a,className:we("inline-flex items-center justify-center","rounded-full","bg-transparent","text-[var(--color-ds-text-primary)]","transition-transform","focus:outline-none",TI[t],n?"opacity-50 cursor-not-allowed":["hover:scale-110","hover:animate-pulse","hover:bg-[var(--color-ds-background-neutral-hover)]"],o),...i,children:l.jsx(e,{className:we(t==="sm"?"h-4 w-4":t==="md"?"h-5 w-5":"h-6 w-6")})})}const $I=({loading:e=!1,ariaLabel:t="Cargando..."})=>e?l.jsxs("div",{className:`\r
|
|
99
|
+
hover:bg-[var(--color-ds-background-surface)]`,onClick:()=>{const ye=String(he.value).trim();E(e,ye,{shouldDirty:!0,shouldValidate:!0}),I(he.label??ye),ee.current=!1,X.current=!1,B(!1)},children:he.label},String(he.value)))})]})}})}const Fo=(e,t)=>e[t],G2=e=>e instanceof Date?e.getTime():e;function DI(e,t,r){const n=G2(e),a=G2(t);return typeof n=="number"&&typeof a=="number"||typeof n=="string"&&typeof a=="string"?r==="gt"?n>a:r==="gte"?n>=a:r==="lt"?n<a:n<=a:!1}function Di(e,t){if(!e)return!1;switch(e.op){case"eq":return Fo(t,e.field)===e.value;case"neq":return Fo(t,e.field)!==e.value;case"in":return e.values.includes(Fo(t,e.field));case"notIn":return!e.values.includes(Fo(t,e.field));case"gt":case"gte":case"lt":case"lte":return DI(Fo(t,e.field),e.value,e.op);case"and":return e.rules.every(r=>Di(r,t));case"or":return e.rules.some(r=>Di(r,t));case"always":return!!e.value;default:return!1}}function hd(e){return!!e&&(typeof e=="function"||typeof e=="object")}function Ma(e,t){const r=t==="outline"?ba:Da,n=r==null?void 0:r[e];return hd(n)?n:null}const SI=Object.entries(ba).filter(([e,t])=>e.endsWith("Icon")&&hd(t)).map(([e,t])=>({name:e,Icon:t,style:"outline"})),AI=Object.entries(Da).filter(([e,t])=>e.endsWith("Icon")&&hd(t)).map(([e,t])=>({name:e,Icon:t,style:"solid"})),NI=dc||cc||(e=>l.jsx("svg",{...e})),Wn=({value:e,onChange:t,buttonLabel:r,disabled:n,className:a})=>{const[o,i]=C.useState(!1),[c,d]=C.useState(""),[u,f]=C.useState((e==null?void 0:e.style)??"outline"),h=e&&Ma(e.name,e.style)||NI,p=C.useCallback((v,g)=>{const b=Ma(v,g);t==null||t({name:v,style:g},b),i(!1)},[t]),m=C.useCallback(()=>{t==null||t(void 0,void 0),i(!1)},[t]);return l.jsxs(l.Fragment,{children:[l.jsx(me,{size:"sm",variant:"outline",shape:"circle",className:`rounded-full p-0 w-8 h-8 inline-flex items-center justify-center ${a??""}`,disabled:n,onClick:()=>i(!0),ariaLabel:"Elegir icono",title:r||"Elegir icono",children:l.jsx(h,{className:"h-4 w-4"})}),l.jsx(Bt,{isOpen:o,onClose:()=>i(!1),title:"Seleccionar icono",children:l.jsxs("div",{className:"space-y-3",children:[l.jsx(De,{labelHidden:!0,placeholder:"Buscar icono (p. ej. 'user', 'arrow', 'calendar'...)",value:c,onChange:v=>d(v.target.value)}),l.jsx(zr,{options:[{label:"Outline",value:"outline"},{label:"Solid",value:"solid"}],value:u,onChange:v=>f(v),children:{outline:l.jsx(K2,{items:SI,query:c,onPick:v=>p(v,"outline"),onClear:m}),solid:l.jsx(K2,{items:AI,query:c,onPick:v=>p(v,"solid"),onClear:m})}})]})})]})},K2=({items:e,query:t,onPick:r,onClear:n})=>{const a=C.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]),o=st;return l.jsx("div",{className:"custom-scroll max-h-[60vh] overflow-y-auto",children:l.jsxs("div",{className:"grid gap-2 grid-cols-3 sm:grid-cols-4 md:grid-cols-6",children:[l.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:[l.jsx("div",{className:"h-full w-full flex items-center justify-center",children:o?l.jsx(o,{className:"w-6 h-6"}):l.jsx("span",{className:"text-ds-lg",children:"×"})}),l.jsx("div",{className:"mt-1 text-center",children:l.jsx("span",{className:"block text-[11px] leading-tight text-[var(--color-ds-text-secondary)] truncate",children:"Ninguno"})})]}),(a.length===0?e:a).map(({name:i,Icon:c})=>l.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:[l.jsx("div",{className:"h-full w-full flex items-center justify-center",children:l.jsx(c,{className:"w-6 h-6 text-[var(--color-ds-text-primary)]"})}),l.jsx("div",{className:"mt-1 text-center",children:l.jsx("span",{className:"block text-[11px] leading-tight text-[var(--color-ds-text-secondary)] truncate",children:i.replace(/Icon$/,"")})})]},i))]})})};function gt(e,t,r=""){if(!t)return r;if(typeof t=="object"&&t!==null){if(t.type==="complex"){const a=[];return t.header&&a.push(`<strong>${t.header}</strong>`),t.template&&a.push(t.template),a.join("<br/>")||r}return r}return e(t,{defaultValue:t})}const FI=({schema:e,renderField:t})=>{var g,b,x;const{control:r}=gn(),{fields:n,append:a,remove:o}=KE({control:r,name:e.name}),{label:i,addLabel:c="Añadir",items:d,disabled:u,validation:f,className:h}=e,{formState:{errors:p}}=gn(),m=((b=(g=p[e.name])==null?void 0:g.root)==null?void 0:b.message)||((x=p[e.name])==null?void 0:x.message),v=typeof m=="string"?m:void 0;return l.jsxs("div",{className:we("space-y-3",h),children:[i&&l.jsx("div",{className:"flex items-center justify-between",children:l.jsx("label",{className:"block text-ds-sm font-medium text-[var(--color-ds-text-primary)]",children:i})}),l.jsx("div",{className:"space-y-4",children:n.map((w,y)=>{const E=`${e.name}.${y}`;return l.jsxs("div",{className:"relative rounded-lg border border-[var(--color-ds-border-default-50)] bg-[var(--color-ds-background-surface)] p-4 group",children:[!u&&l.jsx("div",{className:"absolute top-2 right-2",children:l.jsx(me,{size:"xs",variant:"ghost",className:"text-[var(--color-ds-text-error)] hover:bg-[var(--color-ds-background-error-hover)]",onClick:()=>o(y),title:"Eliminar fila",ariaLabel:"Eliminar fila",children:l.jsx(St,{className:"w-4 h-4"})})}),l.jsx("div",{className:"grid grid-cols-1 gap-4",children:d.map((k,j)=>l.jsx(C.Fragment,{children:t(k,E)},j))})]},w.id)})}),n.length===0&&l.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."}),v&&l.jsx("p",{className:"text-xs text-[var(--color-ds-text-error)]",children:v}),!u&&l.jsxs(me,{type:"button",variant:"outline",size:"sm",onClick:()=>{a({})},children:[l.jsx(hr,{className:"w-4 h-4 mr-1"}),c]})]})};function J2(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,24)}function _I(e){return e.replace(/(.{4})/g,"$1 ").trim()}function Si({label:e,labelHidden:t,placeholder:r="ES00 0000 0000 0000 0000 0000",size:n="sm",value:a,onChange:o,onBlur:i,disabled:c,required:d,reserveErrorSpace:u=!0,error:f,errorMessage:h,hasError:p,id:m,name:v,className:g,"aria-label":b}){const x=C.useMemo(()=>J2(a),[a]),w=C.useMemo(()=>_I(x),[x]),y=E=>{const k=J2(E.target.value);o(k)};return l.jsx(De,{id:m,name:v,label:e,labelHidden:t,placeholder:r,size:n,value:w,onChange:y,onBlur:i,disabled:c,required:d,hasError:p||!!f||!!h,errorMessage:h||f,reserveErrorSpace:u,prefixIcon:ql,className:g,"aria-label":b,inputMode:"text",autoComplete:"off",spellCheck:!1})}function Y2(e){return(e??"").toUpperCase().replace(/\s+/g,"").replace(/[^A-Z0-9]/g,"").slice(0,9)}function _ee(e){return e}function pd({label:e,labelHidden:t,placeholder:r="12345678A",size:n="sm",value:a,onChange:o,onBlur:i,disabled:c,required:d,reserveErrorSpace:u=!0,error:f,errorMessage:h,hasError:p,id:m,name:v,className:g,"aria-label":b}){const{t:x}=Nt(),w=C.useMemo(()=>Y2(a),[a]),y=C.useMemo(()=>w,[w]),E=k=>{const j=Y2(k.target.value);o(j)};return l.jsx(De,{id:m,name:v,label:e,labelHidden:t,placeholder:r,size:n,value:y,onChange:E,onBlur:i,disabled:c,required:d,hasError:p||!!f||!!h,errorMessage:h||f,prefixIcon:nc,className:g,"aria-label":b,inputMode:"text",autoComplete:"off",spellCheck:!1,reserveErrorSpace:u})}function X2(e){if(e){if(typeof e=="string")try{return JSON.parse(e)}catch{return}if(typeof e=="object")return e}}function MI(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 RI=e=>e.type!=="inputGroup"&&e.type!=="button";function OI(){try{return Zt()??void 0}catch{return}}function Kt(e){if(!e||typeof e!="object")return;const t=e.name,r=e.style;if(!(!t||!r))return Ma(t,r)||void 0}function Q2({schema:e,resolver:t,serviceRegistry:r,activeVariantId:n}){var U;const{layout:a,fields:o=[],onSubmit:i,successMessage:c,errorMessage:d,footerButtons:u,defaultValues:f,loadDefaultValues:h,validationSchema:p}=e,{show:m}=xn(),{t:v}=Nt(),g=OI(),b=r??((U=g==null?void 0:g.services)==null?void 0:U.registry)??void 0,x=C.useMemo(()=>{if(t)return t;try{const P=p??ld(e);return Xc(P)}catch{return}},[t,e,p]),w=Ic({resolver:x,mode:"onBlur",reValidateMode:"onChange",defaultValues:f??{}}),y=Hn(P=>P.setRuntimeState),E=Hn(P=>P.systemContext),k=Hn(P=>P.formValues);C.useEffect(()=>{y({isActive:!0});let P=!1;return(async()=>{const $=e.defaultSource,L=e.onloadEndpoint;let Z={};if(e.variables&&Array.isArray(e.variables)&&(e.variables.forEach(J=>{J.type==="constant"&&(Z[J.key]=J.value)}),e.variables.forEach(J=>{if(J.type==="computed"&&J.value)try{const te=new Function("ctx",`return (${J.value});`);Z[J.key]=te(Z)}catch(te){console.warn(`[FormRenderer] Error evaluating computed variable "${J.key}":`,te),Z[J.key]=null}})),$)try{const J=b==null?void 0:b[$];if(J){const te=typeof J=="function"?await J():J;te&&typeof te=="object"&&(Z={...Z,...te})}}catch{}y({systemContext:{...Z}});const z=[];if(L&&z.push(L),e.onloadEndpoints&&Array.isArray(e.onloadEndpoints)&&z.push(...e.onloadEndpoints),z.length>0){const J=async oe=>{if(!oe)return{};try{const ce=b==null?void 0:b[oe.key];if(!ce)return console.warn("[FormRenderer] Provider not found for key:",oe.key),{};const ve=Pr(oe.parameters,(()=>({})),{...Z,ACTIVE_VARIANT:e.activeVariantId});console.log(`[FormRenderer] Calling ${oe.key} with params:`,ve);const ke=await Promise.resolve(ce(ve,{getValues:(()=>({})),watch:(()=>{}),params:ve,...Z}));let be=ke;if(typeof ke=="string")try{be=JSON.parse(ke)}catch(Se){console.warn("[FormRenderer] Failed to parse onload response string",Se)}return be&&typeof be=="object"?be:(console.warn("[FormRenderer] OnLoad response is not an object:",be),{})}catch(ce){return console.error("Error in onloadEndpoint",ce),{}}};(await Promise.all(z.map(J))).forEach(oe=>{oe&&typeof oe=="object"&&(Z={...Z,...oe})}),P||y({systemContext:{...Z}})}if(!P&&Object.keys(Z).length>0){const J={...e.defaultValues??{}};Object.assign(J,Z);const te=e.fields.map(oe=>oe.name);Object.keys(Z).forEach(oe=>{const ce=oe.toLowerCase(),ve=te.find(ke=>ke.toLowerCase()===ce);ve&&(J[ve]===void 0||J[ve]==="")&&(J[ve]=Z[oe])}),w.reset(J)}})(),()=>{P=!0,y({isActive:!1,systemContext:{},formValues:{}})}},[e,b,w.reset]);const{control:j,reset:A,handleSubmit:S,formState:{errors:_,isSubmitting:M}}=w,[B,R]=C.useState(!1);C.useEffect(()=>{h&&(R(!0),h().then(P=>A(P)).finally(()=>R(!1)))},[h,A]);const I=C.useMemo(()=>(o??[]).filter(RI),[o]),{loadingCount:F,optionsMap:V}=U2(I),[ee,X]=C.useState({}),[ne,se]=C.useState(0);C.useEffect(()=>{let P;const $=w.watch(()=>{clearTimeout(P),P=setTimeout(()=>{se(L=>L+1)},500)});return()=>{$.unsubscribe(),clearTimeout(P)}},[w.watch]);const q=C.useRef(b);C.useEffect(()=>{q.current=b},[b]);const N=C.useRef({});C.useEffect(()=>{let P=!0;return(async()=>{const L=await Promise.all(I.filter(z=>z.type==="select"&&(z.optionSource||z.endpointConfig)).map(async z=>{var be;const J=z.name,te=ui(z.optionSource,z.endpointConfig);if(!te)return[J,[]];const oe=z.endpointConfig?Pr(z.endpointConfig.parameters,w.getValues,E):{...E,...w.getValues()},ce=X2(z.adapterCtx??z.optionAdapterCtx),ve=JSON.stringify({key:te,resolvedParams:oe,ctx:ce});N.current[J],N.current[J]=ve;const ke=(be=q.current)==null?void 0:be[te];if(typeof ke!="function")return[J,[]];try{const Se=await Promise.resolve(ke(oe,{getValues:w.getValues,watch:w.watch,ctx:ce,params:oe,...E})),Me=Array.isArray(Se)?Se:[];return[J,Me]}catch{return[J,[]]}}));if(!P)return;const Z={};for(const[z,J]of L)Z[z]=J;X(z=>Object.entries(Z).some(([te,oe])=>{const ce=z[te];return!ce||ce.length!==oe.length?!0:JSON.stringify(ce)!==JSON.stringify(oe)})?Z:z)})(),()=>{P=!1}},[ne,JSON.stringify(I.map(P=>({n:P.name,os:P.optionSource??null,ec:P.endpointConfig??null,ctx:P.adapterCtx??P.optionAdapterCtx??null}))),E]),C.useEffect(()=>{let P=!0;return(async()=>{for(const L of I){if(L.type!=="select")continue;const Z=L.name,z=L.defaultSource;if(!z)continue;const J=w.getValues(Z);if(!(J==null||(Array.isArray(J)?J.length===0:J==="")))continue;const oe=b==null?void 0:b[z];if(typeof oe=="function")try{const ce=X2(L.adapterCtx??L.optionAdapterCtx),ve=await Promise.resolve(oe("",{getValues:w.getValues,watch:w.watch,ctx:ce}));if(!P)return;const ke=MI(ve,!!L.multiple);w.setValue(Z,ke,{shouldDirty:!0,shouldTouch:!0})}catch{}}})(),()=>{P=!1}},[b,w.getValues,w.setValue,JSON.stringify(I.map(P=>({n:P.name,ds:P.defaultSource??null,mult:!!P.multiple})))]);const O=z2(o),ae=q2(o,j),G=C.useMemo(()=>{const P={};return a.forEach(($,L)=>{$.type==="tabs"&&(P[L]=$.tabs[0].key)}),P},[a]),[Q,pe]=C.useState(G),[le,ge]=C.useState({}),[ue,de]=C.useState({}),xe=C.useRef({}),he=C.useRef({}),ye=C.useMemo(()=>Array.isArray(e.reactiveCalculations)?e.reactiveCalculations:[],[e]);C.useEffect(()=>{if(!ye.length)return;const P=te=>{if(te==null||te==="")return 0;if(typeof te=="number")return Number.isFinite(te)?te:0;let oe=String(te).trim().replace(/€/g,"").replace(/%/g,"").replace(/\s/g,"");if(!oe)return 0;const ce=oe.includes(","),ve=oe.includes(".");if(ce&&ve){const be=oe.lastIndexOf(","),Se=oe.lastIndexOf(".");be>Se?oe=oe.replace(/\./g,"").replace(",","."):oe=oe.replace(/,/g,"")}else ce&&(oe=oe.replace(/\./g,"").replace(",","."));const ke=Number(oe);return Number.isFinite(ke)?ke:0},$=te=>Math.round((te+Number.EPSILON)*100)/100,L=te=>{var Me,Ae;const oe=te.type??te.formula??te.operation??te.calculation,ce=te.parameters??{};if(oe!=="importeConImpuestos")return;const ve=((Me=ce.importeSin)==null?void 0:Me.fieldRef)??te.importeSinField??"nImpSinImpuesto",ke=((Ae=ce.impuestos)==null?void 0:Ae.fieldRef)??te.impuestosField??"N_IMPUESTO",be=P(w.getValues(ve)),Se=P(w.getValues(ke));return!be&&!Se?"":$(be+be*Se/100)},Z=(te,oe)=>{if(te!=null)return typeof te!="object"?te:te[oe]??te.value??te.total??te.importeTotal??te.importeCon??te.iImporteCon},z=async te=>{const oe=te.targetField??te.target;if(oe)try{let ce=L(te);if(ce===void 0){const ke=te.endpoint??te.endpointConfig,be=(ke==null?void 0:ke.key)??te.endpointKey??te.key;if(!be)return;const Se=b==null?void 0:b[be];if(typeof Se!="function"){console.warn("[FormRenderer] Reactive calculation provider not found:",be);return}const Me=ke!=null&&ke.parameters?Pr(ke.parameters,w.getValues,E):w.getValues(),Ae=await Promise.resolve(Se(Me,{getValues:w.getValues,watch:w.watch,params:Me,...E}));ce=Z(Ae,oe)}if(ce===void 0)return;const ve=w.getValues(oe);if(String(ve??"")===String(ce??""))return;w.setValue(oe,ce,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!0})}catch(ce){console.error("[FormRenderer] Error executing reactive calculation:",ce)}},J=w.watch((te,{name:oe})=>{oe&&ye.forEach((ce,ve)=>{const ke=ce.targetField??ce.target,be=ce.triggerFields??ce.fields??[];if(oe===ke||Array.isArray(be)&&be.length>0&&!be.includes(oe))return;const Se=`${ke??"target"}_${ve}`;he.current[Se]&&clearTimeout(he.current[Se]),he.current[Se]=setTimeout(()=>z(ce),ce.debounceMs??250)})});return()=>{J.unsubscribe(),Object.values(he.current).forEach(te=>te&&clearTimeout(te)),he.current={}}},[w,b,E,ye]);const D=C.useCallback(async()=>{const P={},$=o.filter(Z=>{var J,te,oe;const z=Z;return((J=z.visibleWhen)==null?void 0:J.endpoint)||((te=z.disabledWhen)==null?void 0:te.endpoint)||((oe=z.clearWhen)==null?void 0:oe.endpoint)});if($.length===0)return;(await Promise.all($.map(async Z=>{const z=Z,J=z.name,te={};for(const oe of["visibleWhen","disabledWhen","clearWhen"]){const ce=z[oe];if(ce!=null&&ce.enabled&&ce.endpoint){const ve=ce.endpoint.key,ke=b==null?void 0:b[ve];if(typeof ke=="function")try{const be=Pr(ce.endpoint.parameters,w.getValues,E),Se=await Promise.resolve(ke(be,{getValues:w.getValues,watch:w.watch,params:be,...E}));te[oe]=typeof Se=="object"&&Se!==null?!!Se.ok:!!Se}catch(be){console.error(`Error evaluando regla backend para ${J}.${oe}:`,be),te[oe]=!1}}}return{fieldName:J,res:te}}))).forEach(({fieldName:Z,res:z})=>{Object.keys(z).length>0&&(P[Z]=z)}),ge(P)},[o,b,w,E]),K=C.useCallback(async P=>{var te;const $=P,L=$.name,Z=$.asyncValidation.endpoint,z=Z.key,J=b==null?void 0:b[z];if(typeof J=="function"){de(oe=>({...oe,[L]:{...oe[L],loading:!0}}));try{const oe=Pr(Z.parameters,w.getValues,E),ce=await Promise.resolve(J(oe,{getValues:w.getValues,watch:w.watch,params:oe,...E})),ve=typeof ce=="object"&&ce!==null?!!ce.ok:!!ce,ke=typeof ce=="object"&&ce!==null?ce.message:void 0;de(be=>({...be,[L]:{ok:ve,message:ke,loading:!1}})),ve?((te=w.formState.errors[L])==null?void 0:te.type)==="manual"&&w.clearErrors(L):w.setError(L,{type:"manual",message:ke||"Validación externa fallida"})}catch{de(ce=>({...ce,[L]:{ok:!1,message:"Error de conexión",loading:!1}}))}}},[b,w,E]),re=C.useCallback(async(P,$,L)=>{const Z=o.filter(z=>{var ce,ve;const J=z,te=(ce=J.asyncValidation)==null?void 0:ce.endpoint;if(!te)return!1;const oe=te.trigger||J.asyncValidation.trigger||"onBlur";if(L&&oe!==L&&!(oe==="auto"&&L==="onChange"))return!1;if($&&L!=="onSubmit"){const ke=J.name===$,be=Object.values(te.parameters||{}).some(Me=>Me.fieldRef===$),Se=(ve=te.triggerFields)==null?void 0:ve.includes($);if(!ke&&!be&&!Se)return!1}return!0});for(const z of Z){const J=z,te=J.name,oe=J.asyncValidation.endpoint;if(L==="onChange"&&oe.trigger==="debounced"){xe.current[te]&&clearTimeout(xe.current[te]),xe.current[te]=setTimeout(()=>K(z),oe.debounceMs||300);continue}await K(z)}},[o,K]);C.useEffect(()=>{D();const P=w.watch(($,{name:L})=>{D(),L&&re($,L,"onChange")});return()=>{P.unsubscribe(),Object.values(xe.current).forEach($=>$&&clearTimeout($))}},[D,re,w]);const W=C.useCallback((P,$,L,Z)=>{var J;if(!(P!=null&&P.enabled))return $;let z=!0;if(P.rule)try{const te={...w.getValues(),...E,ACTIVE_VARIANT:n};z=!!Di(P.rule,te)}catch{z=$}if(z&&L&&Z&&P.endpoint){const te=(J=le[L])==null?void 0:J[Z];if(te===void 0)return!1;z=te}return z},[w,le,n]),H=C.useMemo(()=>o.map(P=>P).filter(P=>{var $;return(($=P.clearWhen)==null?void 0:$.enabled)&&(P.clearWhen.rule||P.clearWhen.endpoint)}).map(P=>({name:P.name,container:P.clearWhen})),[o]);C.useEffect(()=>{if(!H.length)return;const P=L=>{H.forEach(({name:Z,container:z})=>{try{if(W(z,!1,Z,"clearWhen")){const te=z.clearTo??"";L[Z]!==te&&w.setValue(Z,te,{shouldDirty:!0,shouldValidate:!0})}}catch{}})};P(w.getValues());const $=w.watch(()=>P(w.getValues()));return()=>{var L;return(L=$==null?void 0:$.unsubscribe)==null?void 0:L.call($)}},[w,H,W]);const Y=C.useCallback(P=>{const $=gt(v,P);if(!$)return"";const L={...E,...k,sys:E,form:k};return cd($,L)},[v,E,k]),T=C.useCallback((P,$)=>{var Ge,pt,dt,ze;let L;if(typeof P=="string"){if(L=O[P],!L){const Ce=(o??[]).find(Re=>(Re==null?void 0:Re.name)===P);if(Ce)L=Ce;else return null}}else L=P;const Z=L.name,z=Z?$?`${$}.${Z}`:Z:void 0,J=L.visibleWhen;if(!W(J,!0,Z,"visibleWhen"))return null;let oe=!!L.disabled;const ce=L.disabledWhen,ve=W(ce,!1,Z,"disabledWhen");if(ce!=null&&ce.enabled&&(oe=ve),!(ce!=null&&ce.enabled)&&Z&&ae[Z]&&(oe=!0),L.type==="search"){const Ce=typeof L.searchFn=="function",Re=ui(L.searchSource,L.endpointConfig),Oe=async Ye=>{if(Ce)return L.searchFn(Ye,{getValues:w.getValues,watch:w.watch});if(Re){const We=L.endpointConfig?Pr(L.endpointConfig.parameters,w.getValues,E):{...E,...w.getValues()},nt=b==null?void 0:b[Re];if(typeof nt=="function")return await nt({q:Ye,...We},{getValues:w.getValues,watch:w.watch,params:We,...E});if(Array.isArray(nt))return nt}return[]},Ne={};L.searchMode&&(Ne.searchMode=L.searchMode),L.minChars&&(Ne.minChars=L.minChars),L.debounceMs&&(Ne.debounceMs=L.debounceMs),L.resolveByValue&&(Ne.resolveByValue=L.resolveByValue);const Be=Kt(L.labelIconLeft??L.labelPrefixIcon),He=Kt(L.labelIconRight??L.labelSuffixIcon),ut=Kt(L.prefixIcon),Ve=Kt(L.suffixIcon);return l.jsx(fd,{name:z,control:j,searchFn:Oe,label:Y(L.label),size:L.size,width:L.width,disabled:oe||M,labelPrefixIcon:Be,labelSuffixIcon:He,prefixIcon:ut,suffixIcon:Ve,...Ne},z)}if(L.type==="inputGroup"){const Ce=L,Re=(Ce.inputs??[]).map(Oe=>{var On,uo;const Ne=typeof Oe=="string"?O[Oe]??(o??[]).find(G0=>(G0==null?void 0:G0.name)===Oe):Oe;if(!Ne)return null;const Be=Ne.name,He=$?`${$}.${Be}`:Be,ut=Ne.disabledWhen;let Ve=!!Ne.disabled;const Ye=W(ut,!1,Be,"disabledWhen");ut!=null&&ut.enabled&&(Ve=Ye),!(ut!=null&&ut.enabled)&&ae[Be]&&(Ve=!0);const We=Kt(Ne.labelIconLeft??Ne.labelPrefixIcon),nt=Kt(Ne.labelIconRight??Ne.labelSuffixIcon),cn=Kt(Ne.prefixIcon),da=Kt(Ne.suffixIcon),Er={name:He,control:j,label:Y(Ne.label),size:Ne.size,width:Ne.width,placeholder:Y(Ne.placeholder),hasError:!!(_[He]||$&&((On=_[$])!=null&&On[Be])),errorMessage:gt(v,(uo=_[He])==null?void 0:uo.message),loading:B,disabled:Ve||M,suffixButton:Ne.suffixButton,reserveErrorSpace:!0,labelPrefixIcon:We,labelSuffixIcon:nt,prefixIcon:cn,suffixIcon:da};return Ne.type==="select"?{...Er,options:Ne.options??ee[Be]??V[Be]??[],loadOptions:Ne.options||Ne.optionSource?void 0:Ne.loadOptions}:{...Er,type:Ne.type}}).filter(Boolean);return l.jsx(dd,{groupLabel:gt(v,Ce.groupLabel),inputs:Re,separator:Ce.separator,useSeparator:Ce.useSeparator,className:Ce.className,showVisibleLabel:Ce.showVisibleLabel,size:Ce.size},`inputGroup_${z??Ce.groupLabel??"group"}`)}if(L.type==="button"){const Ce=L,Re=Ce.icon,Oe=Re&&typeof Re=="object"&&Re.name&&Re.style?Kt(Re):void 0;return l.jsx("div",{className:"self-center",children:l.jsx(me,{type:"button",variant:Ce.variant,size:Ce.size,width:Ce.width,icon:Oe,iconPosition:Ce.iconPosition,ariaLabel:Y(Ce.ariaLabel),onClick:Ce.onClick,disabled:oe||M,children:Y(Ce.label)})},z??Ce.label)}if(L.type==="array"){const Ce=L;return l.jsx(FI,{schema:{...Ce,name:z},renderField:T},z)}const ke=L.suffixButton,be=typeof ke=="string"?T(ke):ke,Se=Kt(L.labelIconLeft??L.labelPrefixIcon),Me=Kt(L.labelIconRight??L.labelSuffixIcon),Ae=Kt(L.prefixIcon),Le=Kt(L.suffixIcon),$e={name:z,control:j,disabled:oe||M,readOnly:L.readOnly===!0,label:Y(L.label),size:L.size,width:L.width,placeholder:Y(L.placeholder),info:gt(v,L.info),suffixButton:be,labelPrefixIcon:Se,labelSuffixIcon:Me,prefixIcon:Ae,suffixIcon:Le,onBlur:()=>{re(w.getValues(),Z,"onBlur"),o.filter(Re=>{const Oe=Re;return["visibleWhen","disabledWhen","clearWhen"].some(Ne=>{var He;const Be=(He=Oe[Ne])==null?void 0:He.endpoint;return(Be==null?void 0:Be.trigger)==="onBlur"&&Object.values(Be.parameters||{}).some(ut=>ut.fieldRef===Z)})}).length>0&&D()}};switch(L.type){case"select":{const Ce=L.options??ee[Z]??V[Z]??[],Re=Array.isArray(Ce)&&Ce.length?`${Ce.length}:${Ce.map(Ne=>String((Ne==null?void 0:Ne.value)??"")).join("|")}`:"0",Oe=!L.options&&!L.optionSource&&L.loadOptions;return l.jsx(Ct,{name:z,control:j,render:({field:Ne})=>{var Be;return l.jsx(Je,{...$e,value:Ne.value,onChange:Ne.onChange,options:Ce,loadOptions:Oe||void 0,hasError:!!_[z],errorMessage:gt(v,(Be=_[z])==null?void 0:Be.message),suffixButton:be,mode:"menu",searchable:!0,searchPlaceholder:v("ds.fields.defaults.search.placeholder"),noOptionsText:v("ds.fields.defaults.search.noMatches")})}},`${z}:${Re}`)}case"textarea":return l.jsx(Ct,{name:z,control:j,render:({field:Ce,fieldState:Re})=>{var Oe;return l.jsx(Dr,{...$e,value:Ce.value,onChange:Ce.onChange,maxLength:L.maxLength,showCounter:!!L.showCounter,hasError:!!Re.error,errorMessage:gt(v,(Oe=Re.error)==null?void 0:Oe.message)})}},z);case"file":return l.jsx(Yc,{...$e,defaultValue:[],maxFiles:L.maxFiles,accept:L.accept,hideDropZone:L.hideDropZone,existingFiles:L.existingFiles,hasError:!!_[z],errorMessage:gt(v,(Ge=_[z])==null?void 0:Ge.message)},z);case"checkbox":return l.jsx(it,{...$e,defaultValue:!1,hasError:!!_[z],errorMessage:gt(v,(pt=_[z])==null?void 0:pt.message),name:z},z);case"date":return l.jsx(Sa,{...$e,defaultValue:"",showTime:!!L.showTime,hasError:!!_[z],errorMessage:gt(v,(dt=_[z])==null?void 0:dt.message)},z);case"optionGroup":return l.jsx(ji,{...$e,options:L.options||[],multiple:L.multiple,vertical:L.vertical,groupLabel:L.groupLabel,defaultValue:L.defaultValue,className:L.width?void 0:"w-full",name:z},z);case"iban":return l.jsx(Ct,{name:z,control:j,render:({field:Ce,fieldState:Re})=>{var Oe;return l.jsx(Si,{label:Y(L.label),placeholder:Y(L.placeholder),size:L.size,disabled:oe||M,value:Ce.value??"",onChange:Ce.onChange,onBlur:Ce.onBlur,hasError:!!Re.error,errorMessage:gt(v,(Oe=Re.error)==null?void 0:Oe.message),name:z})}},z);case"dni":return l.jsx(Ct,{name:z,control:j,render:({field:Ce,fieldState:Re})=>{var Oe;return l.jsx(pd,{label:Y(L.label),placeholder:Y(L.placeholder),size:L.size,disabled:oe||M,value:Ce.value??"",onChange:Ce.onChange,onBlur:Ce.onBlur,hasError:!!Re.error,errorMessage:gt(v,(Oe=Re.error)==null?void 0:Oe.message),name:z})}},z);default:return l.jsx(di,{...$e,type:L.type,loadingDefaults:B,hasError:!!_[z],errorMessage:gt(v,(ze=_[z])==null?void 0:ze.message),suffixButton:be,name:z},z)}},[o,O,j,_,M,B,V,ee,W,ae,w.getValues,w.watch,b,v]);return l.jsx(xc,{...w,children:l.jsxs("form",{noValidate:!0,onSubmit:S(async P=>{await re(P,void 0,"onSubmit"),!(Object.keys(w.formState.errors).length>0)&&(await i(P),m(c??v("ds.form.saveSuccess"),"success"))},P=>{aI(P),m(d??v("ds.form.saveError"),"error")}),className:"space-y-6",children:[a.map((P,$)=>P.type==="rows"?l.jsx(C.Fragment,{children:P.sections.map((L,Z)=>l.jsx("div",{children:l.jsx(lt,{title:Y(L.sectionTitle),defaultOpen:L.defaultOpen,children:L.rows.map((z,J)=>l.jsxs("div",{children:[z.title&&l.jsx("h2",{className:"mb-2 text-lg text-[var(--color-ds-text-primary)]",children:Y(z.title)}),l.jsx("div",{className:"flex flex-wrap -mx-2",children:z.columns.map((te,oe)=>{var ce;return l.jsx("div",{className:`${te.width} px-2 flex flex-col`,children:l.jsx("div",{className:"",children:te.fields?te.fields.map(ve=>T(ve)):(ce=te.rows)==null?void 0:ce.map((ve,ke)=>l.jsx("div",{className:"mb-1",children:l.jsx("div",{className:"flex flex-wrap -mx-2",children:ve.columns.map((be,Se)=>{var Me;return l.jsx("div",{className:`${be.width} px-2`,children:(Me=be.fields)==null?void 0:Me.map(Ae=>T(Ae))},Se)})})},ke))})},oe)})})]},J))})},Z))},$):l.jsx(zr,{options:P.tabs.map(L=>{const Z=L.icon?Ma(L.icon.name,L.icon.style):null;return{label:Y(L.label),value:L.key,disabled:L.disabled,icon:Z?l.jsx(Z,{className:"w-4 h-4"}):null}}),value:Q[$],onChange:L=>pe(Z=>({...Z,[$]:L})),children:Object.fromEntries(P.tabs.map(L=>[L.key,l.jsx("div",{className:"space-y-6",children:L.sections.map((Z,z)=>l.jsx("div",{className:"mb-6",children:l.jsx(lt,{title:Y(Z.sectionTitle),defaultOpen:Z.defaultOpen,children:Z.rows.map((J,te)=>l.jsx("div",{children:l.jsx("div",{className:"flex flex-wrap -mx-2",children:J.columns.map((oe,ce)=>{var ve;return l.jsx("div",{className:`${oe.width??"flex-1"} px-2 flex flex-col`,children:l.jsx("div",{className:"space-y-4",children:(ve=oe.fields)==null?void 0:ve.map((ke,be)=>l.jsx(C.Fragment,{children:T(ke)},be))})},ce)})})},te))})},z))},L.key)]))},$)),l.jsx("footer",{className:"py-4 w-full flex justify-center space-x-4",children:u??l.jsx(me,{type:"submit",variant:"primary",icon:Ln,size:"sm",disabled:M||B||F>0,children:v(M?"ds.form.sending":"ds.form.submit")})})]})})}function ef({dark:e,onToggle:t}){return l.jsx("button",{type:"button","aria-pressed":e,"aria-label":e?"Cambiar a modo claro":"Cambiar a modo oscuro",onClick:t,className:we("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:l.jsxs("div",{className:we("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:[l.jsx(_t,{component:uc,size:"sm",className:we("absolute transition-opacity duration-200 ease-in-out",e?"opacity-0":"opacity-100 text-[var(--color-ds-background-accent)]")}),l.jsx(_t,{component:oc,size:"sm",className:we("absolute transition-opacity duration-200 ease-in-out",e?"opacity-100 text-[var(--color-ds-background-accent)]":"opacity-0")})]})})}const tf="licytal:ui:theme",rf=C.createContext({theme:"light",dark:!1,toggle:()=>{}});function LI({children:e}){const[t,r]=C.useState(!1),[n,a]=C.useState("light");C.useEffect(()=>{if(typeof window>"u")return;const i=localStorage.getItem(tf);i==="light"||i==="dark"?a(i):window.matchMedia("(prefers-color-scheme: dark)").matches&&a("dark"),r(!0)},[]),C.useEffect(()=>{t&&(document.documentElement.classList.toggle("dark",n==="dark"),localStorage.setItem(tf,n))},[n,t]);const o=()=>a(i=>i==="light"?"dark":"light");return t?l.jsx(rf.Provider,{value:{theme:n,dark:n==="dark",toggle:o},children:e}):null}const md=()=>C.useContext(rf),_o={locale:"licytal:ui:locale",theme:"licytal:ui:theme"},nf=({pinnedPages:e,onRemovePinned:t,onBack:r,dark:n,locale:a,languageOptions:o,onChangeLocale:i,profile:c="",profileOptions:d=[],onChangeProfile:u,logoSrc:f,logoAlt:h="Logo aplicación"})=>{e.slice(0,3);const{toggle:p}=md(),m=g=>{try{localStorage.setItem(_o.locale,g)}catch{}i==null||i(g)},v=()=>{const g=!n;try{localStorage.setItem(_o.theme,g?"dark":"light")}catch{}p()};return C.useEffect(()=>{try{const g=localStorage.getItem(_o.locale);g&&g!==a&&(i==null||i(g))}catch{}},[]),C.useEffect(()=>{if(a)try{localStorage.setItem(_o.locale,a)}catch{}},[a]),C.useEffect(()=>{try{const g=localStorage.getItem(_o.theme);if(!g)return;g==="dark"!==n&&p()}catch{}},[]),l.jsxs("header",{className:"flex items-center justify-between bg-[var(--color-ds-background-page)] py-2 px-4 min-h-[88px]",children:[l.jsx("div",{className:"flex items-center",children:f&&l.jsx("img",{src:f,alt:h,className:"h-24 w-auto object-contain"})}),l.jsxs("div",{className:"flex items-center space-x-2",children:[l.jsx(Je,{size:"sm",width:"auto",options:o,value:a,onChange:m,disableErrorPlaceholder:!0,label:"Idioma",labelHidden:!0}),!!d.length&&l.jsx(Je,{size:"sm",width:"auto",options:d,value:c,onChange:g=>u==null?void 0:u(g),disableErrorPlaceholder:!0,label:"Perfil",labelHidden:!0}),l.jsx(ef,{dark:n,onToggle:v})]})]})},TI={sm:"h-8 w-8",md:"h-10 w-10",lg:"h-12 w-12"};function Jt({icon:e,size:t="md",ariaLabel:r,disabled:n=!1,onClick:a,className:o,...i}){return l.jsx("button",{type:"button","aria-label":r,disabled:n,onClick:a,className:we("inline-flex items-center justify-center","rounded-full","bg-transparent","text-[var(--color-ds-text-primary)]","transition-transform","focus:outline-none",TI[t],n?"opacity-50 cursor-not-allowed":["hover:scale-110","hover:animate-pulse","hover:bg-[var(--color-ds-background-neutral-hover)]"],o),...i,children:l.jsx(e,{className:we(t==="sm"?"h-4 w-4":t==="md"?"h-5 w-5":"h-6 w-6")})})}const $I=({loading:e=!1,ariaLabel:t="Cargando..."})=>e?l.jsxs("div",{className:`\r
|
|
100
100
|
fixed inset-0\r
|
|
101
101
|
flex items-center justify-center\r
|
|
102
102
|
bg-[var(--color-ds-background-surface)]/90\r
|