"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.HeaderDecorator = exports.HeaderBase = exports.Header = void 0;
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 _Marquee = require("../Marquee");
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _HeaderModule = _interopRequireDefault(require("./Header.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["children", "css", "marqueeOn", "title", "titleAboveComponent", "subtitleComponent"];
/**
 * Agate styled Header.
 *
 * @example
 * <Header hideLine title="Profile" titleAbove="Settings">
 * 	<Button>Close</Button>
 * </Header>
 *
 * @module agate/Header
 * @exports Header
 * @exports HeaderBase
 * @exports HeaderDecorator
 */
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
var MarqueeH1 = (0, _Marquee.MarqueeDecorator)('h1');
var MarqueeH2 = (0, _Marquee.MarqueeDecorator)('h2');

/**
 * A header component for a Panel with a `title`, `titleAbove`, `subtitle`
 *
 * @class HeaderBase
 * @memberof agate/Header
 * @ui
 * @public
 */
var HeaderBase = exports.HeaderBase = (0, _kind["default"])({
  name: 'Header',
  propTypes: /** @lends agate/Header.HeaderBase.prototype */{
    /**
     * Title of the header.
     *
     * This is a {@link ui/Slottable.Slottable|slot}, 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,
    /**
     * Determines what triggers the marquee to start its animation.
     *
     * @type {('focus'|'hover'|'render')}
     * @public
     */
    marqueeOn: _propTypes["default"].oneOf(['hover', 'render']),
    /**
     * Text displayed below the title.
     *
     * This is a {@link ui/Slottable.Slottable|slot}, 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 {@link ui/Slottable.Slottable|slot}, so it can be used as a tag-name inside
     * this component.
     *
     * @type {String}
     */
    titleAbove: _propTypes["default"].string
  },
  defaultProps: {
    marqueeOn: 'render'
  },
  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,
        marqueeOn = _ref3.marqueeOn,
        subtitle = _ref3.subtitle;
      return subtitle != null && subtitle !== '' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(MarqueeH2, {
        className: css.subtitle,
        marqueeOn: marqueeOn,
        children: subtitle
      }) : null;
    },
    titleAboveComponent: function titleAboveComponent(_ref4) {
      var css = _ref4.css,
        marqueeOn = _ref4.marqueeOn,
        titleAbove = _ref4.titleAbove;
      return titleAbove != null && titleAbove !== '' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(MarqueeH2, {
        className: css.titleAbove,
        marqueeOn: marqueeOn,
        children: titleAbove
      }) : null;
    }
  },
  render: function render(_ref5) {
    var children = _ref5.children,
      css = _ref5.css,
      marqueeOn = _ref5.marqueeOn,
      title = _ref5.title,
      titleAboveComponent = _ref5.titleAboveComponent,
      subtitleComponent = _ref5.subtitleComponent,
      rest = _objectWithoutProperties(_ref5, _excluded);
    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.Cell, {
        className: css.titleContainer,
        children: [titleAboveComponent, /*#__PURE__*/(0, _jsxRuntime.jsx)(MarqueeH1, {
          className: css.title,
          marqueeOn: marqueeOn,
          children: title
        }), subtitleComponent]
      }), children ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Layout.Layout, {
        className: css.endSlot,
        children: children
      }) : null]
    }));
  }
});

/**
 * Applies Agate specific behaviors to {@link agate/Header.Header|Header} components.
 *
 * @hoc
 * @memberof agate/Header
 * @mixes ui/Slottable.Slottable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */
var HeaderDecorator = exports.HeaderDecorator = (0, _compose["default"])((0, _Slottable["default"])({
  slots: ['subtitle', 'title', 'titleAbove']
}), _Marquee.MarqueeController, _Skinnable["default"]);

/**
 * An Agate-style header component
 *
 * @class Header
 * @memberof agate/Header
 * @extends agate/Header.HeaderBase
 * @mixes agate/Header.HeaderDecorator
 * @ui
 * @public
 */
var Header = exports.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.
Header.defaultSlot = 'header';
var _default = exports["default"] = Header;