import PillBadge from '@/components/PillBadge';

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

interface RealizationStatusBadgeProps {
  approval?: BaseApproval;
}

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

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

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

  let realizationStatusPillBadgeColor:
    | 'yellow'
    | 'green'
    | 'gray'
    | 'red'
    | 'purple'
    | 'blue' = isExpenseRealized ? 'green' : 'yellow';

  if (isLatestApprovalRejected) {
    realizationStatusPillBadgeColor = 'red';
  }

  return (
    <PillBadge
      content={isLatestApprovalRejected ? 'Ditolak' : realizationStatus}
      color={realizationStatusPillBadgeColor}
      className='text-xs'
    />
  );
};

export default RealizationStatusBadge;
