import { defineComponent, onMounted, watch } from 'vue'
import state from '/src/pages/detail/state'

export default defineComponent({
  name: 'afterClassTraining',
  setup() {
    watch(
      () => state.initRendered,
      () => {
        if (state.initRendered) {
          window.parent.postMessage(
            {
              api: 'admin-selectMusicMeasure',
              start: state.times[0]?.measureNumberPrinted,
              end: state.times[state.times.length - 1]?.measureNumberPrinted,
              speed: state.activeSpeed,
            },
            '*'
          )
        }
      }
    )
    watch(
      () => state.section.length,
      () => {
        if (state.section.length === 2) {
        //   console.log(state.section)
          window.parent.postMessage(
            {
              api: 'admin-selectMusicMeasure',
              start: state.section[0]?.measureNumberPrinted,
              end: state.section[1]?.measureNumberPrinted,
              speed: state.activeSpeed,
              change: true
            },
            '*'
          )
        }
      }
    )
    return () => ''
  },
})
