<script setup lang="ts">
import { computed } from 'vue'
import { NColorPicker } 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-color-picker 
      v-model:value="record[df.fieldname]" 
      :disabled="!canEdit"
      size="medium"
    />
  </div>
</template>

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

/* 确保颜色选择器与naive-ui input高度完全一致 */
.field-wrapper :deep(.n-color-picker .n-color-picker-trigger) {
  height: 40px;
  box-sizing: border-box;
}
</style>


