import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
import { parseDate, pickTime } from './helper';

const PickerType = {
  date: 'date',
  datetime: 'datetime',
  datemultiple: 'datemultiple',
  daterange: 'daterange',
  datetimerange: 'datetimerange',
  datemonthrange: 'datemonthrange',
  year: 'year',
  month: 'month',
  quarter: 'quarter'
};
class DatePicker {
  constructor() {
    _defineProperty(this, "name", PickerType.date);
    _defineProperty(this, "confirmLang", 'datePicker.now');
    _defineProperty(this, "placeholderLang", 'datePicker.selectDate');
    _defineProperty(this, "format", 'yyyy-MM-dd');
    _defineProperty(this, "isRange", false);
    _defineProperty(this, "hasTime", false);
  }
  getDateFromStr(val) {
    return new Date(val);
  }
}
class DateMultiplePicker {
  constructor() {
    _defineProperty(this, "name", PickerType.datemultiple);
    _defineProperty(this, "confirmLang", '');
    _defineProperty(this, "placeholderLang", 'datePicker.selectDate');
    _defineProperty(this, "format", 'yyyy-MM-dd');
    _defineProperty(this, "isRange", false);
    _defineProperty(this, "hasTime", false);
  }
  getDateFromStr(val) {
    return new Date(val);
  }
}
class DateTimePicker {
  constructor() {
    _defineProperty(this, "name", PickerType.datetime);
    _defineProperty(this, "confirmLang", 'datePicker.today');
    _defineProperty(this, "placeholderLang", 'datePicker.selectDateTime');
    _defineProperty(this, "format", 'yyyy-MM-dd HH:mm:ss');
    _defineProperty(this, "isRange", false);
    _defineProperty(this, "hasTime", true);
  }
  getDateFromStr(val) {
    return new Date(val);
  }
}
class DateRange {
  getLeftActiveDate(rightActiveDate) {
    const endDate = new Date(rightActiveDate);
    return endDate.setMonth(endDate.getMonth() - 1, 1);
  }
  getRightActiveDate(leftActiveDate) {
    const endDate = new Date(leftActiveDate);
    return endDate.setMonth(endDate.getMonth() + 1, 1);
  }
  isInSamePanel(left, right) {
    const leftDate = parseDate(left);
    const rightDate = parseDate(right);
    return leftDate.year === rightDate.year && leftDate.month === rightDate.month;
  }
  getRangeSelectedDate(date, preDate) {
    return Object.assign(date, pickTime(preDate));
  }
}
class DateRangePicker extends DateRange {
  constructor() {
    super(...arguments);
    _defineProperty(this, "name", PickerType.daterange);
    _defineProperty(this, "confirmLang", '');
    _defineProperty(this, "placeholderLang", ['datePicker.selectStartDate', 'datePicker.selectEndDate']);
    _defineProperty(this, "format", 'yyyy-MM-dd');
    _defineProperty(this, "isRange", true);
    _defineProperty(this, "hasTime", false);
  }
  getDateFromStr(val) {
    return new Date(val);
  }
}
class DateTimeRangePicker extends DateRange {
  constructor() {
    super(...arguments);
    _defineProperty(this, "name", PickerType.datetimerange);
    _defineProperty(this, "confirmLang", '');
    _defineProperty(this, "placeholderLang", ['datePicker.selectStartDateTime', 'datePicker.selectEndDateTime']);
    _defineProperty(this, "format", 'yyyy-MM-dd HH:mm:ss');
    _defineProperty(this, "isRange", true);
    _defineProperty(this, "hasTime", true);
  }
  getDateFromStr(val) {
    return new Date(val);
  }
}
class DateMonthRangePicker {
  constructor() {
    _defineProperty(this, "name", PickerType.datemonthrange);
    _defineProperty(this, "confirmLang", '');
    _defineProperty(this, "placeholderLang", ['datePicker.selectStartDateMonth', 'datePicker.selectEndDateMonth']);
    _defineProperty(this, "format", 'yyyy-MM');
    _defineProperty(this, "isRange", true);
    _defineProperty(this, "hasTime", false);
  }
  getDateFromStr(val) {
    return new Date(val);
  }
  getLeftActiveDate(rightActiveDate) {
    const endDate = new Date(rightActiveDate);
    return endDate.setFullYear(endDate.getFullYear() - 1, 0, 1);
  }
  getRightActiveDate(leftActiveDate) {
    const endDate = new Date(leftActiveDate);
    return endDate.setFullYear(endDate.getFullYear() + 1, 0, 1);
  }
  isInSamePanel(left, right) {
    const leftDate = parseDate(left);
    const rightDate = parseDate(right);
    return leftDate.year === rightDate.year;
  }
  getRangeSelectedDate(date, preDate) {
    return Object.assign(date, pickTime(preDate));
  }
}
class YearPicker {
  constructor() {
    _defineProperty(this, "name", PickerType.year);
    _defineProperty(this, "confirmLang", 'datePicker.currentYear');
    _defineProperty(this, "placeholderLang", 'datePicker.selectYear');
    _defineProperty(this, "format", 'yyyy');
    _defineProperty(this, "isRange", false);
    _defineProperty(this, "hasTime", false);
  }
  getDateFromStr(val) {
    return new Date(val);
  }
}
class MonthPicker {
  constructor() {
    _defineProperty(this, "name", PickerType.month);
    _defineProperty(this, "confirmLang", 'datePicker.currentMonth');
    _defineProperty(this, "placeholderLang", 'datePicker.selectMonth');
    _defineProperty(this, "format", 'yyyy-MM');
    _defineProperty(this, "isRange", false);
    _defineProperty(this, "hasTime", false);
  }
  getDateFromStr(val) {
    return new Date(val);
  }
}
class QuarterPicker {
  constructor() {
    _defineProperty(this, "name", PickerType.quarter);
    _defineProperty(this, "confirmLang", 'datePicker.currentQuarter');
    _defineProperty(this, "placeholderLang", 'datePicker.selectQuarter');
    _defineProperty(this, "format", 'yyyy-QQQ');
    _defineProperty(this, "isRange", false);
    _defineProperty(this, "hasTime", false);
  }
  getDateFromStr(val) {
    const [year, quarter] = val.match(/\d+/g);
    return new Date(Number(year), (Number(quarter) - 1) * 3);
  }
}
function pickerFactory(type) {
  switch (type) {
    case PickerType.date:
      return new DatePicker();
    case PickerType.datetime:
      return new DateTimePicker();
    case PickerType.datemultiple:
      return new DateMultiplePicker();
    case PickerType.daterange:
      return new DateRangePicker();
    case PickerType.datetimerange:
      return new DateTimeRangePicker();
    case PickerType.datemonthrange:
      return new DateMonthRangePicker();
    case PickerType.year:
      return new YearPicker();
    case PickerType.month:
      return new MonthPicker();
    case PickerType.quarter:
      return new QuarterPicker();
    default:
      return new DatePicker();
  }
}

export { DateMonthRangePicker, DateMultiplePicker, DatePicker, DateRangePicker, DateTimePicker, DateTimeRangePicker, MonthPicker, PickerType, QuarterPicker, YearPicker, pickerFactory };
