function formatNumber (n) {
  const str = n.toString()
  return str[1] ? str : `0${str}`
}

export function formatTime (date) {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()

  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  const t1 = [year, month, day].map(formatNumber).join('/')
  const t2 = [hour, minute, second].map(formatNumber).join(':')

  return `${t1} ${t2}`
}

// 专注力与放松力图表
function getLineOption(lineData_att, lineData_med) {
  const that = this
  var option = {
    color: ["#36bffb", "#fd671e"],
    legend: {
      data: ["Att(专注度)", "Med(放松度)"],
      top: -5,
      left: 210,
      // left: 'center',
      orient: "horizontal",
      icon: "circle",
      itemWidth: 8,
      itemGap: 5,
      // 解决部分安卓手机图例字体显示太小的问题
      textStyle: {
        // fontWeight: 'bold',
        fontSize: 10,
        color: "#CFCFCF"
      },
      selectedMode: false,
      show:false
    },
    grid: {
      left: 20,
      right: 20,
      bottom: 16,
      top: 16,
      // show:true,
      containLabel: true
    },
    tooltip: {
      show: true,
      trigger: 'axis'
    },
    yAxis: {
      x: 'center',
      type: 'value',
      splitLine: {
        lineStyle: {
          type: 'dashed'
        }
      },
      axisLine: {
        lineStyle: {
          color: '#ccc'
        },
        show: false
      },
      axisLabel: {
        color: '#ccc'
      },
      max: 100,
      // data: ["0", "20", "40", "60", "80", "100"]
      // show: false
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      splitLine: {
        lineStyle: {
          type: 'dashed'
        }
      },
      axisLine: {
        lineStyle: {
          color: '#ccc'
        }
      },
      axisLabel: {
        color: '#ccc'
      },
      show: false
    },
    series: [{
      name: "Att(专注度)",
      symbol: 'none', //取消折点圆圈
      type: 'line',
      smooth: true,
      data: lineData_att
    },
    {
      name: "Med(放松度)",
      symbol: 'none', //取消折点圆圈
      type: 'line',
      smooth: true,
      data: lineData_med
    },
    ],
    animation: false
  }
  return option
}

// 基本脑波图
function getBaseOption(delta, theta, alpha, beta) {
  const that = this
  var option = {
    color: ["#4b8cb4", "#ed4b59", "#fdb64b", "#F6CB90"],
    legend: {
      data: ["Delta", "Theta", "Alpha", "Beta"],
      left: 'center',
      bottom: 20,
      icon: "circle",
      itemWidth: 8,
      itemGap: 25,
      // 解决部分安卓手机图例字体显示太小的问题
      textStyle: {
        // fontWeight: 'bold',
        fontSize: 10,
        color: "#CFCFCF",
      },
      show:false
    },
    grid: {
      left: 20,
      right: 20,
      bottom: 16,
      top: 16,
      // show:false,
      containLabel: true
    },
    tooltip: {
      show: true,
      trigger: 'axis'
    },
    yAxis: {
      x: 'center',
      type: 'value',
      splitLine: {
        lineStyle: {
          type: 'dashed'
        }
      },
      axisLine: {
        lineStyle: {
          color: '#ccc'
        },
        show: false
      },
      axisLabel: {
        color: '#ccc'
      },
      // max: 100,
      // data: ["0", "20", "40", "60", "80", "100"]
      // show: false
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      splitLine: {
        lineStyle: {
          type: 'dashed'
        }
      },
      axisLine: {
        lineStyle: {
          color: '#ccc'
        }
      },
      axisLabel: {
        color: '#ccc'
      },
      show: false
    },
    series: [{
      name: "Delta",
      symbol: 'none', //取消折点圆圈
      type: 'line',
      smooth: true,
      data: delta
    },
    {
      name: "Theta",
      symbol: 'none', //取消折点圆圈
      type: 'line',
      smooth: true,
      data: theta
    },
    {
      name: "Alpha",
      symbol: 'none', //取消折点圆圈
      type: 'line',
      smooth: true,
      data: alpha
    },
    {
      name: "Beta",
      symbol: 'none', //取消折点圆圈
      type: 'line',
      smooth: true,
      data: beta,
    },
    ],
    animation: false
  }
  return option
}

export default {
  formatNumber,
  formatTime,
  getLineOption,
  getBaseOption
}
