"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.ScrollbarBase = exports.Scrollbar = void 0;
var _Scrollbar = require("@enact/ui/useScroll/Scrollbar");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = require("react");
var _ScrollButton = _interopRequireDefault(require("./ScrollButton"));
var _ScrollButtons = _interopRequireDefault(require("./ScrollButtons"));
var _ScrollbarTrack = _interopRequireDefault(require("./ScrollbarTrack"));
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _ScrollbarModule = _interopRequireDefault(require("./Scrollbar.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["cbAlertScrollbarTrack", "disabled", "focusableScrollButtons", "nextButtonAriaLabel", "onKeyDownButton", "onNextScroll", "onPrevScroll", "preventBubblingOnKeyDown", "previousButtonAriaLabel", "rtl"],
  _excluded2 = ["css", "minThumbSize", "vertical"];
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 useThemeScrollbar = function useThemeScrollbar(props) {
  var _useScrollbarBase = (0, _Scrollbar.useScrollbar)(props),
    restProps = _useScrollbarBase.restProps,
    scrollbarProps = _useScrollbarBase.scrollbarProps,
    scrollbarTrackProps = _useScrollbarBase.scrollbarTrackProps;
  var cbAlertScrollbarTrack = restProps.cbAlertScrollbarTrack,
    disabled = restProps.disabled,
    focusableScrollButtons = restProps.focusableScrollButtons,
    nextButtonAriaLabel = restProps.nextButtonAriaLabel,
    onKeyDownButton = restProps.onKeyDownButton,
    onNextScroll = restProps.onNextScroll,
    onPrevScroll = restProps.onPrevScroll,
    preventBubblingOnKeyDown = restProps.preventBubblingOnKeyDown,
    previousButtonAriaLabel = restProps.previousButtonAriaLabel,
    rtl = restProps.rtl,
    rest = _objectWithoutProperties(restProps, _excluded);
  var vertical = scrollbarTrackProps.vertical;
  return {
    restProps: rest,
    scrollbarProps: scrollbarProps,
    scrollbarButtonsProps: {
      disabled: disabled,
      focusableScrollButtons: focusableScrollButtons,
      nextButtonAriaLabel: nextButtonAriaLabel,
      onKeyDownButton: onKeyDownButton,
      onNextScroll: onNextScroll,
      onPrevScroll: onPrevScroll,
      preventBubblingOnKeyDown: preventBubblingOnKeyDown,
      previousButtonAriaLabel: previousButtonAriaLabel,
      rtl: rtl,
      vertical: vertical
    },
    scrollbarTrackProps: _objectSpread(_objectSpread({}, scrollbarTrackProps), {}, {
      cbAlertScrollbarTrack: cbAlertScrollbarTrack
    })
  };
};

/**
 * An Agate-styled scrollbar base component.
 *
 * @class ScrollbarBase
 * @memberof agate/useScroll
 * @ui
 * @private
 */
var ScrollbarBase = exports.ScrollbarBase = /*#__PURE__*/(0, _react.memo)(function (_ref) {
  var _ref$css = _ref.css,
    css = _ref$css === void 0 ? _ScrollbarModule["default"] : _ref$css,
    _ref$minThumbSize = _ref.minThumbSize,
    minThumbSize = _ref$minThumbSize === void 0 ? 18 : _ref$minThumbSize,
    _ref$vertical = _ref.vertical,
    vertical = _ref$vertical === void 0 ? true : _ref$vertical,
    rest = _objectWithoutProperties(_ref, _excluded2);
  var props = _objectSpread({
    css: css,
    minThumbSize: minThumbSize,
    vertical: vertical
  }, rest);
  var _useThemeScrollbar = useThemeScrollbar(props),
    restProps = _useThemeScrollbar.restProps,
    scrollbarProps = _useThemeScrollbar.scrollbarProps,
    scrollbarButtonsProps = _useThemeScrollbar.scrollbarButtonsProps,
    scrollbarTrackProps = _useThemeScrollbar.scrollbarTrackProps;
  var _useScrollButtons = (0, _ScrollButtons["default"])(scrollbarButtonsProps),
    focusOnButton = _useScrollButtons.focusOnButton,
    isOneOfScrollButtonsFocused = _useScrollButtons.isOneOfScrollButtonsFocused,
    nextButtonDisabled = _useScrollButtons.nextButtonDisabled,
    nextButtonRef = _useScrollButtons.nextButtonRef,
    nextIcon = _useScrollButtons.nextIcon,
    onClickNext = _useScrollButtons.onClickNext,
    onClickPrev = _useScrollButtons.onClickPrev,
    prevButtonDisabled = _useScrollButtons.prevButtonDisabled,
    prevButtonRef = _useScrollButtons.prevButtonRef,
    prevIcon = _useScrollButtons.prevIcon,
    updateButtons = _useScrollButtons.updateButtons;
  var disabled = scrollbarButtonsProps.disabled,
    nextButtonAriaLabel = scrollbarButtonsProps.nextButtonAriaLabel,
    previousButtonAriaLabel = scrollbarButtonsProps.previousButtonAriaLabel,
    rtl = scrollbarButtonsProps.rtl;
  (0, _react.useLayoutEffect)(function () {
    var scrollbarHandle = props.scrollbarHandle;
    var uiUpdate = scrollbarHandle.current.update;
    scrollbarHandle.current.update = function (bounds) {
      updateButtons(bounds);
      uiUpdate(bounds);
    };
    scrollbarHandle.current.focusOnButton = focusOnButton;
    scrollbarHandle.current.isOneOfScrollButtonsFocused = isOneOfScrollButtonsFocused;
  });
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", _objectSpread(_objectSpread(_objectSpread({}, restProps), scrollbarProps), {}, {
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ScrollButton["default"], {
      "aria-label": rtl && !vertical ? nextButtonAriaLabel : previousButtonAriaLabel,
      "data-spotlight-overflow": "ignore",
      disabled: disabled || prevButtonDisabled,
      onClick: onClickPrev,
      onHold: onClickPrev,
      ref: prevButtonRef,
      icon: prevIcon
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ScrollbarTrack["default"], _objectSpread({}, scrollbarTrackProps)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ScrollButton["default"], {
      "aria-label": rtl && !vertical ? previousButtonAriaLabel : nextButtonAriaLabel,
      "data-spotlight-overflow": "ignore",
      disabled: disabled || nextButtonDisabled,
      onClick: onClickNext,
      onHold: onClickNext,
      ref: nextButtonRef,
      icon: nextIcon
    })]
  }));
});
ScrollbarBase.displayName = 'ScrollbarBase';
ScrollbarBase.propTypes = /** @lends agate/useScroll.Scrollbar.prototype */{
  /**
   * If `true`, add the corner between vertical and horizontal scrollbars.
   *
   * @type {Boolean}
   * @default false
   * @public
   */
  corner: _propTypes["default"].bool,
  /**
   * 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:
   *
   * * `scrollbar` - The scrollbar component class
   *
   * @type {Object}
   * @public
   */
  css: _propTypes["default"].object,
  /**
   * Specifies to reflect scrollbar's disabled property to the paging controls.
   * When it is `true`, both prev/next buttons are going to be disabled.
   *
   * @type {Boolean}
   * @default false
   * @public
   */
  disabled: _propTypes["default"].bool,
  /**
   * When it is `true`, it allows 5 way navigation to the ScrollButtons.
   *
   * @type {Boolean}
   * @default false
   * @private
   */
  focusableScrollButtons: _propTypes["default"].bool,
  /**
   * The minimum size of the thumb.
   * This value will be applied ri.scale.
   *
   * @type {Number}
   * @default 18
   * @public
   */
  minThumbSize: _propTypes["default"].number,
  /**
   * Sets the hint string read when focusing the next button in the scroll bar.
   *
   * @type {String}
   * @public
   */
  nextButtonAriaLabel: _propTypes["default"].string,
  /**
   * Called when the scrollbar's button is pressed and needs to be bubbled.
   *
   * @type {Function}
   * @private
   */
  onKeyDownButton: _propTypes["default"].func,
  /**
   * Called when the scrollbar's down/right button is pressed.
   *
   * @type {Function}
   * @public
   */
  onNextScroll: _propTypes["default"].func,
  /**
   * Called when the scrollbar's up/left button is pressed.
   *
   * @type {Function}
   * @public
   */
  onPrevScroll: _propTypes["default"].func,
  /**
   * Specifies preventing keydown events from bubbling up to applications.
   * Valid values are `'none'`, and `'programmatic'`.
   *
   * When it is `'none'`, every keydown event is bubbled.
   * When it is `'programmatic'`, an event bubbling is not allowed for a keydown input
   * which invokes programmatic spotlight moving.
   *
   * @type {String}
   * @private
   */
  preventBubblingOnKeyDown: _propTypes["default"].oneOf(['none', 'programmatic']),
  /**
   * Sets the hint string read when focusing the previous button in the scroll bar.
   *
   * @type {String}
   * @public
   */
  previousButtonAriaLabel: _propTypes["default"].string,
  /**
   * `true` if rtl, `false` if ltr.
   *
   * @type {Boolean}
   * @private
   */
  rtl: _propTypes["default"].bool,
  /**
   * The scrollbar will be oriented vertically.
   *
   * @type {Boolean}
   * @default true
   * @public
   */
  vertical: _propTypes["default"].bool
};

/**
 * An Agate-styled scroll bar.
 *
 * @class Scrollbar
 * @memberof agate/useScroll
 * @ui
 * @private
 */
var Scrollbar = exports.Scrollbar = (0, _Skinnable["default"])(ScrollbarBase);
Scrollbar.displayName = 'Scrollbar';
var _default = exports["default"] = Scrollbar;