import { verifyUrl } from '@/helpers/toolsValidate'
import { openDefaultWebView } from '@/student/home-layout-orchestra/state-orchestra'
import { Swipe, SwipeItem, Image } from 'vant'
import { defineComponent } from 'vue'
import event from '../../event'
import styles from './index.module.less'

export default defineComponent({
  name: 'menu-list',
  props: {
    productList: {
      type: Array,
      default: []
    },
    onOpenWebView: {
      type: Function,
      default: (a: any) => {}
    }
  },
  render() {
    return (
      <Swipe
        class={[
          styles.swipeType,
          this.productList.length > 1 && styles.swipeTypeShow
        ]}
        indicator-color="var(--van-primary)"
        loop={false}
        showIndicators={this.productList.length > 1}
      >
        {this.productList.map((product: any) => (
          <SwipeItem class={styles.typeSection}>
            {product.map((item: any) => (
              <div
                class={styles.typeItem}
                onClick={() => {
                  // if (verifyUrl(item.linkUrl)) {
                  //   openDefaultWebView(item.linkUrl, () => {
                  //     window.location.href = item.linkUrl
                  //   })
                  // }
                  event.emit('downloadApp')
                }}
              >
                <Image
                  class={styles.swipeTypeImg}
                  src={item.coverImage}
                  fit="cover"
                />
                <p class={styles.typeName}>{item.title}</p>
              </div>
            ))}
          </SwipeItem>
        ))}
      </Swipe>
    )
  }
})
