"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ScrollbarBase = exports.Scrollbar = exports.default = void 0;

var _ApiDecorator = _interopRequireDefault(require("@enact/core/internal/ApiDecorator"));

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

var _react = _interopRequireWildcard(require("react"));

var _Scrollbar = require("@enact/ui/Scrollable/Scrollbar");

var _ScrollButtons = _interopRequireDefault(require("./ScrollButtons"));

var _ScrollThumb = _interopRequireDefault(require("./ScrollThumb"));

var _Scrollbar2 = _interopRequireDefault(require("./Scrollbar.less"));

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(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]; } 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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

/**
 * A Moonstone-styled scroller base component.
 *
 * @class ScrollbarBase
 * @memberof moonstone/Scrollable
 * @extends ui/ScrollbarBase
 * @ui
 * @private
 */
var ScrollbarBase =
/*#__PURE__*/
function (_Component) {
  _inherits(ScrollbarBase, _Component);

  function ScrollbarBase(props) {
    var _this;

    _classCallCheck(this, ScrollbarBase);

    _this = _possibleConstructorReturn(this, (ScrollbarBase.__proto__ || Object.getPrototypeOf(ScrollbarBase)).call(this, props));
    Object.defineProperty(_assertThisInitialized(_this), "initScrollbarRef", {
      configurable: true,
      enumerable: true,
      writable: true,
      value: function value(ref) {
        if (ref) {
          var getContainerRef = ref.getContainerRef,
              showThumb = ref.showThumb,
              startHidingThumb = ref.startHidingThumb,
              uiUpdate = ref.update;
          _this.getContainerRef = getContainerRef;
          _this.showThumb = showThumb;
          _this.startHidingThumb = startHidingThumb;
          _this.uiUpdate = uiUpdate;
        }
      }
    });
    Object.defineProperty(_assertThisInitialized(_this), "initScrollButtonsRef", {
      configurable: true,
      enumerable: true,
      writable: true,
      value: function value(ref) {
        if (ref) {
          var isOneOfScrollButtonsFocused = ref.isOneOfScrollButtonsFocused,
              updateButtons = ref.updateButtons;
          _this.isOneOfScrollButtonsFocused = isOneOfScrollButtonsFocused;

          _this.update = function (bounds) {
            updateButtons(bounds);

            _this.uiUpdate(bounds);
          };
        }
      }
    });

    if (props.setApiProvider) {
      props.setApiProvider(_assertThisInitialized(_this));
    }

    return _this;
  }

  _createClass(ScrollbarBase, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      var _props = this.props,
          cbAlertThumb = _props.cbAlertThumb,
          corner = _props.corner,
          vertical = _props.vertical,
          rest = _objectWithoutProperties(_props, ["cbAlertThumb", "corner", "vertical"]);

      return _react.default.createElement(_Scrollbar.ScrollbarBase, {
        corner: corner,
        css: _Scrollbar2.default,
        ref: this.initScrollbarRef,
        vertical: vertical,
        childRenderer: function childRenderer(_ref) {
          var initScrollThumbRef = _ref.initScrollThumbRef;
          return (// eslint-disable-line react/jsx-no-bind
            _react.default.createElement(_ScrollButtons.default, _extends({}, rest, {
              ref: _this2.initScrollButtonsRef,
              vertical: vertical,
              thumbRenderer: function thumbRenderer() {
                return (// eslint-disable-line react/jsx-no-bind
                  _react.default.createElement(_ScrollThumb.default, {
                    cbAlertThumb: cbAlertThumb,
                    key: "thumb",
                    setRef: initScrollThumbRef,
                    vertical: vertical
                  })
                );
              }
            }))
          );
        }
      });
    }
  }]);

  return ScrollbarBase;
}(_react.Component);
/**
 * A Moonstone-styled scroll bar. It is used in [Scrollable]{@link moonstone/Scrollable.Scrollable}.
 *
 * @class Scrollbar
 * @memberof moonstone/Scrollable
 * @ui
 * @private
 */


Object.defineProperty(ScrollbarBase, "displayName", {
  configurable: true,
  enumerable: true,
  writable: true,
  value: 'ScrollbarBase'
});
Object.defineProperty(ScrollbarBase, "propTypes", {
  configurable: true,
  enumerable: true,
  writable: true,
  value:
  /** @lends moonstone/Scrollable.Scrollbar.prototype */
  {
    /**
     * Called when [ScrollThumb]{@link moonstone/Scrollable.ScrollThumb} is updated.
     *
     * @type {Function}
     * @private
     */
    cbAlertThumb: _propTypes.default.func,

    /**
     * Adds the corner between vertical and horizontal scrollbars.
     *
     * @type {Booelan}
     * @default false
     * @public
     */
    corner: _propTypes.default.bool,

    /**
     * `true` if rtl, `false` if ltr.
     * Normally, [Scrollable]{@link ui/Scrollable.Scrollable} should set this value.
     *
     * @type {Boolean}
     * @private
     */
    rtl: _propTypes.default.bool,

    /**
     * Registers the ScrollButtons component with an
     * {@link core/internal/ApiDecorator.ApiDecorator}.
     *
     * @type {Function}
     * @private
     */
    setApiProvider: _propTypes.default.func,

    /**
     * The scrollbar will be oriented vertically.
     *
     * @type {Boolean}
     * @default true
     * @public
     */
    vertical: _propTypes.default.bool
  }
});
Object.defineProperty(ScrollbarBase, "defaultProps", {
  configurable: true,
  enumerable: true,
  writable: true,
  value: {
    corner: false,
    vertical: true
  }
});
var Scrollbar = (0, _ApiDecorator.default)({
  api: ['getContainerRef', 'isOneOfScrollButtonsFocused', 'showThumb', 'startHidingThumb', 'update']
}, ScrollbarBase);
exports.ScrollbarBase = exports.Scrollbar = Scrollbar;
Scrollbar.displayName = 'Scrollbar';
var _default = Scrollbar;
exports.default = _default;