"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.UsaBanner = void 0;
var _compat = _interopRequireWildcard(require("preact/compat"));
var _classnames = _interopRequireDefault(require("classnames"));
var _useCssDebugger = _interopRequireDefault(require("../utilities/useCssDebugger"));
var _useId = _interopRequireDefault(require("../utilities/useId"));
var _i18n = require("../i18n");
var _Icons = require("../Icons");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
/**
 * For information about how and when to use this component,
 * [refer to its full documentation page](https://design.cms.gov/components/usa-banner/).
 */
var UsaBanner = function UsaBanner(props) {
  (0, _useCssDebugger.default)();
  var _useState = (0, _compat.useState)(false),
    _useState2 = _slicedToArray(_useState, 2),
    isBannerOpen = _useState2[0],
    setBannerOpen = _useState2[1];
  var classes = (0, _classnames.default)('ds-c-usa-banner', props.className);
  var rootId = (0, _useId.default)('usa-banner--', props.id);
  var panelId = "".concat(rootId, "__panel");
  var toggleBanner = function toggleBanner() {
    setBannerOpen(!isBannerOpen);
  };
  var actionText = /*#__PURE__*/_compat.default.createElement(_compat.default.Fragment, null, (0, _i18n.t)('usaBanner.bannerActionText'), /*#__PURE__*/_compat.default.createElement(_Icons.ArrowIcon, {
    direction: isBannerOpen ? 'up' : 'down',
    className: "ds-c-usa-banner__action-icon"
  }));
  return /*#__PURE__*/_compat.default.createElement("section", {
    className: classes,
    "aria-label": (0, _i18n.t)('usaBanner.bannerLabel')
  }, /*#__PURE__*/_compat.default.createElement("header", {
    className: (0, _classnames.default)('ds-c-usa-banner__header ds-u-font-size--sm', isBannerOpen && 'ds-c-usa-banner__header--expanded')
  }, /*#__PURE__*/_compat.default.createElement(_Icons.UsaFlagIcon, {
    className: "ds-c-usa-banner__header-icon"
  }), /*#__PURE__*/_compat.default.createElement("p", {
    className: "ds-c-usa-banner__header-text"
  }, (0, _i18n.t)('usaBanner.bannerText')), /*#__PURE__*/_compat.default.createElement("p", {
    className: (0, _classnames.default)('ds-c-usa-banner__action ds-u-align-items--center ds-u-md-display--none', !isBannerOpen && 'ds-u-display--flex')
  }, actionText), /*#__PURE__*/_compat.default.createElement("button", {
    type: "button",
    onClick: toggleBanner,
    className: "ds-c-usa-banner__button",
    "aria-expanded": isBannerOpen,
    "aria-controls": panelId
  }, /*#__PURE__*/_compat.default.createElement("span", {
    className: "ds-c-usa-banner__button-text ds-u-md-display--flex ds-u-align-items--center"
  }, actionText), /*#__PURE__*/_compat.default.createElement("span", {
    className: "ds-c-usa-banner__button-icon-container",
    hidden: !isBannerOpen
  }, /*#__PURE__*/_compat.default.createElement(_Icons.CloseIconThin, {
    className: "ds-c-usa-banner__button-icon"
  })))), /*#__PURE__*/_compat.default.createElement("div", {
    className: "ds-c-usa-banner__guidance [ ds-u-leading--base ds-u-font-size--base ]"
  }, /*#__PURE__*/_compat.default.createElement("div", {
    id: panelId,
    className: "ds-c-usa-banner__guidance-container",
    hidden: !isBannerOpen
  }, /*#__PURE__*/_compat.default.createElement("div", {
    className: "ds-c-usa-banner__guidance-item"
  }, /*#__PURE__*/_compat.default.createElement(_Icons.BuildingCircleIcon, {
    className: "ds-c-usa-banner__guidance-icon"
  }), /*#__PURE__*/_compat.default.createElement("p", {
    className: "ds-c-usa-banner__guidance-text"
  }, /*#__PURE__*/_compat.default.createElement("strong", null, (0, _i18n.t)('usaBanner.domainHeaderText')), /*#__PURE__*/_compat.default.createElement("br", null), "".concat((0, _i18n.t)('usaBanner.domainAText'), " "), /*#__PURE__*/_compat.default.createElement("strong", null, " ".concat((0, _i18n.t)('usaBanner.govText'), " ")), (0, _i18n.t)('usaBanner.domainText'))), /*#__PURE__*/_compat.default.createElement("div", {
    className: "ds-c-usa-banner__guidance-item"
  }, /*#__PURE__*/_compat.default.createElement(_Icons.LockCircleIcon, {
    className: "ds-c-usa-banner__guidance-icon"
  }), /*#__PURE__*/_compat.default.createElement("p", {
    className: "ds-c-usa-banner__guidance-text"
  }, /*#__PURE__*/_compat.default.createElement("strong", null, (0, _i18n.t)('usaBanner.httpsHeaderText')), /*#__PURE__*/_compat.default.createElement("br", null), "".concat((0, _i18n.t)('usaBanner.httpsAText'), " "), /*#__PURE__*/_compat.default.createElement("strong", null, "".concat((0, _i18n.t)('usaBanner.httpsLockText'), " ")), "(", /*#__PURE__*/_compat.default.createElement(_Icons.LockIcon, {
    className: "ds-c-usa-banner__inline-lock-icon"
  }), ")", /*#__PURE__*/_compat.default.createElement("span", null, " ".concat((0, _i18n.t)('usaBanner.httpsOrText'))), /*#__PURE__*/_compat.default.createElement("strong", null, " ".concat((0, _i18n.t)('usaBanner.httpsText'), " ")), (0, _i18n.t)('usaBanner.httpsDetailText'))))));
};
exports.UsaBanner = UsaBanner;
var _default = UsaBanner;
exports.default = _default;