import { Button } from 'vant'
import { defineComponent, ref, Ref } from 'vue'
import iconDemand from './icons/demand.svg'
import iconColse from '../close.svg'
import styles from './index.module.less'
import classNames from 'classnames'
import detailState from '/src/pages/detail/state'
import qs from 'query-string'
import { permissionPopup } from './permission'
import * as RuntimeUtils from '/src/pages/detail/runtime'
import { postMessage } from '/src/helpers/native-message'
import { useClientType, useOriginSearch } from '../../uses'
export const confirmShow: Ref<boolean> = ref(false)


export default defineComponent({
  name: 'memberAndDemand',
  setup() {
    const search = useOriginSearch()
    const client = useClientType()
    const buy = async () => {
      delete search.Authorization
      postMessage({
        api: 'openWebView',
        content: {
          url: location.origin + '/' + client + '/#/orderDetail?' + qs.stringify({ orderType: 'MUSIC', ...search }),
          orientation: 1,
        },
      })
    }

    // 去购买会员
    const buyMenber = () => {
      delete search.Authorization
      postMessage({
        api: 'openWebView',
        content: {
          url: location.origin + '/' + client + '/#/memberCenter',
          orientation: 1,
        },
      })
    }

    const close = () => {
      permissionPopup.show = false
      RuntimeUtils.setCurrentTime(0)
      RuntimeUtils.refreshIndex(0)
    }

    return () => (
      <div style={{position: 'relative'}}>
        <img class={styles.closeBtn} src={iconColse} onClick={close} />
        <img class={styles.image} src={iconDemand} />
        <div class={styles.wrap}>
          <div class={styles.des}>
            <div class={[styles.title, styles.andTitle]}>该曲目为会员曲目，可以单曲购买哦</div>
            <div class={[styles.sub, styles.andSub]}>
            开通酷乐秀会员海量曲目尽情练习<br/>单曲点播仅需 <span style={{ color: '#FF4E19' }}>¥{detailState.activeDetail?.musicPrice}</span>
              ，点播后可永久使用
            </div>
          </div>
          <div class={styles.btnWrap}>
            <Button class={classNames(styles.btn, styles.membershipBtn)} onClick={buyMenber}></Button>
            <Button class={classNames(styles.btn, styles.demandBtn)} onClick={buy}></Button>
          </div>
        </div>
      </div>
    )
  },
})
