import { ReactNode } from 'react'
import { MenuItemProps } from '../components/Menu/index.js'
import { FinderView } from '../components/BasedFinder/index.js'

type Select = string[]

type Sort = {
  key: string
  direction: 'asc' | 'desc' | ''
}

type FilterGroupItem = { field: string; operator: string; value: string }
type Filter = {
  operator: 'and' | 'or'
  items: FilterGroupItem[]
  nested?: {
    operator: 'and' | 'or'
    group: Filter
  }
}

type Fields = Record<Field['key'], Field>

type Field = {
  key: string
  render?: (item: any, view: FinderView) => ReactNode
  renderAccessorFn?: (item: any) => any
  table?: {
    title?: string
    width?: number
  }

  grid?: {
    type: 'title' | 'description' | 'media'
  }
  calendar?: {
    type: 'title' | 'start' | 'end'
  }
}

type ItemActions = {
  label: string
  icon?: MenuItemProps['leadIcon']
  color?: MenuItemProps['color']
  onClick: (item: any) => void
}[]
type BulkActions = {
  label: string
  icon?: MenuItemProps['leadIcon']
  color?: MenuItemProps['color']
  onClick: (
    selected: Select,
    opts: { setSelect: (select: Select) => void },
  ) => void
}[]

export type {
  Select,
  Sort,
  Field,
  ItemActions,
  BulkActions,
  Fields,
  Filter,
  FilterGroupItem,
}
