import React from "react";
import PropTypes from "prop-types";
import { GrayButton } from "../MyProfile.styled";
import { PopoverButton } from "../../HeaderPopover/HeaderPopover.styled";
import { BuildingShieldIcon } from "./PrivacyPolicyButton.styled";
import { ABOUT_PAGE } from "../../../../constants/pages";
import { useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";
import scrollConstants from "../../../../constants/scrollConstants";
import { routeMatches } from "../../../../util/helpers/routeHelpers";

const PrivacyPolicyButton = (props) => {
  const { t } = useTranslation();
  const history = useHistory();
  const seePrivacy = () => {
    if (!routeMatches(ABOUT_PAGE)) {
      history.push({
        pathname: ABOUT_PAGE,
        state: {
          clicked: true,
          navigation: scrollConstants.about.privacyPolicyPage,
        },
      });
    } else {
      history.replace({
        state: {
          clicked: true,
          navigation: scrollConstants.about.privacyPolicyPage,
        }
      })
    }
    props.closePopover();
  };
  return (
    <GrayButton>
      <PopoverButton
        sx={{
          mr: 2,
          mb: 2,
        }}
        variant="text"
        endIcon={<BuildingShieldIcon />}
        onClick={seePrivacy}
      >
        {t("header.privacy")}
      </PopoverButton>
    </GrayButton>
  );
};

PrivacyPolicyButton.propTypes = {
  children: PropTypes.node,
  closePopover: PropTypes.func,
};

export default PrivacyPolicyButton;
