import { EventType } from '@/types';
import { Calendar1, Clock, MapPin } from 'lucide-vue-next';
import { computed } from 'vue';

export function useEvent(event?: EventType) {
    const eventDates = [
        {
            content: `${event?.date_start} - ${event?.date_end}`,
            icon: Calendar1,
        },
        {
            content: `${event?.time_start} - ${event?.time_end}`,
            icon: Clock,
        },
        {
            content: event?.place,
            icon: MapPin,
        },
    ];

    const filterDates = [
        {
            params: 'Today',
            name: 'Hari Ini',
        },
        {
            params: 'Tomorrow',
            name: 'Besok',
        },
        {
            params: 'Weekend',
            name: 'Akhir Pekan',
        },
        {
            params: 'This Week',
            name: 'Minggu Ini',
        },
        {
            params: 'Next Week',
            name: 'Minggu Depan',
        },
        {
            params: 'This Month',
            name: 'Bulan Ini',
        },
        {
            params: 'Next Month',
            name: 'Bulan Depan',
        },
    ];

    const ticketQuantityTotal = computed(() => {
        return event?.tickets?.reduce((acc, ticket) => acc + Number(ticket.quantity) * Number(ticket.amount_people), 0);
    });

    const ticketPriceTotal = computed(() => {
        return event?.tickets?.reduce((acc, ticket) => {
            return Number(ticket.quantity) * Number(ticket.price) + Number(acc);
        }, 0);
    });

    const ticketParticipantTotal = computed(() => {
        return event?.tickets?.reduce((acc, ticket) => acc + Number(ticket.quantity) * Number(ticket.amount_people), 0);
    });

    return {
        ticketQuantityTotal,
        filterDates,
        eventDates,
        ticketPriceTotal,
        ticketParticipantTotal,
    };
}
