/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["require","exports","../../../chunks/_rollupPluginBabelHelpers","../../maybe","../../multiOriginJSONSupportUtils","../../urlUtils","../../uuid","../metadata","../PropertyOrigin","./property","../../../portal/support/resourceExtension","../../../chunks/persistableUrlUtils"],(function(e,t,r,o,n,i,s,u,l,c,a,p){"use strict";const f=e=>Object.freeze(Object.defineProperty({__proto__:null,default:e},Symbol.toStringTag,{value:"Module"}));function y(e){const t=o.isSome(e)&&e.origins?e.origins:[void 0];return(r,o)=>{const n=d(e,r,o);for(const e of t){const t=c.propertyJSONMeta(r,e,o);for(const e in n)t[e]=n[e]}}}function d(e,t,r){if(o.isSome(e)&&"resource"===e.type)return g(e,t,r);switch(o.isSome(e)&&e.type?e.type:"other"){case"other":return{read:!0,write:!0};case"url":{const{read:e,write:t}=p.persistableUrlUtils;return{read:e,write:t}}}}function g(e,t,r){const s=u.getOwnPropertyMetadata(t,r);return{type:String,read:(e,t,r)=>{const o=p.read(e,t,r);return s.type===String?o:"function"==typeof s.type?new s.type({url:o}):void 0},write:{writer(t,u,c,a){if(!a||!a.resources)return"string"==typeof t?void(u[c]=p.toJSON(t,a)):void(u[c]=t.write({},a));const f=w(t),y=f?p.toJSON(f,{...a,verifyItemRelativeUrls:a&&a.verifyItemRelativeUrls?{writtenUrls:a.verifyItemRelativeUrls.writtenUrls,rootPath:null}:null},p.MarkKeep.NO):null,d=s.type!==String&&(!n.isMultiOriginJSONMixin(this)||a&&a.origin&&this.originIdOf(r)>l.nameToId(a.origin));a&&a.portalItem&&o.isSome(y)&&!i.isAbsolute(y)?d?h(this,r,t,y,u,c,a,e):S(y,u,c,a):a&&a.portalItem&&(o.isNone(y)||o.isSome(p.itemIdFromResourceUrl(y))||i.isBlobProtocol(y)||d)?m(this,r,t,y,u,c,a,e):u[c]=y}}}}function m(e,t,r,n,u,l,c,p){const f=s.generateUUID(),y=U(r,n,c),d=i.join(o.get(p,"prefix"),f),g=`${d}.${a.getResourceContentExtension(y)}`,m=c.portalItem.resourceFromPath(g);i.isBlobProtocol(n)&&c.resources.pendingOperations.push(b(n).then((e=>{m.path=`${d}.${a.getResourceContentExtension(e)}`,u[l]=m.itemRelativeUrl})).catch((()=>{}))),O(e,t,m,y,c.resources.toAdd),u[l]=m.itemRelativeUrl}function h(e,t,r,o,n,s,u,l){const c=u.portalItem.resourceFromPath(o),p=U(r,o,u);a.getResourceContentExtension(p)===i.getPathExtension(c.path)?(O(e,t,c,p,u.resources.toUpdate),n[s]=o):m(e,t,r,o,n,s,u,l)}function S(e,t,r,o){o.resources.toKeep.push({resource:o.portalItem.resourceFromPath(e)}),t[r]=e}function O(e,t,r,o,n){n.push({resource:r,content:o,finish:r=>{P(e,t,r)}})}function U(e,t,r){return"string"==typeof e?{url:t}:new Blob([JSON.stringify(e.toJSON(r))],{type:"application/json"})}function b(e){return v.apply(this,arguments)}function v(){return(v=r._asyncToGenerator((function*(t){const r=(yield new Promise(((t,r)=>e(["../../../request"],(e=>t(f(e))),r)))).default,{data:o}=yield r(t,{responseType:"blob"});return o}))).apply(this,arguments)}function w(e){return o.isNone(e)?null:"string"==typeof e?e:e.url}function P(e,t,r){"string"==typeof e[t]?e[t]=r.url:e[t].url=r.url}t.persistable=y,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
