text: const {Router} = require('express')
  const router = Router()
  const Theme = require('../models/Theme')
  const content = require('../json/content.json')
  const {setVars, loadVars} = require('../middleware/theme')
  const ac = require('../json/accent-color.json')
  const cs = require('../json/color-scheme.json')
  
  router.get('/theme', async (req, res) => {
  	const theme = await Theme.findOne({name: 'default'})
  	const vars = loadVars(theme)
  	
  	res.render('theme', {content, theme, vars, inputs: [ac, cs]})
  })
  
  router.post('/theme', async (req, res) => {
  	const theme = await Theme.findOne({name: 'default'})
  
  	theme.darkMode = !!req.body.darkMode
  
  	setVars(req.body.accentColor, ['R', 'G', 'B'], theme)
  	theme.checked.accentColor = JSON.parse(req.body.accentColor).id
  
  	setVars(req.body.colorScheme, ['H', 'S'], theme)
  	theme.checked.colorScheme = JSON.parse(req.body.colorScheme).id
  
  	await theme.save()
  	res.redirect('/')
  })
  
  module.exports = router