import type { BillArchiveStatus, LeaseDetailStatus } from '../types';

export const LEFT_STICKY_LAST_COLUMN_KEY = 'customerName';

/** 宽表列定义（对齐 Excel「租赁车辆收入明细表」） */
export interface LeaseTableColumn {
  key: string;
  title: string;
  money?: boolean;
  date?: boolean;
  sticky?: 'left' | 'right';
  className?: string;
  annotationId?: string;
  headerTip?: string;
  sortable?: boolean;
  defaultWidth?: number;
  render?:
    | 'stack-dept' | 'stack-plate' | 'stack-customer' | 'status' | 'deposit'
    | 'asset-owner' | 'signing-company'
    | 'monthly-income' | 'maintenance-income' | 'insurance-surcharge'
    | 'detail-popover-maintenance-income' | 'line-items-income' | 'line-items-deduction'
    | 'received-amount' | 'detail-popover-receipts'
    | 'invoice-date' | 'vehicle-standard-cost' | 'vehicle-actual-cost'
    | 'insurance-readonly' | 'detail-popover-hydrogen' | 'detail-popover-maintenance-cost'
    | 'brokerage-fee' | 'other-cost' | 'gps-mileage'
    | 'deduction-detail' | 'remark-text' | 'year-month' | 'text' | 'maintainer-time' | 'value-added-service' | 'exemption-policy' | 'archive-status';
}

export const LEASE_TABLE_COLUMNS: LeaseTableColumn[] = [
  { key: 'status', title: '状态', render: 'status', annotationId: 'lbl-col-status', sortable: false },
  { key: 'billingYearMonth', title: '年月', className: 'tabular-nums', render: 'year-month', sortable: false },
  { key: 'dept', title: '业务部门', render: 'stack-dept', sortable: false },
  {
    key: 'paymentDueDate',
    title: '应付款日',
    date: true,
    annotationId: 'lbl-col-payment-due',
  },
  { key: 'plateNo', title: '车牌号码', render: 'stack-plate', annotationId: 'lbl-col-plate' },
  { key: 'customerName', title: '客户名称', render: 'stack-customer', annotationId: 'lbl-col-customer', sortable: false },
  {
    key: 'valueAddedService',
    title: '增值服务',
    render: 'value-added-service',
    annotationId: 'lbl-col-value-added-service',
    sortable: false,
  },
  { key: 'exemptionPolicy', title: '享免政策', render: 'exemption-policy', annotationId: 'lbl-col-exemption-policy', sortable: false },
  { key: 'pickupDate', title: '提车日期', date: true, annotationId: 'lbl-col-pickup-date' },
  {
    key: 'contractStartDate',
    title: '合同生效日期',
    date: true,
    annotationId: 'lbl-col-contract-start-date',
  },
  {
    key: 'contractEndDate',
    title: '合同到期日期',
    date: true,
    annotationId: 'lbl-col-contract-end-date',
  },
  {
    key: 'periodStartDate',
    title: '起始日期',
    date: true,
    annotationId: 'lbl-col-period-start-date',
  },
  {
    key: 'returnDate',
    title: '退车日期',
    date: true,
    annotationId: 'lbl-col-return-date',
  },
  {
    key: 'avgDays',
    title: '平均天数',
    className: 'tabular-nums',
    annotationId: 'lbl-col-avg-days',
    sortable: false,
  },
  { key: 'deposit', title: '保证金', render: 'deposit', annotationId: 'lbl-col-deposit', sortable: false },
  { key: 'contractRent', title: '合同标的租金', money: true, annotationId: 'lbl-col-contract-rent', sortable: false },
  {
    key: 'receivableTotal',
    title: '应收合计',
    money: true,
    annotationId: 'lbl-col-receivable-total',
    sortable: false,
  },
  { key: 'receivableRent', title: '应收租金', money: true, annotationId: 'lbl-col-receivable-rent', sortable: false },
  { key: 'monthlyIncome', title: '月度收入', money: true, render: 'monthly-income', annotationId: 'lbl-col-monthly-income', sortable: false },
  { key: 'monthlyRent', title: '月度租金', money: true, annotationId: 'lbl-col-monthly-rent', sortable: false },
  { key: 'maintenanceIncome', title: '维保包干收入', money: true, render: 'maintenance-income', annotationId: 'lbl-col-maintenance-income', sortable: false },
  { key: 'insuranceSurcharge', title: '保险上浮费', money: true, render: 'insurance-surcharge', annotationId: 'lbl-col-insurance-surcharge', sortable: false },
  {
    key: 'opsFeeIncome',
    title: '运维费',
    money: true,
    className: 'ldb-col-ops-income',
    render: 'detail-popover-maintenance-income',
    annotationId: 'lbl-col-ops-income',
    sortable: false,
  },
  {
    key: 'otherIncome',
    title: '其他收入',
    money: true,
    render: 'line-items-income',
    annotationId: 'lbl-col-other-income',
    sortable: false,
  },
  {
    key: 'mileageDeduction',
    title: '里程减免金额',
    money: true,
    annotationId: 'lbl-col-mileage-deduction',
    sortable: false,
  },
  {
    key: 'otherDeduction',
    title: '其他减免金额',
    money: true,
    render: 'line-items-deduction',
    annotationId: 'lbl-col-other-deduction',
    sortable: false,
  },
  { key: 'receivedAmount', title: '实收金额', money: true, render: 'received-amount', annotationId: 'lbl-col-received-amount', sortable: false },
  { key: 'unreceived', title: '未收金额', money: true, annotationId: 'lbl-col-unreceived', sortable: false },
  { key: 'invoiceDate', title: '开票日期', date: true, render: 'invoice-date', annotationId: 'lbl-col-invoice-date' },
  { key: 'actualPaymentDate', title: '实际付款日期', date: true, annotationId: 'lbl-col-actual-payment' },
  { key: 'paymentMethod', title: '付款方式', annotationId: 'lbl-col-payment-method', sortable: false },
  { key: 'vehicleStandardCost', title: '车辆标准成本', money: true, render: 'vehicle-standard-cost', annotationId: 'lbl-col-vehicle-standard-cost', sortable: false },
  { key: 'vehicleActualCost', title: '车辆实际成本', money: true, render: 'vehicle-actual-cost', annotationId: 'lbl-col-vehicle-actual-cost', sortable: false },
  { key: 'insuranceFee', title: '保险费', money: true, render: 'insurance-readonly', annotationId: 'lbl-col-insurance-fee', sortable: false },
  {
    key: 'hydrogenFee',
    title: '氢费',
    money: true,
    render: 'detail-popover-hydrogen',
    annotationId: 'lbl-col-hydrogen-fee',
    sortable: false,
  },
  {
    key: 'opsFeeCost',
    title: '运维费',
    money: true,
    className: 'ldb-col-ops-cost',
    render: 'detail-popover-maintenance-cost',
    annotationId: 'lbl-col-ops-cost',
    sortable: false,
  },
  { key: 'brokerageFee', title: '居间费', money: true, render: 'brokerage-fee', annotationId: 'lbl-col-brokerage-fee', sortable: false },
  { key: 'otherCost', title: '其他', money: true, render: 'other-cost', annotationId: 'lbl-col-other-cost', sortable: false },
  { key: 'totalCost', title: '总成本', money: true, sortable: false },
  { key: 'profitLoss', title: '盈亏', money: true, sortable: false },
  { key: 'gpsMileage', title: 'GPS里程', render: 'gps-mileage', annotationId: 'lbl-col-gps-mileage', sortable: false },
  { key: 'otherDeductionDetail', title: '其他减免金额明细内容', className: 'ldb-col-remark', render: 'deduction-detail', annotationId: 'lbl-col-deduction-detail' },
  { key: 'assetOwner', title: '资产归属', render: 'asset-owner', annotationId: 'lbl-col-asset-ownership', sortable: false },
  { key: 'signingCompany', title: '签约公司', className: 'ldb-col-name', render: 'signing-company', annotationId: 'lbl-col-signing-company', sortable: false },
  { key: 'remark', title: '备注', className: 'ldb-col-remark', render: 'remark-text', annotationId: 'lbl-col-remark', sortable: false },
  {
    key: 'archiveStatus',
    title: '账单状态',
    render: 'archive-status',
    annotationId: 'lbl-col-archive-status',
    sortable: false,
  },
  { key: 'maintainerName', title: '维护人', sortable: false },
  {
    key: 'maintainerTime',
    title: '维护时间',
    className: 'tabular-nums',
    annotationId: 'lbl-col-maintainer-time',
    render: 'maintainer-time',
  },
];

export const STATUS_CLASS: Record<LeaseDetailStatus, string> = {
  未收款: 'ldb-status--unpaid',
  部分收款: 'ldb-status--partial',
  已收款: 'ldb-status--paid',
};

export const ARCHIVE_STATUS_CLASS: Record<BillArchiveStatus, string> = {
  已归档: 'ldb-status--archived',
  未归档: 'ldb-status--unarchived',
  草稿: 'ldb-status--draft',
};
