/* COPYRIGHT Esri - https://js.arcgis.com/5.0/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){let y=u(n,r);if(!y)throw new t("orientedimageryviewer:invalid-geometry","InvalidGeometry");return y=d(y,s,o),new e({attributes:n,layer:a,symbol:m(y.type,a.geometryType,p),geometry:y,visible:a.visible&&i})}function u(e,t){const{geometry:n}=JSON.parse(atob(e[t]));return r(n)}function b(e,t,n){switch(t){case"default":return f(e);case"panoramic":return g(e,n)}}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){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:a,ymin:i,ymax:o}=g(n.fromExtent(e),t).extent;e.xmax=a,e.xmin=r,e.ymax=o,e.ymin=i;break}}return e}function d(e,t,n){switch(t){case"default":return h(e);case"panoramic":return k(e,n)}}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){switch(e.type){case"point":{const[n,r,i]=a(e,t[0],t[1]);e.x=n,e.y=r,e.z=i;break}case"polyline":e.paths=e.paths.map(e=>e.map(e=>{const[n,r,i]=a({x:e[0],y:e[1]},t[0],t[1]);return[n,r,i]}));break;case"polygon":e.rings=e.rings.map(e=>e.map(e=>{const[n,r,i]=a({x:e[0],y:e[1]},t[0],t[1]);return[n,r,i]}));break;case"multipoint":e.points=e.points.map(e=>{const[n,r,i]=a({x:e[0],y:e[1]},t[0],t[1]);return[n,r,i]});break;case"extent":{const{xmin:r,xmax:a,ymin:i,ymax:o}=k(n.fromExtent(e),t).extent;e.xmax=a,e.xmin=r,e.ymax=o,e.ymin=i}}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};
