/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
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{convertPixelLocationToSphereVertex as a,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:r}=e,a=p(t),i=r?"symbol"in r?r.symbol:"defaultSymbol"in r?r.defaultSymbol:r.getSymbol():null,o=a(i?.color);n[`${t}Symbol`]=(t===e.geometryType?i:null)??o}function l(e,n,r){const a=e.fields.find(({name:e,alias:t,type:r})=>y(n?.length?n:o,e,t)&&"blob"===r),i=e.fields.find(({name:e,alias:t})=>y(r?.length?r:s,e,t));if(!a||!i)throw new t("orientedimageryviewer:invalid-data-capture-layer","Data capture layer is not configured correctly.",{layer:e,imageGeometryField:a,oiObjectIdField:i});return{imageGeometryField:a,oiObjectIdField:i}}function x(n,r,a,i,o,s,p,y){let c=u(n,r);if(!c)throw new t("orientedimageryviewer:invalid-geometry","InvalidGeometry");return c=d(c,s,o,y),new e({attributes:n,layer:a,symbol:m(c.type,a.geometryType,p),geometry:c,visible:a.visible&&i})}function u(e,t){const{geometry:n}=JSON.parse(atob(e[t]));return r(n)}function b(e,t,n,r){switch(t){case"default":return f(e);case"panoramic":return g(e,n,r)}}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,r){switch(e.type){case"point":{const{x:n,y:a}=i(e,...t,r);e.x=n,e.y=a,delete e.z;break}case"polyline":e.paths=e.paths.map(e=>e.map(e=>{const{x:n,y:a}=i({x:e[0],y:e[1],z:e[2]},...t,r);return[n,a]}));break;case"polygon":e.rings=e.rings.map(e=>e.map(e=>{const{x:n,y:a}=i({x:e[0],y:e[1],z:e[2]},...t,r);return[n,a]}));break;case"multipoint":e.points=e.points.map(e=>{const{x:n,y:a}=i({x:e[0],y:e[1],z:e[2]},...t,r);return[n,a]});break;case"extent":{const{xmin:a,xmax:i,ymin:o,ymax:s}=g(n.fromExtent(e),t,r).extent;e.xmax=i,e.xmin=a,e.ymax=s,e.ymin=o;break}}return e}function d(e,t,n,r){switch(t){case"default":return h(e);case"panoramic":return k(e,n,r)}}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,r){switch(e.type){case"point":{const[n,i,o]=a(e,...t,r);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]=a({x:e[0],y:e[1]},...t,r);return[n,i,o]}));break;case"polygon":e.rings=e.rings.map(e=>e.map(e=>{const[n,i,o]=a({x:e[0],y:e[1]},...t,r);return[n,i,o]}));break;case"multipoint":e.points=e.points.map(e=>{const[n,i,o]=a({x:e[0],y:e[1]},...t,r);return[n,i,o]});break;case"extent":{const{xmin:a,xmax:i,ymin:o,ymax:s}=k(n.fromExtent(e),t,r).extent;e.xmax=i,e.xmin=a,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};
