
import axios from 'axios'

axios.defaults.headers.Accept = 'application/vnd.github.v3.html'

const loadurl = ({url, data = {} }) => {
    if (window.config.token) {
        data.access_token = window.config.token.split('#').join('')
    }

    return url +'?'+ Object.keys(data).map(key => key +'='+ data[key]).join('&')
}

export const timeFormat = (time) => {
    const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    const data = new Date(time)
    const day = data.getDate()
    const monthIndex = data.getMonth()
    const year = data.getFullYear()
    return `${months[monthIndex]} ${day}, ${year}`
}

export const titleFormat = (title) => title.split(/\[.*?\]/g).join('')

export const load = (...args) => {
    const rqs = args.map(arg => axios.get(loadurl(arg)))
    return axios.all(rqs).then(axios.spread((...res) => res))
}

export const $ = (dom) => {
    dom = document.querySelectorAll(dom)

    if (dom.length > 1) {
        return dom
    }

    return dom[0]
}

export const clone = (o) => JSON.parse(JSON.stringify(o))

export const box = (src) => {
    if (!src) {
        const el = document.querySelector('.box')
        if (el) {
            return document.body.removeChild(el)
        }
        return
    }

    const tpl = `
        <div class="box">
            <img src="${src}" />
        </div>
    `

    document.body.innerHTML += tpl
}

// http://jsfiddle.net/salman/f9Re3/
export const invert = (color) => {
    color = parseInt(color, 16)
    color = 0xFFFFFF ^ color
    color = color.toString(16)
    color = `000000${color}`.slice(-6)

    return color
}
@@ -1418,227 +1418,4 @@
 l%0A%7D%0A
-%0A// http://jsfiddle.net/salman/f9Re3/%0Aexport const invert = (color) =%3E %7B%0A    color = parseInt(color, 16)%0A    color = 0xFFFFFF %5E color%0A    color = color.toString(16)%0A    color = %60000000$%7Bcolor%7D%60.slice(-6)%0A%0A    return color%0A%7D

remove invert function