/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as t}from"tslib";import{serializeInclusionDefinitionToEntitiesPbf as e,serializeInclusionDefinitionToRelationshipsPbf as r}from"../applications/KnowledgeStudio/resourceSerializationUtils.js";import{Clonable as i}from"../core/Clonable.js";import{MultiOriginJSONSupportMixin as o}from"../core/MultiOriginJSONSupport.js";import{join as s}from"../core/urlUtils.js";import{generateUUID as n}from"../core/uuid.js";import{property as a,subclass as l}from"../core/accessorSupport/decorators.js";import{nameToId as p}from"../core/accessorSupport/PropertyOrigin.js";import{getRelationshipEndNodeMap as u}from"../layers/knowledgeGraph/supportUtils.js";import{layoutTypes as c}from"./enums.js";import h from"./LayoutSettings.js";import d from"./NonspatialDataDisplay.js";import{areResourcesSafe as m}from"./utils.js";import{f as y,t as U}from"../chunks/persistableUrlUtils.js";import{reader as g}from"../core/accessorSupport/decorators/reader.js";import{writer as f}from"../core/accessorSupport/decorators/writer.js";let w=class extends(o(i)){constructor(t){super(t),this.aggregatedEntitiesUrl=null,this.aggregatedRelationshipsUrl=null,this.autoCollapseRelationships=!0,this.centralityIsUpToDate=!0,this.entitiesUrl=null,this.layoutSettings=null,this.layoutType="organic-standard",this.nonspatialDataDisplay=null,this.relationshipsUrl=null,this._entitiesResourceCreationDate=null,this._relationshipsResourceCreationDate=null}readEntitiesUrl(t,e,r){return y(t,r)}writeEntitiesUrl(t,e,r,i){e[r]="<pending>",i?.resources?.pendingOperations.push(new Promise((o,s)=>{this._writeResourceUrl(t,e,r,i,o,s)}))}readRelationshipsUrl(t,e,r){return y(t,r)}writeRelationshipsUrl(t,e,r,i){e[r]="<pending>",i?.resources?.pendingOperations.push(new Promise((o,s)=>{this._writeResourceUrl(t,e,r,i,o,s)}))}setCreationDatesForResources(t){if(this.entitiesUrl){const e=t.get(this.entitiesUrl);"number"==typeof e&&(this._entitiesResourceCreationDate=e)}if(this.relationshipsUrl){const e=t.get(this.relationshipsUrl);"number"==typeof e&&(this._relationshipsResourceCreationDate=e)}}async _writeResourceUrl(t,e,r,i,o,s){try{const n=i?.portalItem,a=i?.resources,l=p(i?.origin),u=i?.webmap?.activeLinkChartLayer,c="entitiesUrl"===r?this._entitiesResourceCreationDate:this._relationshipsResourceCreationDate,h=await m(t??"",n?.itemUrl??"","number"==typeof c?c:void 0);if(!n||!a||null==l||!u||!u.membershipModified&&n.id&&h)return t&&(e[r]=U(t,i)),void o();this._saveUrlAsNewResource(e,r,a,n,u,o,s)}catch(n){s(n)}}_saveUrlAsNewResource(t,e,r,i,o,s,n){const a=(o.knowledgeGraph.dataModel.relationshipTypes??[]).map(t=>t.name).reduce((t,e)=>{if(!e)return t;const{members:r}=o.dataManager.inclusionModeDefinition.namedTypeDefinitions.get(e)||{members:void 0};if(!r)return t;for(const[i]of r)t.push({id:i,typeName:e});return t},[]);u(a,o.knowledgeGraph).then(a=>{D(o.dataManager.inclusionModeDefinition,e,o.knowledgeGraph,a).then(o=>{const n=R(i,"entitiesUrl"===e?"entitiesUrl":"relationshipsUrl");t[e]=n.itemRelativeUrl,r.toAdd.push({resource:n,content:{type:"blob",blob:o},compress:!1,finish:t=>{"entitiesUrl"===e?this.entitiesUrl=t.url:this.relationshipsUrl=t.url}}),s()}).catch(t=>{n(t)})}).catch(t=>{n(t)})}};t([a({type:String,json:{write:!0}})],w.prototype,"aggregatedEntitiesUrl",void 0),t([a({type:String,json:{write:!0}})],w.prototype,"aggregatedRelationshipsUrl",void 0),t([a({type:Boolean,json:{write:!0}})],w.prototype,"autoCollapseRelationships",void 0),t([a({type:Boolean,json:{write:!0}})],w.prototype,"centralityIsUpToDate",void 0),t([a({type:String,json:{write:{ignoreOrigin:!0,writerEnsuresNonNull:!0}}})],w.prototype,"entitiesUrl",void 0),t([g("entitiesUrl")],w.prototype,"readEntitiesUrl",null),t([f("entitiesUrl")],w.prototype,"writeEntitiesUrl",null),t([a({type:h,json:{write:!0}})],w.prototype,"layoutSettings",void 0),t([a({type:c,json:{write:!0}})],w.prototype,"layoutType",void 0),t([a({type:d,json:{write:!0}})],w.prototype,"nonspatialDataDisplay",void 0),t([a({type:String,json:{write:{ignoreOrigin:!0,writerEnsuresNonNull:!0}}})],w.prototype,"relationshipsUrl",void 0),t([g("relationshipsUrl")],w.prototype,"readRelationshipsUrl",null),t([f("relationshipsUrl")],w.prototype,"writeRelationshipsUrl",null),w=t([l("esri.linkChart.LinkChartProperties")],w);const j=w;function R(t,e){const r=`${e}-${n()}.dat`,i=s("linkChart",r);return t.resourceFromPath(i)}async function D(t,i,o,s){let n;return n="entitiesUrl"===i?await e(t,o,s):await r(t,o,s),new Blob([n],{type:"application/x-protobuf"})}export{j as default};
