/**
 * Copyright 2024 Phenix Real Time Solutions, Inc. Confidential and Proprietary. All Rights Reserved.
 */
import React, {CSSProperties} from 'react';

import {DirectionType, ITableSearch, ITableSort} from 'interfaces/tableProps';
import {ITableCellDropdown} from '.';

export enum CellType {
  Text = 'text',
  Link = 'link',
  Date = 'date',
  DateTime = 'datetime',
  DropDown = 'dropdown',
  Component = 'component'
}

export type DataValueType = string | number | null | undefined;
export type DataRowType = Record<string, DataValueType>;

interface ITableCellText {
  propName: string;
  hasShow?: boolean;
  hasCopy?: boolean;
  isSortable?: boolean;
  direction?: DirectionType;
  sortable?: boolean;
  mutate?: (value: DataValueType | boolean) => string | number;
}

export interface ITableColumn {
  title: string;
  type?: CellType;
  textCell?: ITableCellText;
  renderCell?: (row?: DataRowType) => React.JSX.Element;
  dropdownCell?: Omit<ITableCellDropdown, 'row'>;
  thStyle?: CSSProperties;
  tdStyle?: CSSProperties;
  hasBorder?: boolean;
  sortAction?: (key: string) => void;
  hideColumnAt?: number;
  isHidden?: boolean;
  width?: number;
  path?: string;
}

export type ColumnsType = Record<string, ITableColumn>;

export interface ITableRow {
  columns: ColumnsType;
  row: DataRowType;
}

export interface ITable {
  title?: string;
  columns: ColumnsType;
  className?: string;
  data?: DataRowType[];
  tableName?: string;
  addRow?: (row?: DataRowType) => void;
  searchProps?: string[];
  sortColumn?: string;
  sortDirection?: DirectionType;
  style?: CSSProperties;
  tableHeader?: Element;
  tableBottom?: Element;
  sort?: (data: ITableSort) => void;
  errorMessage?: null | string;
  isFetching?: boolean;
  hasMore?: boolean;
  searchValue?: string;
  changeSearch?: (val: ITableSearch) => void;
  changeSortProps?: (data: ITableSort) => void;
}
