<!-- eslint-disable vue/no-mutating-props -->
<script setup lang="ts">
import type { MjFormTargetRenderOpts } from '.'
import type { RenderParams } from '../mj-form-plugin'

defineOptions({ name: 'MjFormTargetPlugin' })

const props = withDefaults(
  defineProps<{
    renderOpts: MjFormTargetRenderOpts
    // 表格、表单相关的一些数据
    renderParams: RenderParams
  }>(),
  {},
)

const schoolId = computed(() => props.renderParams.data?.schoolId)

const text = computed({
  get() {
    return props.renderParams.data[props.renderParams.field]
  },
  set(val) {
    props.renderParams.data[props.renderParams.field] = val
  },
})

// watch(
//   () => ,
//   (newVal) => {
//     console.log('schoolId', newVal)
//   },
// )
</script>

<template>
  <mj-form-target
    v-model="text"
    v-bind="renderOpts.props"
    :school-id="schoolId"
  />
</template>

<style lang="scss" scoped></style>
