import moment from "moment";

export const picker = {
  本日: [moment(), moment()],
  近7日: [moment().subtract(7, "d"), moment()],
  近14日: [moment().subtract(14, "d"), moment()],
  近30日: [moment().subtract(30, "d"), moment()],
  上季度: [
    moment()
      .subtract(3, "month")
      .startOf("month"),
    moment().startOf("month"),
  ],
};

export const pickerText = {
  today: "今天",
  week: "一周前",
  month: "一月前",
  three_month: "3个月前",
};

/**
 * 日期picker range可自定义添加
 * @methods add("本周", [moment(), moment()])
 * @methods pick(["today", "week"])
 */
class RangePicker implements RangePickerClass {
  private config: Record<string, moment.Moment[]>;

  constructor() {
    this.config = Object.create({});
  }

  add(text: string, range: moment.Moment[]) {
    this.config[text] = range;
    return this;
  }

  pick(range: string[]) {
    range.forEach((r: string) => {
      // const text = (<Record<string, string>>pickerText)[r];
      this.config[r] = (picker as Record<string, moment.Moment[]>)[r];
    });

    return this;
  }

  getRange() {
    return this.config;
  }
}

export default new RangePicker();
