import{validation}from"../../Validation.js";import{text}from"../../forms/utils.js";import*as TemplateUtils from"../../TemplateUtils.js";class GetFormElementItemsFromFeatures{_getAttributeValue(t,e,a){let r=e[t];if(void 0!==r)return r;if(a&&0!==a.length){a=a.filter(e=>t===e.alias)[0];return r=a&&a.name?e[a.name]:r,r}}_isLabelFieldName(e,t,a){t=(0<t.length?t[0].attributes:{})||{};return void 0!==this._getAttributeValue(e,t,a)}_getTokenValues(e,t,a){const r={};for(const s of e){var l,i=s.token;r.hasOwnProperty(i)||(l=this._getAttributeValue(i,t,a),l=TemplateUtils.getTokenValueString(i,l),r[i]=text.escapeTextForMarkdown(l))}return r}execute(e){var r=e.features||[],l=e.fields||[],i=e.labelFieldName||void 0;validation.string("labelFieldName",i);var s=e.valueFieldName||void 0;const o={};var m=this._isLabelFieldName(i,r,l),n=m?[]:TemplateUtils.findTokenInstances(i);for(let a=0;a<r.length;++a){var u,F=r[a],d=F.attributes||{};const f={};let e;e=m?this._getAttributeValue(i,d,l):(u=this._getTokenValues(n,d,l),TemplateUtils.replacePlaceholders(i,n,u));d=this._getAttributeValue(s,d,l);let t;t=text.isMarkdown(e)?e:String(e),f.label=t,f.value=d,f.value||(f.value={refValueType:"data",type:"feature",data:F}),f.index=a,o[a]=f}return{items:o}}}GetFormElementItemsFromFeatures.action="gcx:wf:forms::GetFormElementItemsFromFeatures",GetFormElementItemsFromFeatures.suite="gcx:wf:builtin";export{GetFormElementItemsFromFeatures};