<commit_before>// This file is part of Indico.
// Copyright (C) 2002 - 2019 CERN
//
// Indico is free software; you can redistribute it and/or
// modify it under the terms of the MIT License; see the
// LICENSE file for more details.

import contactURL from 'indico-url:core.contact';
import tosURL from 'indico-url:legal.display_tos';
import privacyPolicyURL from 'indico-url:legal.display_privacy';

import React, {useState} from 'react';
import PropTypes from 'prop-types';
import {Icon, Menu, Modal, Popup} from 'semantic-ui-react';
import {connect} from 'react-redux';
import {Translate} from 'indico/react/i18n';
import {Responsive} from 'indico/react/util';
import {selectors as configSelectors} from '../common/config';

const buildMenuItems = (helpURL, hasTOS, hasPrivacyPolicy, contactEmail) => {
  const menuItems = [
    [
      'help',
      {
        href: helpURL,
        target: '_blank',
        rel: 'noopener noreferrer',
        caption: Translate.string('Help'),
        icon: 'question',
      },
    ],
  ];

  if (contactEmail) {
    menuItems.push([
      'contact',
      {
        href: contactURL(),
        modal: true,
        caption: Translate.string('Contact'),
        icon: 'at',
      },
    ]);
  }
  if (hasTOS) {
    menuItems.push([
      'tos',
      {
        href: tosURL(),
        modal: true,
        target: '_blank',
        rel: 'noopener noreferrer',
        caption: Translate.string('Terms and Conditions'),
        icon: 'file text',
      },
    ]);
  }
  if (hasPrivacyPolicy) {
    menuItems.push([
      'privacy',
      {
        href: privacyPolicyURL(),
        modal: true,
        target: '_blank',
        rel: 'noopener noreferrer',
        caption: Translate.string('Privacy Policy'),
        icon: 'eye',
      },
    ]);
  }
  return menuItems;
};

function SidebarFooter({
  hasTOS,
  tosHTML,
  hasPrivacyPolicy,
  privacyPolicyHTML,
  helpURL,
  contactEmail,
}) {
  const [currentModal, setModal] = useState(null);

  function openModal(e, id) {
    setModal(id);
    e.preventDefault();
  }

  const items = buildMenuItems(helpURL, hasTOS, hasPrivacyPolicy, contactEmail);

  return (
    <>
      <Responsive.Phone andLarger minHeight={600}>
        <Menu.Item>
          {items.map(([id, {href, icon, modal, caption, ...extraProps}]) => (
            <Popup
              key={id}
              inverted
              position="bottom right"
              trigger={
                <a href={href} onClick={modal && (e => openModal(e, id))} {...extraProps}>
                  <Icon size="large" name={icon} />
                </a>
              }
            >
              {caption}
            </Popup>
          ))}
        </Menu.Item>
      </Responsive.Phone>
      {contactEmail && (
        <Modal
          open={currentModal === 'contact'}
          size="tiny"
          closeIcon
          onClose={() => setModal(null)}
        >
          <Modal.Header>
            <Translate>Contact</Translate>
          </Modal.Header>
          <Modal.Content>
            <div>
              <Translate>
                If you need support, you can contact the following email address:
              </Translate>
            </div>
            <div>
              <a href={`mailto:${contactEmail}`}>{contactEmail}</a>
            </div>
          </Modal.Content>
        </Modal><commit_msg>Add workaround for babel/babel#10257<commit_after>// This file is part of Indico.
// Copyright (C) 2002 - 2019 CERN
//
// Indico is free software; you can redistribute it and/or
// modify it under the terms of the MIT License; see the
// LICENSE file for more details.

import contactURL from 'indico-url:core.contact';
import tosURL from 'indico-url:legal.display_tos';
import privacyPolicyURL from 'indico-url:legal.display_privacy';

import React, {useState} from 'react';
import PropTypes from 'prop-types';
import {Icon, Menu, Modal, Popup} from 'semantic-ui-react';
import {connect} from 'react-redux';
import {Translate} from 'indico/react/i18n';
import {Responsive} from 'indico/react/util';
import {selectors as configSelectors} from '../common/config';

const buildMenuItems = (helpURL, hasTOS, hasPrivacyPolicy, contactEmail) => {
  const menuItems = [
    [
      'help',
      {
        href: helpURL,
        target: '_blank',
        rel: 'noopener noreferrer',
        caption: Translate.string('Help'),
        icon: 'question',
      },
    ],
  ];

  if (contactEmail) {
    menuItems.push([
      'contact',
      {
        href: contactURL(),
        modal: true,
        caption: Translate.string('Contact'),
        icon: 'at',
      },
    ]);
  }
  if (hasTOS) {
    menuItems.push([
      'tos',
      {
        href: tosURL(),
        modal: true,
        target: '_blank',
        rel: 'noopener noreferrer',
        caption: Translate.string('Terms and Conditions'),
        icon: 'file text',
      },
    ]);
  }
  if (hasPrivacyPolicy) {
    menuItems.push([
      'privacy',
      {
        href: privacyPolicyURL(),
        modal: true,
        target: '_blank',
        rel: 'noopener noreferrer',
        caption: Translate.string('Privacy Policy'),
        icon: 'eye',
      },
    ]);
  }
  return menuItems;
};

function SidebarFooter({
  hasTOS,
  tosHTML,
  hasPrivacyPolicy,
  privacyPolicyHTML,
  helpURL,
  contactEmail,
}) {
  const [currentModal, setModal] = useState(null);

  function openModal(e, id) {
    setModal(id);
    e.preventDefault();
  }

  const items = buildMenuItems(helpURL, hasTOS, hasPrivacyPolicy, contactEmail);

  return (
    <>
      <Responsive.Phone andLarger minHeight={600}>
        <Menu.Item>
          {items.map(([id, item]) => {
            // XXX: Babel doesn't transpile [x, {y, ...rest}] correctly
            // https://github.com/babel/babel/issues/10257
            const {href, icon, modal, caption, ...extraProps} = item;
            return (
              <Popup
                key={id}
                inverted
                position="bottom right"
                trigger={
                  <a href={href} onClick={modal && (e => openModal(e, id))} {...extraProps}>
                    <Icon size="large" name={icon} />
                  </a>
                }
              >
                {caption}
              </Popup>
            );
          })}
        </Menu.Item>
      </Responsive.Phone>
      {contactEmail && (
        <Modal
          open={currentModal === 'contact'}
          size="tiny"
          closeIcon
          onClose={() => setModal(null)}
        >
          <Modal.Header>
            <Translate>Contact</Translate>
          </Modal.Header>
          <Modal.Content>
            <div>
              <Translate>
                If you need support, you can contact the following email address:
              </Translate>
            </div>
            <div>
              <a href={`mailto:${contactEmail}`}>{contactEmail}</a>
            </div>
          </Modal.Content>
        </Modal>
{'fraction_non_alphanumeric': 0.13657838224767357, 'fraction_numerical': 0.0051539012168933425, 'mean_word_length': 1.9023680930619027, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 63, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5523784', 'n_tokens_mistral': 2141, 'n_tokens_neox': 2077, 'n_words': 501}