"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.HeaderDecorator = exports.HeaderBase = exports.Header = exports["default"] = void 0;

var _jsxRuntime = require("react/jsx-runtime");

var _kind = _interopRequireDefault(require("@enact/core/kind"));

var _Layout = require("@enact/ui/Layout");

var _Slottable = _interopRequireDefault(require("@enact/ui/Slottable"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _compose = _interopRequireDefault(require("ramda/src/compose"));

var _Skinnable = _interopRequireDefault(require("../Skinnable"));

var _HeaderModule = _interopRequireDefault(require("./Header.module.css"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

/**
 * A header component for a Panel with a `title`, `titleAbove`, `subtitle`
 *
 * @class HeaderBase
 * @memberof agate/Header
 * @ui
 * @public
 */
var HeaderBase = (0, _kind["default"])({
  name: 'Header',
  propTypes:
  /** @lends agate/Header.HeaderBase.prototype */
  {
    /**
     * Title of the header.
     *
     * This is a [`slot`]{@link ui/Slottable.Slottable}, so it can be used as a tag-name inside
     * this component.
     *
     * Example:
     * ```
     *  <Header>
     *  	<titleAbove>Introducing...</titleAbove>
     *  	<title>Example Header Title</title>
     *  	<subtitle>The Adventure Continues</subtitle>
     *  </Header>
     * ```
     *
     * @required
     * @type {String}
     */
    title: _propTypes["default"].string.isRequired,

    /**
     * Sets the hint string read.
     *
     * @type {String}
     * @public
     */
    'aria-label': _propTypes["default"].string,

    /**
     * Customizes the component by mapping the supplied collection of CSS class names to the
     * corresponding internal elements and states of this component.
     *
     * The following classes are supported:
     *
     * * `header` - The root class name
     * * `titleContainer` - The background title container
     * * `subtitle` - Applied to `subtitle`
     * * `title` - Applied to `title`
     * * `titleAbove` - Applied to `titleAbove`
     *
     * @type {Object}
     * @public
     */
    css: _propTypes["default"].object,

    /**
     * Hides the horizontal-rule (line) under the component
     *
     * @type {Boolean}
     * @public
     */
    hideLine: _propTypes["default"].bool,

    /**
     * Text displayed below the title.
     *
     * This is a [`slot`]{@link ui/Slottable.Slottable}, so it can be used as a tag-name inside
     * this component.
     *
     * @type {String}
     */
    subtitle: _propTypes["default"].string,

    /**
     * Text displayed above the title.
     *
     * This is a [`slot`]{@link ui/Slottable.Slottable}, so it can be used as a tag-name inside
     * this component.
     *
     * @type {String}
     */
    titleAbove: _propTypes["default"].string
  },
  styles: {
    css: _HeaderModule["default"],
    className: 'header',
    publicClassNames: true
  },
  computed: {
    'aria-label': function ariaLabel(_ref) {
      var _ariaLabel = _ref['aria-label'],
          title = _ref.title,
          subtitle = _ref.subtitle;
      return _ariaLabel || subtitle ? title + ' ' + subtitle : title;
    },
    className: function className(_ref2) {
      var hideLine = _ref2.hideLine,
          styler = _ref2.styler;
      return styler.append({
        hideLine: hideLine,
        standard: true
      });
    },
    subtitleComponent: function subtitleComponent(_ref3) {
      var css = _ref3.css,
          subtitle = _ref3.subtitle;
      return subtitle != null && subtitle !== '' ? /*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
        className: css.subtitle,
        children: subtitle
      }) : null;
    },
    titleAboveComponent: function titleAboveComponent(_ref4) {
      var css = _ref4.css,
          titleAbove = _ref4.titleAbove;
      return titleAbove != null && titleAbove !== '' ? /*#__PURE__*/(0, _jsxRuntime.jsx)("h2", {
        className: css.titleAbove,
        children: titleAbove
      }) : null;
    }
  },
  render: function render(_ref5) {
    var children = _ref5.children,
        css = _ref5.css,
        title = _ref5.title,
        titleAboveComponent = _ref5.titleAboveComponent,
        subtitleComponent = _ref5.subtitleComponent,
        rest = _objectWithoutProperties(_ref5, ["children", "css", "title", "titleAboveComponent", "subtitleComponent"]);

    delete rest.hideLine;
    delete rest.subtitle;
    delete rest.titleAbove;
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Layout.Row, _objectSpread(_objectSpread({
      component: "header"
    }, rest), {}, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Layout.Column, {
        className: css.titleContainer,
        children: [titleAboveComponent, /*#__PURE__*/(0, _jsxRuntime.jsx)("h1", {
          className: css.title,
          children: title
        }), subtitleComponent]
      }), children ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Layout, {
        className: css.endSlot,
        children: children
      }) : null]
    }));
  }
});
/**
 * Applies Agate specific behaviors to [Header]{@link agate/Header.Header} components.
 *
 * @hoc
 * @memberof agate/Header
 * @mixes ui/Slottable.Slottable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */

exports.HeaderBase = HeaderBase;
var HeaderDecorator = (0, _compose["default"])((0, _Slottable["default"])({
  slots: ['subtitle', 'title', 'titleAbove']
}), _Skinnable["default"]);
/**
 * An Agate-style header component
 *
 * @class Header
 * @memberof agate/Header
 * @extends agate/Header.HeaderBase
 * @mixes agate/Header.HeaderDecorator
 * @ui
 * @public
 */

exports.HeaderDecorator = HeaderDecorator;
var Header = HeaderDecorator(HeaderBase); // Set up Header so when it's used in a slottable layout (like Panel), it is automatically
// recognized as this specific slot.

exports.Header = Header;
Header.defaultSlot = 'header';
var _default = Header;
exports["default"] = _default;