import { defineComponent, ref } from 'vue';
import styles from './index.module.less';
import { useUserStore } from '/src/store/modules/users';
import { vaildMusicScoreUrl } from '/src/utils/urlUtils';
import { iframeDislableKeyboard } from '/src/utils';

export default defineComponent({
  name: 'song-modal',
  props: {
    item: {
      type: Object,
      default: () => ({})
    }
  },
  setup(props) {
    const userStore = useUserStore();
    const iframeRef = ref();
    const isLoaded = ref(false);

    let src = `${origin}/classroom-app/#/tempo-practice?v=${Date.now()}&Authorization=${
      userStore.getToken
    }&platform=modal`;
    if (/(localhost)/.test(location.host)) {
      src = `https://test.kt.colexiu.com/classroom-app/#/tempo-practice?v=${Date.now()}&Authorization=${
        userStore.getToken
      }&platform=modal`;
    }
    if (props.item.dataJson) {
      src += '&dataJson=' + props.item.dataJson;
    }
    return () => (
      <div class={styles.musicScore}>
        <iframe
          ref={iframeRef}
          onLoad={(val: any) => {
            // emit('setIframe', iframeRef.value);
            isLoaded.value = true;
            iframeDislableKeyboard(val.target);
          }}
          class={[styles.container, 'musicIframe']}
          frameborder="0"
          src={src}></iframe>
      </div>
    );
  }
});
