'use strict'

/* eslint-disable require-jsdoc, no-unused-vars */

var CalendarList = []

function CalendarInfo () {
  this.id = null
  this.name = null
  this.checked = true
  this.color = null
  this.bgColor = null
  this.borderColor = null
  this.dragBgColor = null
}

function addCalendar (calendar) {
  CalendarList.push(calendar)
}

function findCalendar (id) {
  var found

  CalendarList.forEach(function (calendar) {
    if (calendar.id === id) {
      found = calendar
    }
  })

  return found || CalendarList[0]
}

function hexToRGBA (hex) {
  var radix = 16
  var r = parseInt(hex.slice(1, 3), radix)
  var g = parseInt(hex.slice(3, 5), radix)
  var b = parseInt(hex.slice(5, 7), radix)
  var a = parseInt(hex.slice(7, 9), radix) / 255 || 1
  var rgba = 'rgba(' + r + ', ' + g + ', ' + b + ', ' + a + ')'

  return rgba
}

(function () {
  if (CalendarList.length === 0) {
    var cList = JSON.parse(localStorage.getItem('calendarList2'))
    for (var i = 0; i < cList.length; i++) {
      console.log(cList[i].id)
      var calendar = new CalendarInfo()
      calendar.id = cList[i].id
      calendar.name = cList[i].name
      calendar.color = cList[i].color
      calendar.bgColor = cList[i].bgColor
      calendar.dragBgColor = cList[i].dragBgColor
      calendar.borderColor = cList[i].borderColor
      addCalendar(calendar)
    }
  }
})()
