import { cloneDeep as i, isEqual as c } from "lodash";
import { Color as h } from "three";
import { watch as n } from "vue";
import { createFloorRotateBorder as I } from "./utils/module/FloorRotateBorder.mjs";
import { createFloorGridRipple as b } from "./utils/module/FloorGridRipple.mjs";
import { createParticles as B } from "./utils/module/Particles.mjs";
import { createAmbientLight as x, createDirectionalLight as z, createPointLight1 as w, createPointLight2 as L, createEnvironment as P } from "./utils/module/Environment.mjs";
const R = (a, t, S, k, M) => {
  n(
    () => i(a.option.map.depth),
    (e, r) => {
      try {
        !c(e, r) && t.value && M();
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.scene.defaultMapAdcode),
    (e, r) => {
      try {
        !c(e, r) && t.value && M();
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.scene.translateX),
    (e, r) => {
      try {
        if (!c(e, r) && t.value) {
          const o = a.option.scene.translateX || 0, u = a.option.scene.translateY || 0, l = a.option.scene.translateZ || 0, m = a.option.camera.position.x + o, s = a.option.camera.position.y + u, d = a.option.camera.position.z + l;
          t.value.camera.instance.position.set(m, s, d);
          const g = a.option.camera.target;
          if (g) {
            const f = g[0] + o, v = g[1] + u, y = g[2] + l;
            t.value.camera.controls.target.set(f, v, y);
          }
        }
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.scene.translateY),
    (e, r) => {
      try {
        if (!c(e, r) && t.value) {
          const o = a.option.scene.translateX || 0, u = a.option.scene.translateY || 0, l = a.option.scene.translateZ || 0, m = a.option.camera.position.x + o, s = a.option.camera.position.y + u, d = a.option.camera.position.z + l;
          t.value.camera.instance.position.set(m, s, d);
          const g = a.option.camera.target;
          if (g) {
            const f = g[0] + o, v = g[1] + u, y = g[2] + l;
            t.value.camera.controls.target.set(f, v, y);
          }
        }
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.scene.translateZ),
    (e, r) => {
      try {
        if (!c(e, r) && t.value) {
          const o = a.option.scene.translateX || 0, u = a.option.scene.translateY || 0, l = a.option.scene.translateZ || 0, m = a.option.camera.position.x + o, s = a.option.camera.position.y + u, d = a.option.camera.position.z + l;
          t.value.camera.instance.position.set(m, s, d);
          const g = a.option.camera.target;
          if (g) {
            const f = g[0] + o, v = g[1] + u, y = g[2] + l;
            t.value.camera.controls.target.set(f, v, y);
          }
        }
      } catch {
      }
    },
    {
      deep: !0
    }
  ), a.option.orbitControls && n(
    () => i(a.option.orbitControls),
    (e, r) => {
      try {
        !c(e, r) && t.value && t.value.camera.setControls(e);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.scene.z),
    (e, r) => {
      try {
        !c(e, r) && t.value && (t.value.scene.position.z = e);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), a.option.map.backgroundImg && (n(
    () => i(a.option.map.backgroundImg.show),
    (e, r) => {
      try {
        !c(e, r) && t.value && t.value.createMapBackgroundImg(!1);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.map.backgroundImg.src),
    (e, r) => {
      try {
        !c(e, r) && t.value && t.value.mapBackgroundImgMaterial && t.value.createMapBackgroundImg(!1);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.map.backgroundImg.alphaMap),
    (e, r) => {
      try {
        !c(e, r) && t.value && t.value.mapBackgroundImgMaterial && t.value.createMapBackgroundImg(!1);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.map.backgroundImg.color),
    (e, r) => {
      try {
        !c(e, r) && t.value && t.value.mapBackgroundImgMaterial && (t.value.mapBackgroundImgMaterial.color = new h(e));
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.map.backgroundImg.opacity),
    (e, r) => {
      try {
        !c(e, r) && t.value && t.value.mapBackgroundImgMaterial && (t.value.mapBackgroundImgMaterial.opacity = e);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.map.backgroundImg.rotation),
    (e, r) => {
      try {
        !c(e, r) && t.value && t.value.mapBackgroundImgMesh && (t.value.mapBackgroundImgMesh.rotation.x = e[0] * (Math.PI / 180), t.value.mapBackgroundImgMesh.rotation.y = e[1] * (Math.PI / 180), t.value.mapBackgroundImgMesh.rotation.z = e[2] * (Math.PI / 180));
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.map.backgroundImg.position),
    (e, r) => {
      try {
        !c(e, r) && t.value && t.value.mapBackgroundImgMesh && (t.value.mapBackgroundImgMesh.position.x = e[0], t.value.mapBackgroundImgMesh.position.y = e[1], t.value.mapBackgroundImgMesh.position.z = e[2]);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.map.backgroundImg.scale),
    (e, r) => {
      try {
        !c(e, r) && t.value && t.value.mapBackgroundImgMesh && (t.value.mapBackgroundImgMesh.scale.x = e[0], t.value.mapBackgroundImgMesh.scale.y = e[1], t.value.mapBackgroundImgMesh.scale.z = e[2]);
      } catch {
      }
    },
    {
      deep: !0
    }
  )), n(
    () => i(a.option.scene.background),
    (e, r) => {
      try {
        !c(e, r) && t.value && (t.value.scene.background = new h(e));
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.scene.isBackground),
    (e, r) => {
      try {
        !c(e, r) && t.value && (e ? t.value.scene.background = new h(
          a.option.scene.background
        ) : t.value.scene.background = null);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.map.lineColor),
    (e, r) => {
      try {
        !c(e, r) && t.value && (t.value.provinceLineMaterial.color = new h(e));
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.map.mirrorShow),
    (e, r) => {
      try {
        !c(e, r) && t.value && (t.value.groundMirror.visible = e);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.map.arealabel),
    (e, r) => {
      try {
        !c(e, r) && t.value && t.value.setAreaLabelStyle(e);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.map.titleLabel),
    (e, r) => {
      try {
        !c(e, r) && t.value && t.value.setMapTitleLabelStyle(e);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.map.topMaterial),
    async (e, r) => {
      try {
        if (!c(e, r) && t.value) {
          let [o, u] = t.value.createProvinceMaterial(
            a.option.map.topMaterial,
            a.option.map.sideMaterial
          );
          t.value.areaMapTopMaterial = o, t.value.areaMapSideMaterial = u, t.value.provinceMesh.mapGroup.traverse((l) => {
            l.isMesh && (l.material[0] = o, l.material[1] = u);
          });
        }
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.map.sideMaterial),
    (e, r) => {
      try {
        if (!c(e, r) && t.value) {
          let [o, u] = t.value.createProvinceMaterial(
            a.option.map.topMaterial,
            a.option.map.sideMaterial
          );
          t.value.areaMapTopMaterial = o, t.value.areaMapSideMaterial = u, t.value.provinceMesh.mapGroup.traverse((l) => {
            l.isMesh && (l.material[0] = o, l.material[1] = u);
          });
        }
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.map.storkeAnimation),
    (e, r) => {
      try {
        !c(e, r) && t.value && t.value.createAreaMapStorke(e, !1);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.particle),
    (e, r) => {
      try {
        !c(e, r) && t.value && B(t.value, e);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.floor.gaoguang),
    (e, r) => {
      try {
        !c(e, r) && t.value && (t.value.gaoguangMesh.visible = e.show, t.value.gaoguangMesh.material.color = new h(e.color));
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.floor.quan),
    (e, r) => {
      try {
        !c(e, r) && t.value && (t.value.quan.visible = e.show, t.value.quan.material.color = new h(e.color));
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.floor.gridRipple),
    (e, r) => {
      try {
        !c(e, r) && t.value && b(t.value, e);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.floor.rotateBorder),
    (e, r) => {
      try {
        !c(e, r) && t.value && I(t.value, e, !1);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.light.ambientLight),
    (e, r) => {
      try {
        !c(e, r) && t.value && x(t.value, e);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.light.directionalLight),
    (e, r) => {
      try {
        !c(e, r) && t.value && z(t.value, e, a.option.debugger);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.light.pointLight1),
    (e, r) => {
      try {
        !c(e, r) && t.value && w(t.value, e, a.option.debugger);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.light.pointLight2),
    (e, r) => {
      try {
        !c(e, r) && t.value && L(t.value, e, a.option.debugger);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.debugger),
    (e, r) => {
      try {
        !c(e, r) && t.value && (P(
          t.value,
          a.option.light,
          a.option.debugger
        ), t.value.mapBoxHelper.visible = a.option.debugger, t.value.axesHelper.visible = a.option.debugger);
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.camera.position),
    (e, r) => {
      try {
        if (!c(e, r) && t.value) {
          const o = a.option.scene.translateX || 0, u = a.option.scene.translateY || 0, l = a.option.scene.translateZ || 0, m = a.option.camera.position.x + o, s = a.option.camera.position.y + u, d = a.option.camera.position.z + l;
          t.value.camera.instance.position.set(m, s, d);
        }
      } catch {
      }
    },
    {
      deep: !0
    }
  ), a.option.camera.target && n(
    () => i(a.option.camera.target),
    (e, r) => {
      try {
        if (!c(e, r) && t.value) {
          const o = a.option.scene.translateX || 0, u = a.option.scene.translateY || 0, l = a.option.scene.translateZ || 0, m = a.option.camera.target;
          if (m) {
            const s = m[0] + o, d = m[1] + u, g = m[2] + l;
            t.value.camera.controls.target.set(s, d, g);
          }
        }
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.widgets.filter((e) => e.type === "bar")),
    (e, r) => {
      try {
        !c(e, r) && t.value && e.length === r.length && e.forEach((o) => {
          t.value.createBar(o, void 0, !1);
        });
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.widgets.filter((e) => e.type === "scatter")),
    (e, r) => {
      try {
        !c(e, r) && t.value && e.length === r.length && e.forEach((o) => {
          t.value.createScatter(o, void 0, !1);
        });
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.option.widgets.filter((e) => e.type === "flyline")),
    (e, r) => {
      try {
        !c(e, r) && t.value && e.length === r.length && e.forEach((o) => {
          t.value.createFlyLine(o, void 0, !1);
        });
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(
      a.option.widgets.filter((e) => e.type === "regionalLevel")
    ),
    (e, r) => {
      try {
        !c(e, r) && t.value && e.length === r.length && e.forEach((o) => {
          t.value.createRegionalLevel(o, void 0, !1);
        });
      } catch {
      }
    },
    {
      deep: !0
    }
  ), n(
    () => i(a.sources),
    (e, r) => {
      try {
        !c(e, r) && t.value && k(!1);
      } catch {
      }
    },
    {
      deep: !0
    }
  );
};
export {
  R as initWatch
};
