1import{At as e,Ft as t,It as a,Lt as i,St as l}from"./B8XHxhss.js";import{vt as n}from"#entry";var s=(s,d={})=>{d={clone:!1,populate:!1,enrichMagicKeys:!1,setDefaultValues:!0,includeList:[],excludeList:[],fetchOptions:{dataAppendage:{},includeList:[],excludeList:[],useNativeFormDataOnPost:!1},...d||{}},(s=d.clone?JSON.parse(JSON.stringify(s||{})):{...s||{}}).title=s.title??"",s.method=s.method??"GET",s.endpointUrl=s.endpointUrl??"",s.fields=s.fields??[],s.labels=s.labels??{},c(s?.fields,d);const o={dataAppendage:{},includeList:[],excludeList:[],useNativeFormDataOnPost:!1,...d.fetchOptions||{}},u=i(s.endpointUrl);if(s={...s,get endpointUrl(){let e=u.value,t={};return d?.enrichMagicKeys&&"object"==typeof d.enrichMagicKeys&&(t=d.enrichMagicKeys,e&&Object.keys(t).forEach(a=>{e=e.replaceAll(`{${a}}`,t[a])})),e},set endpointUrl(e){u.value=e},get fieldByName(){return this.fields?.reduce((e,t)=>(e[t.name]=t,e),{})??{}},get fieldsByName(){return this.fields?.reduce((e,t)=>(e[t.name]=e[t.name]??[],e[t.name].push(t),e),{})??{}},get fieldByType(){return this.fields?.reduce((e,t)=>(e[t.type]=t,e),{})??{}},get fieldsByType(){return this.fields?.reduce((e,t)=>(e[t.type]=e[t.type]??[],e[t.type].push(t),e),{})??{}},async fetch(e=o){e={...o,...e||{}};const t={...e};delete t.dataAppendage,delete t.includeList,delete t.excludeList,delete t.useNativeFormDataOnPost;const a=new FormData;try{if(this.fields.filter(t=>t&&!e.excludeList?.includes?.(t.name)&&!["button","submit"].includes(t.type)).forEach(e=>{e.name&&a.set(e.name,e.value)}),e.includeList?.length)for(const[t]of a.entries())e.includeList?.includes?.(t)||a.delete(t);for(const t in e.dataAppendage)e.excludeList?.includes?.(t)||a.set(t,e.dataAppendage[t]);const i=e.useNativeFormDataOnPost&&["POST","PUT","PATCH"].includes(this.method?.toUpperCase?.())?a:Object.fromEntries(a.entries());if(["GET","DELETE"].includes(this.method?.toUpperCase?.())||!this.method){const e=new URL(this.endpointUrl,"https://example.com");return e.search=new URLSearchParams(i).toString(),await n(e.toString().startsWith("https://example.com")?e.toString().replace("https://example.com",""):e.toString(),{method:this.method||"GET",...t}).then(e=>e).finally(()=>{a.forEach((e,t)=>a.delete(t))})}return await n(this.endpointUrl,{method:this.method,body:i,...t}).then(e=>e).finally(()=>{a instanceof FormData&&a.forEach((e,t)=>a.delete(t))})}catch(i){throw a.forEach((e,t)=>a.delete(t)),i}}},d.includeList?.length)for(const e in s)d.includeList.includes(e)||delete s[e];d.excludeList?.forEach(e=>{delete s[e]});const r=a({});s.fields?.forEach(e=>{e.name&&(r[e.name]=e.value)}),Object.defineProperty(s,"fieldValues",{get(){return this.fields?.forEach(e=>{e.name&&(r[e.name]=e.value)}),r},set(e){"object"==typeof e&&null!==e&&this.fields?.forEach(t=>{t.name&&t.name in e&&(t.value=e[t.name],r[t.name]=e[t.name],t.items&&t.items.forEach(a=>{a.checked=a.value===e[t.name]||e[t.name]?.split(",").includes?.(a.value)}))})},enumerable:!0,configurable:!0});const h=l(r,e=>{s.fieldValues=e});return e()&&t(()=>{h()},!0),s};function c(e,t){let a={};t?.populate&&"object"==typeof t.populate&&(a=t.populate);let i={};t?.enrichMagicKeys&&"object"==typeof t.enrichMagicKeys&&(i=t.enrichMagicKeys),e?.forEach((e,l,n)=>{if(t?.setDefaultValues&&!("defaultValue"in e)&&(e.defaultValue="value"in e?e.value:e.items?.filter(e=>e.checked)?.map?.(e=>e.value)?.join?.(",")??e.items?.find(e=>!e.value)?.value),"checked"in e&&!("defaultChecked"in e)&&(e.defaultChecked=e.checked),!("value"in e)&&(e.value=e.defaultValue,e.items?.length)){const t=e.items.reduce((e,t)=>(t.checked&&e.push(t.value),e),[]);e.value=t.length?t.join(","):e.defaultValue}if(t?.populate&&Object.keys(a).length>0)for(const t in a)e?.name===t&&("checked"in e?"boolean"==typeof a[t]?e.checked=a[t]:e.value===a[t]?e.checked=!0:e.checked=!1:(e.value=a[t],e.items&&e.items.forEach(e=>{e.checked=e.value===a[t]})));if(t?.enrichMagicKeys&&Object.keys(i).length>0)for(const t in i)e?.value===`{${t}}`?(e.value=i[t],e.items&&e.items.forEach(a=>{a.checked=a.value===e.value[t]})):e?.value?.includes?.(`{${t}}`)&&(e.value=e.value.replaceAll(`{${t}}
1`,i[t]),e.items&&e.items.forEach(a=>{a.checked=a.value===e.value[t]}));"fields"in e&&c(e.fields,t)})}export{s as t};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.