<template>
  <CommonTopBanner title="乡源人数">
    <SimplePageListLoader :loader="villageUserRankListLoader">
      <FlexCol gap="gap.lg" padding="space.md">
        <Touchable
          v-for="(item, index) in villageUserRankListLoader.list.value"
          :key="item.id"
          direction="column"
          @click="goDetails(item)"
        >
          <BackgroundBox
            backgroundImage="https://xy.wenlvti.net/app_static/images/village/BoxDark.png"
            :backgroundCutBorder="[6,6,6,6]"
            :backgroundCutBorderSize="[10,10,10,10]"
            :padding="[25,25]"
            direction="row"
            justify="space-between"
            align="center"
            gap="gap.md"
            
          >
            <FlexRow align="center" gap="gap.lg">
              <Avatar 
                :url="item.image" 
                defaultAvatar="https://xy.wenlvti.net/app_static/images/village/PlaceholderVolunteer.png"
                :size="70" 
                mode="aspectFill" 
                radius="radius.md" 
              />
              <Text :text="item.name" fontConfig="contentText" />
            </FlexRow>
            <FlexRow center gap="gap.md">
              <Tag v-if="item.isAdmin" text="管理员" size="small" />
              <BackgroundBox
                backgroundImage="https://xy.wenlvti.net/app_static/images/village/TagNormal.png"
                :backgroundCutBorder="[10,10,10,10]"
                :backgroundCutBorderSize="[10,10,10,10]"
                :padding="[15,10]"
                center
                direction="row"
                gap="gap.md"
                width="100"
              >
                <Image src="https://xy.wenlvti.net/app_static/images/village/IconFruit.png" width="30rpx" height="30rpx" mode="aspectFill" />
                <Text :text="item.points" fontConfig="contentText" />
              </BackgroundBox>
            </FlexRow>
          </BackgroundBox>
        </Touchable>
      </FlexCol>
    </SimplePageListLoader>
  </CommonTopBanner>
</template>

<script setup lang="ts">
import { useSimplePageListLoader } from '@/components/composeabe/loader/SimplePageListLoader';
import { useLoadQuerys } from '@/components/composeabe/LoadQuerys';
import { navTo } from '@/components/utils/PageAction';
import FlexCol from '@/components/layout/FlexCol.vue';
import BackgroundBox from '@/components/display/block/BackgroundBox.vue';
import Text from '@/components/basic/Text.vue';
import Avatar from '@/components/display/Avatar.vue';
import Tag from '@/components/display/Tag.vue';
import Image from '@/components/basic/Image.vue';
import FlexRow from '@/components/layout/FlexRow.vue';
import Touchable from '@/components/feedback/Touchable.vue';
import CommonTopBanner from '@/common/components/CommonTopBanner.vue';
import VillageApi from '@/api/inhert/VillageApi';
import SimplePageListLoader from '@/components/loader/SimplePageListLoader.vue';

const { querys } = useLoadQuerys({
  villageId: 0,
}, () => {
  villageUserRankListLoader.reload();
}); 

const villageUserRankListLoader = useSimplePageListLoader(20, async (page, pageSize) => {
  return (await VillageApi.getVillageVolunteerList(page, pageSize, querys.value.villageId))
});

function goDetails(item: {
  id: number;
}) {
  console.log(item);
  
  navTo('../volunteer/detail', { id: item.id });
}

</script>