import { DEFAULT_POSE } from './rigTypes.js';
import { POSE_DANCE_A, POSE_ANGRY, POSE_HAPPY } from './presets.js';
import { ease, tweenPose } from './poseOps.js';

/** Map a high-level PersonPose to a rig pose. */
function rigPoseFor(pose) {
    switch (pose) {
        case "happy":
        case "celebrate":
            return POSE_HAPPY;
        case "angry":
        case "shouting":
            return POSE_ANGRY;
        case "danceA":
        case "danceB":
        case "danceC":
            return POSE_DANCE_A;
        case "raiseCard":
            return { ...DEFAULT_POSE, rUpperArm: 350, rForearm: 320, lUpperArm: 140, lForearm: 150, head: 60 };
        case "waveHand":
            return { ...DEFAULT_POSE, rUpperArm: 330, rForearm: 300 };
        case "facepalm":
            return { ...DEFAULT_POSE, rUpperArm: 20, rForearm: 340, head: 80 };
        case "shrug":
            return { ...DEFAULT_POSE, lUpperArm: 110, rUpperArm: 70, head: 85 };
        case "nodYes":
            return { ...DEFAULT_POSE, head: 90 };
        case "shakeNo":
            return { ...DEFAULT_POSE, head: 60 };
        case "rock":
            return { ...DEFAULT_POSE, pelvis: 100, spineLower: 100, spineUpper: 80 };
        case "jump":
            return { ...DEFAULT_POSE, lThigh: 70, rThigh: 110, lShin: 70, rShin: 110 };
        case "leanBack":
            return { ...DEFAULT_POSE, spineLower: 80, spineUpper: 70, head: 50 };
        case "pointRight":
            return { ...DEFAULT_POSE, rUpperArm: 10, rForearm: 350 };
        case "idle":
        default:
            return DEFAULT_POSE;
    }
}
/** Play a DSL choreography program by tweening the provided pose setter. */
async function playRigFromChoreo(steps, setPose, opts) {
    var _a, _b, _c, _d, _e;
    const duration = (_a = opts === null || opts === void 0 ? void 0 : opts.duration) !== null && _a !== void 0 ? _a : 450;
    const easeFn = (_b = opts === null || opts === void 0 ? void 0 : opts.easing) !== null && _b !== void 0 ? _b : ease.inOut;
    let current = DEFAULT_POSE;
    for (const s of steps) {
        const target = rigPoseFor(s.pose);
        await tweenPose(current, target, (_d = (_c = s.options) === null || _c === void 0 ? void 0 : _c.duration) !== null && _d !== void 0 ? _d : duration, setPose, easeFn);
        current = target;
        const hold = (_e = s.holdMs) !== null && _e !== void 0 ? _e : 0;
        if (hold > 0)
            await new Promise((r) => setTimeout(r, hold));
    }
}

export { playRigFromChoreo, rigPoseFor };
//# sourceMappingURL=choreoRigBridge.js.map
