/**
 * Field Configuration Types
 *
 * Pure field definitions independent of how they're created (manifest, manual, etc.)
 * These types describe what a field IS, not where it came from.
 *
 * FieldConfig types are structurally compatible with FieldDefinition from @riverbankcms/blocks,
 * allowing manifest fields to be passed through with minimal transformation.
 */
import type { FieldDefinition } from '../../../blocks/src/index';
import type { ZodTypeAny } from 'zod';
import type { TabGroupFieldConfig } from '../widgets/TabGroupField/types';
import type { PresetOrCustomFieldConfig } from '../widgets/PresetOrCustomField/types';
export type MediaKind = 'image' | 'video' | 'audio';
export type FileFieldKind = 'document' | 'spreadsheet' | 'archive' | 'audio';
/**
 * Base configuration for all field types
 */
export interface BaseFieldConfig {
    /** Unique identifier for this field */
    id: string;
    /** Field type discriminator */
    type: string;
    /** Human-readable label */
    label: string;
    /** Optional description/help text */
    description?: string;
    /** Whether this field is required (defaults to false if not specified) */
    required?: boolean;
    /** Default value for this field */
    defaultValue?: unknown;
    /** UI-specific configuration - uses same type as FieldDefinition for compatibility */
    ui?: FieldDefinition['ui'];
}
/**
 * Text field configuration
 */
export interface TextFieldConfig extends BaseFieldConfig {
    type: 'text';
    multiline?: boolean;
    maxLength?: number;
}
/**
 * Number field configuration
 */
export interface NumberFieldConfig extends BaseFieldConfig {
    type: 'number';
    min?: number;
    max?: number;
    step?: number;
}
/**
 * Rich text field configuration
 */
export interface RichTextFieldConfig extends BaseFieldConfig {
    type: 'richText';
}
/**
 * Media field configuration
 */
export interface MediaFieldConfig extends BaseFieldConfig {
    type: 'media';
    mediaKinds?: MediaKind[];
    aspectRatio?: string;
}
/**
 * Public file field configuration.
 *
 * File fields are media-backed internally but carry file/download intent for
 * editor upload policy, picker filtering, and future file-specific workflows.
 */
export interface FileFieldConfig extends BaseFieldConfig {
    type: 'file';
    fileKinds?: FileFieldKind[];
}
/**
 * Boolean field configuration
 */
export interface BooleanFieldConfig extends BaseFieldConfig {
    type: 'boolean';
}
/**
 * Date field configuration
 */
export interface DateFieldConfig extends BaseFieldConfig {
    type: 'date';
}
/**
 * Time field configuration
 */
export interface TimeFieldConfig extends BaseFieldConfig {
    type: 'time';
}
/**
 * DateTime field configuration
 */
export interface DateTimeFieldConfig extends BaseFieldConfig {
    type: 'datetime';
}
/**
 * Slug field configuration
 */
export interface SlugFieldConfig extends BaseFieldConfig {
    type: 'slug';
    sourceFieldId?: string;
    statusFieldId?: string;
    maxLength?: number;
}
/**
 * URL field configuration
 */
export interface UrlFieldConfig extends BaseFieldConfig {
    type: 'url';
    allowRelative?: boolean;
}
/**
 * Link field configuration
 */
export interface LinkFieldConfig extends BaseFieldConfig {
    type: 'link';
}
/**
 * Select field configuration
 */
export interface SelectFieldConfig extends BaseFieldConfig {
    type: 'select';
    options: Array<{
        value: string;
        label: string;
    }>;
    multiple?: boolean;
}
/**
 * Reference field configuration
 */
export interface ReferenceFieldConfig extends BaseFieldConfig {
    type: 'reference';
    referenceKind: string;
    allowManualEntry?: boolean;
}
/**
 * Group field configuration (nested object)
 */
export interface GroupFieldConfig extends BaseFieldConfig {
    type: 'group';
    fields: FieldConfig[];
    /** Optional nested schema shape for compatibility with manifest FieldDefinition */
    schema?: {
        fields?: FieldConfig[];
    };
}
/**
 * Modal field configuration (nested object shown in a dialog)
 *
 * Modal fields are structurally similar to group fields, but store children under
 * `schema.fields` in the block manifest.
 */
export interface ModalFieldConfig extends BaseFieldConfig {
    type: 'modal';
    schema: {
        fields: FieldConfig[];
    };
}
/**
 * Repeater field configuration (array)
 */
export type RepeaterFieldConfig = BaseFieldConfig & ({
    /**
     * Optional custom validation schema for the entire repeater field.
     * Useful for complex constraints that aren't expressible via field-level config.
     */
    validation?: ZodTypeAny;
} & ({
    type: 'repeater';
    itemLabel?: string;
    itemLabelSource?: string;
    minItems?: number;
    maxItems?: number;
    polymorphic?: false;
    fields: FieldConfig[];
    /** Optional nested schema shape for compatibility with manifest FieldDefinition */
    schema?: {
        fields?: FieldConfig[];
    };
    itemTypes?: never;
    allowConversion?: boolean;
} | {
    type: 'repeater';
    itemLabel?: string;
    itemLabelSource?: string;
    minItems?: number;
    maxItems?: number;
    polymorphic: true;
    fields?: never;
    /** Polymorphic repeaters do not use schema.fields */
    schema?: never;
    itemTypes: Record<string, {
        label: string;
        icon?: string;
        fields: FieldConfig[];
    }>;
    allowConversion?: boolean;
}));
/**
 * Button field configuration
 */
export interface ButtonFieldConfig extends BaseFieldConfig {
    type: 'button';
    allowedSizes?: Array<'sm' | 'md' | 'lg' | 'xl'>;
    defaultSize?: 'sm' | 'md' | 'lg' | 'xl';
}
/**
 * Content type select field configuration
 */
export interface ContentTypeSelectFieldConfig extends BaseFieldConfig {
    type: 'contentTypeSelect';
    /** Filter: all, routable (hasPages=true), nonRoutable (hasPages=false) */
    filter?: 'all' | 'routable' | 'nonRoutable';
}
/**
 * Entry picker field configuration
 */
export interface EntryPickerFieldConfig extends BaseFieldConfig {
    type: 'entryPicker';
    /** Fixed content type to filter entries by (no sibling contentType field required) */
    fixedContentType?: string;
    /** Field ID that contains the content type to filter entries by */
    contentTypeField?: string;
    /** What value should be stored when an entry is selected */
    valueFrom?: 'id' | 'identifier' | 'slug';
}
/**
 * Union of all field configuration types
 */
export type FieldConfig = TextFieldConfig | NumberFieldConfig | RichTextFieldConfig | MediaFieldConfig | FileFieldConfig | BooleanFieldConfig | DateFieldConfig | TimeFieldConfig | DateTimeFieldConfig | SlugFieldConfig | UrlFieldConfig | LinkFieldConfig | SelectFieldConfig | ReferenceFieldConfig | GroupFieldConfig | ModalFieldConfig | RepeaterFieldConfig | ButtonFieldConfig | TabGroupFieldConfig | PresetOrCustomFieldConfig | ContentTypeSelectFieldConfig | EntryPickerFieldConfig;
