/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import e from"../../../Graphic.js";import t from"../../../core/Error.js";import n from"../../../geometry/Polygon.js";import{fromJSON as a}from"../../../geometry/support/jsonUtils.js";import{convertPixelLocationToSphereVertex as r,convertSphereVertexToPixelLocation as i}from"../../../layers/orientedImagery/transformations/utils.js";import{defaultImageGeometryField as o,defaultOIObjectIDField as s}from"../constants.js";import{createGraphicSymbol as m,dataCaptureFeatureSymbol as p}from"../symbols.js";import{checkNameOrAlias as y}from"./typeUtils.js";function c(e,t,n){if(!e)return;const{renderer:a}=e,r=p(t),i=a?"symbol"in a?a.symbol:"defaultSymbol"in a?a.defaultSymbol:a.getSymbol():null,o=r(i?.color);n[`${t}Symbol`]=(t===e.geometryType?i:null)??o}function l(e,n,a){const r=e.fields.find(({name:e,alias:t,type:a})=>y(n?.length?n:o,e,t)&&"blob"===a),i=e.fields.find(({name:e,alias:t})=>y(a?.length?a:s,e,t));if(!r||!i)throw new t("orientedimageryviewer:invalid-data-capture-layer","Data capture layer is not configured correctly.",{layer:e,imageGeometryField:r,oiObjectIdField:i});return{imageGeometryField:r,oiObjectIdField:i}}function x(n,a,r,i,o,s,p,y){let c=u(n,a);if(!c)throw new t("orientedimageryviewer:invalid-geometry","InvalidGeometry");return c=d(c,s,o,y),new e({attributes:n,layer:r,symbol:m(c.type,r.geometryType,p),geometry:c,visible:r.visible&&i})}function u(e,t){const{geometry:n}=JSON.parse(atob(e[t]));return a(n)}function b(e,t,n,a){switch(t){case"default":return f(e);case"panoramic":case"panoramic-video":return g(e,n,a)}}function f(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 g(e,t,a){switch(e.type){case"point":{const{x:n,y:r}=i(e,...t,a);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,a);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,a);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,a);return[n,r]});break;case"extent":{const{xmin:r,xmax:i,ymin:o,ymax:s}=g(n.fromExtent(e),t,a).extent;e.xmax=i,e.xmin=r,e.ymax=s,e.ymin=o;break}}return e}function d(e,t,n,a){switch(t){case"default":return h(e);case"panoramic":case"panoramic-video":return k(e,n,a)}}function h(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 k(e,t,a){switch(e.type){case"point":{const[n,i,o]=r(e,...t,a);e.x=n,e.y=i,e.z=o;break}case"polyline":e.paths=e.paths.map(e=>e.map(e=>{const[n,i,o]=r({x:e[0],y:e[1]},...t,a);return[n,i,o]}));break;case"polygon":e.rings=e.rings.map(e=>e.map(e=>{const[n,i,o]=r({x:e[0],y:e[1]},...t,a);return[n,i,o]}));break;case"multipoint":e.points=e.points.map(e=>{const[n,i,o]=r({x:e[0],y:e[1]},...t,a);return[n,i,o]});break;case"extent":{const{xmin:r,xmax:i,ymin:o,ymax:s}=k(n.fromExtent(e),t,a).extent;e.xmax=i,e.xmin=r,e.ymax=s,e.ymin=o}}return e}export{c as configureSketchTool,x as constructGraphicFromImageGeometry,l as extractFieldsFromDataCaptureLayer,b as mapSpaceToImageSpace,f as mapSpaceToImageSpaceDefault,g as mapSpaceToImageSpacePanoramic,u as parseAndExtractField,d as pixelToMapSpace,h as pixelToMapSpaceDefault,k as pixelToMapSpacePanoramic};
