import res from '../config/resources'
import { makeResourceItem } from './helpers'

let offers = []

export const update = () => {
    const items = Object.keys(res)
        .filter(item => res[item].market)
        .sort(() => Math.random() - 0.5)
        .slice(0, 6)

    const from = [items[0], items[1], items[2]]
    const to = [items[3], items[4], items[5]]

    offers = from.map((_, i) => {
        return {
            id: i,
            from: makeResourceItem(from[i], 50, 150),
            to: makeResourceItem(to[i], 50, 150)
        }
    })
}

export const removeOffer = id => {
    offers = offers.filter(item => item.id !== id)
}

export const get = () => offers

export default {
    update,
    get,
    removeOffer
}
