import { Button } from 'vant'
import { defineComponent } from 'vue'
import iconMembership from './icons/membership.png'
import styles from './index.module.less'
import classNames from 'classnames'
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 default defineComponent({
  name: 'ColexiuMember',
  setup() {
    const search = useOriginSearch()
    const client = useClientType()
    const buy = () => {
      delete search.Authorization
      postMessage({
        api: 'openWebView',
        content: {
          url: location.origin + '/' + client + '/#/memberCenter?' + qs.stringify({ ...search }),
          orientation: 1,
        },
      })
    }

    const close = () => {
      permissionPopup.show = false
      RuntimeUtils.setCurrentTime(0)
      RuntimeUtils.refreshIndex(0)
    }
    return () => (
      <div>
        <img class={styles.image} src={iconMembership} />
        <div class={styles.wrap}>
          <div class={styles.des}>
            <div class={styles.title}>请开通会员</div>
            <div class={styles.sub}>开通会员后可完整使用该曲目</div>
          </div>
          <div class={styles.btnWrap}>
            <Button class={classNames(styles.btn, styles.tryoutBtn)} onClick={close}></Button>
            <Button
              class={classNames([
                styles.btn,
                styles.membershipBtn,
                { [styles.discounts]: (search.discounts as unknown) == 1 },
              ])}
              onClick={buy}
            ></Button>
          </div>
        </div>
      </div>
    )
  },
})
