<template>
  <Empty v-if="list.length === 0" description="暂无排名数据" />
  <FlexRow align="flex-end">
    <Touchable 
      v-for="(item) in list" 
      position="relative" 
      :key="item.id" 
      :width="item.rank == 1 ? '35%' : '32.5%'" 
      :height="item.rank == 1 ? 380 : 320"
      :innerStyle="{
        backgroundSize: '100% auto',
        backgroundRepeat: 'no-repeat',
        backgroundPosition: 'center',
        backgroundImage: `url('https://xy.wenlvti.net/app_static/images/home/Rank${item.rank}.png')`
      }"
      direction="column"
      overflow="hidden"
      @click="emit('goDetails', item)"
    >
      <FlexCol 
        position="absolute"
        :left="15"
        :right="15"
        :bottom="item.rank == 1 ? 62 : 36"
        center
      >
        <Avatar 
          :url="item.image" :size="item.rank == 1 ? 100 : 90" mode="aspectFill" radius="radius.md" 
          defaultAvatar="https://xy.wenlvti.net/app_static/images/village/PlaceholderVolunteer.png"
        />
        <Height :height="item.rank == 1 ? 15 : 10" />
        <Text fontConfig="h4" :text="item.title" color="white" />
        <Text fontConfig="h2" :text="item.score" :color="scoreColors[item.rank - 1]" fontFamily="SongtiSCBlack" />
      </FlexCol>
    </Touchable>
  </FlexRow>
</template>

<script setup lang="ts">
import Text from '@/components/basic/Text.vue';
import Avatar from '@/components/display/Avatar.vue';
import Empty from '@/components/feedback/Empty.vue';
import Touchable from '@/components/feedback/Touchable.vue';
import FlexCol from '@/components/layout/FlexCol.vue';
import FlexRow from '@/components/layout/FlexRow.vue';
import Height from '@/components/layout/space/Height.vue';

const scoreColors = [
  '#cb8833',
  '#7788b9',
  '#cd7853',
]

withDefaults(defineProps<{
  list?: {
    id: number;
    image: string;
    title: string;
    rank: number;
    score: number;
  }[];
}>(), {
  list: () => [
    {
      id: 2,
      image: 'https://mncdn.wenlvti.net/app_static/minnan/images/test/ImageTest2.png',
      title: '用户2',
      rank: 2,
      score: 90,
    },
    {
      id: 1,
      image: 'https://mncdn.wenlvti.net/app_static/minnan/images/test/ImageTest1.png',
      title: '用户1',
      rank: 1,
      score: 100,
    },
    {
      id: 3,
      image: 'https://mncdn.wenlvti.net/app_static/minnan/images/test/ImageTest3.png',
      title: '用户3',
      rank: 3,
      score: 80,
    },
  ],
});

const emit = defineEmits<{
  (e: 'goDetails', item: {
    id: number;
    image: string;
    title: string;
    rank: number;
    score: number;
  }): void;
}>();

</script>