text: import{r as t,c as e,h as i,g as s}from"./p-87f0c668.js";import"./p-c06cc5e4.js";import{j as o}from"./p-5120ebde.js";import{T as n}from"./p-454c45f1.js";const r=class{constructor(i){t(this,i),this.getModelEvent=e(this,"getModelEvent",7),this.modelChanged=!1,this.chain="",this.ignoredNodeNames=["link","style","slot","#text","#comment","text","comment"],this.templateNodes=[],this.dataViewModel=null}prepareTemplate(){let t=Array.from(this.__host.childNodes).filter(t=>-1===this.ignoredNodeNames.indexOf(t.nodeName.toLowerCase())),e=t.filter(t=>!t.hasAttribute("slot")),i=t.find(t=>t.hasAttribute("slot")&&"no-data"===t.getAttribute("slot"));i&&(i.removeAttribute("slot"),this.emptyNode=i.cloneNode(!0)),this.__host.innerHTML="",e?e.forEach(t=>{this.templateNodes.push(t.cloneNode(!0))}):console.error("No template found!")}componentWillLoad(){if(this.__host.isConnected)return this.chain=this.dataViewModel,this.chain=o(this.chain),this.prepareTemplate(),new Promise(t=>{this.getModelEvent.emit({callback:(e,i)=>{e&&console.log(e),this.model=i,this.model.onChange(this.chain,()=>{this.modelChanged=!this.modelChanged}),t()}})})}render(){if(!this.__host.isConnected)return null;if(!this.templateNodes)return null;let t=this.model.getChainValue(this.chain);t||(t=[]);let e=[];for(let s=0;s<t.length;s++){let t=this.chain?`${this.chain}.${s}`:""+s;this.templateNodes.forEach(s=>{let o=s.cloneNode(!0);this.__processNode(o,t);let n=o.tagName.toLowerCase(),r={};o.getAttributeNames().forEach(t=>{r[t]=o.getAttribute(t)});let h=i(n,Object.assign({innerHTML:o.innerHTML},r));e.push(h)})}return 0===e.length&&this.emptyNode?i("div",{innerHTML:this.emptyNode.outerHTML}):e}__processNode(t,e){function i(i,s){let o=s.trim().split("@").pop(),n=e;e&&o.length>0&&(n=`${e}.${o}`),t.setAttribute(i,"@"+n)}let s=t.getAttribute("view-model");s&&i("view-model",s),Array.from(t.attributes).filter(t=>t.value.startsWith("@")&&"view-model"!==t.name).forEach(t=>{i(t.name,t.value)}),"psk-for-each"!==t.tagName.toLowerCase()&&Array.from(t.children).forEach(t=>{this.__processNode.call(this,t,e)})}get __host(){return s(this)}};!function(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,i,s);else for(var h=t.length-1;h>=0;h--)(o=t[h])&&(r=(n<3?o(r):n>3?o(e,i,r):o(e,i))||r);n>3&&r&&Object.defineProperty(e,i,r)}([n({description:["This property is the name of the model which will be used to generate the form. The model should be a JavaScript array.",'All the information about how to write a model, hot to use the two-way binding and how to use the model with this component cand be found in the documentation found at: <psk-link page="forms/using-forms">Using forms</psk-link>'],isMandatory:!0,propertyType:"string",specialNote:["If this property is not provided, nothing written inside the component's template will be displayed."]})],r.prototype,"dataViewModel",void 0);export{r as psk_for_each}