/**
 * 门店列表页常量集合：
 * - 色值与文案映射
 * - 选项数据
 * - 默认状态
 * - 表格列定义
 */
import type {
  PagePaginationState,
  SelectOptionItem,
  StatusTagMeta,
  StoreFilterState,
  StoreFormState,
} from '../../types';

import type {
  ServiceType,
  StoreAuditStatus,
  StoreBusinessStatus,
  StoreStatsDto,
} from '#/api/store';

import {
  GeoLocationStatus as GeoLocationStatusEnum,
  ServiceType as ServiceTypeEnum,
  StoreAuditStatus as StoreAuditStatusEnum,
  StoreBusinessStatus as StoreBusinessStatusEnum,
} from '#/api/store';

export const THEME_COLORS = {
  danger: '#ef4444',
  success: '#22c55e',
  text: '#1f1f1f',
  warning: '#f59e0b',
} as const;

export const AVATAR_COLORS = [
  '#3b82f6',
  '#f59e0b',
  '#8b5cf6',
  '#ef4444',
  '#22c55e',
  '#06b6d4',
  '#ec4899',
  '#f97316',
  '#14b8a6',
  '#6366f1',
] as const;

export const DEFAULT_STATS: StoreStatsDto = {
  operating: 0,
  pendingAudit: 0,
  resting: 0,
  total: 0,
};

export const DEFAULT_PAGINATION: PagePaginationState = {
  current: 1,
  pageSize: 10,
  total: 0,
};

export const DEFAULT_FILTERS: StoreFilterState = {
  auditStatus: undefined,
  businessStatus: undefined,
  keyword: '',
  serviceType: undefined,
};

export const DEFAULT_FORM_STATE: StoreFormState = {
  address: '',
  contactPhone: '',
  coverImage: '',
  id: '',
  managerName: '',
  name: '',
  serviceTypes: [ServiceTypeEnum.Delivery],
};

export const businessStatusMap: Record<number, StatusTagMeta> = {
  [StoreBusinessStatusEnum.ForceClosed]: { color: 'red', text: '强制关闭' },
  [StoreBusinessStatusEnum.Operating]: { color: 'green', text: '营业中' },
  [StoreBusinessStatusEnum.Resting]: { color: 'default', text: '休息中' },
};

export const auditStatusMap: Record<number, StatusTagMeta> = {
  [StoreAuditStatusEnum.Draft]: { color: 'default', text: '草稿' },
  [StoreAuditStatusEnum.Approved]: { color: 'green', text: '已通过' },
  [StoreAuditStatusEnum.Pending]: { color: 'orange', text: '待审核' },
  [StoreAuditStatusEnum.Rejected]: { color: 'red', text: '已拒绝' },
};

export const serviceTypeMap: Record<number, StatusTagMeta> = {
  [ServiceTypeEnum.Delivery]: { color: 'blue', text: '外卖' },
  [ServiceTypeEnum.DineIn]: { color: 'orange', text: '堂食' },
  [ServiceTypeEnum.Pickup]: { color: 'green', text: '自提' },
};

export const geoStatusMap: Record<number, StatusTagMeta> = {
  [GeoLocationStatusEnum.Pending]: { color: 'orange', text: '待定位' },
  [GeoLocationStatusEnum.Success]: { color: 'green', text: '已定位' },
  [GeoLocationStatusEnum.Failed]: { color: 'red', text: '定位失败' },
};

export const businessStatusOptions: SelectOptionItem<StoreBusinessStatus>[] = [
  { label: '营业中', value: StoreBusinessStatusEnum.Operating },
  { label: '休息中', value: StoreBusinessStatusEnum.Resting },
  { label: '强制关闭', value: StoreBusinessStatusEnum.ForceClosed },
];

export const auditStatusOptions: SelectOptionItem<StoreAuditStatus>[] = [
  { label: '草稿', value: StoreAuditStatusEnum.Draft },
  { label: '待审核', value: StoreAuditStatusEnum.Pending },
  { label: '已通过', value: StoreAuditStatusEnum.Approved },
  { label: '已拒绝', value: StoreAuditStatusEnum.Rejected },
];

export const serviceTypeOptions: SelectOptionItem<ServiceType>[] = [
  { label: '外卖配送', value: ServiceTypeEnum.Delivery },
  { label: '到店自提', value: ServiceTypeEnum.Pickup },
  { label: '堂食', value: ServiceTypeEnum.DineIn },
];

export const columns = [
  { key: 'storeInfo', title: '门店信息', width: 240 },
  {
    dataIndex: 'contactPhone',
    key: 'contactPhone',
    title: '联系电话',
    width: 120,
  },
  { dataIndex: 'managerName', key: 'managerName', title: '店长', width: 80 },
  { dataIndex: 'address', ellipsis: true, key: 'address', title: '地址' },
  { key: 'serviceTypes', title: '服务方式', width: 180 },
  { key: 'geoStatus', title: '定位状态', width: 110 },
  { key: 'businessStatus', title: '营业状态', width: 100 },
  { key: 'auditStatus', title: '审核状态', width: 100 },
  { dataIndex: 'createdAt', key: 'createdAt', title: '创建时间', width: 120 },
  { fixed: 'right' as const, key: 'action', title: '操作', width: 240 },
];
