import { reactive } from 'vue'
import { GradualNote } from './calcSpeed'
import { IDifficulty } from './setting-state'

type IRenderType = 'native' | 'cache'
type IMode = 'homework' | 'contact' | 'evaluating'

export enum GradualVersion {
  BASE,
  ENSEMBLE
}


type URLSetting = {
  mode?: 'EVALUATING',
  resets?: ['SPEED'],
  difficulty?: IDifficulty,
  feeType?: 'FREE',
  submitData?: any
}

const state = reactive({
  sectionStatus: false,
  maskStatus: false,
  section: [] as any[],
  times: [] as any[],
  sectionBoundingBoxs: [] as any[],
  activeTick: -1,
  activeTickRepeat: 1,
  showTick: false,
  isSpecialShapedScreen: false,
  notchHeight: 0,
  fixedKey: 0,
  renderLoading: false,
  evaluatings: {} as any,
  isPauseRecording: false,
  feeShow: false,
  vipShow: false,
  mode: 'contact' as IMode,
  subjectId: 0 as number,
  activeSpeed: 90 as number, // 当前速度
  baseSpeed: 90 as number, // 基准速度
  activeDetail: null as any,
  needTick: false, // 是否需要节拍器
  /** 跳过节拍器 */
  skipTick: false,
  /** 重复节拍 */
  repeatedBeats: false,
  sectionFlash: false,
  befireSection: null as any,
  /** 是否是打击乐 true: 是, false: 不是 */
  isPercussion: false,
  enableEvaluation: true, // 是否开启评测
  isAppPlay: false, // 是否是app播放
  partListNames: [] as string[], // 当前曲谱中所有声部名字
  partIndex: 0, // 当前显示声部索引
  partName: '', //当前显示声部名字
  midiPlayIniting: false, // midi播放器是否初始化中
  isSpecialBookCategory: false, // 是否是特殊乐谱类型
  // 声部对应code
  code: '',
  /** 是否冻结模式 */
  frozenMode: false,
  /** 初次render结束 */
  initRendered: false,
  /** URL参数设置 */
  setting: null as null | URLSetting,
  /**当前激活的note */
  activeNote: '' as any,
  /** 免费试用比例，默认10% */
  freeRate: 0.1 as number,
  /** 渲染比例 */
  zoom: 1,
  /** 渲染模式*/
  renderType: 'native' as IRenderType,
  /** 渐变速度信息 */
  gradual: [] as GradualNote[],
  /** 渐变速度版本 */
  /** 渐变时间信息 */
  gradualTimes: null as GradualTimes,
  /** 单声部多声轨 */
  multitrack: 0,
  /** 渐变速度版本 */
  gradualVersion: GradualVersion.BASE as GradualVersion,
  /** 是否需要刷新选段小节，谱面重新渲染后需要刷新选段小节 */
  isNeedRefreshSection: false,
  /** 是否是课后训练模式 */
  isLessonTrain: false,
  /** 是否隐藏评测报告弹窗，保存演奏按钮，默认不隐藏 */
  isHideEvaluatReportSaveBtn: false,    
  /** 合奏曲目是否合并展示 */
  isCombineRender: false,
  /** 大雅金唐类目 */
  isDaYaCategory: false,
})

export const isRhythmicExercises = (musicName?: string) => {
  const examSongName = musicName ? musicName : state?.activeDetail?.musicSheetName || ''
  // console.log("🚀 ~ examSongName:", examSongName,state)
  return examSongName.indexOf('节奏练习') > -1
}

export default state
export type GradualTimes = null | {
  [key: string]: string
}