import { Switch } from "antd";
import React from "react";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import ipcTypes from "../../../ipc.types";
import { selectSettings } from "../../../redux/application/application.selectors";
import DataLabel from "../../atoms/data-label/data-label.atom";
const { ipcRenderer } = window;

const mapStateToProps = createStructuredSelector({
  //currentUser: selectCurrentUser
  appSettings: selectSettings,
});
const mapDispatchToProps = (dispatch) => ({
  //setUserLanguage: language => dispatch(setUserLanguage(language))
});

export function NotificationsToggleAtom({ appSettings }) {
  const handleChange = (val) => {
    ipcRenderer.send(ipcTypes.app.toMain.track, {
      event: "TOGGLE_NOTIFICATION",
      enabled: val,
    });

    ipcRenderer.send(ipcTypes.store.set, {
      enableNotifications: val,
    });
  };

  return (
    <div>
      <DataLabel label="Notifications Enabled?">
        <Switch
          onChange={handleChange}
          checked={appSettings && appSettings.enableNotifications}
        />
      </DataLabel>
    </div>
  );
}
export default connect(
  mapStateToProps,
  mapDispatchToProps
)(NotificationsToggleAtom);
