import { Not } from '../../types';
import { IconName } from '../Icons';
import { ConfirmAction, DefaultHandler, LinkAction } from '../models';

export type ActionData<THandler = DefaultHandler> =
  | ContextActionData<THandler>
  | NavigationActionData;

/**
 * Properties necessary for context type action
 * to render an element with JS handler
 * and specified confirmation mode for click event
 */
export interface ContextActionData<THandler = DefaultHandler>
  extends ActionBaseData,
    ConfirmAction,
    HandledAction<THandler>,
    Not<LinkAction> {}

/**
 * Properties necessary for navigation type action
 * to render an anchor tag
 */
export interface NavigationActionData
  extends ActionBaseData,
    LinkAction,
    Not<ConfirmAction>,
    Not<HandledAction<unknown>> {}

export interface HandledAction<THandler> {
  /** Callback emitted when a user clicks on the Action. */
  onActionSelected: THandler;
}

interface ActionBaseData {
  /** The label of the action. */
  label: string;
  /** Optional icon (default: 'IconName.ChevronRight') */
  icon?: IconName;
  /** Renders an un-clickable button if true. */
  isDisabled?: boolean;
}
