import React from 'react';
import PropTypes from 'prop-types';
import { Manager } from 'react-popper';
import classnames from 'classnames';
import { InstanceQuickviewDot } from './InstanceQuickviewDot';

const propTypes = {
  /**
   * The component used for the root node.
   * Either a string to use a DOM element or a component.
   */
  tag: PropTypes.elementType,
  defaultClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
  className: PropTypes.string,
  instanceInfos: PropTypes.arrayOf(
    PropTypes.shape({
      main: PropTypes.string,
      secondary: PropTypes.string,
    })
  ),
  status: PropTypes.oneOf(['awaiting', 'requested', 'queued', 'running', 'succeeded', 'stopping', 'stopped', 'skipped', 'failed']).isRequired,
};

const defaultProps = {
  tag: 'span',
  defaultClassName: 'sui-prj-instance-quickview__item',
  className: '',
  instanceInfos: { name: '', duration: '' },
};

export const InstanceQuickviewItemStack = (props) => {
  const {
    tag: Tag,
    defaultClassName,
    className,
    status,
    instanceInfos,
    ...attributes
  } = props;

  const classes = classnames(
    defaultClassName,
    status ? `as--${status}` : '',
    className
  );

  return (
    <Manager>
      <Tag {...attributes} className={classes}>
        <InstanceQuickviewDot className="as--stack" status={status} instanceInfos={instanceInfos} isStack />
      </Tag>
    </Manager>
  );
};

InstanceQuickviewItemStack.propTypes = propTypes;
InstanceQuickviewItemStack.defaultProps = defaultProps;
