import type { FormSchemaEntryShared } from "../form/webcomponent.type";

/**
 * Same shape as `FormSchemaEntry` in `hb-form` (nested rows inside `params.schema`).
 * Defined locally so `ts-json-schema-generator` does not merge two symbols named `FormSchemaEntry`.
 *
 * Nested `params` may include any keys supported by the embedded input types (min/max, options, …)
 * in addition to `columns` for `type: "row"`.
 */
type InputArrayObjectsNestedField = Omit<FormSchemaEntryShared, "params"> & {
  type: string;
  params?: {
    columns?: InputArrayObjectsNestedField[];
  } & Record<string, unknown>;
};

export type InputArrayObjectsParams = {
  /** Sub-form template for each row in the table. */
  schema?: InputArrayObjectsNestedField[];
  /** Rarely used; mirror of row-style layouts. */
  columns?: InputArrayObjectsNestedField[];
  /** Label for the “add property” / add-row control. */
  addPropertyLabel?: string;
};

export type FormSchemaEntry = Omit<FormSchemaEntryShared, "params"> & {
  /**
   * Optional default value.
   */
  value?: { [key: string]: unknown; _objId: string }[];
  params?: InputArrayObjectsParams;
};

export type Component = {
  id?: string;
  style?: string;
  show_validation?: "yes" | "no";
  /** JSON string from HTML, or a parsed object from JavaScript (`parseSchemaentryProp`). */
  schemaentry: string | FormSchemaEntry | undefined;
};

export type Events = {
  setVal: {
    value: { [key: string]: unknown; _objId: string }[];
    valid: boolean;
    id: string;
  };
};
