/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{replace as e}from"../../core/string.js";const n="__begin__",r="__end__",s=new RegExp(n,"ig"),t=new RegExp(r,"ig"),l=new RegExp("^"+n,"i"),o=new RegExp(r+"$","i"),i='"',a=i+" + ",c=" + "+i;function u(e){return e.replaceAll(new RegExp("\\[","g"),"{").replaceAll(new RegExp("\\]","g"),"}")}function p(e){return e.replaceAll(new RegExp("\\{","g"),"[").replaceAll(new RegExp("\\}","g"),"]")}function x(e){const n={expression:"",type:"none"};return e.labelExpressionInfo?e.labelExpressionInfo.value?(n.expression=e.labelExpressionInfo.value,n.type="conventional"):e.labelExpressionInfo.expression&&(n.expression=e.labelExpressionInfo.expression,n.type="arcade"):null!=e.labelExpression&&(n.expression=u(e.labelExpression),n.type="conventional"),n}function f(e){const n=x(e);if(!n)return null;switch(n.type){case"conventional":return E(n.expression);case"arcade":return n.expression}return null}function g(e){const n=x(e);if(!n)return null;switch(n.type){case"conventional":return $(n.expression);case"arcade":return R(n.expression)}return null}function E(u){let p;return u?(p=e(u,e=>n+'$feature["'+e+'"]'+r),p=l.test(p)?p.replace(l,""):i+p,p=o.test(p)?p.replace(o,""):p+i,p=p.replaceAll(s,a).replaceAll(t,c)):p='""',p}const w=/^\s*\{([^}]+)\}\s*$/i;function $(e){const n=e?.match(w);return n?.[1].trim()||null}const b=/^\s*(?:(?:\$feature\.(\w+))|(?:\$feature\[(["'])(.+)(\2)\]));?\s*$/i,m=/^\s*(?:(?:\$feature\.(\w+))|(?:\$feature\[(["'])(.+)(\2)\]));?\s*(?:DomainName\(\s*\$feature\s*,\s*(["'])(\1|\3)(\5)\s*\));?\s*$/i,y=/^\s*(?:DomainName\(\s*\$feature\s*,\s*(["'])(.+)(\1)\s*\));?\s*$/i;function R(e){if(!e)return null;let n=b.exec(e)||m.exec(e);return n?n[1]||n[3]:(n=y.exec(e),n?n[2]:null)}const _=Symbol("LabelClassInstance");function v(e){return null!=e&&"object"==typeof e&&_ in e}export{_ as LabelClassSymbol,E as convertTemplatedStringToArcade,x as getLabelExpression,f as getLabelExpressionArcade,g as getLabelExpressionSingleField,R as getSingleFieldArcadeExpression,$ as getSingleFieldTemplatedString,v as isLabelClass,u as sqlToTemplateString,p as templateStringToSql};
