import { jsx as l, Fragment as p, jsxs as n } from "react/jsx-runtime";
import { useMemo as c, useEffect as h } from "react";
const x = ({ vrm: t, configs: r, setConfigs: s }) => {
  var o, d;
  const u = c(() => {
    var i;
    if (!((i = t == null ? void 0 : t.springBoneManager) != null && i.joints))
      return {};
    const a = {};
    return t.springBoneManager.joints.forEach((e) => {
      if (e.bone.name.includes("Skirt")) {
        a[e.bone.name] = {
          stiffness: 5,
          dragForce: 0.2,
          hitRadius: 1
        };
        return;
      }
      a[e.bone.name] = {
        stiffness: 6,
        dragForce: 0.2,
        hitRadius: 1
      };
    }), a;
  }, [(o = t == null ? void 0 : t.springBoneManager) == null ? void 0 : o.joints]);
  h(() => {
    s && !r && s(u);
  }, [r, u]);
  const f = c(() => {
    var a;
    return (a = t == null ? void 0 : t.springBoneManager) != null && a.joints ? Array.from(t.springBoneManager.joints).map((i) => {
      const e = r == null ? void 0 : r[i.bone.name];
      return {
        name: i.bone.name,
        stiffness: (e == null ? void 0 : e.stiffness) ?? 0,
        dragForce: (e == null ? void 0 : e.dragForce) ?? 0,
        hitRadius: (e == null ? void 0 : e.hitRadius) ?? 0
      };
    }) : [];
  }, [(d = t == null ? void 0 : t.springBoneManager) == null ? void 0 : d.joints, r]);
  return !t || !s ? /* @__PURE__ */ l(p, {}) : /* @__PURE__ */ n("div", { className: "virtual-fixed virtual-top-1/2 virtual-right-4 -virtual-translate-y-1/2 virtual-p-4 virtual-rounded-lg virtual-bg-white virtual-h-[80%] virtual-overflow-y-auto virtual-gap-4 virtual-flex virtual-flex-col virtual-z-40 virtual-w-[300px]", children: [
    f.map((a, i) => /* @__PURE__ */ n(
      "div",
      {
        className: "virtual-flex virtual-flex-col virtual-gap-2",
        children: [
          /* @__PURE__ */ l("p", { children: a.name }),
          /* @__PURE__ */ n("div", { className: "virtual-flex virtual-flex-row virtual-items-center virtual-gap-2", children: [
            /* @__PURE__ */ l("p", { className: "virtual-w-[180px]", children: "Stiffness:" }),
            /* @__PURE__ */ l(
              "input",
              {
                value: a.stiffness,
                placeholder: "Stiffness",
                className: "virtual-w-full",
                onChange: (e) => {
                  s({
                    ...r,
                    [a.name]: {
                      stiffness: +e.target.value,
                      hitRadius: a.hitRadius,
                      dragForce: a.dragForce
                    }
                  });
                }
              }
            )
          ] }),
          /* @__PURE__ */ n("div", { className: "virtual-flex virtual-flex-row virtual-items-center virtual-gap-2", children: [
            /* @__PURE__ */ l("p", { className: "virtual-w-[180px]", children: "Hit Radius:" }),
            /* @__PURE__ */ l(
              "input",
              {
                value: a.hitRadius,
                placeholder: "Hit Radius",
                className: "virtual-w-full",
                onChange: (e) => {
                  s({
                    ...r,
                    [a.name]: {
                      stiffness: a.stiffness,
                      hitRadius: +e.target.value,
                      dragForce: a.dragForce
                    }
                  });
                }
              }
            )
          ] }),
          /* @__PURE__ */ n("div", { className: "virtual-flex virtual-flex-row virtual-items-center virtual-gap-2", children: [
            /* @__PURE__ */ l("p", { className: "virtual-w-[180px]", children: "Drag Force:" }),
            /* @__PURE__ */ l(
              "input",
              {
                value: a.dragForce,
                placeholder: "Drag Force",
                className: "virtual-w-full",
                onChange: (e) => {
                  s({
                    ...r,
                    [a.name]: {
                      stiffness: a.stiffness,
                      hitRadius: a.hitRadius,
                      dragForce: +e.target.value
                    }
                  });
                }
              }
            )
          ] })
        ]
      },
      `${a.name}_${i}`
    )),
    /* @__PURE__ */ l(
      "button",
      {
        onClick: () => {
          var a = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(r)), i = document.createElement("a");
          i.setAttribute("href", a), i.setAttribute("download", "modelConfigs.json"), document.body.appendChild(i), i.click(), i.remove();
        },
        className: "virtual-bg-black virtual-text-white",
        children: "Export"
      }
    )
  ] });
};
export {
  x as ModelConfigs
};
