import assert from "node:assert/strict";
import test from "node:test";
import { configureMediaSession } from "../../lib/client/player/media-session.ts";

test("wires lock-screen metadata and required playback actions", () => {
  const actions = new Map();
  const session = { metadata: null, playbackState: "none", setActionHandler(name, handler) { actions.set(name, handler); } };
  const calls = [];
  configureMediaSession(session, { title: "第一句", artist: "第一章", album: "测试书", artwork: [{ src: "https://example.test/cover" }] }, {
    play: () => calls.push("play"), pause: () => calls.push("pause"),
    next: () => calls.push("next"), previous: () => calls.push("previous"),
    seekBy: (seconds) => calls.push(seconds),
  }, (value) => value);
  assert.deepEqual(session.metadata, { title: "第一句", artist: "第一章", album: "测试书", artwork: [{ src: "https://example.test/cover" }] });
  for (const action of ["play", "pause", "nexttrack", "previoustrack", "seekbackward", "seekforward"]) assert.equal(actions.has(action), true);
  actions.get("seekbackward")({ seekOffset: 15 });
  actions.get("seekforward")({ seekOffset: 15 });
  assert.deepEqual(calls, [-15, 15]);
});
