<script setup lang="ts">
import { computed } from 'vue'
import { NDatePicker } from 'naive-ui'

const props = defineProps<{ df: any; record: Record<string, any>; canEdit: boolean; ctx: any }>()

// Label布局：上下结构(vertical) 或 左右结构(horizontal)
const labelLayout = computed(() => props.df.label_layout || 'vertical')
</script>

<template>
  <div :class="['field-wrapper', `layout-${labelLayout}`]">
    <label class="field-label">
      {{ ctx.t(df.label || df.fieldname) }}
      <span v-if="df.reqd" class="required">*</span>
    </label>
    <n-date-picker 
      :value="ctx.toDateValue ? ctx.toDateValue(record[df.fieldname]) : null" 
      @update:value="(v)=> ctx.updateDateValue && ctx.updateDateValue(df.fieldname, v)"
      type="date"
      :placeholder="ctx.t(df.fieldname)"
      :disabled="!canEdit"
    />
  </div>
</template>

<style scoped>
.field-wrapper :deep(.n-date-picker) {
  flex: 1;
}
</style>


