import { render, screen } from "@testing-library/react";
import { test, expect } from "vitest";

import { OrderDetail } from "@/features/orders/order-detail";
import type { OrderDetailVM } from "@/lib/types/view-models";

const BASE_ORDER_DETAIL: OrderDetailVM = {
  orderId: 101,
  workflowId: "wf-101",
  customerLevel: "mid",
  serviceMode: "semi_pro",
  status: "waiting_review",
  statusMeta: {
    label: "待审核",
    tone: "warning",
  },
  currentStep: "review",
  currentStepLabel: "人工审核",
  modelId: 1001,
  poseId: 2002,
  garmentAssetId: 3003,
  sceneRefAssetId: 4004,
  currentRevisionAssetId: null,
  currentRevisionVersion: null,
  latestRevisionAssetId: null,
  latestRevisionVersion: null,
  revisionCount: 0,
  reviewTaskStatus: null,
  pendingManualConfirm: false,
  createdAt: "2026-03-27T00:00:00Z",
  updatedAt: "2026-03-27T00:10:00Z",
  finalAsset: {
    id: 88,
    orderId: 101,
    type: "final",
    stepName: null,
    parentAssetId: null,
    rootAssetId: null,
    versionNo: 0,
    isCurrentVersion: false,
    stepLabel: "最终图",
    label: "最终图",
    uri: "mock://final-preview",
    metadata: null,
    createdAt: "2026-03-27T00:10:00Z",
    isMock: true,
  },
  finalAssetState: {
    kind: "ready",
  },
  assets: [
    {
      id: 77,
      orderId: 101,
      type: "fusion",
      stepName: "fusion",
      parentAssetId: null,
      rootAssetId: null,
      versionNo: 0,
      isCurrentVersion: false,
      stepLabel: "融合",
      label: "融合产物",
      uri: "mock://fusion-preview",
      metadata: null,
      createdAt: "2026-03-27T00:09:00Z",
      isMock: true,
    },
  ],
  assetGalleryState: {
    kind: "ready",
  },
  hasMockAssets: true,
};

test("shows a mock asset banner when the current order contains mock assets", () => {
  render(<OrderDetail viewModel={BASE_ORDER_DETAIL} />);

  expect(screen.getByText("当前资产来自 mock 流程")).toBeInTheDocument();
  expect(screen.getAllByText("最终图").length).toBeGreaterThan(0);
});

test("renders the business-empty final-result state when no final asset exists", () => {
  render(
    <OrderDetail
      viewModel={{
        ...BASE_ORDER_DETAIL,
        finalAsset: null,
        finalAssetState: {
          kind: "business-empty",
          title: "最终图暂未生成",
          description: "当前订单还没有可展示的最终结果。",
        },
      }}
    />,
  );

  expect(screen.getByText("最终图暂未生成")).toBeInTheDocument();
  expect(screen.getByText("当前订单还没有可展示的最终结果。")).toBeInTheDocument();
});
