import { inject, type ComputedRef, type InjectionKey, type Component, } from "vue"; import type { DateValue, Time } from "@internationalized/date"; import type { DateFieldInputProps } from "reka-ui"; import type { dateInputGroupVariants } from "@heroui-vue/styles"; export interface DateSegment { part: DateFieldInputProps["part"]; type: DateFieldInputProps["part"]; value: string; text: string; isPlaceholder: boolean; isEditable: boolean; } export interface DateFieldContext { value: ComputedRef; disabled: ComputedRef; readOnly: ComputedRef; required: ComputedRef; invalid: ComputedRef; form?: () => HTMLFormElement | null | undefined; leadingZeros: () => boolean | undefined; labelledBy: () => string | undefined; describedBy: () => string | undefined; ariaLabel: () => unknown; } export const dateFieldKey: InjectionKey = Symbol("hv-date-field"); export const dateGroupKey: InjectionKey< ComputedRef> > = Symbol("hv-date-group"); export function useDateField() { const value = inject(dateFieldKey, undefined); if (!value) throw new Error("Date input parts require a DateField or TimeField root."); return value; } export const dateSegmentsKey: InjectionKey< ComputedRef<{ part: DateFieldInputProps["part"]; value: string }[]> > = Symbol("hv-date-segments"); export const dateSegmentBaseKey: InjectionKey<{ base: NonNullable< ReturnType >; input: Component; kind: "date" | "time"; /** Range endpoints reuse the same segment parts with an explicit start/end field. */ endpoint?: "start" | "end"; }> = Symbol("hv-date-segment-base"); /** Marker provided by the DateRangePicker private field body. Only inputs with * an explicit endpoint consume it; nested TimeFields keep their own segment base. */ export const dateRangeFieldKey: InjectionKey<{ root: NonNullable< ReturnType >; }> = Symbol("hv-date-range-field");