"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports.default=createMappingParser;var _constant=require("../common/constant"),_util=require("../common/util"),_merge=_interopRequireDefault(require("lodash/merge"));function getType(a){let b;return b=a.IsDevice&&(0==a.Type||9999==a.Type)?_constant.ComponentType.iot:_constant.SpaceTypeMap[a.Type]||_constant.ComponentType.unknow,b}function createMappingParser(a,b="/",c=[]){function d(b){return"webgl"===a?[-(0,_util.toNumber)(null===b||void 0===b?void 0:b.X),(0,_util.toNumber)(null===b||void 0===b?void 0:b.Y),(0,_util.toNumber)(null===b||void 0===b?void 0:b.Z)]:[(0,_util.toNumber)(null===b||void 0===b?void 0:b.X),(0,_util.toNumber)(null===b||void 0===b?void 0:b.Y),(0,_util.toNumber)(null===b||void 0===b?void 0:b.Z)]}const e=a=>a?`${b}${a}`:a,f=(b,f,g={})=>{var h,i,j,k,l;let m=getType(f),n=f.GraphicUri;c.includes(m)&&n&&(n=n.replace(/graphic\.glb$/i,"graphic_merged.glb"));let o=(0,_merge.default)({modelId:f.GraphicId||f.Id,name:f.DeviceName||f.Name,realType:f.DeviceType,type:m,realId:f.DeviceId,children:[],parentId:b,url:e(n),mappingUrl:e(f.MetaUri),props:{type:f.Type,tags:f.Tags||[],position:d(f.GraphicPosition),rotation:d(f.GraphicRotation),scale:[(0,_util.toNumber)(null===(h=f.GraphicScale)||void 0===h?void 0:h.X,1),(0,_util.toNumber)(null===(i=f.GraphicScale)||void 0===i?void 0:i.Y,1),(0,_util.toNumber)(null===(j=f.GraphicScale)||void 0===j?void 0:j.Z,1)]},extension:{sync:!0,preload:!0,other:f.OtherData||{},geo:{longitude:null===(k=f.GeoLocation)||void 0===k?void 0:k.X,latitude:null===(l=f.GeoLocation)||void 0===l?void 0:l.Y}}},g);return"unity"===a&&(o.exists=!0),o},g=(a,b)=>{if(![1,2,3,4,5,9999].includes(a.Type))return h(a||[],b);const c=f(b,a,{extension:{sync:!1}});if(a.Children)for(const b of a.Children)c.children=c.children.concat(g(b,a.GraphicId));return c},h=(a,b)=>{const c=a.Children||[];let d=[];for(let e=0;e<c.length;e++){const b=c[e];d=d.concat(h(b,a.GraphicId))}let e=f(b,a);return e.children=d,e};return(a,b)=>{let c=g(a,b);return"building"==c.type&&(c.url=void 0),c}}