import { GapData, GapX, GapYDescriptor, GapYPropControllerData, ResponsiveLengthOptions, ResponsiveLengthPropControllerData, ResponsiveIconRadioGroup, ResponsiveNumber, ResponsiveSelect, type Descriptor, type PropDef, type OptionsType } from '@makeswift/prop-controllers';
import { type Data, type Device, ControlDefinition as UnifiedControlDefinition, type SerializedRecord, type RichTextValue as RichTextControlValue } from '@makeswift/controls';
import { PanelDescriptorType as PanelControlType, Descriptor as ControlDefinition } from '../../prop-controllers/descriptors';
import { DELETED_PROP_CONTROLLER_TYPES, ListDescriptor as ListControl, ListOptions as ListControlConfig, ListValue as ListControlValue, ShapeDescriptor as ShapeControl, ShapeValue as ShapeControlValue, TypeaheadDescriptor as TypeaheadControl, TypeaheadOptions as TypeaheadControlConfig, TypeaheadValue as TypeaheadControlValue, RichTextDescriptor as RichTextControl } from '../../prop-controllers/deleted';
import { DeserializedFunction, SerializedFunction } from './function-serialization';
import { LinkData, DateDescriptor as DateControl, DatePropControllerData, Types as PropControllerTypes, ImageDescriptor as ImageControl, ImageData as ImageControlValue, LinkDescriptor as LinkControl, LinkPropControllerData, ResponsiveLengthDescriptor, NumberOptions, NumberPropControllerData, NumberDescriptor, ResponsiveColorPropControllerData, ResponsiveColorDescriptor, CheckboxPropControllerData, CheckboxDescriptor as CheckboxControl, TextStyleDescriptor as TextStyleControl, TextStylePropControllerData, TextInputDescriptor as TextInputControl } from '@makeswift/prop-controllers';
import { type LegacyDescriptor } from '../../prop-controllers/descriptors';
import { type DeserializedRecord } from '@makeswift/controls';
type SerializedShapeControlConfig<T extends Record<string, SerializedPanelControl>> = {
    type: T;
    preset?: {
        [K in keyof T]?: SerializedPanelControlValueType<T[K]>;
    };
};
type SerializedShapeControl<_T extends Record<string, Data>, U extends Record<string, SerializedPanelControl>> = {
    type: typeof DELETED_PROP_CONTROLLER_TYPES.Shape;
    options: SerializedShapeControlConfig<U>;
};
type DeserializedShapeControlConfig<T extends Record<string, DeserializedPanelControl>> = {
    type: T;
    preset?: {
        [K in keyof T]?: DeserializedPanelControlValueType<T[K]>;
    };
};
type DeserializedShapeControl<_T extends Record<string, Data>, U extends Record<string, DeserializedPanelControl>> = {
    type: typeof DELETED_PROP_CONTROLLER_TYPES.Shape;
    options: DeserializedShapeControlConfig<U>;
};
type SerializedListControlConfig<T extends Data> = {
    type: SerializedPanelControl<T>;
    label?: string;
    getItemLabel?: SerializedFunction<Exclude<ListControlConfig<T>['getItemLabel'], undefined>>;
    preset?: ListControlValue<T>;
    defaultValue?: ListControlValue<T>;
};
type SerializedListControl<T extends ListControlValue = ListControlValue> = {
    type: typeof DELETED_PROP_CONTROLLER_TYPES.List;
    options: SerializedListControlConfig<T extends ListControlValue<infer U> ? U : never>;
};
type DeserializedListControlConfig<T extends Data> = {
    type: DeserializedPanelControl<T>;
    label?: string;
    getItemLabel?: DeserializedFunction<Exclude<ListControlConfig<T>['getItemLabel'], undefined>>;
    preset?: ListControlValue<T>;
    defaultValue?: ListControlValue<T>;
};
type DeserializedListControl<T extends ListControlValue = ListControlValue> = {
    type: typeof DELETED_PROP_CONTROLLER_TYPES.List;
    options: DeserializedListControlConfig<T extends ListControlValue<infer U> ? U : never>;
};
type SerializedTypeaheadControlConfig<T extends Data> = {
    getItems: SerializedFunction<TypeaheadControlConfig<T>['getItems']>;
    label?: string;
    preset?: TypeaheadControlValue<T>;
    defaultValue?: TypeaheadControlValue<T>;
};
type SerializedTypeaheadControl<T extends TypeaheadControlValue = TypeaheadControlValue> = {
    type: typeof DELETED_PROP_CONTROLLER_TYPES.Typeahead;
    options: SerializedTypeaheadControlConfig<T['value']>;
};
type DeserializedTypeaheadControlConfig<T extends Data> = {
    getItems: DeserializedFunction<TypeaheadControlConfig<T>['getItems']>;
    label?: string;
    preset?: TypeaheadControlValue<T>;
    defaultValue?: TypeaheadControlValue<T>;
};
type DeserializedTypeaheadControl<T extends TypeaheadControlValue = TypeaheadControlValue> = {
    type: typeof DELETED_PROP_CONTROLLER_TYPES.Typeahead;
    options: DeserializedTypeaheadControlConfig<T['value']>;
};
type SerializedConfig<T> = T | SerializedFunction<(props: Record<string, unknown>, deviceMode: Device) => T>;
export type DeserializedConfig<T> = T | DeserializedFunction<(props: Record<string, unknown>, deviceMode: Device) => T>;
type SerializedControlDef<P extends PropDef> = Descriptor<P> & {
    options: SerializedConfig<OptionsType<P>>;
};
export type DeserializedControlDef<P extends PropDef> = Descriptor<P> & {
    options: DeserializedConfig<OptionsType<P>>;
};
type GapYControlConfig = {
    preset?: GapYPropControllerData;
    label?: string;
    defaultValue?: GapData;
    min?: number;
    max?: number;
    step?: number;
    hidden?: boolean;
};
type SerializedGapYControl<_T = GapYPropControllerData> = {
    type: typeof PropControllerTypes.GapY;
    options: SerializedConfig<GapYControlConfig>;
};
type DeserializedGapYControl<_T = GapYPropControllerData> = {
    type: typeof PropControllerTypes.GapY;
    options: DeserializedConfig<GapYControlConfig>;
};
type CheckboxControlConfig = {
    preset?: CheckboxPropControllerData;
    label: string;
    hidden?: boolean;
};
type SerializedCheckboxControl<_T = CheckboxPropControllerData> = {
    type: typeof PropControllerTypes.Checkbox;
    options: SerializedConfig<CheckboxControlConfig>;
};
type DeserializedCheckboxControl<_T = CheckboxPropControllerData> = {
    type: typeof PropControllerTypes.Checkbox;
    options: DeserializedConfig<CheckboxControlConfig>;
};
type ResponsiveColorControlConfig = {
    label?: string;
    placeholder?: string;
    hidden?: boolean;
};
type SerializedResponsiveColorControl<_T = ResponsiveColorPropControllerData> = {
    type: typeof PropControllerTypes.ResponsiveColor;
    options: SerializedConfig<ResponsiveColorControlConfig>;
};
type DeserializedResponsiveColorControl<_T = ResponsiveColorPropControllerData> = {
    type: typeof PropControllerTypes.ResponsiveColor;
    options: DeserializedConfig<ResponsiveColorControlConfig>;
};
type SerializedNumberControl<_T = NumberPropControllerData> = {
    type: typeof PropControllerTypes.Number;
    options: SerializedConfig<NumberOptions>;
};
type DeserializedNumberControl<_T = NumberPropControllerData> = {
    type: typeof PropControllerTypes.Number;
    options: DeserializedConfig<NumberOptions>;
};
type DateControlConfig = {
    preset?: DatePropControllerData;
};
type SerializedDateControl<_T = DatePropControllerData> = {
    type: typeof PropControllerTypes.Date;
    options: SerializedConfig<DateControlConfig>;
};
type DeserializedDateControl<_T = DatePropControllerData> = {
    type: typeof PropControllerTypes.Date;
    options: DeserializedConfig<DateControlConfig>;
};
type LinkControlConfig = {
    preset?: LinkPropControllerData;
    label?: string;
    defaultValue?: LinkPropControllerData;
    options?: {
        value: LinkData['type'];
        label: string;
    }[];
    hidden?: boolean;
};
type SerializedLinkControl<_T = LinkPropControllerData> = {
    type: typeof PropControllerTypes.Link;
    options: SerializedConfig<LinkControlConfig>;
};
type DeserializedLinkControl<_T = LinkPropControllerData> = {
    type: typeof PropControllerTypes.Link;
    options: DeserializedConfig<LinkControlConfig>;
};
type TextInputControlConfig = {
    label?: string;
    placeholder?: string;
    hidden?: boolean;
};
type TextInputControlValue = string;
type SerializedTextInputControl<_T = TextInputControlValue> = {
    type: typeof PropControllerTypes.TextInput;
    options: SerializedConfig<TextInputControlConfig>;
};
type DeserializedTextInputControl<_T = TextInputControlValue> = {
    type: typeof PropControllerTypes.TextInput;
    options: DeserializedConfig<TextInputControlConfig>;
};
type SerializedResponsiveLengthControl<_T = ResponsiveLengthPropControllerData> = {
    type: typeof PropControllerTypes.ResponsiveLength;
    options: SerializedConfig<ResponsiveLengthOptions>;
};
type DeserializedResponsiveLengthControl<_T = ResponsiveLengthPropControllerData> = {
    type: typeof PropControllerTypes.ResponsiveLength;
    options: DeserializedConfig<ResponsiveLengthOptions>;
};
type SerializedTextStyleControl<_T = TextStylePropControllerData> = {
    type: typeof PropControllerTypes.TextStyle;
    options: SerializedConfig<TextStyleControlConfig>;
};
type TextStyleControlConfig = {
    preset?: TextStylePropControllerData;
    label?: string;
    hidden?: boolean;
};
type DeserializedTextStyleControl<_T = TextStylePropControllerData> = {
    type: typeof PropControllerTypes.TextStyle;
    options: DeserializedConfig<TextStyleControlConfig>;
};
type ImageControlConfig = {
    label?: string;
    hidden?: boolean;
};
type SerializedImageControl<_T = ImageControlValue> = {
    type: typeof PropControllerTypes.Image;
    options: SerializedConfig<ImageControlConfig>;
};
type DeserializedImageControl<_T = ImageControlValue> = {
    type: typeof PropControllerTypes.Image;
    options: DeserializedConfig<ImageControlConfig>;
};
type RichTextControlConfig = {
    preset?: RichTextControlValue;
};
type SerializedRichTextControl<_T = RichTextControlValue> = {
    type: typeof DELETED_PROP_CONTROLLER_TYPES.RichText;
    options: SerializedConfig<RichTextControlConfig>;
};
type DeserializedRichTextControl<_T = RichTextControlValue> = {
    type: typeof DELETED_PROP_CONTROLLER_TYPES.RichText;
    options: DeserializedConfig<RichTextControlConfig>;
};
export type SerializedLegacyControl<T extends Data = Data> = Exclude<LegacyDescriptor<T>, ListControl<T extends ListControlValue ? T : ListControlValue> | ShapeControl<T extends ShapeControlValue ? T : ShapeControlValue, any> | TypeaheadControl<T extends TypeaheadControlValue ? T : TypeaheadControlValue> | Descriptor<typeof GapX> | GapYDescriptor<T> | Descriptor<typeof ResponsiveNumber> | CheckboxControl<T> | ResponsiveColorDescriptor<T> | NumberDescriptor<T> | Descriptor<typeof ResponsiveIconRadioGroup> | Descriptor<typeof ResponsiveSelect> | ResponsiveLengthDescriptor<T> | DateControl<T> | LinkControl<T> | TextInputControl<T> | TextStyleControl<T> | ImageControl<T> | RichTextControl<T>> | SerializedListControl<T extends ListControlValue ? T : ListControlValue> | SerializedShapeControl<T extends ShapeControlValue ? T : ShapeControlValue, any> | SerializedTypeaheadControl<T extends TypeaheadControlValue ? T : TypeaheadControlValue> | SerializedControlDef<typeof GapX> | SerializedGapYControl<T> | SerializedControlDef<typeof ResponsiveNumber> | SerializedCheckboxControl<T> | SerializedResponsiveColorControl<T> | SerializedNumberControl<T> | SerializedControlDef<typeof ResponsiveIconRadioGroup> | SerializedControlDef<typeof ResponsiveSelect> | SerializedResponsiveLengthControl<T> | SerializedDateControl<T> | SerializedLinkControl<T> | SerializedTextInputControl<T> | SerializedTextStyleControl<T> | SerializedImageControl<T> | SerializedRichTextControl<T>;
export type SerializedControl<T extends Data = Data> = SerializedLegacyControl<T> | SerializedRecord;
type SerializedPanelControl<T extends Data = Data> = Extract<SerializedControl<T>, {
    type: PanelControlType;
}>;
type SerializedPanelControlValueType<T extends SerializedPanelControl> = T extends SerializedPanelControl<infer U> ? U : never;
export type DeserializedLegacyControl<T extends Data = Data> = Exclude<LegacyDescriptor<T>, ListControl<T extends ListControlValue ? T : ListControlValue> | ShapeControl<T extends ShapeControlValue ? T : ShapeControlValue, any> | TypeaheadControl<T extends TypeaheadControlValue ? T : TypeaheadControlValue> | Descriptor<typeof GapX> | GapYDescriptor<T> | Descriptor<typeof ResponsiveNumber> | CheckboxControl<T> | ResponsiveColorDescriptor<T> | NumberDescriptor<T> | Descriptor<typeof ResponsiveIconRadioGroup> | Descriptor<typeof ResponsiveSelect> | ResponsiveLengthDescriptor<T> | DateControl<T> | LinkControl<T> | TextInputControl<T> | TextStyleControl<T> | ImageControl<T> | RichTextControl<T>> | DeserializedListControl<T extends ListControlValue ? T : ListControlValue> | DeserializedShapeControl<T extends ShapeControlValue ? T : ShapeControlValue, any> | DeserializedTypeaheadControl<T extends TypeaheadControlValue ? T : TypeaheadControlValue> | DeserializedControlDef<typeof GapX> | DeserializedGapYControl<T> | DeserializedControlDef<typeof ResponsiveNumber> | DeserializedCheckboxControl<T> | DeserializedResponsiveColorControl<T> | DeserializedNumberControl<T> | DeserializedControlDef<typeof ResponsiveIconRadioGroup> | DeserializedControlDef<typeof ResponsiveSelect> | DeserializedResponsiveLengthControl<T> | DeserializedDateControl<T> | DeserializedLinkControl<T> | DeserializedTextInputControl<T> | DeserializedTextStyleControl<T> | DeserializedImageControl<T> | DeserializedRichTextControl<T>;
export type DeserializedControl<T extends Data = Data> = DeserializedLegacyControl<T> | UnifiedControlDefinition;
export type DeserializedPanelControl<T extends Data = Data> = Extract<DeserializedControl<T>, {
    type: PanelControlType;
}>;
type DeserializedPanelControlValueType<T extends DeserializedPanelControl> = T extends DeserializedPanelControl<infer U> ? U : never;
export declare function serializeControl<T extends Data>(control: ControlDefinition<T>): [SerializedControl<T>, Transferable[]];
export declare function isSerializedControl(control: unknown): control is SerializedControl;
export declare function deserializeLegacyControl<T extends Data>(serializedControl: SerializedLegacyControl<T>): DeserializedControl<T>;
export declare function deserializeControl<T extends Data>(serializedControl: SerializedControl<T>): DeserializedControl<T>;
export declare function deserializeUnifiedControlDef(record: DeserializedRecord): UnifiedControlDefinition;
export declare function serializeControls(controls: Record<string, ControlDefinition>): [Record<string, SerializedControl>, Transferable[]];
export declare function deserializeControls(serializedControls: Record<string, unknown>, { onError, }?: {
    onError?: (err: Error, context: {
        key: string;
        serializedControl: unknown;
    }) => void;
}): Record<string, DeserializedControl>;
export {};
//# sourceMappingURL=control-serialization.d.ts.map