"use strict";

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

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

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

var _ForwardRef = _interopRequireDefault(require("@enact/ui/ForwardRef"));

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

var _reactDom = _interopRequireDefault(require("react-dom"));

var _Button = _interopRequireDefault(require("../Button"));

var _ScrollbarModule = _interopRequireDefault(require("./Scrollbar.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 [Button]{@link agate/Button.Button} used within
 * a [Scrollbar]{@link agate/useScroll.Scrollbar}.
 *
 * @class ScrollButton
 * @memberof agate/useScroll
 * @extends agate/Button.Button
 * @ui
 * @private
 */
var ScrollButtonBase = (0, _kind["default"])({
  name: 'ScrollButton',
  propTypes:
  /** @lends agate/useScroll.ScrollButton.prototype */
  {
    /**
     * Name of icon.
     *
     * @type {String}
     * @required
     * @public
     */
    icon: _propTypes["default"].string.isRequired,

    /**
     * Sets the `aria-label`.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    active: _propTypes["default"].bool,

    /**
     * Sets the hint string read when focusing the scroll bar button.
     *
     * @type {String}
     * @memberof agate/useScroll.ScrollButton.prototype
     * @public
     */
    'aria-label': _propTypes["default"].string,

    /**
     * Disables the button.
     *
     * @type {Boolean}
     * @public
     */
    disabled: _propTypes["default"].bool,

    /**
     * Returns a ref to the root node of the scroll button
     *
     * See: https://github.com/facebook/prop-types/issues/240
     *
     * @type {Function|Object}
     * @private
     */
    forwardRef: _propTypes["default"].oneOfType([_propTypes["default"].func, _propTypes["default"].shape({
      current: _propTypes["default"].any
    })])
  },
  styles: {
    css: _ScrollbarModule["default"],
    className: 'scrollButton'
  },
  handlers: {
    forwardRef: function forwardRef(node, _ref) {
      var _forwardRef = _ref.forwardRef;

      // Allowing findDOMNode in the absence of a means to retrieve a node ref through Button
      // eslint-disable-next-line react/no-find-dom-node
      var current = _reactDom["default"].findDOMNode(node); // Safely handle old ref functions and new ref objects


      switch (typeof _forwardRef) {
        case 'object':
          _forwardRef.current = current;
          break;

        case 'function':
          _forwardRef(current);

          break;
      }
    }
  },
  computed: {
    'aria-label': function ariaLabel(_ref2) {
      var active = _ref2.active,
          _ariaLabel = _ref2['aria-label'];
      return active ? null : _ariaLabel;
    }
  },
  render: function render(_ref3) {
    var forwardRef = _ref3.forwardRef,
        rest = _objectWithoutProperties(_ref3, ["forwardRef"]);

    delete rest.active;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button["default"], _objectSpread(_objectSpread({}, rest), {}, {
      backgroundOpacity: "transparent",
      ref: forwardRef,
      size: "small"
    }));
  }
});
var ScrollButton = (0, _ForwardRef["default"])(ScrollButtonBase);
exports.ScrollButton = ScrollButton;
var _default = ScrollButton;
exports["default"] = _default;