<template>
  <div class="rhythmPracticeList">
    <div class="headCon">
      <div class="headLeft">
        <img class="tipImg" src="@/views/Editor/CanvasTool/imgs/jzlx.png" alt="" />
        <div class="title">节奏练习</div>
      </div>
      <div class="headright">
        <img @click="emits('close')" class="closeBtn" src="../../cloudCoachElement/cloudCoachList/imgs/close.png" alt="" />
      </div>
    </div>
    <div class="content">
      <rhythmPracticePlayer @handleIframeLoad="handleIframeLoad" :settingMode="true" ref="rhythmPracticePlayerDom" :width="1098" :height="618" />
    </div>
    <div class="btnCon">
      <div class="cancelBtn" @click="emits('close')">取消</div>
      <div class="addBtn" :class="{ disabled: loading }" @click="handleAddrhythmPractice">添加</div>
    </div>
  </div>
</template>

<script setup lang="ts">
import rhythmPracticePlayer from "../rhythmPracticePlayer"
import { ref } from "vue"
import { rhythmPracticeMes } from "@/messageHooks/rhythmPractice"

const emits = defineEmits<{
  (event: "update", value: string): void
  (event: "close"): void
}>()

const loading = ref(true)
const rhythmPracticePlayerDom = ref<InstanceType<typeof rhythmPracticePlayer>>()
const { getRhythmPracticeSetting } = rhythmPracticeMes()

async function handleAddrhythmPractice() {
  if (loading.value) return
  try {
    const rhythmPracticeSetting = await getRhythmPracticeSetting(rhythmPracticePlayerDom.value?.rhythmPracticeIframeDom)
    emits("update", rhythmPracticeSetting)
  } catch (e) {
    console.log(e)
  }
}
function handleIframeLoad() {
  loading.value = false
}
</script>

<style lang="scss" scoped>
.rhythmPracticeList {
  width: 100%;
  height: 100%;
  .headCon {
    width: 100%;
    height: 64px;
    border-bottom: 1px solid #eaeaea;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .headLeft {
      margin-left: 30px;
      display: flex;
      align-items: center;
      .tipImg {
        width: 24px;
        height: 24px;
      }
      .title {
        font-weight: 600;
        font-size: 18px;
        color: #131415;
        margin-left: 8px;
      }
    }
    .headright {
      margin-right: 30px;
      display: flex;
      align-items: center;
      .closeBtn {
        width: 24px;
        height: 24px;
        cursor: pointer;
        &:hover {
          opacity: 0.8;
        }
      }
    }
  }
  .content {
    width: 100%;
    height: calc(100% - 130px);
  }
  .btnCon {
    width: 100%;
    height: 66px;
    padding: 0 30px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    .addBtn {
      width: 76px;
      height: 34px;
      background: linear-gradient(312deg, #1b7af8 0%, #3cbbff 100%);
      border-radius: 6px;
      line-height: 34px;
      text-align: center;
      font-weight: 600;
      font-size: 14px;
      color: #ffffff;
      cursor: pointer;
      &:hover {
        opacity: 0.8;
      }
      &.disabled {
        opacity: 0.7;
        cursor: default;
      }
    }
    .cancelBtn {
      margin-right: 12px;
      width: 76px;
      height: 34px;
      background: #f1f2f6;
      border-radius: 6px;
      line-height: 34px;
      text-align: center;
      font-weight: 600;
      font-size: 14px;
      color: #1e2022;
      cursor: pointer;
      &:hover {
        opacity: 0.8;
      }
    }
  }
}
</style>
