import React from "react";
import { LanguageContext, languages } from "./LanguageContext";

export class LanguageProvider extends React.Component {
  constructor(props) {
    super(props);

    this.state = { language: languages.german };
    this.changeLanguage = this.changeLanguage.bind(this);
  }

  changeLanguage = (language) => {
    this.setState({
      language: language === "en" ? languages.english : languages.german,
    });
  };

  render() {
    return (
      <LanguageContext.Provider
        value={{
          language: this.state.language,
          changeLanguage: this.changeLanguage,
        }}
      >
        {this.props.children}
      </LanguageContext.Provider>
    );
  }
}
