import React, { useCallback, useState } from "react";
import BreadcrumbComBS from "../breadcrumb/BreadcrumbComBS";
import EventCalendar from "./EventCalendar";


export default function Calendar(){

    const [draggedEvent, setDraggedEvent] = useState('undroppable')
    const handleDragStart = useCallback((event) => setDraggedEvent(event), [])

    // const dummyEvents = [
    //     {id: '1', title: 'Family Vacation', color: 'fc-event-primary', start: new Date('2024-12-18'), end: new Date('2024-12-18'), isAllDay: false, resource: ''},
    //     {id: '2', title: 'Meeting In Office', color: 'fc-event-warning', start: new Date('2024-12-19'), end: new Date('2024-12-19'), isAllDay: false, resource: ''},
    //     {id: '3', title: 'Client Call', color: 'fc-event-danger', start: new Date('2024-12-20'), end: new Date('2024-12-20'), isAllDay: false, resource: ''},
    //     {id: '4', title: 'Interview', color: 'fc-event-success', start: new Date('2024-12-21'), end: new Date('2024-12-21'), isAllDay: false, resource: ''}
    // ]
    const dummyEvents = [
        {id: '1', title: 'Family Vacation', color: 'fc-event-primary', isAllDay: false},
        {id: '2', title: 'Meeting In Office', color: 'fc-event-warning', isAllDay: false},
        {id: '3', title: 'Client Call', color: 'fc-event-danger', isAllDay: false},
        {id: '4', title: 'Interview', color: 'fc-event-success', isAllDay: false}
    ]

    return(
        <>
            <BreadcrumbComBS title='Calendar' paths={['Dashboard', 'Calendar']} />
            <div className="row">
                <div className="col-lg-12">
                    <div className="card card-statistics">
                        <div className="card-header">
                            <div className="card-heading">
                                <h4 className="card-title">Event Calendar</h4>
                            </div>
                        </div>
                        <div className="card-body">
                            <div className="row">
                                <div className="col-xl-3">
                                    <div id="external-events">
                                        <button className="btn btn-primary btn-block" data-bs-toggle="modal" data-bs-target="#eventModal">
                                            Add New Event
                                        </button>
                                        <p className="mt-3">
                                            Drag and drop your event or click in the calendar.
                                        </p>
                                        {dummyEvents.map((item, index) => (
                                            <div key={index} className={`fc-event ${item.color}`} data-color={`${item.color}`} 
                                                draggable="true"
                                                onDragStart={() =>
                                                handleDragStart({...item})
                                                }
                                            >
                                                <span></span> {item.title}
                                            </div>
                                        ))}
                                        <div className="form-check">
                                            <input className="form-check-input" type="checkbox" value=""
                                                   id="defaultCheck1" />
                                                <label className="form-check-label" htmlFor="defaultCheck1">
                                                    Remove After Drop
                                                </label>
                                        </div>
                                    </div>
                                </div>
                                <div className="col-xl-9">
                                    <div className="event-calendar">
                                        <EventCalendar draggedEvent={draggedEvent} setDraggedEvent={setDraggedEvent} />
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>

            {/* Event Modal */}
            <div className="modal fade" id="eventModal" tabIndex="-1" role="dialog">
                <div className="modal-dialog modal-dialog-centered" role="document">
                    <div className="modal-content">
                        <div className="modal-header">
                            <h5 className="modal-title" id="verticalCenterTitle">Add New Event</h5>
                            <button type="button" className="close" data-bs-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div className="modal-body">
                            <form>
                                <div className="form-group">
                                    <label>Event Name</label>
                                    <input type="email" className="form-control" id="eventname" />
                                </div>
                                <div className="form-group">
                                    <label>Choose Event Color</label>
                                    <select className="form-control">
                                        <option>Primary</option>
                                        <option>Warning</option>
                                        <option>Success</option>
                                        <option>Danger</option>
                                    </select>
                                </div>

                            </form>
                        </div>
                        <div className="modal-footer">
                            <button type="button" className="btn btn-danger" data-bs-dismiss="modal">Close</button>
                            <button type="button" className="btn btn-success">Save changes</button>
                        </div>
                    </div>
                </div>
            </div>
        </>
    )
}