/**
 * View type metadata for the ViewSwitcher dropdown (U4 / R3).
 *
 * Pure data + lookup — no Vue, no store, no I/O. Safe to unit-test in
 * isolation.
 *
 * v1 ships only `grid`; the other four types (kanban/gallery/gantt/form) are
 * rendered as disabled menu items with a "规划中" tooltip so users can see the
 * roadmap without hitting a dead-end click. The "规划中" string is hardcoded
 * per spec (no i18n lookup, no config) — it is a temporary placeholder that
 * gets replaced per-type when each view ships.
 *
 * ponytail: icon is a Vue component ref (Ant Design icon), typed as `Component`
 * so the dropdown can render it via `<component :is="meta.icon" />`. Ceiling:
 * the list is static; adding a new view type means appending here + flipping
 * `disabled` to false when implemented.
 */

import type { Component } from 'vue'
import {
  TableOutlined,
  AppstoreOutlined,
  PictureOutlined,
  BarChartOutlined,
  FormOutlined,
} from '@ant-design/icons-vue'
import type { ViewType } from '@/api/bitable'

export interface ViewTypeMeta {
  /** Backend view_type discriminator (matches ViewType union + ViewType enum). */
  viewType: ViewType
  /** Chinese label shown in the dropdown. */
  label: string
  /** Ant Design icon component rendered before the label. */
  icon: Component
  /** Disabled = not yet implemented in v1; shown greyed-out with tooltip. */
  disabled: boolean
  /** Tooltip shown on hover for disabled items (hardcoded "规划中"). */
  tooltip?: string
}

/**
 * Ordered view type list for the "新建视图" dropdown.
 *
 * Order matches the U4 spec: grid (enabled) → kanban / gallery / gantt / form
 * (disabled, "规划中"). Only `grid` is creatable in v1.
 */
export const VIEW_TYPE_LIST: ViewTypeMeta[] = [
  { viewType: 'grid', label: '表格', icon: TableOutlined, disabled: false },
  { viewType: 'kanban', label: '看板', icon: AppstoreOutlined, disabled: true, tooltip: '规划中' },
  { viewType: 'gallery', label: '画廊', icon: PictureOutlined, disabled: true, tooltip: '规划中' },
  { viewType: 'gantt', label: '甘特', icon: BarChartOutlined, disabled: true, tooltip: '规划中' },
  { viewType: 'form', label: '表单', icon: FormOutlined, disabled: true, tooltip: '规划中' },
]

/**
 * Look up the metadata for a given view type.
 *
 * Falls back to `grid` (the only enabled v1 type) for unknown values — this
 * keeps the UI robust against a stale/forward-incompatible view_type returned
 * by the backend after an upgrade.
 */
export function getViewTypeMeta(viewType: ViewType): ViewTypeMeta {
  return VIEW_TYPE_LIST.find((m) => m.viewType === viewType) ?? VIEW_TYPE_LIST[0]
}
