{"size": 1367, "ext": "js", "max_stars_repo_path": "src/index.js", "max_stars_repo_name": "Betrayer/goit-js-hw-10-food-service", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/index.js", "max_issues_repo_name": "Betrayer/goit-js-hw-10-food-service", "max_issues_repo_issues_event_min_datetime": "2021-03-10T07:12:24.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T23:27:45.000Z", "max_forks_repo_path": "src/index.js", "max_forks_repo_name": "Betrayer/goit-js-hw-10-food-service", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 26.2884615385, "max_line_length": 77, "alphanum_fraction": 0.7147037308}
'use strict';

import menuItems from './menu.json';
import menuItemsFeed from './tmpl.hbs';
import './styles.css';

const Theme = {
  LIGHT: 'light-theme',
  DARK: 'dark-theme',
};

const refs = {
  menuItems: document.querySelector('.js-menu'),
  bodyElement: document.querySelector('body'),
  themeSwitcher: document.querySelector('#theme-switch-control'),
};

builder(menuItems);

function builder(menuItems) {
  const markup = menuItems.map(menuItem => menuItemsFeed(menuItem)).join('');
  refs.menuItems.insertAdjacentHTML('afterbegin', markup);
}

refs.themeSwitcher.addEventListener('change', themeChange);

function themeChange() {
  if (!refs.themeSwitcher.checked) {
    refs.bodyElement.classList.remove(Theme.DARK);
    refs.bodyElement.classList.add(Theme.LIGHT);
    localStorage.setItem('theme', Theme.LIGHT);
  } else {
    refs.bodyElement.classList.remove(Theme.LIGHT);
    refs.bodyElement.classList.add(Theme.DARK);
    localStorage.setItem('theme', Theme.DARK);
  }
}

smth();

function smth() {
  if (localStorage.getItem('theme') === Theme.DARK) {
    refs.themeSwitcher.checked = true;
    refs.bodyElement.classList.remove(Theme.LIGHT);
    refs.bodyElement.classList.add(Theme.DARK);
  } else {
    refs.themeSwitcher.checked = false;
    refs.bodyElement.classList.remove(Theme.DARK);
    refs.bodyElement.classList.add(Theme.LIGHT);
  }
}
