import React from 'react';
import {
  TableActionCellMainAction as TableActionCellMainActionWds,
  TableActionCellPrimaryAction as TableActionCellPrimaryActionWds,
  TableActionCellProps,
  TableActionCellSecondaryAction,
  TableActionCellSecondaryDivider,
} from '@wix/design-system';
import { FiltersMap } from '@wix/bex-core';
import { ActionCellAPI as ActionCellAPIType } from '../../state';

export type SecondaryActionAction = TableActionCellSecondaryAction & {
  biName?: string;
  componentId?: string;
  appId?: string;
  divider?: false;
};

export type SecondaryAction =
  | SecondaryActionAction
  | TableActionCellSecondaryDivider;

export type ActionCellAPI<T, F extends FiltersMap> = ActionCellAPIType<T, F>;
export type TableActionCellMainAction = TableActionCellMainActionWds & {
  biName?: string;
  disabledMessage?: string;
};
export type TableActionCellPrimaryAction = TableActionCellPrimaryActionWds & {
  biName?: string;
  disabledMessage?: string;
};

export interface ActionCellProps
  extends Omit<TableActionCellProps, 'primaryAction' | 'secondaryActions'> {
  /**
   * Whether the secondary actions menu (3-dots) is disabled. When `true`, a disabled icon button replaces the menu.
   * @external
   */
  secondaryMenuDisabled?: boolean;

  /**
   * Tooltip content shown on hover when the secondary actions menu is disabled.
   * @external
   */
  secondaryMenuDisabledTooltip?: React.ReactNode;

  /**
   * Primary call to action for each item in a table. Controls the behavior and appearance of the primary action. <br>
   * Can be a single action object or an array of actions. When an array is provided, the first action becomes the primary action and the rest are added to secondary actions. <br>
   * Supported parameters:
   *  + `disabledMessage`: Message to show when the action is disabled. Relevant only to grid.
   *  + `text`: Specifies action label.
   *  + `skin`: Deprecated property that was previously used to control the visual appearance of a button. It has been replaced by the visibility property, which switches skin properties automatically based on visibility options.
   *  + `onClick`: Defines a callback function which is called on button click.
   *  + `disabled`: [bool] Whether user interactions are disabled.
   *  + `prefixIcon`: Icon in front of a button label.
   *  + `suffixIcon`: Icon after a button label.
   *  + `as`: Renders button as another component or a DOM tag.
   *  + `visibility`: Specifies whether the primary action button is visible. When the value is set to `'onHover'`, the button is only visible when the mouse hovers over it, and it appears as a primary button. When the value is set to `'always'`, the button is always visible and appears as a secondary button.
   * 
   * This prop extends the `primaryAction` prop in Wix Design System's [TableActionCellProp](https://www.docs.wixdesignsystem.com/?path=/story/components-lists-table--tableactioncell) component.   

   * @external
   */
  primaryAction?: TableActionCellPrimaryAction | TableActionCellMainAction[];
  /**
   * Secondary CTAs for each item in a table. Controls the behavior and appearance of the secondary actions. <br>
   * Supported parameters:
   *  + `deleteSecondaryAction:` A function that adds a "Delete" action as a secondary action.
   *  + `text`: Specifies action label to be shown in the tooltip or popover menu.
   *  + `icon`: Action icon.
   *  + `onClick`: Defines a callback function which is called on button click.
   *  + `subtitle`: Action subtitle.
   *  + `disabled`: [bool] Whether user interactions are disabled.
   *  + `dataHook`: A data-hook HTML attribute to be used in the tests.
   *  + `disabledDescription`: [string] Text to display in tooltip when action is visible and disabled.
   *  + `tooltipProps`: Controls the tooltip appearance.
   *  + `skin`: Controls the skin of the item.
   *
   * OR Divider object containing
   *  + `divider`: A divider between the action items in popover menu.
   *
   * This prop extends the `primaryAction` prop in Wix Design System's [TableActionCellProp](https://www.docs.wixdesignsystem.com/?path=/story/components-lists-table--tableactioncell) component.
   * @external
   */
  secondaryActions?: SecondaryAction[];

  /**
   * This ID is used to specify the target container for [dashboard menu plugin](./?path=/story/features-enrich-slots-and-plugins--slots-and-plugins) items.
   */
  containerId?: string;
}

export type ActionCell<T, F extends FiltersMap> =
  | ActionCellProps
  | ((item: T, index: number, api: ActionCellAPI<T, F>) => ActionCellProps);
