/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import e from"../../request.js";import r from"../../core/Error.js";import{join as t}from"../../core/urlUtils.js";import a from"../../editing/sharedTemplates/SharedTemplateMetadata.js";import{isEmptyValue as s}from"./utils.js";async function o({featureService:o,query:m,requestOptions:p={}}){if(s(m.layers)&&s(m.templateIds)&&(m.layers=o.layerInfos.map(e=>e.id),!m.layers.length))throw new r("query-shared-templates:invalid-parameters","Must supply a value for either the 'layers' or the 'templateIds' parameters");const i=t(o.url,"sharedTemplates","query"),n={f:"json",...p.query,...m};n.layers&&(n.layers=l(n.layers)),n.templateIds&&(n.templateIds=l(n.templateIds)),n.tags&&(n.tags=l(n.tags));const u={...p,responseType:"json",query:n};return(await e(i,u)).data.templates.map(e=>{const r=a.fromJSON(e);return r.featureService=o,r})}function l(e){return Array.isArray(e)?e.join(","):""}export{o as querySharedTemplates};
