/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import e from"../../Graphic.js";import t from"../../core/Error.js";import n from"../../geometry/Polygon.js";import{fromJSON as r}from"../../geometry/support/jsonUtils.js";import{or as o,convertPixelLocationToSphereVertex as a,convertSphereVertexToPixelLocation as i}from"../../layers/orientedImagery/transformations/utils.js";import{defaultImageGeometryField as s,defaultOIObjectIDField as m}from"./constants.js";import{dataCaptureFeatureSymbol as y,createGraphicSymbol as p}from"./symbols.js";function l(e,t,n){const r=e.toLowerCase(),a=t.toLowerCase()===r,i=n?.toLowerCase()===r;return o(a,i)}function c(e){return"point"===e||"polygon"===e||"polyline"===e}function u(e,t,n){return c(e.geometryType)&&2===e.fields.filter(({name:e,type:r,alias:o})=>l(n?.length?n:m,e,o)||l(t?.length?t:s,e,o)&&"blob"===r).length}function x(e){return"feature"===e.type&&f(e)}function f(e){return"point"===e.geometryType||"polygon"===e.geometryType||"polyline"===e.geometryType}function g(e,t,n){if(!e)return;const{renderer:r}=e,o=y(t),a=r?"symbol"in r?r.symbol:"defaultSymbol"in r?r.defaultSymbol:r.getSymbol():null,i=o(a?.color);n[`${t}Symbol`]=(t===e.geometryType?a:null)??i}function b(e,n,r){const o=e.fields.find(({name:e,alias:t,type:r})=>l(n?.length?n:s,e,t)&&"blob"===r),a=e.fields.find(({name:e,alias:t})=>l(r?.length?r:m,e,t));if(!o||!a)throw new t("orientedimageryviewer:invalid-data-capture-layer","Data capture layer is not configured correctly.",{layer:e,imageGeometryField:o,oiObjectIdField:a});return{imageGeometryField:o,oiObjectIdField:a}}function d(n,r,o,a,i,s,m){let y=h(n,r);if(!y)throw new t("orientedimageryviewer:invalid-geometry","InvalidGeometry");return y=v(y,s,i),new e({attributes:n,layer:o,symbol:p(y.type,o.geometryType,m),geometry:y,visible:o.visible&&a})}function h(e,t){const{geometry:n}=JSON.parse(atob(e[t]));return r(n)}function k(e,t,n){switch(t){case"default":return w(e);case"panoramic":return j(e,n)}}function w(e){switch(e.type){case"point":e.x+=.5,e.y=.5-e.y;break;case"polyline":e.paths=e.paths.map(e=>e.map(([e,t])=>[e+.5,.5-t]));break;case"polygon":e.rings=e.rings.map(e=>e.map(([e,t])=>[e+.5,.5-t]));break;case"multipoint":e.points=e.points.map(([e,t])=>[e+.5,.5-t]);break;case"extent":e.xmin+=.5,e.xmax+=.5,e.ymin=.5-e.ymin,e.ymax=.5-e.ymax}return e}function j(e,t){switch(e.type){case"point":{const{x:n,y:r}=i(e,t[0],t[1]);e.x=n,e.y=r,delete e.z;break}case"polyline":e.paths=e.paths.map(e=>e.map(e=>{const{x:n,y:r}=i({x:e[0],y:e[1],z:e[2]},t[0],t[1]);return[n,r]}));break;case"polygon":e.rings=e.rings.map(e=>e.map(e=>{const{x:n,y:r}=i({x:e[0],y:e[1],z:e[2]},t[0],t[1]);return[n,r]}));break;case"multipoint":e.points=e.points.map(e=>{const{x:n,y:r}=i({x:e[0],y:e[1],z:e[2]},t[0],t[1]);return[n,r]});break;case"extent":{const{xmin:r,xmax:o,ymin:a,ymax:i}=j(n.fromExtent(e),t).extent;e.xmax=o,e.xmin=r,e.ymax=i,e.ymin=a;break}}return e}function v(e,t,n){switch(t){case"default":return T(e);case"panoramic":return z(e,n)}}function T(e){switch(e.type){case"point":e.x-=.5,e.y=.5-e.y;break;case"polyline":e.paths=e.paths.map(e=>e.map(([e,t])=>[e-.5,.5-t]));break;case"polygon":e.rings=e.rings.map(e=>e.map(([e,t])=>[e-.5,.5-t]));break;case"multipoint":e.points=e.points.map(([e,t])=>[e-.5,.5-t]);break;case"extent":e.xmin-=.5,e.xmax-=.5,e.ymin=.5-e.ymin,e.ymax=.5-e.ymax}return e}function z(e,t){switch(e.type){case"point":{const[n,r,o]=a(e,t[0],t[1]);e.x=n,e.y=r,e.z=o;break}case"polyline":e.paths=e.paths.map(e=>e.map(e=>{const[n,r,o]=a({x:e[0],y:e[1]},t[0],t[1]);return[n,r,o]}));break;case"polygon":e.rings=e.rings.map(e=>e.map(e=>{const[n,r,o]=a({x:e[0],y:e[1]},t[0],t[1]);return[n,r,o]}));break;case"multipoint":e.points=e.points.map(e=>{const[n,r,o]=a({x:e[0],y:e[1]},t[0],t[1]);return[n,r,o]});break;case"extent":{const{xmin:r,xmax:o,ymin:a,ymax:i}=z(n.fromExtent(e),t).extent;e.xmax=o,e.xmin=r,e.ymax=i,e.ymin=a}}return e}export{g as configureSketchTool,d as constructGraphicFromImageGeometry,b as extractFieldsFromDataCaptureLayer,u as isValidDataCaptureLayer,x as isValidOverlayLayer,k as mapSpaceToImageSpace,w as mapSpaceToImageSpaceDefault,j as mapSpaceToImageSpacePanoramic,h as parseAndExtractField,v as pixelToMapSpace,T as pixelToMapSpaceDefault,z as pixelToMapSpacePanoramic,f as supportedDigitigedGeometryType};
