/* eslint-disable @typescript-eslint/no-explicit-any */ import type { DeepKeys, DeepValue, FieldApi, FieldAsyncValidateOrFn, FieldValidateAsyncFn, FieldValidateFn, FieldValidateOrFn, FormAsyncValidateOrFn, FormValidateOrFn, StandardSchemaV1 } from "@tanstack/vue-form" import { type IsUnion } from "effect-app/utils" export type OmegaFieldInternalApi, TName extends DeepKeys> = FieldApi< /* in out TParentData*/ From, /* in out TName*/ TName, /* in out TData*/ DeepValue, /* in out TOnMount*/ FieldValidateOrFn> | undefined, /* in out TOnChange*/ StandardSchemaV1, unknown> | FieldValidateFn, /* in out TOnChangeAsync*/ StandardSchemaV1, unknown> | FieldValidateAsyncFn, /* in out TOnBlur*/ FieldValidateOrFn>, /* in out TOnBlurAsync*/ FieldAsyncValidateOrFn>, /* in out TOnSubmit*/ FieldValidateOrFn> | undefined, /* in out TOnSubmitAsync*/ FieldAsyncValidateOrFn> | undefined, /* in out TOnDynamic*/ FieldValidateOrFn> | undefined, /* in out TOnDynamicAsync*/ FieldAsyncValidateOrFn> | undefined, /* in out TFormOnMount*/ FormValidateOrFn | undefined, /* in out TFormOnChange*/ FormValidateOrFn | undefined, /* in out TFormOnChangeAsync*/ any, /* in out TFormOnBlur*/ FormValidateOrFn | undefined, /* in out TFormOnBlurAsync*/ FormAsyncValidateOrFn | undefined, /* in out TFormOnSubmit*/ FormValidateOrFn | undefined, /* in out TFormOnSubmitAsync*/ FormAsyncValidateOrFn | undefined, /* in out TFormOnDynamic*/ FormValidateOrFn | undefined, /* in out TFormOnDynamicAsync*/ FormAsyncValidateOrFn | undefined, /* in out TFormOnServer*/ FormAsyncValidateOrFn | undefined, /* in out TParentSubmitMeta*/ Record | undefined > export type InputProps, TName extends DeepKeys> = { inputProps: { id: string required?: boolean minLength?: number | false maxLength?: number | false max?: number | false min?: number | false errorMessages: string[] error: boolean label: string type: string inputClass: string | undefined | null } field: OmegaFieldInternalApi /** reactive field state, sourced from `field.state` (the Field slot's own `state` prop is a stale snapshot since @tanstack/vue-form 1.32) */ state: OmegaFieldInternalApi["state"] } export type MergedInputProps, TName extends DeepKeys> = & InputProps["inputProps"] & Pick, "field" | "state"> export type VuetifyInputProps, TName extends DeepKeys> = { inputProps: InputProps["inputProps"] & { type: string options?: { title: string; value: unknown }[] } } & Pick, "field" | "state"> // Utility type to extract _tag literal values from a discriminated union // For a union like { _tag: "A", ... } | { _tag: "B", ... }, this returns "A" | "B" // For nullable unions like { _tag: "A" } | { _tag: "B" } | null, this still returns "A" | "B" (excluding null) export type ExtractTagValue< From extends Record, TName extends DeepKeys | undefined > = IsUnion extends true ? From extends { _tag: infer Tag } ? Tag : never : DeepValue extends infer U ? U extends { _tag: infer Tag } ? Tag : never : never // Utility type to extract a specific branch from a discriminated union based on _tag value // For union { _tag: "A", foo: string } | { _tag: "B", bar: number } and Tag="A", returns { _tag: "A", foo: string } export type ExtractUnionBranch = T extends { _tag: Tag } ? T : never // Option type for TaggedUnion component with strongly-typed value // The value can be either one of the _tag values OR null (for the placeholder) export type TaggedUnionOption, TName extends DeepKeys | undefined> = { readonly title: string readonly value: ExtractTagValue | null } // Options array must ALWAYS start with a null option (placeholder), followed by the actual options export type TaggedUnionOptionsArray< From extends Record, TName extends DeepKeys | undefined > = | readonly [ { readonly title: string; readonly value: null }, ...ReadonlyArray<{ readonly title: string; readonly value: ExtractTagValue }> ] | ReadonlyArray<{ readonly title: string; readonly value: ExtractTagValue }> // Props for TaggedUnion component export type TaggedUnionProps, TName extends DeepKeys> = { name: TName options: TaggedUnionOptionsArray }