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 WatcherStartupAtom({ appSettings }) {
  const handleChange = (val) => {
    ipcRenderer.send(ipcTypes.app.toMain.track, {
      event: "TOGGLE_WATCHER_ON_STARTUP",
      enabled: val,
    });

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

  return (
    <div>
      <DataLabel label="Run Watcher on Startup?">
        <Switch
          onChange={handleChange}
          checked={appSettings && appSettings.runWatcherOnStartup}
        />
      </DataLabel>
    </div>
  );
}
export default connect(mapStateToProps, mapDispatchToProps)(WatcherStartupAtom);
