import { format } from 'date-fns';
import { StatusType } from './types';

interface Option {
  id: string;
  name?: string;
  type?: string;
  category?: string;
  color?: string;
}

//to change data into options
export const transformOption = (option: Option, key: keyof Option) => {
  const rawLabel = option[key] ? String(option[key]) : '';
  const formattedLabel = rawLabel.replace(/_/g, ' ');
  const capitalizedLabel =
    formattedLabel.charAt(0).toUpperCase() + formattedLabel.slice(1);
  return {
    label: capitalizedLabel,
    value: option.id,
  };
};

export const getStatusColor = (status: StatusType) => {
  switch (status) {
    case 'AD':
      return 'linear-gradient(180deg, #DC69AE 0%, #E95252 100%)';
    case 'SD':
      return 'linear-gradient(180deg, #B6DC69 0%, #57DB7A 100%)';
    default:
      return 'black';
  }
};

//date format
export function formatDate(dateInput?: string | number | Date): string {
  if (!dateInput) return 'N/A';

  const date = new Date(dateInput);
  if (isNaN(date.getTime())) return 'N/A';

  return format(date, 'eee, dd/MM/yyyy HH:mm:ss');
}

export function getDay(dateInput?: string | number | Date): string {
  if (!dateInput) return 'N/A';

  const date = new Date(dateInput);
  if (isNaN(date.getTime())) return 'N/A';

  return format(date, 'eee');
}

//with colors
export const priorityData = [
  { id: 1, name: 'Low', color: '#6396E5' },
  { id: 2, name: 'Medium', color: '#FEBA30' },
  { id: 3, name: 'High', color: '#E95252' },
];

export const snoozeData = [
  { id: 1, name: '15m' },
  { id: 2, name: '30m' },
  { id: 3, name: '1h' },
];
