import React from 'react';
import { Nav, Row, Col, Drawer, Message, Divider, Tooltip, Whisper, Button, Placeholder, Stack, Notification, useToaster, Progress } from 'rsuite';
import { capitalizeFirstLetter } from '@/lib/utils/string';
import { DrawerRowData, UserInfo } from '@/lib/utils/types';
import { getPlanDetails } from '@/lib/utils/getPlanDetails';
import { useAtom } from 'jotai';
import { userAtom } from '@/lib/context/user';
import { TypeAttributes } from 'rsuite/esm/@types/common';


interface CalloutProps {
  rowData: DrawerRowData
}

const Callout: React.FC<CalloutProps> = (props) => {
  const [_userAuth] = useAtom(userAtom);
  const user = _userAuth as UserInfo; // TODO handle properly
  const userPlan = getPlanDetails(user.plan);
  const { rowData } = props;

  let msg = '';
  let list = [];
  let status: TypeAttributes.Status = 'info'

  function setStatusLevel(lvl: TypeAttributes.Status) {
    const order = ['info', 'warning', 'error'];
    const idx = order.indexOf(lvl);
    const currentIdx = order.indexOf(status);

    if (idx > currentIdx) {
      status = lvl;
    }
  }

  if (rowData.nbRows > userPlan.nbRows) {
    setStatusLevel('error');
    list.push(' • Your document has more than 1000 rows. This is beyond your quota limit. Extra rows will be ignored.');
  } else if (rowData.nbRows === userPlan.nbRows) {
    setStatusLevel('warning');
    list.push(' • Your document has 1000 rows. This is the maximum number of rows allowed in your plan. Extra rows will be ignored.');
  }

  if (rowData.nbColumns > userPlan.nbColumns) {
    setStatusLevel('error');
    list.push(' • Your document has more than 10 columns. This is beyond your quota limit. Extra columns will be ignored.');
  } else if (rowData.nbColumns === userPlan.nbColumns) {
    setStatusLevel('warning');
    list.push(' • Your document has 10 columns. This is the maximum number of columns allowed in your plan. Extra columns will be ignored.');
  }

  if (rowData.size > userPlan.maxSize) {
    setStatusLevel('error');
    list.push(' • Your document size is beyond your quota limit. The document will not be available');
  } else if (rowData.size === userPlan.maxSize) {
    setStatusLevel('warning');
    list.push(' • Your document size is at the maximum allowed in your plan. The document will not be available');
  }

  msg = list.join('\n');


  return (
    <Message showIcon type={status} header={capitalizeFirstLetter(status)}>
      {list.map((item, idx) => <p key={idx}>{item}</p>)}
    </Message>
  )
}

export default Callout;