// 查看方式
export const viewMethodList = [
  { value: 'independent', label: '独立排放' },
  { value: 'list', label: '播放列表' },
];

// 序号显示方式
export const displayList = [
  { value: 'true', label: '显示' },
  { value: 'false', label: '隐藏' },
];

// 序号类型
export const serialNumberTypeList = [
  { value: 'number', label: '数字' },
  { value: 'bracket_number', label: '括号数字' },
  { value: 'letter', label: '字母' },
  { value: 'capital', label: '大写字母' },
];

// 序号位置
export const serialNumberPositionList = [
  { value: 'top-start', justifyContent: 'flex-start' },
  { value: 'top', justifyContent: 'center' },
  { value: 'top-end', justifyContent: 'flex-end' },
  { value: 'left-start', justifyContent: 'flex-start' },
  { value: 'left', justifyContent: 'center' },
  { value: 'left-end', justifyContent: 'flex-end' },
  { value: 'right-start', justifyContent: 'flex-start' },
  { value: 'right', justifyContent: 'center' },
  { value: 'right-end', justifyContent: 'flex-end' },
  { value: 'bottom-start', justifyContent: 'flex-start' },
  { value: 'bottom', justifyContent: 'center' },
  { value: 'bottom-end', justifyContent: 'flex-end' },
];

// 序号样式
export const serialNumberStyleList = [
  { value: 'solidBlockStyle' }, // 实心方块
  { value: 'solidCircleStyle' }, // 实心圆
  { value: 'hollowBlockStyle' }, // 空心方块
  { value: 'hollowCircleStyle' }, // 空心圆
  { value: 'defaultStyle' }, // 默认无
];

// 拼音位置
export const pinyinPositionList = [
  { value: 'top', label: '上' },
  { value: 'bottom', label: '下' },
];

// 排列方式
export const arrangeTypeList = [
  { value: 'horizontal', label: '横排' },
  { value: 'vertical', label: '竖排' },
];

export const switchOption = [
  {
    value: 'true',
    label: '开启',
  },
  {
    value: 'false',
    label: '关闭',
  },
];

/**
 * 是否开启
 * @param {String} value 值
 * @returns Boolean
 */
export function isEnable(value) {
  return value === switchOption[0].value;
}

export const tone_data = [
  ['ā', 'á', 'ǎ', 'à', 'a'],
  ['ō', 'ó', 'ǒ', 'ò', 'o'],
  ['ē', 'é', 'ě', 'è', 'e'],
  ['ī', 'í', 'ǐ', 'ì', 'i'],
  ['ū', 'ú', 'ǔ', 'ù', 'u'],
  ['ǖ', 'ǘ', 'ǚ', 'ǜ', 'ü'],
  ['ǖ', 'ǘ', 'ǚ', 'ǜ', 'ü'],
  ['Ā', 'Á', 'Â', 'À', 'A'],
  ['Ō', 'Ó', 'Ô', 'Ò', 'O'],
  ['Ē', 'É', 'Ê', 'È', 'E'],
  ['Ī', 'Í', 'Î', 'Ì', 'I'],
  ['Ū', 'Ú', 'Û', 'Ù', 'U'],
];

/**
 * 添加声调
 * @param {Number} number
 * @param {String} con
 * @returns String
 */
export function addTone(number, con) {
  const zmList = ['a', 'o', 'e', 'i', 'u', 'v', 'ü', 'A', 'O', 'E', 'I', 'U'];
  let cons = con;
  if (number) {
    for (let i = 0; i < zmList.length; i++) {
      let zm = zmList[i];
      if (con.includes(zm)) {
        let zm2 = tone_data[i][number - 1];
        if (con.includes('iu')) {
          zm2 = tone_data[4][number - 1];
          cons = con.replace('u', zm2);
        } else if (con.includes('ui')) {
          zm2 = tone_data[3][number - 1];
          cons = con.replace('i', zm2);
        } else if (/yv|jv|qv|xv/.test(con)) {
          zm2 = tone_data[4][number - 1];
          cons = con.replace('v', zm2);
        } else if (/yü|jü|qü|xü/.test(con)) {
          zm2 = tone_data[4][number - 1];
          cons = con.replace('ü', zm2);
        } else {
          cons = con.replace(zm, zm2);
        }

        break;
      }
    }
  }
  return cons;
}

export function handleToneValue(valItem) {
  let numList = [];
  if (/[A-Za-zü]+\d/g.test(valItem)) {
    valItem.split('').forEach((item, i) => {
      if (/\d/.test(item)) {
        let numIndex = numList.length === 0 ? 0 : numList[numList.length - 1].index;
        let con = valItem.substring(numIndex, i).replace(/\d/g, '');
        numList.push({
          number: item,
          con,
        });
      }
    });
  } else {
    numList = [];
  }

  return numList.length === 0 ? [{ con: valItem }] : numList;
}

/**
 * 判断序号类型
 * @param {string} str
 */
export function checkString(str) {
  const number = /^\d/.test(str); // 判断是否包含数字
  const letter = /^[a-z]/.test(str); // 判断是否包含字母
  const capital = /^[A-Z]/.test(str); // 判断是否包含大写字母
  const bracket_number = /\(\d+\)/.test(str); // 判断是否包含括号数字，例如 (123)
  const obj = { number, letter, capital, bracket_number };
  let strType = Object.keys(obj).find((key) => obj[key]);
  return strType;
}

// 计算选项方法
export const computeOptionMethods = {
  [serialNumberTypeList[0].value]: (i) => `${i + 1}`,
  [serialNumberTypeList[1].value]: (i) => `(${i + 1})`,
  [serialNumberTypeList[2].value]: (i) => `${String.fromCharCode(97 + i)}`, // 小写
  [serialNumberTypeList[3].value]: (i) => `${String.fromCharCode(65 + i)}`, // 大写
};

// 反向计算选项方法
export const reversedComputeOptionMethods = {
  [serialNumberTypeList[0].value]: (i) => Number(i),
  [serialNumberTypeList[1].value]: (i) => Number(i.replace('(', '').replace(')', '')),
  [serialNumberTypeList[2].value]: (i) => i.charCodeAt(0) - 97 + 1, // 小写
  [serialNumberTypeList[3].value]: (i) => i.charCodeAt(0) - 65 + 1,
};
