/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import{b as E}from"./EH5Y2TRK.js";import{k as x}from"./DVG3NA3H.js";import{f as V,s as k,t as F}from"./PGOMURMZ.js";var T=["date","datetime-local","month","number","range","time","week"],q=["email","password","search","tel","text","url"],w=["email","password","search","tel","text","textarea","url"];function g(a,e,i,s){let l=i.toLowerCase(),r=a[i];s&&r!=null?e.setAttribute(l,`${r}`):e.removeAttribute(l)}function N(a,e,i){i.type=a;let s=T.includes(a),l=e;g(l,i,"min",s),g(l,i,"max",s),g(l,i,"step",s);let r=w.includes(a),u=e;g(u,i,"minLength",r),g(u,i,"maxLength",r);let c=q.includes(a);g(u,i,"pattern",c)}function j(a){let e=a==="textarea"?"text":a;return T.includes(e)||q.includes(e)||w.includes(e)}var S=["text","email","search","hidden","tel","url"],L=Object.freeze({validity:{},validationMessage:""});function R({component:a,input:e,value:i}){if(!Array.isArray(i)){if(a&&e.type==="radio"){let r=a.elementInternals.form?.elements[a.name];if(r?.length>0){r=Array.from(r).filter(n=>n.tagName===a.el.tagName);let u=r.some(n=>n.required),c=r.some(n=>n.checked),m=r.filter(n=>n!==a.el),y=u&&!c;e.required=!!y;let v=b(e.validity),I=e.validationMessage;m?.length>0&&m.forEach(n=>{y!==n.validity?.valueMissing&&n.setValidity&&n.setValidity(v,I)})}}return C(e,i)?L:{validity:b(e.validity),validationMessage:e.validationMessage}}if(S.includes(e.type))return C(e,i.join(","))?L:{validity:b(e.validity),validationMessage:e.validationMessage};let s={},l=[];for(let r of i)C(e,r)||(Object.assign(s,b(e.validity)),e.validationMessage&&l.push(e.validationMessage));return{validity:s,validationMessage:l.join("; ")}}function C(a,e){if(a.type==="file"){a.value="";let i=!e||e instanceof FileList&&e.length===0;return!a.required||!i}return a.value=e==null?"":String(e),a.validity.valid}function b(a){let e={};for(let i in a)i!=="valid"&&a[i]&&(e[i]=!0);return e}var D=["calcite-input","calcite-input-number","calcite-input-text","calcite-text-area"];function O(a){return`${F(k(a))}${D.includes(a)?"Input":"Change"}`}function P(a){return"form"in a&&"name"in a&&x(a)}function U(a,{status:e,message:i,icon:s}){"status"in a&&(a.status=e),"validationIcon"in a&&typeof a.validationIcon!="string"&&(a.validationIcon=s),"validationMessage"in a&&!a.validationMessage&&(a.validationMessage=i)}function A(a,e){"status"in a&&(a.status="idle"),"validationIcon"in a&&(!a.validationIcon||a.validationIcon===!0)&&(a.validationIcon=!1),"validationMessage"in a&&a.validationMessage===e&&(a.validationMessage="")}function $(a,e){let{disabled:i,name:s,required:l}=a;e.disabled=i,e.name=s||"",e.required=!!l,M(a)?e.checked=a.checked:z(a,e)&&N(e.type,a,e)}function M(a){return"checked"in a}function z(a,e){return a&&j(e.type)}function G(a){let e=Array.from(a.elements);requestAnimationFrame(()=>{let i=e.filter(s=>s.matches("[status=invalid]")&&P(s));for(let s of i)if(s.validationMessage){s.setFocus();break}})}var K=a=>E((e,i)=>{let s="",l,r=null,u=a.inputType;u&&(l=document.createElement("input"));function c(t){if(t.defaultPrevented)return;t.preventDefault();let f=t.currentTarget;G(f)}function m(){"status"in e&&(e.status="idle"),"validationIcon"in e&&(e.validationIcon=!1),"validationMessage"in e&&(e.validationMessage=""),M(e)&&(e.checked=e.defaultChecked),e.value=e.defaultValue}e.listen("luminaFormResetCallback",()=>{m()}),e.listen("luminaFormAssociatedCallback",({detail:[t]})=>{t?t.addEventListener("invalid",c,{capture:!0}):r?.removeEventListener("invalid",c,{capture:!0}),r=t});function y(){let t=s||l?.validationMessage||"";U(e,{message:t,icon:!0,status:"invalid"}),e.el.dispatchEvent(new CustomEvent("calciteInvalid",{bubbles:!0,composed:!0}));let f=O(e.el.tagName.toLowerCase());e.listen(f,()=>{if(A(e,t),l?.type==="radio"){let d=e.elementInternals.form?.elements[e.name];if(d?.length>0){d=Array.from(d).filter(h=>h.tagName===e.el.tagName);let o=d.filter(h=>h!==e.el);o?.length>0&&o.forEach(h=>{A(h)})}}},{once:!0})}i.onConnected(()=>{e.el.addEventListener("invalid",y)}),i.onDisconnected(()=>{e.el.removeEventListener("invalid",y)}),i.onUpdate(t=>{e.hasUpdated||(e.defaultValue=e.value,M(e)&&(e.defaultChecked=e.checked)),(t.has("name")||t.has("value")||M(e)&&t.has("checked"))&&e.elementInternals.setFormValue(n()),e.hasUpdated&&v()}),i.onLoaded(()=>v());function v(){let{disabled:t,elementInternals:f}=e,d={},o="";t||(l&&(l.type=u,$(e,l),{validity:d,validationMessage:o}=R({component:e,input:l,value:I()})),s&&(d={...d,customError:!0},o=s)),f.setValidity(d,o),"validity"in e&&V(()=>{e.validity=f.validity})}function I(){return a.getValue?a.getValue():e.value}function n(){let t=I();if(Array.isArray(t)||t instanceof FileList){let f=new FormData;for(let d of t)f.append(e.name,d);return f}return M(e)?e.checked?t||"on":null:t}return{get active(){return!!e.elementInternals.form},overrideDefaultValue:t=>{e.defaultValue=t},overrideInputType:t=>{u=t,v()},requestSubmit:()=>{e.elementInternals.form?.requestSubmit()},setCustomValidity:t=>{s=t,v()}}});export{U as a,A as b,K as c};
