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

export interface ITableCellDropdown {
  row: DataRowType;
  title?: string;
  icon?: React.JSX.Element;
  Component: (props: any) => React.JSX.Element; //eslint-disable-line
  keys: string[];
  action?: (key: string) => void;
  componentProps?: Record<string, unknown>;
}

export const TableCellDropdown = ({title = '', Component, keys, action, componentProps, row}: ITableCellDropdown): React.JSX.Element => {
  const data = {} as Record<string, unknown>;

  keys.forEach(value => {
    data[value] = row[value];
  });

  if (data.showDropdown !== undefined) {
    return data.showDropdown ? <Component title={title} data={data} action={action} {...componentProps} /> : null;
  }

  return <Component title={title} data={data} action={action} {...componentProps} />;
};
