{"version":3,"file":"use-range-picker.js","sources":["../../../../../../../packages/components/date-picker/src/composables/use-range-picker.ts"],"sourcesContent":["import { getCurrentInstance, inject, ref, unref, watch } from 'vue'\nimport { isArray } from '@element-plus/utils'\nimport { useLocale, useNamespace } from '@element-plus/hooks'\nimport { getDefaultValue, isValidRange } from '../utils'\nimport { ROOT_PICKER_INJECTION_KEY } from '../constants'\nimport { useShortcut } from './use-shortcut'\n\nimport type { Ref } from 'vue'\nimport type { Dayjs } from 'dayjs'\nimport type { PanelRangeSharedProps, RangeState } from '../props/shared'\nimport type { DefaultValue } from '../utils'\n\ntype UseRangePickerProps = {\n onParsedValueChanged: (\n minDate: Dayjs | undefined,\n maxDate: Dayjs | undefined\n ) => void\n defaultValue: Ref\n leftDate: Ref\n rightDate: Ref\n unit: 'month' | 'year'\n}\n\nexport const useRangePicker = (\n props: PanelRangeSharedProps,\n {\n defaultValue,\n leftDate,\n rightDate,\n unit,\n\n onParsedValueChanged,\n }: UseRangePickerProps\n) => {\n const { emit } = getCurrentInstance()!\n\n const { pickerNs } = inject(ROOT_PICKER_INJECTION_KEY)!\n const drpNs = useNamespace('date-range-picker')\n const { t, lang } = useLocale()\n const handleShortcutClick = useShortcut(lang)\n const minDate = ref()\n const maxDate = ref()\n const rangeState = ref({\n endDate: null,\n selecting: false,\n })\n\n const handleChangeRange = (val: RangeState) => {\n rangeState.value = val\n }\n\n const handleRangeConfirm = (visible = false) => {\n const _minDate = unref(minDate)\n const _maxDate = unref(maxDate)\n\n if (isValidRange([_minDate, _maxDate])) {\n emit('pick', [_minDate, _maxDate], visible)\n }\n }\n\n const onSelect = (selecting: boolean) => {\n rangeState.value.selecting = selecting\n if (!selecting) {\n rangeState.value.endDate = null\n }\n }\n\n const onReset = (parsedValue: PanelRangeSharedProps['parsedValue']) => {\n if (isArray(parsedValue) && parsedValue.length === 2) {\n const [start, end] = parsedValue\n minDate.value = start\n leftDate.value = start\n maxDate.value = end\n onParsedValueChanged(unref(minDate), unref(maxDate))\n } else {\n restoreDefault()\n }\n }\n\n const restoreDefault = () => {\n const [start, end] = getDefaultValue(unref(defaultValue), {\n lang: unref(lang),\n unit,\n unlinkPanels: props.unlinkPanels,\n })\n minDate.value = undefined\n maxDate.value = undefined\n leftDate.value = start\n rightDate.value = end\n }\n\n watch(\n defaultValue,\n (val) => {\n if (val) {\n restoreDefault()\n }\n },\n { immediate: true }\n )\n\n watch(() => props.parsedValue, onReset, { immediate: true })\n\n return {\n minDate,\n maxDate,\n rangeState,\n lang,\n ppNs: pickerNs,\n drpNs,\n\n handleChangeRange,\n handleRangeConfirm,\n handleShortcutClick,\n onSelect,\n onReset,\n t,\n }\n}\n"],"names":["getCurrentInstance","inject","ROOT_PICKER_INJECTION_KEY","useNamespace","useLocale","useShortcut","ref","unref","isValidRange","isArray","getDefaultValue","watch"],"mappings":";;;;;;;;;;;;;;AAMY,MAAC,cAAc,GAAG,CAAC,KAAK,EAAE;AACtC,EAAE,YAAY;AACd,EAAE,QAAQ;AACV,EAAE,SAAS;AACX,EAAE,IAAI;AACN,EAAE,oBAAoB;AACtB,CAAC,KAAK;AACN,EAAE,MAAM,EAAE,IAAI,EAAE,GAAGA,sBAAkB,EAAE,CAAC;AACxC,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAGC,UAAM,CAACC,mCAAyB,CAAC,CAAC;AACzD,EAAE,MAAM,KAAK,GAAGC,kBAAY,CAAC,mBAAmB,CAAC,CAAC;AAClD,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,GAAGC,iBAAS,EAAE,CAAC;AAClC,EAAE,MAAM,mBAAmB,GAAGC,uBAAW,CAAC,IAAI,CAAC,CAAC;AAChD,EAAE,MAAM,OAAO,GAAGC,OAAG,EAAE,CAAC;AACxB,EAAE,MAAM,OAAO,GAAGA,OAAG,EAAE,CAAC;AACxB,EAAE,MAAM,UAAU,GAAGA,OAAG,CAAC;AACzB,IAAI,OAAO,EAAE,IAAI;AACjB,IAAI,SAAS,EAAE,KAAK;AAC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