import React from 'react';
import PropTypes from 'prop-types';
import { useTheme } from '@mui/material/styles';

import { Chip } from '@/mui/components';

function LiveCell({ startTime = 0, endTime = 0, ...props }) {
  const theme = useTheme();
  const now = Date.now();
  let status = 'Live';

  if (props.status !== -1 && now < startTime) {
    status = 'Ready';
  } else if (
    (props.status !== -1 && now > endTime && !props.recurrent) ||
    (props.recurrent && props.recurrentEndDate <= Date.now())
  ) {
    status = 'Ended';
  } else if (props.status === -1) {
    status = 'Archived';
  }

  return (
    <Chip
      variant="filled"
      label={status}
      shape="rounded"
      size="small"
      style={{
        color: theme.palette.getContrastText(props.indicationColor),
        backgroundColor: props.indicationColor,
      }}
    />
  );
}

LiveCell.propTypes = {
  indicationColor: PropTypes.string.isRequired,
  startTime: PropTypes.number,
  endTime: PropTypes.number,
  status: PropTypes.number.isRequired,
  recurrent: PropTypes.bool.isRequired,
  recurrentEndDate: PropTypes.number.isRequired,
};

export default LiveCell;
