<template>
  <el-form-item
    :prop="prop"
    class="ecp-pro-table-form__cell-item"
  >
    <!-- slot 列：完全透传给父级 -->
    <slot
      v-if="col.component === 'slot' && col.slotName"
      :name="'cell-' + col.slotName"
      :column="col"
      :row="row"
      :value="value"
      :update-value="updateValue"
    />
    <!-- 内置组件 -->
    <component
      v-else
      :is="cellComponent(col)"
      :value="value"
      v-bind="cellBind(col)"
      :placeholder="col.placeholder || placeholder"
      @input="updateValue"
    />
  </el-form-item>
</template>

<script setup lang="ts">
import type { ProTableFormColumn } from './types'

interface Props {
  col: ProTableFormColumn
  row: TableRow
  prop: string
  value: unknown
  updateValue: (v: unknown) => void
  cellComponent: (col: ProTableFormColumn) => unknown
  cellBind: (col: ProTableFormColumn) => Record<string, unknown>
  placeholder?: string
}

defineProps<Props>()

type TableRow =
  | { _type: 'fixed'; rowKey: string; rowLabel: string }
  | { _type: 'competitor'; _index: number }
</script>
