import { defineComponent, reactive, ref, watch } from "vue";
import state, { handleSetSpeed } from "/src/state";

export default defineComponent({
	name: "measureSpeed",
	setup() {
		const isSelected = ref(false);
		const recordSpeed = reactive({
			speed: state.speed,
			originSpeed: state.originSpeed
		}) 
		watch(
			() => state.section.length,
			() => {
				// 只有练习模式生效
				if (state.modeType !== 'practise') return
				// 选段
				if (!isSelected.value && state.section.length === 2) {
					// console.log("设置选段速度");
					isSelected.value = true;
					recordSpeed.speed = state.speed;
					const beatSpeed = state.section[0].beatSpeed;
					state.originSpeed = beatSpeed
					handleSetSpeed(beatSpeed)
				}
				// 设置过基准速度
				if (isSelected.value && state.section.length === 0) {
					// console.log("还原速度");
					isSelected.value = false;
					state.originSpeed = recordSpeed.originSpeed
					handleSetSpeed(recordSpeed.speed)
				}
			}
		);
		return () => <div></div>;
	},
});
