/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
import{c as i,d as f}from"./WGO4EVOV.js";import{l as g}from"./N22MFQSQ.js";import{a as o}from"./KOIDWEP3.js";import{b as c}from"./LP2JYX4X.js";import{c as m,j as l,k as s,l as d,v as p}from"./AYSQIO6L.js";function P(e,t=""){return f(g(e),t,4)}function M(e,t){let r=e.filter(n=>!n.startsWith(`${i}|`));return r.push([i,t].join("|")),r}async function S(e,t){if(!e.slug)return[];let n={filter:`typekeywords:"${e.slug.startsWith(`${i}|`)?e.slug:[i,e.slug].join("|")}"`};return t.authentication?n.authentication=t.authentication:t.portal&&(n.portal=t.portal),e.exclude&&(n.q=`NOT id:${e.exclude}`),(await p(n)).results}function I(e,t,r=0){let n=r?[e.slug,r].join("-"):e.slug;return S({slug:n,exclude:e.existingId},t).then(a=>a.length?I(e,t,r+1):n).catch(a=>{throw Error(`Error in getUniqueSlug ${a}`)})}function U(e){let t=o(e.item);return t.text=JSON.stringify(e.data),t}function u(e){return e.params=Object.assign(Object.assign({},e.params),b(e.item)),e}function b(e){let t=JSON.parse(JSON.stringify(e));return t.data&&(typeof Blob<"u"&&e.data instanceof Blob||e.data.constructor.name==="ReadStream"?t.file=e.data:t.text=e.data,delete t.data),t}function x(...e){return l(u(e[0]))}function h(...e){return m(u(e[0]))}function y(e,t){return Promise.all([s(e,t),d(e,t)]).then(r=>({item:r[0],data:r[1]}))}async function D(e,t){let r=o(e.item);r.data=o(e.data),r.extent&&typeof r.extent!="string"&&(r.extent=c(r.extent));let n=await x(Object.assign({item:r},t));return y(n.id,t)}function Y(e,t){let r=o(e.item);r.data=o(e.data),r.extent&&typeof r.extent!="string"&&(r.extent=c(r.extent)),j(r)&&(t.params=Object.assign(Object.assign({},t.params),{clearEmptyFields:!0}));let n=Object.assign({item:r},t);return h(n).then(()=>r.data?y(r.id,t):s(r.id,t).then(a=>({item:a})))}function j(e){return["description","snippet","tags","categories","licenseInfo"].some(t=>{var r;return e[t]===""||((r=e[t])===null||r===void 0?void 0:r.length)===0})}export{U as a,x as b,h as c,P as d,M as e,I as f,y as g,D as h,Y as i};
