import type { InjectionKey, Ref } from 'vue'

export type SortOrder = 'asc' | 'desc'
export type ColumnFixed = false | 'left' | 'right'
export type ColumnAlign = 'left' | 'center' | 'right'

export interface SortChangePayload {
  prop: string
  order: SortOrder | null
}

export interface ColumnSettingItem {
  key: string
  label: string
  visible: boolean
  fixed: ColumnFixed
  children?: ColumnSettingItem[]
}

export interface TableContext<T = any> {
  data: Ref<T[]>
  loading: Ref<boolean>
  columnAlign: Ref<ColumnAlign>
  columnMaxWidth: Ref<number>
  columnSettings: Ref<ColumnSettingItem[]>
  updateColumnVisible: (key: string, visible: boolean) => void
  updateColumnFixed: (key: string, fixed: ColumnFixed) => void
  updateColumnOrder: (keys: string[], parentKey?: string) => void
  resetColumnSettings: () => void
}

export const TableContextKey: InjectionKey<TableContext> = Symbol('zm-table')
