import StatusBadge from '@/components/helper/StatusBadge';

import { BaseApproval } from '@/types/api/api-general';
import { Color } from '@/types/theme';

interface RealizationStatusBadgeProps {
  approval?: BaseApproval;
}

const RealizationStatusBadge = ({ approval }: RealizationStatusBadgeProps) => {
  const isLatestApprovalRejected = approval?.action === 'REJECTED';

  const isExpenseRealized = approval?.step_number && approval.step_number >= 5;

  const realizationStatus = isExpenseRealized
    ? 'Sudah Realisasi'
    : 'Belum Realisasi';

  let realizationStatusBadgeColor: Color = isExpenseRealized
    ? 'success'
    : 'warning';

  if (isLatestApprovalRejected) {
    realizationStatusBadgeColor = 'error';
  }

  return (
    <StatusBadge
      color={realizationStatusBadgeColor}
      text={isLatestApprovalRejected ? 'Ditolak' : realizationStatus}
      className={{
        badge: 'whitespace-nowrap max-w-max w-fit',
      }}
    />
  );
};

export default RealizationStatusBadge;
