import React, { useState, useEffect } from 'react';
import classNames from 'classnames/bind';
import TextItem from 'components/items/TextItem';
import CustomDropdown from 'components/enhancers/CustomDropdown';
import CustomIcon from 'components/items/CustomIcon';
import ModuleButton from 'components/items/ModuleButton';
import { FaAngleDown } from 'react-icons/fa';
import styleIdentifiers from './moduleDropActions.scss';

const styles = classNames.bind(styleIdentifiers);

const ActionButton = props => {
  const { label, active, buttonClassName, buttonComponent, color } = props;

  if (buttonComponent)
    return (
      <ModuleButton
        iconClassName={styles('icon-right', active && 'icon-active')}
        iconRight={<FaAngleDown />}
        noMargin
        label={label}
        color={color}
        noShadow
      />
    );

  return (
    <div className={styles('action-button', buttonClassName)}>
      <TextItem path={label} />
      <CustomIcon className={styles('icon', active && 'active')} icon="angle-down" />
    </div>
  );
};

const EnhancedDropdown = CustomDropdown(ActionButton);

export interface StateProps {}

export interface DispatchProps {}

export interface OwnProps {}

export type ModuleDropActionsProps = StateProps & DispatchProps & OwnProps;

const ModuleDropActions = (props: ModuleDropActionsProps) => {
  const {
    label,
    className,
    buttonClassName,
    actions,
    children,
    buttonComponent,
    color,
    ...rest
  } = props;

  return (
    <EnhancedDropdown
      noArrow
      className={styles('ModuleDropActions', className)}
      contentClass={styles('content-drop')}
      label={label}
      buttonClassName={buttonClassName}
      buttonComponent={buttonComponent}
      color={color}
      toggleContent
    >
      {/* <div className={styles('label')}>
        <CustomIcon icon="check" className={styles('label-icon')} />
        <TextItem path={label} />
      </div> */}
      {actions &&
        actions.map((item, key) => (
          <div className={styles('item')} onClick={() => item.action(rest)} key={key}>
            <TextItem tag="none" path={item.label || item.title} />
          </div>
        ))}
      {!actions && children}
    </EnhancedDropdown>
  );
};

export default ModuleDropActions;
