import { j as t, e as z } from "./externalizeComponent-Dc3fViZA.js";
import * as x from "three";
import { Matrix4 as w, Vector3 as T, Quaternion as U } from "three";
import { ConvexGeometry as te } from "three-stdlib";
import { useThree as ne, useFrame as re, Canvas as N } from "@react-three/fiber";
import { Environment as we, Lightformer as V, Line as O, useGLTF as be, Bounds as Y } from "@react-three/drei";
import { useTheme as Re, Card as ve, Box as b, Typography as q, Divider as X, Button as K } from "@mui/material";
import { observer as Me } from "mobx-react-lite";
import _e, { useRef as R, useEffect as L, useCallback as _, useState as G, Suspense as oe } from "react";
import { useTranslation as Le } from "react-i18next";
import { N as Te, V as se, c as ie, b as Z, M as v } from "./interpolation-baUmFLkh.js";
import { ErrorBoundary as ae } from "react-error-boundary";
function Ve(e) {
  switch (e.shape_type) {
    case "convex_hull":
      return new te(
        e.vertices.map(
          (n) => new x.Vector3(
            n[0] / 1e3,
            n[1] / 1e3,
            n[2] / 1e3
          )
        )
      );
    case "box":
      return new x.BoxGeometry(
        e.size_x / 1e3,
        e.size_y / 1e3,
        e.size_z / 1e3
      );
    case "sphere":
      return new x.SphereGeometry(e.radius / 1e3);
    case "capsule":
      return new x.CapsuleGeometry(
        e.radius / 1e3,
        e.cylinder_height / 1e3
      );
    case "cylinder":
      return new x.CylinderGeometry(
        e.radius / 1e3,
        e.radius / 1e3,
        e.height / 1e3
      );
    case "rectangle":
      return new x.BoxGeometry(e.size_x / 1e3, e.size_y / 1e3, 0);
    default:
      return console.warn(`${e.shape_type} is not supported`), new x.BufferGeometry();
  }
}
function Ge({
  name: e,
  collider: r,
  children: n
}) {
  var u, a;
  const l = ((u = r.pose) == null ? void 0 : u.position) ?? [0, 0, 0], o = ((a = r.pose) == null ? void 0 : a.orientation) ?? [0, 0, 0];
  return r.margin && console.warn(`${e} margin is not supported`), /* @__PURE__ */ t.jsx(
    "mesh",
    {
      name: e,
      position: new x.Vector3(
        l[0],
        l[1],
        l[2]
      ).divideScalar(1e3),
      rotation: new x.Euler(o[0], o[1], o[2], "XYZ"),
      geometry: Ve(r.shape),
      children: n
    }
  );
}
function ke({
  name: e,
  colliders: r,
  meshChildrenProvider: n,
  ...l
}) {
  return /* @__PURE__ */ t.jsx("group", { name: e, ...l, children: Object.entries(r).map(([o, u]) => /* @__PURE__ */ t.jsx(
    Ge,
    {
      name: o,
      collider: u,
      children: n(o, u)
    },
    o
  )) });
}
function nt({
  scene: e,
  meshChildrenProvider: r
}) {
  const n = e.colliders;
  return /* @__PURE__ */ t.jsx("group", { children: n && /* @__PURE__ */ t.jsx(
    ke,
    {
      meshChildrenProvider: r,
      colliders: n
    }
  ) });
}
function Q() {
  return /* @__PURE__ */ t.jsx(we, { children: /* @__PURE__ */ t.jsx(Fe, {}) });
}
function Fe({ positions: e = [2, 0, 2, 0, 2, 0, 2, 0] }) {
  return /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
    /* @__PURE__ */ t.jsx(
      V,
      {
        intensity: 5,
        "rotation-x": Math.PI / 2,
        position: [0, 5, -9],
        scale: [10, 10, 1]
      }
    ),
    /* @__PURE__ */ t.jsx("group", { rotation: [0, 0.5, 0], children: /* @__PURE__ */ t.jsx("group", { children: e.map((r, n) => /* @__PURE__ */ t.jsx(
      V,
      {
        form: "circle",
        intensity: 5,
        rotation: [Math.PI / 2, 0, 0],
        position: [r, 4, n * 4],
        scale: [3, 1, 1]
      },
      n
    )) }) }),
    /* @__PURE__ */ t.jsx(
      V,
      {
        intensity: 40,
        "rotation-y": Math.PI / 2,
        position: [-5, 1, -1],
        scale: [20, 0.1, 1]
      }
    ),
    /* @__PURE__ */ t.jsx(
      V,
      {
        intensity: 20,
        "rotation-y": -Math.PI,
        position: [-5, -2, -1],
        scale: [20, 0.1, 1]
      }
    ),
    /* @__PURE__ */ t.jsx(
      V,
      {
        "rotation-y": Math.PI / 2,
        position: [-5, -1, -1],
        scale: [20, 0.5, 1],
        intensity: 5
      }
    ),
    /* @__PURE__ */ t.jsx(
      V,
      {
        "rotation-y": -Math.PI / 2,
        position: [10, 1, 0],
        scale: [20, 1, 1],
        intensity: 10
      }
    ),
    /* @__PURE__ */ t.jsx(
      V,
      {
        form: "ring",
        color: "white",
        intensity: 5,
        scale: 10,
        position: [-15, 4, -18],
        target: [0, 0, 0]
      }
    )
  ] });
}
function Ae(e) {
  if (e.length < 3)
    return console.log("Not enough vertices to define a plane"), { isCoplanar: !1 };
  const r = new x.Vector3(e[0].x, e[0].y, e[0].z), n = new x.Vector3(e[1].x, e[1].y, e[1].z), l = new x.Vector3(e[2].x, e[2].y, e[2].z), o = new x.Vector3().subVectors(n, r), u = new x.Vector3().subVectors(l, r), a = new x.Vector3().crossVectors(o, u).normalize();
  for (let f = 3; f < e.length; f++) {
    const c = new x.Vector3(e[f].x, e[f].y, e[f].z), m = new x.Vector3().subVectors(c, r), d = a.dot(m);
    if (Math.abs(d) > 1e-6)
      return console.log("Vertices are not on the same plane"), { isCoplanar: !1 };
  }
  return { isCoplanar: !0, normal: a };
}
function rt({
  safetyZones: e,
  ...r
}) {
  return /* @__PURE__ */ t.jsx("group", { ...r, children: e.map((n, l) => {
    let o = [];
    return n.geometry && (n.geometry.compound ? o = n.geometry.compound.child_geometries : n.geometry.convex_hull && (o = [n.geometry])), o.map((u, a) => {
      if (!u.convex_hull) return null;
      const f = u.convex_hull.vertices.map(
        (d) => new x.Vector3(d.x / 1e3, d.y / 1e3, d.z / 1e3)
      ), c = Ae(f);
      if (c.isCoplanar && c.normal) {
        const s = new x.Vector3().addVectors(
          f[0],
          c.normal.multiplyScalar(1e-4)
        );
        f.push(s);
      }
      let m;
      try {
        m = new te(f);
      } catch (d) {
        return console.log("Error creating ConvexGeometry:", d), null;
      }
      return /* @__PURE__ */ t.jsx("mesh", { geometry: m, children: /* @__PURE__ */ t.jsx(
        "meshStandardMaterial",
        {
          attach: "material",
          color: "#009f4d",
          opacity: 0.2,
          depthTest: !1,
          depthWrite: !1,
          transparent: !0,
          polygonOffset: !0,
          polygonOffsetFactor: -a
        },
        l
      ) }, `${l}-${a}`);
    });
  }) });
}
function ot({
  trajectory: e,
  ...r
}) {
  var l;
  const n = ((l = e.trajectory) == null ? void 0 : l.map((o) => o.tcp_pose ? new x.Vector3(
    o.tcp_pose.position.x / 1e3,
    o.tcp_pose.position.z / 1e3,
    -o.tcp_pose.position.y / 1e3
  ) : null).filter((o) => o !== null)) || [];
  return /* @__PURE__ */ t.jsx("group", { ...r, children: n.length > 0 && /* @__PURE__ */ t.jsx(
    O,
    {
      points: n,
      lineWidth: 3,
      polygonOffset: !0,
      polygonOffsetFactor: 10,
      polygonOffsetUnits: 10
    }
  ) });
}
const D = /* @__PURE__ */ new Map();
async function S(e) {
  if (D.has(e))
    return D.get(e);
  const r = (async () => {
    var u;
    const l = new Te({ instanceUrl: "" }), o = l.api.motionGroupModels;
    (u = o.axios) != null && u.interceptors && o.axios.interceptors.request.use((a) => {
      var f;
      return (f = a.url) != null && f.includes("/glb") && (a.responseType = "blob"), a;
    });
    try {
      const a = await l.api.motionGroupModels.getMotionGroupGlbModel(e);
      return URL.createObjectURL(a);
    } catch (a) {
      throw console.error("Failed to fetch model:", a), a;
    }
  })();
  return D.set(e, r), r;
}
function le(e) {
  function r(n) {
    return n.children.length === 0 ? [n] : [n, ...n.children.flatMap((l) => r(l))];
  }
  return r(e).filter((n) => ue(n));
}
function ce(e) {
  return e.name.endsWith("_FLG");
}
function ue(e) {
  return /_J[0-9]+$/.test(e.name);
}
function Ie(e, r) {
  let n;
  function l(o) {
    if (ce(o)) {
      if (n)
        throw Error(
          `Found multiple flange groups in robot model ${r}; first ${n.name} then ${o.name}. Only one _FLG group is allowed.`
        );
      n = o;
    }
    ue(o), o.children.map(l);
  }
  if (l(e.scene), !n)
    throw Error(
      `No flange group found in robot model ${r}. Flange must be identified with a name ending in _FLG.`
    );
  return { gltf: e };
}
function fe({
  rapidlyChangingMotionState: e,
  dhParameters: r,
  onRotationChanged: n,
  children: l
}) {
  const o = R([]), u = R([]), a = R(null), { invalidate: f } = ne();
  L(() => {
    const s = e.joint_position.filter(
      (i) => i !== void 0
    );
    return a.current = new se(s, {
      tension: 120,
      // Controls spring stiffness - higher values create faster, more responsive motion
      friction: 20,
      // Controls damping - higher values reduce oscillation and create smoother settling
      threshold: 1e-3
    }), () => {
      var i;
      (i = a.current) == null || i.destroy();
    };
  }, []), re((s, i) => {
    if (a.current) {
      const h = a.current.update(i);
      m(), h || f();
    }
  });
  function c(s) {
    s && (u.current = le(s), m(), f());
  }
  function m() {
    var i;
    const s = ((i = a.current) == null ? void 0 : i.getCurrentValues()) || [];
    if (n)
      n(u.current, s);
    else
      for (const [h, g] of u.current.entries()) {
        const p = r[h], j = p.theta || 0, y = p.reverse_rotation_direction ? -1 : 1;
        g.rotation.y = y * (s[h] || 0) + j;
      }
  }
  const d = _(() => {
    const s = e.joint_position.filter(
      (i) => i !== void 0
    );
    requestAnimationFrame(() => {
      var i;
      o.current = s, (i = a.current) == null || i.setTarget(s);
    });
  }, [e]);
  return L(() => {
    d();
  }, [e, d]), ie(() => {
    d();
  }), /* @__PURE__ */ t.jsx("group", { ref: c, children: l });
}
const Pe = "line", Se = "mesh";
function Ce({
  rapidlyChangingMotionState: e,
  dhParameters: r,
  ...n
}) {
  const l = new w(), o = R([]), u = R([]);
  _e.useEffect(() => {
    o.current = new Array(r.length).fill(null), u.current = new Array(r.length).fill(null);
  }, [r.length]);
  function a(m, d) {
    const s = new T(), i = new U(), h = new T();
    l.decompose(s, i, h);
    const g = s.clone(), p = new w().makeRotationY(
      m.theta + d * (m.reverse_rotation_direction ? -1 : 1)
    ).multiply(new w().makeTranslation(0, m.d / 1e3, 0)).multiply(new w().makeTranslation(m.a / 1e3, 0, 0)).multiply(new w().makeRotationX(m.alpha));
    return l.multiply(p), l.decompose(s, i, h), { a: g, b: s };
  }
  function f(m, d, s, i) {
    if (!r)
      return;
    const h = r[m];
    if (!h)
      return;
    const { a: g, b: p } = a(h, i);
    d.geometry.setPositions([g.toArray(), p.toArray()].flat()), s.position.set(p.x, p.y, p.z);
  }
  function c(m, d) {
    l.identity();
    for (let s = 0; s < Math.min(m.length, d.length); s++) {
      const i = o.current[s], h = u.current[s];
      i && h && f(s, i, h, d[s]);
    }
  }
  return /* @__PURE__ */ t.jsx(t.Fragment, { children: /* @__PURE__ */ t.jsx(
    fe,
    {
      rapidlyChangingMotionState: e,
      dhParameters: r,
      onRotationChanged: c,
      children: /* @__PURE__ */ t.jsxs("group", { ...n, name: "Scene", children: [
        /* @__PURE__ */ t.jsxs("mesh", { children: [
          /* @__PURE__ */ t.jsx("sphereGeometry", { args: [0.01, 32, 32] }),
          /* @__PURE__ */ t.jsx("meshStandardMaterial", { color: "black", depthTest: !0 })
        ] }),
        r.map((m, d) => {
          const { a: s, b: i } = a(
            m,
            e.joint_position[d] ?? 0
          ), h = `dhrobot_J0${d}`;
          return /* @__PURE__ */ t.jsxs("group", { name: h, children: [
            /* @__PURE__ */ t.jsx(
              O,
              {
                ref: (g) => {
                  o.current[d] = g;
                },
                name: Pe,
                points: [s, i],
                color: "white",
                lineWidth: 5
              }
            ),
            /* @__PURE__ */ t.jsxs(
              "mesh",
              {
                ref: (g) => {
                  u.current[d] = g;
                },
                name: Se,
                position: i,
                children: [
                  /* @__PURE__ */ t.jsx("sphereGeometry", { args: [0.01, 32, 32] }),
                  /* @__PURE__ */ t.jsx("meshStandardMaterial", { color: "black", depthTest: !0 })
                ]
              },
              "mesh_" + d
            )
          ] }, h);
        })
      ] })
    }
  ) });
}
const De = console.warn;
function de() {
  return L(() => {
    console.warn = (e) => {
      e !== "Cannot call the manual advancement of rafz whilst frameLoop is not set as demand" && De(e);
    };
  }, []), /* @__PURE__ */ t.jsx(t.Fragment, {});
}
function Ue(e) {
  return e.type === "Mesh";
}
function ze({
  url: e,
  flangeRef: r,
  postModelRender: n,
  ...l
}) {
  const o = be(e);
  let u;
  try {
    u = Ie(o, "robot.glb").gltf;
  } catch (c) {
    throw c;
  }
  const a = _(
    (c) => {
      c && n && n();
    },
    [n]
  );
  function f(c) {
    try {
      return Ue(c) ? c.geometry ? /* @__PURE__ */ t.jsx(
        "mesh",
        {
          name: c.name,
          geometry: c.geometry,
          material: c.material,
          position: c.position,
          rotation: c.rotation
        },
        c.uuid
      ) : /* @__PURE__ */ t.jsx("group", { name: c.name, position: c.position, rotation: c.rotation }, c.uuid) : /* @__PURE__ */ t.jsx(
        "group",
        {
          name: c.name,
          position: c.position,
          rotation: c.rotation,
          ref: ce(c) ? r : void 0,
          children: c.children.map(f)
        },
        c.uuid
      );
    } catch (m) {
      return console.warn("Error rendering node", c.name, m), null;
    }
  }
  return /* @__PURE__ */ t.jsx("group", { ...l, dispose: null, ref: a, children: f(u.scene) });
}
function me({
  modelURL: e,
  flangeRef: r,
  postModelRender: n,
  ...l
}) {
  const [o, u] = G(null);
  return L(() => {
    (async () => {
      try {
        if (typeof e == "string")
          u(e);
        else {
          const f = await e;
          u(f);
        }
      } catch (f) {
        console.error("Failed to resolve model URL:", f);
      }
    })();
  }, [e]), o ? /* @__PURE__ */ t.jsx(
    ze,
    {
      url: o,
      flangeRef: r,
      postModelRender: n,
      ...l
    }
  ) : null;
}
const he = (e, r) => {
  e.userData.isGhost || (e.traverse((n) => {
    if (n instanceof x.Mesh) {
      n.material instanceof x.Material && (n.material.colorWrite = !1);
      const l = n.clone(), o = n.clone();
      l.material = new x.MeshStandardMaterial({
        depthTest: !0,
        depthWrite: !0,
        colorWrite: !1,
        polygonOffset: !0,
        polygonOffsetFactor: -1,
        side: x.DoubleSide
      }), l.userData.isGhost = !0, o.material = new x.MeshStandardMaterial({
        color: r,
        opacity: 0.3,
        depthTest: !0,
        depthWrite: !1,
        transparent: !0,
        polygonOffset: !0,
        polygonOffsetFactor: -2,
        side: x.DoubleSide
      }), o.userData.isGhost = !0, n.parent && (n.parent.add(l), n.parent.add(o));
    }
  }), e.userData.isGhost = !0);
}, pe = (e) => {
  if (!e.userData.isGhost) return;
  const r = [];
  e.traverse((n) => {
    var l;
    n instanceof x.Mesh && ((l = n.userData) != null && l.isGhost ? r.push(n) : n.material instanceof x.Material && (n.material.colorWrite = !0));
  }), r.forEach((n) => {
    n.parent && n.parent.remove(n);
  }), e.userData.isGhost = !1;
}, Oe = z(
  ({
    rapidlyChangingMotionState: e,
    modelFromController: r,
    dhParameters: n,
    getModel: l = S,
    flangeRef: o,
    postModelRender: u,
    transparentColor: a,
    ...f
  }) => {
    const [c, m] = G(null), d = _((i) => {
      m(i);
    }, []);
    L(() => {
      c && (a ? he(c, a) : pe(c));
    }, [c, a]);
    const s = /* @__PURE__ */ t.jsx(
      Ce,
      {
        rapidlyChangingMotionState: e,
        dhParameters: n,
        ...f
      }
    );
    return /* @__PURE__ */ t.jsxs(
      ae,
      {
        fallback: s,
        onError: (i) => {
          console.warn(i);
        },
        children: [
          /* @__PURE__ */ t.jsx(oe, { fallback: s, children: /* @__PURE__ */ t.jsx("group", { ref: d, children: /* @__PURE__ */ t.jsx(
            fe,
            {
              rapidlyChangingMotionState: e,
              dhParameters: n,
              children: /* @__PURE__ */ t.jsx(
                me,
                {
                  modelURL: (() => {
                    const i = l(r);
                    if (!i) {
                      const h = new Blob([], { type: "model/gltf-binary" }), g = new File([h], `${r}.glb`, { type: "model/gltf-binary" });
                      return Promise.resolve(URL.createObjectURL(g));
                    }
                    return i;
                  })(),
                  postModelRender: u,
                  flangeRef: o,
                  ...f
                }
              )
            }
          ) }) }),
          /* @__PURE__ */ t.jsx(de, {})
        ]
      }
    );
  }
);
function Ee({
  connectedMotionGroup: e,
  getModel: r = S,
  flangeRef: n,
  transparentColor: l,
  postModelRender: o,
  ...u
}) {
  return e.dhParameters ? /* @__PURE__ */ t.jsx(
    Oe,
    {
      rapidlyChangingMotionState: e.rapidlyChangingMotionState,
      modelFromController: e.modelFromController || "",
      dhParameters: e.dhParameters,
      getModel: r,
      flangeRef: n,
      transparentColor: l,
      postModelRender: o,
      ...u
    }
  ) : null;
}
const st = z(
  Me(
    ({
      robotName: e,
      programState: r,
      safetyState: n,
      operationMode: l,
      driveToHomeEnabled: o = !1,
      onDriveToHomePress: u,
      onDriveToHomeRelease: a,
      connectedMotionGroup: f,
      robotComponent: c = Ee,
      customContentComponent: m,
      className: d
    }) => {
      var W;
      const s = Re(), { t: i } = Le(), [h, g] = G(!1), p = R(null), j = R(null), [y, C] = G(!1), [k, ye] = G({ width: 400, height: 600 }), [Je, je] = G(0);
      L(() => {
        const P = () => {
          if (j.current) {
            const { offsetWidth: $, offsetHeight: H } = j.current;
            C($ > H), ye({ width: $, height: H });
          }
        };
        P();
        const J = new ResizeObserver(P);
        return j.current && J.observe(j.current), () => {
          J.disconnect();
        };
      }, []);
      const E = _(() => {
        je((P) => P + 1);
      }, []), F = _(() => {
        !o || !u || (g(!0), u());
      }, [o, u]), A = _(() => {
        !o || !a || (g(!1), a());
      }, [o, a]), B = _(() => {
        h && a && (g(!1), a());
      }, [h, a]), M = y ? k.width < 350 : k.height < 200, I = y ? k.height < 310 : k.height < 450;
      return /* @__PURE__ */ t.jsx(
        ve,
        {
          ref: j,
          className: d,
          sx: {
            width: "100%",
            height: "100%",
            display: "flex",
            flexDirection: y ? "row" : "column",
            position: "relative",
            overflow: "hidden",
            minWidth: { xs: 180, sm: 220, md: 250 },
            minHeight: y ? { xs: 200, sm: 240, md: 260 } : { xs: 150, sm: 180, md: 220 },
            // Allow progressive hiding in portrait mode
            border: `1px solid ${s.palette.divider}`,
            borderRadius: "18px",
            boxShadow: "none",
            backgroundColor: ((W = s.palette.backgroundPaperElevation) == null ? void 0 : W[8]) || "#2A2A3F",
            backgroundImage: "none"
            // Override any gradient from elevation
          },
          children: y ? /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
            /* @__PURE__ */ t.jsx(
              b,
              {
                sx: {
                  flex: "0 0 50%",
                  position: "relative",
                  height: "100%",
                  minHeight: "100%",
                  maxHeight: "100%",
                  borderRadius: 1,
                  m: { xs: 1.5, sm: 2, md: 3 },
                  mr: { xs: 0.75, sm: 1, md: 1.5 },
                  overflow: "hidden",
                  // Prevent content from affecting container size
                  display: M ? "none" : "block"
                },
                children: !M && /* @__PURE__ */ t.jsxs(
                  N,
                  {
                    orthographic: !0,
                    camera: {
                      position: [3, 2, 3],
                      zoom: 1
                    },
                    shadows: !0,
                    frameloop: "demand",
                    style: {
                      borderRadius: s.shape.borderRadius,
                      width: "100%",
                      height: "100%",
                      background: "transparent",
                      position: "absolute",
                      top: 0,
                      left: 0
                    },
                    dpr: [1, 2],
                    gl: { alpha: !0, antialias: !0 },
                    children: [
                      /* @__PURE__ */ t.jsx(Q, {}),
                      /* @__PURE__ */ t.jsx(Y, { fit: !0, observe: !0, margin: 1, maxDuration: 1, children: /* @__PURE__ */ t.jsx(
                        c,
                        {
                          connectedMotionGroup: f,
                          postModelRender: E
                        }
                      ) })
                    ]
                  }
                )
              }
            ),
            /* @__PURE__ */ t.jsxs(
              b,
              {
                sx: {
                  flex: "1",
                  display: "flex",
                  flexDirection: "column",
                  justifyContent: "flex-start",
                  width: M ? "100%" : "50%"
                },
                children: [
                  /* @__PURE__ */ t.jsxs(
                    b,
                    {
                      sx: {
                        p: { xs: 1.5, sm: 2, md: 3 },
                        pb: { xs: 1, sm: 1.5, md: 2 },
                        textAlign: "left"
                      },
                      children: [
                        /* @__PURE__ */ t.jsx(q, { variant: "h6", component: "h2", sx: { mb: 1 }, children: e }),
                        /* @__PURE__ */ t.jsx(
                          Z,
                          {
                            programState: r,
                            safetyState: n,
                            operationMode: l
                          }
                        )
                      ]
                    }
                  ),
                  /* @__PURE__ */ t.jsxs(
                    b,
                    {
                      sx: {
                        p: { xs: 1.5, sm: 2, md: 3 },
                        pt: 0,
                        flex: "1",
                        display: "flex",
                        flexDirection: "column",
                        justifyContent: "space-between"
                      },
                      children: [
                        !I && m && /* @__PURE__ */ t.jsxs(b, { children: [
                          /* @__PURE__ */ t.jsx(m, {}),
                          /* @__PURE__ */ t.jsx(
                            X,
                            {
                              sx: {
                                mt: 1,
                                mb: 0,
                                borderColor: s.palette.divider,
                                opacity: 0.5
                              }
                            }
                          )
                        ] }),
                        /* @__PURE__ */ t.jsx(
                          b,
                          {
                            sx: {
                              mt: !I && m ? "auto" : 0
                            },
                            children: /* @__PURE__ */ t.jsx(
                              b,
                              {
                                sx: {
                                  display: "flex",
                                  justifyContent: "flex-start",
                                  mt: { xs: 1, sm: 1.5, md: 2 },
                                  mb: { xs: 0.5, sm: 0.75, md: 1 }
                                },
                                children: /* @__PURE__ */ t.jsx(
                                  K,
                                  {
                                    ref: p,
                                    variant: "contained",
                                    color: "secondary",
                                    size: "small",
                                    disabled: !o,
                                    onMouseDown: F,
                                    onMouseUp: A,
                                    onMouseLeave: B,
                                    onTouchStart: F,
                                    onTouchEnd: A,
                                    sx: {
                                      textTransform: "none",
                                      px: 1.5,
                                      py: 0.5
                                    },
                                    children: i("RobotCard.DriveToHome.bt")
                                  }
                                )
                              }
                            )
                          }
                        )
                      ]
                    }
                  )
                ]
              }
            )
          ] }) : /* @__PURE__ */ t.jsx(t.Fragment, { children: /* @__PURE__ */ t.jsxs(
            b,
            {
              sx: {
                p: 3,
                height: "100%",
                display: "flex",
                flexDirection: "column"
              },
              children: [
                /* @__PURE__ */ t.jsxs(b, { children: [
                  /* @__PURE__ */ t.jsx(q, { variant: "h6", component: "h2", sx: { mb: 1 }, children: e }),
                  /* @__PURE__ */ t.jsx(
                    Z,
                    {
                      programState: r,
                      safetyState: n,
                      operationMode: l
                    }
                  )
                ] }),
                /* @__PURE__ */ t.jsx(
                  b,
                  {
                    sx: {
                      flex: M ? 0 : 1,
                      position: "relative",
                      minHeight: M ? 0 : { xs: 120, sm: 150, md: 200 },
                      height: M ? 0 : "auto",
                      borderRadius: 1,
                      overflow: "hidden",
                      display: M ? "none" : "block"
                    },
                    children: !M && /* @__PURE__ */ t.jsxs(
                      N,
                      {
                        orthographic: !0,
                        camera: {
                          position: [3, 2, 3],
                          zoom: 1
                        },
                        shadows: !0,
                        frameloop: "demand",
                        style: {
                          borderRadius: s.shape.borderRadius,
                          width: "100%",
                          height: "100%",
                          background: "transparent",
                          position: "absolute"
                        },
                        dpr: [1, 2],
                        gl: { alpha: !0, antialias: !0 },
                        children: [
                          /* @__PURE__ */ t.jsx(Q, {}),
                          /* @__PURE__ */ t.jsx(Y, { fit: !0, clip: !0, observe: !0, margin: 1, maxDuration: 1, children: /* @__PURE__ */ t.jsx(
                            c,
                            {
                              connectedMotionGroup: f,
                              postModelRender: E
                            }
                          ) })
                        ]
                      }
                    )
                  }
                ),
                /* @__PURE__ */ t.jsxs(b, { children: [
                  !I && m && /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
                    /* @__PURE__ */ t.jsx(m, {}),
                    /* @__PURE__ */ t.jsx(
                      X,
                      {
                        sx: {
                          mt: 1,
                          mb: 0,
                          borderColor: s.palette.divider,
                          opacity: 0.5
                        }
                      }
                    )
                  ] }),
                  /* @__PURE__ */ t.jsx(
                    b,
                    {
                      sx: {
                        display: "flex",
                        justifyContent: "flex-start",
                        mt: !I && m ? { xs: 1, sm: 2, md: 5 } : { xs: 0.5, sm: 1, md: 2 },
                        mb: { xs: 0.5, sm: 0.75, md: 1 }
                      },
                      children: /* @__PURE__ */ t.jsx(
                        K,
                        {
                          ref: p,
                          variant: "contained",
                          color: "secondary",
                          size: "small",
                          disabled: !o,
                          onMouseDown: F,
                          onMouseUp: A,
                          onMouseLeave: B,
                          onTouchStart: F,
                          onTouchEnd: A,
                          sx: {
                            textTransform: "none",
                            px: 1.5,
                            py: 0.5
                          },
                          children: i("RobotCard.DriveToHome.bt")
                        }
                      )
                    }
                  )
                ] })
              ]
            }
          ) })
        }
      );
    }
  )
), it = Array(6).fill(2 * Math.PI);
function xe({
  rapidlyChangingMotionState: e,
  dhParameters: r,
  onTranslationChanged: n,
  children: l
}) {
  const o = R([]), u = R([]), a = R(null), { invalidate: f } = ne();
  L(() => {
    const s = e.joint_position.filter(
      (i) => i !== void 0
    );
    return a.current = new se(s, {
      tension: 120,
      // Controls spring stiffness - higher values create faster, more responsive motion
      friction: 20,
      // Controls damping - higher values reduce oscillation and create smoother settling
      threshold: 1e-3
    }), () => {
      var i;
      (i = a.current) == null || i.destroy();
    };
  }, []), re((s, i) => {
    if (a.current) {
      const h = a.current.update(i);
      m(), h || f();
    }
  });
  function c(s) {
    s && (u.current = le(s), m(), f());
  }
  function m() {
    var i;
    const s = ((i = a.current) == null ? void 0 : i.getCurrentValues()) || [];
    if (n)
      n(u.current, s);
    else
      for (const [h, g] of u.current.entries()) {
        const j = r[h].reverse_rotation_direction ? -1 : 1;
        g.position.x = j * (s[h] || 0) / 1e3;
      }
  }
  const d = _(() => {
    const s = e.joint_position.filter(
      (i) => i !== void 0
    );
    requestAnimationFrame(() => {
      var i;
      o.current = s, (i = a.current) == null || i.setTarget(s);
    });
  }, [e]);
  return L(() => {
    d();
  }, [e, d]), ie(() => {
    d();
  }), /* @__PURE__ */ t.jsx("group", { ref: c, children: l });
}
function ge({
  rapidlyChangingMotionState: e,
  dhParameters: r,
  ...n
}) {
  const l = new w(), o = R(null), u = R(null);
  function a(m) {
    const d = new w();
    for (let g = 0; g < r.length; g++) {
      const p = r[g], j = m[g] ?? 0, y = new w().makeRotationY(p.theta).multiply(
        new w().makeTranslation(
          p.a / 1e3,
          (p.d + j * (p.reverse_rotation_direction ? -1 : 1)) / 1e3,
          0
        )
      ).multiply(new w().makeRotationX(p.alpha));
      d.multiply(y);
    }
    const s = new T(), i = new U(), h = new T();
    return d.decompose(s, i, h), s;
  }
  const f = a(e.joint_position);
  function c(m, d) {
    l.identity();
    let s = new T();
    for (let p = 0; p < r.length; p++) {
      const j = d[p] ?? 0, y = r[p], C = new w().makeRotationY(y.theta).multiply(
        new w().makeTranslation(
          y.a / 1e3,
          (y.d + j * (y.reverse_rotation_direction ? -1 : 1)) / 1e3,
          0
        )
      ).multiply(new w().makeRotationX(y.alpha));
      l.multiply(C);
    }
    const i = new T(), h = new U(), g = new T();
    if (l.decompose(i, h, g), s = i, o.current && o.current.position.set(s.x, s.y, s.z), u.current) {
      const p = u.current.geometry;
      p && p.setPositions && p.setPositions([0, 0, 0, s.x, s.y, s.z]);
    }
  }
  return /* @__PURE__ */ t.jsx(t.Fragment, { children: /* @__PURE__ */ t.jsx(
    xe,
    {
      rapidlyChangingMotionState: e,
      dhParameters: r,
      onTranslationChanged: c,
      children: /* @__PURE__ */ t.jsxs("group", { ...n, name: "Scene", children: [
        /* @__PURE__ */ t.jsxs("mesh", { name: "Base", position: [0, 0, 0], children: [
          /* @__PURE__ */ t.jsx("sphereGeometry", { args: [0.02, 32, 32] }),
          /* @__PURE__ */ t.jsx("meshStandardMaterial", { color: "green", depthTest: !0 })
        ] }),
        /* @__PURE__ */ t.jsx(
          O,
          {
            ref: u,
            points: [new T(0, 0, 0), f],
            color: "White",
            lineWidth: 5
          }
        ),
        /* @__PURE__ */ t.jsxs("mesh", { ref: o, name: "TCP", position: f, children: [
          /* @__PURE__ */ t.jsx("sphereGeometry", { args: [0.025, 32, 32] }),
          /* @__PURE__ */ t.jsx("meshStandardMaterial", { color: "red", depthTest: !0 })
        ] })
      ] })
    }
  ) });
}
const Be = z(
  ({
    rapidlyChangingMotionState: e,
    modelFromController: r,
    dhParameters: n,
    getModel: l = S,
    flangeRef: o,
    postModelRender: u,
    transparentColor: a,
    ...f
  }) => {
    const [c, m] = G(null), d = _((i) => {
      m(i);
    }, []);
    L(() => {
      c && (a ? he(c, a) : pe(c));
    }, [c, a]);
    const s = /* @__PURE__ */ t.jsx(
      ge,
      {
        rapidlyChangingMotionState: e,
        dhParameters: n,
        ...f
      }
    );
    return /* @__PURE__ */ t.jsxs(
      ae,
      {
        fallback: s,
        onError: (i) => {
          console.warn(i);
        },
        children: [
          /* @__PURE__ */ t.jsx(oe, { fallback: s, children: /* @__PURE__ */ t.jsx("group", { ref: d, children: /* @__PURE__ */ t.jsx(
            xe,
            {
              rapidlyChangingMotionState: e,
              dhParameters: n,
              children: /* @__PURE__ */ t.jsx(
                me,
                {
                  modelURL: (() => {
                    const i = l(r);
                    if (!i) {
                      const h = new Blob([], { type: "model/gltf-binary" }), g = new File([h], `${r}.glb`, { type: "model/gltf-binary" });
                      return Promise.resolve(URL.createObjectURL(g));
                    }
                    return i;
                  })(),
                  postModelRender: u,
                  flangeRef: o,
                  ...f
                }
              )
            }
          ) }) }),
          /* @__PURE__ */ t.jsx(de, {})
        ]
      }
    );
  }
);
function at({
  connectedMotionGroup: e,
  getModel: r = S,
  flangeRef: n,
  transparentColor: l,
  postModelRender: o,
  ...u
}) {
  if (!e.dhParameters)
    return null;
  const a = e.modelFromController || "";
  return a && r(a) ? /* @__PURE__ */ t.jsx(
    Be,
    {
      rapidlyChangingMotionState: e.rapidlyChangingMotionState,
      modelFromController: a,
      dhParameters: e.dhParameters,
      getModel: r,
      flangeRef: n,
      transparentColor: l,
      postModelRender: o,
      ...u
    }
  ) : /* @__PURE__ */ t.jsx(
    ge,
    {
      rapidlyChangingMotionState: e.rapidlyChangingMotionState,
      dhParameters: e.dhParameters,
      ...u
    }
  );
}
const ee = {
  [v.Abb]: [0, 0, 0, 0, Math.PI / 2, 0, 0],
  [v.Fanuc]: [0, 0, 0, 0, -Math.PI / 2, 0, 0],
  [v.Yaskawa]: [0, 0, 0, 0, -Math.PI / 2, 0, 0],
  [v.Kuka]: [
    0,
    -Math.PI / 2,
    Math.PI / 2,
    0,
    Math.PI / 2,
    0,
    0
  ],
  [v.Universalrobots]: [
    0,
    -Math.PI / 2,
    -Math.PI / 2,
    -Math.PI / 2,
    Math.PI / 2,
    -Math.PI / 2,
    0
  ]
};
function We(e) {
  const [r] = e.split("_");
  switch (r) {
    case "ABB":
      return v.Abb;
    case "FANUC":
      return v.Fanuc;
    case "YASKAWA":
      return v.Yaskawa;
    case "KUKA":
      return v.Kuka;
    case "UniversalRobots":
      return v.Universalrobots;
    default:
      return null;
  }
}
function lt(e, r) {
  const n = We(e);
  return n && n in ee ? ee[n] : r || null;
}
export {
  nt as C,
  at as L,
  ee as M,
  Q as P,
  Ee as R,
  rt as S,
  ot as T,
  st as a,
  Be as b,
  Oe as c,
  it as d,
  S as e,
  We as f,
  lt as g
};
//# sourceMappingURL=manufacturerHomePositions-BCgn-SCy.js.map
