"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.TooltipBase = exports.Tooltip = void 0;
var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types"));
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _propTypes2 = _interopRequireDefault(require("prop-types"));
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _TooltipLabel = _interopRequireDefault(require("./TooltipLabel"));
var _TooltipModule = _interopRequireDefault(require("./Tooltip.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["arrowAnchor", "children", "tooltipRef", "width", "labelOffset", "marquee"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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; }
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); } /**
 * A stateless tooltip component with Agate styling applied.
 *
 * @class TooltipBase
 * @memberof agate/TooltipDecorator
 * @ui
 * @public
 */
var TooltipBase = exports.TooltipBase = (0, _kind["default"])({
  name: 'Tooltip',
  propTypes: /** @lends agate/TooltipDecorator.TooltipBase.prototype */{
    /**
     * The node to be displayed as the main content of the tooltip.
     *
     * @type {Node}
     * @required
     */
    children: _propTypes2["default"].node.isRequired,
    /**
     * Position of tooltip arrow in relation to the activator.
     *
     * Note that `'left'`, `'center'`, `'right'` are applicable when direction is in vertical
     * orientation (i.e. `'above'`, `'below'`), and `'top'`, `'middle'`, and `'bottom'` are
     * applicable when direction is in horizontal orientation (i.e. `'left'`, `'right'`)
     *
     * @type {('left'|'center'|'right'|'top'|'middle'|'bottom')}
     * @default 'right'
     * @public
     */
    arrowAnchor: _propTypes2["default"].oneOf(['left', 'center', 'right', 'top', 'middle', 'bottom']),
    /**
     * 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:
     *
     * * `tooltip` - The root component class
     * * `tooltipLabel` - Applied the label node
     *
     * @type {Object}
     * @public
     */
    css: _propTypes2["default"].object,
    /**
     * Direction of label in relation to the activator.
     *
     * @type {('above'|'below'|'left'|'right')}
     * @default 'above'
     * @public
     */
    direction: _propTypes2["default"].oneOf(['above', 'below', 'left', 'right']),
    /**
     * A value representing the amount to offset the label portion of the tooltip.
     *
     * In a "center" aligned tooltip, the label may be desirable to offset to one side or the
     * other. This prop accepts a value between -0.5 and 0.5 (representing 50% to the left or
     * right). This defaults to 0 offset (centered). It also automatically caps the value so it
     * never positions the tooltip label past the anchored arrow. If the tooltip label or arrow
     * has non-rectangular geometry (rounded corners, a wide tail, etc), you'll need to manually
     * account for that in your provided offset value.
     *
     * @type {Number}
     * @default 0
     * @public
     */
    labelOffset: _propTypes2["default"].number,
    /**
     * Allows the tooltip to marquee.
     *
     * Specifying a {@link agate/TooltipDecorator.TooltipBase#width|width} restricts
     * the marquee to that size.
     *
     * @type {Boolean}
     * @public
     */
    marquee: _propTypes2["default"].bool,
    /**
     * Style object for tooltip position.
     *
     * @type {Object}
     * @public
     */
    position: _propTypes2["default"].shape({
      bottom: _propTypes2["default"].number,
      left: _propTypes2["default"].number,
      right: _propTypes2["default"].number,
      top: _propTypes2["default"].number
    }),
    /**
     * Anchors the tooltip relative to its container.
     *
     * Reconfigures the component to anchor itself to the designated edge of its container.
     * When this is not specified, the implication is that the component is "absolutely"
     * positioned, relative to the viewport, rather than its parent layer.
     *
     * @type {Boolean}
     * @public
     */
    relative: _propTypes2["default"].bool,
    /**
     * Called when the tooltip mounts/unmounts, giving a reference to the DOM.
     *
     * @type {Object|Function}
     * @public
     */
    tooltipRef: _propTypes["default"].ref,
    /**
     * The width of tooltip content.
     *
     * Value expects a number of pixels, which will be automatically scaled to the appropriate
     * size given the current screen resolution, or a string value containing a measurement and
     * a valid CSS unit included.
     * If the content goes over the given width, it will automatically wrap, or marquee if
     * `marquee` is enabled.
     *
     * When `null`, content will auto-size and not wrap. If `marquee` is also enabled,
     * marqueeing will begin when the width is greater than the default (theme specified) width.
     *
     * @type {Number|String}
     * @public
     */
    width: _propTypes2["default"].oneOfType([_propTypes2["default"].number, _propTypes2["default"].string])
  },
  defaultProps: {
    arrowAnchor: 'right',
    direction: 'above',
    labelOffset: 0
  },
  styles: {
    css: _TooltipModule["default"],
    className: 'tooltip'
  },
  computed: {
    labelOffset: function labelOffset(_ref) {
      var _labelOffset = _ref.labelOffset;
      if (_labelOffset) {
        var cappedPosition = Math.max(-0.5, Math.min(0.5, _labelOffset));
        return {
          transform: "translateX(".concat(cappedPosition * 100, "%)")
        };
      }
    },
    className: function className(_ref2) {
      var direction = _ref2.direction,
        arrowAnchor = _ref2.arrowAnchor,
        relative = _ref2.relative,
        styler = _ref2.styler;
      return styler.append(direction, "".concat(arrowAnchor, "Arrow"), {
        relative: relative,
        absolute: !relative
      });
    },
    style: function style(_ref3) {
      var position = _ref3.position,
        _style = _ref3.style;
      return _objectSpread(_objectSpread({}, _style), position);
    }
  },
  render: function render(_ref4) {
    var arrowAnchor = _ref4.arrowAnchor,
      children = _ref4.children,
      tooltipRef = _ref4.tooltipRef,
      width = _ref4.width,
      labelOffset = _ref4.labelOffset,
      marquee = _ref4.marquee,
      rest = _objectWithoutProperties(_ref4, _excluded);
    delete rest.labelOffset;
    delete rest.direction;
    delete rest.position;
    delete rest.relative;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, rest), {}, {
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        className: _TooltipModule["default"].tooltipAnchor,
        ref: tooltipRef,
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: _TooltipModule["default"].tooltipArrow
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_TooltipLabel["default"], {
          className: _TooltipModule["default"].tooltipLabel,
          centered: arrowAnchor === 'center',
          marquee: marquee,
          width: width,
          style: labelOffset,
          children: children
        })]
      })
    }));
  }
});

/**
 * A tooltip component with Agate styling applied.
 *
 * @class Tooltip
 * @memberof agate/TooltipDecorator
 * @ui
 * @public
 */
var Tooltip = exports.Tooltip = (0, _Skinnable["default"])(TooltipBase);
var _default = exports["default"] = Tooltip;