import { defineComponent, reactive } from 'vue'
import styles from './point.module.less'
import iconMulv from '../image/icon-mulv.svg'
import iconArrow from '../image/icon-arrow.svg'
import { Collapse, CollapseItem } from 'vant'
export default defineComponent({
  name: 'points',
  props: {
    data: {
      type: Array,
      default: () => []
    },
    tabActive: {
      type: String,
      default: ''
    },
    itemActive: {
      type: String,
      default: ''
    }
  },
  emits: ['handleSelect'],
  setup(props, { emit }) {
    const pointData = reactive({
      active: props.tabActive || '1610827376354500609' || ''
    })
    return () => (
      <div class={styles.container}>
        <div>
          <div class={styles.pointHead}>
            <img src={iconMulv} />
            课程目录
          </div>
          <Collapse
            class={styles.collapse}
            modelValue={pointData.active}
            onUpdate:modelValue={(val: any) => {
              pointData.active = val
            }}
            accordion
          >
            {props.data.map((item: any) => {
              return (
                <CollapseItem center border={false} isLink={false} title={item.name} name={item.id}>
                  {{
                    default: () => (
                      <>
                        {Array.isArray(item?.materialList) &&
                          item.materialList.map((n: any) => {
                            return (
                              <div
                                class={[
                                  styles.item,
                                  props.itemActive == n.id ? styles.itemActive : ''
                                ]}
                                onClick={() => {
                                  emit('handleSelect', { itemActive: n.id, tabActive: item.id, tabName: item.name })
                                }}
                              >
                                {n.name}
                              </div>
                            )
                          })}
                      </>
                    ),
                    icon: () => <img class={styles.arrow} src={iconArrow} />
                  }}
                </CollapseItem>
              )
            })}
          </Collapse>
        </div>
      </div>
    )
  }
})
