"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.Drawer = void 0;
var _compat = _interopRequireWildcard(require("preact/compat"));
var _Button = _interopRequireDefault(require("../Button/Button"));
var _NativeDialog = _interopRequireDefault(require("../NativeDialog/NativeDialog"));
var _classnames = _interopRequireDefault(require("classnames"));
var _i18n = require("../i18n");
var _useId = _interopRequireDefault(require("../utilities/useId"));
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; }
// TODO: closeButtonText, heading should be a string, but it is being used as a node in MCT,
// until we provide a better solution for customization, we type it as a node.

/**
 * For information about how and when to use this component,
 * [refer to its full documentation page](https://design.cms.gov/components/drawer/).
 */
var Drawer = function Drawer(props) {
  var _props$ariaLabel, _props$closeButtonTex;
  var headingRef = (0, _compat.useRef)(null);
  var headingId = (0, _useId.default)('drawer--', props.headingId);
  var Heading = "h".concat(props.headingLevel);
  return /*#__PURE__*/_compat.default.createElement(_NativeDialog.default, {
    className: (0, _classnames.default)(props.className, 'ds-c-drawer'),
    exit: props.onCloseClick,
    showModal: props.hasFocusTrap,
    isOpen: props.isOpen
  }, /*#__PURE__*/_compat.default.createElement("div", {
    className: "ds-c-drawer__window",
    tabIndex: -1,
    "aria-labelledby": headingId
  }, /*#__PURE__*/_compat.default.createElement("div", {
    className: "ds-c-drawer__header"
  }, /*#__PURE__*/_compat.default.createElement(Heading, {
    id: headingId,
    className: "ds-c-drawer__header-heading",
    ref: function ref(el) {
      headingRef.current = el;
      if (props.headingRef) {
        props.headingRef.current = el;
      }
    }
  }, props.heading), /*#__PURE__*/_compat.default.createElement(_Button.default, {
    "aria-label": (_props$ariaLabel = props.ariaLabel) !== null && _props$ariaLabel !== void 0 ? _props$ariaLabel : (0, _i18n.t)('drawer.ariaLabel'),
    className: "ds-c-drawer__close-button",
    size: "small",
    onClick: props.onCloseClick,
    variation: props.closeButtonVariation
  }, (_props$closeButtonTex = props.closeButtonText) !== null && _props$closeButtonTex !== void 0 ? _props$closeButtonTex : (0, _i18n.t)('drawer.closeButtonText'))), /*#__PURE__*/_compat.default.createElement("div", {
    className: (0, _classnames.default)('ds-c-drawer__body', {
      'ds-c-drawer--is-sticky': props.isHeaderSticky || props.isFooterSticky
    }),
    tabIndex: 0
  }, props.children), (props.footerTitle || props.footerBody) && /*#__PURE__*/_compat.default.createElement("div", {
    className: "ds-c-drawer__footer"
  }, /*#__PURE__*/_compat.default.createElement("h4", {
    className: "ds-c-drawer__footer-title"
  }, props.footerTitle), /*#__PURE__*/_compat.default.createElement("div", {
    className: "ds-c-drawer__footer-body"
  }, props.footerBody))));
};
exports.Drawer = Drawer;
Drawer.defaultProps = {
  headingLevel: '3',
  hasFocusTrap: false
};
var _default = Drawer;
exports.default = _default;