import React, { useState } from 'react';
import { useLocation } from 'react-router-dom';
import Switcher from '../Switcher/Switcher';
import { contextArr } from '../../db';
import './Setting.scss';
export default function Component() {
const location = useLocation();
let [lang, setLang] = useState('en');
const chooseLang = (e) => {
setLang(e.target.checked ? (lang = 'ua') : (lang = 'en'));
};
window.location = location.pathname + '#' + lang;
for (let key in contextArr) {
let elem = document.querySelector('.lng-' + key);
if (elem) {
elem.innerHTML = contextArr[key][lang];
}
}
return (
<section id='setting'>
<Switcher
id='lang'
title='Language'
label_lt='English'
label_rt='Українська'
value={lang}
onClick={chooseLang}
/>
</section>
);
}