import { jsxs, jsx } from 'react/jsx-runtime';
import { DEFAULT_POSE, DEFAULT_RIG } from './rigTypes.js';
import { solveFK } from './rigMath.js';

/** Render a multi-bone body (arms: 3, legs: 3, torso: 3, neck+head). */
const NiceRiggedBody = ({ character, rig, pose, size, debug }) => {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
    const S = Math.max(140, Math.floor((_a = size !== null && size !== void 0 ? size : character.size) !== null && _a !== void 0 ? _a : 180));
    const r = rig !== null && rig !== void 0 ? rig : DEFAULT_RIG;
    const p = { ...DEFAULT_POSE, ...(pose !== null && pose !== void 0 ? pose : {}) };
    const fk = solveFK(r, p, S);
    const stroke = (_d = (_c = (_b = character.face) === null || _b === void 0 ? void 0 : _b.colors) === null || _c === void 0 ? void 0 : _c[2]) !== null && _d !== void 0 ? _d : "var(--anim-stroke, #111)";
    const skin = (_g = (_f = (_e = character.face) === null || _e === void 0 ? void 0 : _e.colors) === null || _f === void 0 ? void 0 : _f[0]) !== null && _g !== void 0 ? _g : "var(--anim-skin, #FFD2B3)";
    const cloth = (_k = (_j = (_h = character.outfit) === null || _h === void 0 ? void 0 : _h.colors) === null || _j === void 0 ? void 0 : _j[0]) !== null && _k !== void 0 ? _k : "var(--anim-shirt, #3B82F6)";
    const sw = Math.max(2, S * 0.015);
    const seg = (a, color) => (jsx("line", { x1: fk[a].x, y1: fk[a].y, x2: fk[a].x2, y2: fk[a].y2, stroke: color, strokeWidth: sw, strokeLinecap: "round" }));
    const torsoPath = `
    M ${fk.pelvis.x - S * 0.09} ${fk.pelvis.y}
    L ${fk.pelvis.x + S * 0.09} ${fk.pelvis.y}
    L ${fk.spineUpper.x + S * 0.10} ${fk.spineUpper.y}
    L ${fk.spineUpper.x - S * 0.10} ${fk.spineUpper.y} Z
  `;
    const headR = S * 0.11;
    return (jsxs("svg", { width: S, height: S * 1.25, viewBox: `0 0 ${S} ${S * 1.25}`, children: [seg("lThigh", cloth), seg("lShin", cloth), seg("lFoot", cloth), seg("rThigh", cloth), seg("rShin", cloth), seg("rFoot", cloth), jsx("path", { d: torsoPath, fill: (_o = (_m = (_l = character.outfit) === null || _l === void 0 ? void 0 : _l.colors) === null || _m === void 0 ? void 0 : _m[1]) !== null && _o !== void 0 ? _o : "var(--anim-outfit-2, #2563EB)", stroke: stroke, strokeWidth: sw * 0.8 }), seg("pelvis", stroke), seg("spineLower", stroke), seg("spineUpper", stroke), seg("neck", stroke), seg("lUpperArm", skin), seg("lForearm", skin), seg("lHand", skin), seg("rUpperArm", skin), seg("rForearm", skin), seg("rHand", skin), jsx("circle", { cx: fk.head.x2, cy: fk.head.y2, r: headR, fill: skin, stroke: stroke, strokeWidth: sw * 0.7 }), debug && (jsx("g", { opacity: 0.65, fill: stroke, children: Object.values(fk).map((b, i) => jsx("circle", { cx: b.x, cy: b.y, r: sw * 0.55 }, i)) }))] }));
};

export { NiceRiggedBody as default };
//# sourceMappingURL=RiggedBody.js.map
