import axios from "axios";
import { useEffect } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { setBreadcrumbs, setSelectedHeader } from "../../redux/application/application.actions";
import InstanceRenderManager from "../../utils/instanceRenderMgr";

const mapDispatchToProps = (dispatch) => ({
  setBreadcrumbs: (breadcrumbs) => dispatch(setBreadcrumbs(breadcrumbs)),
  setSelectedHeader: (key) => dispatch(setSelectedHeader(key))
});

export function FeedbackPage({ setBreadcrumbs, setSelectedHeader }) {
  const { t } = useTranslation();

  useEffect(() => {
    document.title = t("titles.feature-request", {
      app: InstanceRenderManager({
        imex: "$t(titles.imexonline)",
        rome: "$t(titles.romeonline)"
      })
    });
    setBreadcrumbs([{ link: "/manage/feature-request", label: t("titles.bc.feature-request") }]);
  }, [t, setBreadcrumbs, setSelectedHeader]);

  useEffect(() => {
    async function RenderCanny() {
      const ssoToken = await axios.post("/sso/canny");
      window.Canny("render", {
        boardToken: "bba97b06-70db-0334-dee7-8108d73ef614",
        basePath: `/manage/feature-request`, // See step 2
        ssoToken: ssoToken.data, // See step 3,
        theme: "light" // options: light [default], dark, auto
      });
    }

    RenderCanny();
  }, []);

  return <div data-canny />;
}

export default connect(null, mapDispatchToProps)(FeedbackPage);
