import { PropType, defineComponent, onMounted, ref, toRefs, watch } from 'vue';
import styles from '../index.module.less';
import icons from '../icons.json';
import { Badge, Grid, GridItem, Icon, Image, Progress, Tab, Tabs } from 'vant';
import iconLine from '../image/icon-line.png';
import { IStudentLessons } from '../type';
const colors = [
  {
    name: '正常',
    background: 'linear-gradient(180deg, #02E2DB 0%, #01C1B5 100%)'
  },
  {
    text: '迟到',
    background:
      'linear-gradient(180deg, rgba(148, 194, 253, 0.85) 0%, rgba(91, 143, 249, 0.85) 100%)'
  },
  {
    text: '请假',
    background:
      'linear-gradient(180deg, rgba(251,224,49,0.85) 0%, rgba(246,189,22,0.85) 100%)'
  },
  {
    text: '旷课',
    background:
      'linear-gradient(180deg, rgba(245,161,129,0.85) 0%, rgba(232,104,74,0.85) 100%)'
  }
];

export default defineComponent({
  name: 'Practice',
  props: {
    data: {
      type: Object as PropType<IStudentLessons>,
      default: () => ({})
    }
  },
  emits: ['change'],
  setup(props, { emit }) {
    const { data } = toRefs(props);
    const tab = ref('week')
    return () => (
      <div class={styles.item}>
        <div class={styles.top}>
          <Image class={styles.iconRight} src={icons.right} />
          <span>学员练习</span>
          <Image class={styles.iconLeft} src={icons.left} />
        </div>
        <div class={styles.tabsContainer}>
          <Tabs
            class={styles.practiceTabs}
            shrink
            v-model:active={tab.value}
            onChange={value => {
              console.log(value);
              emit('change', value);
            }}>
            <Tab name="week" title="本周"></Tab>
            <Tab name="month" title="本月"></Tab>
            <Tab name="term" title="本学期"></Tab>
          </Tabs>
        </div>
        <div class={styles.practiceContainer}>
          <Grid border={false}>
            <GridItem>
              {{
                icon: () => (
                  <div>
                    <span class={styles.tagNum}>
                      {data.value.commitRate || 0}
                    </span>
                    <span class={[styles.tagNum, styles.fenHao]}>%</span>
                  </div>
                ),
                text: () => <div>练习率</div>
              }}
            </GridItem>
            <Image class={styles.iconline} src={iconLine} fit="contain" />
            <GridItem>
              {{
                icon: () => (
                  <div>
                    <span class={styles.tagNum}>
                      {data.value.passRate || 0}
                    </span>
                    <span class={[styles.tagNum, styles.fenHao]}>%</span>
                  </div>
                ),
                text: () => <div>合格率</div>
              }}
            </GridItem>
          </Grid>
          <div class={styles.progressItem}>
            <Progress
              percentage={data.value.expectNum || 1}
              strokeWidth={8}
              trackColor="transparent"
              showPivot={false}
              color="linear-gradient(to right, #9AC6FF, #5C91FF)"></Progress>
            <div>
              应提交{' '}
              <span
                style={{ color: '#5C91FF' }}
                class={[styles.tagNum, styles.numDes]}>
                {data.value.expectNum || 0}
              </span>
              人
            </div>
          </div>
          <div class={styles.progressItem}>
            <Progress
              percentage={data.value.actualNum || 1}
              strokeWidth={8}
              trackColor="transparent"
              showPivot={false}
              color="linear-gradient(to right, #91F4DA, #01C1B5)"></Progress>
            <div>
              实际提交{' '}
              <span
                style={{ color: '#01C1B5' }}
                class={[styles.tagNum, styles.numDes]}>
                {data.value.actualNum || 0}
              </span>
              人
            </div>
          </div>
          <div class={styles.progressItem}>
            <Progress
              percentage={data.value.passNum || 1}
              strokeWidth={8}
              trackColor="transparent"
              showPivot={false}
              color="linear-gradient(to right, #FFDCAC, #FFA724)"></Progress>
            <div>
              合格提交{' '}
              <span
                style={{ color: '#FFA724' }}
                class={[styles.tagNum, styles.numDes]}>
                {data.value.passNum || 0}
              </span>
              人
            </div>
          </div>
        </div>
      </div>
    );
  }
});
