"use strict";

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

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

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"));

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; }

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, ["cbAlertScrollbarTrack", "disabled", "focusableScrollButtons", "nextButtonAriaLabel", "onKeyDownButton", "onNextScroll", "onPrevScroll", "preventBubblingOnKeyDown", "previousButtonAriaLabel", "rtl"]);

  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 = /*#__PURE__*/(0, _react.memo)(function (props) {
  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,
      vertical = scrollbarButtonsProps.vertical;
  (0, _react.useEffect)(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,
      onHoldPulse: 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,
      onHoldPulse: onClickNext,
      ref: nextButtonRef,
      icon: nextIcon
    })]
  }));
});
exports.ScrollbarBase = ScrollbarBase;
ScrollbarBase.displayName = 'ScrollbarBase';
ScrollbarBase.propTypes =
/** @lends agate/useScroll.Scrollbar.prototype */
{
  /**
   * If `true`, add the corner between vertical and horizontal scrollbars.
   *
   * @type {Booelan}
   * @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
};
ScrollbarBase.defaultProps = {
  css: _ScrollbarModule["default"],
  minThumbSize: 18,
  vertical: true
};
/**
 * An Agate-styled scroll bar.
 *
 * @class Scrollbar
 * @memberof agate/useScroll
 * @ui
 * @private
 */

var Scrollbar = (0, _Skinnable["default"])(ScrollbarBase);
exports.Scrollbar = Scrollbar;
Scrollbar.displayName = 'Scrollbar';
var _default = Scrollbar;
exports["default"] = _default;