import request from '@/helpers/request'
import { state } from '@/state'
import { Button, Empty, Grid, GridItem, Icon } from 'vant'
import { defineComponent, onMounted, reactive } from 'vue'
import styles from './index.module.less'
import iconLook from './image/look.svg'
import { useRoute, useRouter } from 'vue-router'
export default defineComponent({
  name: 'lessonCourseware',
  setup() {
    const route = useRoute()
    const router = useRouter()
    const data = reactive({
      list: [] as any
    })
    const getList = async () => {
      try {
        const res: any = await request.post(
          state.platformApi + '/courseSchedule/myCoursewareDetail/' + route.query.id
        )
        if (Array.isArray(res?.data)) {
          data.list = res.data
        }
      } catch (error) {}
    }
    onMounted(() => {
      getList()
    })

    const handleClick = (item: any) => {
      if (route.query.code === 'select') {
        console.log('选择课时')
      }
      router.push({
        path: '/coursewarePlay',
        query: {
          id: item.lessonCoursewareDetailId
        }
      })
    }
    return () => (
      <div style={{ paddingTop: '14px' }}>
        <Grid gutter={14} columnNum={3} class={styles.grid}>
          {data.list.map((item: any) => {
            return (
              <GridItem>
                <div
                  class={styles.gridItem}
                  style={{
                    background: item.coverImg
                      ? ''
                      : `hsla(${Math.floor(Math.random() * 360)},50%,50%,.8)`
                  }}
                  onClick={() => handleClick(item)}
                >
                  {/* <img src={item.coverImg} class={styles.cover} /> */}
                  <div class={styles.title}>
                    <div>{item.coursewareDetailName}</div>
                    <div>已使用 {item.useNum} 次</div>
                  </div>
                  <div class={styles.num}>
                    查看
                    <Icon name="play-circle-o" />
                  </div>
                 
                  {item.unlock && (
                    <div class={styles.look}>
                      <Icon name={iconLook} /> 未解锁
                    </div>
                  )}
                </div>
              </GridItem>
            )
          })}
        </Grid>
        <Button onClick={() => {
          location.href = 'http://192.168.3.114:1000/teacher.html#/coursewarePlay?id=1610595720511209474'
        }}>测试</Button>
        {!data.list.length && <Empty description="空空如也" />}
      </div>
    )
  }
})
