import { TypeDefinitions } from './definition.js' import type { Rule } from './rule.js' import type { Style } from '../sdk.js' export type Type = keyof typeof TypeDefinitions export type Props = { [T in Type]: ReturnType<(typeof TypeDefinitions)[T]['Props']> } export function fix(type: T, props: Props[T], styles: Rule[]): Props[T] { // TODO: Couldnt figure out how to fix the type narrowing here return TypeDefinitions[type] ? (TypeDefinitions[type].fix(props as any, styles) as any) : props } export function PropsConstructor(type: T, props: Props[T], styles: Rule[]) { // TODO: Couldnt figure out how to fix the type narrowing here return TypeDefinitions[type] ? TypeDefinitions[type].Props(props) : props } export function summarize( type: T, props: Props[T], styles?: Style.Rule[], formId?: string ): string { return TypeDefinitions[type].summarize(props as any, styles, formId) } export const Props = Object.assign(PropsConstructor, { fix })