/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../core/maybe","../../core/sql","../../geometry/support/jsonUtils","../../geometry/support/scaleUtils","../../layers/support/floorFilterUtils","../../layers/support/sublayerUtils"],(function(e,t,r,n,i,l,s){"use strict";const o=e=>e.spatialReference.wkid||JSON.stringify(e.spatialReference);function a(e,r){const{dpi:i,gdbVersion:l,geometry:s,geometryPrecision:a,height:u,layerOption:f,mapExtent:p,maxAllowableOffset:c,returnFieldName:d,returnGeometry:m,returnUnformattedValues:g,returnZ:x,spatialReference:S,timeExtent:b,tolerance:E,width:O}=e.toJSON(),{dynamicLayers:h,layerDefs:N,layerIds:J}=y(e),v=r&&t.isSome(r.geometry)?r.geometry:null,R={geometryPrecision:a,maxAllowableOffset:c,returnFieldName:d,returnGeometry:m,returnUnformattedValues:g,returnZ:x,tolerance:E},I=v&&v.toJSON()||s;if(R.imageDisplay=`${O},${u},${i}`,l&&(R.gdbVersion=l),I&&(delete I.spatialReference,R.geometry=JSON.stringify(I),R.geometryType=n.getJsonType(I)),S?R.sr=S.wkid||JSON.stringify(S):I&&I.spatialReference?R.sr=o(I):p&&p.spatialReference&&(R.sr=o(p)),R.time=b?[b.start,b.end].join(","):null,p){const{xmin:e,ymin:t,xmax:r,ymax:n}=p;R.mapExtent=`${e},${t},${r},${n}`}return N&&(R.layerDefs=N),h&&!N&&(R.dynamicLayers=h),R.layers="popup"===f?"visible":f,J&&!h&&(R.layers+=`:${J.join(",")}`),R}function y(e){var r,n;const{mapExtent:o,floors:a,width:y,sublayers:f,layerIds:p,layerOption:c,gdbVersion:d}=e,m=null==f||null==(r=f.find((e=>null!=e.layer)))||null==(n=r.layer)?void 0:n.serviceSublayers,g="popup"===c,x={},S={extent:o,width:y,spatialReference:null==o?void 0:o.spatialReference},b=i.getScale(S),E=[],O=e=>{const t=0===b,r=0===e.minScale||b<=e.minScale,n=0===e.maxScale||b>=e.maxScale;if(e.visible&&(t||r&&n))if(e.sublayers)e.sublayers.forEach(O);else{if(!1===(null==p?void 0:p.includes(e.id))||g&&(!e.popupTemplate||!e.popupEnabled))return;E.unshift(e)}};if(null==f||f.forEach(O),f&&!E.length)x.layerIds=[];else{const e=s.isExportDynamic(E,m,d),r=E.map((e=>{const t=l.getLayerFloorFilterClause(a,e);return e.toExportImageJSON(t)}));if(e)x.dynamicLayers=JSON.stringify(r);else{if(f){let e=E.map((({id:e})=>e));p&&(e=e.filter((e=>p.includes(e)))),x.layerIds=e}else null!=p&&p.length&&(x.layerIds=p);const e=u(a,E);if(t.isSome(e)&&e.length){const t={};for(const r of e)r.definitionExpression&&(t[r.id]=r.definitionExpression);Object.keys(t).length&&(x.layerDefs=JSON.stringify(t))}}}return x}function u(e,t){const n=!(null==e||!e.length),i=t.filter((e=>null!=e.definitionExpression||n&&null!=e.floorInfo));return i.length?i.map((t=>{const n=l.getLayerFloorFilterClause(e,t),i=r.sqlAnd(n,t.definitionExpression);return{id:t.id,definitionExpression:i}})):null}e.identifyToIdentifyRESTParameters=a,e.toDynamicLayersJSON=y,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
