import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import React, { useState } from 'react';
import BrowserWarning from './BrowserWarning';
import Modal from '../../components/Modal';
import Link from '../../components/Link';
import InfoBar from '../../components/InfoBar';
import markdown from './README.mdx';
export default {
  title: 'Templates/Browser warning (outdated)',
  component: BrowserWarning,
  parameters: {
    componentSubtitle: 'Template',
    status: 'legacy',
    mdx: markdown,
    previewWidth: 'full'
  }
};
export var ErrorDialog = function ErrorDialog(args) {
  var _useState = useState(true),
      _useState2 = _slicedToArray(_useState, 2),
      open = _useState2[0],
      setOpen = _useState2[1];

  var isIE = function isIE() {
    var ua = window.navigator.userAgent; //Check the userAgent property of the window.navigator object

    var msie = ua.indexOf('MSIE '); // IE 10 or older

    var trident = ua.indexOf('Trident/'); //IE 11
    //Remove this line in production and use second line

    return true; //return msie > 0 || trident > 0;
  };

  var toggleModal = function toggleModal() {
    setOpen(!open);
  };

  var submitAndClose = function submitAndClose() {
    setOpen(false);
  };

  if (isIE()) return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
    onClick: toggleModal
  }, "Manually open warning modal"), /*#__PURE__*/React.createElement(Modal, {
    open: open,
    primaryButtonText: "Continue with current browser",
    onRequestSubmit: submitAndClose,
    modalHeading: "Outdated browser",
    onRequestClose: toggleModal,
    danger: true
  }, /*#__PURE__*/React.createElement("p", {
    className: "wfp--modal-content__text"
  }, "It looks like you are using Internet Explorer 11 or older as your favourite browser. We recommend that you switch to a more modern browser to ensure that you get the best experience out of this application. ", /*#__PURE__*/React.createElement(Link, {
    href: "#"
  }, "Learn more on go.wfp.org."))));
  return null;
};
export var Warning = function Warning(args) {
  return /*#__PURE__*/React.createElement(InfoBar, null, "Your browser version is outdated. ", /*#__PURE__*/React.createElement(Link, {
    href: "#"
  }, "Please upgrade"));
};
Warning.story = {
  parameters: {
    docs: {
      storyDescription: "In cases the applications works with minor restrictions and you just want to inform the user you can show a <InfoBar />."
    }
  }
};