<template>
    <Table :data="classList" :columns="columns" selection-mode="multiple" row-key="classId"
           :selected-rows="selectedClasses" @selection-change="handleSelectionChange"/>
</template>

<script setup name="ClassStatisticTable">
import {useInjectPaperClassStatisticCondition} from "@/views/dz/papers/hooks/usePaperClassStatisticCondition.js";
import Table from '@/components/Table/index.vue';
import consts from "@/utils/consts.js";

const props = defineProps({
    exactMode: Boolean,
    handMode: Boolean
})

const {classList, selectedClasses} = useInjectPaperClassStatisticCondition()

const ids = ref([]);
const single = ref(true);
const multiple = ref(true);

const columns = props.exactMode
    ? props.handMode
        ? [{label: '班级名称', prop: 'className'}, {label: '专业人数', prop: 'total'}, ...consts.config.exactColumns.slice(0, 3)]
        : [{label: '班级名称', prop: 'className'}, {label: '总人数', prop: 'total'}, ...consts.config.exactColumns]
    : [{label: '班级名称', prop: 'className'}, {label: '总人数', prop: 'total'}, ...consts.config.fullColumns]

function handleSelectionChange(selection) {
    ids.value = selection.map((item) => item.classId);
    single.value = selection.length != 1;
    multiple.value = !selection.length;

    selectedClasses.value = selection
}
</script>

<style scoped>

</style>