import { randomID6n } from '../../helpers'
const faker = require('faker')

const dates = [
  '1/1/11', '1.1.11', '1-1-11', '01/01/11', '01.01.11', '01-01-11', '01/01/2011',
  '01.01.2011', '01-01-2011', '01/1/2011', '01.1.2011', '01-1-2011', '1/11/2011',
  '1.11.2011', '1-11-2011', '1/11/11', '1.11.11', '1-11-11', '11/1/11', '11.1.11', '11-1-11',
].concat(Array.from({ length: 42 }, () => '') )

export const fakerDB = length => {
  const data = []
  const cat = window.env.schemas.note.category[1].slice(2, -2).split('|')

  length = length > window.env.fakerAmount*2 ? window.env.fakerAmount : length

  for (let i = 0; i < length; i++) {

    const updated = faker['date'].between('2021-07-01', '2021-10-07')
    let pickedDates = []
    for (let i = 0; i < 4; i++) {
      pickedDates.push(dates[(Math.random() * dates.length) | 0])
    }
    pickedDates = pickedDates.filter(el => el !== '')

    data.push({
      id: randomID6n(),
      title: faker['animal'].snake(),
      category: cat[(Math.random() * cat.length) | 0],
      archive: ['', 'on'][(Math.random() * 2) | 0],
      content: faker['hacker'].phrase() +
        (pickedDates.length > 0 ? '<br/><strong style=\'color: green\'>Dates:</strong> [ ' + pickedDates.join(',  ') : '') +
        ' ]',
      createdAt: faker['date'].between('2021-07-06', '2021-10-01'),
      updatedAt: ['', updated][(Math.random() * 2) | 0],
    })
  }

  return data
}

//console.log( JSON.stringify( data, null, 2 ))
