import{validation}from"../../Validation.js";import{text}from"../../forms/utils.js";import*as TemplateUtils from"../../TemplateUtils.js";class GetFormElementItemsFromCollection{_isLabelFieldName(e,t){return void 0!==(t&&0<t.length?t[0][e]:void 0)}_getTokenValues(e,t){const l={};for(const i of e){var o,a=i.token;l.hasOwnProperty(a)||(o=t[a],o=TemplateUtils.getTokenValueString(a,o),l[a]=text.escapeTextForMarkdown(o))}return l}execute(l,e){var o=l.labelFieldName||void 0,a=validation.array("collection",l.collection,validation.never);const i={};var r=this._isLabelFieldName(o,a),n=r?[]:TemplateUtils.findTokenInstances(o);for(let t=0;t<a.length;++t){var m,s=a[t];let e;e=r?s[l.labelFieldName]:o?(m=this._getTokenValues(n,s),TemplateUtils.replacePlaceholders(o,n,m)):s,void 0!==e&&null!==e||(e="");const c={};l.valueFieldName?c.value=s[l.valueFieldName]:c.value={refValueType:"data",type:"object",data:s},text.isMarkdown(e)?c.label=e:c.label=e.toString(),i[t]=c}return{items:i}}}GetFormElementItemsFromCollection.action="gcx:wf:forms::GetFormElementItemsFromCollection",GetFormElementItemsFromCollection.suite="gcx:wf:builtin";export{GetFormElementItemsFromCollection};