import assert from "node:assert/strict";
import { describe, it } from "node:test";

import { resolveButtonSemantics } from "./buttonSemantics.js";

describe("resolveButtonSemantics", () => {
  it("expands terse common action labels into clear ERP labels", () => {
    assert.deepEqual(resolveButtonSemantics("刷新"), {
      label: "刷新数据",
      icon: "refresh",
      tone: "neutral",
      kind: "tool"
    });
    assert.deepEqual(resolveButtonSemantics("查看"), {
      label: "查看详情",
      icon: "view",
      tone: "info",
      kind: "table"
    });
    assert.deepEqual(resolveButtonSemantics("编辑"), {
      label: "编辑资料",
      icon: "edit",
      tone: "info",
      kind: "table"
    });
    assert.deepEqual(resolveButtonSemantics("删除"), {
      label: "删除记录",
      icon: "delete",
      tone: "danger",
      kind: "danger"
    });
    assert.deepEqual(resolveButtonSemantics("增加一行"), {
      label: "添加明细行",
      icon: "rowAdd",
      tone: "info",
      kind: "secondary"
    });
    assert.deepEqual(resolveButtonSemantics("保存"), {
      label: "保存信息",
      icon: "save",
      tone: "primary",
      kind: "primary"
    });
  });

  it("keeps already explicit business labels while assigning icon and tone", () => {
    assert.deepEqual(resolveButtonSemantics("新增采购订单"), {
      label: "新建采购订单",
      icon: "plus",
      tone: "primary",
      kind: "primary"
    });
    assert.deepEqual(resolveButtonSemantics("保存授权"), {
      label: "保存授权",
      icon: "authorize",
      tone: "primary",
      kind: "primary"
    });
    assert.deepEqual(resolveButtonSemantics("质检放行"), {
      label: "质检放行",
      icon: "check",
      tone: "success",
      kind: "success"
    });
    assert.deepEqual(resolveButtonSemantics("保存产品需规"), {
      label: "保存产品需规",
      icon: "save",
      tone: "primary",
      kind: "primary"
    });
  });

  it("uses distinct tones for transfer actions instead of rendering every utility button alike", () => {
    assert.deepEqual(resolveButtonSemantics("导入"), {
      label: "导入",
      icon: "import",
      tone: "primary",
      kind: "primary"
    });
    assert.deepEqual(resolveButtonSemantics("导出"), {
      label: "导出",
      icon: "export",
      tone: "success",
      kind: "tool"
    });
    assert.deepEqual(resolveButtonSemantics("下载模板"), {
      label: "下载模板",
      icon: "download",
      tone: "success",
      kind: "tool"
    });
  });

  it("treats danger classes as risk actions even when the label is short", () => {
    assert.deepEqual(resolveButtonSemantics("移除", "ghost-button danger-ghost"), {
      label: "移除记录",
      icon: "delete",
      tone: "danger",
      kind: "danger"
    });
  });

  it("does not decorate business identifier links that are not actions", () => {
    assert.equal(resolveButtonSemantics("产品需规00001", "link-button"), null);
  });
});
