import { createVNode as _createVNode } from "vue";
import "./styles/date-range-picker-panel.css";
import { computed, provide, ref } from "vue";
import { defineComponent } from "../../utils";
import { createDate, defaultDateFormat } from "../../composables/date";
import { useProxiedModel } from "../../composables/proxied-model";
import { Card } from "../card";
import { DatePickerPanel } from "./date-picker-panel";
import { DateRangeKey } from "./key";
const DateRangePickerPanel = defineComponent({
  name: "VeDateRangePickerPanel",
  props: {
    /**
     * @zh 时间格式化
     */
    format: {
      type: [Array, Function],
      default: () => ["YYYY-MM-DD", "YYYY-MM-DD"]
    },
    /**
     * @zh 时间值
     */
    modelValue: {
      type: Array,
      default: () => []
    }
  },
  emits: {
    "update:modelValue": (_value) => true,
    "preview": (_value) => true
  },
  setup(props, {
    emit
  }) {
    const model = useProxiedModel(props, "modelValue");
    const selected = computed(() => {
      return model.value.map(createDate).sort((a, b) => a.valueOf() - b.valueOf());
    });
    const isPreview = ref(false);
    function formatter(dates) {
      return typeof props.format === "function" ? props.format(dates) : dates.map((date, i) => date.format(props.format[i]));
    }
    function preview(value) {
      isPreview.value = value;
      emit("preview", isPreview.value);
    }
    function select(value) {
      const length = model.value.length;
      if (length === 1 || isPreview.value && length > 0) {
        if (model.value[1] === value)
          return;
        model.value = formatter([model.value[0], value].map(createDate));
      } else {
        if (model.value[0] === value)
          return;
        model.value = formatter([value].map(createDate));
      }
    }
    function inRange(value) {
      if (selected.value.length < 2)
        return false;
      return selected.value[0].valueOf() <= value && selected.value[1].valueOf() >= value;
    }
    provide(DateRangeKey, {
      selected,
      select,
      inRange,
      preview,
      isPreview
    });
    return () => {
      return _createVNode(Card, {
        "class": "ve-date-range-picker-panel"
      }, {
        default: () => [_createVNode(DatePickerPanel, {
          "format": defaultDateFormat,
          "modelValue": createDate().startOf("month").format(),
          "max": createDate().startOf("month").format()
        }, null), _createVNode(DatePickerPanel, {
          "format": defaultDateFormat,
          "modelValue": createDate().add(1, "month").startOf("month").format(),
          "min": createDate().add(1, "month").startOf("month").format()
        }, null)]
      });
    };
  }
});
export {
  DateRangePickerPanel
};
//# sourceMappingURL=date-range-picker-panel.mjs.map
