<script lang="ts" setup>
/**
 * 开方医生单元格：头像 + 可点击姓名
 */
import { computed } from 'vue';

import { Avatar, Button } from 'ant-design-vue';

import { resolveAvatarUrl } from '#/views/system/store-input/utils/inputUser';

const props = defineProps<{
  row: Record<string, any>;
}>();

const emit = defineEmits<{
  open: [row: Record<string, any>];
}>();

const defaultAvatar = '/img/user-default-avatar.png';

const doctor = computed(
  () => props.row?.doctor_info ?? props.row?.doctorInfo ?? {},
);

function avatarSrc() {
  const raw = String(doctor.value?.avatar ?? '').trim();
  if (!raw) return defaultAvatar;
  return resolveAvatarUrl(raw) || defaultAvatar;
}
</script>

<template>
  <div class="flex items-center gap-2 min-w-0">
    <Avatar :size="28" :src="avatarSrc()" class="shrink-0" />
    <Button
      v-if="doctor?.name"
      class="!h-auto !px-0 !py-0 truncate"
      type="link"
      @click.stop="emit('open', row)"
    >
      {{ doctor.name }}
    </Button>
    <span v-else class="text-gray-400">—</span>
  </div>
</template>
