import { Clock, CheckCircle, XCircle, DoorOpen, DoorClosed, AlertCircle } from 'lucide-react';
import type { Booking } from '../../features/bookings/services/bookingService';

/**
 * Status configuration for booking status badges
 */
export interface StatusConfig {
  icon: React.ComponentType<{ className?: string }>;
  color: string;
  text: string;
}

/**
 * Get status configuration for a booking status
 */
export const getBookingStatusConfig = (status: string): StatusConfig => {
  switch (status) {
    case 'pending':
      return {
        icon: Clock,
        color: 'bg-yellow-100 text-yellow-800',
        text: 'Pending confirmation',
      };
    case 'confirmed':
      return {
        icon: CheckCircle,
        color: 'bg-green-100 text-green-800',
        text: 'Confirmed',
      };
    case 'cancelled':
      return {
        icon: XCircle,
        color: 'bg-red-100 text-red-800',
        text: 'Cancelled',
      };
    case 'checked_in':
      return {
        icon: DoorOpen,
        color: 'bg-blue-100 text-blue-800',
        text: 'Checked in',
      };
    case 'checked_out':
      return {
        icon: DoorClosed,
        color: 'bg-gray-100 text-gray-800',
        text: 'Checked out',
      };
    default:
      return {
        icon: AlertCircle,
        color: 'bg-gray-100 text-gray-800',
        text: status,
      };
  }
};

/**
 * Check if a booking can be cancelled
 */
export const canCancelBooking = (booking: Booking): boolean => {
  return booking.status === 'pending';
};

/**
 * Calculate number of nights for a booking
 */
export const calculateNights = (checkInDate: string, checkOutDate: string): number => {
  const checkIn = new Date(checkInDate);
  const checkOut = new Date(checkOutDate);
  const nights = Math.ceil((checkOut.getTime() - checkIn.getTime()) / (1000 * 60 * 60 * 24));
  return nights > 0 ? nights : 1;
};

