import { defineComponent, reactive, watch } from 'vue'
import icon from '../videoDetailItem/images/icon.png'
import classes from './index.module.less'
import gou from './images/gou.png'
import music from './images/music.png'
import member from './images/member.png'
import palyer from './images/palyer.png'
import arrow from './images/arrow.png'
import { goodsType } from '@/constant'
import { useRouter } from 'vue-router'
import start from '@/common/images/start.png'
import lineStart from '@/common/images/lineStart.png'
import iconFine from '@/common/images/icon_fine.png'
import iconAlbum from '@/common/images/icon_album_active.png'

type Props = {
  id?: Number
  addName: String
  addUserAvatar: String
  musicSheetName: String
  subjectNames: String
  composer: String
  chargeType: String
}
const chargeTypes = {
  CHARGE: '点播',
  FREE: '免费',
  VIP: '会员'
}
const chargeImg = {
  CHARGE: palyer,
  FREE: gou,
  VIP: member
}
export default defineComponent({
  name: 'musicLIstItem',
  props: {
    item: {
      type: Object as () => Props,
      default: () => ({})
    },
    hiddenCollect: {
      type: Boolean,
      defualt: false
    },
    isClick: {
      type: Boolean,
      default: false
    },
    onClick: {
      type: Function,
      default: (item: any) => {}
    }
  },

  setup(props: any) {
    const state = reactive({
      item: props.item
    })
    const router = useRouter()
    watch(
      () => props.item,
      item => {
        state.item = item
      }
    )

    const gotoMusicDetail = () => {
      router.push({ path: '/muiscDetial', query: { id: state.item.id } })
    }
    return () => (
      <div
        class={classes.itemWrapAll}
        onClick={() => {
          props.onClick(state.item)
        }}
      >
        <div
          class={classes.itemWrap}
          onClick={() => !props.isClick && gotoMusicDetail()}
        >
          <div class={classes.left}>
            <div class={classes.imgWrap}>
              <img src={state.item.titleImg || music} alt="" />
            </div>
            <div class={classes.textWrap}>
              <p class={classes.musicName}>
                {state.item.exquisiteFlag === 1 && (
                  <img src={iconFine} class={classes.iconFine} />
                )}

                {state.item.albumNums > 0 && (
                  <img src={iconAlbum} class={classes.iconAlbum} />
                )}

                <p class={classes.musicSheetName}>
                  {state.item.musicSheetName}
                </p>

                <p class={classes.authorName}>—— 作曲：{state.item.composer}</p>
              </p>

              <div class={classes.authorInfo}>
                <img
                  class={classes.icon}
                  src={state.item.addUserAvatar || icon}
                  alt=""
                />
                <span class={classes.authorName}>
                  {state.item.addName ? state.item.addName : '小酷有谱'}
                </span>
              </div>
            </div>
          </div>

          <div class={classes.right}>
            {!props.hiddenCollect && (
              <div class={classes.favoriteWrap}>
                <span>{state.item.favoriteCount | 0} 收藏</span>
                <img src={state.item.favorite ? lineStart : start} alt="" />
              </div>
            )}

            <div class={classes.tagList}>
              {state.item.subjectNames ? (
                <div class={classes.tag}>{state.item.subjectNames}</div>
              ) : null}
            </div>
          </div>
        </div>
      </div>
    )
  }
})
