import type { CardType } from "@/definitions/shared/base"

/**
 * v1 → v2 card type mapping. The v1 docs schema uses snake_case
 * (`fields_list`, `data_table`, ...) while v2's internal `cardType`
 * is kebab-case (`element-list`, `datatable`, ...).
 *
 * Two v1 card types don't map to v2 cards at all:
 *   - `button_group` — in v2 this is an `action` ELEMENT with
 *     style=`button-group`, not a card. The adapter rewrites these
 *     into a one-element `element-list` card with the button-group
 *     element inside.
 *   - `form_builder`  — in v2 this is a `builder` ELEMENT with
 *     style=`form-builder`. Same rewrite as button_group.
 */
export const V1_TO_V2_CARD_TYPE: Record<string, CardType> = {
  fields_list: "element-list",
  data_table: "datatable",
  card_list: "card-list",
  tabs_list: "tab-list",
  info_card: "info-card",
  grid_view: "grid-view",
  component: "element-display",
  // Also pass through the v2 names so callers can mix-and-match.
  "element-list": "element-list",
  datatable: "datatable",
  "card-list": "card-list",
  "tab-list": "tab-list",
  "info-card": "info-card",
  "grid-view": "grid-view",
  "element-display": "element-display",
}

export const V2_TO_V1_CARD_TYPE: Record<CardType, string> = {
  "element-list": "fields_list",
  datatable: "data_table",
  "card-list": "card_list",
  "tab-list": "tabs_list",
  "info-card": "info_card",
  "grid-view": "grid_view",
  "element-display": "component",
}

/** v1 card types that map to an element wrapped in an element-list, not a card. */
export const V1_ELEMENT_AS_CARD: ReadonlySet<string> = new Set([
  "button_group",
  "form_builder",
])
