<template>
    <Table :data="classList" :columns="columns" selection-mode="multiple" row-key="classId"
           :selected-rows="selectedClasses" @selection-change="handleSelectionChange">
        <template #send="{row}">
            <el-link type="primary" :underline="false" @click.stop="$emit('stat-click', row, 'send')" style="cursor: pointer;">
                {{ row.send || 0 }}
            </el-link>
        </template>
        <template #total="{row}">
            <el-link type="primary" :underline="false" @click.stop="$emit('stat-click', row, 'total')" style="cursor: pointer;">
                {{ row.total || 0 }}
            </el-link>
        </template>
        <template #unexact="{row}">
            <el-link type="primary" :underline="false" @click.stop="$emit('stat-click', row, 'unexact')" style="cursor: pointer;">
                {{ row.unexact || 0 }}
            </el-link>
        </template>
        <template #unfinish="{row}">
            <el-link type="primary" :underline="false" @click.stop="$emit('stat-click', row, 'unfinish')" style="cursor: pointer;">
                {{ row.unfinish || 0 }}
            </el-link>
        </template>
        <template #unsend="{row}">
            <el-link type="primary" :underline="false" @click.stop="$emit('stat-click', row, 'unsend')" style="cursor: pointer;">
                {{ row.unsend || 0 }}
            </el-link>
        </template>
    </Table>
</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
})

defineEmits(['stat-click'])

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', type: 'slot', slotName: 'total'}, 
            {label: '组卷已完成', prop: 'send', type: 'slot', slotName: 'send'},
            {label: '组卷未完成', prop: 'unfinish', type: 'slot', slotName: 'unfinish'},
            {label: '定向未组卷', prop: 'unsend', type: 'slot', slotName: 'unsend'}
        ]
        : [
            {label: '班级名称', prop: 'className'}, 
            {label: '总人数', prop: 'total', type: 'slot', slotName: 'total'}, 
            {label: '组卷已完成', prop: 'send', type: 'slot', slotName: 'send'},
            {label: '组卷未完成', prop: 'unfinish', type: 'slot', slotName: 'unfinish'},
            {label: '定向未组卷', prop: 'unsend', type: 'slot', slotName: 'unsend'},
            {label: '未定向未组卷', prop: 'unexact', type: 'slot', slotName: 'unexact'}
        ]
    : [
        {label: '班级名称', prop: 'className'}, 
        {label: '总人数', prop: 'total', type: 'slot', slotName: 'total'}, 
        {label: '组卷已完成', prop: 'send', type: 'slot', slotName: 'send'},
        {label: '组卷未完成', prop: 'unfinish', type: 'slot', slotName: 'unfinish'},
        {label: '未组卷', prop: 'unsend', type: 'slot', slotName: 'unsend'}
    ]

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>