/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../chunks/_rollupPluginBabelHelpers","../../core/Error","../../layers/support/lazyLayerLoader","../PortalItem","./layersLoader","./portalItemUtils","../../support/requestPresets"],(function(e,r,t,a,n,s,u,c){"use strict";function l(e){return!e.portalItem||e.portalItem instanceof n||(e={...e,portalItem:new n(e.portalItem)}),o(e.portalItem).then((r=>{const t={portalItem:e.portalItem,...r.properties};return new(0,r.constructor)(t)}))}function o(e){return e.load().then(i).then(y)}function i(e){switch(e.type){case"Map Service":return p(e);case"Feature Service":return m(e);case"Feature Collection":return f(e);case"Scene Service":return d(e);case"Image Service":return S(e);case"Stream Service":return I();case"Vector Tile Service":return h();case"KML":return g();case"WFS":return v();case"WMTS":return M();case"WMS":return T();case"Feed":return w();default:return Promise.reject(new t("portal:unknown-item-type","Unknown item type '${type}'",{type:e.type}))}}function y(e){return(0,a.layerLookupMap[e.className])().then((r=>({constructor:r,properties:e.properties})))}function p(e){return G(e).then((e=>e?{className:"TileLayer"}:{className:"MapImageLayer"}))}function m(e){return P(e).then((e=>{if("object"==typeof e){const r={};return null!=e.id&&(r.layerId=e.id),{className:"FeatureLayer",properties:r}}return{className:"GroupLayer"}}))}function d(e){return P(e).then((r=>{if("object"==typeof r){const t={};let a;if(null!=r.id?(t.layerId=r.id,a=`${e.url}/layers/${r.id}`):a=e.url,Array.isArray(e.typeKeywords)&&e.typeKeywords.length>0){const r={IntegratedMesh:"IntegratedMeshLayer","3DObject":"SceneLayer",Point:"SceneLayer",PointCloud:"PointCloudLayer",Building:"BuildingSceneLayer"};for(const t of Object.keys(r))if(e.typeKeywords.includes(t))return{className:r[t]}}return c.requestArcGISServiceJSON(a).then((e=>{let r="SceneLayer";const a={Point:"SceneLayer","3DObject":"SceneLayer",IntegratedMesh:"IntegratedMeshLayer",PointCloud:"PointCloudLayer",Building:"BuildingSceneLayer"};return e&&e.layerType&&a[e.layerType]&&(r=a[e.layerType]),{className:r,properties:t}}))}return!1===r?c.requestArcGISServiceJSON(e.url).then((e=>"Voxel"===(null==e?void 0:e.layerType)?{className:"VoxelLayer"}:{className:"GroupLayer"})):{className:"GroupLayer"}}))}function f(e){return L.apply(this,arguments)}function L(){return(L=r._asyncToGenerator((function*(e){yield e.load();if(u.hasTypeKeyword(e,"Map Notes"))return{className:"MapNotesLayer"};if(u.hasTypeKeyword(e,"Route Layer"))return{className:"RouteLayer"};const r=yield e.fetchData();return 1===s.getNumLayersAndTables(r)?{className:"FeatureLayer"}:{className:"GroupLayer"}}))).apply(this,arguments)}function S(e){return N.apply(this,arguments)}function N(){return(N=r._asyncToGenerator((function*(e){var r,t,a;yield e.load();const n=null!=(r=null==(t=e.typeKeywords)?void 0:t.map((e=>e.toLowerCase())))?r:[];if(n.includes("elevation 3d layer"))return{className:"ElevationLayer"};if(n.includes("tiled imagery"))return{className:"ImageryTileLayer"};const s=yield e.fetchData(),u=null==s?void 0:s.layerType;if("ArcGISTiledImageServiceLayer"===u)return{className:"ImageryTileLayer"};if("ArcGISImageServiceLayer"===u)return{className:"ImageryLayer"};return"map"===(null==(a=(yield c.requestArcGISServiceJSON(e.url)).cacheType)?void 0:a.toLowerCase())?{className:"ImageryTileLayer"}:{className:"ImageryLayer"}}))).apply(this,arguments)}function I(){return{className:"StreamLayer"}}function h(){return{className:"VectorTileLayer"}}function g(){return{className:"KMLLayer"}}function v(){return{className:"WFSLayer"}}function T(){return{className:"WMSLayer"}}function M(){return{className:"WMTSLayer"}}function w(){return{className:"StreamLayer"}}function G(e){return c.requestArcGISServiceJSON(e.url).then((e=>e.tileInfo))}function P(e){return!e.url||e.url.match(/\/\d+$/)?Promise.resolve({}):e.load().then((()=>e.fetchData())).then(function(){var t=r._asyncToGenerator((function*(r){if("Feature Service"===e.type)return b(r=yield s.preprocessFSItemData(r,e.url));return s.getNumLayersAndTables(r)>0?b(r):c.requestArcGISServiceJSON(e.url).then(b)}));return function(e){return t.apply(this,arguments)}}())}function b(e){return 1===s.getNumLayersAndTables(e)&&{id:s.getFirstLayerOrTableId(e)}}e.fromItem=l,e.selectLayerClassPath=i,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
