import { Modal } from "antd";
import React, { useEffect } from "react";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import ipcTypes from "../../../ipc.types";
import { setReleaseNotes } from "../../../redux/application/application.actions";
import { selectReleaseNotes } from "../../../redux/application/application.selectors";
const mapStateToProps = createStructuredSelector({
  releaseNotes: selectReleaseNotes,
});
const mapDispatchToProps = (dispatch) => ({
  //setUserLanguage: language => dispatch(setUserLanguage(language))
  setReleaseNotes: (notes) => dispatch(setReleaseNotes(notes)),
});
const { ipcRenderer } = window;

export function ReleaseNotes({ releaseNotes, setReleaseNotes }) {
  console.log("ReleaseNotes -> releaseNotes", releaseNotes);

  useEffect(() => {
    ipcRenderer.send(ipcTypes.app.toMain.getReleaseNotes);
  }, []);

  const handleOk = () => {
    ipcRenderer.send(ipcTypes.store.set, { showChangeLog: false });
    setReleaseNotes(null);
  };

  return (
    <Modal
      open={!!releaseNotes}
      onOk={handleOk}
      onCancel={handleOk}
      cancelButtonProps={{ style: { display: "none" } }}
      title={releaseNotes && releaseNotes.title}
    >
      <div>{releaseNotes && releaseNotes.date}</div>
      <div style={{ whiteSpace: "pre-line" }}>
        {releaseNotes && releaseNotes.notes}
      </div>
    </Modal>
  );
}
export default connect(mapStateToProps, mapDispatchToProps)(ReleaseNotes);
