package com.mycompany.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Style;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.smartgwt.client.widgets.calendar.Calendar;
import com.smartgwt.client.widgets.calendar.CalendarEvent;
import com.google.gwt.i18n.client.DateTimeFormat;

import java.util.Date;

public class CalendarTest implements EntryPoint {
  private Calendar calendar = new Calendar();
  private final String timestampPattern = "EEE LLL dd HH:mm:ss Z yyyy";
  private final DateTimeFormat dateParser = DateTimeFormat.getFormat(timestampPattern);

  public CalendarTest() {
    calendar.setDisableWeekends(false);
    calendar.setShowAddEventButton(false);
    calendar.setCanEditEvents(true);
    calendar.setEventAutoArrange(true);
    calendar.setEventOverlap(true);
    calendar.setEventOverlapPercent(5);
    calendar.setEventOverlapIdenticalStartTimes(true);
    calendar.setSize(400 + Style.Unit.PX.getType(), 200 + Style.Unit.PX.getType());
    calendar.setShowQuickEventDialog(false);
    calendar.setShowOtherDays(false);
  }

  public void setData(CalendarEvent[] data) {
    if (data == null) {
      calendar.setData(new CalendarEvent[0]);
    } else {
      calendar.setData(data);
    }
  }

  public Date getDate(String date) {
    return dateParser.parse(date);
  }

  public void onModuleLoad() {
    CalendarEvent [] data = new CalendarEvent[100];

    CalendarEvent event1 = new CalendarEvent(-1, "28 Schedules", "Sep 6, 2021 2:00:00 PM - Sep 18, 2021 12:00:00 AM test1<br><br>Sep 7, 2021 2:00:00 PM - Sep 19, 2021 12:00:00 AM test1<br><br>Sep 8, 2021 2:00:00 PM - Sep 20, 2021 12:00:00 AM test1<br><br>Sep 9, 2021 2:00:00 PM - Sep 21, 2021 12:00:00 AM test1<br><br>Sep 10, 2021 2:00:00 PM - Sep 22, 2021 12:00:00 AM test1<br><br>Sep 16, 2021 12:00:00 AM - Sep 17, 2021 2:00:00 AM test10<br><br>Sep 16, 2021 12:00:00 AM - Sep 17, 2021 2:00:00 AM test11<br><br>Sep 24, 2020 11:00:00 AM - Sep 24, 2021 11:00:00 AM test12<br><br>Dec 17, 2020 5:41:00 PM - Dec 17, 2021 12:00:00 AM test51<br><br>Dec 17, 2020 5:26:00 PM - Dec 17, 2021 12:00:00 AM test17<br><br>Dec 17, 2020 5:26:00 PM - Dec 17, 2021 12:00:00 AM test14<br><br>Dec 17, 2020 5:26:00 PM - Dec 17, 2021 12:00:00 AM test75<br><br>Dec 17, 2020 5:26:00 PM - Dec 17, 2021 12:00:00 AM test62<br><br>Dec 17, 2020 5:11:00 PM - Dec 17, 2021 12:00:00 AM test13<br><br>Dec 17, 2020 5:11:00 PM - Dec 17, 2021 12:00:00 AM test15<br><br>Dec 17, 2020 5:11:00 PM - Dec 17, 2021 12:00:00 AM test78<br><br>Dec 17, 2020 5:11:00 PM - Dec 17, 2021 12:00:00 AM test16<br><br>Dec 17, 2020 5:11:00 PM - Dec 17, 2021 12:00:00 AM test61<br><br>Dec 17, 2020 5:11:00 PM - Dec 17, 2021 12:00:00 AM test73<br><br>Dec 17, 2020 5:26:00 PM - Dec 17, 2021 12:00:00 AM test70<br><br>Feb 2, 2021 6:41:00 PM - Dec 17, 2021 12:00:00 AM test51<br><br>Feb 2, 2021 6:41:00 PM - Dec 17, 2021 12:00:00 AM test17<br><br>Feb 2, 2021 6:41:00 PM - Dec 17, 2021 12:00:00 AM test13<br><br>Feb 2, 2021 6:41:00 PM - Dec 17, 2021 12:00:00 AM test15<br><br>Feb 2, 2021 6:41:00 PM - Dec 17, 2021 12:00:00 AM test16<br><br>Feb 2, 2021 6:41:00 PM - Dec 17, 2021 12:00:00 AM test61<br><br>Feb 2, 2021 6:41:00 PM - Dec 21, 2021 12:00:00 AM test73<br><br>Sep 17, 2021 2:00:00 AM - Sep 18, 2021 2:00:00 AM dummy3<br><br>",
            getDate("Fri Sep 17 00:00:00 GMT+530 2021"), getDate("Sat Sep 18 00:00:00 GMT+530 2021"));
    data[0] = event1;

    CalendarEvent event2 = new CalendarEvent(-1, "dummy2", "", getDate("Fri Sep 17 00:00:00 GMT+530 2021"), getDate("Sat Sep 18 00:00:00 GMT+530 2021"));
    data[1]= event2;

    CalendarEvent event3 = new CalendarEvent(-1, "test-lgpl-1", "", getDate("Fri Sep 17 00:00:00 GMT+530 2021"), getDate("Sat Sep 18 00:00:00 GMT+530 2021"));
    data[3] = event3;

    CalendarEvent event4 = new CalendarEvent(-1, "smt-5", "", getDate("Fri Sep 17 02:00:00 GMT+530 2021"), getDate("Sat Sep 18 00:00:00 GMT+530 2021"));
    data[4] = event4;

    CalendarEvent event5 = new CalendarEvent(-1, "test88", "", getDate("Fri Sep 17 04:00:00 GMT+530 2021"), getDate("Fri Sep 17 11:00:00 GMT+530 2021"));
    data[5] = event5;

    CalendarEvent event6 = new CalendarEvent(-1, "test89", "", getDate("Fri Sep 17 04:00:00 GMT+530 2021"), getDate("Fri Sep 17 11:00:00 GMT+530 2021"));
    data[6] = event6;

    CalendarEvent event7 = new CalendarEvent(-1, "2 Schedules", "6:00 PM test41<br><br>6:30 PM test42<br><br>", getDate("Fri Sep 17 18:00:00 GMT+530 2021"), getDate("Fri Sep 17 18:30:00 GMT+530 2021"));
    data[7]= event7;

    CalendarEvent event8 = new CalendarEvent(-1, "2 Schedules", "7:00 PM test43<br><br>7:30 PM test44<br><br>", getDate("Fri Sep 17 19:00:00 GMT+530 2021"), getDate("Fri Sep 17 19:30:00 GMT+530 2021"));
    data[8] = event8;

    CalendarEvent event9 = new CalendarEvent(-1, "2 Schedules", "8:00 PM test45<br><br>8:30 PM test46<br><br>", getDate("Fri Sep 17 20:00:00 GMT+530 2021"), getDate("Fri Sep 17 20:30:00 GMT+530 2021"));
    data[9] = event9;

    CalendarEvent event10 = new CalendarEvent(-1, " 2 Schedules", "9:00 PM test47<br><br>9:30 PM test48<br><br>", getDate("Fri Sep 17 21:00:00 GMT+530 2021"), getDate("Fri Sep 17 21:30:00 GMT+530 2021"));
    data[10] = event10;

    setData(data);

    RootLayoutPanel.get().add(calendar);
  }
}